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; | |
| 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 { | |
|
Hiroshi Ichikawa
2017/04/26 08:40:57
When -resetWebStateWithSessionStorage: is called a
jzw1
2017/04/27 04:54:01
Are you OK if i just nil it out _translationContro
Hiroshi Ichikawa
2017/04/27 05:35:42
I believe it doesn't work. Two cases:
1. The user
jzw1
2017/04/27 07:03:18
What if I just set a webState on translationContro
Hiroshi Ichikawa
2017/04/27 07:17:22
Yeah it looks calling -[CWVTranslationController s
| |
| 291 if (!_translationController) { | |
| 292 // Initialize Translate. | |
| 293 ios_web_view::WebViewTranslateClient::CreateForWebState(_webState.get()); | |
| 294 ios_web_view::WebViewTranslateClient* translateClient = | |
| 295 ios_web_view::WebViewTranslateClient::FromWebState(_webState.get()); | |
| 296 _translationController = [[CWVTranslationController alloc] | |
| 297 initWithWebViewTranslateClient:translateClient]; | |
| 298 } | |
| 299 return _translationController; | |
| 300 } | |
| 301 | |
| 293 #pragma mark - Preserving and Restoring State | 302 #pragma mark - Preserving and Restoring State |
| 294 | 303 |
| 295 - (void)encodeRestorableStateWithCoder:(NSCoder*)coder { | 304 - (void)encodeRestorableStateWithCoder:(NSCoder*)coder { |
| 296 [super encodeRestorableStateWithCoder:coder]; | 305 [super encodeRestorableStateWithCoder:coder]; |
| 297 [coder encodeObject:_webState->BuildSessionStorage() | 306 [coder encodeObject:_webState->BuildSessionStorage() |
| 298 forKey:kSessionStorageKey]; | 307 forKey:kSessionStorageKey]; |
| 299 } | 308 } |
| 300 | 309 |
| 301 - (void)decodeRestorableStateWithCoder:(NSCoder*)coder { | 310 - (void)decodeRestorableStateWithCoder:(NSCoder*)coder { |
| 302 [super decodeRestorableStateWithCoder:coder]; | 311 [super decodeRestorableStateWithCoder:coder]; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 334 _webState->SetDelegate(_webStateDelegate.get()); | 343 _webState->SetDelegate(_webStateDelegate.get()); |
| 335 | 344 |
| 336 _webStatePolicyDecider = | 345 _webStatePolicyDecider = |
| 337 base::MakeUnique<ios_web_view::WebViewWebStatePolicyDecider>( | 346 base::MakeUnique<ios_web_view::WebViewWebStatePolicyDecider>( |
| 338 _webState.get(), self); | 347 _webState.get(), self); |
| 339 | 348 |
| 340 _javaScriptDialogPresenter = | 349 _javaScriptDialogPresenter = |
| 341 base::MakeUnique<ios_web_view::WebViewJavaScriptDialogPresenter>(self, | 350 base::MakeUnique<ios_web_view::WebViewJavaScriptDialogPresenter>(self, |
| 342 nullptr); | 351 nullptr); |
| 343 | 352 |
| 344 // Initialize Translate. | |
| 345 ios_web_view::WebViewTranslateClient::CreateForWebState(_webState.get()); | |
| 346 | |
| 347 [self addInternalWebViewAsSubview]; | 353 [self addInternalWebViewAsSubview]; |
| 348 } | 354 } |
| 349 | 355 |
| 350 // Adds the web view provided by |_webState| as a subview unless it has already. | 356 // Adds the web view provided by |_webState| as a subview unless it has already. |
| 351 - (void)addInternalWebViewAsSubview { | 357 - (void)addInternalWebViewAsSubview { |
| 352 UIView* subview = _webState->GetView(); | 358 UIView* subview = _webState->GetView(); |
| 353 if (subview.superview == self) { | 359 if (subview.superview == self) { |
| 354 return; | 360 return; |
| 355 } | 361 } |
| 356 subview.frame = self.bounds; | 362 subview.frame = self.bounds; |
| 357 subview.autoresizingMask = | 363 subview.autoresizingMask = |
| 358 UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; | 364 UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; |
| 359 [self addSubview:subview]; | 365 [self addSubview:subview]; |
| 360 } | 366 } |
| 361 | 367 |
| 362 @end | 368 @end |
| OLD | NEW |