Bug 1315105 - Part 2: Implement <link rel=prerender> behind a pref, r=smaug

MozReview-Commit-ID: ARET98o1FTU
This commit is contained in:
Michael Layzell
2016-12-19 15:05:31 +08:00
parent 2f8026ac1d
commit c6453a3b88
20 changed files with 442 additions and 52 deletions

View File

@@ -1575,6 +1575,7 @@ nsDocShell::LoadURI(nsIURI* aURI,
srcdoc,
sourceDocShell,
baseURI,
false,
nullptr, // No nsIDocShell
nullptr); // No nsIRequest
}
@@ -5367,8 +5368,8 @@ nsDocShell::LoadErrorPage(nsIURI* aURI, const char16_t* aURL,
nsContentUtils::GetSystemPrincipal(), nullptr,
INTERNAL_LOAD_FLAGS_NONE, EmptyString(),
nullptr, NullString(), nullptr, nullptr, LOAD_ERROR_PAGE,
nullptr, true, NullString(), this, nullptr, nullptr,
nullptr);
nullptr, true, NullString(), this, nullptr, false,
nullptr, nullptr);
}
NS_IMETHODIMP
@@ -5460,6 +5461,7 @@ nsDocShell::Reload(uint32_t aReloadFlags)
srcdoc, // srcdoc argument for iframe
this, // For reloads we are the source
baseURI,
false,
nullptr, // No nsIDocShell
nullptr); // No nsIRequest
}
@@ -7956,7 +7958,8 @@ nsDocShell::EnsureContentViewer()
nsresult
nsDocShell::CreateAboutBlankContentViewer(nsIPrincipal* aPrincipal,
nsIURI* aBaseURI,
bool aTryToSaveOldPresentation)
bool aTryToSaveOldPresentation,
bool aCheckPermitUnload)
{
nsCOMPtr<nsIDocument> blankDoc;
nsCOMPtr<nsIContentViewer> viewer;
@@ -7989,31 +7992,32 @@ nsDocShell::CreateAboutBlankContentViewer(nsIPrincipal* aPrincipal,
bool hadTiming = mTiming;
bool toBeReset = MaybeInitTiming();
if (mContentViewer) {
// We've got a content viewer already. Make sure the user
// permits us to discard the current document and replace it
// with about:blank. And also ensure we fire the unload events
// in the current document.
if (aCheckPermitUnload) {
// We've got a content viewer already. Make sure the user
// permits us to discard the current document and replace it
// with about:blank. And also ensure we fire the unload events
// in the current document.
// Unload gets fired first for
// document loaded from the session history.
mTiming->NotifyBeforeUnload();
// Unload gets fired first for
// document loaded from the session history.
mTiming->NotifyBeforeUnload();
bool okToUnload;
rv = mContentViewer->PermitUnload(&okToUnload);
bool okToUnload;
rv = mContentViewer->PermitUnload(&okToUnload);
if (NS_SUCCEEDED(rv) && !okToUnload) {
// The user chose not to unload the page, interrupt the load.
MaybeResetInitTiming(toBeReset);
return NS_ERROR_FAILURE;
if (NS_SUCCEEDED(rv) && !okToUnload) {
// The user chose not to unload the page, interrupt the load.
MaybeResetInitTiming(toBeReset);
return NS_ERROR_FAILURE;
}
if (mTiming) {
mTiming->NotifyUnloadAccepted(mCurrentURI);
}
}
mSavingOldViewer = aTryToSaveOldPresentation &&
CanSavePresentation(LOAD_NORMAL, nullptr, nullptr);
if (mTiming) {
mTiming->NotifyUnloadAccepted(mCurrentURI);
}
// Make sure to blow away our mLoadingURI just in case. No loads
// from inside this pagehide.
mLoadingURI = nullptr;
@@ -8097,6 +8101,12 @@ nsDocShell::CreateAboutBlankContentViewer(nsIPrincipal* aPrincipal)
return CreateAboutBlankContentViewer(aPrincipal, nullptr);
}
NS_IMETHODIMP
nsDocShell::ForceCreateAboutBlankContentViewer(nsIPrincipal* aPrincipal)
{
return CreateAboutBlankContentViewer(aPrincipal, nullptr, true, false);
}
bool
nsDocShell::CanSavePresentation(uint32_t aLoadType,
nsIRequest* aNewRequest,
@@ -9578,7 +9588,7 @@ public:
nsIInputStream* aHeadersData, uint32_t aLoadType,
nsISHEntry* aSHEntry, bool aFirstParty,
const nsAString& aSrcdoc, nsIDocShell* aSourceDocShell,
nsIURI* aBaseURI)
nsIURI* aBaseURI, bool aCheckForPrerender)
: mSrcdoc(aSrcdoc)
, mDocShell(aDocShell)
, mURI(aURI)
@@ -9596,6 +9606,7 @@ public:
, mFirstParty(aFirstParty)
, mSourceDocShell(aSourceDocShell)
, mBaseURI(aBaseURI)
, mCheckForPrerender(aCheckForPrerender)
{
// Make sure to keep null things null as needed
if (aTypeHint) {
@@ -9615,7 +9626,7 @@ public:
NullString(), mPostData, mHeadersData,
mLoadType, mSHEntry, mFirstParty,
mSrcdoc, mSourceDocShell, mBaseURI,
nullptr, nullptr);
mCheckForPrerender, nullptr, nullptr);
}
private:
@@ -9640,6 +9651,7 @@ private:
bool mFirstParty;
nsCOMPtr<nsIDocShell> mSourceDocShell;
nsCOMPtr<nsIURI> mBaseURI;
bool mCheckForPrerender;
};
/**
@@ -9712,6 +9724,7 @@ nsDocShell::InternalLoad(nsIURI* aURI,
const nsAString& aSrcdoc,
nsIDocShell* aSourceDocShell,
nsIURI* aBaseURI,
bool aCheckForPrerender,
nsIDocShell** aDocShell,
nsIRequest** aRequest)
{
@@ -10071,6 +10084,7 @@ nsDocShell::InternalLoad(nsIURI* aURI,
aSrcdoc,
aSourceDocShell,
aBaseURI,
aCheckForPrerender,
aDocShell,
aRequest);
if (rv == NS_ERROR_NO_CONTENT) {
@@ -10141,7 +10155,7 @@ nsDocShell::InternalLoad(nsIURI* aURI,
aTriggeringPrincipal, principalToInherit,
aFlags, aTypeHint, aPostData, aHeadersData,
aLoadType, aSHEntry, aFirstParty, aSrcdoc,
aSourceDocShell, aBaseURI);
aSourceDocShell, aBaseURI, false);
return NS_DispatchToCurrentThread(ev);
}
@@ -10528,6 +10542,25 @@ nsDocShell::InternalLoad(nsIURI* aURI,
mTiming->NotifyUnloadAccepted(mCurrentURI);
}
if (browserChrome3 && aCheckForPrerender) {
nsCOMPtr<nsIRunnable> ev =
new InternalLoadEvent(this, aURI, aOriginalURI, aLoadReplace,
aReferrer, aReferrerPolicy,
aTriggeringPrincipal, principalToInherit,
aFlags, aTypeHint, aPostData, aHeadersData,
aLoadType, aSHEntry, aFirstParty, aSrcdoc,
aSourceDocShell, aBaseURI, false);
// We don't need any success handler since in that case
// OnPartialSessionHistoryDeactive would be called, and it would ensure
// docshell loads about:blank.
bool shouldSwitch = false;
rv = browserChrome3->ShouldSwitchToPrerenderedDocument(
aURI, mCurrentURI, nullptr, ev, &shouldSwitch);
if (NS_SUCCEEDED(rv) && shouldSwitch) {
return NS_OK;
}
}
// Whenever a top-level browsing context is navigated, the user agent MUST
// lock the orientation of the document to the document's default
// orientation. We don't explicitly check for a top-level browsing context
@@ -12531,6 +12564,7 @@ nsDocShell::LoadHistoryEntry(nsISHEntry* aEntry, uint32_t aLoadType)
srcdoc,
nullptr, // Source docshell, see comment above
baseURI,
false,
nullptr, // No nsIDocShell
nullptr); // No nsIRequest
return rv;
@@ -14036,6 +14070,7 @@ nsDocShell::OnLinkClickSync(nsIContent* aContent,
NullString(), // No srcdoc
this, // We are the source
nullptr, // baseURI not needed
true, // Check for prerendered doc
aDocShell, // DocShell out-param
aRequest); // Request out-param
if (NS_SUCCEEDED(rv)) {
@@ -14702,6 +14737,14 @@ nsDocShell::GetCommandManager()
return mCommandManager;
}
NS_IMETHODIMP
nsDocShell::GetIsProcessLocked(bool* aIsLocked)
{
MOZ_ASSERT(aIsLocked);
*aIsLocked = GetProcessLockReason() != PROCESS_LOCK_NONE;
return NS_OK;
}
NS_IMETHODIMP
nsDocShell::GetProcessLockReason(uint32_t* aReason)
{