Bug 1623565 - P1: Move defaultLoadFlags to BrowsingContext. r=nika

Differential Revision: https://phabricator.services.mozilla.com/D67796
This commit is contained in:
Dan Glastonbury 2020-04-27 05:37:59 +00:00
Родитель 6adf2b375d
Коммит a48830f2b3
4 изменённых файлов: 62 добавлений и 35 удалений

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

@ -292,6 +292,10 @@ already_AddRefed<BrowsingContext> BrowsingContext::CreateDetached(
const bool allowPlugins = inherit ? inherit->GetAllowPlugins() : true;
context->mFields.SetWithoutSyncing<IDX_AllowPlugins>(allowPlugins);
const auto defaultLoadFlags =
inherit ? inherit->GetDefaultLoadFlags() : nsIRequest::LOAD_NORMAL;
context->mFields.SetWithoutSyncing<IDX_DefaultLoadFlags>(defaultLoadFlags);
return context.forget();
}
@ -1875,6 +1879,29 @@ bool BrowsingContext::CanSet(FieldIndex<IDX_WatchedByDevtools>,
return CheckOnlyOwningProcessCanSet(aSource);
}
bool BrowsingContext::CanSet(FieldIndex<IDX_DefaultLoadFlags>,
const uint32_t& aDefaultLoadFlags,
ContentParent* aSource) {
// Bug 1623565 - Are these flags only used by the debugger, which makes it
// possible that this field can only be settable by the parent process?
return CheckOnlyOwningProcessCanSet(aSource);
}
void BrowsingContext::DidSet(FieldIndex<IDX_DefaultLoadFlags>) {
auto loadFlags = GetDefaultLoadFlags();
if (GetDocShell()) {
nsDocShell::Cast(GetDocShell())->SetLoadGroupDefaultLoadFlags(loadFlags);
}
if (XRE_IsParentProcess()) {
PreOrderWalk([&](BrowsingContext* aContext) {
if (aContext != this) {
aContext->SetDefaultLoadFlags(loadFlags);
}
});
}
}
bool BrowsingContext::CanSet(FieldIndex<IDX_UserAgentOverride>,
const nsString& aUserAgent,
ContentParent* aSource) {

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

@ -128,7 +128,9 @@ class WindowProxyHolder;
FIELD(MaxTouchPointsOverride, uint8_t) \
FIELD(FullZoom, float) \
FIELD(WatchedByDevtools, bool) \
FIELD(TextZoom, float)
FIELD(TextZoom, float) \
/* See nsIRequest for possible flags. */ \
FIELD(DefaultLoadFlags, uint32_t)
// BrowsingContext, in this context, is the cross process replicated
// environment in which information about documents is stored. In
@ -710,6 +712,10 @@ class BrowsingContext : public nsILoadContext, public nsWrapperCache {
bool CanSet(FieldIndex<IDX_WatchedByDevtools>, const bool& aWatchedByDevtools,
ContentParent* aSource);
bool CanSet(FieldIndex<IDX_DefaultLoadFlags>,
const uint32_t& aDefaultLoadFlags, ContentParent* aSource);
void DidSet(FieldIndex<IDX_DefaultLoadFlags>);
template <size_t I, typename T>
bool CanSet(FieldIndex<I>, const T&, ContentParent*) {
return true;

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

@ -351,7 +351,6 @@ nsDocShell::nsDocShell(BrowsingContext* aBrowsingContext,
mBusyFlags(BUSY_FLAGS_NONE),
mAppType(nsIDocShell::APP_TYPE_UNKNOWN),
mLoadType(0),
mDefaultLoadFlags(nsIRequest::LOAD_NORMAL),
mFailedLoadType(0),
mDisplayMode(nsIDocShell::DISPLAY_MODE_BROWSER),
mJSRunToCompletionDepth(0),
@ -521,6 +520,9 @@ already_AddRefed<nsDocShell> nsDocShell::Create(
// Make |ds| the primary DocShell for the given context.
aBrowsingContext->SetDocShell(ds);
// Set |ds| default load flags on load group.
ds->SetLoadGroupDefaultLoadFlags(aBrowsingContext->GetDefaultLoadFlags());
return ds.forget();
}
@ -725,11 +727,13 @@ nsDocShell::LoadURI(nsDocShellLoadState* aLoadState, bool aSetNavigating) {
return NS_OK; // JS may not handle returning of an error code
}
nsLoadFlags defaultLoadFlags = mBrowsingContext->GetDefaultLoadFlags();
if (aLoadState->LoadFlags() & LOAD_FLAGS_FORCE_TRR) {
mDefaultLoadFlags |= nsIRequest::LOAD_TRR_ONLY_MODE;
defaultLoadFlags |= nsIRequest::LOAD_TRR_ONLY_MODE;
} else if (aLoadState->LoadFlags() & LOAD_FLAGS_DISABLE_TRR) {
mDefaultLoadFlags |= nsIRequest::LOAD_TRR_DISABLED_MODE;
defaultLoadFlags |= nsIRequest::LOAD_TRR_DISABLED_MODE;
}
mBrowsingContext->SetDefaultLoadFlags(defaultLoadFlags);
if (!StartupTimeline::HasRecord(StartupTimeline::FIRST_LOAD_URI) &&
mItemType == typeContent && !NS_IsAboutBlank(aLoadState->URI())) {
@ -2576,10 +2580,6 @@ nsresult nsDocShell::SetDocLoaderParent(nsDocLoader* aParent) {
SetAllowDNSPrefetch(mAllowDNSPrefetch && value);
SetAffectPrivateSessionLifetime(
parentAsDocShell->GetAffectPrivateSessionLifetime());
uint32_t flags;
if (NS_SUCCEEDED(parentAsDocShell->GetDefaultLoadFlags(&flags))) {
SetDefaultLoadFlags(flags);
}
SetTouchEventsOverride(parentAsDocShell->GetTouchEventsOverride());
@ -3079,6 +3079,16 @@ NS_IMETHODIMP nsDocShell::SynchronizeLayoutHistoryState() {
return NS_OK;
}
void nsDocShell::SetLoadGroupDefaultLoadFlags(nsLoadFlags aLoadFlags) {
if (mLoadGroup) {
mLoadGroup->SetDefaultLoadFlags(aLoadFlags);
} else {
NS_WARNING(
"nsDocShell::SetLoadGroupDefaultLoadFlags has no loadGroup to "
"propagate the mode to");
}
}
nsIScriptGlobalObject* nsDocShell::GetScriptGlobalObject() {
NS_ENSURE_SUCCESS(EnsureScriptEnvironment(), nullptr);
return mScriptGlobal;
@ -4737,34 +4747,19 @@ nsDocShell::GetIsAppTab(bool* aIsAppTab) {
NS_IMETHODIMP
nsDocShell::SetDefaultLoadFlags(uint32_t aDefaultLoadFlags) {
mDefaultLoadFlags = aDefaultLoadFlags;
// Tell the load group to set these flags all requests in the group
if (mLoadGroup) {
mLoadGroup->SetDefaultLoadFlags(aDefaultLoadFlags);
if (!mWillChangeProcess) {
mBrowsingContext->SetDefaultLoadFlags(aDefaultLoadFlags);
} else {
NS_WARNING(
"nsDocShell::SetDefaultLoadFlags has no loadGroup to propagate the "
"flags to");
}
// Recursively tell all of our children. We *do not* skip
// <iframe mozbrowser> children - if someone sticks custom flags in this
// docShell then they too get the same flags.
nsTObserverArray<nsDocLoader*>::ForwardIterator iter(mChildList);
while (iter.HasMore()) {
nsCOMPtr<nsIDocShell> docshell = do_QueryObject(iter.GetNext());
if (!docshell) {
continue;
}
docshell->SetDefaultLoadFlags(aDefaultLoadFlags);
// Bug 1623565: DevTools tries to clean up defaultLoadFlags on
// shutdown. Sorry DevTools, your DocShell is in another process.
NS_WARNING("nsDocShell::SetDefaultLoadFlags called on Zombie DocShell");
}
return NS_OK;
}
NS_IMETHODIMP
nsDocShell::GetDefaultLoadFlags(uint32_t* aDefaultLoadFlags) {
*aDefaultLoadFlags = mDefaultLoadFlags;
*aDefaultLoadFlags = mBrowsingContext->GetDefaultLoadFlags();
return NS_OK;
}
@ -7305,9 +7300,6 @@ nsresult nsDocShell::RestoreFromHistory() {
bool allowContentRetargetingOnChildren =
childShell->GetAllowContentRetargetingOnChildren();
uint32_t defaultLoadFlags;
childShell->GetDefaultLoadFlags(&defaultLoadFlags);
// this.AddChild(child) calls child.SetDocLoaderParent(this), meaning that
// the child inherits our state. Among other things, this means that the
// child inherits our mPrivateBrowsingId, which is what we want.
@ -7322,7 +7314,6 @@ nsresult nsDocShell::RestoreFromHistory() {
childShell->SetAllowContentRetargeting(allowContentRetargeting);
childShell->SetAllowContentRetargetingOnChildren(
allowContentRetargetingOnChildren);
childShell->SetDefaultLoadFlags(defaultLoadFlags);
rv = childShell->BeginRestore(nullptr, false);
NS_ENSURE_SUCCESS(rv, rv);
@ -9670,7 +9661,7 @@ nsresult nsDocShell::DoURILoad(nsDocShellLoadState* aLoadState,
inheritPrincipal = inheritAttrs && !isURIUniqueOrigin;
}
nsLoadFlags loadFlags = mDefaultLoadFlags;
nsLoadFlags loadFlags = mBrowsingContext->GetDefaultLoadFlags();
nsSecurityFlags securityFlags =
nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL;
uint32_t sandboxFlags = mBrowsingContext->GetSandboxFlags();

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

@ -1072,6 +1072,10 @@ class nsDocShell final : public nsDocLoader,
// Called when the Private Browsing state of a nsDocShell changes.
void NotifyPrivateBrowsingChanged();
// Internal helpers for BrowsingContext to pass update values to nsIDocShell's
// LoadGroup.
void SetLoadGroupDefaultLoadFlags(nsLoadFlags aLoadFlags);
private: // data members
nsID mHistoryID;
nsString mTitle;
@ -1206,7 +1210,6 @@ class nsDocShell final : public nsDocLoader,
BusyFlags mBusyFlags;
AppType mAppType;
uint32_t mLoadType;
uint32_t mDefaultLoadFlags;
uint32_t mFailedLoadType;
// This represents the CSS display-mode we are currently using. This is mostly