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

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

Powered by Google App Engine
This is Rietveld 408576698