diff options
16 files changed, 69 insertions, 36 deletions
diff --git a/ash/launcher/launcher_item_delegate.h b/ash/launcher/launcher_item_delegate.h index dbc1e65..c83de47 100644 --- a/ash/launcher/launcher_item_delegate.h +++ b/ash/launcher/launcher_item_delegate.h @@ -45,7 +45,8 @@ class ASH_EXPORT LauncherItemDelegate { // but not |aura::Window|. If the |event| is of type KeyEvent, it is assumed // that this was triggered by keyboard action (Alt+<number>) and special // handling might happen. - virtual void ItemSelected(const ui::Event& event) = 0; + // Returns true if a new item was created. + virtual bool ItemSelected(const ui::Event& event) = 0; // Returns the title to display. virtual base::string16 GetTitle() = 0; diff --git a/ash/shelf/app_list_shelf_item_delegate.cc b/ash/shelf/app_list_shelf_item_delegate.cc index f032d69..affa767 100644 --- a/ash/shelf/app_list_shelf_item_delegate.cc +++ b/ash/shelf/app_list_shelf_item_delegate.cc @@ -22,9 +22,10 @@ AppListShelfItemDelegate::~AppListShelfItemDelegate() { // LauncherItemDelegateManager owns and destroys this class. } -void AppListShelfItemDelegate::ItemSelected(const ui::Event& event) { +bool AppListShelfItemDelegate::ItemSelected(const ui::Event& event) { // Pass NULL here to show the app list in the currently active RootWindow. Shell::GetInstance()->ToggleAppList(NULL); + return false; } base::string16 AppListShelfItemDelegate::GetTitle() { diff --git a/ash/shelf/app_list_shelf_item_delegate.h b/ash/shelf/app_list_shelf_item_delegate.h index 6a14f14..750a84b 100644 --- a/ash/shelf/app_list_shelf_item_delegate.h +++ b/ash/shelf/app_list_shelf_item_delegate.h @@ -20,7 +20,7 @@ class AppListShelfItemDelegate : public LauncherItemDelegate { virtual ~AppListShelfItemDelegate(); // ash::LauncherItemDelegate overrides: - virtual void ItemSelected(const ui::Event& event) OVERRIDE; + virtual bool ItemSelected(const ui::Event& event) OVERRIDE; virtual base::string16 GetTitle() OVERRIDE; virtual ui::MenuModel* CreateContextMenu( aura::Window* root_window) OVERRIDE; diff --git a/ash/shelf/shelf_view.cc b/ash/shelf/shelf_view.cc index fcd27ff..86ddc6c 100644 --- a/ash/shelf/shelf_view.cc +++ b/ash/shelf/shelf_view.cc @@ -1672,9 +1672,8 @@ void ShelfView::ButtonPressed(views::Button* sender, const ui::Event& event) { LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate( model_->items()[view_index].id); - item_delegate->ItemSelected(event); - - ShowListMenuForView(model_->items()[view_index], sender, event); + if (!item_delegate->ItemSelected(event)) + ShowListMenuForView(model_->items()[view_index], sender, event); } } diff --git a/ash/shell/window_watcher_launcher_item_delegate.cc b/ash/shell/window_watcher_launcher_item_delegate.cc index e755a6e..76e39fd 100644 --- a/ash/shell/window_watcher_launcher_item_delegate.cc +++ b/ash/shell/window_watcher_launcher_item_delegate.cc @@ -23,12 +23,13 @@ WindowWatcherLauncherItemDelegate::WindowWatcherLauncherItemDelegate( WindowWatcherLauncherItemDelegate::~WindowWatcherLauncherItemDelegate() { } -void WindowWatcherLauncherItemDelegate::ItemSelected(const ui::Event& event) { +bool WindowWatcherLauncherItemDelegate::ItemSelected(const ui::Event& event) { aura::Window* window = watcher_->GetWindowByID(id_); if (window->type() == aura::client::WINDOW_TYPE_PANEL) ash::wm::MoveWindowToEventRoot(window, event); window->Show(); ash::wm::ActivateWindow(window); + return false; } base::string16 WindowWatcherLauncherItemDelegate::GetTitle() { diff --git a/ash/shell/window_watcher_launcher_item_delegate.h b/ash/shell/window_watcher_launcher_item_delegate.h index 53014b6..280f3b4 100644 --- a/ash/shell/window_watcher_launcher_item_delegate.h +++ b/ash/shell/window_watcher_launcher_item_delegate.h @@ -22,7 +22,7 @@ class WindowWatcherLauncherItemDelegate : public ash::LauncherItemDelegate { virtual ~WindowWatcherLauncherItemDelegate(); // ash::LauncherItemDelegate overrides: - virtual void ItemSelected(const ui::Event& event) OVERRIDE; + virtual bool ItemSelected(const ui::Event& event) OVERRIDE; virtual base::string16 GetTitle() OVERRIDE; virtual ui::MenuModel* CreateContextMenu( aura::Window* root_window) OVERRIDE; diff --git a/ash/test/test_launcher_item_delegate.cc b/ash/test/test_launcher_item_delegate.cc index 7ac8b72..3913c68 100644 --- a/ash/test/test_launcher_item_delegate.cc +++ b/ash/test/test_launcher_item_delegate.cc @@ -17,13 +17,14 @@ TestLauncherItemDelegate::TestLauncherItemDelegate(aura::Window* window) TestLauncherItemDelegate::~TestLauncherItemDelegate() { } -void TestLauncherItemDelegate::ItemSelected(const ui::Event& event) { +bool TestLauncherItemDelegate::ItemSelected(const ui::Event& event) { if (window_) { if (window_->type() == aura::client::WINDOW_TYPE_PANEL) ash::wm::MoveWindowToEventRoot(window_, event); window_->Show(); ash::wm::ActivateWindow(window_); } + return false; } base::string16 TestLauncherItemDelegate::GetTitle() { diff --git a/ash/test/test_launcher_item_delegate.h b/ash/test/test_launcher_item_delegate.h index fd4c394..a2f6310 100644 --- a/ash/test/test_launcher_item_delegate.h +++ b/ash/test/test_launcher_item_delegate.h @@ -23,7 +23,7 @@ class TestLauncherItemDelegate : public ash::LauncherItemDelegate { virtual ~TestLauncherItemDelegate(); // ash::LauncherItemDelegate overrides: - virtual void ItemSelected(const ui::Event& event) OVERRIDE; + virtual bool ItemSelected(const ui::Event& event) OVERRIDE; virtual base::string16 GetTitle() OVERRIDE; virtual ui::MenuModel* CreateContextMenu( aura::Window* root_window) OVERRIDE; diff --git a/chrome/browser/ui/ash/launcher/app_shortcut_launcher_item_controller.cc b/chrome/browser/ui/ash/launcher/app_shortcut_launcher_item_controller.cc index cbb15ec..5fa4264 100644 --- a/chrome/browser/ui/ash/launcher/app_shortcut_launcher_item_controller.cc +++ b/chrome/browser/ui/ash/launcher/app_shortcut_launcher_item_controller.cc @@ -31,6 +31,8 @@ #if defined(OS_CHROMEOS) #include "chrome/browser/chromeos/login/default_pinned_apps_field_trial.h" +#include "chrome/browser/chromeos/login/user_manager.h" +#include "chrome/browser/ui/ash/multi_user_window_manager.h" #endif using extensions::Extension; @@ -40,6 +42,29 @@ namespace { // The time delta between clicks in which clicks to launch V2 apps are ignored. const int kClickSuppressionInMS = 1000; +// Check if a browser can be used for activation. This addresses a special use +// case in the M31 multi profile mode where a user activates a V1 app which only +// exists yet on another users desktop, but he expects to get only his own app +// items and not the ones from other users through activation. +// TODO(skuhne): Remove this function and replace the call with +// launcher_controller()->IsBrowserFromActiveUser(browser) once this experiment +// goes away. +bool CanBrowserBeUsedForDirectActivation(Browser* browser, + ChromeLauncherController* launcher) { +#if defined(OS_CHROMEOS) + // If running in any multi user mode, check that the browser belongs to the + // active user. + if (chrome::MultiUserWindowManager::GetMultiProfileMode() == + chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_OFF) + return true; + chromeos::UserManager* manager = chromeos::UserManager::Get(); + return manager->GetActiveUser() == + manager->GetUserByProfile(browser->profile()->GetOriginalProfile()); +#else + return launcher->IsBrowserFromActiveUser(browser); +#endif +} + } // namespace // Item controller for an app shortcut. Shortcuts track app and launcher ids, @@ -101,7 +126,7 @@ void AppShortcutLauncherItemController::Launch(ash::LaunchSource source, launcher_controller()->LaunchApp(app_id(), source, event_flags); } -void AppShortcutLauncherItemController::Activate(ash::LaunchSource source) { +bool AppShortcutLauncherItemController::Activate(ash::LaunchSource source) { content::WebContents* content = GetLRUApplication(); if (!content) { if (IsV2App()) { @@ -112,12 +137,13 @@ void AppShortcutLauncherItemController::Activate(ash::LaunchSource source) { // detect if an app was started we suppress any further clicks within a // special time out. if (!AllowNextLaunchAttempt()) - return; + return false; } Launch(source, ui::EF_NONE); - return; + return true; } ActivateContent(content); + return false; } void AppShortcutLauncherItemController::Close() { @@ -190,7 +216,7 @@ AppShortcutLauncherItemController::GetRunningApplications() { return items; } -void AppShortcutLauncherItemController::ItemSelected(const ui::Event& event) { +bool AppShortcutLauncherItemController::ItemSelected(const ui::Event& event) { #if defined(OS_CHROMEOS) if (!app_id().empty()) chromeos::default_pinned_apps_field_trial::RecordShelfAppClick(app_id()); @@ -199,9 +225,9 @@ void AppShortcutLauncherItemController::ItemSelected(const ui::Event& event) { // activate the next item in line if an item of our list is already active. if (event.type() == ui::ET_KEY_RELEASED) { if (AdvanceToNextApp()) - return; + return false; } - Activate(ash::LAUNCH_FROM_UNKNOWN); + return Activate(ash::LAUNCH_FROM_UNKNOWN); } base::string16 AppShortcutLauncherItemController::GetTitle() { @@ -250,7 +276,7 @@ content::WebContents* AppShortcutLauncherItemController::GetLRUApplication() { it = ash_browser_list->begin_last_active(); it != ash_browser_list->end_last_active(); ++it) { Browser* browser = *it; - if (!launcher_controller()->IsBrowserFromActiveUser(browser)) + if (!CanBrowserBeUsedForDirectActivation(browser, launcher_controller())) continue; TabStripModel* tab_strip = browser->tab_strip_model(); // We start to enumerate from the active index. @@ -268,7 +294,7 @@ content::WebContents* AppShortcutLauncherItemController::GetLRUApplication() { for (BrowserList::const_iterator it = ash_browser_list->begin(); it != ash_browser_list->end(); ++it) { Browser* browser = *it; - if (!launcher_controller()->IsBrowserFromActiveUser(browser)) + if (!CanBrowserBeUsedForDirectActivation(browser, launcher_controller())) continue; TabStripModel* tab_strip = browser->tab_strip_model(); for (int index = 0; index < tab_strip->count(); index++) { diff --git a/chrome/browser/ui/ash/launcher/app_shortcut_launcher_item_controller.h b/chrome/browser/ui/ash/launcher/app_shortcut_launcher_item_controller.h index f74725f..70a3a71 100644 --- a/chrome/browser/ui/ash/launcher/app_shortcut_launcher_item_controller.h +++ b/chrome/browser/ui/ash/launcher/app_shortcut_launcher_item_controller.h @@ -40,11 +40,11 @@ class AppShortcutLauncherItemController : public LauncherItemController { virtual bool IsOpen() const OVERRIDE; virtual bool IsVisible() const OVERRIDE; virtual void Launch(ash::LaunchSource source, int event_flags) OVERRIDE; - virtual void Activate(ash::LaunchSource source) OVERRIDE; + virtual bool Activate(ash::LaunchSource source) OVERRIDE; virtual void Close() OVERRIDE; virtual ChromeLauncherAppMenuItems GetApplicationList( int event_flags) OVERRIDE; - virtual void ItemSelected(const ui::Event& event) OVERRIDE; + virtual bool ItemSelected(const ui::Event& event) OVERRIDE; virtual base::string16 GetTitle() OVERRIDE; virtual ui::MenuModel* CreateContextMenu( aura::Window* root_window) OVERRIDE; diff --git a/chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controller.cc b/chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controller.cc index 737c97d..0f8b1a1 100644 --- a/chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controller.cc +++ b/chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controller.cc @@ -143,7 +143,7 @@ void BrowserShortcutLauncherItemController::Launch(ash::LaunchSource source, int event_flags) { } -void BrowserShortcutLauncherItemController::Activate(ash::LaunchSource source) { +bool BrowserShortcutLauncherItemController::Activate(ash::LaunchSource source) { Browser* last_browser = chrome::FindTabbedBrowser( launcher_controller()->profile(), true, @@ -151,11 +151,12 @@ void BrowserShortcutLauncherItemController::Activate(ash::LaunchSource source) { if (!last_browser) { launcher_controller()->CreateNewWindow(); - return; + return true; } launcher_controller()->ActivateWindowOrMinimizeIfActive( last_browser->window(), GetApplicationList(0).size() == 2); + return false; } void BrowserShortcutLauncherItemController::Close() { @@ -215,7 +216,7 @@ BrowserShortcutLauncherItemController::GetApplicationList(int event_flags) { return items.Pass(); } -void BrowserShortcutLauncherItemController::ItemSelected( +bool BrowserShortcutLauncherItemController::ItemSelected( const ui::Event& event) { #if defined(OS_CHROMEOS) chromeos::default_pinned_apps_field_trial::RecordShelfClick( @@ -224,17 +225,17 @@ void BrowserShortcutLauncherItemController::ItemSelected( if (event.flags() & ui::EF_CONTROL_DOWN) { launcher_controller()->CreateNewWindow(); - return; + return true; } // In case of a keyboard event, we were called by a hotkey. In that case we // activate the next item in line if an item of our list is already active. if (event.type() & ui::ET_KEY_RELEASED) { ActivateOrAdvanceToNextBrowser(); - return; + return false; } - Activate(ash::LAUNCH_FROM_UNKNOWN); + return Activate(ash::LAUNCH_FROM_UNKNOWN); } string16 BrowserShortcutLauncherItemController::GetTitle() { diff --git a/chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controller.h b/chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controller.h index d4e64e5..6e7f682 100644 --- a/chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controller.h +++ b/chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controller.h @@ -34,11 +34,11 @@ class BrowserShortcutLauncherItemController : public LauncherItemController { virtual bool IsOpen() const OVERRIDE; virtual bool IsVisible() const OVERRIDE; virtual void Launch(ash::LaunchSource source, int event_flags) OVERRIDE; - virtual void Activate(ash::LaunchSource source) OVERRIDE; + virtual bool Activate(ash::LaunchSource source) OVERRIDE; virtual void Close() OVERRIDE; virtual ChromeLauncherAppMenuItems GetApplicationList( int event_flags) OVERRIDE; - virtual void ItemSelected(const ui::Event& event) OVERRIDE; + virtual bool ItemSelected(const ui::Event& event) OVERRIDE; virtual base::string16 GetTitle() OVERRIDE; virtual ui::MenuModel* CreateContextMenu( aura::Window* root_window) OVERRIDE; diff --git a/chrome/browser/ui/ash/launcher/chrome_launcher_controller_unittest.cc b/chrome/browser/ui/ash/launcher/chrome_launcher_controller_unittest.cc index e1a1738..7b40911 100644 --- a/chrome/browser/ui/ash/launcher/chrome_launcher_controller_unittest.cc +++ b/chrome/browser/ui/ash/launcher/chrome_launcher_controller_unittest.cc @@ -225,9 +225,9 @@ class TestV2AppLauncherItemController : public LauncherItemController { virtual bool IsOpen() const OVERRIDE { return true; } virtual bool IsVisible() const OVERRIDE { return true; } virtual void Launch(ash::LaunchSource source, int event_flags) OVERRIDE {} - virtual void Activate(ash::LaunchSource source) OVERRIDE {} + virtual bool Activate(ash::LaunchSource source) OVERRIDE { return false; } virtual void Close() OVERRIDE {} - virtual void ItemSelected(const ui::Event& event) OVERRIDE {} + virtual bool ItemSelected(const ui::Event& event) OVERRIDE { return false; } virtual string16 GetTitle() OVERRIDE { return string16(); } virtual ChromeLauncherAppMenuItems GetApplicationList( int event_flags) OVERRIDE { diff --git a/chrome/browser/ui/ash/launcher/launcher_item_controller.h b/chrome/browser/ui/ash/launcher/launcher_item_controller.h index 6398e97..fc4a4d1 100644 --- a/chrome/browser/ui/ash/launcher/launcher_item_controller.h +++ b/chrome/browser/ui/ash/launcher/launcher_item_controller.h @@ -80,7 +80,8 @@ class LauncherItemController : public ash::LauncherItemDelegate { // Shows and activates the most-recently-active window associated with the // item, or launches the item if it is not currently open. - virtual void Activate(ash::LaunchSource source) = 0; + // Returns true when a new item got created. + virtual bool Activate(ash::LaunchSource source) = 0; // Closes all windows associated with this item. virtual void Close() = 0; diff --git a/chrome/browser/ui/ash/launcher/shell_window_launcher_item_controller.cc b/chrome/browser/ui/ash/launcher/shell_window_launcher_item_controller.cc index d86b10a..7f95906 100644 --- a/chrome/browser/ui/ash/launcher/shell_window_launcher_item_controller.cc +++ b/chrome/browser/ui/ash/launcher/shell_window_launcher_item_controller.cc @@ -138,11 +138,12 @@ void ShellWindowLauncherItemController::Launch(ash::LaunchSource source, ui::EF_NONE); } -void ShellWindowLauncherItemController::Activate(ash::LaunchSource source) { +bool ShellWindowLauncherItemController::Activate(ash::LaunchSource source) { DCHECK(!shell_windows_.empty()); ShellWindow* window_to_activate = last_active_shell_window_ ? last_active_shell_window_ : shell_windows_.back(); window_to_activate->GetBaseWindow()->Activate(); + return false; } void ShellWindowLauncherItemController::Close() { @@ -183,9 +184,9 @@ ShellWindowLauncherItemController::GetApplicationList(int event_flags) { return items.Pass(); } -void ShellWindowLauncherItemController::ItemSelected(const ui::Event& event) { +bool ShellWindowLauncherItemController::ItemSelected(const ui::Event& event) { if (shell_windows_.empty()) - return; + return false; if (type() == TYPE_APP_PANEL) { DCHECK(shell_windows_.size() == 1); ShellWindow* panel = shell_windows_.front(); @@ -212,6 +213,7 @@ void ShellWindowLauncherItemController::ItemSelected(const ui::Event& event) { ShowAndActivateOrMinimize(window_to_show); } } + return false; } base::string16 ShellWindowLauncherItemController::GetTitle() { diff --git a/chrome/browser/ui/ash/launcher/shell_window_launcher_item_controller.h b/chrome/browser/ui/ash/launcher/shell_window_launcher_item_controller.h index 2ffc77d..3b3b813 100644 --- a/chrome/browser/ui/ash/launcher/shell_window_launcher_item_controller.h +++ b/chrome/browser/ui/ash/launcher/shell_window_launcher_item_controller.h @@ -59,11 +59,11 @@ class ShellWindowLauncherItemController : public LauncherItemController, virtual bool IsOpen() const OVERRIDE; virtual bool IsVisible() const OVERRIDE; virtual void Launch(ash::LaunchSource source, int event_flags) OVERRIDE; - virtual void Activate(ash::LaunchSource source) OVERRIDE; + virtual bool Activate(ash::LaunchSource source) OVERRIDE; virtual void Close() OVERRIDE; virtual ChromeLauncherAppMenuItems GetApplicationList( int event_flags) OVERRIDE; - virtual void ItemSelected(const ui::Event& eent) OVERRIDE; + virtual bool ItemSelected(const ui::Event& eent) OVERRIDE; virtual base::string16 GetTitle() OVERRIDE; virtual ui::MenuModel* CreateContextMenu( aura::Window* root_window) OVERRIDE; |