2019-05-03 18:12:55 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "mozilla/dom/WindowGlobalActor.h"
|
|
|
|
|
2020-08-12 15:38:12 +00:00
|
|
|
#include "AutoplayPolicy.h"
|
2019-08-08 16:07:05 +00:00
|
|
|
#include "nsContentUtils.h"
|
2021-04-12 18:04:12 +00:00
|
|
|
#include "mozilla/Components.h"
|
2020-03-06 16:36:01 +00:00
|
|
|
#include "mozilla/ContentBlockingAllowList.h"
|
2019-05-03 18:12:55 +00:00
|
|
|
#include "mozilla/Logging.h"
|
2020-11-23 16:21:38 +00:00
|
|
|
#include "mozilla/dom/Document.h"
|
2020-04-30 16:42:53 +00:00
|
|
|
#include "mozilla/dom/JSActorService.h"
|
2019-05-22 16:56:19 +00:00
|
|
|
#include "mozilla/dom/JSWindowActorParent.h"
|
|
|
|
#include "mozilla/dom/JSWindowActorChild.h"
|
2020-07-08 14:22:22 +00:00
|
|
|
#include "mozilla/dom/JSWindowActorProtocol.h"
|
2020-08-12 15:38:12 +00:00
|
|
|
#include "mozilla/dom/PopupBlocker.h"
|
2020-05-27 00:27:30 +00:00
|
|
|
#include "mozilla/net/CookieJarSettings.h"
|
2023-03-29 13:00:15 +00:00
|
|
|
#include "mozilla/dom/WindowContext.h"
|
2020-10-28 12:31:35 +00:00
|
|
|
#include "mozilla/dom/WindowGlobalChild.h"
|
|
|
|
#include "mozilla/dom/WindowGlobalParent.h"
|
|
|
|
|
|
|
|
#include "nsGlobalWindowInner.h"
|
2020-11-23 16:21:38 +00:00
|
|
|
#include "nsNetUtil.h"
|
2019-05-03 18:12:55 +00:00
|
|
|
|
2020-11-04 17:04:01 +00:00
|
|
|
namespace mozilla::dom {
|
2019-05-03 18:12:55 +00:00
|
|
|
|
2020-05-11 18:41:16 +00:00
|
|
|
// CORPP 3.1.3 https://mikewest.github.io/corpp/#integration-html
|
|
|
|
static nsILoadInfo::CrossOriginEmbedderPolicy InheritedPolicy(
|
|
|
|
dom::BrowsingContext* aBrowsingContext) {
|
|
|
|
WindowContext* inherit = aBrowsingContext->GetParentWindowContext();
|
|
|
|
if (inherit) {
|
|
|
|
return inherit->GetEmbedderPolicy();
|
|
|
|
}
|
|
|
|
|
2020-06-25 02:14:29 +00:00
|
|
|
return nsILoadInfo::EMBEDDER_POLICY_NULL;
|
2020-05-11 18:41:16 +00:00
|
|
|
}
|
|
|
|
|
2020-05-08 20:44:12 +00:00
|
|
|
// Common WindowGlobalInit creation code used by both `AboutBlankInitializer`
|
|
|
|
// and `WindowInitializer`.
|
2020-05-11 18:41:16 +00:00
|
|
|
WindowGlobalInit WindowGlobalActor::BaseInitializer(
|
|
|
|
dom::BrowsingContext* aBrowsingContext, uint64_t aInnerWindowId,
|
|
|
|
uint64_t aOuterWindowId) {
|
2020-05-08 20:44:12 +00:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(aBrowsingContext);
|
|
|
|
|
2023-03-29 13:00:15 +00:00
|
|
|
using Indexes = WindowContext::FieldIndexes;
|
|
|
|
|
2020-05-08 20:44:12 +00:00
|
|
|
WindowGlobalInit init;
|
|
|
|
auto& ctx = init.context();
|
|
|
|
ctx.mInnerWindowId = aInnerWindowId;
|
|
|
|
ctx.mOuterWindowId = aOuterWindowId;
|
|
|
|
ctx.mBrowsingContextId = aBrowsingContext->Id();
|
|
|
|
|
2020-05-11 18:41:16 +00:00
|
|
|
// If any synced fields need to be initialized from our BrowsingContext, we
|
|
|
|
// can initialize them here.
|
2020-07-22 14:07:26 +00:00
|
|
|
auto& fields = ctx.mFields;
|
2023-03-29 13:00:15 +00:00
|
|
|
fields.Get<Indexes::IDX_EmbedderPolicy>() = InheritedPolicy(aBrowsingContext);
|
|
|
|
fields.Get<Indexes::IDX_AutoplayPermission>() =
|
|
|
|
nsIPermissionManager::UNKNOWN_ACTION;
|
|
|
|
fields.Get<Indexes::IDX_AllowJavascript>() = true;
|
2020-05-08 20:44:12 +00:00
|
|
|
return init;
|
|
|
|
}
|
|
|
|
|
2019-08-08 16:07:05 +00:00
|
|
|
WindowGlobalInit WindowGlobalActor::AboutBlankInitializer(
|
|
|
|
dom::BrowsingContext* aBrowsingContext, nsIPrincipal* aPrincipal) {
|
2020-05-08 20:44:12 +00:00
|
|
|
WindowGlobalInit init =
|
|
|
|
BaseInitializer(aBrowsingContext, nsContentUtils::GenerateWindowId(),
|
|
|
|
nsContentUtils::GenerateWindowId());
|
2019-08-08 16:07:05 +00:00
|
|
|
|
2020-05-08 20:44:12 +00:00
|
|
|
init.principal() = aPrincipal;
|
2021-05-26 07:14:03 +00:00
|
|
|
init.storagePrincipal() = aPrincipal;
|
2020-05-08 20:44:12 +00:00
|
|
|
Unused << NS_NewURI(getter_AddRefs(init.documentURI()), "about:blank");
|
2021-07-14 15:51:20 +00:00
|
|
|
init.isInitialDocument() = true;
|
2020-05-08 20:44:12 +00:00
|
|
|
|
|
|
|
return init;
|
|
|
|
}
|
2019-08-08 16:07:05 +00:00
|
|
|
|
2020-05-08 20:44:12 +00:00
|
|
|
WindowGlobalInit WindowGlobalActor::WindowInitializer(
|
|
|
|
nsGlobalWindowInner* aWindow) {
|
|
|
|
WindowGlobalInit init =
|
|
|
|
BaseInitializer(aWindow->GetBrowsingContext(), aWindow->WindowID(),
|
|
|
|
aWindow->GetOuterWindow()->WindowID());
|
2019-08-08 16:07:05 +00:00
|
|
|
|
2020-05-08 20:44:12 +00:00
|
|
|
init.principal() = aWindow->GetPrincipal();
|
2021-05-26 07:14:03 +00:00
|
|
|
init.storagePrincipal() = aWindow->GetEffectiveStoragePrincipal();
|
2020-05-08 20:44:12 +00:00
|
|
|
init.documentURI() = aWindow->GetDocumentURI();
|
2020-03-01 19:25:01 +00:00
|
|
|
|
2020-05-27 00:27:30 +00:00
|
|
|
Document* doc = aWindow->GetDocument();
|
|
|
|
|
2021-07-14 15:51:20 +00:00
|
|
|
init.isInitialDocument() = doc->IsInitialDocument();
|
2020-05-27 00:27:30 +00:00
|
|
|
init.blockAllMixedContent() = doc->GetBlockAllMixedContent(false);
|
|
|
|
init.upgradeInsecureRequests() = doc->GetUpgradeInsecureRequests(false);
|
|
|
|
init.sandboxFlags() = doc->GetSandboxFlags();
|
|
|
|
net::CookieJarSettings::Cast(doc->CookieJarSettings())
|
|
|
|
->Serialize(init.cookieJarSettings());
|
|
|
|
init.httpsOnlyStatus() = doc->HttpsOnlyStatus();
|
|
|
|
|
2023-03-29 13:00:15 +00:00
|
|
|
using Indexes = WindowContext::FieldIndexes;
|
|
|
|
|
2020-07-22 14:07:26 +00:00
|
|
|
auto& fields = init.context().mFields;
|
2023-03-29 13:00:15 +00:00
|
|
|
fields.Get<Indexes::IDX_CookieBehavior>() =
|
|
|
|
Some(doc->CookieJarSettings()->GetCookieBehavior());
|
|
|
|
fields.Get<Indexes::IDX_IsOnContentBlockingAllowList>() =
|
2020-05-27 00:27:30 +00:00
|
|
|
doc->CookieJarSettings()->GetIsOnContentBlockingAllowList();
|
2023-03-29 13:00:15 +00:00
|
|
|
fields.Get<Indexes::IDX_IsThirdPartyWindow>() = doc->HasThirdPartyChannel();
|
|
|
|
fields.Get<Indexes::IDX_IsThirdPartyTrackingResourceWindow>() =
|
2020-05-27 00:27:30 +00:00
|
|
|
nsContentUtils::IsThirdPartyTrackingResourceWindow(aWindow);
|
2023-03-29 13:00:15 +00:00
|
|
|
fields.Get<Indexes::IDX_ShouldResistFingerprinting>() =
|
2023-05-31 09:46:54 +00:00
|
|
|
doc->ShouldResistFingerprinting(RFPTarget::IsAlwaysEnabledForPrecompute);
|
2023-10-17 22:02:29 +00:00
|
|
|
fields.Get<Indexes::IDX_OverriddenFingerprintingSettings>() =
|
|
|
|
doc->GetOverriddenFingerprintingSettings();
|
2023-03-29 13:00:15 +00:00
|
|
|
fields.Get<Indexes::IDX_IsSecureContext>() = aWindow->IsSecureContext();
|
2020-05-27 00:27:30 +00:00
|
|
|
|
2020-08-12 15:38:12 +00:00
|
|
|
// Initialze permission fields
|
2023-03-29 13:00:15 +00:00
|
|
|
fields.Get<Indexes::IDX_AutoplayPermission>() =
|
2022-12-19 20:57:54 +00:00
|
|
|
media::AutoplayPolicy::GetSiteAutoplayPermission(init.principal());
|
2023-03-29 13:00:15 +00:00
|
|
|
fields.Get<Indexes::IDX_PopupPermission>() =
|
|
|
|
PopupBlocker::GetPopupPermission(init.principal());
|
2020-08-12 15:38:12 +00:00
|
|
|
|
|
|
|
// Initialize top level permission fields
|
|
|
|
if (aWindow->GetBrowsingContext()->IsTop()) {
|
2023-03-29 13:00:15 +00:00
|
|
|
fields.Get<Indexes::IDX_AllowMixedContent>() = [&] {
|
2021-04-12 18:04:12 +00:00
|
|
|
uint32_t permit = nsIPermissionManager::UNKNOWN_ACTION;
|
|
|
|
nsCOMPtr<nsIPermissionManager> permissionManager =
|
|
|
|
components::PermissionManager::Service();
|
|
|
|
|
|
|
|
if (permissionManager) {
|
|
|
|
permissionManager->TestPermissionFromPrincipal(
|
|
|
|
init.principal(), "mixed-content"_ns, &permit);
|
|
|
|
}
|
|
|
|
|
|
|
|
return permit == nsIPermissionManager::ALLOW_ACTION;
|
|
|
|
}();
|
|
|
|
|
2023-03-29 13:00:15 +00:00
|
|
|
fields.Get<Indexes::IDX_ShortcutsPermission>() =
|
2020-08-12 15:38:12 +00:00
|
|
|
nsGlobalWindowInner::GetShortcutsPermission(init.principal());
|
|
|
|
}
|
|
|
|
|
2021-04-12 18:04:12 +00:00
|
|
|
if (auto policy = doc->GetEmbedderPolicy()) {
|
2023-03-29 13:00:15 +00:00
|
|
|
fields.Get<Indexes::IDX_EmbedderPolicy>() = *policy;
|
2020-05-27 00:27:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Init Mixed Content Fields
|
2020-06-16 09:05:54 +00:00
|
|
|
nsCOMPtr<nsIURI> innerDocURI = NS_GetInnermostURI(doc->GetDocumentURI());
|
2023-03-29 13:00:15 +00:00
|
|
|
fields.Get<Indexes::IDX_IsSecure>() =
|
|
|
|
innerDocURI && innerDocURI->SchemeIs("https");
|
2020-05-27 00:27:30 +00:00
|
|
|
|
2020-05-27 00:28:59 +00:00
|
|
|
nsCOMPtr<nsITransportSecurityInfo> securityInfo;
|
|
|
|
if (nsCOMPtr<nsIChannel> channel = doc->GetChannel()) {
|
2020-09-22 17:41:34 +00:00
|
|
|
nsCOMPtr<nsILoadInfo> loadInfo(channel->LoadInfo());
|
2023-03-29 13:00:15 +00:00
|
|
|
fields.Get<Indexes::IDX_IsOriginalFrameSource>() =
|
|
|
|
loadInfo->GetOriginalFrameSrcLoad();
|
2023-09-21 01:48:49 +00:00
|
|
|
fields.Get<Indexes::IDX_UsingStorageAccess>() =
|
|
|
|
loadInfo->GetStoragePermission() != nsILoadInfo::NoStoragePermission;
|
2020-09-22 17:41:34 +00:00
|
|
|
|
2022-09-20 03:58:49 +00:00
|
|
|
channel->GetSecurityInfo(getter_AddRefs(securityInfo));
|
2020-05-27 00:28:59 +00:00
|
|
|
}
|
|
|
|
init.securityInfo() = securityInfo;
|
|
|
|
|
2023-03-29 13:00:15 +00:00
|
|
|
fields.Get<Indexes::IDX_IsLocalIP>() =
|
|
|
|
init.principal()->GetIsLocalIpAddress();
|
2020-12-10 20:45:54 +00:00
|
|
|
|
2020-05-27 00:27:30 +00:00
|
|
|
// Most data here is specific to the Document, which can change without
|
|
|
|
// creating a new WindowGlobal. Anything new added here which fits that
|
|
|
|
// description should also be synchronized in
|
|
|
|
// WindowGlobalChild::OnNewDocument.
|
2020-05-08 20:44:12 +00:00
|
|
|
return init;
|
2019-08-08 16:07:05 +00:00
|
|
|
}
|
|
|
|
|
2020-07-08 14:22:22 +00:00
|
|
|
already_AddRefed<JSActorProtocol> WindowGlobalActor::MatchingJSActorProtocol(
|
|
|
|
JSActorService* aActorSvc, const nsACString& aName, ErrorResult& aRv) {
|
2020-04-30 16:42:53 +00:00
|
|
|
RefPtr<JSWindowActorProtocol> proto =
|
2020-07-08 14:22:22 +00:00
|
|
|
aActorSvc->GetJSWindowActorProtocol(aName);
|
2019-05-03 18:12:55 +00:00
|
|
|
if (!proto) {
|
2020-07-08 14:22:22 +00:00
|
|
|
aRv.ThrowNotFoundError(nsPrintfCString("No such JSWindowActor '%s'",
|
|
|
|
PromiseFlatCString(aName).get()));
|
|
|
|
return nullptr;
|
2019-05-03 18:12:55 +00:00
|
|
|
}
|
|
|
|
|
2020-11-16 21:18:49 +00:00
|
|
|
if (!proto->Matches(BrowsingContext(), GetDocumentURI(), GetRemoteType(),
|
|
|
|
aRv)) {
|
|
|
|
MOZ_ASSERT(aRv.Failed());
|
2020-07-08 14:22:22 +00:00
|
|
|
return nullptr;
|
2019-05-03 18:12:55 +00:00
|
|
|
}
|
2020-11-16 21:18:49 +00:00
|
|
|
MOZ_ASSERT(!aRv.Failed());
|
2020-07-08 14:22:22 +00:00
|
|
|
return proto.forget();
|
2019-05-03 18:12:55 +00:00
|
|
|
}
|
|
|
|
|
2020-11-04 17:04:01 +00:00
|
|
|
} // namespace mozilla::dom
|