Bug 1383293 - Add a new readonly attribute topLevelPrincipal in nsIPaymentRequest for UI support. r=baku

Getting the top level document's principal when constructing PaymentRequest,
then sending it to chrome process and saving it in nsIPaymentRequest.
Creating a new readonly attribute nsIPrincipal topLevelPrincipal in
nsIPaymentRequest for UI to query the top level document's principal
information.
This commit is contained in:
Eden Chuang 2017-08-23 14:26:51 +08:00
parent a1974f1238
commit 34196fb87f
12 changed files with 55 additions and 3 deletions

View File

@ -61,6 +61,11 @@ interface nsIPaymentCreateActionRequest : nsIPaymentActionRequest
*/
readonly attribute uint64_t tabId;
/*
* The top level document's principal
*/
readonly attribute nsIPrincipal topLevelPrincipal;
/*
* The methodData information of the payment request.
*/
@ -82,6 +87,7 @@ interface nsIPaymentCreateActionRequest : nsIPaymentActionRequest
void initRequest(in AString aRequestId,
in nsIPaymentActionCallback aCallback,
in uint64_t aTabId,
in nsIPrincipal aPrincipal,
in nsIArray aMethodData,
in nsIPaymentDetails aDetails,
in nsIPaymentOptions aOptions);

View File

