mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-19 08:15:31 +00:00
Bug 1616353 - Part 6.4: Delay loading chrome window URIs until docshell has been configured, r=smaug
Previously, a load of the URI within a chrome docshell would start before the chrome docshell has had a chance to be configured. This could cause problems, as the load would be configured incorrectly. After these changes, starting the load is delayed until after nsILoadContext configuration is complete. Differential Revision: https://phabricator.services.mozilla.com/D67048 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
337ec3df9a
commit
cf8902e5b0
@ -156,9 +156,8 @@ NS_INTERFACE_MAP_BEGIN(AppWindow)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
nsresult AppWindow::Initialize(nsIAppWindow* aParent, nsIAppWindow* aOpener,
|
||||
nsIURI* aUrl, int32_t aInitialWidth,
|
||||
int32_t aInitialHeight, bool aIsHiddenWindow,
|
||||
nsIRemoteTab* aOpeningTab,
|
||||
int32_t aInitialWidth, int32_t aInitialHeight,
|
||||
bool aIsHiddenWindow, nsIRemoteTab* aOpeningTab,
|
||||
mozIDOMWindowProxy* aOpenerWindow,
|
||||
nsWidgetInitData& widgetInitData) {
|
||||
nsresult rv;
|
||||
@ -279,47 +278,6 @@ nsresult AppWindow::Initialize(nsIAppWindow* aParent, nsIAppWindow* aOpener,
|
||||
}
|
||||
#endif
|
||||
|
||||
// Eagerly create an about:blank content viewer with the right principal here,
|
||||
// rather than letting it happening in the upcoming call to
|
||||
// SetInitialPrincipalToSubject. This avoids creating the about:blank document
|
||||
// and then blowing it away with a second one, which can cause problems for
|
||||
// the top-level chrome window case. See bug 789773. Note that we don't accept
|
||||
// expanded principals here, similar to SetInitialPrincipalToSubject.
|
||||
if (nsContentUtils::IsInitialized()) { // Sometimes this happens really early
|
||||
// See bug 793370.
|
||||
MOZ_ASSERT(mDocShell->ItemType() == nsIDocShellTreeItem::typeChrome);
|
||||
nsCOMPtr<nsIPrincipal> principal =
|
||||
nsContentUtils::SubjectPrincipalOrSystemIfNativeCaller();
|
||||
if (nsContentUtils::IsExpandedPrincipal(principal)) {
|
||||
principal = nullptr;
|
||||
}
|
||||
// Use the subject (or system) principal as the storage principal too until
|
||||
// the new window finishes navigating and gets a real storage principal.
|
||||
rv = mDocShell->CreateAboutBlankContentViewer(principal, principal,
|
||||
/* aCsp = */ nullptr);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
RefPtr<Document> doc = mDocShell->GetDocument();
|
||||
NS_ENSURE_TRUE(!!doc, NS_ERROR_FAILURE);
|
||||
doc->SetIsInitialDocument(true);
|
||||
}
|
||||
|
||||
if (nullptr != aUrl) {
|
||||
nsCString tmpStr;
|
||||
|
||||
rv = aUrl->GetSpec(tmpStr);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
NS_ConvertUTF8toUTF16 urlString(tmpStr);
|
||||
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(mDocShell));
|
||||
NS_ENSURE_TRUE(webNav, NS_ERROR_FAILURE);
|
||||
|
||||
LoadURIOptions loadURIOptions;
|
||||
loadURIOptions.mTriggeringPrincipal = nsContentUtils::GetSystemPrincipal();
|
||||
|
||||
rv = webNav->LoadURI(urlString, loadURIOptions);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
@ -138,12 +138,13 @@ class AppWindow final : public nsIBaseWindow,
|
||||
|
||||
// AppWindow methods...
|
||||
nsresult Initialize(nsIAppWindow* aParent, nsIAppWindow* aOpener,
|
||||
nsIURI* aUrl, int32_t aInitialWidth,
|
||||
int32_t aInitialHeight, bool aIsHiddenWindow,
|
||||
nsIRemoteTab* aOpeningTab,
|
||||
mozIDOMWindowProxy* aOpenerWIndow,
|
||||
int32_t aInitialWidth, int32_t aInitialHeight,
|
||||
bool aIsHiddenWindow, nsIRemoteTab* aOpeningTab,
|
||||
mozIDOMWindowProxy* aOpenerWindow,
|
||||
nsWidgetInitData& widgetInitData);
|
||||
|
||||
nsIDocShell* GetDocShell() { return mDocShell; }
|
||||
|
||||
nsresult Toolbar();
|
||||
|
||||
// nsIWebProgressListener
|
||||
|
@ -42,6 +42,8 @@
|
||||
#include "gfxPlatform.h"
|
||||
|
||||
#include "nsWebBrowser.h"
|
||||
#include "nsDocShell.h"
|
||||
#include "nsDocShellLoadState.h"
|
||||
|
||||
#ifdef MOZ_INSTRUMENT_EVENT_LOOP
|
||||
# include "EventTracer.h"
|
||||
@ -677,7 +679,7 @@ nsresult nsAppShellService::JustCreateTopWindow(
|
||||
widgetInitData.mRTL = LocaleService::GetInstance()->IsAppLocaleRTL();
|
||||
|
||||
nsresult rv = window->Initialize(
|
||||
parent, center ? aParent : nullptr, aUrl, aInitialWidth, aInitialHeight,
|
||||
parent, center ? aParent : nullptr, aInitialWidth, aInitialHeight,
|
||||
aIsHiddenWindow, aOpeningTab, aOpenerWindow, widgetInitData);
|
||||
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
@ -701,17 +703,48 @@ nsresult nsAppShellService::JustCreateTopWindow(
|
||||
isPrivateBrowsingWindow = parentContext->UsePrivateBrowsing();
|
||||
}
|
||||
|
||||
if (nsDocShell* docShell = nsDocShell::Cast(window->GetDocShell())) {
|
||||
MOZ_ASSERT(docShell->ItemType() == nsIDocShellTreeItem::typeChrome);
|
||||
|
||||
nsCOMPtr<mozIDOMWindowProxy> newDomWin =
|
||||
do_GetInterface(NS_ISUPPORTS_CAST(nsIBaseWindow*, window));
|
||||
nsCOMPtr<nsIWebNavigation> newWebNav = do_GetInterface(newDomWin);
|
||||
nsCOMPtr<nsILoadContext> thisContext = do_GetInterface(newWebNav);
|
||||
if (thisContext) {
|
||||
thisContext->SetPrivateBrowsing(isPrivateBrowsingWindow);
|
||||
thisContext->SetRemoteTabs(aChromeMask &
|
||||
nsIWebBrowserChrome::CHROME_REMOTE_WINDOW);
|
||||
thisContext->SetRemoteSubframes(aChromeMask &
|
||||
nsIWebBrowserChrome::CHROME_FISSION_WINDOW);
|
||||
docShell->SetPrivateBrowsing(isPrivateBrowsingWindow);
|
||||
docShell->SetRemoteTabs(aChromeMask &
|
||||
nsIWebBrowserChrome::CHROME_REMOTE_WINDOW);
|
||||
docShell->SetRemoteSubframes(aChromeMask &
|
||||
nsIWebBrowserChrome::CHROME_FISSION_WINDOW);
|
||||
|
||||
// Eagerly create an about:blank content viewer with the right principal
|
||||
// here, rather than letting it happening in the upcoming call to
|
||||
// SetInitialPrincipalToSubject. This avoids creating the about:blank
|
||||
// document and then blowing it away with a second one, which can cause
|
||||
// problems for the top-level chrome window case. See bug 789773. Note that
|
||||
// we don't accept expanded principals here, similar to
|
||||
// SetInitialPrincipalToSubject.
|
||||
if (nsContentUtils::IsInitialized()) { // Sometimes this happens really
|
||||
// early. See bug 793370.
|
||||
nsCOMPtr<nsIPrincipal> principal =
|
||||
nsContentUtils::SubjectPrincipalOrSystemIfNativeCaller();
|
||||
if (nsContentUtils::IsExpandedPrincipal(principal)) {
|
||||
principal = nullptr;
|
||||
}
|
||||
// Use the subject (or system) principal as the storage principal too
|
||||
// until the new window finishes navigating and gets a real storage
|
||||
// principal.
|
||||
rv = docShell->CreateAboutBlankContentViewer(principal, principal,
|
||||
/* aCsp = */ nullptr);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
RefPtr<Document> doc = docShell->GetDocument();
|
||||
NS_ENSURE_TRUE(!!doc, NS_ERROR_FAILURE);
|
||||
doc->SetIsInitialDocument(true);
|
||||
}
|
||||
|
||||
// Begin loading the URL provided.
|
||||
if (aUrl) {
|
||||
RefPtr<nsDocShellLoadState> loadState = new nsDocShellLoadState(aUrl);
|
||||
loadState->SetTriggeringPrincipal(nsContentUtils::GetSystemPrincipal());
|
||||
loadState->SetFirstParty(true);
|
||||
rv = docShell->LoadURI(loadState, /* aSetNavigating */ true);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
}
|
||||
|
||||
window.forget(aResult);
|
||||
|
Loading…
Reference in New Issue
Block a user