1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/base/src/nsInProcessTabChildGlobal.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,175 @@ 1.4 +/* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 8; -*- */ 1.5 +/* vim: set sw=4 ts=8 et tw=80 : */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef nsInProcessTabChildGlobal_h 1.11 +#define nsInProcessTabChildGlobal_h 1.12 + 1.13 +#include "mozilla/Attributes.h" 1.14 +#include "mozilla/DOMEventTargetHelper.h" 1.15 +#include "nsCOMPtr.h" 1.16 +#include "nsFrameMessageManager.h" 1.17 +#include "nsIScriptContext.h" 1.18 +#include "nsIScriptObjectPrincipal.h" 1.19 +#include "nsIScriptContext.h" 1.20 +#include "nsIClassInfo.h" 1.21 +#include "nsIDocShell.h" 1.22 +#include "nsIDOMElement.h" 1.23 +#include "nsCOMArray.h" 1.24 +#include "nsIRunnable.h" 1.25 +#include "nsIGlobalObject.h" 1.26 +#include "nsIScriptObjectPrincipal.h" 1.27 +#include "nsWeakReference.h" 1.28 + 1.29 +namespace mozilla { 1.30 +class EventChainPreVisitor; 1.31 +} // namespace mozilla 1.32 + 1.33 +class nsInProcessTabChildGlobal : public mozilla::DOMEventTargetHelper, 1.34 + public nsFrameScriptExecutor, 1.35 + public nsIInProcessContentFrameMessageManager, 1.36 + public nsIGlobalObject, 1.37 + public nsIScriptObjectPrincipal, 1.38 + public nsSupportsWeakReference, 1.39 + public mozilla::dom::ipc::MessageManagerCallback 1.40 +{ 1.41 +public: 1.42 + nsInProcessTabChildGlobal(nsIDocShell* aShell, nsIContent* aOwner, 1.43 + nsFrameMessageManager* aChrome); 1.44 + virtual ~nsInProcessTabChildGlobal(); 1.45 + NS_DECL_ISUPPORTS_INHERITED 1.46 + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsInProcessTabChildGlobal, 1.47 + mozilla::DOMEventTargetHelper) 1.48 + NS_FORWARD_SAFE_NSIMESSAGELISTENERMANAGER(mMessageManager) 1.49 + NS_FORWARD_SAFE_NSIMESSAGESENDER(mMessageManager) 1.50 + NS_IMETHOD SendSyncMessage(const nsAString& aMessageName, 1.51 + JS::Handle<JS::Value> aObject, 1.52 + JS::Handle<JS::Value> aRemote, 1.53 + nsIPrincipal* aPrincipal, 1.54 + JSContext* aCx, 1.55 + uint8_t aArgc, 1.56 + JS::MutableHandle<JS::Value> aRetval) 1.57 + { 1.58 + return mMessageManager 1.59 + ? mMessageManager->SendSyncMessage(aMessageName, aObject, aRemote, 1.60 + aPrincipal, aCx, aArgc, aRetval) 1.61 + : NS_ERROR_NULL_POINTER; 1.62 + } 1.63 + NS_IMETHOD SendRpcMessage(const nsAString& aMessageName, 1.64 + JS::Handle<JS::Value> aObject, 1.65 + JS::Handle<JS::Value> aRemote, 1.66 + nsIPrincipal* aPrincipal, 1.67 + JSContext* aCx, 1.68 + uint8_t aArgc, 1.69 + JS::MutableHandle<JS::Value> aRetval) 1.70 + { 1.71 + return mMessageManager 1.72 + ? mMessageManager->SendRpcMessage(aMessageName, aObject, aRemote, 1.73 + aPrincipal, aCx, aArgc, aRetval) 1.74 + : NS_ERROR_NULL_POINTER; 1.75 + } 1.76 + NS_IMETHOD GetContent(nsIDOMWindow** aContent) MOZ_OVERRIDE; 1.77 + NS_IMETHOD GetDocShell(nsIDocShell** aDocShell) MOZ_OVERRIDE; 1.78 + NS_IMETHOD Dump(const nsAString& aStr) MOZ_OVERRIDE 1.79 + { 1.80 + return mMessageManager ? mMessageManager->Dump(aStr) : NS_OK; 1.81 + } 1.82 + NS_IMETHOD PrivateNoteIntentionalCrash() MOZ_OVERRIDE; 1.83 + NS_IMETHOD Btoa(const nsAString& aBinaryData, 1.84 + nsAString& aAsciiBase64String) MOZ_OVERRIDE; 1.85 + NS_IMETHOD Atob(const nsAString& aAsciiString, 1.86 + nsAString& aBinaryData) MOZ_OVERRIDE; 1.87 + 1.88 + NS_DECL_NSIINPROCESSCONTENTFRAMEMESSAGEMANAGER 1.89 + 1.90 + /** 1.91 + * MessageManagerCallback methods that we override. 1.92 + */ 1.93 + virtual bool DoSendBlockingMessage(JSContext* aCx, 1.94 + const nsAString& aMessage, 1.95 + const mozilla::dom::StructuredCloneData& aData, 1.96 + JS::Handle<JSObject *> aCpows, 1.97 + nsIPrincipal* aPrincipal, 1.98 + InfallibleTArray<nsString>* aJSONRetVal, 1.99 + bool aIsSync) MOZ_OVERRIDE; 1.100 + virtual bool DoSendAsyncMessage(JSContext* aCx, 1.101 + const nsAString& aMessage, 1.102 + const mozilla::dom::StructuredCloneData& aData, 1.103 + JS::Handle<JSObject *> aCpows, 1.104 + nsIPrincipal* aPrincipal) MOZ_OVERRIDE; 1.105 + 1.106 + virtual nsresult PreHandleEvent( 1.107 + mozilla::EventChainPreVisitor& aVisitor) MOZ_OVERRIDE; 1.108 + NS_IMETHOD AddEventListener(const nsAString& aType, 1.109 + nsIDOMEventListener* aListener, 1.110 + bool aUseCapture) 1.111 + { 1.112 + // By default add listeners only for trusted events! 1.113 + return mozilla::DOMEventTargetHelper::AddEventListener(aType, aListener, 1.114 + aUseCapture, false, 1.115 + 2); 1.116 + } 1.117 + NS_IMETHOD AddEventListener(const nsAString& aType, 1.118 + nsIDOMEventListener* aListener, 1.119 + bool aUseCapture, bool aWantsUntrusted, 1.120 + uint8_t optional_argc) MOZ_OVERRIDE 1.121 + { 1.122 + return mozilla::DOMEventTargetHelper::AddEventListener(aType, aListener, 1.123 + aUseCapture, 1.124 + aWantsUntrusted, 1.125 + optional_argc); 1.126 + } 1.127 + using mozilla::DOMEventTargetHelper::AddEventListener; 1.128 + 1.129 + virtual JSContext* GetJSContextForEventHandlers() MOZ_OVERRIDE { return nsContentUtils::GetSafeJSContext(); } 1.130 + virtual nsIPrincipal* GetPrincipal() MOZ_OVERRIDE { return mPrincipal; } 1.131 + void LoadFrameScript(const nsAString& aURL, bool aRunInGlobalScope); 1.132 + void Disconnect(); 1.133 + void SendMessageToParent(const nsString& aMessage, bool aSync, 1.134 + const nsString& aJSON, 1.135 + nsTArray<nsString>* aJSONRetVal); 1.136 + nsFrameMessageManager* GetInnerManager() 1.137 + { 1.138 + return static_cast<nsFrameMessageManager*>(mMessageManager.get()); 1.139 + } 1.140 + 1.141 + void SetOwner(nsIContent* aOwner) { mOwner = aOwner; } 1.142 + nsFrameMessageManager* GetChromeMessageManager() 1.143 + { 1.144 + return mChromeMessageManager; 1.145 + } 1.146 + void SetChromeMessageManager(nsFrameMessageManager* aParent) 1.147 + { 1.148 + mChromeMessageManager = aParent; 1.149 + } 1.150 + 1.151 + void DelayedDisconnect(); 1.152 + 1.153 + virtual JSObject* GetGlobalJSObject() MOZ_OVERRIDE { 1.154 + if (!mGlobal) { 1.155 + return nullptr; 1.156 + } 1.157 + 1.158 + return mGlobal->GetJSObject(); 1.159 + } 1.160 +protected: 1.161 + nsresult Init(); 1.162 + nsresult InitTabChildGlobal(); 1.163 + nsCOMPtr<nsIContentFrameMessageManager> mMessageManager; 1.164 + nsCOMPtr<nsIDocShell> mDocShell; 1.165 + bool mInitialized; 1.166 + bool mLoadingScript; 1.167 + 1.168 + // Is this the message manager for an in-process <iframe mozbrowser> or 1.169 + // <iframe mozapp>? This affects where events get sent, so it affects 1.170 + // PreHandleEvent. 1.171 + bool mIsBrowserOrAppFrame; 1.172 +public: 1.173 + nsIContent* mOwner; 1.174 + nsFrameMessageManager* mChromeMessageManager; 1.175 + nsTArray<nsCOMPtr<nsIRunnable> > mASyncMessages; 1.176 +}; 1.177 + 1.178 +#endif