Bug 1508595 - Only set an intercept controller when needed. r=asuth
authorBlake Kaplan <mrbkap@gmail.com>
Wed, 21 Nov 2018 01:06:08 +0000
changeset 447499 8b5e464db40282e66a94eeca41443eaa52d37420
parent 447498 01b3cf972555b90dd9da907b48cc6ff99212e452
child 447500 d71137840bd8ccc0a656ab8719289a29e5449d61
push id35081
push userccoroiu@mozilla.com
push dateWed, 21 Nov 2018 21:41:51 +0000
treeherdermozilla-central@e52cc9776809 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersasuth
bugs1508595
milestone65.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 1508595 - Only set an intercept controller when needed. r=asuth We only need to expose an intercept controller in SharedWorkers if we're on the non-parent-intercept version of ServiceWorkers or if e10s is off. nsDocShell already does this dance and we have to mirror it. Differential Revision: https://phabricator.services.mozilla.com/D12490
docshell/base/nsDocShell.cpp
dom/workers/remoteworkers/RemoteWorkerChild.cpp
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -475,16 +475,18 @@ nsDocShell::Create(BrowsingContext* aBro
   rv = ds->mContentListener->Init();
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return nullptr;
   }
 
   // If parent intercept is not enabled then we must forward to
   // the network controller from docshell.  We also enable if we're
   // in the parent process in order to support non-e10s configurations.
+  // Note: This check is duplicated in SharedWorkerInterfaceRequestor's
+  // constructor.
   if (!ServiceWorkerParentInterceptEnabled() || XRE_IsParentProcess()) {
     ds->mInterceptController = new ServiceWorkerInterceptController();
   }
 
   // We want to hold a strong ref to the loadgroup, so it better hold a weak
   // ref to us...  use an InterfaceRequestorProxy to do this.
   nsCOMPtr<nsIInterfaceRequestor> proxy = new InterfaceRequestorProxy(ds);
   ds->mLoadGroup->SetNotificationCallbacks(proxy);
--- a/dom/workers/remoteworkers/RemoteWorkerChild.cpp
+++ b/dom/workers/remoteworkers/RemoteWorkerChild.cpp
@@ -5,16 +5,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "RemoteWorkerChild.h"
 #include "RemoteWorkerService.h"
 #include "mozilla/dom/IndexedDatabaseManager.h"
 #include "mozilla/dom/MessagePort.h"
 #include "mozilla/dom/RemoteWorkerTypes.h"
 #include "mozilla/dom/ServiceWorkerInterceptController.h"
+#include "mozilla/dom/ServiceWorkerUtils.h"
 #include "mozilla/dom/workerinternals/ScriptLoader.h"
 #include "mozilla/dom/WorkerError.h"
 #include "mozilla/dom/WorkerPrivate.h"
 #include "mozilla/dom/WorkerRef.h"
 #include "mozilla/dom/WorkerRunnable.h"
 #include "mozilla/ipc/BackgroundUtils.h"
 #include "mozilla/ipc/URIUtils.h"
 #include "nsIConsoleReportCollector.h"
@@ -82,25 +83,29 @@ PopulatePrincipalContentSecurityPolicy(n
 }
 
 class SharedWorkerInterfaceRequestor final : public nsIInterfaceRequestor
 {
 public:
   NS_DECL_ISUPPORTS
 
   SharedWorkerInterfaceRequestor()
-    : mSWController(new ServiceWorkerInterceptController())
-  {}
+  {
+    // This check must match the code nsDocShell::Create.
+    if (!ServiceWorkerParentInterceptEnabled() || XRE_IsParentProcess()) {
+      mSWController = new ServiceWorkerInterceptController();
+    }
+  }
 
   NS_IMETHOD
   GetInterface(const nsIID& aIID, void** aSink) override
   {
     MOZ_ASSERT(NS_IsMainThread());
 
-    if (aIID.Equals(NS_GET_IID(nsINetworkInterceptController))) {
+    if (mSWController && aIID.Equals(NS_GET_IID(nsINetworkInterceptController))) {
       // If asked for the network intercept controller, ask the outer requestor,
       // which could be the docshell.
       RefPtr<ServiceWorkerInterceptController> swController = mSWController;
       swController.forget(aSink);
       return NS_OK;
     }
 
     return NS_NOINTERFACE;