Bug 1425965 P3 Make ServiceWorkerManager::FlushReportsToAllClients() use FlushReportsToConsoleForServiceWorkerScope(). r=asuth
authorBen Kelly <ben@wanderview.com>
Fri, 12 Jan 2018 12:16:04 -0500
changeset 453354 79280bcea4451e8f64d329f6ee3c46bc1321dff9
parent 453353 57b875846062f8dcb318f9edfc7d2d3a5321e7fe
child 453355 4027039552fea211647109c3d45b4215d759bd52
push id1648
push usermtabara@mozilla.com
push dateThu, 01 Mar 2018 12:45:47 +0000
treeherdermozilla-release@cbb9688c2eeb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersasuth
bugs1425965
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 1425965 P3 Make ServiceWorkerManager::FlushReportsToAllClients() use FlushReportsToConsoleForServiceWorkerScope(). r=asuth
dom/fetch/Fetch.cpp
dom/fetch/FetchConsumer.cpp
dom/workers/ServiceWorkerManager.cpp
dom/workers/ServiceWorkerManager.h
--- a/dom/fetch/Fetch.cpp
+++ b/dom/fetch/Fetch.cpp
@@ -33,17 +33,16 @@
 #include "mozilla/dom/Headers.h"
 #include "mozilla/dom/MutableBlobStreamListener.h"
 #include "mozilla/dom/Promise.h"
 #include "mozilla/dom/PromiseWorkerProxy.h"
 #include "mozilla/dom/Request.h"
 #include "mozilla/dom/Response.h"
 #include "mozilla/dom/ScriptSettings.h"
 #include "mozilla/dom/URLSearchParams.h"
-#include "mozilla/dom/workers/ServiceWorkerManager.h"
 #include "mozilla/Telemetry.h"
 
 #include "BodyExtractor.h"
 #include "FetchObserver.h"
 #include "InternalRequest.h"
 #include "InternalResponse.h"
 
 #include "WorkerPrivate.h"
