Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #import "ios/chrome/browser/payments/payment_request_manager.h" | 5 #import "ios/chrome/browser/payments/payment_request_manager.h" |
| 6 | 6 |
| 7 #include "base/ios/ios_util.h" | 7 #include "base/ios/ios_util.h" |
| 8 #import "base/ios/weak_nsobject.h" | 8 #import "base/ios/weak_nsobject.h" |
| 9 #import "base/mac/bind_objc_block.h" | 9 #import "base/mac/bind_objc_block.h" |
| 10 #include "base/mac/foundation_util.h" | 10 #include "base/mac/foundation_util.h" |
| 11 #include "base/mac/scoped_nsobject.h" | 11 #include "base/mac/scoped_nsobject.h" |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/strings/sys_string_conversions.h" | 13 #include "base/strings/sys_string_conversions.h" |
| 14 #import "base/values.h" | 14 #import "base/values.h" |
| 15 #include "components/autofill/core/browser/personal_data_manager.h" | 15 #include "components/autofill/core/browser/personal_data_manager.h" |
| 16 #include "ios/chrome/browser/autofill/personal_data_manager_factory.h" | 16 #include "ios/chrome/browser/autofill/personal_data_manager_factory.h" |
| 17 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | 17 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
| 18 #include "ios/chrome/browser/experimental_flags.h" | |
| 18 #import "ios/chrome/browser/payments/js_payment_request_manager.h" | 19 #import "ios/chrome/browser/payments/js_payment_request_manager.h" |
| 19 #import "ios/chrome/browser/payments/payment_request_coordinator.h" | 20 #import "ios/chrome/browser/payments/payment_request_coordinator.h" |
| 20 #import "ios/chrome/browser/payments/payment_request_web_state_observer.h" | 21 #import "ios/chrome/browser/payments/payment_request_web_state_observer.h" |
| 21 #include "ios/web/public/favicon_status.h" | 22 #include "ios/web/public/favicon_status.h" |
| 22 #include "ios/web/public/navigation_item.h" | 23 #include "ios/web/public/navigation_item.h" |
| 23 #include "ios/web/public/navigation_manager.h" | 24 #include "ios/web/public/navigation_manager.h" |
| 24 #include "ios/web/public/payments/payment_request.h" | 25 #include "ios/web/public/payments/payment_request.h" |
| 25 #include "ios/web/public/ssl_status.h" | 26 #include "ios/web/public/ssl_status.h" |
| 26 #import "ios/web/public/url_scheme_util.h" | 27 #import "ios/web/public/url_scheme_util.h" |
| 27 #import "ios/web/public/web_state/crw_web_view_proxy.h" | 28 #import "ios/web/public/web_state/crw_web_view_proxy.h" |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 116 | 117 |
| 117 - (void)setWebState:(web::WebState*)webState { | 118 - (void)setWebState:(web::WebState*)webState { |
| 118 [self disconnectWebState]; | 119 [self disconnectWebState]; |
| 119 if (webState) { | 120 if (webState) { |
| 120 _paymentRequestJsManager.reset( | 121 _paymentRequestJsManager.reset( |
| 121 base::mac::ObjCCastStrict<JSPaymentRequestManager>( | 122 base::mac::ObjCCastStrict<JSPaymentRequestManager>( |
| 122 [webState->GetJSInjectionReceiver() | 123 [webState->GetJSInjectionReceiver() |
| 123 instanceOfClass:[JSPaymentRequestManager class]])); | 124 instanceOfClass:[JSPaymentRequestManager class]])); |
| 124 _webState = webState; | 125 _webState = webState; |
| 125 _webStateObserver->ObserveWebState(webState); | 126 _webStateObserver->ObserveWebState(webState); |
| 126 [self enableCurrentWebState]; | |
|
marq (ping after 24h)
2017/01/11 15:09:57
Removing this call means that the payment request
Moe
2017/01/11 16:45:19
does the JS really need to be injected when switch
| |
| 127 } else { | 127 } else { |
| 128 _webState = nullptr; | 128 _webState = nullptr; |
| 129 } | 129 } |
| 130 } | 130 } |
| 131 | 131 |
| 132 - (void)enablePaymentRequest:(BOOL)enabled { | 132 - (void)enablePaymentRequest:(BOOL)enabled { |
| 133 // Asynchronously enables PaymentRequest, so that some preferences | 133 // Asynchronously enables PaymentRequest, so that some preferences |
| 134 // (UIAccessibilityIsVoiceOverRunning(), for example) have time to synchronize | 134 // (UIAccessibilityIsVoiceOverRunning(), for example) have time to synchronize |
| 135 // with their own notifications. | 135 // with their own notifications. |
| 136 base::WeakNSObject<PaymentRequestManager> weakSelf(self); | 136 base::WeakNSObject<PaymentRequestManager> weakSelf(self); |
| 137 dispatch_async(dispatch_get_main_queue(), ^{ | 137 dispatch_async(dispatch_get_main_queue(), ^{ |
| 138 [weakSelf doEnablePaymentRequest:enabled]; | 138 [weakSelf doEnablePaymentRequest:enabled]; |
| 139 }); | 139 }); |
| 140 } | 140 } |
| 141 | 141 |
| 142 - (void)doEnablePaymentRequest:(BOOL)enabled { | 142 - (void)doEnablePaymentRequest:(BOOL)enabled { |
| 143 BOOL changing = _enabled != enabled; | 143 BOOL changing = _enabled != enabled; |
| 144 if (changing) { | 144 if (changing) { |
| 145 if (!enabled) { | 145 if (!enabled) { |
| 146 [self dismissUI]; | 146 [self dismissUI]; |
| 147 } | 147 } |
| 148 _enabled = enabled; | 148 _enabled = enabled; |
| 149 [self enableCurrentWebState]; | |
|
marq (ping after 24h)
2017/01/11 15:09:57
Removing this call means that if -enablePaymentReq
Moe
2017/01/11 16:45:19
enablePaymentRequest: gets called in BrowserViewCo
| |
| 150 } | 149 } |
| 151 } | 150 } |
| 152 | 151 |
| 153 - (void)cancelRequest { | 152 - (void)cancelRequest { |
| 154 [self dismissUI]; | 153 [self dismissUI]; |
| 155 [_paymentRequestJsManager rejectRequestPromise:@"Request cancelled by user." | 154 [_paymentRequestJsManager rejectRequestPromise:@"Request cancelled by user." |
| 156 completionHandler:nil]; | 155 completionHandler:nil]; |
| 157 } | 156 } |
| 158 | 157 |
| 159 - (void)close { | 158 - (void)close { |
| 160 if (_closed) | 159 if (_closed) |
| 161 return; | 160 return; |
| 162 | 161 |
| 163 _closed = YES; | 162 _closed = YES; |
| 164 [self disableCurrentWebState]; | 163 [self disableCurrentWebState]; |
| 165 [self setWebState:nil]; | 164 [self setWebState:nil]; |
| 166 [self dismissUI]; | 165 [self dismissUI]; |
| 167 } | 166 } |
| 168 | 167 |
| 169 - (void)enableCurrentWebState { | 168 - (void)enableCurrentWebState { |
| 170 if (![self webState]) { | 169 if (![self webState] || !experimental_flags::IsPaymentRequestEnabled()) { |
|
marq (ping after 24h)
2017/01/11 15:09:57
I would prefer that the experimental flag gates cr
Moe
2017/01/11 16:45:19
I Agree. But I found no way of adding a command li
| |
| 171 return; | 170 return; |
| 172 } | 171 } |
| 173 | 172 |
| 174 if (_enabled && [self webStateContentIsSecureHTML]) { | 173 if (_enabled && [self webStateContentIsSecureHTML]) { |
| 175 if (!_webStateEnabled) { | 174 if (!_webStateEnabled) { |
| 176 base::WeakNSObject<PaymentRequestManager> weakSelf(self); | 175 base::WeakNSObject<PaymentRequestManager> weakSelf(self); |
| 177 auto callback = | 176 auto callback = |
| 178 base::BindBlock(^bool(const base::DictionaryValue& JSON, | 177 base::BindBlock(^bool(const base::DictionaryValue& JSON, |
| 179 const GURL& originURL, bool userIsInteracting) { | 178 const GURL& originURL, bool userIsInteracting) { |
| 180 base::scoped_nsobject<PaymentRequestManager> strongSelf( | 179 base::scoped_nsobject<PaymentRequestManager> strongSelf( |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 329 - (void)pageLoadedWithStatus:(web::PageLoadCompletionStatus)loadStatus { | 328 - (void)pageLoadedWithStatus:(web::PageLoadCompletionStatus)loadStatus { |
| 330 if (loadStatus != web::PageLoadCompletionStatus::SUCCESS) | 329 if (loadStatus != web::PageLoadCompletionStatus::SUCCESS) |
| 331 return; | 330 return; |
| 332 | 331 |
| 333 [self dismissUI]; | 332 [self dismissUI]; |
| 334 _isScriptInjected = NO; | 333 _isScriptInjected = NO; |
| 335 [self enableCurrentWebState]; | 334 [self enableCurrentWebState]; |
| 336 } | 335 } |
| 337 | 336 |
| 338 @end | 337 @end |
| OLD | NEW |