Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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; | |
|
kkhorimoto
2017/02/17 02:26:37
Optional NIT: as long as we're defining a convenie
liaoyuke
2017/02/17 17:44:30
Good point! That does make things more compact.
| |
| 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 Loading... | |
| 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 Loading... | |
| 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::NavigationInitiationType::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 Loading... | |
| 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 Loading... | |
| 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 web::NavigationInitiationType navigationInitiationType = |
| 1921 transition:transition | 1921 params.is_renderer_initiated |
| 1922 rendererInitiated:params.is_renderer_initiated]; | 1922 ? web::NavigationInitiationType::RENDERER_INITIATED |
| 1923 : web::NavigationInitiationType::USER_INITIATED; | |
| 1924 [self navigationManagerImpl]->AddPendingItem( | |
| 1925 navUrl, params.referrer, transition, navigationInitiationType); | |
| 1926 | |
| 1923 web::NavigationItemImpl* addedItem = | 1927 web::NavigationItemImpl* addedItem = |
| 1924 [self currentSessionEntry].navigationItemImpl; | 1928 [self currentSessionEntry].navigationItemImpl; |
| 1925 DCHECK(addedItem); | 1929 DCHECK(addedItem); |
| 1926 if (params.extra_headers) | 1930 if (params.extra_headers) |
| 1927 addedItem->AddHttpRequestHeaders(params.extra_headers); | 1931 addedItem->AddHttpRequestHeaders(params.extra_headers); |
| 1928 if (params.post_data) { | 1932 if (params.post_data) { |
| 1929 DCHECK([addedItem->GetHttpRequestHeaders() objectForKey:@"Content-Type"]) | 1933 DCHECK([addedItem->GetHttpRequestHeaders() objectForKey:@"Content-Type"]) |
| 1930 << "Post data should have an associated content type"; | 1934 << "Post data should have an associated content type"; |
| 1931 addedItem->SetPostData(params.post_data); | 1935 addedItem->SetPostData(params.post_data); |
| 1932 addedItem->SetShouldSkipRepostFormConfirmation(true); | 1936 addedItem->SetShouldSkipRepostFormConfirmation(true); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2051 } else if (_requireReloadOnDisplay && _webView) { | 2055 } else if (_requireReloadOnDisplay && _webView) { |
| 2052 _requireReloadOnDisplay = NO; | 2056 _requireReloadOnDisplay = NO; |
| 2053 [self addPlaceholderOverlay]; | 2057 [self addPlaceholderOverlay]; |
| 2054 [self loadCurrentURL]; | 2058 [self loadCurrentURL]; |
| 2055 } | 2059 } |
| 2056 } | 2060 } |
| 2057 | 2061 |
| 2058 - (BOOL)shouldReload:(const GURL&)destinationURL | 2062 - (BOOL)shouldReload:(const GURL&)destinationURL |
| 2059 transition:(ui::PageTransition)transition { | 2063 transition:(ui::PageTransition)transition { |
| 2060 // Do a reload if the user hits enter in the address bar or re-types a URL. | 2064 // Do a reload if the user hits enter in the address bar or re-types a URL. |
| 2061 web::NavigationItem* item = | 2065 web::NavigationItem* item = [self navigationManagerImpl]->GetVisibleItem(); |
| 2062 _webStateImpl->GetNavigationManagerImpl().GetVisibleItem(); | |
| 2063 return (transition & ui::PAGE_TRANSITION_FROM_ADDRESS_BAR) && item && | 2066 return (transition & ui::PAGE_TRANSITION_FROM_ADDRESS_BAR) && item && |
| 2064 (destinationURL == item->GetURL() || | 2067 (destinationURL == item->GetURL() || |
| 2065 destinationURL == item->GetOriginalRequestURL()); | 2068 destinationURL == item->GetOriginalRequestURL()); |
| 2066 } | 2069 } |
| 2067 | 2070 |
| 2068 // Reload either the web view or the native content depending on which is | 2071 // Reload either the web view or the native content depending on which is |
| 2069 // displayed. | 2072 // displayed. |
| 2070 - (void)reloadInternal { | 2073 - (void)reloadInternal { |
| 2071 // Clear last user interaction. | 2074 // Clear last user interaction. |
| 2072 // TODO(crbug.com/546337): Move to after the load commits, in the subclass | 2075 // 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 | 2076 // implementation. This will be inaccurate if the reload fails or is |
| 2074 // cancelled. | 2077 // cancelled. |
| 2075 _lastUserInteraction.reset(); | 2078 _lastUserInteraction.reset(); |
| 2076 base::RecordAction(UserMetricsAction("Reload")); | 2079 base::RecordAction(UserMetricsAction("Reload")); |
| 2077 if (_webView) { | 2080 if (_webView) { |
| 2078 web::NavigationItem* transientItem = | 2081 web::NavigationItem* transientItem = |
| 2079 _webStateImpl->GetNavigationManagerImpl().GetTransientItem(); | 2082 [self navigationManagerImpl]->GetTransientItem(); |
| 2080 if (transientItem) { | 2083 if (transientItem) { |
| 2081 // If there's a transient item, a reload is considered a new navigation to | 2084 // If there's a transient item, a reload is considered a new navigation to |
| 2082 // the transient item's URL (as on other platforms). | 2085 // the transient item's URL (as on other platforms). |
| 2083 NavigationManager::WebLoadParams reloadParams(transientItem->GetURL()); | 2086 NavigationManager::WebLoadParams reloadParams(transientItem->GetURL()); |
| 2084 reloadParams.transition_type = ui::PAGE_TRANSITION_RELOAD; | 2087 reloadParams.transition_type = ui::PAGE_TRANSITION_RELOAD; |
| 2085 reloadParams.extra_headers.reset( | 2088 reloadParams.extra_headers.reset( |
| 2086 [transientItem->GetHttpRequestHeaders() copy]); | 2089 [transientItem->GetHttpRequestHeaders() copy]); |
| 2087 [self loadWithParams:reloadParams]; | 2090 [self loadWithParams:reloadParams]; |
| 2088 } else { | 2091 } else { |
| 2089 // As with back and forward navigation, load the URL manually instead of | 2092 // As with back and forward navigation, load the URL manually instead of |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2263 | 2266 |
| 2264 - (void)goDelta:(int)delta { | 2267 - (void)goDelta:(int)delta { |
| 2265 if (_isBeingDestroyed) | 2268 if (_isBeingDestroyed) |
| 2266 return; | 2269 return; |
| 2267 | 2270 |
| 2268 if (delta == 0) { | 2271 if (delta == 0) { |
| 2269 [self reload]; | 2272 [self reload]; |
| 2270 return; | 2273 return; |
| 2271 } | 2274 } |
| 2272 | 2275 |
| 2273 web::NavigationManagerImpl& navigationManager = | 2276 if ([self navigationManagerImpl]->CanGoToOffset(delta)) { |
| 2274 _webStateImpl->GetNavigationManagerImpl(); | 2277 NSInteger index = [self navigationManagerImpl]->GetIndexForOffset(delta); |
| 2275 if (navigationManager.CanGoToOffset(delta)) { | 2278 [self goToItemAtIndex:index]; |
| 2276 [self goToItemAtIndex:navigationManager.GetIndexForOffset(delta)]; | |
| 2277 } | 2279 } |
| 2278 } | 2280 } |
| 2279 | 2281 |
| 2280 - (void)finishHistoryNavigationFromEntry:(CRWSessionEntry*)fromEntry { | 2282 - (void)finishHistoryNavigationFromEntry:(CRWSessionEntry*)fromEntry { |
| 2281 [self webWillFinishHistoryNavigationFromEntry:fromEntry]; | 2283 [self webWillFinishHistoryNavigationFromEntry:fromEntry]; |
| 2282 | 2284 |
| 2283 // Only load the new URL if it has a different document than |fromEntry| to | 2285 // 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 | 2286 // prevent extra page loads from NavigationItems created by hash changes or |
| 2285 // calls to window.history.pushState(). | 2287 // calls to window.history.pushState(). |
| 2286 BOOL shouldLoadURL = | 2288 BOOL shouldLoadURL = ![self.sessionController |
| 2287 ![_webStateImpl->GetNavigationManagerImpl().GetSessionController() | 2289 isSameDocumentNavigationBetweenItem:fromEntry.navigationItem |
| 2288 isSameDocumentNavigationBetweenItem:fromEntry.navigationItem | 2290 andItem:self.currentNavItem]; |
| 2289 andItem:self.currentNavItem]; | |
| 2290 web::NavigationItemImpl* currentItem = | 2291 web::NavigationItemImpl* currentItem = |
| 2291 self.currentSessionEntry.navigationItemImpl; | 2292 self.currentSessionEntry.navigationItemImpl; |
| 2292 GURL endURL = [self URLForHistoryNavigationFromItem:fromEntry.navigationItem | 2293 GURL endURL = [self URLForHistoryNavigationFromItem:fromEntry.navigationItem |
| 2293 toItem:currentItem]; | 2294 toItem:currentItem]; |
| 2294 if (shouldLoadURL) { | 2295 if (shouldLoadURL) { |
| 2295 ui::PageTransition transition = ui::PageTransitionFromInt( | 2296 ui::PageTransition transition = ui::PageTransitionFromInt( |
| 2296 ui::PAGE_TRANSITION_RELOAD | ui::PAGE_TRANSITION_FORWARD_BACK); | 2297 ui::PAGE_TRANSITION_RELOAD | ui::PAGE_TRANSITION_FORWARD_BACK); |
| 2297 | 2298 |
| 2298 NavigationManager::WebLoadParams params(endURL); | 2299 NavigationManager::WebLoadParams params(endURL); |
| 2299 if (currentItem) { | 2300 if (currentItem) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2348 return _jsInjectionReceiver; | 2349 return _jsInjectionReceiver; |
| 2349 } | 2350 } |
| 2350 | 2351 |
| 2351 - (BOOL)shouldClosePageOnNativeApplicationLoad { | 2352 - (BOOL)shouldClosePageOnNativeApplicationLoad { |
| 2352 // The page should be closed if it was initiated by the DOM and there has been | 2353 // 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 | 2354 // 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 | 2355 // the page has no navigation items, as occurs when an App Store link is |
| 2355 // opened from another application. | 2356 // opened from another application. |
| 2356 BOOL rendererInitiatedWithoutInteraction = | 2357 BOOL rendererInitiatedWithoutInteraction = |
| 2357 self.sessionController.openedByDOM && !_userInteractedWithWebController; | 2358 self.sessionController.openedByDOM && !_userInteractedWithWebController; |
| 2358 BOOL noNavigationItems = | 2359 BOOL noNavigationItems = ![self navigationManagerImpl]->GetItemCount(); |
| 2359 !_webStateImpl->GetNavigationManagerImpl().GetItemCount(); | |
| 2360 return rendererInitiatedWithoutInteraction || noNavigationItems; | 2360 return rendererInitiatedWithoutInteraction || noNavigationItems; |
| 2361 } | 2361 } |
| 2362 | 2362 |
| 2363 - (BOOL)useDesktopUserAgent { | 2363 - (BOOL)useDesktopUserAgent { |
| 2364 web::NavigationItem* item = [self currentNavItem]; | 2364 web::NavigationItem* item = [self currentNavItem]; |
| 2365 return item && item->IsOverridingUserAgent(); | 2365 return item && item->IsOverridingUserAgent(); |
| 2366 } | 2366 } |
| 2367 | 2367 |
| 2368 - (web::MojoFacade*)mojoFacade { | 2368 - (web::MojoFacade*)mojoFacade { |
| 2369 if (!_mojoFacade) { | 2369 if (!_mojoFacade) { |
| (...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2993 DLOG(WARNING) << "JS message parameter not found: pageUrl or baseUrl"; | 2993 DLOG(WARNING) << "JS message parameter not found: pageUrl or baseUrl"; |
| 2994 return NO; | 2994 return NO; |
| 2995 } | 2995 } |
| 2996 GURL replaceURL = web::history_state_util::GetHistoryStateChangeUrl( | 2996 GURL replaceURL = web::history_state_util::GetHistoryStateChangeUrl( |
| 2997 [self currentURL], GURL(baseURL), pageURL); | 2997 [self currentURL], GURL(baseURL), pageURL); |
| 2998 // UIWebView seems to choke on unicode characters that haven't been | 2998 // UIWebView seems to choke on unicode characters that haven't been |
| 2999 // escaped; escape the URL now so the expected load URL is correct. | 2999 // escaped; escape the URL now so the expected load URL is correct. |
| 3000 replaceURL = URLEscapedForHistory(replaceURL); | 3000 replaceURL = URLEscapedForHistory(replaceURL); |
| 3001 if (!replaceURL.is_valid()) | 3001 if (!replaceURL.is_valid()) |
| 3002 return YES; | 3002 return YES; |
| 3003 const NavigationManagerImpl& navigationManager = | 3003 |
| 3004 _webStateImpl->GetNavigationManagerImpl(); | |
| 3005 web::NavigationItem* navItem = [self currentNavItem]; | 3004 web::NavigationItem* navItem = [self currentNavItem]; |
| 3006 // ReplaceState happened before first navigation entry or called right | 3005 // ReplaceState happened before first navigation entry or called right |
| 3007 // after window.open when the url is empty/not valid. | 3006 // after window.open when the url is empty/not valid. |
| 3008 if (!navItem || | 3007 if (!navItem || ([self navigationManagerImpl]->GetItemCount() <= 1 && |
| 3009 (navigationManager.GetItemCount() <= 1 && navItem->GetURL().is_empty())) | 3008 navItem->GetURL().is_empty())) |
| 3010 return YES; | 3009 return YES; |
| 3011 if (!web::history_state_util::IsHistoryStateChangeValid( | 3010 if (!web::history_state_util::IsHistoryStateChangeValid( |
| 3012 [self currentNavItem]->GetURL(), replaceURL)) { | 3011 [self currentNavItem]->GetURL(), replaceURL)) { |
| 3013 // If the current session entry URL origin still doesn't match | 3012 // If the current session entry URL origin still doesn't match |
| 3014 // replaceURL's origin, ignore the replaceState. This can happen if a | 3013 // replaceURL's origin, ignore the replaceState. This can happen if a |
| 3015 // new URL is loaded just before the replaceState. | 3014 // new URL is loaded just before the replaceState. |
| 3016 return YES; | 3015 return YES; |
| 3017 } | 3016 } |
| 3018 std::string stateObjectJSON; | 3017 std::string stateObjectJSON; |
| 3019 if (!message->GetString("stateObject", &stateObjectJSON)) { | 3018 if (!message->GetString("stateObject", &stateObjectJSON)) { |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3175 GURL requestURL = net::GURLWithNSURL(request.URL); | 3174 GURL requestURL = net::GURLWithNSURL(request.URL); |
| 3176 | 3175 |
| 3177 // External application launcher needs |isNavigationTypeLinkActivated| to | 3176 // External application launcher needs |isNavigationTypeLinkActivated| to |
| 3178 // decide if the user intended to open the application by clicking on a link. | 3177 // decide if the user intended to open the application by clicking on a link. |
| 3179 BOOL isNavigationTypeLinkActivated = | 3178 BOOL isNavigationTypeLinkActivated = |
| 3180 action.navigationType == WKNavigationTypeLinkActivated; | 3179 action.navigationType == WKNavigationTypeLinkActivated; |
| 3181 | 3180 |
| 3182 // Check if the link navigation leads to a launch of an external app. | 3181 // 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 | 3182 // TODO(crbug.com/607780): Revise the logic of allowing external app launch |
| 3184 // and move it to externalAppLauncher. | 3183 // and move it to externalAppLauncher. |
| 3185 BOOL isOpenInNewTabNavigation = | 3184 BOOL isOpenInNewTabNavigation = ![self navigationManagerImpl]->GetItemCount(); |
| 3186 !_webStateImpl->GetNavigationManager()->GetItemCount(); | |
| 3187 BOOL isPossibleLinkClick = [self isLinkNavigation:action.navigationType]; | 3185 BOOL isPossibleLinkClick = [self isLinkNavigation:action.navigationType]; |
| 3188 if (isPossibleLinkClick || isOpenInNewTabNavigation || | 3186 if (isPossibleLinkClick || isOpenInNewTabNavigation || |
| 3189 PageTransitionCoreTypeIs([self currentTransition], | 3187 PageTransitionCoreTypeIs([self currentTransition], |
| 3190 ui::PAGE_TRANSITION_AUTO_BOOKMARK)) { | 3188 ui::PAGE_TRANSITION_AUTO_BOOKMARK)) { |
| 3191 web::NavigationItem* item = [self currentNavItem]; | 3189 web::NavigationItem* item = [self currentNavItem]; |
| 3192 const GURL currentNavigationURL = | 3190 const GURL currentNavigationURL = |
| 3193 item ? item->GetVirtualURL() : GURL::EmptyGURL(); | 3191 item ? item->GetVirtualURL() : GURL::EmptyGURL(); |
| 3194 // Check If the URL is handled by a native app. | 3192 // Check If the URL is handled by a native app. |
| 3195 if ([self urlTriggersNativeAppLaunch:requestURL | 3193 if ([self urlTriggersNativeAppLaunch:requestURL |
| 3196 sourceURL:currentNavigationURL | 3194 sourceURL:currentNavigationURL |
| (...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3647 if (_webView) { | 3645 if (_webView) { |
| 3648 [[self view] addSubview:_webView]; | 3646 [[self view] addSubview:_webView]; |
| 3649 } | 3647 } |
| 3650 } | 3648 } |
| 3651 } | 3649 } |
| 3652 | 3650 |
| 3653 #pragma mark - | 3651 #pragma mark - |
| 3654 #pragma mark Session Information | 3652 #pragma mark Session Information |
| 3655 | 3653 |
| 3656 - (CRWSessionController*)sessionController { | 3654 - (CRWSessionController*)sessionController { |
| 3657 return _webStateImpl | 3655 NavigationManagerImpl* navigationManager = [self navigationManagerImpl]; |
| 3658 ? _webStateImpl->GetNavigationManagerImpl().GetSessionController() | 3656 return navigationManager ? navigationManager->GetSessionController() : nil; |
| 3659 : nil; | 3657 } |
| 3658 | |
| 3659 - (NavigationManagerImpl*)navigationManagerImpl { | |
| 3660 return _webStateImpl ? &(_webStateImpl->GetNavigationManagerImpl()) : nil; | |
| 3660 } | 3661 } |
| 3661 | 3662 |
| 3662 - (CRWSessionEntry*)currentSessionEntry { | 3663 - (CRWSessionEntry*)currentSessionEntry { |
| 3663 return [[self sessionController] currentEntry]; | 3664 return [[self sessionController] currentEntry]; |
| 3664 } | 3665 } |
| 3665 | 3666 |
| 3666 - (web::NavigationItem*)currentNavItem { | 3667 - (web::NavigationItem*)currentNavItem { |
| 3667 // This goes through the legacy Session* interface rather than Navigation* | 3668 // This goes through the legacy Session* interface rather than Navigation* |
| 3668 // because it is itself a legacy method that should not exist, and this | 3669 // 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 | 3670 // avoids needing to add a GetActiveItem to NavigationManager. If/when this |
| (...skipping 1645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5315 - (void)simulateLoadRequestWithURL:(const GURL&)URL { | 5316 - (void)simulateLoadRequestWithURL:(const GURL&)URL { |
| 5316 _lastRegisteredRequestURL = URL; | 5317 _lastRegisteredRequestURL = URL; |
| 5317 _loadPhase = web::LOAD_REQUESTED; | 5318 _loadPhase = web::LOAD_REQUESTED; |
| 5318 } | 5319 } |
| 5319 | 5320 |
| 5320 - (NSString*)refererFromNavigationAction:(WKNavigationAction*)action { | 5321 - (NSString*)refererFromNavigationAction:(WKNavigationAction*)action { |
| 5321 return [action.request valueForHTTPHeaderField:@"Referer"]; | 5322 return [action.request valueForHTTPHeaderField:@"Referer"]; |
| 5322 } | 5323 } |
| 5323 | 5324 |
| 5324 @end | 5325 @end |
| OLD | NEW |