2019-05-03 21:12:55 +03: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 18:38:12 +03:00
|
|
|
#include "AutoplayPolicy.h"
|
2019-08-08 19:07:05 +03:00
|
|
|
#include "nsContentUtils.h"
|
2019-05-03 21:12:55 +03:00
|
|
|
#include "mozJSComponentLoader.h"
|
2020-03-06 19:36:01 +03:00
|
|
|
#include "mozilla/ContentBlockingAllowList.h"
|
2019-05-03 21:12:55 +03:00
|
|
|
#include "mozilla/Logging.h"
|
2020-04-30 19:42:53 +03:00
|
|
|
#include "mozilla/dom/JSActorService.h"
|
2019-05-22 19:56:19 +03:00
|
|
|
#include "mozilla/dom/JSWindowActorParent.h"
|
|
|
|
#include "mozilla/dom/JSWindowActorChild.h"
|
2020-07-08 17:22:22 +03:00
|
|
|
#include "mozilla/dom/JSWindowActorProtocol.h"
|
2020-08-12 18:38:12 +03:00
|
|
|
#include "mozilla/dom/PopupBlocker.h"
|
2020-05-27 03:27:30 +03:00
|
|
|
#include "mozilla/net/CookieJarSettings.h"
|
2019-05-03 21:12:55 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2020-05-11 21:41:16 +03: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 05:14:29 +03:00
|
|
|
return nsILoadInfo::EMBEDDER_POLICY_NULL;
|
2020-05-11 21:41:16 +03:00
|
|
|
}
|
|
|
|
|
2020-05-08 23:44:12 +03:00
|
|
|
// Common WindowGlobalInit creation code used by both `AboutBlankInitializer`
|
|
|
|
// and `WindowInitializer`.
|
2020-05-11 21:41:16 +03:00
|
|
|
WindowGlobalInit WindowGlobalActor::BaseInitializer(
|
|
|
|
dom::BrowsingContext* aBrowsingContext, uint64_t aInnerWindowId,
|
|
|
|
uint64_t aOuterWindowId) {
|
2020-05-08 23:44:12 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(aBrowsingContext);
|
|
|
|
|
|
|
|
WindowGlobalInit init;
|
|
|
|
auto& ctx = init.context();
|
|
|
|
ctx.mInnerWindowId = aInnerWindowId;
|
|
|
|
ctx.mOuterWindowId = aOuterWindowId;
|
|
|
|
ctx.mBrowsingContextId = aBrowsingContext->Id();
|
|
|
|
|
2020-05-11 21:41:16 +03:00
|
|
|
// If any synced fields need to be initialized from our BrowsingContext, we
|
|
|
|
// can initialize them here.
|
2020-07-22 17:07:26 +03:00
|
|
|
auto& fields = ctx.mFields;
|
|
|
|
fields.mEmbedderPolicy = InheritedPolicy(aBrowsingContext);
|
|
|
|
fields.mAutoplayPermission = nsIPermissionManager::UNKNOWN_ACTION;
|
2020-05-08 23:44:12 +03:00
|
|
|
return init;
|
|
|
|
}
|
|
|
|
|
2019-08-08 19:07:05 +03:00
|
|
|
WindowGlobalInit WindowGlobalActor::AboutBlankInitializer(
|
|
|
|
dom::BrowsingContext* aBrowsingContext, nsIPrincipal* aPrincipal) {
|
2020-05-08 23:44:12 +03:00
|
|
|
WindowGlobalInit init =
|
|
|
|
BaseInitializer(aBrowsingContext, nsContentUtils::GenerateWindowId(),
|
|
|
|
nsContentUtils::GenerateWindowId());
|
2019-08-08 19:07:05 +03:00
|
|
|
|
2020-05-08 23:44:12 +03:00
|
|
|
init.principal() = aPrincipal;
|
|
|
|
Unused << NS_NewURI(getter_AddRefs(init.documentURI()), "about:blank");
|
|
|
|
ContentBlockingAllowList::ComputePrincipal(
|
|
|
|
aPrincipal, getter_AddRefs(init.contentBlockingAllowListPrincipal()));
|
|
|
|
|
|
|
|
return init;
|
|
|
|
}
|
2019-08-08 19:07:05 +03:00
|
|
|
|
2020-05-08 23:44:12 +03:00
|
|
|
WindowGlobalInit WindowGlobalActor::WindowInitializer(
|
|
|
|
nsGlobalWindowInner* aWindow) {
|
|
|
|
WindowGlobalInit init =
|
|
|
|
BaseInitializer(aWindow->GetBrowsingContext(), aWindow->WindowID(),
|
|
|
|
aWindow->GetOuterWindow()->WindowID());
|
2019-08-08 19:07:05 +03:00
|
|
|
|
2020-05-08 23:44:12 +03:00
|
|
|
init.principal() = aWindow->GetPrincipal();
|
|
|
|
init.contentBlockingAllowListPrincipal() =
|
|
|
|
aWindow->GetDocumentContentBlockingAllowListPrincipal();
|
|
|
|
init.documentURI() = aWindow->GetDocumentURI();
|
2020-03-01 22:25:01 +03:00
|
|
|
|
2020-05-27 03:27:30 +03:00
|
|
|
Document* doc = aWindow->GetDocument();
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
2020-07-22 17:07:26 +03:00
|
|
|
auto& fields = init.context().mFields;
|
|
|
|
fields.mCookieBehavior = Some(doc->CookieJarSettings()->GetCookieBehavior());
|
|
|
|
fields.mIsOnContentBlockingAllowList =
|
2020-05-27 03:27:30 +03:00
|
|
|
doc->CookieJarSettings()->GetIsOnContentBlockingAllowList();
|
2020-07-22 17:07:26 +03:00
|
|
|
fields.mIsThirdPartyWindow = doc->HasThirdPartyChannel();
|
|
|
|
fields.mIsThirdPartyTrackingResourceWindow =
|
2020-05-27 03:27:30 +03:00
|
|
|
nsContentUtils::IsThirdPartyTrackingResourceWindow(aWindow);
|
2020-07-22 17:07:26 +03:00
|
|
|
fields.mIsSecureContext = aWindow->IsSecureContext();
|
2020-05-27 03:27:30 +03:00
|
|
|
|
2020-08-12 18:38:12 +03:00
|
|
|
// Initialze permission fields
|
|
|
|
fields.mAutoplayPermission =
|
|
|
|
AutoplayPolicy::GetSiteAutoplayPermission(init.principal());
|
|
|
|
fields.mPopupPermission = PopupBlocker::GetPopupPermission(init.principal());
|
|
|
|
|
|
|
|
// Initialize top level permission fields
|
|
|
|
if (aWindow->GetBrowsingContext()->IsTop()) {
|
|
|
|
fields.mShortcutsPermission =
|
|
|
|
nsGlobalWindowInner::GetShortcutsPermission(init.principal());
|
|
|
|
}
|
|
|
|
|
2020-06-25 05:14:29 +03:00
|
|
|
auto policy = doc->GetEmbedderPolicy();
|
2020-05-27 03:27:30 +03:00
|
|
|
if (policy.isSome()) {
|
2020-07-22 17:07:26 +03:00
|
|
|
fields.mEmbedderPolicy = *policy;
|
2020-05-27 03:27:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Init Mixed Content Fields
|
2020-06-16 12:05:54 +03:00
|
|
|
nsCOMPtr<nsIURI> innerDocURI = NS_GetInnermostURI(doc->GetDocumentURI());
|
|
|
|
if (innerDocURI) {
|
2020-07-22 17:07:26 +03:00
|
|
|
fields.mIsSecure = innerDocURI->SchemeIs("https");
|
2020-06-16 12:05:54 +03:00
|
|
|
}
|
2020-05-27 03:27:30 +03:00
|
|
|
nsCOMPtr<nsIChannel> mixedChannel;
|
|
|
|
aWindow->GetDocShell()->GetMixedContentChannel(getter_AddRefs(mixedChannel));
|
|
|
|
// A non null mixedContent channel on the docshell indicates,
|
|
|
|
// that the user has overriden mixed content to allow mixed
|
|
|
|
// content loads to happen.
|
|
|
|
if (mixedChannel && (mixedChannel == doc->GetChannel())) {
|
2020-07-22 17:07:26 +03:00
|
|
|
fields.mAllowMixedContent = true;
|
2020-05-27 03:27:30 +03:00
|
|
|
}
|
|
|
|
|
2020-05-27 03:28:59 +03:00
|
|
|
nsCOMPtr<nsITransportSecurityInfo> securityInfo;
|
|
|
|
if (nsCOMPtr<nsIChannel> channel = doc->GetChannel()) {
|
2020-09-22 20:41:34 +03:00
|
|
|
nsCOMPtr<nsILoadInfo> loadInfo(channel->LoadInfo());
|
|
|
|
fields.mIsOriginalFrameSource = loadInfo->GetOriginalFrameSrcLoad();
|
|
|
|
|
2020-05-27 03:28:59 +03:00
|
|
|
nsCOMPtr<nsISupports> securityInfoSupports;
|
|
|
|
channel->GetSecurityInfo(getter_AddRefs(securityInfoSupports));
|
|
|
|
securityInfo = do_QueryInterface(securityInfoSupports);
|
|
|
|
}
|
|
|
|
init.securityInfo() = securityInfo;
|
|
|
|
|
2020-05-27 03:27:30 +03: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 23:44:12 +03:00
|
|
|
return init;
|
2019-08-08 19:07:05 +03:00
|
|
|
}
|
|
|
|
|
2020-07-08 17:22:22 +03:00
|
|
|
already_AddRefed<JSActorProtocol> WindowGlobalActor::MatchingJSActorProtocol(
|
|
|
|
JSActorService* aActorSvc, const nsACString& aName, ErrorResult& aRv) {
|
2020-04-30 19:42:53 +03:00
|
|
|
RefPtr<JSWindowActorProtocol> proto =
|
2020-07-08 17:22:22 +03:00
|
|
|
aActorSvc->GetJSWindowActorProtocol(aName);
|
2019-05-03 21:12:55 +03:00
|
|
|
if (!proto) {
|
2020-07-08 17:22:22 +03:00
|
|
|
aRv.ThrowNotFoundError(nsPrintfCString("No such JSWindowActor '%s'",
|
|
|
|
PromiseFlatCString(aName).get()));
|
|
|
|
return nullptr;
|
2019-05-03 21:12:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!proto->Matches(BrowsingContext(), GetDocumentURI(), GetRemoteType())) {
|
|
|
|
aRv.Throw(NS_ERROR_NOT_AVAILABLE);
|
2020-07-08 17:22:22 +03:00
|
|
|
return nullptr;
|
2019-05-03 21:12:55 +03:00
|
|
|
}
|
2020-07-08 17:22:22 +03:00
|
|
|
return proto.forget();
|
2019-05-03 21:12:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace dom
|
2019-08-08 19:07:05 +03:00
|
|
|
} // namespace mozilla
|