Bug 1419771 - Introduce DOMPreferences, a thread-safe access to preferences for DOM - part 8 - ServiceWorkers enabled, r=asuth
☠☠ backed out by ccd7b237c433 ☠ ☠
authorAndrea Marchesini <amarchesini@mozilla.com>
Wed, 13 Dec 2017 14:02:45 -0600
changeset 396298 d12dc55579820a2120cedfc390ba15f71d171ab0
parent 396297 6c863ab2e986f76bc8ab8fc5b41a49747f080265
child 396299 601b49f51b41ca478019cb28d9ac0c7f1c780f56
push id56975
push userdluca@mozilla.com
push dateThu, 14 Dec 2017 09:59:07 +0000
treeherderautoland@16bcfaad13e1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersasuth
bugs1419771
milestone59.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1419771 - Introduce DOMPreferences, a thread-safe access to preferences for DOM - part 8 - ServiceWorkers enabled, r=asuth
dom/base/DOMPreferences.cpp
dom/base/DOMPreferences.h
dom/ipc/TabContext.cpp
dom/webidl/ServiceWorkerRegistration.webidl
dom/workers/ServiceWorker.cpp
dom/workers/ServiceWorkerContainer.cpp
dom/workers/ServiceWorkerRegistration.cpp
dom/workers/ServiceWorkerRegistration.h
dom/workers/WorkerPrefs.h
--- a/dom/base/DOMPreferences.cpp
+++ b/dom/base/DOMPreferences.cpp
@@ -37,27 +37,29 @@ DOMPreferences::DumpEnabled()
 
 PREF(ImageBitmapExtensionsEnabled, "canvas.imagebitmap_extensions.enabled")
 PREF(DOMCachesEnabled, "dom.caches.enabled")
 PREF(DOMCachesTestingEnabled, "dom.caches.testing.enabled")
 PREF(PerformanceLoggingEnabled, "dom.performance.enable_user_timing_logging")
 PREF(NotificationEnabled, "dom.webnotifications.enabled")
 PREF(NotificationEnabledInServiceWorkers, "dom.webnotifications.serviceworker.enabled")
 PREF(NotificationRIEnabled, "dom.webnotifications.requireinteraction.enabled")
+PREF(ServiceWorkersEnabled, "dom.serviceWorkers.enabled")
 
 #undef PREF
 
 #define PREF_WEBIDL(name)                              \
   /* static */ bool                                    \
   DOMPreferences::name(JSContext* aCx, JSObject* aObj) \
   {                                                    \
     return DOMPreferences::name();                     \
   }
 
 PREF_WEBIDL(ImageBitmapExtensionsEnabled)
 PREF_WEBIDL(DOMCachesEnabled)
 PREF_WEBIDL(NotificationEnabledInServiceWorkers)
 PREF_WEBIDL(NotificationRIEnabled)
+PREF_WEBIDL(ServiceWorkersEnabled)
 
 #undef PREF_WEBIDL
 
 } // dom namespace
 } // mozilla namespace
--- a/dom/base/DOMPreferences.h
+++ b/dom/base/DOMPreferences.h
@@ -39,14 +39,18 @@ public:
   static bool NotificationEnabledInServiceWorkers();
   static bool NotificationEnabledInServiceWorkers(JSContext* aCx,
                                                   JSObject* aObj);
 
   // Returns true if the dom.webnotifications.requireinteraction.enabled pref is
   // set.
   static bool NotificationRIEnabled();
   static bool NotificationRIEnabled(JSContext* aCx, JSObject* aObj);
+
+  // Returns true if the dom.serviceWorkers.enabled pref is set.
+  static bool ServiceWorkersEnabled();
+  static bool ServiceWorkersEnabled(JSContext* aCx, JSObject* aObj);
 };
 
 } // dom namespace
 } // mozilla namespace
 
 #endif // mozilla_dom_DOMPreferences_h
--- a/dom/ipc/TabContext.cpp
+++ b/dom/ipc/TabContext.cpp
@@ -3,16 +3,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/dom/TabContext.h"
 #include "mozilla/dom/PTabContext.h"
 #include "mozilla/dom/TabParent.h"
 #include "mozilla/dom/TabChild.h"
+#include "mozilla/dom/DOMPreferences.h"
 #include "nsIScriptSecurityManager.h"
 #include "nsServiceManagerUtils.h"
 
 #define NO_APP_ID (nsIScriptSecurityManager::NO_APP_ID)
 
 using namespace mozilla::dom::ipc;
 using namespace mozilla::layout;
 
