Bug 1306210 - Expose the principal of the device request; r=smaug
MozReview-Commit-ID: ihzebnIUUU
--- a/dom/presentation/PresentationRequest.cpp
+++ b/dom/presentation/PresentationRequest.cpp
@@ -201,26 +201,28 @@ PresentationRequest::StartWithDevice(con
}
// 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<nsIPrincipal> principal = doc->NodePrincipal();
nsCOMPtr<nsIPresentationServiceCallback> callback =
new PresentationRequesterCallback(this, id, promise);
nsCOMPtr<nsIPresentationTransportBuilderConstructor> constructor =
PresentationTransportBuilderConstructor::Create();
rv = service->StartSession(mUrls,
id,
origin,
aDeviceId,
GetOwner()->WindowID(),
handler,
+ principal,
callback,
constructor);
if (NS_WARN_IF(NS_FAILED(rv))) {
promise->MaybeReject(NS_ERROR_DOM_OPERATION_ERR);
}
return promise.forget();
}
--- a/dom/presentation/PresentationService.cpp
+++ b/dom/presentation/PresentationService.cpp
@@ -108,29 +108,31 @@ public:
NS_DECL_NSIPRESENTATIONDEVICEREQUEST
PresentationDeviceRequest(
const nsTArray<nsString>& aUrls,
const nsAString& aId,
const nsAString& aOrigin,
uint64_t aWindowId,
nsIDOMEventTarget* aEventTarget,
+ nsIPrincipal* aPrincipal,
nsIPresentationServiceCallback* aCallback,
nsIPresentationTransportBuilderConstructor* aBuilderConstructor);
private:
virtual ~PresentationDeviceRequest() = default;
nsresult CreateSessionInfo(nsIPresentationDevice* aDevice,
const nsAString& aSelectedRequestUrl);
nsTArray<nsString> mRequestUrls;
nsString mId;
nsString mOrigin;
uint64_t mWindowId;
nsWeakPtr mChromeEventHandler;
+ nsCOMPtr<nsIPrincipal> mPrincipal;
nsCOMPtr<nsIPresentationServiceCallback> mCallback;
nsCOMPtr<nsIPresentationTransportBuilderConstructor> mBuilderConstructor;
};
LazyLogModule gPresentationLog("Presentation");
} // namespace dom
} // namespace mozilla
@@ -138,23 +140,25 @@ LazyLogModule gPresentationLog("Presenta
NS_IMPL_ISUPPORTS(PresentationDeviceRequest, nsIPresentationDeviceRequest)
PresentationDeviceRequest::PresentationDeviceRequest(
const nsTArray<nsString>& aUrls,
const nsAString& aId,
const nsAString& aOrigin,
uint64_t aWindowId,
nsIDOMEventTarget* aEventTarget,
+ nsIPrincipal* aPrincipal,
nsIPresentationServiceCallback* aCallback,
nsIPresentationTransportBuilderConstructor* aBuilderConstructor)
: mRequestUrls(aUrls)
, mId(aId)
, mOrigin(aOrigin)
, mWindowId(aWindowId)
, mChromeEventHandler(do_GetWeakReference(aEventTarget))
+ , mPrincipal(aPrincipal)
, mCallback(aCallback)
, mBuilderConstructor(aBuilderConstructor)
{
MOZ_ASSERT(!mRequestUrls.IsEmpty());
MOZ_ASSERT(!mId.IsEmpty());
MOZ_ASSERT(!mOrigin.IsEmpty());
MOZ_ASSERT(mCallback);
MOZ_ASSERT(mBuilderConstructor);
@@ -177,16 +181,24 @@ NS_IMETHODIMP
PresentationDeviceRequest::GetChromeEventHandler(nsIDOMEventTarget** aChromeEventHandler)
{
nsCOMPtr<nsIDOMEventTarget> handler(do_QueryReferent(mChromeEventHandler));
handler.forget(aChromeEventHandler);
return NS_OK;
}
NS_IMETHODIMP
+PresentationDeviceRequest::GetPrincipal(nsIPrincipal** aPrincipal)
+{
+ nsCOMPtr<nsIPrincipal> principal(mPrincipal);
+ principal.forget(aPrincipal);
+ return NS_OK;
+}
+
+NS_IMETHODIMP
PresentationDeviceRequest::Select(nsIPresentationDevice* aDevice)
{
MOZ_ASSERT(NS_IsMainThread());
if (NS_WARN_IF(!aDevice)) {
MOZ_ASSERT(false, "|aDevice| should noe be null.");
mCallback->NotifyError(NS_ERROR_DOM_OPERATION_ERR);
return NS_ERROR_INVALID_ARG;
}
@@ -650,32 +662,34 @@ PresentationService::IsAppInstalled(nsIU
NS_IMETHODIMP
PresentationService::StartSession(
const nsTArray<nsString>& aUrls,
const nsAString& aSessionId,
const nsAString& aOrigin,
const nsAString& aDeviceId,
uint64_t aWindowId,
nsIDOMEventTarget* aEventTarget,
+ nsIPrincipal* aPrincipal,
nsIPresentationServiceCallback* aCallback,
nsIPresentationTransportBuilderConstructor* aBuilderConstructor)
{
PRES_DEBUG("%s:id[%s]\n", __func__, NS_ConvertUTF16toUTF8(aSessionId).get());
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(aCallback);
MOZ_ASSERT(!aSessionId.IsEmpty());
MOZ_ASSERT(!aUrls.IsEmpty());
nsCOMPtr<nsIPresentationDeviceRequest> request =
new PresentationDeviceRequest(aUrls,
aSessionId,
aOrigin,
aWindowId,
aEventTarget,
+ aPrincipal,
aCallback,
aBuilderConstructor);
if (aDeviceId.IsVoid()) {
// Pop up a prompt and ask user to select a device.
nsCOMPtr<nsIPresentationDevicePrompt> prompt =
do_GetService(PRESENTATION_DEVICE_PROMPT_CONTRACTID);
if (NS_WARN_IF(!prompt)) {
--- a/dom/presentation/interfaces/nsIPresentationDevicePrompt.idl
+++ b/dom/presentation/interfaces/nsIPresentationDevicePrompt.idl
@@ -2,16 +2,17 @@
* 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/. */
#include "nsISupports.idl"
interface nsIArray;
interface nsIDOMEventTarget;
interface nsIPresentationDevice;
+interface nsIPrincipal;
%{C++
#define PRESENTATION_DEVICE_PROMPT_CONTRACTID "@mozilla.org/presentation-device/prompt;1"
%}
/*
* The information and callbacks for device selection
*/
@@ -22,16 +23,19 @@ interface nsIPresentationDeviceRequest :
readonly attribute DOMString origin;
// The array of candidate URLs.
readonly attribute nsIArray requestURLs;
// The XUL browser element that the request was originated in.
readonly attribute nsIDOMEventTarget chromeEventHandler;
+ // The principal of the request.
+ readonly attribute nsIPrincipal principal;
+
/*
* Callback after selecting a device
* @param device The selected device.
*/
void select(in nsIPresentationDevice device);
/*
* Callback after selection failed or canceled by user.
--- a/dom/presentation/interfaces/nsIPresentationService.idl
+++ b/dom/presentation/interfaces/nsIPresentationService.idl
@@ -6,16 +6,17 @@
interface nsIDOMBlob;
interface nsIDOMEventTarget;
interface nsIInputStream;
interface nsIPresentationAvailabilityListener;
interface nsIPresentationRespondingListener;
interface nsIPresentationSessionListener;
interface nsIPresentationTransportBuilderConstructor;
+interface nsIPrincipal;
%{C++
#define PRESENTATION_SERVICE_CID \
{ 0x1d9bb10c, 0xc0ab, 0x4fe8, \
{ 0x9e, 0x4f, 0x40, 0x58, 0xb8, 0x51, 0x98, 0x32 } }
#define PRESENTATION_SERVICE_CONTRACTID \
"@mozilla.org/presentation/presentationservice;1"
@@ -65,28 +66,30 @@ interface nsIPresentationService : nsISu
* 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 principal: The principal that initiated the session.
* @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.
* Otherwise, NotifyError() is called with a error message.
* @param constructor: The constructor for creating a transport builder.
*/
[noscript] void startSession(in URLArrayRef urls,
in DOMString sessionId,
in DOMString origin,
in DOMString deviceId,
in unsigned long long windowId,
in nsIDOMEventTarget eventTarget,
+ in nsIPrincipal principal,
in nsIPresentationServiceCallback callback,
in nsIPresentationTransportBuilderConstructor constructor);
/*
* Send the message to the session.
*
* @param sessionId: An ID to identify presentation session.
* @param role: Identify the function called by controller or receiver.
--- a/dom/presentation/ipc/PPresentation.ipdl
+++ b/dom/presentation/ipc/PPresentation.ipdl
@@ -5,29 +5,31 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */
include protocol PContent;
include protocol PPresentationRequest;
include protocol PPresentationBuilder;
include InputStreamParams;
+using class IPC::Principal from "mozilla/dom/PermissionMessageUtils.h";
using mozilla::dom::TabId from "mozilla/dom/ipc/IdType.h";
namespace mozilla {
namespace dom {
struct StartSessionRequest
{
nsString[] urls;
nsString sessionId;
nsString origin;
nsString deviceId;
uint64_t windowId;
TabId tabId;
+ Principal principal;
};
struct SendSessionMessageRequest
{
nsString sessionId;
uint8_t role;
nsString data;
};
--- a/dom/presentation/ipc/PresentationIPCService.cpp
+++ b/dom/presentation/ipc/PresentationIPCService.cpp
@@ -1,15 +1,16 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set sw=2 ts=8 et ft=cpp : */
/* 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/. */
#include "mozilla/dom/ContentChild.h"
+#include "mozilla/dom/PermissionMessageUtils.h"
#include "mozilla/dom/PPresentation.h"
#include "mozilla/dom/TabParent.h"
#include "mozilla/ipc/InputStreamUtils.h"
#include "mozilla/ipc/URIUtils.h"
#include "nsGlobalWindow.h"
#include "nsIPresentationListener.h"
#include "PresentationCallbacks.h"
#include "PresentationChild.h"
@@ -55,16 +56,17 @@ PresentationIPCService::~PresentationIPC
NS_IMETHODIMP
PresentationIPCService::StartSession(
const nsTArray<nsString>& aUrls,
const nsAString& aSessionId,
const nsAString& aOrigin,
const nsAString& aDeviceId,
uint64_t aWindowId,
nsIDOMEventTarget* aEventTarget,
+ nsIPrincipal* aPrincipal,
nsIPresentationServiceCallback* aCallback,
nsIPresentationTransportBuilderConstructor* aBuilderConstructor)
{
if (aWindowId != 0) {
AddRespondingSessionId(aWindowId,
aSessionId,
nsIPresentationService::ROLE_CONTROLLER);
}
@@ -73,17 +75,18 @@ PresentationIPCService::StartSession(
nsGlobalWindow::GetInnerWindowWithId(aWindowId)->AsInner();
TabId tabId = TabParent::GetTabIdFrom(window->GetDocShell());
return SendRequest(aCallback, StartSessionRequest(aUrls,
nsString(aSessionId),
nsString(aOrigin),
nsString(aDeviceId),
aWindowId,
- tabId));
+ tabId,
+ IPC::Principal(aPrincipal)));
}
NS_IMETHODIMP
PresentationIPCService::SendSessionMessage(const nsAString& aSessionId,
uint8_t aRole,
const nsAString& aData)
{
MOZ_ASSERT(!aSessionId.IsEmpty());
--- a/dom/presentation/ipc/PresentationParent.cpp
+++ b/dom/presentation/ipc/PresentationParent.cpp
@@ -398,17 +398,18 @@ PresentationRequestParent::DoRequest(con
eventTarget = do_QueryInterface(tp->GetOwnerElement());
}
RefPtr<PresentationParent> parent = static_cast<PresentationParent*>(Manager());
nsCOMPtr<nsIPresentationTransportBuilderConstructor> constructor =
new PresentationTransportBuilderConstructorIPC(parent);
return mService->StartSession(aRequest.urls(), aRequest.sessionId(),
aRequest.origin(), aRequest.deviceId(),
- aRequest.windowId(), eventTarget, this, constructor);
+ aRequest.windowId(), eventTarget,
+ aRequest.principal(), this, constructor);
}
nsresult
PresentationRequestParent::DoRequest(const SendSessionMessageRequest& aRequest)
{
MOZ_ASSERT(mService);
// Validate the accessibility (primarily for receiver side) so that a