2015-05-03 22:32:37 +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: */
|
2015-02-20 04:13:02 +03:00
|
|
|
/* 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-08-03 01:03:50 +03:00
|
|
|
#include "ContentProcessMessageManager.h"
|
2015-02-20 04:13:02 +03:00
|
|
|
|
|
|
|
#include "nsContentCID.h"
|
2018-06-23 06:35:49 +03:00
|
|
|
#include "mozilla/dom/ContentChild.h"
|
2017-07-19 15:59:02 +03:00
|
|
|
#include "mozilla/dom/MessageManagerBinding.h"
|
2018-08-03 01:03:50 +03:00
|
|
|
#include "mozilla/dom/ParentProcessMessageManager.h"
|
2018-08-11 00:03:18 +03:00
|
|
|
#include "mozilla/dom/ScriptSettings.h"
|
2018-06-23 06:35:49 +03:00
|
|
|
#include "mozilla/dom/ipc/SharedMap.h"
|
2020-11-23 19:21:38 +03:00
|
|
|
#include "mozilla/HoldDropJSObjects.h"
|
2015-02-20 04:13:02 +03:00
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
2018-08-03 01:03:50 +03:00
|
|
|
bool ContentProcessMessageManager::sWasCreated = false;
|
2018-04-26 17:54:00 +03:00
|
|
|
|
2018-08-03 01:03:50 +03:00
|
|
|
ContentProcessMessageManager::ContentProcessMessageManager(
|
|
|
|
nsFrameMessageManager* aMessageManager)
|
2017-07-19 15:59:02 +03:00
|
|
|
: MessageManagerGlobal(aMessageManager), mInitialized(false) {
|
2015-02-20 04:13:02 +03:00
|
|
|
mozilla::HoldJSObjects(this);
|
|
|
|
}
|
|
|
|
|
2018-08-03 01:03:50 +03:00
|
|
|
ContentProcessMessageManager::~ContentProcessMessageManager() {
|
2015-02-20 04:13:02 +03:00
|
|
|
mAnonymousGlobalScopes.Clear();
|
|
|
|
mozilla::DropJSObjects(this);
|
|
|
|
}
|
|
|
|
|
2018-08-03 01:03:50 +03:00
|
|
|
ContentProcessMessageManager* ContentProcessMessageManager::Get() {
|
2018-08-11 00:03:18 +03:00
|
|
|
nsCOMPtr<nsIMessageSender> service =
|
|
|
|
do_GetService(NS_CHILDPROCESSMESSAGEMANAGER_CONTRACTID);
|
2015-02-20 04:13:02 +03:00
|
|
|
if (!service) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2018-08-11 00:03:18 +03:00
|
|
|
sWasCreated = true;
|
|
|
|
return static_cast<ContentProcessMessageManager*>(service.get());
|
2018-04-26 17:54:00 +03:00
|
|
|
}
|
|
|
|
|
2018-06-23 06:35:49 +03:00
|
|
|
already_AddRefed<mozilla::dom::ipc::SharedMap>
|
2020-09-30 21:10:29 +03:00
|
|
|
ContentProcessMessageManager::GetSharedData() {
|
2018-06-23 06:35:49 +03:00
|
|
|
if (ContentChild* child = ContentChild::GetSingleton()) {
|
|
|
|
return do_AddRef(child->SharedData());
|
|
|
|
}
|
|
|
|
auto* ppmm = nsFrameMessageManager::sParentProcessManager;
|
|
|
|
return do_AddRef(ppmm->SharedData()->GetReadOnly());
|
|
|
|
}
|
|
|
|
|
2018-08-03 01:03:50 +03:00
|
|
|
bool ContentProcessMessageManager::WasCreated() { return sWasCreated; }
|
2015-02-20 04:13:02 +03:00
|
|
|
|
2018-08-03 01:03:50 +03:00
|
|
|
void ContentProcessMessageManager::MarkForCC() {
|
2015-02-25 01:23:53 +03:00
|
|
|
MarkScopesForCC();
|
2018-02-16 17:28:31 +03:00
|
|
|
MessageManagerGlobal::MarkForCC();
|
2015-02-20 04:13:02 +03:00
|
|
|
}
|
|
|
|
|
2018-08-03 01:03:50 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(ContentProcessMessageManager)
|
2015-02-20 04:13:02 +03:00
|
|
|
|
2018-08-03 01:03:50 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(ContentProcessMessageManager)
|
2015-02-20 04:13:02 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMessageManager)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
2018-08-03 01:03:50 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(ContentProcessMessageManager)
|
2015-02-20 04:13:02 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
|
2016-02-10 01:08:53 +03:00
|
|
|
tmp->nsMessageManagerScriptExecutor::Trace(aCallbacks, aClosure);
|
2015-02-20 04:13:02 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
|
|
|
|
2018-08-03 01:03:50 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(ContentProcessMessageManager)
|
2015-02-20 04:13:02 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mMessageManager)
|
2017-05-15 23:05:18 +03:00
|
|
|
tmp->nsMessageManagerScriptExecutor::Unlink();
|
2020-02-25 22:44:39 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_WEAK_REFERENCE
|
2015-02-20 04:13:02 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
2018-08-03 01:03:50 +03:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ContentProcessMessageManager)
|
2015-02-20 04:13:02 +03:00
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
2018-02-10 13:20:51 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIMessageSender)
|
2015-02-20 04:13:02 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIMessageSender)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2018-08-03 01:03:50 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(ContentProcessMessageManager)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(ContentProcessMessageManager)
|
2015-02-20 04:13:02 +03:00
|
|
|
|
2018-08-03 01:03:50 +03:00
|
|
|
bool ContentProcessMessageManager::Init() {
|
2015-02-20 04:13:02 +03:00
|
|
|
if (mInitialized) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
mInitialized = true;
|
|
|
|
|
2018-08-11 00:03:18 +03:00
|
|
|
return nsMessageManagerScriptExecutor::Init();
|
2017-07-19 15:59:02 +03:00
|
|
|
}
|
|
|
|
|
2018-08-11 00:03:18 +03:00
|
|
|
JSObject* ContentProcessMessageManager::WrapObject(
|
|
|
|
JSContext* aCx, JS::Handle<JSObject*> aGivenProto) {
|
|
|
|
return ContentProcessMessageManager_Binding::Wrap(aCx, this, aGivenProto);
|
|
|
|
}
|
|
|
|
|
|
|
|
JSObject* ContentProcessMessageManager::GetOrCreateWrapper() {
|
2018-08-29 07:26:50 +03:00
|
|
|
JS::RootedValue val(RootingCx());
|
|
|
|
{
|
|
|
|
// Scope to run ~AutoJSAPI before working with a raw JSObject*.
|
|
|
|
AutoJSAPI jsapi;
|
|
|
|
jsapi.Init();
|
|
|
|
|
|
|
|
if (!GetOrCreateDOMReflectorNoWrap(jsapi.cx(), this, &val)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2017-07-19 15:59:02 +03:00
|
|
|
}
|
2018-08-29 07:26:50 +03:00
|
|
|
MOZ_ASSERT(val.isObject());
|
2018-08-11 00:03:18 +03:00
|
|
|
return &val.toObject();
|
2015-02-20 04:13:02 +03:00
|
|
|
}
|
|
|
|
|
2018-08-03 01:03:50 +03:00
|
|
|
void ContentProcessMessageManager::LoadScript(const nsAString& aURL) {
|
2015-02-20 04:13:02 +03:00
|
|
|
Init();
|
2018-08-11 00:03:18 +03:00
|
|
|
JS::Rooted<JSObject*> messageManager(mozilla::dom::RootingCx(),
|
|
|
|
GetOrCreateWrapper());
|
|
|
|
LoadScriptInternal(messageManager, aURL, true);
|
2015-02-20 04:13:02 +03:00
|
|
|
}
|
2015-05-01 04:20:51 +03:00
|
|
|
|
2018-08-03 01:03:50 +03:00
|
|
|
void ContentProcessMessageManager::SetInitialProcessData(
|
|
|
|
JS::HandleValue aInitialData) {
|
2015-05-01 04:20:51 +03:00
|
|
|
mMessageManager->SetInitialProcessData(aInitialData);
|
|
|
|
}
|