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 <cmath> | 8 #include <cmath> |
9 | 9 |
10 #include "base/ios/block_types.h" | 10 #include "base/ios/block_types.h" |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 // entry). | 356 // entry). |
357 - (CRWSessionEntry*)currentSessionEntry; | 357 - (CRWSessionEntry*)currentSessionEntry; |
358 - (web::NavigationItem*)currentNavItem; | 358 - (web::NavigationItem*)currentNavItem; |
359 // Returns the referrer for currentURL as a string. May return nil. | 359 // Returns the referrer for currentURL as a string. May return nil. |
360 - (web::Referrer)currentSessionEntryReferrer; | 360 - (web::Referrer)currentSessionEntryReferrer; |
361 // The data and HTTP headers associated to the current entry. These are nil | 361 // The data and HTTP headers associated to the current entry. These are nil |
362 // unless the request was a POST. | 362 // unless the request was a POST. |
363 - (NSData*)currentPOSTData; | 363 - (NSData*)currentPOSTData; |
364 - (NSDictionary*)currentHttpHeaders; | 364 - (NSDictionary*)currentHttpHeaders; |
365 | 365 |
366 // Have the current web view load the request. If needed, it will add | |
367 // information to let the network stack access the requestGroupID. | |
368 - (void)loadRequest:(NSMutableURLRequest*)request; | |
369 // Finds all the scrollviews in the view hierarchy and makes sure they do not | 366 // Finds all the scrollviews in the view hierarchy and makes sure they do not |
370 // interfere with scroll to top when tapping the statusbar. | 367 // interfere with scroll to top when tapping the statusbar. |
371 - (void)optOutScrollsToTopForSubviews; | 368 - (void)optOutScrollsToTopForSubviews; |
372 // Tears down the old native controller, and then replaces it with the new one. | 369 // Tears down the old native controller, and then replaces it with the new one. |
373 - (void)setNativeController:(id<CRWNativeContent>)nativeController; | 370 - (void)setNativeController:(id<CRWNativeContent>)nativeController; |
374 // Returns whether |url| should be opened. | 371 // Returns whether |url| should be opened. |
375 - (BOOL)shouldOpenURL:(const GURL&)url | 372 - (BOOL)shouldOpenURL:(const GURL&)url |
376 mainDocumentURL:(const GURL&)mainDocumentURL | 373 mainDocumentURL:(const GURL&)mainDocumentURL |
377 linkClicked:(BOOL)linkClicked; | 374 linkClicked:(BOOL)linkClicked; |
378 // Called when |url| needs to be opened in a matching native app. | 375 // Called when |url| needs to be opened in a matching native app. |
(...skipping 793 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1172 return _webViewProxy.get(); | 1169 return _webViewProxy.get(); |
1173 } | 1170 } |
1174 | 1171 |
1175 - (UIView*)viewForPrinting { | 1172 - (UIView*)viewForPrinting { |
1176 // TODO(ios): crbug.com/227944. Printing is not supported for native | 1173 // TODO(ios): crbug.com/227944. Printing is not supported for native |
1177 // controllers. | 1174 // controllers. |
1178 return self.webView; | 1175 return self.webView; |
1179 } | 1176 } |
1180 | 1177 |
1181 - (void)loadRequest:(NSMutableURLRequest*)request { | 1178 - (void)loadRequest:(NSMutableURLRequest*)request { |
1182 DCHECK(web::GetWebClient()); | 1179 // Subclasses must implement this method. |
1183 GURL url = net::GURLWithNSURL(request.URL); | 1180 NOTREACHED(); |
1184 // TODO(stuartmorgan): See if WKWebView has the same issue; if not, this can | |
1185 // move into the subclass. | |
1186 if (web::GetWebClient()->IsAppSpecificURL(url)) { | |
1187 // Sub requests of a chrome:// page will not contain the user agent. | |
1188 // Instead use the username part of the URL to allow the network stack to | |
1189 // associate a request to the correct tab. | |
1190 request.URL = web::AddRequestGroupIDToURL( | |
1191 request.URL, _webStateImpl->GetRequestGroupID()); | |
1192 } | |
1193 [self loadWebRequest:request]; | |
1194 } | 1181 } |
1195 | 1182 |
1196 - (void)registerLoadRequest:(const GURL&)requestURL | 1183 - (void)registerLoadRequest:(const GURL&)requestURL |
1197 referrer:(const web::Referrer&)referrer | 1184 referrer:(const web::Referrer&)referrer |
1198 transition:(ui::PageTransition)transition { | 1185 transition:(ui::PageTransition)transition { |
1199 // Transfer time is registered so that further transitions within the time | 1186 // Transfer time is registered so that further transitions within the time |
1200 // envelope are not also registered as links. | 1187 // envelope are not also registered as links. |
1201 _lastTransferTimeInSeconds = CFAbsoluteTimeGetCurrent(); | 1188 _lastTransferTimeInSeconds = CFAbsoluteTimeGetCurrent(); |
1202 // Before changing phases, the delegate should be informed that any existing | 1189 // Before changing phases, the delegate should be informed that any existing |
1203 // request is being cancelled before completion. | 1190 // request is being cancelled before completion. |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1497 _webStateImpl->SetCacheMode(net::RequestTracker::CACHE_NORMAL); | 1484 _webStateImpl->SetCacheMode(net::RequestTracker::CACHE_NORMAL); |
1498 } | 1485 } |
1499 | 1486 |
1500 - (void)loadCurrentURL { | 1487 - (void)loadCurrentURL { |
1501 // If the content view doesn't exist, the tab has either been evicted, or | 1488 // If the content view doesn't exist, the tab has either been evicted, or |
1502 // never displayed. Bail, and let the URL be loaded when the tab is shown. | 1489 // never displayed. Bail, and let the URL be loaded when the tab is shown. |
1503 if (!_containerView) | 1490 if (!_containerView) |
1504 return; | 1491 return; |
1505 | 1492 |
1506 // Reset current WebUI if one exists. | 1493 // Reset current WebUI if one exists. |
1507 _webStateImpl->ClearWebUI(); | 1494 [self clearWebUI]; |
1508 | 1495 |
1509 // Precaution, so that the outgoing URL is registered, to reduce the risk of | 1496 // Precaution, so that the outgoing URL is registered, to reduce the risk of |
1510 // it being seen as a fresh URL later by the same method (and new page change | 1497 // it being seen as a fresh URL later by the same method (and new page change |
1511 // erroneously reported). | 1498 // erroneously reported). |
1512 [self checkForUnexpectedURLChange]; | 1499 [self checkForUnexpectedURLChange]; |
1513 | 1500 |
1514 // Abort any outstanding page load. This ensures the delegate gets informed | 1501 // Abort any outstanding page load. This ensures the delegate gets informed |
1515 // about the outgoing page, and further messages from the page are suppressed. | 1502 // about the outgoing page, and further messages from the page are suppressed. |
1516 if (_loadPhase != web::PAGE_LOADED) | 1503 if (_loadPhase != web::PAGE_LOADED) |
1517 [self abortLoad]; | 1504 [self abortLoad]; |
1518 | 1505 |
1519 DCHECK(!_isHalted); | 1506 DCHECK(!_isHalted); |
1520 // Remove the interstitial before doing anything else. | 1507 // Remove the interstitial before doing anything else. |
1521 [self clearInterstitials]; | 1508 [self clearInterstitials]; |
1522 | 1509 |
1523 const GURL currentUrl = [self currentNavigationURL]; | 1510 const GURL currentURL = [self currentNavigationURL]; |
1524 // If it's a chrome URL, but not a native one, create the WebUI instance. | 1511 // If it's a chrome URL, but not a native one, create the WebUI instance. |
1525 if (web::GetWebClient()->IsAppSpecificURL(currentUrl) && | 1512 if (web::GetWebClient()->IsAppSpecificURL(currentURL) && |
1526 ![_nativeProvider hasControllerForURL:currentUrl]) { | 1513 ![_nativeProvider hasControllerForURL:currentURL]) { |
1527 _webStateImpl->CreateWebUI(currentUrl); | 1514 [self createWebUIForURL:currentURL]; |
1528 } | 1515 } |
1529 | 1516 |
1530 // Loading a new url, must check here if it's a native chrome URL and | 1517 // Loading a new url, must check here if it's a native chrome URL and |
1531 // replace the appropriate view if so, or transition back to a web view from | 1518 // replace the appropriate view if so, or transition back to a web view from |
1532 // a native view. | 1519 // a native view. |
1533 if ([self shouldLoadURLInNativeView:currentUrl]) { | 1520 if ([self shouldLoadURLInNativeView:currentURL]) { |
1534 [self loadCurrentURLInNativeView]; | 1521 [self loadCurrentURLInNativeView]; |
1535 } else { | 1522 } else { |
1536 [self loadCurrentURLInWebView]; | 1523 [self loadCurrentURLInWebView]; |
1537 } | 1524 } |
1538 | 1525 |
1539 // Once a URL has been loaded, any cached-based reconstruction state has | 1526 // Once a URL has been loaded, any cached-based reconstruction state has |
1540 // either been handled or obsoleted. | 1527 // either been handled or obsoleted. |
1541 _expectedReconstructionURL = GURL(); | 1528 _expectedReconstructionURL = GURL(); |
1542 } | 1529 } |
1543 | 1530 |
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2058 std::string messageContent; | 2045 std::string messageContent; |
2059 base::ListValue* arguments = nullptr; | 2046 base::ListValue* arguments = nullptr; |
2060 if (!message->GetString("message", &messageContent)) { | 2047 if (!message->GetString("message", &messageContent)) { |
2061 DLOG(WARNING) << "JS message parameter not found: message"; | 2048 DLOG(WARNING) << "JS message parameter not found: message"; |
2062 return NO; | 2049 return NO; |
2063 } | 2050 } |
2064 if (!message->GetList("arguments", &arguments)) { | 2051 if (!message->GetList("arguments", &arguments)) { |
2065 DLOG(WARNING) << "JS message parameter not found: arguments"; | 2052 DLOG(WARNING) << "JS message parameter not found: arguments"; |
2066 return NO; | 2053 return NO; |
2067 } | 2054 } |
| 2055 _webStateImpl->OnScriptCommandReceived( |
| 2056 messageContent, *message, currentURL, |
| 2057 context[web::kUserIsInteractingKey]); |
2068 _webStateImpl->ProcessWebUIMessage(currentURL, messageContent, | 2058 _webStateImpl->ProcessWebUIMessage(currentURL, messageContent, |
2069 *arguments); | 2059 *arguments); |
| 2060 return YES; |
2070 } | 2061 } |
2071 } | 2062 } |
2072 return YES; | 2063 |
| 2064 DLOG(WARNING) |
| 2065 << "chrome.send message not handled because WebUI was not found."; |
| 2066 return NO; |
2073 } | 2067 } |
2074 | 2068 |
2075 - (BOOL)handleConsoleMessage:(base::DictionaryValue*)message | 2069 - (BOOL)handleConsoleMessage:(base::DictionaryValue*)message |
2076 context:(NSDictionary*)context { | 2070 context:(NSDictionary*)context { |
2077 // Do not log if JS logging is off. | 2071 // Do not log if JS logging is off. |
2078 if (![[NSUserDefaults standardUserDefaults] boolForKey:web::kLogJavaScript]) { | 2072 if (![[NSUserDefaults standardUserDefaults] boolForKey:web::kLogJavaScript]) { |
2079 return YES; | 2073 return YES; |
2080 } | 2074 } |
2081 | 2075 |
2082 std::string method; | 2076 std::string method; |
(...skipping 808 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2891 } | 2885 } |
2892 } | 2886 } |
2893 return; | 2887 return; |
2894 } | 2888 } |
2895 | 2889 |
2896 [self loadCompleteWithSuccess:NO]; | 2890 [self loadCompleteWithSuccess:NO]; |
2897 [self loadErrorInNativeView:error]; | 2891 [self loadErrorInNativeView:error]; |
2898 } | 2892 } |
2899 | 2893 |
2900 #pragma mark - | 2894 #pragma mark - |
| 2895 #pragma mark WebUI |
| 2896 |
| 2897 - (void)createWebUIForURL:(const GURL&)URL { |
| 2898 _webStateImpl->CreateWebUI(URL); |
| 2899 } |
| 2900 |
| 2901 - (void)clearWebUI { |
| 2902 _webStateImpl->ClearWebUI(); |
| 2903 } |
| 2904 |
| 2905 #pragma mark - |
2901 #pragma mark UIGestureRecognizerDelegate | 2906 #pragma mark UIGestureRecognizerDelegate |
2902 | 2907 |
2903 - (BOOL)gestureRecognizer:(UIGestureRecognizer*)gestureRecognizer | 2908 - (BOOL)gestureRecognizer:(UIGestureRecognizer*)gestureRecognizer |
2904 shouldRecognizeSimultaneouslyWithGestureRecognizer: | 2909 shouldRecognizeSimultaneouslyWithGestureRecognizer: |
2905 (UIGestureRecognizer*)otherGestureRecognizer { | 2910 (UIGestureRecognizer*)otherGestureRecognizer { |
2906 // Allows the custom UILongPressGestureRecognizer to fire simultaneously with | 2911 // Allows the custom UILongPressGestureRecognizer to fire simultaneously with |
2907 // other recognizers. | 2912 // other recognizers. |
2908 return YES; | 2913 return YES; |
2909 } | 2914 } |
2910 | 2915 |
(...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3565 - (void)loadHTML:(NSString*)html forURL:(const GURL&)url { | 3570 - (void)loadHTML:(NSString*)html forURL:(const GURL&)url { |
3566 // Remove the interstitial before doing anything else. | 3571 // Remove the interstitial before doing anything else. |
3567 [self clearInterstitials]; | 3572 [self clearInterstitials]; |
3568 | 3573 |
3569 DLOG_IF(WARNING, !self.webView) | 3574 DLOG_IF(WARNING, !self.webView) |
3570 << "self.webView null while trying to load HTML"; | 3575 << "self.webView null while trying to load HTML"; |
3571 _loadPhase = web::LOAD_REQUESTED; | 3576 _loadPhase = web::LOAD_REQUESTED; |
3572 [self loadWebHTMLString:html forURL:url]; | 3577 [self loadWebHTMLString:html forURL:url]; |
3573 } | 3578 } |
3574 | 3579 |
| 3580 - (void)loadHTML:(NSString*)HTML forAppSpecificURL:(const GURL&)URL { |
| 3581 CHECK(web::GetWebClient()->IsAppSpecificURL(URL)); |
| 3582 [self loadHTML:HTML forURL:URL]; |
| 3583 } |
| 3584 |
3575 - (void)stopLoading { | 3585 - (void)stopLoading { |
3576 web::RecordAction(UserMetricsAction("Stop")); | 3586 web::RecordAction(UserMetricsAction("Stop")); |
3577 // Discard the pending and transient entried before notifying the tab model | 3587 // Discard the pending and transient entried before notifying the tab model |
3578 // observers of the change via |-abortLoad|. | 3588 // observers of the change via |-abortLoad|. |
3579 [[self sessionController] discardNonCommittedEntries]; | 3589 [[self sessionController] discardNonCommittedEntries]; |
3580 [self abortLoad]; | 3590 [self abortLoad]; |
3581 // If discarding the non-committed entries results in an app-specific URL, | 3591 // If discarding the non-committed entries results in an app-specific URL, |
3582 // reload it in its native view. | 3592 // reload it in its native view. |
3583 if (!_nativeController && | 3593 if (!_nativeController && |
3584 [self shouldLoadURLInNativeView:[self currentNavigationURL]]) { | 3594 [self shouldLoadURLInNativeView:[self currentNavigationURL]]) { |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3683 if (!_externalRequest || !_externalRequest->window_name) | 3693 if (!_externalRequest || !_externalRequest->window_name) |
3684 return @""; | 3694 return @""; |
3685 return _externalRequest->window_name; | 3695 return _externalRequest->window_name; |
3686 } | 3696 } |
3687 | 3697 |
3688 - (void)resetExternalRequest { | 3698 - (void)resetExternalRequest { |
3689 _externalRequest.reset(); | 3699 _externalRequest.reset(); |
3690 } | 3700 } |
3691 | 3701 |
3692 @end | 3702 @end |
OLD | NEW |