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

Unified Diff: ios/chrome/browser/ui/browser_view_controller.mm

Issue 2714813002: [iOS] Add Request Mobile Site cell to tools menu (Closed)
Patch Set: Rebase Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: ios/chrome/browser/ui/browser_view_controller.mm
diff --git a/ios/chrome/browser/ui/browser_view_controller.mm b/ios/chrome/browser/ui/browser_view_controller.mm
index 9b3b3afa3ff9a8cbe9cf40f7fc6d4b47c8adb8b0..967cd59b773616b83dd18ea41fc75b95ce565c16 100644
--- a/ios/chrome/browser/ui/browser_view_controller.mm
+++ b/ios/chrome/browser/ui/browser_view_controller.mm
@@ -516,6 +516,8 @@ @interface BrowserViewController ()<AppRatingPromptDelegate,
@property(nonatomic, assign, readonly) BOOL canUseReaderMode;
// Whether the current tab can enable the request desktop menu item.
@property(nonatomic, assign, readonly) BOOL canUseDesktopUserAgent;
+// Whether the current tab can enable the request mobile menu item.
+@property(nonatomic, assign, readonly) BOOL canUseMobileUserAgent;
// Whether the sharing menu should be enabled.
@property(nonatomic, assign, readonly) BOOL canShowShareMenu;
// Helper method to check web controller canShowFindBar method.
@@ -625,8 +627,17 @@ - (void)dismissRateThisAppDialog;
// Shows the source of the current page.
- (void)viewSource;
#endif
-// Whether the given tab's url begins with the chrome prefix.
-- (BOOL)isTabNativePage:(Tab*)tab;
+
+// True if "Request Desktop Site" should be visible in tools menu, otherwise,
+// make "Request Mobile Site" visible.
+- (BOOL)shouldShowRequestDesktopSite;
+
+// Whether the current tab is using desktop user agent.
+- (BOOL)isCurrentTabUsingDesktopUserAgent;
+
+// Whether the current tab's url begins with the chrome prefix.
+- (BOOL)isCurrentTabNativePage;
+
// Returns the view to use when animating a page in or out, positioning it to
// fill the content area but not actually adding it to the view hierarchy.
- (UIImageView*)pageOpenCloseAnimationView;
@@ -683,8 +694,13 @@ - (CardView*)addCardViewInFullscreen:(BOOL)fullScreen;
- (void)tabLoadComplete:(Tab*)tab withSuccess:(BOOL)success;
// Evaluates Javascript asynchronously using the current page context.
- (void)openJavascript:(NSString*)javascript;
+
// Sets the desktop user agent flag and reload the current page.
-- (void)enableDesktopUserAgent;
+- (void)reloadPageWithDesktopUserAgent;
+
+// Sets the mobile user agent flag and reload the current page.
+- (void)reloadPageWithMobileUserAgent;
+
// Helper methods used by ShareToDelegate methods.
// Shows an alert with the given title and message id.
- (void)showErrorAlert:(int)titleMessageId message:(int)messageId;
@@ -1063,13 +1079,27 @@ - (BOOL)canUseReaderMode {
return [tab canSwitchToReaderMode];
}
+- (BOOL)shouldShowRequestDesktopSite {
+ return [self isCurrentTabNativePage] ||
+ ![self isCurrentTabUsingDesktopUserAgent];
+}
+
- (BOOL)canUseDesktopUserAgent {
- Tab* tab = [_model currentTab];
- if ([self isTabNativePage:tab])
- return NO;
+ return ![self isCurrentTabNativePage] &&
+ ![self isCurrentTabUsingDesktopUserAgent];
+}
+
+- (BOOL)canUseMobileUserAgent {
+ return ![self isCurrentTabNativePage] &&
+ [self isCurrentTabUsingDesktopUserAgent];
+}
- // If |useDesktopUserAgent| is |NO|, allow useDesktopUserAgent.
- return !tab.usesDesktopUserAgent;
+- (BOOL)isCurrentTabNativePage {
+ return [self isTabNativePage:[_model currentTab]];
+}
+
+- (BOOL)isCurrentTabUsingDesktopUserAgent {
+ 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
}
// Whether the sharing menu should be shown.
@@ -3289,12 +3319,20 @@ - (void)showToolsMenuPopup {
ToolsPopupController* toolsPopupController =
[_toolbarController toolsPopupController];
if ([_model currentTab]) {
+ // Both "Request Desktop Site" and "Request Mobile Site" are visible by
+ // default, needs to hide exactly one of them.
+ if ([self shouldShowRequestDesktopSite])
+ [toolsPopupController hideRequestMobileSite];
+ else
+ [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.
+
BOOL isBookmarked = _toolbarModelIOS->IsCurrentTabBookmarked();
[toolsPopupController setIsCurrentPageBookmarked:isBookmarked];
[toolsPopupController setCanShowFindBar:self.canShowFindBar];
[toolsPopupController setCanUseReaderMode:self.canUseReaderMode];
[toolsPopupController
setCanUseDesktopUserAgent:self.canUseDesktopUserAgent];
+ [toolsPopupController setCanUseMobileUserAgent:self.canUseMobileUserAgent];
[toolsPopupController setCanShowShareMenu:self.canShowShareMenu];
if (!IsIPadIdiom())
@@ -3926,7 +3964,10 @@ - (IBAction)chromeExecuteCommand:(id)sender {
[[_model currentTab] switchToReaderMode];
break;
case IDC_REQUEST_DESKTOP_SITE:
- [self enableDesktopUserAgent];
+ [self reloadPageWithDesktopUserAgent];
+ break;
+ case IDC_REQUEST_MOBILE_SITE:
+ [self reloadPageWithMobileUserAgent];
break;
case IDC_SHOW_TOOLS_MENU: {
[self showToolsMenuPopup];
@@ -4135,9 +4176,12 @@ - (void)showHelpPage {
appendTo:kCurrentTab];
}
-- (void)enableDesktopUserAgent {
- [[_model currentTab] enableDesktopUserAgent];
- [[_model currentTab] reloadForDesktopUserAgent];
+- (void)reloadPageWithDesktopUserAgent {
+ [[_model currentTab] activateDesktopUserAgent];
+ [[_model currentTab] reloadForUpdatedUserAgent];
+}
+
+- (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
}
- (void)resetAllWebViews {

Powered by Google App Engine
This is Rietveld 408576698