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

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

Issue 2834413002: Return NavigationContext from registerLoadRequest. (Closed)
Patch Set: - Created 3 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 <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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 #import "ios/web/public/web_state/ui/crw_web_view_content_view.h" 75 #import "ios/web/public/web_state/ui/crw_web_view_content_view.h"
76 #import "ios/web/public/web_state/ui/crw_web_view_scroll_view_proxy.h" 76 #import "ios/web/public/web_state/ui/crw_web_view_scroll_view_proxy.h"
77 #include "ios/web/public/web_state/url_verification_constants.h" 77 #include "ios/web/public/web_state/url_verification_constants.h"
78 #import "ios/web/public/web_state/web_state.h" 78 #import "ios/web/public/web_state/web_state.h"
79 #include "ios/web/public/webui/web_ui_ios.h" 79 #include "ios/web/public/webui/web_ui_ios.h"
80 #import "ios/web/web_state/crw_pass_kit_downloader.h" 80 #import "ios/web/web_state/crw_pass_kit_downloader.h"
81 #import "ios/web/web_state/error_translation_util.h" 81 #import "ios/web/web_state/error_translation_util.h"
82 #import "ios/web/web_state/js/crw_js_plugin_placeholder_manager.h" 82 #import "ios/web/web_state/js/crw_js_plugin_placeholder_manager.h"
83 #import "ios/web/web_state/js/crw_js_post_request_loader.h" 83 #import "ios/web/web_state/js/crw_js_post_request_loader.h"
84 #import "ios/web/web_state/js/crw_js_window_id_manager.h" 84 #import "ios/web/web_state/js/crw_js_window_id_manager.h"
85 #include "ios/web/web_state/navigation_context_impl.h"
85 #import "ios/web/web_state/page_viewport_state.h" 86 #import "ios/web/web_state/page_viewport_state.h"
86 #import "ios/web/web_state/ui/crw_context_menu_controller.h" 87 #import "ios/web/web_state/ui/crw_context_menu_controller.h"
87 #import "ios/web/web_state/ui/crw_swipe_recognizer_provider.h" 88 #import "ios/web/web_state/ui/crw_swipe_recognizer_provider.h"
88 #import "ios/web/web_state/ui/crw_web_controller.h" 89 #import "ios/web/web_state/ui/crw_web_controller.h"
89 #import "ios/web/web_state/ui/crw_web_controller_container_view.h" 90 #import "ios/web/web_state/ui/crw_web_controller_container_view.h"
90 #import "ios/web/web_state/ui/crw_web_view_proxy_impl.h" 91 #import "ios/web/web_state/ui/crw_web_view_proxy_impl.h"
91 #import "ios/web/web_state/ui/crw_wk_navigation_states.h" 92 #import "ios/web/web_state/ui/crw_wk_navigation_states.h"
92 #import "ios/web/web_state/ui/crw_wk_script_message_router.h" 93 #import "ios/web/web_state/ui/crw_wk_script_message_router.h"
93 #import "ios/web/web_state/ui/wk_back_forward_list_item_holder.h" 94 #import "ios/web/web_state/ui/wk_back_forward_list_item_holder.h"
94 #import "ios/web/web_state/ui/wk_web_view_configuration_provider.h" 95 #import "ios/web/web_state/ui/wk_web_view_configuration_provider.h"
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 - (web::WKWebViewConfigurationProvider&)webViewConfigurationProvider; 559 - (web::WKWebViewConfigurationProvider&)webViewConfigurationProvider;
559 // Extracts "Referer" [sic] value from WKNavigationAction request header. 560 // Extracts "Referer" [sic] value from WKNavigationAction request header.
560 - (NSString*)referrerFromNavigationAction:(WKNavigationAction*)action; 561 - (NSString*)referrerFromNavigationAction:(WKNavigationAction*)action;
561 562
562 // Returns the current URL of the web view, and sets |trustLevel| accordingly 563 // Returns the current URL of the web view, and sets |trustLevel| accordingly
563 // based on the confidence in the verification. 564 // based on the confidence in the verification.
564 - (GURL)webURLWithTrustLevel:(web::URLVerificationTrustLevel*)trustLevel; 565 - (GURL)webURLWithTrustLevel:(web::URLVerificationTrustLevel*)trustLevel;
565 // Returns |YES| if |url| should be loaded in a native view. 566 // Returns |YES| if |url| should be loaded in a native view.
566 - (BOOL)shouldLoadURLInNativeView:(const GURL&)url; 567 - (BOOL)shouldLoadURLInNativeView:(const GURL&)url;
567 // Loads the request into the |webView|. 568 // Loads the request into the |webView|.
568 - (void)loadRequest:(NSMutableURLRequest*)request; 569 - (WKNavigation*)loadRequest:(NSMutableURLRequest*)request;
569 // Loads POST request with body in |_wkWebView| by constructing an HTML page 570 // Loads POST request with body in |_wkWebView| by constructing an HTML page
570 // that executes the request through JavaScript and replaces document with the 571 // that executes the request through JavaScript and replaces document with the
571 // result. 572 // result.
572 // Note that this approach includes multiple body encodings and decodings, plus 573 // Note that this approach includes multiple body encodings and decodings, plus
573 // the data is passed to |_wkWebView| on main thread. 574 // the data is passed to |_wkWebView| on main thread.
574 // This is necessary because WKWebView ignores POST request body. 575 // This is necessary because WKWebView ignores POST request body.
575 // Workaround for https://bugs.webkit.org/show_bug.cgi?id=145410 576 // Workaround for https://bugs.webkit.org/show_bug.cgi?id=145410
576 - (void)loadPOSTRequest:(NSMutableURLRequest*)request; 577 - (WKNavigation*)loadPOSTRequest:(NSMutableURLRequest*)request;
577 // Loads the HTML into the page at the given URL. 578 // Loads the HTML into the page at the given URL.
578 - (void)loadHTML:(NSString*)html forURL:(const GURL&)url; 579 - (void)loadHTML:(NSString*)html forURL:(const GURL&)url;
579 580
580 // Extracts navigation info from WKNavigationAction and sets it as a pending. 581 // Extracts navigation info from WKNavigationAction and sets it as a pending.
581 // Some pieces of navigation information are only known in 582 // Some pieces of navigation information are only known in
582 // |decidePolicyForNavigationAction|, but must be in a pending state until 583 // |decidePolicyForNavigationAction|, but must be in a pending state until
583 // |didgo/Navigation| where it becames current. 584 // |didgo/Navigation| where it becames current.
584 - (void)updatePendingNavigationInfoFromNavigationAction: 585 - (void)updatePendingNavigationInfoFromNavigationAction:
585 (WKNavigationAction*)action; 586 (WKNavigationAction*)action;
586 // Extracts navigation info from WKNavigationResponse and sets it as a pending. 587 // Extracts navigation info from WKNavigationResponse and sets it as a pending.
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 userIsInteracting:(BOOL)userIsInteracting 640 userIsInteracting:(BOOL)userIsInteracting
640 originURL:(const GURL&)originURL; 641 originURL:(const GURL&)originURL;
641 // Called when web controller receives a new message from the web page. 642 // Called when web controller receives a new message from the web page.
642 - (void)didReceiveScriptMessage:(WKScriptMessage*)message; 643 - (void)didReceiveScriptMessage:(WKScriptMessage*)message;
643 // Returns a new script which wraps |script| with windowID check so |script| is 644 // Returns a new script which wraps |script| with windowID check so |script| is
644 // not evaluated on windowID mismatch. 645 // not evaluated on windowID mismatch.
645 - (NSString*)scriptByAddingWindowIDCheckForScript:(NSString*)script; 646 - (NSString*)scriptByAddingWindowIDCheckForScript:(NSString*)script;
646 // Attempts to handle a script message. Returns YES on success, NO otherwise. 647 // Attempts to handle a script message. Returns YES on success, NO otherwise.
647 - (BOOL)respondToWKScriptMessage:(WKScriptMessage*)scriptMessage; 648 - (BOOL)respondToWKScriptMessage:(WKScriptMessage*)scriptMessage;
648 // Registers load request with empty referrer and link or client redirect 649 // Registers load request with empty referrer and link or client redirect
649 // transition based on user interaction state. 650 // transition based on user interaction state. Returns navigation context for
650 - (void)registerLoadRequest:(const GURL&)URL; 651 // this request.
652 - (std::unique_ptr<web::NavigationContextImpl>)registerLoadRequestForURL:
653 (const GURL&)URL;
651 // Prepares web controller and delegates for anticipated page change. 654 // Prepares web controller and delegates for anticipated page change.
652 // Allows several methods to invoke webWill/DidAddPendingURL on anticipated page 655 // Allows several methods to invoke webWill/DidAddPendingURL on anticipated page
653 // change, using the same cached request and calculated transition types. 656 // change, using the same cached request and calculated transition types.
654 - (void)registerLoadRequest:(const GURL&)URL 657 // Returns navigation context for this request.
655 referrer:(const web::Referrer&)referrer 658 - (std::unique_ptr<web::NavigationContextImpl>)
656 transition:(ui::PageTransition)transition; 659 registerLoadRequestForURL:(const GURL&)URL
660 referrer:(const web::Referrer&)referrer
661 transition:(ui::PageTransition)transition;
657 // Updates the HTML5 history state of the page using the current NavigationItem. 662 // Updates the HTML5 history state of the page using the current NavigationItem.
658 // For same-document navigations and navigations affected by 663 // For same-document navigations and navigations affected by
659 // window.history.[push/replace]State(), the URL and serialized state object 664 // window.history.[push/replace]State(), the URL and serialized state object
660 // will be updated to the current NavigationItem's values. A popState event 665 // will be updated to the current NavigationItem's values. A popState event
661 // will be triggered for all same-document navigations. Additionaly, a 666 // will be triggered for all same-document navigations. Additionaly, a
662 // hashchange event will be triggered for same-document navigations where the 667 // hashchange event will be triggered for same-document navigations where the
663 // only difference between the current and previous URL is the fragment. 668 // only difference between the current and previous URL is the fragment.
664 - (void)updateHTML5HistoryState; 669 - (void)updateHTML5HistoryState;
665 // Generates the JavaScript string used to update the UIWebView's URL so that it 670 // Generates the JavaScript string used to update the UIWebView's URL so that it
666 // matches the URL displayed in the omnibox and sets window.history.state to 671 // matches the URL displayed in the omnibox and sets window.history.state to
(...skipping 771 matching lines...) Expand 10 before | Expand all | Expand 10 after
1438 1443
1439 - (UIView*)viewForPrinting { 1444 - (UIView*)viewForPrinting {
1440 // Printing is not supported for native controllers. 1445 // Printing is not supported for native controllers.
1441 return _webView; 1446 return _webView;
1442 } 1447 }
1443 1448
1444 - (double)loadingProgress { 1449 - (double)loadingProgress {
1445 return [_webView estimatedProgress]; 1450 return [_webView estimatedProgress];
1446 } 1451 }
1447 1452
1448 - (void)registerLoadRequest:(const GURL&)URL { 1453 - (std::unique_ptr<web::NavigationContextImpl>)registerLoadRequestForURL:
1454 (const GURL&)URL {
1449 // Get the navigation type from the last main frame load request, and try to 1455 // Get the navigation type from the last main frame load request, and try to
1450 // map that to a PageTransition. 1456 // map that to a PageTransition.
1451 WKNavigationType navigationType = 1457 WKNavigationType navigationType =
1452 _pendingNavigationInfo ? [_pendingNavigationInfo navigationType] 1458 _pendingNavigationInfo ? [_pendingNavigationInfo navigationType]
1453 : WKNavigationTypeOther; 1459 : WKNavigationTypeOther;
1454 ui::PageTransition transition = ui::PAGE_TRANSITION_CLIENT_REDIRECT; 1460 ui::PageTransition transition = ui::PAGE_TRANSITION_CLIENT_REDIRECT;
1455 switch (navigationType) { 1461 switch (navigationType) {
1456 case WKNavigationTypeLinkActivated: 1462 case WKNavigationTypeLinkActivated:
1457 transition = ui::PAGE_TRANSITION_LINK; 1463 transition = ui::PAGE_TRANSITION_LINK;
1458 break; 1464 break;
(...skipping 12 matching lines...) Expand all
1471 // or may not be the result of user actions. For now, guess based on 1477 // or may not be the result of user actions. For now, guess based on
1472 // whether there's been an interaction since the last URL change. 1478 // whether there's been an interaction since the last URL change.
1473 // TODO(crbug.com/549301): See if this heuristic can be improved. 1479 // TODO(crbug.com/549301): See if this heuristic can be improved.
1474 transition = _interactionRegisteredSinceLastURLChange 1480 transition = _interactionRegisteredSinceLastURLChange
1475 ? ui::PAGE_TRANSITION_LINK 1481 ? ui::PAGE_TRANSITION_LINK
1476 : ui::PAGE_TRANSITION_CLIENT_REDIRECT; 1482 : ui::PAGE_TRANSITION_CLIENT_REDIRECT;
1477 break; 1483 break;
1478 } 1484 }
1479 // The referrer is not known yet, and will be updated later. 1485 // The referrer is not known yet, and will be updated later.
1480 const web::Referrer emptyReferrer; 1486 const web::Referrer emptyReferrer;
1481 [self registerLoadRequest:URL referrer:emptyReferrer transition:transition]; 1487 return [self registerLoadRequestForURL:URL
1488 referrer:emptyReferrer
1489 transition:transition];
1482 } 1490 }
1483 1491
1484 - (void)registerLoadRequest:(const GURL&)requestURL 1492 - (std::unique_ptr<web::NavigationContextImpl>)
1485 referrer:(const web::Referrer&)referrer 1493 registerLoadRequestForURL:(const GURL&)requestURL
1486 transition:(ui::PageTransition)transition { 1494 referrer:(const web::Referrer&)referrer
1495 transition:(ui::PageTransition)transition {
1487 // Transfer time is registered so that further transitions within the time 1496 // Transfer time is registered so that further transitions within the time
1488 // envelope are not also registered as links. 1497 // envelope are not also registered as links.
1489 _lastTransferTimeInSeconds = CFAbsoluteTimeGetCurrent(); 1498 _lastTransferTimeInSeconds = CFAbsoluteTimeGetCurrent();
1490 bool redirect = transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK; 1499 bool redirect = transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK;
1491 if (!redirect) { 1500 if (!redirect) {
1492 // Before changing phases, the delegate should be informed that any existing 1501 // Before changing phases, the delegate should be informed that any existing
1493 // request is being cancelled before completion. 1502 // request is being cancelled before completion.
1494 [self loadCancelled]; 1503 [self loadCancelled];
1495 DCHECK(_loadPhase == web::PAGE_LOADED); 1504 DCHECK(_loadPhase == web::PAGE_LOADED);
1496 } 1505 }
(...skipping 12 matching lines...) Expand all
1509 // Update the existing pending entry. 1518 // Update the existing pending entry.
1510 // Typically on PAGE_TRANSITION_CLIENT_REDIRECT. 1519 // Typically on PAGE_TRANSITION_CLIENT_REDIRECT.
1511 [[self sessionController] updatePendingItem:requestURL]; 1520 [[self sessionController] updatePendingItem:requestURL];
1512 } else { 1521 } else {
1513 // A new session history entry needs to be created. 1522 // A new session history entry needs to be created.
1514 self.navigationManagerImpl->AddPendingItem( 1523 self.navigationManagerImpl->AddPendingItem(
1515 requestURL, referrer, transition, 1524 requestURL, referrer, transition,
1516 web::NavigationInitiationType::RENDERER_INITIATED, 1525 web::NavigationInitiationType::RENDERER_INITIATED,
1517 web::NavigationManager::UserAgentOverrideOption::INHERIT); 1526 web::NavigationManager::UserAgentOverrideOption::INHERIT);
1518 } 1527 }
1528 std::unique_ptr<web::NavigationContextImpl> context =
1529 web::NavigationContextImpl::CreateNavigationContext(
1530 _webStateImpl, requestURL, nullptr /* response_headers */);
1519 _webStateImpl->SetIsLoading(true); 1531 _webStateImpl->SetIsLoading(true);
1532 // TODO(crbug.com/713836): pass context to |OnProvisionalNavigationStarted|.
1520 _webStateImpl->OnProvisionalNavigationStarted(requestURL); 1533 _webStateImpl->OnProvisionalNavigationStarted(requestURL);
1534 return context;
1521 } 1535 }
1522 1536
1523 - (void)updateHTML5HistoryState { 1537 - (void)updateHTML5HistoryState {
1524 web::NavigationItemImpl* currentItem = self.currentNavItem; 1538 web::NavigationItemImpl* currentItem = self.currentNavItem;
1525 if (!currentItem) 1539 if (!currentItem)
1526 return; 1540 return;
1527 1541
1528 // Same-document navigations must trigger a popState event. 1542 // Same-document navigations must trigger a popState event.
1529 CRWSessionController* sessionController = self.sessionController; 1543 CRWSessionController* sessionController = self.sessionController;
1530 BOOL sameDocumentNavigation = [sessionController 1544 BOOL sameDocumentNavigation = [sessionController
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
1805 const web::Referrer referrer; 1819 const web::Referrer referrer;
1806 id<CRWNativeContent> nativeContent = 1820 id<CRWNativeContent> nativeContent =
1807 [_nativeProvider controllerForURL:targetURL webState:self.webState]; 1821 [_nativeProvider controllerForURL:targetURL webState:self.webState];
1808 // Unlike the WebView case, always create a new controller and view. 1822 // Unlike the WebView case, always create a new controller and view.
1809 // TODO(pinkerton): What to do if this does return nil? 1823 // TODO(pinkerton): What to do if this does return nil?
1810 [self setNativeController:nativeContent]; 1824 [self setNativeController:nativeContent];
1811 if ([nativeContent respondsToSelector:@selector(virtualURL)]) { 1825 if ([nativeContent respondsToSelector:@selector(virtualURL)]) {
1812 item->SetVirtualURL([nativeContent virtualURL]); 1826 item->SetVirtualURL([nativeContent virtualURL]);
1813 } 1827 }
1814 1828
1815 [self registerLoadRequest:targetURL 1829 std::unique_ptr<web::NavigationContextImpl> navigationContext =
1816 referrer:referrer 1830 [self registerLoadRequestForURL:targetURL
1817 transition:self.currentTransition]; 1831 referrer:referrer
1832 transition:self.currentTransition];
kkhorimoto 2017/04/25 13:45:50 I'm assuming that this will be utilized in a later
Eugene But (OOO till 7-30) 2017/04/27 16:12:06 Yes, here: https://codereview.chromium.org/284244
1818 [self loadNativeViewWithSuccess:YES]; 1833 [self loadNativeViewWithSuccess:YES];
1819 } 1834 }
1820 1835
1821 - (void)loadWithParams:(const NavigationManager::WebLoadParams&)params { 1836 - (void)loadWithParams:(const NavigationManager::WebLoadParams&)params {
1822 DCHECK(!(params.transition_type & ui::PAGE_TRANSITION_FORWARD_BACK)); 1837 DCHECK(!(params.transition_type & ui::PAGE_TRANSITION_FORWARD_BACK));
1823 1838
1824 // Clear transient view before making any changes to history and navigation 1839 // Clear transient view before making any changes to history and navigation
1825 // manager. TODO(stuartmorgan): Drive Transient Item clearing from 1840 // manager. TODO(stuartmorgan): Drive Transient Item clearing from
1826 // navigation system, rather than from WebController. 1841 // navigation system, rather than from WebController.
1827 [self clearTransientContentView]; 1842 [self clearTransientContentView];
(...skipping 2320 matching lines...) Expand 10 before | Expand all | Expand 10 after
4148 _webProcessIsDead = YES; 4163 _webProcessIsDead = YES;
4149 _webStateImpl->CancelDialogs(); 4164 _webStateImpl->CancelDialogs();
4150 _webStateImpl->OnRenderProcessGone(); 4165 _webStateImpl->OnRenderProcessGone();
4151 } 4166 }
4152 4167
4153 - (web::WKWebViewConfigurationProvider&)webViewConfigurationProvider { 4168 - (web::WKWebViewConfigurationProvider&)webViewConfigurationProvider {
4154 web::BrowserState* browserState = self.webStateImpl->GetBrowserState(); 4169 web::BrowserState* browserState = self.webStateImpl->GetBrowserState();
4155 return web::WKWebViewConfigurationProvider::FromBrowserState(browserState); 4170 return web::WKWebViewConfigurationProvider::FromBrowserState(browserState);
4156 } 4171 }
4157 4172
4158 - (void)loadRequest:(NSMutableURLRequest*)request { 4173 - (WKNavigation*)loadRequest:(NSMutableURLRequest*)request {
4174 WKNavigation* navigation = [_webView loadRequest:request];
4159 [_navigationStates setState:web::WKNavigationState::REQUESTED 4175 [_navigationStates setState:web::WKNavigationState::REQUESTED
4160 forNavigation:[_webView loadRequest:request]]; 4176 forNavigation:navigation];
4177 return navigation;
4161 } 4178 }
4162 4179
4163 - (void)loadPOSTRequest:(NSMutableURLRequest*)request { 4180 - (WKNavigation*)loadPOSTRequest:(NSMutableURLRequest*)request {
4164 if (!_POSTRequestLoader) { 4181 if (!_POSTRequestLoader) {
4165 _POSTRequestLoader.reset([[CRWJSPOSTRequestLoader alloc] init]); 4182 _POSTRequestLoader.reset([[CRWJSPOSTRequestLoader alloc] init]);
4166 } 4183 }
4167 4184
4168 CRWWKScriptMessageRouter* messageRouter = 4185 CRWWKScriptMessageRouter* messageRouter =
4169 [self webViewConfigurationProvider].GetScriptMessageRouter(); 4186 [self webViewConfigurationProvider].GetScriptMessageRouter();
4170 4187
4171 [_POSTRequestLoader loadPOSTRequest:request 4188 return [_POSTRequestLoader
4172 inWebView:_webView 4189 loadPOSTRequest:request
4173 messageRouter:messageRouter 4190 inWebView:_webView
4174 completionHandler:^(NSError* loadError) { 4191 messageRouter:messageRouter
4175 if (loadError) 4192 completionHandler:^(NSError* loadError) {
4176 [self handleLoadError:loadError 4193 if (loadError)
4177 inMainFrame:YES 4194 [self handleLoadError:loadError inMainFrame:YES forNavigation:nil];
4178 forNavigation:nil]; 4195 else
4179 else 4196 self.webStateImpl->SetContentsMimeType("text/html");
4180 self.webStateImpl->SetContentsMimeType("text/html"); 4197 }];
4181 }];
4182 } 4198 }
4183 4199
4184 - (void)loadHTML:(NSString*)HTML forURL:(const GURL&)URL { 4200 - (void)loadHTML:(NSString*)HTML forURL:(const GURL&)URL {
4185 // Remove the transient content view. 4201 // Remove the transient content view.
4186 [self clearTransientContentView]; 4202 [self clearTransientContentView];
4187 4203
4188 _loadPhase = web::LOAD_REQUESTED; 4204 _loadPhase = web::LOAD_REQUESTED;
4189 4205
4190 // Web View should not be created for App Specific URLs. 4206 // Web View should not be created for App Specific URLs.
4191 if (!web::GetWebClient()->IsAppSpecificURL(URL)) { 4207 if (!web::GetWebClient()->IsAppSpecificURL(URL)) {
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
4469 // pages. WebUI pages may have increased power and using the same web 4485 // pages. WebUI pages may have increased power and using the same web
4470 // process (which may potentially be controller by an attacker) is 4486 // process (which may potentially be controller by an attacker) is
4471 // dangerous. 4487 // dangerous.
4472 if (web::GetWebClient()->IsAppSpecificURL(_documentURL)) { 4488 if (web::GetWebClient()->IsAppSpecificURL(_documentURL)) {
4473 [self abortLoad]; 4489 [self abortLoad];
4474 NavigationManager::WebLoadParams params(webViewURL); 4490 NavigationManager::WebLoadParams params(webViewURL);
4475 [self loadWithParams:params]; 4491 [self loadWithParams:params];
4476 } 4492 }
4477 return; 4493 return;
4478 } else { 4494 } else {
4479 [self registerLoadRequest:webViewURL]; 4495 std::unique_ptr<web::NavigationContextImpl> navigationContext =
4496 [self registerLoadRequestForURL:webViewURL];
4480 } 4497 }
4481 } 4498 }
4482 4499
4483 // Ensure the URL is registered and loadPhase is as expected. 4500 // Ensure the URL is registered and loadPhase is as expected.
4484 DCHECK(_lastRegisteredRequestURL == webViewURL); 4501 DCHECK(_lastRegisteredRequestURL == webViewURL);
4485 DCHECK(self.loadPhase == web::LOAD_REQUESTED); 4502 DCHECK(self.loadPhase == web::LOAD_REQUESTED);
4486 } 4503 }
4487 4504
4488 - (void)webView:(WKWebView*)webView 4505 - (void)webView:(WKWebView*)webView
4489 didReceiveServerRedirectForProvisionalNavigation:(WKNavigation*)navigation { 4506 didReceiveServerRedirectForProvisionalNavigation:(WKNavigation*)navigation {
4490 [_navigationStates setState:web::WKNavigationState::REDIRECTED 4507 [_navigationStates setState:web::WKNavigationState::REDIRECTED
4491 forNavigation:navigation]; 4508 forNavigation:navigation];
4492 4509
4493 [self registerLoadRequest:net::GURLWithNSURL(webView.URL) 4510 // It is fine to ignore returned NavigationContet as it did not
kkhorimoto 2017/04/25 13:45:50 s/Contet/Context
Eugene But (OOO till 7-30) 2017/04/27 16:12:06 Done.
4494 referrer:[self currentReferrer] 4511 // change after the redirect.
kkhorimoto 2017/04/25 13:45:50 I don't really understand this comment. It looks
Eugene But (OOO till 7-30) 2017/04/27 16:12:06 Updated the comment. Please let me know if it is s
4495 transition:ui::PAGE_TRANSITION_SERVER_REDIRECT]; 4512 [self registerLoadRequestForURL:net::GURLWithNSURL(webView.URL)
4513 referrer:[self currentReferrer]
4514 transition:ui::PAGE_TRANSITION_SERVER_REDIRECT];
4496 } 4515 }
4497 4516
4498 - (void)webView:(WKWebView*)webView 4517 - (void)webView:(WKWebView*)webView
4499 didFailProvisionalNavigation:(WKNavigation*)navigation 4518 didFailProvisionalNavigation:(WKNavigation*)navigation
4500 withError:(NSError*)error { 4519 withError:(NSError*)error {
4501 [_navigationStates setState:web::WKNavigationState::PROVISIONALY_FAILED 4520 [_navigationStates setState:web::WKNavigationState::PROVISIONALY_FAILED
4502 forNavigation:navigation]; 4521 forNavigation:navigation];
4503 4522
4504 // Ignore provisional navigation failure if a new navigation has been started, 4523 // Ignore provisional navigation failure if a new navigation has been started,
4505 // for example, if a page is reloaded after the start of the provisional 4524 // 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
4954 // history changes when a window.history.didPushState or 4973 // history changes when a window.history.didPushState or
4955 // window.history.didReplaceState message is received, which should happen in 4974 // window.history.didReplaceState message is received, which should happen in
4956 // the next runloop. 4975 // the next runloop.
4957 // 4976 //
4958 // Otherwise, simulate the whole delegate flow for a load (since the 4977 // Otherwise, simulate the whole delegate flow for a load (since the
4959 // superclass currently doesn't have a clean separation between URL changes 4978 // superclass currently doesn't have a clean separation between URL changes
4960 // and document changes). Note that the order of these calls is important: 4979 // and document changes). Note that the order of these calls is important:
4961 // registering a load request logically comes before updating the document 4980 // registering a load request logically comes before updating the document
4962 // URL, but also must come first since it uses state that is reset on URL 4981 // URL, but also must come first since it uses state that is reset on URL
4963 // changes. 4982 // changes.
4983 std::unique_ptr<web::NavigationContextImpl> navigationContext;
4964 if (!_changingHistoryState) { 4984 if (!_changingHistoryState) {
4965 // If this wasn't a previously-expected load (e.g., certain back/forward 4985 // If this wasn't a previously-expected load (e.g., certain back/forward
4966 // navigations), register the load request. 4986 // navigations), register the load request.
4967 if (![self isLoadRequestPendingForURL:newURL]) 4987 if (![self isLoadRequestPendingForURL:newURL])
4968 [self registerLoadRequest:newURL]; 4988 navigationContext = [self registerLoadRequestForURL:newURL];
4969 } 4989 }
4970 4990
4971 [self setDocumentURL:newURL]; 4991 [self setDocumentURL:newURL];
4972 4992
4973 if (!_changingHistoryState) { 4993 if (!_changingHistoryState) {
4974 [self didStartLoadingURL:_documentURL]; 4994 [self didStartLoadingURL:_documentURL];
4975 _webStateImpl->OnSameDocumentNavigation(newURL); 4995 _webStateImpl->OnSameDocumentNavigation(newURL);
4976 [self updateSSLStatusForCurrentNavigationItem]; 4996 [self updateSSLStatusForCurrentNavigationItem];
4977 [self didFinishNavigation:nil]; 4997 [self didFinishNavigation:nil];
4978 } 4998 }
(...skipping 29 matching lines...) Expand all
5008 NSMutableURLRequest* request = [self requestForCurrentNavigationItem]; 5028 NSMutableURLRequest* request = [self requestForCurrentNavigationItem];
5009 5029
5010 // If the request has POST data and is not a repost form, configure and 5030 // If the request has POST data and is not a repost form, configure and
5011 // run the POST request. 5031 // run the POST request.
5012 if (POSTData.length && !repostedForm) { 5032 if (POSTData.length && !repostedForm) {
5013 [request setHTTPMethod:@"POST"]; 5033 [request setHTTPMethod:@"POST"];
5014 [request setHTTPBody:POSTData]; 5034 [request setHTTPBody:POSTData];
5015 [request setAllHTTPHeaderFields:self.currentHTTPHeaders]; 5035 [request setAllHTTPHeaderFields:self.currentHTTPHeaders];
5016 GURL navigationURL = 5036 GURL navigationURL =
5017 currentItem ? currentItem->GetURL() : GURL::EmptyGURL(); 5037 currentItem ? currentItem->GetURL() : GURL::EmptyGURL();
5018 [self registerLoadRequest:navigationURL 5038 std::unique_ptr<web::NavigationContextImpl> navigationContext =
5019 referrer:self.currentNavItemReferrer 5039 [self registerLoadRequestForURL:navigationURL
5020 transition:self.currentTransition]; 5040 referrer:self.currentNavItemReferrer
5041 transition:self.currentTransition];
5021 [self loadPOSTRequest:request]; 5042 [self loadPOSTRequest:request];
5022 return; 5043 return;
5023 } 5044 }
5024 5045
5025 ProceduralBlock defaultNavigationBlock = ^{ 5046 ProceduralBlock defaultNavigationBlock = ^{
5026 web::NavigationItem* item = self.currentNavItem; 5047 web::NavigationItem* item = self.currentNavItem;
5027 GURL navigationURL = item ? item->GetURL() : GURL::EmptyGURL(); 5048 GURL navigationURL = item ? item->GetURL() : GURL::EmptyGURL();
5028 [self registerLoadRequest:navigationURL 5049 std::unique_ptr<web::NavigationContextImpl> navigationContext =
5029 referrer:self.currentNavItemReferrer 5050 [self registerLoadRequestForURL:navigationURL
5030 transition:self.currentTransition]; 5051 referrer:self.currentNavItemReferrer
5052 transition:self.currentTransition];
5031 [self loadRequest:request]; 5053 [self loadRequest:request];
5032 [self reportBackForwardNavigationTypeForFastNavigation:NO]; 5054 [self reportBackForwardNavigationTypeForFastNavigation:NO];
5033 }; 5055 };
5034 5056
5035 // When navigating via WKBackForwardListItem to pages created or updated by 5057 // When navigating via WKBackForwardListItem to pages created or updated by
5036 // calls to pushState() and replaceState(), sometimes web_bundle.js is not 5058 // calls to pushState() and replaceState(), sometimes web_bundle.js is not
5037 // injected correctly. This means that calling window.history navigation 5059 // injected correctly. This means that calling window.history navigation
5038 // functions will invoke WKWebView's non-overridden implementations, causing a 5060 // functions will invoke WKWebView's non-overridden implementations, causing a
5039 // mismatch between the WKBackForwardList and NavigationManager. 5061 // mismatch between the WKBackForwardList and NavigationManager.
5040 // TODO(crbug.com/659816): Figure out how to prevent web_bundle.js injection 5062 // TODO(crbug.com/659816): Figure out how to prevent web_bundle.js injection
(...skipping 14 matching lines...) Expand all
5055 return; 5077 return;
5056 } 5078 }
5057 5079
5058 ProceduralBlock webViewNavigationBlock = ^{ 5080 ProceduralBlock webViewNavigationBlock = ^{
5059 // If the current navigation URL is the same as the URL of the visible 5081 // If the current navigation URL is the same as the URL of the visible
5060 // page, that means the user requested a reload. |goToBackForwardListItem| 5082 // page, that means the user requested a reload. |goToBackForwardListItem|
5061 // will be a no-op when it is passed the current back forward list item, 5083 // will be a no-op when it is passed the current back forward list item,
5062 // so |reload| must be explicitly called. 5084 // so |reload| must be explicitly called.
5063 web::NavigationItem* item = self.currentNavItem; 5085 web::NavigationItem* item = self.currentNavItem;
5064 GURL navigationURL = item ? item->GetURL() : GURL::EmptyGURL(); 5086 GURL navigationURL = item ? item->GetURL() : GURL::EmptyGURL();
5065 [self registerLoadRequest:navigationURL 5087 std::unique_ptr<web::NavigationContextImpl> navigationContext =
5066 referrer:self.currentNavItemReferrer 5088 [self registerLoadRequestForURL:navigationURL
5067 transition:self.currentTransition]; 5089 referrer:self.currentNavItemReferrer
5090 transition:self.currentTransition];
5068 WKNavigation* navigation = nil; 5091 WKNavigation* navigation = nil;
5069 if (navigationURL == net::GURLWithNSURL([_webView URL])) { 5092 if (navigationURL == net::GURLWithNSURL([_webView URL])) {
5070 navigation = [_webView reload]; 5093 navigation = [_webView reload];
5071 } else { 5094 } else {
5072 // |didCommitNavigation:| may not be called for fast navigation, so update 5095 // |didCommitNavigation:| may not be called for fast navigation, so update
5073 // the navigation type now as it is already known. 5096 // the navigation type now as it is already known.
5074 holder->set_navigation_type(WKNavigationTypeBackForward); 5097 holder->set_navigation_type(WKNavigationTypeBackForward);
5075 navigation = 5098 navigation =
5076 [_webView goToBackForwardListItem:holder->back_forward_list_item()]; 5099 [_webView goToBackForwardListItem:holder->back_forward_list_item()];
5077 [self reportBackForwardNavigationTypeForFastNavigation:YES]; 5100 [self reportBackForwardNavigationTypeForFastNavigation:YES];
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
5177 - (NSUInteger)observerCount { 5200 - (NSUInteger)observerCount {
5178 DCHECK_EQ(_observerBridges.size(), [_observers count]); 5201 DCHECK_EQ(_observerBridges.size(), [_observers count]);
5179 return [_observers count]; 5202 return [_observers count];
5180 } 5203 }
5181 5204
5182 - (NSString*)referrerFromNavigationAction:(WKNavigationAction*)action { 5205 - (NSString*)referrerFromNavigationAction:(WKNavigationAction*)action {
5183 return [action.request valueForHTTPHeaderField:kReferrerHeaderName]; 5206 return [action.request valueForHTTPHeaderField:kReferrerHeaderName];
5184 } 5207 }
5185 5208
5186 @end 5209 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698