@ -5,6 +5,7 @@
#include "nsISupports.idl"
#include "nsIVariant.idl"
#include "nsIPrincipal.idl"
interface nsIArray;
@ -77,6 +78,7 @@ interface nsIPaymentOptions : nsISupports
interface nsIPaymentRequest : nsISupports
{
readonly attribute uint64_t tabId;
readonly attribute nsIPrincipal topLevelPrincipal;
readonly attribute AString requestId;
readonly attribute nsIArray paymentMethods;
readonly attribute nsIPaymentDetails paymentDetails;

View File

@ -74,11 +74,13 @@ NS_IMETHODIMP
PaymentCreateActionRequest::InitRequest(const nsAString& aRequestId,
nsIPaymentActionCallback* aCallback,
const uint64_t aTabId,
nsIPrincipal* aTopLevelPrincipal,
nsIArray* aMethodData,
nsIPaymentDetails* aDetails,
nsIPaymentOptions* aOptions)
{
NS_ENSURE_ARG_POINTER(aCallback);
NS_ENSURE_ARG_POINTER(aTopLevelPrincipal);
NS_ENSURE_ARG_POINTER(aMethodData);
NS_ENSURE_ARG_POINTER(aDetails);
NS_ENSURE_ARG_POINTER(aOptions);
@ -87,6 +89,7 @@ PaymentCreateActionRequest::InitRequest(const nsAString& aRequestId,
return rv;
}
mTabId = aTabId;
mTopLevelPrincipal = aTopLevelPrincipal;
mMethodData = aMethodData;
mDetails = aDetails;
mOptions = aOptions;
@ -101,6 +104,16 @@ PaymentCreateActionRequest::GetTabId(uint64_t* aTabId)
return NS_OK;
}
NS_IMETHODIMP
PaymentCreateActionRequest::GetTopLevelPrincipal(nsIPrincipal** aTopLevelPrincipal)
{
NS_ENSURE_ARG_POINTER(aTopLevelPrincipal);
MOZ_ASSERT(mTopLevelPrincipal);
nsCOMPtr<nsIPrincipal> principal = mTopLevelPrincipal;
principal.forget(aTopLevelPrincipal);
return NS_OK;
}
NS_IMETHODIMP
PaymentCreateActionRequest::GetMethodData(nsIArray** aMethodData)
{

View File

@ -45,6 +45,7 @@ private:
~PaymentCreateActionRequest() = default;
uint64_t mTabId;
nsCOMPtr<nsIPrincipal> mTopLevelPrincipal;
nsCOMPtr<nsIArray> mMethodData;
nsCOMPtr<nsIPaymentDetails> mDetails;
nsCOMPtr<nsIPaymentOptions> mOptions;

View File

@ -256,6 +256,8 @@ PaymentRequest::Constructor(const GlobalObject& aGlobal,
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
nsCOMPtr<nsIPrincipal> topLevelPrincipal;
do {
nsINode* parentNode = nsContentUtils::GetCrossDocParentNode(node);
if (parentNode) {
@ -269,6 +271,7 @@ PaymentRequest::Constructor(const GlobalObject& aGlobal,
}
}
}
topLevelPrincipal = node->NodePrincipal();
node = parentNode;
} while (node);
@ -289,8 +292,8 @@ PaymentRequest::Constructor(const GlobalObject& aGlobal,
// Create PaymentRequest and set its |mId|
RefPtr<PaymentRequest> request;
nsresult rv = manager->CreatePayment(window, aMethodData, aDetails,
aOptions, getter_AddRefs(request));
nsresult rv = manager->CreatePayment(window, topLevelPrincipal, aMethodData,
aDetails, aOptions, getter_AddRefs(request));
if (NS_WARN_IF(NS_FAILED(rv))) {
aRv.Throw(NS_ERROR_DOM_TYPE_ERR);
return nullptr;

View File

@ -590,11 +590,13 @@ NS_IMPL_ISUPPORTS(PaymentRequest,
PaymentRequest::PaymentRequest(const uint64_t aTabId,
const nsAString& aRequestId,
nsIPrincipal* aTopLevelPrincipal,
nsIArray* aPaymentMethods,
nsIPaymentDetails* aPaymentDetails,
nsIPaymentOptions* aPaymentOptions)
: mTabId(aTabId)
, mRequestId(aRequestId)
, mTopLevelPrincipal(aTopLevelPrincipal)
, mPaymentMethods(aPaymentMethods)
, mPaymentDetails(aPaymentDetails)
, mPaymentOptions(aPaymentOptions)
@ -609,6 +611,16 @@ PaymentRequest::GetTabId(uint64_t* aTabId)
return NS_OK;
}
NS_IMETHODIMP
PaymentRequest::GetTopLevelPrincipal(nsIPrincipal** aTopLevelPrincipal)
{
NS_ENSURE_ARG_POINTER(aTopLevelPrincipal);
MOZ_ASSERT(mTopLevelPrincipal);
nsCOMPtr<nsIPrincipal> principal = mTopLevelPrincipal;
principal.forget(aTopLevelPrincipal);
return NS_OK;
}
NS_IMETHODIMP
PaymentRequest::GetRequestId(nsAString& aRequestId)
{

View File

@ -179,6 +179,7 @@ public:
PaymentRequest(const uint64_t aTabId,
const nsAString& aRequestId,
nsIPrincipal* aPrincipal,
nsIArray* aPaymentMethods,
nsIPaymentDetails* aPaymentDetails,
nsIPaymentOptions* aPaymentOptions);
@ -188,6 +189,7 @@ private:
uint64_t mTabId;
nsString mRequestId;
nsCOMPtr<nsIPrincipal> mTopLevelPrincipal;
nsCOMPtr<nsIArray> mPaymentMethods;
nsCOMPtr<nsIPaymentDetails> mPaymentDetails;
nsCOMPtr<nsIPaymentOptions> mPaymentOptions;

View File

@ -12,6 +12,7 @@
#include "mozilla/dom/PaymentRequestChild.h"
#include "nsContentUtils.h"
#include "nsString.h"
#include "nsIPrincipal.h"
namespace mozilla {
namespace dom {
@ -390,6 +391,7 @@ GetSelectedShippingOption(const PaymentDetailsInit& aDetails,
nsresult
PaymentRequestManager::CreatePayment(nsPIDOMWindowInner* aWindow,
nsIPrincipal* aTopLevelPrincipal,
const Sequence<PaymentMethodData>& aMethodData,
const PaymentDetailsInit& aDetails,
const PaymentOptions& aOptions,
@ -397,6 +399,7 @@ PaymentRequestManager::CreatePayment(nsPIDOMWindowInner* aWindow,
{
MOZ_ASSERT(NS_IsMainThread());
NS_ENSURE_ARG_POINTER(aRequest);
NS_ENSURE_ARG_POINTER(aTopLevelPrincipal);
*aRequest = nullptr;
nsresult rv;
@ -460,6 +463,7 @@ PaymentRequestManager::CreatePayment(nsPIDOMWindowInner* aWindow,
ConvertOptions(aOptions, options);
IPCPaymentCreateActionRequest action(internalId,
IPC::Principal(aTopLevelPrincipal),
methodData,
details,
options);

View File

@ -42,6 +42,7 @@ public:
*/
nsresult
CreatePayment(nsPIDOMWindowInner* aWindow,
nsIPrincipal* aTopLevelPrincipal,
const Sequence<PaymentMethodData>& aMethodData,
const PaymentDetailsInit& aDetails,
const PaymentOptions& aOptions,

View File

@ -237,6 +237,10 @@ PaymentRequestService::RequestPayment(nsIPaymentActionRequest* aRequest)
rv = request->GetTabId(&tabId);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIPrincipal> topLevelPrincipal;
rv = request->GetTopLevelPrincipal(getter_AddRefs(topLevelPrincipal));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIArray> methodData;
rv = request->GetMethodData(getter_AddRefs(methodData));
NS_ENSURE_SUCCESS(rv, rv);
@ -250,7 +254,8 @@ PaymentRequestService::RequestPayment(nsIPaymentActionRequest* aRequest)
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIPaymentRequest> payment =
new payments::PaymentRequest(tabId, requestId, methodData, details, options);
new payments::PaymentRequest(tabId, requestId, topLevelPrincipal,
methodData, details, options);
if (!mRequestQueue.AppendElement(payment, mozilla::fallible)) {
return NS_ERROR_OUT_OF_MEMORY;

View File

@ -5,6 +5,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
include protocol PBrowser;
using class IPC::Principal from "mozilla/dom/PermissionMessageUtils.h";
namespace mozilla {
namespace dom {
@ -70,6 +71,7 @@ struct IPCPaymentOptions
struct IPCPaymentCreateActionRequest
{
nsString requestId;
Principal topLevelPrincipal;
IPCPaymentMethodData[] methodData;
IPCPaymentDetails details;
IPCPaymentOptions options;

View File

@ -73,6 +73,7 @@ PaymentRequestParent::RecvRequestPayment(const IPCPaymentActionRequest& aRequest
rv = createAction->InitRequest(request.requestId(),
callback,
mTabId,
request.topLevelPrincipal(),
methodData,
details,
options);