2017-10-27 01:08:41 +03: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: */
|
2017-05-25 20:50:32 +03: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/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_PaymentRequestManager_h
|
|
|
|
#define mozilla_dom_PaymentRequestManager_h
|
|
|
|
|
|
|
|
#include "nsISupports.h"
|
|
|
|
#include "PaymentRequest.h"
|
|
|
|
#include "mozilla/dom/PaymentRequestBinding.h"
|
2017-06-23 12:15:51 +03:00
|
|
|
#include "mozilla/dom/PaymentRequestUpdateEventBinding.h"
|
2017-06-14 10:59:00 +03:00
|
|
|
#include "mozilla/dom/PaymentResponseBinding.h"
|
2017-05-25 20:50:32 +03:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsTArray.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
class PaymentRequestChild;
|
2017-06-14 10:59:00 +03:00
|
|
|
class IPCPaymentActionRequest;
|
2017-05-25 20:50:32 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* PaymentRequestManager is a singleton used to manage the created
|
2018-05-10 10:56:09 +03:00
|
|
|
* PaymentRequests. It is also the communication agent to chrome process.
|
2017-05-25 20:50:32 +03:00
|
|
|
*/
|
|
|
|
class PaymentRequestManager final {
|
|
|
|
public:
|
|
|
|
NS_INLINE_DECL_REFCOUNTING(PaymentRequestManager)
|
|
|
|
|
|
|
|
static already_AddRefed<PaymentRequestManager> GetSingleton();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This method is used to create PaymentRequest object and send corresponding
|
|
|
|
* data to chrome process for internal payment creation, such that content
|
|
|
|
* process can ask specific task by sending requestId only.
|
|
|
|
*/
|
2017-09-06 09:36:24 +03:00
|
|
|
nsresult CreatePayment(JSContext* aCx, nsPIDOMWindowInner* aWindow,
|
2017-08-23 09:26:51 +03:00
|
|
|
nsIPrincipal* aTopLevelPrincipal,
|
2017-05-25 20:50:32 +03:00
|
|
|
const Sequence<PaymentMethodData>& aMethodData,
|
|
|
|
const PaymentDetailsInit& aDetails,
|
|
|
|
const PaymentOptions& aOptions,
|
|
|
|
PaymentRequest** aRequest);
|
|
|
|
|
2018-05-31 23:30:29 +03:00
|
|
|
nsresult CanMakePayment(PaymentRequest* aRequest);
|
|
|
|
nsresult ShowPayment(PaymentRequest* aRequest);
|
2018-11-21 13:03:21 +03:00
|
|
|
nsresult AbortPayment(PaymentRequest* aRequest);
|
2018-05-31 23:30:29 +03:00
|
|
|
nsresult CompletePayment(PaymentRequest* aRequest,
|
2018-05-29 12:31:22 +03:00
|
|
|
const PaymentComplete& aComplete,
|
|
|
|
bool aTimedOut = false);
|
2017-09-06 09:36:24 +03:00
|
|
|
nsresult UpdatePayment(JSContext* aCx, PaymentRequest* aRequest,
|
2018-03-07 14:16:46 +03:00
|
|
|
const PaymentDetailsUpdate& aDetails,
|
2018-11-21 13:03:21 +03:00
|
|
|
bool aRequestShipping);
|
2018-08-16 15:27:24 +03:00
|
|
|
nsresult ClosePayment(PaymentRequest* aRequest);
|
2018-09-04 13:28:40 +03:00
|
|
|
nsresult RetryPayment(JSContext* aCx, PaymentRequest* aRequest,
|
|
|
|
const PaymentValidationErrors& aErrors);
|
2017-06-14 10:59:00 +03:00
|
|
|
|
2018-06-01 02:20:51 +03:00
|
|
|
nsresult RespondPayment(PaymentRequest* aRequest,
|
|
|
|
const IPCPaymentActionResponse& aResponse);
|
|
|
|
nsresult ChangeShippingAddress(PaymentRequest* aRequest,
|
2017-06-23 12:15:51 +03:00
|
|
|
const IPCPaymentAddress& aAddress);
|
2018-06-01 02:20:51 +03:00
|
|
|
nsresult ChangeShippingOption(PaymentRequest* aRequest,
|
2017-06-23 12:15:51 +03:00
|
|
|
const nsAString& aOption);
|
2018-09-19 14:23:33 +03:00
|
|
|
nsresult ChangePayerDetail(PaymentRequest* aRequest,
|
|
|
|
const nsAString& aPayerName,
|
|
|
|
const nsAString& aPayerEmail,
|
|
|
|
const nsAString& aPayerPhone);
|
2018-11-27 16:05:00 +03:00
|
|
|
nsresult ChangePaymentMethod(PaymentRequest* aRequest,
|
|
|
|
const nsAString& aMethodName,
|
|
|
|
const IPCMethodChangeDetails& aMethodDetails);
|
2018-09-19 14:23:33 +03:00
|
|
|
|
2018-11-14 01:59:00 +03:00
|
|
|
bool IsRegionSupported(const nsAString& region) const;
|
|
|
|
|
2018-06-20 01:55:32 +03:00
|
|
|
// Called to ensure that we don't "leak" aRequest if we shut down while it had
|
|
|
|
// an active request to the parent.
|
|
|
|
void RequestIPCOver(PaymentRequest* aRequest);
|
|
|
|
|
2017-06-14 10:59:00 +03:00
|
|
|
private:
|
2018-11-14 01:59:00 +03:00
|
|
|
PaymentRequestManager();
|
|
|
|
~PaymentRequestManager();
|
2017-05-25 20:50:32 +03:00
|
|
|
|
2018-05-31 23:30:29 +03:00
|
|
|
PaymentRequestChild* GetPaymentChild(PaymentRequest* aRequest);
|
2017-05-25 20:50:32 +03:00
|
|
|
|
2017-06-14 10:59:00 +03:00
|
|
|
nsresult SendRequestPayment(PaymentRequest* aRequest,
|
|
|
|
const IPCPaymentActionRequest& action,
|
2018-05-31 23:30:29 +03:00
|
|
|
bool aResponseExpected = true);
|
|
|
|
|
|
|
|
void NotifyRequestDone(PaymentRequest* aRequest);
|
2017-06-14 10:59:00 +03:00
|
|
|
|
2018-05-31 23:30:29 +03:00
|
|
|
// Strong pointer to requests with ongoing IPC messages to the parent.
|
|
|
|
nsDataHashtable<nsRefPtrHashKey<PaymentRequest>, uint32_t> mActivePayments;
|
2018-11-14 01:59:00 +03:00
|
|
|
|
|
|
|
nsTArray<nsString> mSupportedRegions;
|
2017-05-25 20:50:32 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // end of namespace dom
|
|
|
|
} // end of namespace mozilla
|
|
|
|
|
|
|
|
#endif
|