mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 14:18:48 +00:00
139dd41f0f
- Bug 1203802 - Websocket Frame Listener API for devtool Network Inspector - part 1 - WindowID added into WebSocketChannel, r=michal (80cae04416) - Bug 1203802 - Websocket Frame Listener API for devtool Network Inspector - part 2 - WebSocketFrameService, r=michal (66e1935806) - Bug 1203802 - Websocket Frame Listener API for devtool Network Inspector - part 3 - timestamp, r=michal (1ee78cbab5) - Bug 1203802 - Websocket Frame Listener API for devtool Network Inspector - part 4 - IPC, r=michal (651d908780) - Bug 1215092 - WebSocketEventService and WebSocket discovering - part 1 - Renaming WebSocketFrameService, r=michal (c215f04303) - Bug 1215092 - WebSocketEventService and WebSocket discovering - part 2 - Unique Serial number for WebSocketChannel in IPC, r=michal (9a42b6b898) - Bug 1215092 - WebSocketEventService and WebSocket discovering - part 3 - Events, r=michal (3e22a9b8a9) - Bug 1215092 - WebSocketEventService and WebSocket discovering - part 4 - MessageAvailable event, r=michal (03606add66) - Bug 1185351 - Don't force inline style CSP checks on native anonymous content; r=ckerschb (51deea3648) - Bug 1212477 - Needs a way to access to <canvas>'s context (2d, webgl) from Anonymous Content API; r=roc;r=smaug (ed3335513d) - Bug 1119692 - Part 1: Get cached jar file fd if it exists instead of always openning it. r=smaug, r=jduell (399a3701dd) - Bug 1119692 - Part 2: Always use scheme jar:remoteopenfile: for out-of-process apps to ease sandboxing code. r=fabrice (d3783120a9) - Bug 1212244 - Same-process sendAsyncMessage can now throw instead of OOM. r=smaug (f22bbeb173) - Bug 1207752 - Increase how long we let incremental GC run before forcing it to finish. r=smaug (ef731501a0) - Bug 1213019. Get UnmapBuffer as part of MapBufferRanges features. r=jgilbert (0e1a1d7ffd) - Bug 941858 - Do not scale down elements passed to setDragImage. r=roc (7c1f18056e) - Bug 1212027 - part 1 - rename ipdl lowering helpers to reflect intent, not function; r=jld (f2c80853a7) - Bug 1212027 - part 2 - add a C++ AST type for 'auto'; r=jld (480120b163) - Bug 1212027 - part 3 - use class interfaces when cloning managees; r=jld (98d8aa9322) - Bug 1212027 - part 4 - use class interfaces when destroying managees; r=jld (2ed9d48242) - Add default initializers for primitive fields in IPDL structs. (bug 1154522, r=billm) (981f0e0d82) - Bug 1158905 - remove dead code from protocol Transition functions; r=bent (e4a43b880a) - Bug 1207921 - Call makeReply before dtorEpilogue so that we don't end up with a nullptr deref r=billm (f7d4530a72) - Bug 1212248 - Align the creation of cpow in ContentBridgeParent to ContentParent. r=khuey (ace596456a) - Bug 1212027 - part 5 - add LoneManagedOrNull for simplifying a lot of upcoming code; r=jld (6aec494580) - Bug 1212027 - part 6 - add an IsEmpty method to nsTHashtable; r=erahm (cabe26f3d6) - bug 1209615 - use TabParent::GetTopLevelDocAccessible() in OuterDocAccessible::RemoteChildDoc() r=davidb (0765f27bb5) - Bug 1214316 - Improve assertions on top level remote accessible doc handling, r=tbsaunde (257c6c8ef6) - Bug 1212027 - part 7 - modify IPDL codegen to store sub-protocols in a hashtable rather than an array; r=jld,nical,cpearce,billm (99dd4fa79c) - Bug 1212027 - followup - qualify PBrowserParent in GonkPermission.cpp; r=me (051e7e1bde) - Bug 1217250 - Fix some IPDL tests that were broken by bug 1212027; r=froydnj (d368b3aa02) - Bug 1202634 - Make sure TabParent LoadContext for pop-ups shares private browsing state of opener. r=billm (b347018487) - Bug 1191740 - Add originAttributes in TabContext. r=bholley (43ea8ca527) - Bug 1191740 - Factor out nsFrameLoader::GetNewTabContext. r=bholley (3311ab7287) - Bug 1180088 - Use origin-based permission check on parent side for signed packaged web app. r=kanru. (01659e2906) - Bug 1205399 - Backend for disabling of notifications for a site from the UI. r=nsm (6380757077) - Bug 1208295 - Dispatch notifications-open-settings upon receiving alertsettingscallback so UI can open notification settings. r=nsm (776ab25c91) - Bug 1212129 - e10s support for disabling site notifications. r=wchen (e896f87940) - Bug 1208622 - Separate API entry points. r=bz (a324f95322)
431 lines
14 KiB
C++
431 lines
14 KiB
C++
/* -*- 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/. */
|
|
|
|
#ifndef nsFrameMessageManager_h__
|
|
#define nsFrameMessageManager_h__
|
|
|
|
#include "nsIMessageManager.h"
|
|
#include "nsIObserver.h"
|
|
#include "nsCOMPtr.h"
|
|
#include "nsAutoPtr.h"
|
|
#include "nsCOMArray.h"
|
|
#include "nsTArray.h"
|
|
#include "nsIAtom.h"
|
|
#include "nsCycleCollectionParticipant.h"
|
|
#include "nsTArray.h"
|
|
#include "nsIPrincipal.h"
|
|
#include "nsIXPConnect.h"
|
|
#include "nsDataHashtable.h"
|
|
#include "nsClassHashtable.h"
|
|
#include "mozilla/Services.h"
|
|
#include "nsIObserverService.h"
|
|
#include "nsThreadUtils.h"
|
|
#include "nsWeakPtr.h"
|
|
#include "mozilla/Attributes.h"
|
|
#include "js/RootingAPI.h"
|
|
#include "nsTObserverArray.h"
|
|
#include "mozilla/dom/SameProcessMessageQueue.h"
|
|
#include "mozilla/dom/ipc/StructuredCloneData.h"
|
|
#include "mozilla/jsipc/CpowHolder.h"
|
|
|
|
class nsIFrameLoader;
|
|
|
|
namespace mozilla {
|
|
namespace dom {
|
|
|
|
class nsIContentParent;
|
|
class nsIContentChild;
|
|
class ClonedMessageData;
|
|
class MessageManagerReporter;
|
|
|
|
namespace ipc {
|
|
|
|
enum MessageManagerFlags {
|
|
MM_CHILD = 0,
|
|
MM_CHROME = 1,
|
|
MM_GLOBAL = 2,
|
|
MM_PROCESSMANAGER = 4,
|
|
MM_BROADCASTER = 8,
|
|
MM_OWNSCALLBACK = 16
|
|
};
|
|
|
|
class MessageManagerCallback
|
|
{
|
|
public:
|
|
virtual ~MessageManagerCallback() {}
|
|
|
|
virtual bool DoLoadMessageManagerScript(const nsAString& aURL, bool aRunInGlobalScope)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
virtual bool DoSendBlockingMessage(JSContext* aCx,
|
|
const nsAString& aMessage,
|
|
StructuredCloneData& aData,
|
|
JS::Handle<JSObject*> aCpows,
|
|
nsIPrincipal* aPrincipal,
|
|
nsTArray<StructuredCloneData>* aRetVal,
|
|
bool aIsSync)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
virtual nsresult DoSendAsyncMessage(JSContext* aCx,
|
|
const nsAString& aMessage,
|
|
StructuredCloneData& aData,
|
|
JS::Handle<JSObject*> aCpows,
|
|
nsIPrincipal* aPrincipal)
|
|
{
|
|
return NS_OK;
|
|
}
|
|
|
|
virtual bool CheckPermission(const nsAString& aPermission)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
virtual bool CheckManifestURL(const nsAString& aManifestURL)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
virtual bool CheckAppHasPermission(const nsAString& aPermission)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
virtual bool CheckAppHasStatus(unsigned short aStatus)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
virtual bool KillChild()
|
|
{
|
|
// By default, does nothing.
|
|
return false;
|
|
}
|
|
|
|
protected:
|
|
bool BuildClonedMessageDataForParent(nsIContentParent* aParent,
|
|
StructuredCloneData& aData,
|
|
ClonedMessageData& aClonedData);
|
|
bool BuildClonedMessageDataForChild(nsIContentChild* aChild,
|
|
StructuredCloneData& aData,
|
|
ClonedMessageData& aClonedData);
|
|
};
|
|
|
|
void UnpackClonedMessageDataForParent(const ClonedMessageData& aClonedData,
|
|
StructuredCloneData& aData);
|
|
|
|
void UnpackClonedMessageDataForChild(const ClonedMessageData& aClonedData,
|
|
StructuredCloneData& aData);
|
|
|
|
} // namespace ipc
|
|
} // namespace dom
|
|
} // namespace mozilla
|
|
|
|
struct nsMessageListenerInfo
|
|
{
|
|
bool operator==(const nsMessageListenerInfo& aOther) const
|
|
{
|
|
return &aOther == this;
|
|
}
|
|
|
|
// Exactly one of mStrongListener and mWeakListener must be non-null.
|
|
nsCOMPtr<nsIMessageListener> mStrongListener;
|
|
nsWeakPtr mWeakListener;
|
|
bool mListenWhenClosed;
|
|
};
|
|
|
|
|
|
class MOZ_STACK_CLASS SameProcessCpowHolder : public mozilla::jsipc::CpowHolder
|
|
{
|
|
public:
|
|
SameProcessCpowHolder(JSRuntime *aRuntime, JS::Handle<JSObject*> aObj)
|
|
: mObj(aRuntime, aObj)
|
|
{
|
|
}
|
|
|
|
virtual bool ToObject(JSContext* aCx, JS::MutableHandle<JSObject*> aObjp)
|
|
override;
|
|
|
|
private:
|
|
JS::Rooted<JSObject*> mObj;
|
|
};
|
|
|
|
class nsFrameMessageManager final : public nsIContentFrameMessageManager,
|
|
public nsIMessageBroadcaster,
|
|
public nsIFrameScriptLoader,
|
|
public nsIGlobalProcessScriptLoader,
|
|
public nsIProcessChecker
|
|
{
|
|
friend class mozilla::dom::MessageManagerReporter;
|
|
typedef mozilla::dom::ipc::StructuredCloneData StructuredCloneData;
|
|
public:
|
|
nsFrameMessageManager(mozilla::dom::ipc::MessageManagerCallback* aCallback,
|
|
nsFrameMessageManager* aParentManager,
|
|
/* mozilla::dom::ipc::MessageManagerFlags */ uint32_t aFlags);
|
|
|
|
private:
|
|
~nsFrameMessageManager();
|
|
|
|
public:
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsFrameMessageManager,
|
|
nsIContentFrameMessageManager)
|
|
NS_DECL_NSIMESSAGELISTENERMANAGER
|
|
NS_DECL_NSIMESSAGESENDER
|
|
NS_DECL_NSIMESSAGEBROADCASTER
|
|
NS_DECL_NSISYNCMESSAGESENDER
|
|
NS_DECL_NSIMESSAGEMANAGERGLOBAL
|
|
NS_DECL_NSICONTENTFRAMEMESSAGEMANAGER
|
|
NS_DECL_NSIFRAMESCRIPTLOADER
|
|
NS_DECL_NSIPROCESSSCRIPTLOADER
|
|
NS_DECL_NSIGLOBALPROCESSSCRIPTLOADER
|
|
NS_DECL_NSIPROCESSCHECKER
|
|
|
|
static nsFrameMessageManager*
|
|
NewProcessMessageManager(bool aIsRemote);
|
|
|
|
nsresult ReceiveMessage(nsISupports* aTarget, nsIFrameLoader* aTargetFrameLoader,
|
|
const nsAString& aMessage,
|
|
bool aIsSync, StructuredCloneData* aCloneData,
|
|
mozilla::jsipc::CpowHolder* aCpows, nsIPrincipal* aPrincipal,
|
|
nsTArray<StructuredCloneData>* aRetVal);
|
|
|
|
void AddChildManager(nsFrameMessageManager* aManager);
|
|
void RemoveChildManager(nsFrameMessageManager* aManager)
|
|
{
|
|
mChildManagers.RemoveObject(aManager);
|
|
}
|
|
void Disconnect(bool aRemoveFromParent = true);
|
|
void Close();
|
|
|
|
void InitWithCallback(mozilla::dom::ipc::MessageManagerCallback* aCallback);
|
|
void SetCallback(mozilla::dom::ipc::MessageManagerCallback* aCallback);
|
|
mozilla::dom::ipc::MessageManagerCallback* GetCallback()
|
|
{
|
|
return mCallback;
|
|
}
|
|
|
|
nsresult DispatchAsyncMessage(const nsAString& aMessageName,
|
|
const JS::Value& aJSON,
|
|
const JS::Value& aObjects,
|
|
nsIPrincipal* aPrincipal,
|
|
JSContext* aCx,
|
|
uint8_t aArgc);
|
|
nsresult DispatchAsyncMessageInternal(JSContext* aCx,
|
|
const nsAString& aMessage,
|
|
StructuredCloneData& aData,
|
|
JS::Handle<JSObject*> aCpows,
|
|
nsIPrincipal* aPrincipal);
|
|
void RemoveFromParent();
|
|
nsFrameMessageManager* GetParentManager() { return mParentManager; }
|
|
void SetParentManager(nsFrameMessageManager* aParent)
|
|
{
|
|
NS_ASSERTION(!mParentManager, "We have parent manager already!");
|
|
NS_ASSERTION(mChrome, "Should not set parent manager!");
|
|
mParentManager = aParent;
|
|
}
|
|
bool IsGlobal() { return mGlobal; }
|
|
bool IsBroadcaster() { return mIsBroadcaster; }
|
|
|
|
static nsFrameMessageManager* GetParentProcessManager()
|
|
{
|
|
return sParentProcessManager;
|
|
}
|
|
static nsFrameMessageManager* GetChildProcessManager()
|
|
{
|
|
return sChildProcessManager;
|
|
}
|
|
static void SetChildProcessManager(nsFrameMessageManager* aManager)
|
|
{
|
|
sChildProcessManager = aManager;
|
|
}
|
|
|
|
void SetInitialProcessData(JS::HandleValue aInitialData);
|
|
|
|
void LoadPendingScripts();
|
|
|
|
private:
|
|
nsresult SendMessage(const nsAString& aMessageName,
|
|
JS::Handle<JS::Value> aJSON,
|
|
JS::Handle<JS::Value> aObjects,
|
|
nsIPrincipal* aPrincipal,
|
|
JSContext* aCx,
|
|
uint8_t aArgc,
|
|
JS::MutableHandle<JS::Value> aRetval,
|
|
bool aIsSync);
|
|
|
|
nsresult ReceiveMessage(nsISupports* aTarget, nsIFrameLoader* aTargetFrameLoader,
|
|
bool aTargetClosed, const nsAString& aMessage,
|
|
bool aIsSync, StructuredCloneData* aCloneData,
|
|
mozilla::jsipc::CpowHolder* aCpows, nsIPrincipal* aPrincipal,
|
|
nsTArray<StructuredCloneData>* aRetVal);
|
|
|
|
NS_IMETHOD LoadScript(const nsAString& aURL,
|
|
bool aAllowDelayedLoad,
|
|
bool aRunInGlobalScope);
|
|
NS_IMETHOD RemoveDelayedScript(const nsAString& aURL);
|
|
NS_IMETHOD GetDelayedScripts(JSContext* aCx, JS::MutableHandle<JS::Value> aList);
|
|
|
|
protected:
|
|
friend class MMListenerRemover;
|
|
// We keep the message listeners as arrays in a hastable indexed by the
|
|
// message name. That gives us fast lookups in ReceiveMessage().
|
|
nsClassHashtable<nsStringHashKey,
|
|
nsAutoTObserverArray<nsMessageListenerInfo, 1>> mListeners;
|
|
nsCOMArray<nsIContentFrameMessageManager> mChildManagers;
|
|
bool mChrome; // true if we're in the chrome process
|
|
bool mGlobal; // true if we're the global frame message manager
|
|
bool mIsProcessManager; // true if the message manager belongs to the process realm
|
|
bool mIsBroadcaster; // true if the message manager is a broadcaster
|
|
bool mOwnsCallback;
|
|
bool mHandlingMessage;
|
|
bool mClosed; // true if we can no longer send messages
|
|
bool mDisconnected;
|
|
mozilla::dom::ipc::MessageManagerCallback* mCallback;
|
|
nsAutoPtr<mozilla::dom::ipc::MessageManagerCallback> mOwnedCallback;
|
|
RefPtr<nsFrameMessageManager> mParentManager;
|
|
nsTArray<nsString> mPendingScripts;
|
|
nsTArray<bool> mPendingScriptsGlobalStates;
|
|
JS::Heap<JS::Value> mInitialProcessData;
|
|
|
|
void LoadPendingScripts(nsFrameMessageManager* aManager,
|
|
nsFrameMessageManager* aChildMM);
|
|
public:
|
|
static nsFrameMessageManager* sParentProcessManager;
|
|
static nsFrameMessageManager* sSameProcessParentManager;
|
|
static nsTArray<nsCOMPtr<nsIRunnable> >* sPendingSameProcessAsyncMessages;
|
|
private:
|
|
static nsFrameMessageManager* sChildProcessManager;
|
|
enum ProcessCheckerType {
|
|
PROCESS_CHECKER_PERMISSION,
|
|
PROCESS_CHECKER_MANIFEST_URL,
|
|
ASSERT_APP_HAS_PERMISSION
|
|
};
|
|
nsresult AssertProcessInternal(ProcessCheckerType aType,
|
|
const nsAString& aCapability,
|
|
bool* aValid);
|
|
};
|
|
|
|
/* A helper class for taking care of many details for async message sending
|
|
within a single process. Intended to be used like so:
|
|
|
|
class MyAsyncMessage : public nsSameProcessAsyncMessageBase, public nsRunnable
|
|
{
|
|
NS_IMETHOD Run() {
|
|
ReceiveMessage(..., ...);
|
|
return NS_OK;
|
|
}
|
|
};
|
|
|
|
|
|
RefPtr<nsSameProcessAsyncMessageBase> ev = new MyAsyncMessage();
|
|
nsresult rv = ev->Init(...);
|
|
if (NS_SUCCEEDED(rv)) {
|
|
NS_DispatchToMainThread(ev);
|
|
}
|
|
*/
|
|
class nsSameProcessAsyncMessageBase
|
|
{
|
|
public:
|
|
typedef mozilla::dom::ipc::StructuredCloneData StructuredCloneData;
|
|
|
|
nsSameProcessAsyncMessageBase(JSContext* aCx, JS::Handle<JSObject*> aCpows);
|
|
nsresult Init(JSContext* aCx,
|
|
const nsAString& aMessage,
|
|
StructuredCloneData& aData,
|
|
nsIPrincipal* aPrincipal);
|
|
|
|
void ReceiveMessage(nsISupports* aTarget, nsIFrameLoader* aTargetFrameLoader,
|
|
nsFrameMessageManager* aManager);
|
|
private:
|
|
nsSameProcessAsyncMessageBase(const nsSameProcessAsyncMessageBase&);
|
|
|
|
JSRuntime* mRuntime;
|
|
nsString mMessage;
|
|
StructuredCloneData mData;
|
|
JS::PersistentRooted<JSObject*> mCpows;
|
|
nsCOMPtr<nsIPrincipal> mPrincipal;
|
|
};
|
|
|
|
class nsScriptCacheCleaner;
|
|
|
|
struct nsMessageManagerScriptHolder
|
|
{
|
|
nsMessageManagerScriptHolder(JSContext* aCx,
|
|
JSScript* aScript,
|
|
bool aRunInGlobalScope)
|
|
: mScript(aCx, aScript), mRunInGlobalScope(aRunInGlobalScope)
|
|
{ MOZ_COUNT_CTOR(nsMessageManagerScriptHolder); }
|
|
|
|
~nsMessageManagerScriptHolder()
|
|
{ MOZ_COUNT_DTOR(nsMessageManagerScriptHolder); }
|
|
|
|
bool WillRunInGlobalScope() { return mRunInGlobalScope; }
|
|
|
|
JS::PersistentRooted<JSScript*> mScript;
|
|
bool mRunInGlobalScope;
|
|
};
|
|
|
|
class nsMessageManagerScriptExecutor
|
|
{
|
|
public:
|
|
static void Shutdown();
|
|
already_AddRefed<nsIXPConnectJSObjectHolder> GetGlobal()
|
|
{
|
|
nsCOMPtr<nsIXPConnectJSObjectHolder> ref = mGlobal;
|
|
return ref.forget();
|
|
}
|
|
|
|
void MarkScopesForCC();
|
|
protected:
|
|
friend class nsMessageManagerScriptCx;
|
|
nsMessageManagerScriptExecutor() { MOZ_COUNT_CTOR(nsMessageManagerScriptExecutor); }
|
|
~nsMessageManagerScriptExecutor() { MOZ_COUNT_DTOR(nsMessageManagerScriptExecutor); }
|
|
|
|
void DidCreateGlobal();
|
|
void LoadScriptInternal(const nsAString& aURL, bool aRunInGlobalScope);
|
|
void TryCacheLoadAndCompileScript(const nsAString& aURL,
|
|
bool aRunInGlobalScope,
|
|
bool aShouldCache,
|
|
JS::MutableHandle<JSScript*> aScriptp);
|
|
void TryCacheLoadAndCompileScript(const nsAString& aURL,
|
|
bool aRunInGlobalScope);
|
|
bool InitChildGlobalInternal(nsISupports* aScope, const nsACString& aID);
|
|
nsCOMPtr<nsIXPConnectJSObjectHolder> mGlobal;
|
|
nsCOMPtr<nsIPrincipal> mPrincipal;
|
|
nsAutoTArray<JS::Heap<JSObject*>, 2> mAnonymousGlobalScopes;
|
|
|
|
static nsDataHashtable<nsStringHashKey, nsMessageManagerScriptHolder*>* sCachedScripts;
|
|
static nsScriptCacheCleaner* sScriptCacheCleaner;
|
|
};
|
|
|
|
class nsScriptCacheCleaner final : public nsIObserver
|
|
{
|
|
~nsScriptCacheCleaner() {}
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
nsScriptCacheCleaner()
|
|
{
|
|
nsCOMPtr<nsIObserverService> obsSvc = mozilla::services::GetObserverService();
|
|
if (obsSvc)
|
|
obsSvc->AddObserver(this, "xpcom-shutdown", false);
|
|
}
|
|
|
|
NS_IMETHODIMP Observe(nsISupports *aSubject,
|
|
const char *aTopic,
|
|
const char16_t *aData) override
|
|
{
|
|
nsMessageManagerScriptExecutor::Shutdown();
|
|
return NS_OK;
|
|
}
|
|
};
|
|
|
|
#endif
|