Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(676)

Side by Side Diff: ios/web_view/internal/cwv_web_view.mm

Issue 2839093002: Implemented new Translate API for purely Objective-C clients. (Closed)
Patch Set: merge Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ios/web_view/BUILD.gn ('k') | ios/web_view/internal/translate/cwv_language_detection_result.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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" 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" 21 #import "ios/web/public/web_state/ui/crw_web_view_scroll_view_proxy.h"
22 #import "ios/web/public/web_state/web_state.h" 22 #import "ios/web/public/web_state/web_state.h"
23 #import "ios/web/public/web_state/web_state_delegate_bridge.h" 23 #import "ios/web/public/web_state/web_state_delegate_bridge.h"
24 #import "ios/web/public/web_state/web_state_observer_bridge.h" 24 #import "ios/web/public/web_state/web_state_observer_bridge.h"
25 #import "ios/web_view/internal/cwv_html_element_internal.h" 25 #import "ios/web_view/internal/cwv_html_element_internal.h"
26 #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" 27 #import "ios/web_view/internal/cwv_scroll_view_internal.h"
28 #import "ios/web_view/internal/cwv_web_view_configuration_internal.h" 28 #import "ios/web_view/internal/cwv_web_view_configuration_internal.h"
29 #import "ios/web_view/internal/translate/cwv_translation_controller_internal.h"
29 #import "ios/web_view/internal/translate/web_view_translate_client.h" 30 #import "ios/web_view/internal/translate/web_view_translate_client.h"
30 #include "ios/web_view/internal/web_view_browser_state.h" 31 #include "ios/web_view/internal/web_view_browser_state.h"
31 #import "ios/web_view/internal/web_view_java_script_dialog_presenter.h" 32 #import "ios/web_view/internal/web_view_java_script_dialog_presenter.h"
32 #import "ios/web_view/internal/web_view_web_state_policy_decider.h" 33 #import "ios/web_view/internal/web_view_web_state_policy_decider.h"
33 #import "ios/web_view/public/cwv_navigation_delegate.h" 34 #import "ios/web_view/public/cwv_navigation_delegate.h"
34 #import "ios/web_view/public/cwv_ui_delegate.h" 35 #import "ios/web_view/public/cwv_ui_delegate.h"
35 #import "ios/web_view/public/cwv_web_view_configuration.h" 36 #import "ios/web_view/public/cwv_web_view_configuration.h"
36 #import "net/base/mac/url_conversions.h" 37 #import "net/base/mac/url_conversions.h"
37 #include "ui/base/page_transition_types.h" 38 #include "ui/base/page_transition_types.h"
38 #include "url/gurl.h" 39 #include "url/gurl.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 // can be used to send KVO notification. 78 // can be used to send KVO notification.
78 @property(nonatomic, readwrite) double estimatedProgress; 79 @property(nonatomic, readwrite) double estimatedProgress;
79 80
80 @end 81 @end
81 82
82 static NSString* gUserAgentProduct = nil; 83 static NSString* gUserAgentProduct = nil;
83 84
84 @implementation CWVWebView 85 @implementation CWVWebView
85 86
86 @synthesize configuration = _configuration; 87 @synthesize configuration = _configuration;
88 @synthesize estimatedProgress = _estimatedProgress;
87 @synthesize navigationDelegate = _navigationDelegate; 89 @synthesize navigationDelegate = _navigationDelegate;
88 @synthesize translationDelegate = _translationDelegate; 90 @synthesize translationController = _translationController;
89 @synthesize estimatedProgress = _estimatedProgress;
90 @synthesize UIDelegate = _UIDelegate; 91 @synthesize UIDelegate = _UIDelegate;
91 @synthesize scrollView = _scrollView; 92 @synthesize scrollView = _scrollView;
92 93
93 + (NSString*)userAgentProduct { 94 + (NSString*)userAgentProduct {
94 return gUserAgentProduct; 95 return gUserAgentProduct;
95 } 96 }
96 97
97 + (void)setUserAgentProduct:(NSString*)product { 98 + (void)setUserAgentProduct:(NSString*)product {
98 gUserAgentProduct = [product copy]; 99 gUserAgentProduct = [product copy];
99 } 100 }
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 [_webState->GetJSInjectionReceiver() executeJavaScript:javaScriptString 186 [_webState->GetJSInjectionReceiver() executeJavaScript:javaScriptString
186 completionHandler:completionHandler]; 187 completionHandler:completionHandler];
187 } 188 }
188 189
189 - (void)setUIDelegate:(id<CWVUIDelegate>)UIDelegate { 190 - (void)setUIDelegate:(id<CWVUIDelegate>)UIDelegate {
190 _UIDelegate = UIDelegate; 191 _UIDelegate = UIDelegate;
191 192
192 _javaScriptDialogPresenter->SetUIDelegate(_UIDelegate); 193 _javaScriptDialogPresenter->SetUIDelegate(_UIDelegate);
193 } 194 }
194 195
195 - (void)setTranslationDelegate:(id<CWVTranslateDelegate>)translationDelegate {
196 _translationDelegate = translationDelegate;
197 ios_web_view::WebViewTranslateClient::FromWebState(_webState.get())
198 ->set_translate_delegate(translationDelegate);
199 }
200
201 // ----------------------------------------------------------------------- 196 // -----------------------------------------------------------------------
202 // WebStateObserver implementation. 197 // WebStateObserver implementation.
203 198
204 - (void)webState:(web::WebState*)webState 199 - (void)webState:(web::WebState*)webState
205 didStartProvisionalNavigationForURL:(const GURL&)URL { 200 didStartProvisionalNavigationForURL:(const GURL&)URL {
206 SEL selector = @selector(webViewDidStartProvisionalNavigation:); 201 SEL selector = @selector(webViewDidStartProvisionalNavigation:);
207 if ([_navigationDelegate respondsToSelector:selector]) { 202 if ([_navigationDelegate respondsToSelector:selector]) {
208 [_navigationDelegate webViewDidStartProvisionalNavigation:self]; 203 [_navigationDelegate webViewDidStartProvisionalNavigation:self];
209 } 204 }
210 } 205 }
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 if ([_UIDelegate respondsToSelector:selector]) { 283 if ([_UIDelegate respondsToSelector:selector]) {
289 [_UIDelegate webViewDidClose:self]; 284 [_UIDelegate webViewDidClose:self];
290 } 285 }
291 } 286 }
292 287
293 - (web::JavaScriptDialogPresenter*)javaScriptDialogPresenterForWebState: 288 - (web::JavaScriptDialogPresenter*)javaScriptDialogPresenterForWebState:
294 (web::WebState*)webState { 289 (web::WebState*)webState {
295 return _javaScriptDialogPresenter.get(); 290 return _javaScriptDialogPresenter.get();
296 } 291 }
297 292
293 #pragma mark - Translation
294
295 - (CWVTranslationController*)translationController {
296 if (!_translationController) {
297 _translationController = [[CWVTranslationController alloc] init];
298 _translationController.webState = _webState.get();
299 }
300 return _translationController;
301 }
302
298 #pragma mark - Preserving and Restoring State 303 #pragma mark - Preserving and Restoring State
299 304
300 - (void)encodeRestorableStateWithCoder:(NSCoder*)coder { 305 - (void)encodeRestorableStateWithCoder:(NSCoder*)coder {
301 [super encodeRestorableStateWithCoder:coder]; 306 [super encodeRestorableStateWithCoder:coder];
302 [coder encodeObject:_webState->BuildSessionStorage() 307 [coder encodeObject:_webState->BuildSessionStorage()
303 forKey:kSessionStorageKey]; 308 forKey:kSessionStorageKey];
304 } 309 }
305 310
306 - (void)decodeRestorableStateWithCoder:(NSCoder*)coder { 311 - (void)decodeRestorableStateWithCoder:(NSCoder*)coder {
307 [super decodeRestorableStateWithCoder:coder]; 312 [super decodeRestorableStateWithCoder:coder];
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 _webStatePolicyDecider = 346 _webStatePolicyDecider =
342 base::MakeUnique<ios_web_view::WebViewWebStatePolicyDecider>( 347 base::MakeUnique<ios_web_view::WebViewWebStatePolicyDecider>(
343 _webState.get(), self); 348 _webState.get(), self);
344 349
345 _javaScriptDialogPresenter = 350 _javaScriptDialogPresenter =
346 base::MakeUnique<ios_web_view::WebViewJavaScriptDialogPresenter>(self, 351 base::MakeUnique<ios_web_view::WebViewJavaScriptDialogPresenter>(self,
347 nullptr); 352 nullptr);
348 353
349 _scrollView.proxy = _webState.get()->GetWebViewProxy().scrollViewProxy; 354 _scrollView.proxy = _webState.get()->GetWebViewProxy().scrollViewProxy;
350 355
351 // Initialize Translate. 356 _translationController.webState = _webState.get();
352 ios_web_view::WebViewTranslateClient::CreateForWebState(_webState.get());
353 357
354 [self addInternalWebViewAsSubview]; 358 [self addInternalWebViewAsSubview];
355 } 359 }
356 360
357 // Adds the web view provided by |_webState| as a subview unless it has already. 361 // Adds the web view provided by |_webState| as a subview unless it has already.
358 - (void)addInternalWebViewAsSubview { 362 - (void)addInternalWebViewAsSubview {
359 UIView* subview = _webState->GetView(); 363 UIView* subview = _webState->GetView();
360 if (subview.superview == self) { 364 if (subview.superview == self) {
361 return; 365 return;
362 } 366 }
363 subview.frame = self.bounds; 367 subview.frame = self.bounds;
364 subview.autoresizingMask = 368 subview.autoresizingMask =
365 UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 369 UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
366 [self addSubview:subview]; 370 [self addSubview:subview];
367 } 371 }
368 372
369 @end 373 @end
OLDNEW
« no previous file with comments | « ios/web_view/BUILD.gn ('k') | ios/web_view/internal/translate/cwv_language_detection_result.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698