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