summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoravi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-22 21:09:08 +0000
committeravi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-22 21:09:08 +0000
commit054545338db4f77d5e5f403a57df757b6f47be07 (patch)
treefb6e9a6993522a802c45490423541cb8072e93f1
parent04504c246dd88763f14933199feb80cde09fd258 (diff)
downloadchromium_src-054545338db4f77d5e5f403a57df757b6f47be07.zip
chromium_src-054545338db4f77d5e5f403a57df757b6f47be07.tar.gz
chromium_src-054545338db4f77d5e5f403a57df757b6f47be07.tar.bz2
Make Mac menu code obey incognito availability.
BUG=170053 TEST=as in bug Review URL: https://chromiumcodereview.appspot.com/11906008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@178093 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/app_controller_mac.h8
-rw-r--r--chrome/browser/app_controller_mac.mm54
-rw-r--r--chrome/browser/ui/browser_command_controller.cc42
-rw-r--r--chrome/browser/ui/browser_command_controller.h15
-rw-r--r--chrome/browser/ui/cocoa/bookmarks/bookmark_menu_cocoa_controller.mm4
-rw-r--r--chrome/browser/ui/cocoa/history_menu_cocoa_controller.mm2
6 files changed, 89 insertions, 36 deletions
diff --git a/chrome/browser/app_controller_mac.h b/chrome/browser/app_controller_mac.h
index d23cac41..27f436b 100644
--- a/chrome/browser/app_controller_mac.h
+++ b/chrome/browser/app_controller_mac.h
@@ -13,6 +13,7 @@
#include "base/memory/scoped_nsobject.h"
#include "base/memory/scoped_ptr.h"
#include "base/observer_list.h"
+#include "base/prefs/public/pref_change_registrar.h"
#include "ui/base/work_area_watcher_observer.h"
class BookmarkMenuBridge;
@@ -72,6 +73,9 @@ class WorkAreaWatcherObserver;
// Observers that listen to the work area changes.
ObserverList<ui::WorkAreaWatcherObserver> workAreaChangeObservers_;
+
+ scoped_ptr<PrefChangeRegistrar> profilePrefRegistrar_;
+ PrefChangeRegistrar localPrefRegistrar_;
}
@property(readonly, nonatomic) BOOL startupComplete;
@@ -86,11 +90,11 @@ class WorkAreaWatcherObserver;
// window closure from causing the application to quit.
- (void)stopTryingToTerminateApplication:(NSApplication*)app;
-// Returns true if there is not a modal window (either window- or application-
+// Returns true if there is a modal window (either window- or application-
// modal) blocking the active browser. Note that tab modal dialogs (HTTP auth
// sheets) will not count as blocking the browser. But things like open/save
// dialogs that are window modal will block the browser.
-- (BOOL)keyWindowIsNotModal;
+- (BOOL)keyWindowIsModal;
// Show the preferences window, or bring it to the front if it's already
// visible.
diff --git a/chrome/browser/app_controller_mac.mm b/chrome/browser/app_controller_mac.mm
index 28fec39..b5d026d 100644
--- a/chrome/browser/app_controller_mac.mm
+++ b/chrome/browser/app_controller_mac.mm
@@ -38,6 +38,7 @@
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/sync/sync_ui_util.h"
#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/browser_command_controller.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_list.h"
@@ -522,6 +523,18 @@ void RecordLastRunAppBundlePath() {
historyMenuBridge_.reset(new HistoryMenuBridge(lastProfile_));
historyMenuBridge_->BuildMenu();
+
+ chrome::BrowserCommandController::
+ UpdateSharedCommandsForIncognitoAvailability(
+ menuState_.get(), lastProfile_);
+ profilePrefRegistrar_.reset(new PrefChangeRegistrar());
+ profilePrefRegistrar_->Init(lastProfile_->GetPrefs());
+ profilePrefRegistrar_->Add(
+ prefs::kIncognitoModeAvailability,
+ base::Bind(&chrome::BrowserCommandController::
+ UpdateSharedCommandsForIncognitoAvailability,
+ menuState_.get(),
+ lastProfile_));
}
- (void)checkForAnyKeyWindows {
@@ -598,6 +611,15 @@ void RecordLastRunAppBundlePath() {
if (!parsed_command_line.HasSwitch(switches::kEnableExposeForTabs)) {
[tabposeMenuItem_ setHidden:YES];
}
+
+ PrefService* localState = g_browser_process->local_state();
+ if (localState) {
+ localPrefRegistrar_.Init(localState);
+ localPrefRegistrar_.Add(
+ prefs::kAllowFileSelectionDialogs,
+ base::Bind(&chrome::BrowserCommandController::UpdateOpenFileState,
+ menuState_.get()));
+ }
}
// This is called after profiles have been loaded and preferences registered.
@@ -692,15 +714,18 @@ void RecordLastRunAppBundlePath() {
return service && !service->entries().empty();
}
-// Returns true if there is not a modal window (either window- or application-
+// Returns true if there is a modal window (either window- or application-
// modal) blocking the active browser. Note that tab modal dialogs (HTTP auth
// sheets) will not count as blocking the browser. But things like open/save
// dialogs that are window modal will block the browser.
-- (BOOL)keyWindowIsNotModal {
+- (BOOL)keyWindowIsModal {
+ if ([NSApp modalWindow])
+ return YES;
+
Browser* browser = chrome::GetLastActiveBrowser();
- return [NSApp modalWindow] == nil && (!browser ||
- ![[browser->window()->GetNativeWindow() attachedSheet]
- isKindOfClass:[NSWindow class]]);
+ return browser &&
+ [[browser->window()->GetNativeWindow() attachedSheet]
+ isKindOfClass:[NSWindow class]];
}
// Called to validate menu items when there are no key windows. All the
@@ -712,9 +737,11 @@ void RecordLastRunAppBundlePath() {
- (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item {
SEL action = [item action];
BOOL enable = NO;
- if (action == @selector(commandDispatch:)) {
+ if (action == @selector(commandDispatch:) ||
+ action == @selector(commandFromDock:)) {
NSInteger tag = [item tag];
- if (menuState_->SupportsCommand(tag)) {
+ if (menuState_ && // NULL in tests.
+ menuState_->SupportsCommand(tag)) {
switch (tag) {
// The File Menu commands are not automatically disabled by Cocoa when a
// dialog sheet obscures the browser window, so we disable several of
@@ -722,7 +749,7 @@ void RecordLastRunAppBundlePath() {
// app_controller is only activated when there are no key windows (see
// function comment).
case IDC_RESTORE_TAB:
- enable = [self keyWindowIsNotModal] && [self canRestoreTab];
+ enable = ![self keyWindowIsModal] && [self canRestoreTab];
break;
// Browser-level items that open in new tabs should not open if there's
// a window- or app-modal dialog.
@@ -730,14 +757,13 @@ void RecordLastRunAppBundlePath() {
case IDC_NEW_TAB:
case IDC_SHOW_HISTORY:
case IDC_SHOW_BOOKMARK_MANAGER:
- enable = [self keyWindowIsNotModal];
+ enable = ![self keyWindowIsModal];
break;
// Browser-level items that open in new windows.
- case IDC_NEW_WINDOW:
case IDC_TASK_MANAGER:
// Allow the user to open a new window if there's a window-modal
// dialog.
- enable = [self keyWindowIsNotModal] || ([NSApp modalWindow] == nil);
+ enable = ![self keyWindowIsModal];
break;
case IDC_SHOW_SYNC_SETUP: {
Profile* lastProfile = [self lastProfile];
@@ -753,7 +779,7 @@ void RecordLastRunAppBundlePath() {
break;
}
enable = lastProfile->IsSyncAccessible() &&
- [self keyWindowIsNotModal];
+ ![self keyWindowIsModal];
[BrowserWindowController updateSigninItem:item
shouldShow:enable
currentProfile:lastProfile];
@@ -764,7 +790,7 @@ void RecordLastRunAppBundlePath() {
break;
default:
enable = menuState_->IsCommandEnabled(tag) ?
- [self keyWindowIsNotModal] : NO;
+ ![self keyWindowIsModal] : NO;
}
}
} else if (action == @selector(terminate:)) {
@@ -1235,6 +1261,7 @@ void RecordLastRunAppBundlePath() {
keyEquivalent:@""]);
[item setTarget:self];
[item setTag:IDC_NEW_WINDOW];
+ [item setEnabled:[self validateUserInterfaceItem:item]];
[dockMenu addItem:item];
titleStr = l10n_util::GetNSStringWithFixup(IDS_NEW_INCOGNITO_WINDOW_MAC);
@@ -1244,6 +1271,7 @@ void RecordLastRunAppBundlePath() {
keyEquivalent:@""]);
[item setTarget:self];
[item setTag:IDC_NEW_INCOGNITO_WINDOW];
+ [item setEnabled:[self validateUserInterfaceItem:item]];
[dockMenu addItem:item];
// TODO(rickcam): Mock out BackgroundApplicationListModel, then add unit
diff --git a/chrome/browser/ui/browser_command_controller.cc b/chrome/browser/ui/browser_command_controller.cc
index 7231d5a..291b021 100644
--- a/chrome/browser/ui/browser_command_controller.cc
+++ b/chrome/browser/ui/browser_command_controller.cc
@@ -878,7 +878,7 @@ void BrowserCommandController::InitCommandState() {
command_updater_.UpdateCommandEnabled(IDC_ZOOM_MINUS, true);
// Show various bits of UI
- UpdateOpenFileState();
+ UpdateOpenFileState(&command_updater_);
command_updater_.UpdateCommandEnabled(IDC_CREATE_SHORTCUTS, false);
UpdateCommandsForDevTools();
command_updater_.UpdateCommandEnabled(IDC_TASK_MANAGER, CanOpenTaskManager());
@@ -953,13 +953,16 @@ void BrowserCommandController::InitCommandState() {
UpdateCommandsForIncognitoAvailability();
}
-void BrowserCommandController::UpdateCommandsForIncognitoAvailability() {
+// static
+void BrowserCommandController::UpdateSharedCommandsForIncognitoAvailability(
+ CommandUpdater* command_updater,
+ Profile* profile) {
IncognitoModePrefs::Availability incognito_availability =
- IncognitoModePrefs::GetAvailability(profile()->GetPrefs());
- command_updater_.UpdateCommandEnabled(
+ IncognitoModePrefs::GetAvailability(profile->GetPrefs());
+ command_updater->UpdateCommandEnabled(
IDC_NEW_WINDOW,
incognito_availability != IncognitoModePrefs::FORCED);
- command_updater_.UpdateCommandEnabled(
+ command_updater->UpdateCommandEnabled(
IDC_NEW_INCOGNITO_WINDOW,
incognito_availability != IncognitoModePrefs::DISABLED);
@@ -967,21 +970,28 @@ void BrowserCommandController::UpdateCommandsForIncognitoAvailability() {
// mode. For this reason we disable these commands when incognito is forced.
const bool command_enabled =
incognito_availability != IncognitoModePrefs::FORCED;
- command_updater_.UpdateCommandEnabled(
+ command_updater->UpdateCommandEnabled(
IDC_SHOW_BOOKMARK_MANAGER,
browser_defaults::bookmarks_enabled && command_enabled);
- ExtensionService* extension_service = profile()->GetExtensionService();
+ ExtensionService* extension_service = profile->GetExtensionService();
bool enable_extensions =
extension_service && extension_service->extensions_enabled();
- command_updater_.UpdateCommandEnabled(IDC_MANAGE_EXTENSIONS,
+ command_updater->UpdateCommandEnabled(IDC_MANAGE_EXTENSIONS,
enable_extensions && command_enabled);
+ command_updater->UpdateCommandEnabled(IDC_IMPORT_SETTINGS, command_enabled);
+ command_updater->UpdateCommandEnabled(IDC_OPTIONS, command_enabled);
+}
+
+void BrowserCommandController::UpdateCommandsForIncognitoAvailability() {
+ UpdateSharedCommandsForIncognitoAvailability(&command_updater_, profile());
+
const bool show_main_ui =
IsShowingMainUI(window() && window()->IsFullscreen());
- command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS,
- show_main_ui && command_enabled);
- command_updater_.UpdateCommandEnabled(IDC_OPTIONS,
- show_main_ui && command_enabled);
+ if (!show_main_ui) {
+ command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, false);
+ command_updater_.UpdateCommandEnabled(IDC_OPTIONS, false);
+ }
}
void BrowserCommandController::UpdateCommandsForTabState() {
@@ -1084,7 +1094,7 @@ void BrowserCommandController::UpdateCommandsForBookmarkBar() {
void BrowserCommandController::UpdateCommandsForFileSelectionDialogs() {
UpdateSaveAsState();
- UpdateOpenFileState();
+ UpdateOpenFileState(&command_updater_);
}
void BrowserCommandController::UpdateCommandsForFullscreenMode(
@@ -1193,13 +1203,15 @@ void BrowserCommandController::UpdateSaveAsState() {
command_updater_.UpdateCommandEnabled(IDC_SAVE_PAGE, CanSavePage(browser_));
}
-void BrowserCommandController::UpdateOpenFileState() {
+// static
+void BrowserCommandController::UpdateOpenFileState(
+ CommandUpdater* command_updater) {
bool enabled = true;
PrefService* local_state = g_browser_process->local_state();
if (local_state)
enabled = local_state->GetBoolean(prefs::kAllowFileSelectionDialogs);
- command_updater_.UpdateCommandEnabled(IDC_OPEN_FILE, enabled);
+ command_updater->UpdateCommandEnabled(IDC_OPEN_FILE, enabled);
}
void BrowserCommandController::UpdateReloadStopState(bool is_loading,
diff --git a/chrome/browser/ui/browser_command_controller.h b/chrome/browser/ui/browser_command_controller.h
index 2ca6945..8d4eefe 100644
--- a/chrome/browser/ui/browser_command_controller.h
+++ b/chrome/browser/ui/browser_command_controller.h
@@ -66,6 +66,18 @@ class BrowserCommandController : public CommandUpdaterDelegate,
void PrintingStateChanged();
void LoadingStateChanged(bool is_loading, bool force);
+ // Shared state updating: these functions are static and public to share with
+ // outside code.
+
+ // Updates the open-file state.
+ static void UpdateOpenFileState(CommandUpdater* command_updater);
+
+ // Update commands whose state depends on incognito mode availability and that
+ // only depend on the profile.
+ static void UpdateSharedCommandsForIncognitoAvailability(
+ CommandUpdater* command_updater,
+ Profile* profile);
+
private:
enum FullScreenMode {
// Not in fullscreen mode.
@@ -163,9 +175,6 @@ class BrowserCommandController : public CommandUpdaterDelegate,
// Updates the save-page-as command state.
void UpdateSaveAsState();
- // Updates the open-file state (Mac Only).
- void UpdateOpenFileState();
-
// Ask the Reload/Stop button to change its icon, and update the Stop command
// state. |is_loading| is true if the current WebContents is loading.
// |force| is true if the button should change its icon immediately.
diff --git a/chrome/browser/ui/cocoa/bookmarks/bookmark_menu_cocoa_controller.mm b/chrome/browser/ui/cocoa/bookmarks/bookmark_menu_cocoa_controller.mm
index 9f3c8fd..67c41de 100644
--- a/chrome/browser/ui/cocoa/bookmarks/bookmark_menu_cocoa_controller.mm
+++ b/chrome/browser/ui/cocoa/bookmarks/bookmark_menu_cocoa_controller.mm
@@ -49,7 +49,7 @@ const NSUInteger kMaximumMenuPixelsWide = 300;
return [NSString stringWithFormat:@"%@\n%@", title, url];
}
-- (id)initWithBridge:(BookmarkMenuBridge *)bridge
+- (id)initWithBridge:(BookmarkMenuBridge*)bridge
andMenu:(NSMenu*)menu {
if ((self = [super init])) {
bridge_ = bridge;
@@ -72,7 +72,7 @@ const NSUInteger kMaximumMenuPixelsWide = 300;
- (BOOL)validateMenuItem:(NSMenuItem*)menuItem {
AppController* controller = [NSApp delegate];
- return [controller keyWindowIsNotModal];
+ return ![controller keyWindowIsModal];
}
// NSMenu delegate method: called just before menu is displayed.
diff --git a/chrome/browser/ui/cocoa/history_menu_cocoa_controller.mm b/chrome/browser/ui/cocoa/history_menu_cocoa_controller.mm
index 1b24476..e17421d 100644
--- a/chrome/browser/ui/cocoa/history_menu_cocoa_controller.mm
+++ b/chrome/browser/ui/cocoa/history_menu_cocoa_controller.mm
@@ -34,7 +34,7 @@ using content::Referrer;
- (BOOL)validateMenuItem:(NSMenuItem*)menuItem {
AppController* controller = [NSApp delegate];
- return [controller keyWindowIsNotModal];
+ return ![controller keyWindowIsModal];
}
// Open the URL of the given history item in the current tab.