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/. */
|
|
|
|
|
|
|
|
#include "ProcessGlobal.h"
|
|
|
|
|
|
|
|
#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"
|
|
|
|
#include "mozilla/dom/ResolveSystemBinding.h"
|
2018-06-23 06:35:49 +03:00
|
|
|
#include "mozilla/dom/ipc/SharedMap.h"
|
2015-02-20 04:13:02 +03:00
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
2018-04-26 17:54:00 +03:00
|
|
|
bool ProcessGlobal::sWasCreated = false;
|
|
|
|
|
2015-02-20 04:13:02 +03:00
|
|
|
ProcessGlobal::ProcessGlobal(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);
|
|
|
|
}
|
|
|
|
|
|
|
|
ProcessGlobal::~ProcessGlobal()
|
|
|
|
{
|
|
|
|
mAnonymousGlobalScopes.Clear();
|
|
|
|
mozilla::DropJSObjects(this);
|
|
|
|
}
|
|
|
|
|
2017-07-19 15:59:02 +03:00
|
|
|
bool
|
|
|
|
ProcessGlobal::DoResolve(JSContext* aCx, JS::Handle<JSObject*> aObj,
|
|
|
|
JS::Handle<jsid> aId,
|
|
|
|
JS::MutableHandle<JS::PropertyDescriptor> aDesc)
|
|
|
|
{
|
|
|
|
bool found;
|
|
|
|
if (!SystemGlobalResolve(aCx, aObj, aId, &found)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (found) {
|
|
|
|
FillPropertyDescriptor(aDesc, aObj, JS::UndefinedValue(), false);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
bool
|
|
|
|
ProcessGlobal::MayResolve(jsid aId)
|
|
|
|
{
|
|
|
|
return MayResolveAsSystemBindingName(aId);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ProcessGlobal::GetOwnPropertyNames(JSContext* aCx, JS::AutoIdVector& aNames,
|
|
|
|
bool aEnumerableOnly, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
JS::Rooted<JSObject*> thisObj(aCx, GetWrapper());
|
|
|
|
GetSystemBindingNames(aCx, thisObj, aNames, aEnumerableOnly, aRv);
|
|
|
|
}
|
|
|
|
|
2015-02-20 04:13:02 +03:00
|
|
|
ProcessGlobal*
|
|
|
|
ProcessGlobal::Get()
|
|
|
|
{
|
2018-02-16 12:34:21 +03:00
|
|
|
nsCOMPtr<nsIGlobalObject> service = do_GetService(NS_CHILDPROCESSMESSAGEMANAGER_CONTRACTID);
|
2015-02-20 04:13:02 +03:00
|
|
|
if (!service) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2018-04-26 17:54:00 +03:00
|
|
|
ProcessGlobal* global = static_cast<ProcessGlobal*>(service.get());
|
|
|
|
if (global) {
|
|
|
|
sWasCreated = true;
|
|
|
|
}
|
|
|
|
return global;
|
|
|
|
}
|
|
|
|
|
2018-06-23 06:35:49 +03:00
|
|
|
already_AddRefed<mozilla::dom::ipc::SharedMap>
|
|
|
|
ProcessGlobal::SharedData()
|
|
|
|
{
|
|
|
|
if (ContentChild* child = ContentChild::GetSingleton()) {
|
|
|
|
return do_AddRef(child->SharedData());
|
|
|
|
}
|
|
|
|
auto* ppmm = nsFrameMessageManager::sParentProcessManager;
|
|
|
|
return do_AddRef(ppmm->SharedData()->GetReadOnly());
|
|
|
|
}
|
|
|
|
|
2018-04-26 17:54:00 +03:00
|
|
|
bool
|
|
|
|
ProcessGlobal::WasCreated()
|
|
|
|
{
|
|
|
|
return sWasCreated;
|
2015-02-20 04:13:02 +03:00
|
|
|
}
|
|
|
|
|
2018-02-16 17:28:31 +03:00
|
|
|
void
|
2015-02-20 04:13:02 +03:00
|
|
|
ProcessGlobal::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
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(ProcessGlobal)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(ProcessGlobal)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMessageManager)
|
2015-05-07 10:05:43 +03:00
|
|
|
tmp->TraverseHostObjectURIs(cb);
|
2015-02-20 04:13:02 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(ProcessGlobal)
|
|
|
|
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
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(ProcessGlobal)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mMessageManager)
|
2017-05-15 23:05:18 +03:00
|
|
|
tmp->nsMessageManagerScriptExecutor::Unlink();
|
2015-05-07 10:05:43 +03:00
|
|
|
tmp->UnlinkHostObjectURIs();
|
2015-02-20 04:13:02 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ProcessGlobal)
|
|
|
|
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(nsIScriptObjectPrincipal)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIGlobalObject)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(ProcessGlobal)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(ProcessGlobal)
|
|
|
|
|
|
|
|
bool
|
|
|
|
ProcessGlobal::Init()
|
|
|
|
{
|
|
|
|
if (mInitialized) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
mInitialized = true;
|
|
|
|
|
2017-07-19 15:59:02 +03:00
|
|
|
return InitChildGlobalInternal(NS_LITERAL_CSTRING("processChildGlobal"));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ProcessGlobal::WrapGlobalObject(JSContext* aCx,
|
2018-05-17 11:59:45 +03:00
|
|
|
JS::RealmOptions& aOptions,
|
2017-07-19 15:59:02 +03:00
|
|
|
JS::MutableHandle<JSObject*> aReflector)
|
|
|
|
{
|
2018-06-26 00:20:54 +03:00
|
|
|
bool ok = ContentProcessMessageManager_Binding::Wrap(aCx, this, this, aOptions,
|
|
|
|
nsJSPrincipals::get(mPrincipal),
|
|
|
|
true, aReflector);
|
2017-07-19 15:59:02 +03:00
|
|
|
if (ok) {
|
|
|
|
// Since we can't rewrap we have to preserve the global's wrapper here.
|
|
|
|
PreserveWrapper(ToSupports(this));
|
|
|
|
}
|
|
|
|
return ok;
|
2015-02-20 04:13:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ProcessGlobal::LoadScript(const nsAString& aURL)
|
|
|
|
{
|
|
|
|
Init();
|
2017-07-19 15:59:02 +03:00
|
|
|
JS::Rooted<JSObject*> global(mozilla::dom::RootingCx(), GetWrapper());
|
|
|
|
LoadScriptInternal(global, aURL, false);
|
2015-02-20 04:13:02 +03:00
|
|
|
}
|
2015-05-01 04:20:51 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
ProcessGlobal::SetInitialProcessData(JS::HandleValue aInitialData)
|
|
|
|
{
|
|
|
|
mMessageManager->SetInitialProcessData(aInitialData);
|
|
|
|
}
|