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 #include <cmath> | 10 #include <cmath> |
| 11 #include <utility> |
10 | 12 |
11 #include "base/ios/block_types.h" | 13 #include "base/ios/block_types.h" |
12 #import "base/ios/ns_error_util.h" | 14 #import "base/ios/ns_error_util.h" |
13 #include "base/ios/weak_nsobject.h" | 15 #include "base/ios/weak_nsobject.h" |
14 #include "base/json/json_reader.h" | 16 #include "base/json/json_reader.h" |
15 #include "base/json/json_writer.h" | 17 #include "base/json/json_writer.h" |
16 #include "base/json/string_escape.h" | 18 #include "base/json/string_escape.h" |
17 #include "base/logging.h" | 19 #include "base/logging.h" |
18 #include "base/mac/bundle_locations.h" | 20 #include "base/mac/bundle_locations.h" |
19 #include "base/mac/foundation_util.h" | 21 #include "base/mac/foundation_util.h" |
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
578 // Callers should create concrete subclasses instead. | 580 // Callers should create concrete subclasses instead. |
579 NOTREACHED(); | 581 NOTREACHED(); |
580 return nil; | 582 return nil; |
581 } | 583 } |
582 return [super allocWithZone:zone]; | 584 return [super allocWithZone:zone]; |
583 } | 585 } |
584 | 586 |
585 - (instancetype)initWithWebState:(scoped_ptr<WebStateImpl>)webState { | 587 - (instancetype)initWithWebState:(scoped_ptr<WebStateImpl>)webState { |
586 self = [super init]; | 588 self = [super init]; |
587 if (self) { | 589 if (self) { |
588 _webStateImpl = webState.Pass(); | 590 _webStateImpl = std::move(webState); |
589 DCHECK(_webStateImpl); | 591 DCHECK(_webStateImpl); |
590 _webStateImpl->SetWebController(self); | 592 _webStateImpl->SetWebController(self); |
591 _webStateImpl->InitializeRequestTracker(self); | 593 _webStateImpl->InitializeRequestTracker(self); |
592 // Load phase when no WebView present is 'loaded' because this represents | 594 // Load phase when no WebView present is 'loaded' because this represents |
593 // the idle state. | 595 // the idle state. |
594 _loadPhase = web::PAGE_LOADED; | 596 _loadPhase = web::PAGE_LOADED; |
595 // Content area is lazily instantiated. | 597 // Content area is lazily instantiated. |
596 _defaultURL = GURL(url::kAboutBlankURL); | 598 _defaultURL = GURL(url::kAboutBlankURL); |
597 _jsInjectionReceiver.reset( | 599 _jsInjectionReceiver.reset( |
598 [[CRWJSInjectionReceiver alloc] initWithEvaluator:self]); | 600 [[CRWJSInjectionReceiver alloc] initWithEvaluator:self]); |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
887 [self fetchDOMElementAtPoint:webViewPoint | 889 [self fetchDOMElementAtPoint:webViewPoint |
888 completionHandler:^(scoped_ptr<base::DictionaryValue> element) { | 890 completionHandler:^(scoped_ptr<base::DictionaryValue> element) { |
889 std::string link; | 891 std::string link; |
890 BOOL hasLink = | 892 BOOL hasLink = |
891 element && element->GetString("href", &link) && link.size(); | 893 element && element->GetString("href", &link) && link.size(); |
892 completionHandler(hasLink); | 894 completionHandler(hasLink); |
893 }]; | 895 }]; |
894 } | 896 } |
895 | 897 |
896 - (void)setDOMElementForLastTouch:(scoped_ptr<base::DictionaryValue>)element { | 898 - (void)setDOMElementForLastTouch:(scoped_ptr<base::DictionaryValue>)element { |
897 _DOMElementForLastTouch = element.Pass(); | 899 _DOMElementForLastTouch = std::move(element); |
898 } | 900 } |
899 | 901 |
900 - (void)showContextMenu:(UIGestureRecognizer*)gestureRecognizer { | 902 - (void)showContextMenu:(UIGestureRecognizer*)gestureRecognizer { |
901 // Calling this method if [self supportsCustomContextMenu] returned NO | 903 // Calling this method if [self supportsCustomContextMenu] returned NO |
902 // is a programmer error. | 904 // is a programmer error. |
903 DCHECK([self supportsCustomContextMenu]); | 905 DCHECK([self supportsCustomContextMenu]); |
904 | 906 |
905 // We don't want ongoing notification that the long press is held. | 907 // We don't want ongoing notification that the long press is held. |
906 if ([gestureRecognizer state] != UIGestureRecognizerStateBegan) | 908 if ([gestureRecognizer state] != UIGestureRecognizerStateBegan) |
907 return; | 909 return; |
(...skipping 961 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1869 | 1871 |
1870 - (void)evaluateJavaScript:(NSString*)script | 1872 - (void)evaluateJavaScript:(NSString*)script |
1871 JSONResultHandler: | 1873 JSONResultHandler: |
1872 (void (^)(scoped_ptr<base::Value>, NSError*))handler { | 1874 (void (^)(scoped_ptr<base::Value>, NSError*))handler { |
1873 [self evaluateJavaScript:script | 1875 [self evaluateJavaScript:script |
1874 stringResultHandler:^(NSString* stringResult, NSError* error) { | 1876 stringResultHandler:^(NSString* stringResult, NSError* error) { |
1875 DCHECK(stringResult || error); | 1877 DCHECK(stringResult || error); |
1876 if (handler) { | 1878 if (handler) { |
1877 scoped_ptr<base::Value> result( | 1879 scoped_ptr<base::Value> result( |
1878 base::JSONReader::Read(base::SysNSStringToUTF8(stringResult))); | 1880 base::JSONReader::Read(base::SysNSStringToUTF8(stringResult))); |
1879 handler(result.Pass(), error); | 1881 handler(std::move(result), error); |
1880 } | 1882 } |
1881 }]; | 1883 }]; |
1882 } | 1884 } |
1883 | 1885 |
1884 - (void)addGestureRecognizerToWebView:(UIGestureRecognizer*)recognizer { | 1886 - (void)addGestureRecognizerToWebView:(UIGestureRecognizer*)recognizer { |
1885 if ([_gestureRecognizers containsObject:recognizer]) | 1887 if ([_gestureRecognizers containsObject:recognizer]) |
1886 return; | 1888 return; |
1887 | 1889 |
1888 [self.webView addGestureRecognizer:recognizer]; | 1890 [self.webView addGestureRecognizer:recognizer]; |
1889 [_gestureRecognizers addObject:recognizer]; | 1891 [_gestureRecognizers addObject:recognizer]; |
(...skipping 1089 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2979 | 2981 |
2980 // This is custom long press gesture recognizer. By the time the gesture is | 2982 // This is custom long press gesture recognizer. By the time the gesture is |
2981 // recognized the web controller needs to know if there is a link under the | 2983 // recognized the web controller needs to know if there is a link under the |
2982 // touch. If there a link, the web controller will reject system's context | 2984 // touch. If there a link, the web controller will reject system's context |
2983 // menu and show another one. If for some reason context menu info is not | 2985 // menu and show another one. If for some reason context menu info is not |
2984 // fetched - system context menu will be shown. | 2986 // fetched - system context menu will be shown. |
2985 [self setDOMElementForLastTouch:nullptr]; | 2987 [self setDOMElementForLastTouch:nullptr]; |
2986 base::WeakNSObject<CRWWebController> weakSelf(self); | 2988 base::WeakNSObject<CRWWebController> weakSelf(self); |
2987 [self fetchDOMElementAtPoint:[touch locationInView:self.webView] | 2989 [self fetchDOMElementAtPoint:[touch locationInView:self.webView] |
2988 completionHandler:^(scoped_ptr<base::DictionaryValue> element) { | 2990 completionHandler:^(scoped_ptr<base::DictionaryValue> element) { |
2989 [weakSelf setDOMElementForLastTouch:element.Pass()]; | 2991 [weakSelf setDOMElementForLastTouch:std::move(element)]; |
2990 }]; | 2992 }]; |
2991 return YES; | 2993 return YES; |
2992 } | 2994 } |
2993 | 2995 |
2994 - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer*)gestureRecognizer { | 2996 - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer*)gestureRecognizer { |
2995 // Expect only _contextMenuRecognizer. | 2997 // Expect only _contextMenuRecognizer. |
2996 DCHECK([gestureRecognizer isEqual:_contextMenuRecognizer]); | 2998 DCHECK([gestureRecognizer isEqual:_contextMenuRecognizer]); |
2997 if (!self.webView || ![self supportsCustomContextMenu]) { | 2999 if (!self.webView || ![self supportsCustomContextMenu]) { |
2998 // Show the context menu iff currently displaying a web view. | 3000 // Show the context menu iff currently displaying a web view. |
2999 // Do nothing for native views. | 3001 // Do nothing for native views. |
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3569 // Release raw element and call handler with DictionaryValue. | 3571 // Release raw element and call handler with DictionaryValue. |
3570 scoped_ptr<base::DictionaryValue> elementAsDict; | 3572 scoped_ptr<base::DictionaryValue> elementAsDict; |
3571 if (element) { | 3573 if (element) { |
3572 base::DictionaryValue* elementAsDictPtr = nullptr; | 3574 base::DictionaryValue* elementAsDictPtr = nullptr; |
3573 element.release()->GetAsDictionary(&elementAsDictPtr); | 3575 element.release()->GetAsDictionary(&elementAsDictPtr); |
3574 // |rawElement| and |elementPtr| now point to the same | 3576 // |rawElement| and |elementPtr| now point to the same |
3575 // memory. |elementPtr| ownership will be transferred to | 3577 // memory. |elementPtr| ownership will be transferred to |
3576 // |element| scoped_ptr. | 3578 // |element| scoped_ptr. |
3577 elementAsDict.reset(elementAsDictPtr); | 3579 elementAsDict.reset(elementAsDictPtr); |
3578 } | 3580 } |
3579 handler(elementAsDict.Pass()); | 3581 handler(std::move(elementAsDict)); |
3580 }]; | 3582 }]; |
3581 }]; | 3583 }]; |
3582 } | 3584 } |
3583 | 3585 |
3584 - (NSDictionary*)contextMenuInfoForElement:(base::DictionaryValue*)element { | 3586 - (NSDictionary*)contextMenuInfoForElement:(base::DictionaryValue*)element { |
3585 DCHECK(element); | 3587 DCHECK(element); |
3586 NSMutableDictionary* mutableInfo = [NSMutableDictionary dictionary]; | 3588 NSMutableDictionary* mutableInfo = [NSMutableDictionary dictionary]; |
3587 NSString* title = nil; | 3589 NSString* title = nil; |
3588 std::string href; | 3590 std::string href; |
3589 if (element->GetString("href", &href)) { | 3591 if (element->GetString("href", &href)) { |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3899 if ([MIMEType isEqualToString:@"text/html"] || | 3901 if ([MIMEType isEqualToString:@"text/html"] || |
3900 [MIMEType isEqualToString:@"application/xhtml+xml"] || | 3902 [MIMEType isEqualToString:@"application/xhtml+xml"] || |
3901 [MIMEType isEqualToString:@"application/xml"]) { | 3903 [MIMEType isEqualToString:@"application/xml"]) { |
3902 return web::WEB_VIEW_DOCUMENT_TYPE_HTML; | 3904 return web::WEB_VIEW_DOCUMENT_TYPE_HTML; |
3903 } | 3905 } |
3904 | 3906 |
3905 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC; | 3907 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC; |
3906 } | 3908 } |
3907 | 3909 |
3908 @end | 3910 @end |
OLD | NEW |