2018-07-26 10:31:00 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* 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/. */
|
|
|
|
|
2018-10-20 01:00:59 +03:00
|
|
|
#include "mozilla/dom/BrowsingContext.h"
|
2018-07-26 10:31:00 +03:00
|
|
|
|
2019-02-21 23:14:28 +03:00
|
|
|
#include "ipc/IPCMessageUtils.h"
|
|
|
|
|
2020-12-11 18:43:19 +03:00
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
# include "mozilla/a11y/DocAccessibleParent.h"
|
|
|
|
# include "mozilla/a11y/Platform.h"
|
|
|
|
# include "mozilla/a11y/ProxyAccessibleBase.h"
|
|
|
|
# include "nsAccessibilityService.h"
|
|
|
|
# if defined(XP_WIN)
|
|
|
|
# include "mozilla/a11y/AccessibleWrap.h"
|
|
|
|
# include "mozilla/a11y/Compatibility.h"
|
|
|
|
# include "mozilla/a11y/nsWinUtils.h"
|
|
|
|
# endif
|
|
|
|
#endif
|
2019-01-29 20:32:28 +03:00
|
|
|
#include "mozilla/dom/CanonicalBrowsingContext.h"
|
2020-05-27 03:28:59 +03:00
|
|
|
#include "mozilla/dom/BrowserParent.h"
|
2019-01-30 19:07:21 +03:00
|
|
|
#include "mozilla/dom/BrowsingContextGroup.h"
|
2018-08-29 05:00:00 +03:00
|
|
|
#include "mozilla/dom/BrowsingContextBinding.h"
|
2018-07-26 10:31:00 +03:00
|
|
|
#include "mozilla/dom/ContentChild.h"
|
2018-11-05 15:43:10 +03:00
|
|
|
#include "mozilla/dom/ContentParent.h"
|
2019-12-01 00:13:54 +03:00
|
|
|
#include "mozilla/dom/Document.h"
|
2019-04-17 03:51:36 +03:00
|
|
|
#include "mozilla/dom/Element.h"
|
2020-06-09 02:49:31 +03:00
|
|
|
#include "mozilla/dom/HTMLEmbedElement.h"
|
2020-01-24 22:03:10 +03:00
|
|
|
#include "mozilla/dom/HTMLIFrameElement.h"
|
2019-01-02 16:29:18 +03:00
|
|
|
#include "mozilla/dom/Location.h"
|
|
|
|
#include "mozilla/dom/LocationBinding.h"
|
2019-10-18 06:04:55 +03:00
|
|
|
#include "mozilla/dom/PopupBlocker.h"
|
2019-10-24 17:53:07 +03:00
|
|
|
#include "mozilla/dom/ScriptSettings.h"
|
2019-12-10 15:12:25 +03:00
|
|
|
#include "mozilla/dom/SessionStorageManager.h"
|
2019-07-02 01:24:09 +03:00
|
|
|
#include "mozilla/dom/StructuredCloneTags.h"
|
2019-09-20 14:10:13 +03:00
|
|
|
#include "mozilla/dom/UserActivationIPCUtils.h"
|
2019-01-02 16:29:18 +03:00
|
|
|
#include "mozilla/dom/WindowBinding.h"
|
2019-04-17 03:51:36 +03:00
|
|
|
#include "mozilla/dom/WindowGlobalChild.h"
|
|
|
|
#include "mozilla/dom/WindowGlobalParent.h"
|
2019-01-03 10:11:00 +03:00
|
|
|
#include "mozilla/dom/WindowProxyHolder.h"
|
2020-01-20 17:57:47 +03:00
|
|
|
#include "mozilla/dom/SyncedContextInlines.h"
|
2020-06-16 21:12:46 +03:00
|
|
|
#include "mozilla/dom/XULFrameElement.h"
|
2020-04-26 03:54:15 +03:00
|
|
|
#include "mozilla/net/DocumentLoadListener.h"
|
2020-05-21 06:38:14 +03:00
|
|
|
#include "mozilla/net/RequestContextService.h"
|
2018-07-26 10:31:00 +03:00
|
|
|
#include "mozilla/Assertions.h"
|
2020-04-30 04:21:20 +03:00
|
|
|
#include "mozilla/AsyncEventDispatcher.h"
|
2018-07-26 10:31:00 +03:00
|
|
|
#include "mozilla/ClearOnShutdown.h"
|
2019-10-11 05:27:14 +03:00
|
|
|
#include "mozilla/Components.h"
|
2018-12-17 13:45:37 +03:00
|
|
|
#include "mozilla/HashTable.h"
|
2018-07-26 10:31:00 +03:00
|
|
|
#include "mozilla/Logging.h"
|
2020-10-09 20:31:59 +03:00
|
|
|
#include "mozilla/MediaFeatureChange.h"
|
2020-04-04 05:42:39 +03:00
|
|
|
#include "mozilla/ResultExtensions.h"
|
2019-10-29 20:15:29 +03:00
|
|
|
#include "mozilla/Services.h"
|
2020-05-20 12:15:31 +03:00
|
|
|
#include "mozilla/StaticPrefs_fission.h"
|
2019-12-01 00:13:24 +03:00
|
|
|
#include "mozilla/StaticPrefs_page_load.h"
|
2018-07-26 10:31:00 +03:00
|
|
|
#include "mozilla/StaticPtr.h"
|
2019-10-11 05:27:14 +03:00
|
|
|
#include "nsIURIFixup.h"
|
2020-09-28 15:01:12 +03:00
|
|
|
#include "nsIXULRuntime.h"
|
2018-07-26 10:31:00 +03:00
|
|
|
|
2018-11-05 15:43:10 +03:00
|
|
|
#include "nsDocShell.h"
|
2020-11-23 19:04:08 +03:00
|
|
|
#include "nsDocShellLoadState.h"
|
2019-11-13 00:52:18 +03:00
|
|
|
#include "nsFocusManager.h"
|
2019-01-02 16:29:18 +03:00
|
|
|
#include "nsGlobalWindowOuter.h"
|
2019-10-29 20:15:29 +03:00
|
|
|
#include "nsIObserverService.h"
|
2020-08-23 20:41:03 +03:00
|
|
|
#include "nsISHistory.h"
|
2018-07-26 10:31:00 +03:00
|
|
|
#include "nsContentUtils.h"
|
2020-06-16 21:12:46 +03:00
|
|
|
#include "nsQueryObject.h"
|
2020-04-04 05:42:30 +03:00
|
|
|
#include "nsSandboxFlags.h"
|
2019-01-02 16:29:18 +03:00
|
|
|
#include "nsScriptError.h"
|
2018-06-29 02:41:00 +03:00
|
|
|
#include "nsThreadUtils.h"
|
2019-02-28 21:23:15 +03:00
|
|
|
#include "xpcprivate.h"
|
2018-07-26 10:31:00 +03:00
|
|
|
|
2019-03-20 06:15:36 +03:00
|
|
|
#include "AutoplayPolicy.h"
|
2019-11-25 14:00:13 +03:00
|
|
|
#include "GVAutoplayRequestStatusIPC.h"
|
2019-03-20 06:15:36 +03:00
|
|
|
|
|
|
|
extern mozilla::LazyLogModule gAutoplayPermissionLog;
|
2019-12-13 20:09:33 +03:00
|
|
|
extern mozilla::LazyLogModule gTimeoutDeferralLog;
|
2019-03-20 06:15:36 +03:00
|
|
|
|
|
|
|
#define AUTOPLAY_LOG(msg, ...) \
|
|
|
|
MOZ_LOG(gAutoplayPermissionLog, LogLevel::Debug, (msg, ##__VA_ARGS__))
|
|
|
|
|
2019-12-04 03:44:27 +03:00
|
|
|
namespace IPC {
|
|
|
|
// Allow serialization and deserialization of OrientationType over IPC
|
|
|
|
template <>
|
|
|
|
struct ParamTraits<mozilla::dom::OrientationType>
|
2020-10-09 20:31:59 +03:00
|
|
|
: public ContiguousEnumSerializer<
|
2019-12-04 03:44:27 +03:00
|
|
|
mozilla::dom::OrientationType,
|
|
|
|
mozilla::dom::OrientationType::Portrait_primary,
|
2020-10-09 20:31:59 +03:00
|
|
|
mozilla::dom::OrientationType::EndGuard_> {};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct ParamTraits<mozilla::dom::DisplayMode>
|
|
|
|
: public ContiguousEnumSerializer<mozilla::dom::DisplayMode,
|
|
|
|
mozilla::dom::DisplayMode::Browser,
|
|
|
|
mozilla::dom::DisplayMode::EndGuard_> {};
|
2019-12-04 03:44:27 +03:00
|
|
|
|
2021-02-03 13:38:09 +03:00
|
|
|
template <>
|
|
|
|
struct ParamTraits<mozilla::dom::PrefersColorSchemeOverride>
|
|
|
|
: public ContiguousEnumSerializer<
|
|
|
|
mozilla::dom::PrefersColorSchemeOverride,
|
|
|
|
mozilla::dom::PrefersColorSchemeOverride::None,
|
|
|
|
mozilla::dom::PrefersColorSchemeOverride::EndGuard_> {};
|
|
|
|
|
2020-12-11 18:43:19 +03:00
|
|
|
template <>
|
|
|
|
struct ParamTraits<mozilla::dom::ExplicitActiveStatus>
|
|
|
|
: public ContiguousEnumSerializer<
|
|
|
|
mozilla::dom::ExplicitActiveStatus,
|
|
|
|
mozilla::dom::ExplicitActiveStatus::None,
|
|
|
|
mozilla::dom::ExplicitActiveStatus::EndGuard_> {};
|
|
|
|
|
2020-11-10 18:57:30 +03:00
|
|
|
// Allow serialization and deserialization of TouchEventsOverride over IPC
|
|
|
|
template <>
|
|
|
|
struct ParamTraits<mozilla::dom::TouchEventsOverride>
|
|
|
|
: public ContiguousEnumSerializer<
|
|
|
|
mozilla::dom::TouchEventsOverride,
|
|
|
|
mozilla::dom::TouchEventsOverride::Disabled,
|
|
|
|
mozilla::dom::TouchEventsOverride::EndGuard_> {};
|
2019-12-04 03:44:27 +03:00
|
|
|
} // namespace IPC
|
|
|
|
|
2018-07-26 10:31:00 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2020-01-20 17:57:47 +03:00
|
|
|
// Explicit specialization of the `Transaction` type. Required by the `extern
|
|
|
|
// template class` declaration in the header.
|
|
|
|
template class syncedcontext::Transaction<BrowsingContext>;
|
|
|
|
|
2019-01-15 02:09:42 +03:00
|
|
|
extern mozilla::LazyLogModule gUserInteractionPRLog;
|
|
|
|
|
|
|
|
#define USER_ACTIVATION_LOG(msg, ...) \
|
|
|
|
MOZ_LOG(gUserInteractionPRLog, LogLevel::Debug, (msg, ##__VA_ARGS__))
|
|
|
|
|
2018-07-26 10:31:00 +03:00
|
|
|
static LazyLogModule gBrowsingContextLog("BrowsingContext");
|
|
|
|
|
2019-05-24 23:15:53 +03:00
|
|
|
typedef nsDataHashtable<nsUint64HashKey, BrowsingContext*> BrowsingContextMap;
|
2018-12-17 13:45:37 +03:00
|
|
|
|
2020-07-09 23:34:06 +03:00
|
|
|
// All BrowsingContexts indexed by Id
|
2019-05-24 23:15:53 +03:00
|
|
|
static StaticAutoPtr<BrowsingContextMap> sBrowsingContexts;
|
2020-07-09 23:34:06 +03:00
|
|
|
// Top-level Content BrowsingContexts only, indexed by BrowserId instead of Id
|
|
|
|
static StaticAutoPtr<BrowsingContextMap> sCurrentTopByBrowserId;
|
|
|
|
|
|
|
|
static void UnregisterBrowserId(BrowsingContext* aBrowsingContext) {
|
|
|
|
if (!aBrowsingContext->IsTopContent() || !sCurrentTopByBrowserId) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Avoids an extra lookup
|
|
|
|
auto browserIdEntry =
|
|
|
|
sCurrentTopByBrowserId->Lookup(aBrowsingContext->BrowserId());
|
|
|
|
if (browserIdEntry && browserIdEntry.Data() == aBrowsingContext) {
|
|
|
|
browserIdEntry.Remove();
|
|
|
|
}
|
|
|
|
}
|
2018-07-26 10:31:00 +03:00
|
|
|
|
2018-11-05 15:43:10 +03:00
|
|
|
static void Register(BrowsingContext* aBrowsingContext) {
|
2019-05-24 23:15:53 +03:00
|
|
|
sBrowsingContexts->Put(aBrowsingContext->Id(), aBrowsingContext);
|
2020-07-09 23:34:06 +03:00
|
|
|
if (aBrowsingContext->IsTopContent()) {
|
|
|
|
sCurrentTopByBrowserId->Put(aBrowsingContext->BrowserId(),
|
|
|
|
aBrowsingContext);
|
|
|
|
}
|
2019-01-30 19:07:21 +03:00
|
|
|
|
|
|
|
aBrowsingContext->Group()->Register(aBrowsingContext);
|
2018-11-05 15:43:10 +03:00
|
|
|
}
|
|
|
|
|
2020-04-24 21:33:06 +03:00
|
|
|
BrowsingContext* BrowsingContext::GetParent() const {
|
|
|
|
return mParentWindow ? mParentWindow->GetBrowsingContext() : nullptr;
|
|
|
|
}
|
|
|
|
|
2020-04-27 08:41:40 +03:00
|
|
|
bool BrowsingContext::IsInSubtreeOf(BrowsingContext* aContext) {
|
|
|
|
BrowsingContext* bc = this;
|
|
|
|
do {
|
|
|
|
if (bc == aContext) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} while ((bc = bc->GetParent()));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-04-09 09:19:24 +03:00
|
|
|
BrowsingContext* BrowsingContext::Top() {
|
2019-01-15 02:09:42 +03:00
|
|
|
BrowsingContext* bc = this;
|
2020-04-24 21:33:06 +03:00
|
|
|
while (bc->mParentWindow) {
|
|
|
|
bc = bc->GetParent();
|
2019-01-15 02:09:42 +03:00
|
|
|
}
|
|
|
|
return bc;
|
|
|
|
}
|
|
|
|
|
2020-10-31 01:10:15 +03:00
|
|
|
int32_t BrowsingContext::IndexOf(BrowsingContext* aChild) {
|
|
|
|
int32_t index = -1;
|
|
|
|
for (BrowsingContext* child : Children()) {
|
|
|
|
++index;
|
|
|
|
if (child == aChild) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
2020-05-04 17:26:34 +03:00
|
|
|
WindowContext* BrowsingContext::GetTopWindowContext() {
|
|
|
|
if (mParentWindow) {
|
|
|
|
return mParentWindow->TopWindowContext();
|
|
|
|
}
|
|
|
|
return mCurrentWindowContext;
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:04:59 +03:00
|
|
|
/* static */
|
|
|
|
void BrowsingContext::Init() {
|
2018-07-26 10:31:00 +03:00
|
|
|
if (!sBrowsingContexts) {
|
2019-05-24 23:15:53 +03:00
|
|
|
sBrowsingContexts = new BrowsingContextMap();
|
2020-07-09 23:34:06 +03:00
|
|
|
sCurrentTopByBrowserId = new BrowsingContextMap();
|
2018-07-26 10:31:00 +03:00
|
|
|
ClearOnShutdown(&sBrowsingContexts);
|
2020-07-09 23:34:06 +03:00
|
|
|
ClearOnShutdown(&sCurrentTopByBrowserId);
|
2018-07-26 10:31:00 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:04:59 +03:00
|
|
|
/* static */
|
|
|
|
LogModule* BrowsingContext::GetLog() { return gBrowsingContextLog; }
|
2018-07-26 10:31:00 +03:00
|
|
|
|
2019-02-26 01:04:59 +03:00
|
|
|
/* static */
|
|
|
|
already_AddRefed<BrowsingContext> BrowsingContext::Get(uint64_t aId) {
|
2019-05-24 23:15:53 +03:00
|
|
|
return do_AddRef(sBrowsingContexts->Get(aId));
|
2018-07-26 10:31:00 +03:00
|
|
|
}
|
|
|
|
|
2020-07-09 23:34:06 +03:00
|
|
|
/* static */
|
|
|
|
already_AddRefed<BrowsingContext> BrowsingContext::GetCurrentTopByBrowserId(
|
|
|
|
uint64_t aBrowserId) {
|
|
|
|
return do_AddRef(sCurrentTopByBrowserId->Get(aBrowserId));
|
|
|
|
}
|
|
|
|
|
2019-06-19 23:06:32 +03:00
|
|
|
/* static */
|
|
|
|
already_AddRefed<BrowsingContext> BrowsingContext::GetFromWindow(
|
|
|
|
WindowProxyHolder& aProxy) {
|
|
|
|
return do_AddRef(aProxy.get());
|
|
|
|
}
|
|
|
|
|
2019-02-14 00:02:55 +03:00
|
|
|
CanonicalBrowsingContext* BrowsingContext::Canonical() {
|
|
|
|
return CanonicalBrowsingContext::Cast(this);
|
|
|
|
}
|
|
|
|
|
2020-08-28 20:21:17 +03:00
|
|
|
bool BrowsingContext::IsOwnedByProcess() const {
|
|
|
|
return mIsInProcess && mDocShell &&
|
|
|
|
!nsDocShell::Cast(mDocShell)->WillChangeProcess();
|
|
|
|
}
|
|
|
|
|
2020-03-17 19:39:27 +03:00
|
|
|
bool BrowsingContext::SameOriginWithTop() {
|
2021-01-05 18:59:54 +03:00
|
|
|
MOZ_ASSERT(IsInProcess());
|
2020-03-17 19:39:27 +03:00
|
|
|
// If the top BrowsingContext is not same-process to us, it is cross-origin
|
|
|
|
if (!Top()->IsInProcess()) {
|
2020-03-17 19:36:58 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-03-17 19:39:27 +03:00
|
|
|
nsIDocShell* docShell = GetDocShell();
|
|
|
|
if (!docShell) {
|
2020-03-17 19:36:58 +03:00
|
|
|
return false;
|
|
|
|
}
|
2020-03-17 19:39:27 +03:00
|
|
|
Document* doc = docShell->GetDocument();
|
|
|
|
if (!doc) {
|
2020-03-17 19:36:58 +03:00
|
|
|
return false;
|
|
|
|
}
|
2020-03-17 19:39:27 +03:00
|
|
|
nsIPrincipal* principal = doc->NodePrincipal();
|
2020-03-17 19:36:58 +03:00
|
|
|
|
2020-03-17 19:39:27 +03:00
|
|
|
nsIDocShell* topDocShell = Top()->GetDocShell();
|
2020-03-17 19:36:58 +03:00
|
|
|
if (!topDocShell) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Document* topDoc = topDocShell->GetDocument();
|
|
|
|
if (!topDoc) {
|
|
|
|
return false;
|
|
|
|
}
|
2020-03-17 19:39:27 +03:00
|
|
|
nsIPrincipal* topPrincipal = topDoc->NodePrincipal();
|
2020-03-17 19:36:58 +03:00
|
|
|
|
2020-03-17 19:39:27 +03:00
|
|
|
return principal->Equals(topPrincipal);
|
2020-03-17 19:36:58 +03:00
|
|
|
}
|
|
|
|
|
2019-02-26 01:04:59 +03:00
|
|
|
/* static */
|
2020-02-06 22:08:04 +03:00
|
|
|
already_AddRefed<BrowsingContext> BrowsingContext::CreateDetached(
|
2020-04-24 21:33:04 +03:00
|
|
|
nsGlobalWindowInner* aParent, BrowsingContext* aOpener,
|
2020-09-23 16:43:38 +03:00
|
|
|
BrowsingContextGroup* aSpecificGroup, const nsAString& aName, Type aType,
|
|
|
|
bool aCreatedDynamically) {
|
2020-06-16 21:12:46 +03:00
|
|
|
if (aParent) {
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(aParent->GetWindowContext());
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(aParent->GetBrowsingContext()->mType == aType);
|
2020-06-23 00:46:03 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(aParent->GetBrowsingContext()->GetBrowserId() != 0);
|
2020-06-16 21:12:46 +03:00
|
|
|
}
|
2018-11-05 15:43:10 +03:00
|
|
|
|
2019-09-20 07:43:46 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(aType != Type::Chrome || XRE_IsParentProcess());
|
|
|
|
|
2018-11-05 15:43:10 +03:00
|
|
|
uint64_t id = nsContentUtils::GenerateBrowsingContextId();
|
|
|
|
|
|
|
|
MOZ_LOG(GetLog(), LogLevel::Debug,
|
|
|
|
("Creating 0x%08" PRIx64 " in %s", id,
|
|
|
|
XRE_IsParentProcess() ? "Parent" : "Child"));
|
|
|
|
|
2020-04-24 21:33:04 +03:00
|
|
|
RefPtr<BrowsingContext> parentBC =
|
|
|
|
aParent ? aParent->GetBrowsingContext() : nullptr;
|
|
|
|
RefPtr<WindowContext> parentWC =
|
|
|
|
aParent ? aParent->GetWindowContext() : nullptr;
|
2020-07-22 12:13:20 +03:00
|
|
|
BrowsingContext* inherit = parentBC ? parentBC.get() : aOpener;
|
2020-04-24 21:33:04 +03:00
|
|
|
|
2019-03-14 21:51:09 +03:00
|
|
|
// Determine which BrowsingContextGroup this context should be created in.
|
2020-07-06 23:10:43 +03:00
|
|
|
RefPtr<BrowsingContextGroup> group = aSpecificGroup;
|
|
|
|
if (aType == Type::Chrome) {
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(!group);
|
|
|
|
group = BrowsingContextGroup::GetChromeGroup();
|
|
|
|
} else if (!group) {
|
|
|
|
group = BrowsingContextGroup::Select(parentWC, aOpener);
|
|
|
|
}
|
2019-03-14 21:51:09 +03:00
|
|
|
|
2020-07-22 12:13:20 +03:00
|
|
|
// Configure initial values for synced fields.
|
|
|
|
FieldValues fields;
|
|
|
|
fields.mName = aName;
|
2019-03-14 21:51:09 +03:00
|
|
|
|
2019-08-28 21:07:31 +03:00
|
|
|
if (aOpener) {
|
2020-04-24 21:33:04 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(!aParent,
|
|
|
|
"new BC with both initial opener and parent");
|
2020-07-22 12:13:20 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(aOpener->Group() == group);
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(aOpener->mType == aType);
|
|
|
|
fields.mOpenerId = aOpener->Id();
|
|
|
|
fields.mHadOriginalOpener = true;
|
2019-08-28 21:07:31 +03:00
|
|
|
}
|
2020-06-16 21:12:46 +03:00
|
|
|
|
2020-04-24 21:33:04 +03:00
|
|
|
if (aParent) {
|
2020-07-22 12:13:20 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(parentBC->Group() == group);
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(parentBC->mType == aType);
|
|
|
|
fields.mEmbedderInnerWindowId = aParent->WindowID();
|
2020-04-24 21:33:04 +03:00
|
|
|
|
2020-07-22 12:13:20 +03:00
|
|
|
// XXX(farre): Can/Should we check aParent->IsLoading() here? (Bug
|
|
|
|
// 1608448) Check if the parent was itself loading already
|
|
|
|
auto readystate = aParent->GetDocument()->GetReadyStateEnum();
|
|
|
|
fields.mAncestorLoading =
|
|
|
|
parentBC->GetAncestorLoading() ||
|
|
|
|
readystate == Document::ReadyState::READYSTATE_LOADING ||
|
|
|
|
readystate == Document::ReadyState::READYSTATE_INTERACTIVE;
|
2020-04-24 21:33:04 +03:00
|
|
|
}
|
|
|
|
|
2020-07-22 12:13:20 +03:00
|
|
|
fields.mBrowserId =
|
2020-06-23 00:46:03 +03:00
|
|
|
parentBC ? parentBC->GetBrowserId() : nsContentUtils::GenerateBrowserId();
|
2020-06-16 21:12:46 +03:00
|
|
|
|
2020-07-22 12:13:20 +03:00
|
|
|
fields.mOpenerPolicy = nsILoadInfo::OPENER_POLICY_UNSAFE_NONE;
|
2020-03-17 19:39:27 +03:00
|
|
|
if (aOpener && aOpener->SameOriginWithTop()) {
|
2020-03-17 19:36:58 +03:00
|
|
|
// We inherit the opener policy if there is a creator and if the creator's
|
|
|
|
// origin is same origin with the creator's top-level origin.
|
2020-03-17 19:39:27 +03:00
|
|
|
// If it is cross origin we should not inherit the CrossOriginOpenerPolicy
|
2020-07-22 12:13:20 +03:00
|
|
|
fields.mOpenerPolicy = aOpener->Top()->GetOpenerPolicy();
|
2020-03-17 19:36:58 +03:00
|
|
|
} else if (aOpener) {
|
|
|
|
// They are not same origin
|
|
|
|
auto topPolicy = aOpener->Top()->GetOpenerPolicy();
|
|
|
|
MOZ_RELEASE_ASSERT(topPolicy == nsILoadInfo::OPENER_POLICY_UNSAFE_NONE ||
|
|
|
|
topPolicy ==
|
|
|
|
nsILoadInfo::OPENER_POLICY_SAME_ORIGIN_ALLOW_POPUPS);
|
|
|
|
}
|
|
|
|
|
2020-07-22 12:13:20 +03:00
|
|
|
nsContentUtils::GenerateUUIDInPlace(fields.mHistoryID);
|
2021-01-21 23:20:57 +03:00
|
|
|
fields.mExplicitActive = [&] {
|
|
|
|
if (parentBC) {
|
|
|
|
// Non-root browsing-contexts inherit their status from its parent.
|
|
|
|
return ExplicitActiveStatus::None;
|
|
|
|
}
|
|
|
|
if (aType == Type::Content) {
|
|
|
|
// Content gets managed by the chrome front-end / embedder element and
|
|
|
|
// starts as inactive.
|
|
|
|
return ExplicitActiveStatus::Inactive;
|
|
|
|
}
|
|
|
|
// Chrome starts as active.
|
|
|
|
return ExplicitActiveStatus::Active;
|
|
|
|
}();
|
2019-03-05 12:33:42 +03:00
|
|
|
|
2020-07-22 12:13:20 +03:00
|
|
|
fields.mFullZoom = parentBC ? parentBC->FullZoom() : 1.0f;
|
|
|
|
fields.mTextZoom = parentBC ? parentBC->TextZoom() : 1.0f;
|
2020-04-22 22:32:52 +03:00
|
|
|
|
2020-07-22 12:13:20 +03:00
|
|
|
bool allowContentRetargeting =
|
2020-03-19 04:49:04 +03:00
|
|
|
inherit ? inherit->GetAllowContentRetargetingOnChildren() : true;
|
2020-07-22 12:13:20 +03:00
|
|
|
fields.mAllowContentRetargeting = allowContentRetargeting;
|
|
|
|
fields.mAllowContentRetargetingOnChildren = allowContentRetargeting;
|
2020-03-19 04:49:04 +03:00
|
|
|
|
2020-06-09 02:49:31 +03:00
|
|
|
// Assume top allows fullscreen for its children unless otherwise stated.
|
|
|
|
// Subframes start with it false unless otherwise noted in SetEmbedderElement.
|
2020-07-22 12:13:20 +03:00
|
|
|
fields.mFullscreenAllowedByOwner = !aParent;
|
2020-06-09 02:49:31 +03:00
|
|
|
|
2020-07-22 12:13:20 +03:00
|
|
|
fields.mAllowPlugins = inherit ? inherit->GetAllowPlugins() : true;
|
2020-03-19 04:48:56 +03:00
|
|
|
|
2020-07-22 12:13:20 +03:00
|
|
|
fields.mDefaultLoadFlags =
|
2020-04-27 08:37:59 +03:00
|
|
|
inherit ? inherit->GetDefaultLoadFlags() : nsIRequest::LOAD_NORMAL;
|
|
|
|
|
2020-07-22 12:13:20 +03:00
|
|
|
fields.mOrientationLock = mozilla::hal::eScreenOrientation_None;
|
|
|
|
|
|
|
|
fields.mUseGlobalHistory = inherit ? inherit->GetUseGlobalHistory() : false;
|
2020-04-27 18:43:36 +03:00
|
|
|
|
2020-07-22 12:13:20 +03:00
|
|
|
fields.mUseErrorPages = true;
|
2020-05-08 06:28:38 +03:00
|
|
|
|
2020-11-10 18:57:30 +03:00
|
|
|
fields.mTouchEventsOverrideInternal = TouchEventsOverride::None;
|
|
|
|
|
2020-07-22 12:13:20 +03:00
|
|
|
RefPtr<BrowsingContext> context;
|
|
|
|
if (XRE_IsParentProcess()) {
|
|
|
|
context = new CanonicalBrowsingContext(parentWC, group, id,
|
|
|
|
/* aOwnerProcessId */ 0,
|
|
|
|
/* aEmbedderProcessId */ 0, aType,
|
|
|
|
std::move(fields));
|
|
|
|
} else {
|
|
|
|
context =
|
|
|
|
new BrowsingContext(parentWC, group, id, aType, std::move(fields));
|
|
|
|
}
|
|
|
|
|
|
|
|
context->mEmbeddedByThisProcess = XRE_IsParentProcess() || aParent;
|
2020-09-23 16:43:38 +03:00
|
|
|
context->mCreatedDynamically = aCreatedDynamically;
|
2020-07-22 12:13:20 +03:00
|
|
|
if (inherit) {
|
|
|
|
context->mPrivateBrowsingId = inherit->mPrivateBrowsingId;
|
|
|
|
context->mUseRemoteTabs = inherit->mUseRemoteTabs;
|
|
|
|
context->mUseRemoteSubframes = inherit->mUseRemoteSubframes;
|
|
|
|
context->mOriginAttributes = inherit->mOriginAttributes;
|
|
|
|
}
|
2020-06-25 07:32:51 +03:00
|
|
|
|
2020-05-21 06:38:14 +03:00
|
|
|
nsCOMPtr<nsIRequestContextService> rcsvc =
|
|
|
|
net::RequestContextService::GetOrCreate();
|
|
|
|
if (rcsvc) {
|
|
|
|
nsCOMPtr<nsIRequestContext> requestContext;
|
|
|
|
nsresult rv = rcsvc->NewRequestContext(getter_AddRefs(requestContext));
|
|
|
|
if (NS_SUCCEEDED(rv) && requestContext) {
|
|
|
|
context->mRequestContextId = requestContext->GetID();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-06 22:08:04 +03:00
|
|
|
return context.forget();
|
|
|
|
}
|
2018-11-05 15:43:10 +03:00
|
|
|
|
2020-04-24 21:33:01 +03:00
|
|
|
already_AddRefed<BrowsingContext> BrowsingContext::CreateIndependent(
|
2020-02-06 22:08:06 +03:00
|
|
|
Type aType) {
|
2020-06-23 02:23:48 +03:00
|
|
|
RefPtr<BrowsingContext> bc(
|
2020-09-23 18:17:15 +03:00
|
|
|
CreateDetached(nullptr, nullptr, nullptr, u""_ns, aType));
|
2020-04-24 21:33:01 +03:00
|
|
|
bc->mWindowless = bc->IsContent();
|
2020-07-02 03:53:18 +03:00
|
|
|
bc->mEmbeddedByThisProcess = true;
|
2020-02-06 22:08:06 +03:00
|
|
|
bc->EnsureAttached();
|
|
|
|
return bc.forget();
|
|
|
|
}
|
|
|
|
|
2020-02-06 22:08:04 +03:00
|
|
|
void BrowsingContext::EnsureAttached() {
|
|
|
|
if (!mEverAttached) {
|
|
|
|
Register(this);
|
|
|
|
|
|
|
|
// Attach the browsing context to the tree.
|
2020-04-24 21:33:09 +03:00
|
|
|
Attach(/* aFromIPC */ false, /* aOriginProcess */ nullptr);
|
2020-02-06 22:08:04 +03:00
|
|
|
}
|
2018-09-14 17:57:18 +03:00
|
|
|
}
|
|
|
|
|
2019-02-26 01:04:59 +03:00
|
|
|
/* static */
|
2020-04-24 21:33:09 +03:00
|
|
|
void BrowsingContext::CreateFromIPC(BrowsingContext::IPCInitializer&& aInit,
|
|
|
|
BrowsingContextGroup* aGroup,
|
|
|
|
ContentParent* aOriginProcess) {
|
2019-03-14 21:51:09 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(aOriginProcess || XRE_IsContentProcess());
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(aGroup);
|
|
|
|
|
2019-05-02 11:50:12 +03:00
|
|
|
uint64_t originId = 0;
|
|
|
|
if (aOriginProcess) {
|
|
|
|
originId = aOriginProcess->ChildID();
|
2020-07-30 23:27:37 +03:00
|
|
|
aGroup->EnsureHostProcess(aOriginProcess);
|
2019-05-02 11:50:12 +03:00
|
|
|
}
|
2018-11-05 15:43:10 +03:00
|
|
|
|
|
|
|
MOZ_LOG(GetLog(), LogLevel::Debug,
|
2019-03-14 21:51:09 +03:00
|
|
|
("Creating 0x%08" PRIx64 " from IPC (origin=0x%08" PRIx64 ")",
|
|
|
|
aInit.mId, originId));
|
|
|
|
|
2020-04-24 21:33:04 +03:00
|
|
|
RefPtr<WindowContext> parent = aInit.GetParent();
|
2018-11-05 15:43:10 +03:00
|
|
|
|
|
|
|
RefPtr<BrowsingContext> context;
|
|
|
|
if (XRE_IsParentProcess()) {
|
2020-02-06 22:07:56 +03:00
|
|
|
// If the new BrowsingContext has a parent, it is a sub-frame embedded in
|
2020-02-06 22:08:06 +03:00
|
|
|
// whatever process sent the message. If it doesn't, and is not windowless,
|
|
|
|
// it is a new window or tab, and will be embedded in the parent process.
|
|
|
|
uint64_t embedderProcessId = (aInit.mWindowless || parent) ? originId : 0;
|
2020-02-06 22:07:56 +03:00
|
|
|
context = new CanonicalBrowsingContext(parent, aGroup, aInit.mId, originId,
|
|
|
|
embedderProcessId, Type::Content,
|
|
|
|
std::move(aInit.mFields));
|
2018-11-05 15:43:10 +03:00
|
|
|
} else {
|
2020-01-20 17:57:47 +03:00
|
|
|
context = new BrowsingContext(parent, aGroup, aInit.mId, Type::Content,
|
|
|
|
std::move(aInit.mFields));
|
2018-11-05 15:43:10 +03:00
|
|
|
}
|
|
|
|
|
2020-02-06 22:08:06 +03:00
|
|
|
context->mWindowless = aInit.mWindowless;
|
2020-09-23 16:43:38 +03:00
|
|
|
context->mCreatedDynamically = aInit.mCreatedDynamically;
|
2020-09-08 18:24:13 +03:00
|
|
|
if (context->GetHasSessionHistory()) {
|
|
|
|
context->CreateChildSHistory();
|
2020-09-28 15:01:12 +03:00
|
|
|
if (mozilla::SessionHistoryInParent()) {
|
2020-09-08 18:24:13 +03:00
|
|
|
context->GetChildSessionHistory()->SetIndexAndLength(
|
|
|
|
aInit.mSessionHistoryIndex, aInit.mSessionHistoryCount, nsID());
|
|
|
|
}
|
2020-05-20 12:15:31 +03:00
|
|
|
}
|
2020-02-06 22:08:06 +03:00
|
|
|
|
2020-04-08 00:39:12 +03:00
|
|
|
// NOTE: Call through the `Set` methods for these values to ensure that any
|
|
|
|
// relevant process-local state is also updated.
|
|
|
|
context->SetOriginAttributes(aInit.mOriginAttributes);
|
|
|
|
context->SetRemoteTabs(aInit.mUseRemoteTabs);
|
|
|
|
context->SetRemoteSubframes(aInit.mUseRemoteSubframes);
|
2020-05-21 06:38:14 +03:00
|
|
|
context->mRequestContextId = aInit.mRequestContextId;
|
2020-04-08 00:39:12 +03:00
|
|
|
// NOTE: Private browsing ID is set by `SetOriginAttributes`.
|
|
|
|
|
2018-11-05 15:43:10 +03:00
|
|
|
Register(context);
|
|
|
|
|
2020-04-24 21:33:09 +03:00
|
|
|
context->Attach(/* aFromIPC */ true, aOriginProcess);
|
2018-07-26 10:31:00 +03:00
|
|
|
}
|
|
|
|
|
2020-04-24 21:33:04 +03:00
|
|
|
BrowsingContext::BrowsingContext(WindowContext* aParentWindow,
|
2019-03-14 21:51:09 +03:00
|
|
|
BrowsingContextGroup* aGroup,
|
2020-01-20 17:57:47 +03:00
|
|
|
uint64_t aBrowsingContextId, Type aType,
|
2020-07-22 17:07:26 +03:00
|
|
|
FieldValues&& aInit)
|
|
|
|
: mFields(std::move(aInit)),
|
2020-01-20 17:57:47 +03:00
|
|
|
mType(aType),
|
2018-11-05 15:43:10 +03:00
|
|
|
mBrowsingContextId(aBrowsingContextId),
|
2019-03-14 21:51:09 +03:00
|
|
|
mGroup(aGroup),
|
2020-04-24 21:33:04 +03:00
|
|
|
mParentWindow(aParentWindow),
|
2020-04-08 00:39:12 +03:00
|
|
|
mPrivateBrowsingId(0),
|
2020-02-06 22:08:04 +03:00
|
|
|
mEverAttached(false),
|
2019-07-02 23:48:13 +03:00
|
|
|
mIsInProcess(false),
|
Bug 1559489, part 4 - Remote-to-local window transplanting. r=tcampbell,bzbarsky
This patch cleans up remote outer window proxies when we navigate back
into the process.
It adds a flag to mDanglingRemoteOuterProxies that is set in between
BrowsingContext::SetDocShell(), where we can tell that the browsing
context is going from being remote to being local, to
nsGlobalWindowOuter::SetNewDocument(), where the local outer window
proxy is actually created. Once the outer window is created, the
remote window proxies can be cleaned up in
CleanUpDanglingRemoteOuterWindowProxies().
The clean up is done by a process that is similar to object
transplanting, except that instead of looking in the cross-compartment
wrapper table for each compartment to find objects to be turned into
CCWs to the new object, it looks in the remote proxy map for each
compartment. SpiderMonkey doesn't know about the proxy maps, so this
has to be done by a new callback object CompartmentTransplantCallback.
Now that this cleanup is being done, it shouldn't be possible to wrap
a remote outer window proxy when the browsing context is local, so
MaybeWrapWindowProxy() can be simplified. I had to drop the assert
here that the browsing context has a window proxy because during clean
up we call wrap on a local outer window proxy before the BC gets the
window proxy set on it. I had the assert because my original plan was
to implicitly fix remote proxies during wrapping, but that is no
longer necessary.
Differential Revision: https://phabricator.services.mozilla.com/D38343
--HG--
extra : moz-landing-system : lando
2019-08-13 22:09:59 +03:00
|
|
|
mIsDiscarded(false),
|
2020-02-06 22:08:06 +03:00
|
|
|
mWindowless(false),
|
2019-12-20 01:05:19 +03:00
|
|
|
mDanglingRemoteOuterProxies(false),
|
2020-04-08 00:39:12 +03:00
|
|
|
mEmbeddedByThisProcess(false),
|
|
|
|
mUseRemoteTabs(false),
|
2020-09-23 16:43:38 +03:00
|
|
|
mUseRemoteSubframes(false),
|
|
|
|
mCreatedDynamically(false) {
|
2020-04-24 21:33:06 +03:00
|
|
|
MOZ_RELEASE_ASSERT(!mParentWindow || mParentWindow->Group() == mGroup);
|
2019-03-14 21:51:09 +03:00
|
|
|
MOZ_RELEASE_ASSERT(mBrowsingContextId != 0);
|
|
|
|
MOZ_RELEASE_ASSERT(mGroup);
|
2018-12-17 13:45:37 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-11-05 15:43:10 +03:00
|
|
|
void BrowsingContext::SetDocShell(nsIDocShell* aDocShell) {
|
|
|
|
// XXX(nika): We should communicate that we are now an active BrowsingContext
|
|
|
|
// process to the parent & do other validation here.
|
2020-02-06 22:08:04 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mEverAttached);
|
2019-08-07 19:59:30 +03:00
|
|
|
MOZ_RELEASE_ASSERT(aDocShell->GetBrowsingContext() == this);
|
2018-11-05 15:43:10 +03:00
|
|
|
mDocShell = aDocShell;
|
Bug 1559489, part 4 - Remote-to-local window transplanting. r=tcampbell,bzbarsky
This patch cleans up remote outer window proxies when we navigate back
into the process.
It adds a flag to mDanglingRemoteOuterProxies that is set in between
BrowsingContext::SetDocShell(), where we can tell that the browsing
context is going from being remote to being local, to
nsGlobalWindowOuter::SetNewDocument(), where the local outer window
proxy is actually created. Once the outer window is created, the
remote window proxies can be cleaned up in
CleanUpDanglingRemoteOuterWindowProxies().
The clean up is done by a process that is similar to object
transplanting, except that instead of looking in the cross-compartment
wrapper table for each compartment to find objects to be turned into
CCWs to the new object, it looks in the remote proxy map for each
compartment. SpiderMonkey doesn't know about the proxy maps, so this
has to be done by a new callback object CompartmentTransplantCallback.
Now that this cleanup is being done, it shouldn't be possible to wrap
a remote outer window proxy when the browsing context is local, so
MaybeWrapWindowProxy() can be simplified. I had to drop the assert
here that the browsing context has a window proxy because during clean
up we call wrap on a local outer window proxy before the BC gets the
window proxy set on it. I had the assert because my original plan was
to implicitly fix remote proxies during wrapping, but that is no
longer necessary.
Differential Revision: https://phabricator.services.mozilla.com/D38343
--HG--
extra : moz-landing-system : lando
2019-08-13 22:09:59 +03:00
|
|
|
mDanglingRemoteOuterProxies = !mIsInProcess;
|
Bug 1529684 - Part 6: Store a mIsInProcess flag to preserve WindowProxy behaviour, r=farre
Currently when we have an in-process WindowProxy object, we will attempt
to either use the cached mWindowProxy value, or fetch the
nsGlobalWindowOuter object from through the nsDocShell. Unfortunately,
when the BrowsingContext is detached, we will fail to get the
nsGlobalWindowOuter object. This happens to be OK for our test cases, as
the cached mWindowProxy value doesn't have the chance to go away, but
isn't acceptable long-term.
These patches exascerbated that issue by causing the nsDocShell pointer
itself to be cleared when it is destroyed, which caused the Remote
WindowProxy logic to be triggered. To deal with that case, this patch
adds a new mIsInProcess flag to continue to act like the old code-path.
In the future, we will need to also handle ensuring that the
nsGlobalWindowOuter lives for long enough, however that is not being
done in this patch in order to land it sooner rather than later.
Depends on D22763
Differential Revision: https://phabricator.services.mozilla.com/D22764
--HG--
extra : moz-landing-system : lando
2019-03-14 21:50:54 +03:00
|
|
|
mIsInProcess = true;
|
2020-05-19 11:57:44 +03:00
|
|
|
if (mChildSessionHistory) {
|
|
|
|
mChildSessionHistory->SetIsInProcess(true);
|
|
|
|
}
|
2018-11-05 15:43:10 +03:00
|
|
|
}
|
|
|
|
|
Bug 1559489, part 4 - Remote-to-local window transplanting. r=tcampbell,bzbarsky
This patch cleans up remote outer window proxies when we navigate back
into the process.
It adds a flag to mDanglingRemoteOuterProxies that is set in between
BrowsingContext::SetDocShell(), where we can tell that the browsing
context is going from being remote to being local, to
nsGlobalWindowOuter::SetNewDocument(), where the local outer window
proxy is actually created. Once the outer window is created, the
remote window proxies can be cleaned up in
CleanUpDanglingRemoteOuterWindowProxies().
The clean up is done by a process that is similar to object
transplanting, except that instead of looking in the cross-compartment
wrapper table for each compartment to find objects to be turned into
CCWs to the new object, it looks in the remote proxy map for each
compartment. SpiderMonkey doesn't know about the proxy maps, so this
has to be done by a new callback object CompartmentTransplantCallback.
Now that this cleanup is being done, it shouldn't be possible to wrap
a remote outer window proxy when the browsing context is local, so
MaybeWrapWindowProxy() can be simplified. I had to drop the assert
here that the browsing context has a window proxy because during clean
up we call wrap on a local outer window proxy before the BC gets the
window proxy set on it. I had the assert because my original plan was
to implicitly fix remote proxies during wrapping, but that is no
longer necessary.
Differential Revision: https://phabricator.services.mozilla.com/D38343
--HG--
extra : moz-landing-system : lando
2019-08-13 22:09:59 +03:00
|
|
|
// This class implements a callback that will return the remote window proxy for
|
|
|
|
// mBrowsingContext in that compartment, if it has one. It also removes the
|
|
|
|
// proxy from the map, because the object will be transplanted into another kind
|
|
|
|
// of object.
|
|
|
|
class MOZ_STACK_CLASS CompartmentRemoteProxyTransplantCallback
|
|
|
|
: public js::CompartmentTransplantCallback {
|
|
|
|
public:
|
|
|
|
explicit CompartmentRemoteProxyTransplantCallback(
|
|
|
|
BrowsingContext* aBrowsingContext)
|
|
|
|
: mBrowsingContext(aBrowsingContext) {}
|
|
|
|
|
|
|
|
virtual JSObject* getObjectToTransplant(
|
|
|
|
JS::Compartment* compartment) override {
|
|
|
|
auto* priv = xpc::CompartmentPrivate::Get(compartment);
|
|
|
|
if (!priv) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto& map = priv->GetRemoteProxyMap();
|
|
|
|
auto result = map.lookup(mBrowsingContext);
|
|
|
|
if (!result) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
JSObject* resultObject = result->value();
|
|
|
|
map.remove(result);
|
|
|
|
|
|
|
|
return resultObject;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
BrowsingContext* mBrowsingContext;
|
|
|
|
};
|
|
|
|
|
|
|
|
void BrowsingContext::CleanUpDanglingRemoteOuterWindowProxies(
|
|
|
|
JSContext* aCx, JS::MutableHandle<JSObject*> aOuter) {
|
|
|
|
if (!mDanglingRemoteOuterProxies) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mDanglingRemoteOuterProxies = false;
|
|
|
|
|
|
|
|
CompartmentRemoteProxyTransplantCallback cb(this);
|
|
|
|
js::RemapRemoteWindowProxies(aCx, &cb, aOuter);
|
|
|
|
}
|
|
|
|
|
2020-12-11 18:43:19 +03:00
|
|
|
bool BrowsingContext::IsActive() const {
|
|
|
|
const BrowsingContext* current = this;
|
|
|
|
do {
|
|
|
|
auto explicit_ = current->GetExplicitActive();
|
|
|
|
if (explicit_ != ExplicitActiveStatus::None) {
|
|
|
|
return explicit_ == ExplicitActiveStatus::Active;
|
|
|
|
}
|
|
|
|
if (current->IsCached()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} while ((current = current->GetParent()));
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-11-20 18:16:58 +03:00
|
|
|
bool BrowsingContext::GetIsActiveBrowserWindow() {
|
|
|
|
if (!XRE_IsParentProcess()) {
|
|
|
|
return Top()->GetIsActiveBrowserWindowInternal();
|
|
|
|
}
|
|
|
|
|
|
|
|
// chrome:// urls loaded in the parent won't receive
|
|
|
|
// their own activation so we defer to the top chrome
|
|
|
|
// Browsing Context when in the parent process.
|
|
|
|
RefPtr<CanonicalBrowsingContext> chromeTop =
|
|
|
|
Canonical()->TopCrossChromeBoundary();
|
|
|
|
return chromeTop->GetIsActiveBrowserWindowInternal();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowsingContext::SetIsActiveBrowserWindow(bool aActive) {
|
|
|
|
Unused << SetIsActiveBrowserWindowInternal(aActive);
|
|
|
|
}
|
|
|
|
|
2020-06-09 02:49:31 +03:00
|
|
|
bool BrowsingContext::FullscreenAllowed() const {
|
|
|
|
for (auto* current = this; current; current = current->GetParent()) {
|
|
|
|
if (!current->GetFullscreenAllowedByOwner()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool OwnerAllowsFullscreen(const Element& aEmbedder) {
|
|
|
|
if (aEmbedder.IsXULElement()) {
|
|
|
|
return !aEmbedder.HasAttr(nsGkAtoms::disablefullscreen);
|
|
|
|
}
|
2020-08-12 13:57:04 +03:00
|
|
|
if (aEmbedder.IsHTMLElement(nsGkAtoms::iframe)) {
|
|
|
|
// This is controlled by feature policy.
|
|
|
|
return true;
|
2020-06-09 02:49:31 +03:00
|
|
|
}
|
|
|
|
if (const auto* embed = HTMLEmbedElement::FromNode(aEmbedder)) {
|
|
|
|
return embed->AllowFullscreen();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-04-17 03:51:36 +03:00
|
|
|
void BrowsingContext::SetEmbedderElement(Element* aEmbedder) {
|
2020-02-26 02:17:56 +03:00
|
|
|
mEmbeddedByThisProcess = true;
|
2020-04-01 15:59:19 +03:00
|
|
|
|
|
|
|
// Update embedder-element-specific fields in a shared transaction.
|
2020-06-09 02:49:31 +03:00
|
|
|
// Don't do this when clearing our embedder, as we're being destroyed either
|
|
|
|
// way.
|
2019-04-17 03:53:24 +03:00
|
|
|
if (aEmbedder) {
|
2020-04-01 15:59:19 +03:00
|
|
|
Transaction txn;
|
|
|
|
txn.SetEmbedderElementType(Some(aEmbedder->LocalName()));
|
2019-10-01 11:48:25 +03:00
|
|
|
if (nsCOMPtr<nsPIDOMWindowInner> inner =
|
|
|
|
do_QueryInterface(aEmbedder->GetOwnerGlobal())) {
|
2020-02-26 02:17:56 +03:00
|
|
|
txn.SetEmbedderInnerWindowId(inner->WindowID());
|
2019-10-01 11:48:25 +03:00
|
|
|
}
|
2020-06-09 02:49:31 +03:00
|
|
|
txn.SetFullscreenAllowedByOwner(OwnerAllowsFullscreen(*aEmbedder));
|
2020-04-01 15:59:19 +03:00
|
|
|
if (XRE_IsParentProcess() && IsTopContent()) {
|
|
|
|
nsAutoString messageManagerGroup;
|
|
|
|
if (aEmbedder->IsXULElement()) {
|
2021-01-21 23:20:57 +03:00
|
|
|
aEmbedder->GetAttr(nsGkAtoms::messagemanagergroup, messageManagerGroup);
|
|
|
|
if (!aEmbedder->AttrValueIs(kNameSpaceID_None,
|
|
|
|
nsGkAtoms::initiallyactive,
|
|
|
|
nsGkAtoms::_false, eIgnoreCase)) {
|
|
|
|
txn.SetExplicitActive(ExplicitActiveStatus::Active);
|
|
|
|
}
|
2020-04-01 15:59:19 +03:00
|
|
|
}
|
|
|
|
txn.SetMessageManagerGroup(messageManagerGroup);
|
2020-05-08 06:28:38 +03:00
|
|
|
|
|
|
|
bool useGlobalHistory = !aEmbedder->HasAttr(
|
|
|
|
kNameSpaceID_None, nsGkAtoms::disableglobalhistory);
|
|
|
|
txn.SetUseGlobalHistory(useGlobalHistory);
|
2020-04-01 15:59:19 +03:00
|
|
|
}
|
2020-07-31 16:37:13 +03:00
|
|
|
|
|
|
|
MOZ_ALWAYS_SUCCEEDS(txn.Commit(this));
|
2019-04-17 03:51:36 +03:00
|
|
|
}
|
2019-04-17 03:53:24 +03:00
|
|
|
|
|
|
|
mEmbedderElement = aEmbedder;
|
2019-04-17 03:51:36 +03:00
|
|
|
}
|
|
|
|
|
2020-01-24 22:03:10 +03:00
|
|
|
void BrowsingContext::Embed() {
|
|
|
|
if (auto* frame = HTMLIFrameElement::FromNode(mEmbedderElement)) {
|
|
|
|
frame->BindToBrowsingContext(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-24 21:33:09 +03:00
|
|
|
void BrowsingContext::Attach(bool aFromIPC, ContentParent* aOriginProcess) {
|
2020-02-06 22:08:04 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(!mEverAttached);
|
|
|
|
mEverAttached = true;
|
|
|
|
|
2020-04-08 00:39:12 +03:00
|
|
|
if (MOZ_LOG_TEST(GetLog(), LogLevel::Debug)) {
|
|
|
|
nsAutoCString suffix;
|
|
|
|
mOriginAttributes.CreateSuffix(suffix);
|
|
|
|
MOZ_LOG(GetLog(), LogLevel::Debug,
|
|
|
|
("%s: Connecting 0x%08" PRIx64 " to 0x%08" PRIx64
|
|
|
|
" (private=%d, remote=%d, fission=%d, oa=%s)",
|
|
|
|
XRE_IsParentProcess() ? "Parent" : "Child", Id(),
|
2020-04-24 21:33:06 +03:00
|
|
|
GetParent() ? GetParent()->Id() : 0, (int)mPrivateBrowsingId,
|
2020-04-08 00:39:12 +03:00
|
|
|
(int)mUseRemoteTabs, (int)mUseRemoteSubframes, suffix.get()));
|
|
|
|
}
|
2018-12-17 13:45:37 +03:00
|
|
|
|
2019-07-02 23:48:13 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mGroup);
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(!mIsDiscarded);
|
2018-07-26 10:31:00 +03:00
|
|
|
|
2020-05-08 01:18:46 +03:00
|
|
|
AssertCoherentLoadContext();
|
|
|
|
|
2020-04-24 21:33:04 +03:00
|
|
|
// Add ourselves either to our parent or BrowsingContextGroup's child list.
|
|
|
|
if (mParentWindow) {
|
2020-08-06 17:03:30 +03:00
|
|
|
if (!aFromIPC) {
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(!mParentWindow->IsDiscarded(),
|
|
|
|
"local attach in discarded window");
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(!GetParent()->IsDiscarded(),
|
|
|
|
"local attach call in discarded bc");
|
|
|
|
}
|
|
|
|
|
2020-04-24 21:33:04 +03:00
|
|
|
mParentWindow->AppendChildBrowsingContext(this);
|
2020-02-26 01:33:53 +03:00
|
|
|
} else {
|
2020-04-24 21:33:04 +03:00
|
|
|
mGroup->Toplevels().AppendElement(this);
|
2020-02-26 01:33:53 +03:00
|
|
|
}
|
2018-07-26 10:31:00 +03:00
|
|
|
|
2020-01-20 17:57:47 +03:00
|
|
|
if (GetIsPopupSpam()) {
|
2019-10-18 06:04:55 +03:00
|
|
|
PopupBlocker::RegisterOpenPopupSpam();
|
|
|
|
}
|
|
|
|
|
2020-09-08 18:24:13 +03:00
|
|
|
if (IsTop() && GetHasSessionHistory() && !mChildSessionHistory) {
|
2020-05-19 11:57:44 +03:00
|
|
|
CreateChildSHistory();
|
|
|
|
}
|
|
|
|
|
2020-04-24 21:33:09 +03:00
|
|
|
if (XRE_IsContentProcess() && !aFromIPC) {
|
2019-04-04 19:17:47 +03:00
|
|
|
// Send attach to our parent if we need to.
|
2020-04-24 21:33:09 +03:00
|
|
|
ContentChild::GetSingleton()->SendCreateBrowsingContext(
|
|
|
|
mGroup->Id(), GetIPCInitializer());
|
|
|
|
} else if (XRE_IsParentProcess()) {
|
|
|
|
mGroup->EachOtherParent(aOriginProcess, [&](ContentParent* aParent) {
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(IsContent(),
|
|
|
|
"chrome BCG cannot be synced to content process");
|
|
|
|
if (!Canonical()->IsEmbeddedInProcess(aParent->ChildID())) {
|
|
|
|
Unused << aParent->SendCreateBrowsingContext(mGroup->Id(),
|
|
|
|
GetIPCInitializer());
|
|
|
|
}
|
|
|
|
});
|
2020-06-17 05:59:29 +03:00
|
|
|
|
|
|
|
if (IsTopContent() && !Canonical()->GetWebProgress()) {
|
|
|
|
Canonical()->mWebProgress = new BrowsingContextWebProgress();
|
|
|
|
}
|
2019-03-14 21:50:38 +03:00
|
|
|
}
|
2020-11-19 01:19:10 +03:00
|
|
|
|
|
|
|
if (nsCOMPtr<nsIObserverService> obs = services::GetObserverService()) {
|
|
|
|
obs->NotifyWhenScriptSafe(ToSupports(this), "browsing-context-attached",
|
|
|
|
nullptr);
|
|
|
|
}
|
2018-07-26 10:31:00 +03:00
|
|
|
}
|
|
|
|
|
2019-03-14 21:50:38 +03:00
|
|
|
void BrowsingContext::Detach(bool aFromIPC) {
|
2018-07-26 10:31:00 +03:00
|
|
|
MOZ_LOG(GetLog(), LogLevel::Debug,
|
|
|
|
("%s: Detaching 0x%08" PRIx64 " from 0x%08" PRIx64,
|
|
|
|
XRE_IsParentProcess() ? "Parent" : "Child", Id(),
|
2020-04-24 21:33:06 +03:00
|
|
|
GetParent() ? GetParent()->Id() : 0));
|
2018-07-26 10:31:00 +03:00
|
|
|
|
2020-08-31 21:51:45 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mEverAttached);
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(!mIsDiscarded);
|
|
|
|
|
2020-05-21 06:38:14 +03:00
|
|
|
nsCOMPtr<nsIRequestContextService> rcsvc =
|
|
|
|
net::RequestContextService::GetOrCreate();
|
|
|
|
if (rcsvc) {
|
|
|
|
rcsvc->RemoveRequestContext(GetRequestContextId());
|
|
|
|
}
|
|
|
|
|
2020-04-24 21:33:04 +03:00
|
|
|
// This will only ever be null if the cycle-collector has unlinked us. Don't
|
|
|
|
// try to detach ourselves in that case.
|
2019-07-02 23:48:13 +03:00
|
|
|
if (NS_WARN_IF(!mGroup)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-24 21:33:04 +03:00
|
|
|
if (mParentWindow) {
|
|
|
|
mParentWindow->RemoveChildBrowsingContext(this);
|
|
|
|
} else {
|
|
|
|
mGroup->Toplevels().RemoveElement(this);
|
2019-09-10 18:37:54 +03:00
|
|
|
}
|
|
|
|
|
2020-07-30 23:27:41 +03:00
|
|
|
auto callSendDiscard = [&](auto* aActor) {
|
|
|
|
// Hold a strong reference to ourself, and keep our BrowsingContextGroup
|
|
|
|
// alive, until the responses comes back to ensure we don't die while
|
|
|
|
// messages relating to this context are in-flight.
|
|
|
|
//
|
|
|
|
// When the callback is called, the keepalive on our group will be
|
|
|
|
// destroyed, and the reference to the BrowsingContext will be dropped,
|
|
|
|
// which may cause it to be fully destroyed.
|
|
|
|
mGroup->AddKeepAlive();
|
|
|
|
auto callback = [self = RefPtr{this}](auto) {
|
|
|
|
self->mGroup->RemoveKeepAlive();
|
|
|
|
};
|
|
|
|
|
|
|
|
aActor->SendDiscardBrowsingContext(this, callback, callback);
|
|
|
|
};
|
|
|
|
|
|
|
|
if (XRE_IsParentProcess()) {
|
|
|
|
Group()->EachParent([&](ContentParent* aParent) {
|
|
|
|
// Only the embedder process is allowed to initiate a BrowsingContext
|
|
|
|
// detach, so if we've gotten here, the host process already knows we've
|
|
|
|
// been detached, and there's no need to tell it again.
|
|
|
|
//
|
|
|
|
// If the owner process is not the same as the embedder process, its
|
|
|
|
// BrowsingContext will be detached when its nsWebBrowser instance is
|
|
|
|
// destroyed.
|
|
|
|
if (!Canonical()->IsEmbeddedInProcess(aParent->ChildID()) &&
|
|
|
|
!Canonical()->IsOwnedByProcess(aParent->ChildID())) {
|
|
|
|
callSendDiscard(aParent);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else if (!aFromIPC) {
|
|
|
|
callSendDiscard(ContentChild::GetSingleton());
|
2020-02-06 22:07:56 +03:00
|
|
|
}
|
|
|
|
|
2019-09-10 18:37:54 +03:00
|
|
|
mGroup->Unregister(this);
|
2020-07-09 23:34:06 +03:00
|
|
|
UnregisterBrowserId(this);
|
2019-09-10 18:37:54 +03:00
|
|
|
mIsDiscarded = true;
|
|
|
|
|
2020-02-18 16:30:04 +03:00
|
|
|
if (XRE_IsParentProcess()) {
|
|
|
|
nsFocusManager* fm = nsFocusManager::GetFocusManager();
|
|
|
|
if (fm) {
|
|
|
|
fm->BrowsingContextDetached(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-06 22:07:56 +03:00
|
|
|
if (nsCOMPtr<nsIObserverService> obs = services::GetObserverService()) {
|
2019-10-29 20:15:29 +03:00
|
|
|
obs->NotifyObservers(ToSupports(this), "browsing-context-discarded",
|
|
|
|
nullptr);
|
|
|
|
}
|
|
|
|
|
2019-09-10 18:37:54 +03:00
|
|
|
// NOTE: Doesn't use SetClosed, as it will be set in all processes
|
|
|
|
// automatically by calls to Detach()
|
2020-01-20 17:57:47 +03:00
|
|
|
mFields.SetWithoutSyncing<IDX_Closed>(true);
|
Bug 1529684 - Part 6: Store a mIsInProcess flag to preserve WindowProxy behaviour, r=farre
Currently when we have an in-process WindowProxy object, we will attempt
to either use the cached mWindowProxy value, or fetch the
nsGlobalWindowOuter object from through the nsDocShell. Unfortunately,
when the BrowsingContext is detached, we will fail to get the
nsGlobalWindowOuter object. This happens to be OK for our test cases, as
the cached mWindowProxy value doesn't have the chance to go away, but
isn't acceptable long-term.
These patches exascerbated that issue by causing the nsDocShell pointer
itself to be cleared when it is destroyed, which caused the Remote
WindowProxy logic to be triggered. To deal with that case, this patch
adds a new mIsInProcess flag to continue to act like the old code-path.
In the future, we will need to also handle ensuring that the
nsGlobalWindowOuter lives for long enough, however that is not being
done in this patch in order to land it sooner rather than later.
Depends on D22763
Differential Revision: https://phabricator.services.mozilla.com/D22764
--HG--
extra : moz-landing-system : lando
2019-03-14 21:50:54 +03:00
|
|
|
|
2020-01-20 17:57:47 +03:00
|
|
|
if (GetIsPopupSpam()) {
|
2019-10-18 06:04:55 +03:00
|
|
|
PopupBlocker::UnregisterOpenPopupSpam();
|
|
|
|
// NOTE: Doesn't use SetIsPopupSpam, as it will be set all processes
|
|
|
|
// automatically.
|
2020-01-20 17:57:47 +03:00
|
|
|
mFields.SetWithoutSyncing<IDX_IsPopupSpam>(false);
|
2019-10-18 06:04:55 +03:00
|
|
|
}
|
|
|
|
|
2020-04-08 00:39:12 +03:00
|
|
|
AssertOriginAttributesMatchPrivateBrowsing();
|
|
|
|
|
2020-01-16 21:05:14 +03:00
|
|
|
if (XRE_IsParentProcess()) {
|
|
|
|
Canonical()->CanonicalDiscard();
|
|
|
|
}
|
2018-06-28 05:40:00 +03:00
|
|
|
}
|
|
|
|
|
2019-06-06 17:57:18 +03:00
|
|
|
void BrowsingContext::PrepareForProcessChange() {
|
|
|
|
MOZ_LOG(GetLog(), LogLevel::Debug,
|
|
|
|
("%s: Preparing 0x%08" PRIx64 " for a process change",
|
|
|
|
XRE_IsParentProcess() ? "Parent" : "Child", Id()));
|
|
|
|
|
|
|
|
MOZ_ASSERT(mIsInProcess, "Must currently be an in-process frame");
|
2019-07-08 20:27:27 +03:00
|
|
|
MOZ_ASSERT(!mIsDiscarded, "We're already closed?");
|
2019-06-06 17:57:18 +03:00
|
|
|
|
|
|
|
mIsInProcess = false;
|
2019-09-07 22:12:20 +03:00
|
|
|
mUserGestureStart = TimeStamp();
|
2019-06-06 17:57:18 +03:00
|
|
|
|
|
|
|
// NOTE: For now, clear our nsDocShell reference, as we're primarily in a
|
|
|
|
// different process now. This may need to change in the future with
|
|
|
|
// Cross-Process BFCache.
|
|
|
|
mDocShell = nullptr;
|
2020-05-19 11:57:44 +03:00
|
|
|
if (mChildSessionHistory) {
|
|
|
|
// This can be removed once session history is stored exclusively in the
|
|
|
|
// parent process.
|
|
|
|
mChildSessionHistory->SetIsInProcess(false);
|
|
|
|
}
|
Bug 1510760, part 5 - Support local-to-remote window proxy transplanting. r=tcampbell,peterv
When a BrowsingContext changes from being local to remote, we have to
change all window proxies from being local to remote, using
transplanting. The actual window proxy becomes a remote window
proxy. Cross compartment wrappers (CCWs) to the window proxy also
become remote window proxies in their respective compartments, rather
than CCWs to a remote proxy in the old compartment of the window
proxy, because the window is no longer actually in that
compartment. This also avoids having to figure out what Xray behavior
for remote window proxies should be.
This patch uses the transplanting support I added to
GetRemoteOuterWindowProxy() in the previous patch to ensure that the
remote proxy map holds the correct value after transplanting finishes.
It drops the requirement that both arguments to JS_TransplantObject
have the same class, because we need to transplant a window proxy with
a remote window proxy. It also deals with this by not adding origobj
to the wrapper map unless it is a CCW, to handle transplanting to a
remote proxy.
The core design here, with the remote window proxies in every
compartment, is taken from a patch by peterv.
Differential Revision: https://phabricator.services.mozilla.com/D35730
--HG--
extra : moz-landing-system : lando
2019-07-18 22:36:19 +03:00
|
|
|
|
|
|
|
if (!mWindowProxy) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We have to go through mWindowProxy rather than calling GetDOMWindow() on
|
|
|
|
// mDocShell because the mDocshell reference gets cleared immediately after
|
|
|
|
// the window is closed.
|
|
|
|
nsGlobalWindowOuter::PrepareForProcessChange(mWindowProxy);
|
|
|
|
MOZ_ASSERT(!mWindowProxy);
|
2019-06-06 17:57:18 +03:00
|
|
|
}
|
|
|
|
|
2020-12-11 18:43:19 +03:00
|
|
|
bool BrowsingContext::IsCached() const {
|
2020-04-24 21:33:04 +03:00
|
|
|
return mParentWindow && mParentWindow->IsCached();
|
2020-04-24 05:31:55 +03:00
|
|
|
}
|
|
|
|
|
2020-12-11 18:43:19 +03:00
|
|
|
bool BrowsingContext::IsTargetable() const {
|
2020-01-20 17:57:47 +03:00
|
|
|
return !GetClosed() && !mIsDiscarded && !IsCached();
|
2019-07-17 18:35:04 +03:00
|
|
|
}
|
|
|
|
|
2019-04-15 18:14:54 +03:00
|
|
|
bool BrowsingContext::HasOpener() const {
|
2020-01-20 17:57:47 +03:00
|
|
|
return sBrowsingContexts->Contains(GetOpenerId());
|
2019-04-15 18:14:54 +03:00
|
|
|
}
|
|
|
|
|
2020-08-31 21:51:56 +03:00
|
|
|
bool BrowsingContext::AncestorsAreCurrent() const {
|
|
|
|
const BrowsingContext* bc = this;
|
|
|
|
while (true) {
|
|
|
|
if (bc->IsDiscarded()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (WindowContext* wc = bc->GetParentWindowContext()) {
|
|
|
|
if (wc->IsCached() || wc->IsDiscarded()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bc = wc->GetBrowsingContext();
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-24 21:33:04 +03:00
|
|
|
Span<RefPtr<BrowsingContext>> BrowsingContext::Children() const {
|
|
|
|
if (WindowContext* current = mCurrentWindowContext) {
|
|
|
|
return current->Children();
|
|
|
|
}
|
|
|
|
return Span<RefPtr<BrowsingContext>>();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowsingContext::GetChildren(
|
|
|
|
nsTArray<RefPtr<BrowsingContext>>& aChildren) {
|
|
|
|
aChildren.AppendElements(Children());
|
2018-08-29 05:00:00 +03:00
|
|
|
}
|
|
|
|
|
2020-01-20 17:58:52 +03:00
|
|
|
void BrowsingContext::GetWindowContexts(
|
|
|
|
nsTArray<RefPtr<WindowContext>>& aWindows) {
|
|
|
|
aWindows.AppendElements(mWindowContexts);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowsingContext::RegisterWindowContext(WindowContext* aWindow) {
|
|
|
|
MOZ_ASSERT(!mWindowContexts.Contains(aWindow),
|
|
|
|
"WindowContext already registered!");
|
2020-04-24 21:33:04 +03:00
|
|
|
MOZ_ASSERT(aWindow->GetBrowsingContext() == this);
|
|
|
|
|
2020-01-20 17:58:52 +03:00
|
|
|
mWindowContexts.AppendElement(aWindow);
|
2020-04-24 21:33:04 +03:00
|
|
|
|
|
|
|
// If the newly registered WindowContext is for our current inner window ID,
|
|
|
|
// re-run the `DidSet` handler to re-establish the relationship.
|
2020-04-01 15:54:28 +03:00
|
|
|
if (aWindow->InnerWindowId() == GetCurrentInnerWindowId()) {
|
2020-04-24 21:33:04 +03:00
|
|
|
DidSet(FieldIndex<IDX_CurrentInnerWindowId>());
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mCurrentWindowContext == aWindow);
|
2020-04-01 15:54:28 +03:00
|
|
|
}
|
2020-01-20 17:58:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void BrowsingContext::UnregisterWindowContext(WindowContext* aWindow) {
|
|
|
|
MOZ_ASSERT(mWindowContexts.Contains(aWindow),
|
|
|
|
"WindowContext not registered!");
|
|
|
|
mWindowContexts.RemoveElement(aWindow);
|
|
|
|
|
2020-04-24 21:33:04 +03:00
|
|
|
// If our currently active window was unregistered, clear our reference to it.
|
2020-01-20 17:58:52 +03:00
|
|
|
if (aWindow == mCurrentWindowContext) {
|
2020-04-24 21:33:04 +03:00
|
|
|
// Re-read our `CurrentInnerWindowId` value and use it to set
|
|
|
|
// `mCurrentWindowContext`. As `aWindow` is now unregistered and discarded,
|
|
|
|
// we won't find it, and the value will be cleared back to `nullptr`.
|
|
|
|
DidSet(FieldIndex<IDX_CurrentInnerWindowId>());
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mCurrentWindowContext == nullptr);
|
2020-01-20 17:58:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-30 00:10:36 +03:00
|
|
|
void BrowsingContext::PreOrderWalk(
|
|
|
|
const std::function<void(BrowsingContext*)>& aCallback) {
|
|
|
|
aCallback(this);
|
2020-09-22 01:41:01 +03:00
|
|
|
|
|
|
|
AutoTArray<RefPtr<BrowsingContext>, 8> children;
|
|
|
|
children.AppendElements(Children());
|
|
|
|
|
|
|
|
for (auto& child : children) {
|
2020-07-30 00:10:36 +03:00
|
|
|
child->PreOrderWalk(aCallback);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowsingContext::PostOrderWalk(
|
|
|
|
const std::function<void(BrowsingContext*)>& aCallback) {
|
2020-09-22 01:41:01 +03:00
|
|
|
AutoTArray<RefPtr<BrowsingContext>, 8> children;
|
|
|
|
children.AppendElements(Children());
|
|
|
|
|
|
|
|
for (auto& child : children) {
|
2020-07-30 00:10:36 +03:00
|
|
|
child->PostOrderWalk(aCallback);
|
|
|
|
}
|
|
|
|
|
|
|
|
aCallback(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowsingContext::GetAllBrowsingContextsInSubtree(
|
|
|
|
nsTArray<RefPtr<BrowsingContext>>& aBrowsingContexts) {
|
|
|
|
PreOrderWalk([&](BrowsingContext* aContext) {
|
|
|
|
aBrowsingContexts.AppendElement(aContext);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-02-15 12:59:21 +03:00
|
|
|
// FindWithName follows the rules for choosing a browsing context,
|
|
|
|
// with the exception of sandboxing for iframes. The implementation
|
|
|
|
// for arbitrarily choosing between two browsing contexts with the
|
|
|
|
// same name is as follows:
|
|
|
|
//
|
|
|
|
// 1) The start browsing context, i.e. 'this'
|
|
|
|
// 2) Descendants in insertion order
|
|
|
|
// 3) The parent
|
|
|
|
// 4) Siblings and their children, both in insertion order
|
|
|
|
// 5) After this we iteratively follow the parent chain, repeating 3
|
|
|
|
// and 4 until
|
|
|
|
// 6) If there is no parent, consider all other top level browsing
|
|
|
|
// contexts and their children, both in insertion order
|
|
|
|
//
|
|
|
|
// See
|
|
|
|
// https://html.spec.whatwg.org/multipage/browsers.html#the-rules-for-choosing-a-browsing-context-given-a-browsing-context-name
|
2019-10-25 18:34:30 +03:00
|
|
|
BrowsingContext* BrowsingContext::FindWithName(
|
|
|
|
const nsAString& aName, bool aUseEntryGlobalForAccessCheck) {
|
2019-10-24 17:53:07 +03:00
|
|
|
RefPtr<BrowsingContext> requestingContext = this;
|
2019-10-25 18:34:30 +03:00
|
|
|
if (aUseEntryGlobalForAccessCheck) {
|
|
|
|
if (nsCOMPtr<nsIDocShell> caller = do_GetInterface(GetEntryGlobal())) {
|
|
|
|
if (caller->GetBrowsingContext()) {
|
|
|
|
requestingContext = caller->GetBrowsingContext();
|
|
|
|
}
|
2019-10-24 17:53:07 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-15 12:59:21 +03:00
|
|
|
BrowsingContext* found = nullptr;
|
|
|
|
if (aName.IsEmpty()) {
|
|
|
|
// You can't find a browsing context with an empty name.
|
|
|
|
found = nullptr;
|
|
|
|
} else if (aName.LowerCaseEqualsLiteral("_blank")) {
|
|
|
|
// Just return null. Caller must handle creating a new window with
|
|
|
|
// a blank name.
|
|
|
|
found = nullptr;
|
2019-10-24 17:53:07 +03:00
|
|
|
} else if (nsContentUtils::IsSpecialName(aName)) {
|
2019-10-24 17:53:07 +03:00
|
|
|
found = FindWithSpecialName(aName, *requestingContext);
|
2019-07-31 03:30:55 +03:00
|
|
|
} else if (BrowsingContext* child =
|
2019-10-24 17:53:07 +03:00
|
|
|
FindWithNameInSubtree(aName, *requestingContext)) {
|
2019-02-15 12:59:21 +03:00
|
|
|
found = child;
|
|
|
|
} else {
|
|
|
|
BrowsingContext* current = this;
|
|
|
|
|
|
|
|
do {
|
2020-04-24 21:33:04 +03:00
|
|
|
Span<RefPtr<BrowsingContext>> siblings;
|
2020-04-24 21:33:06 +03:00
|
|
|
BrowsingContext* parent = current->GetParent();
|
2019-02-15 12:59:21 +03:00
|
|
|
|
|
|
|
if (!parent) {
|
|
|
|
// We've reached the root of the tree, consider browsing
|
|
|
|
// contexts in the same browsing context group.
|
2020-04-24 21:33:04 +03:00
|
|
|
siblings = mGroup->Toplevels();
|
2019-07-31 03:30:55 +03:00
|
|
|
} else if (parent->NameEquals(aName) &&
|
2019-10-24 17:53:07 +03:00
|
|
|
requestingContext->CanAccess(parent) &&
|
2019-07-17 18:31:04 +03:00
|
|
|
parent->IsTargetable()) {
|
2019-02-15 12:59:21 +03:00
|
|
|
found = parent;
|
|
|
|
break;
|
|
|
|
} else {
|
2020-04-24 21:33:04 +03:00
|
|
|
siblings = parent->Children();
|
2019-02-15 12:59:21 +03:00
|
|
|
}
|
|
|
|
|
2020-04-24 21:33:04 +03:00
|
|
|
for (BrowsingContext* sibling : siblings) {
|
2019-02-15 12:59:21 +03:00
|
|
|
if (sibling == current) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (BrowsingContext* relative =
|
2019-10-24 17:53:07 +03:00
|
|
|
sibling->FindWithNameInSubtree(aName, *requestingContext)) {
|
2019-02-15 12:59:21 +03:00
|
|
|
found = relative;
|
|
|
|
// Breaks the outer loop
|
|
|
|
parent = nullptr;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
current = parent;
|
|
|
|
} while (current);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Helpers should perform access control checks, which means that we
|
|
|
|
// only need to assert that we can access found.
|
2019-10-24 17:53:07 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(!found || requestingContext->CanAccess(found));
|
2019-02-15 12:59:21 +03:00
|
|
|
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
2019-07-31 03:30:55 +03:00
|
|
|
BrowsingContext* BrowsingContext::FindChildWithName(
|
|
|
|
const nsAString& aName, BrowsingContext& aRequestingContext) {
|
2019-02-15 12:59:21 +03:00
|
|
|
if (aName.IsEmpty()) {
|
|
|
|
// You can't find a browsing context with the empty name.
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2020-04-24 21:33:04 +03:00
|
|
|
for (BrowsingContext* child : Children()) {
|
2019-07-31 03:30:55 +03:00
|
|
|
if (child->NameEquals(aName) && aRequestingContext.CanAccess(child) &&
|
|
|
|
child->IsTargetable()) {
|
2019-02-15 12:59:21 +03:00
|
|
|
return child;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-07-31 03:30:55 +03:00
|
|
|
BrowsingContext* BrowsingContext::FindWithSpecialName(
|
|
|
|
const nsAString& aName, BrowsingContext& aRequestingContext) {
|
2019-02-15 12:59:21 +03:00
|
|
|
// TODO(farre): Neither BrowsingContext nor nsDocShell checks if the
|
|
|
|
// browsing context pointed to by a special name is active. Should
|
|
|
|
// it be? See Bug 1527913.
|
|
|
|
if (aName.LowerCaseEqualsLiteral("_self")) {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aName.LowerCaseEqualsLiteral("_parent")) {
|
2020-04-24 21:33:06 +03:00
|
|
|
if (BrowsingContext* parent = GetParent()) {
|
|
|
|
return aRequestingContext.CanAccess(parent) ? parent : nullptr;
|
2019-08-02 04:45:47 +03:00
|
|
|
}
|
|
|
|
return this;
|
2019-02-15 12:59:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aName.LowerCaseEqualsLiteral("_top")) {
|
2019-04-09 09:19:24 +03:00
|
|
|
BrowsingContext* top = Top();
|
2019-02-15 12:59:21 +03:00
|
|
|
|
2019-07-31 03:30:55 +03:00
|
|
|
return aRequestingContext.CanAccess(top) ? top : nullptr;
|
2019-02-15 12:59:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
BrowsingContext* BrowsingContext::FindWithNameInSubtree(
|
2019-07-31 03:30:55 +03:00
|
|
|
const nsAString& aName, BrowsingContext& aRequestingContext) {
|
2019-02-15 12:59:21 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(!aName.IsEmpty());
|
|
|
|
|
2019-07-31 03:30:55 +03:00
|
|
|
if (NameEquals(aName) && aRequestingContext.CanAccess(this) &&
|
2019-07-17 18:31:04 +03:00
|
|
|
IsTargetable()) {
|
2019-02-15 12:59:21 +03:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2020-04-24 21:33:04 +03:00
|
|
|
for (BrowsingContext* child : Children()) {
|
2019-02-15 12:59:21 +03:00
|
|
|
if (BrowsingContext* found =
|
|
|
|
child->FindWithNameInSubtree(aName, aRequestingContext)) {
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-07-31 21:40:39 +03:00
|
|
|
// For historical context, see:
|
|
|
|
//
|
|
|
|
// Bug 13871: Prevent frameset spoofing
|
|
|
|
// Bug 103638: Targets with same name in different windows open in wrong
|
|
|
|
// window with javascript
|
|
|
|
// Bug 408052: Adopt "ancestor" frame navigation policy
|
|
|
|
// Bug 1570207: Refactor logic to rely on BrowsingContextGroups to enforce
|
|
|
|
// origin attribute isolation.
|
|
|
|
bool BrowsingContext::CanAccess(BrowsingContext* aTarget,
|
|
|
|
bool aConsiderOpener) {
|
|
|
|
MOZ_ASSERT(
|
|
|
|
mDocShell,
|
|
|
|
"CanAccess() may only be called in the process of the accessing window");
|
|
|
|
MOZ_ASSERT(aTarget, "Must have a target");
|
|
|
|
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(
|
|
|
|
Group() == aTarget->Group(),
|
|
|
|
"A BrowsingContext should never see a context from a different group");
|
|
|
|
|
|
|
|
// A frame can navigate itself and its own root.
|
|
|
|
if (aTarget == this || aTarget == Top()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// A frame can navigate any frame with a same-origin ancestor.
|
|
|
|
for (BrowsingContext* bc = aTarget; bc; bc = bc->GetParent()) {
|
2020-01-23 21:14:42 +03:00
|
|
|
if (bc->mDocShell && nsDocShell::ValidateOrigin(this, bc)) {
|
2019-07-31 21:40:39 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the target is a top-level document, a frame can navigate it if it can
|
|
|
|
// navigate its opener.
|
|
|
|
if (aConsiderOpener && !aTarget->GetParent()) {
|
|
|
|
if (RefPtr<BrowsingContext> opener = aTarget->GetOpener()) {
|
|
|
|
return CanAccess(opener, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2019-02-15 12:59:21 +03:00
|
|
|
}
|
|
|
|
|
2020-04-04 05:42:30 +03:00
|
|
|
bool BrowsingContext::IsSandboxedFrom(BrowsingContext* aTarget) {
|
|
|
|
// If no target then not sandboxed.
|
|
|
|
if (!aTarget) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We cannot be sandboxed from ourselves.
|
|
|
|
if (aTarget == this) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Default the sandbox flags to our flags, so that if we can't retrieve the
|
|
|
|
// active document, we will still enforce our own.
|
|
|
|
uint32_t sandboxFlags = GetSandboxFlags();
|
|
|
|
if (mDocShell) {
|
|
|
|
if (RefPtr<Document> doc = mDocShell->GetExtantDocument()) {
|
|
|
|
sandboxFlags = doc->GetSandboxFlags();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If no flags, we are not sandboxed at all.
|
|
|
|
if (!sandboxFlags) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If aTarget has an ancestor, it is not top level.
|
|
|
|
if (RefPtr<BrowsingContext> ancestorOfTarget = aTarget->GetParent()) {
|
|
|
|
do {
|
|
|
|
// We are not sandboxed if we are an ancestor of target.
|
|
|
|
if (ancestorOfTarget == this) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
ancestorOfTarget = ancestorOfTarget->GetParent();
|
|
|
|
} while (ancestorOfTarget);
|
|
|
|
|
|
|
|
// Otherwise, we are sandboxed from aTarget.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// aTarget is top level, are we the "one permitted sandboxed
|
|
|
|
// navigator", i.e. did we open aTarget?
|
|
|
|
if (aTarget->GetOnePermittedSandboxedNavigatorId() == Id()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If SANDBOXED_TOPLEVEL_NAVIGATION flag is not on, we are not sandboxed
|
|
|
|
// from our top.
|
|
|
|
if (!(sandboxFlags & SANDBOXED_TOPLEVEL_NAVIGATION) && aTarget == Top()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-06-01 15:46:31 +03:00
|
|
|
// If SANDBOXED_TOPLEVEL_NAVIGATION_USER_ACTIVATION flag is not on, we are not
|
|
|
|
// sandboxed from our top if we have user interaction.
|
|
|
|
if (!(sandboxFlags & SANDBOXED_TOPLEVEL_NAVIGATION_USER_ACTIVATION) &&
|
2020-08-17 14:02:34 +03:00
|
|
|
mCurrentWindowContext &&
|
|
|
|
mCurrentWindowContext->HasValidTransientUserGestureActivation() &&
|
|
|
|
aTarget == Top()) {
|
2020-06-01 15:46:31 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-04-04 05:42:30 +03:00
|
|
|
// Otherwise, we are sandboxed from aTarget.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-12-10 15:12:25 +03:00
|
|
|
RefPtr<SessionStorageManager> BrowsingContext::GetSessionStorageManager() {
|
|
|
|
RefPtr<SessionStorageManager>& manager = Top()->mSessionStorageManager;
|
|
|
|
if (!manager) {
|
2019-12-10 15:12:32 +03:00
|
|
|
manager = new SessionStorageManager(this);
|
2019-12-10 15:12:25 +03:00
|
|
|
}
|
|
|
|
return manager;
|
|
|
|
}
|
|
|
|
|
2020-05-25 15:51:53 +03:00
|
|
|
bool BrowsingContext::CrossOriginIsolated() {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2020-06-09 11:10:42 +03:00
|
|
|
return StaticPrefs::
|
|
|
|
dom_postMessage_sharedArrayBuffer_withCOOP_COEP_AtStartup() &&
|
2020-05-25 15:51:53 +03:00
|
|
|
Top()->GetOpenerPolicy() ==
|
|
|
|
nsILoadInfo::
|
|
|
|
OPENER_POLICY_SAME_ORIGIN_EMBEDDER_POLICY_REQUIRE_CORP &&
|
|
|
|
XRE_IsContentProcess() &&
|
2020-07-08 23:15:59 +03:00
|
|
|
StringBeginsWith(ContentChild::GetSingleton()->GetRemoteType(),
|
|
|
|
WITH_COOP_COEP_REMOTE_TYPE_PREFIX);
|
2020-05-25 15:51:53 +03:00
|
|
|
}
|
|
|
|
|
2020-08-28 20:20:30 +03:00
|
|
|
void BrowsingContext::SetTriggeringAndInheritPrincipals(
|
|
|
|
nsIPrincipal* aTriggeringPrincipal, nsIPrincipal* aPrincipalToInherit,
|
|
|
|
uint64_t aLoadIdentifier) {
|
|
|
|
mTriggeringPrincipal = Some(
|
|
|
|
PrincipalWithLoadIdentifierTuple(aTriggeringPrincipal, aLoadIdentifier));
|
|
|
|
if (aPrincipalToInherit) {
|
|
|
|
mPrincipalToInherit = Some(
|
|
|
|
PrincipalWithLoadIdentifierTuple(aPrincipalToInherit, aLoadIdentifier));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Tuple<nsCOMPtr<nsIPrincipal>, nsCOMPtr<nsIPrincipal>>
|
|
|
|
BrowsingContext::GetTriggeringAndInheritPrincipalsForCurrentLoad() {
|
|
|
|
nsCOMPtr<nsIPrincipal> triggeringPrincipal =
|
|
|
|
GetSavedPrincipal(mTriggeringPrincipal);
|
|
|
|
nsCOMPtr<nsIPrincipal> principalToInherit =
|
|
|
|
GetSavedPrincipal(mPrincipalToInherit);
|
|
|
|
return MakeTuple(triggeringPrincipal, principalToInherit);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIPrincipal* BrowsingContext::GetSavedPrincipal(
|
|
|
|
Maybe<PrincipalWithLoadIdentifierTuple> aPrincipalTuple) {
|
|
|
|
if (aPrincipalTuple) {
|
|
|
|
nsCOMPtr<nsIPrincipal> principal;
|
|
|
|
uint64_t loadIdentifier;
|
|
|
|
Tie(principal, loadIdentifier) = *aPrincipalTuple;
|
|
|
|
// We want to return a principal only if the load identifier for it
|
|
|
|
// matches the current one for this BC.
|
|
|
|
if (auto current = GetCurrentLoadIdentifier();
|
|
|
|
current && *current == loadIdentifier) {
|
|
|
|
return principal;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-07-26 10:31:00 +03:00
|
|
|
BrowsingContext::~BrowsingContext() {
|
2020-04-24 21:33:04 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(!mParentWindow ||
|
|
|
|
!mParentWindow->mChildren.Contains(this));
|
2019-01-30 19:07:21 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(!mGroup || !mGroup->Toplevels().Contains(this));
|
2018-07-26 10:31:00 +03:00
|
|
|
|
2019-12-01 00:13:24 +03:00
|
|
|
mDeprioritizedLoadRunner.clear();
|
|
|
|
|
2018-07-26 10:31:00 +03:00
|
|
|
if (sBrowsingContexts) {
|
2019-05-24 23:15:53 +03:00
|
|
|
sBrowsingContexts->Remove(Id());
|
2018-07-26 10:31:00 +03:00
|
|
|
}
|
2020-07-09 23:34:06 +03:00
|
|
|
UnregisterBrowserId(this);
|
2018-07-26 10:31:00 +03:00
|
|
|
}
|
|
|
|
|
2020-08-31 21:51:45 +03:00
|
|
|
/* static */
|
|
|
|
void BrowsingContext::DiscardFromContentParent(ContentParent* aCP) {
|
|
|
|
MOZ_ASSERT(XRE_IsParentProcess());
|
|
|
|
|
|
|
|
if (sBrowsingContexts) {
|
|
|
|
AutoTArray<RefPtr<BrowsingContext>, 8> toDiscard;
|
|
|
|
for (const auto& entry : *sBrowsingContexts) {
|
|
|
|
auto* bc = entry.GetData()->Canonical();
|
|
|
|
if (!bc->IsDiscarded() && bc->IsEmbeddedInProcess(aCP->ChildID())) {
|
|
|
|
toDiscard.AppendElement(bc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (BrowsingContext* bc : toDiscard) {
|
|
|
|
bc->Detach(/* aFromIPC */ true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-29 05:00:00 +03:00
|
|
|
nsISupports* BrowsingContext::GetParentObject() const {
|
|
|
|
return xpc::NativeGlobal(xpc::PrivilegedJunkScope());
|
|
|
|
}
|
|
|
|
|
|
|
|
JSObject* BrowsingContext::WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
|
|
|
return BrowsingContext_Binding::Wrap(aCx, this, aGivenProto);
|
|
|
|
}
|
|
|
|
|
2019-07-02 01:24:09 +03:00
|
|
|
bool BrowsingContext::WriteStructuredClone(JSContext* aCx,
|
|
|
|
JSStructuredCloneWriter* aWriter,
|
|
|
|
StructuredCloneHolder* aHolder) {
|
2020-02-06 22:08:04 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mEverAttached);
|
2019-07-02 01:24:09 +03:00
|
|
|
return (JS_WriteUint32Pair(aWriter, SCTAG_DOM_BROWSING_CONTEXT, 0) &&
|
|
|
|
JS_WriteUint32Pair(aWriter, uint32_t(Id()), uint32_t(Id() >> 32)));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
JSObject* BrowsingContext::ReadStructuredClone(JSContext* aCx,
|
|
|
|
JSStructuredCloneReader* aReader,
|
|
|
|
StructuredCloneHolder* aHolder) {
|
|
|
|
uint32_t idLow = 0;
|
|
|
|
uint32_t idHigh = 0;
|
|
|
|
if (!JS_ReadUint32Pair(aReader, &idLow, &idHigh)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
uint64_t id = uint64_t(idHigh) << 32 | idLow;
|
|
|
|
|
|
|
|
// Note: Do this check after reading our ID data. Returning null will abort
|
|
|
|
// the decode operation anyway, but we should at least be as safe as possible.
|
|
|
|
if (NS_WARN_IF(!NS_IsMainThread())) {
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(false,
|
|
|
|
"We shouldn't be trying to decode a BrowsingContext "
|
|
|
|
"on a background thread.");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS::RootedValue val(aCx, JS::NullValue());
|
|
|
|
// We'll get rooting hazard errors from the RefPtr destructor if it isn't
|
|
|
|
// destroyed before we try to return a raw JSObject*, so create it in its own
|
|
|
|
// scope.
|
|
|
|
if (RefPtr<BrowsingContext> context = Get(id)) {
|
|
|
|
if (!GetOrCreateDOMReflector(aCx, context, &val) || !val.isObject()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return val.toObjectOrNull();
|
|
|
|
}
|
|
|
|
|
2020-04-08 00:39:12 +03:00
|
|
|
bool BrowsingContext::CanSetOriginAttributes() {
|
|
|
|
// A discarded BrowsingContext has already been destroyed, and cannot modify
|
|
|
|
// its OriginAttributes.
|
|
|
|
if (NS_WARN_IF(IsDiscarded())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Before attaching is the safest time to set OriginAttributes, and the only
|
|
|
|
// allowed time for content BrowsingContexts.
|
|
|
|
if (!EverAttached()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Attached content BrowsingContexts may have been synced to other processes.
|
|
|
|
if (NS_WARN_IF(IsContent())) {
|
|
|
|
MOZ_CRASH();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(XRE_IsParentProcess());
|
|
|
|
|
|
|
|
// Cannot set OriginAttributes after we've created our child BrowsingContext.
|
|
|
|
if (NS_WARN_IF(!Children().IsEmpty())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only allow setting OriginAttributes if we have no associated document, or
|
|
|
|
// the document is still `about:blank`.
|
|
|
|
// TODO: Bug 1273058 - should have no document when setting origin attributes.
|
|
|
|
if (WindowGlobalParent* window = Canonical()->GetCurrentWindowGlobal()) {
|
|
|
|
if (nsIURI* uri = window->GetDocumentURI()) {
|
|
|
|
MOZ_ASSERT(NS_IsAboutBlank(uri));
|
|
|
|
return NS_IsAboutBlank(uri);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-26 03:53:01 +03:00
|
|
|
Nullable<WindowProxyHolder> BrowsingContext::GetAssociatedWindow() {
|
|
|
|
// nsILoadContext usually only returns same-process windows,
|
|
|
|
// so we intentionally return nullptr if this BC is out of
|
|
|
|
// process.
|
|
|
|
if (IsInProcess()) {
|
|
|
|
return WindowProxyHolder(this);
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
Nullable<WindowProxyHolder> BrowsingContext::GetTopWindow() {
|
|
|
|
return Top()->GetAssociatedWindow();
|
|
|
|
}
|
|
|
|
|
|
|
|
Element* BrowsingContext::GetTopFrameElement() {
|
|
|
|
return Top()->GetEmbedderElement();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowsingContext::SetUsePrivateBrowsing(bool aUsePrivateBrowsing,
|
|
|
|
ErrorResult& aError) {
|
|
|
|
nsresult rv = SetUsePrivateBrowsing(aUsePrivateBrowsing);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aError.Throw(rv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowsingContext::SetUseTrackingProtectionWebIDL(
|
2020-07-31 16:37:13 +03:00
|
|
|
bool aUseTrackingProtection, ErrorResult& aRv) {
|
|
|
|
SetForceEnableTrackingProtection(aUseTrackingProtection, aRv);
|
2020-04-26 03:53:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void BrowsingContext::GetOriginAttributes(JSContext* aCx,
|
|
|
|
JS::MutableHandle<JS::Value> aVal,
|
|
|
|
ErrorResult& aError) {
|
|
|
|
AssertOriginAttributesMatchPrivateBrowsing();
|
|
|
|
|
|
|
|
if (!ToJSValue(aCx, mOriginAttributes, aVal)) {
|
|
|
|
aError.NoteJSContextException(aCx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-08 00:39:12 +03:00
|
|
|
NS_IMETHODIMP BrowsingContext::GetAssociatedWindow(
|
|
|
|
mozIDOMWindowProxy** aAssociatedWindow) {
|
|
|
|
nsCOMPtr<mozIDOMWindowProxy> win = GetDOMWindow();
|
|
|
|
win.forget(aAssociatedWindow);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP BrowsingContext::GetTopWindow(mozIDOMWindowProxy** aTopWindow) {
|
|
|
|
return Top()->GetAssociatedWindow(aTopWindow);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP BrowsingContext::GetTopFrameElement(Element** aTopFrameElement) {
|
2020-04-26 03:53:01 +03:00
|
|
|
RefPtr<Element> topFrameElement = GetTopFrameElement();
|
2020-04-08 00:39:12 +03:00
|
|
|
topFrameElement.forget(aTopFrameElement);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP BrowsingContext::GetIsContent(bool* aIsContent) {
|
|
|
|
*aIsContent = IsContent();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP BrowsingContext::GetUsePrivateBrowsing(
|
|
|
|
bool* aUsePrivateBrowsing) {
|
|
|
|
*aUsePrivateBrowsing = mPrivateBrowsingId > 0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP BrowsingContext::SetUsePrivateBrowsing(bool aUsePrivateBrowsing) {
|
|
|
|
if (!CanSetOriginAttributes()) {
|
|
|
|
bool changed = aUsePrivateBrowsing != (mPrivateBrowsingId > 0);
|
|
|
|
if (changed) {
|
|
|
|
NS_WARNING("SetUsePrivateBrowsing when !CanSetOriginAttributes()");
|
|
|
|
}
|
|
|
|
return changed ? NS_ERROR_FAILURE : NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SetPrivateBrowsing(aUsePrivateBrowsing);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP BrowsingContext::SetPrivateBrowsing(bool aPrivateBrowsing) {
|
|
|
|
if (!CanSetOriginAttributes()) {
|
|
|
|
NS_WARNING("Attempt to set PrivateBrowsing when !CanSetOriginAttributes");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool changed = aPrivateBrowsing != (mPrivateBrowsingId > 0);
|
|
|
|
if (changed) {
|
|
|
|
mPrivateBrowsingId = aPrivateBrowsing ? 1 : 0;
|
|
|
|
if (IsContent()) {
|
|
|
|
mOriginAttributes.SyncAttributesWithPrivateBrowsing(aPrivateBrowsing);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
AssertOriginAttributesMatchPrivateBrowsing();
|
|
|
|
|
|
|
|
if (changed && mDocShell) {
|
|
|
|
nsDocShell::Cast(mDocShell)->NotifyPrivateBrowsingChanged();
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP BrowsingContext::GetUseRemoteTabs(bool* aUseRemoteTabs) {
|
|
|
|
*aUseRemoteTabs = mUseRemoteTabs;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP BrowsingContext::SetRemoteTabs(bool aUseRemoteTabs) {
|
|
|
|
if (!CanSetOriginAttributes()) {
|
|
|
|
NS_WARNING("Attempt to set RemoteTabs when !CanSetOriginAttributes");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool annotated = false;
|
|
|
|
if (aUseRemoteTabs && !annotated) {
|
|
|
|
annotated = true;
|
|
|
|
CrashReporter::AnnotateCrashReport(CrashReporter::Annotation::DOMIPCEnabled,
|
|
|
|
true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't allow non-remote tabs with remote subframes.
|
|
|
|
if (NS_WARN_IF(!aUseRemoteTabs && mUseRemoteSubframes)) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
mUseRemoteTabs = aUseRemoteTabs;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP BrowsingContext::GetUseRemoteSubframes(
|
|
|
|
bool* aUseRemoteSubframes) {
|
|
|
|
*aUseRemoteSubframes = mUseRemoteSubframes;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP BrowsingContext::SetRemoteSubframes(bool aUseRemoteSubframes) {
|
|
|
|
if (!CanSetOriginAttributes()) {
|
|
|
|
NS_WARNING("Attempt to set RemoteSubframes when !CanSetOriginAttributes");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool annotated = false;
|
|
|
|
if (aUseRemoteSubframes && !annotated) {
|
|
|
|
annotated = true;
|
|
|
|
CrashReporter::AnnotateCrashReport(
|
|
|
|
CrashReporter::Annotation::DOMFissionEnabled, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't allow non-remote tabs with remote subframes.
|
|
|
|
if (NS_WARN_IF(aUseRemoteSubframes && !mUseRemoteTabs)) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
mUseRemoteSubframes = aUseRemoteSubframes;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP BrowsingContext::GetUseTrackingProtection(
|
|
|
|
bool* aUseTrackingProtection) {
|
|
|
|
*aUseTrackingProtection = false;
|
|
|
|
|
|
|
|
if (GetForceEnableTrackingProtection() ||
|
|
|
|
StaticPrefs::privacy_trackingprotection_enabled() ||
|
|
|
|
(UsePrivateBrowsing() &&
|
|
|
|
StaticPrefs::privacy_trackingprotection_pbmode_enabled())) {
|
|
|
|
*aUseTrackingProtection = true;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2020-04-24 21:33:06 +03:00
|
|
|
if (GetParent()) {
|
|
|
|
return GetParent()->GetUseTrackingProtection(aUseTrackingProtection);
|
2020-04-08 00:39:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP BrowsingContext::SetUseTrackingProtection(
|
|
|
|
bool aUseTrackingProtection) {
|
2020-07-31 16:37:13 +03:00
|
|
|
return SetForceEnableTrackingProtection(aUseTrackingProtection);
|
2020-04-08 00:39:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP BrowsingContext::GetScriptableOriginAttributes(
|
|
|
|
JSContext* aCx, JS::MutableHandle<JS::Value> aVal) {
|
|
|
|
AssertOriginAttributesMatchPrivateBrowsing();
|
|
|
|
|
|
|
|
bool ok = ToJSValue(aCx, mOriginAttributes, aVal);
|
|
|
|
NS_ENSURE_TRUE(ok, NS_ERROR_FAILURE);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(void)
|
|
|
|
BrowsingContext::GetOriginAttributes(OriginAttributes& aAttrs) {
|
|
|
|
aAttrs = mOriginAttributes;
|
|
|
|
AssertOriginAttributesMatchPrivateBrowsing();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult BrowsingContext::SetOriginAttributes(const OriginAttributes& aAttrs) {
|
|
|
|
if (!CanSetOriginAttributes()) {
|
|
|
|
NS_WARNING("Attempt to set OriginAttributes when !CanSetOriginAttributes");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
AssertOriginAttributesMatchPrivateBrowsing();
|
|
|
|
mOriginAttributes = aAttrs;
|
|
|
|
|
|
|
|
bool isPrivate = mOriginAttributes.mPrivateBrowsingId !=
|
|
|
|
nsIScriptSecurityManager::DEFAULT_PRIVATE_BROWSING_ID;
|
|
|
|
// Chrome Browsing Context can not contain OriginAttributes.mPrivateBrowsingId
|
|
|
|
if (IsChrome() && isPrivate) {
|
|
|
|
mOriginAttributes.mPrivateBrowsingId =
|
|
|
|
nsIScriptSecurityManager::DEFAULT_PRIVATE_BROWSING_ID;
|
|
|
|
}
|
|
|
|
SetPrivateBrowsing(isPrivate);
|
|
|
|
AssertOriginAttributesMatchPrivateBrowsing();
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2020-05-08 01:18:46 +03:00
|
|
|
void BrowsingContext::AssertCoherentLoadContext() {
|
|
|
|
#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
|
|
|
|
// LoadContext should generally match our opener or parent.
|
2020-05-18 21:23:35 +03:00
|
|
|
if (IsContent()) {
|
|
|
|
if (RefPtr<BrowsingContext> opener = GetOpener()) {
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(opener->mType == mType);
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(opener->mGroup == mGroup);
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(opener->mUseRemoteTabs == mUseRemoteTabs);
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(opener->mUseRemoteSubframes == mUseRemoteSubframes);
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(opener->mPrivateBrowsingId == mPrivateBrowsingId);
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(
|
|
|
|
opener->mOriginAttributes.EqualsIgnoringFPD(mOriginAttributes));
|
|
|
|
}
|
2020-05-08 01:18:46 +03:00
|
|
|
}
|
|
|
|
if (RefPtr<BrowsingContext> parent = GetParent()) {
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(parent->mType == mType);
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(parent->mGroup == mGroup);
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(parent->mUseRemoteTabs == mUseRemoteTabs);
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(parent->mUseRemoteSubframes == mUseRemoteSubframes);
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(parent->mPrivateBrowsingId == mPrivateBrowsingId);
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(
|
|
|
|
parent->mOriginAttributes.EqualsIgnoringFPD(mOriginAttributes));
|
|
|
|
}
|
|
|
|
|
|
|
|
// UseRemoteSubframes and UseRemoteTabs must match.
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(
|
|
|
|
!mUseRemoteSubframes || mUseRemoteTabs,
|
|
|
|
"Cannot set useRemoteSubframes without also setting useRemoteTabs");
|
|
|
|
|
|
|
|
// Double-check OriginAttributes/Private Browsing
|
|
|
|
AssertOriginAttributesMatchPrivateBrowsing();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2020-04-08 00:39:12 +03:00
|
|
|
void BrowsingContext::AssertOriginAttributesMatchPrivateBrowsing() {
|
|
|
|
// Chrome browsing contexts must not have a private browsing OriginAttribute
|
|
|
|
// Content browsing contexts must maintain the equality:
|
|
|
|
// mOriginAttributes.mPrivateBrowsingId == mPrivateBrowsingId
|
|
|
|
if (IsChrome()) {
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mOriginAttributes.mPrivateBrowsingId == 0);
|
|
|
|
} else {
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mOriginAttributes.mPrivateBrowsingId ==
|
|
|
|
mPrivateBrowsingId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-18 21:58:30 +03:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(BrowsingContext)
|
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
2020-04-26 03:50:52 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsILoadContext)
|
2019-10-18 21:58:30 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2018-09-14 17:57:18 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(BrowsingContext)
|
|
|
|
|
2019-10-18 21:58:30 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(BrowsingContext)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(BrowsingContext)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(BrowsingContext)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
|
|
|
|
2018-09-14 17:57:18 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(BrowsingContext)
|
2019-05-24 23:15:53 +03:00
|
|
|
if (sBrowsingContexts) {
|
|
|
|
sBrowsingContexts->Remove(tmp->Id());
|
|
|
|
}
|
2020-07-09 23:34:06 +03:00
|
|
|
UnregisterBrowserId(tmp);
|
2019-05-24 23:15:53 +03:00
|
|
|
|
2020-01-20 17:57:47 +03:00
|
|
|
if (tmp->GetIsPopupSpam()) {
|
2019-10-18 06:04:55 +03:00
|
|
|
PopupBlocker::UnregisterOpenPopupSpam();
|
|
|
|
// NOTE: Doesn't use SetIsPopupSpam, as it will be set all processes
|
|
|
|
// automatically.
|
2020-01-20 17:57:47 +03:00
|
|
|
tmp->mFields.SetWithoutSyncing<IDX_IsPopupSpam>(false);
|
2019-10-18 06:04:55 +03:00
|
|
|
}
|
|
|
|
|
2020-05-19 11:57:44 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(
|
|
|
|
mDocShell, mParentWindow, mGroup, mEmbedderElement, mWindowContexts,
|
|
|
|
mCurrentWindowContext, mSessionStorageManager, mChildSessionHistory)
|
2018-09-14 17:57:18 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(BrowsingContext)
|
2020-01-20 17:58:52 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(
|
2020-04-24 21:33:06 +03:00
|
|
|
mDocShell, mParentWindow, mGroup, mEmbedderElement, mWindowContexts,
|
2020-05-19 11:57:44 +03:00
|
|
|
mCurrentWindowContext, mSessionStorageManager, mChildSessionHistory)
|
2018-09-14 17:57:18 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
2019-02-28 21:23:15 +03:00
|
|
|
class RemoteLocationProxy
|
|
|
|
: public RemoteObjectProxy<BrowsingContext::LocationProxy,
|
2020-06-05 15:45:40 +03:00
|
|
|
Location_Binding::sCrossOriginProperties> {
|
2019-02-28 21:23:15 +03:00
|
|
|
public:
|
|
|
|
typedef RemoteObjectProxy Base;
|
|
|
|
|
|
|
|
constexpr RemoteLocationProxy()
|
|
|
|
: RemoteObjectProxy(prototypes::id::Location) {}
|
2019-02-28 22:34:02 +03:00
|
|
|
|
|
|
|
void NoteChildren(JSObject* aProxy,
|
|
|
|
nsCycleCollectionTraversalCallback& aCb) const override {
|
|
|
|
auto location =
|
|
|
|
static_cast<BrowsingContext::LocationProxy*>(GetNative(aProxy));
|
|
|
|
CycleCollectionNoteChild(aCb, location->GetBrowsingContext(),
|
2020-09-09 01:55:38 +03:00
|
|
|
"JS::GetPrivate(obj)->GetBrowsingContext()");
|
2019-02-28 22:34:02 +03:00
|
|
|
}
|
2019-02-28 21:23:15 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
static const RemoteLocationProxy sSingleton;
|
|
|
|
|
|
|
|
// Give RemoteLocationProxy 2 reserved slots, like the other wrappers,
|
|
|
|
// so JSObject::swap can swap it with CrossCompartmentWrappers without requiring
|
|
|
|
// malloc.
|
|
|
|
template <>
|
2019-08-14 20:15:15 +03:00
|
|
|
const JSClass RemoteLocationProxy::Base::sClass =
|
2019-02-28 21:23:15 +03:00
|
|
|
PROXY_CLASS_DEF("Proxy", JSCLASS_HAS_RESERVED_SLOTS(2));
|
|
|
|
|
2019-01-02 16:29:18 +03:00
|
|
|
void BrowsingContext::Location(JSContext* aCx,
|
|
|
|
JS::MutableHandle<JSObject*> aLocation,
|
2019-02-28 21:23:15 +03:00
|
|
|
ErrorResult& aError) {
|
|
|
|
aError.MightThrowJSException();
|
2019-07-18 22:36:17 +03:00
|
|
|
sSingleton.GetProxyObject(aCx, &mLocation, /* aTransplantTo = */ nullptr,
|
|
|
|
aLocation);
|
2019-02-28 21:23:15 +03:00
|
|
|
if (!aLocation) {
|
|
|
|
aError.StealExceptionFromJSContext(aCx);
|
|
|
|
}
|
|
|
|
}
|
2019-01-02 16:29:18 +03:00
|
|
|
|
2020-08-31 21:51:56 +03:00
|
|
|
bool BrowsingContext::RemoveRootFromBFCacheSync() {
|
|
|
|
if (WindowContext* wc = GetParentWindowContext()) {
|
|
|
|
if (RefPtr<Document> doc = wc->TopWindowContext()->GetDocument()) {
|
|
|
|
return doc->RemoveFromBFCacheSync();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-04-04 05:42:39 +03:00
|
|
|
nsresult BrowsingContext::CheckSandboxFlags(nsDocShellLoadState* aLoadState) {
|
|
|
|
const auto& sourceBC = aLoadState->SourceBrowsingContext();
|
2021-01-14 22:42:07 +03:00
|
|
|
if (sourceBC.IsNull()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We might be called after the source BC has been discarded, but before we've
|
|
|
|
// destroyed our in-process instance of the BrowsingContext object in some
|
|
|
|
// situations (e.g. after creating a new pop-up with window.open while the
|
|
|
|
// window is being closed). In these situations we want to still perform the
|
|
|
|
// sandboxing check against our in-process copy. If we've forgotten about the
|
|
|
|
// context already, assume it is sanboxed. (bug 1643450)
|
|
|
|
BrowsingContext* bc = sourceBC.GetMaybeDiscarded();
|
|
|
|
if (!bc || bc->IsSandboxedFrom(this)) {
|
|
|
|
return NS_ERROR_DOM_SECURITY_ERR;
|
2020-04-04 05:42:39 +03:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2020-04-08 22:04:47 +03:00
|
|
|
nsresult BrowsingContext::LoadURI(nsDocShellLoadState* aLoadState,
|
2019-10-11 05:27:05 +03:00
|
|
|
bool aSetNavigating) {
|
2019-09-12 14:37:01 +03:00
|
|
|
// Per spec, most load attempts are silently ignored when a BrowsingContext is
|
|
|
|
// null (which in our code corresponds to discarded), so we simply fail
|
|
|
|
// silently in those cases. Regardless, we cannot trigger loads in/from
|
|
|
|
// discarded BrowsingContexts via IPC, so we need to abort in any case.
|
2020-04-08 22:04:47 +03:00
|
|
|
if (IsDiscarded()) {
|
2019-09-12 14:37:01 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2019-08-02 04:00:32 +03:00
|
|
|
|
2020-08-26 22:20:06 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(aLoadState->TargetBrowsingContext().IsNull(),
|
|
|
|
"Targeting occurs in InternalLoad");
|
|
|
|
|
2019-08-02 04:00:32 +03:00
|
|
|
if (mDocShell) {
|
2019-10-11 05:27:05 +03:00
|
|
|
return mDocShell->LoadURI(aLoadState, aSetNavigating);
|
2019-08-24 01:26:51 +03:00
|
|
|
}
|
|
|
|
|
2020-04-04 05:42:39 +03:00
|
|
|
// Note: We do this check both here and in `nsDocShell::InternalLoad`, since
|
|
|
|
// document-specific sandbox flags are only available in the process
|
|
|
|
// triggering the load, and we don't want the target process to have to trust
|
|
|
|
// the triggering process to do the appropriate checks for the
|
|
|
|
// BrowsingContext's sandbox flags.
|
|
|
|
MOZ_TRY(CheckSandboxFlags(aLoadState));
|
2020-08-28 20:20:30 +03:00
|
|
|
SetTriggeringAndInheritPrincipals(aLoadState->TriggeringPrincipal(),
|
|
|
|
aLoadState->PrincipalToInherit(),
|
|
|
|
aLoadState->GetLoadIdentifier());
|
2020-04-04 05:42:39 +03:00
|
|
|
|
2020-04-08 22:04:47 +03:00
|
|
|
const auto& sourceBC = aLoadState->SourceBrowsingContext();
|
2021-02-03 01:24:47 +03:00
|
|
|
|
|
|
|
if (net::SchemeIsJavascript(aLoadState->URI())) {
|
|
|
|
if (!XRE_IsParentProcess()) {
|
|
|
|
// Web content should only be able to load javascript: URIs into documents
|
|
|
|
// whose principals the caller principal subsumes, which by definition
|
|
|
|
// excludes any document in a cross-process BrowsingContext.
|
|
|
|
return NS_ERROR_DOM_BAD_CROSS_ORIGIN_URI;
|
|
|
|
}
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(!sourceBC,
|
|
|
|
"Should never see a cross-process javascript: load "
|
|
|
|
"triggered from content");
|
|
|
|
}
|
|
|
|
|
2020-04-08 22:04:47 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(!sourceBC || sourceBC->Group() == Group());
|
|
|
|
if (sourceBC && sourceBC->IsInProcess()) {
|
|
|
|
if (!sourceBC->CanAccess(this)) {
|
Bug 1586926 - Add necessary caller access checks for cross-process Location navigations. r=nika
We attempt to enforce the same (approximate) access checks to Location-based
navigation that we use for loads that use named targeting (e.g., via
window.open), so that a frame that can't be navigated via, e.g., window.open,
also can't be navigated via, e.g., window.parent[1].location = url. For the
in-process case, this is handled by a somewhat hidden call to
CheckLoadingPermissions() in nsDocShell::InternalLoad, where the former checks
whether the principal of whatever JS context happens to be on the stack
subsumes the principal of the target DocShell or any of its ancestors, and
blocks the load if it doesn't.
Since there is no JS context on the stack when we call into the DocShell
loading code in the cross-process case, the check is simply ignored.
So we need to instead do the check in BrowsingContext::LoadURI, where we
already have an explicit accessor, and can simply use the standard access
checks that we use elsewhere.
Differential Revision: https://phabricator.services.mozilla.com/D48443
--HG--
extra : moz-landing-system : lando
2019-10-10 22:36:23 +03:00
|
|
|
return NS_ERROR_DOM_PROP_ACCESS_DENIED;
|
|
|
|
}
|
|
|
|
|
2020-04-08 22:04:47 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> win(sourceBC->GetDOMWindow());
|
2019-08-02 04:00:32 +03:00
|
|
|
if (WindowGlobalChild* wgc =
|
|
|
|
win->GetCurrentInnerWindow()->GetWindowGlobalChild()) {
|
2019-10-11 05:27:05 +03:00
|
|
|
wgc->SendLoadURI(this, aLoadState, aSetNavigating);
|
2019-08-02 04:00:32 +03:00
|
|
|
}
|
2020-07-06 22:56:32 +03:00
|
|
|
} else if (XRE_IsParentProcess()) {
|
2020-06-30 04:19:15 +03:00
|
|
|
if (Canonical()->LoadInParent(aLoadState, aSetNavigating)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2020-04-08 22:04:47 +03:00
|
|
|
if (ContentParent* cp = Canonical()->GetContentParent()) {
|
2020-04-26 03:54:15 +03:00
|
|
|
// Attempt to initiate this load immediately in the parent, if it succeeds
|
|
|
|
// it'll return a unique identifier so that we can find it later.
|
2020-06-23 16:18:56 +03:00
|
|
|
uint64_t loadIdentifier = 0;
|
2020-06-30 04:19:15 +03:00
|
|
|
if (Canonical()->AttemptSpeculativeLoadInParent(aLoadState)) {
|
2020-06-23 16:01:37 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(GetCurrentLoadIdentifier().isSome());
|
|
|
|
loadIdentifier = GetCurrentLoadIdentifier().value();
|
|
|
|
aLoadState->SetChannelInitialized(true);
|
2020-04-26 03:54:15 +03:00
|
|
|
}
|
|
|
|
|
2020-04-21 15:37:02 +03:00
|
|
|
cp->TransmitBlobDataIfBlobURL(aLoadState->URI(),
|
|
|
|
aLoadState->TriggeringPrincipal());
|
2020-04-26 03:54:15 +03:00
|
|
|
|
|
|
|
// Setup a confirmation callback once the content process receives this
|
|
|
|
// load. Normally we'd expect a PDocumentChannel actor to have been
|
|
|
|
// created to claim the load identifier by that time. If not, then it
|
|
|
|
// won't be coming, so make sure we clean up and deregister.
|
|
|
|
cp->SendLoadURI(this, aLoadState, aSetNavigating)
|
|
|
|
->Then(GetMainThreadSerialEventTarget(), __func__,
|
|
|
|
[loadIdentifier](
|
|
|
|
const PContentParent::LoadURIPromise::ResolveOrRejectValue&
|
|
|
|
aValue) {
|
|
|
|
if (loadIdentifier) {
|
|
|
|
net::DocumentLoadListener::CleanupParentLoadAttempt(
|
|
|
|
loadIdentifier);
|
|
|
|
}
|
|
|
|
});
|
2020-04-08 22:04:47 +03:00
|
|
|
}
|
2020-07-06 22:56:32 +03:00
|
|
|
} else {
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(sourceBC);
|
|
|
|
if (!sourceBC) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
// If we're in a content process and the source BC is no longer in-process,
|
|
|
|
// just fail silently.
|
2019-08-02 04:00:32 +03:00
|
|
|
}
|
2019-08-24 01:26:51 +03:00
|
|
|
return NS_OK;
|
2019-08-02 04:00:32 +03:00
|
|
|
}
|
|
|
|
|
2020-06-23 16:01:37 +03:00
|
|
|
nsresult BrowsingContext::InternalLoad(nsDocShellLoadState* aLoadState) {
|
2020-04-08 22:04:47 +03:00
|
|
|
if (IsDiscarded()) {
|
2019-11-13 00:52:18 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2020-08-28 20:20:30 +03:00
|
|
|
SetTriggeringAndInheritPrincipals(aLoadState->TriggeringPrincipal(),
|
|
|
|
aLoadState->PrincipalToInherit(),
|
|
|
|
aLoadState->GetLoadIdentifier());
|
2019-11-13 00:52:18 +03:00
|
|
|
|
2020-08-26 22:20:06 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(aLoadState->Target().IsEmpty(),
|
|
|
|
"should already have retargeted");
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(!aLoadState->TargetBrowsingContext().IsNull(),
|
|
|
|
"should have target bc set");
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(aLoadState->TargetBrowsingContext() == this,
|
|
|
|
"must be targeting this BrowsingContext");
|
|
|
|
|
2019-11-13 00:52:18 +03:00
|
|
|
if (mDocShell) {
|
2021-02-02 17:33:48 +03:00
|
|
|
return nsDocShell::Cast(mDocShell)->InternalLoad(aLoadState);
|
2019-11-13 00:52:18 +03:00
|
|
|
}
|
|
|
|
|
2020-04-04 05:42:39 +03:00
|
|
|
// Note: We do this check both here and in `nsDocShell::InternalLoad`, since
|
|
|
|
// document-specific sandbox flags are only available in the process
|
|
|
|
// triggering the load, and we don't want the target process to have to trust
|
|
|
|
// the triggering process to do the appropriate checks for the
|
|
|
|
// BrowsingContext's sandbox flags.
|
|
|
|
MOZ_TRY(CheckSandboxFlags(aLoadState));
|
|
|
|
|
2021-02-02 17:33:48 +03:00
|
|
|
const auto& sourceBC = aLoadState->SourceBrowsingContext();
|
2021-02-03 01:24:47 +03:00
|
|
|
|
|
|
|
if (net::SchemeIsJavascript(aLoadState->URI())) {
|
|
|
|
if (!XRE_IsParentProcess()) {
|
|
|
|
// Web content should only be able to load javascript: URIs into documents
|
|
|
|
// whose principals the caller principal subsumes, which by definition
|
|
|
|
// excludes any document in a cross-process BrowsingContext.
|
|
|
|
return NS_ERROR_DOM_BAD_CROSS_ORIGIN_URI;
|
|
|
|
}
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(!sourceBC,
|
|
|
|
"Should never see a cross-process javascript: load "
|
|
|
|
"triggered from content");
|
|
|
|
}
|
|
|
|
|
2019-12-12 05:32:00 +03:00
|
|
|
if (XRE_IsParentProcess()) {
|
2020-08-26 22:20:06 +03:00
|
|
|
ContentParent* cp = Canonical()->GetContentParent();
|
|
|
|
if (!cp || !cp->CanSend()) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2020-07-31 16:37:13 +03:00
|
|
|
MOZ_ALWAYS_SUCCEEDS(
|
|
|
|
SetCurrentLoadIdentifier(Some(aLoadState->GetLoadIdentifier())));
|
2021-02-02 17:33:48 +03:00
|
|
|
Unused << cp->SendInternalLoad(aLoadState);
|
2019-11-13 00:52:18 +03:00
|
|
|
} else {
|
2020-04-08 22:04:47 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(sourceBC);
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(sourceBC->Group() == Group());
|
2019-11-13 00:52:18 +03:00
|
|
|
|
2020-04-08 22:04:47 +03:00
|
|
|
if (!sourceBC->CanAccess(this)) {
|
2019-11-13 00:52:18 +03:00
|
|
|
return NS_ERROR_DOM_PROP_ACCESS_DENIED;
|
|
|
|
}
|
|
|
|
|
2020-04-08 22:04:47 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> win(sourceBC->GetDOMWindow());
|
2020-08-26 22:20:06 +03:00
|
|
|
WindowGlobalChild* wgc =
|
|
|
|
win->GetCurrentInnerWindow()->GetWindowGlobalChild();
|
|
|
|
if (!wgc || !wgc->CanSend()) {
|
|
|
|
return NS_ERROR_FAILURE;
|
2019-11-13 00:52:18 +03:00
|
|
|
}
|
2020-08-26 22:20:06 +03:00
|
|
|
|
|
|
|
MOZ_ALWAYS_SUCCEEDS(
|
|
|
|
SetCurrentLoadIdentifier(Some(aLoadState->GetLoadIdentifier())));
|
|
|
|
wgc->SendInternalLoad(aLoadState);
|
2019-11-13 00:52:18 +03:00
|
|
|
}
|
2020-06-23 16:01:37 +03:00
|
|
|
|
2019-11-13 00:52:18 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-10-11 05:27:07 +03:00
|
|
|
void BrowsingContext::DisplayLoadError(const nsAString& aURI) {
|
|
|
|
MOZ_LOG(GetLog(), LogLevel::Debug, ("DisplayLoadError"));
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(!IsDiscarded());
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mDocShell || XRE_IsParentProcess());
|
|
|
|
|
|
|
|
if (mDocShell) {
|
|
|
|
bool didDisplayLoadError = false;
|
|
|
|
mDocShell->DisplayLoadError(NS_ERROR_MALFORMED_URI, nullptr,
|
|
|
|
PromiseFlatString(aURI).get(), nullptr,
|
|
|
|
&didDisplayLoadError);
|
|
|
|
} else {
|
2019-12-12 05:32:00 +03:00
|
|
|
if (ContentParent* cp = Canonical()->GetContentParent()) {
|
|
|
|
Unused << cp->SendDisplayLoadError(this, PromiseFlatString(aURI));
|
|
|
|
}
|
2019-10-11 05:27:07 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-11 22:32:09 +03:00
|
|
|
WindowProxyHolder BrowsingContext::Window() {
|
|
|
|
return WindowProxyHolder(Self());
|
|
|
|
}
|
|
|
|
|
|
|
|
WindowProxyHolder BrowsingContext::GetFrames(ErrorResult& aError) {
|
|
|
|
return Window();
|
|
|
|
}
|
|
|
|
|
2019-01-02 16:29:18 +03:00
|
|
|
void BrowsingContext::Close(CallerType aCallerType, ErrorResult& aError) {
|
2019-12-12 05:31:55 +03:00
|
|
|
if (mIsDiscarded) {
|
|
|
|
return;
|
|
|
|
}
|
2020-06-01 20:13:47 +03:00
|
|
|
|
2020-09-02 12:27:36 +03:00
|
|
|
if (IsFrame()) {
|
|
|
|
// .close() on frames is a no-op.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-11-08 07:35:05 +03:00
|
|
|
if (GetDOMWindow()) {
|
|
|
|
nsGlobalWindowOuter::Cast(GetDOMWindow())
|
|
|
|
->CloseOuter(aCallerType == CallerType::System);
|
2020-06-01 20:13:47 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is a bit of a hack for webcompat. Content needs to see an updated
|
|
|
|
// |window.closed| value as early as possible, so we set this before we
|
|
|
|
// actually send the DOMWindowClose event, which happens in the process where
|
|
|
|
// the document for this browsing context is loaded.
|
2020-07-31 16:37:13 +03:00
|
|
|
MOZ_ALWAYS_SUCCEEDS(SetClosed(true));
|
2020-06-01 20:13:47 +03:00
|
|
|
|
|
|
|
if (ContentChild* cc = ContentChild::GetSingleton()) {
|
2019-03-14 21:50:52 +03:00
|
|
|
cc->SendWindowClose(this, aCallerType == CallerType::System);
|
|
|
|
} else if (ContentParent* cp = Canonical()->GetContentParent()) {
|
|
|
|
Unused << cp->SendWindowClose(this, aCallerType == CallerType::System);
|
|
|
|
}
|
2019-01-02 16:29:18 +03:00
|
|
|
}
|
|
|
|
|
2021-01-18 15:48:42 +03:00
|
|
|
/*
|
|
|
|
* Examine the current document state to see if we're in a way that is
|
|
|
|
* typically abused by web designers. The window.open code uses this
|
|
|
|
* routine to determine whether to allow the new window.
|
|
|
|
* Returns a value from the PopupControlState enum.
|
|
|
|
*/
|
|
|
|
PopupBlocker::PopupControlState BrowsingContext::RevisePopupAbuseLevel(
|
|
|
|
PopupBlocker::PopupControlState aControl) {
|
|
|
|
if (!IsContent()) {
|
|
|
|
return PopupBlocker::openAllowed;
|
|
|
|
}
|
|
|
|
|
|
|
|
PopupBlocker::PopupControlState abuse = aControl;
|
|
|
|
switch (abuse) {
|
|
|
|
case PopupBlocker::openControlled:
|
|
|
|
case PopupBlocker::openBlocked:
|
|
|
|
case PopupBlocker::openOverridden:
|
|
|
|
if (IsPopupAllowed()) {
|
|
|
|
abuse = PopupBlocker::PopupControlState(abuse - 1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PopupBlocker::openAbused:
|
|
|
|
if (IsPopupAllowed()) {
|
|
|
|
// Skip PopupBlocker::openBlocked
|
|
|
|
abuse = PopupBlocker::openControlled;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PopupBlocker::openAllowed:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_WARNING("Strange PopupControlState!");
|
|
|
|
}
|
|
|
|
|
|
|
|
// limit the number of simultaneously open popups
|
|
|
|
if (abuse == PopupBlocker::openAbused || abuse == PopupBlocker::openBlocked ||
|
|
|
|
abuse == PopupBlocker::openControlled) {
|
|
|
|
int32_t popupMax = StaticPrefs::dom_popup_maximum();
|
|
|
|
if (popupMax >= 0 &&
|
|
|
|
PopupBlocker::GetOpenPopupSpamCount() >= (uint32_t)popupMax) {
|
|
|
|
abuse = PopupBlocker::openOverridden;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we're currently in-process, attempt to consume transient user gesture
|
|
|
|
// activations.
|
|
|
|
if (RefPtr<Document> doc = GetExtantDocument()) {
|
|
|
|
// HACK: Some pages using bogus library + UA sniffing call window.open()
|
|
|
|
// from a blank iframe, only on Firefox, see bug 1685056.
|
|
|
|
//
|
|
|
|
// This is a hack-around to preserve behavior in that particular and
|
|
|
|
// specific case, by consuming activation on the parent document, so we
|
|
|
|
// don't care about the InProcessParent bits not being fission-safe or what
|
|
|
|
// not.
|
|
|
|
auto ConsumeTransientUserActivationForMultiplePopupBlocking =
|
|
|
|
[&]() -> bool {
|
|
|
|
if (doc->ConsumeTransientUserGestureActivation()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (!doc->IsInitialDocument()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Document* parentDoc = doc->GetInProcessParentDocument();
|
|
|
|
if (!parentDoc ||
|
|
|
|
!parentDoc->NodePrincipal()->Equals(doc->NodePrincipal())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return parentDoc->ConsumeTransientUserGestureActivation();
|
|
|
|
};
|
|
|
|
|
|
|
|
// If this popup is allowed, let's block any other for this event, forcing
|
|
|
|
// PopupBlocker::openBlocked state.
|
|
|
|
if ((abuse == PopupBlocker::openAllowed ||
|
|
|
|
abuse == PopupBlocker::openControlled) &&
|
|
|
|
StaticPrefs::dom_block_multiple_popups() && !IsPopupAllowed() &&
|
|
|
|
!ConsumeTransientUserActivationForMultiplePopupBlocking()) {
|
|
|
|
nsContentUtils::ReportToConsole(nsIScriptError::warningFlag, "DOM"_ns,
|
|
|
|
doc, nsContentUtils::eDOM_PROPERTIES,
|
|
|
|
"MultiplePopupsBlockedNoUserActivation");
|
|
|
|
abuse = PopupBlocker::openBlocked;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return abuse;
|
|
|
|
}
|
|
|
|
|
2021-02-03 03:02:29 +03:00
|
|
|
void BrowsingContext::IncrementHistoryEntryCountForBrowsingContext() {
|
|
|
|
Unused << SetHistoryEntryCount(GetHistoryEntryCount() + 1);
|
|
|
|
}
|
|
|
|
|
2021-01-18 15:48:42 +03:00
|
|
|
std::tuple<bool, bool> BrowsingContext::CanFocusCheck(CallerType aCallerType) {
|
|
|
|
nsFocusManager* fm = nsFocusManager::GetFocusManager();
|
|
|
|
if (!fm) {
|
|
|
|
return {false, false};
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsPIDOMWindowInner> caller = do_QueryInterface(GetEntryGlobal());
|
|
|
|
BrowsingContext* callerBC = caller ? caller->GetBrowsingContext() : nullptr;
|
|
|
|
RefPtr<BrowsingContext> openerBC = GetOpener();
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(!openerBC || openerBC->Group() == Group());
|
|
|
|
|
|
|
|
// Enforce dom.disable_window_flip (for non-chrome), but still allow the
|
|
|
|
// window which opened us to raise us at times when popups are allowed
|
|
|
|
// (bugs 355482 and 369306).
|
|
|
|
bool canFocus = aCallerType == CallerType::System ||
|
|
|
|
!Preferences::GetBool("dom.disable_window_flip", true);
|
|
|
|
if (!canFocus && openerBC == callerBC) {
|
|
|
|
canFocus = (RevisePopupAbuseLevel(PopupBlocker::GetPopupControlState()) <
|
|
|
|
PopupBlocker::openBlocked);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isActive = false;
|
|
|
|
if (XRE_IsParentProcess()) {
|
|
|
|
RefPtr<CanonicalBrowsingContext> chromeTop =
|
|
|
|
Canonical()->TopCrossChromeBoundary();
|
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> activeWindow = fm->GetActiveWindow();
|
|
|
|
isActive = (activeWindow == chromeTop->GetDOMWindow());
|
|
|
|
} else {
|
|
|
|
isActive = (fm->GetActiveBrowsingContext() == Top());
|
|
|
|
}
|
|
|
|
|
|
|
|
return {canFocus, isActive};
|
|
|
|
}
|
|
|
|
|
2020-01-16 17:38:40 +03:00
|
|
|
void BrowsingContext::Focus(CallerType aCallerType, ErrorResult& aError) {
|
2021-01-18 15:48:42 +03:00
|
|
|
// These checks need to happen before the RequestFrameFocus call, which
|
|
|
|
// is why they are done in an untrusted process. If we wanted to enforce
|
|
|
|
// these in the parent, we'd need to do the checks there _also_.
|
|
|
|
// These should be kept in sync with nsGlobalWindowOuter::FocusOuter.
|
|
|
|
|
|
|
|
auto [canFocus, isActive] = CanFocusCheck(aCallerType);
|
|
|
|
|
|
|
|
if (!(canFocus || isActive)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Permission check passed
|
|
|
|
|
2020-09-02 18:05:53 +03:00
|
|
|
if (mEmbedderElement) {
|
|
|
|
// Make the activeElement in this process update synchronously.
|
|
|
|
nsContentUtils::RequestFrameFocus(*mEmbedderElement, true, aCallerType);
|
|
|
|
}
|
2021-01-18 15:48:42 +03:00
|
|
|
uint64_t actionId = nsFocusManager::GenerateFocusActionId();
|
2019-03-14 21:50:52 +03:00
|
|
|
if (ContentChild* cc = ContentChild::GetSingleton()) {
|
2021-01-18 15:48:42 +03:00
|
|
|
cc->SendWindowFocus(this, aCallerType, actionId);
|
2019-03-14 21:50:52 +03:00
|
|
|
} else if (ContentParent* cp = Canonical()->GetContentParent()) {
|
2021-01-18 15:48:42 +03:00
|
|
|
Unused << cp->SendWindowFocus(this, aCallerType, actionId);
|
2019-03-14 21:50:52 +03:00
|
|
|
}
|
2019-01-02 16:29:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void BrowsingContext::Blur(ErrorResult& aError) {
|
2019-03-14 21:50:52 +03:00
|
|
|
if (ContentChild* cc = ContentChild::GetSingleton()) {
|
|
|
|
cc->SendWindowBlur(this);
|
|
|
|
} else if (ContentParent* cp = Canonical()->GetContentParent()) {
|
|
|
|
Unused << cp->SendWindowBlur(this);
|
|
|
|
}
|
2019-01-02 16:29:18 +03:00
|
|
|
}
|
|
|
|
|
2019-10-05 00:50:34 +03:00
|
|
|
Nullable<WindowProxyHolder> BrowsingContext::GetWindow() {
|
|
|
|
if (XRE_IsParentProcess() && !IsInProcess()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return WindowProxyHolder(this);
|
|
|
|
}
|
|
|
|
|
2019-01-02 16:29:18 +03:00
|
|
|
Nullable<WindowProxyHolder> BrowsingContext::GetTop(ErrorResult& aError) {
|
2019-07-02 23:48:13 +03:00
|
|
|
if (mIsDiscarded) {
|
2019-04-17 03:53:09 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-01-02 16:29:18 +03:00
|
|
|
// We never return null or throw an error, but the implementation in
|
|
|
|
// nsGlobalWindow does and we need to use the same signature.
|
2019-04-09 09:19:24 +03:00
|
|
|
return WindowProxyHolder(Top());
|
2019-01-02 16:29:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void BrowsingContext::GetOpener(JSContext* aCx,
|
|
|
|
JS::MutableHandle<JS::Value> aOpener,
|
|
|
|
ErrorResult& aError) const {
|
2019-03-14 21:51:11 +03:00
|
|
|
RefPtr<BrowsingContext> opener = GetOpener();
|
2019-01-02 16:29:18 +03:00
|
|
|
if (!opener) {
|
|
|
|
aOpener.setNull();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ToJSValue(aCx, WindowProxyHolder(opener), aOpener)) {
|
|
|
|
aError.NoteJSContextException(aCx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-24 21:33:06 +03:00
|
|
|
// We never throw an error, but the implementation in nsGlobalWindow does and
|
|
|
|
// we need to use the same signature.
|
2019-04-17 03:53:05 +03:00
|
|
|
Nullable<WindowProxyHolder> BrowsingContext::GetParent(ErrorResult& aError) {
|
2019-07-02 23:48:13 +03:00
|
|
|
if (mIsDiscarded) {
|
2019-04-17 03:53:05 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2020-04-24 21:33:06 +03:00
|
|
|
if (GetParent()) {
|
|
|
|
return WindowProxyHolder(GetParent());
|
2019-01-02 16:29:18 +03:00
|
|
|
}
|
2020-04-24 21:33:06 +03:00
|
|
|
return WindowProxyHolder(this);
|
2019-01-02 16:29:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void BrowsingContext::PostMessageMoz(JSContext* aCx,
|
|
|
|
JS::Handle<JS::Value> aMessage,
|
|
|
|
const nsAString& aTargetOrigin,
|
|
|
|
const Sequence<JSObject*>& aTransfer,
|
|
|
|
nsIPrincipal& aSubjectPrincipal,
|
|
|
|
ErrorResult& aError) {
|
2019-10-09 17:20:23 +03:00
|
|
|
if (mIsDiscarded) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-01-02 16:29:18 +03:00
|
|
|
RefPtr<BrowsingContext> sourceBc;
|
|
|
|
PostMessageData data;
|
|
|
|
data.targetOrigin() = aTargetOrigin;
|
|
|
|
data.subjectPrincipal() = &aSubjectPrincipal;
|
|
|
|
RefPtr<nsGlobalWindowInner> callerInnerWindow;
|
2020-01-15 23:20:31 +03:00
|
|
|
nsAutoCString scriptLocation;
|
2019-10-23 10:19:48 +03:00
|
|
|
// We don't need to get the caller's agentClusterId since that is used for
|
2019-12-12 16:42:47 +03:00
|
|
|
// checking whether it's okay to sharing memory (and it's not allowed to share
|
2019-10-23 10:19:48 +03:00
|
|
|
// memory cross processes)
|
2019-01-02 16:29:18 +03:00
|
|
|
if (!nsGlobalWindowOuter::GatherPostMessageData(
|
|
|
|
aCx, aTargetOrigin, getter_AddRefs(sourceBc), data.origin(),
|
|
|
|
getter_AddRefs(data.targetOriginURI()),
|
|
|
|
getter_AddRefs(data.callerPrincipal()),
|
2020-01-15 23:20:31 +03:00
|
|
|
getter_AddRefs(callerInnerWindow), getter_AddRefs(data.callerURI()),
|
|
|
|
/* aCallerAgentClusterId */ nullptr, &scriptLocation, aError)) {
|
2019-01-02 16:29:18 +03:00
|
|
|
return;
|
|
|
|
}
|
2019-12-12 16:42:47 +03:00
|
|
|
if (sourceBc && sourceBc->IsDiscarded()) {
|
|
|
|
return;
|
|
|
|
}
|
2019-02-14 00:02:55 +03:00
|
|
|
data.source() = sourceBc;
|
2019-01-02 16:29:18 +03:00
|
|
|
data.isFromPrivateWindow() =
|
|
|
|
callerInnerWindow &&
|
|
|
|
nsScriptErrorBase::ComputeIsFromPrivateWindow(callerInnerWindow);
|
2020-01-15 23:20:31 +03:00
|
|
|
data.innerWindowId() = callerInnerWindow ? callerInnerWindow->WindowID() : 0;
|
|
|
|
data.scriptLocation() = scriptLocation;
|
2019-01-02 16:29:18 +03:00
|
|
|
JS::Rooted<JS::Value> transferArray(aCx);
|
|
|
|
aError = nsContentUtils::CreateJSValueFromSequenceOfObject(aCx, aTransfer,
|
|
|
|
&transferArray);
|
|
|
|
if (NS_WARN_IF(aError.Failed())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-05-20 11:27:16 +03:00
|
|
|
JS::CloneDataPolicy clonePolicy;
|
|
|
|
if (callerInnerWindow && callerInnerWindow->IsSharedMemoryAllowed()) {
|
|
|
|
clonePolicy.allowSharedMemoryObjects();
|
|
|
|
}
|
|
|
|
|
|
|
|
// We will see if the message is required to be in the same process or it can
|
|
|
|
// be in the different process after Write().
|
|
|
|
ipc::StructuredCloneData message = ipc::StructuredCloneData(
|
|
|
|
StructuredCloneHolder::StructuredCloneScope::UnknownDestination,
|
|
|
|
StructuredCloneHolder::TransferringSupported);
|
|
|
|
message.Write(aCx, aMessage, transferArray, clonePolicy, aError);
|
2019-01-02 16:29:18 +03:00
|
|
|
if (NS_WARN_IF(aError.Failed())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-05-20 11:27:16 +03:00
|
|
|
ClonedOrErrorMessageData messageData;
|
2019-03-14 21:50:52 +03:00
|
|
|
if (ContentChild* cc = ContentChild::GetSingleton()) {
|
2020-05-20 11:27:16 +03:00
|
|
|
// The clone scope gets set when we write the message data based on the
|
|
|
|
// requirements of that data that we're writing.
|
|
|
|
// If the message data contins a shared memory object, then CloneScope would
|
|
|
|
// return SameProcess. Otherwise, it returns DifferentProcess.
|
|
|
|
if (message.CloneScope() ==
|
|
|
|
StructuredCloneHolder::StructuredCloneScope::DifferentProcess) {
|
|
|
|
ClonedMessageData clonedMessageData;
|
|
|
|
if (!message.BuildClonedMessageDataForChild(cc, clonedMessageData)) {
|
|
|
|
aError.Throw(NS_ERROR_FAILURE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
messageData = std::move(clonedMessageData);
|
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(message.CloneScope() ==
|
|
|
|
StructuredCloneHolder::StructuredCloneScope::SameProcess);
|
|
|
|
|
|
|
|
messageData = ErrorMessageData();
|
|
|
|
|
|
|
|
nsContentUtils::ReportToConsole(
|
|
|
|
nsIScriptError::warningFlag, "DOM Window"_ns,
|
|
|
|
callerInnerWindow ? callerInnerWindow->GetDocument() : nullptr,
|
|
|
|
nsContentUtils::eDOM_PROPERTIES,
|
|
|
|
"PostMessageSharedMemoryObjectToCrossOriginWarning");
|
2019-03-14 21:50:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
cc->SendWindowPostMessage(this, messageData, data);
|
|
|
|
} else if (ContentParent* cp = Canonical()->GetContentParent()) {
|
2020-05-20 11:27:16 +03:00
|
|
|
if (message.CloneScope() ==
|
|
|
|
StructuredCloneHolder::StructuredCloneScope::DifferentProcess) {
|
|
|
|
ClonedMessageData clonedMessageData;
|
|
|
|
if (!message.BuildClonedMessageDataForParent(cp, clonedMessageData)) {
|
|
|
|
aError.Throw(NS_ERROR_FAILURE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
messageData = std::move(clonedMessageData);
|
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(message.CloneScope() ==
|
|
|
|
StructuredCloneHolder::StructuredCloneScope::SameProcess);
|
|
|
|
|
|
|
|
messageData = ErrorMessageData();
|
|
|
|
|
|
|
|
nsContentUtils::ReportToConsole(
|
|
|
|
nsIScriptError::warningFlag, "DOM Window"_ns,
|
|
|
|
callerInnerWindow ? callerInnerWindow->GetDocument() : nullptr,
|
|
|
|
nsContentUtils::eDOM_PROPERTIES,
|
|
|
|
"PostMessageSharedMemoryObjectToCrossOriginWarning");
|
2019-03-14 21:50:52 +03:00
|
|
|
}
|
2019-01-02 16:29:18 +03:00
|
|
|
|
2019-03-14 21:50:52 +03:00
|
|
|
Unused << cp->SendWindowPostMessage(this, messageData, data);
|
|
|
|
}
|
2019-01-02 16:29:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void BrowsingContext::PostMessageMoz(JSContext* aCx,
|
|
|
|
JS::Handle<JS::Value> aMessage,
|
|
|
|
const WindowPostMessageOptions& aOptions,
|
|
|
|
nsIPrincipal& aSubjectPrincipal,
|
|
|
|
ErrorResult& aError) {
|
|
|
|
PostMessageMoz(aCx, aMessage, aOptions.mTargetOrigin, aOptions.mTransfer,
|
|
|
|
aSubjectPrincipal, aError);
|
|
|
|
}
|
|
|
|
|
2020-01-20 17:57:47 +03:00
|
|
|
void BrowsingContext::SendCommitTransaction(ContentParent* aParent,
|
|
|
|
const BaseTransaction& aTxn,
|
|
|
|
uint64_t aEpoch) {
|
|
|
|
Unused << aParent->SendCommitBrowsingContextTransaction(this, aTxn, aEpoch);
|
2019-08-09 17:51:30 +03:00
|
|
|
}
|
|
|
|
|
2020-01-20 17:57:47 +03:00
|
|
|
void BrowsingContext::SendCommitTransaction(ContentChild* aChild,
|
|
|
|
const BaseTransaction& aTxn,
|
|
|
|
uint64_t aEpoch) {
|
|
|
|
aChild->SendCommitBrowsingContextTransaction(this, aTxn, aEpoch);
|
2019-02-21 23:14:28 +03:00
|
|
|
}
|
|
|
|
|
2019-05-09 22:24:10 +03:00
|
|
|
BrowsingContext::IPCInitializer BrowsingContext::GetIPCInitializer() {
|
2020-02-06 22:08:04 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mEverAttached);
|
2019-09-20 07:43:46 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mType == Type::Content);
|
2019-05-09 22:24:10 +03:00
|
|
|
|
|
|
|
IPCInitializer init;
|
|
|
|
init.mId = Id();
|
2020-04-24 21:33:04 +03:00
|
|
|
init.mParentId = mParentWindow ? mParentWindow->Id() : 0;
|
2020-02-06 22:08:06 +03:00
|
|
|
init.mWindowless = mWindowless;
|
2020-04-08 00:39:12 +03:00
|
|
|
init.mUseRemoteTabs = mUseRemoteTabs;
|
|
|
|
init.mUseRemoteSubframes = mUseRemoteSubframes;
|
2020-09-23 16:43:38 +03:00
|
|
|
init.mCreatedDynamically = mCreatedDynamically;
|
2020-04-08 00:39:12 +03:00
|
|
|
init.mOriginAttributes = mOriginAttributes;
|
2020-09-28 15:01:12 +03:00
|
|
|
if (mChildSessionHistory && mozilla::SessionHistoryInParent()) {
|
2020-09-08 18:24:13 +03:00
|
|
|
init.mSessionHistoryIndex = mChildSessionHistory->Index();
|
|
|
|
init.mSessionHistoryCount = mChildSessionHistory->Count();
|
|
|
|
}
|
2020-05-21 06:38:14 +03:00
|
|
|
init.mRequestContextId = mRequestContextId;
|
2020-07-22 17:07:26 +03:00
|
|
|
init.mFields = mFields.RawValues();
|
2019-05-09 22:24:10 +03:00
|
|
|
return init;
|
|
|
|
}
|
|
|
|
|
2020-04-24 21:33:04 +03:00
|
|
|
already_AddRefed<WindowContext> BrowsingContext::IPCInitializer::GetParent() {
|
|
|
|
RefPtr<WindowContext> parent;
|
2019-03-14 21:51:09 +03:00
|
|
|
if (mParentId != 0) {
|
2020-04-24 21:33:04 +03:00
|
|
|
parent = WindowContext::GetById(mParentId);
|
2019-03-14 21:51:09 +03:00
|
|
|
MOZ_RELEASE_ASSERT(parent);
|
|
|
|
}
|
|
|
|
return parent.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<BrowsingContext> BrowsingContext::IPCInitializer::GetOpener() {
|
|
|
|
RefPtr<BrowsingContext> opener;
|
2020-01-20 17:57:47 +03:00
|
|
|
if (GetOpenerId() != 0) {
|
|
|
|
opener = BrowsingContext::Get(GetOpenerId());
|
2019-03-14 21:51:09 +03:00
|
|
|
MOZ_RELEASE_ASSERT(opener);
|
|
|
|
}
|
|
|
|
return opener.forget();
|
|
|
|
}
|
|
|
|
|
2019-03-20 06:15:36 +03:00
|
|
|
void BrowsingContext::StartDelayedAutoplayMediaComponents() {
|
|
|
|
if (!mDocShell) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
AUTOPLAY_LOG("%s : StartDelayedAutoplayMediaComponents for bc 0x%08" PRIx64,
|
|
|
|
XRE_IsParentProcess() ? "Parent" : "Child", Id());
|
|
|
|
mDocShell->StartDelayedAutoplayMediaComponents();
|
|
|
|
}
|
|
|
|
|
2020-07-31 16:37:13 +03:00
|
|
|
nsresult BrowsingContext::ResetGVAutoplayRequestStatus() {
|
2020-01-06 22:13:38 +03:00
|
|
|
MOZ_ASSERT(IsTop(),
|
2019-11-25 14:00:13 +03:00
|
|
|
"Should only set GVAudibleAutoplayRequestStatus in the top-level "
|
|
|
|
"browsing context");
|
2020-07-31 16:37:13 +03:00
|
|
|
|
|
|
|
Transaction txn;
|
|
|
|
txn.SetGVAudibleAutoplayRequestStatus(GVAutoplayRequestStatus::eUNKNOWN);
|
|
|
|
txn.SetGVInaudibleAutoplayRequestStatus(GVAutoplayRequestStatus::eUNKNOWN);
|
|
|
|
return txn.Commit(this);
|
2019-11-25 14:00:13 +03:00
|
|
|
}
|
|
|
|
|
2020-04-20 23:09:32 +03:00
|
|
|
void BrowsingContext::DidSet(FieldIndex<IDX_GVAudibleAutoplayRequestStatus>) {
|
2020-01-06 22:13:38 +03:00
|
|
|
MOZ_ASSERT(IsTop(),
|
2019-11-25 14:00:13 +03:00
|
|
|
"Should only set GVAudibleAutoplayRequestStatus in the top-level "
|
|
|
|
"browsing context");
|
|
|
|
}
|
|
|
|
|
2020-04-20 23:09:32 +03:00
|
|
|
void BrowsingContext::DidSet(FieldIndex<IDX_GVInaudibleAutoplayRequestStatus>) {
|
2020-01-06 22:13:38 +03:00
|
|
|
MOZ_ASSERT(IsTop(),
|
2019-11-25 14:00:13 +03:00
|
|
|
"Should only set GVAudibleAutoplayRequestStatus in the top-level "
|
|
|
|
"browsing context");
|
|
|
|
}
|
|
|
|
|
2020-12-11 18:43:19 +03:00
|
|
|
void BrowsingContext::DidSet(FieldIndex<IDX_ExplicitActive>,
|
|
|
|
ExplicitActiveStatus aOldValue) {
|
|
|
|
const bool isActive = IsActive();
|
|
|
|
const bool wasActive = [&] {
|
|
|
|
if (aOldValue != ExplicitActiveStatus::None) {
|
|
|
|
return aOldValue == ExplicitActiveStatus::Active;
|
|
|
|
}
|
|
|
|
return GetParent() && GetParent()->IsActive();
|
|
|
|
}();
|
|
|
|
|
|
|
|
if (isActive == wasActive) {
|
2020-07-22 00:04:53 +03:00
|
|
|
return;
|
|
|
|
}
|
2020-12-11 18:43:19 +03:00
|
|
|
|
|
|
|
if (IsTop()) {
|
|
|
|
Group()->UpdateToplevelsSuspendedIfNeeded();
|
|
|
|
|
|
|
|
#if defined(XP_WIN) && defined(ACCESSIBILITY)
|
|
|
|
if (XRE_IsParentProcess() && a11y::Compatibility::IsDolphin()) {
|
|
|
|
// update active accessible documents on windows
|
|
|
|
if (BrowserParent* bp = Canonical()->GetBrowserParent()) {
|
|
|
|
if (a11y::DocAccessibleParent* tabDoc =
|
|
|
|
bp->GetTopLevelDocAccessible()) {
|
|
|
|
HWND window = tabDoc->GetEmulatedWindowHandle();
|
|
|
|
MOZ_ASSERT(window);
|
|
|
|
if (window) {
|
|
|
|
if (isActive) {
|
|
|
|
a11y::nsWinUtils::ShowNativeWindow(window);
|
|
|
|
} else {
|
|
|
|
a11y::nsWinUtils::HideNativeWindow(window);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
PreOrderWalk([&](BrowsingContext* aContext) {
|
|
|
|
if (nsCOMPtr<nsIDocShell> ds = aContext->GetDocShell()) {
|
|
|
|
nsDocShell::Cast(ds)->ActivenessMaybeChanged();
|
|
|
|
}
|
|
|
|
});
|
2020-10-23 00:31:18 +03:00
|
|
|
}
|
2020-07-22 00:04:53 +03:00
|
|
|
|
2020-10-23 00:31:18 +03:00
|
|
|
bool BrowsingContext::CanSet(FieldIndex<IDX_HasMainMediaController>,
|
|
|
|
bool aNewValue, ContentParent* aSource) {
|
2021-01-28 06:31:50 +03:00
|
|
|
return IsTop() && LegacyCheckOnlyOwningProcessCanSet(aSource);
|
2020-10-23 00:31:18 +03:00
|
|
|
}
|
2020-07-22 00:04:53 +03:00
|
|
|
|
2020-10-23 00:31:18 +03:00
|
|
|
void BrowsingContext::DidSet(FieldIndex<IDX_HasMainMediaController>,
|
|
|
|
bool aOldValue) {
|
|
|
|
if (!IsTop() || aOldValue == GetHasMainMediaController()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Group()->UpdateToplevelsSuspendedIfNeeded();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BrowsingContext::InactiveForSuspend() const {
|
|
|
|
if (!StaticPrefs::dom_suspend_inactive_enabled()) {
|
|
|
|
return false;
|
2020-07-22 00:04:53 +03:00
|
|
|
}
|
2020-10-23 00:31:18 +03:00
|
|
|
// We should suspend a page only when it's inactive and doesn't have a main
|
|
|
|
// media controller. Having a main controller in context means it might be
|
|
|
|
// playing media, or waiting media keys to control media (could be not playing
|
|
|
|
// anything currently)
|
2020-12-11 18:43:19 +03:00
|
|
|
return !IsActive() && !GetHasMainMediaController();
|
2020-07-22 00:04:53 +03:00
|
|
|
}
|
|
|
|
|
2020-11-10 18:57:30 +03:00
|
|
|
bool BrowsingContext::CanSet(
|
|
|
|
FieldIndex<IDX_TouchEventsOverrideInternal>,
|
|
|
|
const enum TouchEventsOverride& aTouchEventsOverride,
|
|
|
|
ContentParent* aSource) {
|
2021-01-26 23:38:20 +03:00
|
|
|
// TODO: Bug 1688948 - Should only be set in the parent process.
|
|
|
|
return true;
|
2020-11-10 18:57:30 +03:00
|
|
|
}
|
|
|
|
|
2021-02-03 13:38:09 +03:00
|
|
|
void BrowsingContext::DidSet(FieldIndex<IDX_PrefersColorSchemeOverride>,
|
|
|
|
dom::PrefersColorSchemeOverride aOldValue) {
|
|
|
|
MOZ_ASSERT(IsTop());
|
|
|
|
if (PrefersColorSchemeOverride() == aOldValue) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
PreOrderWalk([&](BrowsingContext* aContext) {
|
|
|
|
if (nsIDocShell* shell = aContext->GetDocShell()) {
|
|
|
|
if (nsPresContext* pc = shell->GetPresContext()) {
|
|
|
|
// This is a bit of a lie, but it's the code-path that gets taken for
|
|
|
|
// regular system metrics changes via ThemeChanged().
|
|
|
|
// TODO(emilio): The JustThisDocument is a bit suspect here,
|
|
|
|
// prefers-color-scheme also applies to images or such, but the override
|
|
|
|
// means that we could need to render the same image both with "light"
|
|
|
|
// and "dark" appearance, so we just don't bother.
|
|
|
|
pc->MediaFeatureValuesChanged(
|
|
|
|
{MediaFeatureChangeReason::SystemMetricsChange},
|
|
|
|
MediaFeatureChangePropagation::JustThisDocument);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowsingContext::DidSet(FieldIndex<IDX_MediumOverride>,
|
|
|
|
nsString&& aOldValue) {
|
|
|
|
MOZ_ASSERT(IsTop());
|
|
|
|
if (GetMediumOverride() == aOldValue) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
PreOrderWalk([&](BrowsingContext* aContext) {
|
|
|
|
if (nsIDocShell* shell = aContext->GetDocShell()) {
|
|
|
|
if (nsPresContext* pc = shell->GetPresContext()) {
|
|
|
|
pc->RecomputeBrowsingContextDependentData();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2020-10-09 20:31:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void BrowsingContext::DidSet(FieldIndex<IDX_DisplayMode>,
|
|
|
|
enum DisplayMode aOldValue) {
|
|
|
|
MOZ_ASSERT(IsTop());
|
|
|
|
|
|
|
|
if (GetDisplayMode() == aOldValue) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
PreOrderWalk([&](BrowsingContext* aContext) {
|
|
|
|
if (nsIDocShell* shell = aContext->GetDocShell()) {
|
|
|
|
if (nsPresContext* pc = shell->GetPresContext()) {
|
2020-10-22 12:29:43 +03:00
|
|
|
pc->MediaFeatureValuesChanged(
|
2020-10-09 20:31:59 +03:00
|
|
|
{MediaFeatureChangeReason::DisplayModeChange},
|
2020-10-22 12:29:43 +03:00
|
|
|
// We're already iterating through sub documents, so we don't need
|
|
|
|
// to propagate the change again.
|
|
|
|
//
|
|
|
|
// Images and other resources don't change their display-mode
|
|
|
|
// evaluation, display-mode is a property of the browsing context.
|
|
|
|
MediaFeatureChangePropagation::JustThisDocument);
|
2020-10-09 20:31:59 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-04-20 23:09:32 +03:00
|
|
|
void BrowsingContext::DidSet(FieldIndex<IDX_Muted>) {
|
2020-10-27 22:55:47 +03:00
|
|
|
MOZ_ASSERT(IsTop(), "Set muted flag on non top-level context!");
|
2019-08-20 00:17:21 +03:00
|
|
|
USER_ACTIVATION_LOG("Set audio muted %d for %s browsing context 0x%08" PRIx64,
|
2020-01-20 17:57:47 +03:00
|
|
|
GetMuted(), XRE_IsParentProcess() ? "Parent" : "Child",
|
|
|
|
Id());
|
2019-08-20 00:17:21 +03:00
|
|
|
PreOrderWalk([&](BrowsingContext* aContext) {
|
|
|
|
nsPIDOMWindowOuter* win = aContext->GetDOMWindow();
|
|
|
|
if (win) {
|
|
|
|
win->RefreshMediaElementsVolume();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-07-31 16:37:13 +03:00
|
|
|
void BrowsingContext::SetCustomUserAgent(const nsAString& aUserAgent,
|
|
|
|
ErrorResult& aRv) {
|
|
|
|
Top()->SetUserAgentOverride(aUserAgent, aRv);
|
2020-03-19 04:49:04 +03:00
|
|
|
}
|
|
|
|
|
2020-07-31 16:37:13 +03:00
|
|
|
nsresult BrowsingContext::SetCustomUserAgent(const nsAString& aUserAgent) {
|
|
|
|
return Top()->SetUserAgentOverride(aUserAgent);
|
2020-02-24 05:15:03 +03:00
|
|
|
}
|
|
|
|
|
2020-04-20 23:09:32 +03:00
|
|
|
void BrowsingContext::DidSet(FieldIndex<IDX_UserAgentOverride>) {
|
2020-02-24 05:15:03 +03:00
|
|
|
MOZ_ASSERT(IsTop());
|
|
|
|
|
|
|
|
PreOrderWalk([&](BrowsingContext* aContext) {
|
|
|
|
nsIDocShell* shell = aContext->GetDocShell();
|
|
|
|
if (shell) {
|
|
|
|
shell->ClearCachedUserAgent();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-07-31 16:37:13 +03:00
|
|
|
void BrowsingContext::SetCustomPlatform(const nsAString& aPlatform,
|
|
|
|
ErrorResult& aRv) {
|
|
|
|
Top()->SetPlatformOverride(aPlatform, aRv);
|
2020-06-26 17:17:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void BrowsingContext::DidSet(FieldIndex<IDX_PlatformOverride>) {
|
|
|
|
MOZ_ASSERT(IsTop());
|
|
|
|
|
|
|
|
PreOrderWalk([&](BrowsingContext* aContext) {
|
|
|
|
nsIDocShell* shell = aContext->GetDocShell();
|
|
|
|
if (shell) {
|
|
|
|
shell->ClearCachedPlatform();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-02-02 17:33:48 +03:00
|
|
|
bool BrowsingContext::LegacyCheckOnlyOwningProcessCanSet(
|
|
|
|
ContentParent* aSource) {
|
2020-02-24 05:15:03 +03:00
|
|
|
if (aSource) {
|
|
|
|
MOZ_ASSERT(XRE_IsParentProcess());
|
|
|
|
|
|
|
|
// Double-check ownership if we aren't the setter.
|
|
|
|
if (!Canonical()->IsOwnedByProcess(aSource->ChildID()) &&
|
|
|
|
aSource->ChildID() != Canonical()->GetInFlightProcessId()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else if (!IsInProcess() && !XRE_IsParentProcess()) {
|
|
|
|
// Don't allow this to be set from content processes that
|
|
|
|
// don't own the BrowsingContext.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-11-20 18:16:58 +03:00
|
|
|
bool BrowsingContext::CanSet(FieldIndex<IDX_IsActiveBrowserWindowInternal>,
|
|
|
|
const bool& aValue, ContentParent* aSource) {
|
|
|
|
// Should only be set in the parent process.
|
|
|
|
return XRE_IsParentProcess() && !aSource && IsTop();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowsingContext::DidSet(FieldIndex<IDX_IsActiveBrowserWindowInternal>,
|
|
|
|
bool aOldValue) {
|
|
|
|
bool isActivateEvent = GetIsActiveBrowserWindowInternal();
|
|
|
|
// The browser window containing this context has changed
|
|
|
|
// activation state so update window inactive document states
|
|
|
|
// for all in-process documents.
|
|
|
|
PreOrderWalk([isActivateEvent](BrowsingContext* aContext) {
|
|
|
|
if (RefPtr<Document> doc = aContext->GetExtantDocument()) {
|
|
|
|
doc->UpdateDocumentStates(NS_DOCUMENT_STATE_WINDOW_INACTIVE, true);
|
|
|
|
|
|
|
|
if (XRE_IsContentProcess() &&
|
|
|
|
(!aContext->GetParent() || !aContext->GetParent()->IsInProcess())) {
|
|
|
|
// Send the inner window an activate/deactivate event if
|
|
|
|
// the context is the top of a sub-tree of in-process
|
|
|
|
// contexts.
|
|
|
|
nsContentUtils::DispatchEventOnlyToChrome(
|
|
|
|
doc, doc->GetWindow()->GetCurrentInnerWindow(),
|
|
|
|
isActivateEvent ? u"activate"_ns : u"deactivate"_ns,
|
|
|
|
CanBubble::eYes, Cancelable::eYes, nullptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-03-19 04:49:04 +03:00
|
|
|
bool BrowsingContext::CanSet(FieldIndex<IDX_AllowContentRetargeting>,
|
|
|
|
const bool& aAllowContentRetargeting,
|
|
|
|
ContentParent* aSource) {
|
2021-01-28 06:31:50 +03:00
|
|
|
return LegacyCheckOnlyOwningProcessCanSet(aSource);
|
2020-03-19 04:49:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool BrowsingContext::CanSet(FieldIndex<IDX_AllowContentRetargetingOnChildren>,
|
|
|
|
const bool& aAllowContentRetargetingOnChildren,
|
|
|
|
ContentParent* aSource) {
|
2021-01-28 06:31:50 +03:00
|
|
|
return LegacyCheckOnlyOwningProcessCanSet(aSource);
|
2020-03-19 04:49:04 +03:00
|
|
|
}
|
|
|
|
|
2020-03-19 04:48:56 +03:00
|
|
|
bool BrowsingContext::CanSet(FieldIndex<IDX_AllowPlugins>,
|
|
|
|
const bool& aAllowPlugins,
|
|
|
|
ContentParent* aSource) {
|
2021-01-28 06:31:50 +03:00
|
|
|
return LegacyCheckOnlyOwningProcessCanSet(aSource);
|
2020-04-30 12:56:25 +03:00
|
|
|
}
|
|
|
|
|
2020-06-09 02:49:31 +03:00
|
|
|
bool BrowsingContext::CanSet(FieldIndex<IDX_FullscreenAllowedByOwner>,
|
|
|
|
const bool& aAllowed, ContentParent* aSource) {
|
|
|
|
return CheckOnlyEmbedderCanSet(aSource);
|
|
|
|
}
|
|
|
|
|
2020-06-25 07:32:51 +03:00
|
|
|
bool BrowsingContext::CanSet(FieldIndex<IDX_UseErrorPages>,
|
|
|
|
const bool& aUseErrorPages,
|
|
|
|
ContentParent* aSource) {
|
|
|
|
return CheckOnlyEmbedderCanSet(aSource);
|
|
|
|
}
|
|
|
|
|
2020-11-20 01:44:42 +03:00
|
|
|
mozilla::dom::TouchEventsOverride BrowsingContext::TouchEventsOverride() const {
|
|
|
|
const BrowsingContext* bc = this;
|
2020-11-10 18:57:30 +03:00
|
|
|
while (bc) {
|
|
|
|
mozilla::dom::TouchEventsOverride tev =
|
|
|
|
bc->GetTouchEventsOverrideInternal();
|
|
|
|
if (tev != mozilla::dom::TouchEventsOverride::None) {
|
|
|
|
return tev;
|
|
|
|
}
|
|
|
|
|
|
|
|
bc = bc->GetParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
return mozilla::dom::TouchEventsOverride::None;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowsingContext::SetTouchEventsOverride(
|
|
|
|
const enum TouchEventsOverride aTouchEventsOverride, ErrorResult& aRv) {
|
|
|
|
SetTouchEventsOverrideInternal(aTouchEventsOverride, aRv);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult BrowsingContext::SetTouchEventsOverride(
|
|
|
|
const enum TouchEventsOverride aTouchEventsOverride) {
|
|
|
|
ErrorResult rv;
|
|
|
|
SetTouchEventsOverride(aTouchEventsOverride, rv);
|
|
|
|
return rv.StealNSResult();
|
|
|
|
}
|
|
|
|
|
2020-05-12 12:18:26 +03:00
|
|
|
// We map `watchedByDevTools` WebIDL attribute to `watchedByDevToolsInternal`
|
|
|
|
// BC field. And we map it to the top level BrowsingContext.
|
|
|
|
bool BrowsingContext::WatchedByDevTools() {
|
|
|
|
return Top()->GetWatchedByDevToolsInternal();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Enforce that the watchedByDevTools BC field can only be set on the top level
|
|
|
|
// Browsing Context.
|
|
|
|
bool BrowsingContext::CanSet(FieldIndex<IDX_WatchedByDevToolsInternal>,
|
|
|
|
const bool& aWatchedByDevTools,
|
2020-04-26 03:55:12 +03:00
|
|
|
ContentParent* aSource) {
|
2020-05-12 12:18:26 +03:00
|
|
|
return IsTop();
|
|
|
|
}
|
|
|
|
void BrowsingContext::SetWatchedByDevTools(bool aWatchedByDevTools,
|
|
|
|
ErrorResult& aRv) {
|
|
|
|
if (!IsTop()) {
|
|
|
|
aRv.ThrowInvalidModificationError(
|
|
|
|
"watchedByDevTools can only be set on top BrowsingContext");
|
|
|
|
return;
|
|
|
|
}
|
2020-07-31 16:37:13 +03:00
|
|
|
SetWatchedByDevToolsInternal(aWatchedByDevTools, aRv);
|
2020-04-26 03:55:12 +03:00
|
|
|
}
|
|
|
|
|
2020-04-27 08:37:59 +03:00
|
|
|
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?
|
2021-01-28 06:31:50 +03:00
|
|
|
return LegacyCheckOnlyOwningProcessCanSet(aSource);
|
2020-04-27 08:37:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2020-07-31 16:37:00 +03:00
|
|
|
// Setting load flags on a discarded context has no effect.
|
|
|
|
Unused << aContext->SetDefaultLoadFlags(loadFlags);
|
2020-04-27 08:37:59 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-08 06:28:38 +03:00
|
|
|
bool BrowsingContext::CanSet(FieldIndex<IDX_UseGlobalHistory>,
|
|
|
|
const bool& aUseGlobalHistory,
|
|
|
|
ContentParent* aSource) {
|
2020-05-08 06:28:44 +03:00
|
|
|
// Should only be set in the parent process.
|
|
|
|
// return XRE_IsParentProcess() && !aSource;
|
2020-05-08 06:28:38 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-03-19 04:48:56 +03:00
|
|
|
bool BrowsingContext::CanSet(FieldIndex<IDX_UserAgentOverride>,
|
|
|
|
const nsString& aUserAgent,
|
|
|
|
ContentParent* aSource) {
|
|
|
|
if (!IsTop()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-01-28 06:31:50 +03:00
|
|
|
return LegacyCheckOnlyOwningProcessCanSet(aSource);
|
2020-06-26 17:17:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool BrowsingContext::CanSet(FieldIndex<IDX_PlatformOverride>,
|
|
|
|
const nsString& aPlatform,
|
|
|
|
ContentParent* aSource) {
|
|
|
|
if (!IsTop()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-01-28 06:31:50 +03:00
|
|
|
return LegacyCheckOnlyOwningProcessCanSet(aSource);
|
2020-03-19 04:48:56 +03:00
|
|
|
}
|
|
|
|
|
2020-02-26 02:17:56 +03:00
|
|
|
bool BrowsingContext::CheckOnlyEmbedderCanSet(ContentParent* aSource) {
|
2020-07-02 03:53:18 +03:00
|
|
|
if (XRE_IsParentProcess()) {
|
|
|
|
uint64_t childId = aSource ? aSource->ChildID() : 0;
|
|
|
|
return Canonical()->IsEmbeddedInProcess(childId);
|
2020-02-26 02:17:56 +03:00
|
|
|
}
|
|
|
|
return mEmbeddedByThisProcess;
|
|
|
|
}
|
|
|
|
|
2020-01-20 17:57:47 +03:00
|
|
|
bool BrowsingContext::CanSet(FieldIndex<IDX_EmbedderInnerWindowId>,
|
|
|
|
const uint64_t& aValue, ContentParent* aSource) {
|
2020-04-24 21:33:04 +03:00
|
|
|
// If we have a parent window, our embedder inner window ID must match it.
|
|
|
|
if (mParentWindow) {
|
|
|
|
return mParentWindow->Id() == aValue;
|
2020-04-24 05:31:55 +03:00
|
|
|
}
|
|
|
|
|
2020-04-24 21:33:04 +03:00
|
|
|
// For toplevel BrowsingContext instances, this value may only be set by the
|
|
|
|
// parent process, or initialized to `0`.
|
|
|
|
return CheckOnlyEmbedderCanSet(aSource);
|
2019-09-26 19:16:32 +03:00
|
|
|
}
|
|
|
|
|
2020-02-26 02:17:56 +03:00
|
|
|
bool BrowsingContext::CanSet(FieldIndex<IDX_EmbedderElementType>,
|
|
|
|
const Maybe<nsString>&, ContentParent* aSource) {
|
|
|
|
return CheckOnlyEmbedderCanSet(aSource);
|
|
|
|
}
|
|
|
|
|
2020-01-20 17:58:52 +03:00
|
|
|
bool BrowsingContext::CanSet(FieldIndex<IDX_CurrentInnerWindowId>,
|
|
|
|
const uint64_t& aValue, ContentParent* aSource) {
|
|
|
|
// Generally allow clearing this. We may want to be more precise about this
|
|
|
|
// check in the future.
|
|
|
|
if (aValue == 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aSource) {
|
|
|
|
MOZ_ASSERT(XRE_IsParentProcess());
|
|
|
|
|
|
|
|
// If in the parent process, double-check ownership and WindowGlobalParent
|
|
|
|
// as well.
|
|
|
|
RefPtr<WindowGlobalParent> wgp =
|
|
|
|
WindowGlobalParent::GetByInnerWindowId(aValue);
|
|
|
|
if (NS_WARN_IF(!wgp) || NS_WARN_IF(wgp->BrowsingContext() != this)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Double-check ownership if we aren't the setter.
|
|
|
|
if (!Canonical()->IsOwnedByProcess(aSource->ChildID()) &&
|
|
|
|
aSource->ChildID() != Canonical()->GetInFlightProcessId()) {
|
|
|
|
return false;
|
|
|
|
}
|
2020-08-28 20:21:17 +03:00
|
|
|
} else if (XRE_IsContentProcess() && !IsOwnedByProcess()) {
|
|
|
|
return false;
|
2020-01-20 17:58:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// We must have access to the specified context.
|
|
|
|
RefPtr<WindowContext> window = WindowContext::GetById(aValue);
|
|
|
|
return window && window->GetBrowsingContext() == this;
|
|
|
|
}
|
|
|
|
|
2020-04-20 23:09:32 +03:00
|
|
|
void BrowsingContext::DidSet(FieldIndex<IDX_CurrentInnerWindowId>) {
|
2020-05-22 03:34:17 +03:00
|
|
|
RefPtr<WindowContext> prevWindowContext = mCurrentWindowContext.forget();
|
2020-01-20 17:58:52 +03:00
|
|
|
mCurrentWindowContext = WindowContext::GetById(GetCurrentInnerWindowId());
|
2020-04-24 21:33:04 +03:00
|
|
|
MOZ_ASSERT(
|
|
|
|
!mCurrentWindowContext || mWindowContexts.Contains(mCurrentWindowContext),
|
|
|
|
"WindowContext not registered?");
|
|
|
|
|
|
|
|
// Clear our cached `children` value, to ensure that JS sees the up-to-date
|
|
|
|
// value.
|
|
|
|
BrowsingContext_Binding::ClearCachedChildrenValue(this);
|
|
|
|
|
2020-02-18 16:30:04 +03:00
|
|
|
if (XRE_IsParentProcess()) {
|
2020-05-22 03:34:17 +03:00
|
|
|
if (prevWindowContext != mCurrentWindowContext) {
|
|
|
|
if (prevWindowContext) {
|
|
|
|
prevWindowContext->Canonical()->DidBecomeCurrentWindowGlobal(false);
|
|
|
|
}
|
|
|
|
if (mCurrentWindowContext) {
|
|
|
|
mCurrentWindowContext->Canonical()->DidBecomeCurrentWindowGlobal(true);
|
|
|
|
}
|
|
|
|
}
|
2020-02-18 16:30:04 +03:00
|
|
|
BrowserParent::UpdateFocusFromBrowsingContext();
|
|
|
|
}
|
2020-01-20 17:58:52 +03:00
|
|
|
}
|
|
|
|
|
2020-01-20 17:57:47 +03:00
|
|
|
bool BrowsingContext::CanSet(FieldIndex<IDX_IsPopupSpam>, const bool& aValue,
|
|
|
|
ContentParent* aSource) {
|
2019-10-18 06:04:55 +03:00
|
|
|
// Ensure that we only mark a browsing context as popup spam once and never
|
|
|
|
// unmark it.
|
2020-01-20 17:57:47 +03:00
|
|
|
return aValue && !GetIsPopupSpam();
|
2019-10-18 06:04:55 +03:00
|
|
|
}
|
|
|
|
|
2020-04-20 23:09:32 +03:00
|
|
|
void BrowsingContext::DidSet(FieldIndex<IDX_IsPopupSpam>) {
|
2020-01-20 17:57:47 +03:00
|
|
|
if (GetIsPopupSpam()) {
|
2019-10-18 06:04:55 +03:00
|
|
|
PopupBlocker::RegisterOpenPopupSpam();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-01 15:59:19 +03:00
|
|
|
bool BrowsingContext::CanSet(FieldIndex<IDX_MessageManagerGroup>,
|
|
|
|
const nsString& aMessageManagerGroup,
|
|
|
|
ContentParent* aSource) {
|
|
|
|
// Should only be set in the parent process on toplevel.
|
|
|
|
return XRE_IsParentProcess() && !aSource && IsTopContent();
|
|
|
|
}
|
|
|
|
|
2020-04-27 18:43:36 +03:00
|
|
|
bool BrowsingContext::CanSet(
|
|
|
|
FieldIndex<IDX_OrientationLock>,
|
|
|
|
const mozilla::hal::ScreenOrientation& aOrientationLock,
|
|
|
|
ContentParent* aSource) {
|
|
|
|
return IsTop();
|
|
|
|
}
|
|
|
|
|
2019-12-01 00:13:54 +03:00
|
|
|
bool BrowsingContext::IsLoading() {
|
|
|
|
if (GetLoading()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we're in the same process as the page, we're possibly just
|
|
|
|
// updating the flag.
|
|
|
|
nsIDocShell* shell = GetDocShell();
|
|
|
|
if (shell) {
|
|
|
|
Document* doc = shell->GetDocument();
|
|
|
|
return doc && doc->GetReadyStateEnum() < Document::READYSTATE_COMPLETE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-04-20 23:09:32 +03:00
|
|
|
void BrowsingContext::DidSet(FieldIndex<IDX_Loading>) {
|
|
|
|
if (mFields.Get<IDX_Loading>()) {
|
2019-12-01 00:13:54 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (!mDeprioritizedLoadRunner.isEmpty()) {
|
|
|
|
nsCOMPtr<nsIRunnable> runner = mDeprioritizedLoadRunner.popFirst();
|
|
|
|
NS_DispatchToCurrentThread(runner.forget());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (StaticPrefs::dom_separate_event_queue_for_post_message_enabled() &&
|
|
|
|
Top() == this) {
|
|
|
|
Group()->FlushPostMessageEvents();
|
2019-12-01 00:13:24 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-20 17:57:47 +03:00
|
|
|
// Inform the Document for this context of the (potential) change in
|
|
|
|
// loading state
|
2020-04-20 23:09:32 +03:00
|
|
|
void BrowsingContext::DidSet(FieldIndex<IDX_AncestorLoading>) {
|
2020-01-20 17:57:47 +03:00
|
|
|
nsPIDOMWindowOuter* outer = GetDOMWindow();
|
|
|
|
if (!outer) {
|
|
|
|
MOZ_LOG(gTimeoutDeferralLog, mozilla::LogLevel::Debug,
|
2020-04-20 23:09:32 +03:00
|
|
|
("DidSetAncestorLoading BC: %p -- No outer window", (void*)this));
|
2020-01-20 17:57:47 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
Document* document = nsGlobalWindowOuter::Cast(outer)->GetExtantDoc();
|
|
|
|
if (document) {
|
|
|
|
MOZ_LOG(gTimeoutDeferralLog, mozilla::LogLevel::Debug,
|
2020-04-20 23:09:32 +03:00
|
|
|
("DidSetAncestorLoading BC: %p -- NotifyLoading(%d, %d, %d)",
|
2020-01-20 17:57:47 +03:00
|
|
|
(void*)this, GetAncestorLoading(), document->GetReadyStateEnum(),
|
|
|
|
document->GetReadyStateEnum()));
|
|
|
|
document->NotifyLoading(GetAncestorLoading(), document->GetReadyStateEnum(),
|
|
|
|
document->GetReadyStateEnum());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-04 06:25:16 +03:00
|
|
|
void BrowsingContext::DidSet(FieldIndex<IDX_AuthorStyleDisabledDefault>) {
|
|
|
|
MOZ_ASSERT(IsTop(),
|
|
|
|
"Should only set AuthorStyleDisabledDefault in the top "
|
|
|
|
"browsing context");
|
|
|
|
|
|
|
|
// We don't need to handle changes to this field, since PageStyleChild.jsm
|
|
|
|
// will respond to the PageStyle:Disable message in all content processes.
|
|
|
|
//
|
|
|
|
// But we store the state here on the top BrowsingContext so that the
|
|
|
|
// docshell has somewhere to look for the current author style disabling
|
|
|
|
// state when new iframes are inserted.
|
|
|
|
}
|
|
|
|
|
2020-04-22 22:32:52 +03:00
|
|
|
void BrowsingContext::DidSet(FieldIndex<IDX_TextZoom>, float aOldValue) {
|
2020-04-30 04:21:20 +03:00
|
|
|
if (GetTextZoom() == aOldValue) {
|
2020-04-22 22:32:52 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-30 04:21:20 +03:00
|
|
|
if (IsInProcess()) {
|
|
|
|
if (nsIDocShell* shell = GetDocShell()) {
|
|
|
|
if (nsPresContext* pc = shell->GetPresContext()) {
|
|
|
|
pc->RecomputeBrowsingContextDependentData();
|
|
|
|
}
|
2020-04-30 00:44:13 +03:00
|
|
|
}
|
2020-04-22 22:32:52 +03:00
|
|
|
|
2020-04-30 04:21:20 +03:00
|
|
|
for (BrowsingContext* child : Children()) {
|
2020-07-31 16:37:00 +03:00
|
|
|
// Setting text zoom on a discarded context has no effect.
|
|
|
|
Unused << child->SetTextZoom(GetTextZoom());
|
2020-04-30 04:21:20 +03:00
|
|
|
}
|
2020-04-30 04:13:42 +03:00
|
|
|
}
|
|
|
|
|
2020-04-30 04:21:20 +03:00
|
|
|
if (IsTop() && XRE_IsParentProcess()) {
|
|
|
|
if (Element* element = GetEmbedderElement()) {
|
|
|
|
auto dispatcher = MakeRefPtr<AsyncEventDispatcher>(
|
|
|
|
element, u"TextZoomChange"_ns, CanBubble::eYes,
|
|
|
|
ChromeOnlyDispatch::eYes);
|
|
|
|
dispatcher->RunDOMEventWhenSafe();
|
|
|
|
}
|
2020-04-22 22:32:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(emilio): It'd be potentially nicer and cheaper to allow to set this only
|
|
|
|
// on the Top() browsing context, but there are a lot of tests that rely on
|
|
|
|
// zooming a subframe so...
|
|
|
|
void BrowsingContext::DidSet(FieldIndex<IDX_FullZoom>, float aOldValue) {
|
2020-04-30 04:21:20 +03:00
|
|
|
if (GetFullZoom() == aOldValue) {
|
2020-04-22 22:32:52 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-30 04:21:20 +03:00
|
|
|
if (IsInProcess()) {
|
|
|
|
if (nsIDocShell* shell = GetDocShell()) {
|
|
|
|
if (nsPresContext* pc = shell->GetPresContext()) {
|
|
|
|
pc->RecomputeBrowsingContextDependentData();
|
|
|
|
}
|
2020-04-30 00:44:13 +03:00
|
|
|
}
|
2020-04-30 04:13:42 +03:00
|
|
|
|
2020-04-30 04:21:20 +03:00
|
|
|
for (BrowsingContext* child : Children()) {
|
2020-07-31 16:37:00 +03:00
|
|
|
// Setting full zoom on a discarded context has no effect.
|
|
|
|
Unused << child->SetFullZoom(GetFullZoom());
|
2020-04-30 04:21:20 +03:00
|
|
|
}
|
2020-04-30 04:13:42 +03:00
|
|
|
}
|
|
|
|
|
2020-04-30 04:21:20 +03:00
|
|
|
if (IsTop() && XRE_IsParentProcess()) {
|
|
|
|
if (Element* element = GetEmbedderElement()) {
|
|
|
|
auto dispatcher = MakeRefPtr<AsyncEventDispatcher>(
|
|
|
|
element, u"FullZoomChange"_ns, CanBubble::eYes,
|
|
|
|
ChromeOnlyDispatch::eYes);
|
|
|
|
dispatcher->RunDOMEventWhenSafe();
|
|
|
|
}
|
2020-04-30 04:13:42 +03:00
|
|
|
}
|
2020-04-22 22:32:52 +03:00
|
|
|
}
|
|
|
|
|
2019-12-01 00:13:24 +03:00
|
|
|
void BrowsingContext::AddDeprioritizedLoadRunner(nsIRunnable* aRunner) {
|
2019-12-01 00:13:54 +03:00
|
|
|
MOZ_ASSERT(IsLoading());
|
2019-12-01 00:13:24 +03:00
|
|
|
MOZ_ASSERT(Top() == this);
|
|
|
|
|
|
|
|
RefPtr<DeprioritizedLoadRunner> runner = new DeprioritizedLoadRunner(aRunner);
|
|
|
|
mDeprioritizedLoadRunner.insertBack(runner);
|
|
|
|
NS_DispatchToCurrentThreadQueue(
|
|
|
|
runner.forget(), StaticPrefs::page_load_deprioritization_period(),
|
|
|
|
EventQueuePriority::Idle);
|
|
|
|
}
|
|
|
|
|
2020-10-23 13:07:09 +03:00
|
|
|
void BrowsingContext::GetHistoryID(JSContext* aCx,
|
|
|
|
JS::MutableHandle<JS::Value> aVal,
|
|
|
|
ErrorResult& aError) {
|
|
|
|
if (!xpc::ID2JSValue(aCx, GetHistoryID(), aVal)) {
|
|
|
|
aError.Throw(NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-19 11:57:44 +03:00
|
|
|
void BrowsingContext::InitSessionHistory() {
|
|
|
|
MOZ_ASSERT(!IsDiscarded());
|
|
|
|
MOZ_ASSERT(IsTop());
|
|
|
|
MOZ_ASSERT(EverAttached());
|
|
|
|
|
|
|
|
if (!GetHasSessionHistory()) {
|
2020-07-31 16:37:13 +03:00
|
|
|
MOZ_ALWAYS_SUCCEEDS(SetHasSessionHistory(true));
|
2020-05-19 11:57:44 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ChildSHistory* BrowsingContext::GetChildSessionHistory() {
|
2020-09-28 15:01:12 +03:00
|
|
|
if (!mozilla::SessionHistoryInParent()) {
|
2020-05-20 12:15:31 +03:00
|
|
|
// For now we're checking that the session history object for the child
|
|
|
|
// process is available before returning the ChildSHistory object, because
|
|
|
|
// it is the actual implementation that ChildSHistory forwards to. This can
|
|
|
|
// be removed once session history is stored exclusively in the parent
|
|
|
|
// process.
|
|
|
|
return mChildSessionHistory && mChildSessionHistory->IsInProcess()
|
|
|
|
? mChildSessionHistory.get()
|
|
|
|
: nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mChildSessionHistory;
|
2020-05-19 11:57:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void BrowsingContext::CreateChildSHistory() {
|
|
|
|
MOZ_ASSERT(IsTop());
|
2020-07-07 04:10:01 +03:00
|
|
|
MOZ_ASSERT(GetHasSessionHistory());
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(!mChildSessionHistory);
|
2020-05-19 11:57:44 +03:00
|
|
|
|
|
|
|
// Because session history is global in a browsing context tree, every process
|
|
|
|
// that has access to a browsing context tree needs access to its session
|
|
|
|
// history. That is why we create the ChildSHistory object in every process
|
|
|
|
// where we have access to this browsing context (which is the top one).
|
|
|
|
mChildSessionHistory = new ChildSHistory(this);
|
2020-07-17 12:39:59 +03:00
|
|
|
|
|
|
|
// If the top browsing context (this one) is loaded in this process then we
|
|
|
|
// also create the session history implementation for the child process.
|
|
|
|
// This can be removed once session history is stored exclusively in the
|
|
|
|
// parent process.
|
2020-07-07 04:10:01 +03:00
|
|
|
mChildSessionHistory->SetIsInProcess(IsInProcess());
|
2020-05-19 11:57:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void BrowsingContext::DidSet(FieldIndex<IDX_HasSessionHistory>,
|
|
|
|
bool aOldValue) {
|
|
|
|
MOZ_ASSERT(GetHasSessionHistory() || !aOldValue,
|
|
|
|
"We don't support turning off session history.");
|
|
|
|
|
2020-07-07 04:10:01 +03:00
|
|
|
if (GetHasSessionHistory() && !aOldValue) {
|
|
|
|
CreateChildSHistory();
|
|
|
|
}
|
2020-05-19 11:57:44 +03:00
|
|
|
}
|
|
|
|
|
2020-06-16 21:12:46 +03:00
|
|
|
bool BrowsingContext::CanSet(FieldIndex<IDX_BrowserId>, const uint32_t& aValue,
|
|
|
|
ContentParent* aSource) {
|
|
|
|
// We should only be able to set this for toplevel contexts which don't have
|
|
|
|
// an ID yet.
|
|
|
|
return GetBrowserId() == 0 && IsTop() && Children().IsEmpty();
|
|
|
|
}
|
|
|
|
|
2020-09-16 23:47:55 +03:00
|
|
|
bool BrowsingContext::CanSet(FieldIndex<IDX_PendingInitialization>,
|
|
|
|
bool aNewValue, ContentParent* aSource) {
|
|
|
|
// Can only be cleared from `true` to `false`, and should only ever be set on
|
|
|
|
// the toplevel BrowsingContext.
|
|
|
|
return IsTop() && GetPendingInitialization() && !aNewValue;
|
|
|
|
}
|
|
|
|
|
2020-07-17 02:04:18 +03:00
|
|
|
void BrowsingContext::SessionHistoryChanged(int32_t aIndexDelta,
|
|
|
|
int32_t aLengthDelta) {
|
2020-09-28 15:01:12 +03:00
|
|
|
if (XRE_IsParentProcess() || mozilla::SessionHistoryInParent()) {
|
2020-07-17 02:04:18 +03:00
|
|
|
// This method is used to test index and length for the session history
|
|
|
|
// in child process only.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!IsTop()) {
|
|
|
|
// Some tests have unexpected setup while Fission shistory is being
|
|
|
|
// implemented.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<ChildSHistory> shistory = GetChildSessionHistory();
|
|
|
|
if (!shistory || !shistory->AsyncHistoryLength()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsID changeID = shistory->AddPendingHistoryChange(aIndexDelta, aLengthDelta);
|
|
|
|
uint32_t index = shistory->Index();
|
|
|
|
uint32_t length = shistory->Count();
|
|
|
|
|
|
|
|
// Do artificial history update through parent process to test asynchronous
|
|
|
|
// history.length handling.
|
|
|
|
ContentChild::GetSingleton()->SendSessionHistoryUpdate(this, index, length,
|
|
|
|
changeID);
|
|
|
|
}
|
|
|
|
|
2020-08-12 18:38:12 +03:00
|
|
|
bool BrowsingContext::IsPopupAllowed() {
|
|
|
|
for (auto* context = GetCurrentWindowContext(); context;
|
|
|
|
context = context->GetParentWindowContext()) {
|
|
|
|
if (context->CanShowPopup()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-12-15 18:02:33 +03:00
|
|
|
void BrowsingContext::SessionHistoryCommit(
|
|
|
|
const LoadingSessionHistoryInfo& aInfo, uint32_t aLoadType,
|
|
|
|
bool aHadActiveEntry, bool aPersist, bool aCloneEntryChildren) {
|
|
|
|
nsID changeID = {};
|
|
|
|
if (XRE_IsContentProcess()) {
|
|
|
|
RefPtr<ChildSHistory> rootSH = Top()->GetChildSessionHistory();
|
|
|
|
if (rootSH) {
|
|
|
|
if (!aInfo.mLoadIsFromSessionHistory) {
|
|
|
|
// We try to mimic as closely as possible what will happen in
|
|
|
|
// CanonicalBrowsingContext::SessionHistoryCommit. We'll be
|
|
|
|
// incrementing the session history length if we're not replacing,
|
|
|
|
// this is a top-level load or it's not the initial load in an iframe,
|
|
|
|
// and ShouldUpdateSessionHistory(loadType) returns true.
|
|
|
|
// It is possible that this leads to wrong length temporarily, but
|
|
|
|
// so would not having the check for replace.
|
|
|
|
if (!LOAD_TYPE_HAS_FLAGS(
|
|
|
|
aLoadType, nsIWebNavigation::LOAD_FLAGS_REPLACE_HISTORY) &&
|
|
|
|
(IsTop() || aHadActiveEntry) &&
|
|
|
|
ShouldUpdateSessionHistory(aLoadType)) {
|
|
|
|
changeID = rootSH->AddPendingHistoryChange();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// This is a load from session history, so we can update
|
|
|
|
// index and length immediately.
|
|
|
|
rootSH->SetIndexAndLength(aInfo.mRequestedIndex,
|
|
|
|
aInfo.mSessionHistoryLength, changeID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ContentChild* cc = ContentChild::GetSingleton();
|
|
|
|
mozilla::Unused << cc->SendHistoryCommit(this, aInfo.mLoadId, changeID,
|
|
|
|
aLoadType, aPersist,
|
|
|
|
aCloneEntryChildren);
|
|
|
|
} else {
|
|
|
|
Canonical()->SessionHistoryCommit(aInfo.mLoadId, changeID, aLoadType,
|
|
|
|
aPersist, aCloneEntryChildren);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-29 15:04:20 +03:00
|
|
|
void BrowsingContext::SetActiveSessionHistoryEntry(
|
2020-08-23 20:41:03 +03:00
|
|
|
const Maybe<nsPoint>& aPreviousScrollPos, SessionHistoryInfo* aInfo,
|
2020-10-31 01:10:15 +03:00
|
|
|
uint32_t aLoadType, uint32_t aUpdatedCacheKey) {
|
2020-08-23 20:41:03 +03:00
|
|
|
if (XRE_IsContentProcess()) {
|
2020-10-09 22:20:07 +03:00
|
|
|
// XXX Why we update cache key only in content process case?
|
2020-09-29 15:09:59 +03:00
|
|
|
if (aUpdatedCacheKey != 0) {
|
|
|
|
aInfo->SetCacheKey(aUpdatedCacheKey);
|
|
|
|
}
|
|
|
|
|
2020-08-23 20:41:03 +03:00
|
|
|
nsID changeID = {};
|
2020-10-05 20:17:56 +03:00
|
|
|
RefPtr<ChildSHistory> shistory = Top()->GetChildSessionHistory();
|
2020-08-23 20:41:03 +03:00
|
|
|
if (shistory) {
|
2020-10-05 14:04:10 +03:00
|
|
|
changeID = shistory->AddPendingHistoryChange();
|
2020-08-23 20:41:03 +03:00
|
|
|
}
|
2020-09-29 15:04:20 +03:00
|
|
|
ContentChild::GetSingleton()->SendSetActiveSessionHistoryEntry(
|
2020-10-31 01:10:15 +03:00
|
|
|
this, aPreviousScrollPos, *aInfo, aLoadType, aUpdatedCacheKey,
|
|
|
|
changeID);
|
2020-08-23 20:41:03 +03:00
|
|
|
} else {
|
2020-10-31 01:10:15 +03:00
|
|
|
Canonical()->SetActiveSessionHistoryEntry(
|
|
|
|
aPreviousScrollPos, aInfo, aLoadType, aUpdatedCacheKey, nsID());
|
2020-08-23 20:41:03 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowsingContext::ReplaceActiveSessionHistoryEntry(
|
|
|
|
SessionHistoryInfo* aInfo) {
|
|
|
|
if (XRE_IsContentProcess()) {
|
|
|
|
ContentChild::GetSingleton()->SendReplaceActiveSessionHistoryEntry(this,
|
|
|
|
*aInfo);
|
|
|
|
} else {
|
|
|
|
Canonical()->ReplaceActiveSessionHistoryEntry(aInfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-25 19:04:51 +03:00
|
|
|
void BrowsingContext::RemoveDynEntriesFromActiveSessionHistoryEntry() {
|
|
|
|
if (XRE_IsContentProcess()) {
|
|
|
|
ContentChild::GetSingleton()
|
|
|
|
->SendRemoveDynEntriesFromActiveSessionHistoryEntry(this);
|
|
|
|
} else {
|
|
|
|
Canonical()->RemoveDynEntriesFromActiveSessionHistoryEntry();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-03 03:02:29 +03:00
|
|
|
void BrowsingContext::RemoveFromSessionHistory(const nsID& aChangeID) {
|
2020-08-25 19:20:17 +03:00
|
|
|
if (XRE_IsContentProcess()) {
|
2021-02-03 03:02:29 +03:00
|
|
|
ContentChild::GetSingleton()->SendRemoveFromSessionHistory(this, aChangeID);
|
2020-08-25 19:20:17 +03:00
|
|
|
} else {
|
2021-02-03 03:02:29 +03:00
|
|
|
Canonical()->RemoveFromSessionHistory(aChangeID);
|
2020-08-25 19:20:17 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-23 23:27:50 +03:00
|
|
|
void BrowsingContext::HistoryGo(int32_t aOffset, uint64_t aHistoryEpoch,
|
2020-11-18 14:51:00 +03:00
|
|
|
bool aRequireUserInteraction,
|
2020-09-08 22:32:27 +03:00
|
|
|
std::function<void(int32_t&&)>&& aResolver) {
|
|
|
|
if (XRE_IsContentProcess()) {
|
|
|
|
ContentChild::GetSingleton()->SendHistoryGo(
|
2020-11-18 14:51:00 +03:00
|
|
|
this, aOffset, aHistoryEpoch, aRequireUserInteraction,
|
|
|
|
std::move(aResolver),
|
2020-09-08 22:32:27 +03:00
|
|
|
[](mozilla::ipc::
|
|
|
|
ResponseRejectReason) { /* FIXME Is ignoring this fine? */ });
|
|
|
|
} else {
|
2020-10-23 23:27:50 +03:00
|
|
|
Canonical()->HistoryGo(
|
2020-11-18 14:51:00 +03:00
|
|
|
aOffset, aHistoryEpoch, aRequireUserInteraction,
|
2020-10-23 23:27:50 +03:00
|
|
|
Canonical()->GetContentParent()
|
|
|
|
? Some(Canonical()->GetContentParent()->ChildID())
|
|
|
|
: Nothing(),
|
|
|
|
std::move(aResolver));
|
2020-09-08 22:32:27 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-08 18:24:13 +03:00
|
|
|
void BrowsingContext::SetChildSHistory(ChildSHistory* aChildSHistory) {
|
|
|
|
mChildSessionHistory = aChildSHistory;
|
|
|
|
mChildSessionHistory->SetBrowsingContext(this);
|
|
|
|
mFields.SetWithoutSyncing<IDX_HasSessionHistory>(true);
|
|
|
|
}
|
|
|
|
|
2020-09-20 15:40:10 +03:00
|
|
|
bool BrowsingContext::ShouldUpdateSessionHistory(uint32_t aLoadType) {
|
|
|
|
// We don't update session history on reload unless we're loading
|
|
|
|
// an iframe in shift-reload case.
|
|
|
|
return nsDocShell::ShouldUpdateGlobalHistory(aLoadType) &&
|
|
|
|
(!(aLoadType & nsIDocShell::LOAD_CMD_RELOAD) ||
|
|
|
|
(IsForceReloadType(aLoadType) && IsFrame()));
|
|
|
|
}
|
|
|
|
|
2020-09-21 14:54:50 +03:00
|
|
|
nsresult BrowsingContext::CheckLocationChangeRateLimit(CallerType aCallerType) {
|
|
|
|
// We only rate limit non system callers
|
|
|
|
if (aCallerType == CallerType::System) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fetch rate limiting preferences
|
|
|
|
uint32_t limitCount =
|
|
|
|
StaticPrefs::dom_navigation_locationChangeRateLimit_count();
|
|
|
|
uint32_t timeSpanSeconds =
|
|
|
|
StaticPrefs::dom_navigation_locationChangeRateLimit_timespan();
|
|
|
|
|
|
|
|
// Disable throttling if either of the preferences is set to 0.
|
|
|
|
if (limitCount == 0 || timeSpanSeconds == 0) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
TimeDuration throttleSpan = TimeDuration::FromSeconds(timeSpanSeconds);
|
|
|
|
|
|
|
|
if (mLocationChangeRateLimitSpanStart.IsNull() ||
|
|
|
|
((TimeStamp::Now() - mLocationChangeRateLimitSpanStart) > throttleSpan)) {
|
|
|
|
// Initial call or timespan exceeded, reset counter and timespan.
|
|
|
|
mLocationChangeRateLimitSpanStart = TimeStamp::Now();
|
|
|
|
mLocationChangeRateLimitCount = 1;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mLocationChangeRateLimitCount >= limitCount) {
|
|
|
|
// Rate limit reached
|
|
|
|
|
|
|
|
Document* doc = GetDocument();
|
|
|
|
if (doc) {
|
|
|
|
nsContentUtils::ReportToConsole(nsIScriptError::errorFlag, "DOM"_ns, doc,
|
|
|
|
nsContentUtils::eDOM_PROPERTIES,
|
|
|
|
"LocChangeFloodingPrevented");
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_DOM_SECURITY_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
mLocationChangeRateLimitCount++;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowsingContext::ResetLocationChangeRateLimit() {
|
|
|
|
// Resetting the timestamp object will cause the check function to
|
|
|
|
// init again and reset the rate limit.
|
|
|
|
mLocationChangeRateLimitSpanStart = TimeStamp();
|
|
|
|
}
|
|
|
|
|
2018-07-26 10:31:00 +03:00
|
|
|
} // namespace dom
|
2019-02-14 00:02:53 +03:00
|
|
|
|
|
|
|
namespace ipc {
|
|
|
|
|
2020-02-21 02:30:33 +03:00
|
|
|
void IPDLParamTraits<dom::MaybeDiscarded<dom::BrowsingContext>>::Write(
|
|
|
|
IPC::Message* aMsg, IProtocol* aActor,
|
|
|
|
const dom::MaybeDiscarded<dom::BrowsingContext>& aParam) {
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(!aParam.GetMaybeDiscarded() ||
|
|
|
|
aParam.GetMaybeDiscarded()->EverAttached());
|
|
|
|
uint64_t id = aParam.ContextId();
|
|
|
|
WriteIPDLParam(aMsg, aActor, id);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IPDLParamTraits<dom::MaybeDiscarded<dom::BrowsingContext>>::Read(
|
|
|
|
const IPC::Message* aMsg, PickleIterator* aIter, IProtocol* aActor,
|
|
|
|
dom::MaybeDiscarded<dom::BrowsingContext>* aResult) {
|
|
|
|
uint64_t id = 0;
|
|
|
|
if (!ReadIPDLParam(aMsg, aIter, aActor, &id)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (id == 0) {
|
|
|
|
*aResult = nullptr;
|
|
|
|
} else if (RefPtr<dom::BrowsingContext> bc = dom::BrowsingContext::Get(id)) {
|
|
|
|
*aResult = std::move(bc);
|
|
|
|
} else {
|
|
|
|
aResult->SetDiscarded(id);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-03-14 21:51:09 +03:00
|
|
|
void IPDLParamTraits<dom::BrowsingContext::IPCInitializer>::Write(
|
|
|
|
IPC::Message* aMessage, IProtocol* aActor,
|
|
|
|
const dom::BrowsingContext::IPCInitializer& aInit) {
|
|
|
|
// Write actor ID parameters.
|
|
|
|
WriteIPDLParam(aMessage, aActor, aInit.mId);
|
|
|
|
WriteIPDLParam(aMessage, aActor, aInit.mParentId);
|
2020-02-06 22:08:06 +03:00
|
|
|
WriteIPDLParam(aMessage, aActor, aInit.mWindowless);
|
2020-04-08 00:39:12 +03:00
|
|
|
WriteIPDLParam(aMessage, aActor, aInit.mUseRemoteTabs);
|
|
|
|
WriteIPDLParam(aMessage, aActor, aInit.mUseRemoteSubframes);
|
2020-10-31 01:10:22 +03:00
|
|
|
WriteIPDLParam(aMessage, aActor, aInit.mCreatedDynamically);
|
2020-04-08 00:39:12 +03:00
|
|
|
WriteIPDLParam(aMessage, aActor, aInit.mOriginAttributes);
|
2020-05-27 00:14:27 +03:00
|
|
|
WriteIPDLParam(aMessage, aActor, aInit.mRequestContextId);
|
2020-09-08 18:24:13 +03:00
|
|
|
WriteIPDLParam(aMessage, aActor, aInit.mSessionHistoryIndex);
|
|
|
|
WriteIPDLParam(aMessage, aActor, aInit.mSessionHistoryCount);
|
2020-01-20 17:57:47 +03:00
|
|
|
WriteIPDLParam(aMessage, aActor, aInit.mFields);
|
2019-03-14 21:51:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool IPDLParamTraits<dom::BrowsingContext::IPCInitializer>::Read(
|
|
|
|
const IPC::Message* aMessage, PickleIterator* aIterator, IProtocol* aActor,
|
|
|
|
dom::BrowsingContext::IPCInitializer* aInit) {
|
|
|
|
// Read actor ID parameters.
|
|
|
|
if (!ReadIPDLParam(aMessage, aIterator, aActor, &aInit->mId) ||
|
2020-01-20 17:57:47 +03:00
|
|
|
!ReadIPDLParam(aMessage, aIterator, aActor, &aInit->mParentId) ||
|
2020-02-06 22:08:06 +03:00
|
|
|
!ReadIPDLParam(aMessage, aIterator, aActor, &aInit->mWindowless) ||
|
2020-04-08 00:39:12 +03:00
|
|
|
!ReadIPDLParam(aMessage, aIterator, aActor, &aInit->mUseRemoteTabs) ||
|
|
|
|
!ReadIPDLParam(aMessage, aIterator, aActor,
|
|
|
|
&aInit->mUseRemoteSubframes) ||
|
2020-10-31 01:10:22 +03:00
|
|
|
!ReadIPDLParam(aMessage, aIterator, aActor,
|
|
|
|
&aInit->mCreatedDynamically) ||
|
2020-04-08 00:39:12 +03:00
|
|
|
!ReadIPDLParam(aMessage, aIterator, aActor, &aInit->mOriginAttributes) ||
|
2020-05-27 00:14:27 +03:00
|
|
|
!ReadIPDLParam(aMessage, aIterator, aActor, &aInit->mRequestContextId) ||
|
2020-09-08 18:24:13 +03:00
|
|
|
!ReadIPDLParam(aMessage, aIterator, aActor,
|
|
|
|
&aInit->mSessionHistoryIndex) ||
|
|
|
|
!ReadIPDLParam(aMessage, aIterator, aActor,
|
|
|
|
&aInit->mSessionHistoryCount) ||
|
2020-01-20 17:57:47 +03:00
|
|
|
!ReadIPDLParam(aMessage, aIterator, aActor, &aInit->mFields)) {
|
2019-04-29 10:01:50 +03:00
|
|
|
return false;
|
|
|
|
}
|
2019-03-14 21:51:09 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-01-20 17:57:47 +03:00
|
|
|
template struct IPDLParamTraits<dom::BrowsingContext::BaseTransaction>;
|
|
|
|
|
2019-02-14 00:02:53 +03:00
|
|
|
} // namespace ipc
|
2018-07-26 10:31:00 +03:00
|
|
|
} // namespace mozilla
|