Bug 1426979 P1 Ignore about:blank and about:srcdoc channels when determining if a window ClientSource is controlled or not. r=asuth
authorBen Kelly <ben@wanderview.com>
Wed, 10 Jan 2018 13:59:29 -0500
changeset 398556 1e1991807b395b83e2e1e7b1eb67ce00c479da2e
parent 398555 d055b4f81d592ee54a6593d09d928c28901b689d
child 398557 a4c611046a0c977a82d0797af446a1b2fca2ee7a
push id98787
push userbkelly@mozilla.com
push dateWed, 10 Jan 2018 18:59:37 +0000
treeherdermozilla-inbound@a4c611046a0c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersasuth
bugs1426979
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 1426979 P1 Ignore about:blank and about:srcdoc channels when determining if a window ClientSource is controlled or not. r=asuth
dom/base/nsGlobalWindowInner.cpp
--- a/dom/base/nsGlobalWindowInner.cpp
+++ b/dom/base/nsGlobalWindowInner.cpp
@@ -1745,18 +1745,42 @@ nsGlobalWindowInner::InnerSetNewDocument
 
 nsresult
 nsGlobalWindowInner::EnsureClientSource()
 {
   MOZ_DIAGNOSTIC_ASSERT(mDoc);
 
   bool newClientSource = false;
 
+  // Get the load info for the document if we performed a load.  Be careful
+  // not to look at about:blank or about:srcdoc loads, though. They will have
+  // a channel and loadinfo, but their loadinfo will never be controlled.  This
+  // would in turn inadvertantly trigger the logic below to clear the inherited
+  // controller.
+  nsCOMPtr<nsILoadInfo> loadInfo;
   nsCOMPtr<nsIChannel> channel = mDoc->GetChannel();
-  nsCOMPtr<nsILoadInfo> loadInfo = channel ? channel->GetLoadInfo() : nullptr;
+  if (channel) {
+    nsCOMPtr<nsIURI> uri;
+    Unused << channel->GetURI(getter_AddRefs(uri));
+
+    bool ignoreLoadInfo = false;
+
+    // Note, this is mostly copied from NS_IsAboutBlank().  Its duplicated
+    // here so we can efficiently check about:srcdoc as well.
+    bool isAbout = false;
+    if (NS_SUCCEEDED(uri->SchemeIs("about", &isAbout)) && isAbout) {
+      nsCString spec = uri->GetSpecOrDefault();
+      ignoreLoadInfo = spec.EqualsLiteral("about:blank") ||
+                       spec.EqualsLiteral("about:srcdoc");
+    }
+
+    if (!ignoreLoadInfo) {
+      loadInfo = channel->GetLoadInfo();
+    }
+  }
 
   // Take the initial client source from the docshell immediately.  Even if we
   // don't end up using it here we should consume it.
   UniquePtr<ClientSource> initialClientSource;
   nsIDocShell* docshell = GetDocShell();
   if (docshell) {
     initialClientSource = docshell->TakeInitialClientSource();
   }