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
|
|
|
#ifndef mozilla_dom_ContentProcessMessageManager_h
|
|
|
|
#define mozilla_dom_ContentProcessMessageManager_h
|
2015-02-20 04:13:02 +03:00
|
|
|
|
|
|
|
#include "mozilla/Attributes.h"
|
2017-07-19 15:59:02 +03:00
|
|
|
#include "mozilla/dom/MessageManagerGlobal.h"
|
2015-02-20 04:13:02 +03:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsFrameMessageManager.h"
|
|
|
|
#include "nsIScriptContext.h"
|
|
|
|
#include "nsIScriptContext.h"
|
|
|
|
#include "nsIClassInfo.h"
|
|
|
|
#include "nsIRunnable.h"
|
2015-09-29 07:31:56 +03:00
|
|
|
#include "nsServiceManagerUtils.h"
|
2015-02-20 04:13:02 +03:00
|
|
|
#include "nsWeakReference.h"
|
2015-09-29 07:31:56 +03:00
|
|
|
#include "nsWrapperCache.h"
|
2018-08-11 00:03:18 +03:00
|
|
|
#include "xpcpublic.h"
|
2015-02-20 04:13:02 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2018-06-23 06:35:49 +03:00
|
|
|
namespace ipc {
|
|
|
|
class SharedMap;
|
|
|
|
}
|
|
|
|
|
2018-08-03 01:03:50 +03:00
|
|
|
/**
|
|
|
|
* This class implements a singleton process message manager for content
|
|
|
|
* processes. Each child process has exactly one instance of this class, which
|
|
|
|
* hosts the process's process scripts, and may exchange messages with its
|
|
|
|
* corresponding ParentProcessMessageManager on the parent side.
|
|
|
|
*/
|
|
|
|
|
|
|
|
class ContentProcessMessageManager :
|
2018-02-10 13:20:51 +03:00
|
|
|
public nsIMessageSender,
|
2017-07-19 15:59:02 +03:00
|
|
|
public nsMessageManagerScriptExecutor,
|
2015-02-20 04:13:02 +03:00
|
|
|
public nsSupportsWeakReference,
|
2017-07-19 15:59:02 +03:00
|
|
|
public ipc::MessageManagerCallback,
|
|
|
|
public MessageManagerGlobal,
|
2015-02-20 04:13:02 +03:00
|
|
|
public nsWrapperCache
|
|
|
|
{
|
|
|
|
public:
|
2018-08-03 01:03:50 +03:00
|
|
|
explicit ContentProcessMessageManager(nsFrameMessageManager* aMessageManager);
|
2015-02-20 04:13:02 +03:00
|
|
|
|
2017-07-19 15:59:02 +03:00
|
|
|
using ipc::MessageManagerCallback::GetProcessMessageManager;
|
2018-02-16 12:34:21 +03:00
|
|
|
using MessageManagerGlobal::GetProcessMessageManager;
|
2016-08-22 11:28:04 +03:00
|
|
|
|
2015-02-20 04:13:02 +03:00
|
|
|
bool Init();
|
|
|
|
|
2018-08-03 01:03:50 +03:00
|
|
|
static ContentProcessMessageManager* Get();
|
2018-04-26 17:54:00 +03:00
|
|
|
static bool WasCreated();
|
2015-02-20 04:13:02 +03:00
|
|
|
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
2018-08-03 01:03:50 +03:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(ContentProcessMessageManager, nsIMessageSender)
|
2015-02-20 04:13:02 +03:00
|
|
|
|
2018-02-16 17:28:31 +03:00
|
|
|
void MarkForCC();
|
|
|
|
|
2017-07-19 15:59:02 +03:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx,
|
2018-08-11 00:03:18 +03:00
|
|
|
JS::Handle<JSObject*> aGivenProto) override;
|
|
|
|
|
|
|
|
JSObject* GetOrCreateWrapper();
|
2017-07-19 15:59:02 +03:00
|
|
|
|
|
|
|
using MessageManagerGlobal::AddMessageListener;
|
|
|
|
using MessageManagerGlobal::RemoveMessageListener;
|
|
|
|
using MessageManagerGlobal::AddWeakMessageListener;
|
|
|
|
using MessageManagerGlobal::RemoveWeakMessageListener;
|
|
|
|
|
|
|
|
// ContentProcessMessageManager
|
|
|
|
void GetInitialProcessData(JSContext* aCx,
|
|
|
|
JS::MutableHandle<JS::Value> aInitialProcessData,
|
|
|
|
ErrorResult& aError)
|
|
|
|
{
|
|
|
|
if (!mMessageManager) {
|
|
|
|
aError.Throw(NS_ERROR_NULL_POINTER);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mMessageManager->GetInitialProcessData(aCx, aInitialProcessData, aError);
|
|
|
|
}
|
|
|
|
|
2018-06-23 06:35:49 +03:00
|
|
|
already_AddRefed<ipc::SharedMap> SharedData();
|
|
|
|
|
2015-02-20 04:13:02 +03:00
|
|
|
NS_FORWARD_SAFE_NSIMESSAGESENDER(mMessageManager)
|
|
|
|
|
2018-08-11 00:03:18 +03:00
|
|
|
nsIGlobalObject* GetParentObject() const { return xpc::NativeGlobal(xpc::PrivilegedJunkScope()); }
|
2015-02-20 04:13:02 +03:00
|
|
|
|
2018-08-11 00:03:18 +03:00
|
|
|
virtual void LoadScript(const nsAString& aURL);
|
2015-02-20 04:13:02 +03:00
|
|
|
|
2018-06-30 04:07:46 +03:00
|
|
|
bool IsProcessScoped() const override
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-05-01 04:20:51 +03:00
|
|
|
void SetInitialProcessData(JS::HandleValue aInitialData);
|
|
|
|
|
2015-02-20 04:13:02 +03:00
|
|
|
protected:
|
2018-08-03 01:03:50 +03:00
|
|
|
virtual ~ContentProcessMessageManager();
|
2015-02-20 04:13:02 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool mInitialized;
|
2018-04-26 17:54:00 +03:00
|
|
|
|
|
|
|
static bool sWasCreated;
|
2015-02-20 04:13:02 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2018-08-03 01:03:50 +03:00
|
|
|
#endif // mozilla_dom_ContentProcessMessageManager_h
|