Bug 1715852 - Fix SessionHistoryEntry::mSrcdocData to work with session restore, r=peterv

Not setting mIsSrcdocEntry causes us to drop srcdoc data and not set
INTERNAL_LOAD_FLAGS_IS_SRCDOC in FillLoadInfo for srcdoc restores.

Differential Revision: https://phabricator.services.mozilla.com/D117479
This commit is contained in:
Kashav Madan 2021-06-15 13:34:01 +00:00
Родитель e6f756935d
Коммит 1a33a37654
5 изменённых файлов: 57 добавлений и 18 удалений

Просмотреть файл

@ -102,6 +102,7 @@ skip-if =
[browser_pinned_tabs.js]
skip-if = debug || ccov # Bug 1625525
apple_silicon # crash
[browser_restore_srcdoc.js]
[browser_unrestored_crashedTabs.js]
skip-if =
!e10s || !crashreporter

Просмотреть файл

@ -0,0 +1,44 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
function makeURL(srcdocValue) {
return `data:text/html;charset=utf-8,<iframe srcdoc="${srcdocValue}">`;
}
async function runTest(srcdocValue) {
forgetClosedWindows();
// Open a new tab.
let tab = BrowserTestUtils.addTab(gBrowser, makeURL(srcdocValue));
await promiseBrowserLoaded(tab.linkedBrowser);
// Close that tab.
await promiseRemoveTabAndSessionState(tab);
// Restore that tab.
tab = ss.undoCloseTab(window, 0);
await promiseTabRestored(tab);
// Verify contents were restored correctly.
let iframe = await SpecialPowers.spawn(
tab.linkedBrowser,
[],
() => content.document.querySelector("iframe").browsingContext
);
await SpecialPowers.spawn(iframe, [srcdocValue], text => {
Assert.equal(content.document.body.innerText, text, "Didn't load neterror");
});
// Cleanup.
gBrowser.removeTab(tab);
}
add_task(async function test_non_blank() {
await runTest("value");
});
add_task(async function test_blank() {
await runTest("");
});

Просмотреть файл

