Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(266)

Side by Side Diff: ios/chrome/browser/ui/browser_view_controller.mm

Issue 2714813002: [iOS] Add Request Mobile Site cell to tools menu (Closed)
Patch Set: Fix unit test Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 #import "ios/chrome/browser/ui/side_swipe/side_swipe_controller.h" 140 #import "ios/chrome/browser/ui/side_swipe/side_swipe_controller.h"
141 #import "ios/chrome/browser/ui/stack_view/card_view.h" 141 #import "ios/chrome/browser/ui/stack_view/card_view.h"
142 #import "ios/chrome/browser/ui/stack_view/page_animation_util.h" 142 #import "ios/chrome/browser/ui/stack_view/page_animation_util.h"
143 #import "ios/chrome/browser/ui/static_content/static_html_native_content.h" 143 #import "ios/chrome/browser/ui/static_content/static_html_native_content.h"
144 #import "ios/chrome/browser/ui/sync/sync_util.h" 144 #import "ios/chrome/browser/ui/sync/sync_util.h"
145 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_controller.h" 145 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_controller.h"
146 #import "ios/chrome/browser/ui/tabs/tab_strip_controller.h" 146 #import "ios/chrome/browser/ui/tabs/tab_strip_controller.h"
147 #import "ios/chrome/browser/ui/toolbar/toolbar_controller.h" 147 #import "ios/chrome/browser/ui/toolbar/toolbar_controller.h"
148 #include "ios/chrome/browser/ui/toolbar/toolbar_model_delegate_ios.h" 148 #include "ios/chrome/browser/ui/toolbar/toolbar_model_delegate_ios.h"
149 #include "ios/chrome/browser/ui/toolbar/toolbar_model_ios.h" 149 #include "ios/chrome/browser/ui/toolbar/toolbar_model_ios.h"
150 #import "ios/chrome/browser/ui/tools_menu/tools_menu_context.h" 150 #import "ios/chrome/browser/ui/tools_menu/tools_menu_configuration.h"
151 #import "ios/chrome/browser/ui/tools_menu/tools_menu_view_item.h" 151 #import "ios/chrome/browser/ui/tools_menu/tools_menu_view_item.h"
152 #import "ios/chrome/browser/ui/tools_menu/tools_popup_controller.h" 152 #import "ios/chrome/browser/ui/tools_menu/tools_popup_controller.h"
153 #include "ios/chrome/browser/ui/ui_util.h" 153 #include "ios/chrome/browser/ui/ui_util.h"
154 #import "ios/chrome/browser/ui/uikit_ui_util.h" 154 #import "ios/chrome/browser/ui/uikit_ui_util.h"
155 #import "ios/chrome/browser/ui/util/pasteboard_util.h" 155 #import "ios/chrome/browser/ui/util/pasteboard_util.h"
156 #import "ios/chrome/browser/ui/voice/text_to_speech_player.h" 156 #import "ios/chrome/browser/ui/voice/text_to_speech_player.h"
157 #include "ios/chrome/browser/upgrade/upgrade_center.h" 157 #include "ios/chrome/browser/upgrade/upgrade_center.h"
158 #import "ios/chrome/browser/web/error_page_content.h" 158 #import "ios/chrome/browser/web/error_page_content.h"
159 #import "ios/chrome/browser/web/passkit_dialog_provider.h" 159 #import "ios/chrome/browser/web/passkit_dialog_provider.h"
160 #import "ios/chrome/browser/web/repost_form_tab_helper.h" 160 #import "ios/chrome/browser/web/repost_form_tab_helper.h"
(...skipping 12 matching lines...) Expand all
173 #include "ios/public/provider/chrome/browser/voice/voice_search_provider.h" 173 #include "ios/public/provider/chrome/browser/voice/voice_search_provider.h"
174 #import "ios/web/navigation/crw_session_controller.h" 174 #import "ios/web/navigation/crw_session_controller.h"
175 #import "ios/web/navigation/crw_session_entry.h" 175 #import "ios/web/navigation/crw_session_entry.h"
176 #include "ios/web/navigation/navigation_manager_impl.h" 176 #include "ios/web/navigation/navigation_manager_impl.h"
177 #include "ios/web/public/active_state_manager.h" 177 #include "ios/web/public/active_state_manager.h"
178 #include "ios/web/public/navigation_item.h" 178 #include "ios/web/public/navigation_item.h"
179 #import "ios/web/public/navigation_manager.h" 179 #import "ios/web/public/navigation_manager.h"
180 #include "ios/web/public/referrer_util.h" 180 #include "ios/web/public/referrer_util.h"
181 #include "ios/web/public/ssl_status.h" 181 #include "ios/web/public/ssl_status.h"
182 #include "ios/web/public/url_scheme_util.h" 182 #include "ios/web/public/url_scheme_util.h"
183 #include "ios/web/public/user_agent.h"
183 #include "ios/web/public/web_client.h" 184 #include "ios/web/public/web_client.h"
184 #import "ios/web/public/web_state/context_menu_params.h" 185 #import "ios/web/public/web_state/context_menu_params.h"
185 #import "ios/web/public/web_state/crw_web_view_proxy.h" 186 #import "ios/web/public/web_state/crw_web_view_proxy.h"
186 #import "ios/web/public/web_state/ui/crw_native_content_provider.h" 187 #import "ios/web/public/web_state/ui/crw_native_content_provider.h"
187 #include "ios/web/public/web_state/web_state.h" 188 #include "ios/web/public/web_state/web_state.h"
188 #import "ios/web/public/web_state/web_state_delegate_bridge.h" 189 #import "ios/web/public/web_state/web_state_delegate_bridge.h"
189 #include "ios/web/public/web_thread.h" 190 #include "ios/web/public/web_thread.h"
190 #import "ios/web/web_state/ui/crw_web_controller.h" 191 #import "ios/web/web_state/ui/crw_web_controller.h"
191 #import "net/base/mac/url_conversions.h" 192 #import "net/base/mac/url_conversions.h"
192 #include "net/base/mime_util.h" 193 #include "net/base/mime_util.h"
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 // Whether BVC prefers to hide the status bar. This value is used to determine 539 // Whether BVC prefers to hide the status bar. This value is used to determine
539 // the response from the |prefersStatusBarHidden| method. 540 // the response from the |prefersStatusBarHidden| method.
540 @property(nonatomic, assign) BOOL hideStatusBar; 541 @property(nonatomic, assign) BOOL hideStatusBar;
541 // Whether the VoiceSearchBar should be displayed. 542 // Whether the VoiceSearchBar should be displayed.
542 @property(nonatomic, readonly) BOOL shouldShowVoiceSearchBar; 543 @property(nonatomic, readonly) BOOL shouldShowVoiceSearchBar;
543 // Coordinator for displaying a modal overlay with activity indicator to prevent 544 // Coordinator for displaying a modal overlay with activity indicator to prevent
544 // the user from interacting with the browser view. 545 // the user from interacting with the browser view.
545 @property(nonatomic, retain) 546 @property(nonatomic, retain)
546 ActivityOverlayCoordinator* activityOverlayCoordinator; 547 ActivityOverlayCoordinator* activityOverlayCoordinator;
547 548
549 // The user agent type used to load the currently visible page. User agent type
550 // is NONE if there is no visible page or visible page is a native page.
551 @property(nonatomic, assign, readonly) web::UserAgentType userAgentType;
552
548 // BVC initialization: 553 // BVC initialization:
549 // If the BVC is initialized with a valid browser state & tab model immediately, 554 // If the BVC is initialized with a valid browser state & tab model immediately,
550 // the path is straightforward: functionality is enabled, and the UI is built 555 // the path is straightforward: functionality is enabled, and the UI is built
551 // when -viewDidLoad is called. 556 // when -viewDidLoad is called.
552 // If the BVC is initialized without a browser state or tab model, the tab model 557 // If the BVC is initialized without a browser state or tab model, the tab model
553 // and browser state may or may not be provided before -viewDidLoad is called. 558 // and browser state may or may not be provided before -viewDidLoad is called.
554 // In most cases, they will not, to improve startup performance. 559 // In most cases, they will not, to improve startup performance.
555 // In order to handle this, initialization of various aspects of BVC have been 560 // In order to handle this, initialization of various aspects of BVC have been
556 // broken out into the following functions, which have expectations (enforced 561 // broken out into the following functions, which have expectations (enforced
557 // with DCHECKs) regarding |_browserState|, |_model|, and [self isViewLoaded]. 562 // with DCHECKs) regarding |_browserState|, |_model|, and [self isViewLoaded].
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
677 // Adds a CardView on top of the contentArea either taking the size of the full 682 // Adds a CardView on top of the contentArea either taking the size of the full
678 // screen or just the size of the space under the header. 683 // screen or just the size of the space under the header.
679 // Returns the CardView that was added. 684 // Returns the CardView that was added.
680 - (CardView*)addCardViewInFullscreen:(BOOL)fullScreen; 685 - (CardView*)addCardViewInFullscreen:(BOOL)fullScreen;
681 // Called when either a tab finishes loading or when a tab with finished content 686 // Called when either a tab finishes loading or when a tab with finished content
682 // is added directly to the model via pre-rendering. The tab must be non-nil and 687 // is added directly to the model via pre-rendering. The tab must be non-nil and
683 // must be a member of the tab model controlled by this BrowserViewController. 688 // must be a member of the tab model controlled by this BrowserViewController.
684 - (void)tabLoadComplete:(Tab*)tab withSuccess:(BOOL)success; 689 - (void)tabLoadComplete:(Tab*)tab withSuccess:(BOOL)success;
685 // Evaluates Javascript asynchronously using the current page context. 690 // Evaluates Javascript asynchronously using the current page context.
686 - (void)openJavascript:(NSString*)javascript; 691 - (void)openJavascript:(NSString*)javascript;
687 // Sets the desktop user agent flag and reload the current page. 692
693 // Sets the desktop user agent flag and reloads the current page.
688 - (void)enableDesktopUserAgent; 694 - (void)enableDesktopUserAgent;
695
696 // Sets the desktop user agent flag and reloads the current page.
697 - (void)enableMobileUserAgent;
698
689 // Helper methods used by ShareToDelegate methods. 699 // Helper methods used by ShareToDelegate methods.
690 // Shows an alert with the given title and message id. 700 // Shows an alert with the given title and message id.
691 - (void)showErrorAlert:(int)titleMessageId message:(int)messageId; 701 - (void)showErrorAlert:(int)titleMessageId message:(int)messageId;
692 // Helper method displaying an alert with the given title and message. 702 // Helper method displaying an alert with the given title and message.
693 // Dismisses previous alert if it has not been dismissed yet. 703 // Dismisses previous alert if it has not been dismissed yet.
694 - (void)showErrorAlertWithStringTitle:(NSString*)title 704 - (void)showErrorAlertWithStringTitle:(NSString*)title
695 message:(NSString*)message; 705 message:(NSString*)message;
696 // Shows a self-dismissing snackbar displaying |message|. 706 // Shows a self-dismissing snackbar displaying |message|.
697 - (void)showSnackbar:(NSString*)message; 707 - (void)showSnackbar:(NSString*)message;
698 // Induces an intentional crash in the browser process. 708 // Induces an intentional crash in the browser process.
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
1089 if (![controller canFindInPage]) 1099 if (![controller canFindInPage])
1090 return NO; 1100 return NO;
1091 1101
1092 // Don't show twice. 1102 // Don't show twice.
1093 if (controller.findInPageModel.enabled) 1103 if (controller.findInPageModel.enabled)
1094 return NO; 1104 return NO;
1095 1105
1096 return YES; 1106 return YES;
1097 } 1107 }
1098 1108
1109 - (web::UserAgentType)userAgentType {
1110 web::WebState* webState = [_model currentTab].webState;
1111 if (!webState)
1112 return web::UserAgentType::NONE;
1113 web::NavigationItem* visibleItem =
1114 webState->GetNavigationManager()->GetVisibleItem();
1115 if (!visibleItem)
1116 return web::UserAgentType::NONE;
1117
1118 return visibleItem->GetUserAgentType();
1119 }
1120
1099 - (void)setVisible:(BOOL)visible { 1121 - (void)setVisible:(BOOL)visible {
1100 if (_visible == visible) 1122 if (_visible == visible)
1101 return; 1123 return;
1102 _visible = visible; 1124 _visible = visible;
1103 } 1125 }
1104 1126
1105 - (void)setViewVisible:(BOOL)viewVisible { 1127 - (void)setViewVisible:(BOOL)viewVisible {
1106 if (_viewVisible == viewVisible) 1128 if (_viewVisible == viewVisible)
1107 return; 1129 return;
1108 _viewVisible = viewVisible; 1130 _viewVisible = viewVisible;
(...skipping 941 matching lines...) Expand 10 before | Expand all | Expand 10 after
2050 atIndex:position 2072 atIndex:position
2051 inBackground:NO]; 2073 inBackground:NO];
2052 return tab; 2074 return tab;
2053 } 2075 }
2054 2076
2055 // Whether the given tab's URL is an application specific URL. 2077 // Whether the given tab's URL is an application specific URL.
2056 - (BOOL)isTabNativePage:(Tab*)tab { 2078 - (BOOL)isTabNativePage:(Tab*)tab {
2057 web::WebState* webState = tab.webState; 2079 web::WebState* webState = tab.webState;
2058 if (!webState) 2080 if (!webState)
2059 return NO; 2081 return NO;
2060 web::NavigationManager* navigationManager = webState->GetNavigationManager(); 2082 web::NavigationItem* visibleItem =
2061 if (!navigationManager) 2083 webState->GetNavigationManager()->GetVisibleItem();
2062 return NO;
2063 web::NavigationItem* visibleItem = navigationManager->GetVisibleItem();
2064 if (!visibleItem) 2084 if (!visibleItem)
2065 return NO; 2085 return NO;
2066 return web::GetWebClient()->IsAppSpecificURL(visibleItem->GetURL()); 2086 return web::GetWebClient()->IsAppSpecificURL(visibleItem->GetURL());
2067 } 2087 }
2068 2088
2069 - (void)expectNewForegroundTab { 2089 - (void)expectNewForegroundTab {
2070 _expectingForegroundTab = YES; 2090 _expectingForegroundTab = YES;
2071 } 2091 }
2072 2092
2073 - (UIImageView*)pageFullScreenOpenCloseAnimationView { 2093 - (UIImageView*)pageFullScreenOpenCloseAnimationView {
(...skipping 1193 matching lines...) Expand 10 before | Expand all | Expand 10 after
3267 DCHECK(_browserState); 3287 DCHECK(_browserState);
3268 DCHECK(self.visible || self.dismissingModal); 3288 DCHECK(self.visible || self.dismissingModal);
3269 3289
3270 // Dismiss the omnibox (if open). 3290 // Dismiss the omnibox (if open).
3271 [_toolbarController cancelOmniboxEdit]; 3291 [_toolbarController cancelOmniboxEdit];
3272 // Dismiss the soft keyboard (if open). 3292 // Dismiss the soft keyboard (if open).
3273 [[_model currentTab].webController dismissKeyboard]; 3293 [[_model currentTab].webController dismissKeyboard];
3274 // Dismiss Find in Page focus. 3294 // Dismiss Find in Page focus.
3275 [self updateFindBar:NO shouldFocus:NO]; 3295 [self updateFindBar:NO shouldFocus:NO];
3276 3296
3277 base::scoped_nsobject<ToolsMenuContext> context( 3297 base::scoped_nsobject<ToolsMenuConfiguration> configuration(
3278 [[ToolsMenuContext alloc] initWithDisplayView:[self view]]); 3298 [[ToolsMenuConfiguration alloc] initWithDisplayView:[self view]]);
3279 if ([_model count] == 0) 3299 if ([_model count] == 0)
3280 [context setNoOpenedTabs:YES]; 3300 [configuration setNoOpenedTabs:YES];
3301
3281 if (_isOffTheRecord) 3302 if (_isOffTheRecord)
3282 [context setInIncognito:YES]; 3303 [configuration setInIncognito:YES];
3304
3283 if (reading_list::switches::IsReadingListEnabled()) { 3305 if (reading_list::switches::IsReadingListEnabled()) {
3284 if (!_readingListMenuNotifier) { 3306 if (!_readingListMenuNotifier) {
3285 _readingListMenuNotifier.reset([[ReadingListMenuNotifier alloc] 3307 _readingListMenuNotifier.reset([[ReadingListMenuNotifier alloc]
3286 initWithReadingList:ReadingListModelFactory::GetForBrowserState( 3308 initWithReadingList:ReadingListModelFactory::GetForBrowserState(
3287 _browserState)]); 3309 _browserState)]);
3288 } 3310 }
3289 [context setReadingListMenuNotifier:_readingListMenuNotifier]; 3311 [configuration setReadingListMenuNotifier:_readingListMenuNotifier];
3290 } 3312 }
3291 3313
3292 [_toolbarController showToolsMenuPopupWithContext:context]; 3314 [configuration setUserAgentType:self.userAgentType];
3315
3316 [_toolbarController showToolsMenuPopupWithConfiguration:configuration];
3317
3293 ToolsPopupController* toolsPopupController = 3318 ToolsPopupController* toolsPopupController =
3294 [_toolbarController toolsPopupController]; 3319 [_toolbarController toolsPopupController];
3295 if ([_model currentTab]) { 3320 if ([_model currentTab]) {
3296 BOOL isBookmarked = _toolbarModelIOS->IsCurrentTabBookmarked(); 3321 BOOL isBookmarked = _toolbarModelIOS->IsCurrentTabBookmarked();
3297 [toolsPopupController setIsCurrentPageBookmarked:isBookmarked]; 3322 [toolsPopupController setIsCurrentPageBookmarked:isBookmarked];
3298 [toolsPopupController setCanShowFindBar:self.canShowFindBar]; 3323 [toolsPopupController setCanShowFindBar:self.canShowFindBar];
3299 [toolsPopupController setCanUseReaderMode:self.canUseReaderMode]; 3324 [toolsPopupController setCanUseReaderMode:self.canUseReaderMode];
3300 [toolsPopupController
3301 setCanUseDesktopUserAgent:self.canUseDesktopUserAgent];
3302 [toolsPopupController setCanShowShareMenu:self.canShowShareMenu]; 3325 [toolsPopupController setCanShowShareMenu:self.canShowShareMenu];
3303 3326
3304 if (!IsIPadIdiom()) 3327 if (!IsIPadIdiom())
3305 [toolsPopupController setIsTabLoading:_toolbarModelIOS->IsLoading()]; 3328 [toolsPopupController setIsTabLoading:_toolbarModelIOS->IsLoading()];
3306 } 3329 }
3307 } 3330 }
3308 3331
3309 - (void)showPageInfoPopupForView:(UIView*)sourceView { 3332 - (void)showPageInfoPopupForView:(UIView*)sourceView {
3310 Tab* tab = [_model currentTab]; 3333 Tab* tab = [_model currentTab];
3311 DCHECK([tab navigationManager]); 3334 DCHECK([tab navigationManager]);
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after
3923 break; 3946 break;
3924 case IDC_SHOW_MAIL_COMPOSER: 3947 case IDC_SHOW_MAIL_COMPOSER:
3925 [self showMailComposer:sender]; 3948 [self showMailComposer:sender];
3926 break; 3949 break;
3927 case IDC_READER_MODE: 3950 case IDC_READER_MODE:
3928 [[_model currentTab] switchToReaderMode]; 3951 [[_model currentTab] switchToReaderMode];
3929 break; 3952 break;
3930 case IDC_REQUEST_DESKTOP_SITE: 3953 case IDC_REQUEST_DESKTOP_SITE:
3931 [self enableDesktopUserAgent]; 3954 [self enableDesktopUserAgent];
3932 break; 3955 break;
3956 case IDC_REQUEST_MOBILE_SITE:
3957 [self enableMobileUserAgent];
3958 break;
3933 case IDC_SHOW_TOOLS_MENU: { 3959 case IDC_SHOW_TOOLS_MENU: {
3934 [self showToolsMenuPopup]; 3960 [self showToolsMenuPopup];
3935 break; 3961 break;
3936 } 3962 }
3937 case IDC_SHOW_BOOKMARK_MANAGER: { 3963 case IDC_SHOW_BOOKMARK_MANAGER: {
3938 if (IsIPadIdiom()) { 3964 if (IsIPadIdiom()) {
3939 [self showAllBookmarks]; 3965 [self showAllBookmarks];
3940 } else { 3966 } else {
3941 [self initializeBookmarkInteractionController]; 3967 [self initializeBookmarkInteractionController];
3942 [_bookmarkInteractionController presentBookmarks]; 3968 [_bookmarkInteractionController presentBookmarks];
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
4134 referrer:web::Referrer() 4160 referrer:web::Referrer()
4135 inBackground:NO 4161 inBackground:NO
4136 appendTo:kCurrentTab]; 4162 appendTo:kCurrentTab];
4137 } 4163 }
4138 4164
4139 - (void)enableDesktopUserAgent { 4165 - (void)enableDesktopUserAgent {
4140 [[_model currentTab] enableDesktopUserAgent]; 4166 [[_model currentTab] enableDesktopUserAgent];
4141 [[_model currentTab] reloadForDesktopUserAgent]; 4167 [[_model currentTab] reloadForDesktopUserAgent];
4142 } 4168 }
4143 4169
4170 // TODO(crbug.com/692303): Implement the actual functionality of
4171 // "Request Mobile Site", and also refactoring the user agent related function
4172 // names to improve readability.
4173 - (void)enableMobileUserAgent {
4174 }
4175
4144 - (void)resetAllWebViews { 4176 - (void)resetAllWebViews {
4145 [_dialogPresenter cancelAllDialogs]; 4177 [_dialogPresenter cancelAllDialogs];
4146 [_model resetAllWebViews]; 4178 [_model resetAllWebViews];
4147 } 4179 }
4148 4180
4149 #pragma mark - Find Bar 4181 #pragma mark - Find Bar
4150 4182
4151 - (void)hideFindBarWithAnimation:(BOOL)animate { 4183 - (void)hideFindBarWithAnimation:(BOOL)animate {
4152 [_findBarController hideFindBarView:animate]; 4184 [_findBarController hideFindBarView:animate];
4153 } 4185 }
(...skipping 874 matching lines...) Expand 10 before | Expand all | Expand 10 after
5028 5060
5029 - (UIView*)voiceSearchButton { 5061 - (UIView*)voiceSearchButton {
5030 return _voiceSearchButton; 5062 return _voiceSearchButton;
5031 } 5063 }
5032 5064
5033 - (id<LogoAnimationControllerOwner>)logoAnimationControllerOwner { 5065 - (id<LogoAnimationControllerOwner>)logoAnimationControllerOwner {
5034 return [self currentLogoAnimationControllerOwner]; 5066 return [self currentLogoAnimationControllerOwner];
5035 } 5067 }
5036 5068
5037 @end 5069 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698