OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/web_state/ui/crw_web_controller.h" | 5 #import "ios/web/web_state/ui/crw_web_controller.h" |
6 | 6 |
7 #import <objc/runtime.h> | 7 #import <objc/runtime.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <cmath> | 10 #include <cmath> |
| 11 #include <memory> |
11 #include <utility> | 12 #include <utility> |
12 | 13 |
13 #include "base/ios/block_types.h" | 14 #include "base/ios/block_types.h" |
14 #import "base/ios/ns_error_util.h" | 15 #import "base/ios/ns_error_util.h" |
15 #include "base/ios/weak_nsobject.h" | 16 #include "base/ios/weak_nsobject.h" |
16 #include "base/json/json_reader.h" | 17 #include "base/json/json_reader.h" |
17 #include "base/json/json_writer.h" | 18 #include "base/json/json_writer.h" |
18 #include "base/json/string_escape.h" | 19 #include "base/json/string_escape.h" |
19 #include "base/logging.h" | 20 #include "base/logging.h" |
20 #include "base/mac/bundle_locations.h" | 21 #include "base/mac/bundle_locations.h" |
21 #include "base/mac/foundation_util.h" | 22 #include "base/mac/foundation_util.h" |
22 #include "base/mac/objc_property_releaser.h" | 23 #include "base/mac/objc_property_releaser.h" |
23 #include "base/mac/scoped_cftyperef.h" | 24 #include "base/mac/scoped_cftyperef.h" |
24 #include "base/mac/scoped_nsobject.h" | 25 #include "base/mac/scoped_nsobject.h" |
25 #include "base/memory/scoped_ptr.h" | |
26 #include "base/metrics/histogram.h" | 26 #include "base/metrics/histogram.h" |
27 #include "base/metrics/user_metrics_action.h" | 27 #include "base/metrics/user_metrics_action.h" |
28 #include "base/strings/string_util.h" | 28 #include "base/strings/string_util.h" |
29 #include "base/strings/sys_string_conversions.h" | 29 #include "base/strings/sys_string_conversions.h" |
30 #include "base/strings/utf_string_conversions.h" | 30 #include "base/strings/utf_string_conversions.h" |
31 #include "base/time/time.h" | 31 #include "base/time/time.h" |
32 #include "base/values.h" | 32 #include "base/values.h" |
33 #include "components/prefs/pref_service.h" | 33 #include "components/prefs/pref_service.h" |
34 #include "components/url_formatter/url_formatter.h" | 34 #include "components/url_formatter/url_formatter.h" |
35 #import "ios/net/nsurlrequest_util.h" | 35 #import "ios/net/nsurlrequest_util.h" |
36 #include "ios/public/provider/web/web_ui_ios.h" | 36 #include "ios/public/provider/web/web_ui_ios.h" |
37 #import "ios/web/crw_network_activity_indicator_manager.h" | 37 #import "ios/web/crw_network_activity_indicator_manager.h" |
38 #import "ios/web/history_state_util.h" | 38 #import "ios/web/history_state_util.h" |
39 #include "ios/web/interstitials/web_interstitial_impl.h" | 39 #include "ios/web/interstitials/web_interstitial_impl.h" |
40 #import "ios/web/navigation/crw_session_certificate_policy_manager.h" | 40 #import "ios/web/navigation/crw_session_certificate_policy_manager.h" |
41 #import "ios/web/navigation/crw_session_controller.h" | 41 #import "ios/web/navigation/crw_session_controller.h" |
42 #import "ios/web/navigation/crw_session_entry.h" | 42 #import "ios/web/navigation/crw_session_entry.h" |
43 #import "ios/web/navigation/navigation_item_impl.h" | 43 #import "ios/web/navigation/navigation_item_impl.h" |
44 #import "ios/web/navigation/navigation_manager_impl.h" | 44 #import "ios/web/navigation/navigation_manager_impl.h" |
45 #include "ios/web/net/request_group_util.h" | 45 #include "ios/web/net/request_group_util.h" |
46 #include "ios/web/public/browser_state.h" | 46 #include "ios/web/public/browser_state.h" |
47 #include "ios/web/public/favicon_url.h" | 47 #include "ios/web/public/favicon_url.h" |
| 48 #include "ios/web/public/navigation_item.h" |
48 #import "ios/web/public/navigation_manager.h" | 49 #import "ios/web/public/navigation_manager.h" |
49 #include "ios/web/public/navigation_item.h" | |
50 #include "ios/web/public/referrer.h" | 50 #include "ios/web/public/referrer.h" |
51 #include "ios/web/public/referrer_util.h" | 51 #include "ios/web/public/referrer_util.h" |
52 #include "ios/web/public/ssl_status.h" | 52 #include "ios/web/public/ssl_status.h" |
53 #import "ios/web/public/url_scheme_util.h" | 53 #import "ios/web/public/url_scheme_util.h" |
54 #include "ios/web/public/url_util.h" | 54 #include "ios/web/public/url_util.h" |
55 #include "ios/web/public/user_metrics.h" | 55 #include "ios/web/public/user_metrics.h" |
56 #include "ios/web/public/web_client.h" | 56 #include "ios/web/public/web_client.h" |
57 #include "ios/web/public/web_kit_constants.h" | 57 #include "ios/web/public/web_kit_constants.h" |
58 #include "ios/web/public/web_state/credential.h" | 58 #include "ios/web/public/web_state/credential.h" |
59 #import "ios/web/public/web_state/crw_web_controller_observer.h" | 59 #import "ios/web/public/web_state/crw_web_controller_observer.h" |
60 #import "ios/web/public/web_state/crw_web_view_scroll_view_proxy.h" | 60 #import "ios/web/public/web_state/crw_web_view_scroll_view_proxy.h" |
61 #import "ios/web/public/web_state/js/credential_util.h" | 61 #import "ios/web/public/web_state/js/credential_util.h" |
62 #import "ios/web/public/web_state/js/crw_js_injection_manager.h" | 62 #import "ios/web/public/web_state/js/crw_js_injection_manager.h" |
63 #import "ios/web/public/web_state/js/crw_js_injection_receiver.h" | 63 #import "ios/web/public/web_state/js/crw_js_injection_receiver.h" |
64 #import "ios/web/public/web_state/ui/crw_content_view.h" | 64 #import "ios/web/public/web_state/ui/crw_content_view.h" |
65 #import "ios/web/public/web_state/ui/crw_native_content.h" | 65 #import "ios/web/public/web_state/ui/crw_native_content.h" |
66 #import "ios/web/public/web_state/ui/crw_native_content_provider.h" | 66 #import "ios/web/public/web_state/ui/crw_native_content_provider.h" |
67 #import "ios/web/public/web_state/ui/crw_web_view_content_view.h" | 67 #import "ios/web/public/web_state/ui/crw_web_view_content_view.h" |
68 #include "ios/web/public/web_state/url_verification_constants.h" | 68 #include "ios/web/public/web_state/url_verification_constants.h" |
69 #include "ios/web/public/web_state/web_state.h" | 69 #include "ios/web/public/web_state/web_state.h" |
70 #include "ios/web/web_state/blocked_popup_info.h" | 70 #include "ios/web/web_state/blocked_popup_info.h" |
71 #import "ios/web/web_state/crw_web_view_proxy_impl.h" | 71 #import "ios/web/web_state/crw_web_view_proxy_impl.h" |
72 #import "ios/web/web_state/error_translation_util.h" | 72 #import "ios/web/web_state/error_translation_util.h" |
73 #include "ios/web/web_state/frame_info.h" | 73 #include "ios/web/web_state/frame_info.h" |
74 #import "ios/web/web_state/page_viewport_state.h" | |
75 #import "ios/web/web_state/js/crw_js_early_script_manager.h" | 74 #import "ios/web/web_state/js/crw_js_early_script_manager.h" |
76 #import "ios/web/web_state/js/crw_js_plugin_placeholder_manager.h" | 75 #import "ios/web/web_state/js/crw_js_plugin_placeholder_manager.h" |
77 #import "ios/web/web_state/js/crw_js_window_id_manager.h" | 76 #import "ios/web/web_state/js/crw_js_window_id_manager.h" |
| 77 #import "ios/web/web_state/page_viewport_state.h" |
78 #import "ios/web/web_state/ui/crw_context_menu_provider.h" | 78 #import "ios/web/web_state/ui/crw_context_menu_provider.h" |
79 #import "ios/web/web_state/ui/crw_swipe_recognizer_provider.h" | 79 #import "ios/web/web_state/ui/crw_swipe_recognizer_provider.h" |
80 #import "ios/web/web_state/ui/crw_web_controller+protected.h" | 80 #import "ios/web/web_state/ui/crw_web_controller+protected.h" |
81 #import "ios/web/web_state/ui/crw_web_controller_container_view.h" | 81 #import "ios/web/web_state/ui/crw_web_controller_container_view.h" |
82 #import "ios/web/web_state/ui/crw_wk_web_view_web_controller.h" | 82 #import "ios/web/web_state/ui/crw_wk_web_view_web_controller.h" |
83 #import "ios/web/web_state/web_controller_observer_bridge.h" | 83 #import "ios/web/web_state/web_controller_observer_bridge.h" |
84 #include "ios/web/web_state/web_state_facade_delegate.h" | 84 #include "ios/web/web_state/web_state_facade_delegate.h" |
85 #import "ios/web/web_state/web_state_impl.h" | 85 #import "ios/web/web_state/web_state_impl.h" |
86 #import "net/base/mac/url_conversions.h" | 86 #import "net/base/mac/url_conversions.h" |
87 #include "net/base/net_errors.h" | 87 #include "net/base/net_errors.h" |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 // The touch tracking recognizer allowing us to decide if a navigation is | 237 // The touch tracking recognizer allowing us to decide if a navigation is |
238 // started by the user. | 238 // started by the user. |
239 base::scoped_nsobject<CRWTouchTrackingRecognizer> _touchTrackingRecognizer; | 239 base::scoped_nsobject<CRWTouchTrackingRecognizer> _touchTrackingRecognizer; |
240 // Long press recognizer that allows showing context menus. | 240 // Long press recognizer that allows showing context menus. |
241 base::scoped_nsobject<UILongPressGestureRecognizer> _contextMenuRecognizer; | 241 base::scoped_nsobject<UILongPressGestureRecognizer> _contextMenuRecognizer; |
242 // DOM element information for the point where the user made the last touch. | 242 // DOM element information for the point where the user made the last touch. |
243 // Can be null if has not been calculated yet. Precalculation is necessary | 243 // Can be null if has not been calculated yet. Precalculation is necessary |
244 // because retreiving DOM element relies on async API so element info can not | 244 // because retreiving DOM element relies on async API so element info can not |
245 // be built on demand. May contain the following keys: "href", "src", "title", | 245 // be built on demand. May contain the following keys: "href", "src", "title", |
246 // "referrerPolicy". All values are strings. Used for showing context menus. | 246 // "referrerPolicy". All values are strings. Used for showing context menus. |
247 scoped_ptr<base::DictionaryValue> _DOMElementForLastTouch; | 247 std::unique_ptr<base::DictionaryValue> _DOMElementForLastTouch; |
248 // Whether a click is in progress. | 248 // Whether a click is in progress. |
249 BOOL _clickInProgress; | 249 BOOL _clickInProgress; |
250 // Data on the recorded last user interaction. | 250 // Data on the recorded last user interaction. |
251 scoped_ptr<web::UserInteractionEvent> _lastUserInteraction; | 251 std::unique_ptr<web::UserInteractionEvent> _lastUserInteraction; |
252 // YES if there has been user interaction with views owned by this controller. | 252 // YES if there has been user interaction with views owned by this controller. |
253 BOOL _userInteractedWithWebController; | 253 BOOL _userInteractedWithWebController; |
254 // The time of the last page transfer start, measured in seconds since Jan 1 | 254 // The time of the last page transfer start, measured in seconds since Jan 1 |
255 // 2001. | 255 // 2001. |
256 CFAbsoluteTime _lastTransferTimeInSeconds; | 256 CFAbsoluteTime _lastTransferTimeInSeconds; |
257 // Default URL (about:blank). | 257 // Default URL (about:blank). |
258 GURL _defaultURL; | 258 GURL _defaultURL; |
259 // Show overlay view, don't reload web page. | 259 // Show overlay view, don't reload web page. |
260 BOOL _overlayPreviewMode; | 260 BOOL _overlayPreviewMode; |
261 // If |YES|, calls |setShouldSuppressDialogs:YES| when window id is injected | 261 // If |YES|, calls |setShouldSuppressDialogs:YES| when window id is injected |
262 // into the web view. | 262 // into the web view. |
263 BOOL _shouldSuppressDialogsOnWindowIDInjection; | 263 BOOL _shouldSuppressDialogsOnWindowIDInjection; |
264 // The URL of an expected future recreation of the |webView|. Valid | 264 // The URL of an expected future recreation of the |webView|. Valid |
265 // only if the web view was discarded for non-user-visible reasons, such that | 265 // only if the web view was discarded for non-user-visible reasons, such that |
266 // if the next load request is for that URL, it should be treated as a | 266 // if the next load request is for that URL, it should be treated as a |
267 // reconstruction that should use cache aggressively. | 267 // reconstruction that should use cache aggressively. |
268 GURL _expectedReconstructionURL; | 268 GURL _expectedReconstructionURL; |
269 // Whether the web page is currently performing window.history.pushState or | 269 // Whether the web page is currently performing window.history.pushState or |
270 // window.history.replaceState | 270 // window.history.replaceState |
271 // Set to YES on window.history.willChangeState message. To NO on | 271 // Set to YES on window.history.willChangeState message. To NO on |
272 // window.history.didPushState or window.history.didReplaceState. | 272 // window.history.didPushState or window.history.didReplaceState. |
273 BOOL _changingHistoryState; | 273 BOOL _changingHistoryState; |
274 | 274 |
275 scoped_ptr<web::NewWindowInfo> _externalRequest; | 275 std::unique_ptr<web::NewWindowInfo> _externalRequest; |
276 | 276 |
277 // The WebStateImpl instance associated with this CRWWebController. | 277 // The WebStateImpl instance associated with this CRWWebController. |
278 scoped_ptr<WebStateImpl> _webStateImpl; | 278 std::unique_ptr<WebStateImpl> _webStateImpl; |
279 | 279 |
280 // A set of URLs opened in external applications; stored so that errors | 280 // A set of URLs opened in external applications; stored so that errors |
281 // from the web view can be identified as resulting from these events. | 281 // from the web view can be identified as resulting from these events. |
282 base::scoped_nsobject<NSMutableSet> _openedApplicationURL; | 282 base::scoped_nsobject<NSMutableSet> _openedApplicationURL; |
283 | 283 |
284 // Object that manages all early script injection into the web view. | 284 // Object that manages all early script injection into the web view. |
285 base::scoped_nsobject<CRWJSEarlyScriptManager> _earlyScriptManager; | 285 base::scoped_nsobject<CRWJSEarlyScriptManager> _earlyScriptManager; |
286 | 286 |
287 // Script manager for setting the windowID. | 287 // Script manager for setting the windowID. |
288 base::scoped_nsobject<CRWJSWindowIdManager> _windowIDJSManager; | 288 base::scoped_nsobject<CRWJSWindowIdManager> _windowIDJSManager; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 - (BOOL)shouldClosePageOnNativeApplicationLoad; | 340 - (BOOL)shouldClosePageOnNativeApplicationLoad; |
341 // Called after URL is finished loading and _loadPhase is set to PAGE_LOADED. | 341 // Called after URL is finished loading and _loadPhase is set to PAGE_LOADED. |
342 - (void)didFinishWithURL:(const GURL&)currentURL loadSuccess:(BOOL)loadSuccess; | 342 - (void)didFinishWithURL:(const GURL&)currentURL loadSuccess:(BOOL)loadSuccess; |
343 // Informs the native controller if web usage is allowed or not. | 343 // Informs the native controller if web usage is allowed or not. |
344 - (void)setNativeControllerWebUsageEnabled:(BOOL)webUsageEnabled; | 344 - (void)setNativeControllerWebUsageEnabled:(BOOL)webUsageEnabled; |
345 // Evaluates the supplied JavaScript in the web view. Calls |handler| with | 345 // Evaluates the supplied JavaScript in the web view. Calls |handler| with |
346 // results of the evaluation (which may be nil if the implementing object has no | 346 // results of the evaluation (which may be nil if the implementing object has no |
347 // way to run the evaluation or the evaluation returns a nil value) or an | 347 // way to run the evaluation or the evaluation returns a nil value) or an |
348 // NSError if there is an error. The |handler| can be nil. | 348 // NSError if there is an error. The |handler| can be nil. |
349 - (void)evaluateJavaScript:(NSString*)script | 349 - (void)evaluateJavaScript:(NSString*)script |
350 JSONResultHandler:(void (^)(scoped_ptr<base::Value>, NSError*))handler; | 350 JSONResultHandler: |
| 351 (void (^)(std::unique_ptr<base::Value>, NSError*))handler; |
351 // Attempts to handle a script message. Returns YES on success, NO otherwise. | 352 // Attempts to handle a script message. Returns YES on success, NO otherwise. |
352 - (BOOL)respondToWKScriptMessage:(WKScriptMessage*)scriptMessage; | 353 - (BOOL)respondToWKScriptMessage:(WKScriptMessage*)scriptMessage; |
353 // Generates the JavaScript string used to update the UIWebView's URL so that it | 354 // Generates the JavaScript string used to update the UIWebView's URL so that it |
354 // matches the URL displayed in the omnibox and sets window.history.state to | 355 // matches the URL displayed in the omnibox and sets window.history.state to |
355 // stateObject. Needed for history.pushState() and history.replaceState(). | 356 // stateObject. Needed for history.pushState() and history.replaceState(). |
356 - (NSString*)javascriptToReplaceWebViewURL:(const GURL&)URL | 357 - (NSString*)javascriptToReplaceWebViewURL:(const GURL&)URL |
357 stateObjectJSON:(NSString*)stateObject; | 358 stateObjectJSON:(NSString*)stateObject; |
358 // Injects JavaScript into the web view to update the URL to |URL|, to set | 359 // Injects JavaScript into the web view to update the URL to |URL|, to set |
359 // window.history.state to |stateObject|, and to trigger a popstate() event. | 360 // window.history.state to |stateObject|, and to trigger a popstate() event. |
360 // Upon the scripts completion, resets |urlOnStartLoading_| and | 361 // Upon the scripts completion, resets |urlOnStartLoading_| and |
(...skipping 26 matching lines...) Expand all Loading... |
387 // Sets scroll offset value for webview scroll view from |scrollState|. | 388 // Sets scroll offset value for webview scroll view from |scrollState|. |
388 - (void)applyWebViewScrollOffsetFromScrollState: | 389 - (void)applyWebViewScrollOffsetFromScrollState: |
389 (const web::PageScrollState&)scrollState; | 390 (const web::PageScrollState&)scrollState; |
390 // Asynchronously fetches full width of the rendered web page. | 391 // Asynchronously fetches full width of the rendered web page. |
391 - (void)fetchWebPageWidthWithCompletionHandler:(void (^)(CGFloat))handler; | 392 - (void)fetchWebPageWidthWithCompletionHandler:(void (^)(CGFloat))handler; |
392 // Asynchronously fetches information about DOM element for the given point (in | 393 // Asynchronously fetches information about DOM element for the given point (in |
393 // UIView coordinates). |handler| can not be nil. See |_DOMElementForLastTouch| | 394 // UIView coordinates). |handler| can not be nil. See |_DOMElementForLastTouch| |
394 // for element format description. | 395 // for element format description. |
395 - (void)fetchDOMElementAtPoint:(CGPoint)point | 396 - (void)fetchDOMElementAtPoint:(CGPoint)point |
396 completionHandler: | 397 completionHandler: |
397 (void (^)(scoped_ptr<base::DictionaryValue>))handler; | 398 (void (^)(std::unique_ptr<base::DictionaryValue>))handler; |
398 // Extracts context menu information from the given DOM element. | 399 // Extracts context menu information from the given DOM element. |
399 // result keys are defined in crw_context_menu_provider.h. | 400 // result keys are defined in crw_context_menu_provider.h. |
400 - (NSDictionary*)contextMenuInfoForElement:(base::DictionaryValue*)element; | 401 - (NSDictionary*)contextMenuInfoForElement:(base::DictionaryValue*)element; |
401 // Sets the value of |_DOMElementForLastTouch|. | 402 // Sets the value of |_DOMElementForLastTouch|. |
402 - (void)setDOMElementForLastTouch:(scoped_ptr<base::DictionaryValue>)element; | 403 - (void)setDOMElementForLastTouch: |
| 404 (std::unique_ptr<base::DictionaryValue>)element; |
403 // Called when the window has determined there was a long-press and context menu | 405 // Called when the window has determined there was a long-press and context menu |
404 // must be shown. | 406 // must be shown. |
405 - (void)showContextMenu:(UIGestureRecognizer*)gestureRecognizer; | 407 - (void)showContextMenu:(UIGestureRecognizer*)gestureRecognizer; |
406 // YES if delegate supports showing context menu by responding to | 408 // YES if delegate supports showing context menu by responding to |
407 // webController:runContextMenu:atPoint:inView: selector. | 409 // webController:runContextMenu:atPoint:inView: selector. |
408 - (BOOL)supportsCustomContextMenu; | 410 - (BOOL)supportsCustomContextMenu; |
409 // Cancels all touch events in the web view (long presses, tapping, scrolling). | 411 // Cancels all touch events in the web view (long presses, tapping, scrolling). |
410 - (void)cancelAllTouches; | 412 - (void)cancelAllTouches; |
411 // Returns the referrer for the current page. | 413 // Returns the referrer for the current page. |
412 - (web::Referrer)currentReferrer; | 414 - (web::Referrer)currentReferrer; |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
566 + (instancetype)allocWithZone:(struct _NSZone*)zone { | 568 + (instancetype)allocWithZone:(struct _NSZone*)zone { |
567 if (self == [CRWWebController class]) { | 569 if (self == [CRWWebController class]) { |
568 // This is an abstract class which should not be instantiated directly. | 570 // This is an abstract class which should not be instantiated directly. |
569 // Callers should create concrete subclasses instead. | 571 // Callers should create concrete subclasses instead. |
570 NOTREACHED(); | 572 NOTREACHED(); |
571 return nil; | 573 return nil; |
572 } | 574 } |
573 return [super allocWithZone:zone]; | 575 return [super allocWithZone:zone]; |
574 } | 576 } |
575 | 577 |
576 - (instancetype)initWithWebState:(scoped_ptr<WebStateImpl>)webState { | 578 - (instancetype)initWithWebState:(std::unique_ptr<WebStateImpl>)webState { |
577 self = [super init]; | 579 self = [super init]; |
578 if (self) { | 580 if (self) { |
579 _webStateImpl = std::move(webState); | 581 _webStateImpl = std::move(webState); |
580 DCHECK(_webStateImpl); | 582 DCHECK(_webStateImpl); |
581 _webStateImpl->SetWebController(self); | 583 _webStateImpl->SetWebController(self); |
582 _webStateImpl->InitializeRequestTracker(self); | 584 _webStateImpl->InitializeRequestTracker(self); |
583 // Load phase when no WebView present is 'loaded' because this represents | 585 // Load phase when no WebView present is 'loaded' because this represents |
584 // the idle state. | 586 // the idle state. |
585 _loadPhase = web::PAGE_LOADED; | 587 _loadPhase = web::PAGE_LOADED; |
586 // Content area is lazily instantiated. | 588 // Content area is lazily instantiated. |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
870 | 872 |
871 // Tear down web ui (in case this is part of this tab) and web state now, | 873 // Tear down web ui (in case this is part of this tab) and web state now, |
872 // since the timing of dealloc can't be guaranteed. | 874 // since the timing of dealloc can't be guaranteed. |
873 _webStateImpl.reset(); | 875 _webStateImpl.reset(); |
874 } | 876 } |
875 | 877 |
876 - (void)checkLinkPresenceUnderGesture:(UIGestureRecognizer*)gestureRecognizer | 878 - (void)checkLinkPresenceUnderGesture:(UIGestureRecognizer*)gestureRecognizer |
877 completionHandler:(void (^)(BOOL))completionHandler { | 879 completionHandler:(void (^)(BOOL))completionHandler { |
878 CGPoint webViewPoint = [gestureRecognizer locationInView:self.webView]; | 880 CGPoint webViewPoint = [gestureRecognizer locationInView:self.webView]; |
879 base::WeakNSObject<CRWWebController> weakSelf(self); | 881 base::WeakNSObject<CRWWebController> weakSelf(self); |
880 [self fetchDOMElementAtPoint:webViewPoint | 882 [self |
881 completionHandler:^(scoped_ptr<base::DictionaryValue> element) { | 883 fetchDOMElementAtPoint:webViewPoint |
882 std::string link; | 884 completionHandler:^(std::unique_ptr<base::DictionaryValue> element) { |
883 BOOL hasLink = | 885 std::string link; |
884 element && element->GetString("href", &link) && link.size(); | 886 BOOL hasLink = |
885 completionHandler(hasLink); | 887 element && element->GetString("href", &link) && link.size(); |
886 }]; | 888 completionHandler(hasLink); |
| 889 }]; |
887 } | 890 } |
888 | 891 |
889 - (void)setDOMElementForLastTouch:(scoped_ptr<base::DictionaryValue>)element { | 892 - (void)setDOMElementForLastTouch: |
| 893 (std::unique_ptr<base::DictionaryValue>)element { |
890 _DOMElementForLastTouch = std::move(element); | 894 _DOMElementForLastTouch = std::move(element); |
891 } | 895 } |
892 | 896 |
893 - (void)showContextMenu:(UIGestureRecognizer*)gestureRecognizer { | 897 - (void)showContextMenu:(UIGestureRecognizer*)gestureRecognizer { |
894 // Calling this method if [self supportsCustomContextMenu] returned NO | 898 // Calling this method if [self supportsCustomContextMenu] returned NO |
895 // is a programmer error. | 899 // is a programmer error. |
896 DCHECK([self supportsCustomContextMenu]); | 900 DCHECK([self supportsCustomContextMenu]); |
897 | 901 |
898 // We don't want ongoing notification that the long press is held. | 902 // We don't want ongoing notification that the long press is held. |
899 if ([gestureRecognizer state] != UIGestureRecognizerStateBegan) | 903 if ([gestureRecognizer state] != UIGestureRecognizerStateBegan) |
(...skipping 944 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1844 | 1848 |
1845 url::StringPieceReplacements<std::string> emptyRef; | 1849 url::StringPieceReplacements<std::string> emptyRef; |
1846 emptyRef.SetRefStr(""); | 1850 emptyRef.SetRefStr(""); |
1847 GURL newEndURL = endURL.ReplaceComponents(emptyRef); | 1851 GURL newEndURL = endURL.ReplaceComponents(emptyRef); |
1848 toItem->SetURL(newEndURL); | 1852 toItem->SetURL(newEndURL); |
1849 return newEndURL; | 1853 return newEndURL; |
1850 } | 1854 } |
1851 | 1855 |
1852 - (void)evaluateJavaScript:(NSString*)script | 1856 - (void)evaluateJavaScript:(NSString*)script |
1853 JSONResultHandler: | 1857 JSONResultHandler: |
1854 (void (^)(scoped_ptr<base::Value>, NSError*))handler { | 1858 (void (^)(std::unique_ptr<base::Value>, NSError*))handler { |
1855 [self evaluateJavaScript:script | 1859 [self evaluateJavaScript:script |
1856 stringResultHandler:^(NSString* stringResult, NSError* error) { | 1860 stringResultHandler:^(NSString* stringResult, NSError* error) { |
1857 DCHECK(stringResult || error); | 1861 DCHECK(stringResult || error); |
1858 if (handler) { | 1862 if (handler) { |
1859 scoped_ptr<base::Value> result( | 1863 std::unique_ptr<base::Value> result( |
1860 base::JSONReader::Read(base::SysNSStringToUTF8(stringResult))); | 1864 base::JSONReader::Read(base::SysNSStringToUTF8(stringResult))); |
1861 handler(std::move(result), error); | 1865 handler(std::move(result), error); |
1862 } | 1866 } |
1863 }]; | 1867 }]; |
1864 } | 1868 } |
1865 | 1869 |
1866 - (void)addGestureRecognizerToWebView:(UIGestureRecognizer*)recognizer { | 1870 - (void)addGestureRecognizerToWebView:(UIGestureRecognizer*)recognizer { |
1867 if ([_gestureRecognizers containsObject:recognizer]) | 1871 if ([_gestureRecognizers containsObject:recognizer]) |
1868 return; | 1872 return; |
1869 | 1873 |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2123 // Broken out into separate method to catch errors. | 2127 // Broken out into separate method to catch errors. |
2124 if (![self respondToWKScriptMessage:message]) { | 2128 if (![self respondToWKScriptMessage:message]) { |
2125 DLOG(WARNING) << "Message from JS not handled due to invalid format"; | 2129 DLOG(WARNING) << "Message from JS not handled due to invalid format"; |
2126 } | 2130 } |
2127 } | 2131 } |
2128 | 2132 |
2129 - (BOOL)respondToWKScriptMessage:(WKScriptMessage*)scriptMessage { | 2133 - (BOOL)respondToWKScriptMessage:(WKScriptMessage*)scriptMessage { |
2130 CHECK(scriptMessage.frameInfo.mainFrame); | 2134 CHECK(scriptMessage.frameInfo.mainFrame); |
2131 int errorCode = 0; | 2135 int errorCode = 0; |
2132 std::string errorMessage; | 2136 std::string errorMessage; |
2133 scoped_ptr<base::Value> inputJSONData(base::JSONReader::ReadAndReturnError( | 2137 std::unique_ptr<base::Value> inputJSONData( |
2134 base::SysNSStringToUTF8(scriptMessage.body), false, &errorCode, | 2138 base::JSONReader::ReadAndReturnError( |
2135 &errorMessage)); | 2139 base::SysNSStringToUTF8(scriptMessage.body), false, &errorCode, |
| 2140 &errorMessage)); |
2136 if (errorCode) { | 2141 if (errorCode) { |
2137 DLOG(WARNING) << "JSON parse error: %s" << errorMessage.c_str(); | 2142 DLOG(WARNING) << "JSON parse error: %s" << errorMessage.c_str(); |
2138 return NO; | 2143 return NO; |
2139 } | 2144 } |
2140 base::DictionaryValue* message = nullptr; | 2145 base::DictionaryValue* message = nullptr; |
2141 if (!inputJSONData->GetAsDictionary(&message)) { | 2146 if (!inputJSONData->GetAsDictionary(&message)) { |
2142 return NO; | 2147 return NO; |
2143 } | 2148 } |
2144 std::string windowID; | 2149 std::string windowID; |
2145 message->GetString("crwWindowId", &windowID); | 2150 message->GetString("crwWindowId", &windowID); |
(...skipping 886 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3032 return YES; | 3037 return YES; |
3033 } | 3038 } |
3034 | 3039 |
3035 // This is custom long press gesture recognizer. By the time the gesture is | 3040 // This is custom long press gesture recognizer. By the time the gesture is |
3036 // recognized the web controller needs to know if there is a link under the | 3041 // recognized the web controller needs to know if there is a link under the |
3037 // touch. If there a link, the web controller will reject system's context | 3042 // touch. If there a link, the web controller will reject system's context |
3038 // menu and show another one. If for some reason context menu info is not | 3043 // menu and show another one. If for some reason context menu info is not |
3039 // fetched - system context menu will be shown. | 3044 // fetched - system context menu will be shown. |
3040 [self setDOMElementForLastTouch:nullptr]; | 3045 [self setDOMElementForLastTouch:nullptr]; |
3041 base::WeakNSObject<CRWWebController> weakSelf(self); | 3046 base::WeakNSObject<CRWWebController> weakSelf(self); |
3042 [self fetchDOMElementAtPoint:[touch locationInView:self.webView] | 3047 [self |
3043 completionHandler:^(scoped_ptr<base::DictionaryValue> element) { | 3048 fetchDOMElementAtPoint:[touch locationInView:self.webView] |
3044 [weakSelf setDOMElementForLastTouch:std::move(element)]; | 3049 completionHandler:^(std::unique_ptr<base::DictionaryValue> element) { |
3045 }]; | 3050 [weakSelf setDOMElementForLastTouch:std::move(element)]; |
| 3051 }]; |
3046 return YES; | 3052 return YES; |
3047 } | 3053 } |
3048 | 3054 |
3049 - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer*)gestureRecognizer { | 3055 - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer*)gestureRecognizer { |
3050 // Expect only _contextMenuRecognizer. | 3056 // Expect only _contextMenuRecognizer. |
3051 DCHECK([gestureRecognizer isEqual:_contextMenuRecognizer]); | 3057 DCHECK([gestureRecognizer isEqual:_contextMenuRecognizer]); |
3052 if (!self.webView || ![self supportsCustomContextMenu]) { | 3058 if (!self.webView || ![self supportsCustomContextMenu]) { |
3053 // Show the context menu iff currently displaying a web view. | 3059 // Show the context menu iff currently displaying a web view. |
3054 // Do nothing for native views. | 3060 // Do nothing for native views. |
3055 return NO; | 3061 return NO; |
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3581 } | 3587 } |
3582 | 3588 |
3583 [self evaluateJavaScript:@"__gCrWeb.getPageWidth();" | 3589 [self evaluateJavaScript:@"__gCrWeb.getPageWidth();" |
3584 stringResultHandler:^(NSString* pageWidthAsString, NSError*) { | 3590 stringResultHandler:^(NSString* pageWidthAsString, NSError*) { |
3585 handler([pageWidthAsString floatValue]); | 3591 handler([pageWidthAsString floatValue]); |
3586 }]; | 3592 }]; |
3587 } | 3593 } |
3588 | 3594 |
3589 - (void)fetchDOMElementAtPoint:(CGPoint)point | 3595 - (void)fetchDOMElementAtPoint:(CGPoint)point |
3590 completionHandler: | 3596 completionHandler: |
3591 (void (^)(scoped_ptr<base::DictionaryValue>))handler { | 3597 (void (^)(std::unique_ptr<base::DictionaryValue>))handler { |
3592 DCHECK(handler); | 3598 DCHECK(handler); |
3593 // Convert point into web page's coordinate system (which may be scaled and/or | 3599 // Convert point into web page's coordinate system (which may be scaled and/or |
3594 // scrolled). | 3600 // scrolled). |
3595 CGPoint scrollOffset = self.scrollPosition; | 3601 CGPoint scrollOffset = self.scrollPosition; |
3596 CGFloat webViewContentWidth = self.webScrollView.contentSize.width; | 3602 CGFloat webViewContentWidth = self.webScrollView.contentSize.width; |
3597 base::WeakNSObject<CRWWebController> weakSelf(self); | 3603 base::WeakNSObject<CRWWebController> weakSelf(self); |
3598 [self fetchWebPageWidthWithCompletionHandler:^(CGFloat pageWidth) { | 3604 [self fetchWebPageWidthWithCompletionHandler:^(CGFloat pageWidth) { |
3599 CGFloat scale = pageWidth / webViewContentWidth; | 3605 CGFloat scale = pageWidth / webViewContentWidth; |
3600 CGPoint localPoint = CGPointMake((point.x + scrollOffset.x) * scale, | 3606 CGPoint localPoint = CGPointMake((point.x + scrollOffset.x) * scale, |
3601 (point.y + scrollOffset.y) * scale); | 3607 (point.y + scrollOffset.y) * scale); |
3602 NSString* const kGetElementScript = | 3608 NSString* const kGetElementScript = |
3603 [NSString stringWithFormat:@"__gCrWeb.getElementFromPoint(%g, %g);", | 3609 [NSString stringWithFormat:@"__gCrWeb.getElementFromPoint(%g, %g);", |
3604 localPoint.x, localPoint.y]; | 3610 localPoint.x, localPoint.y]; |
3605 [weakSelf evaluateJavaScript:kGetElementScript | 3611 [weakSelf |
3606 JSONResultHandler:^(scoped_ptr<base::Value> element, NSError*) { | 3612 evaluateJavaScript:kGetElementScript |
3607 // Release raw element and call handler with DictionaryValue. | 3613 JSONResultHandler:^(std::unique_ptr<base::Value> element, NSError*) { |
3608 scoped_ptr<base::DictionaryValue> elementAsDict; | 3614 // Release raw element and call handler with DictionaryValue. |
3609 if (element) { | 3615 std::unique_ptr<base::DictionaryValue> elementAsDict; |
3610 base::DictionaryValue* elementAsDictPtr = nullptr; | 3616 if (element) { |
3611 element.release()->GetAsDictionary(&elementAsDictPtr); | 3617 base::DictionaryValue* elementAsDictPtr = nullptr; |
3612 // |rawElement| and |elementPtr| now point to the same | 3618 element.release()->GetAsDictionary(&elementAsDictPtr); |
3613 // memory. |elementPtr| ownership will be transferred to | 3619 // |rawElement| and |elementPtr| now point to the same |
3614 // |element| scoped_ptr. | 3620 // memory. |elementPtr| ownership will be transferred to |
3615 elementAsDict.reset(elementAsDictPtr); | 3621 // |element| scoped_ptr. |
3616 } | 3622 elementAsDict.reset(elementAsDictPtr); |
3617 handler(std::move(elementAsDict)); | 3623 } |
3618 }]; | 3624 handler(std::move(elementAsDict)); |
| 3625 }]; |
3619 }]; | 3626 }]; |
3620 } | 3627 } |
3621 | 3628 |
3622 - (NSDictionary*)contextMenuInfoForElement:(base::DictionaryValue*)element { | 3629 - (NSDictionary*)contextMenuInfoForElement:(base::DictionaryValue*)element { |
3623 DCHECK(element); | 3630 DCHECK(element); |
3624 NSMutableDictionary* mutableInfo = [NSMutableDictionary dictionary]; | 3631 NSMutableDictionary* mutableInfo = [NSMutableDictionary dictionary]; |
3625 NSString* title = nil; | 3632 NSString* title = nil; |
3626 std::string href; | 3633 std::string href; |
3627 if (element->GetString("href", &href)) { | 3634 if (element->GetString("href", &href)) { |
3628 mutableInfo[web::kContextLinkURLString] = base::SysUTF8ToNSString(href); | 3635 mutableInfo[web::kContextLinkURLString] = base::SysUTF8ToNSString(href); |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3932 if ([MIMEType isEqualToString:@"text/html"] || | 3939 if ([MIMEType isEqualToString:@"text/html"] || |
3933 [MIMEType isEqualToString:@"application/xhtml+xml"] || | 3940 [MIMEType isEqualToString:@"application/xhtml+xml"] || |
3934 [MIMEType isEqualToString:@"application/xml"]) { | 3941 [MIMEType isEqualToString:@"application/xml"]) { |
3935 return web::WEB_VIEW_DOCUMENT_TYPE_HTML; | 3942 return web::WEB_VIEW_DOCUMENT_TYPE_HTML; |
3936 } | 3943 } |
3937 | 3944 |
3938 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC; | 3945 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC; |
3939 } | 3946 } |
3940 | 3947 |
3941 @end | 3948 @end |
OLD | NEW |