Chromium Code Reviews| 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 #include "components/payments/content/payment_request_web_contents_manager.h" | 5 #include "components/payments/content/payment_request_web_contents_manager.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "components/payments/content/payment_request.h" | 11 #include "components/payments/content/payment_request.h" |
| 12 #include "components/payments/core/payment_request_delegate.h" | 12 #include "components/payments/core/payment_request_delegate.h" |
| 13 #include "content/public/browser/navigation_handle.h" | |
| 13 #include "content/public/browser/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
| 14 | 15 |
| 15 DEFINE_WEB_CONTENTS_USER_DATA_KEY(payments::PaymentRequestWebContentsManager); | 16 DEFINE_WEB_CONTENTS_USER_DATA_KEY(payments::PaymentRequestWebContentsManager); |
| 16 | 17 |
| 17 namespace payments { | 18 namespace payments { |
| 18 | 19 |
| 19 PaymentRequestWebContentsManager::~PaymentRequestWebContentsManager() {} | 20 PaymentRequestWebContentsManager::~PaymentRequestWebContentsManager() {} |
| 20 | 21 |
| 21 PaymentRequestWebContentsManager* | 22 PaymentRequestWebContentsManager* |
| 22 PaymentRequestWebContentsManager::GetOrCreateForWebContents( | 23 PaymentRequestWebContentsManager::GetOrCreateForWebContents( |
| 23 content::WebContents* web_contents) { | 24 content::WebContents* web_contents) { |
| 24 DCHECK(web_contents); | 25 DCHECK(web_contents); |
| 25 // CreateForWebContents does nothing if the manager instance already exists. | 26 // CreateForWebContents does nothing if the manager instance already exists. |
| 26 PaymentRequestWebContentsManager::CreateForWebContents(web_contents); | 27 PaymentRequestWebContentsManager::CreateForWebContents(web_contents); |
| 27 return PaymentRequestWebContentsManager::FromWebContents(web_contents); | 28 return PaymentRequestWebContentsManager::FromWebContents(web_contents); |
| 28 } | 29 } |
| 29 | 30 |
| 30 void PaymentRequestWebContentsManager::CreatePaymentRequest( | 31 void PaymentRequestWebContentsManager::CreatePaymentRequest( |
| 31 content::WebContents* web_contents, | 32 content::WebContents* web_contents, |
| 32 std::unique_ptr<PaymentRequestDelegate> delegate, | 33 std::unique_ptr<PaymentRequestDelegate> delegate, |
| 33 mojo::InterfaceRequest<payments::mojom::PaymentRequest> request, | 34 mojo::InterfaceRequest<payments::mojom::PaymentRequest> request, |
| 34 PaymentRequest::ObserverForTest* observer_for_testing) { | 35 PaymentRequest::ObserverForTest* observer_for_testing) { |
| 35 auto new_request = base::MakeUnique<PaymentRequest>( | 36 auto new_request = base::MakeUnique<PaymentRequest>( |
| 36 web_contents, std::move(delegate), this, std::move(request), | 37 web_contents, std::move(delegate), this, std::move(request), |
| 37 observer_for_testing); | 38 observer_for_testing); |
| 38 PaymentRequest* request_ptr = new_request.get(); | 39 PaymentRequest* request_ptr = new_request.get(); |
| 39 payment_requests_.insert(std::make_pair(request_ptr, std::move(new_request))); | 40 payment_requests_.insert(std::make_pair(request_ptr, std::move(new_request))); |
| 40 } | 41 } |
| 41 | 42 |
| 43 void PaymentRequestWebContentsManager::DidStartNavigation( | |
| 44 content::NavigationHandle* navigation_handle) { | |
| 45 for (auto& it : payment_requests_) { | |
|
Mathieu
2017/05/09 18:12:19
PaymentRequest& ?
sebsg
2017/05/10 14:58:48
the elements are std::pair<PaymentRequest*, std::u
| |
| 46 // Since the PaymentRequest dialog blocks the content of the page, the user | |
| 47 // cannot click on a link to navigate away. Therefore, if the navigation | |
| 48 // is initiated in the renderer, it does not come from the user. | |
| 49 it.second->NavigatedAway(!navigation_handle->IsRendererInitiated()); | |
| 50 } | |
| 51 } | |
| 52 | |
| 42 void PaymentRequestWebContentsManager::DestroyRequest(PaymentRequest* request) { | 53 void PaymentRequestWebContentsManager::DestroyRequest(PaymentRequest* request) { |
| 43 payment_requests_.erase(request); | 54 payment_requests_.erase(request); |
| 44 } | 55 } |
| 45 | 56 |
| 46 PaymentRequestWebContentsManager::PaymentRequestWebContentsManager( | 57 PaymentRequestWebContentsManager::PaymentRequestWebContentsManager( |
| 47 content::WebContents* web_contents) {} | 58 content::WebContents* web_contents) |
| 59 : content::WebContentsObserver(web_contents) {} | |
| 48 | 60 |
| 49 } // namespace payments | 61 } // namespace payments |
| OLD | NEW |