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 <WebKit/WebKit.h> | 7 #import <WebKit/WebKit.h> |
8 | 8 |
9 #import <objc/runtime.h> | 9 #import <objc/runtime.h> |
10 #include <stddef.h> | 10 #include <stddef.h> |
(...skipping 721 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
732 // TODO(stuartmorgan): Move the pushState/replaceState logic into | 732 // TODO(stuartmorgan): Move the pushState/replaceState logic into |
733 // NavigationManager. | 733 // NavigationManager. |
734 - (void)pushStateWithPageURL:(const GURL&)pageURL | 734 - (void)pushStateWithPageURL:(const GURL&)pageURL |
735 stateObject:(NSString*)stateObject | 735 stateObject:(NSString*)stateObject |
736 transition:(ui::PageTransition)transition; | 736 transition:(ui::PageTransition)transition; |
737 // Assigns the given URL and state object to the current CRWSessionEntry. | 737 // Assigns the given URL and state object to the current CRWSessionEntry. |
738 - (void)replaceStateWithPageURL:(const GURL&)pageUrl | 738 - (void)replaceStateWithPageURL:(const GURL&)pageUrl |
739 stateObject:(NSString*)stateObject; | 739 stateObject:(NSString*)stateObject; |
740 // Sets _documentURL to newURL, and updates any relevant state information. | 740 // Sets _documentURL to newURL, and updates any relevant state information. |
741 - (void)setDocumentURL:(const GURL&)newURL; | 741 - (void)setDocumentURL:(const GURL&)newURL; |
742 // Sets WKWebView's title to the last committed navigation item. | 742 // Sets last committed NavigationItem's title to the given |title|, which can |
743 - (void)updateNavigationItemTitle; | 743 // not be nil. |
| 744 - (void)setNavigationItemTitle:(NSString*)title; |
744 // Returns YES if the current navigation item corresponds to a web page | 745 // Returns YES if the current navigation item corresponds to a web page |
745 // loaded by a POST request. | 746 // loaded by a POST request. |
746 - (BOOL)isCurrentNavigationItemPOST; | 747 - (BOOL)isCurrentNavigationItemPOST; |
747 // Returns YES if current navigation item is WKNavigationTypeBackForward. | 748 // Returns YES if current navigation item is WKNavigationTypeBackForward. |
748 - (BOOL)isCurrentNavigationBackForward; | 749 - (BOOL)isCurrentNavigationBackForward; |
749 // Returns whether the given navigation is triggered by a user link click. | 750 // Returns whether the given navigation is triggered by a user link click. |
750 - (BOOL)isLinkNavigation:(WKNavigationType)navigationType; | 751 - (BOOL)isLinkNavigation:(WKNavigationType)navigationType; |
751 | 752 |
752 // Inject windowID if not yet injected. | 753 // Inject windowID if not yet injected. |
753 - (void)injectWindowID; | 754 - (void)injectWindowID; |
(...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1416 [self didUpdateHistoryStateWithPageURL:pageUrl]; | 1417 [self didUpdateHistoryStateWithPageURL:pageUrl]; |
1417 } | 1418 } |
1418 | 1419 |
1419 - (void)setDocumentURL:(const GURL&)newURL { | 1420 - (void)setDocumentURL:(const GURL&)newURL { |
1420 if (newURL != _documentURL && newURL.is_valid()) { | 1421 if (newURL != _documentURL && newURL.is_valid()) { |
1421 _documentURL = newURL; | 1422 _documentURL = newURL; |
1422 _interactionRegisteredSinceLastURLChange = NO; | 1423 _interactionRegisteredSinceLastURLChange = NO; |
1423 } | 1424 } |
1424 } | 1425 } |
1425 | 1426 |
1426 - (void)updateNavigationItemTitle { | 1427 - (void)setNavigationItemTitle:(NSString*)title { |
1427 NSString* webViewTitle = [_webView title]; | 1428 DCHECK(title); |
1428 DCHECK(webViewTitle); | |
1429 auto& navigationManager = _webStateImpl->GetNavigationManagerImpl(); | 1429 auto& navigationManager = _webStateImpl->GetNavigationManagerImpl(); |
1430 web::NavigationItem* item = navigationManager.GetLastCommittedItem(); | 1430 web::NavigationItem* item = navigationManager.GetLastCommittedItem(); |
1431 if (!item) | 1431 if (!item) |
1432 return; | 1432 return; |
1433 | 1433 |
1434 base::string16 newTitle = base::SysNSStringToUTF16(webViewTitle); | 1434 base::string16 newTitle = base::SysNSStringToUTF16(title); |
1435 if (item->GetTitle() == newTitle) | 1435 if (item->GetTitle() == newTitle) |
1436 return; | 1436 return; |
1437 | 1437 |
1438 item->SetTitle(newTitle); | 1438 item->SetTitle(newTitle); |
1439 // TODO(crbug.com/546218): See if this can be removed; it's not clear that | 1439 // TODO(crbug.com/546218): See if this can be removed; it's not clear that |
1440 // other platforms send this (tab sync triggers need to be compared against | 1440 // other platforms send this (tab sync triggers need to be compared against |
1441 // upstream). | 1441 // upstream). |
1442 navigationManager.OnNavigationItemChanged(); | 1442 navigationManager.OnNavigationItemChanged(); |
1443 | 1443 |
1444 if ([_delegate respondsToSelector:@selector(webController:titleDidChange:)]) { | 1444 if ([_delegate respondsToSelector:@selector(webController:titleDidChange:)]) { |
1445 [_delegate webController:self titleDidChange:webViewTitle]; | 1445 [_delegate webController:self titleDidChange:title]; |
1446 } | 1446 } |
1447 } | 1447 } |
1448 | 1448 |
1449 - (BOOL)isCurrentNavigationItemPOST { | 1449 - (BOOL)isCurrentNavigationItemPOST { |
1450 // |_pendingNavigationInfo| will be nil if the decidePolicy* delegate methods | 1450 // |_pendingNavigationInfo| will be nil if the decidePolicy* delegate methods |
1451 // were not called. | 1451 // were not called. |
1452 NSString* HTTPMethod = | 1452 NSString* HTTPMethod = |
1453 _pendingNavigationInfo | 1453 _pendingNavigationInfo |
1454 ? [_pendingNavigationInfo HTTPMethod] | 1454 ? [_pendingNavigationInfo HTTPMethod] |
1455 : [self currentBackForwardListItemHolder]->http_method(); | 1455 : [self currentBackForwardListItemHolder]->http_method(); |
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1863 } | 1863 } |
1864 | 1864 |
1865 - (void)loadNativeViewWithSuccess:(BOOL)loadSuccess { | 1865 - (void)loadNativeViewWithSuccess:(BOOL)loadSuccess { |
1866 const GURL currentURL([self currentURL]); | 1866 const GURL currentURL([self currentURL]); |
1867 [self didStartLoadingURL:currentURL updateHistory:loadSuccess]; | 1867 [self didStartLoadingURL:currentURL updateHistory:loadSuccess]; |
1868 _loadPhase = web::PAGE_LOADED; | 1868 _loadPhase = web::PAGE_LOADED; |
1869 | 1869 |
1870 // Perform post-load-finished updates. | 1870 // Perform post-load-finished updates. |
1871 [self didFinishWithURL:currentURL loadSuccess:loadSuccess]; | 1871 [self didFinishWithURL:currentURL loadSuccess:loadSuccess]; |
1872 | 1872 |
1873 // Inform the embedder the title changed. | 1873 NSString* title = [self.nativeController title]; |
| 1874 if (title) |
| 1875 [self setNavigationItemTitle:title]; |
| 1876 |
| 1877 // If the controller handles title change notification, route those to the |
| 1878 // delegate. |
1874 if ([_delegate respondsToSelector:@selector(webController:titleDidChange:)]) { | 1879 if ([_delegate respondsToSelector:@selector(webController:titleDidChange:)]) { |
1875 NSString* title = [self.nativeController title]; | |
1876 // If a title is present, notify the delegate. | |
1877 if (title) | |
1878 [_delegate webController:self titleDidChange:title]; | |
1879 // If the controller handles title change notification, route those to the | |
1880 // delegate. | |
1881 if ([self.nativeController respondsToSelector:@selector(setDelegate:)]) { | 1880 if ([self.nativeController respondsToSelector:@selector(setDelegate:)]) { |
1882 [self.nativeController setDelegate:self]; | 1881 [self.nativeController setDelegate:self]; |
1883 } | 1882 } |
1884 } | 1883 } |
1885 } | 1884 } |
1886 | 1885 |
1887 - (void)loadErrorInNativeView:(NSError*)error { | 1886 - (void)loadErrorInNativeView:(NSError*)error { |
1888 [self removeWebViewAllowingCachedReconstruction:NO]; | 1887 [self removeWebViewAllowingCachedReconstruction:NO]; |
1889 web::NavigationItem* item = [self currentNavItem]; | 1888 web::NavigationItem* item = [self currentNavItem]; |
1890 const GURL currentURL = item ? item->GetVirtualURL() : GURL::EmptyGURL(); | 1889 const GURL currentURL = item ? item->GetVirtualURL() : GURL::EmptyGURL(); |
(...skipping 3084 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4975 didCommitNavigation:(WKNavigation*)navigation { | 4974 didCommitNavigation:(WKNavigation*)navigation { |
4976 [_navigationStates setState:web::WKNavigationState::COMMITTED | 4975 [_navigationStates setState:web::WKNavigationState::COMMITTED |
4977 forNavigation:navigation]; | 4976 forNavigation:navigation]; |
4978 | 4977 |
4979 DCHECK_EQ(_webView, webView); | 4978 DCHECK_EQ(_webView, webView); |
4980 _certVerificationErrors->Clear(); | 4979 _certVerificationErrors->Clear(); |
4981 | 4980 |
4982 // This is the point where the document's URL and title have actually changed, | 4981 // This is the point where the document's URL and title have actually changed, |
4983 // and pending navigation information should be applied to state information. | 4982 // and pending navigation information should be applied to state information. |
4984 [self setDocumentURL:net::GURLWithNSURL([_webView URL])]; | 4983 [self setDocumentURL:net::GURLWithNSURL([_webView URL])]; |
4985 [self updateNavigationItemTitle]; | |
4986 | 4984 |
4987 if (!_lastRegisteredRequestURL.is_valid() && | 4985 if (!_lastRegisteredRequestURL.is_valid() && |
4988 _documentURL != _lastRegisteredRequestURL) { | 4986 _documentURL != _lastRegisteredRequestURL) { |
4989 // if |_lastRegisteredRequestURL| is an invalid URL, then |_documentURL| | 4987 // if |_lastRegisteredRequestURL| is an invalid URL, then |_documentURL| |
4990 // will be "about:blank". | 4988 // will be "about:blank". |
4991 [[self sessionController] updatePendingEntry:_documentURL]; | 4989 [[self sessionController] updatePendingEntry:_documentURL]; |
4992 } | 4990 } |
4993 DCHECK(_documentURL == _lastRegisteredRequestURL || | 4991 DCHECK(_documentURL == _lastRegisteredRequestURL || |
4994 (!_lastRegisteredRequestURL.is_valid() && | 4992 (!_lastRegisteredRequestURL.is_valid() && |
4995 _documentURL.spec() == url::kAboutBlankURL)); | 4993 _documentURL.spec() == url::kAboutBlankURL)); |
(...skipping 22 matching lines...) Expand all Loading... |
5018 [self injectWindowID]; | 5016 [self injectWindowID]; |
5019 } | 5017 } |
5020 | 5018 |
5021 [self webPageChanged]; | 5019 [self webPageChanged]; |
5022 | 5020 |
5023 [self updateSSLStatusForCurrentNavigationItem]; | 5021 [self updateSSLStatusForCurrentNavigationItem]; |
5024 | 5022 |
5025 // Attempt to update the HTML5 history state. | 5023 // Attempt to update the HTML5 history state. |
5026 [self updateHTML5HistoryState]; | 5024 [self updateHTML5HistoryState]; |
5027 | 5025 |
| 5026 // This is the point where pending entry has been committed, and navigation |
| 5027 // item title should be updated. |
| 5028 [self setNavigationItemTitle:[_webView title]]; |
| 5029 |
5028 // Report cases where SSL cert is missing for a secure connection. | 5030 // Report cases where SSL cert is missing for a secure connection. |
5029 if (_documentURL.SchemeIsCryptographic()) { | 5031 if (_documentURL.SchemeIsCryptographic()) { |
5030 scoped_refptr<net::X509Certificate> cert = | 5032 scoped_refptr<net::X509Certificate> cert = |
5031 web::CreateCertFromChain([_webView certificateChain]); | 5033 web::CreateCertFromChain([_webView certificateChain]); |
5032 UMA_HISTOGRAM_BOOLEAN("WebController.WKWebViewHasCertForSecureConnection", | 5034 UMA_HISTOGRAM_BOOLEAN("WebController.WKWebViewHasCertForSecureConnection", |
5033 static_cast<bool>(cert)); | 5035 static_cast<bool>(cert)); |
5034 } | 5036 } |
5035 } | 5037 } |
5036 | 5038 |
5037 - (void)webView:(WKWebView*)webView | 5039 - (void)webView:(WKWebView*)webView |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5218 if (_webProcessIsDead) { | 5220 if (_webProcessIsDead) { |
5219 DCHECK_EQ([_webView title].length, 0U); | 5221 DCHECK_EQ([_webView title].length, 0U); |
5220 return; | 5222 return; |
5221 } | 5223 } |
5222 | 5224 |
5223 bool hasPendingNavigation = web::WKNavigationState::COMMITTED <= | 5225 bool hasPendingNavigation = web::WKNavigationState::COMMITTED <= |
5224 [_navigationStates lastAddedNavigationState]; | 5226 [_navigationStates lastAddedNavigationState]; |
5225 if (hasPendingNavigation) { | 5227 if (hasPendingNavigation) { |
5226 // Do not update the title if there is a navigation in progress because | 5228 // Do not update the title if there is a navigation in progress because |
5227 // there is no way to tell if KVO change fired for new or previous page. | 5229 // there is no way to tell if KVO change fired for new or previous page. |
5228 [self updateNavigationItemTitle]; | 5230 [self setNavigationItemTitle:[_webView title]]; |
5229 } | 5231 } |
5230 } | 5232 } |
5231 | 5233 |
5232 - (void)webViewURLDidChange { | 5234 - (void)webViewURLDidChange { |
5233 // TODO(stuartmorgan): Determine if there are any cases where this still | 5235 // TODO(stuartmorgan): Determine if there are any cases where this still |
5234 // happens, and if so whether anything should be done when it does. | 5236 // happens, and if so whether anything should be done when it does. |
5235 if (![_webView URL]) { | 5237 if (![_webView URL]) { |
5236 DVLOG(1) << "Received nil URL callback"; | 5238 DVLOG(1) << "Received nil URL callback"; |
5237 return; | 5239 return; |
5238 } | 5240 } |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5555 } | 5557 } |
5556 | 5558 |
5557 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC; | 5559 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC; |
5558 } | 5560 } |
5559 | 5561 |
5560 - (NSString*)refererFromNavigationAction:(WKNavigationAction*)action { | 5562 - (NSString*)refererFromNavigationAction:(WKNavigationAction*)action { |
5561 return [action.request valueForHTTPHeaderField:@"Referer"]; | 5563 return [action.request valueForHTTPHeaderField:@"Referer"]; |
5562 } | 5564 } |
5563 | 5565 |
5564 @end | 5566 @end |
OLD | NEW |