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/chrome/browser/ui/browser_view_controller.h" | 5 #import "ios/chrome/browser/ui/browser_view_controller.h" |
| 6 | 6 |
| 7 #import <AssetsLibrary/AssetsLibrary.h> | 7 #import <AssetsLibrary/AssetsLibrary.h> |
| 8 #import <MobileCoreServices/MobileCoreServices.h> | 8 #import <MobileCoreServices/MobileCoreServices.h> |
| 9 #import <PassKit/PassKit.h> | 9 #import <PassKit/PassKit.h> |
| 10 #import <Photos/Photos.h> | 10 #import <Photos/Photos.h> |
| (...skipping 1088 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1099 Tab* tab = [_model currentTab]; | 1099 Tab* tab = [_model currentTab]; |
| 1100 if ([self isTabNativePage:tab]) | 1100 if ([self isTabNativePage:tab]) |
| 1101 return NO; | 1101 return NO; |
| 1102 | 1102 |
| 1103 // If |useDesktopUserAgent| is |NO|, allow useDesktopUserAgent. | 1103 // If |useDesktopUserAgent| is |NO|, allow useDesktopUserAgent. |
| 1104 return !tab.usesDesktopUserAgent; | 1104 return !tab.usesDesktopUserAgent; |
| 1105 } | 1105 } |
| 1106 | 1106 |
| 1107 // Whether the sharing menu should be shown. | 1107 // Whether the sharing menu should be shown. |
| 1108 - (BOOL)canShowShareMenu { | 1108 - (BOOL)canShowShareMenu { |
| 1109 Tab* tab = [_model currentTab]; | 1109 const GURL& URL = [_model currentTab].lastCommittedURL; |
| 1110 // TODO(shreyasv): Make it so the URL returned by the tab is always valid and | 1110 return URL.is_valid() && !web::GetWebClient()->IsAppSpecificURL(URL); |
|
kkhorimoto
2017/04/14 18:48:19
We want to share based on the visible content, so
Eugene But (OOO till 7-30)
2017/04/14 21:18:24
This matches with adding bookmark functionality, s
| |
| 1111 // remove check on net::NSURLWithGURL(tab.url) ( http://crbug.com/400999 ). | |
| 1112 return tab && !tab.url.SchemeIs(kChromeUIScheme) && | |
| 1113 net::NSURLWithGURL(tab.url); | |
| 1114 } | 1111 } |
| 1115 | 1112 |
| 1116 - (BOOL)canShowFindBar { | 1113 - (BOOL)canShowFindBar { |
| 1117 // Make sure web controller can handle find in page. | 1114 // Make sure web controller can handle find in page. |
| 1118 Tab* tab = [_model currentTab]; | 1115 Tab* tab = [_model currentTab]; |
| 1119 if (!tab) { | 1116 if (!tab) { |
| 1120 return NO; | 1117 return NO; |
| 1121 } | 1118 } |
| 1122 | 1119 |
| 1123 auto* helper = FindTabHelper::FromWebState(tab.webState); | 1120 auto* helper = FindTabHelper::FromWebState(tab.webState); |
| (...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1582 [self startVoiceSearch]; | 1579 [self startVoiceSearch]; |
| 1583 } | 1580 } |
| 1584 }; | 1581 }; |
| 1585 | 1582 |
| 1586 self.inNewTabAnimation = YES; | 1583 self.inNewTabAnimation = YES; |
| 1587 if (!inBackground) { | 1584 if (!inBackground) { |
| 1588 UIView* animationParentView = _contentArea; | 1585 UIView* animationParentView = _contentArea; |
| 1589 // Create the new page image, and load with the new tab page snapshot. | 1586 // Create the new page image, and load with the new tab page snapshot. |
| 1590 CGFloat newPageOffset = 0; | 1587 CGFloat newPageOffset = 0; |
| 1591 UIImageView* newPage; | 1588 UIImageView* newPage; |
| 1592 if (tab.url == GURL(kChromeUINewTabURL) && !_isOffTheRecord && | 1589 if (tab.lastCommittedURL == GURL(kChromeUINewTabURL) && !_isOffTheRecord && |
|
kkhorimoto
2017/04/14 18:48:19
If a Tab was just added, it's either a new tab, a
Eugene But (OOO till 7-30)
2017/04/14 21:18:25
In the worst case this will only be a cosmetic bug
| |
| 1593 !IsIPadIdiom()) { | 1590 !IsIPadIdiom()) { |
| 1594 animationParentView = self.view; | 1591 animationParentView = self.view; |
| 1595 newPage = [self pageFullScreenOpenCloseAnimationView]; | 1592 newPage = [self pageFullScreenOpenCloseAnimationView]; |
| 1596 } else { | 1593 } else { |
| 1597 newPage = [self pageOpenCloseAnimationView]; | 1594 newPage = [self pageOpenCloseAnimationView]; |
| 1598 } | 1595 } |
| 1599 newPageOffset = newPage.frame.origin.y; | 1596 newPageOffset = newPage.frame.origin.y; |
| 1600 | 1597 |
| 1601 [tab view].frame = _contentArea.bounds; | 1598 [tab view].frame = _contentArea.bounds; |
| 1602 newPage.image = [tab updateSnapshotWithOverlay:YES visibleFrameOnly:YES]; | 1599 newPage.image = [tab updateSnapshotWithOverlay:YES visibleFrameOnly:YES]; |
| (...skipping 920 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2523 params:params]; | 2520 params:params]; |
| 2524 | 2521 |
| 2525 NSString* title = nil; | 2522 NSString* title = nil; |
| 2526 ProceduralBlock action = nil; | 2523 ProceduralBlock action = nil; |
| 2527 | 2524 |
| 2528 __weak BrowserViewController* weakSelf = self; | 2525 __weak BrowserViewController* weakSelf = self; |
| 2529 GURL link = params.link_url; | 2526 GURL link = params.link_url; |
| 2530 bool isLink = link.is_valid(); | 2527 bool isLink = link.is_valid(); |
| 2531 GURL imageUrl = params.src_url; | 2528 GURL imageUrl = params.src_url; |
| 2532 bool isImage = imageUrl.is_valid(); | 2529 bool isImage = imageUrl.is_valid(); |
| 2530 const GURL& committedURL = [_model currentTab].lastCommittedURL; | |
|
kkhorimoto
2017/04/14 18:48:19
Context menu is specific to visible content, so co
Eugene But (OOO till 7-30)
2017/04/14 21:18:25
This change fixes a bug.
| |
| 2533 | 2531 |
| 2534 if (isLink) { | 2532 if (isLink) { |
| 2535 if (link.SchemeIs(url::kJavaScriptScheme)) { | 2533 if (link.SchemeIs(url::kJavaScriptScheme)) { |
| 2536 // Open | 2534 // Open |
| 2537 title = l10n_util::GetNSStringWithFixup(IDS_IOS_CONTENT_CONTEXT_OPEN); | 2535 title = l10n_util::GetNSStringWithFixup(IDS_IOS_CONTENT_CONTEXT_OPEN); |
| 2538 action = ^{ | 2536 action = ^{ |
| 2539 Record(ACTION_OPEN_JAVASCRIPT, isImage, isLink); | 2537 Record(ACTION_OPEN_JAVASCRIPT, isImage, isLink); |
| 2540 [weakSelf openJavascript:base::SysUTF8ToNSString(link.GetContent())]; | 2538 [weakSelf openJavascript:base::SysUTF8ToNSString(link.GetContent())]; |
| 2541 }; | 2539 }; |
| 2542 [_contextMenuCoordinator addItemWithTitle:title action:action]; | 2540 [_contextMenuCoordinator addItemWithTitle:title action:action]; |
| 2543 } | 2541 } |
| 2544 | 2542 |
| 2545 if (web::UrlHasWebScheme(link)) { | 2543 if (web::UrlHasWebScheme(link)) { |
| 2546 web::Referrer referrer([_model currentTab].url, params.referrer_policy); | 2544 web::Referrer referrer(committedURL, params.referrer_policy); |
| 2547 | 2545 |
| 2548 // Open in New Tab. | 2546 // Open in New Tab. |
| 2549 title = l10n_util::GetNSStringWithFixup( | 2547 title = l10n_util::GetNSStringWithFixup( |
| 2550 IDS_IOS_CONTENT_CONTEXT_OPENLINKNEWTAB); | 2548 IDS_IOS_CONTENT_CONTEXT_OPENLINKNEWTAB); |
| 2551 action = ^{ | 2549 action = ^{ |
| 2552 Record(ACTION_OPEN_IN_NEW_TAB, isImage, isLink); | 2550 Record(ACTION_OPEN_IN_NEW_TAB, isImage, isLink); |
| 2553 [weakSelf webPageOrderedOpen:link | 2551 [weakSelf webPageOrderedOpen:link |
| 2554 referrer:referrer | 2552 referrer:referrer |
| 2555 inBackground:YES | 2553 inBackground:YES |
| 2556 appendTo:kCurrentTab]; | 2554 appendTo:kCurrentTab]; |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 2586 } | 2584 } |
| 2587 // Copy Link. | 2585 // Copy Link. |
| 2588 title = l10n_util::GetNSStringWithFixup(IDS_IOS_CONTENT_CONTEXT_COPY); | 2586 title = l10n_util::GetNSStringWithFixup(IDS_IOS_CONTENT_CONTEXT_COPY); |
| 2589 action = ^{ | 2587 action = ^{ |
| 2590 Record(ACTION_COPY_LINK_ADDRESS, isImage, isLink); | 2588 Record(ACTION_COPY_LINK_ADDRESS, isImage, isLink); |
| 2591 StoreURLInPasteboard(link); | 2589 StoreURLInPasteboard(link); |
| 2592 }; | 2590 }; |
| 2593 [_contextMenuCoordinator addItemWithTitle:title action:action]; | 2591 [_contextMenuCoordinator addItemWithTitle:title action:action]; |
| 2594 } | 2592 } |
| 2595 if (isImage) { | 2593 if (isImage) { |
| 2596 web::Referrer referrer([_model currentTab].url, params.referrer_policy); | 2594 web::Referrer referrer(committedURL, params.referrer_policy); |
| 2597 // Save Image. | 2595 // Save Image. |
| 2598 if (experimental_flags::IsDownloadRenamingEnabled()) { | 2596 if (experimental_flags::IsDownloadRenamingEnabled()) { |
| 2599 title = l10n_util::GetNSStringWithFixup( | 2597 title = l10n_util::GetNSStringWithFixup( |
| 2600 IDS_IOS_CONTENT_CONTEXT_DOWNLOADIMAGE); | 2598 IDS_IOS_CONTENT_CONTEXT_DOWNLOADIMAGE); |
| 2601 } else { | 2599 } else { |
| 2602 title = | 2600 title = |
| 2603 l10n_util::GetNSStringWithFixup(IDS_IOS_CONTENT_CONTEXT_SAVEIMAGE); | 2601 l10n_util::GetNSStringWithFixup(IDS_IOS_CONTENT_CONTEXT_SAVEIMAGE); |
| 2604 } | 2602 } |
| 2605 action = ^{ | 2603 action = ^{ |
| 2606 Record(ACTION_SAVE_IMAGE, isImage, isLink); | 2604 Record(ACTION_SAVE_IMAGE, isImage, isLink); |
| (...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3111 // controller of the appropriate type vended to it (occurs when a native | 3109 // controller of the appropriate type vended to it (occurs when a native |
| 3112 // controller is opened in a new tab from a tab with a matching URL, e.g. | 3110 // controller is opened in a new tab from a tab with a matching URL, e.g. |
| 3113 // opening an NTP when an NTP is already displayed in the current tab). | 3111 // opening an NTP when an NTP is already displayed in the current tab). |
| 3114 // For normal page loads, history navigations, tab restorations, and crash | 3112 // For normal page loads, history navigations, tab restorations, and crash |
| 3115 // recoveries, the tab will already exist in the tab model and the tabId can | 3113 // recoveries, the tab will already exist in the tab model and the tabId can |
| 3116 // be used as the native controller key. | 3114 // be used as the native controller key. |
| 3117 // TODO(crbug.com/498568): To reduce complexity here, refactor the flow so | 3115 // TODO(crbug.com/498568): To reduce complexity here, refactor the flow so |
| 3118 // that native controllers vended here always correspond to the current tab. | 3116 // that native controllers vended here always correspond to the current tab. |
| 3119 Tab* currentTab = [_model currentTab]; | 3117 Tab* currentTab = [_model currentTab]; |
| 3120 NSString* nativeControllerKey = currentTab.tabId; | 3118 NSString* nativeControllerKey = currentTab.tabId; |
| 3121 if (!currentTab || currentTab.url != url || | 3119 if (!currentTab || currentTab.lastCommittedURL != url || |
|
kkhorimoto
2017/04/14 18:48:18
Native URLs are never pending, so last committed i
Eugene But (OOO till 7-30)
2017/04/14 21:18:25
Do you want to use webState->GetLastCommmittedURL?
| |
| 3122 [[_nativeControllersForTabIDs objectForKey:nativeControllerKey] | 3120 [[_nativeControllersForTabIDs objectForKey:nativeControllerKey] |
| 3123 isKindOfClass:[nativeController class]]) { | 3121 isKindOfClass:[nativeController class]]) { |
| 3124 nativeControllerKey = kNativeControllerTemporaryKey; | 3122 nativeControllerKey = kNativeControllerTemporaryKey; |
| 3125 } | 3123 } |
| 3126 DCHECK(nativeControllerKey); | 3124 DCHECK(nativeControllerKey); |
| 3127 [_nativeControllersForTabIDs setObject:nativeController | 3125 [_nativeControllersForTabIDs setObject:nativeController |
| 3128 forKey:nativeControllerKey]; | 3126 forKey:nativeControllerKey]; |
| 3129 return nativeController; | 3127 return nativeController; |
| 3130 } | 3128 } |
| 3131 | 3129 |
| (...skipping 1333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4465 __weak BrowserViewController* weakSelf = self; | 4463 __weak BrowserViewController* weakSelf = self; |
| 4466 web::JavaScriptResultBlock completionHandlerBlock = ^(id result, NSError*) { | 4464 web::JavaScriptResultBlock completionHandlerBlock = ^(id result, NSError*) { |
| 4467 Tab* strongTab = weakTab; | 4465 Tab* strongTab = weakTab; |
| 4468 if (!strongTab) | 4466 if (!strongTab) |
| 4469 return; | 4467 return; |
| 4470 if (![result isKindOfClass:[NSString class]]) | 4468 if (![result isKindOfClass:[NSString class]]) |
| 4471 result = @"Not an HTML page"; | 4469 result = @"Not an HTML page"; |
| 4472 std::string base64HTML; | 4470 std::string base64HTML; |
| 4473 base::Base64Encode(base::SysNSStringToUTF8(result), &base64HTML); | 4471 base::Base64Encode(base::SysNSStringToUTF8(result), &base64HTML); |
| 4474 GURL URL(std::string("data:text/plain;charset=utf-8;base64,") + base64HTML); | 4472 GURL URL(std::string("data:text/plain;charset=utf-8;base64,") + base64HTML); |
| 4475 web::Referrer referrer([strongTab url], web::ReferrerPolicyDefault); | 4473 web::Referrer referrer([strongTab lastCommittedURL], |
|
kkhorimoto
2017/04/14 18:48:18
View source is specific to visible content, so las
Eugene But (OOO till 7-30)
2017/04/14 21:18:25
Looks correct, and this is also debug-only feature
| |
| 4474 web::ReferrerPolicyDefault); | |
| 4476 | 4475 |
| 4477 [[weakSelf tabModel] | 4476 [[weakSelf tabModel] |
| 4478 insertTabWithURL:URL | 4477 insertTabWithURL:URL |
| 4479 referrer:referrer | 4478 referrer:referrer |
| 4480 transition:ui::PAGE_TRANSITION_LINK | 4479 transition:ui::PAGE_TRANSITION_LINK |
| 4481 opener:strongTab | 4480 opener:strongTab |
| 4482 openedByDOM:YES | 4481 openedByDOM:YES |
| 4483 atIndex:TabModelConstants::kTabPositionAutomatically | 4482 atIndex:TabModelConstants::kTabPositionAutomatically |
| 4484 inBackground:NO]; | 4483 inBackground:NO]; |
| 4485 }; | 4484 }; |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 4512 | 4511 |
| 4513 #pragma mark - ToolbarOwner | 4512 #pragma mark - ToolbarOwner |
| 4514 | 4513 |
| 4515 - (ToolbarController*)relinquishedToolbarController { | 4514 - (ToolbarController*)relinquishedToolbarController { |
| 4516 if (_isToolbarControllerRelinquished) | 4515 if (_isToolbarControllerRelinquished) |
| 4517 return nil; | 4516 return nil; |
| 4518 | 4517 |
| 4519 ToolbarController* relinquishedToolbarController = nil; | 4518 ToolbarController* relinquishedToolbarController = nil; |
| 4520 if ([_toolbarController view].hidden) { | 4519 if ([_toolbarController view].hidden) { |
| 4521 Tab* currentTab = [_model currentTab]; | 4520 Tab* currentTab = [_model currentTab]; |
| 4522 if (currentTab && UrlHasChromeScheme(currentTab.url)) { | 4521 if (currentTab && UrlHasChromeScheme(currentTab.lastCommittedURL)) { |
|
kkhorimoto
2017/04/14 18:48:19
chrome:// scheme URLs are never pending, so last c
Eugene But (OOO till 7-30)
2017/04/14 21:18:24
I think WebUI URLs can be pending.
rohitrao (ping after 24h)
2017/05/09 15:18:38
NTP is the only native page that's a ToolbarOwner,
kkhorimoto
2017/05/31 21:53:42
The toolbar visibility is updated when a navigatio
| |
| 4523 // Use the native content controller's toolbar when the BVC's is hidden. | 4522 // Use the native content controller's toolbar when the BVC's is hidden. |
| 4524 id nativeController = [self nativeControllerForTab:currentTab]; | 4523 id nativeController = [self nativeControllerForTab:currentTab]; |
| 4525 if ([nativeController conformsToProtocol:@protocol(ToolbarOwner)]) { | 4524 if ([nativeController conformsToProtocol:@protocol(ToolbarOwner)]) { |
| 4526 relinquishedToolbarController = | 4525 relinquishedToolbarController = |
| 4527 [nativeController relinquishedToolbarController]; | 4526 [nativeController relinquishedToolbarController]; |
| 4528 _relinquishedToolbarOwner = nativeController; | 4527 _relinquishedToolbarOwner = nativeController; |
| 4529 } | 4528 } |
| 4530 } | 4529 } |
| 4531 } else { | 4530 } else { |
| 4532 relinquishedToolbarController = _toolbarController; | 4531 relinquishedToolbarController = _toolbarController; |
| (...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4967 | 4966 |
| 4968 - (BOOL)shouldUseDesktopUserAgent { | 4967 - (BOOL)shouldUseDesktopUserAgent { |
| 4969 return [_model currentTab].usesDesktopUserAgent; | 4968 return [_model currentTab].usesDesktopUserAgent; |
| 4970 } | 4969 } |
| 4971 | 4970 |
| 4972 #pragma mark - BookmarkBridgeMethods | 4971 #pragma mark - BookmarkBridgeMethods |
| 4973 | 4972 |
| 4974 // If an added or removed bookmark is the same as the current url, update the | 4973 // If an added or removed bookmark is the same as the current url, update the |
| 4975 // toolbar so the star highlight is kept in sync. | 4974 // toolbar so the star highlight is kept in sync. |
| 4976 - (void)bookmarkNodeModified:(const BookmarkNode*)node { | 4975 - (void)bookmarkNodeModified:(const BookmarkNode*)node { |
| 4977 if ([_model currentTab] && node->url() == [_model currentTab].url) | 4976 if ([_model currentTab] && |
| 4977 node->url() == [_model currentTab].lastCommittedURL) { | |
|
kkhorimoto
2017/04/14 18:48:19
Depends on what we decide for https://codereview.c
Eugene But (OOO till 7-30)
2017/04/14 21:18:24
This matches Desktop, so should be fine.
| |
| 4978 [self updateToolbar]; | 4978 [self updateToolbar]; |
| 4979 } | |
| 4979 } | 4980 } |
| 4980 | 4981 |
| 4981 // If all bookmarks are removed, update the toolbar so the star highlight is | 4982 // If all bookmarks are removed, update the toolbar so the star highlight is |
| 4982 // kept in sync. | 4983 // kept in sync. |
| 4983 - (void)allBookmarksRemoved { | 4984 - (void)allBookmarksRemoved { |
| 4984 [self updateToolbar]; | 4985 [self updateToolbar]; |
| 4985 } | 4986 } |
| 4986 | 4987 |
| 4987 #pragma mark - ShareToDelegate methods | 4988 #pragma mark - ShareToDelegate methods |
| 4988 | 4989 |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5173 | 5174 |
| 5174 - (UIView*)voiceSearchButton { | 5175 - (UIView*)voiceSearchButton { |
| 5175 return _voiceSearchButton; | 5176 return _voiceSearchButton; |
| 5176 } | 5177 } |
| 5177 | 5178 |
| 5178 - (id<LogoAnimationControllerOwner>)logoAnimationControllerOwner { | 5179 - (id<LogoAnimationControllerOwner>)logoAnimationControllerOwner { |
| 5179 return [self currentLogoAnimationControllerOwner]; | 5180 return [self currentLogoAnimationControllerOwner]; |
| 5180 } | 5181 } |
| 5181 | 5182 |
| 5182 @end | 5183 @end |
| OLD | NEW |