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 PaymentRequests.
|
2018-05-10 10:56:09 +03:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
nsresult
|
2017-09-06 09:36:24 +03:00
|
|
|
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);
|
|
|
|
nsresult AbortPayment(PaymentRequest* aRequest, bool aDeferredShow);
|
|
|
|
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,
|
2018-06-01 02:20:51 +03:00
|
|
|
PaymentRequest* aRequest,
|
2018-03-07 14:16:46 +03:00
|
|
|
const PaymentDetailsUpdate& aDetails,
|
2018-05-31 23:30:29 +03:00
|
|
|
bool aRequestShipping,
|
|
|
|
bool aDeferredShow);
|
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);
|
2017-06-14 10:59:00 +03:00
|
|
|
|
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:
|
2017-05-25 20:50:32 +03:00
|
|
|
PaymentRequestManager() = default;
|
2018-05-31 23:30:29 +03:00
|
|
|
~PaymentRequestManager()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mActivePayments.Count() == 0);
|
|
|
|
}
|
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;
|
2017-07-25 10:39:39 +03:00
|
|
|
RefPtr<PaymentRequest> mShowingRequest;
|
2017-05-25 20:50:32 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // end of namespace dom
|
|
|
|
} // end of namespace mozilla
|
|
|
|
|
|
|
|
#endif
|