| 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/ui/crw_web_view_proxy.h" |
| 21 #import "ios/web/public/web_state/ui/crw_web_view_scroll_view_proxy.h" |
| 20 #import "ios/web/public/web_state/web_state.h" | 22 #import "ios/web/public/web_state/web_state.h" |
| 21 #import "ios/web/public/web_state/web_state_delegate_bridge.h" | 23 #import "ios/web/public/web_state/web_state_delegate_bridge.h" |
| 22 #import "ios/web/public/web_state/web_state_observer_bridge.h" | 24 #import "ios/web/public/web_state/web_state_observer_bridge.h" |
| 23 #import "ios/web_view/internal/cwv_html_element_internal.h" | 25 #import "ios/web_view/internal/cwv_html_element_internal.h" |
| 24 #import "ios/web_view/internal/cwv_navigation_action_internal.h" | 26 #import "ios/web_view/internal/cwv_navigation_action_internal.h" |
| 27 #import "ios/web_view/internal/cwv_scroll_view_internal.h" |
| 25 #import "ios/web_view/internal/cwv_web_view_configuration_internal.h" | 28 #import "ios/web_view/internal/cwv_web_view_configuration_internal.h" |
| 26 #import "ios/web_view/internal/translate/web_view_translate_client.h" | 29 #import "ios/web_view/internal/translate/web_view_translate_client.h" |
| 27 #include "ios/web_view/internal/web_view_browser_state.h" | 30 #include "ios/web_view/internal/web_view_browser_state.h" |
| 28 #import "ios/web_view/internal/web_view_java_script_dialog_presenter.h" | 31 #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" | 32 #import "ios/web_view/internal/web_view_web_state_policy_decider.h" |
| 30 #import "ios/web_view/public/cwv_navigation_delegate.h" | 33 #import "ios/web_view/public/cwv_navigation_delegate.h" |
| 31 #import "ios/web_view/public/cwv_ui_delegate.h" | 34 #import "ios/web_view/public/cwv_ui_delegate.h" |
| 32 #import "ios/web_view/public/cwv_web_view_configuration.h" | 35 #import "ios/web_view/public/cwv_web_view_configuration.h" |
| 33 #import "net/base/mac/url_conversions.h" | 36 #import "net/base/mac/url_conversions.h" |
| 34 #include "ui/base/page_transition_types.h" | 37 #include "ui/base/page_transition_types.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 | 81 |
| 79 static NSString* gUserAgentProduct = nil; | 82 static NSString* gUserAgentProduct = nil; |
| 80 | 83 |
| 81 @implementation CWVWebView | 84 @implementation CWVWebView |
| 82 | 85 |
| 83 @synthesize configuration = _configuration; | 86 @synthesize configuration = _configuration; |
| 84 @synthesize navigationDelegate = _navigationDelegate; | 87 @synthesize navigationDelegate = _navigationDelegate; |
| 85 @synthesize translationDelegate = _translationDelegate; | 88 @synthesize translationDelegate = _translationDelegate; |
| 86 @synthesize estimatedProgress = _estimatedProgress; | 89 @synthesize estimatedProgress = _estimatedProgress; |
| 87 @synthesize UIDelegate = _UIDelegate; | 90 @synthesize UIDelegate = _UIDelegate; |
| 91 @synthesize scrollView = _scrollView; |
| 88 | 92 |
| 89 + (NSString*)userAgentProduct { | 93 + (NSString*)userAgentProduct { |
| 90 return gUserAgentProduct; | 94 return gUserAgentProduct; |
| 91 } | 95 } |
| 92 | 96 |
| 93 + (void)setUserAgentProduct:(NSString*)product { | 97 + (void)setUserAgentProduct:(NSString*)product { |
| 94 gUserAgentProduct = [product copy]; | 98 gUserAgentProduct = [product copy]; |
| 95 } | 99 } |
| 96 | 100 |
| 97 + (void)setGoogleAPIKey:(NSString*)googleAPIKey | 101 + (void)setGoogleAPIKey:(NSString*)googleAPIKey |
| 98 clientID:(NSString*)clientID | 102 clientID:(NSString*)clientID |
| 99 clientSecret:(NSString*)clientSecret { | 103 clientSecret:(NSString*)clientSecret { |
| 100 google_apis::SetAPIKey(base::SysNSStringToUTF8(googleAPIKey)); | 104 google_apis::SetAPIKey(base::SysNSStringToUTF8(googleAPIKey)); |
| 101 | 105 |
| 102 std::string clientIDString = base::SysNSStringToUTF8(clientID); | 106 std::string clientIDString = base::SysNSStringToUTF8(clientID); |
| 103 std::string clientSecretString = base::SysNSStringToUTF8(clientSecret); | 107 std::string clientSecretString = base::SysNSStringToUTF8(clientSecret); |
| 104 for (size_t i = 0; i < google_apis::CLIENT_NUM_ITEMS; ++i) { | 108 for (size_t i = 0; i < google_apis::CLIENT_NUM_ITEMS; ++i) { |
| 105 google_apis::OAuth2Client client = | 109 google_apis::OAuth2Client client = |
| 106 static_cast<google_apis::OAuth2Client>(i); | 110 static_cast<google_apis::OAuth2Client>(i); |
| 107 google_apis::SetOAuth2ClientID(client, clientIDString); | 111 google_apis::SetOAuth2ClientID(client, clientIDString); |
| 108 google_apis::SetOAuth2ClientSecret(client, clientSecretString); | 112 google_apis::SetOAuth2ClientSecret(client, clientSecretString); |
| 109 } | 113 } |
| 110 } | 114 } |
| 111 | 115 |
| 112 - (instancetype)initWithFrame:(CGRect)frame | 116 - (instancetype)initWithFrame:(CGRect)frame |
| 113 configuration:(CWVWebViewConfiguration*)configuration { | 117 configuration:(CWVWebViewConfiguration*)configuration { |
| 114 self = [super initWithFrame:frame]; | 118 self = [super initWithFrame:frame]; |
| 115 if (self) { | 119 if (self) { |
| 116 _configuration = [configuration copy]; | 120 _configuration = [configuration copy]; |
| 121 _scrollView = [[CWVScrollView alloc] init]; |
| 117 [self resetWebStateWithSessionStorage:nil]; | 122 [self resetWebStateWithSessionStorage:nil]; |
| 118 } | 123 } |
| 119 return self; | 124 return self; |
| 120 } | 125 } |
| 121 | 126 |
| 122 - (BOOL)canGoBack { | 127 - (BOOL)canGoBack { |
| 123 return _webState && _webState->GetNavigationManager()->CanGoBack(); | 128 return _webState && _webState->GetNavigationManager()->CanGoBack(); |
| 124 } | 129 } |
| 125 | 130 |
| 126 - (BOOL)canGoForward { | 131 - (BOOL)canGoForward { |
| (...skipping 207 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 |
| 349 _scrollView.proxy = _webState.get()->GetWebViewProxy().scrollViewProxy; |
| 350 |
| 344 // Initialize Translate. | 351 // Initialize Translate. |
| 345 ios_web_view::WebViewTranslateClient::CreateForWebState(_webState.get()); | 352 ios_web_view::WebViewTranslateClient::CreateForWebState(_webState.get()); |
| 346 | 353 |
| 347 [self addInternalWebViewAsSubview]; | 354 [self addInternalWebViewAsSubview]; |
| 348 } | 355 } |
| 349 | 356 |
| 350 // Adds the web view provided by |_webState| as a subview unless it has already. | 357 // Adds the web view provided by |_webState| as a subview unless it has already. |
| 351 - (void)addInternalWebViewAsSubview { | 358 - (void)addInternalWebViewAsSubview { |
| 352 UIView* subview = _webState->GetView(); | 359 UIView* subview = _webState->GetView(); |
| 353 if (subview.superview == self) { | 360 if (subview.superview == self) { |
| 354 return; | 361 return; |
| 355 } | 362 } |
| 356 subview.frame = self.bounds; | 363 subview.frame = self.bounds; |
| 357 subview.autoresizingMask = | 364 subview.autoresizingMask = |
| 358 UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; | 365 UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; |
| 359 [self addSubview:subview]; | 366 [self addSubview:subview]; |
| 360 } | 367 } |
| 361 | 368 |
| 362 @end | 369 @end |
| OLD | NEW |