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

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

Powered by Google App Engine
This is Rietveld 408576698