2018-09-14 17:57:18 +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/. */
|
|
|
|
|
2019-01-29 20:32:28 +03:00
|
|
|
#include "mozilla/dom/CanonicalBrowsingContext.h"
|
2019-01-30 19:07:21 +03:00
|
|
|
|
|
|
|
#include "mozilla/dom/BrowsingContextGroup.h"
|
2018-10-20 01:00:59 +03:00
|
|
|
#include "mozilla/dom/WindowGlobalParent.h"
|
2019-03-14 21:50:50 +03:00
|
|
|
#include "mozilla/dom/ContentProcessManager.h"
|
2018-09-14 17:57:18 +03:00
|
|
|
|
2019-03-20 06:15:36 +03:00
|
|
|
extern mozilla::LazyLogModule gAutoplayPermissionLog;
|
|
|
|
|
|
|
|
#define AUTOPLAY_LOG(msg, ...) \
|
|
|
|
MOZ_LOG(gAutoplayPermissionLog, LogLevel::Debug, (msg, ##__VA_ARGS__))
|
|
|
|
|
2018-09-14 17:57:18 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2019-01-14 19:08:06 +03:00
|
|
|
extern mozilla::LazyLogModule gUserInteractionPRLog;
|
|
|
|
|
|
|
|
#define USER_ACTIVATION_LOG(msg, ...) \
|
|
|
|
MOZ_LOG(gUserInteractionPRLog, LogLevel::Debug, (msg, ##__VA_ARGS__))
|
|
|
|
|
2019-01-29 20:32:28 +03:00
|
|
|
CanonicalBrowsingContext::CanonicalBrowsingContext(BrowsingContext* aParent,
|
2019-03-14 21:51:09 +03:00
|
|
|
BrowsingContextGroup* aGroup,
|
2019-01-29 20:32:28 +03:00
|
|
|
uint64_t aBrowsingContextId,
|
|
|
|
uint64_t aProcessId,
|
|
|
|
BrowsingContext::Type aType)
|
2019-03-14 21:51:09 +03:00
|
|
|
: BrowsingContext(aParent, aGroup, aBrowsingContextId, aType),
|
2018-09-14 17:57:18 +03:00
|
|
|
mProcessId(aProcessId) {
|
2019-01-29 20:32:28 +03:00
|
|
|
// You are only ever allowed to create CanonicalBrowsingContexts in the
|
2018-09-14 17:57:18 +03:00
|
|
|
// parent process.
|
|
|
|
MOZ_RELEASE_ASSERT(XRE_IsParentProcess());
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:04:59 +03:00
|
|
|
/* static */
|
|
|
|
already_AddRefed<CanonicalBrowsingContext> CanonicalBrowsingContext::Get(
|
|
|
|
uint64_t aId) {
|
2018-09-14 17:57:18 +03:00
|
|
|
MOZ_RELEASE_ASSERT(XRE_IsParentProcess());
|
2019-01-29 20:32:28 +03:00
|
|
|
return BrowsingContext::Get(aId).downcast<CanonicalBrowsingContext>();
|
2018-09-14 17:57:18 +03:00
|
|
|
}
|
|
|
|
|
2019-02-26 01:04:59 +03:00
|
|
|
/* static */
|
|
|
|
CanonicalBrowsingContext* CanonicalBrowsingContext::Cast(
|
2018-09-14 17:57:18 +03:00
|
|
|
BrowsingContext* aContext) {
|
|
|
|
MOZ_RELEASE_ASSERT(XRE_IsParentProcess());
|
2019-01-29 20:32:28 +03:00
|
|
|
return static_cast<CanonicalBrowsingContext*>(aContext);
|
2018-09-14 17:57:18 +03:00
|
|
|
}
|
|
|
|
|
2019-03-14 21:50:50 +03:00
|
|
|
/* static */
|
|
|
|
const CanonicalBrowsingContext* CanonicalBrowsingContext::Cast(
|
2018-11-05 15:43:10 +03:00
|
|
|
const BrowsingContext* aContext) {
|
|
|
|
MOZ_RELEASE_ASSERT(XRE_IsParentProcess());
|
2019-01-29 20:32:28 +03:00
|
|
|
return static_cast<const CanonicalBrowsingContext*>(aContext);
|
2018-09-14 17:57:18 +03:00
|
|
|
}
|
|
|
|
|
2019-03-14 21:50:50 +03:00
|
|
|
ContentParent* CanonicalBrowsingContext::GetContentParent() const {
|
|
|
|
if (mProcessId == 0) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
ContentProcessManager* cpm = ContentProcessManager::GetSingleton();
|
|
|
|
return cpm->GetContentProcessById(ContentParentId(mProcessId));
|
|
|
|
}
|
|
|
|
|
2019-04-08 19:29:08 +03:00
|
|
|
void CanonicalBrowsingContext::GetCurrentRemoteType(nsAString& aRemoteType,
|
|
|
|
ErrorResult& aRv) const {
|
|
|
|
// If we're in the parent process, dump out the void string.
|
|
|
|
if (mProcessId == 0) {
|
|
|
|
aRemoteType.Assign(VoidString());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ContentParent* cp = GetContentParent();
|
|
|
|
if (!cp) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
aRemoteType.Assign(cp->GetRemoteType());
|
|
|
|
}
|
|
|
|
|
2019-06-21 19:34:30 +03:00
|
|
|
void CanonicalBrowsingContext::SetOwnerProcessId(uint64_t aProcessId) {
|
|
|
|
MOZ_LOG(GetLog(), LogLevel::Debug,
|
|
|
|
("SetOwnerProcessId for 0x%08" PRIx64 " (0x%08" PRIx64
|
|
|
|
" -> 0x%08" PRIx64 ")",
|
|
|
|
Id(), mProcessId, aProcessId));
|
|
|
|
|
|
|
|
mProcessId = aProcessId;
|
|
|
|
}
|
|
|
|
|
2019-01-29 20:32:28 +03:00
|
|
|
void CanonicalBrowsingContext::GetWindowGlobals(
|
2018-10-20 02:02:56 +03:00
|
|
|
nsTArray<RefPtr<WindowGlobalParent>>& aWindows) {
|
|
|
|
aWindows.SetCapacity(mWindowGlobals.Count());
|
|
|
|
for (auto iter = mWindowGlobals.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
aWindows.AppendElement(iter.Get()->GetKey());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-29 20:32:28 +03:00
|
|
|
void CanonicalBrowsingContext::RegisterWindowGlobal(
|
|
|
|
WindowGlobalParent* aGlobal) {
|
2018-10-20 01:00:59 +03:00
|
|
|
MOZ_ASSERT(!mWindowGlobals.Contains(aGlobal), "Global already registered!");
|
|
|
|
mWindowGlobals.PutEntry(aGlobal);
|
|
|
|
}
|
|
|
|
|
2019-01-29 20:32:28 +03:00
|
|
|
void CanonicalBrowsingContext::UnregisterWindowGlobal(
|
2018-10-20 01:00:59 +03:00
|
|
|
WindowGlobalParent* aGlobal) {
|
|
|
|
MOZ_ASSERT(mWindowGlobals.Contains(aGlobal), "Global not registered!");
|
|
|
|
mWindowGlobals.RemoveEntry(aGlobal);
|
2018-11-27 23:03:05 +03:00
|
|
|
|
|
|
|
// Our current window global should be in our mWindowGlobals set. If it's not
|
|
|
|
// anymore, clear that reference.
|
|
|
|
if (aGlobal == mCurrentWindowGlobal) {
|
|
|
|
mCurrentWindowGlobal = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-29 20:32:28 +03:00
|
|
|
void CanonicalBrowsingContext::SetCurrentWindowGlobal(
|
2018-11-27 23:03:05 +03:00
|
|
|
WindowGlobalParent* aGlobal) {
|
|
|
|
MOZ_ASSERT(mWindowGlobals.Contains(aGlobal), "Global not registered!");
|
|
|
|
|
|
|
|
// TODO: This should probably assert that the processes match.
|
|
|
|
mCurrentWindowGlobal = aGlobal;
|
2018-10-20 01:00:59 +03:00
|
|
|
}
|
|
|
|
|
2019-04-17 03:51:36 +03:00
|
|
|
void CanonicalBrowsingContext::SetEmbedderWindowGlobal(
|
|
|
|
WindowGlobalParent* aGlobal) {
|
|
|
|
MOZ_RELEASE_ASSERT(aGlobal, "null embedder");
|
|
|
|
if (RefPtr<BrowsingContext> parent = GetParent()) {
|
|
|
|
MOZ_RELEASE_ASSERT(aGlobal->BrowsingContext() == parent,
|
|
|
|
"Embedder has incorrect browsing context");
|
|
|
|
}
|
|
|
|
|
|
|
|
mEmbedderWindowGlobal = aGlobal;
|
|
|
|
}
|
|
|
|
|
2019-03-14 21:51:03 +03:00
|
|
|
bool CanonicalBrowsingContext::ValidateTransaction(
|
|
|
|
const Transaction& aTransaction, ContentParent* aProcess) {
|
2019-06-21 19:34:30 +03:00
|
|
|
if (MOZ_LOG_TEST(GetLog(), LogLevel::Debug)) {
|
|
|
|
#define MOZ_BC_FIELD(name, ...) \
|
|
|
|
if (aTransaction.m##name.isSome()) { \
|
|
|
|
MOZ_LOG(GetLog(), LogLevel::Debug, \
|
|
|
|
("Validate Transaction 0x%08" PRIx64 " set " #name \
|
|
|
|
" (from: 0x%08" PRIx64 " owner: 0x%08" PRIx64 ")", \
|
|
|
|
Id(), aProcess ? static_cast<uint64_t>(aProcess->ChildID()) : 0, \
|
|
|
|
mProcessId)); \
|
|
|
|
}
|
|
|
|
#include "mozilla/dom/BrowsingContextFieldList.h"
|
|
|
|
}
|
|
|
|
|
2019-03-27 16:46:01 +03:00
|
|
|
// Check that the correct process is performing sets for transactions with
|
|
|
|
// non-racy fields.
|
|
|
|
if (aTransaction.HasNonRacyField()) {
|
|
|
|
if (NS_WARN_IF(aProcess && mProcessId != aProcess->ChildID())) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-03-14 21:51:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-01-29 20:32:28 +03:00
|
|
|
JSObject* CanonicalBrowsingContext::WrapObject(
|
|
|
|
JSContext* aCx, JS::Handle<JSObject*> aGivenProto) {
|
|
|
|
return CanonicalBrowsingContext_Binding::Wrap(aCx, this, aGivenProto);
|
2018-10-20 02:02:56 +03:00
|
|
|
}
|
|
|
|
|
2019-01-29 20:32:28 +03:00
|
|
|
void CanonicalBrowsingContext::Traverse(
|
|
|
|
nsCycleCollectionTraversalCallback& cb) {
|
|
|
|
CanonicalBrowsingContext* tmp = this;
|
2019-04-17 03:51:36 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mWindowGlobals, mCurrentWindowGlobal,
|
|
|
|
mEmbedderWindowGlobal);
|
2018-10-20 01:00:59 +03:00
|
|
|
}
|
|
|
|
|
2019-01-29 20:32:28 +03:00
|
|
|
void CanonicalBrowsingContext::Unlink() {
|
|
|
|
CanonicalBrowsingContext* tmp = this;
|
2019-04-17 03:51:36 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mWindowGlobals, mCurrentWindowGlobal,
|
|
|
|
mEmbedderWindowGlobal);
|
2018-10-20 01:00:59 +03:00
|
|
|
}
|
|
|
|
|
2019-03-20 06:15:36 +03:00
|
|
|
void CanonicalBrowsingContext::NotifyStartDelayedAutoplayMedia() {
|
|
|
|
if (!mCurrentWindowGlobal) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// As this function would only be called when user click the play icon on the
|
|
|
|
// tab bar. That's clear user intent to play, so gesture activate the browsing
|
|
|
|
// context so that the block-autoplay logic allows the media to autoplay.
|
|
|
|
NotifyUserGestureActivation();
|
|
|
|
AUTOPLAY_LOG("NotifyStartDelayedAutoplayMedia for chrome bc 0x%08" PRIx64,
|
|
|
|
Id());
|
|
|
|
StartDelayedAutoplayMediaComponents();
|
|
|
|
// Notfiy all content browsing contexts which are related with the canonical
|
|
|
|
// browsing content tree to start delayed autoplay media.
|
2019-04-30 11:45:41 +03:00
|
|
|
|
|
|
|
Group()->EachParent([&](ContentParent* aParent) {
|
|
|
|
Unused << aParent->SendStartDelayedAutoplayMediaComponents(this);
|
|
|
|
});
|
2019-03-20 06:15:36 +03:00
|
|
|
}
|
|
|
|
|
2019-05-22 15:19:49 +03:00
|
|
|
void CanonicalBrowsingContext::NotifyMediaMutedChanged(bool aMuted) {
|
|
|
|
nsPIDOMWindowOuter* window = GetDOMWindow();
|
|
|
|
if (window) {
|
|
|
|
window->SetAudioMuted(aMuted);
|
|
|
|
}
|
|
|
|
Group()->EachParent([&](ContentParent* aParent) {
|
|
|
|
Unused << aParent->SendSetMediaMuted(this, aMuted);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-03-27 12:19:29 +03:00
|
|
|
void CanonicalBrowsingContext::SetFieldEpochsForChild(
|
|
|
|
ContentParent* aChild, const BrowsingContext::FieldEpochs& aEpochs) {
|
|
|
|
mChildFieldEpochs.Put(aChild->ChildID(), aEpochs);
|
|
|
|
}
|
|
|
|
|
|
|
|
const BrowsingContext::FieldEpochs&
|
|
|
|
CanonicalBrowsingContext::GetFieldEpochsForChild(ContentParent* aChild) {
|
|
|
|
static const BrowsingContext::FieldEpochs sDefaultFieldEpochs;
|
|
|
|
|
|
|
|
if (auto entry = mChildFieldEpochs.Lookup(aChild->ChildID())) {
|
|
|
|
return entry.Data();
|
|
|
|
}
|
|
|
|
return sDefaultFieldEpochs;
|
|
|
|
}
|
|
|
|
|
2018-09-14 17:57:18 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|