@@ -241,17 +242,17 @@ MaybeInvalidTabContext::MaybeInvalidTabC
       originAttributes = ipcContext.originAttributes();
       break;
     }
     case IPCTabContext::TUnsafeIPCTabContext: {
       // XXXcatalinb: This used *only* by ServiceWorkerClients::OpenWindow.
       // It is meant as a temporary solution until service workers can
       // provide a TabChild equivalent. Don't allow this on b2g since
       // it might be used to escalate privileges.
-      if (!Preferences::GetBool("dom.serviceWorkers.enabled", false)) {
+      if (!DOMPreferences::ServiceWorkersEnabled()) {
         mInvalidReason = "ServiceWorkers should be enabled.";
         return;
       }
 
       break;
     }
     default: {
       MOZ_CRASH();
--- a/dom/webidl/ServiceWorkerRegistration.webidl
+++ b/dom/webidl/ServiceWorkerRegistration.webidl
@@ -4,17 +4,17 @@
  * You can obtain one at http://mozilla.org/MPL/2.0/.
  *
  * The origin of this IDL file is
  * http://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html
  * https://w3c.github.io/push-api/
  * https://notifications.spec.whatwg.org/
  */
 
-[Func="mozilla::dom::ServiceWorkerRegistration::Visible",
+[Func="mozilla::dom::DOMPreferences::ServiceWorkersEnabled",
  Exposed=(Window,Worker)]
 interface ServiceWorkerRegistration : EventTarget {
   [Unforgeable] readonly attribute ServiceWorker? installing;
   [Unforgeable] readonly attribute ServiceWorker? waiting;
   [Unforgeable] readonly attribute ServiceWorker? active;
 
   readonly attribute USVString scope;
   [Throws]
--- a/dom/workers/ServiceWorker.cpp
+++ b/dom/workers/ServiceWorker.cpp
@@ -7,17 +7,17 @@
 #include "ServiceWorker.h"
 
 #include "nsIDocument.h"
 #include "nsPIDOMWindow.h"
 #include "ServiceWorkerManager.h"
 #include "ServiceWorkerPrivate.h"
 #include "WorkerPrivate.h"
 
-#include "mozilla/Preferences.h"
+#include "mozilla/dom/DOMPreferences.h"
 #include "mozilla/dom/ClientIPCTypes.h"
 #include "mozilla/dom/ClientState.h"
 #include "mozilla/dom/Promise.h"
 #include "mozilla/dom/ServiceWorkerGlobalScopeBinding.h"
 
 #ifdef XP_WIN
 #undef PostMessage
 #endif
@@ -28,17 +28,17 @@ using namespace mozilla::dom;
 namespace mozilla {
 namespace dom {
 namespace workers {
 
 bool
 ServiceWorkerVisible(JSContext* aCx, JSObject* aObj)
 {
   if (NS_IsMainThread()) {
-    return Preferences::GetBool("dom.serviceWorkers.enabled", false);
+    return DOMPreferences::ServiceWorkersEnabled();
   }
 
   return IS_INSTANCE_OF(ServiceWorkerGlobalScope, aObj);
 }
 
 ServiceWorker::ServiceWorker(nsPIDOMWindowInner* aWindow,
                              ServiceWorkerInfo* aInfo)
   : DOMEventTargetHelper(aWindow),
--- a/dom/workers/ServiceWorkerContainer.cpp
+++ b/dom/workers/ServiceWorkerContainer.cpp
@@ -7,22 +7,22 @@
 #include "ServiceWorkerContainer.h"
 
 #include "nsContentUtils.h"
 #include "nsIDocument.h"
 #include "nsIServiceWorkerManager.h"
 #include "nsIURL.h"
 #include "nsNetUtil.h"
 #include "nsPIDOMWindow.h"
-#include "mozilla/Preferences.h"
 #include "mozilla/Services.h"
 
 #include "nsCycleCollectionParticipant.h"
 #include "nsServiceManagerUtils.h"
 
+#include "mozilla/dom/DOMPreferences.h"
 #include "mozilla/dom/Navigator.h"
 #include "mozilla/dom/Promise.h"
 #include "mozilla/dom/ServiceWorkerContainerBinding.h"
 #include "mozilla/dom/workers/bindings/ServiceWorker.h"
 
 #include "ServiceWorker.h"
 
 namespace mozilla {
@@ -48,17 +48,17 @@ ServiceWorkerContainer::IsEnabled(JSCont
     return false;
   }
 
   nsIDocument* doc = window->GetExtantDoc();
   if (!doc || nsContentUtils::IsInPrivateBrowsing(doc)) {
     return false;
   }
 
-  return Preferences::GetBool("dom.serviceWorkers.enabled", false);
+  return DOMPreferences::ServiceWorkersEnabled();
 }
 
 ServiceWorkerContainer::ServiceWorkerContainer(nsPIDOMWindowInner* aWindow)
   : DOMEventTargetHelper(aWindow)
 {
 }
 
 ServiceWorkerContainer::~ServiceWorkerContainer()
--- a/dom/workers/ServiceWorkerRegistration.cpp
+++ b/dom/workers/ServiceWorkerRegistration.cpp
@@ -2,24 +2,24 @@
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "ServiceWorkerRegistration.h"
 
 #include "ipc/ErrorIPCUtils.h"
+#include "mozilla/dom/DOMPreferences.h"
 #include "mozilla/dom/Notification.h"
 #include "mozilla/dom/Promise.h"
 #include "mozilla/dom/PromiseWindowProxy.h"
 #include "mozilla/dom/PromiseWorkerProxy.h"
 #include "mozilla/dom/PushManagerBinding.h"
 #include "mozilla/dom/PushManager.h"
 #include "mozilla/dom/ServiceWorkerRegistrationBinding.h"
-#include "mozilla/Preferences.h"
 #include "mozilla/Services.h"
 #include "mozilla/Unused.h"
 #include "nsCycleCollectionParticipant.h"
 #include "nsNetUtil.h"
 #include "nsServiceManagerUtils.h"
 #include "ServiceWorker.h"
 #include "ServiceWorkerManager.h"
 
@@ -33,32 +33,16 @@
 #include "Workers.h"
 #include "WorkerScope.h"
 
 using namespace mozilla::dom::workers;
 
 namespace mozilla {
 namespace dom {
 
-/* static */ bool
-ServiceWorkerRegistration::Visible(JSContext* aCx, JSObject* aObj)
-{
-  if (NS_IsMainThread()) {
-    return Preferences::GetBool("dom.serviceWorkers.enabled", false);
-  }
-
-  // Otherwise check the pref via the work private helper
-  WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(aCx);
-  if (!workerPrivate) {
-    return false;
-  }
-
-  return workerPrivate->ServiceWorkersEnabled();
-}
-
 ////////////////////////////////////////////////////
 // Main Thread implementation
 
 class ServiceWorkerRegistrationMainThread final : public ServiceWorkerRegistration,
                                                   public ServiceWorkerRegistrationListener
 {
   friend nsPIDOMWindowInner;
 public:
--- a/dom/workers/ServiceWorkerRegistration.h
+++ b/dom/workers/ServiceWorkerRegistration.h
@@ -56,19 +56,16 @@ public:
 
 class ServiceWorkerRegistration : public DOMEventTargetHelper
 {
 public:
   NS_DECL_ISUPPORTS_INHERITED
 
   IMPL_EVENT_HANDLER(updatefound)
 
-  static bool
-  Visible(JSContext* aCx, JSObject* aObj);
-
   static already_AddRefed<ServiceWorkerRegistration>
   CreateForMainThread(nsPIDOMWindowInner* aWindow,
                       const nsAString& aScope);
 
   static already_AddRefed<ServiceWorkerRegistration>
   CreateForWorker(workers::WorkerPrivate* aWorkerPrivate,
                   const nsAString& aScope);
 
--- a/dom/workers/WorkerPrefs.h
+++ b/dom/workers/WorkerPrefs.h
@@ -16,17 +16,16 @@
 //     macro in Workers.h.
 //   * The name of the function that updates the new value of a pref.
 //
 //   WORKER_PREF("foo.bar", UpdaterFunction)
 //
 //   * First argument is the name of the pref.
 //   * The name of the function that updates the new value of a pref.
 
-WORKER_SIMPLE_PREF("dom.serviceWorkers.enabled", ServiceWorkersEnabled, SERVICEWORKERS_ENABLED)
 WORKER_SIMPLE_PREF("dom.serviceWorkers.testing.enabled", ServiceWorkersTestingEnabled, SERVICEWORKERS_TESTING_ENABLED)
 WORKER_SIMPLE_PREF("dom.storageManager.enabled", StorageManagerEnabled, STORAGEMANAGER_ENABLED)
 WORKER_SIMPLE_PREF("dom.promise_rejection_events.enabled", PromiseRejectionEventsEnabled, PROMISE_REJECTION_EVENTS_ENABLED)
 WORKER_SIMPLE_PREF("dom.push.enabled", PushEnabled, PUSH_ENABLED)
 WORKER_SIMPLE_PREF("dom.streams.enabled", StreamsEnabled, STREAMS_ENABLED)
 WORKER_SIMPLE_PREF("dom.requestcontext.enabled", RequestContextEnabled, REQUESTCONTEXT_ENABLED)
 WORKER_SIMPLE_PREF("gfx.offscreencanvas.enabled", OffscreenCanvasEnabled, OFFSCREENCANVAS_ENABLED)
 WORKER_SIMPLE_PREF("dom.webkitBlink.dirPicker.enabled", WebkitBlinkDirectoryPickerEnabled, DOM_WEBKITBLINK_DIRPICKER_WEBKITBLINK)