@ -42,11 +42,11 @@ SessionHistoryInfo::SessionHistoryInfo(nsDocShellLoadState* aLoadState,
mResultPrincipalURI(aLoadState->ResultPrincipalURI()),
mPostData(aLoadState->PostDataStream()),
mLoadType(aLoadState->LoadType()),
mSrcdocData(aLoadState->SrcdocData()),
mSrcdocData(aLoadState->SrcdocData().IsVoid()
? Nothing()
: Some(aLoadState->SrcdocData())),
mBaseURI(aLoadState->BaseURI()),
mLoadReplace(aLoadState->LoadReplace()),
/* FIXME Should this be aLoadState->IsSrcdocLoad()? */
mIsSrcdocEntry(!aLoadState->SrcdocData().IsEmpty()),
mHasUserInteraction(false),
mHasUserActivation(aLoadState->HasValidUserGestureActivation()),
mSharedState(SharedState::Create(
@ -133,11 +133,10 @@ void SessionHistoryInfo::Reset(nsIURI* aURI, const nsID& aDocShellID,
mScrollPositionX = 0;
mScrollPositionY = 0;
mStateData = nullptr;
mSrcdocData.Truncate();
mSrcdocData = Nothing();
mBaseURI = nullptr;
mLoadReplace = false;
mURIWasModified = false;
mIsSrcdocEntry = false;
mScrollRestorationIsManual = false;
mPersist = false;
mHasUserInteraction = false;
@ -231,8 +230,8 @@ void SessionHistoryInfo::FillLoadInfo(nsDocShellLoadState& aLoadState) const {
// first created. bug 947716 has been created to address this issue.
nsAutoString srcdoc;
nsCOMPtr<nsIURI> baseURI;
if (mIsSrcdocEntry) {
srcdoc = mSrcdocData;
if (mSrcdocData) {
srcdoc = mSrcdocData.value();
baseURI = mBaseURI;
flags |= nsDocShell::InternalLoad::INTERNAL_LOAD_FLAGS_IS_SRCDOC;
} else {
@ -830,19 +829,19 @@ SessionHistoryEntry::SetDocshellID(const nsID& aDocshellID) {
NS_IMETHODIMP
SessionHistoryEntry::GetIsSrcdocEntry(bool* aIsSrcdocEntry) {
*aIsSrcdocEntry = mInfo->mIsSrcdocEntry;
*aIsSrcdocEntry = mInfo->mSrcdocData.isSome();
return NS_OK;
}
NS_IMETHODIMP
SessionHistoryEntry::GetSrcdocData(nsAString& aSrcdocData) {
aSrcdocData = mInfo->mSrcdocData;
aSrcdocData = mInfo->mSrcdocData.valueOr(EmptyString());
return NS_OK;
}
NS_IMETHODIMP
SessionHistoryEntry::SetSrcdocData(const nsAString& aSrcdocData) {
mInfo->mSrcdocData = aSrcdocData;
mInfo->mSrcdocData = Some(nsString(aSrcdocData));
return NS_OK;
}
@ -1444,7 +1443,6 @@ void IPDLParamTraits<dom::SessionHistoryInfo>::Write(
WriteIPDLParam(aMsg, aActor, aParam.mBaseURI);
WriteIPDLParam(aMsg, aActor, aParam.mLoadReplace);
WriteIPDLParam(aMsg, aActor, aParam.mURIWasModified);
WriteIPDLParam(aMsg, aActor, aParam.mIsSrcdocEntry);
WriteIPDLParam(aMsg, aActor, aParam.mScrollRestorationIsManual);
WriteIPDLParam(aMsg, aActor, aParam.mPersist);
WriteIPDLParam(aMsg, aActor, aParam.mHasUserInteraction);
@ -1481,7 +1479,6 @@ bool IPDLParamTraits<dom::SessionHistoryInfo>::Read(
!ReadIPDLParam(aMsg, aIter, aActor, &aResult->mBaseURI) ||
!ReadIPDLParam(aMsg, aIter, aActor, &aResult->mLoadReplace) ||
!ReadIPDLParam(aMsg, aIter, aActor, &aResult->mURIWasModified) ||
!ReadIPDLParam(aMsg, aIter, aActor, &aResult->mIsSrcdocEntry) ||
!ReadIPDLParam(aMsg, aIter, aActor,
&aResult->mScrollRestorationIsManual) ||
!ReadIPDLParam(aMsg, aIter, aActor, &aResult->mPersist) ||

Просмотреть файл

@ -7,6 +7,7 @@
#ifndef mozilla_dom_SessionHistoryEntry_h
#define mozilla_dom_SessionHistoryEntry_h
#include "mozilla/Maybe.h"
#include "mozilla/UniquePtr.h"
#include "nsILayoutHistoryState.h"
#include "nsISHEntry.h"
@ -160,12 +161,11 @@ class SessionHistoryInfo {
int32_t mScrollPositionX = 0;
int32_t mScrollPositionY = 0;
RefPtr<nsStructuredCloneContainer> mStateData;
nsString mSrcdocData;
Maybe<nsString> mSrcdocData;
nsCOMPtr<nsIURI> mBaseURI;
bool mLoadReplace = false;
bool mURIWasModified = false;
bool mIsSrcdocEntry = false;
bool mScrollRestorationIsManual = false;
bool mPersist = true;
bool mHasUserInteraction = false;

Просмотреть файл

@ -221,11 +221,8 @@ var SessionHistoryInternal = {
entry.loadReplace2 = shEntry.loadReplace;
}
if (shEntry.srcdocData) {
entry.srcdocData = shEntry.srcdocData;
}
if (shEntry.isSrcdocEntry) {
entry.srcdocData = shEntry.srcdocData;
entry.isSrcdocEntry = shEntry.isSrcdocEntry;
}