Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/web_view/public/cwv_web_view.h" | 5 #import "ios/web_view/public/cwv_web_view.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #import "base/ios/weak_nsobject.h" | 10 #import "base/ios/weak_nsobject.h" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/strings/sys_string_conversions.h" | 12 #include "base/strings/sys_string_conversions.h" |
| 13 #import "ios/web/public/navigation_manager.h" | 13 #import "ios/web/public/navigation_manager.h" |
| 14 #include "ios/web/public/referrer.h" | 14 #include "ios/web/public/referrer.h" |
| 15 #include "ios/web/public/reload_type.h" | 15 #include "ios/web/public/reload_type.h" |
| 16 #import "ios/web/public/web_state/context_menu_params.h" | 16 #import "ios/web/public/web_state/context_menu_params.h" |
| 17 #import "ios/web/public/web_state/js/crw_js_injection_receiver.h" | 17 #import "ios/web/public/web_state/js/crw_js_injection_receiver.h" |
| 18 #import "ios/web/public/web_state/ui/crw_web_delegate.h" | 18 #import "ios/web/public/web_state/ui/crw_web_delegate.h" |
| 19 #import "ios/web/public/web_state/web_state.h" | 19 #import "ios/web/public/web_state/web_state.h" |
| 20 #import "ios/web/public/web_state/web_state_delegate_bridge.h" | 20 #import "ios/web/public/web_state/web_state_delegate_bridge.h" |
| 21 #import "ios/web/public/web_state/web_state_observer_bridge.h" | 21 #import "ios/web/public/web_state/web_state_observer_bridge.h" |
| 22 #import "ios/web_view/internal/cwv_html_element_internal.h" | 22 #import "ios/web_view/internal/cwv_html_element_internal.h" |
| 23 #import "ios/web_view/internal/cwv_navigation_action_internal.h" | 23 #import "ios/web_view/internal/cwv_navigation_action_internal.h" |
| 24 #import "ios/web_view/internal/cwv_web_view_configuration_internal.h" | 24 #import "ios/web_view/internal/cwv_web_view_configuration_internal.h" |
| 25 #import "ios/web_view/internal/translate/web_view_translate_client.h" | 25 #import "ios/web_view/internal/translate/web_view_translate_client.h" |
| 26 #include "ios/web_view/internal/web_view_browser_state.h" | 26 #include "ios/web_view/internal/web_view_browser_state.h" |
| 27 #import "ios/web_view/internal/web_view_java_script_dialog_presenter.h" | 27 #import "ios/web_view/internal/web_view_java_script_dialog_presenter.h" |
| 28 #import "ios/web_view/internal/web_view_web_client.h" | |
| 28 #import "ios/web_view/internal/web_view_web_state_policy_decider.h" | 29 #import "ios/web_view/internal/web_view_web_state_policy_decider.h" |
| 29 #import "ios/web_view/public/cwv_navigation_delegate.h" | 30 #import "ios/web_view/public/cwv_navigation_delegate.h" |
| 30 #import "ios/web_view/public/cwv_ui_delegate.h" | 31 #import "ios/web_view/public/cwv_ui_delegate.h" |
| 31 #import "ios/web_view/public/cwv_web_view_configuration.h" | 32 #import "ios/web_view/public/cwv_web_view_configuration.h" |
| 32 #import "net/base/mac/url_conversions.h" | 33 #import "net/base/mac/url_conversions.h" |
| 33 #include "ui/base/page_transition_types.h" | 34 #include "ui/base/page_transition_types.h" |
| 34 #include "url/gurl.h" | 35 #include "url/gurl.h" |
| 35 | 36 |
| 36 @interface CWVWebView ()<CRWWebStateDelegate, CRWWebStateObserver> { | 37 @interface CWVWebView ()<CRWWebStateDelegate, CRWWebStateObserver> { |
| 37 CWVWebViewConfiguration* _configuration; | |
| 38 std::unique_ptr<web::WebState> _webState; | 38 std::unique_ptr<web::WebState> _webState; |
| 39 std::unique_ptr<web::WebStateDelegateBridge> _webStateDelegate; | 39 std::unique_ptr<web::WebStateDelegateBridge> _webStateDelegate; |
| 40 std::unique_ptr<web::WebStateObserverBridge> _webStateObserver; | 40 std::unique_ptr<web::WebStateObserverBridge> _webStateObserver; |
| 41 std::unique_ptr<ios_web_view::WebViewWebStatePolicyDecider> | 41 std::unique_ptr<ios_web_view::WebViewWebStatePolicyDecider> |
| 42 _webStatePolicyDecider; | 42 _webStatePolicyDecider; |
| 43 double _estimatedProgress; | 43 double _estimatedProgress; |
| 44 // Handles presentation of JavaScript dialogs. | 44 // Handles presentation of JavaScript dialogs. |
| 45 std::unique_ptr<ios_web_view::WebViewJavaScriptDialogPresenter> | 45 std::unique_ptr<ios_web_view::WebViewJavaScriptDialogPresenter> |
| 46 _javaScriptDialogPresenter; | 46 _javaScriptDialogPresenter; |
| 47 } | 47 } |
| 48 | 48 |
| 49 // The configuration of the web view. | |
|
Eugene But (OOO till 7-30)
2017/04/11 17:52:41
s/The configuration of the web view/Redefine the p
michaeldo
2017/04/11 21:57:02
Done.
| |
| 50 @property(nonatomic, copy) CWVWebViewConfiguration* configuration; | |
| 49 // Redefine the property as readwrite to define -setEstimatedProgress:, which | 51 // Redefine the property as readwrite to define -setEstimatedProgress:, which |
| 50 // can be used to send KVO notification. | 52 // can be used to send KVO notification. |
| 51 @property(nonatomic, readwrite) double estimatedProgress; | 53 @property(nonatomic, readwrite) double estimatedProgress; |
| 52 | 54 |
| 53 @end | 55 @end |
| 54 | 56 |
| 55 @implementation CWVWebView | 57 @implementation CWVWebView |
| 56 | 58 |
| 57 @synthesize configuration = _configuration; | 59 @synthesize configuration = _configuration; |
| 58 @synthesize navigationDelegate = _navigationDelegate; | 60 @synthesize navigationDelegate = _navigationDelegate; |
| 59 @synthesize translationDelegate = _translationDelegate; | 61 @synthesize translationDelegate = _translationDelegate; |
| 60 @synthesize estimatedProgress = _estimatedProgress; | 62 @synthesize estimatedProgress = _estimatedProgress; |
| 61 @synthesize UIDelegate = _UIDelegate; | 63 @synthesize UIDelegate = _UIDelegate; |
| 62 | 64 |
| 65 + (void)setUserAgentProduct:(NSString*)product { | |
| 66 ios_web_view::WebViewWebClient* client = [CWVWebViewConfiguration webClient]; | |
| 67 client->SetProduct(base::SysNSStringToUTF8(product)); | |
| 68 } | |
| 69 | |
| 63 - (instancetype)initWithFrame:(CGRect)frame | 70 - (instancetype)initWithFrame:(CGRect)frame |
| 64 configuration:(CWVWebViewConfiguration*)configuration { | 71 configuration:(CWVWebViewConfiguration*)configuration { |
| 65 self = [super initWithFrame:frame]; | 72 self = [super initWithFrame:frame]; |
| 66 if (self) { | 73 if (self) { |
| 67 _configuration = [configuration copy]; | 74 _configuration = [configuration copy]; |
| 68 | 75 |
| 69 web::WebState::CreateParams webStateCreateParams( | 76 web::WebState::CreateParams webStateCreateParams( |
| 70 configuration.browserState); | 77 _configuration.browserState); |
| 71 _webState = web::WebState::Create(webStateCreateParams); | 78 _webState = web::WebState::Create(webStateCreateParams); |
| 72 _webState->SetWebUsageEnabled(true); | 79 _webState->SetWebUsageEnabled(true); |
| 73 | 80 |
| 74 _webStateObserver = | 81 _webStateObserver = |
| 75 base::MakeUnique<web::WebStateObserverBridge>(_webState.get(), self); | 82 base::MakeUnique<web::WebStateObserverBridge>(_webState.get(), self); |
| 76 _webStateDelegate = base::MakeUnique<web::WebStateDelegateBridge>(self); | 83 _webStateDelegate = base::MakeUnique<web::WebStateDelegateBridge>(self); |
| 77 _webState->SetDelegate(_webStateDelegate.get()); | 84 _webState->SetDelegate(_webStateDelegate.get()); |
| 78 | 85 |
| 79 _webStatePolicyDecider = | 86 _webStatePolicyDecider = |
| 80 base::MakeUnique<ios_web_view::WebViewWebStatePolicyDecider>( | 87 base::MakeUnique<ios_web_view::WebViewWebStatePolicyDecider>( |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 263 [_UIDelegate webViewDidClose:self]; | 270 [_UIDelegate webViewDidClose:self]; |
| 264 } | 271 } |
| 265 } | 272 } |
| 266 | 273 |
| 267 - (web::JavaScriptDialogPresenter*)javaScriptDialogPresenterForWebState: | 274 - (web::JavaScriptDialogPresenter*)javaScriptDialogPresenterForWebState: |
| 268 (web::WebState*)webState { | 275 (web::WebState*)webState { |
| 269 return _javaScriptDialogPresenter.get(); | 276 return _javaScriptDialogPresenter.get(); |
| 270 } | 277 } |
| 271 | 278 |
| 272 @end | 279 @end |
| OLD | NEW |