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 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 509 // The browser's preload controller. | 509 // The browser's preload controller. |
| 510 @property(nonatomic, retain, readonly) PreloadController* preloadController; | 510 @property(nonatomic, retain, readonly) PreloadController* preloadController; |
| 511 // The dialog presenter for this BVC's tab model. | 511 // The dialog presenter for this BVC's tab model. |
| 512 @property(nonatomic, retain, readonly) DialogPresenter* dialogPresenter; | 512 @property(nonatomic, retain, readonly) DialogPresenter* dialogPresenter; |
| 513 // The object that manages keyboard commands on behalf of the BVC. | 513 // The object that manages keyboard commands on behalf of the BVC. |
| 514 @property(nonatomic, retain, readonly) KeyCommandsProvider* keyCommandsProvider; | 514 @property(nonatomic, retain, readonly) KeyCommandsProvider* keyCommandsProvider; |
| 515 // Whether the current tab can enable the reader mode menu item. | 515 // Whether the current tab can enable the reader mode menu item. |
| 516 @property(nonatomic, assign, readonly) BOOL canUseReaderMode; | 516 @property(nonatomic, assign, readonly) BOOL canUseReaderMode; |
| 517 // Whether the current tab can enable the request desktop menu item. | 517 // Whether the current tab can enable the request desktop menu item. |
| 518 @property(nonatomic, assign, readonly) BOOL canUseDesktopUserAgent; | 518 @property(nonatomic, assign, readonly) BOOL canUseDesktopUserAgent; |
| 519 // Whether the current tab can enable the request mobile menu item. | |
| 520 @property(nonatomic, assign, readonly) BOOL canUseMobileUserAgent; | |
| 519 // Whether the sharing menu should be enabled. | 521 // Whether the sharing menu should be enabled. |
| 520 @property(nonatomic, assign, readonly) BOOL canShowShareMenu; | 522 @property(nonatomic, assign, readonly) BOOL canShowShareMenu; |
| 521 // Helper method to check web controller canShowFindBar method. | 523 // Helper method to check web controller canShowFindBar method. |
| 522 @property(nonatomic, assign, readonly) BOOL canShowFindBar; | 524 @property(nonatomic, assign, readonly) BOOL canShowFindBar; |
| 523 // Whether the controller's view is currently available. | 525 // Whether the controller's view is currently available. |
| 524 // YES from viewWillAppear to viewWillDisappear. | 526 // YES from viewWillAppear to viewWillDisappear. |
| 525 @property(nonatomic, assign, getter=isVisible) BOOL visible; | 527 @property(nonatomic, assign, getter=isVisible) BOOL visible; |
| 526 // Whether the controller's view is currently visible. | 528 // Whether the controller's view is currently visible. |
| 527 // YES from viewDidAppear to viewWillDisappear. | 529 // YES from viewDidAppear to viewWillDisappear. |
| 528 @property(nonatomic, assign) BOOL viewVisible; | 530 @property(nonatomic, assign) BOOL viewVisible; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 618 // Shows a panel within the New Tab Page. | 620 // Shows a panel within the New Tab Page. |
| 619 - (void)showNTPPanel:(NewTabPage::PanelIdentifier)panel; | 621 - (void)showNTPPanel:(NewTabPage::PanelIdentifier)panel; |
| 620 // Shows the "rate this app" dialog. | 622 // Shows the "rate this app" dialog. |
| 621 - (void)showRateThisAppDialog; | 623 - (void)showRateThisAppDialog; |
| 622 // Dismisses the "rate this app" dialog. | 624 // Dismisses the "rate this app" dialog. |
| 623 - (void)dismissRateThisAppDialog; | 625 - (void)dismissRateThisAppDialog; |
| 624 #if !defined(NDEBUG) | 626 #if !defined(NDEBUG) |
| 625 // Shows the source of the current page. | 627 // Shows the source of the current page. |
| 626 - (void)viewSource; | 628 - (void)viewSource; |
| 627 #endif | 629 #endif |
| 628 // Whether the given tab's url begins with the chrome prefix. | 630 |
| 629 - (BOOL)isTabNativePage:(Tab*)tab; | 631 // True if "Request Desktop Site" should be visible in tools menu, otherwise, |
| 632 // make "Request Mobile Site" visible. | |
| 633 - (BOOL)shouldShowRequestDesktopSite; | |
| 634 | |
| 635 // Whether the current tab is using desktop user agent. | |
| 636 - (BOOL)isCurrentTabUsingDesktopUserAgent; | |
| 637 | |
| 638 // Whether the current tab's url begins with the chrome prefix. | |
| 639 - (BOOL)isCurrentTabNativePage; | |
| 640 | |
| 630 // Returns the view to use when animating a page in or out, positioning it to | 641 // Returns the view to use when animating a page in or out, positioning it to |
| 631 // fill the content area but not actually adding it to the view hierarchy. | 642 // fill the content area but not actually adding it to the view hierarchy. |
| 632 - (UIImageView*)pageOpenCloseAnimationView; | 643 - (UIImageView*)pageOpenCloseAnimationView; |
| 633 // Returns the view to use when animating full screen NTP paper in, filling the | 644 // Returns the view to use when animating full screen NTP paper in, filling the |
| 634 // entire screen but not actually adding it to the view hierarchy. | 645 // entire screen but not actually adding it to the view hierarchy. |
| 635 - (UIImageView*)pageFullScreenOpenCloseAnimationView; | 646 - (UIImageView*)pageFullScreenOpenCloseAnimationView; |
| 636 // Updates the toolbar display based on the current tab. | 647 // Updates the toolbar display based on the current tab. |
| 637 - (void)updateToolbar; | 648 - (void)updateToolbar; |
| 638 // Updates |dialogPresenter|'s |active| property to account for the BVC's | 649 // Updates |dialogPresenter|'s |active| property to account for the BVC's |
| 639 // |active| and |visible| properties. | 650 // |active| and |visible| properties. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 676 // Adds a CardView on top of the contentArea either taking the size of the full | 687 // Adds a CardView on top of the contentArea either taking the size of the full |
| 677 // screen or just the size of the space under the header. | 688 // screen or just the size of the space under the header. |
| 678 // Returns the CardView that was added. | 689 // Returns the CardView that was added. |
| 679 - (CardView*)addCardViewInFullscreen:(BOOL)fullScreen; | 690 - (CardView*)addCardViewInFullscreen:(BOOL)fullScreen; |
| 680 // Called when either a tab finishes loading or when a tab with finished content | 691 // Called when either a tab finishes loading or when a tab with finished content |
| 681 // is added directly to the model via pre-rendering. The tab must be non-nil and | 692 // is added directly to the model via pre-rendering. The tab must be non-nil and |
| 682 // must be a member of the tab model controlled by this BrowserViewController. | 693 // must be a member of the tab model controlled by this BrowserViewController. |
| 683 - (void)tabLoadComplete:(Tab*)tab withSuccess:(BOOL)success; | 694 - (void)tabLoadComplete:(Tab*)tab withSuccess:(BOOL)success; |
| 684 // Evaluates Javascript asynchronously using the current page context. | 695 // Evaluates Javascript asynchronously using the current page context. |
| 685 - (void)openJavascript:(NSString*)javascript; | 696 - (void)openJavascript:(NSString*)javascript; |
| 697 | |
| 686 // Sets the desktop user agent flag and reload the current page. | 698 // Sets the desktop user agent flag and reload the current page. |
| 687 - (void)enableDesktopUserAgent; | 699 - (void)reloadPageWithDesktopUserAgent; |
| 700 | |
| 701 // Sets the mobile user agent flag and reload the current page. | |
| 702 - (void)reloadPageWithMobileUserAgent; | |
| 703 | |
| 688 // Helper methods used by ShareToDelegate methods. | 704 // Helper methods used by ShareToDelegate methods. |
| 689 // Shows an alert with the given title and message id. | 705 // Shows an alert with the given title and message id. |
| 690 - (void)showErrorAlert:(int)titleMessageId message:(int)messageId; | 706 - (void)showErrorAlert:(int)titleMessageId message:(int)messageId; |
| 691 // Helper method displaying an alert with the given title and message. | 707 // Helper method displaying an alert with the given title and message. |
| 692 // Dismisses previous alert if it has not been dismissed yet. | 708 // Dismisses previous alert if it has not been dismissed yet. |
| 693 - (void)showErrorAlertWithStringTitle:(NSString*)title | 709 - (void)showErrorAlertWithStringTitle:(NSString*)title |
| 694 message:(NSString*)message; | 710 message:(NSString*)message; |
| 695 // Shows a self-dismissing snackbar displaying |message|. | 711 // Shows a self-dismissing snackbar displaying |message|. |
| 696 - (void)showSnackbar:(NSString*)message; | 712 - (void)showSnackbar:(NSString*)message; |
| 697 // Induces an intentional crash in the browser process. | 713 // Induces an intentional crash in the browser process. |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1056 } | 1072 } |
| 1057 | 1073 |
| 1058 - (BOOL)canUseReaderMode { | 1074 - (BOOL)canUseReaderMode { |
| 1059 Tab* tab = [_model currentTab]; | 1075 Tab* tab = [_model currentTab]; |
| 1060 if ([self isTabNativePage:tab]) | 1076 if ([self isTabNativePage:tab]) |
| 1061 return NO; | 1077 return NO; |
| 1062 | 1078 |
| 1063 return [tab canSwitchToReaderMode]; | 1079 return [tab canSwitchToReaderMode]; |
| 1064 } | 1080 } |
| 1065 | 1081 |
| 1082 - (BOOL)shouldShowRequestDesktopSite { | |
| 1083 return [self isCurrentTabNativePage] || | |
| 1084 ![self isCurrentTabUsingDesktopUserAgent]; | |
| 1085 } | |
| 1086 | |
| 1066 - (BOOL)canUseDesktopUserAgent { | 1087 - (BOOL)canUseDesktopUserAgent { |
| 1067 Tab* tab = [_model currentTab]; | 1088 return ![self isCurrentTabNativePage] && |
| 1068 if ([self isTabNativePage:tab]) | 1089 ![self isCurrentTabUsingDesktopUserAgent]; |
| 1069 return NO; | 1090 } |
| 1070 | 1091 |
| 1071 // If |useDesktopUserAgent| is |NO|, allow useDesktopUserAgent. | 1092 - (BOOL)canUseMobileUserAgent { |
| 1072 return !tab.usesDesktopUserAgent; | 1093 return ![self isCurrentTabNativePage] && |
| 1094 [self isCurrentTabUsingDesktopUserAgent]; | |
| 1095 } | |
| 1096 | |
| 1097 - (BOOL)isCurrentTabNativePage { | |
| 1098 return [self isTabNativePage:[_model currentTab]]; | |
| 1099 } | |
| 1100 | |
| 1101 - (BOOL)isCurrentTabUsingDesktopUserAgent { | |
| 1102 return [_model currentTab].usesDesktopUserAgent; | |
|
kkhorimoto
2017/02/25 02:36:32
After updating the tools menu interface as I sugge
liaoyuke
2017/02/27 17:34:22
I personally do not like this type of function cal
liaoyuke
2017/02/27 21:48:59
I guess this is fine in the context of BVC, as BVC
kkhorimoto
2017/02/27 23:44:23
I definitely agree that layering violations should
| |
| 1073 } | 1103 } |
| 1074 | 1104 |
| 1075 // Whether the sharing menu should be shown. | 1105 // Whether the sharing menu should be shown. |
| 1076 - (BOOL)canShowShareMenu { | 1106 - (BOOL)canShowShareMenu { |
| 1077 Tab* tab = [_model currentTab]; | 1107 Tab* tab = [_model currentTab]; |
| 1078 // TODO(shreyasv): Make it so the URL returned by the tab is always valid and | 1108 // TODO(shreyasv): Make it so the URL returned by the tab is always valid and |
| 1079 // remove check on net::NSURLWithGURL(tab.url) ( http://crbug.com/400999 ). | 1109 // remove check on net::NSURLWithGURL(tab.url) ( http://crbug.com/400999 ). |
| 1080 return tab && !tab.url.SchemeIs(kChromeUIScheme) && | 1110 return tab && !tab.url.SchemeIs(kChromeUIScheme) && |
| 1081 net::NSURLWithGURL(tab.url); | 1111 net::NSURLWithGURL(tab.url); |
| 1082 } | 1112 } |
| (...skipping 2199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3282 initWithReadingList:ReadingListModelFactory::GetForBrowserState( | 3312 initWithReadingList:ReadingListModelFactory::GetForBrowserState( |
| 3283 _browserState)]); | 3313 _browserState)]); |
| 3284 } | 3314 } |
| 3285 [context setReadingListMenuNotifier:_readingListMenuNotifier]; | 3315 [context setReadingListMenuNotifier:_readingListMenuNotifier]; |
| 3286 } | 3316 } |
| 3287 | 3317 |
| 3288 [_toolbarController showToolsMenuPopupWithContext:context]; | 3318 [_toolbarController showToolsMenuPopupWithContext:context]; |
| 3289 ToolsPopupController* toolsPopupController = | 3319 ToolsPopupController* toolsPopupController = |
| 3290 [_toolbarController toolsPopupController]; | 3320 [_toolbarController toolsPopupController]; |
| 3291 if ([_model currentTab]) { | 3321 if ([_model currentTab]) { |
| 3322 // Both "Request Desktop Site" and "Request Mobile Site" are visible by | |
| 3323 // default, needs to hide exactly one of them. | |
| 3324 if ([self shouldShowRequestDesktopSite]) | |
| 3325 [toolsPopupController hideRequestMobileSite]; | |
| 3326 else | |
| 3327 [toolsPopupController hideRequestDesktopSite]; | |
|
kkhorimoto
2017/02/25 02:36:32
This code doesn't seem necessary, since we're alre
liaoyuke
2017/02/27 17:34:22
Done.
| |
| 3328 | |
| 3292 BOOL isBookmarked = _toolbarModelIOS->IsCurrentTabBookmarked(); | 3329 BOOL isBookmarked = _toolbarModelIOS->IsCurrentTabBookmarked(); |
| 3293 [toolsPopupController setIsCurrentPageBookmarked:isBookmarked]; | 3330 [toolsPopupController setIsCurrentPageBookmarked:isBookmarked]; |
| 3294 [toolsPopupController setCanShowFindBar:self.canShowFindBar]; | 3331 [toolsPopupController setCanShowFindBar:self.canShowFindBar]; |
| 3295 [toolsPopupController setCanUseReaderMode:self.canUseReaderMode]; | 3332 [toolsPopupController setCanUseReaderMode:self.canUseReaderMode]; |
| 3296 [toolsPopupController | 3333 [toolsPopupController |
| 3297 setCanUseDesktopUserAgent:self.canUseDesktopUserAgent]; | 3334 setCanUseDesktopUserAgent:self.canUseDesktopUserAgent]; |
| 3335 [toolsPopupController setCanUseMobileUserAgent:self.canUseMobileUserAgent]; | |
| 3298 [toolsPopupController setCanShowShareMenu:self.canShowShareMenu]; | 3336 [toolsPopupController setCanShowShareMenu:self.canShowShareMenu]; |
| 3299 | 3337 |
| 3300 if (!IsIPadIdiom()) | 3338 if (!IsIPadIdiom()) |
| 3301 [toolsPopupController setIsTabLoading:_toolbarModelIOS->IsLoading()]; | 3339 [toolsPopupController setIsTabLoading:_toolbarModelIOS->IsLoading()]; |
| 3302 } | 3340 } |
| 3303 } | 3341 } |
| 3304 | 3342 |
| 3305 - (void)showPageInfoPopupForView:(UIView*)sourceView { | 3343 - (void)showPageInfoPopupForView:(UIView*)sourceView { |
| 3306 Tab* tab = [_model currentTab]; | 3344 Tab* tab = [_model currentTab]; |
| 3307 DCHECK([tab navigationManager]); | 3345 DCHECK([tab navigationManager]); |
| (...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3919 case IDC_SHARE_PAGE: | 3957 case IDC_SHARE_PAGE: |
| 3920 [self sharePage]; | 3958 [self sharePage]; |
| 3921 break; | 3959 break; |
| 3922 case IDC_SHOW_MAIL_COMPOSER: | 3960 case IDC_SHOW_MAIL_COMPOSER: |
| 3923 [self showMailComposer:sender]; | 3961 [self showMailComposer:sender]; |
| 3924 break; | 3962 break; |
| 3925 case IDC_READER_MODE: | 3963 case IDC_READER_MODE: |
| 3926 [[_model currentTab] switchToReaderMode]; | 3964 [[_model currentTab] switchToReaderMode]; |
| 3927 break; | 3965 break; |
| 3928 case IDC_REQUEST_DESKTOP_SITE: | 3966 case IDC_REQUEST_DESKTOP_SITE: |
| 3929 [self enableDesktopUserAgent]; | 3967 [self reloadPageWithDesktopUserAgent]; |
| 3968 break; | |
| 3969 case IDC_REQUEST_MOBILE_SITE: | |
| 3970 [self reloadPageWithMobileUserAgent]; | |
| 3930 break; | 3971 break; |
| 3931 case IDC_SHOW_TOOLS_MENU: { | 3972 case IDC_SHOW_TOOLS_MENU: { |
| 3932 [self showToolsMenuPopup]; | 3973 [self showToolsMenuPopup]; |
| 3933 break; | 3974 break; |
| 3934 } | 3975 } |
| 3935 case IDC_SHOW_BOOKMARK_MANAGER: { | 3976 case IDC_SHOW_BOOKMARK_MANAGER: { |
| 3936 if (IsIPadIdiom()) { | 3977 if (IsIPadIdiom()) { |
| 3937 [self showAllBookmarks]; | 3978 [self showAllBookmarks]; |
| 3938 } else { | 3979 } else { |
| 3939 [self initializeBookmarkInteractionController]; | 3980 [self initializeBookmarkInteractionController]; |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4128 | 4169 |
| 4129 - (void)showHelpPage { | 4170 - (void)showHelpPage { |
| 4130 GURL helpUrl(l10n_util::GetStringUTF16(IDS_IOS_TOOLS_MENU_HELP_URL)); | 4171 GURL helpUrl(l10n_util::GetStringUTF16(IDS_IOS_TOOLS_MENU_HELP_URL)); |
| 4131 [self webPageOrderedOpen:helpUrl | 4172 [self webPageOrderedOpen:helpUrl |
| 4132 referrer:web::Referrer() | 4173 referrer:web::Referrer() |
| 4133 windowName:nil | 4174 windowName:nil |
| 4134 inBackground:NO | 4175 inBackground:NO |
| 4135 appendTo:kCurrentTab]; | 4176 appendTo:kCurrentTab]; |
| 4136 } | 4177 } |
| 4137 | 4178 |
| 4138 - (void)enableDesktopUserAgent { | 4179 - (void)reloadPageWithDesktopUserAgent { |
| 4139 [[_model currentTab] enableDesktopUserAgent]; | 4180 [[_model currentTab] activateDesktopUserAgent]; |
| 4140 [[_model currentTab] reloadForDesktopUserAgent]; | 4181 [[_model currentTab] reloadForUpdatedUserAgent]; |
| 4182 } | |
| 4183 | |
| 4184 - (void)reloadPageWithMobileUserAgent { | |
|
kkhorimoto
2017/02/25 02:36:32
Please add a TODO here for the next step of featur
liaoyuke
2017/02/27 17:34:22
I'll leave this for next CL. In this one, I'll jus
| |
| 4141 } | 4185 } |
| 4142 | 4186 |
| 4143 - (void)resetAllWebViews { | 4187 - (void)resetAllWebViews { |
| 4144 [_dialogPresenter cancelAllDialogs]; | 4188 [_dialogPresenter cancelAllDialogs]; |
| 4145 [_model resetAllWebViews]; | 4189 [_model resetAllWebViews]; |
| 4146 } | 4190 } |
| 4147 | 4191 |
| 4148 #pragma mark - Find Bar | 4192 #pragma mark - Find Bar |
| 4149 | 4193 |
| 4150 - (void)hideFindBarWithAnimation:(BOOL)animate { | 4194 - (void)hideFindBarWithAnimation:(BOOL)animate { |
| (...skipping 874 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5025 | 5069 |
| 5026 - (UIView*)voiceSearchButton { | 5070 - (UIView*)voiceSearchButton { |
| 5027 return _voiceSearchButton; | 5071 return _voiceSearchButton; |
| 5028 } | 5072 } |
| 5029 | 5073 |
| 5030 - (id<LogoAnimationControllerOwner>)logoAnimationControllerOwner { | 5074 - (id<LogoAnimationControllerOwner>)logoAnimationControllerOwner { |
| 5031 return [self currentLogoAnimationControllerOwner]; | 5075 return [self currentLogoAnimationControllerOwner]; |
| 5032 } | 5076 } |
| 5033 | 5077 |
| 5034 @end | 5078 @end |
| OLD | NEW |