Attachment #8705632: Part 1: WebIDL (WIP) for bug #1217544

View | Details | Raw Unified | Return to bug 1217544
Collapse All | Expand All

(-)a/dom/moz.build (+1 lines)
Line     Link Here 
 Lines 109-124   DIRS += [ Link Here 
109
    'xbl',
109
    'xbl',
110
    'xml',
110
    'xml',
111
    'xslt',
111
    'xslt',
112
    'xul',
112
    'xul',
113
    'resourcestats',
113
    'resourcestats',
114
    'manifest',
114
    'manifest',
115
    'vr',
115
    'vr',
116
    'newapps',
116
    'newapps',
117
    'sync'
117
]
118
]
118
119
119
if CONFIG['OS_ARCH'] == 'WINNT':
120
if CONFIG['OS_ARCH'] == 'WINNT':
120
    DIRS += ['plugins/ipc/hangui']
121
    DIRS += ['plugins/ipc/hangui']
121
122
122
if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
123
if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
123
    DIRS += [
124
    DIRS += [
124
        'speakermanager',
125
        'speakermanager',
(-)a/dom/sync/SyncManager.cpp (+136 lines)
Line     Link Here 
Line 0    Link Here 
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5
 * You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#include "SyncManager.h"
8
9
#include "mozilla/dom/Promise.h"
10
#include "mozilla/dom/PromiseWorkerProxy.h"
11
#include "mozilla/dom/SyncManagerBinding.h"
12
#include "mozilla/ipc/BackgroundChild.h"
13
#include "mozilla/ipc/BackgroundUtils.h"
14
#include "mozilla/ipc/PBackgroundChild.h"
15
#include "mozilla/Preferences.h"
16
#include "nsIGlobalObject.h"
17
#include "WorkerPrivate.h"
18
19
namespace mozilla {
20
21
using namespace ipc;
22
23
namespace dom {
24
25
using namespace workers;
26
27
// SyncManager
28
29
// static
30
already_AddRefed<SyncManager>
31
SyncManager::CreateOnMainThread(nsIGlobalObject* aGlobal,
32
                                nsIPrincipal* aPrincipal,
33
                                ErrorResult& aRv)
34
{
35
  MOZ_ASSERT(aGlobal);
36
  MOZ_ASSERT(aPrincipal);
37
  MOZ_ASSERT(NS_IsMainThread());
38
39
  PrincipalInfo principalInfo;
40
  nsresult rv = PrincipalToPrincipalInfo(aPrincipal, &principalInfo);
41
  if (NS_WARN_IF(NS_FAILED(rv))) {
42
    aRv.Throw(rv);
43
    return nullptr;
44
  }
45
46
  RefPtr<SyncManager> ref = new SyncManager(aGlobal, principalInfo);
47
  return ref.forget();
48
}
49
50
// static
51
already_AddRefed<SyncManager>
52
SyncManager::CreateOnWorker(WorkerPrivate* aWorkerPrivate)
53
{
54
  MOZ_ASSERT(aWorkerPrivate);
55
  aWorkerPrivate->AssertIsOnWorkerThread();
56
57
  const PrincipalInfo& principalInfo = aWorkerPrivate->GetPrincipalInfo();
58
59
  RefPtr<SyncManager> ref = new SyncManager(nullptr, principalInfo);
60
  return ref.forget();
61
}
62
63
SyncManager::SyncManager(nsIGlobalObject* aGlobal,
64
                         const PrincipalInfo& aPrincipalInfo)
65
  : mGlobal(aGlobal)
66
  , mPrincipalInfo(new PrincipalInfo(aPrincipalInfo))
67
{}
68
69
SyncManager::~SyncManager()
70
{}
71
72
// Bindings methods.
73
74
JSObject*
75
SyncManager::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
76
{
77
  return SyncManagerBinding::Wrap(aCx, this, aGivenProto);
78
}
79
80
// static
81
bool
82
SyncManager::PrefEnabled(JSContext* aCx, JSObject* aObj)
83
{
84
  using mozilla::dom::workers::WorkerPrivate;
85
  using mozilla::dom::workers::GetWorkerPrivateFromContext;
86
87
  // If we are on the main thread, then check the pref directly.
88
  if (NS_IsMainThread()) {
89
    bool enabled = false;
90
    Preferences::GetBool("dom.background.sync.enabled", &enabled);
91
    return enabled;
92
  }
93
94
  // Otherwise check the pref via the worker private helper.
95
  WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(aCx);
96
  if (!workerPrivate) {
97
    return false;
98
  }
99
100
  return workerPrivate->BackgroundSyncEnabled();
101
}
102
103
// WebIDL interace methods.
104
105
already_AddRefed<Promise>
106
SyncManager::Register(const nsAString& aName, ErrorResult& aRv)
107
{
108
  RefPtr<Promise> p = Promise::Create(mGlobal, aRv);
109
  if (NS_WARN_IF(aRv.Failed())) {
110
    return nullptr;
111
  }
112
113
  return p.forget();
114
}
115
116
already_AddRefed<Promise>
117
SyncManager::GetTags(ErrorResult& aRv)
118
{
119
  RefPtr<Promise> p = Promise::Create(mGlobal, aRv);
120
  if (NS_WARN_IF(aRv.Failed())) {
121
    return nullptr;
122
  }
123
124
  return p.forget();
125
}
126
127
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(SyncManager, mGlobal)
128
NS_IMPL_CYCLE_COLLECTING_ADDREF(SyncManager)
129
NS_IMPL_CYCLE_COLLECTING_RELEASE(SyncManager)
130
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(SyncManager)
131
  NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
132
  NS_INTERFACE_MAP_ENTRY(nsISupports)
133
NS_INTERFACE_MAP_END
134
135
} // namespace dom
136
} // namespace mozilla
(-)a/dom/sync/SyncManager.h (+87 lines)
Line     Link Here 
Line 0    Link Here 
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5
 * You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#ifndef mozilla_dom_SyncManager_h
8
#define mozilla_dom_SyncManager_h
9
10
#include "nsIPrincipal.h"
11
#include "nsWrapperCache.h"
12
13
#include "mozilla/AlreadyAddRefed.h"
14
#include "mozilla/ErrorResult.h"
15
#include "mozilla/dom/BindingDeclarations.h"
16
17
#include "nsCOMPtr.h"
18
#include "jsapi.h"
19
20
class nsIGlobalObject;
21
22
namespace mozilla {
23
24
namespace ipc {
25
  class PrincipalInfo;
26
} // namespace ipc
27
28
namespace dom {
29
30
namespace workers {
31
  class WorkerPrivate;
32
} // namespace workers
33
34
class Promise;
35
36
class SyncManager final : public nsISupports
37
                        , public nsWrapperCache
38
{
39
public:
40
  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
41
  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(SyncManager)
42
43
  static already_AddRefed<SyncManager>
44
  CreateOnMainThread(nsIGlobalObject* aGlobal,
45
                     nsIPrincipal* aPrincipal,
46
                     ErrorResult& aRv);
47
48
  static already_AddRefed<SyncManager>
49
  CreateOnWorker(workers::WorkerPrivate* aWorkerPrivate);
50
51
  // Binding methods.
52
53
  nsIGlobalObject*
54
  GetParentObject() const
55
  {
56
    // Can be nullptr on workers.
57
    return mGlobal;
58
  }
59
60
  JSObject*
61
  WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
62
63
  static bool PrefEnabled(JSContext* aCx, JSObject* aObj);
64
65
  // WebIDL interface methods.
66
67
  already_AddRefed<Promise>
68
  Register(const nsAString& aName, ErrorResult& aRv);
69
70
  already_AddRefed<Promise>
71
  GetTags(ErrorResult& aRv);
72
73
private:
74
  SyncManager(nsIGlobalObject* aGlobal,
75
              const mozilla::ipc::PrincipalInfo& aPrincipalInfo);
76
77
  ~SyncManager();
78
79
  nsCOMPtr<nsIGlobalObject> mGlobal;
80
81
  nsAutoPtr<mozilla::ipc::PrincipalInfo> mPrincipalInfo;
82
};
83
84
} // namespace dom
85
} // namespace mozilla
86
87
#endif // mozilla_dom_SyncManager_h
(-)a/dom/sync/moz.build (+20 lines)
Line     Link Here 
Line 0    Link Here 
1
# vim: set filetype=python:
2
# This Source Code Form is subject to the terms of the Mozilla Public
3
# License, v. 2.0. If a copy of the MPL was not distributed with this
4
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
5
6
EXPORTS.mozilla.dom += [
7
    'SyncManager.h'
8
]
9
10
UNIFIED_SOURCES += [
11
    'SyncManager.cpp'
12
]
13
14
LOCAL_INCLUDES += [
15
    '/dom/workers'
16
]
17
18
include('/ipc/chromium/chromium-config.mozbuild')
19
20
FINAL_LIBRARY = 'xul'
(-)a/dom/tests/mochitest/general/test_interfaces.html (+2 lines)
Line     Link Here 
 Lines 1291-1306   var interfaceNamesInGlobalScope = Link Here 
1291
    "SVGUseElement",
1291
    "SVGUseElement",
1292
// IMPORTANT: Do not change this list without review from a DOM peer!
1292
// IMPORTANT: Do not change this list without review from a DOM peer!
1293
    "SVGViewElement",
1293
    "SVGViewElement",
1294
// IMPORTANT: Do not change this list without review from a DOM peer!
1294
// IMPORTANT: Do not change this list without review from a DOM peer!
1295
    "SVGZoomAndPan",
1295
    "SVGZoomAndPan",
1296
// IMPORTANT: Do not change this list without review from a DOM peer!
1296
// IMPORTANT: Do not change this list without review from a DOM peer!
1297
    "SVGZoomEvent",
1297
    "SVGZoomEvent",
1298
// IMPORTANT: Do not change this list without review from a DOM peer!
1298
// IMPORTANT: Do not change this list without review from a DOM peer!
1299
    {name: "SyncManager", b2g: false},
1300
// IMPORTANT: Do not change this list without review from a DOM peer!
1299
    {name: "RequestSyncManager", b2g: true, permission: ["requestsync-manager"] },
1301
    {name: "RequestSyncManager", b2g: true, permission: ["requestsync-manager"] },
1300
// IMPORTANT: Do not change this list without review from a DOM peer!
1302
// IMPORTANT: Do not change this list without review from a DOM peer!
1301
    {name: "RequestSyncApp", b2g: true, permission: ["requestsync-manager"] },
1303
    {name: "RequestSyncApp", b2g: true, permission: ["requestsync-manager"] },
1302
// IMPORTANT: Do not change this list without review from a DOM peer!
1304
// IMPORTANT: Do not change this list without review from a DOM peer!
1303
    {name: "RequestSyncTask", b2g: true, permission: ["requestsync-manager"] },
1305
    {name: "RequestSyncTask", b2g: true, permission: ["requestsync-manager"] },
1304
// IMPORTANT: Do not change this list without review from a DOM peer!
1306
// IMPORTANT: Do not change this list without review from a DOM peer!
1305
    {name: "Telephony", b2g: true},
1307
    {name: "Telephony", b2g: true},
1306
// IMPORTANT: Do not change this list without review from a DOM peer!
1308
// IMPORTANT: Do not change this list without review from a DOM peer!
(-)a/dom/webidl/SyncManager.webidl (+17 lines)
Line     Link Here 
Line 0    Link Here 
1
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* This Source Code Form is subject to the terms of the Mozilla Public
3
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
4
* You can obtain one at http://mozilla.org/MPL/2.0/.
5
*
6
* The origin of this IDL file is
7
* https://wicg.github.io/BackgroundSync/spec/
8
*/
9
10
[Exposed=(Window,Worker),
11
 Func="mozilla::dom::SyncManager::PrefEnabled"]
12
interface SyncManager {
13
  [Throws]
14
  Promise<void> register(DOMString tag);
15
  [Throws]
16
  Promise<sequence<DOMString>> getTags();
17
};
(-)a/dom/webidl/moz.build (+1 lines)
Line     Link Here 
 Lines 531-546   WEBIDL_FILES = [ Link Here 
531
    'SVGTransformList.webidl',
531
    'SVGTransformList.webidl',
532
    'SVGTSpanElement.webidl',
532
    'SVGTSpanElement.webidl',
533
    'SVGUnitTypes.webidl',
533
    'SVGUnitTypes.webidl',
534
    'SVGURIReference.webidl',
534
    'SVGURIReference.webidl',
535
    'SVGUseElement.webidl',
535
    'SVGUseElement.webidl',
536
    'SVGViewElement.webidl',
536
    'SVGViewElement.webidl',
537
    'SVGZoomAndPan.webidl',
537
    'SVGZoomAndPan.webidl',
538
    'SVGZoomEvent.webidl',
538
    'SVGZoomEvent.webidl',
539
    'SyncManager.webidl',
539
    'SystemUpdate.webidl',
540
    'SystemUpdate.webidl',
540
    'TCPServerSocket.webidl',
541
    'TCPServerSocket.webidl',
541
    'TCPServerSocketEvent.webidl',
542
    'TCPServerSocketEvent.webidl',
542
    'TCPSocket.webidl',
543
    'TCPSocket.webidl',
543
    'TCPSocketErrorEvent.webidl',
544
    'TCPSocketErrorEvent.webidl',
544
    'TCPSocketEvent.webidl',
545
    'TCPSocketEvent.webidl',
545
    'Telephony.webidl',
546
    'Telephony.webidl',
546
    'TelephonyCall.webidl',
547
    'TelephonyCall.webidl',
(-)a/dom/workers/WorkerPrefs.h (+1 lines)
Line     Link Here 
 Lines 30-45   WORKER_SIMPLE_PREF("dom.performance.enab Link Here 
30
WORKER_SIMPLE_PREF("dom.webnotifications.enabled", DOMWorkerNotificationEnabled, DOM_WORKERNOTIFICATION)
30
WORKER_SIMPLE_PREF("dom.webnotifications.enabled", DOMWorkerNotificationEnabled, DOM_WORKERNOTIFICATION)
31
WORKER_SIMPLE_PREF("dom.webnotifications.serviceworker.enabled", DOMServiceWorkerNotificationEnabled, DOM_SERVICEWORKERNOTIFICATION)
31
WORKER_SIMPLE_PREF("dom.webnotifications.serviceworker.enabled", DOMServiceWorkerNotificationEnabled, DOM_SERVICEWORKERNOTIFICATION)
32
WORKER_SIMPLE_PREF("dom.serviceWorkers.enabled", ServiceWorkersEnabled, SERVICEWORKERS_ENABLED)
32
WORKER_SIMPLE_PREF("dom.serviceWorkers.enabled", ServiceWorkersEnabled, SERVICEWORKERS_ENABLED)
33
WORKER_SIMPLE_PREF("dom.serviceWorkers.testing.enabled", ServiceWorkersTestingEnabled, SERVICEWORKERS_TESTING_ENABLED)
33
WORKER_SIMPLE_PREF("dom.serviceWorkers.testing.enabled", ServiceWorkersTestingEnabled, SERVICEWORKERS_TESTING_ENABLED)
34
WORKER_SIMPLE_PREF("dom.serviceWorkers.interception.enabled", InterceptionEnabled, INTERCEPTION_ENABLED)
34
WORKER_SIMPLE_PREF("dom.serviceWorkers.interception.enabled", InterceptionEnabled, INTERCEPTION_ENABLED)
35
WORKER_SIMPLE_PREF("dom.serviceWorkers.interception.opaque.enabled", OpaqueInterceptionEnabled, INTERCEPTION_OPAQUE_ENABLED)
35
WORKER_SIMPLE_PREF("dom.serviceWorkers.interception.opaque.enabled", OpaqueInterceptionEnabled, INTERCEPTION_OPAQUE_ENABLED)
36
WORKER_SIMPLE_PREF("dom.serviceWorkers.openWindow.enabled", OpenWindowEnabled, OPEN_WINDOW_ENABLED)
36
WORKER_SIMPLE_PREF("dom.serviceWorkers.openWindow.enabled", OpenWindowEnabled, OPEN_WINDOW_ENABLED)
37
WORKER_SIMPLE_PREF("dom.push.enabled", PushEnabled, PUSH_ENABLED)
37
WORKER_SIMPLE_PREF("dom.push.enabled", PushEnabled, PUSH_ENABLED)
38
WORKER_SIMPLE_PREF("dom.background.sync.enabled", BackgroundSyncEnabled, BACKGROUND_SYNC_ENABLED)
38
WORKER_SIMPLE_PREF("dom.requestcache.enabled", RequestCacheEnabled, REQUESTCACHE_ENABLED)
39
WORKER_SIMPLE_PREF("dom.requestcache.enabled", RequestCacheEnabled, REQUESTCACHE_ENABLED)
39
WORKER_SIMPLE_PREF("dom.requestcontext.enabled", RequestContextEnabled, REQUESTCONTEXT_ENABLED)
40
WORKER_SIMPLE_PREF("dom.requestcontext.enabled", RequestContextEnabled, REQUESTCONTEXT_ENABLED)
40
WORKER_SIMPLE_PREF("gfx.offscreencanvas.enabled", OffscreenCanvasEnabled, OFFSCREENCANVAS_ENABLED)
41
WORKER_SIMPLE_PREF("gfx.offscreencanvas.enabled", OffscreenCanvasEnabled, OFFSCREENCANVAS_ENABLED)
41
WORKER_PREF("dom.workers.latestJSVersion", JSVersionChanged)
42
WORKER_PREF("dom.workers.latestJSVersion", JSVersionChanged)
42
WORKER_PREF("intl.accept_languages", PrefLanguagesChanged)
43
WORKER_PREF("intl.accept_languages", PrefLanguagesChanged)
43
WORKER_PREF("general.appname.override", AppNameOverrideChanged)
44
WORKER_PREF("general.appname.override", AppNameOverrideChanged)
44
WORKER_PREF("general.appversion.override", AppVersionOverrideChanged)
45
WORKER_PREF("general.appversion.override", AppVersionOverrideChanged)
45
WORKER_PREF("general.platform.override", PlatformOverrideChanged)
46
WORKER_PREF("general.platform.override", PlatformOverrideChanged)

Return to bug 1217544