Bug 1598131 - Propagate the browsingContext's COEP to the new created one in nsFrameLoader::Recreate r=farre

The COEP header needs to propagate to the new created BrowsingContext for process switching.

Differential Revision: https://phabricator.services.mozilla.com/D69936
This commit is contained in:
Eden Chuang 2020-04-17 11:29:13 +00:00
Родитель 5bffe12d30
Коммит f519d74b3b
6 изменённых файлов: 47 добавлений и 21 удалений

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

@ -413,7 +413,7 @@ already_AddRefed<nsFrameLoader> nsFrameLoader::Create(
/* static */
already_AddRefed<nsFrameLoader> nsFrameLoader::Recreate(
mozilla::dom::Element* aOwner, BrowsingContext* aContext,
const nsAString& aRemoteType, bool aNetworkCreated) {
const nsAString& aRemoteType, bool aNetworkCreated, bool aPreserveContext) {
NS_ENSURE_TRUE(aOwner, nullptr);
#ifdef DEBUG
@ -426,11 +426,16 @@ already_AddRefed<nsFrameLoader> nsFrameLoader::Recreate(
#endif
RefPtr<BrowsingContext> context = aContext;
if (!context) {
if (!context || !aPreserveContext) {
context = CreateBrowsingContext(aOwner, /* openWindowInfo */ nullptr);
}
NS_ENSURE_TRUE(context, nullptr);
// aContext is not preserved, propagate its COEP to the new created.
if (aContext && !aPreserveContext) {
context->SetEmbedderPolicy(aContext->GetEmbedderPolicy());
}
RefPtr<nsFrameLoader> fl =
new nsFrameLoader(aOwner, context, aRemoteType, aNetworkCreated);
return fl.forget();

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

@ -111,7 +111,8 @@ class nsFrameLoader final : public nsStubMutationObserver,
static already_AddRefed<nsFrameLoader> Recreate(Element* aOwner,
BrowsingContext* aContext,
const nsAString& aRemoteType,
bool aNetworkCreated);
bool aNetworkCreated,
bool aPreserveContext);
NS_DECLARE_STATIC_IID_ACCESSOR(NS_FRAMELOADER_IID)

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

@ -74,9 +74,9 @@ bool nsFrameLoaderOwner::ShouldPreserveBrowsingContext(
}
void nsFrameLoaderOwner::ChangeRemotenessCommon(
bool aPreserveContext, bool aSwitchingInProgressLoad,
const nsAString& aRemoteType, std::function<void()>& aFrameLoaderInit,
mozilla::ErrorResult& aRv) {
const ChangeRemotenessContextType& aContextType,
bool aSwitchingInProgressLoad, const nsAString& aRemoteType,
std::function<void()>& aFrameLoaderInit, mozilla::ErrorResult& aRv) {
RefPtr<mozilla::dom::BrowsingContext> bc;
bool networkCreated = false;
@ -105,9 +105,11 @@ void nsFrameLoaderOwner::ChangeRemotenessCommon(
// If we already have a Frameloader, destroy it, possibly preserving its
// browsing context.
if (mFrameLoader) {
if (aPreserveContext) {
if (aContextType != ChangeRemotenessContextType::DONT_PRESERVE) {
bc = mFrameLoader->GetBrowsingContext();
mFrameLoader->SetWillChangeProcess();
if (aContextType == ChangeRemotenessContextType::PRESERVE) {
mFrameLoader->SetWillChangeProcess();
}
}
// Preserve the networkCreated status, as nsDocShells created after a
@ -117,8 +119,9 @@ void nsFrameLoaderOwner::ChangeRemotenessCommon(
mFrameLoader = nullptr;
}
mFrameLoader =
nsFrameLoader::Recreate(owner, bc, aRemoteType, networkCreated);
mFrameLoader = nsFrameLoader::Recreate(
owner, bc, aRemoteType, networkCreated,
aContextType == ChangeRemotenessContextType::PRESERVE);
if (NS_WARN_IF(!mFrameLoader)) {
aRv.Throw(NS_ERROR_FAILURE);
return;
@ -204,8 +207,15 @@ void nsFrameLoaderOwner::ChangeRemoteness(
}
};
ChangeRemotenessCommon(ShouldPreserveBrowsingContext(aOptions),
aOptions.mSwitchingInProgressLoad,
ChangeRemotenessContextType preserveType =
ChangeRemotenessContextType::DONT_PRESERVE;
if (ShouldPreserveBrowsingContext(aOptions)) {
preserveType = ChangeRemotenessContextType::PRESERVE;
} else if (aOptions.mReplaceBrowsingContext) {
preserveType = ChangeRemotenessContextType::DONT_PRESERVE_BUT_PROPAGATE;
}
ChangeRemotenessCommon(preserveType, aOptions.mSwitchingInProgressLoad,
aOptions.mRemoteType, frameLoaderInit, rv);
}
@ -227,6 +237,7 @@ void nsFrameLoaderOwner::ChangeRemotenessWithBridge(BrowserBridgeChild* aBridge,
// NOTE: We always use the DEFAULT_REMOTE_TYPE here, because we don't actually
// know the real remote type, and don't need to, as we're a content process.
ChangeRemotenessCommon(
/* preserve */ true, /* switching in progress load */ true,
/* preserve */ ChangeRemotenessContextType::PRESERVE,
/* switching in progress load */ true,
NS_LITERAL_STRING(DEFAULT_REMOTE_TYPE), frameLoaderInit, rv);
}

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

@ -60,7 +60,22 @@ class nsFrameLoaderOwner : public nsISupports {
bool UseRemoteSubframes();
bool ShouldPreserveBrowsingContext(
const mozilla::dom::RemotenessOptions& aOptions);
void ChangeRemotenessCommon(bool aPreserveContext,
// The enum class for determine how to handle previous BrowsingContext during
// the change remoteness. It could be followings
// 1. DONT_PRESERVE
// Create a whole new BrowsingContext.
// 2. DONT_PRESERVE_BUT_PROPAGETE
// Create a whole new BrowsingContext, but propagate necessary feilds from
// previous BrowsingContext, i.e. COEP.
// 3. PRESERVE
// Preserve the previous BrowsingContext.
enum class ChangeRemotenessContextType {
DONT_PRESERVE = 0,
DONT_PRESERVE_BUT_PROPAGATE = 1,
PRESERVE = 2,
};
void ChangeRemotenessCommon(const ChangeRemotenessContextType& aContextType,
bool aSwitchingInProgressLoad,
const nsAString& aRemoteType,
std::function<void()>& aFrameLoaderInit,

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

@ -1,10 +1,3 @@
[coep-blob-popup.https.html]
[COOP+COEP blob URL popup: <a rel=noopener>]
expected: FAIL
[COOP+COEP blob URL popup: window.open()]
expected: FAIL
[COOP+COEP blob URL popup: <a>]
expected: FAIL

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

@ -0,0 +1 @@
Cross-Origin-Embedder-Policy: require-corp