| 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/chrome/browser/tabs/tab.h" | 5 #import "ios/chrome/browser/tabs/tab.h" |
| 6 | 6 |
| 7 #import <CoreLocation/CoreLocation.h> | 7 #import <CoreLocation/CoreLocation.h> |
| 8 #import <UIKit/UIKit.h> | 8 #import <UIKit/UIKit.h> |
| 9 | 9 |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 _parentTabModel = model; | 553 _parentTabModel = model; |
| 554 | 554 |
| 555 if (_parentTabModel.syncedWindowDelegate) { | 555 if (_parentTabModel.syncedWindowDelegate) { |
| 556 IOSChromeSessionTabHelper::FromWebState(self.webState) | 556 IOSChromeSessionTabHelper::FromWebState(self.webState) |
| 557 ->SetWindowID(model.sessionID); | 557 ->SetWindowID(model.sessionID); |
| 558 } | 558 } |
| 559 } | 559 } |
| 560 | 560 |
| 561 - (NSString*)description { | 561 - (NSString*)description { |
| 562 return [NSString stringWithFormat:@"%p ... %@ - %s", self, self.title, | 562 return [NSString stringWithFormat:@"%p ... %@ - %s", self, self.title, |
| 563 self.url.spec().c_str()]; | 563 self.visibleURL.spec().c_str()]; |
| 564 } | 564 } |
| 565 | 565 |
| 566 - (CRWWebController*)webController { | 566 - (CRWWebController*)webController { |
| 567 return _webStateImpl ? _webStateImpl->GetWebController() : nil; | 567 return _webStateImpl ? _webStateImpl->GetWebController() : nil; |
| 568 } | 568 } |
| 569 | 569 |
| 570 - (id<TabDialogDelegate>)dialogDelegate { | 570 - (id<TabDialogDelegate>)dialogDelegate { |
| 571 return dialogDelegate_; | 571 return dialogDelegate_; |
| 572 } | 572 } |
| 573 | 573 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 620 DCHECK([self navigationManager]); | 620 DCHECK([self navigationManager]); |
| 621 web::NavigationItem* item = [self navigationManager]->GetLastCommittedItem(); | 621 web::NavigationItem* item = [self navigationManager]->GetLastCommittedItem(); |
| 622 if (!item) | 622 if (!item) |
| 623 return nil; | 623 return nil; |
| 624 base::string16 pageTitle = item->GetTitle(); | 624 base::string16 pageTitle = item->GetTitle(); |
| 625 return pageTitle.empty() ? nil : base::SysUTF16ToNSString(pageTitle); | 625 return pageTitle.empty() ? nil : base::SysUTF16ToNSString(pageTitle); |
| 626 } | 626 } |
| 627 | 627 |
| 628 - (NSString*)urlDisplayString { | 628 - (NSString*)urlDisplayString { |
| 629 base::string16 urlText = url_formatter::FormatUrl( | 629 base::string16 urlText = url_formatter::FormatUrl( |
| 630 self.url, url_formatter::kFormatUrlOmitNothing, net::UnescapeRule::SPACES, | 630 self.visibleURL, url_formatter::kFormatUrlOmitNothing, |
| 631 nullptr, nullptr, nullptr); | 631 net::UnescapeRule::SPACES, nullptr, nullptr, nullptr); |
| 632 return base::SysUTF16ToNSString(urlText); | 632 return base::SysUTF16ToNSString(urlText); |
| 633 } | 633 } |
| 634 | 634 |
| 635 - (NSString*)tabId { | 635 - (NSString*)tabId { |
| 636 if (!self.webState) { | 636 if (!self.webState) { |
| 637 // Tab can outlive WebState, in which case Tab is not valid anymore and | 637 // Tab can outlive WebState, in which case Tab is not valid anymore and |
| 638 // tabId should be nil. | 638 // tabId should be nil. |
| 639 return nil; | 639 return nil; |
| 640 } | 640 } |
| 641 | 641 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 654 | 654 |
| 655 tabId_ = [tabId copy]; | 655 tabId_ = [tabId copy]; |
| 656 return tabId_; | 656 return tabId_; |
| 657 } | 657 } |
| 658 | 658 |
| 659 - (web::WebState*)webState { | 659 - (web::WebState*)webState { |
| 660 return _webStateImpl; | 660 return _webStateImpl; |
| 661 } | 661 } |
| 662 | 662 |
| 663 - (void)fetchFavicon { | 663 - (void)fetchFavicon { |
| 664 const GURL& url = self.url; | 664 const GURL& url = self.visibleURL; |
| 665 if (!url.is_valid()) | 665 if (!url.is_valid()) |
| 666 return; | 666 return; |
| 667 | 667 |
| 668 favicon::FaviconDriver* faviconDriver = | 668 favicon::FaviconDriver* faviconDriver = |
| 669 favicon::WebFaviconDriver::FromWebState(self.webState); | 669 favicon::WebFaviconDriver::FromWebState(self.webState); |
| 670 if (faviconDriver) | 670 if (faviconDriver) |
| 671 faviconDriver->FetchFavicon(url); | 671 faviconDriver->FetchFavicon(url); |
| 672 } | 672 } |
| 673 | 673 |
| 674 - (void)setFavicon:(const gfx::Image*)image { | 674 - (void)setFavicon:(const gfx::Image*)image { |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 837 NSString* title = [self title]; | 837 NSString* title = [self title]; |
| 838 if (![title length] || | 838 if (![title length] || |
| 839 [title isEqualToString:l10n_util::GetNSString(IDS_DEFAULT_TAB_TITLE)]) { | 839 [title isEqualToString:l10n_util::GetNSString(IDS_DEFAULT_TAB_TITLE)]) { |
| 840 return; | 840 return; |
| 841 } | 841 } |
| 842 | 842 |
| 843 history::HistoryService* historyService = | 843 history::HistoryService* historyService = |
| 844 ios::HistoryServiceFactory::GetForBrowserState( | 844 ios::HistoryServiceFactory::GetForBrowserState( |
| 845 _browserState, ServiceAccessType::IMPLICIT_ACCESS); | 845 _browserState, ServiceAccessType::IMPLICIT_ACCESS); |
| 846 DCHECK(historyService); | 846 DCHECK(historyService); |
| 847 historyService->SetPageTitle(self.url, base::SysNSStringToUTF16(title)); | 847 historyService->SetPageTitle(self.lastCommittedURL, |
| 848 base::SysNSStringToUTF16(title)); |
| 848 } | 849 } |
| 849 | 850 |
| 850 - (void)addCurrentEntryToHistoryDB { | 851 - (void)addCurrentEntryToHistoryDB { |
| 851 DCHECK([self navigationManager]->GetVisibleItem()); | 852 DCHECK([self navigationManager]->GetVisibleItem()); |
| 852 // If incognito, don't update history. | 853 // If incognito, don't update history. |
| 853 if (_browserState->IsOffTheRecord()) | 854 if (_browserState->IsOffTheRecord()) |
| 854 return; | 855 return; |
| 855 | 856 |
| 856 web::NavigationItem* item = [self navigationManager]->GetVisibleItem(); | 857 web::NavigationItem* item = [self navigationManager]->GetVisibleItem(); |
| 857 | 858 |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1115 if (finalURL.SchemeIs("u2f")) { | 1116 if (finalURL.SchemeIs("u2f")) { |
| 1116 // Create U2FController object lazily. | 1117 // Create U2FController object lazily. |
| 1117 if (!_secondFactorController) | 1118 if (!_secondFactorController) |
| 1118 _secondFactorController = [[U2FController alloc] init]; | 1119 _secondFactorController = [[U2FController alloc] init]; |
| 1119 | 1120 |
| 1120 DCHECK([self navigationManager]); | 1121 DCHECK([self navigationManager]); |
| 1121 GURL origin = | 1122 GURL origin = |
| 1122 [self navigationManager]->GetLastCommittedItem()->GetURL().GetOrigin(); | 1123 [self navigationManager]->GetLastCommittedItem()->GetURL().GetOrigin(); |
| 1123 | 1124 |
| 1124 // Compose u2f-x-callback URL and update urlToOpen. | 1125 // Compose u2f-x-callback URL and update urlToOpen. |
| 1125 finalURL = [_secondFactorController XCallbackFromRequestURL:finalURL | 1126 finalURL = |
| 1126 originURL:origin | 1127 [_secondFactorController XCallbackFromRequestURL:finalURL |
| 1127 tabURL:self.url | 1128 originURL:origin |
| 1128 tabID:self.tabId]; | 1129 tabURL:self.lastCommittedURL |
| 1130 tabID:self.tabId]; |
| 1129 | 1131 |
| 1130 if (!finalURL.is_valid()) | 1132 if (!finalURL.is_valid()) |
| 1131 return NO; | 1133 return NO; |
| 1132 } | 1134 } |
| 1133 | 1135 |
| 1134 if ([_externalAppLauncher openURL:finalURL linkClicked:linkClicked]) { | 1136 if ([_externalAppLauncher openURL:finalURL linkClicked:linkClicked]) { |
| 1135 // Clears pending navigation history after successfully launching the | 1137 // Clears pending navigation history after successfully launching the |
| 1136 // external app. | 1138 // external app. |
| 1137 DCHECK([self navigationManager]); | 1139 DCHECK([self navigationManager]); |
| 1138 [self navigationManager]->DiscardNonCommittedItems(); | 1140 [self navigationManager]->DiscardNonCommittedItems(); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1207 | 1209 |
| 1208 - (void)handleExportableFile:(net::HttpResponseHeaders*)headers { | 1210 - (void)handleExportableFile:(net::HttpResponseHeaders*)headers { |
| 1209 // Only "application/pdf" is supported for now. | 1211 // Only "application/pdf" is supported for now. |
| 1210 if (self.webState->GetContentsMimeType() != "application/pdf") | 1212 if (self.webState->GetContentsMimeType() != "application/pdf") |
| 1211 return; | 1213 return; |
| 1212 | 1214 |
| 1213 [[NSNotificationCenter defaultCenter] | 1215 [[NSNotificationCenter defaultCenter] |
| 1214 postNotificationName:kTabIsShowingExportableNotificationForCrashReporting | 1216 postNotificationName:kTabIsShowingExportableNotificationForCrashReporting |
| 1215 object:self]; | 1217 object:self]; |
| 1216 // Try to generate a filename by first looking at |content_disposition_|, then | 1218 // Try to generate a filename by first looking at |content_disposition_|, then |
| 1217 // at the last component of |self.url| and if both of these fail use the | 1219 // at the last component of |lastCommittedURL| and if both of these fail use |
| 1218 // default filename "document". | 1220 // the default filename "document". |
| 1219 std::string contentDisposition; | 1221 std::string contentDisposition; |
| 1220 if (headers) | 1222 if (headers) |
| 1221 headers->GetNormalizedHeader("content-disposition", &contentDisposition); | 1223 headers->GetNormalizedHeader("content-disposition", &contentDisposition); |
| 1222 std::string defaultFilename = | 1224 std::string defaultFilename = |
| 1223 l10n_util::GetStringUTF8(IDS_IOS_OPEN_IN_FILE_DEFAULT_TITLE); | 1225 l10n_util::GetStringUTF8(IDS_IOS_OPEN_IN_FILE_DEFAULT_TITLE); |
| 1226 const GURL& committedURL = self.lastCommittedURL; |
| 1224 base::string16 filename = | 1227 base::string16 filename = |
| 1225 net::GetSuggestedFilename(self.url, contentDisposition, | 1228 net::GetSuggestedFilename(committedURL, contentDisposition, |
| 1226 "", // referrer-charset | 1229 "", // referrer-charset |
| 1227 "", // suggested-name | 1230 "", // suggested-name |
| 1228 "application/pdf", // mime-type | 1231 "application/pdf", // mime-type |
| 1229 defaultFilename); | 1232 defaultFilename); |
| 1230 [[self openInController] | 1233 [[self openInController] |
| 1231 enableWithDocumentURL:self.url | 1234 enableWithDocumentURL:committedURL |
| 1232 suggestedFilename:base::SysUTF16ToNSString(filename)]; | 1235 suggestedFilename:base::SysUTF16ToNSString(filename)]; |
| 1233 } | 1236 } |
| 1234 | 1237 |
| 1235 - (void)countMainFrameLoad { | 1238 - (void)countMainFrameLoad { |
| 1236 if ([self isPrerenderTab] || [self url].SchemeIs(kChromeUIScheme)) | 1239 if ([self isPrerenderTab] || |
| 1240 self.lastCommittedURL.SchemeIs(kChromeUIScheme)) { |
| 1237 return; | 1241 return; |
| 1242 } |
| 1238 base::RecordAction(base::UserMetricsAction("MobilePageLoaded")); | 1243 base::RecordAction(base::UserMetricsAction("MobilePageLoaded")); |
| 1239 } | 1244 } |
| 1240 | 1245 |
| 1241 - (void)applicationDidBecomeActive { | 1246 - (void)applicationDidBecomeActive { |
| 1242 if (!_requireReloadAfterBecomingActive) | 1247 if (!_requireReloadAfterBecomingActive) |
| 1243 return; | 1248 return; |
| 1244 if (_visible) { | 1249 if (_visible) { |
| 1245 self.navigationManager->Reload(web::ReloadType::NORMAL, | 1250 self.navigationManager->Reload(web::ReloadType::NORMAL, |
| 1246 false /* check_for_repost */); | 1251 false /* check_for_repost */); |
| 1247 } else { | 1252 } else { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1282 - (void)switchToReaderMode { | 1287 - (void)switchToReaderMode { |
| 1283 DCHECK(self.view); | 1288 DCHECK(self.view); |
| 1284 [self.readerModeController switchToReaderMode]; | 1289 [self.readerModeController switchToReaderMode]; |
| 1285 } | 1290 } |
| 1286 | 1291 |
| 1287 - (void)loadReaderModeHTML:(NSString*)html forURL:(const GURL&)url { | 1292 - (void)loadReaderModeHTML:(NSString*)html forURL:(const GURL&)url { |
| 1288 // Before changing the HTML on the current page, this checks that the URL has | 1293 // Before changing the HTML on the current page, this checks that the URL has |
| 1289 // not changed since reader mode was requested. This could happen for example | 1294 // not changed since reader mode was requested. This could happen for example |
| 1290 // if the page does a late redirect itself or if the user tapped on a link and | 1295 // if the page does a late redirect itself or if the user tapped on a link and |
| 1291 // triggered reader mode before the page load is detected by webState. | 1296 // triggered reader mode before the page load is detected by webState. |
| 1292 if (url == self.url) | 1297 if (url == self.lastCommittedURL) |
| 1293 [self.webController loadHTMLForCurrentURL:html]; | 1298 [self.webController loadHTMLForCurrentURL:html]; |
| 1294 | 1299 |
| 1295 [self.readerModeController exitReaderMode]; | 1300 [self.readerModeController exitReaderMode]; |
| 1296 } | 1301 } |
| 1297 | 1302 |
| 1298 #pragma mark - | 1303 #pragma mark - |
| 1299 | 1304 |
| 1300 - (BOOL)usesDesktopUserAgent { | 1305 - (BOOL)usesDesktopUserAgent { |
| 1301 if (!self.navigationManager) | 1306 if (!self.navigationManager) |
| 1302 return NO; | 1307 return NO; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1383 | 1388 |
| 1384 BOOL isUserNavigationEvent = | 1389 BOOL isUserNavigationEvent = |
| 1385 (transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK) == 0; | 1390 (transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK) == 0; |
| 1386 // Check for link-follow clobbers. These are changes where there is no | 1391 // Check for link-follow clobbers. These are changes where there is no |
| 1387 // pending entry (since that means the change wasn't caused by this class), | 1392 // pending entry (since that means the change wasn't caused by this class), |
| 1388 // and where the URL changes (to avoid counting page resurrection). | 1393 // and where the URL changes (to avoid counting page resurrection). |
| 1389 // TODO(crbug.com/546401): Consider moving this into NavigationManager, or | 1394 // TODO(crbug.com/546401): Consider moving this into NavigationManager, or |
| 1390 // into a NavigationManager observer callback, so it doesn't need to be | 1395 // into a NavigationManager observer callback, so it doesn't need to be |
| 1391 // checked in several places. | 1396 // checked in several places. |
| 1392 if (isUserNavigationEvent && !_isPrerenderTab && | 1397 if (isUserNavigationEvent && !_isPrerenderTab && |
| 1393 ![self navigationManager]->GetPendingItem() && url != self.url) { | 1398 ![self navigationManager]->GetPendingItem() && |
| 1399 url != self.lastCommittedURL) { |
| 1394 base::RecordAction(base::UserMetricsAction("MobileTabClobbered")); | 1400 base::RecordAction(base::UserMetricsAction("MobileTabClobbered")); |
| 1395 if ([_parentTabModel tabUsageRecorder]) | 1401 if ([_parentTabModel tabUsageRecorder]) |
| 1396 [_parentTabModel tabUsageRecorder]->RecordPageLoadStart(self); | 1402 [_parentTabModel tabUsageRecorder]->RecordPageLoadStart(self); |
| 1397 } | 1403 } |
| 1398 if (![self navigationManager]->GetPendingItem()) { | 1404 if (![self navigationManager]->GetPendingItem()) { |
| 1399 // Reset |isVoiceSearchResultsTab| since a new page is being navigated to. | 1405 // Reset |isVoiceSearchResultsTab| since a new page is being navigated to. |
| 1400 self.isVoiceSearchResultsTab = NO; | 1406 self.isVoiceSearchResultsTab = NO; |
| 1401 } | 1407 } |
| 1402 } | 1408 } |
| 1403 | 1409 |
| (...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1902 | 1908 |
| 1903 - (TabModel*)parentTabModel { | 1909 - (TabModel*)parentTabModel { |
| 1904 return _parentTabModel; | 1910 return _parentTabModel; |
| 1905 } | 1911 } |
| 1906 | 1912 |
| 1907 - (FormInputAccessoryViewController*)inputAccessoryViewController { | 1913 - (FormInputAccessoryViewController*)inputAccessoryViewController { |
| 1908 return _inputAccessoryViewController; | 1914 return _inputAccessoryViewController; |
| 1909 } | 1915 } |
| 1910 | 1916 |
| 1911 @end | 1917 @end |
| OLD | NEW |