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

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

Issue 2834413002: Return NavigationContext from registerLoadRequest. (Closed)
Patch Set: Rebased Created 3 years, 7 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 #import "ios/web/public/web_state/ui/crw_web_view_scroll_view_proxy.h" 74 #import "ios/web/public/web_state/ui/crw_web_view_scroll_view_proxy.h"
75 #include "ios/web/public/web_state/url_verification_constants.h" 75 #include "ios/web/public/web_state/url_verification_constants.h"
76 #import "ios/web/public/web_state/web_state.h" 76 #import "ios/web/public/web_state/web_state.h"
77 #include "ios/web/public/web_state/web_state_interface_provider.h" 77 #include "ios/web/public/web_state/web_state_interface_provider.h"
78 #include "ios/web/public/webui/web_ui_ios.h" 78 #include "ios/web/public/webui/web_ui_ios.h"
79 #import "ios/web/web_state/crw_pass_kit_downloader.h" 79 #import "ios/web/web_state/crw_pass_kit_downloader.h"
80 #import "ios/web/web_state/error_translation_util.h" 80 #import "ios/web/web_state/error_translation_util.h"
81 #import "ios/web/web_state/js/crw_js_plugin_placeholder_manager.h" 81 #import "ios/web/web_state/js/crw_js_plugin_placeholder_manager.h"
82 #import "ios/web/web_state/js/crw_js_post_request_loader.h" 82 #import "ios/web/web_state/js/crw_js_post_request_loader.h"
83 #import "ios/web/web_state/js/crw_js_window_id_manager.h" 83 #import "ios/web/web_state/js/crw_js_window_id_manager.h"
84 #include "ios/web/web_state/navigation_context_impl.h"
84 #import "ios/web/web_state/page_viewport_state.h" 85 #import "ios/web/web_state/page_viewport_state.h"
85 #import "ios/web/web_state/ui/crw_context_menu_controller.h" 86 #import "ios/web/web_state/ui/crw_context_menu_controller.h"
86 #import "ios/web/web_state/ui/crw_swipe_recognizer_provider.h" 87 #import "ios/web/web_state/ui/crw_swipe_recognizer_provider.h"
87 #import "ios/web/web_state/ui/crw_web_controller.h" 88 #import "ios/web/web_state/ui/crw_web_controller.h"
88 #import "ios/web/web_state/ui/crw_web_controller_container_view.h" 89 #import "ios/web/web_state/ui/crw_web_controller_container_view.h"
89 #import "ios/web/web_state/ui/crw_web_view_proxy_impl.h" 90 #import "ios/web/web_state/ui/crw_web_view_proxy_impl.h"
90 #import "ios/web/web_state/ui/crw_wk_navigation_states.h" 91 #import "ios/web/web_state/ui/crw_wk_navigation_states.h"
91 #import "ios/web/web_state/ui/crw_wk_script_message_router.h" 92 #import "ios/web/web_state/ui/crw_wk_script_message_router.h"
92 #import "ios/web/web_state/ui/wk_back_forward_list_item_holder.h" 93 #import "ios/web/web_state/ui/wk_back_forward_list_item_holder.h"
93 #import "ios/web/web_state/ui/wk_web_view_configuration_provider.h" 94 #import "ios/web/web_state/ui/wk_web_view_configuration_provider.h"
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after
637 userIsInteracting:(BOOL)userIsInteracting 638 userIsInteracting:(BOOL)userIsInteracting
638 originURL:(const GURL&)originURL; 639 originURL:(const GURL&)originURL;
639 // Called when web controller receives a new message from the web page. 640 // Called when web controller receives a new message from the web page.
640 - (void)didReceiveScriptMessage:(WKScriptMessage*)message; 641 - (void)didReceiveScriptMessage:(WKScriptMessage*)message;
641 // Returns a new script which wraps |script| with windowID check so |script| is 642 // Returns a new script which wraps |script| with windowID check so |script| is
642 // not evaluated on windowID mismatch. 643 // not evaluated on windowID mismatch.
643 - (NSString*)scriptByAddingWindowIDCheckForScript:(NSString*)script; 644 - (NSString*)scriptByAddingWindowIDCheckForScript:(NSString*)script;
644 // Attempts to handle a script message. Returns YES on success, NO otherwise. 645 // Attempts to handle a script message. Returns YES on success, NO otherwise.
645 - (BOOL)respondToWKScriptMessage:(WKScriptMessage*)scriptMessage; 646 - (BOOL)respondToWKScriptMessage:(WKScriptMessage*)scriptMessage;
646 // Registers load request with empty referrer and link or client redirect 647 // Registers load request with empty referrer and link or client redirect
647 // transition based on user interaction state. 648 // transition based on user interaction state. Returns navigation context for
648 - (void)registerLoadRequest:(const GURL&)URL; 649 // this request.
650 - (std::unique_ptr<web::NavigationContextImpl>)registerLoadRequestForURL:
651 (const GURL&)URL;
649 // Prepares web controller and delegates for anticipated page change. 652 // Prepares web controller and delegates for anticipated page change.
650 // Allows several methods to invoke webWill/DidAddPendingURL on anticipated page 653 // Allows several methods to invoke webWill/DidAddPendingURL on anticipated page
651 // change, using the same cached request and calculated transition types. 654 // change, using the same cached request and calculated transition types.
652 - (void)registerLoadRequest:(const GURL&)URL 655 // Returns navigation context for this request.
653 referrer:(const web::Referrer&)referrer 656 - (std::unique_ptr<web::NavigationContextImpl>)
654 transition:(ui::PageTransition)transition; 657 registerLoadRequestForURL:(const GURL&)URL
658 referrer:(const web::Referrer&)referrer
659 transition:(ui::PageTransition)transition;
655 // Updates the HTML5 history state of the page using the current NavigationItem. 660 // Updates the HTML5 history state of the page using the current NavigationItem.
656 // For same-document navigations and navigations affected by 661 // For same-document navigations and navigations affected by
657 // window.history.[push/replace]State(), the URL and serialized state object 662 // window.history.[push/replace]State(), the URL and serialized state object
658 // will be updated to the current NavigationItem's values. A popState event 663 // will be updated to the current NavigationItem's values. A popState event
659 // will be triggered for all same-document navigations. Additionaly, a 664 // will be triggered for all same-document navigations. Additionaly, a
660 // hashchange event will be triggered for same-document navigations where the 665 // hashchange event will be triggered for same-document navigations where the
661 // only difference between the current and previous URL is the fragment. 666 // only difference between the current and previous URL is the fragment.
662 - (void)updateHTML5HistoryState; 667 - (void)updateHTML5HistoryState;
663 // Generates the JavaScript string used to update the UIWebView's URL so that it 668 // Generates the JavaScript string used to update the UIWebView's URL so that it
664 // matches the URL displayed in the omnibox and sets window.history.state to 669 // matches the URL displayed in the omnibox and sets window.history.state to
(...skipping 761 matching lines...) Expand 10 before | Expand all | Expand 10 after
1426 1431
1427 - (UIView*)viewForPrinting { 1432 - (UIView*)viewForPrinting {
1428 // Printing is not supported for native controllers. 1433 // Printing is not supported for native controllers.
1429 return _webView; 1434 return _webView;
1430 } 1435 }
1431 1436
1432 - (double)loadingProgress { 1437 - (double)loadingProgress {
1433 return [_webView estimatedProgress]; 1438 return [_webView estimatedProgress];
1434 } 1439 }
1435 1440
1436 - (void)registerLoadRequest:(const GURL&)URL { 1441 - (std::unique_ptr<web::NavigationContextImpl>)registerLoadRequestForURL:
1442 (const GURL&)URL {
1437 // Get the navigation type from the last main frame load request, and try to 1443 // Get the navigation type from the last main frame load request, and try to
1438 // map that to a PageTransition. 1444 // map that to a PageTransition.
1439 WKNavigationType navigationType = 1445 WKNavigationType navigationType =
1440 _pendingNavigationInfo ? [_pendingNavigationInfo navigationType] 1446 _pendingNavigationInfo ? [_pendingNavigationInfo navigationType]
1441 : WKNavigationTypeOther; 1447 : WKNavigationTypeOther;
1442 ui::PageTransition transition = ui::PAGE_TRANSITION_CLIENT_REDIRECT; 1448 ui::PageTransition transition = ui::PAGE_TRANSITION_CLIENT_REDIRECT;
1443 switch (navigationType) { 1449 switch (navigationType) {
1444 case WKNavigationTypeLinkActivated: 1450 case WKNavigationTypeLinkActivated:
1445 transition = ui::PAGE_TRANSITION_LINK; 1451 transition = ui::PAGE_TRANSITION_LINK;
1446 break; 1452 break;
(...skipping 12 matching lines...) Expand all
1459 // or may not be the result of user actions. For now, guess based on 1465 // or may not be the result of user actions. For now, guess based on
1460 // whether there's been an interaction since the last URL change. 1466 // whether there's been an interaction since the last URL change.
1461 // TODO(crbug.com/549301): See if this heuristic can be improved. 1467 // TODO(crbug.com/549301): See if this heuristic can be improved.
1462 transition = _interactionRegisteredSinceLastURLChange 1468 transition = _interactionRegisteredSinceLastURLChange
1463 ? ui::PAGE_TRANSITION_LINK 1469 ? ui::PAGE_TRANSITION_LINK
1464 : ui::PAGE_TRANSITION_CLIENT_REDIRECT; 1470 : ui::PAGE_TRANSITION_CLIENT_REDIRECT;
1465 break; 1471 break;
1466 } 1472 }
1467 // The referrer is not known yet, and will be updated later. 1473 // The referrer is not known yet, and will be updated later.
1468 const web::Referrer emptyReferrer; 1474 const web::Referrer emptyReferrer;
1469 [self registerLoadRequest:URL referrer:emptyReferrer transition:transition]; 1475 return [self registerLoadRequestForURL:URL
1476 referrer:emptyReferrer
1477 transition:transition];
1470 } 1478 }
1471 1479
1472 - (void)registerLoadRequest:(const GURL&)requestURL 1480 - (std::unique_ptr<web::NavigationContextImpl>)
1473 referrer:(const web::Referrer&)referrer 1481 registerLoadRequestForURL:(const GURL&)requestURL
1474 transition:(ui::PageTransition)transition { 1482 referrer:(const web::Referrer&)referrer
1483 transition:(ui::PageTransition)transition {
1475 // Transfer time is registered so that further transitions within the time 1484 // Transfer time is registered so that further transitions within the time
1476 // envelope are not also registered as links. 1485 // envelope are not also registered as links.
1477 _lastTransferTimeInSeconds = CFAbsoluteTimeGetCurrent(); 1486 _lastTransferTimeInSeconds = CFAbsoluteTimeGetCurrent();
1478 bool redirect = transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK; 1487 bool redirect = transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK;
1479 if (!redirect) { 1488 if (!redirect) {
1480 // Before changing phases, the delegate should be informed that any existing 1489 // Before changing phases, the delegate should be informed that any existing
1481 // request is being cancelled before completion. 1490 // request is being cancelled before completion.
1482 [self loadCancelled]; 1491 [self loadCancelled];
1483 DCHECK(_loadPhase == web::PAGE_LOADED); 1492 DCHECK(_loadPhase == web::PAGE_LOADED);
1484 } 1493 }
(...skipping 12 matching lines...) Expand all
1497 // Update the existing pending entry. 1506 // Update the existing pending entry.
1498 // Typically on PAGE_TRANSITION_CLIENT_REDIRECT. 1507 // Typically on PAGE_TRANSITION_CLIENT_REDIRECT.
1499 [[self sessionController] updatePendingItem:requestURL]; 1508 [[self sessionController] updatePendingItem:requestURL];
1500 } else { 1509 } else {
1501 // A new session history entry needs to be created. 1510 // A new session history entry needs to be created.
1502 self.navigationManagerImpl->AddPendingItem( 1511 self.navigationManagerImpl->AddPendingItem(
1503 requestURL, referrer, transition, 1512 requestURL, referrer, transition,
1504 web::NavigationInitiationType::RENDERER_INITIATED, 1513 web::NavigationInitiationType::RENDERER_INITIATED,
1505 web::NavigationManager::UserAgentOverrideOption::INHERIT); 1514 web::NavigationManager::UserAgentOverrideOption::INHERIT);
1506 } 1515 }
1516 std::unique_ptr<web::NavigationContextImpl> context =
1517 web::NavigationContextImpl::CreateNavigationContext(
1518 _webStateImpl, requestURL, nullptr /* response_headers */);
1507 _webStateImpl->SetIsLoading(true); 1519 _webStateImpl->SetIsLoading(true);
1520 // TODO(crbug.com/713836): pass context to |OnProvisionalNavigationStarted|.
1508 _webStateImpl->OnProvisionalNavigationStarted(requestURL); 1521 _webStateImpl->OnProvisionalNavigationStarted(requestURL);
1522 return context;
1509 } 1523 }
1510 1524
1511 - (void)updateHTML5HistoryState { 1525 - (void)updateHTML5HistoryState {
1512 web::NavigationItemImpl* currentItem = self.currentNavItem; 1526 web::NavigationItemImpl* currentItem = self.currentNavItem;
1513 if (!currentItem) 1527 if (!currentItem)
1514 return; 1528 return;
1515 1529
1516 // Same-document navigations must trigger a popState event. 1530 // Same-document navigations must trigger a popState event.
1517 CRWSessionController* sessionController = self.sessionController; 1531 CRWSessionController* sessionController = self.sessionController;
1518 BOOL sameDocumentNavigation = [sessionController 1532 BOOL sameDocumentNavigation = [sessionController
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
1793 const web::Referrer referrer; 1807 const web::Referrer referrer;
1794 id<CRWNativeContent> nativeContent = 1808 id<CRWNativeContent> nativeContent =
1795 [_nativeProvider controllerForURL:targetURL webState:self.webState]; 1809 [_nativeProvider controllerForURL:targetURL webState:self.webState];
1796 // Unlike the WebView case, always create a new controller and view. 1810 // Unlike the WebView case, always create a new controller and view.
1797 // TODO(pinkerton): What to do if this does return nil? 1811 // TODO(pinkerton): What to do if this does return nil?
1798 [self setNativeController:nativeContent]; 1812 [self setNativeController:nativeContent];
1799 if ([nativeContent respondsToSelector:@selector(virtualURL)]) { 1813 if ([nativeContent respondsToSelector:@selector(virtualURL)]) {
1800 item->SetVirtualURL([nativeContent virtualURL]); 1814 item->SetVirtualURL([nativeContent virtualURL]);
1801 } 1815 }
1802 1816
1803 [self registerLoadRequest:targetURL 1817 std::unique_ptr<web::NavigationContextImpl> navigationContext =
1804 referrer:referrer 1818 [self registerLoadRequestForURL:targetURL
1805 transition:self.currentTransition]; 1819 referrer:referrer
1820 transition:self.currentTransition];
1806 [self loadNativeViewWithSuccess:YES]; 1821 [self loadNativeViewWithSuccess:YES];
1807 } 1822 }
1808 1823
1809 - (void)loadWithParams:(const NavigationManager::WebLoadParams&)params { 1824 - (void)loadWithParams:(const NavigationManager::WebLoadParams&)params {
1810 DCHECK(!(params.transition_type & ui::PAGE_TRANSITION_FORWARD_BACK)); 1825 DCHECK(!(params.transition_type & ui::PAGE_TRANSITION_FORWARD_BACK));
1811 1826
1812 // Clear transient view before making any changes to history and navigation 1827 // Clear transient view before making any changes to history and navigation
1813 // manager. TODO(stuartmorgan): Drive Transient Item clearing from 1828 // manager. TODO(stuartmorgan): Drive Transient Item clearing from
1814 // navigation system, rather than from WebController. 1829 // navigation system, rather than from WebController.
1815 [self clearTransientContentView]; 1830 [self clearTransientContentView];
(...skipping 2542 matching lines...) Expand 10 before | Expand all | Expand 10 after
4358 // pages. WebUI pages may have increased power and using the same web 4373 // pages. WebUI pages may have increased power and using the same web
4359 // process (which may potentially be controller by an attacker) is 4374 // process (which may potentially be controller by an attacker) is
4360 // dangerous. 4375 // dangerous.
4361 if (web::GetWebClient()->IsAppSpecificURL(_documentURL)) { 4376 if (web::GetWebClient()->IsAppSpecificURL(_documentURL)) {
4362 [self abortLoad]; 4377 [self abortLoad];
4363 NavigationManager::WebLoadParams params(webViewURL); 4378 NavigationManager::WebLoadParams params(webViewURL);
4364 [self loadWithParams:params]; 4379 [self loadWithParams:params];
4365 } 4380 }
4366 return; 4381 return;
4367 } else { 4382 } else {
4368 [self registerLoadRequest:webViewURL]; 4383 std::unique_ptr<web::NavigationContextImpl> navigationContext =
4384 [self registerLoadRequestForURL:webViewURL];
4369 } 4385 }
4370 } 4386 }
4371 4387
4372 // Ensure the URL is registered and loadPhase is as expected. 4388 // Ensure the URL is registered and loadPhase is as expected.
4373 DCHECK(_lastRegisteredRequestURL == webViewURL); 4389 DCHECK(_lastRegisteredRequestURL == webViewURL);
4374 DCHECK(self.loadPhase == web::LOAD_REQUESTED); 4390 DCHECK(self.loadPhase == web::LOAD_REQUESTED);
4375 } 4391 }
4376 4392
4377 - (void)webView:(WKWebView*)webView 4393 - (void)webView:(WKWebView*)webView
4378 didReceiveServerRedirectForProvisionalNavigation:(WKNavigation*)navigation { 4394 didReceiveServerRedirectForProvisionalNavigation:(WKNavigation*)navigation {
4379 [_navigationStates setState:web::WKNavigationState::REDIRECTED 4395 [_navigationStates setState:web::WKNavigationState::REDIRECTED
4380 forNavigation:navigation]; 4396 forNavigation:navigation];
4381 4397
4382 [self registerLoadRequest:net::GURLWithNSURL(webView.URL) 4398 // It is fine to ignore returned NavigationContext. Context does not change
4383 referrer:[self currentReferrer] 4399 // for redirect and old context stored _navigationStates is valid and it
4384 transition:ui::PAGE_TRANSITION_SERVER_REDIRECT]; 4400 // should not be replaced.
4401 [self registerLoadRequestForURL:net::GURLWithNSURL(webView.URL)
4402 referrer:[self currentReferrer]
4403 transition:ui::PAGE_TRANSITION_SERVER_REDIRECT];
4385 } 4404 }
4386 4405
4387 - (void)webView:(WKWebView*)webView 4406 - (void)webView:(WKWebView*)webView
4388 didFailProvisionalNavigation:(WKNavigation*)navigation 4407 didFailProvisionalNavigation:(WKNavigation*)navigation
4389 withError:(NSError*)error { 4408 withError:(NSError*)error {
4390 [_navigationStates setState:web::WKNavigationState::PROVISIONALY_FAILED 4409 [_navigationStates setState:web::WKNavigationState::PROVISIONALY_FAILED
4391 forNavigation:navigation]; 4410 forNavigation:navigation];
4392 4411
4393 // Ignore provisional navigation failure if a new navigation has been started, 4412 // Ignore provisional navigation failure if a new navigation has been started,
4394 // for example, if a page is reloaded after the start of the provisional 4413 // for example, if a page is reloaded after the start of the provisional
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
4843 // history changes when a window.history.didPushState or 4862 // history changes when a window.history.didPushState or
4844 // window.history.didReplaceState message is received, which should happen in 4863 // window.history.didReplaceState message is received, which should happen in
4845 // the next runloop. 4864 // the next runloop.
4846 // 4865 //
4847 // Otherwise, simulate the whole delegate flow for a load (since the 4866 // Otherwise, simulate the whole delegate flow for a load (since the
4848 // superclass currently doesn't have a clean separation between URL changes 4867 // superclass currently doesn't have a clean separation between URL changes
4849 // and document changes). Note that the order of these calls is important: 4868 // and document changes). Note that the order of these calls is important:
4850 // registering a load request logically comes before updating the document 4869 // registering a load request logically comes before updating the document
4851 // URL, but also must come first since it uses state that is reset on URL 4870 // URL, but also must come first since it uses state that is reset on URL
4852 // changes. 4871 // changes.
4872 std::unique_ptr<web::NavigationContextImpl> navigationContext;
4853 if (!_changingHistoryState) { 4873 if (!_changingHistoryState) {
4854 // If this wasn't a previously-expected load (e.g., certain back/forward 4874 // If this wasn't a previously-expected load (e.g., certain back/forward
4855 // navigations), register the load request. 4875 // navigations), register the load request.
4856 if (![self isLoadRequestPendingForURL:newURL]) 4876 if (![self isLoadRequestPendingForURL:newURL])
4857 [self registerLoadRequest:newURL]; 4877 navigationContext = [self registerLoadRequestForURL:newURL];
4858 } 4878 }
4859 4879
4860 [self setDocumentURL:newURL]; 4880 [self setDocumentURL:newURL];
4861 4881
4862 if (!_changingHistoryState) { 4882 if (!_changingHistoryState) {
4863 [self didStartLoadingURL:_documentURL]; 4883 [self didStartLoadingURL:_documentURL];
4864 _webStateImpl->OnSameDocumentNavigation(newURL); 4884 _webStateImpl->OnSameDocumentNavigation(newURL);
4865 [self updateSSLStatusForCurrentNavigationItem]; 4885 [self updateSSLStatusForCurrentNavigationItem];
4866 [self didFinishNavigation:nil]; 4886 [self didFinishNavigation:nil];
4867 } 4887 }
(...skipping 29 matching lines...) Expand all
4897 NSMutableURLRequest* request = [self requestForCurrentNavigationItem]; 4917 NSMutableURLRequest* request = [self requestForCurrentNavigationItem];
4898 4918
4899 // If the request has POST data and is not a repost form, configure and 4919 // If the request has POST data and is not a repost form, configure and
4900 // run the POST request. 4920 // run the POST request.
4901 if (POSTData.length && !repostedForm) { 4921 if (POSTData.length && !repostedForm) {
4902 [request setHTTPMethod:@"POST"]; 4922 [request setHTTPMethod:@"POST"];
4903 [request setHTTPBody:POSTData]; 4923 [request setHTTPBody:POSTData];
4904 [request setAllHTTPHeaderFields:self.currentHTTPHeaders]; 4924 [request setAllHTTPHeaderFields:self.currentHTTPHeaders];
4905 GURL navigationURL = 4925 GURL navigationURL =
4906 currentItem ? currentItem->GetURL() : GURL::EmptyGURL(); 4926 currentItem ? currentItem->GetURL() : GURL::EmptyGURL();
4907 [self registerLoadRequest:navigationURL 4927 std::unique_ptr<web::NavigationContextImpl> navigationContext =
4908 referrer:self.currentNavItemReferrer 4928 [self registerLoadRequestForURL:navigationURL
4909 transition:self.currentTransition]; 4929 referrer:self.currentNavItemReferrer
4930 transition:self.currentTransition];
4910 [self loadPOSTRequest:request]; 4931 [self loadPOSTRequest:request];
4911 return; 4932 return;
4912 } 4933 }
4913 4934
4914 ProceduralBlock defaultNavigationBlock = ^{ 4935 ProceduralBlock defaultNavigationBlock = ^{
4915 web::NavigationItem* item = self.currentNavItem; 4936 web::NavigationItem* item = self.currentNavItem;
4916 GURL navigationURL = item ? item->GetURL() : GURL::EmptyGURL(); 4937 GURL navigationURL = item ? item->GetURL() : GURL::EmptyGURL();
4917 [self registerLoadRequest:navigationURL 4938 std::unique_ptr<web::NavigationContextImpl> navigationContext =
4918 referrer:self.currentNavItemReferrer 4939 [self registerLoadRequestForURL:navigationURL
4919 transition:self.currentTransition]; 4940 referrer:self.currentNavItemReferrer
4941 transition:self.currentTransition];
4920 [self loadRequest:request]; 4942 [self loadRequest:request];
4921 [self reportBackForwardNavigationTypeForFastNavigation:NO]; 4943 [self reportBackForwardNavigationTypeForFastNavigation:NO];
4922 }; 4944 };
4923 4945
4924 // When navigating via WKBackForwardListItem to pages created or updated by 4946 // When navigating via WKBackForwardListItem to pages created or updated by
4925 // calls to pushState() and replaceState(), sometimes web_bundle.js is not 4947 // calls to pushState() and replaceState(), sometimes web_bundle.js is not
4926 // injected correctly. This means that calling window.history navigation 4948 // injected correctly. This means that calling window.history navigation
4927 // functions will invoke WKWebView's non-overridden implementations, causing a 4949 // functions will invoke WKWebView's non-overridden implementations, causing a
4928 // mismatch between the WKBackForwardList and NavigationManager. 4950 // mismatch between the WKBackForwardList and NavigationManager.
4929 // TODO(crbug.com/659816): Figure out how to prevent web_bundle.js injection 4951 // TODO(crbug.com/659816): Figure out how to prevent web_bundle.js injection
(...skipping 14 matching lines...) Expand all
4944 return; 4966 return;
4945 } 4967 }
4946 4968
4947 ProceduralBlock webViewNavigationBlock = ^{ 4969 ProceduralBlock webViewNavigationBlock = ^{
4948 // If the current navigation URL is the same as the URL of the visible 4970 // If the current navigation URL is the same as the URL of the visible
4949 // page, that means the user requested a reload. |goToBackForwardListItem| 4971 // page, that means the user requested a reload. |goToBackForwardListItem|
4950 // will be a no-op when it is passed the current back forward list item, 4972 // will be a no-op when it is passed the current back forward list item,
4951 // so |reload| must be explicitly called. 4973 // so |reload| must be explicitly called.
4952 web::NavigationItem* item = self.currentNavItem; 4974 web::NavigationItem* item = self.currentNavItem;
4953 GURL navigationURL = item ? item->GetURL() : GURL::EmptyGURL(); 4975 GURL navigationURL = item ? item->GetURL() : GURL::EmptyGURL();
4954 [self registerLoadRequest:navigationURL 4976 std::unique_ptr<web::NavigationContextImpl> navigationContext =
4955 referrer:self.currentNavItemReferrer 4977 [self registerLoadRequestForURL:navigationURL
4956 transition:self.currentTransition]; 4978 referrer:self.currentNavItemReferrer
4979 transition:self.currentTransition];
4957 WKNavigation* navigation = nil; 4980 WKNavigation* navigation = nil;
4958 if (navigationURL == net::GURLWithNSURL([_webView URL])) { 4981 if (navigationURL == net::GURLWithNSURL([_webView URL])) {
4959 navigation = [_webView reload]; 4982 navigation = [_webView reload];
4960 } else { 4983 } else {
4961 // |didCommitNavigation:| may not be called for fast navigation, so update 4984 // |didCommitNavigation:| may not be called for fast navigation, so update
4962 // the navigation type now as it is already known. 4985 // the navigation type now as it is already known.
4963 holder->set_navigation_type(WKNavigationTypeBackForward); 4986 holder->set_navigation_type(WKNavigationTypeBackForward);
4964 navigation = 4987 navigation =
4965 [_webView goToBackForwardListItem:holder->back_forward_list_item()]; 4988 [_webView goToBackForwardListItem:holder->back_forward_list_item()];
4966 [self reportBackForwardNavigationTypeForFastNavigation:YES]; 4989 [self reportBackForwardNavigationTypeForFastNavigation:YES];
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
5066 - (NSUInteger)observerCount { 5089 - (NSUInteger)observerCount {
5067 DCHECK_EQ(_observerBridges.size(), [_observers count]); 5090 DCHECK_EQ(_observerBridges.size(), [_observers count]);
5068 return [_observers count]; 5091 return [_observers count];
5069 } 5092 }
5070 5093
5071 - (NSString*)referrerFromNavigationAction:(WKNavigationAction*)action { 5094 - (NSString*)referrerFromNavigationAction:(WKNavigationAction*)action {
5072 return [action.request valueForHTTPHeaderField:kReferrerHeaderName]; 5095 return [action.request valueForHTTPHeaderField:kReferrerHeaderName];
5073 } 5096 }
5074 5097
5075 @end 5098 @end
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698