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

Side by Side Diff: ios/web/web_state/ui/crw_web_controller.mm

Issue 1861593005: Convert //ios from scoped_ptr to std::unique_ptr. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase? Created 4 years, 8 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
OLDNEW
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 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 // The touch tracking recognizer allowing us to decide if a navigation is 240 // The touch tracking recognizer allowing us to decide if a navigation is
241 // started by the user. 241 // started by the user.
242 base::scoped_nsobject<CRWTouchTrackingRecognizer> _touchTrackingRecognizer; 242 base::scoped_nsobject<CRWTouchTrackingRecognizer> _touchTrackingRecognizer;
243 // Long press recognizer that allows showing context menus. 243 // Long press recognizer that allows showing context menus.
244 base::scoped_nsobject<UILongPressGestureRecognizer> _contextMenuRecognizer; 244 base::scoped_nsobject<UILongPressGestureRecognizer> _contextMenuRecognizer;
245 // DOM element information for the point where the user made the last touch. 245 // DOM element information for the point where the user made the last touch.
246 // Can be null if has not been calculated yet. Precalculation is necessary 246 // Can be null if has not been calculated yet. Precalculation is necessary
247 // because retreiving DOM element relies on async API so element info can not 247 // because retreiving DOM element relies on async API so element info can not
248 // be built on demand. May contain the following keys: "href", "src", "title", 248 // be built on demand. May contain the following keys: "href", "src", "title",
249 // "referrerPolicy". All values are strings. Used for showing context menus. 249 // "referrerPolicy". All values are strings. Used for showing context menus.
250 scoped_ptr<base::DictionaryValue> _DOMElementForLastTouch; 250 std::unique_ptr<base::DictionaryValue> _DOMElementForLastTouch;
251 // Whether a click is in progress. 251 // Whether a click is in progress.
252 BOOL _clickInProgress; 252 BOOL _clickInProgress;
253 // Data on the recorded last user interaction. 253 // Data on the recorded last user interaction.
254 scoped_ptr<web::UserInteractionEvent> _lastUserInteraction; 254 std::unique_ptr<web::UserInteractionEvent> _lastUserInteraction;
255 // YES if there has been user interaction with views owned by this controller. 255 // YES if there has been user interaction with views owned by this controller.
256 BOOL _userInteractedWithWebController; 256 BOOL _userInteractedWithWebController;
257 // The time of the last page transfer start, measured in seconds since Jan 1 257 // The time of the last page transfer start, measured in seconds since Jan 1
258 // 2001. 258 // 2001.
259 CFAbsoluteTime _lastTransferTimeInSeconds; 259 CFAbsoluteTime _lastTransferTimeInSeconds;
260 // Default URL (about:blank). 260 // Default URL (about:blank).
261 GURL _defaultURL; 261 GURL _defaultURL;
262 // Show overlay view, don't reload web page. 262 // Show overlay view, don't reload web page.
263 BOOL _overlayPreviewMode; 263 BOOL _overlayPreviewMode;
264 // If |YES|, calls |setShouldSuppressDialogs:YES| when window id is injected 264 // If |YES|, calls |setShouldSuppressDialogs:YES| when window id is injected
265 // into the web view. 265 // into the web view.
266 BOOL _shouldSuppressDialogsOnWindowIDInjection; 266 BOOL _shouldSuppressDialogsOnWindowIDInjection;
267 // The URL of an expected future recreation of the |webView|. Valid 267 // The URL of an expected future recreation of the |webView|. Valid
268 // only if the web view was discarded for non-user-visible reasons, such that 268 // only if the web view was discarded for non-user-visible reasons, such that
269 // if the next load request is for that URL, it should be treated as a 269 // if the next load request is for that URL, it should be treated as a
270 // reconstruction that should use cache aggressively. 270 // reconstruction that should use cache aggressively.
271 GURL _expectedReconstructionURL; 271 GURL _expectedReconstructionURL;
272 // Whether the web page is currently performing window.history.pushState or 272 // Whether the web page is currently performing window.history.pushState or
273 // window.history.replaceState 273 // window.history.replaceState
274 // Set to YES on window.history.willChangeState message. To NO on 274 // Set to YES on window.history.willChangeState message. To NO on
275 // window.history.didPushState or window.history.didReplaceState. 275 // window.history.didPushState or window.history.didReplaceState.
276 BOOL _changingHistoryState; 276 BOOL _changingHistoryState;
277 277
278 scoped_ptr<web::NewWindowInfo> _externalRequest; 278 std::unique_ptr<web::NewWindowInfo> _externalRequest;
279 279
280 // The WebStateImpl instance associated with this CRWWebController. 280 // The WebStateImpl instance associated with this CRWWebController.
281 scoped_ptr<WebStateImpl> _webStateImpl; 281 std::unique_ptr<WebStateImpl> _webStateImpl;
282 282
283 // A set of URLs opened in external applications; stored so that errors 283 // A set of URLs opened in external applications; stored so that errors
284 // from the web view can be identified as resulting from these events. 284 // from the web view can be identified as resulting from these events.
285 base::scoped_nsobject<NSMutableSet> _openedApplicationURL; 285 base::scoped_nsobject<NSMutableSet> _openedApplicationURL;
286 286
287 // Object that manages all early script injection into the web view. 287 // Object that manages all early script injection into the web view.
288 base::scoped_nsobject<CRWJSEarlyScriptManager> _earlyScriptManager; 288 base::scoped_nsobject<CRWJSEarlyScriptManager> _earlyScriptManager;
289 289
290 // Script manager for setting the windowID. 290 // Script manager for setting the windowID.
291 base::scoped_nsobject<CRWJSWindowIdManager> _windowIDJSManager; 291 base::scoped_nsobject<CRWJSWindowIdManager> _windowIDJSManager;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 - (BOOL)shouldClosePageOnNativeApplicationLoad; 343 - (BOOL)shouldClosePageOnNativeApplicationLoad;
344 // Called after URL is finished loading and _loadPhase is set to PAGE_LOADED. 344 // Called after URL is finished loading and _loadPhase is set to PAGE_LOADED.
345 - (void)didFinishWithURL:(const GURL&)currentURL loadSuccess:(BOOL)loadSuccess; 345 - (void)didFinishWithURL:(const GURL&)currentURL loadSuccess:(BOOL)loadSuccess;
346 // Informs the native controller if web usage is allowed or not. 346 // Informs the native controller if web usage is allowed or not.
347 - (void)setNativeControllerWebUsageEnabled:(BOOL)webUsageEnabled; 347 - (void)setNativeControllerWebUsageEnabled:(BOOL)webUsageEnabled;
348 // Evaluates the supplied JavaScript in the web view. Calls |handler| with 348 // Evaluates the supplied JavaScript in the web view. Calls |handler| with
349 // results of the evaluation (which may be nil if the implementing object has no 349 // results of the evaluation (which may be nil if the implementing object has no
350 // way to run the evaluation or the evaluation returns a nil value) or an 350 // way to run the evaluation or the evaluation returns a nil value) or an
351 // NSError if there is an error. The |handler| can be nil. 351 // NSError if there is an error. The |handler| can be nil.
352 - (void)evaluateJavaScript:(NSString*)script 352 - (void)evaluateJavaScript:(NSString*)script
353 JSONResultHandler:(void (^)(scoped_ptr<base::Value>, NSError*))handler; 353 JSONResultHandler:
354 (void (^)(std::unique_ptr<base::Value>, NSError*))handler;
354 // Attempts to handle a script message. Returns YES on success, NO otherwise. 355 // Attempts to handle a script message. Returns YES on success, NO otherwise.
355 - (BOOL)respondToWKScriptMessage:(WKScriptMessage*)scriptMessage; 356 - (BOOL)respondToWKScriptMessage:(WKScriptMessage*)scriptMessage;
356 // Generates the JavaScript string used to update the UIWebView's URL so that it 357 // Generates the JavaScript string used to update the UIWebView's URL so that it
357 // matches the URL displayed in the omnibox and sets window.history.state to 358 // matches the URL displayed in the omnibox and sets window.history.state to
358 // stateObject. Needed for history.pushState() and history.replaceState(). 359 // stateObject. Needed for history.pushState() and history.replaceState().
359 - (NSString*)javascriptToReplaceWebViewURL:(const GURL&)URL 360 - (NSString*)javascriptToReplaceWebViewURL:(const GURL&)URL
360 stateObjectJSON:(NSString*)stateObject; 361 stateObjectJSON:(NSString*)stateObject;
361 // Injects JavaScript into the web view to update the URL to |URL|, to set 362 // Injects JavaScript into the web view to update the URL to |URL|, to set
362 // window.history.state to |stateObject|, and to trigger a popstate() event. 363 // window.history.state to |stateObject|, and to trigger a popstate() event.
363 // Upon the scripts completion, resets |urlOnStartLoading_| and 364 // Upon the scripts completion, resets |urlOnStartLoading_| and
(...skipping 26 matching lines...) Expand all
390 // Sets scroll offset value for webview scroll view from |scrollState|. 391 // Sets scroll offset value for webview scroll view from |scrollState|.
391 - (void)applyWebViewScrollOffsetFromScrollState: 392 - (void)applyWebViewScrollOffsetFromScrollState:
392 (const web::PageScrollState&)scrollState; 393 (const web::PageScrollState&)scrollState;
393 // Asynchronously fetches full width of the rendered web page. 394 // Asynchronously fetches full width of the rendered web page.
394 - (void)fetchWebPageWidthWithCompletionHandler:(void (^)(CGFloat))handler; 395 - (void)fetchWebPageWidthWithCompletionHandler:(void (^)(CGFloat))handler;
395 // Asynchronously fetches information about DOM element for the given point (in 396 // Asynchronously fetches information about DOM element for the given point (in
396 // UIView coordinates). |handler| can not be nil. See |_DOMElementForLastTouch| 397 // UIView coordinates). |handler| can not be nil. See |_DOMElementForLastTouch|
397 // for element format description. 398 // for element format description.
398 - (void)fetchDOMElementAtPoint:(CGPoint)point 399 - (void)fetchDOMElementAtPoint:(CGPoint)point
399 completionHandler: 400 completionHandler:
400 (void (^)(scoped_ptr<base::DictionaryValue>))handler; 401 (void (^)(std::unique_ptr<base::DictionaryValue>))handler;
401 // Extracts context menu information from the given DOM element. 402 // Extracts context menu information from the given DOM element.
402 // result keys are defined in crw_context_menu_provider.h. 403 // result keys are defined in crw_context_menu_provider.h.
403 - (NSDictionary*)contextMenuInfoForElement:(base::DictionaryValue*)element; 404 - (NSDictionary*)contextMenuInfoForElement:(base::DictionaryValue*)element;
404 // Sets the value of |_DOMElementForLastTouch|. 405 // Sets the value of |_DOMElementForLastTouch|.
405 - (void)setDOMElementForLastTouch:(scoped_ptr<base::DictionaryValue>)element; 406 - (void)setDOMElementForLastTouch:
407 (std::unique_ptr<base::DictionaryValue>)element;
406 // Called when the window has determined there was a long-press and context menu 408 // Called when the window has determined there was a long-press and context menu
407 // must be shown. 409 // must be shown.
408 - (void)showContextMenu:(UIGestureRecognizer*)gestureRecognizer; 410 - (void)showContextMenu:(UIGestureRecognizer*)gestureRecognizer;
409 // YES if delegate supports showing context menu by responding to 411 // YES if delegate supports showing context menu by responding to
410 // webController:runContextMenu:atPoint:inView: selector. 412 // webController:runContextMenu:atPoint:inView: selector.
411 - (BOOL)supportsCustomContextMenu; 413 - (BOOL)supportsCustomContextMenu;
412 // Cancels all touch events in the web view (long presses, tapping, scrolling). 414 // Cancels all touch events in the web view (long presses, tapping, scrolling).
413 - (void)cancelAllTouches; 415 - (void)cancelAllTouches;
414 // Returns the referrer for the current page. 416 // Returns the referrer for the current page.
415 - (web::Referrer)currentReferrer; 417 - (web::Referrer)currentReferrer;
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 + (instancetype)allocWithZone:(struct _NSZone*)zone { 571 + (instancetype)allocWithZone:(struct _NSZone*)zone {
570 if (self == [CRWWebController class]) { 572 if (self == [CRWWebController class]) {
571 // This is an abstract class which should not be instantiated directly. 573 // This is an abstract class which should not be instantiated directly.
572 // Callers should create concrete subclasses instead. 574 // Callers should create concrete subclasses instead.
573 NOTREACHED(); 575 NOTREACHED();
574 return nil; 576 return nil;
575 } 577 }
576 return [super allocWithZone:zone]; 578 return [super allocWithZone:zone];
577 } 579 }
578 580
579 - (instancetype)initWithWebState:(scoped_ptr<WebStateImpl>)webState { 581 - (instancetype)initWithWebState:(std::unique_ptr<WebStateImpl>)webState {
580 self = [super init]; 582 self = [super init];
581 if (self) { 583 if (self) {
582 _webStateImpl = std::move(webState); 584 _webStateImpl = std::move(webState);
583 DCHECK(_webStateImpl); 585 DCHECK(_webStateImpl);
584 _webStateImpl->SetWebController(self); 586 _webStateImpl->SetWebController(self);
585 _webStateImpl->InitializeRequestTracker(self); 587 _webStateImpl->InitializeRequestTracker(self);
586 // Load phase when no WebView present is 'loaded' because this represents 588 // Load phase when no WebView present is 'loaded' because this represents
587 // the idle state. 589 // the idle state.
588 _loadPhase = web::PAGE_LOADED; 590 _loadPhase = web::PAGE_LOADED;
589 // Content area is lazily instantiated. 591 // Content area is lazily instantiated.
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
873 875
874 // Tear down web ui (in case this is part of this tab) and web state now, 876 // Tear down web ui (in case this is part of this tab) and web state now,
875 // since the timing of dealloc can't be guaranteed. 877 // since the timing of dealloc can't be guaranteed.
876 _webStateImpl.reset(); 878 _webStateImpl.reset();
877 } 879 }
878 880
879 - (void)checkLinkPresenceUnderGesture:(UIGestureRecognizer*)gestureRecognizer 881 - (void)checkLinkPresenceUnderGesture:(UIGestureRecognizer*)gestureRecognizer
880 completionHandler:(void (^)(BOOL))completionHandler { 882 completionHandler:(void (^)(BOOL))completionHandler {
881 CGPoint webViewPoint = [gestureRecognizer locationInView:self.webView]; 883 CGPoint webViewPoint = [gestureRecognizer locationInView:self.webView];
882 base::WeakNSObject<CRWWebController> weakSelf(self); 884 base::WeakNSObject<CRWWebController> weakSelf(self);
883 [self fetchDOMElementAtPoint:webViewPoint 885 [self
884 completionHandler:^(scoped_ptr<base::DictionaryValue> element) { 886 fetchDOMElementAtPoint:webViewPoint
885 std::string link; 887 completionHandler:^(std::unique_ptr<base::DictionaryValue> element) {
886 BOOL hasLink = 888 std::string link;
887 element && element->GetString("href", &link) && link.size(); 889 BOOL hasLink =
888 completionHandler(hasLink); 890 element && element->GetString("href", &link) && link.size();
889 }]; 891 completionHandler(hasLink);
892 }];
890 } 893 }
891 894
892 - (void)setDOMElementForLastTouch:(scoped_ptr<base::DictionaryValue>)element { 895 - (void)setDOMElementForLastTouch:
896 (std::unique_ptr<base::DictionaryValue>)element {
893 _DOMElementForLastTouch = std::move(element); 897 _DOMElementForLastTouch = std::move(element);
894 } 898 }
895 899
896 - (void)showContextMenu:(UIGestureRecognizer*)gestureRecognizer { 900 - (void)showContextMenu:(UIGestureRecognizer*)gestureRecognizer {
897 // Calling this method if [self supportsCustomContextMenu] returned NO 901 // Calling this method if [self supportsCustomContextMenu] returned NO
898 // is a programmer error. 902 // is a programmer error.
899 DCHECK([self supportsCustomContextMenu]); 903 DCHECK([self supportsCustomContextMenu]);
900 904
901 // We don't want ongoing notification that the long press is held. 905 // We don't want ongoing notification that the long press is held.
902 if ([gestureRecognizer state] != UIGestureRecognizerStateBegan) 906 if ([gestureRecognizer state] != UIGestureRecognizerStateBegan)
(...skipping 944 matching lines...) Expand 10 before | Expand all | Expand 10 after
1847 1851
1848 url::StringPieceReplacements<std::string> emptyRef; 1852 url::StringPieceReplacements<std::string> emptyRef;
1849 emptyRef.SetRefStr(""); 1853 emptyRef.SetRefStr("");
1850 GURL newEndURL = endURL.ReplaceComponents(emptyRef); 1854 GURL newEndURL = endURL.ReplaceComponents(emptyRef);
1851 toItem->SetURL(newEndURL); 1855 toItem->SetURL(newEndURL);
1852 return newEndURL; 1856 return newEndURL;
1853 } 1857 }
1854 1858
1855 - (void)evaluateJavaScript:(NSString*)script 1859 - (void)evaluateJavaScript:(NSString*)script
1856 JSONResultHandler: 1860 JSONResultHandler:
1857 (void (^)(scoped_ptr<base::Value>, NSError*))handler { 1861 (void (^)(std::unique_ptr<base::Value>, NSError*))handler {
1858 [self evaluateJavaScript:script 1862 [self evaluateJavaScript:script
1859 stringResultHandler:^(NSString* stringResult, NSError* error) { 1863 stringResultHandler:^(NSString* stringResult, NSError* error) {
1860 DCHECK(stringResult || error); 1864 DCHECK(stringResult || error);
1861 if (handler) { 1865 if (handler) {
1862 scoped_ptr<base::Value> result( 1866 std::unique_ptr<base::Value> result(
1863 base::JSONReader::Read(base::SysNSStringToUTF8(stringResult))); 1867 base::JSONReader::Read(base::SysNSStringToUTF8(stringResult)));
1864 handler(std::move(result), error); 1868 handler(std::move(result), error);
1865 } 1869 }
1866 }]; 1870 }];
1867 } 1871 }
1868 1872
1869 - (void)addGestureRecognizerToWebView:(UIGestureRecognizer*)recognizer { 1873 - (void)addGestureRecognizerToWebView:(UIGestureRecognizer*)recognizer {
1870 if ([_gestureRecognizers containsObject:recognizer]) 1874 if ([_gestureRecognizers containsObject:recognizer])
1871 return; 1875 return;
1872 1876
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
2126 // Broken out into separate method to catch errors. 2130 // Broken out into separate method to catch errors.
2127 if (![self respondToWKScriptMessage:message]) { 2131 if (![self respondToWKScriptMessage:message]) {
2128 DLOG(WARNING) << "Message from JS not handled due to invalid format"; 2132 DLOG(WARNING) << "Message from JS not handled due to invalid format";
2129 } 2133 }
2130 } 2134 }
2131 2135
2132 - (BOOL)respondToWKScriptMessage:(WKScriptMessage*)scriptMessage { 2136 - (BOOL)respondToWKScriptMessage:(WKScriptMessage*)scriptMessage {
2133 CHECK(scriptMessage.frameInfo.mainFrame); 2137 CHECK(scriptMessage.frameInfo.mainFrame);
2134 int errorCode = 0; 2138 int errorCode = 0;
2135 std::string errorMessage; 2139 std::string errorMessage;
2136 scoped_ptr<base::Value> inputJSONData(base::JSONReader::ReadAndReturnError( 2140 std::unique_ptr<base::Value> inputJSONData(
2137 base::SysNSStringToUTF8(scriptMessage.body), false, &errorCode, 2141 base::JSONReader::ReadAndReturnError(
2138 &errorMessage)); 2142 base::SysNSStringToUTF8(scriptMessage.body), false, &errorCode,
2143 &errorMessage));
2139 if (errorCode) { 2144 if (errorCode) {
2140 DLOG(WARNING) << "JSON parse error: %s" << errorMessage.c_str(); 2145 DLOG(WARNING) << "JSON parse error: %s" << errorMessage.c_str();
2141 return NO; 2146 return NO;
2142 } 2147 }
2143 base::DictionaryValue* message = nullptr; 2148 base::DictionaryValue* message = nullptr;
2144 if (!inputJSONData->GetAsDictionary(&message)) { 2149 if (!inputJSONData->GetAsDictionary(&message)) {
2145 return NO; 2150 return NO;
2146 } 2151 }
2147 std::string windowID; 2152 std::string windowID;
2148 message->GetString("crwWindowId", &windowID); 2153 message->GetString("crwWindowId", &windowID);
(...skipping 886 matching lines...) Expand 10 before | Expand all | Expand 10 after
3035 return YES; 3040 return YES;
3036 } 3041 }
3037 3042
3038 // This is custom long press gesture recognizer. By the time the gesture is 3043 // This is custom long press gesture recognizer. By the time the gesture is
3039 // recognized the web controller needs to know if there is a link under the 3044 // recognized the web controller needs to know if there is a link under the
3040 // touch. If there a link, the web controller will reject system's context 3045 // touch. If there a link, the web controller will reject system's context
3041 // menu and show another one. If for some reason context menu info is not 3046 // menu and show another one. If for some reason context menu info is not
3042 // fetched - system context menu will be shown. 3047 // fetched - system context menu will be shown.
3043 [self setDOMElementForLastTouch:nullptr]; 3048 [self setDOMElementForLastTouch:nullptr];
3044 base::WeakNSObject<CRWWebController> weakSelf(self); 3049 base::WeakNSObject<CRWWebController> weakSelf(self);
3045 [self fetchDOMElementAtPoint:[touch locationInView:self.webView] 3050 [self
3046 completionHandler:^(scoped_ptr<base::DictionaryValue> element) { 3051 fetchDOMElementAtPoint:[touch locationInView:self.webView]
3047 [weakSelf setDOMElementForLastTouch:std::move(element)]; 3052 completionHandler:^(std::unique_ptr<base::DictionaryValue> element) {
3048 }]; 3053 [weakSelf setDOMElementForLastTouch:std::move(element)];
3054 }];
3049 return YES; 3055 return YES;
3050 } 3056 }
3051 3057
3052 - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer*)gestureRecognizer { 3058 - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer*)gestureRecognizer {
3053 // Expect only _contextMenuRecognizer. 3059 // Expect only _contextMenuRecognizer.
3054 DCHECK([gestureRecognizer isEqual:_contextMenuRecognizer]); 3060 DCHECK([gestureRecognizer isEqual:_contextMenuRecognizer]);
3055 if (!self.webView || ![self supportsCustomContextMenu]) { 3061 if (!self.webView || ![self supportsCustomContextMenu]) {
3056 // Show the context menu iff currently displaying a web view. 3062 // Show the context menu iff currently displaying a web view.
3057 // Do nothing for native views. 3063 // Do nothing for native views.
3058 return NO; 3064 return NO;
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after
3597 } 3603 }
3598 3604
3599 [self evaluateJavaScript:@"__gCrWeb.getPageWidth();" 3605 [self evaluateJavaScript:@"__gCrWeb.getPageWidth();"
3600 stringResultHandler:^(NSString* pageWidthAsString, NSError*) { 3606 stringResultHandler:^(NSString* pageWidthAsString, NSError*) {
3601 handler([pageWidthAsString floatValue]); 3607 handler([pageWidthAsString floatValue]);
3602 }]; 3608 }];
3603 } 3609 }
3604 3610
3605 - (void)fetchDOMElementAtPoint:(CGPoint)point 3611 - (void)fetchDOMElementAtPoint:(CGPoint)point
3606 completionHandler: 3612 completionHandler:
3607 (void (^)(scoped_ptr<base::DictionaryValue>))handler { 3613 (void (^)(std::unique_ptr<base::DictionaryValue>))handler {
3608 DCHECK(handler); 3614 DCHECK(handler);
3609 // Convert point into web page's coordinate system (which may be scaled and/or 3615 // Convert point into web page's coordinate system (which may be scaled and/or
3610 // scrolled). 3616 // scrolled).
3611 CGPoint scrollOffset = self.scrollPosition; 3617 CGPoint scrollOffset = self.scrollPosition;
3612 CGFloat webViewContentWidth = self.webScrollView.contentSize.width; 3618 CGFloat webViewContentWidth = self.webScrollView.contentSize.width;
3613 base::WeakNSObject<CRWWebController> weakSelf(self); 3619 base::WeakNSObject<CRWWebController> weakSelf(self);
3614 [self fetchWebPageWidthWithCompletionHandler:^(CGFloat pageWidth) { 3620 [self fetchWebPageWidthWithCompletionHandler:^(CGFloat pageWidth) {
3615 CGFloat scale = pageWidth / webViewContentWidth; 3621 CGFloat scale = pageWidth / webViewContentWidth;
3616 CGPoint localPoint = CGPointMake((point.x + scrollOffset.x) * scale, 3622 CGPoint localPoint = CGPointMake((point.x + scrollOffset.x) * scale,
3617 (point.y + scrollOffset.y) * scale); 3623 (point.y + scrollOffset.y) * scale);
3618 NSString* const kGetElementScript = 3624 NSString* const kGetElementScript =
3619 [NSString stringWithFormat:@"__gCrWeb.getElementFromPoint(%g, %g);", 3625 [NSString stringWithFormat:@"__gCrWeb.getElementFromPoint(%g, %g);",
3620 localPoint.x, localPoint.y]; 3626 localPoint.x, localPoint.y];
3621 [weakSelf evaluateJavaScript:kGetElementScript 3627 [weakSelf
3622 JSONResultHandler:^(scoped_ptr<base::Value> element, NSError*) { 3628 evaluateJavaScript:kGetElementScript
3623 // Release raw element and call handler with DictionaryValue. 3629 JSONResultHandler:^(std::unique_ptr<base::Value> element, NSError*) {
3624 scoped_ptr<base::DictionaryValue> elementAsDict; 3630 // Release raw element and call handler with DictionaryValue.
3625 if (element) { 3631 std::unique_ptr<base::DictionaryValue> elementAsDict;
3626 base::DictionaryValue* elementAsDictPtr = nullptr; 3632 if (element) {
3627 element.release()->GetAsDictionary(&elementAsDictPtr); 3633 base::DictionaryValue* elementAsDictPtr = nullptr;
3628 // |rawElement| and |elementPtr| now point to the same 3634 element.release()->GetAsDictionary(&elementAsDictPtr);
3629 // memory. |elementPtr| ownership will be transferred to 3635 // |rawElement| and |elementPtr| now point to the same
3630 // |element| scoped_ptr. 3636 // memory. |elementPtr| ownership will be transferred to
3631 elementAsDict.reset(elementAsDictPtr); 3637 // |element| scoped_ptr.
3632 } 3638 elementAsDict.reset(elementAsDictPtr);
3633 handler(std::move(elementAsDict)); 3639 }
3634 }]; 3640 handler(std::move(elementAsDict));
3641 }];
3635 }]; 3642 }];
3636 } 3643 }
3637 3644
3638 - (NSDictionary*)contextMenuInfoForElement:(base::DictionaryValue*)element { 3645 - (NSDictionary*)contextMenuInfoForElement:(base::DictionaryValue*)element {
3639 DCHECK(element); 3646 DCHECK(element);
3640 NSMutableDictionary* mutableInfo = [NSMutableDictionary dictionary]; 3647 NSMutableDictionary* mutableInfo = [NSMutableDictionary dictionary];
3641 NSString* title = nil; 3648 NSString* title = nil;
3642 std::string href; 3649 std::string href;
3643 if (element->GetString("href", &href)) { 3650 if (element->GetString("href", &href)) {
3644 mutableInfo[web::kContextLinkURLString] = base::SysUTF8ToNSString(href); 3651 mutableInfo[web::kContextLinkURLString] = base::SysUTF8ToNSString(href);
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
3948 if ([MIMEType isEqualToString:@"text/html"] || 3955 if ([MIMEType isEqualToString:@"text/html"] ||
3949 [MIMEType isEqualToString:@"application/xhtml+xml"] || 3956 [MIMEType isEqualToString:@"application/xhtml+xml"] ||
3950 [MIMEType isEqualToString:@"application/xml"]) { 3957 [MIMEType isEqualToString:@"application/xml"]) {
3951 return web::WEB_VIEW_DOCUMENT_TYPE_HTML; 3958 return web::WEB_VIEW_DOCUMENT_TYPE_HTML;
3952 } 3959 }
3953 3960
3954 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC; 3961 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC;
3955 } 3962 }
3956 3963
3957 @end 3964 @end
OLDNEW
« no previous file with comments | « ios/web/web_state/ui/crw_web_controller.h ('k') | ios/web/web_state/ui/crw_web_controller+protected.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698