Bug 1375573 - Part 2: Avoid creating an about:blank document in setupJSON() by creating a Window binding through exposing a getter for the inner window ID on nsIWebProgress; r=billm
authorEhsan Akhgari <ehsan@mozilla.com>
Tue, 27 Jun 2017 15:40:33 -0400
changeset 366600 dc98dc9e0725161322496bd009da8687af4df3d3
parent 366599 a872b197585ae9bd09e3bb51b93a95ff27491776
child 366601 e929b33e751168ed07317c0befb420176efeb3cf
push id32105
push usercbook@mozilla.com
push dateThu, 29 Jun 2017 13:47:53 +0000
treeherdermozilla-central@08465078f3c2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbillm
bugs1375573
milestone56.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 1375573 - Part 2: Avoid creating an about:blank document in setupJSON() by creating a Window binding through exposing a getter for the inner window ID on nsIWebProgress; r=billm
toolkit/components/statusfilter/nsBrowserStatusFilter.cpp
toolkit/content/browser-child.js
uriloader/base/nsDocLoader.cpp
uriloader/base/nsIWebProgress.idl
--- a/toolkit/components/statusfilter/nsBrowserStatusFilter.cpp
+++ b/toolkit/components/statusfilter/nsBrowserStatusFilter.cpp
@@ -77,16 +77,24 @@ NS_IMETHODIMP
 nsBrowserStatusFilter::GetDOMWindowID(uint64_t *aResult)
 {
     *aResult = 0;
     NS_NOTREACHED("nsBrowserStatusFilter::GetDOMWindowID");
     return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 NS_IMETHODIMP
+nsBrowserStatusFilter::GetInnerDOMWindowID(uint64_t *aResult)
+{
+    *aResult = 0;
+    NS_NOTREACHED("nsBrowserStatusFilter::GetInnerDOMWindowID");
+    return NS_ERROR_NOT_IMPLEMENTED;
+}
+
+NS_IMETHODIMP
 nsBrowserStatusFilter::GetIsTopLevel(bool *aIsTopLevel)
 {
     *aIsTopLevel = false;
     NS_NOTREACHED("nsBrowserStatusFilter::GetIsTopLevel");
     return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 NS_IMETHODIMP
--- a/toolkit/content/browser-child.js
+++ b/toolkit/content/browser-child.js
@@ -67,25 +67,22 @@ var WebProgressListener = {
     } else {
       contentDocument = content.document;
     }
 
     let innerWindowID = null;
     if (aWebProgress) {
       let domWindowID = null;
       try {
-        let utils = aWebProgress.DOMWindow.QueryInterface(Ci.nsIInterfaceRequestor)
-                                .getInterface(Ci.nsIDOMWindowUtils);
-        domWindowID = utils.outerWindowID;
-        innerWindowID = utils.currentInnerWindowID;
+        domWindowID = aWebProgress.DOMWindowID;
+        innerWindowID = aWebProgress.innerDOMWindowID;
       } catch (e) {
-        // If nsDocShell::Destroy has already been called, then we'll
-        // get NS_NOINTERFACE when trying to get the DOM window.
-        // If there is no current inner window, we'll get
-        // NS_ERROR_NOT_AVAILABLE.
+        // The DOM Window ID getters above may throw if the inner or outer
+        // windows aren't created yet or are destroyed at the time we're making
+        // this call but that isn't fatal so ignore the exceptions here.
       }
 
       aWebProgress = {
         isTopLevel: aWebProgress.isTopLevel,
         isLoadingDocument: aWebProgress.isLoadingDocument,
         loadType: aWebProgress.loadType,
         DOMWindowID: domWindowID
       };
--- a/uriloader/base/nsDocLoader.cpp
+++ b/uriloader/base/nsDocLoader.cpp
@@ -919,16 +919,39 @@ nsDocLoader::GetDOMWindowID(uint64_t *aR
   NS_ENSURE_STATE(piwindow);
 
   MOZ_ASSERT(piwindow->IsOuterWindow());
   *aResult = piwindow->WindowID();
   return NS_OK;
 }
 
 NS_IMETHODIMP
+nsDocLoader::GetInnerDOMWindowID(uint64_t *aResult)
+{
+  *aResult = 0;
+
+  nsCOMPtr<mozIDOMWindowProxy> window;
+  nsresult rv = GetDOMWindow(getter_AddRefs(window));
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  nsCOMPtr<nsPIDOMWindowOuter> outer = nsPIDOMWindowOuter::From(window);
+  NS_ENSURE_STATE(outer);
+
+  nsPIDOMWindowInner* inner = outer->GetCurrentInnerWindow();
+  if (!inner) {
+    // If we don't have an inner window, return 0.
+    return NS_OK;
+  }
+
+  MOZ_ASSERT(inner->IsInnerWindow());
+  *aResult = inner->WindowID();
+  return NS_OK;
+}
+
+NS_IMETHODIMP
 nsDocLoader::GetIsTopLevel(bool *aResult)
 {
   *aResult = false;
 
   nsCOMPtr<mozIDOMWindowProxy> window;
   GetDOMWindow(getter_AddRefs(window));
   if (window) {
     nsCOMPtr<nsPIDOMWindowOuter> piwindow = nsPIDOMWindowOuter::From(window);
--- a/uriloader/base/nsIWebProgress.idl
+++ b/uriloader/base/nsIWebProgress.idl
@@ -128,16 +128,17 @@ interface nsIWebProgress : nsISupports
   /**
    * The DOM window associated with this nsIWebProgress instance.
    *
    * @throw NS_ERROR_FAILURE
    *        Indicates that there is no associated DOM window.
    */
   readonly attribute mozIDOMWindowProxy DOMWindow;
   readonly attribute uint64_t DOMWindowID;
+  readonly attribute uint64_t innerDOMWindowID;
 
   /**
    * Indicates whether DOMWindow.top == DOMWindow.
    */
   readonly attribute boolean isTopLevel;
 
   /**
    * Indicates whether or not a document is currently being loaded