Backed out changeset f75d3d084662 (bug 1593969) for causing toolchain bustages in /builds/worker/workspace/build/src/dom/base/nsWindowMemoryReporter.cpp CLOSED TREE
authorshindli <shindli@mozilla.com>
Mon, 18 Nov 2019 19:03:51 +0200
changeset 502440 c0b01b965387f871cea0a5fd9eebad0e848d7162
parent 502439 c62f8fbfd80a45b73a53b78fc2a41178d53dbdda
child 502441 65d5310bd0be5f1865f3d33fd363ded4d150a361
push id114172
push userdluca@mozilla.com
push dateTue, 19 Nov 2019 11:31:10 +0000
treeherdermozilla-inbound@b5c5ba07d3db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1593969
milestone72.0a1
backs outf75d3d0846627e3d47efad9e61701f41491fa4be
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
Backed out changeset f75d3d084662 (bug 1593969) for causing toolchain bustages in /builds/worker/workspace/build/src/dom/base/nsWindowMemoryReporter.cpp CLOSED TREE
dom/base/nsWindowMemoryReporter.cpp
--- a/dom/base/nsWindowMemoryReporter.cpp
+++ b/dom/base/nsWindowMemoryReporter.cpp
@@ -111,70 +111,74 @@ void nsWindowMemoryReporter::Init() {
   RegisterGhostWindowsDistinguishedAmount(GhostWindowsDistinguishedAmount);
 }
 
 /* static */
 nsWindowMemoryReporter* nsWindowMemoryReporter::Get() {
   return sWindowReporter;
 }
 
-static nsCString GetWindowURISpec(nsGlobalWindowInner* aWindow) {
-  NS_ENSURE_TRUE(aWindow, NS_LITERAL_CSTRING(""));
+static already_AddRefed<nsIURI> GetWindowURI(nsGlobalWindowInner* aWindow) {
+  NS_ENSURE_TRUE(aWindow, nullptr);
 
   nsCOMPtr<Document> doc = aWindow->GetExtantDoc();
+  nsCOMPtr<nsIURI> uri;
+
   if (doc) {
-    nsCOMPtr<nsIURI> uri;
     uri = doc->GetDocumentURI();
-    return uri->GetSpecOrDefault();
   }
-  nsCOMPtr<nsIScriptObjectPrincipal> scriptObjPrincipal =
-      do_QueryObject(aWindow);
-  NS_ENSURE_TRUE(scriptObjPrincipal, NS_LITERAL_CSTRING(""));
+
+  if (!uri) {
+    nsCOMPtr<nsIScriptObjectPrincipal> scriptObjPrincipal =
+        do_QueryObject(aWindow);
+    NS_ENSURE_TRUE(scriptObjPrincipal, nullptr);
 
-  // GetPrincipal() will print a warning if the window does not have an outer
-  // window, so check here for an outer window first.  This code is
-  // functionally correct if we leave out the GetOuterWindow() check, but we
-  // end up printing a lot of warnings during debug mochitests.
-  if (!aWindow->GetOuterWindow()) {
-    return NS_LITERAL_CSTRING("");
+    // GetPrincipal() will print a warning if the window does not have an outer
+    // window, so check here for an outer window first.  This code is
+    // functionally correct if we leave out the GetOuterWindow() check, but we
+    // end up printing a lot of warnings during debug mochitests.
+    if (aWindow->GetOuterWindow()) {
+      nsIPrincipal* principal = scriptObjPrincipal->GetPrincipal();
+      if (principal) {
+        principal->GetURI(getter_AddRefs(uri));
+      }
+    }
   }
-  nsIPrincipal* principal = scriptObjPrincipal->GetPrincipal();
-  if (!principal) {
-    return NS_LITERAL_CSTRING("");
-  }
-  nsCString spec;
-  principal->GetAsciiSpec(spec);
-  return spec;
+
+  return uri.forget();
 }
 
 // Forward to the inner window if we need to when getting the window's URI.
-static nsCString GetWindowURISpec(nsGlobalWindowOuter* aWindow) {
-  NS_ENSURE_TRUE(aWindow, NS_LITERAL_CSTRING(""));
-  return GetWindowURISpec(aWindow->GetCurrentInnerWindowInternal());
+static already_AddRefed<nsIURI> GetWindowURI(nsGlobalWindowOuter* aWindow) {
+  NS_ENSURE_TRUE(aWindow, nullptr);
+  return GetWindowURI(aWindow->GetCurrentInnerWindowInternal());
 }
 
 static void AppendWindowURI(nsGlobalWindowInner* aWindow, nsACString& aStr,
                             bool aAnonymize) {
-  nsCString spec = GetWindowURISpec(aWindow);
+  nsCOMPtr<nsIURI> uri = GetWindowURI(aWindow);
+
+  if (uri) {
+    if (aAnonymize && !aWindow->IsChromeWindow()) {
+      aStr.AppendPrintf("<anonymized-%" PRIu64 ">", aWindow->WindowID());
+    } else {
+      nsCString spec = uri->GetSpecOrDefault();
 
-  if (spec.IsEmpty()) {
+      // A hack: replace forward slashes with '\\' so they aren't
+      // treated as path separators.  Users of the reporters
+      // (such as about:memory) have to undo this change.
+      spec.ReplaceChar('/', '\\');
+
+      aStr += spec;
+    }
+  } else {
     // If we're unable to find a URI, we're dealing with a chrome window with
     // no document in it (or somesuch), so we call this a "system window".
     aStr += NS_LITERAL_CSTRING("[system]");
-    return;
   }
-  if (aAnonymize && !aWindow->IsChromeWindow()) {
-    aStr.AppendPrintf("<anonymized-%" PRIu64 ">", aWindow->WindowID());
-    return;
-  }
-  // A hack: replace forward slashes with '\\' so they aren't
-  // treated as path separators.  Users of the reporters
-  // (such as about:memory) have to undo this change.
-  spec.ReplaceChar('/', '\\');
-  aStr += spec;
 }
 
 MOZ_DEFINE_MALLOC_SIZE_OF(WindowsMallocSizeOf)
 
 // The key is the window ID.
 typedef nsDataHashtable<nsUint64HashKey, nsCString> WindowPaths;
 
 static void ReportAmount(const nsCString& aBasePath, const char* aPathTail,
@@ -218,21 +222,28 @@ static void CollectWindowReports(nsGloba
                                  WindowPaths* aTopWindowPaths,
                                  nsIHandleReportCallback* aHandleReport,
                                  nsISupports* aData, bool aAnonymize) {
   nsAutoCString windowPath("explicit/");
 
   // Avoid calling aWindow->GetInProcessTop() if there's no outer window.  It
   // will work just fine, but will spew a lot of warnings.
   nsGlobalWindowOuter* top = nullptr;
+  nsCOMPtr<nsIURI> location;
   if (aWindow->GetOuterWindow()) {
     // Our window should have a null top iff it has a null docshell.
     MOZ_ASSERT(!!aWindow->GetInProcessTopInternal() ==
                !!aWindow->GetDocShell());
     top = aWindow->GetInProcessTopInternal();
+    if (top) {
+      location = GetWindowURI(top);
+    }
+  }
+  if (!location) {
+    location = GetWindowURI(aWindow);
   }
 
   windowPath += NS_LITERAL_CSTRING("window-objects/");
 
   if (top) {
     windowPath += NS_LITERAL_CSTRING("top(");
     AppendWindowURI(top->GetCurrentInnerWindowInternal(), windowPath,
                     aAnonymize);