| 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 <map> |
| 8 #include <memory> | 9 #include <memory> |
| 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.h" |
| 13 #include "components/payments/mojom/payment_request.mojom.h" | 13 #include "components/payments/mojom/payment_request.mojom.h" |
| 14 #include "content/public/browser/web_contents_user_data.h" | 14 #include "content/public/browser/web_contents_user_data.h" |
| 15 #include "mojo/public/cpp/bindings/binding.h" | 15 #include "mojo/public/cpp/bindings/binding.h" |
| 16 | 16 |
| 17 namespace content { | 17 namespace content { |
| 18 class WebContents; | 18 class WebContents; |
| 19 } | 19 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 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 PaymentRequest::ObserverForTest* observer_for_testing); |
| 49 | 49 |
| 50 // Destroys the given |request|. | 50 // Destroys the given |request|. |
| 51 void DestroyRequest(PaymentRequest* request); | 51 void DestroyRequest(PaymentRequest* request); |
| 52 | 52 |
| 53 // Called when |request| has received the show() call. If the |request| can be |
| 54 // shown, then returns true and assumes that |request| is now showing until |
| 55 // DestroyRequest(|request|) is called with the same pointer. (Only one |
| 56 // request at a time can be shown per tab.) |
| 57 bool CanShow(PaymentRequest* request); |
| 58 |
| 53 private: | 59 private: |
| 54 explicit PaymentRequestWebContentsManager(content::WebContents* web_contents); | 60 explicit PaymentRequestWebContentsManager(content::WebContents* web_contents); |
| 55 friend class content::WebContentsUserData<PaymentRequestWebContentsManager>; | 61 friend class content::WebContentsUserData<PaymentRequestWebContentsManager>; |
| 56 friend class PaymentRequestBrowserTestBase; | 62 friend class PaymentRequestBrowserTestBase; |
| 57 | 63 |
| 58 // Owns all the PaymentRequest for this WebContents. Since the | 64 // Owns all the PaymentRequest for this WebContents. Since the |
| 59 // PaymentRequestWebContentsManager's lifetime is tied to the WebContents, | 65 // PaymentRequestWebContentsManager's lifetime is tied to the WebContents, |
| 60 // these requests only get destroyed when the WebContents goes away, or when | 66 // these requests only get destroyed when the WebContents goes away, or when |
| 61 // the requests themselves call DestroyRequest(). | 67 // the requests themselves call DestroyRequest(). |
| 62 std::unordered_map<PaymentRequest*, std::unique_ptr<PaymentRequest>> | 68 std::map<PaymentRequest*, std::unique_ptr<PaymentRequest>> payment_requests_; |
| 63 payment_requests_; | 69 |
| 70 // The currently displayed instance of PaymentRequest. Points to one of the |
| 71 // elements in |payment_requests_|. Can be null. |
| 72 PaymentRequest* showing_; |
| 64 | 73 |
| 65 DISALLOW_COPY_AND_ASSIGN(PaymentRequestWebContentsManager); | 74 DISALLOW_COPY_AND_ASSIGN(PaymentRequestWebContentsManager); |
| 66 }; | 75 }; |
| 67 | 76 |
| 68 } // namespace payments | 77 } // namespace payments |
| 69 | 78 |
| 70 #endif // COMPONENTS_PAYMENTS_PAYMENT_REQUEST_WEB_CONTENTS_MANAGER_H_ | 79 #endif // COMPONENTS_PAYMENTS_PAYMENT_REQUEST_WEB_CONTENTS_MANAGER_H_ |
| OLD | NEW |