Bug 1496251 - Remove InternalLoad from nsIDocShell r=bzbarsky
authorKyle Machulis <kyle@nonpolynomial.com>
Wed, 19 Dec 2018 21:01:05 +0000
changeset 451398 eab2b1be4f3fc1eca0120080975365e1f72056eb
parent 451397 b77b6244ebc95356c4bb552ba4524531967f9838
child 451399 73ecece00c9c7261bbe72ebbb7f4232bf2cd2ec9
push id35237
push userrmaries@mozilla.com
push dateThu, 20 Dec 2018 04:52:39 +0000
treeherdermozilla-central@1260c07d4b17 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbzbarsky
bugs1496251
milestone66.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 1496251 - Remove InternalLoad from nsIDocShell r=bzbarsky We only call through the nsIDocShell interface in one place, which can be replaced with a cast to nsDocShell. Differential Revision: https://phabricator.services.mozilla.com/D13487
docshell/base/nsDocShell.cpp
docshell/base/nsDocShell.h
docshell/base/nsIDocShell.idl
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -8699,18 +8699,17 @@ class InternalLoadEvent : public Runnabl
  * mLoadType and mLSHE.  These are both set when the asynchronous load first
  * starts, and the load expects that, when it eventually runs InternalLoad,
  * mLoadType and mLSHE will have their original values.
  */
 bool nsDocShell::JustStartedNetworkLoad() {
   return mDocumentRequest && mDocumentRequest != GetCurrentDocChannel();
 }
 
-NS_IMETHODIMP
-nsDocShell::InternalLoad(
+nsresult nsDocShell::InternalLoad(
     nsIURI* aURI, nsIURI* aOriginalURI,
     Maybe<nsCOMPtr<nsIURI>> const& aResultPrincipalURI,
     bool aKeepResultPrincipalURIIfSet, bool aLoadReplace,
     bool aIsFromProcessingFrameAttributes, nsIURI* aReferrer,
     uint32_t aReferrerPolicy, nsIPrincipal* aTriggeringPrincipal,
     nsIPrincipal* aPrincipalToInherit, uint32_t aFlags,
     const nsAString& aWindowTarget, const nsACString& aTypeHint,
     const nsAString& aFileName, nsIInputStream* aPostData,
@@ -8880,19 +8879,19 @@ nsDocShell::InternalLoad(
       }
 
       return NS_ERROR_CONTENT_BLOCKED;
     }
   }
 
   nsCOMPtr<nsIPrincipal> principalToInherit = aPrincipalToInherit;
   //
