michael@0: /* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 8; -*- */ michael@0: /* vim: set sw=4 ts=8 et tw=80 : */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsInProcessTabChildGlobal_h michael@0: #define nsInProcessTabChildGlobal_h michael@0: michael@0: #include "mozilla/Attributes.h" michael@0: #include "mozilla/DOMEventTargetHelper.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsFrameMessageManager.h" michael@0: #include "nsIScriptContext.h" michael@0: #include "nsIScriptObjectPrincipal.h" michael@0: #include "nsIScriptContext.h" michael@0: #include "nsIClassInfo.h" michael@0: #include "nsIDocShell.h" michael@0: #include "nsIDOMElement.h" michael@0: #include "nsCOMArray.h" michael@0: #include "nsIRunnable.h" michael@0: #include "nsIGlobalObject.h" michael@0: #include "nsIScriptObjectPrincipal.h" michael@0: #include "nsWeakReference.h" michael@0: michael@0: namespace mozilla { michael@0: class EventChainPreVisitor; michael@0: } // namespace mozilla michael@0: michael@0: class nsInProcessTabChildGlobal : public mozilla::DOMEventTargetHelper, michael@0: public nsFrameScriptExecutor, michael@0: public nsIInProcessContentFrameMessageManager, michael@0: public nsIGlobalObject, michael@0: public nsIScriptObjectPrincipal, michael@0: public nsSupportsWeakReference, michael@0: public mozilla::dom::ipc::MessageManagerCallback michael@0: { michael@0: public: michael@0: nsInProcessTabChildGlobal(nsIDocShell* aShell, nsIContent* aOwner, michael@0: nsFrameMessageManager* aChrome); michael@0: virtual ~nsInProcessTabChildGlobal(); michael@0: NS_DECL_ISUPPORTS_INHERITED michael@0: NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsInProcessTabChildGlobal, michael@0: mozilla::DOMEventTargetHelper) michael@0: NS_FORWARD_SAFE_NSIMESSAGELISTENERMANAGER(mMessageManager) michael@0: NS_FORWARD_SAFE_NSIMESSAGESENDER(mMessageManager) michael@0: NS_IMETHOD SendSyncMessage(const nsAString& aMessageName, michael@0: JS::Handle aObject, michael@0: JS::Handle aRemote, michael@0: nsIPrincipal* aPrincipal, michael@0: JSContext* aCx, michael@0: uint8_t aArgc, michael@0: JS::MutableHandle aRetval) michael@0: { michael@0: return mMessageManager michael@0: ? mMessageManager->SendSyncMessage(aMessageName, aObject, aRemote, michael@0: aPrincipal, aCx, aArgc, aRetval) michael@0: : NS_ERROR_NULL_POINTER; michael@0: } michael@0: NS_IMETHOD SendRpcMessage(const nsAString& aMessageName, michael@0: JS::Handle aObject, michael@0: JS::Handle aRemote, michael@0: nsIPrincipal* aPrincipal, michael@0: JSContext* aCx, michael@0: uint8_t aArgc, michael@0: JS::MutableHandle aRetval) michael@0: { michael@0: return mMessageManager michael@0: ? mMessageManager->SendRpcMessage(aMessageName, aObject, aRemote, michael@0: aPrincipal, aCx, aArgc, aRetval) michael@0: : NS_ERROR_NULL_POINTER; michael@0: } michael@0: NS_IMETHOD GetContent(nsIDOMWindow** aContent) MOZ_OVERRIDE; michael@0: NS_IMETHOD GetDocShell(nsIDocShell** aDocShell) MOZ_OVERRIDE; michael@0: NS_IMETHOD Dump(const nsAString& aStr) MOZ_OVERRIDE michael@0: { michael@0: return mMessageManager ? mMessageManager->Dump(aStr) : NS_OK; michael@0: } michael@0: NS_IMETHOD PrivateNoteIntentionalCrash() MOZ_OVERRIDE; michael@0: NS_IMETHOD Btoa(const nsAString& aBinaryData, michael@0: nsAString& aAsciiBase64String) MOZ_OVERRIDE; michael@0: NS_IMETHOD Atob(const nsAString& aAsciiString, michael@0: nsAString& aBinaryData) MOZ_OVERRIDE; michael@0: michael@0: NS_DECL_NSIINPROCESSCONTENTFRAMEMESSAGEMANAGER michael@0: michael@0: /** michael@0: * MessageManagerCallback methods that we override. michael@0: */ michael@0: virtual bool DoSendBlockingMessage(JSContext* aCx, michael@0: const nsAString& aMessage, michael@0: const mozilla::dom::StructuredCloneData& aData, michael@0: JS::Handle aCpows, michael@0: nsIPrincipal* aPrincipal, michael@0: InfallibleTArray* aJSONRetVal, michael@0: bool aIsSync) MOZ_OVERRIDE; michael@0: virtual bool DoSendAsyncMessage(JSContext* aCx, michael@0: const nsAString& aMessage, michael@0: const mozilla::dom::StructuredCloneData& aData, michael@0: JS::Handle aCpows, michael@0: nsIPrincipal* aPrincipal) MOZ_OVERRIDE; michael@0: michael@0: virtual nsresult PreHandleEvent( michael@0: mozilla::EventChainPreVisitor& aVisitor) MOZ_OVERRIDE; michael@0: NS_IMETHOD AddEventListener(const nsAString& aType, michael@0: nsIDOMEventListener* aListener, michael@0: bool aUseCapture) michael@0: { michael@0: // By default add listeners only for trusted events! michael@0: return mozilla::DOMEventTargetHelper::AddEventListener(aType, aListener, michael@0: aUseCapture, false, michael@0: 2); michael@0: } michael@0: NS_IMETHOD AddEventListener(const nsAString& aType, michael@0: nsIDOMEventListener* aListener, michael@0: bool aUseCapture, bool aWantsUntrusted, michael@0: uint8_t optional_argc) MOZ_OVERRIDE michael@0: { michael@0: return mozilla::DOMEventTargetHelper::AddEventListener(aType, aListener, michael@0: aUseCapture, michael@0: aWantsUntrusted, michael@0: optional_argc); michael@0: } michael@0: using mozilla::DOMEventTargetHelper::AddEventListener; michael@0: michael@0: virtual JSContext* GetJSContextForEventHandlers() MOZ_OVERRIDE { return nsContentUtils::GetSafeJSContext(); } michael@0: virtual nsIPrincipal* GetPrincipal() MOZ_OVERRIDE { return mPrincipal; } michael@0: void LoadFrameScript(const nsAString& aURL, bool aRunInGlobalScope); michael@0: void Disconnect(); michael@0: void SendMessageToParent(const nsString& aMessage, bool aSync, michael@0: const nsString& aJSON, michael@0: nsTArray* aJSONRetVal); michael@0: nsFrameMessageManager* GetInnerManager() michael@0: { michael@0: return static_cast(mMessageManager.get()); michael@0: } michael@0: michael@0: void SetOwner(nsIContent* aOwner) { mOwner = aOwner; } michael@0: nsFrameMessageManager* GetChromeMessageManager() michael@0: { michael@0: return mChromeMessageManager; michael@0: } michael@0: void SetChromeMessageManager(nsFrameMessageManager* aParent) michael@0: { michael@0: mChromeMessageManager = aParent; michael@0: } michael@0: michael@0: void DelayedDisconnect(); michael@0: michael@0: virtual JSObject* GetGlobalJSObject() MOZ_OVERRIDE { michael@0: if (!mGlobal) { michael@0: return nullptr; michael@0: } michael@0: michael@0: return mGlobal->GetJSObject(); michael@0: } michael@0: protected: michael@0: nsresult Init(); michael@0: nsresult InitTabChildGlobal(); michael@0: nsCOMPtr mMessageManager; michael@0: nsCOMPtr mDocShell; michael@0: bool mInitialized; michael@0: bool mLoadingScript; michael@0: michael@0: // Is this the message manager for an in-process