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

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

Issue 2698773002: [iOS] Refactoring web CRWSessionController user agent code. (Closed)
Patch Set: Update NavigationItemImpl to use NavigationInitiationType Created 3 years, 10 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 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 @property(nonatomic, readonly) WKWebView* webView; 428 @property(nonatomic, readonly) WKWebView* webView;
429 // The scroll view of |webView|. 429 // The scroll view of |webView|.
430 @property(nonatomic, readonly) UIScrollView* webScrollView; 430 @property(nonatomic, readonly) UIScrollView* webScrollView;
431 // The current page state of the web view. Writing to this property 431 // The current page state of the web view. Writing to this property
432 // asynchronously applies the passed value to the current web view. 432 // asynchronously applies the passed value to the current web view.
433 @property(nonatomic, readwrite) web::PageDisplayState pageDisplayState; 433 @property(nonatomic, readwrite) web::PageDisplayState pageDisplayState;
434 // The currently displayed native controller, if any. 434 // The currently displayed native controller, if any.
435 @property(nonatomic, readwrite) id<CRWNativeContent> nativeController; 435 @property(nonatomic, readwrite) id<CRWNativeContent> nativeController;
436 // Returns NavigationManager's session controller. 436 // Returns NavigationManager's session controller.
437 @property(nonatomic, readonly) CRWSessionController* sessionController; 437 @property(nonatomic, readonly) CRWSessionController* sessionController;
438 // The associated NavigationManagerImpl.
439 @property(nonatomic, readonly) NavigationManagerImpl* navigationManagerImpl;
438 // Dictionary where keys are the names of WKWebView properties and values are 440 // Dictionary where keys are the names of WKWebView properties and values are
439 // selector names which should be called when a corresponding property has 441 // selector names which should be called when a corresponding property has
440 // changed. e.g. @{ @"URL" : @"webViewURLDidChange" } means that 442 // changed. e.g. @{ @"URL" : @"webViewURLDidChange" } means that
441 // -[self webViewURLDidChange] must be called every time when WKWebView.URL is 443 // -[self webViewURLDidChange] must be called every time when WKWebView.URL is
442 // changed. 444 // changed.
443 @property(nonatomic, readonly) NSDictionary* WKWebViewObservers; 445 @property(nonatomic, readonly) NSDictionary* WKWebViewObservers;
444 // Downloader for PassKit files. Lazy initialized. 446 // Downloader for PassKit files. Lazy initialized.
445 @property(nonatomic, readonly) CRWPassKitDownloader* passKitDownloader; 447 @property(nonatomic, readonly) CRWPassKitDownloader* passKitDownloader;
446 448
447 // The web view's view of the current URL. During page transitions 449 // The web view's view of the current URL. During page transitions
(...skipping 918 matching lines...) Expand 10 before | Expand all | Expand 10 after
1366 1368
1367 - (void)setDocumentURL:(const GURL&)newURL { 1369 - (void)setDocumentURL:(const GURL&)newURL {
1368 if (newURL != _documentURL && newURL.is_valid()) { 1370 if (newURL != _documentURL && newURL.is_valid()) {
1369 _documentURL = newURL; 1371 _documentURL = newURL;
1370 _interactionRegisteredSinceLastURLChange = NO; 1372 _interactionRegisteredSinceLastURLChange = NO;
1371 } 1373 }
1372 } 1374 }
1373 1375
1374 - (void)setNavigationItemTitle:(NSString*)title { 1376 - (void)setNavigationItemTitle:(NSString*)title {
1375 DCHECK(title); 1377 DCHECK(title);
1376 auto& navigationManager = _webStateImpl->GetNavigationManagerImpl(); 1378 web::NavigationItem* item =
1377 web::NavigationItem* item = navigationManager.GetLastCommittedItem(); 1379 self.navigationManagerImpl->GetLastCommittedItem();
1378 if (!item) 1380 if (!item)
1379 return; 1381 return;
1380 1382
1381 base::string16 newTitle = base::SysNSStringToUTF16(title); 1383 base::string16 newTitle = base::SysNSStringToUTF16(title);
1382 if (item->GetTitle() == newTitle) 1384 if (item->GetTitle() == newTitle)
1383 return; 1385 return;
1384 1386
1385 item->SetTitle(newTitle); 1387 item->SetTitle(newTitle);
1386 // TODO(crbug.com/546218): See if this can be removed; it's not clear that 1388 // TODO(crbug.com/546218): See if this can be removed; it's not clear that
1387 // other platforms send this (tab sync triggers need to be compared against 1389 // other platforms send this (tab sync triggers need to be compared against
1388 // upstream). 1390 // upstream).
1389 navigationManager.OnNavigationItemChanged(); 1391 self.navigationManagerImpl->OnNavigationItemChanged();
1390 1392
1391 if ([_delegate respondsToSelector:@selector(webController:titleDidChange:)]) { 1393 if ([_delegate respondsToSelector:@selector(webController:titleDidChange:)]) {
1392 [_delegate webController:self titleDidChange:title]; 1394 [_delegate webController:self titleDidChange:title];
1393 } 1395 }
1394 } 1396 }
1395 1397
1396 - (BOOL)isCurrentNavigationItemPOST { 1398 - (BOOL)isCurrentNavigationItemPOST {
1397 // |_pendingNavigationInfo| will be nil if the decidePolicy* delegate methods 1399 // |_pendingNavigationInfo| will be nil if the decidePolicy* delegate methods
1398 // were not called. 1400 // were not called.
1399 NSString* HTTPMethod = 1401 NSString* HTTPMethod =
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
1562 _loadPhase = web::LOAD_REQUESTED; 1564 _loadPhase = web::LOAD_REQUESTED;
1563 _lastRegisteredRequestURL = requestURL; 1565 _lastRegisteredRequestURL = requestURL;
1564 1566
1565 if (!(transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK)) { 1567 if (!(transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK)) {
1566 // Record state of outgoing page. 1568 // Record state of outgoing page.
1567 [self recordStateInHistory]; 1569 [self recordStateInHistory];
1568 } 1570 }
1569 1571
1570 [_delegate webWillAddPendingURL:requestURL transition:transition]; 1572 [_delegate webWillAddPendingURL:requestURL transition:transition];
1571 // Add or update pending url. 1573 // Add or update pending url.
1572 if (_webStateImpl->GetNavigationManagerImpl().GetPendingItem()) { 1574 if (self.navigationManagerImpl->GetPendingItem()) {
1573 // Update the existing pending entry. 1575 // Update the existing pending entry.
1574 // Typically on PAGE_TRANSITION_CLIENT_REDIRECT. 1576 // Typically on PAGE_TRANSITION_CLIENT_REDIRECT.
1575 [[self sessionController] updatePendingItem:requestURL]; 1577 [[self sessionController] updatePendingItem:requestURL];
1576 } else { 1578 } else {
1577 // A new session history entry needs to be created. 1579 // A new session history entry needs to be created.
1578 [[self sessionController] addPendingItem:requestURL 1580 self.navigationManagerImpl->AddPendingItem(
1579 referrer:referrer 1581 requestURL, referrer, transition,
1580 transition:transition 1582 web::NavigationInitiationType::RENDERER_INITIATED);
1581 rendererInitiated:YES];
1582 } 1583 }
1583 _webStateImpl->SetIsLoading(true); 1584 _webStateImpl->SetIsLoading(true);
1584 _webStateImpl->OnProvisionalNavigationStarted(requestURL); 1585 _webStateImpl->OnProvisionalNavigationStarted(requestURL);
1585 } 1586 }
1586 1587
1587 - (void)updateHTML5HistoryState { 1588 - (void)updateHTML5HistoryState {
1588 web::NavigationItemImpl* currentItem = 1589 web::NavigationItemImpl* currentItem =
1589 static_cast<web::NavigationItemImpl*>([self currentNavItem]); 1590 static_cast<web::NavigationItemImpl*>([self currentNavItem]);
1590 if (!currentItem) 1591 if (!currentItem)
1591 return; 1592 return;
(...skipping 17 matching lines...) Expand all
1609 // NavigationItems that were created or updated by calls to pushState() or 1610 // NavigationItems that were created or updated by calls to pushState() or
1610 // replaceState(). 1611 // replaceState().
1611 BOOL shouldUpdateState = sameDocumentNavigation || 1612 BOOL shouldUpdateState = sameDocumentNavigation ||
1612 currentItem->IsCreatedFromPushState() || 1613 currentItem->IsCreatedFromPushState() ||
1613 currentItem->HasStateBeenReplaced(); 1614 currentItem->HasStateBeenReplaced();
1614 if (!shouldUpdateState) 1615 if (!shouldUpdateState)
1615 return; 1616 return;
1616 1617
1617 // TODO(stuartmorgan): Make CRWSessionController manage this internally (or 1618 // TODO(stuartmorgan): Make CRWSessionController manage this internally (or
1618 // remove it; it's not clear this matches other platforms' behavior). 1619 // remove it; it's not clear this matches other platforms' behavior).
1619 _webStateImpl->GetNavigationManagerImpl().OnNavigationItemCommitted(); 1620 self.navigationManagerImpl->OnNavigationItemCommitted();
1620 // Record that a same-document hashchange event will be fired. This flag will 1621 // Record that a same-document hashchange event will be fired. This flag will
1621 // be reset when resonding to the hashchange message. Note that resetting the 1622 // be reset when resonding to the hashchange message. Note that resetting the
1622 // flag in the completion block below is too early, as that block is called 1623 // flag in the completion block below is too early, as that block is called
1623 // before hashchange event listeners have a chance to fire. 1624 // before hashchange event listeners have a chance to fire.
1624 _dispatchingSameDocumentHashChangeEvent = shouldDispatchHashchange; 1625 _dispatchingSameDocumentHashChangeEvent = shouldDispatchHashchange;
1625 // Inject the JavaScript to update the state on the browser side. 1626 // Inject the JavaScript to update the state on the browser side.
1626 [self injectHTML5HistoryScriptWithHashChange:shouldDispatchHashchange 1627 [self injectHTML5HistoryScriptWithHashChange:shouldDispatchHashchange
1627 sameDocumentNavigation:sameDocumentNavigation]; 1628 sameDocumentNavigation:sameDocumentNavigation];
1628 } 1629 }
1629 1630
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
1905 } else { 1906 } else {
1906 // Clear transient view before making any changes to history and navigation 1907 // Clear transient view before making any changes to history and navigation
1907 // manager. TODO(stuartmorgan): Drive Transient Item clearing from 1908 // manager. TODO(stuartmorgan): Drive Transient Item clearing from
1908 // navigation system, rather than from WebController. 1909 // navigation system, rather than from WebController.
1909 [self clearTransientContentView]; 1910 [self clearTransientContentView];
1910 1911
1911 // TODO(stuartmorgan): Why doesn't recordStateInHistory get called for 1912 // TODO(stuartmorgan): Why doesn't recordStateInHistory get called for
1912 // forward/back transitions? 1913 // forward/back transitions?
1913 [self recordStateInHistory]; 1914 [self recordStateInHistory];
1914 1915
1915 CRWSessionController* history =
1916 _webStateImpl->GetNavigationManagerImpl().GetSessionController();
1917 if (!self.currentSessionEntry) 1916 if (!self.currentSessionEntry)
1918 initialNavigation = YES; 1917 initialNavigation = YES;
1919 [history addPendingItem:navUrl 1918
1920 referrer:params.referrer 1919 web::NavigationInitiationType navigationInitiationType =
1921 transition:transition 1920 params.is_renderer_initiated
1922 rendererInitiated:params.is_renderer_initiated]; 1921 ? web::NavigationInitiationType::RENDERER_INITIATED
1922 : web::NavigationInitiationType::USER_INITIATED;
1923 self.navigationManagerImpl->AddPendingItem(
1924 navUrl, params.referrer, transition, navigationInitiationType);
1925
1923 web::NavigationItemImpl* addedItem = 1926 web::NavigationItemImpl* addedItem =
1924 [self currentSessionEntry].navigationItemImpl; 1927 [self currentSessionEntry].navigationItemImpl;
1925 DCHECK(addedItem); 1928 DCHECK(addedItem);
1926 if (params.extra_headers) 1929 if (params.extra_headers)
1927 addedItem->AddHttpRequestHeaders(params.extra_headers); 1930 addedItem->AddHttpRequestHeaders(params.extra_headers);
1928 if (params.post_data) { 1931 if (params.post_data) {
1929 DCHECK([addedItem->GetHttpRequestHeaders() objectForKey:@"Content-Type"]) 1932 DCHECK([addedItem->GetHttpRequestHeaders() objectForKey:@"Content-Type"])
1930 << "Post data should have an associated content type"; 1933 << "Post data should have an associated content type";
1931 addedItem->SetPostData(params.post_data); 1934 addedItem->SetPostData(params.post_data);
1932 addedItem->SetShouldSkipRepostFormConfirmation(true); 1935 addedItem->SetShouldSkipRepostFormConfirmation(true);
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
2051 } else if (_requireReloadOnDisplay && _webView) { 2054 } else if (_requireReloadOnDisplay && _webView) {
2052 _requireReloadOnDisplay = NO; 2055 _requireReloadOnDisplay = NO;
2053 [self addPlaceholderOverlay]; 2056 [self addPlaceholderOverlay];
2054 [self loadCurrentURL]; 2057 [self loadCurrentURL];
2055 } 2058 }
2056 } 2059 }
2057 2060
2058 - (BOOL)shouldReload:(const GURL&)destinationURL 2061 - (BOOL)shouldReload:(const GURL&)destinationURL
2059 transition:(ui::PageTransition)transition { 2062 transition:(ui::PageTransition)transition {
2060 // Do a reload if the user hits enter in the address bar or re-types a URL. 2063 // Do a reload if the user hits enter in the address bar or re-types a URL.
2061 web::NavigationItem* item = 2064 web::NavigationItem* item = self.navigationManagerImpl->GetVisibleItem();
2062 _webStateImpl->GetNavigationManagerImpl().GetVisibleItem();
2063 return (transition & ui::PAGE_TRANSITION_FROM_ADDRESS_BAR) && item && 2065 return (transition & ui::PAGE_TRANSITION_FROM_ADDRESS_BAR) && item &&
2064 (destinationURL == item->GetURL() || 2066 (destinationURL == item->GetURL() ||
2065 destinationURL == item->GetOriginalRequestURL()); 2067 destinationURL == item->GetOriginalRequestURL());
2066 } 2068 }
2067 2069
2068 // Reload either the web view or the native content depending on which is 2070 // Reload either the web view or the native content depending on which is
2069 // displayed. 2071 // displayed.
2070 - (void)reloadInternal { 2072 - (void)reloadInternal {
2071 // Clear last user interaction. 2073 // Clear last user interaction.
2072 // TODO(crbug.com/546337): Move to after the load commits, in the subclass 2074 // TODO(crbug.com/546337): Move to after the load commits, in the subclass
2073 // implementation. This will be inaccurate if the reload fails or is 2075 // implementation. This will be inaccurate if the reload fails or is
2074 // cancelled. 2076 // cancelled.
2075 _lastUserInteraction.reset(); 2077 _lastUserInteraction.reset();
2076 base::RecordAction(UserMetricsAction("Reload")); 2078 base::RecordAction(UserMetricsAction("Reload"));
2077 if (_webView) { 2079 if (_webView) {
2078 web::NavigationItem* transientItem = 2080 web::NavigationItem* transientItem =
2079 _webStateImpl->GetNavigationManagerImpl().GetTransientItem(); 2081 self.navigationManagerImpl->GetTransientItem();
2080 if (transientItem) { 2082 if (transientItem) {
2081 // If there's a transient item, a reload is considered a new navigation to 2083 // If there's a transient item, a reload is considered a new navigation to
2082 // the transient item's URL (as on other platforms). 2084 // the transient item's URL (as on other platforms).
2083 NavigationManager::WebLoadParams reloadParams(transientItem->GetURL()); 2085 NavigationManager::WebLoadParams reloadParams(transientItem->GetURL());
2084 reloadParams.transition_type = ui::PAGE_TRANSITION_RELOAD; 2086 reloadParams.transition_type = ui::PAGE_TRANSITION_RELOAD;
2085 reloadParams.extra_headers.reset( 2087 reloadParams.extra_headers.reset(
2086 [transientItem->GetHttpRequestHeaders() copy]); 2088 [transientItem->GetHttpRequestHeaders() copy]);
2087 [self loadWithParams:reloadParams]; 2089 [self loadWithParams:reloadParams];
2088 } else { 2090 } else {
2089 // As with back and forward navigation, load the URL manually instead of 2091 // As with back and forward navigation, load the URL manually instead of
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
2263 2265
2264 - (void)goDelta:(int)delta { 2266 - (void)goDelta:(int)delta {
2265 if (_isBeingDestroyed) 2267 if (_isBeingDestroyed)
2266 return; 2268 return;
2267 2269
2268 if (delta == 0) { 2270 if (delta == 0) {
2269 [self reload]; 2271 [self reload];
2270 return; 2272 return;
2271 } 2273 }
2272 2274
2273 web::NavigationManagerImpl& navigationManager = 2275 if (self.navigationManagerImpl->CanGoToOffset(delta)) {
2274 _webStateImpl->GetNavigationManagerImpl(); 2276 NSInteger index = self.navigationManagerImpl->GetIndexForOffset(delta);
2275 if (navigationManager.CanGoToOffset(delta)) { 2277 [self goToItemAtIndex:index];
2276 [self goToItemAtIndex:navigationManager.GetIndexForOffset(delta)];
2277 } 2278 }
2278 } 2279 }
2279 2280
2280 - (void)finishHistoryNavigationFromEntry:(CRWSessionEntry*)fromEntry { 2281 - (void)finishHistoryNavigationFromEntry:(CRWSessionEntry*)fromEntry {
2281 [self webWillFinishHistoryNavigationFromEntry:fromEntry]; 2282 [self webWillFinishHistoryNavigationFromEntry:fromEntry];
2282 2283
2283 // Only load the new URL if it has a different document than |fromEntry| to 2284 // Only load the new URL if it has a different document than |fromEntry| to
2284 // prevent extra page loads from NavigationItems created by hash changes or 2285 // prevent extra page loads from NavigationItems created by hash changes or
2285 // calls to window.history.pushState(). 2286 // calls to window.history.pushState().
2286 BOOL shouldLoadURL = 2287 BOOL shouldLoadURL = ![self.sessionController
2287 ![_webStateImpl->GetNavigationManagerImpl().GetSessionController() 2288 isSameDocumentNavigationBetweenItem:fromEntry.navigationItem
2288 isSameDocumentNavigationBetweenItem:fromEntry.navigationItem 2289 andItem:self.currentNavItem];
2289 andItem:self.currentNavItem];
2290 web::NavigationItemImpl* currentItem = 2290 web::NavigationItemImpl* currentItem =
2291 self.currentSessionEntry.navigationItemImpl; 2291 self.currentSessionEntry.navigationItemImpl;
2292 GURL endURL = [self URLForHistoryNavigationFromItem:fromEntry.navigationItem 2292 GURL endURL = [self URLForHistoryNavigationFromItem:fromEntry.navigationItem
2293 toItem:currentItem]; 2293 toItem:currentItem];
2294 if (shouldLoadURL) { 2294 if (shouldLoadURL) {
2295 ui::PageTransition transition = ui::PageTransitionFromInt( 2295 ui::PageTransition transition = ui::PageTransitionFromInt(
2296 ui::PAGE_TRANSITION_RELOAD | ui::PAGE_TRANSITION_FORWARD_BACK); 2296 ui::PAGE_TRANSITION_RELOAD | ui::PAGE_TRANSITION_FORWARD_BACK);
2297 2297
2298 NavigationManager::WebLoadParams params(endURL); 2298 NavigationManager::WebLoadParams params(endURL);
2299 if (currentItem) { 2299 if (currentItem) {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
2348 return _jsInjectionReceiver; 2348 return _jsInjectionReceiver;
2349 } 2349 }
2350 2350
2351 - (BOOL)shouldClosePageOnNativeApplicationLoad { 2351 - (BOOL)shouldClosePageOnNativeApplicationLoad {
2352 // The page should be closed if it was initiated by the DOM and there has been 2352 // The page should be closed if it was initiated by the DOM and there has been
2353 // no user interaction with the page since the web view was created, or if 2353 // no user interaction with the page since the web view was created, or if
2354 // the page has no navigation items, as occurs when an App Store link is 2354 // the page has no navigation items, as occurs when an App Store link is
2355 // opened from another application. 2355 // opened from another application.
2356 BOOL rendererInitiatedWithoutInteraction = 2356 BOOL rendererInitiatedWithoutInteraction =
2357 self.sessionController.openedByDOM && !_userInteractedWithWebController; 2357 self.sessionController.openedByDOM && !_userInteractedWithWebController;
2358 BOOL noNavigationItems = 2358 BOOL noNavigationItems = !(self.navigationManagerImpl->GetItemCount());
2359 !_webStateImpl->GetNavigationManagerImpl().GetItemCount();
2360 return rendererInitiatedWithoutInteraction || noNavigationItems; 2359 return rendererInitiatedWithoutInteraction || noNavigationItems;
2361 } 2360 }
2362 2361
2363 - (BOOL)useDesktopUserAgent { 2362 - (BOOL)useDesktopUserAgent {
2364 web::NavigationItem* item = [self currentNavItem]; 2363 web::NavigationItem* item = [self currentNavItem];
2365 return item && item->IsOverridingUserAgent(); 2364 return item && item->IsOverridingUserAgent();
2366 } 2365 }
2367 2366
2368 - (web::MojoFacade*)mojoFacade { 2367 - (web::MojoFacade*)mojoFacade {
2369 if (!_mojoFacade) { 2368 if (!_mojoFacade) {
(...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after
2993 DLOG(WARNING) << "JS message parameter not found: pageUrl or baseUrl"; 2992 DLOG(WARNING) << "JS message parameter not found: pageUrl or baseUrl";
2994 return NO; 2993 return NO;
2995 } 2994 }
2996 GURL replaceURL = web::history_state_util::GetHistoryStateChangeUrl( 2995 GURL replaceURL = web::history_state_util::GetHistoryStateChangeUrl(
2997 [self currentURL], GURL(baseURL), pageURL); 2996 [self currentURL], GURL(baseURL), pageURL);
2998 // UIWebView seems to choke on unicode characters that haven't been 2997 // UIWebView seems to choke on unicode characters that haven't been
2999 // escaped; escape the URL now so the expected load URL is correct. 2998 // escaped; escape the URL now so the expected load URL is correct.
3000 replaceURL = URLEscapedForHistory(replaceURL); 2999 replaceURL = URLEscapedForHistory(replaceURL);
3001 if (!replaceURL.is_valid()) 3000 if (!replaceURL.is_valid())
3002 return YES; 3001 return YES;
3003 const NavigationManagerImpl& navigationManager = 3002
3004 _webStateImpl->GetNavigationManagerImpl();
3005 web::NavigationItem* navItem = [self currentNavItem]; 3003 web::NavigationItem* navItem = [self currentNavItem];
3006 // ReplaceState happened before first navigation entry or called right 3004 // ReplaceState happened before first navigation entry or called right
3007 // after window.open when the url is empty/not valid. 3005 // after window.open when the url is empty/not valid.
3008 if (!navItem || 3006 if (!navItem || (self.navigationManagerImpl->GetItemCount() <= 1 &&
3009 (navigationManager.GetItemCount() <= 1 && navItem->GetURL().is_empty())) 3007 navItem->GetURL().is_empty()))
3010 return YES; 3008 return YES;
3011 if (!web::history_state_util::IsHistoryStateChangeValid( 3009 if (!web::history_state_util::IsHistoryStateChangeValid(
3012 [self currentNavItem]->GetURL(), replaceURL)) { 3010 [self currentNavItem]->GetURL(), replaceURL)) {
3013 // If the current session entry URL origin still doesn't match 3011 // If the current session entry URL origin still doesn't match
3014 // replaceURL's origin, ignore the replaceState. This can happen if a 3012 // replaceURL's origin, ignore the replaceState. This can happen if a
3015 // new URL is loaded just before the replaceState. 3013 // new URL is loaded just before the replaceState.
3016 return YES; 3014 return YES;
3017 } 3015 }
3018 std::string stateObjectJSON; 3016 std::string stateObjectJSON;
3019 if (!message->GetString("stateObject", &stateObjectJSON)) { 3017 if (!message->GetString("stateObject", &stateObjectJSON)) {
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
3175 GURL requestURL = net::GURLWithNSURL(request.URL); 3173 GURL requestURL = net::GURLWithNSURL(request.URL);
3176 3174
3177 // External application launcher needs |isNavigationTypeLinkActivated| to 3175 // External application launcher needs |isNavigationTypeLinkActivated| to
3178 // decide if the user intended to open the application by clicking on a link. 3176 // decide if the user intended to open the application by clicking on a link.
3179 BOOL isNavigationTypeLinkActivated = 3177 BOOL isNavigationTypeLinkActivated =
3180 action.navigationType == WKNavigationTypeLinkActivated; 3178 action.navigationType == WKNavigationTypeLinkActivated;
3181 3179
3182 // Check if the link navigation leads to a launch of an external app. 3180 // Check if the link navigation leads to a launch of an external app.
3183 // TODO(crbug.com/607780): Revise the logic of allowing external app launch 3181 // TODO(crbug.com/607780): Revise the logic of allowing external app launch
3184 // and move it to externalAppLauncher. 3182 // and move it to externalAppLauncher.
3185 BOOL isOpenInNewTabNavigation = 3183 BOOL isOpenInNewTabNavigation = !(self.navigationManagerImpl->GetItemCount());
3186 !_webStateImpl->GetNavigationManager()->GetItemCount();
3187 BOOL isPossibleLinkClick = [self isLinkNavigation:action.navigationType]; 3184 BOOL isPossibleLinkClick = [self isLinkNavigation:action.navigationType];
3188 if (isPossibleLinkClick || isOpenInNewTabNavigation || 3185 if (isPossibleLinkClick || isOpenInNewTabNavigation ||
3189 PageTransitionCoreTypeIs([self currentTransition], 3186 PageTransitionCoreTypeIs([self currentTransition],
3190 ui::PAGE_TRANSITION_AUTO_BOOKMARK)) { 3187 ui::PAGE_TRANSITION_AUTO_BOOKMARK)) {
3191 web::NavigationItem* item = [self currentNavItem]; 3188 web::NavigationItem* item = [self currentNavItem];
3192 const GURL currentNavigationURL = 3189 const GURL currentNavigationURL =
3193 item ? item->GetVirtualURL() : GURL::EmptyGURL(); 3190 item ? item->GetVirtualURL() : GURL::EmptyGURL();
3194 // Check If the URL is handled by a native app. 3191 // Check If the URL is handled by a native app.
3195 if ([self urlTriggersNativeAppLaunch:requestURL 3192 if ([self urlTriggersNativeAppLaunch:requestURL
3196 sourceURL:currentNavigationURL 3193 sourceURL:currentNavigationURL
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after
3647 if (_webView) { 3644 if (_webView) {
3648 [[self view] addSubview:_webView]; 3645 [[self view] addSubview:_webView];
3649 } 3646 }
3650 } 3647 }
3651 } 3648 }
3652 3649
3653 #pragma mark - 3650 #pragma mark -
3654 #pragma mark Session Information 3651 #pragma mark Session Information
3655 3652
3656 - (CRWSessionController*)sessionController { 3653 - (CRWSessionController*)sessionController {
3657 return _webStateImpl 3654 NavigationManagerImpl* navigationManager = self.navigationManagerImpl;
3658 ? _webStateImpl->GetNavigationManagerImpl().GetSessionController() 3655 return navigationManager ? navigationManager->GetSessionController() : nil;
3659 : nil; 3656 }
3657
3658 - (NavigationManagerImpl*)navigationManagerImpl {
3659 return _webStateImpl ? &(_webStateImpl->GetNavigationManagerImpl()) : nil;
3660 } 3660 }
3661 3661
3662 - (CRWSessionEntry*)currentSessionEntry { 3662 - (CRWSessionEntry*)currentSessionEntry {
3663 return [[self sessionController] currentEntry]; 3663 return [[self sessionController] currentEntry];
3664 } 3664 }
3665 3665
3666 - (web::NavigationItem*)currentNavItem { 3666 - (web::NavigationItem*)currentNavItem {
3667 // This goes through the legacy Session* interface rather than Navigation* 3667 // This goes through the legacy Session* interface rather than Navigation*
3668 // because it is itself a legacy method that should not exist, and this 3668 // because it is itself a legacy method that should not exist, and this
3669 // avoids needing to add a GetActiveItem to NavigationManager. If/when this 3669 // avoids needing to add a GetActiveItem to NavigationManager. If/when this
(...skipping 1645 matching lines...) Expand 10 before | Expand all | Expand 10 after
5315 - (void)simulateLoadRequestWithURL:(const GURL&)URL { 5315 - (void)simulateLoadRequestWithURL:(const GURL&)URL {
5316 _lastRegisteredRequestURL = URL; 5316 _lastRegisteredRequestURL = URL;
5317 _loadPhase = web::LOAD_REQUESTED; 5317 _loadPhase = web::LOAD_REQUESTED;
5318 } 5318 }
5319 5319
5320 - (NSString*)refererFromNavigationAction:(WKNavigationAction*)action { 5320 - (NSString*)refererFromNavigationAction:(WKNavigationAction*)action {
5321 return [action.request valueForHTTPHeaderField:@"Referer"]; 5321 return [action.request valueForHTTPHeaderField:@"Referer"];
5322 } 5322 }
5323 5323
5324 @end 5324 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698