content/base/src/nsInProcessTabChildGlobal.h

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

michael@0 1 /* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 8; -*- */
michael@0 2 /* vim: set sw=4 ts=8 et tw=80 : */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #ifndef nsInProcessTabChildGlobal_h
michael@0 8 #define nsInProcessTabChildGlobal_h
michael@0 9
michael@0 10 #include "mozilla/Attributes.h"
michael@0 11 #include "mozilla/DOMEventTargetHelper.h"
michael@0 12 #include "nsCOMPtr.h"
michael@0 13 #include "nsFrameMessageManager.h"
michael@0 14 #include "nsIScriptContext.h"
michael@0 15 #include "nsIScriptObjectPrincipal.h"
michael@0 16 #include "nsIScriptContext.h"
michael@0 17 #include "nsIClassInfo.h"
michael@0 18 #include "nsIDocShell.h"
michael@0 19 #include "nsIDOMElement.h"
michael@0 20 #include "nsCOMArray.h"
michael@0 21 #include "nsIRunnable.h"
michael@0 22 #include "nsIGlobalObject.h"
michael@0 23 #include "nsIScriptObjectPrincipal.h"
michael@0 24 #include "nsWeakReference.h"
michael@0 25
michael@0 26 namespace mozilla {
michael@0 27 class EventChainPreVisitor;
michael@0 28 } // namespace mozilla
michael@0 29
michael@0 30 class nsInProcessTabChildGlobal : public mozilla::DOMEventTargetHelper,
michael@0 31 public nsFrameScriptExecutor,
michael@0 32 public nsIInProcessContentFrameMessageManager,
michael@0 33 public nsIGlobalObject,
michael@0 34 public nsIScriptObjectPrincipal,
michael@0 35 public nsSupportsWeakReference,
michael@0 36 public mozilla::dom::ipc::MessageManagerCallback
michael@0 37 {
michael@0 38 public:
michael@0 39 nsInProcessTabChildGlobal(nsIDocShell* aShell, nsIContent* aOwner,
michael@0 40 nsFrameMessageManager* aChrome);
michael@0 41 virtual ~nsInProcessTabChildGlobal();
michael@0 42 NS_DECL_ISUPPORTS_INHERITED
michael@0 43 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsInProcessTabChildGlobal,
michael@0 44 mozilla::DOMEventTargetHelper)
michael@0 45 NS_FORWARD_SAFE_NSIMESSAGELISTENERMANAGER(mMessageManager)
michael@0 46 NS_FORWARD_SAFE_NSIMESSAGESENDER(mMessageManager)
michael@0 47 NS_IMETHOD SendSyncMessage(const nsAString& aMessageName,
michael@0 48 JS::Handle<JS::Value> aObject,
michael@0 49 JS::Handle<JS::Value> aRemote,
michael@0 50 nsIPrincipal* aPrincipal,
michael@0 51 JSContext* aCx,
michael@0 52 uint8_t aArgc,
michael@0 53 JS::MutableHandle<JS::Value> aRetval)
michael@0 54 {
michael@0 55 return mMessageManager
michael@0 56 ? mMessageManager->SendSyncMessage(aMessageName, aObject, aRemote,
michael@0 57 aPrincipal, aCx, aArgc, aRetval)
michael@0 58 : NS_ERROR_NULL_POINTER;
michael@0 59 }
michael@0 60 NS_IMETHOD SendRpcMessage(const nsAString& aMessageName,
michael@0 61 JS::Handle<JS::Value> aObject,
michael@0 62 JS::Handle<JS::Value> aRemote,
michael@0 63 nsIPrincipal* aPrincipal,
michael@0 64 JSContext* aCx,
michael@0 65 uint8_t aArgc,
michael@0 66 JS::MutableHandle<JS::Value> aRetval)
michael@0 67 {
michael@0 68 return mMessageManager
michael@0 69 ? mMessageManager->SendRpcMessage(aMessageName, aObject, aRemote,
michael@0 70 aPrincipal, aCx, aArgc, aRetval)
michael@0 71 : NS_ERROR_NULL_POINTER;
michael@0 72 }
michael@0 73 NS_IMETHOD GetContent(nsIDOMWindow** aContent) MOZ_OVERRIDE;
michael@0 74 NS_IMETHOD GetDocShell(nsIDocShell** aDocShell) MOZ_OVERRIDE;
michael@0 75 NS_IMETHOD Dump(const nsAString& aStr) MOZ_OVERRIDE
michael@0 76 {
michael@0 77 return mMessageManager ? mMessageManager->Dump(aStr) : NS_OK;
michael@0 78 }
michael@0 79 NS_IMETHOD PrivateNoteIntentionalCrash() MOZ_OVERRIDE;
michael@0 80 NS_IMETHOD Btoa(const nsAString& aBinaryData,
michael@0 81 nsAString& aAsciiBase64String) MOZ_OVERRIDE;
michael@0 82 NS_IMETHOD Atob(const nsAString& aAsciiString,
michael@0 83 nsAString& aBinaryData) MOZ_OVERRIDE;
michael@0 84
michael@0 85 NS_DECL_NSIINPROCESSCONTENTFRAMEMESSAGEMANAGER
michael@0 86
michael@0 87 /**
michael@0 88 * MessageManagerCallback methods that we override.
michael@0 89 */
michael@0 90 virtual bool DoSendBlockingMessage(JSContext* aCx,
michael@0 91 const nsAString& aMessage,
michael@0 92 const mozilla::dom::StructuredCloneData& aData,
michael@0 93 JS::Handle<JSObject *> aCpows,
michael@0 94 nsIPrincipal* aPrincipal,
michael@0 95 InfallibleTArray<nsString>* aJSONRetVal,
michael@0 96 bool aIsSync) MOZ_OVERRIDE;
michael@0 97 virtual bool DoSendAsyncMessage(JSContext* aCx,
michael@0 98 const nsAString& aMessage,
michael@0 99 const mozilla::dom::StructuredCloneData& aData,
michael@0 100 JS::Handle<JSObject *> aCpows,
michael@0 101 nsIPrincipal* aPrincipal) MOZ_OVERRIDE;
michael@0 102
michael@0 103 virtual nsresult PreHandleEvent(
michael@0 104 mozilla::EventChainPreVisitor& aVisitor) MOZ_OVERRIDE;
michael@0 105 NS_IMETHOD AddEventListener(const nsAString& aType,
michael@0 106 nsIDOMEventListener* aListener,
michael@0 107 bool aUseCapture)
michael@0 108 {
michael@0 109 // By default add listeners only for trusted events!
michael@0 110 return mozilla::DOMEventTargetHelper::AddEventListener(aType, aListener,
michael@0 111 aUseCapture, false,
michael@0 112 2);
michael@0 113 }
michael@0 114 NS_IMETHOD AddEventListener(const nsAString& aType,
michael@0 115 nsIDOMEventListener* aListener,
michael@0 116 bool aUseCapture, bool aWantsUntrusted,
michael@0 117 uint8_t optional_argc) MOZ_OVERRIDE
michael@0 118 {
michael@0 119 return mozilla::DOMEventTargetHelper::AddEventListener(aType, aListener,
michael@0 120 aUseCapture,
michael@0 121 aWantsUntrusted,
michael@0 122 optional_argc);
michael@0 123 }
michael@0 124 using mozilla::DOMEventTargetHelper::AddEventListener;
michael@0 125
michael@0 126 virtual JSContext* GetJSContextForEventHandlers() MOZ_OVERRIDE { return nsContentUtils::GetSafeJSContext(); }
michael@0 127 virtual nsIPrincipal* GetPrincipal() MOZ_OVERRIDE { return mPrincipal; }
michael@0 128 void LoadFrameScript(const nsAString& aURL, bool aRunInGlobalScope);
michael@0 129 void Disconnect();
michael@0 130 void SendMessageToParent(const nsString& aMessage, bool aSync,
michael@0 131 const nsString& aJSON,
michael@0 132 nsTArray<nsString>* aJSONRetVal);
michael@0 133 nsFrameMessageManager* GetInnerManager()
michael@0 134 {
michael@0 135 return static_cast<nsFrameMessageManager*>(mMessageManager.get());
michael@0 136 }
michael@0 137
michael@0 138 void SetOwner(nsIContent* aOwner) { mOwner = aOwner; }
michael@0 139 nsFrameMessageManager* GetChromeMessageManager()
michael@0 140 {
michael@0 141 return mChromeMessageManager;
michael@0 142 }
michael@0 143 void SetChromeMessageManager(nsFrameMessageManager* aParent)
michael@0 144 {
michael@0 145 mChromeMessageManager = aParent;
michael@0 146 }
michael@0 147
michael@0 148 void DelayedDisconnect();
michael@0 149
michael@0 150 virtual JSObject* GetGlobalJSObject() MOZ_OVERRIDE {
michael@0 151 if (!mGlobal) {
michael@0 152 return nullptr;
michael@0 153 }
michael@0 154
michael@0 155 return mGlobal->GetJSObject();
michael@0 156 }
michael@0 157 protected:
michael@0 158 nsresult Init();
michael@0 159 nsresult InitTabChildGlobal();
michael@0 160 nsCOMPtr<nsIContentFrameMessageManager> mMessageManager;
michael@0 161 nsCOMPtr<nsIDocShell> mDocShell;
michael@0 162 bool mInitialized;
michael@0 163 bool mLoadingScript;
michael@0 164
michael@0 165 // Is this the message manager for an in-process <iframe mozbrowser> or
michael@0 166 // <iframe mozapp>? This affects where events get sent, so it affects
michael@0 167 // PreHandleEvent.
michael@0 168 bool mIsBrowserOrAppFrame;
michael@0 169 public:
michael@0 170 nsIContent* mOwner;
michael@0 171 nsFrameMessageManager* mChromeMessageManager;
michael@0 172 nsTArray<nsCOMPtr<nsIRunnable> > mASyncMessages;
michael@0 173 };
michael@0 174
michael@0 175 #endif

mercurial