| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef COMPONENTS_PAYMENTS_PAYMENT_REQUEST_WEB_CONTENTS_MANAGER_H_ | 5 #ifndef COMPONENTS_PAYMENTS_PAYMENT_REQUEST_WEB_CONTENTS_MANAGER_H_ |
| 6 #define COMPONENTS_PAYMENTS_PAYMENT_REQUEST_WEB_CONTENTS_MANAGER_H_ | 6 #define COMPONENTS_PAYMENTS_PAYMENT_REQUEST_WEB_CONTENTS_MANAGER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <unordered_map> | 9 #include <unordered_map> |
| 10 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "components/payments/content/payment_request.h" |
| 12 #include "components/payments/content/payment_request.mojom.h" | 13 #include "components/payments/content/payment_request.mojom.h" |
| 13 #include "content/public/browser/web_contents_user_data.h" | 14 #include "content/public/browser/web_contents_user_data.h" |
| 14 #include "mojo/public/cpp/bindings/binding.h" | 15 #include "mojo/public/cpp/bindings/binding.h" |
| 15 | 16 |
| 16 namespace content { | 17 namespace content { |
| 17 class WebContents; | 18 class WebContents; |
| 18 } | 19 } |
| 19 | 20 |
| 20 namespace payments { | 21 namespace payments { |
| 21 | 22 |
| 22 class PaymentRequest; | |
| 23 class PaymentRequestDelegate; | 23 class PaymentRequestDelegate; |
| 24 | 24 |
| 25 // This class owns the PaymentRequest associated with a given WebContents. | 25 // This class owns the PaymentRequest associated with a given WebContents. |
| 26 // | 26 // |
| 27 // Responsible for creating PaymentRequest's and retaining ownership. No request | 27 // Responsible for creating PaymentRequest's and retaining ownership. No request |
| 28 // pointers are currently available because the request manages its interactions | 28 // pointers are currently available because the request manages its interactions |
| 29 // with UI and renderer. The PaymentRequest may call DestroyRequest() to signal | 29 // with UI and renderer. The PaymentRequest may call DestroyRequest() to signal |
| 30 // it is ready to die. Otherwise it gets destroyed when the WebContents (thus | 30 // it is ready to die. Otherwise it gets destroyed when the WebContents (thus |
| 31 // this class) goes away. | 31 // this class) goes away. |
| 32 class PaymentRequestWebContentsManager | 32 class PaymentRequestWebContentsManager |
| 33 : public content::WebContentsUserData<PaymentRequestWebContentsManager> { | 33 : public content::WebContentsUserData<PaymentRequestWebContentsManager> { |
| 34 public: | 34 public: |
| 35 ~PaymentRequestWebContentsManager() override; | 35 ~PaymentRequestWebContentsManager() override; |
| 36 | 36 |
| 37 // Retrieves the instance of PaymentRequestWebContentsManager that was | 37 // Retrieves the instance of PaymentRequestWebContentsManager that was |
| 38 // attached to the specified WebContents. If no instance was attached, | 38 // attached to the specified WebContents. If no instance was attached, |
| 39 // creates one, and attaches it to the specified WebContents. | 39 // creates one, and attaches it to the specified WebContents. |
| 40 static PaymentRequestWebContentsManager* GetOrCreateForWebContents( | 40 static PaymentRequestWebContentsManager* GetOrCreateForWebContents( |
| 41 content::WebContents* web_contents); | 41 content::WebContents* web_contents); |
| 42 | 42 |
| 43 // Creates the PaymentRequest that will interact with this |web_contents|. | 43 // Creates the PaymentRequest that will interact with this |web_contents|. |
| 44 void CreatePaymentRequest( | 44 void CreatePaymentRequest( |
| 45 content::WebContents* web_contents, | 45 content::WebContents* web_contents, |
| 46 std::unique_ptr<PaymentRequestDelegate> delegate, | 46 std::unique_ptr<PaymentRequestDelegate> delegate, |
| 47 mojo::InterfaceRequest<payments::mojom::PaymentRequest> request); | 47 mojo::InterfaceRequest<payments::mojom::PaymentRequest> request, |
| 48 PaymentRequest::ObserverForTest* observer_for_testing); |
| 48 | 49 |
| 49 // Destroys the given |request|. | 50 // Destroys the given |request|. |
| 50 void DestroyRequest(PaymentRequest* request); | 51 void DestroyRequest(PaymentRequest* request); |
| 51 | 52 |
| 52 private: | 53 private: |
| 53 explicit PaymentRequestWebContentsManager(content::WebContents* web_contents); | 54 explicit PaymentRequestWebContentsManager(content::WebContents* web_contents); |
| 54 friend class content::WebContentsUserData<PaymentRequestWebContentsManager>; | 55 friend class content::WebContentsUserData<PaymentRequestWebContentsManager>; |
| 55 friend class PaymentRequestBrowserTestBase; | 56 friend class PaymentRequestBrowserTestBase; |
| 56 | 57 |
| 57 // Owns all the PaymentRequest for this WebContents. Since the | 58 // Owns all the PaymentRequest for this WebContents. Since the |
| 58 // PaymentRequestWebContentsManager's lifetime is tied to the WebContents, | 59 // PaymentRequestWebContentsManager's lifetime is tied to the WebContents, |
| 59 // these requests only get destroyed when the WebContents goes away, or when | 60 // these requests only get destroyed when the WebContents goes away, or when |
| 60 // the requests themselves call DestroyRequest(). | 61 // the requests themselves call DestroyRequest(). |
| 61 std::unordered_map<PaymentRequest*, std::unique_ptr<PaymentRequest>> | 62 std::unordered_map<PaymentRequest*, std::unique_ptr<PaymentRequest>> |
| 62 payment_requests_; | 63 payment_requests_; |
| 63 | 64 |
| 64 DISALLOW_COPY_AND_ASSIGN(PaymentRequestWebContentsManager); | 65 DISALLOW_COPY_AND_ASSIGN(PaymentRequestWebContentsManager); |
| 65 }; | 66 }; |
| 66 | 67 |
| 67 } // namespace payments | 68 } // namespace payments |
| 68 | 69 |
| 69 #endif // COMPONENTS_PAYMENTS_PAYMENT_REQUEST_WEB_CONTENTS_MANAGER_H_ | 70 #endif // COMPONENTS_PAYMENTS_PAYMENT_REQUEST_WEB_CONTENTS_MANAGER_H_ |
| OLD | NEW |