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: */
|
2012-05-21 15:12:37 +04: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/. */
|
2010-05-18 16:28:37 +04:00
|
|
|
|
|
|
|
#ifndef nsInProcessTabChildGlobal_h
|
|
|
|
#define nsInProcessTabChildGlobal_h
|
|
|
|
|
2013-05-30 00:43:41 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2014-04-01 10:13:50 +04:00
|
|
|
#include "mozilla/DOMEventTargetHelper.h"
|
2010-05-18 16:28:37 +04:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsFrameMessageManager.h"
|
|
|
|
#include "nsIScriptContext.h"
|
|
|
|
#include "nsIScriptObjectPrincipal.h"
|
|
|
|
#include "nsIScriptContext.h"
|
|
|
|
#include "nsIClassInfo.h"
|
|
|
|
#include "nsIDocShell.h"
|
|
|
|
#include "nsIDOMElement.h"
|
|
|
|
#include "nsCOMArray.h"
|
2013-09-19 17:54:39 +04:00
|
|
|
#include "nsIRunnable.h"
|
2013-04-04 13:27:06 +04:00
|
|
|
#include "nsIGlobalObject.h"
|
2013-09-09 07:28:48 +04:00
|
|
|
#include "nsIScriptObjectPrincipal.h"
|
2013-04-04 13:27:40 +04:00
|
|
|
#include "nsWeakReference.h"
|
2010-05-18 16:28:37 +04:00
|
|
|
|
2014-03-18 08:48:19 +04:00
|
|
|
namespace mozilla {
|
|
|
|
class EventChainPreVisitor;
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2014-04-01 10:13:50 +04:00
|
|
|
class nsInProcessTabChildGlobal : public mozilla::DOMEventTargetHelper,
|
2015-02-20 04:10:44 +03:00
|
|
|
public nsMessageManagerScriptExecutor,
|
2010-05-18 16:28:37 +04:00
|
|
|
public nsIInProcessContentFrameMessageManager,
|
2013-04-04 13:27:06 +04:00
|
|
|
public nsIGlobalObject,
|
2013-09-09 07:28:48 +04:00
|
|
|
public nsIScriptObjectPrincipal,
|
2013-04-04 13:27:40 +04:00
|
|
|
public nsSupportsWeakReference,
|
2012-09-28 09:43:12 +04:00
|
|
|
public mozilla::dom::ipc::MessageManagerCallback
|
2010-05-18 16:28:37 +04:00
|
|
|
{
|
2015-09-10 23:50:58 +03:00
|
|
|
typedef mozilla::dom::ipc::StructuredCloneData StructuredCloneData;
|
2015-04-30 06:39:59 +03:00
|
|
|
|
2016-08-22 11:28:04 +03:00
|
|
|
using mozilla::dom::ipc::MessageManagerCallback::GetProcessMessageManager;
|
|
|
|
|
2010-05-18 16:28:37 +04:00
|
|
|
public:
|
|
|
|
nsInProcessTabChildGlobal(nsIDocShell* aShell, nsIContent* aOwner,
|
|
|
|
nsFrameMessageManager* aChrome);
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2014-06-13 21:56:38 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(nsInProcessTabChildGlobal,
|
|
|
|
mozilla::DOMEventTargetHelper)
|
|
|
|
|
2012-08-27 18:13:02 +04:00
|
|
|
NS_FORWARD_SAFE_NSIMESSAGELISTENERMANAGER(mMessageManager)
|
|
|
|
NS_FORWARD_SAFE_NSIMESSAGESENDER(mMessageManager)
|
2015-02-20 04:12:11 +03:00
|
|
|
NS_FORWARD_SAFE_NSIMESSAGEMANAGERGLOBAL(mMessageManager)
|
2011-10-01 20:14:36 +04:00
|
|
|
NS_IMETHOD SendSyncMessage(const nsAString& aMessageName,
|
2014-01-09 21:39:36 +04:00
|
|
|
JS::Handle<JS::Value> aObject,
|
|
|
|
JS::Handle<JS::Value> aRemote,
|
2013-11-06 21:21:15 +04:00
|
|
|
nsIPrincipal* aPrincipal,
|
2011-10-01 20:14:36 +04:00
|
|
|
JSContext* aCx,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t aArgc,
|
2015-03-21 19:28:04 +03:00
|
|
|
JS::MutableHandle<JS::Value> aRetval) override
|
2010-05-18 16:28:37 +04:00
|
|
|
{
|
2011-10-01 20:14:36 +04:00
|
|
|
return mMessageManager
|
2013-11-06 21:21:15 +04:00
|
|
|
? mMessageManager->SendSyncMessage(aMessageName, aObject, aRemote,
|
|
|
|
aPrincipal, aCx, aArgc, aRetval)
|
2011-10-01 20:14:36 +04:00
|
|
|
: NS_ERROR_NULL_POINTER;
|
2010-05-18 16:28:37 +04:00
|
|
|
}
|
2013-10-01 20:15:06 +04:00
|
|
|
NS_IMETHOD SendRpcMessage(const nsAString& aMessageName,
|
2014-01-09 21:39:36 +04:00
|
|
|
JS::Handle<JS::Value> aObject,
|
|
|
|
JS::Handle<JS::Value> aRemote,
|
2013-11-06 21:21:15 +04:00
|
|
|
nsIPrincipal* aPrincipal,
|
2013-10-01 20:15:06 +04:00
|
|
|
JSContext* aCx,
|
|
|
|
uint8_t aArgc,
|
2015-03-21 19:28:04 +03:00
|
|
|
JS::MutableHandle<JS::Value> aRetval) override
|
2013-10-01 20:15:06 +04:00
|
|
|
{
|
|
|
|
return mMessageManager
|
2013-11-06 21:21:15 +04:00
|
|
|
? mMessageManager->SendRpcMessage(aMessageName, aObject, aRemote,
|
|
|
|
aPrincipal, aCx, aArgc, aRetval)
|
2013-10-01 20:15:06 +04:00
|
|
|
: NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
2016-01-30 20:05:36 +03:00
|
|
|
NS_IMETHOD GetContent(mozIDOMWindowProxy** aContent) override;
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD GetDocShell(nsIDocShell** aDocShell) override;
|
2011-06-25 13:52:00 +04:00
|
|
|
|
2010-05-18 16:28:37 +04:00
|
|
|
NS_DECL_NSIINPROCESSCONTENTFRAMEMESSAGEMANAGER
|
|
|
|
|
2012-09-28 09:43:12 +04:00
|
|
|
/**
|
|
|
|
* MessageManagerCallback methods that we override.
|
|
|
|
*/
|
2013-10-01 20:15:06 +04:00
|
|
|
virtual bool DoSendBlockingMessage(JSContext* aCx,
|
|
|
|
const nsAString& aMessage,
|
2015-09-10 23:50:58 +03:00
|
|
|
StructuredCloneData& aData,
|
2013-10-01 20:15:06 +04:00
|
|
|
JS::Handle<JSObject *> aCpows,
|
2013-11-06 21:21:15 +04:00
|
|
|
nsIPrincipal* aPrincipal,
|
2015-09-10 23:50:58 +03:00
|
|
|
nsTArray<StructuredCloneData>* aRetVal,
|
2015-03-21 19:28:04 +03:00
|
|
|
bool aIsSync) override;
|
2015-10-07 13:42:43 +03:00
|
|
|
virtual nsresult DoSendAsyncMessage(JSContext* aCx,
|
|
|
|
const nsAString& aMessage,
|
|
|
|
StructuredCloneData& aData,
|
|
|
|
JS::Handle<JSObject *> aCpows,
|
|
|
|
nsIPrincipal* aPrincipal) override;
|
2012-09-28 09:43:12 +04:00
|
|
|
|
2014-03-18 08:48:19 +04:00
|
|
|
virtual nsresult PreHandleEvent(
|
2015-03-21 19:28:04 +03:00
|
|
|
mozilla::EventChainPreVisitor& aVisitor) override;
|
2010-05-18 16:28:37 +04:00
|
|
|
NS_IMETHOD AddEventListener(const nsAString& aType,
|
|
|
|
nsIDOMEventListener* aListener,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aUseCapture)
|
2010-05-18 16:28:37 +04:00
|
|
|
{
|
|
|
|
// By default add listeners only for trusted events!
|
2014-04-01 10:13:50 +04:00
|
|
|
return mozilla::DOMEventTargetHelper::AddEventListener(aType, aListener,
|
|
|
|
aUseCapture, false,
|
|
|
|
2);
|
2010-05-18 16:28:37 +04:00
|
|
|
}
|
|
|
|
NS_IMETHOD AddEventListener(const nsAString& aType,
|
|
|
|
nsIDOMEventListener* aListener,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aUseCapture, bool aWantsUntrusted,
|
2015-03-21 19:28:04 +03:00
|
|
|
uint8_t optional_argc) override
|
2010-05-18 16:28:37 +04:00
|
|
|
{
|
2014-04-01 10:13:50 +04:00
|
|
|
return mozilla::DOMEventTargetHelper::AddEventListener(aType, aListener,
|
|
|
|
aUseCapture,
|
|
|
|
aWantsUntrusted,
|
|
|
|
optional_argc);
|
2010-05-18 16:28:37 +04:00
|
|
|
}
|
2014-04-01 10:13:50 +04:00
|
|
|
using mozilla::DOMEventTargetHelper::AddEventListener;
|
2010-05-18 16:28:37 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual nsIPrincipal* GetPrincipal() override { return mPrincipal; }
|
2013-11-24 09:32:45 +04:00
|
|
|
void LoadFrameScript(const nsAString& aURL, bool aRunInGlobalScope);
|
2015-02-27 08:35:26 +03:00
|
|
|
void FireUnloadEvent();
|
|
|
|
void DisconnectEventListeners();
|
2010-05-18 16:28:37 +04:00
|
|
|
void Disconnect();
|
2011-09-29 10:19:26 +04:00
|
|
|
void SendMessageToParent(const nsString& aMessage, bool aSync,
|
2010-05-18 16:28:37 +04:00
|
|
|
const nsString& aJSON,
|
|
|
|
nsTArray<nsString>* aJSONRetVal);
|
|
|
|
nsFrameMessageManager* GetInnerManager()
|
|
|
|
{
|
|
|
|
return static_cast<nsFrameMessageManager*>(mMessageManager.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetOwner(nsIContent* aOwner) { mOwner = aOwner; }
|
|
|
|
nsFrameMessageManager* GetChromeMessageManager()
|
|
|
|
{
|
|
|
|
return mChromeMessageManager;
|
|
|
|
}
|
|
|
|
void SetChromeMessageManager(nsFrameMessageManager* aParent)
|
|
|
|
{
|
|
|
|
mChromeMessageManager = aParent;
|
|
|
|
}
|
2010-08-12 20:47:22 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual JSObject* GetGlobalJSObject() override {
|
2013-04-04 13:27:06 +04:00
|
|
|
if (!mGlobal) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2013-05-20 16:44:18 +04:00
|
|
|
return mGlobal->GetJSObject();
|
2013-04-04 13:27:06 +04:00
|
|
|
}
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual JSObject* WrapObject(JSContext* cx, JS::Handle<JSObject*> aGivenProto) override
|
2014-10-07 13:44:48 +04:00
|
|
|
{
|
|
|
|
MOZ_CRASH("nsInProcessTabChildGlobal doesn't use DOM bindings!");
|
|
|
|
}
|
2015-04-16 18:17:54 +03:00
|
|
|
|
|
|
|
already_AddRefed<nsIFrameLoader> GetFrameLoader();
|
|
|
|
|
2010-05-18 16:28:37 +04:00
|
|
|
protected:
|
2014-07-09 01:23:16 +04:00
|
|
|
virtual ~nsInProcessTabChildGlobal();
|
|
|
|
|
2010-05-18 16:28:37 +04:00
|
|
|
nsresult Init();
|
|
|
|
nsresult InitTabChildGlobal();
|
|
|
|
nsCOMPtr<nsIContentFrameMessageManager> mMessageManager;
|
|
|
|
nsCOMPtr<nsIDocShell> mDocShell;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mInitialized;
|
|
|
|
bool mLoadingScript;
|
2012-05-08 20:20:35 +04:00
|
|
|
|
2016-10-15 04:46:26 +03:00
|
|
|
// Is this the message manager for an in-process <iframe mozbrowser>? This
|
|
|
|
// affects where events get sent, so it affects PreHandleEvent.
|
|
|
|
bool mIsBrowserFrame;
|
2015-02-27 08:35:26 +03:00
|
|
|
bool mPreventEventsEscaping;
|
2015-04-16 18:17:54 +03:00
|
|
|
|
|
|
|
// We keep a strong reference to the frameloader after we've started
|
|
|
|
// teardown. This allows us to dispatch message manager messages during this
|
|
|
|
// time.
|
|
|
|
nsCOMPtr<nsIFrameLoader> mFrameLoader;
|
2010-05-18 16:28:37 +04:00
|
|
|
public:
|
|
|
|
nsIContent* mOwner;
|
|
|
|
nsFrameMessageManager* mChromeMessageManager;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|