2015-05-03 12:32:37 -07: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 04:12:37 -07: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 05:28:37 -07:00
|
|
|
|
|
|
|
#ifndef nsInProcessTabChildGlobal_h
|
|
|
|
#define nsInProcessTabChildGlobal_h
|
|
|
|
|
2013-05-29 13:43:41 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2014-03-31 23:13:50 -07:00
|
|
|
#include "mozilla/DOMEventTargetHelper.h"
|
2010-05-18 05:28:37 -07: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 06:54:39 -07:00
|
|
|
#include "nsIRunnable.h"
|
2013-04-04 02:27:06 -07:00
|
|
|
#include "nsIGlobalObject.h"
|
2013-09-08 20:28:48 -07:00
|
|
|
#include "nsIScriptObjectPrincipal.h"
|
2013-04-04 02:27:40 -07:00
|
|
|
#include "nsWeakReference.h"
|
2010-05-18 05:28:37 -07:00
|
|
|
|
2014-03-17 21:48:19 -07:00
|
|
|
namespace mozilla {
|
|
|
|
class EventChainPreVisitor;
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2014-03-31 23:13:50 -07:00
|
|
|
class nsInProcessTabChildGlobal : public mozilla::DOMEventTargetHelper,
|
2015-02-19 17:10:44 -08:00
|
|
|
public nsMessageManagerScriptExecutor,
|
2010-05-18 05:28:37 -07:00
|
|
|
public nsIInProcessContentFrameMessageManager,
|
2013-04-04 02:27:06 -07:00
|
|
|
public nsIGlobalObject,
|
2013-09-08 20:28:48 -07:00
|
|
|
public nsIScriptObjectPrincipal,
|
2013-04-04 02:27:40 -07:00
|
|
|
public nsSupportsWeakReference,
|
2012-09-27 22:43:12 -07:00
|
|
|
public mozilla::dom::ipc::MessageManagerCallback
|
2010-05-18 05:28:37 -07:00
|
|
|
{
|
2015-04-29 20:39:59 -07:00
|
|
|
typedef mozilla::OwningSerializedStructuredCloneBuffer OwningSerializedStructuredCloneBuffer;
|
|
|
|
|
2010-05-18 05:28:37 -07:00
|
|
|
public:
|
|
|
|
nsInProcessTabChildGlobal(nsIDocShell* aShell, nsIContent* aOwner,
|
|
|
|
nsFrameMessageManager* aChrome);
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2014-06-13 10:56:38 -07:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(nsInProcessTabChildGlobal,
|
|
|
|
mozilla::DOMEventTargetHelper)
|
|
|
|
|
2012-08-27 07:13:02 -07:00
|
|
|
NS_FORWARD_SAFE_NSIMESSAGELISTENERMANAGER(mMessageManager)
|
|
|
|
NS_FORWARD_SAFE_NSIMESSAGESENDER(mMessageManager)
|
2015-02-19 17:12:11 -08:00
|
|
|
NS_FORWARD_SAFE_NSIMESSAGEMANAGERGLOBAL(mMessageManager)
|
2011-10-01 09:14:36 -07:00
|
|
|
NS_IMETHOD SendSyncMessage(const nsAString& aMessageName,
|
2014-01-09 09:39:36 -08:00
|
|
|
JS::Handle<JS::Value> aObject,
|
|
|
|
JS::Handle<JS::Value> aRemote,
|
2013-11-06 09:21:15 -08:00
|
|
|
nsIPrincipal* aPrincipal,
|
2011-10-01 09:14:36 -07:00
|
|
|
JSContext* aCx,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t aArgc,
|
2015-03-21 09:28:04 -07:00
|
|
|
JS::MutableHandle<JS::Value> aRetval) override
|
2010-05-18 05:28:37 -07:00
|
|
|
{
|
2011-10-01 09:14:36 -07:00
|
|
|
return mMessageManager
|
2013-11-06 09:21:15 -08:00
|
|
|
? mMessageManager->SendSyncMessage(aMessageName, aObject, aRemote,
|
|
|
|
aPrincipal, aCx, aArgc, aRetval)
|
2011-10-01 09:14:36 -07:00
|
|
|
: NS_ERROR_NULL_POINTER;
|
2010-05-18 05:28:37 -07:00
|
|
|
}
|
2013-10-01 09:15:06 -07:00
|
|
|
NS_IMETHOD SendRpcMessage(const nsAString& aMessageName,
|
2014-01-09 09:39:36 -08:00
|
|
|
JS::Handle<JS::Value> aObject,
|
|
|
|
JS::Handle<JS::Value> aRemote,
|
2013-11-06 09:21:15 -08:00
|
|
|
nsIPrincipal* aPrincipal,
|
2013-10-01 09:15:06 -07:00
|
|
|
JSContext* aCx,
|
|
|
|
uint8_t aArgc,
|
2015-03-21 09:28:04 -07:00
|
|
|
JS::MutableHandle<JS::Value> aRetval) override
|
2013-10-01 09:15:06 -07:00
|
|
|
{
|
|
|
|
return mMessageManager
|
2013-11-06 09:21:15 -08:00
|
|
|
? mMessageManager->SendRpcMessage(aMessageName, aObject, aRemote,
|
|
|
|
aPrincipal, aCx, aArgc, aRetval)
|
2013-10-01 09:15:06 -07:00
|
|
|
: NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
2015-03-21 09:28:04 -07:00
|
|
|
NS_IMETHOD GetContent(nsIDOMWindow** aContent) override;
|
|
|
|
NS_IMETHOD GetDocShell(nsIDocShell** aDocShell) override;
|
2011-06-25 02:52:00 -07:00
|
|
|
|
2010-05-18 05:28:37 -07:00
|
|
|
NS_DECL_NSIINPROCESSCONTENTFRAMEMESSAGEMANAGER
|
|
|
|
|
2012-09-27 22:43:12 -07:00
|
|
|
/**
|
|
|
|
* MessageManagerCallback methods that we override.
|
|
|
|
*/
|
2013-10-01 09:15:06 -07:00
|
|
|
virtual bool DoSendBlockingMessage(JSContext* aCx,
|
|
|
|
const nsAString& aMessage,
|
|
|
|
const mozilla::dom::StructuredCloneData& aData,
|
|
|
|
JS::Handle<JSObject *> aCpows,
|
2013-11-06 09:21:15 -08:00
|
|
|
nsIPrincipal* aPrincipal,
|
2015-04-29 20:39:59 -07:00
|
|
|
nsTArray<OwningSerializedStructuredCloneBuffer>* aRetVal,
|
2015-03-21 09:28:04 -07:00
|
|
|
bool aIsSync) override;
|
2013-07-10 15:05:39 -07:00
|
|
|
virtual bool DoSendAsyncMessage(JSContext* aCx,
|
|
|
|
const nsAString& aMessage,
|
|
|
|
const mozilla::dom::StructuredCloneData& aData,
|
2013-11-06 09:21:15 -08:00
|
|
|
JS::Handle<JSObject *> aCpows,
|
2015-03-21 09:28:04 -07:00
|
|
|
nsIPrincipal* aPrincipal) override;
|
2012-09-27 22:43:12 -07:00
|
|
|
|
2014-03-17 21:48:19 -07:00
|
|
|
virtual nsresult PreHandleEvent(
|
2015-03-21 09:28:04 -07:00
|
|
|
mozilla::EventChainPreVisitor& aVisitor) override;
|
2010-05-18 05:28:37 -07:00
|
|
|
NS_IMETHOD AddEventListener(const nsAString& aType,
|
|
|
|
nsIDOMEventListener* aListener,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aUseCapture)
|
2010-05-18 05:28:37 -07:00
|
|
|
{
|
|
|
|
// By default add listeners only for trusted events!
|
2014-03-31 23:13:50 -07:00
|
|
|
return mozilla::DOMEventTargetHelper::AddEventListener(aType, aListener,
|
|
|
|
aUseCapture, false,
|
|
|
|
2);
|
2010-05-18 05:28:37 -07:00
|
|
|
}
|
|
|
|
NS_IMETHOD AddEventListener(const nsAString& aType,
|
|
|
|
nsIDOMEventListener* aListener,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aUseCapture, bool aWantsUntrusted,
|
2015-03-21 09:28:04 -07:00
|
|
|
uint8_t optional_argc) override
|
2010-05-18 05:28:37 -07:00
|
|
|
{
|
2014-03-31 23:13:50 -07:00
|
|
|
return mozilla::DOMEventTargetHelper::AddEventListener(aType, aListener,
|
|
|
|
aUseCapture,
|
|
|
|
aWantsUntrusted,
|
|
|
|
optional_argc);
|
2010-05-18 05:28:37 -07:00
|
|
|
}
|
2014-03-31 23:13:50 -07:00
|
|
|
using mozilla::DOMEventTargetHelper::AddEventListener;
|
2010-05-18 05:28:37 -07:00
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual JSContext* GetJSContextForEventHandlers() override { return nsContentUtils::GetSafeJSContext(); }
|
|
|
|
virtual nsIPrincipal* GetPrincipal() override { return mPrincipal; }
|
2013-11-23 21:32:45 -08:00
|
|
|
void LoadFrameScript(const nsAString& aURL, bool aRunInGlobalScope);
|
2015-02-26 21:35:26 -08:00
|
|
|
void FireUnloadEvent();
|
|
|
|
void DisconnectEventListeners();
|
2010-05-18 05:28:37 -07:00
|
|
|
void Disconnect();
|
2011-09-28 23:19:26 -07:00
|
|
|
void SendMessageToParent(const nsString& aMessage, bool aSync,
|
2010-05-18 05:28:37 -07: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 09:47:22 -07:00
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual JSObject* GetGlobalJSObject() override {
|
2013-04-04 02:27:06 -07:00
|
|
|
if (!mGlobal) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2013-05-20 05:44:18 -07:00
|
|
|
return mGlobal->GetJSObject();
|
2013-04-04 02:27:06 -07:00
|
|
|
}
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual JSObject* WrapObject(JSContext* cx, JS::Handle<JSObject*> aGivenProto) override
|
2014-10-07 02:44:48 -07:00
|
|
|
{
|
|
|
|
MOZ_CRASH("nsInProcessTabChildGlobal doesn't use DOM bindings!");
|
|
|
|
}
|
2015-04-16 08:17:54 -07:00
|
|
|
|
|
|
|
already_AddRefed<nsIFrameLoader> GetFrameLoader();
|
|
|
|
|
2010-05-18 05:28:37 -07:00
|
|
|
protected:
|
2014-07-08 14:23:16 -07:00
|
|
|
virtual ~nsInProcessTabChildGlobal();
|
|
|
|
|
2010-05-18 05:28:37 -07:00
|
|
|
nsresult Init();
|
|
|
|
nsresult InitTabChildGlobal();
|
|
|
|
nsCOMPtr<nsIContentFrameMessageManager> mMessageManager;
|
|
|
|
nsCOMPtr<nsIDocShell> mDocShell;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mInitialized;
|
|
|
|
bool mLoadingScript;
|
2012-05-08 09:20:35 -07:00
|
|
|
|
Bug 802366 - The main event: Let a browser process inherit its app's id. r=bz,cjones
The main bug fixed here is that in half of our interfaces, we use "is browser frame/element" to mean "browser or app", and in the other half, we use it to mean "is browser not app".
There's a related, functional bug also fixed here, which is that a browser process doesn't inherit its parent's app-id. This causes problems e.g. for IndexedDB: If a browser inside an app uses IndexedDB, the DB should have the app's app-id.
I also modified Tab{Parent,Child} and nsFrameLoader to call "app" "ownOrContainingApp", to emphasize that we might have inherited the app from a parent process. I left nsIDocShell::appId alone, because changing that would have necessitated changing nsILoadGroup and therefore a /lot/ of users in Necko; it's also not clear it would have clarified anything in those cases.
2012-11-10 10:32:37 -08:00
|
|
|
// Is this the message manager for an in-process <iframe mozbrowser> or
|
|
|
|
// <iframe mozapp>? This affects where events get sent, so it affects
|
|
|
|
// PreHandleEvent.
|
|
|
|
bool mIsBrowserOrAppFrame;
|
2015-02-26 21:35:26 -08:00
|
|
|
bool mPreventEventsEscaping;
|
2015-04-16 08:17:54 -07: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 05:28:37 -07:00
|
|
|
public:
|
|
|
|
nsIContent* mOwner;
|
|
|
|
nsFrameMessageManager* mChromeMessageManager;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|