| 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 1095 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1106 Tab* tab = [_model currentTab]; | 1106 Tab* tab = [_model currentTab]; |
| 1107 if ([self isTabNativePage:tab]) | 1107 if ([self isTabNativePage:tab]) |
| 1108 return NO; | 1108 return NO; |
| 1109 | 1109 |
| 1110 // If |useDesktopUserAgent| is |NO|, allow useDesktopUserAgent. | 1110 // If |useDesktopUserAgent| is |NO|, allow useDesktopUserAgent. |
| 1111 return !tab.usesDesktopUserAgent; | 1111 return !tab.usesDesktopUserAgent; |
| 1112 } | 1112 } |
| 1113 | 1113 |
| 1114 // Whether the sharing menu should be shown. | 1114 // Whether the sharing menu should be shown. |
| 1115 - (BOOL)canShowShareMenu { | 1115 - (BOOL)canShowShareMenu { |
| 1116 Tab* tab = [_model currentTab]; | 1116 const GURL& URL = [_model currentTab].lastCommittedURL; |
| 1117 // TODO(shreyasv): Make it so the URL returned by the tab is always valid and | 1117 return URL.is_valid() && !web::GetWebClient()->IsAppSpecificURL(URL); |
| 1118 // remove check on net::NSURLWithGURL(tab.url) ( http://crbug.com/400999 ). | |
| 1119 return tab && !tab.url.SchemeIs(kChromeUIScheme) && | |
| 1120 net::NSURLWithGURL(tab.url); | |
| 1121 } | 1118 } |
| 1122 | 1119 |
| 1123 - (BOOL)canShowFindBar { | 1120 - (BOOL)canShowFindBar { |
| 1124 // Make sure web controller can handle find in page. | 1121 // Make sure web controller can handle find in page. |
| 1125 Tab* tab = [_model currentTab]; | 1122 Tab* tab = [_model currentTab]; |
| 1126 if (!tab) { | 1123 if (!tab) { |
| 1127 return NO; | 1124 return NO; |
| 1128 } | 1125 } |
| 1129 | 1126 |
| 1130 auto* helper = FindTabHelper::FromWebState(tab.webState); | 1127 auto* helper = FindTabHelper::FromWebState(tab.webState); |
| (...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1589 [self startVoiceSearch]; | 1586 [self startVoiceSearch]; |
| 1590 } | 1587 } |
| 1591 }; | 1588 }; |
| 1592 | 1589 |
| 1593 self.inNewTabAnimation = YES; | 1590 self.inNewTabAnimation = YES; |
| 1594 if (!inBackground) { | 1591 if (!inBackground) { |
| 1595 UIView* animationParentView = _contentArea; | 1592 UIView* animationParentView = _contentArea; |
| 1596 // Create the new page image, and load with the new tab page snapshot. | 1593 // Create the new page image, and load with the new tab page snapshot. |
| 1597 CGFloat newPageOffset = 0; | 1594 CGFloat newPageOffset = 0; |
| 1598 UIImageView* newPage; | 1595 UIImageView* newPage; |
| 1599 if (tab.url == GURL(kChromeUINewTabURL) && !_isOffTheRecord && | 1596 if (tab.lastCommittedURL == GURL(kChromeUINewTabURL) && !_isOffTheRecord && |
| 1600 !IsIPadIdiom()) { | 1597 !IsIPadIdiom()) { |
| 1601 animationParentView = self.view; | 1598 animationParentView = self.view; |
| 1602 newPage = [self pageFullScreenOpenCloseAnimationView]; | 1599 newPage = [self pageFullScreenOpenCloseAnimationView]; |
| 1603 } else { | 1600 } else { |
| 1604 newPage = [self pageOpenCloseAnimationView]; | 1601 newPage = [self pageOpenCloseAnimationView]; |
| 1605 } | 1602 } |
| 1606 newPageOffset = newPage.frame.origin.y; | 1603 newPageOffset = newPage.frame.origin.y; |
| 1607 | 1604 |
| 1608 [tab view].frame = _contentArea.bounds; | 1605 [tab view].frame = _contentArea.bounds; |
| 1609 newPage.image = [tab updateSnapshotWithOverlay:YES visibleFrameOnly:YES]; | 1606 newPage.image = [tab updateSnapshotWithOverlay:YES visibleFrameOnly:YES]; |
| (...skipping 928 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2538 params:params]; | 2535 params:params]; |
| 2539 | 2536 |
| 2540 NSString* title = nil; | 2537 NSString* title = nil; |
| 2541 ProceduralBlock action = nil; | 2538 ProceduralBlock action = nil; |
| 2542 | 2539 |
| 2543 __weak BrowserViewController* weakSelf = self; | 2540 __weak BrowserViewController* weakSelf = self; |
| 2544 GURL link = params.link_url; | 2541 GURL link = params.link_url; |
| 2545 bool isLink = link.is_valid(); | 2542 bool isLink = link.is_valid(); |
| 2546 GURL imageUrl = params.src_url; | 2543 GURL imageUrl = params.src_url; |
| 2547 bool isImage = imageUrl.is_valid(); | 2544 bool isImage = imageUrl.is_valid(); |
| 2545 const GURL& committedURL = [_model currentTab].lastCommittedURL; |
| 2548 | 2546 |
| 2549 if (isLink) { | 2547 if (isLink) { |
| 2550 if (link.SchemeIs(url::kJavaScriptScheme)) { | 2548 if (link.SchemeIs(url::kJavaScriptScheme)) { |
| 2551 // Open | 2549 // Open |
| 2552 title = l10n_util::GetNSStringWithFixup(IDS_IOS_CONTENT_CONTEXT_OPEN); | 2550 title = l10n_util::GetNSStringWithFixup(IDS_IOS_CONTENT_CONTEXT_OPEN); |
| 2553 action = ^{ | 2551 action = ^{ |
| 2554 Record(ACTION_OPEN_JAVASCRIPT, isImage, isLink); | 2552 Record(ACTION_OPEN_JAVASCRIPT, isImage, isLink); |
| 2555 [weakSelf openJavascript:base::SysUTF8ToNSString(link.GetContent())]; | 2553 [weakSelf openJavascript:base::SysUTF8ToNSString(link.GetContent())]; |
| 2556 }; | 2554 }; |
| 2557 [_contextMenuCoordinator addItemWithTitle:title action:action]; | 2555 [_contextMenuCoordinator addItemWithTitle:title action:action]; |
| 2558 } | 2556 } |
| 2559 | 2557 |
| 2560 if (web::UrlHasWebScheme(link)) { | 2558 if (web::UrlHasWebScheme(link)) { |
| 2561 web::Referrer referrer([_model currentTab].url, params.referrer_policy); | 2559 web::Referrer referrer(committedURL, params.referrer_policy); |
| 2562 | 2560 |
| 2563 // Open in New Tab. | 2561 // Open in New Tab. |
| 2564 title = l10n_util::GetNSStringWithFixup( | 2562 title = l10n_util::GetNSStringWithFixup( |
| 2565 IDS_IOS_CONTENT_CONTEXT_OPENLINKNEWTAB); | 2563 IDS_IOS_CONTENT_CONTEXT_OPENLINKNEWTAB); |
| 2566 action = ^{ | 2564 action = ^{ |
| 2567 Record(ACTION_OPEN_IN_NEW_TAB, isImage, isLink); | 2565 Record(ACTION_OPEN_IN_NEW_TAB, isImage, isLink); |
| 2568 [weakSelf webPageOrderedOpen:link | 2566 [weakSelf webPageOrderedOpen:link |
| 2569 referrer:referrer | 2567 referrer:referrer |
| 2570 inBackground:YES | 2568 inBackground:YES |
| 2571 appendTo:kCurrentTab]; | 2569 appendTo:kCurrentTab]; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 2601 } | 2599 } |
| 2602 // Copy Link. | 2600 // Copy Link. |
| 2603 title = l10n_util::GetNSStringWithFixup(IDS_IOS_CONTENT_CONTEXT_COPY); | 2601 title = l10n_util::GetNSStringWithFixup(IDS_IOS_CONTENT_CONTEXT_COPY); |
| 2604 action = ^{ | 2602 action = ^{ |
| 2605 Record(ACTION_COPY_LINK_ADDRESS, isImage, isLink); | 2603 Record(ACTION_COPY_LINK_ADDRESS, isImage, isLink); |
| 2606 StoreURLInPasteboard(link); | 2604 StoreURLInPasteboard(link); |
| 2607 }; | 2605 }; |
| 2608 [_contextMenuCoordinator addItemWithTitle:title action:action]; | 2606 [_contextMenuCoordinator addItemWithTitle:title action:action]; |
| 2609 } | 2607 } |
| 2610 if (isImage) { | 2608 if (isImage) { |
| 2611 web::Referrer referrer([_model currentTab].url, params.referrer_policy); | 2609 web::Referrer referrer(committedURL, params.referrer_policy); |
| 2612 // Save Image. | 2610 // Save Image. |
| 2613 title = l10n_util::GetNSStringWithFixup(IDS_IOS_CONTENT_CONTEXT_SAVEIMAGE); | 2611 title = l10n_util::GetNSStringWithFixup(IDS_IOS_CONTENT_CONTEXT_SAVEIMAGE); |
| 2614 action = ^{ | 2612 action = ^{ |
| 2615 Record(ACTION_SAVE_IMAGE, isImage, isLink); | 2613 Record(ACTION_SAVE_IMAGE, isImage, isLink); |
| 2616 [weakSelf saveImageAtURL:imageUrl referrer:referrer]; | 2614 [weakSelf saveImageAtURL:imageUrl referrer:referrer]; |
| 2617 }; | 2615 }; |
| 2618 [_contextMenuCoordinator addItemWithTitle:title action:action]; | 2616 [_contextMenuCoordinator addItemWithTitle:title action:action]; |
| 2619 // Open Image. | 2617 // Open Image. |
| 2620 title = l10n_util::GetNSStringWithFixup(IDS_IOS_CONTENT_CONTEXT_OPENIMAGE); | 2618 title = l10n_util::GetNSStringWithFixup(IDS_IOS_CONTENT_CONTEXT_OPENIMAGE); |
| 2621 action = ^{ | 2619 action = ^{ |
| (...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3108 // controller of the appropriate type vended to it (occurs when a native | 3106 // controller of the appropriate type vended to it (occurs when a native |
| 3109 // controller is opened in a new tab from a tab with a matching URL, e.g. | 3107 // controller is opened in a new tab from a tab with a matching URL, e.g. |
| 3110 // opening an NTP when an NTP is already displayed in the current tab). | 3108 // opening an NTP when an NTP is already displayed in the current tab). |
| 3111 // For normal page loads, history navigations, tab restorations, and crash | 3109 // For normal page loads, history navigations, tab restorations, and crash |
| 3112 // recoveries, the tab will already exist in the tab model and the tabId can | 3110 // recoveries, the tab will already exist in the tab model and the tabId can |
| 3113 // be used as the native controller key. | 3111 // be used as the native controller key. |
| 3114 // TODO(crbug.com/498568): To reduce complexity here, refactor the flow so | 3112 // TODO(crbug.com/498568): To reduce complexity here, refactor the flow so |
| 3115 // that native controllers vended here always correspond to the current tab. | 3113 // that native controllers vended here always correspond to the current tab. |
| 3116 Tab* currentTab = [_model currentTab]; | 3114 Tab* currentTab = [_model currentTab]; |
| 3117 NSString* nativeControllerKey = currentTab.tabId; | 3115 NSString* nativeControllerKey = currentTab.tabId; |
| 3118 if (!currentTab || currentTab.url != url || | 3116 if (!currentTab || currentTab.lastCommittedURL != url || |
| 3119 [[_nativeControllersForTabIDs objectForKey:nativeControllerKey] | 3117 [[_nativeControllersForTabIDs objectForKey:nativeControllerKey] |
| 3120 isKindOfClass:[nativeController class]]) { | 3118 isKindOfClass:[nativeController class]]) { |
| 3121 nativeControllerKey = kNativeControllerTemporaryKey; | 3119 nativeControllerKey = kNativeControllerTemporaryKey; |
| 3122 } | 3120 } |
| 3123 DCHECK(nativeControllerKey); | 3121 DCHECK(nativeControllerKey); |
| 3124 [_nativeControllersForTabIDs setObject:nativeController | 3122 [_nativeControllersForTabIDs setObject:nativeController |
| 3125 forKey:nativeControllerKey]; | 3123 forKey:nativeControllerKey]; |
| 3126 return nativeController; | 3124 return nativeController; |
| 3127 } | 3125 } |
| 3128 | 3126 |
| (...skipping 1339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4468 __weak BrowserViewController* weakSelf = self; | 4466 __weak BrowserViewController* weakSelf = self; |
| 4469 web::JavaScriptResultBlock completionHandlerBlock = ^(id result, NSError*) { | 4467 web::JavaScriptResultBlock completionHandlerBlock = ^(id result, NSError*) { |
| 4470 Tab* strongTab = weakTab; | 4468 Tab* strongTab = weakTab; |
| 4471 if (!strongTab) | 4469 if (!strongTab) |
| 4472 return; | 4470 return; |
| 4473 if (![result isKindOfClass:[NSString class]]) | 4471 if (![result isKindOfClass:[NSString class]]) |
| 4474 result = @"Not an HTML page"; | 4472 result = @"Not an HTML page"; |
| 4475 std::string base64HTML; | 4473 std::string base64HTML; |
| 4476 base::Base64Encode(base::SysNSStringToUTF8(result), &base64HTML); | 4474 base::Base64Encode(base::SysNSStringToUTF8(result), &base64HTML); |
| 4477 GURL URL(std::string("data:text/plain;charset=utf-8;base64,") + base64HTML); | 4475 GURL URL(std::string("data:text/plain;charset=utf-8;base64,") + base64HTML); |
| 4478 web::Referrer referrer([strongTab url], web::ReferrerPolicyDefault); | 4476 web::Referrer referrer([strongTab lastCommittedURL], |
| 4477 web::ReferrerPolicyDefault); |
| 4479 | 4478 |
| 4480 [[weakSelf tabModel] | 4479 [[weakSelf tabModel] |
| 4481 insertTabWithURL:URL | 4480 insertTabWithURL:URL |
| 4482 referrer:referrer | 4481 referrer:referrer |
| 4483 transition:ui::PAGE_TRANSITION_LINK | 4482 transition:ui::PAGE_TRANSITION_LINK |
| 4484 opener:strongTab | 4483 opener:strongTab |
| 4485 openedByDOM:YES | 4484 openedByDOM:YES |
| 4486 atIndex:TabModelConstants::kTabPositionAutomatically | 4485 atIndex:TabModelConstants::kTabPositionAutomatically |
| 4487 inBackground:NO]; | 4486 inBackground:NO]; |
| 4488 }; | 4487 }; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 4515 | 4514 |
| 4516 #pragma mark - ToolbarOwner | 4515 #pragma mark - ToolbarOwner |
| 4517 | 4516 |
| 4518 - (ToolbarController*)relinquishedToolbarController { | 4517 - (ToolbarController*)relinquishedToolbarController { |
| 4519 if (_isToolbarControllerRelinquished) | 4518 if (_isToolbarControllerRelinquished) |
| 4520 return nil; | 4519 return nil; |
| 4521 | 4520 |
| 4522 ToolbarController* relinquishedToolbarController = nil; | 4521 ToolbarController* relinquishedToolbarController = nil; |
| 4523 if ([_toolbarController view].hidden) { | 4522 if ([_toolbarController view].hidden) { |
| 4524 Tab* currentTab = [_model currentTab]; | 4523 Tab* currentTab = [_model currentTab]; |
| 4525 if (currentTab && UrlHasChromeScheme(currentTab.url)) { | 4524 if (currentTab && UrlHasChromeScheme(currentTab.lastCommittedURL)) { |
| 4526 // Use the native content controller's toolbar when the BVC's is hidden. | 4525 // Use the native content controller's toolbar when the BVC's is hidden. |
| 4527 id nativeController = [self nativeControllerForTab:currentTab]; | 4526 id nativeController = [self nativeControllerForTab:currentTab]; |
| 4528 if ([nativeController conformsToProtocol:@protocol(ToolbarOwner)]) { | 4527 if ([nativeController conformsToProtocol:@protocol(ToolbarOwner)]) { |
| 4529 relinquishedToolbarController = | 4528 relinquishedToolbarController = |
| 4530 [nativeController relinquishedToolbarController]; | 4529 [nativeController relinquishedToolbarController]; |
| 4531 _relinquishedToolbarOwner = nativeController; | 4530 _relinquishedToolbarOwner = nativeController; |
| 4532 } | 4531 } |
| 4533 } | 4532 } |
| 4534 } else { | 4533 } else { |
| 4535 relinquishedToolbarController = _toolbarController; | 4534 relinquishedToolbarController = _toolbarController; |
| (...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4975 | 4974 |
| 4976 - (BOOL)shouldUseDesktopUserAgent { | 4975 - (BOOL)shouldUseDesktopUserAgent { |
| 4977 return [_model currentTab].usesDesktopUserAgent; | 4976 return [_model currentTab].usesDesktopUserAgent; |
| 4978 } | 4977 } |
| 4979 | 4978 |
| 4980 #pragma mark - BookmarkBridgeMethods | 4979 #pragma mark - BookmarkBridgeMethods |
| 4981 | 4980 |
| 4982 // If an added or removed bookmark is the same as the current url, update the | 4981 // If an added or removed bookmark is the same as the current url, update the |
| 4983 // toolbar so the star highlight is kept in sync. | 4982 // toolbar so the star highlight is kept in sync. |
| 4984 - (void)bookmarkNodeModified:(const BookmarkNode*)node { | 4983 - (void)bookmarkNodeModified:(const BookmarkNode*)node { |
| 4985 if ([_model currentTab] && node->url() == [_model currentTab].url) | 4984 if ([_model currentTab] && |
| 4985 node->url() == [_model currentTab].lastCommittedURL) { |
| 4986 [self updateToolbar]; | 4986 [self updateToolbar]; |
| 4987 } |
| 4987 } | 4988 } |
| 4988 | 4989 |
| 4989 // If all bookmarks are removed, update the toolbar so the star highlight is | 4990 // If all bookmarks are removed, update the toolbar so the star highlight is |
| 4990 // kept in sync. | 4991 // kept in sync. |
| 4991 - (void)allBookmarksRemoved { | 4992 - (void)allBookmarksRemoved { |
| 4992 [self updateToolbar]; | 4993 [self updateToolbar]; |
| 4993 } | 4994 } |
| 4994 | 4995 |
| 4995 #pragma mark - ShareToDelegate methods | 4996 #pragma mark - ShareToDelegate methods |
| 4996 | 4997 |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5181 | 5182 |
| 5182 - (UIView*)voiceSearchButton { | 5183 - (UIView*)voiceSearchButton { |
| 5183 return _voiceSearchButton; | 5184 return _voiceSearchButton; |
| 5184 } | 5185 } |
| 5185 | 5186 |
| 5186 - (id<LogoAnimationControllerOwner>)logoAnimationControllerOwner { | 5187 - (id<LogoAnimationControllerOwner>)logoAnimationControllerOwner { |
| 5187 return [self currentLogoAnimationControllerOwner]; | 5188 return [self currentLogoAnimationControllerOwner]; |
| 5188 } | 5189 } |
| 5189 | 5190 |
| 5190 @end | 5191 @end |
| OLD | NEW |