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

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

Issue 1836543002: [ios] Removed RequestTracker dependency from WebLoadParams. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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
« no previous file with comments | « ios/web/navigation/web_load_params.mm ('k') | ios/web/web_state/web_state_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <objc/runtime.h> 7 #import <objc/runtime.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <cmath> 10 #include <cmath>
(...skipping 1203 matching lines...) Expand 10 before | Expand all | Expand 10 after
1214 1214
1215 _loadPhase = web::LOAD_REQUESTED; 1215 _loadPhase = web::LOAD_REQUESTED;
1216 [self resetLoadState]; 1216 [self resetLoadState];
1217 _lastRegisteredRequestURL = requestURL; 1217 _lastRegisteredRequestURL = requestURL;
1218 1218
1219 if (!(transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK)) { 1219 if (!(transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK)) {
1220 // Record state of outgoing page. 1220 // Record state of outgoing page.
1221 [self recordStateInHistory]; 1221 [self recordStateInHistory];
1222 } 1222 }
1223 1223
1224 // If the web view had been discarded, and this request is to load that
1225 // URL again, then it's a rebuild and should use the cache.
1226 BOOL preferCache = _expectedReconstructionURL.is_valid() &&
1227 _expectedReconstructionURL == requestURL;
1228
1229 [_delegate webWillAddPendingURL:requestURL transition:transition]; 1224 [_delegate webWillAddPendingURL:requestURL transition:transition];
1230 // Add or update pending url. 1225 // Add or update pending url.
1231 if (_webStateImpl->GetNavigationManagerImpl().GetPendingItem()) { 1226 if (_webStateImpl->GetNavigationManagerImpl().GetPendingItem()) {
1232 // Update the existing pending entry. 1227 // Update the existing pending entry.
1233 // Typically on PAGE_TRANSITION_CLIENT_REDIRECT. 1228 // Typically on PAGE_TRANSITION_CLIENT_REDIRECT.
1234 [[self sessionController] updatePendingEntry:requestURL]; 1229 [[self sessionController] updatePendingEntry:requestURL];
1235 } else { 1230 } else {
1236 // A new session history entry needs to be created. 1231 // A new session history entry needs to be created.
1237 [[self sessionController] addPendingEntry:requestURL 1232 [[self sessionController] addPendingEntry:requestURL
1238 referrer:referrer 1233 referrer:referrer
1239 transition:transition 1234 transition:transition
1240 rendererInitiated:YES]; 1235 rendererInitiated:YES];
1241 } 1236 }
1242 // Update the cache mode for all the network requests issued by this web view.
1243 // The mode is reset to CACHE_NORMAL after each page load.
1244 if (_webStateImpl->GetCacheMode() != net::RequestTracker::CACHE_NORMAL) {
1245 _webStateImpl->GetRequestTracker()->SetCacheModeFromUIThread(
1246 _webStateImpl->GetCacheMode());
1247 } else if (preferCache) {
1248 _webStateImpl->GetRequestTracker()->SetCacheModeFromUIThread(
1249 net::RequestTracker::CACHE_HISTORY);
1250 }
1251 _webStateImpl->SetIsLoading(true); 1237 _webStateImpl->SetIsLoading(true);
1252 [_delegate webDidAddPendingURL]; 1238 [_delegate webDidAddPendingURL];
1253 _webStateImpl->OnProvisionalNavigationStarted(requestURL); 1239 _webStateImpl->OnProvisionalNavigationStarted(requestURL);
1254 } 1240 }
1255 1241
1256 - (NSString*)javascriptToReplaceWebViewURL:(const GURL&)URL 1242 - (NSString*)javascriptToReplaceWebViewURL:(const GURL&)URL
1257 stateObjectJSON:(NSString*)stateObject { 1243 stateObjectJSON:(NSString*)stateObject {
1258 std::string outURL; 1244 std::string outURL;
1259 base::EscapeJSONString(URL.spec(), true, &outURL); 1245 base::EscapeJSONString(URL.spec(), true, &outURL);
1260 return 1246 return
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
1448 DCHECK([addedItem->GetHttpRequestHeaders() objectForKey:@"Content-Type"]) 1434 DCHECK([addedItem->GetHttpRequestHeaders() objectForKey:@"Content-Type"])
1449 << "Post data should have an associated content type"; 1435 << "Post data should have an associated content type";
1450 addedItem->SetPostData(params.post_data); 1436 addedItem->SetPostData(params.post_data);
1451 addedItem->SetShouldSkipResubmitDataConfirmation(true); 1437 addedItem->SetShouldSkipResubmitDataConfirmation(true);
1452 } 1438 }
1453 } 1439 }
1454 1440
1455 [_delegate webDidUpdateSessionForLoadWithParams:params 1441 [_delegate webDidUpdateSessionForLoadWithParams:params
1456 wasInitialNavigation:initialNavigation]; 1442 wasInitialNavigation:initialNavigation];
1457 1443
1458 // If a non-default cache mode is passed in, it takes precedence over
1459 // |reload|.
1460 const BOOL reload = [self shouldReload:navUrl transition:transition];
1461 if (params.cache_mode != net::RequestTracker::CACHE_NORMAL) {
1462 _webStateImpl->SetCacheMode(params.cache_mode);
1463 } else if (reload) {
1464 _webStateImpl->SetCacheMode(net::RequestTracker::CACHE_RELOAD);
1465 }
1466
1467 [self loadCurrentURL]; 1444 [self loadCurrentURL];
1468
1469 // Change the cache mode back to CACHE_NORMAL after a reload.
1470 _webStateImpl->SetCacheMode(net::RequestTracker::CACHE_NORMAL);
1471 } 1445 }
1472 1446
1473 - (void)loadCurrentURL { 1447 - (void)loadCurrentURL {
1474 // If the content view doesn't exist, the tab has either been evicted, or 1448 // If the content view doesn't exist, the tab has either been evicted, or
1475 // never displayed. Bail, and let the URL be loaded when the tab is shown. 1449 // never displayed. Bail, and let the URL be loaded when the tab is shown.
1476 if (!self.containerView) 1450 if (!self.containerView)
1477 return; 1451 return;
1478 1452
1479 // Reset current WebUI if one exists. 1453 // Reset current WebUI if one exists.
1480 [self clearWebUI]; 1454 [self clearWebUI];
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
1609 // TODO(eugenebut): revisit this for WKWebView. 1583 // TODO(eugenebut): revisit this for WKWebView.
1610 [self loadCurrentURL]; 1584 [self loadCurrentURL];
1611 } 1585 }
1612 } else { 1586 } else {
1613 [self.nativeController reload]; 1587 [self.nativeController reload];
1614 } 1588 }
1615 } 1589 }
1616 1590
1617 - (void)reload { 1591 - (void)reload {
1618 [_delegate webWillReload]; 1592 [_delegate webWillReload];
1619
1620 _webStateImpl->SetCacheMode(net::RequestTracker::CACHE_RELOAD);
1621 [self reloadInternal]; 1593 [self reloadInternal];
1622 _webStateImpl->SetCacheMode(net::RequestTracker::CACHE_NORMAL);
1623 } 1594 }
1624 1595
1625 - (void)loadCancelled { 1596 - (void)loadCancelled {
1626 // Current load will not complete; this should be communicated upstream to the 1597 // Current load will not complete; this should be communicated upstream to the
1627 // delegate. 1598 // delegate.
1628 switch (_loadPhase) { 1599 switch (_loadPhase) {
1629 case web::LOAD_REQUESTED: 1600 case web::LOAD_REQUESTED:
1630 // Load phase after abort is always PAGE_LOADED. 1601 // Load phase after abort is always PAGE_LOADED.
1631 _loadPhase = web::PAGE_LOADED; 1602 _loadPhase = web::PAGE_LOADED;
1632 if (!_isHalted) { 1603 if (!_isHalted) {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
1702 } 1673 }
1703 1674
1704 CRWSessionController* sessionController = 1675 CRWSessionController* sessionController =
1705 _webStateImpl->GetNavigationManagerImpl().GetSessionController(); 1676 _webStateImpl->GetNavigationManagerImpl().GetSessionController();
1706 // fromEntry is retained because it has the potential to be released 1677 // fromEntry is retained because it has the potential to be released
1707 // by goDelta: if it has not been committed. 1678 // by goDelta: if it has not been committed.
1708 base::scoped_nsobject<CRWSessionEntry> fromEntry( 1679 base::scoped_nsobject<CRWSessionEntry> fromEntry(
1709 [[sessionController currentEntry] retain]); 1680 [[sessionController currentEntry] retain]);
1710 [sessionController goDelta:delta]; 1681 [sessionController goDelta:delta];
1711 if (fromEntry) { 1682 if (fromEntry) {
1712 _webStateImpl->SetCacheMode(net::RequestTracker::CACHE_HISTORY);
1713 [self finishHistoryNavigationFromEntry:fromEntry]; 1683 [self finishHistoryNavigationFromEntry:fromEntry];
1714 _webStateImpl->SetCacheMode(net::RequestTracker::CACHE_NORMAL);
1715 } 1684 }
1716 } 1685 }
1717 1686
1718 - (BOOL)isLoaded { 1687 - (BOOL)isLoaded {
1719 return _loadPhase == web::PAGE_LOADED; 1688 return _loadPhase == web::PAGE_LOADED;
1720 } 1689 }
1721 1690
1722 - (void)loadCompleteWithSuccess:(BOOL)loadSuccess { 1691 - (void)loadCompleteWithSuccess:(BOOL)loadSuccess {
1723 [self removePlaceholderOverlay]; 1692 [self removePlaceholderOverlay];
1724 // The webView may have been torn down (or replaced by a native view). Be 1693 // The webView may have been torn down (or replaced by a native view). Be
(...skipping 28 matching lines...) Expand all
1753 1722
1754 - (void)didFinishWithURL:(const GURL&)currentURL loadSuccess:(BOOL)loadSuccess { 1723 - (void)didFinishWithURL:(const GURL&)currentURL loadSuccess:(BOOL)loadSuccess {
1755 DCHECK(_loadPhase == web::PAGE_LOADED); 1724 DCHECK(_loadPhase == web::PAGE_LOADED);
1756 _webStateImpl->GetRequestTracker()->FinishPageLoad(currentURL, loadSuccess); 1725 _webStateImpl->GetRequestTracker()->FinishPageLoad(currentURL, loadSuccess);
1757 // Reset the navigation type to the default value. 1726 // Reset the navigation type to the default value.
1758 // Note: it is possible that the web view has already started loading the 1727 // Note: it is possible that the web view has already started loading the
1759 // next page when this is called. In that case the cache mode can leak to 1728 // next page when this is called. In that case the cache mode can leak to
1760 // (some of) the requests of the next page. It's expected to be an edge case, 1729 // (some of) the requests of the next page. It's expected to be an edge case,
1761 // but if it becomes a problem it should be possible to notice it afterwards 1730 // but if it becomes a problem it should be possible to notice it afterwards
1762 // and react to it (by warning the user or reloading the page for example). 1731 // and react to it (by warning the user or reloading the page for example).
1763 _webStateImpl->SetCacheMode(net::RequestTracker::CACHE_NORMAL);
1764 _webStateImpl->GetRequestTracker()->SetCacheModeFromUIThread( 1732 _webStateImpl->GetRequestTracker()->SetCacheModeFromUIThread(
1765 _webStateImpl->GetCacheMode()); 1733 net::RequestTracker::CACHE_NORMAL);
1766 1734
1767 [self restoreStateFromHistory]; 1735 [self restoreStateFromHistory];
1768 [self loadCompletedForURL:currentURL]; 1736 [self loadCompletedForURL:currentURL];
1769 _webStateImpl->OnPageLoaded(currentURL, loadSuccess); 1737 _webStateImpl->OnPageLoaded(currentURL, loadSuccess);
1770 _webStateImpl->SetIsLoading(false); 1738 _webStateImpl->SetIsLoading(false);
1771 // Inform the embedder the load completed. 1739 // Inform the embedder the load completed.
1772 [_delegate webDidFinishWithURL:currentURL loadSuccess:loadSuccess]; 1740 [_delegate webDidFinishWithURL:currentURL loadSuccess:loadSuccess];
1773 } 1741 }
1774 1742
1775 - (void)finishHistoryNavigationFromEntry:(CRWSessionEntry*)fromEntry { 1743 - (void)finishHistoryNavigationFromEntry:(CRWSessionEntry*)fromEntry {
(...skipping 2046 matching lines...) Expand 10 before | Expand all | Expand 10 after
3822 if ([MIMEType isEqualToString:@"text/html"] || 3790 if ([MIMEType isEqualToString:@"text/html"] ||
3823 [MIMEType isEqualToString:@"application/xhtml+xml"] || 3791 [MIMEType isEqualToString:@"application/xhtml+xml"] ||
3824 [MIMEType isEqualToString:@"application/xml"]) { 3792 [MIMEType isEqualToString:@"application/xml"]) {
3825 return web::WEB_VIEW_DOCUMENT_TYPE_HTML; 3793 return web::WEB_VIEW_DOCUMENT_TYPE_HTML;
3826 } 3794 }
3827 3795
3828 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC; 3796 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC;
3829 } 3797 }
3830 3798
3831 @end 3799 @end
OLDNEW
« no previous file with comments | « ios/web/navigation/web_load_params.mm ('k') | ios/web/web_state/web_state_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698