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 1375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1386 [self executeJavaScript:@"__gCrWeb.getPageReferrerPolicy()" | 1386 [self executeJavaScript:@"__gCrWeb.getPageReferrerPolicy()" |
1387 completionHandler:^(id referrer, NSError* error) { | 1387 completionHandler:^(id referrer, NSError* error) { |
1388 DCHECK_NE(error.code, WKErrorJavaScriptExceptionOccurred); | 1388 DCHECK_NE(error.code, WKErrorJavaScriptExceptionOccurred); |
1389 responseHandler(base::mac::ObjCCast<NSString>(referrer)); | 1389 responseHandler(base::mac::ObjCCast<NSString>(referrer)); |
1390 }]; | 1390 }]; |
1391 } | 1391 } |
1392 | 1392 |
1393 - (void)pushStateWithPageURL:(const GURL&)pageURL | 1393 - (void)pushStateWithPageURL:(const GURL&)pageURL |
1394 stateObject:(NSString*)stateObject | 1394 stateObject:(NSString*)stateObject |
1395 transition:(ui::PageTransition)transition { | 1395 transition:(ui::PageTransition)transition { |
1396 [[self sessionController] pushNewEntryWithURL:pageURL | 1396 [[self sessionController] pushNewItemWithURL:pageURL |
1397 stateObject:stateObject | 1397 stateObject:stateObject |
1398 transition:transition]; | 1398 transition:transition]; |
1399 [self didUpdateHistoryStateWithPageURL:pageURL]; | 1399 [self didUpdateHistoryStateWithPageURL:pageURL]; |
1400 self.userInteractionRegistered = NO; | 1400 self.userInteractionRegistered = NO; |
1401 } | 1401 } |
1402 | 1402 |
1403 - (void)replaceStateWithPageURL:(const GURL&)pageUrl | 1403 - (void)replaceStateWithPageURL:(const GURL&)pageUrl |
1404 stateObject:(NSString*)stateObject { | 1404 stateObject:(NSString*)stateObject { |
1405 [[self sessionController] updateCurrentEntryWithURL:pageUrl | 1405 [[self sessionController] updateCurrentItemWithURL:pageUrl |
1406 stateObject:stateObject]; | 1406 stateObject:stateObject]; |
1407 [self didUpdateHistoryStateWithPageURL:pageUrl]; | 1407 [self didUpdateHistoryStateWithPageURL:pageUrl]; |
1408 } | 1408 } |
1409 | 1409 |
1410 - (void)setDocumentURL:(const GURL&)newURL { | 1410 - (void)setDocumentURL:(const GURL&)newURL { |
1411 if (newURL != _documentURL && newURL.is_valid()) { | 1411 if (newURL != _documentURL && newURL.is_valid()) { |
1412 _documentURL = newURL; | 1412 _documentURL = newURL; |
1413 _interactionRegisteredSinceLastURLChange = NO; | 1413 _interactionRegisteredSinceLastURLChange = NO; |
1414 } | 1414 } |
1415 } | 1415 } |
1416 | 1416 |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1587 if (!(transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK)) { | 1587 if (!(transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK)) { |
1588 // Record state of outgoing page. | 1588 // Record state of outgoing page. |
1589 [self recordStateInHistory]; | 1589 [self recordStateInHistory]; |
1590 } | 1590 } |
1591 | 1591 |
1592 [_delegate webWillAddPendingURL:requestURL transition:transition]; | 1592 [_delegate webWillAddPendingURL:requestURL transition:transition]; |
1593 // Add or update pending url. | 1593 // Add or update pending url. |
1594 if (_webStateImpl->GetNavigationManagerImpl().GetPendingItem()) { | 1594 if (_webStateImpl->GetNavigationManagerImpl().GetPendingItem()) { |
1595 // Update the existing pending entry. | 1595 // Update the existing pending entry. |
1596 // Typically on PAGE_TRANSITION_CLIENT_REDIRECT. | 1596 // Typically on PAGE_TRANSITION_CLIENT_REDIRECT. |
1597 [[self sessionController] updatePendingEntry:requestURL]; | 1597 [[self sessionController] updatePendingItem:requestURL]; |
1598 } else { | 1598 } else { |
1599 // A new session history entry needs to be created. | 1599 // A new session history entry needs to be created. |
1600 [[self sessionController] addPendingEntry:requestURL | 1600 [[self sessionController] addPendingItem:requestURL |
1601 referrer:referrer | 1601 referrer:referrer |
1602 transition:transition | 1602 transition:transition |
1603 rendererInitiated:YES]; | 1603 rendererInitiated:YES]; |
1604 } | 1604 } |
1605 _webStateImpl->SetIsLoading(true); | 1605 _webStateImpl->SetIsLoading(true); |
1606 _webStateImpl->OnProvisionalNavigationStarted(requestURL); | 1606 _webStateImpl->OnProvisionalNavigationStarted(requestURL); |
1607 } | 1607 } |
1608 | 1608 |
1609 - (void)updateHTML5HistoryState { | 1609 - (void)updateHTML5HistoryState { |
1610 web::NavigationItemImpl* currentItem = | 1610 web::NavigationItemImpl* currentItem = |
1611 static_cast<web::NavigationItemImpl*>([self currentNavItem]); | 1611 static_cast<web::NavigationItemImpl*>([self currentNavItem]); |
1612 if (!currentItem) | 1612 if (!currentItem) |
1613 return; | 1613 return; |
1614 | 1614 |
1615 // Same-document navigations must trigger a popState event. | 1615 // Same-document navigations must trigger a popState event. |
1616 CRWSessionController* sessionController = self.sessionController; | 1616 CRWSessionController* sessionController = self.sessionController; |
1617 BOOL sameDocumentNavigation = [sessionController | 1617 BOOL sameDocumentNavigation = [sessionController |
1618 isSameDocumentNavigationBetweenEntry:sessionController.currentEntry | 1618 isSameDocumentNavigationBetweenItem:sessionController.currentItem |
1619 andEntry:sessionController.previousEntry]; | 1619 andItem:sessionController.previousItem]; |
1620 // WKWebView doesn't send hashchange events for same-document non-BFLI | 1620 // WKWebView doesn't send hashchange events for same-document non-BFLI |
1621 // navigations, so one must be dispatched manually for hash change same- | 1621 // navigations, so one must be dispatched manually for hash change same- |
1622 // document navigations. | 1622 // document navigations. |
1623 web::NavigationItem* previousItem = | 1623 web::NavigationItem* previousItem = |
1624 self.sessionController.previousEntry.navigationItem; | 1624 self.sessionController.previousEntry.navigationItem; |
1625 const GURL URL = currentItem->GetURL(); | 1625 const GURL URL = currentItem->GetURL(); |
1626 const GURL oldURL = previousItem ? previousItem->GetURL() : GURL(); | 1626 const GURL oldURL = previousItem ? previousItem->GetURL() : GURL(); |
1627 BOOL shouldDispatchHashchange = sameDocumentNavigation && previousItem && | 1627 BOOL shouldDispatchHashchange = sameDocumentNavigation && previousItem && |
1628 (web::GURLByRemovingRefFromGURL(URL) == | 1628 (web::GURLByRemovingRefFromGURL(URL) == |
1629 web::GURLByRemovingRefFromGURL(oldURL)); | 1629 web::GURLByRemovingRefFromGURL(oldURL)); |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1903 - (void)loadWithParams:(const NavigationManager::WebLoadParams&)originalParams { | 1903 - (void)loadWithParams:(const NavigationManager::WebLoadParams&)originalParams { |
1904 // Make a copy of |params|, as some of the delegate methods may modify it. | 1904 // Make a copy of |params|, as some of the delegate methods may modify it. |
1905 NavigationManager::WebLoadParams params(originalParams); | 1905 NavigationManager::WebLoadParams params(originalParams); |
1906 | 1906 |
1907 // Initiating a navigation from the UI, record the current page state before | 1907 // Initiating a navigation from the UI, record the current page state before |
1908 // the new page loads. Don't record for back/forward, as the current entry | 1908 // the new page loads. Don't record for back/forward, as the current entry |
1909 // has already been moved to the next entry in the history. Do, however, | 1909 // has already been moved to the next entry in the history. Do, however, |
1910 // record it for general reload. | 1910 // record it for general reload. |
1911 // TODO(jimblackler): consider a single unified call to record state whenever | 1911 // TODO(jimblackler): consider a single unified call to record state whenever |
1912 // the page is about to be changed. This cannot currently be done after | 1912 // the page is about to be changed. This cannot currently be done after |
1913 // addPendingEntry is called. | 1913 // addPendingItem is called. |
1914 | 1914 |
1915 [_delegate webWillInitiateLoadWithParams:params]; | 1915 [_delegate webWillInitiateLoadWithParams:params]; |
1916 | 1916 |
1917 GURL navUrl = params.url; | 1917 GURL navUrl = params.url; |
1918 ui::PageTransition transition = params.transition_type; | 1918 ui::PageTransition transition = params.transition_type; |
1919 | 1919 |
1920 BOOL initialNavigation = NO; | 1920 BOOL initialNavigation = NO; |
1921 BOOL forwardBack = | 1921 BOOL forwardBack = |
1922 PageTransitionCoreTypeIs(transition, ui::PAGE_TRANSITION_RELOAD) && | 1922 PageTransitionCoreTypeIs(transition, ui::PAGE_TRANSITION_RELOAD) && |
1923 (transition & ui::PAGE_TRANSITION_FORWARD_BACK); | 1923 (transition & ui::PAGE_TRANSITION_FORWARD_BACK); |
1924 if (forwardBack) { | 1924 if (forwardBack) { |
1925 // Setting these for back/forward is not supported. | 1925 // Setting these for back/forward is not supported. |
1926 DCHECK(!params.extra_headers); | 1926 DCHECK(!params.extra_headers); |
1927 DCHECK(!params.post_data); | 1927 DCHECK(!params.post_data); |
1928 } else { | 1928 } else { |
1929 // Clear transient view before making any changes to history and navigation | 1929 // Clear transient view before making any changes to history and navigation |
1930 // manager. TODO(stuartmorgan): Drive Transient Item clearing from | 1930 // manager. TODO(stuartmorgan): Drive Transient Item clearing from |
1931 // navigation system, rather than from WebController. | 1931 // navigation system, rather than from WebController. |
1932 [self clearTransientContentView]; | 1932 [self clearTransientContentView]; |
1933 | 1933 |
1934 // TODO(stuartmorgan): Why doesn't recordStateInHistory get called for | 1934 // TODO(stuartmorgan): Why doesn't recordStateInHistory get called for |
1935 // forward/back transitions? | 1935 // forward/back transitions? |
1936 [self recordStateInHistory]; | 1936 [self recordStateInHistory]; |
1937 | 1937 |
1938 CRWSessionController* history = | 1938 CRWSessionController* history = |
1939 _webStateImpl->GetNavigationManagerImpl().GetSessionController(); | 1939 _webStateImpl->GetNavigationManagerImpl().GetSessionController(); |
1940 if (!self.currentSessionEntry) | 1940 if (!self.currentSessionEntry) |
1941 initialNavigation = YES; | 1941 initialNavigation = YES; |
1942 [history addPendingEntry:navUrl | 1942 [history addPendingItem:navUrl |
1943 referrer:params.referrer | 1943 referrer:params.referrer |
1944 transition:transition | 1944 transition:transition |
1945 rendererInitiated:params.is_renderer_initiated]; | 1945 rendererInitiated:params.is_renderer_initiated]; |
1946 web::NavigationItemImpl* addedItem = | 1946 web::NavigationItemImpl* addedItem = |
1947 [self currentSessionEntry].navigationItemImpl; | 1947 [self currentSessionEntry].navigationItemImpl; |
1948 DCHECK(addedItem); | 1948 DCHECK(addedItem); |
1949 if (params.extra_headers) | 1949 if (params.extra_headers) |
1950 addedItem->AddHttpRequestHeaders(params.extra_headers); | 1950 addedItem->AddHttpRequestHeaders(params.extra_headers); |
1951 if (params.post_data) { | 1951 if (params.post_data) { |
1952 DCHECK([addedItem->GetHttpRequestHeaders() objectForKey:@"Content-Type"]) | 1952 DCHECK([addedItem->GetHttpRequestHeaders() objectForKey:@"Content-Type"]) |
1953 << "Post data should have an associated content type"; | 1953 << "Post data should have an associated content type"; |
1954 addedItem->SetPostData(params.post_data); | 1954 addedItem->SetPostData(params.post_data); |
1955 addedItem->SetShouldSkipRepostFormConfirmation(true); | 1955 addedItem->SetShouldSkipRepostFormConfirmation(true); |
(...skipping 28 matching lines...) Expand all Loading... |
1984 const GURL currentURL = item ? item->GetURL() : GURL::EmptyGURL(); | 1984 const GURL currentURL = item ? item->GetURL() : GURL::EmptyGURL(); |
1985 // If it's a chrome URL, but not a native one, create the WebUI instance. | 1985 // If it's a chrome URL, but not a native one, create the WebUI instance. |
1986 if (web::GetWebClient()->IsAppSpecificURL(currentURL) && | 1986 if (web::GetWebClient()->IsAppSpecificURL(currentURL) && |
1987 ![_nativeProvider hasControllerForURL:currentURL]) { | 1987 ![_nativeProvider hasControllerForURL:currentURL]) { |
1988 if (!(item->GetTransitionType() & ui::PAGE_TRANSITION_TYPED || | 1988 if (!(item->GetTransitionType() & ui::PAGE_TRANSITION_TYPED || |
1989 item->GetTransitionType() & ui::PAGE_TRANSITION_AUTO_BOOKMARK) && | 1989 item->GetTransitionType() & ui::PAGE_TRANSITION_AUTO_BOOKMARK) && |
1990 self.sessionController.openedByDOM) { | 1990 self.sessionController.openedByDOM) { |
1991 // WebUI URLs can not be opened by DOM to prevent cross-site scripting as | 1991 // WebUI URLs can not be opened by DOM to prevent cross-site scripting as |
1992 // they have increased power. WebUI URLs may only be opened when the user | 1992 // they have increased power. WebUI URLs may only be opened when the user |
1993 // types in the URL or use bookmarks. | 1993 // types in the URL or use bookmarks. |
1994 [[self sessionController] discardNonCommittedEntries]; | 1994 [[self sessionController] discardNonCommittedItems]; |
1995 return; | 1995 return; |
1996 } else { | 1996 } else { |
1997 [self createWebUIForURL:currentURL]; | 1997 [self createWebUIForURL:currentURL]; |
1998 } | 1998 } |
1999 } | 1999 } |
2000 | 2000 |
2001 // Loading a new url, must check here if it's a native chrome URL and | 2001 // Loading a new url, must check here if it's a native chrome URL and |
2002 // replace the appropriate view if so, or transition back to a web view from | 2002 // replace the appropriate view if so, or transition back to a web view from |
2003 // a native view. | 2003 // a native view. |
2004 if ([self shouldLoadURLInNativeView:currentURL]) { | 2004 if ([self shouldLoadURLInNativeView:currentURL]) { |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2163 - (void)goToItemAtIndex:(int)index { | 2163 - (void)goToItemAtIndex:(int)index { |
2164 CRWSessionController* sessionController = self.sessionController; | 2164 CRWSessionController* sessionController = self.sessionController; |
2165 NSArray* entries = sessionController.entries; | 2165 NSArray* entries = sessionController.entries; |
2166 if (index < 0 || index >= static_cast<int>(entries.count)) { | 2166 if (index < 0 || index >= static_cast<int>(entries.count)) { |
2167 NOTREACHED(); | 2167 NOTREACHED(); |
2168 return; | 2168 return; |
2169 } | 2169 } |
2170 | 2170 |
2171 if (!_webStateImpl->IsShowingWebInterstitial()) | 2171 if (!_webStateImpl->IsShowingWebInterstitial()) |
2172 [self recordStateInHistory]; | 2172 [self recordStateInHistory]; |
2173 CRWSessionEntry* fromEntry = self.sessionController.currentEntry; | 2173 CRWSessionEntry* fromEntry = sessionController.currentEntry; |
| 2174 CRWSessionEntry* toEntry = entries[index]; |
2174 | 2175 |
2175 NSUserDefaults* userDefaults = [NSUserDefaults standardUserDefaults]; | 2176 NSUserDefaults* userDefaults = [NSUserDefaults standardUserDefaults]; |
2176 if (![userDefaults boolForKey:@"PendingIndexNavigationDisabled"]) { | 2177 if (![userDefaults boolForKey:@"PendingIndexNavigationDisabled"]) { |
2177 BOOL sameDocumentNavigation = | 2178 BOOL sameDocumentNavigation = [sessionController |
2178 [sessionController isSameDocumentNavigationBetweenEntry:fromEntry | 2179 isSameDocumentNavigationBetweenItem:fromEntry.navigationItem |
2179 andEntry:entries[index]]; | 2180 andItem:toEntry.navigationItem]; |
2180 if (sameDocumentNavigation) { | 2181 if (sameDocumentNavigation) { |
2181 [self.sessionController goToEntryAtIndex:index]; | 2182 [self.sessionController goToItemAtIndex:index]; |
2182 // TODO(crbug.com/684098): move this call out this block to avoid code | 2183 // TODO(crbug.com/684098): move this call out this block to avoid code |
2183 // duplication. | 2184 // duplication. |
2184 [self webWillFinishHistoryNavigationFromEntry:fromEntry]; | 2185 [self webWillFinishHistoryNavigationFromEntry:fromEntry]; |
2185 [self updateHTML5HistoryState]; | 2186 [self updateHTML5HistoryState]; |
2186 } else { | 2187 } else { |
2187 [sessionController discardNonCommittedEntries]; | 2188 [sessionController discardNonCommittedItems]; |
2188 [sessionController setPendingEntryIndex:index]; | 2189 [sessionController setPendingItemIndex:index]; |
2189 | 2190 |
2190 // TODO(crbug.com/684098): move this call out this block to avoid code | 2191 // TODO(crbug.com/684098): move this call out this block to avoid code |
2191 // duplication. | 2192 // duplication. |
2192 [self webWillFinishHistoryNavigationFromEntry:fromEntry]; | 2193 [self webWillFinishHistoryNavigationFromEntry:fromEntry]; |
2193 | 2194 |
2194 web::NavigationItemImpl* pendingItem = | 2195 web::NavigationItemImpl* pendingItem = |
2195 sessionController.pendingEntry.navigationItemImpl; | 2196 sessionController.pendingEntry.navigationItemImpl; |
2196 pendingItem->SetTransitionType(ui::PageTransitionFromInt( | 2197 pendingItem->SetTransitionType(ui::PageTransitionFromInt( |
2197 pendingItem->GetTransitionType() | ui::PAGE_TRANSITION_FORWARD_BACK)); | 2198 pendingItem->GetTransitionType() | ui::PAGE_TRANSITION_FORWARD_BACK)); |
2198 | 2199 |
2199 [self loadCurrentURL]; | 2200 [self loadCurrentURL]; |
2200 } | 2201 } |
2201 } else { | 2202 } else { |
2202 [self.sessionController goToEntryAtIndex:index]; | 2203 [self.sessionController goToItemAtIndex:index]; |
2203 if (fromEntry) | 2204 if (fromEntry) |
2204 [self finishHistoryNavigationFromEntry:fromEntry]; | 2205 [self finishHistoryNavigationFromEntry:fromEntry]; |
2205 } | 2206 } |
2206 } | 2207 } |
2207 | 2208 |
2208 - (BOOL)isLoaded { | 2209 - (BOOL)isLoaded { |
2209 return _loadPhase == web::PAGE_LOADED; | 2210 return _loadPhase == web::PAGE_LOADED; |
2210 } | 2211 } |
2211 | 2212 |
2212 - (void)didFinishNavigation { | 2213 - (void)didFinishNavigation { |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2297 } | 2298 } |
2298 | 2299 |
2299 - (void)finishHistoryNavigationFromEntry:(CRWSessionEntry*)fromEntry { | 2300 - (void)finishHistoryNavigationFromEntry:(CRWSessionEntry*)fromEntry { |
2300 [self webWillFinishHistoryNavigationFromEntry:fromEntry]; | 2301 [self webWillFinishHistoryNavigationFromEntry:fromEntry]; |
2301 | 2302 |
2302 // Only load the new URL if it has a different document than |fromEntry| to | 2303 // Only load the new URL if it has a different document than |fromEntry| to |
2303 // prevent extra page loads from NavigationItems created by hash changes or | 2304 // prevent extra page loads from NavigationItems created by hash changes or |
2304 // calls to window.history.pushState(). | 2305 // calls to window.history.pushState(). |
2305 BOOL shouldLoadURL = | 2306 BOOL shouldLoadURL = |
2306 ![_webStateImpl->GetNavigationManagerImpl().GetSessionController() | 2307 ![_webStateImpl->GetNavigationManagerImpl().GetSessionController() |
2307 isSameDocumentNavigationBetweenEntry:fromEntry | 2308 isSameDocumentNavigationBetweenItem:fromEntry.navigationItem |
2308 andEntry:self.currentSessionEntry]; | 2309 andItem:self.currentNavItem]; |
2309 web::NavigationItemImpl* currentItem = | 2310 web::NavigationItemImpl* currentItem = |
2310 self.currentSessionEntry.navigationItemImpl; | 2311 self.currentSessionEntry.navigationItemImpl; |
2311 GURL endURL = [self URLForHistoryNavigationFromItem:fromEntry.navigationItem | 2312 GURL endURL = [self URLForHistoryNavigationFromItem:fromEntry.navigationItem |
2312 toItem:currentItem]; | 2313 toItem:currentItem]; |
2313 if (shouldLoadURL) { | 2314 if (shouldLoadURL) { |
2314 ui::PageTransition transition = ui::PageTransitionFromInt( | 2315 ui::PageTransition transition = ui::PageTransitionFromInt( |
2315 ui::PAGE_TRANSITION_RELOAD | ui::PAGE_TRANSITION_FORWARD_BACK); | 2316 ui::PAGE_TRANSITION_RELOAD | ui::PAGE_TRANSITION_FORWARD_BACK); |
2316 | 2317 |
2317 NavigationManager::WebLoadParams params(endURL); | 2318 NavigationManager::WebLoadParams params(endURL); |
2318 if (currentItem) { | 2319 if (currentItem) { |
(...skipping 829 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3148 } | 3149 } |
3149 | 3150 |
3150 - (void)didStartLoadingURL:(const GURL&)url updateHistory:(BOOL)updateHistory { | 3151 - (void)didStartLoadingURL:(const GURL&)url updateHistory:(BOOL)updateHistory { |
3151 _loadPhase = web::PAGE_LOADING; | 3152 _loadPhase = web::PAGE_LOADING; |
3152 _URLOnStartLoading = url; | 3153 _URLOnStartLoading = url; |
3153 _displayStateOnStartLoading = self.pageDisplayState; | 3154 _displayStateOnStartLoading = self.pageDisplayState; |
3154 | 3155 |
3155 self.userInteractionRegistered = NO; | 3156 self.userInteractionRegistered = NO; |
3156 _pageHasZoomed = NO; | 3157 _pageHasZoomed = NO; |
3157 | 3158 |
3158 [[self sessionController] commitPendingEntry]; | 3159 [[self sessionController] commitPendingItem]; |
3159 [_delegate webDidStartLoadingURL:url shouldUpdateHistory:updateHistory]; | 3160 [_delegate webDidStartLoadingURL:url shouldUpdateHistory:updateHistory]; |
3160 } | 3161 } |
3161 | 3162 |
3162 - (void)wasShown { | 3163 - (void)wasShown { |
3163 if ([self.nativeController respondsToSelector:@selector(wasShown)]) { | 3164 if ([self.nativeController respondsToSelector:@selector(wasShown)]) { |
3164 [self.nativeController wasShown]; | 3165 [self.nativeController wasShown]; |
3165 } | 3166 } |
3166 } | 3167 } |
3167 | 3168 |
3168 - (void)wasHidden { | 3169 - (void)wasHidden { |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3454 return; | 3455 return; |
3455 } | 3456 } |
3456 | 3457 |
3457 [self loadCompleteWithSuccess:NO]; | 3458 [self loadCompleteWithSuccess:NO]; |
3458 [self loadErrorInNativeView:error]; | 3459 [self loadErrorInNativeView:error]; |
3459 } | 3460 } |
3460 | 3461 |
3461 - (void)handleCancelledError:(NSError*)error { | 3462 - (void)handleCancelledError:(NSError*)error { |
3462 if ([self shouldCancelLoadForCancelledError:error]) { | 3463 if ([self shouldCancelLoadForCancelledError:error]) { |
3463 [self loadCancelled]; | 3464 [self loadCancelled]; |
3464 [[self sessionController] discardNonCommittedEntries]; | 3465 [[self sessionController] discardNonCommittedItems]; |
3465 } | 3466 } |
3466 } | 3467 } |
3467 | 3468 |
3468 - (BOOL)shouldCancelLoadForCancelledError:(NSError*)error { | 3469 - (BOOL)shouldCancelLoadForCancelledError:(NSError*)error { |
3469 DCHECK_EQ(error.code, NSURLErrorCancelled); | 3470 DCHECK_EQ(error.code, NSURLErrorCancelled); |
3470 // Do not cancel the load if it is for an app specific URL, as such errors | 3471 // Do not cancel the load if it is for an app specific URL, as such errors |
3471 // are produced during the app specific URL load process. | 3472 // are produced during the app specific URL load process. |
3472 const GURL errorURL = | 3473 const GURL errorURL = |
3473 net::GURLWithNSURL(error.userInfo[NSURLErrorFailingURLErrorKey]); | 3474 net::GURLWithNSURL(error.userInfo[NSURLErrorFailingURLErrorKey]); |
3474 if (web::GetWebClient()->IsAppSpecificURL(errorURL)) | 3475 if (web::GetWebClient()->IsAppSpecificURL(errorURL)) |
(...skipping 1046 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4521 - (void)loadHTMLForCurrentURL:(NSString*)HTML { | 4522 - (void)loadHTMLForCurrentURL:(NSString*)HTML { |
4522 [self loadHTML:HTML forURL:self.currentURL]; | 4523 [self loadHTML:HTML forURL:self.currentURL]; |
4523 } | 4524 } |
4524 | 4525 |
4525 - (void)stopLoading { | 4526 - (void)stopLoading { |
4526 _stoppedWKNavigation.reset([_navigationStates lastAddedNavigation]); | 4527 _stoppedWKNavigation.reset([_navigationStates lastAddedNavigation]); |
4527 | 4528 |
4528 base::RecordAction(UserMetricsAction("Stop")); | 4529 base::RecordAction(UserMetricsAction("Stop")); |
4529 // Discard the pending and transient entried before notifying the tab model | 4530 // Discard the pending and transient entried before notifying the tab model |
4530 // observers of the change via |-abortLoad|. | 4531 // observers of the change via |-abortLoad|. |
4531 [[self sessionController] discardNonCommittedEntries]; | 4532 [[self sessionController] discardNonCommittedItems]; |
4532 [self abortLoad]; | 4533 [self abortLoad]; |
4533 web::NavigationItem* item = [self currentNavItem]; | 4534 web::NavigationItem* item = [self currentNavItem]; |
4534 GURL navigationURL = item ? item->GetVirtualURL() : GURL::EmptyGURL(); | 4535 GURL navigationURL = item ? item->GetVirtualURL() : GURL::EmptyGURL(); |
4535 // If discarding the non-committed entries results in an app-specific URL, | 4536 // If discarding the non-committed entries results in an app-specific URL, |
4536 // reload it in its native view. | 4537 // reload it in its native view. |
4537 if (!self.nativeController && | 4538 if (!self.nativeController && |
4538 [self shouldLoadURLInNativeView:navigationURL]) { | 4539 [self shouldLoadURLInNativeView:navigationURL]) { |
4539 [self loadCurrentURLInNativeView]; | 4540 [self loadCurrentURLInNativeView]; |
4540 } | 4541 } |
4541 } | 4542 } |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4728 // committed URL, which can happen when a link is opened in a new tab via a | 4729 // committed URL, which can happen when a link is opened in a new tab via a |
4729 // context menu or window.open, the pending entry should not be | 4730 // context menu or window.open, the pending entry should not be |
4730 // discarded so that the NavigationManager is never empty. Also, URLs loaded | 4731 // discarded so that the NavigationManager is never empty. Also, URLs loaded |
4731 // in a native view should be excluded to avoid an ugly animation where the | 4732 // in a native view should be excluded to avoid an ugly animation where the |
4732 // web view is inserted and quickly removed. | 4733 // web view is inserted and quickly removed. |
4733 GURL lastCommittedURL = self.webState->GetLastCommittedURL(); | 4734 GURL lastCommittedURL = self.webState->GetLastCommittedURL(); |
4734 BOOL isFirstLoad = lastCommittedURL.is_empty(); | 4735 BOOL isFirstLoad = lastCommittedURL.is_empty(); |
4735 BOOL previousItemWasLoadedInNativeView = | 4736 BOOL previousItemWasLoadedInNativeView = |
4736 [self shouldLoadURLInNativeView:lastCommittedURL]; | 4737 [self shouldLoadURLInNativeView:lastCommittedURL]; |
4737 if (!isFirstLoad && !previousItemWasLoadedInNativeView) | 4738 if (!isFirstLoad && !previousItemWasLoadedInNativeView) |
4738 [self.sessionController discardNonCommittedEntries]; | 4739 [self.sessionController discardNonCommittedItems]; |
4739 } | 4740 } |
4740 | 4741 |
4741 handler(allowNavigation ? WKNavigationResponsePolicyAllow | 4742 handler(allowNavigation ? WKNavigationResponsePolicyAllow |
4742 : WKNavigationResponsePolicyCancel); | 4743 : WKNavigationResponsePolicyCancel); |
4743 } | 4744 } |
4744 | 4745 |
4745 // TODO(stuartmorgan): Move all the guesswork around these states out of the | 4746 // TODO(stuartmorgan): Move all the guesswork around these states out of the |
4746 // superclass, and wire these up to the remaining methods. | 4747 // superclass, and wire these up to the remaining methods. |
4747 - (void)webView:(WKWebView*)webView | 4748 - (void)webView:(WKWebView*)webView |
4748 didStartProvisionalNavigation:(WKNavigation*)navigation { | 4749 didStartProvisionalNavigation:(WKNavigation*)navigation { |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4878 _certVerificationErrors->Clear(); | 4879 _certVerificationErrors->Clear(); |
4879 | 4880 |
4880 // This is the point where the document's URL has actually changed, and | 4881 // This is the point where the document's URL has actually changed, and |
4881 // pending navigation information should be applied to state information. | 4882 // pending navigation information should be applied to state information. |
4882 [self setDocumentURL:net::GURLWithNSURL([_webView URL])]; | 4883 [self setDocumentURL:net::GURLWithNSURL([_webView URL])]; |
4883 | 4884 |
4884 if (!_lastRegisteredRequestURL.is_valid() && | 4885 if (!_lastRegisteredRequestURL.is_valid() && |
4885 _documentURL != _lastRegisteredRequestURL) { | 4886 _documentURL != _lastRegisteredRequestURL) { |
4886 // if |_lastRegisteredRequestURL| is an invalid URL, then |_documentURL| | 4887 // if |_lastRegisteredRequestURL| is an invalid URL, then |_documentURL| |
4887 // will be "about:blank". | 4888 // will be "about:blank". |
4888 [[self sessionController] updatePendingEntry:_documentURL]; | 4889 [[self sessionController] updatePendingItem:_documentURL]; |
4889 } | 4890 } |
4890 DCHECK(_documentURL == _lastRegisteredRequestURL || | 4891 DCHECK(_documentURL == _lastRegisteredRequestURL || |
4891 (!_lastRegisteredRequestURL.is_valid() && | 4892 (!_lastRegisteredRequestURL.is_valid() && |
4892 _documentURL.spec() == url::kAboutBlankURL)); | 4893 _documentURL.spec() == url::kAboutBlankURL)); |
4893 | 4894 |
4894 self.webStateImpl->OnNavigationCommitted(_documentURL); | 4895 self.webStateImpl->OnNavigationCommitted(_documentURL); |
4895 [self commitPendingNavigationInfo]; | 4896 [self commitPendingNavigationInfo]; |
4896 if ([self currentBackForwardListItemHolder]->navigation_type() == | 4897 if ([self currentBackForwardListItemHolder]->navigation_type() == |
4897 WKNavigationTypeBackForward) { | 4898 WKNavigationTypeBackForward) { |
4898 // A fast back/forward won't call decidePolicyForNavigationResponse, so | 4899 // A fast back/forward won't call decidePolicyForNavigationResponse, so |
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5452 } | 5453 } |
5453 | 5454 |
5454 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC; | 5455 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC; |
5455 } | 5456 } |
5456 | 5457 |
5457 - (NSString*)refererFromNavigationAction:(WKNavigationAction*)action { | 5458 - (NSString*)refererFromNavigationAction:(WKNavigationAction*)action { |
5458 return [action.request valueForHTTPHeaderField:@"Referer"]; | 5459 return [action.request valueForHTTPHeaderField:@"Referer"]; |
5459 } | 5460 } |
5460 | 5461 |
5461 @end | 5462 @end |
OLD | NEW |