-  // Get a principal from the current document if necessary.  Note that we only
-  // do this for URIs that inherit a security context and local file URIs;
-  // in particular we do NOT do this for about:blank.  This way, random
+  // Get a principal from the current document if necessary.  Note that we
+  // only do this for URIs that inherit a security context and local file
+  // URIs; in particular we do NOT do this for about:blank.  This way, random
   // about:blank loads that have no principal (which basically means they were
   // done by someone from chrome manually messing with our nsIWebNavigation
   // or by C++ setting document.location) don't get a funky principal.  If
   // callers want something interesting to happen with the about:blank
   // principal in this case, they should pass aPrincipalToInherit in.
   //
   {
     bool inherits;
@@ -8961,18 +8960,18 @@ nsDocShell::InternalLoad(
       nsCOMPtr<nsPIDOMWindowOuter> newWin;
       nsAutoCString spec;
       if (aURI) {
         aURI->GetSpec(spec);
       }
       // If we are a noopener load, we just hand the whole thing over to our
       // window.
       if (aFlags & INTERNAL_LOAD_FLAGS_NO_OPENER) {
-        // Various asserts that we know to hold because NO_OPENER loads can only
-        // happen for links.
+        // Various asserts that we know to hold because NO_OPENER loads can
+        // only happen for links.
         MOZ_ASSERT(!aLoadReplace);
         MOZ_ASSERT(aPrincipalToInherit == aTriggeringPrincipal);
         MOZ_ASSERT((aFlags & ~INTERNAL_LOAD_FLAGS_IS_USER_TRIGGERED) ==
                        INTERNAL_LOAD_FLAGS_NO_OPENER ||
                    (aFlags & ~INTERNAL_LOAD_FLAGS_IS_USER_TRIGGERED) ==
                        (INTERNAL_LOAD_FLAGS_NO_OPENER |
                         INTERNAL_LOAD_FLAGS_DONT_SEND_REFERRER));
         MOZ_ASSERT(!aPostData);
@@ -8981,32 +8980,32 @@ nsDocShell::InternalLoad(
         // type would be set to LOAD_NORMAL_REPLACE; otherwise it should be
         // LOAD_LINK.
         MOZ_ASSERT(aLoadType == LOAD_LINK || aLoadType == LOAD_NORMAL_REPLACE);
         MOZ_ASSERT(!aSHEntry);
         MOZ_ASSERT(aFirstParty);  // Windowwatcher will assume this.
 
         RefPtr<nsDocShellLoadState> loadState = new nsDocShellLoadState();
 
-        // Set up our loadinfo so it will do the load as much like we would have
-        // as possible.
+        // Set up our loadinfo so it will do the load as much like we would
+        // have as possible.
         loadState->SetReferrer(aReferrer);
         loadState->SetReferrerPolicy(
             (mozilla::net::ReferrerPolicy)aReferrerPolicy);
         loadState->SetSendReferrer(
             !(aFlags & INTERNAL_LOAD_FLAGS_DONT_SEND_REFERRER));
         loadState->SetOriginalURI(aOriginalURI);
         loadState->SetMaybeResultPrincipalURI(aResultPrincipalURI);
         loadState->SetKeepResultPrincipalURIIfSet(aKeepResultPrincipalURIIfSet);
         loadState->SetLoadReplace(aLoadReplace);
         loadState->SetTriggeringPrincipal(aTriggeringPrincipal);
         loadState->SetInheritPrincipal(aFlags &
                                        INTERNAL_LOAD_FLAGS_INHERIT_PRINCIPAL);
-        // Explicit principal because we do not want any guesses as to what the
-        // principal to inherit is: it should be aTriggeringPrincipal.
+        // Explicit principal because we do not want any guesses as to what
+        // the principal to inherit is: it should be aTriggeringPrincipal.
         loadState->SetPrincipalIsExplicit(true);
         loadState->SetLoadType(LOAD_LINK);
         loadState->SetForceAllowDataURI(
             aFlags & INTERNAL_LOAD_FLAGS_FORCE_ALLOW_DATA_URI);
 
         rv = win->Open(NS_ConvertUTF8toUTF16(spec),
                        aWindowTarget,  // window name
                        EmptyString(),  // Features
@@ -9038,17 +9037,18 @@ nsDocShell::InternalLoad(
       targetDocShell = do_QueryInterface(webNav);
     }
 
     //
     // Transfer the load to the target DocShell...  Pass nullptr as the
     // window target name from to prevent recursive retargeting!
     //
     if (NS_SUCCEEDED(rv) && targetDocShell) {
-      rv = targetDocShell->InternalLoad(
+      nsDocShell* docShell = nsDocShell::Cast(targetDocShell);
+      rv = docShell->InternalLoad(
           aURI, aOriginalURI, aResultPrincipalURI, aKeepResultPrincipalURIIfSet,
           aLoadReplace, aIsFromProcessingFrameAttributes, aReferrer,
           aReferrerPolicy, aTriggeringPrincipal, principalToInherit, aFlags,
           EmptyString(),  // No window target
           aTypeHint,
           VoidString(),  // No forced download
           aPostData, aHeadersData, aLoadType, aSHEntry, aFirstParty, aSrcdoc,
           aSourceDocShell, aBaseURI, aDocShell, aRequest);
@@ -9790,19 +9790,19 @@ nsresult nsDocShell::DoURILoad(
     nsIPrincipal* aTriggeringPrincipal, nsIPrincipal* aPrincipalToInherit,
     const nsACString& aTypeHint, const nsAString& aFileName,
     nsIInputStream* aPostData, nsIInputStream* aHeadersData, bool aFirstParty,
     nsIDocShell** aDocShell, nsIRequest** aRequest, bool aIsNewWindowTarget,
     bool aBypassClassifier, bool aForceAllowCookies, const nsAString& aSrcdoc,
     nsIURI* aBaseURI, nsContentPolicyType aContentPolicyType) {
   // Double-check that we're still around to load this URI.
   if (mIsBeingDestroyed) {
-    // Return NS_OK despite not doing anything to avoid throwing exceptions from
-    // nsLocation::SetHref if the unload handler of the existing page tears us
-    // down.
+    // Return NS_OK despite not doing anything to avoid throwing exceptions
+    // from nsLocation::SetHref if the unload handler of the existing page
+    // tears us down.
     return NS_OK;
   }
 
   nsresult rv;
   nsCOMPtr<nsIURILoader> uriLoader =
       do_GetService(NS_URI_LOADER_CONTRACTID, &rv);
   if (NS_FAILED(rv)) {
     return rv;
@@ -9848,18 +9848,18 @@ nsresult nsDocShell::DoURILoad(
   nsCOMPtr<nsIChannel> channel;
 
   bool isSrcdoc = !aSrcdoc.IsVoid();
 
   // There are two cases we care about:
   // * Top-level load: In this case, loadingNode is null, but loadingWindow
   //   is our mScriptGlobal. We pass null for loadingPrincipal in this case.
   // * Subframe load: loadingWindow is null, but loadingNode is the frame
-  //   element for the load. loadingPrincipal is the NodePrincipal of the frame
-  //   element.
+  //   element for the load. loadingPrincipal is the NodePrincipal of the
+  //   frame element.
   nsCOMPtr<nsINode> loadingNode;
   nsCOMPtr<nsPIDOMWindowOuter> loadingWindow;
   nsCOMPtr<nsIPrincipal> loadingPrincipal;
   nsCOMPtr<nsISupports> topLevelLoadingContext;
 
   if (aContentPolicyType == nsIContentPolicy::TYPE_DOCUMENT) {
     loadingNode = nullptr;
     loadingPrincipal = nullptr;
@@ -9972,18 +9972,18 @@ nsresult nsDocShell::DoURILoad(
   // OriginAttributes of the parent document. Or in case there isn't a
   // parent document.
   bool isTopLevelDoc = mItemType == typeContent &&
                        (aContentPolicyType == nsIContentPolicy::TYPE_DOCUMENT ||
                         GetIsMozBrowser());
 
   OriginAttributes attrs;
 
-  // Inherit origin attributes from aPrincipalToInherit if inheritAttrs is true.
-  // Otherwise we just use the origin attributes from docshell.
+  // Inherit origin attributes from aPrincipalToInherit if inheritAttrs is
+  // true. Otherwise we just use the origin attributes from docshell.
   if (inheritAttrs) {
     MOZ_ASSERT(aPrincipalToInherit, "We should have aPrincipalToInherit here.");
     attrs = aPrincipalToInherit->OriginAttributesRef();
     // If firstPartyIsolation is not enabled, then PrincipalToInherit should
     // have the same origin attributes with docshell.
     MOZ_ASSERT_IF(!OriginAttributes::IsFirstPartyEnabled(),
                   attrs == GetOriginAttributes());
   } else {
@@ -10434,18 +10434,19 @@ nsresult nsDocShell::DoChannelLoad(nsICh
 
     case LOAD_RELOAD_CHARSET_CHANGE_BYPASS_PROXY_AND_CACHE:
     case LOAD_RELOAD_CHARSET_CHANGE_BYPASS_CACHE:
       loadFlags |=
           nsIRequest::LOAD_BYPASS_CACHE | nsIRequest::LOAD_FRESH_CONNECTION;
       MOZ_FALLTHROUGH;
 
     case LOAD_RELOAD_CHARSET_CHANGE: {
-      // Use SetAllowStaleCacheContent (not LOAD_FROM_CACHE flag) since we only
-      // want to force cache load for this channel, not the whole loadGroup.
+      // Use SetAllowStaleCacheContent (not LOAD_FROM_CACHE flag) since we
+      // only want to force cache load for this channel, not the whole
+      // loadGroup.
       nsCOMPtr<nsICacheInfoChannel> cachingChannel =
           do_QueryInterface(aChannel);
       if (cachingChannel) {
         cachingChannel->SetAllowStaleCacheContent(true);
       }
       break;
     }
 
@@ -10826,18 +10827,18 @@ bool nsDocShell::OnNewURI(nsIURI* aURI, 
     }
 
     // Since we're force-reloading, clear all the sub frame history.
     ClearFrameHistory(mLSHE);
     ClearFrameHistory(mOSHE);
   }
 
   // Clear subframe history on refresh.
-  // XXX: history.go(0) won't go this path as aLoadType is LOAD_HISTORY in this
-  // case. One should re-validate after bug 1331865 fixed.
+  // XXX: history.go(0) won't go this path as aLoadType is LOAD_HISTORY in
+  // this case. One should re-validate after bug 1331865 fixed.
   if (aLoadType == LOAD_REFRESH) {
     ClearFrameHistory(mLSHE);
     ClearFrameHistory(mOSHE);
   }
 
   if (updateSHistory) {
     // Update session history if necessary...
     if (!mLSHE && (mItemType == typeContent) && mURIResultedInDocument) {
@@ -10860,19 +10861,20 @@ bool nsDocShell::OnNewURI(nsIURI* aURI, 
     mSessionHistory->LegacySHistory()->GetEntryAtIndex(
         index, getter_AddRefs(currentSH));
     if (currentSH != mLSHE) {
       mSessionHistory->LegacySHistory()->ReplaceEntry(index, mLSHE);
     }
   }
 
 #ifdef MOZ_GECKO_PROFILER
-  // We register the page load only if the load updates the history and it's not
-  // a refresh. This also registers the iframes in shift-reload case, but it's
-  // reasonable to register since we are updating the historyId in that case.
+  // We register the page load only if the load updates the history and it's
+  // not a refresh. This also registers the iframes in shift-reload case, but
+  // it's reasonable to register since we are updating the historyId in that
+  // case.
   if (updateSHistory) {
     uint32_t id = 0;
     nsAutoCString spec;
     if (mLSHE) {
       mLSHE->GetID(&id);
     }
     aURI->GetSpec(spec);
     profiler_register_page(mHistoryID, id, spec, IsFrame());
@@ -11703,18 +11705,18 @@ nsresult nsDocShell::PersistLayoutHistor
 
   if (mOSHE) {
     bool scrollRestorationIsManual = mOSHE->GetScrollRestorationIsManual();
     nsCOMPtr<nsIPresShell> shell = GetPresShell();
     nsCOMPtr<nsILayoutHistoryState> layoutState;
     if (shell) {
       rv = shell->CaptureHistoryState(getter_AddRefs(layoutState));
     } else if (scrollRestorationIsManual) {
-      // Even if we don't have layout anymore, we may want to reset the current
-      // scroll state in layout history.
+      // Even if we don't have layout anymore, we may want to reset the
+      // current scroll state in layout history.
       GetLayoutHistoryState(getter_AddRefs(layoutState));
     }
 
     if (scrollRestorationIsManual && layoutState) {
       layoutState->ResetScrollState();
     }
   }
 
@@ -12498,21 +12500,22 @@ class OnLinkClickEvent : public Runnable
                    nsIInputStream* aPostDataStream,
                    nsIInputStream* aHeadersDataStream, bool aNoOpenerImplied,
                    bool aIsUserTriggered, bool aIsTrusted,
                    nsIPrincipal* aTriggeringPrincipal);
 
   NS_IMETHOD Run() override {
     nsAutoPopupStatePusher popupStatePusher(mPopupState);
 
-    // We need to set up an AutoJSAPI here for the following reason: When we do
-    // OnLinkClickSync we'll eventually end up in nsGlobalWindow::OpenInternal
-    // which only does popup blocking if !LegacyIsCallerChromeOrNativeCode().
-    // So we need to fake things so that we don't look like native code as far
-    // as LegacyIsCallerNativeCode() is concerned.
+    // We need to set up an AutoJSAPI here for the following reason: When we
+    // do OnLinkClickSync we'll eventually end up in
+    // nsGlobalWindow::OpenInternal which only does popup blocking if
+    // !LegacyIsCallerChromeOrNativeCode(). So we need to fake things so that
+    // we don't look like native code as far as LegacyIsCallerNativeCode() is
+    // concerned.
     AutoJSAPI jsapi;
     if (mIsTrusted || jsapi.Init(mContent->OwnerDoc()->GetScopeObject())) {
       mHandler->OnLinkClickSync(mContent, mURI, mTargetSpec, mFileName,
                                 mPostDataStream, mHeadersDataStream,
                                 mNoOpenerImplied, nullptr, nullptr,
                                 mIsUserTriggered, mTriggeringPrincipal);
     }
     return NS_OK;
@@ -12652,18 +12655,19 @@ nsDocShell::OnLinkClickSync(nsIContent* 
   {
     // defer to an external protocol handler if necessary...
     nsCOMPtr<nsIExternalProtocolService> extProtService =
         do_GetService(NS_EXTERNALPROTOCOLSERVICE_CONTRACTID);
     if (extProtService) {
       nsAutoCString scheme;
       aURI->GetScheme(scheme);
       if (!scheme.IsEmpty()) {
-        // if the URL scheme does not correspond to an exposed protocol, then we
-        // need to hand this link click over to the external protocol handler.
+        // if the URL scheme does not correspond to an exposed protocol, then
+        // we need to hand this link click over to the external protocol
+        // handler.
         bool isExposed;
         nsresult rv =
             extProtService->IsExposedProtocol(scheme.get(), &isExposed);
         if (NS_SUCCEEDED(rv) && !isExposed) {
           return extProtService->LoadURI(aURI, this);
         }
       }
     }
@@ -12680,19 +12684,19 @@ nsDocShell::OnLinkClickSync(nsIContent* 
     nsAutoString referrer;
     aContent->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::rel, referrer);
     nsWhitespaceTokenizerTemplate<nsContentUtils::IsHTMLWhitespace> tok(
         referrer);
 
     bool targetBlank = aTargetSpec.LowerCaseEqualsLiteral("_blank");
     bool explicitOpenerSet = false;
 
-    // The opener behaviour follows a hierarchy, such that if a higher priority
-    // behaviour is specified, it always takes priority. That priority is
-    // currently: norefrerer > noopener > opener > default
+    // The opener behaviour follows a hierarchy, such that if a higher
+    // priority behaviour is specified, it always takes priority. That
+    // priority is currently: norefrerer > noopener > opener > default
 
     while (tok.hasMoreTokens()) {
       const nsAString& token = tok.nextToken();
       if (token.LowerCaseEqualsLiteral("noreferrer")) {
         flags |= INTERNAL_LOAD_FLAGS_DONT_SEND_REFERRER |
                  INTERNAL_LOAD_FLAGS_NO_OPENER;
         // noreferrer cannot be overwritten by a 'rel=opener'.
         explicitOpenerSet = true;
@@ -12763,18 +12767,18 @@ nsDocShell::OnLinkClickSync(nsIContent* 
   if (anchor) {
     anchor->GetType(typeHint);
     NS_ConvertUTF16toUTF8 utf8Hint(typeHint);
     nsAutoCString type, dummy;
     NS_ParseRequestContentType(utf8Hint, type, dummy);
     CopyUTF8toUTF16(type, typeHint);
   }
 
-  // Link click (or form submission) can be triggered inside an onload handler,
-  // and we don't want to add history entry in this case.
+  // Link click (or form submission) can be triggered inside an onload
+  // handler, and we don't want to add history entry in this case.
   bool inOnLoadHandler = false;
   GetIsExecutingOnLoadHandler(&inOnLoadHandler);
   uint32_t loadType = inOnLoadHandler ? LOAD_NORMAL_REPLACE : LOAD_LINK;
 
   if (aIsUserTriggered) {
     flags |= INTERNAL_LOAD_FLAGS_IS_USER_TRIGGERED;
   }
 
@@ -13346,25 +13350,25 @@ nsICommandManager* nsDocShell::GetComman
 
 NS_IMETHODIMP
 nsDocShell::GetIsOnlyToplevelInTabGroup(bool* aResult) {
   MOZ_ASSERT(aResult);
 
   nsPIDOMWindowOuter* outer = GetWindow();
   MOZ_ASSERT(outer);
 
-  // If we are not toplevel then we are not the only toplevel window in the tab
-  // group.
+  // If we are not toplevel then we are not the only toplevel window in the
+  // tab group.
   if (outer->GetScriptableParentOrNull()) {
     *aResult = false;
     return NS_OK;
   }
 
-  // If we have any other toplevel windows in our tab group, then we are not the
-  // only toplevel window in the tab group.
+  // If we have any other toplevel windows in our tab group, then we are not
+  // the only toplevel window in the tab group.
   nsTArray<nsPIDOMWindowOuter*> toplevelWindows =
       outer->TabGroup()->GetTopLevelWindows();
   if (toplevelWindows.Length() > 1) {
     *aResult = false;
     return NS_OK;
   }
   MOZ_ASSERT(toplevelWindows.Length() == 1);
   MOZ_ASSERT(toplevelWindows[0] == outer);
@@ -13403,18 +13407,18 @@ nsresult nsIDocShell::SetHTMLEditor(HTML
 NS_IMETHODIMP
 nsDocShell::GetDisplayMode(DisplayMode* aDisplayMode) {
   *aDisplayMode = mDisplayMode;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDocShell::SetDisplayMode(DisplayMode aDisplayMode) {
-  // We don't have a way to verify this coming from Javascript, so this check is
-  // still needed.
+  // We don't have a way to verify this coming from Javascript, so this check
+  // is still needed.
   if (!(aDisplayMode == nsIDocShell::DISPLAY_MODE_BROWSER ||
         aDisplayMode == nsIDocShell::DISPLAY_MODE_STANDALONE ||
         aDisplayMode == nsIDocShell::DISPLAY_MODE_FULLSCREEN ||
         aDisplayMode == nsIDocShell::DISPLAY_MODE_MINIMAL_UI)) {
     return NS_ERROR_INVALID_ARG;
   }
 
   if (aDisplayMode != mDisplayMode) {
--- a/docshell/base/nsDocShell.h
+++ b/docshell/base/nsDocShell.h
@@ -383,16 +383,95 @@ class nsDocShell final : public nsDocLoa
   // shift while triggering reload)
   bool IsForceReloading();
 
   /**
    * Native getter for a DocShell's BrowsingContext.
    */
   mozilla::dom::BrowsingContext* GetBrowsingContext() const;
 
+  /**
+   * Loads the given URI. This method is identical to nsIDocShell::loadURI(...)
+   * except that its parameter list is broken out instead of being packaged
+   * inside of an nsIDocShellLoadInfo object...
+   *
+   * @param aURI                 - The URI to load.
+   * @param aOriginalURI         - The URI to set as the originalURI on the channel
+   *                               that does the load. If null, aURI will be set as
+   *                               the originalURI.
+   * @param aResultPrincipalURI  - The URI to be set to loadInfo.resultPrincipalURI
+   *                               When Nothing, there will be no change
+   *                               When Some, the principal URI will overwrite even
+   *                               with a null value.
+   * @param aKeepResultPrincipalURIIfSet - If a refresh is caused by
+   *                                       http-equiv="refresh" we want to set
+   *                                       aResultPrincipalURI, but we do not want
+   *                                       to overwrite the channel's
+   *                                       ResultPrincipalURI, if it has already
+   *                                       been set on the channel by a protocol
+   *                                       handler.
+   * @param aLoadReplace         - If set LOAD_REPLACE flag will be set on the
+   *                               channel. aOriginalURI is null, this argument is
+   *                               ignored.
+   * @param aIsFromProcessingFrameAttributes
+   *                             - If this is a load triggered by changing frame
+   *                               attributes.
+   * @param aReferrer            - Referring URI
+   * @param aReferrerPolicy      - Referrer policy
+   * @param aTriggeringPrincipal - A non-null principal that initiated that load.
+   *                               Please note that this is the principal that is
+   *                               used for security checks. If the argument aURI
+   *                               is provided by the web, then please do not pass
+   *                               a SystemPrincipal as the triggeringPrincipal.
+   * @param aPrincipalToInherit  - Principal to be inherited for that load. If this
+   *                               argument is null then principalToInherit is
+   *                               computed as follows:
+   *                               a) If INTERNAL_LOAD_FLAGS_INHERIT_PRINCIPAL, and
+   *                                  aLoadType is not LOAD_NORMAL_EXTERNAL, and the
+   *                                  URI would normally inherit a principal, then
+   *                                  principalToInherit is set to the current
+   *                                  document's principal, or parent document if
+   *                                  there is not a current document.
+   *                               b) If principalToInherit is still null (e.g. if
+   *                                  some of the conditions of (a) were not satisfied),
+   *                                  then no inheritance of any sort will happen: the
+   *                                  load will just get a principal based on the URI
+   *                                  being loaded.
+   * @param aFlags               - Any of the load flags defined within above.
+   * @param aWindowTarget        - Window target for the load.
+   * @param aTypeHint            - A hint as to the content-type of the resulting
+   *                               data.  May be null or empty if no hint.
+   * @param aFileName            - Non-null when the link should be downloaded as
+   *                               the given filename.
+   * @param aPostDataStream      - Post data stream (if POSTing)
+   * @param aHeadersStream       - Stream containing "extra" request headers...
+   * @param aLoadFlags           - Flags to modify load behaviour. Flags are defined
+   *                               in nsIWebNavigation.
+   * @param aSHEntry             - Active Session History entry (if loading from SH)
+   * @param aSrcdoc                When INTERNAL_LOAD_FLAGS_IS_SRCDOC is set, the
+   *                               contents of this parameter will be loaded instead
+   *                               of aURI.
+   * @param aSourceDocShell      - The source browsing context for the navigation.
+   * @param aBaseURI             - The base URI to be used for the load.  Set in
+   *                               srcdoc loads as it cannot otherwise be inferred
+   *                               in certain situations such as view-source.
+   */
+  nsresult InternalLoad(
+      nsIURI* aURI, nsIURI* aOriginalURI,
+      mozilla::Maybe<nsCOMPtr<nsIURI>> const& aResultPrincipalURI,
+      bool aKeepResultPrincipalURIIfSet, bool aLoadReplace,
+      bool aIsFromProcessingFrameAttributes, nsIURI* aReferrer,
+      uint32_t aReferrerPolicy, nsIPrincipal* aTriggeringPrincipal,
+      nsIPrincipal* aPrincipalToInherit, uint32_t aFlags,
+      const nsAString& aWindowTarget, const nsACString& aTypeHint,
+      const nsAString& aFileName, nsIInputStream* aPostData,
+      nsIInputStream* aHeadersData, uint32_t aLoadType, nsISHEntry* aSHEntry,
+      bool aFirstParty, const nsAString& aSrcdoc, nsIDocShell* aSourceDocShell,
+      nsIURI* aBaseURI, nsIDocShell** aDocShell, nsIRequest** aRequest);
+
  private:  // member functions
   friend class nsDSURIContentListener;
   friend class FramingChecker;
   friend class OnLinkClickEvent;
   friend class nsIDocShell;
 
   // It is necessary to allow adding a timeline marker wherever a docshell
   // instance is available. This operation happens frequently and needs to
--- a/docshell/base/nsIDocShell.idl
+++ b/docshell/base/nsIDocShell.idl
@@ -78,109 +78,16 @@ interface nsIDocShell : nsIDocShellTreeI
    * however, the URL dispatcher will go through its normal process of content
    * loading.
    *
    * @param loadState   - This is the extended load info for this load.
    */
   [noscript]void loadURI(in nsDocShellLoadStatePtr loadState);
 
   /**
-   * Loads the given URI.  This method is identical to loadURI(...) except
-   * that its parameter list is broken out instead of being packaged inside
-   * of an nsIDocShellLoadInfo object...
-   *
-   * @param aURI                 - The URI to load.
-   * @param aOriginalURI         - The URI to set as the originalURI on the channel
-   *                               that does the load. If null, aURI will be set as
-   *                               the originalURI.
-   * @param aResultPrincipalURI  - The URI to be set to loadInfo.resultPrincipalURI
-   *                               When Nothing, there will be no change
-   *                               When Some, the principal URI will overwrite even
-   *                               with a null value.
-   * @param aKeepResultPrincipalURIIfSet - If a refresh is caused by
-   *                                       http-equiv="refresh" we want to set
-   *                                       aResultPrincipalURI, but we do not want
-   *                                       to overwrite the channel's
-   *                                       ResultPrincipalURI, if it has already
-   *                                       been set on the channel by a protocol
-   *                                       handler.
-   * @param aLoadReplace         - If set LOAD_REPLACE flag will be set on the
-   *                               channel. aOriginalURI is null, this argument is
-   *                               ignored.
-   * @param aIsFromProcessingFrameAttributes
-   *          - If this is a load triggered by changing frame attributes.
-   *            See nsILoadInfo.isFromProcessingFrameAttributes
-   * @param aReferrer            - Referring URI
-   * @param aReferrerPolicy      - Referrer policy
-   * @param aTriggeringPrincipal - A non-null principal that initiated that load.
-   *                               Please note that this is the principal that is
-   *                               used for security checks. If the argument aURI
-   *                               is provided by the web, then please do not pass
-   *                               a SystemPrincipal as the triggeringPrincipal.
-   * @param aPrincipalToInherit  - Principal to be inherited for that load. If this
-   *                               argument is null then principalToInherit is
-   *                               computed as follows:
-   *                               a) If INTERNAL_LOAD_FLAGS_INHERIT_PRINCIPAL, and
-   *                                  aLoadType is not LOAD_NORMAL_EXTERNAL, and the
-   *                                  URI would normally inherit a principal, then
-   *                                  principalToInherit is set to the current
-   *                                  document's principal, or parent document if
-   *                                  there is not a current document.
-   *                               b) If principalToInherit is still null (e.g. if
-   *                                  some of the conditions of (a) were not satisfied),
-   *                                  then no inheritance of any sort will happen: the
-   *                                  load will just get a principal based on the URI
-   *                                  being loaded.
-   * @param aFlags               - Any of the load flags defined within above.
-   * @param aStopActiveDoc       - Flag indicating whether loading the current
-   *                               document should be stopped.
-   * @param aWindowTarget        - Window target for the load.
-   * @param aTypeHint            - A hint as to the content-type of the resulting
-   *                               data.  May be null or empty if no hint.
-   * @param aFileName            - Non-null when the link should be downloaded as
-                                   the given filename.
-   * @param aPostDataStream      - Post data stream (if POSTing)
-   * @param aHeadersStream       - Stream containing "extra" request headers...
-   * @param aLoadFlags           - Flags to modify load behaviour. Flags are defined
-   *                               in nsIWebNavigation.
-   * @param aSHEntry             - Active Session History entry (if loading from SH)
-   * @param aSrcdoc                When INTERNAL_LOAD_FLAGS_IS_SRCDOC is set, the
-   *                               contents of this parameter will be loaded instead
-   *                               of aURI.
-   * @param aSourceDocShell      - The source browsing context for the navigation.
-   * @param aBaseURI             - The base URI to be used for the load.  Set in
-   *                               srcdoc loads as it cannot otherwise be inferred
-   *                               in certain situations such as view-source.
-   */
-  [noscript]void internalLoad(in nsIURI aURI,
-                              in nsIURI aOriginalURI,
-                              [const] in MaybeURI aResultPrincipalURI,
-                              in bool aKeepResultPrincipalURIIfSet,
-                              in boolean aLoadReplace,
-                              in boolean aIsFromProcessingFrameAttributes,
-                              in nsIURI aReferrer,
-                              in unsigned long aReferrerPolicy,
-                              in nsIPrincipal aTriggeringPrincipal,
-                              in nsIPrincipal aPrincipalToInherit,
-                              in uint32_t aFlags,
-                              in AString aWindowTarget,
-                              in ACString aTypeHint,
-                              in AString aFileName,
-                              in nsIInputStream aPostDataStream,
-                              in nsIInputStream aHeadersStream,
-                              in unsigned long aLoadFlags,
-                              in nsISHEntry aSHEntry,
-                              in boolean aFirstParty,
-                              in AString aSrcdoc,
-                              in nsIDocShell aSourceDocShell,
-                              in nsIURI aBaseURI,
-                              out nsIDocShell aDocShell,
-                              out nsIRequest aRequest);
-
-  /**
    * Do either a history.pushState() or history.replaceState() operation,
    * depending on the value of aReplace.
    */
   [implicit_jscontext]
   void addState(in jsval aData, in AString aTitle,
                 in AString aURL, in boolean aReplace);
 
   /**