@@ -861,23 +860,17 @@ WorkerFetchResolver::FlushConsoleReport(
   workers::WorkerPrivate* worker = mPromiseProxy->GetWorkerPrivate();
   if (!worker) {
     mReporter->FlushReportsToConsole(0);
     return;
   }
 
   if (worker->IsServiceWorker()) {
     // Flush to service worker
-    RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
-    if (!swm) {
-      mReporter->FlushReportsToConsole(0);
-      return;
-    }
-
-    swm->FlushReportsToAllClients(worker->ServiceWorkerScope(), mReporter);
+    mReporter->FlushReportsToConsoleForServiceWorkerScope(worker->ServiceWorkerScope());
     return;
   }
 
   if (worker->IsSharedWorker()) {
     // Flush to shared worker
     worker->FlushReportsToSharedWorkers(mReporter);
     return;
   }
--- a/dom/fetch/FetchConsumer.cpp
+++ b/dom/fetch/FetchConsumer.cpp
@@ -2,16 +2,17 @@
 /* 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 "Fetch.h"
 #include "FetchConsumer.h"
 
+#include "mozilla/ipc/PBackgroundSharedTypes.h"
 #include "nsIInputStreamPump.h"
 #include "nsProxyRelease.h"
 #include "WorkerPrivate.h"
 #include "WorkerRunnable.h"
 #include "WorkerScope.h"
 #include "Workers.h"
 
 namespace mozilla {
--- a/dom/workers/ServiceWorkerManager.cpp
+++ b/dom/workers/ServiceWorkerManager.cpp
@@ -1761,108 +1761,16 @@ ServiceWorkerManager::LocalizeAndReportT
                             aFilename, aLine, aLineNumber, aColumnNumber,
                             aFlags);
   } else {
     NS_WARNING("Failed to format and therefore report localized error.");
   }
 }
 
 void
-ServiceWorkerManager::FlushReportsToAllClients(const nsACString& aScope,
-                                               nsIConsoleReportCollector* aReporter)
-{
-  AutoTArray<uint64_t, 16> windows;
-
-  // Report errors to every controlled document.
-  for (auto iter = mControlledDocuments.Iter(); !iter.Done(); iter.Next()) {
-    ServiceWorkerRegistrationInfo* reg = iter.UserData();
-    MOZ_ASSERT(reg);
-    if (!reg->mScope.Equals(aScope)) {
-      continue;
-    }
-
-    nsCOMPtr<nsIDocument> doc = do_QueryInterface(iter.Key());
-    if (!doc || !doc->IsCurrentActiveDocument() || !doc->GetWindow()) {
-      continue;
-    }
-
-    uint64_t innerWindowId = doc->InnerWindowID();
-    windows.AppendElement(innerWindowId);
-
-    aReporter->FlushReportsToConsole(
-      innerWindowId, nsIConsoleReportCollector::ReportAction::Save);
-  }
-
-  // Report to any documents that have called .register() for this scope.  They
-  // may not be controlled, but will still want to see error reports.
-  WeakDocumentList* regList = mRegisteringDocuments.Get(aScope);
-  if (regList) {
-    for (int32_t i = regList->Length() - 1; i >= 0; --i) {
-      nsCOMPtr<nsIDocument> doc = do_QueryReferent(regList->ElementAt(i));
-      if (!doc) {
-        regList->RemoveElementAt(i);
-        continue;
-      }
-
-      if (!doc->IsCurrentActiveDocument()) {
-        continue;
-      }
-
-      uint64_t innerWindowId = doc->InnerWindowID();
-      if (windows.Contains(innerWindowId)) {
-        continue;
-      }
-
-      windows.AppendElement(innerWindowId);
-
-      aReporter->FlushReportsToConsole(
-        innerWindowId, nsIConsoleReportCollector::ReportAction::Save);
-    }
-
-    if (regList->IsEmpty()) {
-      regList = nullptr;
-      mRegisteringDocuments.Remove(aScope);
-    }
-  }
-
-  nsresult rv;
-  InterceptionList* intList = mNavigationInterceptions.Get(aScope);
-  if (intList) {
-    for (uint32_t i = 0; i < intList->Length(); ++i) {
-      nsCOMPtr<nsIInterceptedChannel> channel = intList->ElementAt(i);
-
-      nsCOMPtr<nsIChannel> inner;
-      rv = channel->GetChannel(getter_AddRefs(inner));
-      if (NS_WARN_IF(NS_FAILED(rv))) {
-        continue;
-      }
-
-      uint64_t innerWindowId = nsContentUtils::GetInnerWindowID(inner);
-      if (innerWindowId == 0 || windows.Contains(innerWindowId)) {
-        continue;
-      }
-
-      windows.AppendElement(innerWindowId);
-
-      aReporter->FlushReportsToConsole(
-        innerWindowId, nsIConsoleReportCollector::ReportAction::Save);
-    }
-  }
-
-  // If there are no documents to report to, at least report something to the
-  // browser console.
-  if (windows.IsEmpty()) {
-    aReporter->FlushReportsToConsole(0);
-    return;
-  }
-
-  aReporter->ClearConsoleReports();
-}
-
-void
 ServiceWorkerManager::HandleError(JSContext* aCx,
                                   nsIPrincipal* aPrincipal,
                                   const nsCString& aScope,
                                   const nsString& aWorkerURL,
                                   const nsString& aMessage,
                                   const nsString& aFilename,
                                   const nsString& aLine,
                                   uint32_t aLineNumber,
--- a/dom/workers/ServiceWorkerManager.h
+++ b/dom/workers/ServiceWorkerManager.h
@@ -260,20 +260,16 @@ public:
                                 const char* aStringKey,
                                 const nsTArray<nsString>& aParamArray,
                                 uint32_t aFlags = 0x0,
                                 const nsString& aFilename = EmptyString(),
                                 const nsString& aLine = EmptyString(),
                                 uint32_t aLineNumber = 0,
                                 uint32_t aColumnNumber = 0);
 
-  void
-  FlushReportsToAllClients(const nsACString& aScope,
-                           nsIConsoleReportCollector* aReporter);
-
   // Always consumes the error by reporting to consoles of all controlled
   // documents.
   void
   HandleError(JSContext* aCx,
               nsIPrincipal* aPrincipal,
               const nsCString& aScope,
               const nsString& aWorkerURL,
               const nsString& aMessage,