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 #include "google_apis/google_api_keys.h" | 13 #include "google_apis/google_api_keys.h" |
| 14 #import "ios/web/public/navigation_manager.h" | 14 #import "ios/web/public/navigation_manager.h" |
| 15 #include "ios/web/public/referrer.h" | 15 #include "ios/web/public/referrer.h" |
| 16 #include "ios/web/public/reload_type.h" | 16 #include "ios/web/public/reload_type.h" |
| 17 #import "ios/web/public/web_state/context_menu_params.h" | 17 #import "ios/web/public/web_state/context_menu_params.h" |
| 18 #import "ios/web/public/web_state/js/crw_js_injection_receiver.h" | 18 #import "ios/web/public/web_state/js/crw_js_injection_receiver.h" |
| 19 #import "ios/web/public/web_state/ui/crw_web_delegate.h" | 19 #import "ios/web/public/web_state/ui/crw_web_delegate.h" |
| 20 #import "ios/web/public/web_state/web_state.h" | 20 #import "ios/web/public/web_state/web_state.h" |
| 21 #import "ios/web/public/web_state/web_state_delegate_bridge.h" | 21 #import "ios/web/public/web_state/web_state_delegate_bridge.h" |
| 22 #import "ios/web/public/web_state/web_state_observer_bridge.h" | 22 #import "ios/web/public/web_state/web_state_observer_bridge.h" |
| 23 #import "ios/web_view/internal/cwv_html_element_internal.h" | 23 #import "ios/web_view/internal/cwv_html_element_internal.h" |
| 24 #import "ios/web_view/internal/cwv_navigation_action_internal.h" | 24 #import "ios/web_view/internal/cwv_navigation_action_internal.h" |
| 25 #import "ios/web_view/internal/cwv_web_view_configuration_internal.h" | 25 #import "ios/web_view/internal/cwv_web_view_configuration_internal.h" |
| 26 #import "ios/web_view/internal/translate/cwv_translation_controller_internal.h" | |
| 26 #import "ios/web_view/internal/translate/web_view_translate_client.h" | 27 #import "ios/web_view/internal/translate/web_view_translate_client.h" |
| 27 #include "ios/web_view/internal/web_view_browser_state.h" | 28 #include "ios/web_view/internal/web_view_browser_state.h" |
| 28 #import "ios/web_view/internal/web_view_java_script_dialog_presenter.h" | 29 #import "ios/web_view/internal/web_view_java_script_dialog_presenter.h" |
| 29 #import "ios/web_view/internal/web_view_web_state_policy_decider.h" | 30 #import "ios/web_view/internal/web_view_web_state_policy_decider.h" |
| 30 #import "ios/web_view/public/cwv_navigation_delegate.h" | 31 #import "ios/web_view/public/cwv_navigation_delegate.h" |
| 31 #import "ios/web_view/public/cwv_ui_delegate.h" | 32 #import "ios/web_view/public/cwv_ui_delegate.h" |
| 32 #import "ios/web_view/public/cwv_web_view_configuration.h" | 33 #import "ios/web_view/public/cwv_web_view_configuration.h" |
| 33 #import "net/base/mac/url_conversions.h" | 34 #import "net/base/mac/url_conversions.h" |
| 34 #include "ui/base/page_transition_types.h" | 35 #include "ui/base/page_transition_types.h" |
| 35 #include "url/gurl.h" | 36 #include "url/gurl.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 @property(nonatomic, readwrite) double estimatedProgress; | 76 @property(nonatomic, readwrite) double estimatedProgress; |
| 76 | 77 |
| 77 @end | 78 @end |
| 78 | 79 |
| 79 static NSString* gUserAgentProduct = nil; | 80 static NSString* gUserAgentProduct = nil; |
| 80 | 81 |
| 81 @implementation CWVWebView | 82 @implementation CWVWebView |
| 82 | 83 |
| 83 @synthesize configuration = _configuration; | 84 @synthesize configuration = _configuration; |
| 84 @synthesize navigationDelegate = _navigationDelegate; | 85 @synthesize navigationDelegate = _navigationDelegate; |
| 85 @synthesize translationDelegate = _translationDelegate; | |
| 86 @synthesize estimatedProgress = _estimatedProgress; | 86 @synthesize estimatedProgress = _estimatedProgress; |
| 87 @synthesize UIDelegate = _UIDelegate; | 87 @synthesize UIDelegate = _UIDelegate; |
| 88 @synthesize translationController = _translationController; | |
|
michaeldo
2017/05/01 18:25:36
Please move up to sort alphabetically.
jzw1
2017/05/08 03:36:27
Done.
| |
| 88 | 89 |
| 89 + (NSString*)userAgentProduct { | 90 + (NSString*)userAgentProduct { |
| 90 return gUserAgentProduct; | 91 return gUserAgentProduct; |
| 91 } | 92 } |
| 92 | 93 |
| 93 + (void)setUserAgentProduct:(NSString*)product { | 94 + (void)setUserAgentProduct:(NSString*)product { |
| 94 gUserAgentProduct = [product copy]; | 95 gUserAgentProduct = [product copy]; |
| 95 } | 96 } |
| 96 | 97 |
| 97 + (void)setGoogleAPIKey:(NSString*)googleAPIKey | 98 + (void)setGoogleAPIKey:(NSString*)googleAPIKey |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 180 [_webState->GetJSInjectionReceiver() executeJavaScript:javaScriptString | 181 [_webState->GetJSInjectionReceiver() executeJavaScript:javaScriptString |
| 181 completionHandler:completionHandler]; | 182 completionHandler:completionHandler]; |
| 182 } | 183 } |
| 183 | 184 |
| 184 - (void)setUIDelegate:(id<CWVUIDelegate>)UIDelegate { | 185 - (void)setUIDelegate:(id<CWVUIDelegate>)UIDelegate { |
| 185 _UIDelegate = UIDelegate; | 186 _UIDelegate = UIDelegate; |
| 186 | 187 |
| 187 _javaScriptDialogPresenter->SetUIDelegate(_UIDelegate); | 188 _javaScriptDialogPresenter->SetUIDelegate(_UIDelegate); |
| 188 } | 189 } |
| 189 | 190 |
| 190 - (void)setTranslationDelegate:(id<CWVTranslateDelegate>)translationDelegate { | |
| 191 _translationDelegate = translationDelegate; | |
| 192 ios_web_view::WebViewTranslateClient::FromWebState(_webState.get()) | |
| 193 ->set_translate_delegate(translationDelegate); | |
| 194 } | |
| 195 | |
| 196 // ----------------------------------------------------------------------- | 191 // ----------------------------------------------------------------------- |
| 197 // WebStateObserver implementation. | 192 // WebStateObserver implementation. |
| 198 | 193 |
| 199 - (void)webState:(web::WebState*)webState | 194 - (void)webState:(web::WebState*)webState |
| 200 didStartProvisionalNavigationForURL:(const GURL&)URL { | 195 didStartProvisionalNavigationForURL:(const GURL&)URL { |
| 201 SEL selector = @selector(webViewDidStartProvisionalNavigation:); | 196 SEL selector = @selector(webViewDidStartProvisionalNavigation:); |
| 202 if ([_navigationDelegate respondsToSelector:selector]) { | 197 if ([_navigationDelegate respondsToSelector:selector]) { |
| 203 [_navigationDelegate webViewDidStartProvisionalNavigation:self]; | 198 [_navigationDelegate webViewDidStartProvisionalNavigation:self]; |
| 204 } | 199 } |
| 205 } | 200 } |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 283 if ([_UIDelegate respondsToSelector:selector]) { | 278 if ([_UIDelegate respondsToSelector:selector]) { |
| 284 [_UIDelegate webViewDidClose:self]; | 279 [_UIDelegate webViewDidClose:self]; |
| 285 } | 280 } |
| 286 } | 281 } |
| 287 | 282 |
| 288 - (web::JavaScriptDialogPresenter*)javaScriptDialogPresenterForWebState: | 283 - (web::JavaScriptDialogPresenter*)javaScriptDialogPresenterForWebState: |
| 289 (web::WebState*)webState { | 284 (web::WebState*)webState { |
| 290 return _javaScriptDialogPresenter.get(); | 285 return _javaScriptDialogPresenter.get(); |
| 291 } | 286 } |
| 292 | 287 |
| 288 #pragma mark - Translation | |
| 289 | |
| 290 - (CWVTranslationController*)translationController { | |
| 291 if (!_translationController) { | |
| 292 _translationController = [[CWVTranslationController alloc] init]; | |
| 293 _translationController.webState = _webState.get(); | |
| 294 } | |
| 295 return _translationController; | |
| 296 } | |
| 297 | |
| 293 #pragma mark - Preserving and Restoring State | 298 #pragma mark - Preserving and Restoring State |
| 294 | 299 |
| 295 - (void)encodeRestorableStateWithCoder:(NSCoder*)coder { | 300 - (void)encodeRestorableStateWithCoder:(NSCoder*)coder { |
| 296 [super encodeRestorableStateWithCoder:coder]; | 301 [super encodeRestorableStateWithCoder:coder]; |
| 297 [coder encodeObject:_webState->BuildSessionStorage() | 302 [coder encodeObject:_webState->BuildSessionStorage() |
| 298 forKey:kSessionStorageKey]; | 303 forKey:kSessionStorageKey]; |
| 299 } | 304 } |
| 300 | 305 |
| 301 - (void)decodeRestorableStateWithCoder:(NSCoder*)coder { | 306 - (void)decodeRestorableStateWithCoder:(NSCoder*)coder { |
| 302 [super decodeRestorableStateWithCoder:coder]; | 307 [super decodeRestorableStateWithCoder:coder]; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 334 _webState->SetDelegate(_webStateDelegate.get()); | 339 _webState->SetDelegate(_webStateDelegate.get()); |
| 335 | 340 |
| 336 _webStatePolicyDecider = | 341 _webStatePolicyDecider = |
| 337 base::MakeUnique<ios_web_view::WebViewWebStatePolicyDecider>( | 342 base::MakeUnique<ios_web_view::WebViewWebStatePolicyDecider>( |
| 338 _webState.get(), self); | 343 _webState.get(), self); |
| 339 | 344 |
| 340 _javaScriptDialogPresenter = | 345 _javaScriptDialogPresenter = |
| 341 base::MakeUnique<ios_web_view::WebViewJavaScriptDialogPresenter>(self, | 346 base::MakeUnique<ios_web_view::WebViewJavaScriptDialogPresenter>(self, |
| 342 nullptr); | 347 nullptr); |
| 343 | 348 |
| 344 // Initialize Translate. | 349 _translationController.webState = _webState.get(); |
| 345 ios_web_view::WebViewTranslateClient::CreateForWebState(_webState.get()); | |
| 346 | 350 |
| 347 [self addInternalWebViewAsSubview]; | 351 [self addInternalWebViewAsSubview]; |
| 348 } | 352 } |
| 349 | 353 |
| 350 // Adds the web view provided by |_webState| as a subview unless it has already. | 354 // Adds the web view provided by |_webState| as a subview unless it has already. |
| 351 - (void)addInternalWebViewAsSubview { | 355 - (void)addInternalWebViewAsSubview { |
| 352 UIView* subview = _webState->GetView(); | 356 UIView* subview = _webState->GetView(); |
| 353 if (subview.superview == self) { | 357 if (subview.superview == self) { |
| 354 return; | 358 return; |
| 355 } | 359 } |
| 356 subview.frame = self.bounds; | 360 subview.frame = self.bounds; |
| 357 subview.autoresizingMask = | 361 subview.autoresizingMask = |
| 358 UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; | 362 UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; |
| 359 [self addSubview:subview]; | 363 [self addSubview:subview]; |
| 360 } | 364 } |
| 361 | 365 |
| 362 @end | 366 @end |
| OLD | NEW |