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 572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
583 parentTabModel_ = model; | 583 parentTabModel_ = model; |
584 | 584 |
585 if (parentTabModel_.syncedWindowDelegate) { | 585 if (parentTabModel_.syncedWindowDelegate) { |
586 IOSChromeSessionTabHelper::FromWebState(self.webState) | 586 IOSChromeSessionTabHelper::FromWebState(self.webState) |
587 ->SetWindowID(model.sessionID); | 587 ->SetWindowID(model.sessionID); |
588 } | 588 } |
589 } | 589 } |
590 | 590 |
591 - (NSString*)description { | 591 - (NSString*)description { |
592 return [NSString stringWithFormat:@"%p ... %@ - %s", self, self.title, | 592 return [NSString stringWithFormat:@"%p ... %@ - %s", self, self.title, |
593 self.url.spec().c_str()]; | 593 self.visibleURL.spec().c_str()]; |
kkhorimoto
2017/04/14 21:05:16
It seems to make the most sense to use the URL tha
| |
594 } | 594 } |
595 | 595 |
596 - (CRWWebController*)webController { | 596 - (CRWWebController*)webController { |
597 return webStateImpl_ ? webStateImpl_->GetWebController() : nil; | 597 return webStateImpl_ ? webStateImpl_->GetWebController() : nil; |
598 } | 598 } |
599 | 599 |
600 - (id<TabDialogDelegate>)dialogDelegate { | 600 - (id<TabDialogDelegate>)dialogDelegate { |
601 return dialogDelegate_; | 601 return dialogDelegate_; |
602 } | 602 } |
603 | 603 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
658 DCHECK([self navigationManager]); | 658 DCHECK([self navigationManager]); |
659 web::NavigationItem* item = [self navigationManager]->GetLastCommittedItem(); | 659 web::NavigationItem* item = [self navigationManager]->GetLastCommittedItem(); |
660 if (!item) | 660 if (!item) |
661 return nil; | 661 return nil; |
662 base::string16 pageTitle = item->GetTitle(); | 662 base::string16 pageTitle = item->GetTitle(); |
663 return pageTitle.empty() ? nil : base::SysUTF16ToNSString(pageTitle); | 663 return pageTitle.empty() ? nil : base::SysUTF16ToNSString(pageTitle); |
664 } | 664 } |
665 | 665 |
666 - (NSString*)urlDisplayString { | 666 - (NSString*)urlDisplayString { |
667 base::string16 urlText = url_formatter::FormatUrl( | 667 base::string16 urlText = url_formatter::FormatUrl( |
668 self.url, url_formatter::kFormatUrlOmitNothing, net::UnescapeRule::SPACES, | 668 self.visibleURL, url_formatter::kFormatUrlOmitNothing, |
kkhorimoto
2017/04/14 21:05:16
It seems to make the most sense to use the URL tha
| |
669 nullptr, nullptr, nullptr); | 669 net::UnescapeRule::SPACES, nullptr, nullptr, nullptr); |
670 return base::SysUTF16ToNSString(urlText); | 670 return base::SysUTF16ToNSString(urlText); |
671 } | 671 } |
672 | 672 |
673 - (NSString*)tabId { | 673 - (NSString*)tabId { |
674 if (tabId_) | 674 if (tabId_) |
675 return tabId_.get(); | 675 return tabId_.get(); |
676 | 676 |
677 DCHECK(self.webState); | 677 DCHECK(self.webState); |
678 web::SerializableUserDataManager* userDataManager = | 678 web::SerializableUserDataManager* userDataManager = |
679 web::SerializableUserDataManager::FromWebState(self.webState); | 679 web::SerializableUserDataManager::FromWebState(self.webState); |
680 NSString* tabId = base::mac::ObjCCast<NSString>( | 680 NSString* tabId = base::mac::ObjCCast<NSString>( |
681 userDataManager->GetValueForSerializationKey(kTabIDKey)); | 681 userDataManager->GetValueForSerializationKey(kTabIDKey)); |
682 | 682 |
683 if (!tabId || ![tabId length]) { | 683 if (!tabId || ![tabId length]) { |
684 tabId = [[NSUUID UUID] UUIDString]; | 684 tabId = [[NSUUID UUID] UUIDString]; |
685 userDataManager->AddSerializableData(tabId, kTabIDKey); | 685 userDataManager->AddSerializableData(tabId, kTabIDKey); |
686 } | 686 } |
687 | 687 |
688 tabId_.reset([tabId copy]); | 688 tabId_.reset([tabId copy]); |
689 return tabId_.get(); | 689 return tabId_.get(); |
690 } | 690 } |
691 | 691 |
692 - (web::WebState*)webState { | 692 - (web::WebState*)webState { |
693 return webStateImpl_; | 693 return webStateImpl_; |
694 } | 694 } |
695 | 695 |
696 - (void)fetchFavicon { | 696 - (void)fetchFavicon { |
697 const GURL& url = self.url; | 697 const GURL& url = self.visibleURL; |
kkhorimoto
2017/04/14 21:05:16
Since favicon fetching occurs during a load, we sh
| |
698 if (!url.is_valid()) | 698 if (!url.is_valid()) |
699 return; | 699 return; |
700 | 700 |
701 favicon::FaviconDriver* faviconDriver = | 701 favicon::FaviconDriver* faviconDriver = |
702 favicon::WebFaviconDriver::FromWebState(self.webState); | 702 favicon::WebFaviconDriver::FromWebState(self.webState); |
703 if (faviconDriver) { | 703 if (faviconDriver) { |
704 faviconDriver->FetchFavicon(url); | 704 faviconDriver->FetchFavicon(url); |
705 } | 705 } |
706 } | 706 } |
707 | 707 |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
886 // Don't update the history if current entry has no title. | 886 // Don't update the history if current entry has no title. |
887 NSString* title = [self title]; | 887 NSString* title = [self title]; |
888 if (![title length] || | 888 if (![title length] || |
889 [title isEqualToString:l10n_util::GetNSString(IDS_DEFAULT_TAB_TITLE)]) | 889 [title isEqualToString:l10n_util::GetNSString(IDS_DEFAULT_TAB_TITLE)]) |
890 return; | 890 return; |
891 | 891 |
892 history::HistoryService* historyService = | 892 history::HistoryService* historyService = |
893 ios::HistoryServiceFactory::GetForBrowserState( | 893 ios::HistoryServiceFactory::GetForBrowserState( |
894 browserState_, ServiceAccessType::IMPLICIT_ACCESS); | 894 browserState_, ServiceAccessType::IMPLICIT_ACCESS); |
895 DCHECK(historyService); | 895 DCHECK(historyService); |
896 historyService->SetPageTitle(self.url, base::SysNSStringToUTF16(title)); | 896 historyService->SetPageTitle(self.lastCommittedURL, |
897 base::SysNSStringToUTF16(title)); | |
kkhorimoto
2017/04/14 21:05:16
|title| is fetched via WebState::GetTitle(), which
| |
897 } | 898 } |
898 | 899 |
899 - (void)addCurrentEntryToHistoryDB { | 900 - (void)addCurrentEntryToHistoryDB { |
900 DCHECK([self navigationManager]->GetVisibleItem()); | 901 DCHECK([self navigationManager]->GetVisibleItem()); |
901 // If incognito, don't update history. | 902 // If incognito, don't update history. |
902 if (browserState_->IsOffTheRecord()) | 903 if (browserState_->IsOffTheRecord()) |
903 return; | 904 return; |
904 | 905 |
905 web::NavigationItem* item = [self navigationManager]->GetVisibleItem(); | 906 web::NavigationItem* item = [self navigationManager]->GetVisibleItem(); |
906 | 907 |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1171 U2FController_.reset([[U2FController alloc] init]); | 1172 U2FController_.reset([[U2FController alloc] init]); |
1172 } | 1173 } |
1173 | 1174 |
1174 DCHECK([self navigationManager]); | 1175 DCHECK([self navigationManager]); |
1175 GURL origin = | 1176 GURL origin = |
1176 [self navigationManager]->GetLastCommittedItem()->GetURL().GetOrigin(); | 1177 [self navigationManager]->GetLastCommittedItem()->GetURL().GetOrigin(); |
1177 | 1178 |
1178 // Compose u2f-x-callback URL and update urlToOpen. | 1179 // Compose u2f-x-callback URL and update urlToOpen. |
1179 finalURL = [U2FController_ XCallbackFromRequestURL:finalURL | 1180 finalURL = [U2FController_ XCallbackFromRequestURL:finalURL |
1180 originURL:origin | 1181 originURL:origin |
1181 tabURL:self.url | 1182 tabURL:self.lastCommittedURL |
kkhorimoto
2017/04/14 21:05:16
If an external URL is being opened by a page, then
| |
1182 tabID:self.tabId]; | 1183 tabID:self.tabId]; |
1183 | 1184 |
1184 if (!finalURL.is_valid()) { | 1185 if (!finalURL.is_valid()) { |
1185 return NO; | 1186 return NO; |
1186 } | 1187 } |
1187 } | 1188 } |
1188 | 1189 |
1189 if ([externalAppLauncher_ openURL:finalURL linkClicked:linkClicked]) { | 1190 if ([externalAppLauncher_ openURL:finalURL linkClicked:linkClicked]) { |
1190 // Clears pending navigation history after successfully launching the | 1191 // Clears pending navigation history after successfully launching the |
1191 // external app. | 1192 // external app. |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1279 postNotificationName:kTabIsShowingExportableNotificationForCrashReporting | 1280 postNotificationName:kTabIsShowingExportableNotificationForCrashReporting |
1280 object:self]; | 1281 object:self]; |
1281 // Try to generate a filename by first looking at |content_disposition_|, then | 1282 // Try to generate a filename by first looking at |content_disposition_|, then |
1282 // at the last component of |self.url| and if both of these fail use the | 1283 // at the last component of |self.url| and if both of these fail use the |
1283 // default filename "document". | 1284 // default filename "document". |
1284 std::string contentDisposition; | 1285 std::string contentDisposition; |
1285 if (headers) | 1286 if (headers) |
1286 headers->GetNormalizedHeader("content-disposition", &contentDisposition); | 1287 headers->GetNormalizedHeader("content-disposition", &contentDisposition); |
1287 std::string defaultFilename = | 1288 std::string defaultFilename = |
1288 l10n_util::GetStringUTF8(IDS_IOS_OPEN_IN_FILE_DEFAULT_TITLE); | 1289 l10n_util::GetStringUTF8(IDS_IOS_OPEN_IN_FILE_DEFAULT_TITLE); |
1290 const GURL& committedURL = self.lastCommittedURL; | |
kkhorimoto
2017/04/14 21:05:16
If a file is being opened by a page, then we want
| |
1289 base::string16 filename = | 1291 base::string16 filename = |
1290 net::GetSuggestedFilename(self.url, contentDisposition, | 1292 net::GetSuggestedFilename(committedURL, contentDisposition, |
1291 "", // referrer-charset | 1293 "", // referrer-charset |
1292 "", // suggested-name | 1294 "", // suggested-name |
1293 "application/pdf", // mime-type | 1295 "application/pdf", // mime-type |
1294 defaultFilename); | 1296 defaultFilename); |
1295 [[self openInController] | 1297 [[self openInController] |
1296 enableWithDocumentURL:self.url | 1298 enableWithDocumentURL:committedURL |
1297 suggestedFilename:base::SysUTF16ToNSString(filename)]; | 1299 suggestedFilename:base::SysUTF16ToNSString(filename)]; |
1298 } | 1300 } |
1299 | 1301 |
1300 - (void)countMainFrameLoad { | 1302 - (void)countMainFrameLoad { |
1301 if ([self isPrerenderTab] || [self url].SchemeIs(kChromeUIScheme)) { | 1303 if ([self isPrerenderTab] || |
1304 self.lastCommittedURL.SchemeIs(kChromeUIScheme)) { | |
kkhorimoto
2017/04/14 21:05:16
If we're counting a main frame load, then we can a
| |
1302 return; | 1305 return; |
1303 } | 1306 } |
1304 base::RecordAction(UserMetricsAction("MobilePageLoaded")); | 1307 base::RecordAction(UserMetricsAction("MobilePageLoaded")); |
1305 } | 1308 } |
1306 | 1309 |
1307 - (void)applicationDidBecomeActive { | 1310 - (void)applicationDidBecomeActive { |
1308 if (requireReloadAfterBecomingActive_) { | 1311 if (requireReloadAfterBecomingActive_) { |
1309 if (visible_) { | 1312 if (visible_) { |
1310 self.navigationManager->Reload(web::ReloadType::NORMAL, | 1313 self.navigationManager->Reload(web::ReloadType::NORMAL, |
1311 false /* check_for_repost */); | 1314 false /* check_for_repost */); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1352 - (void)switchToReaderMode { | 1355 - (void)switchToReaderMode { |
1353 DCHECK(self.view); | 1356 DCHECK(self.view); |
1354 [self.readerModeController switchToReaderMode]; | 1357 [self.readerModeController switchToReaderMode]; |
1355 } | 1358 } |
1356 | 1359 |
1357 - (void)loadReaderModeHTML:(NSString*)html forURL:(const GURL&)url { | 1360 - (void)loadReaderModeHTML:(NSString*)html forURL:(const GURL&)url { |
1358 // Before changing the HTML on the current page, this checks that the URL has | 1361 // Before changing the HTML on the current page, this checks that the URL has |
1359 // not changed since reader mode was requested. This could happen for example | 1362 // not changed since reader mode was requested. This could happen for example |
1360 // if the page does a late redirect itself or if the user tapped on a link and | 1363 // if the page does a late redirect itself or if the user tapped on a link and |
1361 // triggered reader mode before the page load is detected by webState. | 1364 // triggered reader mode before the page load is detected by webState. |
1362 if (url == self.url) | 1365 if (url == self.visibleURL) |
kkhorimoto
2017/04/14 21:05:16
Reader mode HTML is loaded when a load is taking t
| |
1363 [self.webController loadHTMLForCurrentURL:html]; | 1366 [self.webController loadHTMLForCurrentURL:html]; |
1364 | 1367 |
1365 [self.readerModeController exitReaderMode]; | 1368 [self.readerModeController exitReaderMode]; |
1366 } | 1369 } |
1367 | 1370 |
1368 #pragma mark - | 1371 #pragma mark - |
1369 | 1372 |
1370 - (BOOL)usesDesktopUserAgent { | 1373 - (BOOL)usesDesktopUserAgent { |
1371 if (!self.navigationManager) | 1374 if (!self.navigationManager) |
1372 return NO; | 1375 return NO; |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1464 | 1467 |
1465 BOOL isUserNavigationEvent = | 1468 BOOL isUserNavigationEvent = |
1466 (transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK) == 0; | 1469 (transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK) == 0; |
1467 // Check for link-follow clobbers. These are changes where there is no | 1470 // Check for link-follow clobbers. These are changes where there is no |
1468 // pending entry (since that means the change wasn't caused by this class), | 1471 // pending entry (since that means the change wasn't caused by this class), |
1469 // and where the URL changes (to avoid counting page resurrection). | 1472 // and where the URL changes (to avoid counting page resurrection). |
1470 // TODO(crbug.com/546401): Consider moving this into NavigationManager, or | 1473 // TODO(crbug.com/546401): Consider moving this into NavigationManager, or |
1471 // into a NavigationManager observer callback, so it doesn't need to be | 1474 // into a NavigationManager observer callback, so it doesn't need to be |
1472 // checked in several places. | 1475 // checked in several places. |
1473 if (isUserNavigationEvent && !isPrerenderTab_ && | 1476 if (isUserNavigationEvent && !isPrerenderTab_ && |
1474 ![self navigationManager]->GetPendingItem() && url != self.url) { | 1477 ![self navigationManager]->GetPendingItem() && url != self.visibleURL) { |
1475 base::RecordAction(UserMetricsAction("MobileTabClobbered")); | 1478 base::RecordAction(UserMetricsAction("MobileTabClobbered")); |
1476 if ([parentTabModel_ tabUsageRecorder]) | 1479 if ([parentTabModel_ tabUsageRecorder]) |
1477 [parentTabModel_ tabUsageRecorder]->RecordPageLoadStart(self); | 1480 [parentTabModel_ tabUsageRecorder]->RecordPageLoadStart(self); |
1478 } | 1481 } |
1479 if (![self navigationManager]->GetPendingItem()) { | 1482 if (![self navigationManager]->GetPendingItem()) { |
1480 // Reset |isVoiceSearchResultsTab| since a new page is being navigated to. | 1483 // Reset |isVoiceSearchResultsTab| since a new page is being navigated to. |
1481 self.isVoiceSearchResultsTab = NO; | 1484 self.isVoiceSearchResultsTab = NO; |
1482 } | 1485 } |
1483 } | 1486 } |
1484 | 1487 |
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1988 | 1991 |
1989 - (TabModel*)parentTabModel { | 1992 - (TabModel*)parentTabModel { |
1990 return parentTabModel_; | 1993 return parentTabModel_; |
1991 } | 1994 } |
1992 | 1995 |
1993 - (FormInputAccessoryViewController*)inputAccessoryViewController { | 1996 - (FormInputAccessoryViewController*)inputAccessoryViewController { |
1994 return inputAccessoryViewController_.get(); | 1997 return inputAccessoryViewController_.get(); |
1995 } | 1998 } |
1996 | 1999 |
1997 @end | 2000 @end |
OLD | NEW |