mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-08 19:04:45 +00:00
Bug 1299061 - Expose the browser that the request was originated in; r=smaug
MozReview-Commit-ID: 2iFQiYeoxBh --HG-- extra : rebase_source : ae00411a047e7331d4f7b988abe544047cce86f2
This commit is contained in:
parent
6377847c29
commit
941035740b
@ -3643,7 +3643,7 @@ ContentParent::DeallocPPresentationParent(PPresentationParent* aActor)
|
||||
bool
|
||||
ContentParent::RecvPPresentationConstructor(PPresentationParent* aActor)
|
||||
{
|
||||
return static_cast<PresentationParent*>(aActor)->Init();
|
||||
return static_cast<PresentationParent*>(aActor)->Init(mChildID);
|
||||
}
|
||||
|
||||
PFlyWebPublishedServerParent*
|
||||
|
@ -184,9 +184,15 @@ PresentationRequest::StartWithDevice(const nsAString& aDeviceId,
|
||||
return promise.forget();
|
||||
}
|
||||
|
||||
// Get xul:browser element in parent process or nsWindowRoot object in child
|
||||
// process. If it's in child process, the corresponding xul:browser element
|
||||
// will be obtained at PresentationRequestParent::DoRequest in its parent
|
||||
// process.
|
||||
nsCOMPtr<nsIDOMEventTarget> handler =
|
||||
do_QueryInterface(GetOwner()->GetChromeEventHandler());
|
||||
nsCOMPtr<nsIPresentationServiceCallback> callback =
|
||||
new PresentationRequesterCallback(this, mUrl, id, promise);
|
||||
rv = service->StartSession(mUrl, id, origin, aDeviceId, GetOwner()->WindowID(), callback);
|
||||
rv = service->StartSession(mUrl, id, origin, aDeviceId, GetOwner()->WindowID(), handler, callback);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
promise->MaybeReject(NS_ERROR_DOM_OPERATION_ERR);
|
||||
}
|
||||
|
@ -73,6 +73,7 @@ public:
|
||||
const nsAString& aId,
|
||||
const nsAString& aOrigin,
|
||||
uint64_t aWindowId,
|
||||
nsIDOMEventTarget* aEventTarget,
|
||||
nsIPresentationServiceCallback* aCallback);
|
||||
|
||||
private:
|
||||
@ -83,6 +84,7 @@ private:
|
||||
nsString mId;
|
||||
nsString mOrigin;
|
||||
uint64_t mWindowId;
|
||||
nsWeakPtr mChromeEventHandler;
|
||||
nsCOMPtr<nsIPresentationServiceCallback> mCallback;
|
||||
};
|
||||
|
||||
@ -98,11 +100,13 @@ PresentationDeviceRequest::PresentationDeviceRequest(
|
||||
const nsAString& aId,
|
||||
const nsAString& aOrigin,
|
||||
uint64_t aWindowId,
|
||||
nsIDOMEventTarget* aEventTarget,
|
||||
nsIPresentationServiceCallback* aCallback)
|
||||
: mRequestUrl(aRequestUrl)
|
||||
, mId(aId)
|
||||
, mOrigin(aOrigin)
|
||||
, mWindowId(aWindowId)
|
||||
, mChromeEventHandler(do_GetWeakReference(aEventTarget))
|
||||
, mCallback(aCallback)
|
||||
{
|
||||
MOZ_ASSERT(!mRequestUrl.IsEmpty());
|
||||
@ -125,6 +129,14 @@ PresentationDeviceRequest::GetRequestURL(nsAString& aRequestUrl)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
PresentationDeviceRequest::GetChromeEventHandler(nsIDOMEventTarget** aChromeEventHandler)
|
||||
{
|
||||
nsCOMPtr<nsIDOMEventTarget> handler(do_QueryReferent(mChromeEventHandler));
|
||||
handler.forget(aChromeEventHandler);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
PresentationDeviceRequest::Select(nsIPresentationDevice* aDevice)
|
||||
{
|
||||
@ -577,6 +589,7 @@ PresentationService::StartSession(const nsAString& aUrl,
|
||||
const nsAString& aOrigin,
|
||||
const nsAString& aDeviceId,
|
||||
uint64_t aWindowId,
|
||||
nsIDOMEventTarget* aEventTarget,
|
||||
nsIPresentationServiceCallback* aCallback)
|
||||
{
|
||||
PRES_DEBUG("%s:url[%s], id[%s]\n", __func__,
|
||||
@ -592,6 +605,7 @@ PresentationService::StartSession(const nsAString& aUrl,
|
||||
aSessionId,
|
||||
aOrigin,
|
||||
aWindowId,
|
||||
aEventTarget,
|
||||
aCallback);
|
||||
|
||||
if (aDeviceId.IsVoid()) {
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
interface nsIDOMEventTarget;
|
||||
interface nsIPresentationDevice;
|
||||
|
||||
%{C++
|
||||
@ -22,6 +23,9 @@ interface nsIPresentationDeviceRequest : nsISupports
|
||||
// The URL to be opened after selection.
|
||||
readonly attribute DOMString requestURL;
|
||||
|
||||
// The XUL browser element that the request was originated in.
|
||||
readonly attribute nsIDOMEventTarget chromeEventHandler;
|
||||
|
||||
/*
|
||||
* Callback after selecting a device
|
||||
* @param device The selected device.
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
interface nsIDOMEventTarget;
|
||||
interface nsIInputStream;
|
||||
interface nsIPresentationAvailabilityListener;
|
||||
interface nsIPresentationRespondingListener;
|
||||
@ -51,11 +52,14 @@ interface nsIPresentationService : nsISupports
|
||||
* @param sessionId: An ID to identify presentation session.
|
||||
* @param origin: The url of requesting page.
|
||||
* @param deviceId: The specified device of handling this request, null string
|
||||
for prompt device selection dialog.
|
||||
* for prompt device selection dialog.
|
||||
* @param windowId: The inner window ID associated with the presentation
|
||||
* session. (0 implies no window ID since no actual window
|
||||
* uses 0 as its ID. Generally it's the case the window is
|
||||
* located in different process from this service)
|
||||
* @param eventTarget: The chrome event handler, in particular XUL browser
|
||||
* element in parent process, that the request was
|
||||
* originated in.
|
||||
* @param callback: Invoke the callback when the operation is completed.
|
||||
* NotifySuccess() is called with |id| if a session is
|
||||
* established successfully with the selected device.
|
||||
@ -66,6 +70,7 @@ interface nsIPresentationService : nsISupports
|
||||
in DOMString origin,
|
||||
in DOMString deviceId,
|
||||
in unsigned long long windowId,
|
||||
in nsIDOMEventTarget eventTarget,
|
||||
in nsIPresentationServiceCallback callback);
|
||||
|
||||
/*
|
||||
|
@ -10,6 +10,8 @@ include protocol PPresentationBuilder;
|
||||
|
||||
include InputStreamParams;
|
||||
|
||||
using mozilla::dom::TabId from "mozilla/dom/ipc/IdType.h";
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
@ -20,6 +22,7 @@ struct StartSessionRequest
|
||||
nsString origin;
|
||||
nsString deviceId;
|
||||
uint64_t windowId;
|
||||
TabId tabId;
|
||||
};
|
||||
|
||||
struct SendSessionMessageRequest
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
#include "mozilla/dom/ContentChild.h"
|
||||
#include "mozilla/dom/PPresentation.h"
|
||||
#include "mozilla/dom/TabParent.h"
|
||||
#include "mozilla/ipc/InputStreamUtils.h"
|
||||
#include "mozilla/ipc/URIUtils.h"
|
||||
#include "nsGlobalWindow.h"
|
||||
@ -57,6 +58,7 @@ PresentationIPCService::StartSession(const nsAString& aUrl,
|
||||
const nsAString& aOrigin,
|
||||
const nsAString& aDeviceId,
|
||||
uint64_t aWindowId,
|
||||
nsIDOMEventTarget* aEventTarget,
|
||||
nsIPresentationServiceCallback* aCallback)
|
||||
{
|
||||
if (aWindowId != 0) {
|
||||
@ -65,11 +67,16 @@ PresentationIPCService::StartSession(const nsAString& aUrl,
|
||||
nsIPresentationService::ROLE_CONTROLLER);
|
||||
}
|
||||
|
||||
nsPIDOMWindowInner* window =
|
||||
nsGlobalWindow::GetInnerWindowWithId(aWindowId)->AsInner();
|
||||
TabId tabId = TabParent::GetTabIdFrom(window->GetDocShell());
|
||||
|
||||
return SendRequest(aCallback, StartSessionRequest(nsString(aUrl),
|
||||
nsString(aSessionId),
|
||||
nsString(aOrigin),
|
||||
nsString(aDeviceId),
|
||||
aWindowId));
|
||||
aWindowId,
|
||||
tabId));
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -5,6 +5,7 @@
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "DCPresentationChannelDescription.h"
|
||||
#include "mozilla/dom/ContentProcessManager.h"
|
||||
#include "mozilla/ipc/InputStreamUtils.h"
|
||||
#include "nsIPresentationDeviceManager.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
@ -35,10 +36,11 @@ PresentationParent::PresentationParent()
|
||||
}
|
||||
|
||||
bool
|
||||
PresentationParent::Init()
|
||||
PresentationParent::Init(ContentParentId aContentParentId)
|
||||
{
|
||||
MOZ_ASSERT(!mService);
|
||||
mService = do_GetService(PRESENTATION_SERVICE_CONTRACTID);
|
||||
mChildId = aContentParentId;
|
||||
return NS_WARN_IF(!mService) ? false : true;
|
||||
}
|
||||
|
||||
@ -107,7 +109,7 @@ PresentationParent::AllocPPresentationRequestParent(
|
||||
const PresentationIPCRequest& aRequest)
|
||||
{
|
||||
MOZ_ASSERT(mService);
|
||||
RefPtr<PresentationRequestParent> actor = new PresentationRequestParent(mService);
|
||||
RefPtr<PresentationRequestParent> actor = new PresentationRequestParent(mService, mChildId);
|
||||
return actor.forget().take();
|
||||
}
|
||||
|
||||
@ -309,8 +311,10 @@ PresentationParent::RecvNotifyTransportClosed(const nsString& aSessionId,
|
||||
|
||||
NS_IMPL_ISUPPORTS(PresentationRequestParent, nsIPresentationServiceCallback)
|
||||
|
||||
PresentationRequestParent::PresentationRequestParent(nsIPresentationService* aService)
|
||||
PresentationRequestParent::PresentationRequestParent(nsIPresentationService* aService,
|
||||
ContentParentId aContentParentId)
|
||||
: mService(aService)
|
||||
, mChildId(aContentParentId)
|
||||
{
|
||||
MOZ_COUNT_CTOR(PresentationRequestParent);
|
||||
}
|
||||
@ -333,9 +337,18 @@ PresentationRequestParent::DoRequest(const StartSessionRequest& aRequest)
|
||||
MOZ_ASSERT(mService);
|
||||
mNeedRegisterBuilder = true;
|
||||
mSessionId = aRequest.sessionId();
|
||||
|
||||
nsCOMPtr<nsIDOMEventTarget> eventTarget;
|
||||
ContentProcessManager* cpm = ContentProcessManager::GetSingleton();
|
||||
RefPtr<TabParent> tp =
|
||||
cpm->GetTopLevelTabParentByProcessAndTabId(mChildId, aRequest.tabId());
|
||||
if (tp) {
|
||||
eventTarget = do_QueryInterface(tp->GetOwnerElement());
|
||||
}
|
||||
|
||||
return mService->StartSession(aRequest.url(), aRequest.sessionId(),
|
||||
aRequest.origin(), aRequest.deviceId(),
|
||||
aRequest.windowId(), this);
|
||||
aRequest.windowId(), eventTarget, this);
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -7,6 +7,7 @@
|
||||
#ifndef mozilla_dom_PresentationParent_h__
|
||||
#define mozilla_dom_PresentationParent_h__
|
||||
|
||||
#include "mozilla/dom/ipc/IdType.h"
|
||||
#include "mozilla/dom/PPresentationBuilderParent.h"
|
||||
#include "mozilla/dom/PPresentationParent.h"
|
||||
#include "mozilla/dom/PPresentationRequestParent.h"
|
||||
@ -30,7 +31,7 @@ public:
|
||||
|
||||
PresentationParent();
|
||||
|
||||
bool Init();
|
||||
bool Init(ContentParentId aContentParentId);
|
||||
|
||||
bool RegisterTransportBuilder(const nsString& aSessionId, const uint8_t& aRole);
|
||||
|
||||
@ -86,6 +87,7 @@ private:
|
||||
nsTArray<nsString> mSessionIdsAtController;
|
||||
nsTArray<nsString> mSessionIdsAtReceiver;
|
||||
nsTArray<uint64_t> mWindowIds;
|
||||
ContentParentId mChildId;
|
||||
};
|
||||
|
||||
class PresentationRequestParent final : public PPresentationRequestParent
|
||||
@ -97,7 +99,8 @@ public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIPRESENTATIONSERVICECALLBACK
|
||||
|
||||
explicit PresentationRequestParent(nsIPresentationService* aService);
|
||||
explicit PresentationRequestParent(nsIPresentationService* aService,
|
||||
ContentParentId aContentParentId);
|
||||
|
||||
virtual void ActorDestroy(ActorDestroyReason aWhy) override;
|
||||
|
||||
@ -122,6 +125,7 @@ private:
|
||||
bool mNeedRegisterBuilder = false;
|
||||
nsString mSessionId;
|
||||
nsCOMPtr<nsIPresentationService> mService;
|
||||
ContentParentId mChildId;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
|
Loading…
Reference in New Issue
Block a user