Bug 1624550 - P1: Move nsDocShell::mUseGlobalHistory to BrowsingContext. r=farre

Differential Revision: https://phabricator.services.mozilla.com/D72276
This commit is contained in:
Dan Glastonbury
2020-05-08 03:28:38 +00:00
parent 5eb0d9f223
commit eadb57ae0a
4 changed files with 25 additions and 7 deletions

View File

@@ -307,6 +307,10 @@ already_AddRefed<BrowsingContext> BrowsingContext::CreateDetached(
context->mFields.SetWithoutSyncing<IDX_OrientationLock>(
mozilla::hal::eScreenOrientation_None);
const bool useGlobalHistory =
inherit ? inherit->GetUseGlobalHistory() : false;
context->mFields.SetWithoutSyncing<IDX_UseGlobalHistory>(useGlobalHistory);
return context.forget();
}
@@ -477,6 +481,10 @@ void BrowsingContext::SetEmbedderElement(Element* aEmbedder) {
messageManagerGroup);
}
txn.SetMessageManagerGroup(messageManagerGroup);
bool useGlobalHistory = !aEmbedder->HasAttr(
kNameSpaceID_None, nsGkAtoms::disableglobalhistory);
txn.SetUseGlobalHistory(useGlobalHistory);
}
txn.Commit(this);
}
@@ -1952,6 +1960,13 @@ void BrowsingContext::DidSet(FieldIndex<IDX_DefaultLoadFlags>) {
}
}
bool BrowsingContext::CanSet(FieldIndex<IDX_UseGlobalHistory>,
const bool& aUseGlobalHistory,
ContentParent* aSource) {
// TODO: Allow access from all
return true;
}
bool BrowsingContext::CanSet(FieldIndex<IDX_UserAgentOverride>,
const nsString& aUserAgent,
ContentParent* aSource) {

View File

@@ -115,6 +115,7 @@ class WindowProxyHolder;
FIELD(AllowContentRetargeting, bool) \
FIELD(AllowContentRetargetingOnChildren, bool) \
FIELD(ForceEnableTrackingProtection, bool) \
FIELD(UseGlobalHistory, bool) \
/* These field are used to store the states of autoplay media request on \
* GeckoView only, and it would only be modified on the top level browsing \
* context. */ \
@@ -735,6 +736,9 @@ class BrowsingContext : public nsILoadContext, public nsWrapperCache {
const uint32_t& aDefaultLoadFlags, ContentParent* aSource);
void DidSet(FieldIndex<IDX_DefaultLoadFlags>);
bool CanSet(FieldIndex<IDX_UseGlobalHistory>, const bool& aUseGlobalHistory,
ContentParent* aSource);
template <size_t I, typename T>
bool CanSet(FieldIndex<I>, const T&, ContentParent*) {
return true;

View File

@@ -379,7 +379,6 @@ nsDocShell::nsDocShell(BrowsingContext* aBrowsingContext,
mIsOffScreenBrowser(false),
mDisableMetaRefreshWhenInactive(false),
mIsAppTab(false),
mUseGlobalHistory(false),
mDeviceSizeIsPageSize(false),
mWindowDraggingAllowed(false),
mInFrameSwap(false),
@@ -2830,7 +2829,7 @@ nsDocShell::AddChild(nsIDocShellTreeItem* aChild) {
childDocShell->SetChildOffset(dynamic ? -1 : mChildList.Length() - 1);
/* Set the child's global history if the parent has one */
if (mUseGlobalHistory) {
if (mBrowsingContext->GetUseGlobalHistory()) {
childDocShell->SetUseGlobalHistory(true);
}
@@ -3009,7 +3008,7 @@ nsresult nsDocShell::AddChildSHEntryToParent(nsISHEntry* aNewEntry,
NS_IMETHODIMP
nsDocShell::SetUseGlobalHistory(bool aUseGlobalHistory) {
mUseGlobalHistory = aUseGlobalHistory;
mBrowsingContext->SetUseGlobalHistory(aUseGlobalHistory);
if (!aUseGlobalHistory) {
return NS_OK;
}
@@ -3020,7 +3019,7 @@ nsDocShell::SetUseGlobalHistory(bool aUseGlobalHistory) {
NS_IMETHODIMP
nsDocShell::GetUseGlobalHistory(bool* aUseGlobalHistory) {
*aUseGlobalHistory = mUseGlobalHistory;
*aUseGlobalHistory = mBrowsingContext->GetUseGlobalHistory();
return NS_OK;
}
@@ -11232,7 +11231,8 @@ void nsDocShell::AddURIVisit(nsIURI* aURI, nsIURI* aPreviousURI,
// Only content-type docshells save URI visits. Also don't do
// anything here if we're not supposed to use global history.
if (mItemType != typeContent || !mUseGlobalHistory || UsePrivateBrowsing()) {
if (mItemType != typeContent || !mBrowsingContext->GetUseGlobalHistory() ||
UsePrivateBrowsing()) {
return;
}
@@ -12362,7 +12362,7 @@ bool nsDocShell::HasUnloadedParent() {
}
void nsDocShell::UpdateGlobalHistoryTitle(nsIURI* aURI) {
if (!mUseGlobalHistory || UsePrivateBrowsing()) {
if (!mBrowsingContext->GetUseGlobalHistory() || UsePrivateBrowsing()) {
return;
}

View File

@@ -1263,7 +1263,6 @@ class nsDocShell final : public nsDocLoader,
bool mIsOffScreenBrowser : 1;
bool mDisableMetaRefreshWhenInactive : 1;
bool mIsAppTab : 1;
bool mUseGlobalHistory : 1;
bool mDeviceSizeIsPageSize : 1;
bool mWindowDraggingAllowed : 1;
bool mInFrameSwap : 1;