diff --git a/dom/base/nsGlobalWindowInner.cpp b/dom/base/nsGlobalWindowInner.cpp index 78537b1a27d0..231176d540f4 100644 --- a/dom/base/nsGlobalWindowInner.cpp +++ b/dom/base/nsGlobalWindowInner.cpp @@ -1750,8 +1750,32 @@ nsGlobalWindowInner::EnsureClientSource() 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 loadInfo; nsCOMPtr channel = mDoc->GetChannel(); - nsCOMPtr loadInfo = channel ? channel->GetLoadInfo() : nullptr; + if (channel) { + nsCOMPtr 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.