diff options
author | jamescook@chromium.org <jamescook@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-22 08:05:50 +0000 |
---|---|---|
committer | jamescook@chromium.org <jamescook@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-22 08:05:50 +0000 |
commit | b1b340a939cd35fd4d5be6c38e54c73f526bfe46 (patch) | |
tree | f6558f761d8543dea6ddd9936963075b6876b14e /chrome | |
parent | 9fb8bd07d02facec663c17f84cd140c2b8004d18 (diff) | |
download | chromium_src-b1b340a939cd35fd4d5be6c38e54c73f526bfe46.zip chromium_src-b1b340a939cd35fd4d5be6c38e54c73f526bfe46.tar.gz chromium_src-b1b340a939cd35fd4d5be6c38e54c73f526bfe46.tar.bz2 |
Remove PerBrowser launcher, reland step 1 of 2
Relanding https://chromiumcodereview.appspot.com/22887015/ in two steps to
preserve history of c/b/ui/ash/launcher/chrome_launcher_controller_per_app.*
Step 2 will rename chrome_launcher_controller_per_app.* to
chrome_launcher_controller.*
Original description:
Remove per-browser.* and related tests.
Remove IsPerAppLauncher() interface in LauncherDelegate.
Remove ash-disable-per-app-launcher switch.
Change class name from ChromeLauncherControllerPerApp to ChromeLauncherController.
In the next CL, BrowserLauncherItemController will be replaced with new browser status monitor only for monitoring browser and tab status.
BUG=169303
TEST=unit_tests, browser_tests Launcher*
TBR=skuhne@chromium.org
Review URL: https://chromiumcodereview.appspot.com/23068021
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@218945 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
36 files changed, 698 insertions, 4709 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd index ab09e5a..f7a3caa 100644 --- a/chrome/app/generated_resources.grd +++ b/chrome/app/generated_resources.grd @@ -5971,12 +5971,6 @@ Keep your key file in a safe place. You will need it to create new versions of y <message name="IDS_FLAGS_ASH_AUTO_MAXIMIZING_DESCRIPTION" desc="Description for the option to disable the auto window maximizing functionality."> Disable automatic window maximization for browser / app windows if they are started the first time. </message> - <message name="IDS_FLAGS_ASH_DISABLE_PER_APP_LAUNCHER_NAME" desc="Name for the option to enable/disable the per application sorting launcher functionality."> - Disable per application sorting in the launcher. - </message> - <message name="IDS_FLAGS_ASH_DISABLE_PER_APP_LAUNCHER_DESCRIPTION" desc="Description for the option to enable/disable the per application sorting launcher functionality."> - Disable the per application sorting mode of the launcher. - </message> <message name="IDS_FLAGS_DISABLE_GESTURE_REQUIREMENT_FOR_MEDIA_PLAYBACK_NAME" desc="Title for the flag to disable gesture requiment for media playback"> Disable gesture requirement for media playback. </message> diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc index 399d30a..0334972 100644 --- a/chrome/browser/about_flags.cc +++ b/chrome/browser/about_flags.cc @@ -783,13 +783,6 @@ const Experiment kExperiments[] = { kOsWin | kOsLinux | kOsCrOS, SINGLE_VALUE_TYPE(ash::switches::kAshDisableAutoWindowPlacement) }, - { - "ash-disable-per-app-launcher", - IDS_FLAGS_ASH_DISABLE_PER_APP_LAUNCHER_NAME, - IDS_FLAGS_ASH_DISABLE_PER_APP_LAUNCHER_DESCRIPTION, - kOsWin | kOsLinux | kOsCrOS, - SINGLE_VALUE_TYPE(ash::switches::kAshDisablePerAppLauncher) - }, #endif { "per-tile-painting", diff --git a/chrome/browser/ui/ash/app_list/app_list_controller_ash.cc b/chrome/browser/ui/ash/app_list/app_list_controller_ash.cc index 7bf0587..4eea851 100644 --- a/chrome/browser/ui/ash/app_list/app_list_controller_ash.cc +++ b/chrome/browser/ui/ash/app_list/app_list_controller_ash.cc @@ -5,7 +5,7 @@ #include "chrome/browser/ui/ash/app_list/app_list_controller_ash.h" #include "ash/shell.h" -#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" +#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app.h" AppListControllerDelegateAsh::AppListControllerDelegateAsh() {} diff --git a/chrome/browser/ui/ash/app_list/app_list_service_ash.cc b/chrome/browser/ui/ash/app_list/app_list_service_ash.cc index 1e9d69f..4aa59fa 100644 --- a/chrome/browser/ui/ash/app_list/app_list_service_ash.cc +++ b/chrome/browser/ui/ash/app_list/app_list_service_ash.cc @@ -9,7 +9,7 @@ #include "base/memory/singleton.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/app_list/app_list_service_impl.h" -#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" +#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app.h" namespace { diff --git a/chrome/browser/ui/ash/chrome_shell_delegate.cc b/chrome/browser/ui/ash/chrome_shell_delegate.cc index 2a22df0..ad01678 100644 --- a/chrome/browser/ui/ash/chrome_shell_delegate.cc +++ b/chrome/browser/ui/ash/chrome_shell_delegate.cc @@ -30,7 +30,7 @@ #include "chrome/browser/ui/app_list/app_list_view_delegate.h" #include "chrome/browser/ui/ash/app_list/app_list_controller_ash.h" #include "chrome/browser/ui/ash/ash_keyboard_controller_proxy.h" -#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" +#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app.h" #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h" #include "chrome/browser/ui/ash/user_action_handler.h" #include "chrome/browser/ui/ash/window_positioner.h" 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 7cf4554..1470c9e 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 @@ -11,7 +11,6 @@ #include "chrome/browser/favicon/favicon_tab_helper.h" #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h" #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_tab.h" -#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app.h" #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h" #include "chrome/browser/ui/browser.h" @@ -40,9 +39,9 @@ const int kClickSuppressionInMS = 1000; // item with the appropriate LauncherItemController type). AppShortcutLauncherItemController::AppShortcutLauncherItemController( const std::string& app_id, - ChromeLauncherControllerPerApp* controller) + ChromeLauncherController* controller) : LauncherItemController(TYPE_SHORTCUT, app_id, controller), - app_controller_(controller) { + chrome_launcher_controller_(controller) { // To detect V1 applications we use their domain and match them against the // used URL. This will also work with applications like Google Drive. const Extension* extension = @@ -68,7 +67,7 @@ bool AppShortcutLauncherItemController::IsCurrentlyShownInWindow( browser ? browser->tab_strip_model()->GetActiveWebContents() : NULL; std::vector<content::WebContents*> content = - app_controller_->GetV1ApplicationsFromAppId(app_id()); + chrome_launcher_controller_->GetV1ApplicationsFromAppId(app_id()); std::vector<content::WebContents*>::const_iterator iter = std::find(content.begin(), content.end(), active_content_of_window); @@ -77,13 +76,14 @@ bool AppShortcutLauncherItemController::IsCurrentlyShownInWindow( } bool AppShortcutLauncherItemController::IsOpen() const { - return !app_controller_->GetV1ApplicationsFromAppId(app_id()).empty(); + return !chrome_launcher_controller_-> + GetV1ApplicationsFromAppId(app_id()).empty(); } bool AppShortcutLauncherItemController::IsVisible() const { // Return true if any browser window associated with the app is visible. std::vector<content::WebContents*> content = - app_controller_->GetV1ApplicationsFromAppId(app_id()); + chrome_launcher_controller_->GetV1ApplicationsFromAppId(app_id()); for (size_t i = 0; i < content.size(); i++) { Browser* browser = chrome::FindBrowserWithWebContents(content[i]); if (browser && browser->window()->GetNativeWindow()->IsVisible()) @@ -93,7 +93,7 @@ bool AppShortcutLauncherItemController::IsVisible() const { } void AppShortcutLauncherItemController::Launch(int event_flags) { - app_controller_->LaunchApp(app_id(), event_flags); + launcher_controller()->LaunchApp(app_id(), event_flags); } void AppShortcutLauncherItemController::Activate() { @@ -118,7 +118,7 @@ void AppShortcutLauncherItemController::Activate() { void AppShortcutLauncherItemController::Close() { // Close all running 'programs' of this type. std::vector<content::WebContents*> content = - app_controller_->GetV1ApplicationsFromAppId(app_id()); + launcher_controller()->GetV1ApplicationsFromAppId(app_id()); for (size_t i = 0; i < content.size(); i++) { Browser* browser = chrome::FindBrowserWithWebContents(content[i]); if (!browser) @@ -161,8 +161,8 @@ AppShortcutLauncherItemController::GetApplicationList(int event_flags) { for (size_t i = 0; i < content_list.size(); i++) { content::WebContents* web_contents = content_list[i]; // Get the icon. - gfx::Image app_icon = app_controller_->GetAppListIcon(web_contents); - string16 title = app_controller_->GetAppListTitle(web_contents); + gfx::Image app_icon = launcher_controller()->GetAppListIcon(web_contents); + string16 title = launcher_controller()->GetAppListTitle(web_contents); items.push_back(new ChromeLauncherAppMenuItemTab( title, &app_icon, web_contents, i == 0)); } @@ -265,8 +265,8 @@ bool AppShortcutLauncherItemController::WebContentMatchesApp( refocus_pattern.MatchesURL(tab_url)) || (extension->OverlapsWithOrigin(tab_url) && extension->web_extent().MatchesURL(tab_url)) || - launcher_controller()->GetPerAppInterface()-> - IsWebContentHandledByApplication(web_contents, app_id())); + launcher_controller()->IsWebContentHandledByApplication(web_contents, + app_id())); } void AppShortcutLauncherItemController::ActivateContent( @@ -279,7 +279,8 @@ void AppShortcutLauncherItemController::ActivateContent( int old_index = tab_strip->active_index(); if (index != old_index) tab_strip->ActivateTabAt(index, false); - app_controller_->ActivateWindowOrMinimizeIfActive(browser->window(), + launcher_controller()->ActivateWindowOrMinimizeIfActive( + browser->window(), index == old_index && GetRunningApplications().size() == 1); } @@ -312,7 +313,8 @@ bool AppShortcutLauncherItemController::AdvanceToNextApp() { } bool AppShortcutLauncherItemController::IsV2App() { - const Extension* extension = app_controller_->GetExtensionForAppID(app_id()); + const Extension* extension = + launcher_controller()->GetExtensionForAppID(app_id()); return extension && extension->is_platform_app(); } 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 bae7e3c..bf8ab68 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 @@ -8,8 +8,10 @@ #include <string> #include "base/time/time.h" -#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app.h" #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h" +#include "url/gurl.h" + +class URLPattern; namespace aura { class Window; @@ -27,7 +29,7 @@ class ChromeLauncherController; class AppShortcutLauncherItemController : public LauncherItemController { public: AppShortcutLauncherItemController(const std::string& app_id, - ChromeLauncherControllerPerApp* controller); + ChromeLauncherController* controller); virtual ~AppShortcutLauncherItemController(); @@ -79,12 +81,13 @@ class AppShortcutLauncherItemController : public LauncherItemController { bool AllowNextLaunchAttempt(); GURL refocus_url_; - ChromeLauncherControllerPerApp* app_controller_; // Since V2 applications can be undetectable after launching, this timer is // keeping track of the last launch attempt. base::Time last_launch_attempt_; + ChromeLauncherController* chrome_launcher_controller_; + DISALLOW_COPY_AND_ASSIGN(AppShortcutLauncherItemController); }; diff --git a/chrome/browser/ui/ash/launcher/browser_launcher_item_controller.cc b/chrome/browser/ui/ash/launcher/browser_launcher_item_controller.cc index a2c958e..583956d 100644 --- a/chrome/browser/ui/ash/launcher/browser_launcher_item_controller.cc +++ b/chrome/browser/ui/ash/launcher/browser_launcher_item_controller.cc @@ -13,7 +13,7 @@ #include "chrome/browser/favicon/favicon_tab_helper.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h" -#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" +#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_list.h" #include "chrome/browser/ui/browser_window.h" @@ -63,17 +63,11 @@ void BrowserLauncherItemController::Init() { ash::LauncherItemStatus app_status = ash::wm::IsActiveWindow(window_) ? ash::STATUS_ACTIVE : ash::STATUS_RUNNING; - if (type() != TYPE_TABBED && type() != TYPE_WINDOWED_APP) { + if (type() != TYPE_TABBED && type() != TYPE_WINDOWED_APP) launcher_controller()->CreateAppLauncherItem(this, app_id(), app_status); - } else { - launcher_controller()->CreateTabbedLauncherItem( - this, - is_incognito_ ? ChromeLauncherController::STATE_INCOGNITO : - ChromeLauncherController::STATE_NOT_INCOGNITO, - app_status); - if (type() == TYPE_WINDOWED_APP) - launcher_controller()->LockV1AppWithID(LauncherItemController::app_id()); - } + else if (type() == TYPE_WINDOWED_APP) + launcher_controller()->LockV1AppWithID(LauncherItemController::app_id()); + // In testing scenarios we can get tab strips with no active contents. if (tab_model_->active_index() != TabStripModel::kNoTab) UpdateLauncher(tab_model_->GetActiveWebContents()); @@ -92,8 +86,7 @@ BrowserLauncherItemController* BrowserLauncherItemController::Create( type = TYPE_TABBED; if (!browser->is_type_tabbed() && browser->is_type_popup() && - browser->is_app() && - ChromeLauncherController::instance()->GetPerAppInterface()) { + browser->is_app()) { app_id = web_app::GetExtensionIdFromApplicationName( browser->app_name()); // Only allow this for known applications. Some unit tests for example @@ -180,11 +173,6 @@ void BrowserLauncherItemController::OnRemoved() { void BrowserLauncherItemController::LauncherItemChanged( int index, const ash::LauncherItem& old_item) { - if (!launcher_controller()->GetPerAppInterface() && - launcher_model()->items()[index].status == ash::STATUS_ACTIVE && - old_item.status == ash::STATUS_RUNNING) { - Activate(); - } } ChromeLauncherAppMenuItems @@ -201,9 +189,8 @@ void BrowserLauncherItemController::ActiveTabChanged( int reason) { // Update immediately on a tab change. if (old_contents && - (!launcher_controller()->GetPerAppInterface() || - TabStripModel::kNoTab != - tab_model_->GetIndexOfWebContents(old_contents))) + TabStripModel::kNoTab != + tab_model_->GetIndexOfWebContents(old_contents)) UpdateAppState(old_contents); UpdateAppState(new_contents); UpdateLauncher(new_contents); @@ -257,60 +244,15 @@ void BrowserLauncherItemController::OnWindowPropertyChanged( } void BrowserLauncherItemController::UpdateItemStatus() { - if (launcher_controller()->GetPerAppInterface()) - return; - - ash::LauncherItemStatus status; - if (ash::wm::IsActiveWindow(window_)) { - // Clear attention state if active. - if (window_->GetProperty(aura::client::kDrawAttentionKey)) - window_->SetProperty(aura::client::kDrawAttentionKey, false); - status = ash::STATUS_ACTIVE; - } else if (window_->GetProperty(aura::client::kDrawAttentionKey)) { - status = ash::STATUS_ATTENTION; - } else { - status = ash::STATUS_RUNNING; - } - launcher_controller()->SetItemStatus(launcher_id(), status); } void BrowserLauncherItemController::UpdateLauncher(content::WebContents* tab) { - if (launcher_controller()->GetPerAppInterface()) - return; - - if (type() == TYPE_APP_PANEL) - return; // Maintained entirely by ChromeLauncherController. - - if (!tab) - return; // Assume the window is going to be closed if there are no tabs. - - int item_index = launcher_model()->ItemIndexByID(launcher_id()); - if (item_index == -1) - return; - - ash::LauncherItem item = launcher_model()->items()[item_index]; - DCHECK_EQ(TYPE_TABBED, type()); - ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); - FaviconTabHelper* favicon_tab_helper = - FaviconTabHelper::FromWebContents(tab); - if (favicon_tab_helper->ShouldDisplayFavicon()) { - item.image = favicon_tab_helper->GetFavicon().AsImageSkia(); - if (item.image.isNull()) { - item.image = *rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON); - } - } else { - item.image = *rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON); - } - launcher_model()->Set(item_index, item); } void BrowserLauncherItemController::UpdateAppState(content::WebContents* tab) { ChromeLauncherController::AppState app_state; - if (!launcher_controller()->GetPerAppInterface() && - tab_model_->GetIndexOfWebContents(tab) == TabStripModel::kNoTab) { - app_state = ChromeLauncherController::APP_STATE_REMOVED; - } else if (tab_model_->GetActiveWebContents() == tab) { + if (tab_model_->GetActiveWebContents() == tab) { if (ash::wm::IsActiveWindow(window_)) app_state = ChromeLauncherController::APP_STATE_WINDOW_ACTIVE; else diff --git a/chrome/browser/ui/ash/launcher/browser_launcher_item_controller_unittest.cc b/chrome/browser/ui/ash/launcher/browser_launcher_item_controller_unittest.cc deleted file mode 100644 index 0f20bc2..0000000 --- a/chrome/browser/ui/ash/launcher/browser_launcher_item_controller_unittest.cc +++ /dev/null @@ -1,543 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/ui/ash/launcher/browser_launcher_item_controller.h" - -#include <map> -#include <string> - -#include "ash/ash_switches.h" -#include "ash/launcher/launcher_model.h" -#include "base/command_line.h" -#include "base/memory/scoped_ptr.h" -#include "chrome/browser/favicon/favicon_tab_helper.h" -#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" -#include "chrome/browser/ui/ash/launcher/launcher_item_controller.h" -#include "chrome/browser/ui/tabs/tab_strip_model.h" -#include "chrome/browser/ui/tabs/test_tab_strip_model_delegate.h" -#include "chrome/test/base/chrome_render_view_host_test_harness.h" -#include "chrome/test/base/testing_profile.h" -#include "content/public/browser/web_contents.h" -#include "testing/gtest/include/gtest/gtest.h" -#include "third_party/skia/include/core/SkBitmap.h" -#include "ui/aura/client/activation_change_observer.h" -#include "ui/aura/client/activation_delegate.h" -#include "ui/aura/client/aura_constants.h" -#include "ui/aura/root_window.h" -#include "ui/aura/test/test_activation_client.h" -#include "ui/aura/test/test_window_delegate.h" -#include "ui/aura/window.h" -#include "ui/aura/window_delegate.h" -#include "ui/base/events/event.h" - -// TODO(skuhne): Remove this module together with the -// browser_launcher_item_controller.* when the old launcher goes away. - -namespace { - -// Test implementation of AppTabHelper. -class AppTabHelperImpl : public ChromeLauncherController::AppTabHelper { - public: - AppTabHelperImpl() {} - virtual ~AppTabHelperImpl() {} - - // Sets the id for the specified tab. The id is removed if Remove() is - // invoked. - void SetAppID(content::WebContents* tab, const std::string& id) { - tab_id_map_[tab] = id; - } - - // Returns true if there is an id registered for |tab|. - bool HasAppID(content::WebContents* tab) const { - return tab_id_map_.find(tab) != tab_id_map_.end(); - } - - // AppTabHelper implementation: - virtual std::string GetAppID(content::WebContents* tab) OVERRIDE { - return tab_id_map_.find(tab) != tab_id_map_.end() ? tab_id_map_[tab] : - std::string(); - } - - virtual bool IsValidID(const std::string& id) OVERRIDE { - for (TabToStringMap::const_iterator i = tab_id_map_.begin(); - i != tab_id_map_.end(); ++i) { - if (i->second == id) - return true; - } - return false; - } - - private: - typedef std::map<content::WebContents*, std::string> TabToStringMap; - - TabToStringMap tab_id_map_; - - DISALLOW_COPY_AND_ASSIGN(AppTabHelperImpl); -}; - -// Test implementation of AppIconLoader. -class AppIconLoaderImpl : public extensions::AppIconLoader { - public: - AppIconLoaderImpl() : fetch_count_(0) {} - virtual ~AppIconLoaderImpl() {} - - // Returns the number of times FetchImage() has been invoked and resets the - // count to 0. - int GetAndClearFetchCount() { - int value = fetch_count_; - fetch_count_ = 0; - return value; - } - - // AppIconLoader implementation: - virtual void FetchImage(const std::string& id) OVERRIDE { - fetch_count_++; - } - virtual void ClearImage(const std::string& id) OVERRIDE { - } - virtual void UpdateImage(const std::string& id) OVERRIDE { - } - - private: - int fetch_count_; - - DISALLOW_COPY_AND_ASSIGN(AppIconLoaderImpl); -}; - -// Test implementation of TabStripModelDelegate. -class TabHelperTabStripModelDelegate : public TestTabStripModelDelegate { - public: - TabHelperTabStripModelDelegate() {} - virtual ~TabHelperTabStripModelDelegate() {} - - virtual void WillAddWebContents(content::WebContents* contents) OVERRIDE { - // BrowserLauncherItemController assumes that all WebContents passed to it - // have attached an extensions::TabHelper and a FaviconTabHelper. The - // TestTabStripModelDelegate adds an extensions::TabHelper. - TestTabStripModelDelegate::WillAddWebContents(contents); - FaviconTabHelper::CreateForWebContents(contents); - } - - private: - DISALLOW_COPY_AND_ASSIGN(TabHelperTabStripModelDelegate); -}; - -} // namespace - -// TODO(skuhne): Several of these unit tests need to be moved into a new home -// when the old launcher & the browser launcher item controller are removed -// (several of these tests are not testing the BrowserLauncherItemController - -// but the LauncherController framework). -class LauncherItemControllerPerAppTest - : public ChromeRenderViewHostTestHarness { - public: - virtual void SetUp() OVERRIDE { - ChromeRenderViewHostTestHarness::SetUp(); - - activation_client_.reset( - new aura::test::TestActivationClient(root_window())); - launcher_model_.reset(new ash::LauncherModel); - launcher_delegate_.reset( - ChromeLauncherController::CreateInstance(profile(), - launcher_model_.get())); - app_tab_helper_ = new AppTabHelperImpl; - app_icon_loader_ = new AppIconLoaderImpl; - launcher_delegate_->SetAppTabHelperForTest(app_tab_helper_); - launcher_delegate_->SetAppIconLoaderForTest(app_icon_loader_); - launcher_delegate_->Init(); - } - - virtual void TearDown() OVERRIDE { - launcher_delegate_.reset(); - ChromeRenderViewHostTestHarness::TearDown(); - } - - protected: - // Contains all the objects needed to create a BrowserLauncherItemController. - struct State : public aura::client::ActivationDelegate, - public aura::client::ActivationChangeObserver { - public: - State(LauncherItemControllerPerAppTest* test, - const std::string& app_id, - BrowserLauncherItemController::Type launcher_type) - : launcher_test(test), - window(NULL), - tab_strip(&tab_strip_delegate, test->profile()), - updater(launcher_type, - &window, - &tab_strip, - test->launcher_delegate_.get(), - app_id) { - window.Init(ui::LAYER_NOT_DRAWN); - launcher_test->root_window()->AddChild(&window); - launcher_test->activation_client_->ActivateWindow(&window); - aura::client::SetActivationDelegate(&window, this); - aura::client::SetActivationChangeObserver(&window, this); - updater.Init(); - } - - ash::LauncherItem GetUpdaterItem() { - ash::LauncherID launcher_id = - BrowserLauncherItemController::TestApi(&updater).item_id(); - int index = launcher_test->launcher_model_->ItemIndexByID(launcher_id); - return launcher_test->launcher_model_->items()[index]; - } - - // aura::client::ActivationDelegate overrides. - virtual bool ShouldActivate() const OVERRIDE { - return true; - } - - // aura::client::ActivationChangeObserver overrides: - virtual void OnWindowActivated(aura::Window* gained_active, - aura::Window* lost_active) OVERRIDE { - DCHECK(&window == gained_active || &window == lost_active); - updater.BrowserActivationStateChanged(); - } - - LauncherItemControllerPerAppTest* launcher_test; - aura::Window window; - TabHelperTabStripModelDelegate tab_strip_delegate; - TabStripModel tab_strip; - BrowserLauncherItemController updater; - - private: - DISALLOW_COPY_AND_ASSIGN(State); - }; - - const std::string& GetAppID(ash::LauncherID id) const { - return launcher_delegate_->GetAppIdFromLauncherIdForTest(id); - } - - void ResetAppTabHelper() { - launcher_delegate_->SetAppTabHelperForTest(app_tab_helper_); - } - - void ResetAppIconLoader() { - launcher_delegate_->SetAppIconLoaderForTest(app_icon_loader_); - } - - void UnpinAppsWithID(const std::string& app_id) { - launcher_delegate_->UnpinAppsWithID(app_id); - } - - const ash::LauncherItem& GetItem(BrowserLauncherItemController* updater) { - int index = launcher_model_->ItemIndexByID( - BrowserLauncherItemController::TestApi(updater).item_id()); - return launcher_model_->items()[index]; - } - - scoped_ptr<ash::LauncherModel> launcher_model_; - scoped_ptr<ChromeLauncherController> launcher_delegate_; - - // Owned by BrowserLauncherItemController. - AppTabHelperImpl* app_tab_helper_; - AppIconLoaderImpl* app_icon_loader_; - - scoped_ptr<aura::test::TestActivationClient> activation_client_; -}; - -// Verify that the launcher item positions are persisted and restored. -TEST_F(LauncherItemControllerPerAppTest, PersistLauncherItemPositions) { - EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, - launcher_model_->items()[0].type); - EXPECT_EQ(ash::TYPE_APP_LIST, - launcher_model_->items()[1].type); - scoped_ptr<content::WebContents> tab1(CreateTestWebContents()); - scoped_ptr<content::WebContents> tab2(CreateTestWebContents()); - app_tab_helper_->SetAppID(tab1.get(), "1"); - app_tab_helper_->SetAppID(tab1.get(), "2"); - - EXPECT_FALSE(launcher_delegate_->IsAppPinned("1")); - launcher_delegate_->PinAppWithID("1"); - EXPECT_TRUE(launcher_delegate_->IsAppPinned("1")); - launcher_delegate_->PinAppWithID("2"); - - EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, - launcher_model_->items()[0].type); - EXPECT_EQ(ash::TYPE_APP_SHORTCUT, - launcher_model_->items()[1].type); - EXPECT_EQ(ash::TYPE_APP_SHORTCUT, - launcher_model_->items()[2].type); - EXPECT_EQ(ash::TYPE_APP_LIST, - launcher_model_->items()[3].type); - - launcher_model_->Move(0, 2); - EXPECT_EQ(ash::TYPE_APP_SHORTCUT, - launcher_model_->items()[0].type); - EXPECT_EQ(ash::TYPE_APP_SHORTCUT, - launcher_model_->items()[1].type); - EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, - launcher_model_->items()[2].type); - EXPECT_EQ(ash::TYPE_APP_LIST, - launcher_model_->items()[3].type); - - launcher_delegate_.reset(); - launcher_model_.reset(new ash::LauncherModel); - launcher_delegate_.reset( - ChromeLauncherController::CreateInstance(profile(), - launcher_model_.get())); - app_tab_helper_ = new AppTabHelperImpl; - app_tab_helper_->SetAppID(tab1.get(), "1"); - app_tab_helper_->SetAppID(tab2.get(), "2"); - ResetAppTabHelper(); - - launcher_delegate_->Init(); - - EXPECT_EQ(ash::TYPE_APP_SHORTCUT, - launcher_model_->items()[0].type); - EXPECT_EQ(ash::TYPE_APP_SHORTCUT, - launcher_model_->items()[1].type); - EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, - launcher_model_->items()[2].type); - EXPECT_EQ(ash::TYPE_APP_LIST, - launcher_model_->items()[3].type); -} - -class BrowserLauncherItemControllerTest - : public LauncherItemControllerPerAppTest { - public: - BrowserLauncherItemControllerTest() {} - - virtual void SetUp() OVERRIDE { - CommandLine::ForCurrentProcess()->AppendSwitch( - ash::switches::kAshDisablePerAppLauncher); - - LauncherItemControllerPerAppTest::SetUp(); - } - - virtual void TearDown() OVERRIDE { - LauncherItemControllerPerAppTest::TearDown(); - } -}; - -// Verifies a new launcher item is added for TYPE_TABBED. -TEST_F(BrowserLauncherItemControllerTest, TabbedSetup) { - size_t initial_size = launcher_model_->items().size(); - { - scoped_ptr<content::WebContents> web_contents(CreateTestWebContents()); - State state(this, std::string(), - BrowserLauncherItemController::TYPE_TABBED); - - // There should be one more item. - ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); - // New item should be added at the end. - EXPECT_EQ(ash::TYPE_TABBED, state.GetUpdaterItem().type); - } - - // Deleting the BrowserLauncherItemController should have removed the item. - ASSERT_EQ(initial_size, launcher_model_->items().size()); - - // Do the same, but this time add the tab first. - { - scoped_ptr<content::WebContents> web_contents(CreateTestWebContents()); - - TabHelperTabStripModelDelegate tab_strip_delegate; - TabStripModel tab_strip(&tab_strip_delegate, profile()); - tab_strip.InsertWebContentsAt(0, - web_contents.get(), - TabStripModel::ADD_ACTIVE); - aura::Window window(NULL); - window.Init(ui::LAYER_NOT_DRAWN); - root_window()->AddChild(&window); - BrowserLauncherItemController updater( - LauncherItemController::TYPE_TABBED, - &window, &tab_strip, launcher_delegate_.get(), - std::string()); - updater.Init(); - - // There should be one more item. - ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); - // New item should be added at the end. - EXPECT_EQ(ash::TYPE_TABBED, GetItem(&updater).type); - } -} - -// Verifies pinned apps are persisted and restored. -TEST_F(BrowserLauncherItemControllerTest, PersistPinned) { - size_t initial_size = launcher_model_->items().size(); - scoped_ptr<content::WebContents> tab1(CreateTestWebContents()); - - app_tab_helper_->SetAppID(tab1.get(), "1"); - - app_icon_loader_->GetAndClearFetchCount(); - launcher_delegate_->PinAppWithID("1"); - ash::LauncherID id = launcher_delegate_->GetLauncherIDForAppID("1"); - int app_index = launcher_model_->ItemIndexByID(id); - EXPECT_GT(app_icon_loader_->GetAndClearFetchCount(), 0); - EXPECT_EQ(ash::TYPE_APP_SHORTCUT, - launcher_model_->items()[app_index].type); - EXPECT_TRUE(launcher_delegate_->IsAppPinned("1")); - EXPECT_FALSE(launcher_delegate_->IsAppPinned("0")); - EXPECT_EQ(initial_size + 1, launcher_model_->items().size()); - - launcher_delegate_.reset(); - launcher_model_.reset(new ash::LauncherModel); - launcher_delegate_.reset( - ChromeLauncherController::CreateInstance(profile(), - launcher_model_.get())); - app_tab_helper_ = new AppTabHelperImpl; - app_tab_helper_->SetAppID(tab1.get(), "1"); - ResetAppTabHelper(); - app_icon_loader_ = new AppIconLoaderImpl; - ResetAppIconLoader(); - launcher_delegate_->Init(); - EXPECT_GT(app_icon_loader_->GetAndClearFetchCount(), 0); - ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); - EXPECT_TRUE(launcher_delegate_->IsAppPinned("1")); - EXPECT_FALSE(launcher_delegate_->IsAppPinned("0")); - EXPECT_EQ(ash::TYPE_APP_SHORTCUT, - launcher_model_->items()[app_index].type); - - UnpinAppsWithID("1"); - ASSERT_EQ(initial_size, launcher_model_->items().size()); -} - -// Verify that launcher item positions are persisted and restored. -TEST_F(BrowserLauncherItemControllerTest, - PersistLauncherItemPositionsPerBrowser) { - int browser_shortcut_index = 0; - int app_list_index = 1; - - EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, - launcher_model_->items()[browser_shortcut_index].type); - EXPECT_EQ(ash::TYPE_APP_LIST, - launcher_model_->items()[app_list_index].type); - - scoped_ptr<content::WebContents> tab1(CreateTestWebContents()); - scoped_ptr<content::WebContents> tab2(CreateTestWebContents()); - - app_tab_helper_->SetAppID(tab1.get(), "1"); - app_tab_helper_->SetAppID(tab2.get(), "2"); - - app_icon_loader_->GetAndClearFetchCount(); - launcher_delegate_->PinAppWithID("1"); - ash::LauncherID id = launcher_delegate_->GetLauncherIDForAppID("1"); - int app1_index = launcher_model_->ItemIndexByID(id); - - launcher_delegate_->PinAppWithID("2"); - id = launcher_delegate_->GetLauncherIDForAppID("2"); - int app2_index = launcher_model_->ItemIndexByID(id); - - launcher_model_->Move(browser_shortcut_index, app1_index); - - browser_shortcut_index = 1; - app1_index = 0; - - EXPECT_GT(app_icon_loader_->GetAndClearFetchCount(), 0); - EXPECT_EQ(ash::TYPE_APP_SHORTCUT, - launcher_model_->items()[app1_index].type); - EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, - launcher_model_->items()[browser_shortcut_index].type); - EXPECT_EQ(ash::TYPE_APP_SHORTCUT, - launcher_model_->items()[app2_index].type); - - launcher_delegate_.reset(); - launcher_model_.reset(new ash::LauncherModel); - launcher_delegate_.reset( - ChromeLauncherController::CreateInstance(profile(), - launcher_model_.get())); - - app_tab_helper_ = new AppTabHelperImpl; - app_tab_helper_->SetAppID(tab1.get(), "1"); - app_tab_helper_->SetAppID(tab2.get(), "2"); - ResetAppTabHelper(); - app_icon_loader_ = new AppIconLoaderImpl; - ResetAppIconLoader(); - launcher_delegate_->Init(); - - EXPECT_EQ(ash::TYPE_APP_SHORTCUT, - launcher_model_->items()[app1_index].type); - EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, - launcher_model_->items()[browser_shortcut_index].type); - EXPECT_EQ(ash::TYPE_APP_SHORTCUT, - launcher_model_->items()[app2_index].type); -} - -// Confirm that tabbed browsers handle activation correctly. -TEST_F(BrowserLauncherItemControllerTest, ActivateBrowsers) { - State state1(this, std::string(), BrowserLauncherItemController::TYPE_TABBED); - - // First browser is active. - EXPECT_EQ(ash::STATUS_ACTIVE, state1.GetUpdaterItem().status); - - { - // Both running. - State state2(this, std::string(), - BrowserLauncherItemController::TYPE_TABBED); - EXPECT_EQ(ash::STATUS_ACTIVE, state2.GetUpdaterItem().status); - EXPECT_EQ(ash::STATUS_RUNNING, state1.GetUpdaterItem().status); - - // Make first browser active again. - activation_client_->ActivateWindow(&state1.window); - EXPECT_EQ(ash::STATUS_ACTIVE, state1.GetUpdaterItem().status); - EXPECT_EQ(ash::STATUS_RUNNING, state2.GetUpdaterItem().status); - - // And back to second. - activation_client_->ActivateWindow(&state2.window); - EXPECT_EQ(ash::STATUS_ACTIVE, state2.GetUpdaterItem().status); - EXPECT_EQ(ash::STATUS_RUNNING, state1.GetUpdaterItem().status); - } - - // First browser should be active again after second is closed. - EXPECT_EQ(ash::STATUS_ACTIVE, state1.GetUpdaterItem().status); -} - -// Confirm that window activation works through the model. -TEST_F(BrowserLauncherItemControllerTest, SwitchDirectlyToApp) { - State state1(this, std::string(), - BrowserLauncherItemController::TYPE_TABBED); - int index1 = launcher_model_->ItemIndexByID(state1.GetUpdaterItem().id); - - // Second app is active and first is inactive. - State state2(this, std::string(), - BrowserLauncherItemController::TYPE_TABBED); - int index2 = launcher_model_->ItemIndexByID(state2.GetUpdaterItem().id); - - EXPECT_EQ(ash::STATUS_RUNNING, state1.GetUpdaterItem().status); - EXPECT_EQ(ash::STATUS_ACTIVE, state2.GetUpdaterItem().status); - EXPECT_EQ(&state2.window, activation_client_->GetActiveWindow()); - - // Test that we can properly switch to the first item. - ash::LauncherItem new_item1(launcher_model_->items()[index1]); - new_item1.status = ash::STATUS_ACTIVE; - launcher_model_->Set(index1, new_item1); - EXPECT_EQ(ash::STATUS_ACTIVE, launcher_model_->items()[index1].status); - EXPECT_EQ(ash::STATUS_RUNNING, launcher_model_->items()[index2].status); - EXPECT_EQ(&state1.window, activation_client_->GetActiveWindow()); - - // And to the second item active. - ash::LauncherItem new_item2(launcher_model_->items()[index2]); - new_item2.status = ash::STATUS_ACTIVE; - launcher_model_->Set(index2, new_item2); - EXPECT_EQ(ash::STATUS_RUNNING, launcher_model_->items()[index1].status); - EXPECT_EQ(ash::STATUS_ACTIVE, launcher_model_->items()[index2].status); - EXPECT_EQ(&state2.window, activation_client_->GetActiveWindow()); -} - -// Test attention states of windows. -TEST_F(BrowserLauncherItemControllerTest, FlashWindow) { - // App panel first - State app_state(this, "1", BrowserLauncherItemController::TYPE_APP_PANEL); - EXPECT_EQ(ash::STATUS_ACTIVE, app_state.GetUpdaterItem().status); - - // Active windows don't show attention. - app_state.window.SetProperty(aura::client::kDrawAttentionKey, true); - EXPECT_EQ(ash::STATUS_ACTIVE, app_state.GetUpdaterItem().status); - - // Then browser window - State browser_state( - this, std::string(), BrowserLauncherItemController::TYPE_TABBED); - // First browser is active. - EXPECT_EQ(ash::STATUS_ACTIVE, browser_state.GetUpdaterItem().status); - EXPECT_EQ(ash::STATUS_RUNNING, app_state.GetUpdaterItem().status); - - // App window should go to attention state. - app_state.window.SetProperty(aura::client::kDrawAttentionKey, true); - EXPECT_EQ(ash::STATUS_ATTENTION, app_state.GetUpdaterItem().status); - - // Activating app window should clear attention state. - activation_client_->ActivateWindow(&app_state.window); - EXPECT_EQ(ash::STATUS_ACTIVE, app_state.GetUpdaterItem().status); -} 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 f732149..2967302 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 @@ -36,12 +36,11 @@ #endif BrowserShortcutLauncherItemController::BrowserShortcutLauncherItemController( - ChromeLauncherControllerPerApp* launcher_controller, + ChromeLauncherController* launcher_controller, Profile* profile) : LauncherItemController(TYPE_SHORTCUT, extension_misc::kChromeAppId, launcher_controller), - app_controller_(launcher_controller), profile_(profile) { } @@ -158,7 +157,7 @@ BrowserShortcutLauncherItemController::GetApplicationList(int event_flags) { continue; if (browser->is_type_tabbed()) found_tabbed_browser = true; - else if (!app_controller_->IsBrowserRepresentedInBrowserList(browser)) + else if (!launcher_controller()->IsBrowserRepresentedInBrowserList(browser)) continue; TabStripModel* tab_strip = browser->tab_strip_model(); if (tab_strip->active_index() == -1) @@ -174,8 +173,9 @@ BrowserShortcutLauncherItemController::GetApplicationList(int event_flags) { for (int index = 0; index < tab_strip->count(); ++index) { content::WebContents* web_contents = tab_strip->GetWebContentsAt(index); - gfx::Image app_icon = app_controller_->GetAppListIcon(web_contents); - string16 title = app_controller_->GetAppListTitle(web_contents); + gfx::Image app_icon = + launcher_controller()->GetAppListIcon(web_contents); + string16 title = launcher_controller()->GetAppListTitle(web_contents); // Check if we need to insert a separator in front. bool leading_separator = !index; items.push_back(new ChromeLauncherAppMenuItemTab( @@ -223,7 +223,7 @@ void BrowserShortcutLauncherItemController::ActivateOrAdvanceToNextBrowser() { for (BrowserList::const_iterator it = ash_browser_list->begin(); it != ash_browser_list->end(); ++it) { - if (app_controller_->IsBrowserRepresentedInBrowserList(*it)) + if (launcher_controller()->IsBrowserRepresentedInBrowserList(*it)) items.push_back(*it); } // If there are no suitable browsers we create a new one. @@ -254,7 +254,7 @@ void BrowserShortcutLauncherItemController::ActivateOrAdvanceToNextBrowser() { true, chrome::HOST_DESKTOP_TYPE_ASH); if (!browser || - !app_controller_->IsBrowserRepresentedInBrowserList(browser)) + !launcher_controller()->IsBrowserRepresentedInBrowserList(browser)) browser = items[0]; } } 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 3418ba6..c7583f8 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 @@ -16,15 +16,14 @@ class Image; } class Browser; -class ChromeLauncherControllerPerApp; +class ChromeLauncherController; class Profile; // Item controller for an browser shortcut. class BrowserShortcutLauncherItemController : public LauncherItemController { public: - BrowserShortcutLauncherItemController( - ChromeLauncherControllerPerApp* controller, - Profile* profile); + BrowserShortcutLauncherItemController(ChromeLauncherController* controller, + Profile* profile); virtual ~BrowserShortcutLauncherItemController(); @@ -59,8 +58,6 @@ class BrowserShortcutLauncherItemController : public LauncherItemController { // Activate a browser - or advance to the next one on the list. void ActivateOrAdvanceToNextBrowser(); - ChromeLauncherControllerPerApp* app_controller_; - Profile* profile_; DISALLOW_COPY_AND_ASSIGN(BrowserShortcutLauncherItemController); diff --git a/chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_browser.cc b/chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_browser.cc index a2c4907..9ca859d 100644 --- a/chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_browser.cc +++ b/chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_browser.cc @@ -6,12 +6,12 @@ #include "ash/wm/window_util.h" #include "chrome/browser/chrome_notification_types.h" -#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_finder.h" #include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/tabs/tab_strip_model.h" #include "content/public/browser/notification_service.h" +#include "ui/base/events/event_constants.h" ChromeLauncherAppMenuItemBrowser::ChromeLauncherAppMenuItemBrowser( const string16 title, diff --git a/chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_tab.cc b/chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_tab.cc index 1aaf17d..294c2f1 100644 --- a/chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_tab.cc +++ b/chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_tab.cc @@ -5,11 +5,11 @@ #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_tab.h" #include "ash/wm/window_util.h" -#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_finder.h" #include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/tabs/tab_strip_model.h" +#include "ui/base/events/event_constants.h" ChromeLauncherAppMenuItemTab::ChromeLauncherAppMenuItemTab( const string16 title, diff --git a/chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_v2app.cc b/chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_v2app.cc index d85c90b..02f23ed 100644 --- a/chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_v2app.cc +++ b/chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_v2app.cc @@ -10,7 +10,7 @@ ChromeLauncherAppMenuItemV2App::ChromeLauncherAppMenuItemV2App( const string16 title, const gfx::Image* icon, const std::string& app_id, - ChromeLauncherControllerPerApp* launcher_controller, + ChromeLauncherController* launcher_controller, int app_index, bool has_leading_separator) : ChromeLauncherAppMenuItem(title, icon, has_leading_separator), diff --git a/chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_v2app.h b/chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_v2app.h index 391ae26..c195b0e 100644 --- a/chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_v2app.h +++ b/chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_v2app.h @@ -13,7 +13,7 @@ namespace gfx { class image; } -class ChromeLauncherControllerPerApp; +class ChromeLauncherController; // A menu item controller for a running V2 application. It gets created when an // application list gets created. It's main purpose is to add the activation @@ -24,7 +24,7 @@ class ChromeLauncherAppMenuItemV2App : public ChromeLauncherAppMenuItem { const string16 title, const gfx::Image* icon, const std::string& app_id, - ChromeLauncherControllerPerApp* launcher_controller, + ChromeLauncherController* launcher_controller, int app_index, bool has_leading_separator); virtual bool IsEnabled() const OVERRIDE; @@ -32,7 +32,7 @@ class ChromeLauncherAppMenuItemV2App : public ChromeLauncherAppMenuItem { private: // The owning class which can be used to validate the controller. - ChromeLauncherControllerPerApp* launcher_controller_; + ChromeLauncherController* launcher_controller_; // The application ID. const std::string app_id_; diff --git a/chrome/browser/ui/ash/launcher/chrome_launcher_controller.cc b/chrome/browser/ui/ash/launcher/chrome_launcher_controller.cc deleted file mode 100644 index 442f2e8..0000000 --- a/chrome/browser/ui/ash/launcher/chrome_launcher_controller.cc +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" - -#include "ash/ash_switches.h" -#include "base/command_line.h" -#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app.h" -#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_browser.h" - -// statics -ChromeLauncherController* ChromeLauncherController::instance_ = NULL; - -// static -ChromeLauncherController* ChromeLauncherController::CreateInstance( - Profile* profile, - ash::LauncherModel* model) { - // We do not check here for re-creation of the ChromeLauncherController since - // it appears that it might be intentional that the ChromeLauncherController - // can be re-created. - if (!CommandLine::ForCurrentProcess()->HasSwitch( - ash::switches::kAshDisablePerAppLauncher)) - instance_ = new ChromeLauncherControllerPerApp(profile, model); - else - instance_ = new ChromeLauncherControllerPerBrowser(profile, model); - return instance_; -} - -ChromeLauncherController::~ChromeLauncherController() { - if (instance_ == this) - instance_ = NULL; -} - -bool ChromeLauncherController::IsPerAppLauncher() { - if (!instance_) - return false; - return instance_->GetPerAppInterface() != NULL; -} diff --git a/chrome/browser/ui/ash/launcher/chrome_launcher_controller.h b/chrome/browser/ui/ash/launcher/chrome_launcher_controller.h deleted file mode 100644 index dafc18d..0000000 --- a/chrome/browser/ui/ash/launcher/chrome_launcher_controller.h +++ /dev/null @@ -1,310 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_H_ -#define CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_H_ - -#include <string> - -#include "ash/launcher/launcher_delegate.h" -#include "ash/launcher/launcher_types.h" -#include "ash/shelf/shelf_types.h" -#include "base/memory/scoped_vector.h" -#include "chrome/browser/extensions/app_icon_loader.h" -#include "chrome/browser/extensions/extension_prefs.h" - -class LauncherItemControllerPerAppTest; -class LauncherItemController; -class Profile; -class ChromeLauncherAppMenuItem; -class ChromeLauncherControllerPerApp; - -namespace ash { -class LauncherModel; -} - -namespace aura { -class Window; -class RootWindow; -} - -namespace content { -class WebContents; -} - -namespace ui { -class BaseWindow; -} - -// A list of the elements which makes up a simple menu description. -typedef ScopedVector<ChromeLauncherAppMenuItem> ChromeLauncherAppMenuItems; - -// ChromeLauncherController manages the launcher items needed for content -// windows. Launcher items have a type, an optional app id, and a controller. -// ChromeLauncherController will furthermore create the particular -// implementation of interest - either sorting by application (new) or sorting -// by browser (old). -// * Tabbed browsers and browser app windows have BrowserLauncherItemController, -// owned by the BrowserView instance. -// * App shell windows have ShellWindowLauncherItemController, owned by -// ShellWindowLauncherController. -// * Shortcuts have no LauncherItemController. -class ChromeLauncherController - : public ash::LauncherDelegate, - public extensions::AppIconLoader::Delegate { - public: - // Indicates if a launcher item is incognito or not. - enum IncognitoState { - STATE_INCOGNITO, - STATE_NOT_INCOGNITO, - }; - - // Used to update the state of non plaform apps, as web contents change. - enum AppState { - APP_STATE_ACTIVE, - APP_STATE_WINDOW_ACTIVE, - APP_STATE_INACTIVE, - APP_STATE_REMOVED - }; - - // Mockable interface to get app ids from tabs. - class AppTabHelper { - public: - virtual ~AppTabHelper() {} - - // Returns the app id of the specified tab, or an empty string if there is - // no app. - virtual std::string GetAppID(content::WebContents* tab) = 0; - - // Returns true if |id| is valid. Used during restore to ignore no longer - // valid extensions. - virtual bool IsValidID(const std::string& id) = 0; - }; - - ChromeLauncherController() {} - virtual ~ChromeLauncherController(); - - // Initializes this ChromeLauncherController. - virtual void Init() = 0; - - // Returns the new per application interface of the given launcher. If it is - // a per browser (old) controller, it will return NULL; - // TODO(skuhne): Remove when we rip out the old launcher. - virtual ChromeLauncherControllerPerApp* GetPerAppInterface() = 0; - - // Creates an instance. - static ChromeLauncherController* CreateInstance(Profile* profile, - ash::LauncherModel* model); - - // Returns the single ChromeLauncherController instance. - static ChromeLauncherController* instance() { return instance_; } - - // Creates a new tabbed item on the launcher for |controller|. - virtual ash::LauncherID CreateTabbedLauncherItem( - LauncherItemController* controller, - IncognitoState is_incognito, - ash::LauncherItemStatus status) = 0; - - // Creates a new app item on the launcher for |controller|. - virtual ash::LauncherID CreateAppLauncherItem( - LauncherItemController* controller, - const std::string& app_id, - ash::LauncherItemStatus status) = 0; - - // Updates the running status of an item. - virtual void SetItemStatus(ash::LauncherID id, - ash::LauncherItemStatus status) = 0; - - // Updates the controller associated with id (which should be a shortcut). - // |controller| remains owned by caller. - virtual void SetItemController(ash::LauncherID id, - LauncherItemController* controller) = 0; - - // Closes or unpins the launcher item. - virtual void CloseLauncherItem(ash::LauncherID id) = 0; - - // Pins the specified id. Currently only supports platform apps. - virtual void Pin(ash::LauncherID id) = 0; - - // Unpins the specified id, closing if not running. - virtual void Unpin(ash::LauncherID id) = 0; - - // Returns true if the item identified by |id| is pinned. - virtual bool IsPinned(ash::LauncherID id) = 0; - - // Pins/unpins the specified id. - virtual void TogglePinned(ash::LauncherID id) = 0; - - // Returns true if the specified item can be pinned or unpinned. Only apps can - // be pinned. - virtual bool IsPinnable(ash::LauncherID id) const = 0; - - // If there is no launcher item in the launcher for application |app_id|, one - // gets created. The (existing or created) launcher items get then locked - // against a users un-pinning removal. - virtual void LockV1AppWithID(const std::string& app_id) = 0; - - // A previously locked launcher item of type |app_id| gets unlocked. If the - // lock count reaches 0 and the item is not pinned it will go away. - virtual void UnlockV1AppWithID(const std::string& app_id) = 0; - - // Requests that the launcher item controller specified by |id| open a new - // instance of the app. |event_flags| holds the flags of the event which - // triggered this command. - virtual void Launch(ash::LauncherID id, int event_flags) = 0; - - // Closes the specified item. - virtual void Close(ash::LauncherID id) = 0; - - // Returns true if the specified item is open. - virtual bool IsOpen(ash::LauncherID id) = 0; - - // Returns true if the specified item is for a platform app. - virtual bool IsPlatformApp(ash::LauncherID id) = 0; - - // Opens a new instance of the application identified by |app_id|. - // Used by the app-list, and by pinned-app launcher items. - virtual void LaunchApp(const std::string& app_id, int event_flags) = 0; - - // If |app_id| is running, reactivates the app's most recently active window, - // otherwise launches and activates the app. - // Used by the app-list, and by pinned-app launcher items. - virtual void ActivateApp(const std::string& app_id, int event_flags) = 0; - - // Returns the launch type of app for the specified id. - virtual extensions::ExtensionPrefs::LaunchType GetLaunchType( - ash::LauncherID id) = 0; - - // Returns the id of the app for the specified tab. - virtual std::string GetAppID(content::WebContents* tab) = 0; - - // Returns the launcherID of the first non-panel item whose app_id - // matches |app_id| or 0 if none match. - virtual ash::LauncherID GetLauncherIDForAppID(const std::string& app_id) = 0; - - // Returns the id of the app for the specified id (which must exist). - virtual std::string GetAppIDForLauncherID(ash::LauncherID id) = 0; - - // Set the image for a specific launcher item (e.g. when set by the app). - virtual void SetLauncherItemImage(ash::LauncherID launcher_id, - const gfx::ImageSkia& image) = 0; - - // Returns true if a pinned launcher item with given |app_id| could be found. - virtual bool IsAppPinned(const std::string& app_id) = 0; - - // Pins an app with |app_id| to launcher. If there is a running instance in - // launcher, the running instance is pinned. If there is no running instance, - // a new launcher item is created and pinned. - virtual void PinAppWithID(const std::string& app_id) = 0; - - // Updates the launche type of the app for the specified id to |launch_type|. - virtual void SetLaunchType( - ash::LauncherID id, - extensions::ExtensionPrefs::LaunchType launch_type) = 0; - - // Unpins any app items whose id is |app_id|. - virtual void UnpinAppsWithID(const std::string& app_id) = 0; - - // Returns true if the user is currently logged in as a guest. - virtual bool IsLoggedInAsGuest() = 0; - - // Invoked when user clicks on button in the launcher and there is no last - // used window (or CTRL is held with the click). - virtual void CreateNewWindow() = 0; - - // Invoked when the user clicks on button in the launcher to create a new - // incognito window. - virtual void CreateNewIncognitoWindow() = 0; - - // Checks whether the user is allowed to pin apps. Pinning may be disallowed - // by policy in case there is a pre-defined set of pinned apps. - virtual bool CanPin() const = 0; - - // Updates the pinned pref state. The pinned state consists of a list pref. - // Each item of the list is a dictionary. The key |kAppIDPath| gives the - // id of the app. - virtual void PersistPinnedState() = 0; - - virtual ash::LauncherModel* model() = 0; - - virtual Profile* profile() = 0; - - // Gets the shelf auto-hide behavior on |root_window|. - virtual ash::ShelfAutoHideBehavior GetShelfAutoHideBehavior( - aura::RootWindow* root_window) const = 0; - - // Returns |true| if the user is allowed to modify the shelf auto-hide - // behavior on |root_window|. - virtual bool CanUserModifyShelfAutoHideBehavior( - aura::RootWindow* root_window) const = 0; - - // Toggles the shelf auto-hide behavior on |root_window|. Does nothing if the - // user is not allowed to modify the auto-hide behavior. - virtual void ToggleShelfAutoHideBehavior(aura::RootWindow* root_window) = 0; - - // The tab no longer represents its previously identified application. - virtual void RemoveTabFromRunningApp(content::WebContents* tab, - const std::string& app_id) = 0; - - // Notify the controller that the state of an non platform app's tabs - // have changed, - virtual void UpdateAppState(content::WebContents* contents, - AppState app_state) = 0; - - // Limits application refocusing to urls that match |url| for |id|. - virtual void SetRefocusURLPatternForTest(ash::LauncherID id, - const GURL& url) = 0; - - // Returns the extension identified by |app_id|. - virtual const extensions::Extension* GetExtensionForAppID( - const std::string& app_id) const = 0; - - // Activates a |window|. If |allow_minimize| is true and the system allows - // it, the the window will get minimized instead. - virtual void ActivateWindowOrMinimizeIfActive(ui::BaseWindow* window, - bool allow_minimize) = 0; - // ash::LauncherDelegate overrides: - virtual void ItemSelected(const ash::LauncherItem& item, - const ui::Event& event) OVERRIDE = 0; - virtual string16 GetTitle(const ash::LauncherItem& item) OVERRIDE = 0; - virtual ui::MenuModel* CreateContextMenu( - const ash::LauncherItem& item, aura::RootWindow* root) OVERRIDE = 0; - virtual ash::LauncherMenuModel* CreateApplicationMenu( - const ash::LauncherItem& item, - int event_flags) OVERRIDE = 0; - virtual ash::LauncherID GetIDByWindow(aura::Window* window) OVERRIDE = 0; - virtual bool IsDraggable(const ash::LauncherItem& item) OVERRIDE = 0; - virtual bool ShouldShowTooltip(const ash::LauncherItem& item) OVERRIDE = 0; - virtual bool IsPerAppLauncher() OVERRIDE; - - // extensions::AppIconLoader overrides: - virtual void SetAppImage(const std::string& app_id, - const gfx::ImageSkia& image) OVERRIDE = 0; - - protected: - friend class LauncherItemControllerPerAppTest; - friend class LauncherPlatformAppBrowserTest; - friend class LauncherAppBrowserTest; - // TODO(skuhne): Remove these when the old launcher get removed. - friend class LauncherPlatformPerAppAppBrowserTest; - friend class LauncherPerAppAppBrowserTest; - - // Creates a new app shortcut item and controller on the launcher at |index|. - // Use kInsertItemAtEnd to add a shortcut as the last item. - virtual ash::LauncherID CreateAppShortcutLauncherItem( - const std::string& app_id, - int index) = 0; - - // Sets the AppTabHelper/AppIconLoader, taking ownership of the helper class. - // These are intended for testing. - virtual void SetAppTabHelperForTest(AppTabHelper* helper) = 0; - virtual void SetAppIconLoaderForTest(extensions::AppIconLoader* loader) = 0; - virtual const std::string& GetAppIdFromLauncherIdForTest( - ash::LauncherID id) = 0; - - private: - static ChromeLauncherController* instance_; -}; - -#endif // CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_H_ diff --git a/chrome/browser/ui/ash/launcher/chrome_launcher_controller_browsertest.cc b/chrome/browser/ui/ash/launcher/chrome_launcher_controller_browsertest.cc deleted file mode 100644 index c68476c..0000000 --- a/chrome/browser/ui/ash/launcher/chrome_launcher_controller_browsertest.cc +++ /dev/null @@ -1,837 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" - -#include "apps/native_app_window.h" -#include "apps/shell_window.h" -#include "apps/shell_window_registry.h" -#include "ash/ash_switches.h" -#include "ash/launcher/launcher.h" -#include "ash/launcher/launcher_model.h" -#include "ash/shell.h" -#include "ash/test/launcher_view_test_api.h" -#include "ash/test/shell_test_api.h" -#include "ash/wm/window_util.h" -#include "base/command_line.h" -#include "base/strings/stringprintf.h" -#include "base/strings/utf_string_conversions.h" -#include "chrome/browser/apps/app_browsertest_util.h" -#include "chrome/browser/automation/automation_util.h" -#include "chrome/browser/chrome_notification_types.h" -#include "chrome/browser/extensions/extension_apitest.h" -#include "chrome/browser/extensions/extension_browsertest.h" -#include "chrome/browser/extensions/extension_function_test_utils.h" -#include "chrome/browser/extensions/extension_service.h" -#include "chrome/browser/extensions/extension_system.h" -#include "chrome/browser/extensions/extension_test_message_listener.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/ui/browser.h" -#include "chrome/browser/ui/browser_commands.h" -#include "chrome/browser/ui/browser_window.h" -#include "chrome/browser/ui/extensions/application_launch.h" -#include "chrome/browser/ui/host_desktop.h" -#include "chrome/browser/ui/tabs/tab_strip_model.h" -#include "chrome/common/chrome_switches.h" -#include "chrome/common/extensions/extension_constants.h" -#include "chrome/test/base/ui_test_utils.h" -#include "content/public/browser/notification_service.h" -#include "content/public/browser/notification_source.h" -#include "content/public/browser/web_contents.h" -#include "testing/gtest/include/gtest/gtest.h" -#include "ui/aura/client/aura_constants.h" -#include "ui/aura/window.h" - -using apps::ShellWindow; -using extensions::Extension; -using content::WebContents; - -class LauncherPlatformAppBrowserTest - : public extensions::PlatformAppBrowserTest { - protected: - LauncherPlatformAppBrowserTest() - : launcher_(NULL), - controller_(NULL) { - } - - virtual ~LauncherPlatformAppBrowserTest() {} - - ash::LauncherModel* launcher_model() { - return ash::test::ShellTestApi(ash::Shell::GetInstance()).launcher_model(); - } - - virtual void RunTestOnMainThreadLoop() OVERRIDE { - launcher_ = ash::Launcher::ForPrimaryDisplay(); - controller_ = static_cast<ChromeLauncherController*>(launcher_->delegate()); - return extensions::PlatformAppBrowserTest::RunTestOnMainThreadLoop(); - } - - virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { - PlatformAppBrowserTest::SetUpCommandLine(command_line); - command_line->AppendSwitch(ash::switches::kAshDisablePerAppLauncher); - } - - ash::LauncherID CreateAppShortcutLauncherItem(const std::string& name) { - return controller_->CreateAppShortcutLauncherItem( - name, controller_->model()->item_count()); - } - - const ash::LauncherItem& GetLastLauncherItem() { - // Unless there are any panels, the item at index [count - 1] will be - // the app list, and the item at [count - 2] will be the desited item. - return launcher_model()->items()[launcher_model()->item_count() - 2]; - } - - const ash::LauncherItem& GetLastLauncherPanelItem() { - // Panels show up on the right side of the launcher, so the desired item - // will be the last one. - return launcher_model()->items()[launcher_model()->item_count() - 1]; - } - - ash::Launcher* launcher_; - ChromeLauncherController* controller_; -}; - -class LauncherAppBrowserTest : public ExtensionBrowserTest { - protected: - LauncherAppBrowserTest() - : launcher_(NULL), - model_(NULL) { - } - - virtual ~LauncherAppBrowserTest() {} - - virtual void RunTestOnMainThreadLoop() OVERRIDE { - launcher_ = ash::Launcher::ForPrimaryDisplay(); - model_ = - ash::test::ShellTestApi(ash::Shell::GetInstance()).launcher_model(); - return ExtensionBrowserTest::RunTestOnMainThreadLoop(); - } - - virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { - ExtensionBrowserTest::SetUpCommandLine(command_line); - command_line->AppendSwitch(ash::switches::kAshDisablePerAppLauncher); - } - - const Extension* LoadAndLaunchExtension( - const char* name, - extension_misc::LaunchContainer container, - WindowOpenDisposition disposition) { - EXPECT_TRUE(LoadExtension(test_data_dir_.AppendASCII(name))); - - ExtensionService* service = extensions::ExtensionSystem::Get( - browser()->profile())->extension_service(); - const Extension* extension = - service->GetExtensionById(last_loaded_extension_id_, false); - EXPECT_TRUE(extension); - - chrome::OpenApplication(chrome::AppLaunchParams( - browser()->profile(), extension, container, disposition)); - return extension; - } - - ash::LauncherID CreateShortcut(const char* name) { - ExtensionService* service = extensions::ExtensionSystem::Get( - browser()->profile())->extension_service(); - LoadExtension(test_data_dir_.AppendASCII(name)); - - // First get app_id. - const Extension* extension = - service->GetExtensionById(last_loaded_extension_id_, false); - const std::string app_id = extension->id(); - - // Then create a shortcut. - ChromeLauncherController* controller = - static_cast<ChromeLauncherController*>(launcher_->delegate()); - int item_count = model_->item_count(); - ash::LauncherID shortcut_id = controller->CreateAppShortcutLauncherItem( - app_id, item_count); - controller->PersistPinnedState(); - EXPECT_EQ(++item_count, model_->item_count()); - ash::LauncherItem item = *model_->ItemByID(shortcut_id); - EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item.type); - return item.id; - } - - ash::LauncherID PinFakeApp(const std::string& name) { - ChromeLauncherController* controller = - static_cast<ChromeLauncherController*>(launcher_->delegate()); - return controller->CreateAppShortcutLauncherItem( - name, model_->item_count()); - } - - ash::Launcher* launcher_; - ash::LauncherModel* model_; -}; - -// Test that we can launch a platform app and get a running item. -IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, LaunchUnpinned) { - int item_count = launcher_model()->item_count(); - const Extension* extension = LoadAndLaunchPlatformApp("launch"); - ShellWindow* window = CreateShellWindow(extension); - ++item_count; - ASSERT_EQ(item_count, launcher_model()->item_count()); - const ash::LauncherItem& item = GetLastLauncherItem(); - EXPECT_EQ(ash::TYPE_PLATFORM_APP, item.type); - EXPECT_EQ(ash::STATUS_ACTIVE, item.status); - CloseShellWindow(window); - --item_count; - EXPECT_EQ(item_count, launcher_model()->item_count()); -} - -// Test that we can launch a platform app that already has a shortcut. -IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, LaunchPinned) { - int item_count = launcher_model()->item_count(); - - // First get app_id. - const Extension* extension = LoadAndLaunchPlatformApp("launch"); - const std::string app_id = extension->id(); - - // Then create a shortcut. - ash::LauncherID shortcut_id = CreateAppShortcutLauncherItem(app_id); - ++item_count; - ASSERT_EQ(item_count, launcher_model()->item_count()); - ash::LauncherItem item = *launcher_model()->ItemByID(shortcut_id); - EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item.type); - EXPECT_EQ(ash::STATUS_CLOSED, item.status); - - // Open a window. Confirm the item is now running. - ShellWindow* window = CreateShellWindow(extension); - ash::wm::ActivateWindow(window->GetNativeWindow()); - ASSERT_EQ(item_count, launcher_model()->item_count()); - item = *launcher_model()->ItemByID(shortcut_id); - EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item.type); - EXPECT_EQ(ash::STATUS_ACTIVE, item.status); - - // Then close it, make sure there's still an item. - CloseShellWindow(window); - ASSERT_EQ(item_count, launcher_model()->item_count()); - item = *launcher_model()->ItemByID(shortcut_id); - EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item.type); - EXPECT_EQ(ash::STATUS_CLOSED, item.status); -} - -IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, PinRunning) { - // Run. - int item_count = launcher_model()->item_count(); - const Extension* extension = LoadAndLaunchPlatformApp("launch"); - ShellWindow* window = CreateShellWindow(extension); - ++item_count; - ASSERT_EQ(item_count, launcher_model()->item_count()); - const ash::LauncherItem& item1 = GetLastLauncherItem(); - ash::LauncherID id = item1.id; - EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type); - EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); - - // Create a shortcut. The app item should be after it. - ash::LauncherID foo_id = CreateAppShortcutLauncherItem("foo"); - ++item_count; - ASSERT_EQ(item_count, launcher_model()->item_count()); - EXPECT_LT(launcher_model()->ItemIndexByID(foo_id), - launcher_model()->ItemIndexByID(id)); - - // Pin the app. The item should remain. - controller_->Pin(id); - ASSERT_EQ(item_count, launcher_model()->item_count()); - const ash::LauncherItem& item2 = *launcher_model()->ItemByID(id); - EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item2.type); - EXPECT_EQ(ash::STATUS_ACTIVE, item2.status); - - // New shortcuts should come after the item. - ash::LauncherID bar_id = CreateAppShortcutLauncherItem("bar"); - ++item_count; - ASSERT_EQ(item_count, launcher_model()->item_count()); - EXPECT_LT(launcher_model()->ItemIndexByID(id), - launcher_model()->ItemIndexByID(bar_id)); - - // Then close it, make sure the item remains. - CloseShellWindow(window); - ASSERT_EQ(item_count, launcher_model()->item_count()); -} - -IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, UnpinRunning) { - int item_count = launcher_model()->item_count(); - - // First get app_id. - const Extension* extension = LoadAndLaunchPlatformApp("launch"); - const std::string app_id = extension->id(); - - // Then create a shortcut. - ash::LauncherID shortcut_id = CreateAppShortcutLauncherItem(app_id); - ++item_count; - ASSERT_EQ(item_count, launcher_model()->item_count()); - ash::LauncherItem item = *launcher_model()->ItemByID(shortcut_id); - EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item.type); - EXPECT_EQ(ash::STATUS_CLOSED, item.status); - - // Create a second shortcut. This will be needed to force the first one to - // move once it gets unpinned. - ash::LauncherID foo_id = CreateAppShortcutLauncherItem("foo"); - ++item_count; - ASSERT_EQ(item_count, launcher_model()->item_count()); - EXPECT_LT(launcher_model()->ItemIndexByID(shortcut_id), - launcher_model()->ItemIndexByID(foo_id)); - - // Open a window. Confirm the item is now running. - ShellWindow* window = CreateShellWindow(extension); - ash::wm::ActivateWindow(window->GetNativeWindow()); - ASSERT_EQ(item_count, launcher_model()->item_count()); - item = *launcher_model()->ItemByID(shortcut_id); - EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item.type); - EXPECT_EQ(ash::STATUS_ACTIVE, item.status); - - // Unpin the app. The item should remain. - controller_->Unpin(shortcut_id); - ASSERT_EQ(item_count, launcher_model()->item_count()); - item = *launcher_model()->ItemByID(shortcut_id); - EXPECT_EQ(ash::TYPE_PLATFORM_APP, item.type); - EXPECT_EQ(ash::STATUS_ACTIVE, item.status); - // The item should have moved after the other shortcuts. - EXPECT_GT(launcher_model()->ItemIndexByID(shortcut_id), - launcher_model()->ItemIndexByID(foo_id)); - - // Then close it, make sure the item's gone. - CloseShellWindow(window); - --item_count; - ASSERT_EQ(item_count, launcher_model()->item_count()); -} - -// Test that we can launch a platform app with more than one window. -IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, MultipleWindows) { - int item_count = launcher_model()->item_count(); - - // First run app. - const Extension* extension = LoadAndLaunchPlatformApp("launch"); - ShellWindow* window1 = CreateShellWindow(extension); - ++item_count; - ASSERT_EQ(item_count, launcher_model()->item_count()); - const ash::LauncherItem& item1 = GetLastLauncherItem(); - ash::LauncherID item_id = item1.id; - EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type); - EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); - - // Add second window. - ShellWindow* window2 = CreateShellWindow(extension); - // Confirm item stays. - ASSERT_EQ(item_count, launcher_model()->item_count()); - const ash::LauncherItem& item2 = *launcher_model()->ItemByID(item_id); - EXPECT_EQ(ash::STATUS_ACTIVE, item2.status); - - // Close second window. - CloseShellWindow(window2); - // Confirm item stays. - ASSERT_EQ(item_count, launcher_model()->item_count()); - const ash::LauncherItem& item3 = *launcher_model()->ItemByID(item_id); - EXPECT_EQ(ash::STATUS_ACTIVE, item3.status); - - // Close first window. - CloseShellWindow(window1); - // Confirm item is removed. - --item_count; - ASSERT_EQ(item_count, launcher_model()->item_count()); -} - -IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, MultipleApps) { - int item_count = launcher_model()->item_count(); - - // First run app. - const Extension* extension1 = LoadAndLaunchPlatformApp("launch"); - ShellWindow* window1 = CreateShellWindow(extension1); - ++item_count; - ASSERT_EQ(item_count, launcher_model()->item_count()); - const ash::LauncherItem& item1 = GetLastLauncherItem(); - ash::LauncherID item_id1 = item1.id; - EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type); - EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); - - // Then run second app. - const Extension* extension2 = LoadAndLaunchPlatformApp("launch_2"); - ShellWindow* window2 = CreateShellWindow(extension2); - ++item_count; - ASSERT_EQ(item_count, launcher_model()->item_count()); - const ash::LauncherItem& item2 = GetLastLauncherItem(); - ash::LauncherID item_id2 = item2.id; - EXPECT_EQ(ash::TYPE_PLATFORM_APP, item2.type); - EXPECT_EQ(ash::STATUS_ACTIVE, item2.status); - - EXPECT_NE(item_id1, item_id2); - EXPECT_EQ(ash::STATUS_RUNNING, - launcher_model()->ItemByID(item_id1)->status); - - // Close second app. - CloseShellWindow(window2); - --item_count; - ASSERT_EQ(item_count, launcher_model()->item_count()); - // First app should be active again. - EXPECT_EQ(ash::STATUS_ACTIVE, - launcher_model()->ItemByID(item_id1)->status); - - // Close first app. - CloseShellWindow(window1); - --item_count; - ASSERT_EQ(item_count, launcher_model()->item_count()); -} - -// Test that we can launch a platform app panel and get a running item. -IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, LaunchPanelWindow) { - int item_count = launcher_model()->item_count(); - const Extension* extension = LoadAndLaunchPlatformApp("launch"); - ShellWindow::CreateParams params; - params.window_type = ShellWindow::WINDOW_TYPE_PANEL; - params.focused = false; - ShellWindow* window = CreateShellWindowFromParams(extension, params); - ++item_count; - ASSERT_EQ(item_count, launcher_model()->item_count()); - const ash::LauncherItem& item = GetLastLauncherPanelItem(); - EXPECT_EQ(ash::TYPE_APP_PANEL, item.type); - // Opening a panel does not activate it. - EXPECT_EQ(ash::STATUS_RUNNING, item.status); - CloseShellWindow(window); - --item_count; - EXPECT_EQ(item_count, launcher_model()->item_count()); -} - -#if defined(OS_CHROMEOS) -#define MAYBE_WindowActivation DISABLED_WindowActivation -#else -#define MAYBE_WindowActivation WindowActivation -#endif -// Confirm that app windows can be reactivated by clicking their icons and that -// the correct activation order is maintained. -IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, MAYBE_WindowActivation) { - int item_count = launcher_model()->item_count(); - - // First run app. - const Extension* extension1 = LoadAndLaunchPlatformApp("launch"); - ShellWindow* window1 = CreateShellWindow(extension1); - ++item_count; - ASSERT_EQ(item_count, launcher_model()->item_count()); - const ash::LauncherItem& item1 = GetLastLauncherItem(); - ash::LauncherID item_id1 = item1.id; - EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type); - EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); - - // Then run second app. - const Extension* extension2 = LoadAndLaunchPlatformApp("launch_2"); - ShellWindow* window2 = CreateShellWindow(extension2); - ++item_count; - ASSERT_EQ(item_count, launcher_model()->item_count()); - const ash::LauncherItem& item2 = GetLastLauncherItem(); - ash::LauncherID item_id2 = item2.id; - EXPECT_EQ(ash::TYPE_PLATFORM_APP, item2.type); - EXPECT_EQ(ash::STATUS_ACTIVE, item2.status); - - EXPECT_NE(item_id1, item_id2); - EXPECT_EQ(ash::STATUS_RUNNING, - launcher_model()->ItemByID(item_id1)->status); - - // Activate first one. - launcher_->ActivateLauncherItem(launcher_model()->ItemIndexByID(item_id1)); - EXPECT_EQ(ash::STATUS_ACTIVE, launcher_model()->ItemByID(item_id1)->status); - EXPECT_EQ(ash::STATUS_RUNNING, - launcher_model()->ItemByID(item_id2)->status); - EXPECT_TRUE(ash::wm::IsActiveWindow(window1->GetNativeWindow())); - EXPECT_FALSE(ash::wm::IsActiveWindow(window2->GetNativeWindow())); - - // Activate second one. - launcher_->ActivateLauncherItem(launcher_model()->ItemIndexByID(item_id2)); - EXPECT_EQ(ash::STATUS_RUNNING, - launcher_model()->ItemByID(item_id1)->status); - EXPECT_EQ(ash::STATUS_ACTIVE, launcher_model()->ItemByID(item_id2)->status); - EXPECT_FALSE(ash::wm::IsActiveWindow(window1->GetNativeWindow())); - EXPECT_TRUE(ash::wm::IsActiveWindow(window2->GetNativeWindow())); - - // Add window for app1. This will activate it. - ShellWindow* window1b = CreateShellWindow(extension1); - ash::wm::ActivateWindow(window1b->GetNativeWindow()); - EXPECT_FALSE(ash::wm::IsActiveWindow(window1->GetNativeWindow())); - EXPECT_FALSE(ash::wm::IsActiveWindow(window2->GetNativeWindow())); - EXPECT_TRUE(ash::wm::IsActiveWindow(window1b->GetNativeWindow())); - - // Activate launcher item for app1, this will activate the first app window. - launcher_->ActivateLauncherItem(launcher_model()->ItemIndexByID(item_id1)); - EXPECT_TRUE(ash::wm::IsActiveWindow(window1->GetNativeWindow())); - EXPECT_FALSE(ash::wm::IsActiveWindow(window1b->GetNativeWindow())); - launcher_->ActivateLauncherItem(launcher_model()->ItemIndexByID(item_id1)); - EXPECT_TRUE(ash::wm::IsActiveWindow(window1->GetNativeWindow())); - - // Activate the second app again - launcher_->ActivateLauncherItem(launcher_model()->ItemIndexByID(item_id2)); - EXPECT_FALSE(ash::wm::IsActiveWindow(window1->GetNativeWindow())); - EXPECT_TRUE(ash::wm::IsActiveWindow(window2->GetNativeWindow())); - EXPECT_FALSE(ash::wm::IsActiveWindow(window1b->GetNativeWindow())); - - // Activate the first app again - launcher_->ActivateLauncherItem(launcher_model()->ItemIndexByID(item_id1)); - EXPECT_TRUE(ash::wm::IsActiveWindow(window1->GetNativeWindow())); - EXPECT_FALSE(ash::wm::IsActiveWindow(window2->GetNativeWindow())); - EXPECT_FALSE(ash::wm::IsActiveWindow(window1b->GetNativeWindow())); - - // Close second app. - CloseShellWindow(window2); - --item_count; - EXPECT_EQ(item_count, launcher_model()->item_count()); - // First app should be active again. - EXPECT_EQ(ash::STATUS_ACTIVE, launcher_model()->ItemByID(item_id1)->status); - - // Close first app. - CloseShellWindow(window1b); - CloseShellWindow(window1); - --item_count; - EXPECT_EQ(item_count, launcher_model()->item_count()); -} - -IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, BrowserActivation) { - int item_count = launcher_model()->item_count(); - - // First run app. - const Extension* extension1 = LoadAndLaunchPlatformApp("launch"); - CreateShellWindow(extension1); - ++item_count; - ASSERT_EQ(item_count, launcher_model()->item_count()); - const ash::LauncherItem& item1 = GetLastLauncherItem(); - ash::LauncherID item_id1 = item1.id; - EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type); - EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); - - ash::wm::ActivateWindow(browser()->window()->GetNativeWindow()); - EXPECT_EQ(ash::STATUS_RUNNING, - launcher_model()->ItemByID(item_id1)->status); -} - -// Test that draw attention sets the launcher item status. -IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, DrawAttention) { - const Extension* extension = LoadAndLaunchPlatformApp("launch"); - ShellWindow* shell_window = CreateShellWindow(extension); - const ash::LauncherItem& item = GetLastLauncherItem(); - EXPECT_EQ(ash::STATUS_ACTIVE, item.status); - // Set Minimize window to deactivate the launcher item. - shell_window->GetBaseWindow()->Minimize(); - EXPECT_EQ(ash::STATUS_RUNNING, item.status); - // Set DrawAttention property. - shell_window->GetNativeWindow()->SetProperty( - aura::client::kDrawAttentionKey, true); - EXPECT_EQ(ash::STATUS_ATTENTION, item.status); - // Activate window, should clear DrawAttention. - shell_window->GetBaseWindow()->Activate(); - EXPECT_EQ(ash::STATUS_ACTIVE, item.status); - EXPECT_FALSE(shell_window->GetNativeWindow()->GetProperty( - aura::client::kDrawAttentionKey)); -} - -// Test that we can launch an app with a shortcut. -IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, LaunchPinned) { - TabStripModel* tab_strip = browser()->tab_strip_model(); - int tab_count = tab_strip->count(); - ash::LauncherID shortcut_id = CreateShortcut("app1"); - EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status); - launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); - EXPECT_EQ(++tab_count, tab_strip->count()); - EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status); - WebContents* tab = tab_strip->GetActiveWebContents(); - content::WindowedNotificationObserver close_observer( - content::NOTIFICATION_WEB_CONTENTS_DESTROYED, - content::Source<WebContents>(tab)); - browser()->tab_strip_model()->CloseSelectedTabs(); - close_observer.Wait(); - EXPECT_EQ(--tab_count, tab_strip->count()); - EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status); -} - -// Launch the app first and then create the shortcut. -IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, LaunchUnpinned) { - TabStripModel* tab_strip = browser()->tab_strip_model(); - int tab_count = tab_strip->count(); - LoadAndLaunchExtension("app1", extension_misc::LAUNCH_TAB, - NEW_FOREGROUND_TAB); - EXPECT_EQ(++tab_count, tab_strip->count()); - ash::LauncherID shortcut_id = CreateShortcut("app1"); - EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status); - WebContents* tab = tab_strip->GetActiveWebContents(); - content::WindowedNotificationObserver close_observer( - content::NOTIFICATION_WEB_CONTENTS_DESTROYED, - content::Source<WebContents>(tab)); - browser()->tab_strip_model()->CloseSelectedTabs(); - close_observer.Wait(); - EXPECT_EQ(--tab_count, tab_strip->count()); - EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status); -} - -// Launches an app in the background and then tries to open it. This is test for -// a crash we had. -IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, LaunchInBackground) { - TabStripModel* tab_strip = browser()->tab_strip_model(); - int tab_count = tab_strip->count(); - LoadAndLaunchExtension("app1", extension_misc::LAUNCH_TAB, - NEW_BACKGROUND_TAB); - EXPECT_EQ(++tab_count, tab_strip->count()); - ChromeLauncherController::instance()->LaunchApp(last_loaded_extension_id_, 0); -} - -// Confirm that clicking a icon for an app running in one of 2 maxmized windows -// activates the right window. -IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, LaunchMaximized) { - aura::Window* window1 = browser()->window()->GetNativeWindow(); - ash::wm::MaximizeWindow(window1); - content::WindowedNotificationObserver open_observer( - chrome::NOTIFICATION_BROWSER_WINDOW_READY, - content::NotificationService::AllSources()); - chrome::NewEmptyWindow(browser()->profile(), chrome::HOST_DESKTOP_TYPE_ASH); - open_observer.Wait(); - Browser* browser2 = content::Source<Browser>(open_observer.source()).ptr(); - aura::Window* window2 = browser2->window()->GetNativeWindow(); - TabStripModel* tab_strip = browser2->tab_strip_model(); - int tab_count = tab_strip->count(); - ash::wm::MaximizeWindow(window2); - - ash::LauncherID shortcut_id = CreateShortcut("app1"); - launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); - EXPECT_EQ(++tab_count, tab_strip->count()); - EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status); - - window1->Show(); - ash::wm::ActivateWindow(window1); - EXPECT_EQ(ash::STATUS_RUNNING, (*model_->ItemByID(shortcut_id)).status); - - launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); - EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status); -} - -// Activating the same app multiple times should launch only a single copy. -IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, ActivateApp) { - TabStripModel* tab_strip = browser()->tab_strip_model(); - int tab_count = tab_strip->count(); - const Extension* extension = - LoadExtension(test_data_dir_.AppendASCII("app1")); - - ChromeLauncherController::instance()->ActivateApp(extension->id(), 0); - EXPECT_EQ(++tab_count, tab_strip->count()); - ChromeLauncherController::instance()->ActivateApp(extension->id(), 0); - EXPECT_EQ(tab_count, tab_strip->count()); -} - -// Launching the same app multiple times should launch a copy for each call. -IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, LaunchApp) { - TabStripModel* tab_strip = browser()->tab_strip_model(); - int tab_count = tab_strip->count(); - const Extension* extension = - LoadExtension(test_data_dir_.AppendASCII("app1")); - - ChromeLauncherController::instance()->LaunchApp(extension->id(), 0); - EXPECT_EQ(++tab_count, tab_strip->count()); - ChromeLauncherController::instance()->LaunchApp(extension->id(), 0); - EXPECT_EQ(++tab_count, tab_strip->count()); -} - -// Launch 2 apps and toggle which is active. -IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, MultipleApps) { - int item_count = model_->item_count(); - TabStripModel* tab_strip = browser()->tab_strip_model(); - int tab_count = tab_strip->count(); - ash::LauncherID shortcut1 = CreateShortcut("app1"); - EXPECT_EQ(++item_count, model_->item_count()); - ash::LauncherID shortcut2 = CreateShortcut("app2"); - EXPECT_EQ(++item_count, model_->item_count()); - - // Launch first app. - launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut1)); - EXPECT_EQ(++tab_count, tab_strip->count()); - WebContents* tab1 = tab_strip->GetActiveWebContents(); - EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut1)).status); - - // Launch second app. - launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut2)); - EXPECT_EQ(++tab_count, tab_strip->count()); - WebContents* tab2 = tab_strip->GetActiveWebContents(); - ASSERT_NE(tab1, tab2); - EXPECT_EQ(ash::STATUS_RUNNING, (*model_->ItemByID(shortcut1)).status); - EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut2)).status); - - // Reactivate first app. - launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut1)); - EXPECT_EQ(tab_count, tab_strip->count()); - EXPECT_EQ(tab_strip->GetActiveWebContents(), tab1); - EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut1)).status); - EXPECT_EQ(ash::STATUS_RUNNING, (*model_->ItemByID(shortcut2)).status); - - // Open second tab for second app. This should activate it. - ui_test_utils::NavigateToURLWithDisposition( - browser(), - GURL("http://www.example.com/path3/foo.html"), - NEW_FOREGROUND_TAB, - 0); - EXPECT_EQ(++tab_count, tab_strip->count()); - WebContents* tab3 = tab_strip->GetActiveWebContents(); - EXPECT_EQ(ash::STATUS_RUNNING, (*model_->ItemByID(shortcut1)).status); - EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut2)).status); - - // Reactivate first app. - launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut1)); - EXPECT_EQ(tab_count, tab_strip->count()); - EXPECT_EQ(tab_strip->GetActiveWebContents(), tab1); - EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut1)).status); - EXPECT_EQ(ash::STATUS_RUNNING, (*model_->ItemByID(shortcut2)).status); - - // And second again. This time the second tab should become active. - launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut2)); - EXPECT_EQ(tab_count, tab_strip->count()); - EXPECT_EQ(tab_strip->GetActiveWebContents(), tab3); - EXPECT_EQ(ash::STATUS_RUNNING, (*model_->ItemByID(shortcut1)).status); - EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut2)).status); -} - -// Confirm that a page can be navigated from and to while maintaining the -// correct running state. -IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, Navigation) { - ash::LauncherID shortcut_id = CreateShortcut("app1"); - EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status); - launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); - EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status); - - // Navigate away. - ui_test_utils::NavigateToURL( - browser(), GURL("http://www.example.com/path0/bar.html")); - EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status); - - // Navigate back. - ui_test_utils::NavigateToURL( - browser(), GURL("http://www.example.com/path1/foo.html")); - EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status); -} - -IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, MultipleOwnedTabs) { - TabStripModel* tab_strip = browser()->tab_strip_model(); - int tab_count = tab_strip->count(); - ash::LauncherID shortcut_id = CreateShortcut("app1"); - launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); - EXPECT_EQ(++tab_count, tab_strip->count()); - EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status); - - // Create new tab owned by app. - ui_test_utils::NavigateToURLWithDisposition( - browser(), - GURL("http://www.example.com/path2/bar.html"), - NEW_FOREGROUND_TAB, - ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); - EXPECT_EQ(++tab_count, tab_strip->count()); - // Confirm app is still active. - EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status); - WebContents* second_tab = tab_strip->GetActiveWebContents(); - - // Create new tab not owned by app. - ui_test_utils::NavigateToURLWithDisposition( - browser(), - GURL("http://www.example.com/path3/foo.html"), - NEW_FOREGROUND_TAB, - 0); - EXPECT_EQ(++tab_count, tab_strip->count()); - // No longer active. - EXPECT_EQ(ash::STATUS_RUNNING, model_->ItemByID(shortcut_id)->status); - - // Activating app makes second tab active again. - launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); - EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status); - EXPECT_EQ(tab_strip->GetActiveWebContents(), second_tab); -} - -IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, RefocusFilter) { - ChromeLauncherController* controller = - static_cast<ChromeLauncherController*>(launcher_->delegate()); - TabStripModel* tab_strip = browser()->tab_strip_model(); - int tab_count = tab_strip->count(); - ash::LauncherID shortcut_id = CreateShortcut("app1"); - launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); - EXPECT_EQ(++tab_count, tab_strip->count()); - EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status); - WebContents* first_tab = tab_strip->GetActiveWebContents(); - - controller->SetRefocusURLPatternForTest( - shortcut_id, GURL("http://www.example.com/path1/*")); - // Create new tab owned by app. - ui_test_utils::NavigateToURLWithDisposition( - browser(), - GURL("http://www.example.com/path2/bar.html"), - NEW_FOREGROUND_TAB, - ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); - EXPECT_EQ(++tab_count, tab_strip->count()); - // Confirm app is still active. - EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status); - - // Create new tab not owned by app. - ui_test_utils::NavigateToURLWithDisposition( - browser(), - GURL("http://www.example.com/path3/foo.html"), - NEW_FOREGROUND_TAB, - 0); - EXPECT_EQ(++tab_count, tab_strip->count()); - // No longer active. - EXPECT_EQ(ash::STATUS_RUNNING, model_->ItemByID(shortcut_id)->status); - - // Activating app makes first tab active again, because second tab isn't - // in its refocus url path. - launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); - EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status); - EXPECT_EQ(tab_strip->GetActiveWebContents(), first_tab); -} - -IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, RefocusFilterLaunch) { - ChromeLauncherController* controller = - static_cast<ChromeLauncherController*>(launcher_->delegate()); - TabStripModel* tab_strip = browser()->tab_strip_model(); - int tab_count = tab_strip->count(); - ash::LauncherID shortcut_id = CreateShortcut("app1"); - controller->SetRefocusURLPatternForTest( - shortcut_id, GURL("http://www.example.com/path1/*")); - - // Create new tab owned by app. - ui_test_utils::NavigateToURLWithDisposition( - browser(), - GURL("http://www.example.com/path2/bar.html"), - NEW_FOREGROUND_TAB, - ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); - EXPECT_EQ(++tab_count, tab_strip->count()); - WebContents* first_tab = tab_strip->GetActiveWebContents(); - // Confirm app is active. - EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status); - - // Activating app should launch new tab, because second tab isn't - // in its refocus url path. - launcher_->ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); - EXPECT_EQ(++tab_count, tab_strip->count()); - WebContents* second_tab = tab_strip->GetActiveWebContents(); - EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status); - EXPECT_NE(first_tab, second_tab); - EXPECT_EQ(tab_strip->GetActiveWebContents(), second_tab); -} - -IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, OverflowBubble) { - // Make sure to have a browser window - chrome::NewTab(browser()); - - // No overflow yet. - EXPECT_FALSE(launcher_->IsShowingOverflowBubble()); - - ash::test::LauncherViewTestAPI test(launcher_->GetLauncherViewForTest()); - - int items_added = 0; - while (!test.IsOverflowButtonVisible()) { - std::string fake_app_id = base::StringPrintf("fake_app_%d", items_added); - PinFakeApp(fake_app_id); - - ++items_added; - ASSERT_LT(items_added, 10000); - } - - // Now show overflow bubble. - test.ShowOverflowBubble(); - EXPECT_TRUE(launcher_->IsShowingOverflowBubble()); - - // Unpin first pinned app and there should be no crash. - ChromeLauncherController* controller = - static_cast<ChromeLauncherController*>(launcher_->delegate()); - controller->UnpinAppsWithID(std::string("fake_app_0")); - - test.RunMessageLoopUntilAnimationsDone(); - EXPECT_FALSE(launcher_->IsShowingOverflowBubble()); -} diff --git a/chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app.cc b/chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app.cc index 3137581..94a636c 100644 --- a/chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app.cc +++ b/chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app.cc @@ -61,6 +61,7 @@ #include "chrome/common/pref_names.h" #include "chrome/common/url_constants.h" #include "content/public/browser/navigation_entry.h" +#include "content/public/browser/notification_registrar.h" #include "content/public/browser/notification_service.h" #include "content/public/browser/web_contents.h" #include "extensions/common/extension_resource.h" @@ -83,6 +84,9 @@ using extensions::Extension; using extension_misc::kGmailAppId; using content::WebContents; +// static +ChromeLauncherController* ChromeLauncherController::instance_ = NULL; + namespace { std::string GetPrefKeyForRootWindow(aura::RootWindow* root_window) { @@ -186,7 +190,7 @@ void MaybePropagatePrefToLocal(PrefServiceSyncable* pref_service, } // namespace -ChromeLauncherControllerPerApp::ChromeLauncherControllerPerApp( +ChromeLauncherController::ChromeLauncherController( Profile* profile, ash::LauncherModel* model) : model_(model), @@ -224,24 +228,24 @@ ChromeLauncherControllerPerApp::ChromeLauncherControllerPerApp( pref_change_registrar_.Init(profile_->GetPrefs()); pref_change_registrar_.Add( prefs::kPinnedLauncherApps, - base::Bind(&ChromeLauncherControllerPerApp::UpdateAppLaunchersFromPref, + base::Bind(&ChromeLauncherController::UpdateAppLaunchersFromPref, base::Unretained(this))); pref_change_registrar_.Add( prefs::kShelfAlignmentLocal, - base::Bind(&ChromeLauncherControllerPerApp::SetShelfAlignmentFromPrefs, + base::Bind(&ChromeLauncherController::SetShelfAlignmentFromPrefs, base::Unretained(this))); pref_change_registrar_.Add( prefs::kShelfAutoHideBehaviorLocal, - base::Bind(&ChromeLauncherControllerPerApp:: + base::Bind(&ChromeLauncherController:: SetShelfAutoHideBehaviorFromPrefs, base::Unretained(this))); pref_change_registrar_.Add( prefs::kShelfPreferences, - base::Bind(&ChromeLauncherControllerPerApp::SetShelfBehaviorsFromPrefs, + base::Bind(&ChromeLauncherController::SetShelfBehaviorsFromPrefs, base::Unretained(this))); } -ChromeLauncherControllerPerApp::~ChromeLauncherControllerPerApp() { +ChromeLauncherController::~ChromeLauncherController() { // Reset the shell window controller here since it has a weak pointer to this. shell_window_controller_.reset(); @@ -275,9 +279,23 @@ ChromeLauncherControllerPerApp::~ChromeLauncherControllerPerApp() { app_sync_ui_state_->RemoveObserver(this); PrefServiceSyncable::FromProfile(profile_)->RemoveObserver(this); + + if (instance_ == this) + instance_ = NULL; +} + +// static +ChromeLauncherController* ChromeLauncherController::CreateInstance( + Profile* profile, + ash::LauncherModel* model) { + // We do not check here for re-creation of the ChromeLauncherController since + // it appears that it might be intentional that the ChromeLauncherController + // can be re-created. + instance_ = new ChromeLauncherController(profile, model); + return instance_; } -void ChromeLauncherControllerPerApp::Init() { +void ChromeLauncherController::Init() { UpdateAppLaunchersFromPref(); CreateBrowserShortcutLauncherItem(); @@ -297,22 +315,7 @@ void ChromeLauncherControllerPerApp::Init() { } } -ChromeLauncherControllerPerApp* -ChromeLauncherControllerPerApp::GetPerAppInterface() { - return this; -} - -ash::LauncherID ChromeLauncherControllerPerApp::CreateTabbedLauncherItem( - LauncherItemController* controller, - IncognitoState is_incognito, - ash::LauncherItemStatus status) { - // The PerAppLauncher doesn't need an empty slot for TabbedLauncherItem and - // its LauncherItemController. - // TODO(skuhne): Remove function when PerBrowser launcher gets removed. - return 0; -} - -ash::LauncherID ChromeLauncherControllerPerApp::CreateAppLauncherItem( +ash::LauncherID ChromeLauncherController::CreateAppLauncherItem( LauncherItemController* controller, const std::string& app_id, ash::LauncherItemStatus status) { @@ -332,7 +335,7 @@ ash::LauncherID ChromeLauncherControllerPerApp::CreateAppLauncherItem( controller->GetLauncherItemType()); } -void ChromeLauncherControllerPerApp::SetItemStatus( +void ChromeLauncherController::SetItemStatus( ash::LauncherID id, ash::LauncherItemStatus status) { int index = model_->ItemIndexByID(id); @@ -349,7 +352,7 @@ void ChromeLauncherControllerPerApp::SetItemStatus( UpdateBrowserItemStatus(); } -void ChromeLauncherControllerPerApp::SetItemController( +void ChromeLauncherController::SetItemController( ash::LauncherID id, LauncherItemController* controller) { CHECK(controller); @@ -360,7 +363,7 @@ void ChromeLauncherControllerPerApp::SetItemController( controller->set_launcher_id(id); } -void ChromeLauncherControllerPerApp::CloseLauncherItem(ash::LauncherID id) { +void ChromeLauncherController::CloseLauncherItem(ash::LauncherID id) { CHECK(id); if (IsPinned(id)) { // Create a new shortcut controller. @@ -376,7 +379,7 @@ void ChromeLauncherControllerPerApp::CloseLauncherItem(ash::LauncherID id) { } } -void ChromeLauncherControllerPerApp::Pin(ash::LauncherID id) { +void ChromeLauncherController::Pin(ash::LauncherID id) { DCHECK(HasItemController(id)); int index = model_->ItemIndexByID(id); @@ -396,7 +399,7 @@ void ChromeLauncherControllerPerApp::Pin(ash::LauncherID id) { PersistPinnedState(); } -void ChromeLauncherControllerPerApp::Unpin(ash::LauncherID id) { +void ChromeLauncherController::Unpin(ash::LauncherID id) { DCHECK(HasItemController(id)); LauncherItemController* controller = id_to_item_controller_map_[id]; @@ -423,7 +426,7 @@ void ChromeLauncherControllerPerApp::Unpin(ash::LauncherID id) { PersistPinnedState(); } -bool ChromeLauncherControllerPerApp::IsPinned(ash::LauncherID id) { +bool ChromeLauncherController::IsPinned(ash::LauncherID id) { int index = model_->ItemIndexByID(id); if (index < 0) return false; @@ -431,7 +434,7 @@ bool ChromeLauncherControllerPerApp::IsPinned(ash::LauncherID id) { return (type == ash::TYPE_APP_SHORTCUT || type == ash::TYPE_BROWSER_SHORTCUT); } -void ChromeLauncherControllerPerApp::TogglePinned(ash::LauncherID id) { +void ChromeLauncherController::TogglePinned(ash::LauncherID id) { if (!HasItemController(id)) return; // May happen if item closed with menu open. @@ -441,7 +444,7 @@ void ChromeLauncherControllerPerApp::TogglePinned(ash::LauncherID id) { Pin(id); } -bool ChromeLauncherControllerPerApp::IsPinnable(ash::LauncherID id) const { +bool ChromeLauncherController::IsPinnable(ash::LauncherID id) const { int index = model_->ItemIndexByID(id); if (index == -1) return false; @@ -453,7 +456,7 @@ bool ChromeLauncherControllerPerApp::IsPinnable(ash::LauncherID id) const { CanPin()); } -void ChromeLauncherControllerPerApp::LockV1AppWithID( +void ChromeLauncherController::LockV1AppWithID( const std::string& app_id) { ash::LauncherID id = GetLauncherIDForAppID(app_id); if (!IsPinned(id) && !IsWindowedAppInLauncher(app_id)) { @@ -466,7 +469,7 @@ void ChromeLauncherControllerPerApp::LockV1AppWithID( id_to_item_controller_map_[id]->lock(); } -void ChromeLauncherControllerPerApp::UnlockV1AppWithID( +void ChromeLauncherController::UnlockV1AppWithID( const std::string& app_id) { ash::LauncherID id = GetLauncherIDForAppID(app_id); CHECK(IsPinned(id) || IsWindowedAppInLauncher(app_id)); @@ -477,26 +480,26 @@ void ChromeLauncherControllerPerApp::UnlockV1AppWithID( CloseLauncherItem(id); } -void ChromeLauncherControllerPerApp::Launch(ash::LauncherID id, +void ChromeLauncherController::Launch(ash::LauncherID id, int event_flags) { if (!HasItemController(id)) return; // In case invoked from menu and item closed while menu up. id_to_item_controller_map_[id]->Launch(event_flags); } -void ChromeLauncherControllerPerApp::Close(ash::LauncherID id) { +void ChromeLauncherController::Close(ash::LauncherID id) { if (!HasItemController(id)) return; // May happen if menu closed. id_to_item_controller_map_[id]->Close(); } -bool ChromeLauncherControllerPerApp::IsOpen(ash::LauncherID id) { +bool ChromeLauncherController::IsOpen(ash::LauncherID id) { if (!HasItemController(id)) return false; return id_to_item_controller_map_[id]->IsOpen(); } -bool ChromeLauncherControllerPerApp::IsPlatformApp(ash::LauncherID id) { +bool ChromeLauncherController::IsPlatformApp(ash::LauncherID id) { if (!HasItemController(id)) return false; @@ -507,7 +510,7 @@ bool ChromeLauncherControllerPerApp::IsPlatformApp(ash::LauncherID id) { return extension ? extension->is_platform_app() : false; } -void ChromeLauncherControllerPerApp::LaunchApp(const std::string& app_id, +void ChromeLauncherController::LaunchApp(const std::string& app_id, int event_flags) { // |extension| could be NULL when it is being unloaded for updating. const Extension* extension = GetExtensionForAppID(app_id); @@ -532,7 +535,7 @@ void ChromeLauncherControllerPerApp::LaunchApp(const std::string& app_id, event_flags)); } -void ChromeLauncherControllerPerApp::ActivateApp(const std::string& app_id, +void ChromeLauncherController::ActivateApp(const std::string& app_id, int event_flags) { // If there is an existing non-shortcut controller for this app, open it. ash::LauncherID id = GetLauncherIDForAppID(app_id); @@ -553,7 +556,7 @@ void ChromeLauncherControllerPerApp::ActivateApp(const std::string& app_id, } extensions::ExtensionPrefs::LaunchType - ChromeLauncherControllerPerApp::GetLaunchType(ash::LauncherID id) { + ChromeLauncherController::GetLaunchType(ash::LauncherID id) { DCHECK(HasItemController(id)); const Extension* extension = GetExtensionForAppID( @@ -568,12 +571,11 @@ extensions::ExtensionPrefs::LaunchType extensions::ExtensionPrefs::LAUNCH_DEFAULT); } -std::string ChromeLauncherControllerPerApp::GetAppID( - content::WebContents* tab) { +std::string ChromeLauncherController::GetAppID(content::WebContents* tab) { return app_tab_helper_->GetAppID(tab); } -ash::LauncherID ChromeLauncherControllerPerApp::GetLauncherIDForAppID( +ash::LauncherID ChromeLauncherController::GetLauncherIDForAppID( const std::string& app_id) { for (IDToItemControllerMap::const_iterator i = id_to_item_controller_map_.begin(); @@ -586,15 +588,14 @@ ash::LauncherID ChromeLauncherControllerPerApp::GetLauncherIDForAppID( return 0; } -std::string ChromeLauncherControllerPerApp::GetAppIDForLauncherID( +std::string ChromeLauncherController::GetAppIDForLauncherID( ash::LauncherID id) { CHECK(HasItemController(id)); return id_to_item_controller_map_[id]->app_id(); } -void ChromeLauncherControllerPerApp::SetAppImage( - const std::string& id, - const gfx::ImageSkia& image) { +void ChromeLauncherController::SetAppImage(const std::string& id, + const gfx::ImageSkia& image) { // TODO: need to get this working for shortcuts. for (IDToItemControllerMap::const_iterator i = @@ -615,13 +616,13 @@ void ChromeLauncherControllerPerApp::SetAppImage( } } -void ChromeLauncherControllerPerApp::OnAutoHideBehaviorChanged( +void ChromeLauncherController::OnAutoHideBehaviorChanged( aura::RootWindow* root_window, ash::ShelfAutoHideBehavior new_behavior) { SetShelfAutoHideBehaviorPrefs(new_behavior, root_window); } -void ChromeLauncherControllerPerApp::SetLauncherItemImage( +void ChromeLauncherController::SetLauncherItemImage( ash::LauncherID launcher_id, const gfx::ImageSkia& image) { int index = model_->ItemIndexByID(launcher_id); @@ -632,7 +633,7 @@ void ChromeLauncherControllerPerApp::SetLauncherItemImage( model_->Set(index, item); } -bool ChromeLauncherControllerPerApp::IsAppPinned(const std::string& app_id) { +bool ChromeLauncherController::IsAppPinned(const std::string& app_id) { for (IDToItemControllerMap::const_iterator i = id_to_item_controller_map_.begin(); i != id_to_item_controller_map_.end(); ++i) { @@ -642,7 +643,7 @@ bool ChromeLauncherControllerPerApp::IsAppPinned(const std::string& app_id) { return false; } -bool ChromeLauncherControllerPerApp::IsWindowedAppInLauncher( +bool ChromeLauncherController::IsWindowedAppInLauncher( const std::string& app_id) { int index = model_->ItemIndexByID(GetLauncherIDForAppID(app_id)); if (index < 0) @@ -652,14 +653,14 @@ bool ChromeLauncherControllerPerApp::IsWindowedAppInLauncher( return type == ash::TYPE_WINDOWED_APP; } -void ChromeLauncherControllerPerApp::PinAppWithID(const std::string& app_id) { +void ChromeLauncherController::PinAppWithID(const std::string& app_id) { if (CanPin()) DoPinAppWithID(app_id); else NOTREACHED(); } -void ChromeLauncherControllerPerApp::SetLaunchType( +void ChromeLauncherController::SetLaunchType( ash::LauncherID id, extensions::ExtensionPrefs::LaunchType launch_type) { if (!HasItemController(id)) @@ -669,35 +670,34 @@ void ChromeLauncherControllerPerApp::SetLaunchType( id_to_item_controller_map_[id]->app_id(), launch_type); } -void ChromeLauncherControllerPerApp::UnpinAppsWithID( - const std::string& app_id) { +void ChromeLauncherController::UnpinAppsWithID(const std::string& app_id) { if (CanPin()) DoUnpinAppsWithID(app_id); else NOTREACHED(); } -bool ChromeLauncherControllerPerApp::IsLoggedInAsGuest() { +bool ChromeLauncherController::IsLoggedInAsGuest() { return ProfileManager::GetDefaultProfileOrOffTheRecord()->IsOffTheRecord(); } -void ChromeLauncherControllerPerApp::CreateNewWindow() { +void ChromeLauncherController::CreateNewWindow() { chrome::NewEmptyWindow( GetProfileForNewWindows(), chrome::HOST_DESKTOP_TYPE_ASH); } -void ChromeLauncherControllerPerApp::CreateNewIncognitoWindow() { +void ChromeLauncherController::CreateNewIncognitoWindow() { chrome::NewEmptyWindow(GetProfileForNewWindows()->GetOffTheRecordProfile(), chrome::HOST_DESKTOP_TYPE_ASH); } -bool ChromeLauncherControllerPerApp::CanPin() const { +bool ChromeLauncherController::CanPin() const { const PrefService::Preference* pref = profile_->GetPrefs()->FindPreference(prefs::kPinnedLauncherApps); return pref && pref->IsUserModifiable(); } -void ChromeLauncherControllerPerApp::PersistPinnedState() { +void ChromeLauncherController::PersistPinnedState() { if (ignore_persist_pinned_state_change_) return; // It is a coding error to call PersistPinnedState() if the pinned apps are @@ -731,21 +731,20 @@ void ChromeLauncherControllerPerApp::PersistPinnedState() { } pref_change_registrar_.Add( prefs::kPinnedLauncherApps, - base::Bind(&ChromeLauncherControllerPerApp::UpdateAppLaunchersFromPref, + base::Bind(&ChromeLauncherController::UpdateAppLaunchersFromPref, base::Unretained(this))); } -ash::LauncherModel* ChromeLauncherControllerPerApp::model() { +ash::LauncherModel* ChromeLauncherController::model() { return model_; } -Profile* ChromeLauncherControllerPerApp::profile() { +Profile* ChromeLauncherController::profile() { return profile_; } -ash::ShelfAutoHideBehavior - ChromeLauncherControllerPerApp::GetShelfAutoHideBehavior( - aura::RootWindow* root_window) const { +ash::ShelfAutoHideBehavior ChromeLauncherController::GetShelfAutoHideBehavior( + aura::RootWindow* root_window) const { // Don't show the shelf in app mode. if (chrome::IsRunningInAppMode()) return ash::SHELF_AUTO_HIDE_ALWAYS_HIDDEN; @@ -766,13 +765,13 @@ ash::ShelfAutoHideBehavior return ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER; } -bool ChromeLauncherControllerPerApp::CanUserModifyShelfAutoHideBehavior( +bool ChromeLauncherController::CanUserModifyShelfAutoHideBehavior( aura::RootWindow* root_window) const { return profile_->GetPrefs()-> FindPreference(prefs::kShelfAutoHideBehaviorLocal)->IsUserModifiable(); } -void ChromeLauncherControllerPerApp::ToggleShelfAutoHideBehavior( +void ChromeLauncherController::ToggleShelfAutoHideBehavior( aura::RootWindow* root_window) { ash::ShelfAutoHideBehavior behavior = GetShelfAutoHideBehavior(root_window) == ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS ? @@ -782,7 +781,7 @@ void ChromeLauncherControllerPerApp::ToggleShelfAutoHideBehavior( return; } -void ChromeLauncherControllerPerApp::RemoveTabFromRunningApp( +void ChromeLauncherController::RemoveTabFromRunningApp( WebContents* tab, const std::string& app_id) { web_contents_to_app_id_.erase(tab); @@ -801,9 +800,8 @@ void ChromeLauncherControllerPerApp::RemoveTabFromRunningApp( } } -void ChromeLauncherControllerPerApp::UpdateAppState( - content::WebContents* contents, - AppState app_state) { +void ChromeLauncherController::UpdateAppState(content::WebContents* contents, + AppState app_state) { std::string app_id = GetAppID(contents); // Check if the gMail app is loaded and it matches the given content. @@ -858,9 +856,8 @@ void ChromeLauncherControllerPerApp::UpdateAppState( UpdateBrowserItemStatus(); } -void ChromeLauncherControllerPerApp::SetRefocusURLPatternForTest( - ash::LauncherID id, - const GURL& url) { +void ChromeLauncherController::SetRefocusURLPatternForTest(ash::LauncherID id, + const GURL& url) { DCHECK(HasItemController(id)); LauncherItemController* controller = id_to_item_controller_map_[id]; @@ -880,14 +877,14 @@ void ChromeLauncherControllerPerApp::SetRefocusURLPatternForTest( } } -const Extension* ChromeLauncherControllerPerApp::GetExtensionForAppID( +const Extension* ChromeLauncherController::GetExtensionForAppID( const std::string& app_id) const { // Some unit tests do not have a real extension. return (profile_->GetExtensionService()) ? profile_->GetExtensionService()->GetInstalledExtension(app_id) : NULL; } -void ChromeLauncherControllerPerApp::ActivateWindowOrMinimizeIfActive( +void ChromeLauncherController::ActivateWindowOrMinimizeIfActive( ui::BaseWindow* window, bool allow_minimize) { if (window->IsActive() && allow_minimize) { @@ -904,8 +901,8 @@ void ChromeLauncherControllerPerApp::ActivateWindowOrMinimizeIfActive( } } -void ChromeLauncherControllerPerApp::ItemSelected(const ash::LauncherItem& item, - const ui::Event& event) { +void ChromeLauncherController::ItemSelected(const ash::LauncherItem& item, + const ui::Event& event) { DCHECK(HasItemController(item.id)); LauncherItemController* item_controller = id_to_item_controller_map_[item.id]; #if defined(OS_CHROMEOS) @@ -917,27 +914,25 @@ void ChromeLauncherControllerPerApp::ItemSelected(const ash::LauncherItem& item, item_controller->Clicked(event); } -string16 ChromeLauncherControllerPerApp::GetTitle( - const ash::LauncherItem& item) { +string16 ChromeLauncherController::GetTitle(const ash::LauncherItem& item) { DCHECK(HasItemController(item.id)); return id_to_item_controller_map_[item.id]->GetTitle(); } -ui::MenuModel* ChromeLauncherControllerPerApp::CreateContextMenu( +ui::MenuModel* ChromeLauncherController::CreateContextMenu( const ash::LauncherItem& item, aura::RootWindow* root_window) { return new LauncherContextMenu(this, &item, root_window); } -ash::LauncherMenuModel* ChromeLauncherControllerPerApp::CreateApplicationMenu( +ash::LauncherMenuModel* ChromeLauncherController::CreateApplicationMenu( const ash::LauncherItem& item, int event_flags) { return new LauncherApplicationMenuItemModel(GetApplicationList(item, event_flags)); } -ash::LauncherID ChromeLauncherControllerPerApp::GetIDByWindow( - aura::Window* window) { +ash::LauncherID ChromeLauncherController::GetIDByWindow(aura::Window* window) { int browser_index = ash::launcher::GetBrowserItemIndex(*model_); DCHECK_GE(browser_index, 0); ash::LauncherID browser_id = model_->items()[browser_index].id; @@ -958,13 +953,12 @@ ash::LauncherID ChromeLauncherControllerPerApp::GetIDByWindow( return 0; } -bool ChromeLauncherControllerPerApp::IsDraggable( - const ash::LauncherItem& item) { +bool ChromeLauncherController::IsDraggable(const ash::LauncherItem& item) { return (item.type == ash::TYPE_APP_SHORTCUT || item.type == ash::TYPE_WINDOWED_APP) ? CanPin() : true; } -bool ChromeLauncherControllerPerApp::ShouldShowTooltip( +bool ChromeLauncherController::ShouldShowTooltip( const ash::LauncherItem& item) { if (item.type == ash::TYPE_APP_PANEL && id_to_item_controller_map_[item.id]->IsVisible()) @@ -972,36 +966,32 @@ bool ChromeLauncherControllerPerApp::ShouldShowTooltip( return true; } -void ChromeLauncherControllerPerApp::OnLauncherCreated( - ash::Launcher* launcher) { +void ChromeLauncherController::OnLauncherCreated(ash::Launcher* launcher) { launchers_.insert(launcher); launcher->shelf_widget()->shelf_layout_manager()->AddObserver(this); } -void ChromeLauncherControllerPerApp::OnLauncherDestroyed( - ash::Launcher* launcher) { +void ChromeLauncherController::OnLauncherDestroyed(ash::Launcher* launcher) { launchers_.erase(launcher); // RemoveObserver is not called here, since by the time this method is called // Launcher is already in its destructor. } -void ChromeLauncherControllerPerApp::LauncherItemAdded(int index) { +void ChromeLauncherController::LauncherItemAdded(int index) { } -void ChromeLauncherControllerPerApp::LauncherItemRemoved( - int index, - ash::LauncherID id) { +void ChromeLauncherController::LauncherItemRemoved(int index, + ash::LauncherID id) { } -void ChromeLauncherControllerPerApp::LauncherItemMoved( - int start_index, - int target_index) { +void ChromeLauncherController::LauncherItemMoved(int start_index, + int target_index) { ash::LauncherID id = model_->items()[target_index].id; if (HasItemController(id) && IsPinned(id)) PersistPinnedState(); } -void ChromeLauncherControllerPerApp::LauncherItemChanged( +void ChromeLauncherController::LauncherItemChanged( int index, const ash::LauncherItem& old_item) { ash::LauncherID id = model_->items()[index].id; @@ -1009,10 +999,10 @@ void ChromeLauncherControllerPerApp::LauncherItemChanged( id_to_item_controller_map_[id]->LauncherItemChanged(index, old_item); } -void ChromeLauncherControllerPerApp::LauncherStatusChanged() { +void ChromeLauncherController::LauncherStatusChanged() { } -void ChromeLauncherControllerPerApp::Observe( +void ChromeLauncherController::Observe( int type, const content::NotificationSource& source, const content::NotificationDetails& details) { @@ -1056,7 +1046,7 @@ void ChromeLauncherControllerPerApp::Observe( } } -void ChromeLauncherControllerPerApp::OnShelfAlignmentChanged( +void ChromeLauncherController::OnShelfAlignmentChanged( aura::RootWindow* root_window) { const char* pref_value = NULL; switch (ash::Shell::GetInstance()->GetShelfAlignment(root_window)) { @@ -1083,14 +1073,14 @@ void ChromeLauncherControllerPerApp::OnShelfAlignmentChanged( } } -void ChromeLauncherControllerPerApp::OnDisplayConfigurationChanging() { +void ChromeLauncherController::OnDisplayConfigurationChanging() { } -void ChromeLauncherControllerPerApp::OnDisplayConfigurationChanged() { +void ChromeLauncherController::OnDisplayConfigurationChanged() { SetShelfBehaviorsFromPrefs(); } -void ChromeLauncherControllerPerApp::OnIsSyncingChanged() { +void ChromeLauncherController::OnIsSyncingChanged() { PrefServiceSyncable* prefs = PrefServiceSyncable::FromProfile(profile_); MaybePropagatePrefToLocal(prefs, prefs::kShelfAlignmentLocal, @@ -1100,24 +1090,23 @@ void ChromeLauncherControllerPerApp::OnIsSyncingChanged() { prefs::kShelfAutoHideBehavior); } -void ChromeLauncherControllerPerApp::OnAppSyncUIStatusChanged() { +void ChromeLauncherController::OnAppSyncUIStatusChanged() { if (app_sync_ui_state_->status() == AppSyncUIState::STATUS_SYNCING) model_->SetStatus(ash::LauncherModel::STATUS_LOADING); else model_->SetStatus(ash::LauncherModel::STATUS_NORMAL); } -void ChromeLauncherControllerPerApp::ExtensionEnableFlowFinished() { +void ChromeLauncherController::ExtensionEnableFlowFinished() { LaunchApp(extension_enable_flow_->extension_id(), ui::EF_NONE); extension_enable_flow_.reset(); } -void ChromeLauncherControllerPerApp::ExtensionEnableFlowAborted( - bool user_initiated) { +void ChromeLauncherController::ExtensionEnableFlowAborted(bool user_initiated) { extension_enable_flow_.reset(); } -ChromeLauncherAppMenuItems ChromeLauncherControllerPerApp::GetApplicationList( +ChromeLauncherAppMenuItems ChromeLauncherController::GetApplicationList( const ash::LauncherItem& item, int event_flags) { // Make sure that there is a controller associated with the id and that the @@ -1130,8 +1119,7 @@ ChromeLauncherAppMenuItems ChromeLauncherControllerPerApp::GetApplicationList( } std::vector<content::WebContents*> -ChromeLauncherControllerPerApp::GetV1ApplicationsFromAppId( - std::string app_id) { +ChromeLauncherController::GetV1ApplicationsFromAppId(std::string app_id) { ash::LauncherID id = GetLauncherIDForAppID(app_id); // If there is no such an item pinned to the launcher, no menu gets created. @@ -1144,9 +1132,8 @@ ChromeLauncherControllerPerApp::GetV1ApplicationsFromAppId( return std::vector<content::WebContents*>(); } -void ChromeLauncherControllerPerApp::ActivateShellApp( - const std::string& app_id, - int index) { +void ChromeLauncherController::ActivateShellApp(const std::string& app_id, + int index) { ash::LauncherID id = GetLauncherIDForAppID(app_id); if (id) { LauncherItemController* controller = id_to_item_controller_map_[id]; @@ -1158,7 +1145,7 @@ void ChromeLauncherControllerPerApp::ActivateShellApp( } } -bool ChromeLauncherControllerPerApp::IsWebContentHandledByApplication( +bool ChromeLauncherController::IsWebContentHandledByApplication( content::WebContents* web_contents, const std::string& app_id) { if ((web_contents_to_app_id_.find(web_contents) != @@ -1168,7 +1155,7 @@ bool ChromeLauncherControllerPerApp::IsWebContentHandledByApplication( return (app_id == kGmailAppId && ContentCanBeHandledByGmailApp(web_contents)); } -bool ChromeLauncherControllerPerApp::ContentCanBeHandledByGmailApp( +bool ChromeLauncherController::ContentCanBeHandledByGmailApp( content::WebContents* web_contents) { ash::LauncherID id = GetLauncherIDForAppID(kGmailAppId); if (id) { @@ -1185,7 +1172,7 @@ bool ChromeLauncherControllerPerApp::ContentCanBeHandledByGmailApp( return false; } -gfx::Image ChromeLauncherControllerPerApp::GetAppListIcon( +gfx::Image ChromeLauncherController::GetAppListIcon( content::WebContents* web_contents) const { ResourceBundle& rb = ResourceBundle::GetSharedInstance(); if (IsIncognito(web_contents)) @@ -1198,7 +1185,7 @@ gfx::Image ChromeLauncherControllerPerApp::GetAppListIcon( return result; } -string16 ChromeLauncherControllerPerApp::GetAppListTitle( +string16 ChromeLauncherController::GetAppListTitle( content::WebContents* web_contents) const { string16 title = web_contents->GetTitle(); if (!title.empty()) @@ -1214,14 +1201,14 @@ string16 ChromeLauncherControllerPerApp::GetAppListTitle( return l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE); } -void ChromeLauncherControllerPerApp::OnBrowserRemoved(Browser* browser) { +void ChromeLauncherController::OnBrowserRemoved(Browser* browser) { // When called by a unit test it is possible that there is no shell. // In that case, the following function should not get called. if (ash::Shell::HasInstance()) UpdateBrowserItemStatus(); } -ash::LauncherID ChromeLauncherControllerPerApp::CreateAppShortcutLauncherItem( +ash::LauncherID ChromeLauncherController::CreateAppShortcutLauncherItem( const std::string& app_id, int index) { return CreateAppShortcutLauncherItemWithType(app_id, @@ -1229,24 +1216,21 @@ ash::LauncherID ChromeLauncherControllerPerApp::CreateAppShortcutLauncherItem( ash::TYPE_APP_SHORTCUT); } -void ChromeLauncherControllerPerApp::SetAppTabHelperForTest( - AppTabHelper* helper) { +void ChromeLauncherController::SetAppTabHelperForTest(AppTabHelper* helper) { app_tab_helper_.reset(helper); } -void ChromeLauncherControllerPerApp::SetAppIconLoaderForTest( +void ChromeLauncherController::SetAppIconLoaderForTest( extensions::AppIconLoader* loader) { app_icon_loader_.reset(loader); } -const std::string& -ChromeLauncherControllerPerApp::GetAppIdFromLauncherIdForTest( +const std::string& ChromeLauncherController::GetAppIdFromLauncherIdForTest( ash::LauncherID id) { return id_to_item_controller_map_[id]->app_id(); } -ash::LauncherID -ChromeLauncherControllerPerApp::CreateAppShortcutLauncherItemWithType( +ash::LauncherID ChromeLauncherController::CreateAppShortcutLauncherItemWithType( const std::string& app_id, int index, ash::LauncherItemType launcher_item_type) { @@ -1257,7 +1241,7 @@ ChromeLauncherControllerPerApp::CreateAppShortcutLauncherItemWithType( return launcher_id; } -void ChromeLauncherControllerPerApp::UpdateBrowserItemStatus() { +void ChromeLauncherController::UpdateBrowserItemStatus() { // Determine the new browser's active state and change if necessary. size_t browser_index = ash::launcher::GetBrowserItemIndex(*model_); DCHECK_GE(browser_index, 0u); @@ -1300,11 +1284,11 @@ void ChromeLauncherControllerPerApp::UpdateBrowserItemStatus() { } } -Profile* ChromeLauncherControllerPerApp::GetProfileForNewWindows() { +Profile* ChromeLauncherController::GetProfileForNewWindows() { return ProfileManager::GetDefaultProfileOrOffTheRecord(); } -void ChromeLauncherControllerPerApp::LauncherItemClosed(ash::LauncherID id) { +void ChromeLauncherController::LauncherItemClosed(ash::LauncherID id) { IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); CHECK(iter != id_to_item_controller_map_.end()); CHECK(iter->second); @@ -1318,8 +1302,7 @@ void ChromeLauncherControllerPerApp::LauncherItemClosed(ash::LauncherID id) { model_->RemoveItemAt(index); } -void ChromeLauncherControllerPerApp::DoPinAppWithID( - const std::string& app_id) { +void ChromeLauncherController::DoPinAppWithID(const std::string& app_id) { // If there is an item, do nothing and return. if (IsAppPinned(app_id)) return; @@ -1336,8 +1319,7 @@ void ChromeLauncherControllerPerApp::DoPinAppWithID( } } -void ChromeLauncherControllerPerApp::DoUnpinAppsWithID( - const std::string& app_id) { +void ChromeLauncherController::DoUnpinAppsWithID(const std::string& app_id) { for (IDToItemControllerMap::iterator i = id_to_item_controller_map_.begin(); i != id_to_item_controller_map_.end(); ) { IDToItemControllerMap::iterator current(i); @@ -1347,7 +1329,7 @@ void ChromeLauncherControllerPerApp::DoUnpinAppsWithID( } } -void ChromeLauncherControllerPerApp::UpdateAppLaunchersFromPref() { +void ChromeLauncherController::UpdateAppLaunchersFromPref() { // Construct a vector representation of to-be-pinned apps from the pref. std::vector<std::string> pinned_apps; int chrome_icon_index = GetChromeIconIndexFromPref(); @@ -1451,7 +1433,7 @@ void ChromeLauncherControllerPerApp::UpdateAppLaunchersFromPref() { } -void ChromeLauncherControllerPerApp::SetShelfAutoHideBehaviorPrefs( +void ChromeLauncherController::SetShelfAutoHideBehaviorPrefs( ash::ShelfAutoHideBehavior behavior, aura::RootWindow* root_window) { const char* value = NULL; @@ -1479,7 +1461,7 @@ void ChromeLauncherControllerPerApp::SetShelfAutoHideBehaviorPrefs( } } -void ChromeLauncherControllerPerApp::SetShelfAutoHideBehaviorFromPrefs() { +void ChromeLauncherController::SetShelfAutoHideBehaviorFromPrefs() { ash::Shell::RootWindowList root_windows = ash::Shell::GetAllRootWindows(); for (ash::Shell::RootWindowList::const_iterator iter = root_windows.begin(); @@ -1489,7 +1471,7 @@ void ChromeLauncherControllerPerApp::SetShelfAutoHideBehaviorFromPrefs() { } } -void ChromeLauncherControllerPerApp::SetShelfAlignmentFromPrefs() { +void ChromeLauncherController::SetShelfAlignmentFromPrefs() { if (!ash::ShelfWidget::ShelfAlignmentAllowed()) return; @@ -1514,12 +1496,12 @@ void ChromeLauncherControllerPerApp::SetShelfAlignmentFromPrefs() { } } -void ChromeLauncherControllerPerApp::SetShelfBehaviorsFromPrefs() { +void ChromeLauncherController::SetShelfBehaviorsFromPrefs() { SetShelfAutoHideBehaviorFromPrefs(); SetShelfAlignmentFromPrefs(); } -WebContents* ChromeLauncherControllerPerApp::GetLastActiveWebContents( +WebContents* ChromeLauncherController::GetLastActiveWebContents( const std::string& app_id) { AppIDToWebContentsListMap::const_iterator i = app_id_to_web_contents_list_.find(app_id); @@ -1529,7 +1511,7 @@ WebContents* ChromeLauncherControllerPerApp::GetLastActiveWebContents( return *i->second.begin(); } -ash::LauncherID ChromeLauncherControllerPerApp::InsertAppLauncherItem( +ash::LauncherID ChromeLauncherController::InsertAppLauncherItem( LauncherItemController* controller, const std::string& app_id, ash::LauncherItemStatus status, @@ -1564,14 +1546,13 @@ ash::LauncherID ChromeLauncherControllerPerApp::InsertAppLauncherItem( return id; } -bool ChromeLauncherControllerPerApp::HasItemController( - ash::LauncherID id) const { +bool ChromeLauncherController::HasItemController(ash::LauncherID id) const { return id_to_item_controller_map_.find(id) != id_to_item_controller_map_.end(); } std::vector<content::WebContents*> -ChromeLauncherControllerPerApp::GetV1ApplicationsFromController( +ChromeLauncherController::GetV1ApplicationsFromController( LauncherItemController* controller) { DCHECK(controller->type() == LauncherItemController::TYPE_SHORTCUT); AppShortcutLauncherItemController* app_controller = @@ -1579,7 +1560,7 @@ ChromeLauncherControllerPerApp::GetV1ApplicationsFromController( return app_controller->GetRunningApplications(); } -bool ChromeLauncherControllerPerApp::IsBrowserRepresentedInBrowserList( +bool ChromeLauncherController::IsBrowserRepresentedInBrowserList( Browser* browser) { return (browser && (browser->is_type_tabbed() || @@ -1590,7 +1571,7 @@ bool ChromeLauncherControllerPerApp::IsBrowserRepresentedInBrowserList( } LauncherItemController* -ChromeLauncherControllerPerApp::GetBrowserShortcutLauncherItemController() { +ChromeLauncherController::GetBrowserShortcutLauncherItemController() { for (IDToItemControllerMap::iterator i = id_to_item_controller_map_.begin(); i != id_to_item_controller_map_.end(); ++i) { int index = model_->ItemIndexByID(i->first); @@ -1605,8 +1586,7 @@ ChromeLauncherControllerPerApp::GetBrowserShortcutLauncherItemController() { return id_to_item_controller_map_[id]; } -ash::LauncherID -ChromeLauncherControllerPerApp::CreateBrowserShortcutLauncherItem() { +ash::LauncherID ChromeLauncherController::CreateBrowserShortcutLauncherItem() { ash::LauncherItem browser_shortcut; browser_shortcut.type = ash::TYPE_BROWSER_SHORTCUT; browser_shortcut.is_incognito = false; @@ -1622,11 +1602,11 @@ ChromeLauncherControllerPerApp::CreateBrowserShortcutLauncherItem() { return id; } -void ChromeLauncherControllerPerApp::PersistChromeItemIndex(int index) { +void ChromeLauncherController::PersistChromeItemIndex(int index) { profile_->GetPrefs()->SetInteger(prefs::kShelfChromeIconIndex, index); } -int ChromeLauncherControllerPerApp::GetChromeIconIndexFromPref() const { +int ChromeLauncherController::GetChromeIconIndexFromPref() const { size_t index = profile_->GetPrefs()->GetInteger(prefs::kShelfChromeIconIndex); const base::ListValue* pinned_apps_pref = profile_->GetPrefs()->GetList(prefs::kPinnedLauncherApps); @@ -1637,14 +1617,14 @@ int ChromeLauncherControllerPerApp::GetChromeIconIndexFromPref() const { std::min(pinned_apps_pref->GetSize(), index)); } -bool ChromeLauncherControllerPerApp::IsIncognito( +bool ChromeLauncherController::IsIncognito( content::WebContents* web_contents) const { const Profile* profile = Profile::FromBrowserContext(web_contents->GetBrowserContext()); return profile->IsOffTheRecord() && !profile->IsGuestSession(); } -void ChromeLauncherControllerPerApp::CloseWindowedAppsFromRemovedExtension( +void ChromeLauncherController::CloseWindowedAppsFromRemovedExtension( const std::string& app_id) { // This function cannot rely on the controller's enumeration functionality // since the extension has already be unloaded. @@ -1671,7 +1651,7 @@ void ChromeLauncherControllerPerApp::CloseWindowedAppsFromRemovedExtension( } void -ChromeLauncherControllerPerApp::MoveItemWithoutPinnedStateChangeNotification( +ChromeLauncherController::MoveItemWithoutPinnedStateChangeNotification( int source_index, int target_index) { base::AutoReset<bool> auto_reset(&ignore_persist_pinned_state_change_, true); model_->Move(source_index, target_index); diff --git a/chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app.h b/chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app.h index 951589c..7f4cc73 100644 --- a/chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app.h +++ b/chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_PER_APP_H_ -#define CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_PER_APP_H_ +#ifndef CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_H_ +#define CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_H_ #include <list> #include <map> @@ -12,6 +12,7 @@ #include <vector> #include "ash/display/display_controller.h" +#include "ash/launcher/launcher_delegate.h" #include "ash/launcher/launcher_model_observer.h" #include "ash/launcher/launcher_types.h" #include "ash/shelf/shelf_layout_manager_observer.h" @@ -22,25 +23,24 @@ #include "base/memory/scoped_ptr.h" #include "base/memory/scoped_vector.h" #include "base/prefs/pref_change_registrar.h" +#include "chrome/browser/extensions/app_icon_loader.h" #include "chrome/browser/extensions/extension_prefs.h" #include "chrome/browser/prefs/pref_service_syncable_observer.h" #include "chrome/browser/ui/ash/app_sync_ui_state_observer.h" #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h" -#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" -#include "chrome/browser/ui/ash/launcher/shell_window_launcher_controller.h" #include "chrome/browser/ui/browser_list_observer.h" #include "chrome/browser/ui/extensions/extension_enable_flow_delegate.h" #include "content/public/browser/notification_observer.h" -#include "content/public/browser/notification_registrar.h" #include "ui/aura/window_observer.h" class AppSyncUIState; class Browser; -class BrowserLauncherItemControllerTest; class BrowserShortcutLauncherItemController; class ExtensionEnableFlow; +class GURL; class LauncherItemController; class Profile; +class ShellWindowLauncherController; class TabContents; namespace ash { @@ -52,6 +52,7 @@ class Window; } namespace content { +class NotificationRegistrar; class WebContents; } @@ -59,208 +60,211 @@ namespace ui { class BaseWindow; } -// ChromeLauncherControllerPerApp manages the launcher items needed for content -// content windows. Launcher items have a type, an optional app id, and a -// controller. This incarnation groups running tabs/windows in application -// specific lists. -// * Tabbed browsers and browser app windows have BrowserLauncherItemController, -// owned by the BrowserView instance. +// A list of the elements which makes up a simple menu description. +typedef ScopedVector<ChromeLauncherAppMenuItem> ChromeLauncherAppMenuItems; + +// ChromeLauncherController manages the launcher items needed for content +// windows. Launcher items have a type, an optional app id, and a controller. +// This incarnation groups running tabs/windows in application specific lists. +// * Browser app windows have BrowserLauncherItemController, owned by the +// BrowserView instance. // * App shell windows have ShellWindowLauncherItemController, owned by // ShellWindowLauncherController. // * Shortcuts have no LauncherItemController. -class ChromeLauncherControllerPerApp - : public ash::LauncherModelObserver, - public ash::ShellObserver, - public ash::DisplayController::Observer, - public ChromeLauncherController, - public content::NotificationObserver, - public PrefServiceSyncableObserver, - public AppSyncUIStateObserver, - public ExtensionEnableFlowDelegate, - public chrome::BrowserListObserver, - public ash::ShelfLayoutManagerObserver { +class ChromeLauncherController : public ash::LauncherDelegate, + public ash::LauncherModelObserver, + public ash::ShellObserver, + public ash::DisplayController::Observer, + public content::NotificationObserver, + public extensions::AppIconLoader::Delegate, + public PrefServiceSyncableObserver, + public AppSyncUIStateObserver, + public ExtensionEnableFlowDelegate, + public chrome::BrowserListObserver, + public ash::ShelfLayoutManagerObserver { public: - ChromeLauncherControllerPerApp(Profile* profile, ash::LauncherModel* model); - virtual ~ChromeLauncherControllerPerApp(); - - // ChromeLauncherController overrides: - - // Initializes this ChromeLauncherControllerPerApp. - virtual void Init() OVERRIDE; - - // Returns the new per application interface of the given launcher. If it is - // a per browser (old) controller, it will return NULL; - // TODO(skuhne): Remove when we rip out the old launcher. - virtual ChromeLauncherControllerPerApp* GetPerAppInterface() OVERRIDE; - - // Creates a new tabbed item on the launcher for |controller|. - virtual ash::LauncherID CreateTabbedLauncherItem( - LauncherItemController* controller, - IncognitoState is_incognito, - ash::LauncherItemStatus status) OVERRIDE; + // Indicates if a launcher item is incognito or not. + enum IncognitoState { + STATE_INCOGNITO, + STATE_NOT_INCOGNITO, + }; + + // Used to update the state of non plaform apps, as web contents change. + enum AppState { + APP_STATE_ACTIVE, + APP_STATE_WINDOW_ACTIVE, + APP_STATE_INACTIVE, + APP_STATE_REMOVED + }; + + // Mockable interface to get app ids from tabs. + class AppTabHelper { + public: + virtual ~AppTabHelper() {} + + // Returns the app id of the specified tab, or an empty string if there is + // no app. + virtual std::string GetAppID(content::WebContents* tab) = 0; + + // Returns true if |id| is valid. Used during restore to ignore no longer + // valid extensions. + virtual bool IsValidID(const std::string& id) = 0; + }; + + ChromeLauncherController(Profile* profile, ash::LauncherModel* model); + virtual ~ChromeLauncherController(); + + // Initializes this ChromeLauncherController. + void Init(); + + // Creates an instance. + static ChromeLauncherController* CreateInstance(Profile* profile, + ash::LauncherModel* model); + + // Returns the single ChromeLauncherController instance. + static ChromeLauncherController* instance() { return instance_; } // Creates a new app item on the launcher for |controller|. - virtual ash::LauncherID CreateAppLauncherItem( - LauncherItemController* controller, - const std::string& app_id, - ash::LauncherItemStatus status) OVERRIDE; + ash::LauncherID CreateAppLauncherItem(LauncherItemController* controller, + const std::string& app_id, + ash::LauncherItemStatus status); // Updates the running status of an item. It will also update the status of // browsers launcher item if needed. - virtual void SetItemStatus(ash::LauncherID id, - ash::LauncherItemStatus status) OVERRIDE; + void SetItemStatus(ash::LauncherID id, ash::LauncherItemStatus status); // Updates the controller associated with id (which should be a shortcut). // |controller| remains owned by caller. - virtual void SetItemController(ash::LauncherID id, - LauncherItemController* controller) OVERRIDE; + void SetItemController(ash::LauncherID id, + LauncherItemController* controller); // Closes or unpins the launcher item. - virtual void CloseLauncherItem(ash::LauncherID id) OVERRIDE; + void CloseLauncherItem(ash::LauncherID id); // Pins the specified id. Currently only supports platform apps. - virtual void Pin(ash::LauncherID id) OVERRIDE; + void Pin(ash::LauncherID id); // Unpins the specified id, closing if not running. - virtual void Unpin(ash::LauncherID id) OVERRIDE; + void Unpin(ash::LauncherID id); // Returns true if the item identified by |id| is pinned. - virtual bool IsPinned(ash::LauncherID id) OVERRIDE; + bool IsPinned(ash::LauncherID id); // Pins/unpins the specified id. - virtual void TogglePinned(ash::LauncherID id) OVERRIDE; + void TogglePinned(ash::LauncherID id); // Returns true if the specified item can be pinned or unpinned. Only apps can // be pinned. - virtual bool IsPinnable(ash::LauncherID id) const OVERRIDE; + bool IsPinnable(ash::LauncherID id) const; // If there is no launcher item in the launcher for application |app_id|, one // gets created. The (existing or created) launcher items get then locked // against a users un-pinning removal. - virtual void LockV1AppWithID(const std::string& app_id) OVERRIDE; + void LockV1AppWithID(const std::string& app_id); // A previously locked launcher item of type |app_id| gets unlocked. If the // lock count reaches 0 and the item is not pinned it will go away. - virtual void UnlockV1AppWithID(const std::string& app_id) OVERRIDE; + void UnlockV1AppWithID(const std::string& app_id); // Requests that the launcher item controller specified by |id| open a new // instance of the app. |event_flags| holds the flags of the event which // triggered this command. - virtual void Launch(ash::LauncherID id, int event_flags) OVERRIDE; + void Launch(ash::LauncherID id, int event_flags); // Closes the specified item. - virtual void Close(ash::LauncherID id) OVERRIDE; + void Close(ash::LauncherID id); // Returns true if the specified item is open. - virtual bool IsOpen(ash::LauncherID id) OVERRIDE; + bool IsOpen(ash::LauncherID id); // Returns true if the specified item is for a platform app. - virtual bool IsPlatformApp(ash::LauncherID id) OVERRIDE; + bool IsPlatformApp(ash::LauncherID id); // Opens a new instance of the application identified by |app_id|. // Used by the app-list, and by pinned-app launcher items. - virtual void LaunchApp(const std::string& app_id, int event_flags) OVERRIDE; + void LaunchApp(const std::string& app_id, int event_flags); // If |app_id| is running, reactivates the app's most recently active window, // otherwise launches and activates the app. // Used by the app-list, and by pinned-app launcher items. - virtual void ActivateApp(const std::string& app_id, int event_flags) OVERRIDE; + void ActivateApp(const std::string& app_id, int event_flags); // Returns the launch type of app for the specified id. - virtual extensions::ExtensionPrefs::LaunchType GetLaunchType( - ash::LauncherID id) OVERRIDE; + extensions::ExtensionPrefs::LaunchType GetLaunchType(ash::LauncherID id); // Returns the id of the app for the specified tab. - virtual std::string GetAppID(content::WebContents* tab) OVERRIDE; + std::string GetAppID(content::WebContents* tab); - // Returns the |LauncherModel|'s ID or 0 if the AppId was not found. - virtual ash::LauncherID GetLauncherIDForAppID( - const std::string& app_id) OVERRIDE; - virtual std::string GetAppIDForLauncherID(ash::LauncherID id) OVERRIDE; + std::string GetAppIDForLauncherID(ash::LauncherID id); // Set the image for a specific launcher item (e.g. when set by the app). - virtual void SetLauncherItemImage(ash::LauncherID launcher_id, - const gfx::ImageSkia& image) OVERRIDE; - - // Returns true if a pinned launcher item with given |app_id| could be found. - virtual bool IsAppPinned(const std::string& app_id) OVERRIDE; + void SetLauncherItemImage(ash::LauncherID launcher_id, + const gfx::ImageSkia& image); // Find out if the given application |id| is a windowed app item and not a // pinned item in the launcher. bool IsWindowedAppInLauncher(const std::string& app_id); - // Pins an app with |app_id| to launcher. If there is a running instance in - // launcher, the running instance is pinned. If there is no running instance, - // a new launcher item is created and pinned. - virtual void PinAppWithID(const std::string& app_id) OVERRIDE; - // Updates the launche type of the app for the specified id to |launch_type|. - virtual void SetLaunchType( - ash::LauncherID id, - extensions::ExtensionPrefs::LaunchType launch_type) OVERRIDE; - - // Unpins any app items whose id is |app_id|. - virtual void UnpinAppsWithID(const std::string& app_id) OVERRIDE; + void SetLaunchType(ash::LauncherID id, + extensions::ExtensionPrefs::LaunchType launch_type); // Returns true if the user is currently logged in as a guest. - virtual bool IsLoggedInAsGuest() OVERRIDE; + // Makes virtual for unittest in LauncherContextMenuTest. + virtual bool IsLoggedInAsGuest(); // Invoked when user clicks on button in the launcher and there is no last // used window (or CTRL is held with the click). - virtual void CreateNewWindow() OVERRIDE; + void CreateNewWindow(); // Invoked when the user clicks on button in the launcher to create a new // incognito window. - virtual void CreateNewIncognitoWindow() OVERRIDE; + void CreateNewIncognitoWindow(); // Checks whether the user is allowed to pin apps. Pinning may be disallowed // by policy in case there is a pre-defined set of pinned apps. - virtual bool CanPin() const OVERRIDE; + bool CanPin() const; // Updates the pinned pref state. The pinned state consists of a list pref. // Each item of the list is a dictionary. The key |kAppIDPath| gives the // id of the app. - virtual void PersistPinnedState() OVERRIDE; + void PersistPinnedState(); - virtual ash::LauncherModel* model() OVERRIDE; + ash::LauncherModel* model(); - virtual Profile* profile() OVERRIDE; + Profile* profile(); // Gets the shelf auto-hide behavior on |root_window|. - virtual ash::ShelfAutoHideBehavior GetShelfAutoHideBehavior( - aura::RootWindow* root_window) const OVERRIDE; + ash::ShelfAutoHideBehavior GetShelfAutoHideBehavior( + aura::RootWindow* root_window) const; // Returns |true| if the user is allowed to modify the shelf auto-hide // behavior on |root_window|. - virtual bool CanUserModifyShelfAutoHideBehavior( - aura::RootWindow* root_window) const OVERRIDE; + bool CanUserModifyShelfAutoHideBehavior(aura::RootWindow* root_window) const; // Toggles the shelf auto-hide behavior on |root_window|. Does nothing if the // user is not allowed to modify the auto-hide behavior. - virtual void ToggleShelfAutoHideBehavior( - aura::RootWindow* root_window) OVERRIDE; + void ToggleShelfAutoHideBehavior(aura::RootWindow* root_window); // The tab no longer represents its previously identified application. - virtual void RemoveTabFromRunningApp(content::WebContents* tab, - const std::string& app_id) OVERRIDE; + void RemoveTabFromRunningApp(content::WebContents* tab, + const std::string& app_id); // Notify the controller that the state of an non platform app's tabs // have changed, - virtual void UpdateAppState(content::WebContents* contents, - AppState app_state) OVERRIDE; + void UpdateAppState(content::WebContents* contents, AppState app_state); // Limits application refocusing to urls that match |url| for |id|. - virtual void SetRefocusURLPatternForTest(ash::LauncherID id, - const GURL& url) OVERRIDE; + void SetRefocusURLPatternForTest(ash::LauncherID id, const GURL& url); // Returns the extension identified by |app_id|. - virtual const extensions::Extension* GetExtensionForAppID( - const std::string& app_id) const OVERRIDE; + const extensions::Extension* GetExtensionForAppID( + const std::string& app_id) const; // Activates a |window|. If |allow_minimize| is true and the system allows // it, the the window will get minimized instead. - virtual void ActivateWindowOrMinimizeIfActive(ui::BaseWindow* window, - bool allow_minimize) OVERRIDE; + void ActivateWindowOrMinimizeIfActive(ui::BaseWindow* window, + bool allow_minimize); // ash::LauncherDelegate overrides: virtual void ItemSelected(const ash::LauncherItem& item, @@ -276,6 +280,11 @@ class ChromeLauncherControllerPerApp virtual bool ShouldShowTooltip(const ash::LauncherItem& item) OVERRIDE; virtual void OnLauncherCreated(ash::Launcher* launcher) OVERRIDE; virtual void OnLauncherDestroyed(ash::Launcher* launcher) OVERRIDE; + virtual ash::LauncherID GetLauncherIDForAppID( + const std::string& app_id) OVERRIDE; + virtual void PinAppWithID(const std::string& app_id) OVERRIDE; + virtual bool IsAppPinned(const std::string& app_id) OVERRIDE; + virtual void UnpinAppsWithID(const std::string& app_id) OVERRIDE; // ash::LauncherModelObserver overrides: virtual void LauncherItemAdded(int index) OVERRIDE; @@ -358,36 +367,21 @@ class ChromeLauncherControllerPerApp LauncherItemController* GetBrowserShortcutLauncherItemController(); protected: - // ChromeLauncherController overrides: - // Creates a new app shortcut item and controller on the launcher at |index|. // Use kInsertItemAtEnd to add a shortcut as the last item. - virtual ash::LauncherID CreateAppShortcutLauncherItem( - const std::string& app_id, - int index) OVERRIDE; + ash::LauncherID CreateAppShortcutLauncherItem(const std::string& app_id, + int index); // Sets the AppTabHelper/AppIconLoader, taking ownership of the helper class. // These are intended for testing. - virtual void SetAppTabHelperForTest(AppTabHelper* helper) OVERRIDE; - virtual void SetAppIconLoaderForTest( - extensions::AppIconLoader* loader) OVERRIDE; - virtual const std::string& GetAppIdFromLauncherIdForTest( - ash::LauncherID id) OVERRIDE; + void SetAppTabHelperForTest(AppTabHelper* helper); + void SetAppIconLoaderForTest(extensions::AppIconLoader* loader); + const std::string& GetAppIdFromLauncherIdForTest(ash::LauncherID id); private: - friend class ChromeLauncherControllerPerAppTest; - friend class LauncherPerAppAppBrowserTest; - friend class LauncherPlatformPerAppAppBrowserTest; - - // Creates a new app shortcut item and controller on the launcher at |index|. - // Use kInsertItemAtEnd to add a shortcut as the last item. - virtual ash::LauncherID CreateAppShortcutLauncherItemWithType( - const std::string& app_id, - int index, - ash::LauncherItemType launcher_item_type); - - // Updates the activation state of the Broswer item. - void UpdateBrowserItemStatus(); + friend class ChromeLauncherControllerTest; + friend class LauncherAppBrowserTest; + friend class LauncherPlatformAppBrowserTest; typedef std::map<ash::LauncherID, LauncherItemController*> IDToItemControllerMap; @@ -395,6 +389,16 @@ class ChromeLauncherControllerPerApp typedef std::map<std::string, WebContentsList> AppIDToWebContentsListMap; typedef std::map<content::WebContents*, std::string> WebContentsToAppIDMap; + // Creates a new app shortcut item and controller on the launcher at |index|. + // Use kInsertItemAtEnd to add a shortcut as the last item. + ash::LauncherID CreateAppShortcutLauncherItemWithType( + const std::string& app_id, + int index, + ash::LauncherItemType launcher_item_type); + + // Updates the activation state of the Broswer item. + void UpdateBrowserItemStatus(); + // Returns the profile used for new windows. Profile* GetProfileForNewWindows(); @@ -462,6 +466,8 @@ class ChromeLauncherControllerPerApp void MoveItemWithoutPinnedStateChangeNotification(int source_index, int target_index); + static ChromeLauncherController* instance_; + ash::LauncherModel* model_; // Profile used for prefs and loading extensions. This is NOT necessarily the @@ -502,7 +508,7 @@ class ChromeLauncherControllerPerApp // If true, incoming pinned state changes should be ignored. bool ignore_persist_pinned_state_change_; - DISALLOW_COPY_AND_ASSIGN(ChromeLauncherControllerPerApp); + DISALLOW_COPY_AND_ASSIGN(ChromeLauncherController); }; -#endif // CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_PER_APP_H_ +#endif // CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_H_ diff --git a/chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app_browsertest.cc b/chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app_browsertest.cc index 23b41f7..5c70b384 100644 --- a/chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app_browsertest.cc +++ b/chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app_browsertest.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" +#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app.h" #include "apps/native_app_window.h" #include "apps/shell_window.h" @@ -17,6 +17,7 @@ #include "ash/test/launcher_view_test_api.h" #include "ash/test/shell_test_api.h" #include "ash/wm/window_util.h" +#include "base/strings/stringprintf.h" #include "base/strings/utf_string_conversions.h" #include "chrome/browser/apps/app_browsertest_util.h" #include "chrome/browser/automation/automation_util.h" @@ -30,7 +31,6 @@ #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/app_list/app_list_service.h" #include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controller.h" -#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app.h" #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_commands.h" @@ -49,6 +49,7 @@ #include "extensions/common/switches.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/app_list/views/apps_grid_view.h" +#include "ui/aura/client/aura_constants.h" #include "ui/aura/test/event_generator.h" #include "ui/aura/window.h" #include "ui/base/events/event.h" @@ -104,22 +105,17 @@ class TestShellWindowRegistryObserver } // namespace -// TODO(skuhne): Change name back to LauncherPlatformAppBrowserTest when the -// old launcher gets ripped out. -class LauncherPlatformPerAppAppBrowserTest +class LauncherPlatformAppBrowserTest : public extensions::PlatformAppBrowserTest { protected: - LauncherPlatformPerAppAppBrowserTest() - : launcher_(NULL), - controller_(NULL) { + LauncherPlatformAppBrowserTest() : launcher_(NULL), controller_(NULL) { } - virtual ~LauncherPlatformPerAppAppBrowserTest() {} + virtual ~LauncherPlatformAppBrowserTest() {} virtual void RunTestOnMainThreadLoop() OVERRIDE { launcher_ = ash::Launcher::ForPrimaryDisplay(); - controller_ = - static_cast<ChromeLauncherControllerPerApp*>(launcher_->delegate()); + controller_ = ChromeLauncherController::instance(); return extensions::PlatformAppBrowserTest::RunTestOnMainThreadLoop(); } @@ -167,36 +163,31 @@ class LauncherPlatformPerAppAppBrowserTest } ash::Launcher* launcher_; - ChromeLauncherControllerPerApp* controller_; + ChromeLauncherController* controller_; private: - DISALLOW_COPY_AND_ASSIGN(LauncherPlatformPerAppAppBrowserTest); + DISALLOW_COPY_AND_ASSIGN(LauncherPlatformAppBrowserTest); }; -// TODO(skuhne): Change name back to LauncherAppBrowserTest when the -// old launcher gets ripped out. -class LauncherPerAppAppBrowserTest : public ExtensionBrowserTest { +class LauncherAppBrowserTest : public ExtensionBrowserTest { protected: - LauncherPerAppAppBrowserTest() - : launcher_(NULL), - model_(NULL) { + LauncherAppBrowserTest() : launcher_(NULL), model_(NULL), controller_(NULL) { } - virtual ~LauncherPerAppAppBrowserTest() {} + virtual ~LauncherAppBrowserTest() {} virtual void RunTestOnMainThreadLoop() OVERRIDE { launcher_ = ash::Launcher::ForPrimaryDisplay(); model_ = ash::test::ShellTestApi(ash::Shell::GetInstance()).launcher_model(); + controller_ = ChromeLauncherController::instance(); return ExtensionBrowserTest::RunTestOnMainThreadLoop(); } size_t NumberOfDetectedLauncherBrowsers(bool show_all_tabs) { - ChromeLauncherControllerPerApp* controller = - static_cast<ChromeLauncherControllerPerApp*>(launcher_->delegate()); LauncherItemController* item_controller = - controller->GetBrowserShortcutLauncherItemController(); + controller_->GetBrowserShortcutLauncherItemController(); int items = item_controller->GetApplicationList( show_all_tabs ? ui::EF_SHIFT_DOWN : 0).size(); // If we have at least one item, we have also a title which we remove here. @@ -233,13 +224,11 @@ class LauncherPerAppAppBrowserTest : public ExtensionBrowserTest { const std::string app_id = extension->id(); // Then create a shortcut. - ChromeLauncherController* controller = - static_cast<ChromeLauncherController*>(launcher_->delegate()); int item_count = model_->item_count(); - ash::LauncherID shortcut_id = controller->CreateAppShortcutLauncherItem( + ash::LauncherID shortcut_id = controller_->CreateAppShortcutLauncherItem( app_id, item_count); - controller->PersistPinnedState(); + controller_->PersistPinnedState(); EXPECT_EQ(++item_count, model_->item_count()); const ash::LauncherItem& item = *model_->ItemByID(shortcut_id); EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item.type); @@ -251,56 +240,58 @@ class LauncherPerAppAppBrowserTest : public ExtensionBrowserTest { launcher_->ActivateLauncherItem(id); } + ash::LauncherID PinFakeApp(const std::string& name) { + return controller_->CreateAppShortcutLauncherItem( + name, model_->item_count()); + } + ash::Launcher* launcher_; ash::LauncherModel* model_; + ChromeLauncherController* controller_; private: - DISALLOW_COPY_AND_ASSIGN(LauncherPerAppAppBrowserTest); + DISALLOW_COPY_AND_ASSIGN(LauncherAppBrowserTest); }; -// TODO(skuhne): Change name to LauncherAppBrowserTestNoBrowser when the -// old launcher gets ripped out. -class LauncherPerAppAppBrowserTestNoDefaultBrowser - : public LauncherPerAppAppBrowserTest { +class LauncherAppBrowserTestNoDefaultBrowser : public LauncherAppBrowserTest { protected: - LauncherPerAppAppBrowserTestNoDefaultBrowser() {} - virtual ~LauncherPerAppAppBrowserTestNoDefaultBrowser() {} + LauncherAppBrowserTestNoDefaultBrowser() {} + virtual ~LauncherAppBrowserTestNoDefaultBrowser() {} virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { - LauncherPerAppAppBrowserTest::SetUpCommandLine(command_line); + LauncherAppBrowserTest::SetUpCommandLine(command_line); command_line->AppendSwitch(switches::kNoStartupWindow); } private: - DISALLOW_COPY_AND_ASSIGN(LauncherPerAppAppBrowserTestNoDefaultBrowser); + DISALLOW_COPY_AND_ASSIGN(LauncherAppBrowserTestNoDefaultBrowser); }; // Since the default for minimizing on click might change, I added both classes // to either get the minimize on click or not. -class LauncherPerAppAppBrowserNoMinimizeOnClick - : public LauncherPlatformPerAppAppBrowserTest { +class LauncherAppBrowserNoMinimizeOnClick + : public LauncherPlatformAppBrowserTest { protected: - LauncherPerAppAppBrowserNoMinimizeOnClick() {} - virtual ~LauncherPerAppAppBrowserNoMinimizeOnClick() {} + LauncherAppBrowserNoMinimizeOnClick() {} + virtual ~LauncherAppBrowserNoMinimizeOnClick() {} virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { - LauncherPlatformPerAppAppBrowserTest::SetUpCommandLine(command_line); + LauncherPlatformAppBrowserTest::SetUpCommandLine(command_line); command_line->AppendSwitch( switches::kDisableMinimizeOnSecondLauncherItemClick); } private: - DISALLOW_COPY_AND_ASSIGN(LauncherPerAppAppBrowserNoMinimizeOnClick); + DISALLOW_COPY_AND_ASSIGN(LauncherAppBrowserNoMinimizeOnClick); }; -typedef LauncherPlatformPerAppAppBrowserTest - LauncherPerAppAppBrowserMinimizeOnClick; +typedef LauncherPlatformAppBrowserTest LauncherAppBrowserMinimizeOnClick; // Test that we can launch a platform app and get a running item. -IN_PROC_BROWSER_TEST_F(LauncherPlatformPerAppAppBrowserTest, LaunchUnpinned) { +IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, LaunchUnpinned) { int item_count = launcher_model()->item_count(); const Extension* extension = LoadAndLaunchPlatformApp("launch"); ShellWindow* window = CreateShellWindow(extension); @@ -315,7 +306,7 @@ IN_PROC_BROWSER_TEST_F(LauncherPlatformPerAppAppBrowserTest, LaunchUnpinned) { } // Test that we can launch a platform app that already has a shortcut. -IN_PROC_BROWSER_TEST_F(LauncherPlatformPerAppAppBrowserTest, LaunchPinned) { +IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, LaunchPinned) { int item_count = launcher_model()->item_count(); // First get app_id. @@ -346,7 +337,7 @@ IN_PROC_BROWSER_TEST_F(LauncherPlatformPerAppAppBrowserTest, LaunchPinned) { EXPECT_EQ(ash::STATUS_CLOSED, item.status); } -IN_PROC_BROWSER_TEST_F(LauncherPlatformPerAppAppBrowserTest, PinRunning) { +IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, PinRunning) { // Run. int item_count = launcher_model()->item_count(); const Extension* extension = LoadAndLaunchPlatformApp("launch"); @@ -384,7 +375,7 @@ IN_PROC_BROWSER_TEST_F(LauncherPlatformPerAppAppBrowserTest, PinRunning) { ASSERT_EQ(item_count, launcher_model()->item_count()); } -IN_PROC_BROWSER_TEST_F(LauncherPlatformPerAppAppBrowserTest, UnpinRunning) { +IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, UnpinRunning) { int item_count = launcher_model()->item_count(); // First get app_id. @@ -432,7 +423,7 @@ IN_PROC_BROWSER_TEST_F(LauncherPlatformPerAppAppBrowserTest, UnpinRunning) { } // Test that we can launch a platform app with more than one window. -IN_PROC_BROWSER_TEST_F(LauncherPlatformPerAppAppBrowserTest, MultipleWindows) { +IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, MultipleWindows) { int item_count = launcher_model()->item_count(); // First run app. @@ -440,11 +431,11 @@ IN_PROC_BROWSER_TEST_F(LauncherPlatformPerAppAppBrowserTest, MultipleWindows) { ShellWindow* window1 = CreateShellWindow(extension); ++item_count; ASSERT_EQ(item_count, launcher_model()->item_count()); - const ash::LauncherItem& item = GetLastLauncherItem(); - ash::LauncherID item_id = item.id; - EXPECT_EQ(ash::TYPE_PLATFORM_APP, item.type); - EXPECT_EQ(ash::STATUS_ACTIVE, item.status); - EXPECT_EQ(2, GetNumApplicationMenuItems(item)); // Title + 1 window + const ash::LauncherItem& item1 = GetLastLauncherItem(); + ash::LauncherID item_id = item1.id; + EXPECT_EQ(ash::TYPE_PLATFORM_APP, item1.type); + EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); + EXPECT_EQ(2, GetNumApplicationMenuItems(item1)); // Title + 1 window // Add second window. ShellWindow* window2 = CreateShellWindow(extension); @@ -469,7 +460,7 @@ IN_PROC_BROWSER_TEST_F(LauncherPlatformPerAppAppBrowserTest, MultipleWindows) { ASSERT_EQ(item_count, launcher_model()->item_count()); } -IN_PROC_BROWSER_TEST_F(LauncherPlatformPerAppAppBrowserTest, MultipleApps) { +IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, MultipleApps) { int item_count = launcher_model()->item_count(); // First run app. @@ -508,12 +499,11 @@ IN_PROC_BROWSER_TEST_F(LauncherPlatformPerAppAppBrowserTest, MultipleApps) { CloseShellWindow(window1); --item_count; ASSERT_EQ(item_count, launcher_model()->item_count()); - } // Confirm that app windows can be reactivated by clicking their icons and that // the correct activation order is maintained. -IN_PROC_BROWSER_TEST_F(LauncherPlatformPerAppAppBrowserTest, WindowActivation) { +IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, WindowActivation) { int item_count = launcher_model()->item_count(); // First run app. @@ -597,7 +587,7 @@ IN_PROC_BROWSER_TEST_F(LauncherPlatformPerAppAppBrowserTest, WindowActivation) { } // Confirm that Click behavior for app windows is correnct. -IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserNoMinimizeOnClick, +IN_PROC_BROWSER_TEST_F(LauncherAppBrowserNoMinimizeOnClick, AppClickBehavior) { // Launch a platform app and create a window for it. const Extension* extension1 = LoadAndLaunchPlatformApp("launch"); @@ -635,7 +625,7 @@ IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserNoMinimizeOnClick, } // Confirm the minimizing click behavior for apps. -IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserMinimizeOnClick, +IN_PROC_BROWSER_TEST_F(LauncherAppBrowserMinimizeOnClick, PackagedAppClickBehaviorInMinimizeMode) { // Launch one platform app and create a window for it. const Extension* extension1 = LoadAndLaunchPlatformApp("launch"); @@ -693,8 +683,7 @@ IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserMinimizeOnClick, } // Confirm that click behavior for app panels is correct. -IN_PROC_BROWSER_TEST_F(LauncherPlatformPerAppAppBrowserTest, - AppPanelClickBehavior) { +IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, AppPanelClickBehavior) { // Enable experimental APIs to allow panel creation. CommandLine::ForCurrentProcess()->AppendSwitch( extensions::switches::kEnableExperimentalExtensionApis); @@ -729,8 +718,7 @@ IN_PROC_BROWSER_TEST_F(LauncherPlatformPerAppAppBrowserTest, EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); } -IN_PROC_BROWSER_TEST_F(LauncherPlatformPerAppAppBrowserTest, - BrowserActivation) { +IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, BrowserActivation) { int item_count = launcher_model()->item_count(); // First run app. @@ -749,7 +737,7 @@ IN_PROC_BROWSER_TEST_F(LauncherPlatformPerAppAppBrowserTest, } // Test that opening an app sets the correct icon -IN_PROC_BROWSER_TEST_F(LauncherPlatformPerAppAppBrowserTest, SetIcon) { +IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, SetIcon) { TestShellWindowRegistryObserver test_observer(browser()->profile()); // Enable experimental APIs to allow panel creation. @@ -794,7 +782,7 @@ IN_PROC_BROWSER_TEST_F(LauncherPlatformPerAppAppBrowserTest, SetIcon) { } // Test that we can launch an app with a shortcut. -IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, LaunchPinned) { +IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, LaunchPinned) { TabStripModel* tab_strip = browser()->tab_strip_model(); int tab_count = tab_strip->count(); ash::LauncherID shortcut_id = CreateShortcut("app1"); @@ -813,7 +801,7 @@ IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, LaunchPinned) { } // Launch the app first and then create the shortcut. -IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, LaunchUnpinned) { +IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, LaunchUnpinned) { TabStripModel* tab_strip = browser()->tab_strip_model(); int tab_count = tab_strip->count(); LoadAndLaunchExtension("app1", extension_misc::LAUNCH_TAB, @@ -833,7 +821,7 @@ IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, LaunchUnpinned) { // Launches an app in the background and then tries to open it. This is test for // a crash we had. -IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, LaunchInBackground) { +IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, LaunchInBackground) { TabStripModel* tab_strip = browser()->tab_strip_model(); int tab_count = tab_strip->count(); LoadAndLaunchExtension("app1", extension_misc::LAUNCH_TAB, @@ -844,7 +832,7 @@ IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, LaunchInBackground) { // Confirm that clicking a icon for an app running in one of 2 maxmized windows // activates the right window. -IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, LaunchMaximized) { +IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, LaunchMaximized) { aura::Window* window1 = browser()->window()->GetNativeWindow(); ash::wm::MaximizeWindow(window1); content::WindowedNotificationObserver open_observer( @@ -872,7 +860,7 @@ IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, LaunchMaximized) { } // Activating the same app multiple times should launch only a single copy. -IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, ActivateApp) { +IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, ActivateApp) { TabStripModel* tab_strip = browser()->tab_strip_model(); int tab_count = tab_strip->count(); const Extension* extension = @@ -885,7 +873,7 @@ IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, ActivateApp) { } // Launching the same app multiple times should launch a copy for each call. -IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, LaunchApp) { +IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, LaunchApp) { TabStripModel* tab_strip = browser()->tab_strip_model(); int tab_count = tab_strip->count(); const Extension* extension = @@ -898,7 +886,7 @@ IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, LaunchApp) { } // Launch 2 apps and toggle which is active. -IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, MultipleApps) { +IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, MultipleApps) { int item_count = model_->item_count(); TabStripModel* tab_strip = browser()->tab_strip_model(); int tab_count = tab_strip->count(); @@ -955,7 +943,7 @@ IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, MultipleApps) { // Confirm that a page can be navigated from and to while maintaining the // correct running state. -IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, Navigation) { +IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, Navigation) { ash::LauncherID shortcut_id = CreateShortcut("app1"); EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status); ActivateLauncherItem(model_->ItemIndexByID(shortcut_id)); @@ -972,7 +960,7 @@ IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, Navigation) { EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status); } -IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, MultipleOwnedTabs) { +IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, MultipleOwnedTabs) { TabStripModel* tab_strip = browser()->tab_strip_model(); int tab_count = tab_strip->count(); ash::LauncherID shortcut_id = CreateShortcut("app1"); @@ -1007,9 +995,7 @@ IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, MultipleOwnedTabs) { EXPECT_EQ(tab_strip->GetActiveWebContents(), first_tab); } -IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, RefocusFilter) { - ChromeLauncherController* controller = - static_cast<ChromeLauncherController*>(launcher_->delegate()); +IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, RefocusFilter) { TabStripModel* tab_strip = browser()->tab_strip_model(); int tab_count = tab_strip->count(); ash::LauncherID shortcut_id = CreateShortcut("app1"); @@ -1018,7 +1004,7 @@ IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, RefocusFilter) { EXPECT_EQ(ash::STATUS_ACTIVE, model_->ItemByID(shortcut_id)->status); WebContents* first_tab = tab_strip->GetActiveWebContents(); - controller->SetRefocusURLPatternForTest( + controller_->SetRefocusURLPatternForTest( shortcut_id, GURL("http://www.example.com/path1/*")); // Create new tab owned by app. ui_test_utils::NavigateToURLWithDisposition( @@ -1047,13 +1033,11 @@ IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, RefocusFilter) { EXPECT_EQ(tab_strip->GetActiveWebContents(), first_tab); } -IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, RefocusFilterLaunch) { - ChromeLauncherController* controller = - static_cast<ChromeLauncherController*>(launcher_->delegate()); +IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, RefocusFilterLaunch) { TabStripModel* tab_strip = browser()->tab_strip_model(); int tab_count = tab_strip->count(); ash::LauncherID shortcut_id = CreateShortcut("app1"); - controller->SetRefocusURLPatternForTest( + controller_->SetRefocusURLPatternForTest( shortcut_id, GURL("http://www.example.com/path1/*")); // Create new tab. @@ -1078,19 +1062,17 @@ IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, RefocusFilterLaunch) { } // Check the launcher activation state for applications and browser. -IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, ActivationStateCheck) { - ChromeLauncherController* controller = - static_cast<ChromeLauncherController*>(launcher_->delegate()); +IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, ActivationStateCheck) { TabStripModel* tab_strip = browser()->tab_strip_model(); // Get the browser item index - int browser_index = ash::launcher::GetBrowserItemIndex(*controller->model()); + int browser_index = ash::launcher::GetBrowserItemIndex(*controller_->model()); EXPECT_TRUE(browser_index >= 0); // Even though we are just comming up, the browser should be active. EXPECT_EQ(ash::STATUS_ACTIVE, model_->items()[browser_index].status); ash::LauncherID shortcut_id = CreateShortcut("app1"); - controller->SetRefocusURLPatternForTest( + controller_->SetRefocusURLPatternForTest( shortcut_id, GURL("http://www.example.com/path1/*")); EXPECT_EQ(ash::STATUS_CLOSED, model_->ItemByID(shortcut_id)->status); @@ -1123,14 +1105,11 @@ IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, ActivationStateCheck) { // Check that the launcher activation state for a V1 application stays closed // even after an asynchronous browser event comes in after the tab got // destroyed. -IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, - AsyncActivationStateCheck) { - ChromeLauncherController* controller = - static_cast<ChromeLauncherController*>(launcher_->delegate()); +IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, AsyncActivationStateCheck) { TabStripModel* tab_strip = browser()->tab_strip_model(); ash::LauncherID shortcut_id = CreateShortcut("app1"); - controller->SetRefocusURLPatternForTest( + controller_->SetRefocusURLPatternForTest( shortcut_id, GURL("http://www.example.com/path1/*")); EXPECT_EQ(ash::STATUS_CLOSED, model_->ItemByID(shortcut_id)->status); @@ -1155,7 +1134,7 @@ IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, } // Checks that a windowed application does not add an item to the browser list. -IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTestNoDefaultBrowser, +IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTestNoDefaultBrowser, WindowedAppDoesNotAddToBrowser) { // Get the number of items in the browser menu. size_t items = NumberOfDetectedLauncherBrowsers(false); @@ -1177,7 +1156,7 @@ IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTestNoDefaultBrowser, } // Checks the functionality to enumerate all browsers vs. all tabs. -IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTestNoDefaultBrowser, +IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTestNoDefaultBrowser, EnumerateALlBrowsersAndTabs) { // Create at least one browser. LoadAndLaunchExtension("app1", extension_misc::LAUNCH_TAB, NEW_WINDOW); @@ -1201,13 +1180,11 @@ IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTestNoDefaultBrowser, // Check that the keyboard activation of a launcher item tabs properly through // the items at hand. -IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, AltNumberTabsTabbing) { +IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, AltNumberTabsTabbing) { TabStripModel* tab_strip = browser()->tab_strip_model(); - ChromeLauncherController* controller = - static_cast<ChromeLauncherController*>(launcher_->delegate()); ash::LauncherID shortcut_id = CreateShortcut("app"); - controller->SetRefocusURLPatternForTest( + controller_->SetRefocusURLPatternForTest( shortcut_id, GURL("http://www.example.com/path/*")); std::string url = "http://www.example.com/path/bla"; @@ -1257,7 +1234,7 @@ IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, AltNumberTabsTabbing) { // Check that the keyboard activation of a launcher item tabs properly through // the items at hand. -IN_PROC_BROWSER_TEST_F(LauncherPlatformPerAppAppBrowserTest, +IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, AltNumberAppsTabbing) { // First run app. const Extension* extension1 = LoadAndLaunchPlatformApp("launch"); @@ -1290,8 +1267,60 @@ IN_PROC_BROWSER_TEST_F(LauncherPlatformPerAppAppBrowserTest, EXPECT_TRUE(window1a->IsActive()); } +// Test that we can launch a platform app panel and get a running item. +IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, + LaunchPanelWindow) { + int item_count = launcher_model()->item_count(); + const Extension* extension = LoadAndLaunchPlatformApp("launch"); + ShellWindow::CreateParams params; + params.window_type = ShellWindow::WINDOW_TYPE_PANEL; + params.focused = false; + ShellWindow* window = CreateShellWindowFromParams(extension, params); + ++item_count; + ASSERT_EQ(item_count, launcher_model()->item_count()); + const ash::LauncherItem& item = GetLastLauncherPanelItem(); + EXPECT_EQ(ash::TYPE_APP_PANEL, item.type); + // Opening a panel does not activate it. + EXPECT_EQ(ash::STATUS_RUNNING, item.status); + CloseShellWindow(window); + --item_count; + EXPECT_EQ(item_count, launcher_model()->item_count()); +} + +// Test attention states of windows. +IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, WindowAttentionStatus) { + const Extension* extension = LoadAndLaunchPlatformApp("launch"); + ShellWindow::CreateParams params; + params.window_type = ShellWindow::WINDOW_TYPE_PANEL; + params.focused = false; + ShellWindow* panel = CreateShellWindowFromParams(extension, params); + EXPECT_TRUE(panel->GetNativeWindow()->IsVisible()); + // Panels should not be active by default. + EXPECT_FALSE(panel->GetBaseWindow()->IsActive()); + // Confirm that a controller item was created and is the correct state. + const ash::LauncherItem& item = GetLastLauncherPanelItem(); + LauncherItemController* item_controller = GetItemController(item.id); + EXPECT_EQ(ash::TYPE_APP_PANEL, item.type); + EXPECT_EQ(ash::STATUS_RUNNING, item.status); + EXPECT_EQ(LauncherItemController::TYPE_APP_PANEL, item_controller->type()); + + // App windows should go to attention state. + panel->GetNativeWindow()->SetProperty(aura::client::kDrawAttentionKey, true); + EXPECT_EQ(ash::STATUS_ATTENTION, item.status); + + // Click the item and confirm that the panel is activated. + TestEvent click_event(ui::ET_MOUSE_PRESSED); + item_controller->Clicked(click_event); + EXPECT_TRUE(panel->GetBaseWindow()->IsActive()); + EXPECT_EQ(ash::STATUS_ACTIVE, item.status); + + // Active windows don't show attention. + panel->GetNativeWindow()->SetProperty(aura::client::kDrawAttentionKey, true); + EXPECT_EQ(ash::STATUS_ACTIVE, item.status); +} + // Checks that the browser Alt "tabbing" is properly done. -IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTestNoDefaultBrowser, +IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTestNoDefaultBrowser, AltNumberBrowserTabbing) { // Get the number of items in the browser menu. EXPECT_EQ(0u, chrome::GetTotalBrowserCount()); @@ -1347,13 +1376,10 @@ IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTestNoDefaultBrowser, // Checks that after a session restore, we do not start applications on an // activation. -IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, - ActivateAfterSessionRestore) { +IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, ActivateAfterSessionRestore) { EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); // Create a known application. - ChromeLauncherController* controller = - static_cast<ChromeLauncherController*>(launcher_->delegate()); ash::LauncherID shortcut_id = CreateShortcut("app1"); // Create a new browser - without activating it - and load an "app" into it. @@ -1361,7 +1387,7 @@ IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, Browser::CreateParams(profile(), chrome::GetActiveDesktop()); params.initial_show_state = ui::SHOW_STATE_INACTIVE; Browser* browser2 = new Browser(params); - controller->SetRefocusURLPatternForTest( + controller_->SetRefocusURLPatternForTest( shortcut_id, GURL("http://www.example.com/path/*")); std::string url = "http://www.example.com/path/bla"; ui_test_utils::NavigateToURLWithDisposition( @@ -1390,7 +1416,7 @@ IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, EXPECT_EQ(it, ash_browser_list->end_last_active()); // Now request to either activate an existing app or create a new one. - controller->ItemSelected(*model_->ItemByID(shortcut_id), + controller_->ItemSelected(*model_->ItemByID(shortcut_id), ui::KeyEvent(ui::ET_KEY_RELEASED, ui::VKEY_RETURN, 0, @@ -1407,7 +1433,7 @@ IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, // Do various drag and drop interaction tests between the application list and // the launcher. -IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, DragAndDrop) { +IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, DragAndDrop) { // Get a number of interfaces we need. aura::test::EventGenerator generator( ash::Shell::GetPrimaryRootWindow(), gfx::Point()); @@ -1512,7 +1538,7 @@ IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, DragAndDrop) { } // Check that clicking on an app launcher item launches a new browser. -IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, ClickItem) { +IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, ClickItem) { // Get a number of interfaces we need. aura::test::EventGenerator generator( ash::Shell::GetPrimaryRootWindow(), gfx::Point()); @@ -1548,12 +1574,10 @@ IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, ClickItem) { } // Check LauncherItemController of Browser Shortcut functionality. -IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTestNoDefaultBrowser, +IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTestNoDefaultBrowser, BrowserShortcutLauncherItemController) { - ChromeLauncherControllerPerApp* controller = - static_cast<ChromeLauncherControllerPerApp*>(launcher_->delegate()); LauncherItemController* item_controller = - controller->GetBrowserShortcutLauncherItemController(); + controller_->GetBrowserShortcutLauncherItemController(); // Get the number of browsers. size_t running_browser = chrome::GetTotalBrowserCount(); @@ -1582,11 +1606,7 @@ IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTestNoDefaultBrowser, } // Check that GetIDByWindow() returns |LauncherID| of the active tab. -IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, - MatchingLauncherIDandActiveTab) { - ChromeLauncherControllerPerApp* controller = - static_cast<ChromeLauncherControllerPerApp*>(launcher_->delegate()); - +IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, MatchingLauncherIDandActiveTab) { EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); EXPECT_EQ(1, browser()->tab_strip_model()->count()); EXPECT_EQ(0, browser()->tab_strip_model()->active_index()); @@ -1596,7 +1616,7 @@ IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, int browser_index = ash::launcher::GetBrowserItemIndex(*model_); ash::LauncherID browser_id = model_->items()[browser_index].id; - EXPECT_EQ(browser_id, controller->GetIDByWindow(window)); + EXPECT_EQ(browser_id, controller_->GetIDByWindow(window)); ash::LauncherID app_id = CreateShortcut("app1"); EXPECT_EQ(3, model_->item_count()); @@ -1606,11 +1626,40 @@ IN_PROC_BROWSER_TEST_F(LauncherPerAppAppBrowserTest, ActivateLauncherItem(model_->ItemIndexByID(app_id)); EXPECT_EQ(2, browser()->tab_strip_model()->count()); EXPECT_EQ(1, browser()->tab_strip_model()->active_index()); - EXPECT_EQ(app_id, controller->GetIDByWindow(window)); + EXPECT_EQ(app_id, controller_->GetIDByWindow(window)); // Makes tab at index 0(NTP) as an active tab and checks that GetIDByWindow() // returns |LauncherID| of browser shortcut. browser()->tab_strip_model()->ActivateTabAt(0, false); EXPECT_EQ(0, browser()->tab_strip_model()->active_index()); - EXPECT_EQ(browser_id, controller->GetIDByWindow(window)); + EXPECT_EQ(browser_id, controller_->GetIDByWindow(window)); +} + +IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, OverflowBubble) { + // Make sure to have a browser window + chrome::NewTab(browser()); + + // No overflow yet. + EXPECT_FALSE(launcher_->IsShowingOverflowBubble()); + + ash::test::LauncherViewTestAPI test(launcher_->GetLauncherViewForTest()); + + int items_added = 0; + while (!test.IsOverflowButtonVisible()) { + std::string fake_app_id = base::StringPrintf("fake_app_%d", items_added); + PinFakeApp(fake_app_id); + + ++items_added; + ASSERT_LT(items_added, 10000); + } + + // Now show overflow bubble. + test.ShowOverflowBubble(); + EXPECT_TRUE(launcher_->IsShowingOverflowBubble()); + + // Unpin first pinned app and there should be no crash. + controller_->UnpinAppsWithID(std::string("fake_app_0")); + + test.RunMessageLoopUntilAnimationsDone(); + EXPECT_FALSE(launcher_->IsShowingOverflowBubble()); } diff --git a/chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app_unittest.cc b/chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app_unittest.cc index ea3861f..eba97a9 100644 --- a/chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app_unittest.cc +++ b/chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app_unittest.cc @@ -35,6 +35,7 @@ #include "chrome/test/base/browser_with_test_window_test.h" #include "chrome/test/base/testing_pref_service_syncable.h" #include "chrome/test/base/testing_profile.h" +#include "content/public/browser/web_contents.h" #include "content/public/test/test_browser_thread.h" #include "extensions/common/manifest_constants.h" #include "testing/gtest/include/gtest/gtest.h" @@ -135,16 +136,55 @@ class TestAppIconLoaderImpl : public extensions::AppIconLoader { DISALLOW_COPY_AND_ASSIGN(TestAppIconLoaderImpl); }; +// Test implementation of AppTabHelper. +class TestAppTabHelperImpl : public ChromeLauncherController::AppTabHelper { + public: + TestAppTabHelperImpl() {} + virtual ~TestAppTabHelperImpl() {} + + // Sets the id for the specified tab. The id is removed if Remove() is + // invoked. + void SetAppID(content::WebContents* tab, const std::string& id) { + tab_id_map_[tab] = id; + } + + // Returns true if there is an id registered for |tab|. + bool HasAppID(content::WebContents* tab) const { + return tab_id_map_.find(tab) != tab_id_map_.end(); + } + + // AppTabHelper implementation: + virtual std::string GetAppID(content::WebContents* tab) OVERRIDE { + return tab_id_map_.find(tab) != tab_id_map_.end() ? tab_id_map_[tab] : + std::string(); + } + + virtual bool IsValidID(const std::string& id) OVERRIDE { + for (TabToStringMap::const_iterator i = tab_id_map_.begin(); + i != tab_id_map_.end(); ++i) { + if (i->second == id) + return true; + } + return false; + } + + private: + typedef std::map<content::WebContents*, std::string> TabToStringMap; + + TabToStringMap tab_id_map_; + + DISALLOW_COPY_AND_ASSIGN(TestAppTabHelperImpl); +}; + } // namespace -class ChromeLauncherControllerPerAppTest : public BrowserWithTestWindowTest { +class ChromeLauncherControllerTest : public BrowserWithTestWindowTest { protected: - ChromeLauncherControllerPerAppTest() - : extension_service_(NULL) { + ChromeLauncherControllerTest() : extension_service_(NULL) { SetHostDesktopType(chrome::HOST_DESKTOP_TYPE_ASH); } - virtual ~ChromeLauncherControllerPerAppTest() { + virtual ~ChromeLauncherControllerTest() { } virtual void SetUp() OVERRIDE { @@ -216,7 +256,7 @@ class ChromeLauncherControllerPerAppTest : public BrowserWithTestWindowTest { void InitLauncherController() { launcher_controller_.reset( - new ChromeLauncherControllerPerApp(profile(), model_.get())); + new ChromeLauncherController(profile(), model_.get())); launcher_controller_->Init(); } @@ -230,6 +270,10 @@ class ChromeLauncherControllerPerAppTest : public BrowserWithTestWindowTest { launcher_controller_->SetAppIconLoaderForTest(loader); } + void SetAppTabHelper(ChromeLauncherController::AppTabHelper* helper) { + launcher_controller_->SetAppTabHelperForTest(helper); + } + void InsertPrefValue(base::ListValue* pref_value, int index, const std::string& extension_id) { @@ -239,12 +283,12 @@ class ChromeLauncherControllerPerAppTest : public BrowserWithTestWindowTest { } // Gets the currently configured app launchers from the controller. - void GetAppLaunchers(ChromeLauncherControllerPerApp* controller, + void GetAppLaunchers(ChromeLauncherController* controller, std::vector<std::string>* launchers) { launchers->clear(); for (ash::LauncherItems::const_iterator iter(model_->items().begin()); iter != model_->items().end(); ++iter) { - ChromeLauncherControllerPerApp::IDToItemControllerMap::const_iterator + ChromeLauncherController::IDToItemControllerMap::const_iterator entry(controller->id_to_item_controller_map_.find(iter->id)); if (iter->type == ash::TYPE_APP_SHORTCUT && entry != controller->id_to_item_controller_map_.end()) { @@ -297,30 +341,30 @@ class ChromeLauncherControllerPerAppTest : public BrowserWithTestWindowTest { scoped_refptr<Extension> extension2_; scoped_refptr<Extension> extension3_; scoped_refptr<Extension> extension4_; - scoped_ptr<ChromeLauncherControllerPerApp> launcher_controller_; + scoped_ptr<ChromeLauncherController> launcher_controller_; scoped_ptr<TestLauncherModelObserver> model_observer_; scoped_ptr<ash::LauncherModel> model_; ExtensionService* extension_service_; - DISALLOW_COPY_AND_ASSIGN(ChromeLauncherControllerPerAppTest); + DISALLOW_COPY_AND_ASSIGN(ChromeLauncherControllerTest); }; // The testing framework to test the alternate shelf layout. -class AlternateLayoutChromeLauncherControllerPerAppTest - : public ChromeLauncherControllerPerAppTest { +class AlternateLayoutChromeLauncherControllerTest + : public ChromeLauncherControllerTest { protected: - AlternateLayoutChromeLauncherControllerPerAppTest() { + AlternateLayoutChromeLauncherControllerTest() { } - virtual ~AlternateLayoutChromeLauncherControllerPerAppTest() { + virtual ~AlternateLayoutChromeLauncherControllerTest() { } // Overwrite the Setup function to add the Alternate Shelf layout option. virtual void SetUp() OVERRIDE { CommandLine::ForCurrentProcess()->AppendSwitch( ash::switches::kAshUseAlternateShelfLayout); - ChromeLauncherControllerPerAppTest::SetUp(); + ChromeLauncherControllerTest::SetUp(); } // Set the index at which the chrome icon should be. @@ -331,11 +375,11 @@ class AlternateLayoutChromeLauncherControllerPerAppTest private: - DISALLOW_COPY_AND_ASSIGN(AlternateLayoutChromeLauncherControllerPerAppTest); + DISALLOW_COPY_AND_ASSIGN(AlternateLayoutChromeLauncherControllerTest); }; -TEST_F(ChromeLauncherControllerPerAppTest, DefaultApps) { +TEST_F(ChromeLauncherControllerTest, DefaultApps) { InitLauncherController(); // Model should only contain the browser shortcut and app list items. EXPECT_EQ(2, model_->item_count()); @@ -354,7 +398,7 @@ TEST_F(ChromeLauncherControllerPerAppTest, DefaultApps) { // Check that the restauration of launcher items is happening in the same order // as the user has pinned them (on another system) when they are synced reverse // order. -TEST_F(ChromeLauncherControllerPerAppTest, RestoreDefaultAppsReverseOrder) { +TEST_F(ChromeLauncherControllerTest, RestoreDefaultAppsReverseOrder) { InitLauncherController(); base::ListValue policy_value; @@ -393,7 +437,7 @@ TEST_F(ChromeLauncherControllerPerAppTest, RestoreDefaultAppsReverseOrder) { // Check that the restauration of launcher items is happening in the same order // as the user has pinned them (on another system) when they are synced random // order. -TEST_F(ChromeLauncherControllerPerAppTest, RestoreDefaultAppsRandomOrder) { +TEST_F(ChromeLauncherControllerTest, RestoreDefaultAppsRandomOrder) { InitLauncherController(); base::ListValue policy_value; @@ -431,8 +475,7 @@ TEST_F(ChromeLauncherControllerPerAppTest, RestoreDefaultAppsRandomOrder) { // Check that the restauration of launcher items is happening in the same order // as the user has pinned / moved them (on another system) when they are synced // random order - including the chrome icon. -TEST_F(ChromeLauncherControllerPerAppTest, - RestoreDefaultAppsRandomOrderChromeMoved) { +TEST_F(ChromeLauncherControllerTest, RestoreDefaultAppsRandomOrderChromeMoved) { InitLauncherController(); base::ListValue policy_value; @@ -470,7 +513,7 @@ TEST_F(ChromeLauncherControllerPerAppTest, } // Check that syncing to a different state does the correct thing. -TEST_F(ChromeLauncherControllerPerAppTest, RestoreDefaultAppsResyncOrder) { +TEST_F(ChromeLauncherControllerTest, RestoreDefaultAppsResyncOrder) { InitLauncherController(); base::ListValue policy_value; InsertPrefValue(&policy_value, 0, extension1_->id()); @@ -505,7 +548,7 @@ TEST_F(ChromeLauncherControllerPerAppTest, RestoreDefaultAppsResyncOrder) { EXPECT_EQ("App2, Chrome, App3, App1, AppList, ", GetPinnedAppStatus()); } -TEST_F(AlternateLayoutChromeLauncherControllerPerAppTest, DefaultApps) { +TEST_F(AlternateLayoutChromeLauncherControllerTest, DefaultApps) { InitLauncherController(); // Model should only contain the browser shortcut and app list items. EXPECT_EQ(2, model_->item_count()); @@ -524,7 +567,7 @@ TEST_F(AlternateLayoutChromeLauncherControllerPerAppTest, DefaultApps) { // Check that the restauration of launcher items is happening in the same order // as the user has pinned them (on another system) when they are synced reverse // order. -TEST_F(AlternateLayoutChromeLauncherControllerPerAppTest, +TEST_F(AlternateLayoutChromeLauncherControllerTest, RestoreDefaultAppsReverseOrder) { InitLauncherController(); @@ -564,7 +607,7 @@ TEST_F(AlternateLayoutChromeLauncherControllerPerAppTest, // Check that the restauration of launcher items is happening in the same order // as the user has pinned them (on another system) when they are synced random // order. -TEST_F(AlternateLayoutChromeLauncherControllerPerAppTest, +TEST_F(AlternateLayoutChromeLauncherControllerTest, RestoreDefaultAppsRandomOrder) { InitLauncherController(); @@ -603,7 +646,7 @@ TEST_F(AlternateLayoutChromeLauncherControllerPerAppTest, // Check that the restauration of launcher items is happening in the same order // as the user has pinned / moved them (on another system) when they are synced // random order - including the chrome icon - using the alternate shelf layout. -TEST_F(AlternateLayoutChromeLauncherControllerPerAppTest, +TEST_F(AlternateLayoutChromeLauncherControllerTest, RestoreDefaultAppsRandomOrderChromeMoved) { InitLauncherController(); @@ -642,7 +685,7 @@ TEST_F(AlternateLayoutChromeLauncherControllerPerAppTest, // Check that syncing to a different state does the correct thing with the // alternate shelf layout. -TEST_F(AlternateLayoutChromeLauncherControllerPerAppTest, +TEST_F(AlternateLayoutChromeLauncherControllerTest, RestoreDefaultAppsResyncOrder) { InitLauncherController(); base::ListValue policy_value; @@ -704,7 +747,7 @@ TEST_F(AlternateLayoutChromeLauncherControllerPerAppTest, } // Check that simple locking of an application will 'create' a launcher item. -TEST_F(ChromeLauncherControllerPerAppTest, CheckLockApps) { +TEST_F(ChromeLauncherControllerTest, CheckLockApps) { InitLauncherController(); // Model should only contain the browser shortcut and app list items. EXPECT_EQ(2, model_->item_count()); @@ -737,7 +780,7 @@ TEST_F(ChromeLauncherControllerPerAppTest, CheckLockApps) { } // Check that multiple locks of an application will be properly handled. -TEST_F(ChromeLauncherControllerPerAppTest, CheckMukltiLockApps) { +TEST_F(ChromeLauncherControllerTest, CheckMukltiLockApps) { InitLauncherController(); // Model should only contain the browser shortcut and app list items. EXPECT_EQ(2, model_->item_count()); @@ -774,7 +817,7 @@ TEST_F(ChromeLauncherControllerPerAppTest, CheckMukltiLockApps) { } // Check that already pinned items are not effected by locks. -TEST_F(ChromeLauncherControllerPerAppTest, CheckAlreadyPinnedLockApps) { +TEST_F(ChromeLauncherControllerTest, CheckAlreadyPinnedLockApps) { InitLauncherController(); // Model should only contain the browser shortcut and app list items. EXPECT_EQ(2, model_->item_count()); @@ -814,7 +857,7 @@ TEST_F(ChromeLauncherControllerPerAppTest, CheckAlreadyPinnedLockApps) { } // Check that already pinned items which get locked stay after unpinning. -TEST_F(ChromeLauncherControllerPerAppTest, CheckPinnedAppsStayAfterUnlock) { +TEST_F(ChromeLauncherControllerTest, CheckPinnedAppsStayAfterUnlock) { InitLauncherController(); // Model should only contain the browser shortcut and app list items. EXPECT_EQ(2, model_->item_count()); @@ -851,7 +894,7 @@ TEST_F(ChromeLauncherControllerPerAppTest, CheckPinnedAppsStayAfterUnlock) { } // Check that lock -> pin -> unlock -> unpin does properly transition. -TEST_F(ChromeLauncherControllerPerAppTest, CheckLockPinUnlockUnpin) { +TEST_F(ChromeLauncherControllerTest, CheckLockPinUnlockUnpin) { InitLauncherController(); // Model should only contain the browser shortcut and app list items. EXPECT_EQ(2, model_->item_count()); @@ -887,7 +930,7 @@ TEST_F(ChromeLauncherControllerPerAppTest, CheckLockPinUnlockUnpin) { EXPECT_EQ(2, model_->item_count()); } -TEST_F(ChromeLauncherControllerPerAppTest, Policy) { +TEST_F(ChromeLauncherControllerTest, Policy) { extension_service_->AddExtension(extension1_.get()); extension_service_->AddExtension(extension3_.get()); @@ -927,7 +970,7 @@ TEST_F(ChromeLauncherControllerPerAppTest, Policy) { EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); } -TEST_F(ChromeLauncherControllerPerAppTest, UnpinWithUninstall) { +TEST_F(ChromeLauncherControllerTest, UnpinWithUninstall) { extension_service_->AddExtension(extension3_.get()); extension_service_->AddExtension(extension4_.get()); @@ -943,7 +986,7 @@ TEST_F(ChromeLauncherControllerPerAppTest, UnpinWithUninstall) { EXPECT_TRUE(launcher_controller_->IsAppPinned(extension4_->id())); } -TEST_F(ChromeLauncherControllerPerAppTest, PrefUpdates) { +TEST_F(ChromeLauncherControllerTest, PrefUpdates) { extension_service_->AddExtension(extension2_.get()); extension_service_->AddExtension(extension3_.get()); extension_service_->AddExtension(extension4_.get()); @@ -999,7 +1042,7 @@ TEST_F(ChromeLauncherControllerPerAppTest, PrefUpdates) { EXPECT_EQ(expected_launchers, actual_launchers); } -TEST_F(ChromeLauncherControllerPerAppTest, PendingInsertionOrder) { +TEST_F(ChromeLauncherControllerTest, PendingInsertionOrder) { extension_service_->AddExtension(extension1_.get()); extension_service_->AddExtension(extension3_.get()); @@ -1032,7 +1075,7 @@ TEST_F(ChromeLauncherControllerPerAppTest, PendingInsertionOrder) { // found item count against the |expected_items|. The |title| list contains the // menu titles in the order of their appearance in the menu (not including the // application name). -bool CheckMenuCreation(ChromeLauncherControllerPerApp* controller, +bool CheckMenuCreation(ChromeLauncherController* controller, const ash::LauncherItem& item, size_t expected_items, string16 title[], @@ -1074,7 +1117,7 @@ bool CheckMenuCreation(ChromeLauncherControllerPerApp* controller, } // Check that browsers get reflected correctly in the launcher menu. -TEST_F(ChromeLauncherControllerPerAppTest, BrowserMenuGeneration) { +TEST_F(ChromeLauncherControllerTest, BrowserMenuGeneration) { EXPECT_EQ(1U, chrome::GetTotalBrowserCount()); chrome::NewTab(browser()); @@ -1122,7 +1165,7 @@ TEST_F(ChromeLauncherControllerPerAppTest, BrowserMenuGeneration) { // refocus logic. // Note that the extension matching logic is tested by the extension system // and does not need a separate test here. -TEST_F(ChromeLauncherControllerPerAppTest, V1AppMenuGeneration) { +TEST_F(ChromeLauncherControllerTest, V1AppMenuGeneration) { EXPECT_EQ(1U, chrome::GetTotalBrowserCount()); EXPECT_EQ(0, browser()->tab_strip_model()->count()); @@ -1195,7 +1238,7 @@ TEST_F(ChromeLauncherControllerPerAppTest, V1AppMenuGeneration) { } // Checks that the generated menu list properly activates items. -TEST_F(ChromeLauncherControllerPerAppTest, V1AppMenuExecution) { +TEST_F(ChromeLauncherControllerTest, V1AppMenuExecution) { InitLauncherControllerWithBrowser(); // Add |extension3_| to the launcher and add two items. @@ -1244,7 +1287,7 @@ TEST_F(ChromeLauncherControllerPerAppTest, V1AppMenuExecution) { } // Checks that the generated menu list properly deletes items. -TEST_F(ChromeLauncherControllerPerAppTest, V1AppMenuDeletionExecution) { +TEST_F(ChromeLauncherControllerTest, V1AppMenuDeletionExecution) { InitLauncherControllerWithBrowser(); // Add |extension3_| to the launcher and add two items. @@ -1285,8 +1328,9 @@ TEST_F(ChromeLauncherControllerPerAppTest, V1AppMenuDeletionExecution) { } // Tests that panels create launcher items correctly -TEST_F(ChromeLauncherControllerPerAppTest, AppPanels) { +TEST_F(ChromeLauncherControllerTest, AppPanels) { InitLauncherControllerWithBrowser(); + // Browser shortcut LauncherItem is added. EXPECT_EQ(1, model_observer_->added()); TestAppIconLoaderImpl* app_icon_loader = new TestAppIconLoaderImpl(); @@ -1330,7 +1374,7 @@ TEST_F(ChromeLauncherControllerPerAppTest, AppPanels) { // Tests that the Gmail extension matches more then the app itself claims with // the manifest file. -TEST_F(ChromeLauncherControllerPerAppTest, GmailMatching) { +TEST_F(ChromeLauncherControllerTest, GmailMatching) { InitLauncherControllerWithBrowser(); // Create a Gmail browser tab. @@ -1362,7 +1406,7 @@ TEST_F(ChromeLauncherControllerPerAppTest, GmailMatching) { } // Tests that the Gmail extension does not match the offline verison. -TEST_F(ChromeLauncherControllerPerAppTest, GmailOfflineMatching) { +TEST_F(ChromeLauncherControllerTest, GmailOfflineMatching) { InitLauncherControllerWithBrowser(); // Create a Gmail browser tab. @@ -1385,3 +1429,102 @@ TEST_F(ChromeLauncherControllerPerAppTest, GmailOfflineMatching) { // The content should not be able to be handled by the app. EXPECT_FALSE(launcher_controller_->ContentCanBeHandledByGmailApp(content)); } + +// Verify that the launcher item positions are persisted and restored. +TEST_F(ChromeLauncherControllerTest, PersistLauncherItemPositions) { + InitLauncherController(); + + TestAppTabHelperImpl* app_tab_helper = new TestAppTabHelperImpl; + SetAppTabHelper(app_tab_helper); + + EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, model_->items()[0].type); + EXPECT_EQ(ash::TYPE_APP_LIST, model_->items()[1].type); + + TabStripModel* tab_strip_model = browser()->tab_strip_model(); + EXPECT_EQ(0, tab_strip_model->count()); + chrome::NewTab(browser()); + chrome::NewTab(browser()); + EXPECT_EQ(2, tab_strip_model->count()); + app_tab_helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1"); + app_tab_helper->SetAppID(tab_strip_model->GetWebContentsAt(1), "2"); + + EXPECT_FALSE(launcher_controller_->IsAppPinned("1")); + launcher_controller_->PinAppWithID("1"); + EXPECT_TRUE(launcher_controller_->IsAppPinned("1")); + launcher_controller_->PinAppWithID("2"); + + EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, model_->items()[0].type); + EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[1].type); + EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type); + EXPECT_EQ(ash::TYPE_APP_LIST, model_->items()[3].type); + + // Move browser shortcut item from index 0 to index 2. + model_->Move(0, 2); + EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[0].type); + EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[1].type); + EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, model_->items()[2].type); + EXPECT_EQ(ash::TYPE_APP_LIST, model_->items()[3].type); + + launcher_controller_.reset(); + model_.reset(new ash::LauncherModel); + launcher_controller_.reset( + ChromeLauncherController::CreateInstance(profile(), model_.get())); + app_tab_helper = new TestAppTabHelperImpl; + app_tab_helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1"); + app_tab_helper->SetAppID(tab_strip_model->GetWebContentsAt(1), "2"); + SetAppTabHelper(app_tab_helper); + + launcher_controller_->Init(); + + // Check LauncherItems are restored after resetting ChromeLauncherController. + EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[0].type); + EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[1].type); + EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, model_->items()[2].type); + EXPECT_EQ(ash::TYPE_APP_LIST, model_->items()[3].type); +} + +// Verifies pinned apps are persisted and restored. +TEST_F(ChromeLauncherControllerTest, PersistPinned) { + InitLauncherControllerWithBrowser(); + size_t initial_size = model_->items().size(); + + TabStripModel* tab_strip_model = browser()->tab_strip_model(); + EXPECT_EQ(1, tab_strip_model->count()); + + TestAppTabHelperImpl* app_tab_helper = new TestAppTabHelperImpl; + app_tab_helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1"); + SetAppTabHelper(app_tab_helper); + + TestAppIconLoaderImpl* app_icon_loader = new TestAppIconLoaderImpl; + SetAppIconLoader(app_icon_loader); + EXPECT_EQ(0, app_icon_loader->fetch_count()); + + launcher_controller_->PinAppWithID("1"); + ash::LauncherID id = launcher_controller_->GetLauncherIDForAppID("1"); + int app_index = model_->ItemIndexByID(id); + EXPECT_EQ(1, app_icon_loader->fetch_count()); + EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[app_index].type); + EXPECT_TRUE(launcher_controller_->IsAppPinned("1")); + EXPECT_FALSE(launcher_controller_->IsAppPinned("0")); + EXPECT_EQ(initial_size + 1, model_->items().size()); + + launcher_controller_.reset(); + model_.reset(new ash::LauncherModel); + launcher_controller_.reset( + ChromeLauncherController::CreateInstance(profile(), model_.get())); + app_tab_helper = new TestAppTabHelperImpl; + app_tab_helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1"); + SetAppTabHelper(app_tab_helper); + app_icon_loader = new TestAppIconLoaderImpl; + SetAppIconLoader(app_icon_loader); + launcher_controller_->Init(); + + EXPECT_EQ(1, app_icon_loader->fetch_count()); + ASSERT_EQ(initial_size + 1, model_->items().size()); + EXPECT_TRUE(launcher_controller_->IsAppPinned("1")); + EXPECT_FALSE(launcher_controller_->IsAppPinned("0")); + EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[app_index].type); + + launcher_controller_->UnpinAppsWithID("1"); + ASSERT_EQ(initial_size, model_->items().size()); +} diff --git a/chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_browser.cc b/chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_browser.cc deleted file mode 100644 index 4836677..0000000 --- a/chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_browser.cc +++ /dev/null @@ -1,1476 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_browser.h" - -#include <vector> - -#include "ash/ash_switches.h" -#include "ash/launcher/launcher_model.h" -#include "ash/root_window_controller.h" -#include "ash/shelf/shelf_layout_manager.h" -#include "ash/shelf/shelf_widget.h" -#include "ash/shell.h" -#include "ash/wm/window_util.h" -#include "base/command_line.h" -#include "base/strings/string_number_conversions.h" -#include "base/values.h" -#include "chrome/browser/app_mode/app_mode_utils.h" -#include "chrome/browser/defaults.h" -#include "chrome/browser/chrome_notification_types.h" -#include "chrome/browser/extensions/app_icon_loader_impl.h" -#include "chrome/browser/extensions/extension_service.h" -#include "chrome/browser/extensions/extension_system.h" -#include "chrome/browser/prefs/incognito_mode_prefs.h" -#include "chrome/browser/prefs/pref_service_syncable.h" -#include "chrome/browser/prefs/scoped_user_pref_update.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/profiles/profile_manager.h" -#include "chrome/browser/ui/ash/app_sync_ui_state.h" -#include "chrome/browser/ui/ash/chrome_launcher_prefs.h" -#include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h" -#include "chrome/browser/ui/ash/launcher/launcher_app_tab_helper.h" -#include "chrome/browser/ui/ash/launcher/launcher_context_menu.h" -#include "chrome/browser/ui/ash/launcher/launcher_item_controller.h" -#include "chrome/browser/ui/ash/launcher/shell_window_launcher_controller.h" -#include "chrome/browser/ui/browser.h" -#include "chrome/browser/ui/browser_commands.h" -#include "chrome/browser/ui/browser_finder.h" -#include "chrome/browser/ui/browser_tabstrip.h" -#include "chrome/browser/ui/browser_window.h" -#include "chrome/browser/ui/extensions/application_launch.h" -#include "chrome/browser/ui/extensions/extension_enable_flow.h" -#include "chrome/browser/ui/host_desktop.h" -#include "chrome/browser/ui/tabs/tab_strip_model.h" -#include "chrome/browser/web_applications/web_app.h" -#include "chrome/common/chrome_switches.h" -#include "chrome/common/extensions/extension.h" -#include "chrome/common/extensions/manifest_handlers/app_launch_info.h" -#include "chrome/common/extensions/manifest_handlers/icons_handler.h" -#include "chrome/common/pref_names.h" -#include "chrome/common/url_constants.h" -#include "content/public/browser/navigation_entry.h" -#include "content/public/browser/notification_service.h" -#include "content/public/browser/web_contents.h" -#include "extensions/common/url_pattern.h" -#include "grit/chromium_strings.h" -#include "grit/theme_resources.h" -#include "ui/aura/root_window.h" -#include "ui/aura/window.h" -#include "ui/base/l10n/l10n_util.h" - -#if defined(OS_CHROMEOS) -#include "chrome/browser/chromeos/login/default_pinned_apps_field_trial.h" -#endif - -using content::WebContents; -using extensions::Extension; - -namespace { - -// Item controller for an app shortcut. Shortcuts track app and launcher ids, -// but do not have any associated windows (opening a shortcut will replace the -// item with the appropriate LauncherItemController type). -class AppShortcutLauncherItemController : public LauncherItemController { - public: - AppShortcutLauncherItemController( - const std::string& app_id, - ChromeLauncherControllerPerBrowser* controller) - : LauncherItemController(TYPE_SHORTCUT, app_id, controller) { - // Google Drive should just refocus to it's main app UI. - // TODO(davemoore): Generalize this for other applications. - if (app_id == "apdfllckaahabafndbhieahigkjlhalf") { - const Extension* extension = - launcher_controller()->GetExtensionForAppID(app_id); - refocus_url_ = GURL( - extensions::AppLaunchInfo::GetLaunchWebURL(extension).spec() + "*"); - } - } - - virtual ~AppShortcutLauncherItemController() {} - - // LauncherItemController overrides: - virtual string16 GetTitle() OVERRIDE { - return GetAppTitle(); - } - - virtual bool IsCurrentlyShownInWindow(aura::Window* window) const OVERRIDE { - return false; - } - - virtual bool IsOpen() const OVERRIDE { - return false; - } - - virtual bool IsVisible() const OVERRIDE { - return false; - } - - virtual void Launch(int event_flags) OVERRIDE { - launcher_controller()->LaunchApp(app_id(), event_flags); - } - - virtual void Activate() OVERRIDE { - launcher_controller()->ActivateApp(app_id(), ui::EF_NONE); - } - - virtual void Close() OVERRIDE { - // TODO: maybe should treat as unpin? - } - - virtual void Clicked(const ui::Event& event) OVERRIDE { - Activate(); - } - - virtual void OnRemoved() OVERRIDE { - // AppShortcutLauncherItemController is unowned; delete on removal. - delete this; - } - - virtual void LauncherItemChanged( - int model_index, - const ash::LauncherItem& old_item) OVERRIDE { - } - - virtual ChromeLauncherAppMenuItems GetApplicationList( - int event_flags) OVERRIDE { - ChromeLauncherAppMenuItems items; - return items.Pass(); - } - - // Stores the optional refocus url pattern for this item. - const GURL& refocus_url() const { return refocus_url_; } - void set_refocus_url(const GURL& refocus_url) { refocus_url_ = refocus_url; } - - private: - GURL refocus_url_; - DISALLOW_COPY_AND_ASSIGN(AppShortcutLauncherItemController); -}; - -std::string GetPrefKeyForRootWindow(aura::RootWindow* root_window) { - gfx::Display display = gfx::Screen::GetScreenFor( - root_window)->GetDisplayNearestWindow(root_window); - DCHECK(display.is_valid()); - - return base::Int64ToString(display.id()); -} - -void UpdatePerDisplayPref(PrefService* pref_service, - aura::RootWindow* root_window, - const char* pref_key, - const std::string& value) { - std::string key = GetPrefKeyForRootWindow(root_window); - if (key.empty()) - return; - - DictionaryPrefUpdate update(pref_service, prefs::kShelfPreferences); - base::DictionaryValue* shelf_prefs = update.Get(); - base::DictionaryValue* prefs = NULL; - if (!shelf_prefs->GetDictionary(key, &prefs)) { - prefs = new base::DictionaryValue(); - shelf_prefs->Set(key, prefs); - } - prefs->SetStringWithoutPathExpansion(pref_key, value); -} - -// Returns a pref value in |pref_service| for the display of |root_window|. The -// pref value is stored in |local_path| and |path|, but |pref_service| may have -// per-display preferences and the value can be specified by policy. Here is -// the priority: -// * A value managed by policy. This is a single value that applies to all -// displays. -// * A user-set value for the specified display. -// * A user-set value in |local_path| or |path|, if no per-display settings are -// ever specified (see http://crbug.com/173719 for why). |local_path| is -// preferred. See comment in |kShelfAlignment| as to why we consider two -// prefs and why |local_path| is preferred. -// * A value recommended by policy. This is a single value that applies to all -// root windows. -// * The default value for |local_path| if the value is not recommended by -// policy. -std::string GetPrefForRootWindow(PrefService* pref_service, - aura::RootWindow* root_window, - const char* local_path, - const char* path) { - const PrefService::Preference* local_pref = - pref_service->FindPreference(local_path); - const std::string value(pref_service->GetString(local_path)); - if (local_pref->IsManaged()) - return value; - - std::string pref_key = GetPrefKeyForRootWindow(root_window); - bool has_per_display_prefs = false; - if (!pref_key.empty()) { - const base::DictionaryValue* shelf_prefs = pref_service->GetDictionary( - prefs::kShelfPreferences); - const base::DictionaryValue* display_pref = NULL; - std::string per_display_value; - if (shelf_prefs->GetDictionary(pref_key, &display_pref) && - display_pref->GetString(path, &per_display_value)) - return per_display_value; - - // If the pref for the specified display is not found, scan the whole prefs - // and check if the prefs for other display is already specified. - std::string unused_value; - for (base::DictionaryValue::Iterator iter(*shelf_prefs); - !iter.IsAtEnd(); iter.Advance()) { - const base::DictionaryValue* display_pref = NULL; - if (iter.value().GetAsDictionary(&display_pref) && - display_pref->GetString(path, &unused_value)) { - has_per_display_prefs = true; - break; - } - } - } - - if (local_pref->IsRecommended() || !has_per_display_prefs) - return value; - - const base::Value* default_value = - pref_service->GetDefaultPrefValue(local_path); - std::string default_string; - default_value->GetAsString(&default_string); - return default_string; -} - -// If prefs have synced and no user-set value exists at |local_path|, the value -// from |synced_path| is copied to |local_path|. -void MaybePropagatePrefToLocal(PrefServiceSyncable* pref_service, - const char* local_path, - const char* synced_path) { - if (!pref_service->FindPreference(local_path)->HasUserSetting() && - pref_service->IsSyncing()) { - // First time the user is using this machine, propagate from remote to - // local. - pref_service->SetString(local_path, pref_service->GetString(synced_path)); - } -} - -} // namespace - -// ChromeLauncherControllerPerBrowser ----------------------------------------- - -ChromeLauncherControllerPerBrowser::ChromeLauncherControllerPerBrowser( - Profile* profile, - ash::LauncherModel* model) - : model_(model), - profile_(profile), - app_sync_ui_state_(NULL), - ignore_persist_pinned_state_change_(false) { - if (!profile_) { - // Use the original profile as on chromeos we may get a temporary off the - // record profile. - profile_ = ProfileManager::GetDefaultProfile()->GetOriginalProfile(); - - app_sync_ui_state_ = AppSyncUIState::Get(profile_); - if (app_sync_ui_state_) - app_sync_ui_state_->AddObserver(this); - } - - model_->AddObserver(this); - // Right now ash::Shell isn't created for tests. - // TODO(mukai): Allows it to observe display change and write tests. - if (ash::Shell::HasInstance()) - ash::Shell::GetInstance()->display_controller()->AddObserver(this); - // TODO(stevenjb): Find a better owner for shell_window_controller_? - shell_window_controller_.reset(new ShellWindowLauncherController(this)); - app_tab_helper_.reset(new LauncherAppTabHelper(profile_)); - app_icon_loader_.reset(new extensions::AppIconLoaderImpl( - profile_, extension_misc::EXTENSION_ICON_SMALL, this)); - - notification_registrar_.Add(this, - chrome::NOTIFICATION_EXTENSION_LOADED, - content::Source<Profile>(profile_)); - notification_registrar_.Add(this, - chrome::NOTIFICATION_EXTENSION_UNLOADED, - content::Source<Profile>(profile_)); - pref_change_registrar_.Init(profile_->GetPrefs()); - pref_change_registrar_.Add( - prefs::kPinnedLauncherApps, - base::Bind(&ChromeLauncherControllerPerBrowser:: - UpdateAppLaunchersFromPref, - base::Unretained(this))); - pref_change_registrar_.Add( - prefs::kShelfAlignmentLocal, - base::Bind(&ChromeLauncherControllerPerBrowser:: - SetShelfAlignmentFromPrefs, - base::Unretained(this))); - pref_change_registrar_.Add( - prefs::kShelfAutoHideBehaviorLocal, - base::Bind(&ChromeLauncherControllerPerBrowser:: - SetShelfAutoHideBehaviorFromPrefs, - base::Unretained(this))); - pref_change_registrar_.Add( - prefs::kShelfPreferences, - base::Bind(&ChromeLauncherControllerPerBrowser:: - SetShelfBehaviorsFromPrefs, - base::Unretained(this))); -} - -ChromeLauncherControllerPerBrowser::~ChromeLauncherControllerPerBrowser() { - // Reset the shell window controller here since it has a weak pointer to - // this. - shell_window_controller_.reset(); - - for (std::set<ash::Launcher*>::iterator iter = launchers_.begin(); - iter != launchers_.end(); - ++iter) - (*iter)->shelf_widget()->shelf_layout_manager()->RemoveObserver(this); - - model_->RemoveObserver(this); - if (ash::Shell::HasInstance()) - ash::Shell::GetInstance()->display_controller()->RemoveObserver(this); - for (IDToItemControllerMap::iterator i = id_to_item_controller_map_.begin(); - i != id_to_item_controller_map_.end(); ++i) { - i->second->OnRemoved(); - model_->RemoveItemAt(model_->ItemIndexByID(i->first)); - } - - if (ash::Shell::HasInstance()) - ash::Shell::GetInstance()->RemoveShellObserver(this); - - if (app_sync_ui_state_) - app_sync_ui_state_->RemoveObserver(this); - - PrefServiceSyncable::FromProfile(profile_)->RemoveObserver(this); -} - -void ChromeLauncherControllerPerBrowser::Init() { - UpdateAppLaunchersFromPref(); - CreateBrowserShortcutLauncherItem(); - - // TODO(sky): update unit test so that this test isn't necessary. - if (ash::Shell::HasInstance()) { - SetShelfAutoHideBehaviorFromPrefs(); - SetShelfAlignmentFromPrefs(); - PrefServiceSyncable* prefs = PrefServiceSyncable::FromProfile(profile_); - if (!prefs->FindPreference(prefs::kShelfAlignmentLocal)->HasUserSetting() || - !prefs->FindPreference(prefs::kShelfAutoHideBehaviorLocal)-> - HasUserSetting()) { - // This causes OnIsSyncingChanged to be called when the value of - // PrefService::IsSyncing() changes. - prefs->AddObserver(this); - } - ash::Shell::GetInstance()->AddShellObserver(this); - } -} - -ChromeLauncherControllerPerApp* -ChromeLauncherControllerPerBrowser::GetPerAppInterface() { - return NULL; -} - -ash::LauncherID ChromeLauncherControllerPerBrowser::CreateTabbedLauncherItem( - LauncherItemController* controller, - IncognitoState is_incognito, - ash::LauncherItemStatus status) { - ash::LauncherID id = model_->next_id(); - DCHECK(!HasItemController(id)); - DCHECK(controller); - id_to_item_controller_map_[id] = controller; - controller->set_launcher_id(id); - - ash::LauncherItem item; - item.type = ash::TYPE_TABBED; - item.is_incognito = (is_incognito == STATE_INCOGNITO); - item.status = status; - model_->Add(item); - return id; -} - -ash::LauncherID ChromeLauncherControllerPerBrowser::CreateAppLauncherItem( - LauncherItemController* controller, - const std::string& app_id, - ash::LauncherItemStatus status) { - DCHECK(controller); - int index = 0; - // Panels are inserted on the left so as not to push all existing panels over. - if (controller->GetLauncherItemType() != ash::TYPE_APP_PANEL) { - index = model_->item_count(); - // For the alternate shelf layout increment index (insert after app icon). - if (ash::switches::UseAlternateShelfLayout()) - ++index; - } - return InsertAppLauncherItem(controller, app_id, status, index); -} - -void ChromeLauncherControllerPerBrowser::SetItemStatus( - ash::LauncherID id, - ash::LauncherItemStatus status) { - int index = model_->ItemIndexByID(id); - DCHECK_GE(index, 0); - ash::LauncherItem item = model_->items()[index]; - item.status = status; - model_->Set(index, item); -} - -void ChromeLauncherControllerPerBrowser::SetItemController( - ash::LauncherID id, - LauncherItemController* controller) { - IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); - DCHECK(iter != id_to_item_controller_map_.end()); - iter->second->OnRemoved(); - iter->second = controller; - controller->set_launcher_id(id); -} - -void ChromeLauncherControllerPerBrowser::CloseLauncherItem( - ash::LauncherID id) { - if (IsPinned(id)) { - // Create a new shortcut controller. - IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); - DCHECK(iter != id_to_item_controller_map_.end()); - SetItemStatus(id, ash::STATUS_CLOSED); - std::string app_id = iter->second->app_id(); - iter->second->OnRemoved(); - iter->second = new AppShortcutLauncherItemController(app_id, this); - iter->second->set_launcher_id(id); - } else { - LauncherItemClosed(id); - } -} - -void ChromeLauncherControllerPerBrowser::Unpin(ash::LauncherID id) { - DCHECK(HasItemController(id)); - - LauncherItemController* controller = id_to_item_controller_map_[id]; - if (controller->type() == LauncherItemController::TYPE_APP) { - int index = model_->ItemIndexByID(id); - ash::LauncherItem item = model_->items()[index]; - item.type = ash::TYPE_PLATFORM_APP; - model_->Set(index, item); - } else { - LauncherItemClosed(id); - } - if (CanPin()) - PersistPinnedState(); -} - -void ChromeLauncherControllerPerBrowser::Pin(ash::LauncherID id) { - DCHECK(HasItemController(id)); - - int index = model_->ItemIndexByID(id); - ash::LauncherItem item = model_->items()[index]; - - if (item.type != ash::TYPE_PLATFORM_APP) - return; - - item.type = ash::TYPE_APP_SHORTCUT; - model_->Set(index, item); - - if (CanPin()) - PersistPinnedState(); -} - -bool ChromeLauncherControllerPerBrowser::IsPinned(ash::LauncherID id) { - int index = model_->ItemIndexByID(id); - ash::LauncherItemType type = model_->items()[index].type; - return (type == ash::TYPE_APP_SHORTCUT || type == ash::TYPE_BROWSER_SHORTCUT); -} - -void ChromeLauncherControllerPerBrowser::TogglePinned(ash::LauncherID id) { - if (!HasItemController(id)) - return; // May happen if item closed with menu open. - - if (IsPinned(id)) - Unpin(id); - else - Pin(id); -} - -bool ChromeLauncherControllerPerBrowser::IsPinnable(ash::LauncherID id) const { - int index = model_->ItemIndexByID(id); - if (index == -1) - return false; - - ash::LauncherItemType type = model_->items()[index].type; - return ((type == ash::TYPE_APP_SHORTCUT || type == ash::TYPE_PLATFORM_APP) && - CanPin()); -} - -void ChromeLauncherControllerPerBrowser::LockV1AppWithID( - const std::string& app_id) { -} - -void ChromeLauncherControllerPerBrowser::UnlockV1AppWithID( - const std::string& app_id) { -} - -void ChromeLauncherControllerPerBrowser::Launch( - ash::LauncherID id, int event_flags) { - if (!HasItemController(id)) - return; // In case invoked from menu and item closed while menu up. - id_to_item_controller_map_[id]->Launch(event_flags); -} - -void ChromeLauncherControllerPerBrowser::Close(ash::LauncherID id) { - if (!HasItemController(id)) - return; // May happen if menu closed. - id_to_item_controller_map_[id]->Close(); -} - -bool ChromeLauncherControllerPerBrowser::IsOpen(ash::LauncherID id) { - if (!HasItemController(id)) - return false; - return id_to_item_controller_map_[id]->IsOpen(); -} - -bool ChromeLauncherControllerPerBrowser::IsPlatformApp(ash::LauncherID id) { - if (!HasItemController(id)) - return false; - - std::string app_id = GetAppIDForLauncherID(id); - const Extension* extension = GetExtensionForAppID(app_id); - DCHECK(extension); - return extension->is_platform_app(); -} - -void ChromeLauncherControllerPerBrowser::LaunchApp(const std::string& app_id, - int event_flags) { - // |extension| could be NULL when it is being unloaded for updating. - const Extension* extension = GetExtensionForAppID(app_id); - if (!extension) - return; - - const ExtensionService* service = - extensions::ExtensionSystem::Get(profile_)->extension_service(); - if (!service->IsExtensionEnabledForLauncher(app_id)) { - // Do nothing if there is already a running enable flow. - if (extension_enable_flow_) - return; - - extension_enable_flow_.reset( - new ExtensionEnableFlow(profile_, app_id, this)); - extension_enable_flow_->StartForNativeWindow(NULL); - return; - } - - chrome::OpenApplication(chrome::AppLaunchParams(GetProfileForNewWindows(), - extension, - event_flags)); -} - -void ChromeLauncherControllerPerBrowser::ActivateApp(const std::string& app_id, - int event_flags) { - if (app_id == extension_misc::kChromeAppId) { - BrowserShortcutClicked(event_flags); - return; - } - - // If there is an existing non-shortcut controller for this app, open it. - ash::LauncherID id = GetLauncherIDForAppID(app_id); - URLPattern refocus_pattern(URLPattern::SCHEME_ALL); - refocus_pattern.SetMatchAllURLs(true); - - if (id > 0) { - LauncherItemController* controller = id_to_item_controller_map_[id]; - if (controller->type() != LauncherItemController::TYPE_SHORTCUT) { - controller->Activate(); - return; - } - - AppShortcutLauncherItemController* app_controller = - static_cast<AppShortcutLauncherItemController*>(controller); - const GURL refocus_url = app_controller->refocus_url(); - - if (!refocus_url.is_empty()) - refocus_pattern.Parse(refocus_url.spec()); - } - - // Check if there are any open tabs for this app. - AppIDToWebContentsListMap::iterator app_i = - app_id_to_web_contents_list_.find(app_id); - if (app_i != app_id_to_web_contents_list_.end()) { - for (WebContentsList::iterator tab_i = app_i->second.begin(); - tab_i != app_i->second.end(); - ++tab_i) { - WebContents* tab = *tab_i; - const GURL tab_url = tab->GetURL(); - if (refocus_pattern.MatchesURL(tab_url)) { - Browser* browser = chrome::FindBrowserWithWebContents(tab); - TabStripModel* tab_strip = browser->tab_strip_model(); - int index = tab_strip->GetIndexOfWebContents(tab); - DCHECK_NE(TabStripModel::kNoTab, index); - tab_strip->ActivateTabAt(index, false); - browser->window()->Show(); - ash::wm::ActivateWindow(browser->window()->GetNativeWindow()); - return; - } - } - } - - LaunchApp(app_id, event_flags); -} - -extensions::ExtensionPrefs::LaunchType - ChromeLauncherControllerPerBrowser::GetLaunchType(ash::LauncherID id) { - DCHECK(HasItemController(id)); - - const Extension* extension = GetExtensionForAppID( - id_to_item_controller_map_[id]->app_id()); - return profile_->GetExtensionService()->extension_prefs()->GetLaunchType( - extension, - extensions::ExtensionPrefs::LAUNCH_DEFAULT); -} - -std::string ChromeLauncherControllerPerBrowser::GetAppID( - content::WebContents* tab) { - return app_tab_helper_->GetAppID(tab); -} - -ash::LauncherID ChromeLauncherControllerPerBrowser::GetLauncherIDForAppID( - const std::string& app_id) { - for (IDToItemControllerMap::const_iterator i = - id_to_item_controller_map_.begin(); - i != id_to_item_controller_map_.end(); ++i) { - if (i->second->type() == LauncherItemController::TYPE_APP_PANEL) - continue; // Don't include panels - if (i->second->app_id() == app_id) - return i->first; - } - return 0; -} - -std::string ChromeLauncherControllerPerBrowser::GetAppIDForLauncherID( - ash::LauncherID id) { - DCHECK(HasItemController(id)); - return id_to_item_controller_map_[id]->app_id(); -} - -void ChromeLauncherControllerPerBrowser::SetAppImage( - const std::string& id, - const gfx::ImageSkia& image) { - // TODO: need to get this working for shortcuts. - - for (IDToItemControllerMap::const_iterator i = - id_to_item_controller_map_.begin(); - i != id_to_item_controller_map_.end(); ++i) { - if (i->second->app_id() != id) - continue; - - int index = model_->ItemIndexByID(i->first); - ash::LauncherItem item = model_->items()[index]; - item.image = image; - model_->Set(index, item); - // It's possible we're waiting on more than one item, so don't break. - } -} - -void ChromeLauncherControllerPerBrowser::OnAutoHideBehaviorChanged( - aura::RootWindow* root_window, - ash::ShelfAutoHideBehavior new_behavior) { - SetShelfAutoHideBehaviorPrefs(new_behavior, root_window); -} - -void ChromeLauncherControllerPerBrowser::SetLauncherItemImage( - ash::LauncherID launcher_id, - const gfx::ImageSkia& image) { - int index = model_->ItemIndexByID(launcher_id); - if (index == -1) - return; - ash::LauncherItem item = model_->items()[index]; - item.image = image; - model_->Set(index, item); -} - -bool ChromeLauncherControllerPerBrowser::IsAppPinned( - const std::string& app_id) { - // Check the LauncherModel since there is no controller for the browser item. - if (app_id == extension_misc::kChromeAppId) { - for (size_t index = 0; index < model_->items().size(); index++) { - if (model_->items()[index].type == ash::TYPE_BROWSER_SHORTCUT) - return true; - } - return false; - } - for (IDToItemControllerMap::const_iterator i = - id_to_item_controller_map_.begin(); - i != id_to_item_controller_map_.end(); ++i) { - if (IsPinned(i->first) && i->second->app_id() == app_id) - return true; - } - return false; -} - -void ChromeLauncherControllerPerBrowser::PinAppWithID( - const std::string& app_id) { - if (CanPin()) - DoPinAppWithID(app_id); - else - NOTREACHED(); -} - -void ChromeLauncherControllerPerBrowser::SetLaunchType( - ash::LauncherID id, - extensions::ExtensionPrefs::LaunchType launch_type) { - if (!HasItemController(id)) - return; - - return profile_->GetExtensionService()->extension_prefs()->SetLaunchType( - id_to_item_controller_map_[id]->app_id(), launch_type); -} - -void ChromeLauncherControllerPerBrowser::UnpinAppsWithID( - const std::string& app_id) { - if (CanPin()) - DoUnpinAppsWithID(app_id); - else - NOTREACHED(); -} - -bool ChromeLauncherControllerPerBrowser::IsLoggedInAsGuest() { - return ProfileManager::GetDefaultProfileOrOffTheRecord()->IsOffTheRecord(); -} - -void ChromeLauncherControllerPerBrowser::CreateNewWindow() { - chrome::NewEmptyWindow( - GetProfileForNewWindows(), chrome::HOST_DESKTOP_TYPE_ASH); -} - -void ChromeLauncherControllerPerBrowser::CreateNewIncognitoWindow() { - chrome::NewEmptyWindow(GetProfileForNewWindows()->GetOffTheRecordProfile(), - chrome::HOST_DESKTOP_TYPE_ASH); -} - -bool ChromeLauncherControllerPerBrowser::CanPin() const { - const PrefService::Preference* pref = - profile_->GetPrefs()->FindPreference(prefs::kPinnedLauncherApps); - return pref && pref->IsUserModifiable(); -} - -ash::ShelfAutoHideBehavior - ChromeLauncherControllerPerBrowser::GetShelfAutoHideBehavior( - aura::RootWindow* root_window) const { - // Don't show the shelf in the app mode. - if (chrome::IsRunningInAppMode()) - return ash::SHELF_AUTO_HIDE_ALWAYS_HIDDEN; - - // See comment in |kShelfAlignment| as to why we consider two prefs. - const std::string behavior_value( - GetPrefForRootWindow(profile_->GetPrefs(), - root_window, - prefs::kShelfAutoHideBehaviorLocal, - prefs::kShelfAutoHideBehavior)); - - // Note: To maintain sync compatibility with old images of chrome/chromeos - // the set of values that may be encountered includes the now-extinct - // "Default" as well as "Never" and "Always", "Default" should now - // be treated as "Never" (http://crbug.com/146773). - if (behavior_value == ash::kShelfAutoHideBehaviorAlways) - return ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS; - return ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER; -} - -bool ChromeLauncherControllerPerBrowser::CanUserModifyShelfAutoHideBehavior( - aura::RootWindow* root_window) const { - return profile_->GetPrefs()-> - FindPreference(prefs::kShelfAutoHideBehaviorLocal)->IsUserModifiable(); -} - -void ChromeLauncherControllerPerBrowser::ToggleShelfAutoHideBehavior( - aura::RootWindow* root_window) { - ash::ShelfAutoHideBehavior behavior = GetShelfAutoHideBehavior(root_window) == - ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS ? - ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER : - ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS; - SetShelfAutoHideBehaviorPrefs(behavior, root_window); - return; -} - -void ChromeLauncherControllerPerBrowser::RemoveTabFromRunningApp( - WebContents* tab, - const std::string& app_id) { - web_contents_to_app_id_.erase(tab); - AppIDToWebContentsListMap::iterator i_app_id = - app_id_to_web_contents_list_.find(app_id); - if (i_app_id != app_id_to_web_contents_list_.end()) { - WebContentsList* tab_list = &i_app_id->second; - tab_list->remove(tab); - if (tab_list->empty()) { - app_id_to_web_contents_list_.erase(i_app_id); - i_app_id = app_id_to_web_contents_list_.end(); - ash::LauncherID id = GetLauncherIDForAppID(app_id); - if (id > 0) - SetItemStatus(id, ash::STATUS_CLOSED); - } - } -} - -void ChromeLauncherControllerPerBrowser::UpdateAppState( - content::WebContents* contents, - AppState app_state) { - std::string app_id = GetAppID(contents); - - // Check the old |app_id| for a tab. If the contents has changed we need to - // remove it from the previous app. - if (web_contents_to_app_id_.find(contents) != web_contents_to_app_id_.end()) { - std::string last_app_id = web_contents_to_app_id_[contents]; - if (last_app_id != app_id) - RemoveTabFromRunningApp(contents, last_app_id); - } - - if (app_id.empty()) - return; - - web_contents_to_app_id_[contents] = app_id; - - if (app_state == APP_STATE_REMOVED) { - // The tab has gone away. - RemoveTabFromRunningApp(contents, app_id); - } else { - WebContentsList& tab_list(app_id_to_web_contents_list_[app_id]); - - if (app_state == APP_STATE_INACTIVE) { - WebContentsList::const_iterator i_tab = - std::find(tab_list.begin(), tab_list.end(), contents); - if (i_tab == tab_list.end()) - tab_list.push_back(contents); - if (i_tab != tab_list.begin()) { - // Going inactive, but wasn't the front tab, indicating that a new - // tab has already become active. - return; - } - } else { - tab_list.remove(contents); - tab_list.push_front(contents); - } - ash::LauncherID id = GetLauncherIDForAppID(app_id); - if (id > 0) { - // If the window is active, mark the app as active. - SetItemStatus(id, app_state == APP_STATE_WINDOW_ACTIVE ? - ash::STATUS_ACTIVE : ash::STATUS_RUNNING); - } - } -} - -void ChromeLauncherControllerPerBrowser::SetRefocusURLPatternForTest( - ash::LauncherID id, - const GURL& url) { - DCHECK(HasItemController(id)); - LauncherItemController* controller = id_to_item_controller_map_[id]; - - int index = model_->ItemIndexByID(id); - if (index == -1) { - NOTREACHED() << "Invalid launcher id"; - return; - } - - ash::LauncherItemType type = model_->items()[index].type; - if (type == ash::TYPE_APP_SHORTCUT) { - AppShortcutLauncherItemController* app_controller = - static_cast<AppShortcutLauncherItemController*>(controller); - app_controller->set_refocus_url(url); - } else { - NOTREACHED() << "Invalid launcher type"; - } -} - -const Extension* ChromeLauncherControllerPerBrowser::GetExtensionForAppID( - const std::string& app_id) const { - return profile_->GetExtensionService()->GetInstalledExtension(app_id); -} - -void ChromeLauncherControllerPerBrowser::ActivateWindowOrMinimizeIfActive( - ui::BaseWindow* window, - bool allow_minimize) { - window->Show(); - window->Activate(); -} - -void ChromeLauncherControllerPerBrowser::BrowserShortcutClicked( - int event_flags) { -#if defined(OS_CHROMEOS) - chromeos::default_pinned_apps_field_trial::RecordShelfClick( - chromeos::default_pinned_apps_field_trial::CHROME); -#endif - if (event_flags & ui::EF_CONTROL_DOWN) { - CreateNewWindow(); - return; - } - - Browser* last_browser = chrome::FindTabbedBrowser( - GetProfileForNewWindows(), true, chrome::HOST_DESKTOP_TYPE_ASH); - - if (!last_browser) { - CreateNewWindow(); - return; - } - - aura::Window* window = last_browser->window()->GetNativeWindow(); - window->Show(); - ash::wm::ActivateWindow(window); -} - -void ChromeLauncherControllerPerBrowser::ItemSelected( - const ash::LauncherItem& item, - const ui::Event& event) { - if (item.type == ash::TYPE_BROWSER_SHORTCUT) { - BrowserShortcutClicked(event.flags()); - return; - } - - DCHECK(HasItemController(item.id)); - LauncherItemController* item_controller = id_to_item_controller_map_[item.id]; -#if defined(OS_CHROMEOS) - if (!item_controller->app_id().empty()) { - chromeos::default_pinned_apps_field_trial::RecordShelfAppClick( - item_controller->app_id()); - } -#endif - item_controller->Clicked(event); -} - -string16 ChromeLauncherControllerPerBrowser::GetTitle( - const ash::LauncherItem& item) { - if (item.type == ash::TYPE_BROWSER_SHORTCUT) - return l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); - - DCHECK(HasItemController(item.id)); - return id_to_item_controller_map_[item.id]->GetTitle(); -} - -ui::MenuModel* ChromeLauncherControllerPerBrowser::CreateContextMenu( - const ash::LauncherItem& item, - aura::RootWindow* root_window) { - return new LauncherContextMenu(this, &item, root_window); -} - -ash::LauncherMenuModel* -ChromeLauncherControllerPerBrowser::CreateApplicationMenu( - const ash::LauncherItem& item, - int event_flags) { - // Not used by this launcher type. - return NULL; -} - -ash::LauncherID ChromeLauncherControllerPerBrowser::GetIDByWindow( - aura::Window* window) { - for (IDToItemControllerMap::const_iterator i = - id_to_item_controller_map_.begin(); - i != id_to_item_controller_map_.end(); ++i) { - if (i->second->IsCurrentlyShownInWindow(window)) - return i->first; - } - return 0; -} - -bool ChromeLauncherControllerPerBrowser::IsDraggable( - const ash::LauncherItem& item) { - return item.type == ash::TYPE_APP_SHORTCUT ? CanPin() : true; -} - -bool ChromeLauncherControllerPerBrowser::ShouldShowTooltip( - const ash::LauncherItem& item) { - if (item.type == ash::TYPE_APP_PANEL && - id_to_item_controller_map_[item.id]->IsVisible()) - return false; - return true; -} - -void ChromeLauncherControllerPerBrowser::OnLauncherCreated( - ash::Launcher* launcher) { - launchers_.insert(launcher); - launcher->shelf_widget()->shelf_layout_manager()->AddObserver(this); -} - -void ChromeLauncherControllerPerBrowser::OnLauncherDestroyed( - ash::Launcher* launcher) { - launchers_.erase(launcher); - // RemoveObserver is not called here, since by the time this method is called - // Launcher is already in its destructor. -} - -void ChromeLauncherControllerPerBrowser::LauncherItemAdded(int index) { -} - -void ChromeLauncherControllerPerBrowser::LauncherItemRemoved( - int index, - ash::LauncherID id) { -} - -void ChromeLauncherControllerPerBrowser::LauncherItemMoved( - int start_index, - int target_index) { - ash::LauncherID id = model_->items()[target_index].id; - if (HasItemController(id) && IsPinned(id)) - PersistPinnedState(); - else if (!HasItemController(id) && - model_->items()[target_index].type == ash::TYPE_BROWSER_SHORTCUT) - PersistPinnedState(); -} - -void ChromeLauncherControllerPerBrowser::LauncherItemChanged( - int index, - const ash::LauncherItem& old_item) { - ash::LauncherID id = model_->items()[index].id; - id_to_item_controller_map_[id]->LauncherItemChanged(index, old_item); -} - -void ChromeLauncherControllerPerBrowser::LauncherStatusChanged() { -} - -void ChromeLauncherControllerPerBrowser::Observe( - int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { - switch (type) { - case chrome::NOTIFICATION_EXTENSION_LOADED: { - const Extension* extension = - content::Details<const Extension>(details).ptr(); - if (IsAppPinned(extension->id())) { - // Clear and re-fetch to ensure icon is up-to-date. - app_icon_loader_->ClearImage(extension->id()); - app_icon_loader_->FetchImage(extension->id()); - } - - UpdateAppLaunchersFromPref(); - break; - } - case chrome::NOTIFICATION_EXTENSION_UNLOADED: { - const content::Details<extensions::UnloadedExtensionInfo>& unload_info( - details); - const Extension* extension = unload_info->extension; - if (IsAppPinned(extension->id())) { - if (unload_info->reason == extension_misc::UNLOAD_REASON_UNINSTALL) { - DoUnpinAppsWithID(extension->id()); - app_icon_loader_->ClearImage(extension->id()); - } else { - app_icon_loader_->UpdateImage(extension->id()); - } - } - break; - } - default: - NOTREACHED() << "Unexpected notification type=" << type; - } -} - -void ChromeLauncherControllerPerBrowser::OnShelfAlignmentChanged( - aura::RootWindow* root_window) { - const char* pref_value = NULL; - switch (ash::Shell::GetInstance()->GetShelfAlignment(root_window)) { - case ash::SHELF_ALIGNMENT_BOTTOM: - pref_value = ash::kShelfAlignmentBottom; - break; - case ash::SHELF_ALIGNMENT_LEFT: - pref_value = ash::kShelfAlignmentLeft; - break; - case ash::SHELF_ALIGNMENT_RIGHT: - pref_value = ash::kShelfAlignmentRight; - break; - case ash::SHELF_ALIGNMENT_TOP: - pref_value = ash::kShelfAlignmentTop; - break; - } - - UpdatePerDisplayPref( - profile_->GetPrefs(), root_window, prefs::kShelfAlignment, pref_value); - - if (root_window == ash::Shell::GetPrimaryRootWindow()) { - // See comment in |kShelfAlignment| about why we have two prefs here. - profile_->GetPrefs()->SetString(prefs::kShelfAlignmentLocal, pref_value); - profile_->GetPrefs()->SetString(prefs::kShelfAlignment, pref_value); - } -} - -void ChromeLauncherControllerPerBrowser::OnDisplayConfigurationChanging() { -} - -void ChromeLauncherControllerPerBrowser::OnDisplayConfigurationChanged() { - SetShelfBehaviorsFromPrefs(); -} - -void ChromeLauncherControllerPerBrowser::OnIsSyncingChanged() { - PrefServiceSyncable* prefs = PrefServiceSyncable::FromProfile(profile_); - MaybePropagatePrefToLocal(prefs, - prefs::kShelfAlignmentLocal, - prefs::kShelfAlignment); - MaybePropagatePrefToLocal(prefs, - prefs::kShelfAutoHideBehaviorLocal, - prefs::kShelfAutoHideBehavior); -} - -void ChromeLauncherControllerPerBrowser::OnAppSyncUIStatusChanged() { - if (app_sync_ui_state_->status() == AppSyncUIState::STATUS_SYNCING) - model_->SetStatus(ash::LauncherModel::STATUS_LOADING); - else - model_->SetStatus(ash::LauncherModel::STATUS_NORMAL); -} - -void ChromeLauncherControllerPerBrowser::ExtensionEnableFlowFinished() { - LaunchApp(extension_enable_flow_->extension_id(), ui::EF_NONE); - extension_enable_flow_.reset(); -} - -void ChromeLauncherControllerPerBrowser::ExtensionEnableFlowAborted( - bool user_initiated) { - extension_enable_flow_.reset(); -} - -void ChromeLauncherControllerPerBrowser::PersistPinnedState() { - if (ignore_persist_pinned_state_change_) - return; - // It is a coding error to call PersistPinnedState() if the pinned apps are - // not user-editable. The code should check earlier and not perform any - // modification actions that trigger persisting the state. - if (!CanPin()) { - NOTREACHED() << "Can't pin but pinned state being updated"; - return; - } - - // Mutating kPinnedLauncherApps is going to notify us and trigger us to - // process the change. We don't want that to happen so remove ourselves as a - // listener. - pref_change_registrar_.Remove(prefs::kPinnedLauncherApps); - { - ListPrefUpdate updater(profile_->GetPrefs(), prefs::kPinnedLauncherApps); - updater->Clear(); - for (size_t i = 0; i < model_->items().size(); ++i) { - if (model_->items()[i].type == ash::TYPE_APP_SHORTCUT) { - ash::LauncherID id = model_->items()[i].id; - if (HasItemController(id) && IsPinned(id)) { - base::DictionaryValue* app_value = ash::CreateAppDict( - id_to_item_controller_map_[id]->app_id()); - if (app_value) - updater->Append(app_value); - } - } else if (model_->items()[i].type == ash::TYPE_BROWSER_SHORTCUT) { - SetChromeIconIndexToPref(i); - } - } - } - pref_change_registrar_.Add( - prefs::kPinnedLauncherApps, - base::Bind(&ChromeLauncherControllerPerBrowser:: - UpdateAppLaunchersFromPref, - base::Unretained(this))); -} - -ash::LauncherModel* ChromeLauncherControllerPerBrowser::model() { - return model_; -} - -Profile* ChromeLauncherControllerPerBrowser::profile() { - return profile_; -} - -Profile* ChromeLauncherControllerPerBrowser::GetProfileForNewWindows() { - return ProfileManager::GetDefaultProfileOrOffTheRecord(); -} - -void ChromeLauncherControllerPerBrowser::LauncherItemClosed( - ash::LauncherID id) { - IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); - DCHECK(iter != id_to_item_controller_map_.end()); - app_icon_loader_->ClearImage(iter->second->app_id()); - iter->second->OnRemoved(); - id_to_item_controller_map_.erase(iter); - model_->RemoveItemAt(model_->ItemIndexByID(id)); -} - -void ChromeLauncherControllerPerBrowser::DoPinAppWithID( - const std::string& app_id) { - // If there is an item, do nothing and return. - if (IsAppPinned(app_id)) - return; - - ash::LauncherID launcher_id = GetLauncherIDForAppID(app_id); - if (launcher_id) { - // App item exists, pin it - Pin(launcher_id); - } else { - // Otherwise, create a shortcut item for it. - CreateAppShortcutLauncherItem(app_id, model_->item_count()); - if (CanPin()) - PersistPinnedState(); - } -} - -void ChromeLauncherControllerPerBrowser::DoUnpinAppsWithID( - const std::string& app_id) { - for (IDToItemControllerMap::iterator i = id_to_item_controller_map_.begin(); - i != id_to_item_controller_map_.end(); ) { - IDToItemControllerMap::iterator current(i); - ++i; - if (current->second->app_id() == app_id && IsPinned(current->first)) - Unpin(current->first); - } -} - -void ChromeLauncherControllerPerBrowser::UpdateAppLaunchersFromPref() { - // Construct a vector representation of to-be-pinned apps from the pref. - std::vector<std::string> pinned_apps; - int chrome_icon_index = GetChromeIconIndexFromPref(); - const base::ListValue* pinned_apps_pref = - profile_->GetPrefs()->GetList(prefs::kPinnedLauncherApps); - for (base::ListValue::const_iterator it(pinned_apps_pref->begin()); - it != pinned_apps_pref->end(); ++it) { - // To preserve the Chrome icon position, we insert a dummy slot for it - if - // the model has a Chrome item. While initializing we can come here with no - // item in which case the count would be 1 or below. - if (it - pinned_apps_pref->begin() == chrome_icon_index && - model_->item_count() > 1) { - pinned_apps.push_back(extension_misc::kChromeAppId); - } - DictionaryValue* app = NULL; - std::string app_id; - if ((*it)->GetAsDictionary(&app) && - app->GetString(ash::kPinnedAppsPrefAppIDPath, &app_id) && - std::find(pinned_apps.begin(), pinned_apps.end(), app_id) == - pinned_apps.end() && - app_tab_helper_->IsValidID(app_id)) { - pinned_apps.push_back(app_id); - } - } - - // Walk the model and |pinned_apps| from the pref lockstep, adding and - // removing items as necessary. NB: This code uses plain old indexing instead - // of iterators because of model mutations as part of the loop. - std::vector<std::string>::const_iterator pref_app_id(pinned_apps.begin()); - int index = 0; - int max_index = model_->item_count(); - if (ash::switches::UseAlternateShelfLayout()) { - ++index; - ++max_index; - } - for (; index < model_->item_count() && pref_app_id != pinned_apps.end(); - ++index) { - // If the next app launcher according to the pref is present in the model, - // delete all app launcher entries in between. - if (*pref_app_id == extension_misc::kChromeAppId || - IsAppPinned(*pref_app_id)) { - for (; index < model_->item_count(); ++index) { - const ash::LauncherItem& item(model_->items()[index]); - if (item.type != ash::TYPE_APP_SHORTCUT && - item.type != ash::TYPE_BROWSER_SHORTCUT) - continue; - - IDToItemControllerMap::const_iterator entry = - id_to_item_controller_map_.find(item.id); - if ((extension_misc::kChromeAppId == *pref_app_id && - item.type == ash::TYPE_BROWSER_SHORTCUT) || - (entry != id_to_item_controller_map_.end() && - entry->second->app_id() == *pref_app_id)) { - ++pref_app_id; - break; - } else { - if (item.type == ash::TYPE_BROWSER_SHORTCUT) { - // We cannot delete the browser shortcut. As such we move it up by - // one. To avoid any side effects from our pinned state observer, we - // do not call the model directly. - MoveItemWithoutPinnedStateChangeNotification(index, index + 1); - } else { - LauncherItemClosed(item.id); - --max_index; - } - --index; - } - } - // If the item wasn't found, that means id_to_item_controller_map_ - // is out of sync. - DCHECK(index < model_->item_count()); - } else { - // This app wasn't pinned before, insert a new entry. - ash::LauncherID id = CreateAppShortcutLauncherItem(*pref_app_id, index); - index = model_->ItemIndexByID(id); - ++pref_app_id; - } - } - - // Remove any trailing existing items. - while (index < model_->item_count()) { - const ash::LauncherItem& item(model_->items()[index]); - if (item.type == ash::TYPE_APP_SHORTCUT) - LauncherItemClosed(item.id); - else - ++index; - } - - // Append unprocessed items from the pref to the end of the model. - for (; pref_app_id != pinned_apps.end(); ++pref_app_id) { - // Ignore the chrome icon. - if (*pref_app_id != extension_misc::kChromeAppId) - DoPinAppWithID(*pref_app_id); - } -} - -void ChromeLauncherControllerPerBrowser::SetShelfAutoHideBehaviorPrefs( - ash::ShelfAutoHideBehavior behavior, - aura::RootWindow* root_window) { - const char* value = NULL; - switch (behavior) { - case ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS: - value = ash::kShelfAutoHideBehaviorAlways; - break; - case ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER: - value = ash::kShelfAutoHideBehaviorNever; - break; - case ash::SHELF_AUTO_HIDE_ALWAYS_HIDDEN: - // This one should not be a valid preference option for now. We only want - // to completely hide it when we run app mode. - NOTREACHED(); - return; - } - - UpdatePerDisplayPref( - profile_->GetPrefs(), root_window, prefs::kShelfAutoHideBehavior, value); - - if (root_window == ash::Shell::GetPrimaryRootWindow()) { - // See comment in |kShelfAlignment| about why we have two prefs here. - profile_->GetPrefs()->SetString(prefs::kShelfAutoHideBehaviorLocal, value); - profile_->GetPrefs()->SetString(prefs::kShelfAutoHideBehavior, value); - } -} - -void ChromeLauncherControllerPerBrowser::SetShelfAutoHideBehaviorFromPrefs() { - ash::Shell::RootWindowList root_windows = ash::Shell::GetAllRootWindows(); - - for (ash::Shell::RootWindowList::const_iterator iter = root_windows.begin(); - iter != root_windows.end(); ++iter) { - ash::Shell::GetInstance()->SetShelfAutoHideBehavior( - GetShelfAutoHideBehavior(*iter), *iter); - } -} - -void ChromeLauncherControllerPerBrowser::SetShelfAlignmentFromPrefs() { - if (!ash::ShelfWidget::ShelfAlignmentAllowed()) - return; - - ash::Shell::RootWindowList root_windows = ash::Shell::GetAllRootWindows(); - - for (ash::Shell::RootWindowList::const_iterator iter = root_windows.begin(); - iter != root_windows.end(); ++iter) { - // See comment in |kShelfAlignment| as to why we consider two prefs. - const std::string alignment_value( - GetPrefForRootWindow(profile_->GetPrefs(), - *iter, - prefs::kShelfAlignmentLocal, - prefs::kShelfAlignment)); - ash::ShelfAlignment alignment = ash::SHELF_ALIGNMENT_BOTTOM; - if (alignment_value == ash::kShelfAlignmentLeft) - alignment = ash::SHELF_ALIGNMENT_LEFT; - else if (alignment_value == ash::kShelfAlignmentRight) - alignment = ash::SHELF_ALIGNMENT_RIGHT; - else if (alignment_value == ash::kShelfAlignmentTop) - alignment = ash::SHELF_ALIGNMENT_TOP; - ash::Shell::GetInstance()->SetShelfAlignment(alignment, *iter); - } -} - -void ChromeLauncherControllerPerBrowser::SetShelfBehaviorsFromPrefs() { - SetShelfAutoHideBehaviorFromPrefs(); - SetShelfAlignmentFromPrefs(); -} - -WebContents* ChromeLauncherControllerPerBrowser::GetLastActiveWebContents( - const std::string& app_id) { - AppIDToWebContentsListMap::const_iterator i = - app_id_to_web_contents_list_.find(app_id); - if (i == app_id_to_web_contents_list_.end()) - return NULL; - DCHECK_GT(i->second.size(), 0u); - return *i->second.begin(); -} - -ash::LauncherID ChromeLauncherControllerPerBrowser::InsertAppLauncherItem( - LauncherItemController* controller, - const std::string& app_id, - ash::LauncherItemStatus status, - int index) { - ash::LauncherID id = model_->next_id(); - DCHECK(!HasItemController(id)); - DCHECK(controller); - id_to_item_controller_map_[id] = controller; - controller->set_launcher_id(id); - - ash::LauncherItem item; - item.type = controller->GetLauncherItemType(); - item.is_incognito = false; - item.image = extensions::IconsInfo::GetDefaultAppIcon(); - - WebContents* active_tab = GetLastActiveWebContents(app_id); - if (active_tab) { - Browser* browser = chrome::FindBrowserWithWebContents(active_tab); - DCHECK(browser); - if (browser->window()->IsActive()) - status = ash::STATUS_ACTIVE; - else - status = ash::STATUS_RUNNING; - } - item.status = status; - - model_->AddAt(index, item); - - app_icon_loader_->FetchImage(app_id); - - return id; -} - -bool ChromeLauncherControllerPerBrowser::HasItemController( - ash::LauncherID id) const { - return id_to_item_controller_map_.find(id) != - id_to_item_controller_map_.end(); -} - -ash::LauncherID -ChromeLauncherControllerPerBrowser::CreateBrowserShortcutLauncherItem() { - ash::LauncherItem browser_shortcut; - browser_shortcut.type = ash::TYPE_BROWSER_SHORTCUT; - browser_shortcut.is_incognito = false; - ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - browser_shortcut.image = *rb.GetImageSkiaNamed(IDR_PRODUCT_LOGO_32); - ash::LauncherID id = model_->next_id(); - size_t index = GetChromeIconIndexFromPref(); - model_->AddAt(index, browser_shortcut); - return id; -} - -void ChromeLauncherControllerPerBrowser::SetChromeIconIndexToPref(int index) { - profile_->GetPrefs()->SetInteger(prefs::kShelfChromeIconIndex, index); -} - -int ChromeLauncherControllerPerBrowser::GetChromeIconIndexFromPref() const { - size_t index = profile_->GetPrefs()->GetInteger(prefs::kShelfChromeIconIndex); - const base::ListValue* pinned_apps_pref = - profile_->GetPrefs()->GetList(prefs::kPinnedLauncherApps); - if (ash::switches::UseAlternateShelfLayout()) - return std::max(static_cast<size_t>(1), - std::min(pinned_apps_pref->GetSize(), index)); - return std::max(static_cast<size_t>(0), - std::min(pinned_apps_pref->GetSize(), index)); -} - -ash::LauncherID -ChromeLauncherControllerPerBrowser::CreateAppShortcutLauncherItem( - const std::string& app_id, - int index) { - AppShortcutLauncherItemController* controller = - new AppShortcutLauncherItemController(app_id, this); - ash::LauncherID launcher_id = InsertAppLauncherItem( - controller, app_id, ash::STATUS_CLOSED, index); - return launcher_id; -} - -void ChromeLauncherControllerPerBrowser::SetAppTabHelperForTest( - AppTabHelper* helper) { - app_tab_helper_.reset(helper); -} - -void ChromeLauncherControllerPerBrowser::SetAppIconLoaderForTest( - extensions::AppIconLoader* loader) { - app_icon_loader_.reset(loader); -} - -const std::string& -ChromeLauncherControllerPerBrowser::GetAppIdFromLauncherIdForTest( - ash::LauncherID id) { - return id_to_item_controller_map_[id]->app_id(); -} - -void ChromeLauncherControllerPerBrowser:: - MoveItemWithoutPinnedStateChangeNotification(int source_index, - int target_index) { - base::AutoReset<bool> auto_reset(&ignore_persist_pinned_state_change_, true); - model_->Move(source_index, target_index); -} diff --git a/chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_browser.h b/chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_browser.h deleted file mode 100644 index 0204501..0000000 --- a/chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_browser.h +++ /dev/null @@ -1,430 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_PER_BROWSER_H_ -#define CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_PER_BROWSER_H_ - -#include <list> -#include <map> -#include <string> - -#include "ash/display/display_controller.h" -#include "ash/launcher/launcher_delegate.h" -#include "ash/launcher/launcher_model_observer.h" -#include "ash/launcher/launcher_types.h" -#include "ash/shelf/shelf_layout_manager_observer.h" -#include "ash/shelf/shelf_types.h" -#include "ash/shell_observer.h" -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "base/memory/scoped_ptr.h" -#include "base/prefs/pref_change_registrar.h" -#include "chrome/browser/extensions/extension_prefs.h" -#include "chrome/browser/prefs/pref_service_syncable_observer.h" -#include "chrome/browser/ui/ash/app_sync_ui_state_observer.h" -#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" -#include "chrome/browser/ui/extensions/extension_enable_flow_delegate.h" -#include "content/public/browser/notification_observer.h" -#include "content/public/browser/notification_registrar.h" -#include "ui/aura/window_observer.h" - -class AppSyncUIState; -class Browser; -class BrowserLauncherItemControllerTest; -class ExtensionEnableFlow; -class LauncherItemController; -class Profile; -class ShellWindowLauncherController; - -namespace ash { -class LauncherModel; -} - -namespace aura { -class Window; -} - -namespace content { -class WebContents; -} - -namespace ui { -class BaseWindow; -} - -// ChromeLauncherControllerPerBrowser manages the launcher items needed for -// content windows. Launcher items have a type, an optional app id, and a -// controller. This incarnation manages the items on a per browser base using -// browser proxies and application icons. -// * Tabbed browsers and browser app windows have BrowserLauncherItemController, -// owned by the BrowserView instance. -// * App shell windows have ShellWindowLauncherItemController, owned by -// ShellWindowLauncherController. -// * Shortcuts have no LauncherItemController. -class ChromeLauncherControllerPerBrowser - : public ash::LauncherModelObserver, - public ash::ShellObserver, - public ash::DisplayController::Observer, - public ChromeLauncherController, - public content::NotificationObserver, - public PrefServiceSyncableObserver, - public AppSyncUIStateObserver, - public ExtensionEnableFlowDelegate, - public ash::ShelfLayoutManagerObserver { - public: - ChromeLauncherControllerPerBrowser(Profile* profile, - ash::LauncherModel* model); - virtual ~ChromeLauncherControllerPerBrowser(); - - // ChromeLauncherController overrides: - - // Initializes this ChromeLauncherControllerPerBrowser. - virtual void Init() OVERRIDE; - - // Returns the new per application interface of the given launcher. If it is - // a per browser (old) controller, it will return NULL; - // TODO(skuhne): Remove when we rip out the old launcher. - virtual ChromeLauncherControllerPerApp* GetPerAppInterface() OVERRIDE; - - // Creates a new tabbed item on the launcher for |controller|. - virtual ash::LauncherID CreateTabbedLauncherItem( - LauncherItemController* controller, - IncognitoState is_incognito, - ash::LauncherItemStatus status) OVERRIDE; - - // Creates a new app item on the launcher for |controller|. - virtual ash::LauncherID CreateAppLauncherItem( - LauncherItemController* controller, - const std::string& app_id, - ash::LauncherItemStatus status) OVERRIDE; - - // Updates the running status of an item. - virtual void SetItemStatus(ash::LauncherID id, - ash::LauncherItemStatus status) OVERRIDE; - - // Updates the controller associated with id (which should be a shortcut). - // |controller| remains owned by caller. - virtual void SetItemController(ash::LauncherID id, - LauncherItemController* controller) OVERRIDE; - - // Closes or unpins the launcher item. - virtual void CloseLauncherItem(ash::LauncherID id) OVERRIDE; - - // Pins the specified id. Currently only supports platform apps. - virtual void Pin(ash::LauncherID id) OVERRIDE; - - // Unpins the specified id, closing if not running. - virtual void Unpin(ash::LauncherID id) OVERRIDE; - - // Returns true if the item identified by |id| is pinned. - virtual bool IsPinned(ash::LauncherID id) OVERRIDE; - - // Pins/unpins the specified id. - virtual void TogglePinned(ash::LauncherID id) OVERRIDE; - - // Returns true if the specified item can be pinned or unpinned. Only apps can - // be pinned. - virtual bool IsPinnable(ash::LauncherID id) const OVERRIDE; - - // If there is no launcher item in the launcher for application |app_id|, one - // gets created. The (existing or created) launcher items get then locked - // against a users un-pinning removal. - virtual void LockV1AppWithID(const std::string& app_id) OVERRIDE; - - // A previously locked launcher item of type |app_id| gets unlocked. If the - // lock count reaches 0 and the item is not pinned it will go away. - virtual void UnlockV1AppWithID(const std::string& app_id) OVERRIDE; - - // Requests that the launcher item controller specified by |id| open a new - // instance of the app. |event_flags| holds the flags of the event which - // triggered this command. - virtual void Launch(ash::LauncherID id, int event_flags) OVERRIDE; - - // Closes the specified item. - virtual void Close(ash::LauncherID id) OVERRIDE; - - // Returns true if the specified item is open. - virtual bool IsOpen(ash::LauncherID id) OVERRIDE; - - // Returns true if the specified item is for a platform app. - virtual bool IsPlatformApp(ash::LauncherID id) OVERRIDE; - - // Opens a new instance of the application identified by |app_id|. - // Used by the app-list, and by pinned-app launcher items. - virtual void LaunchApp(const std::string& app_id, int event_flags) OVERRIDE; - - // If |app_id| is running, reactivates the app's most recently active window, - // otherwise launches and activates the app. - // Used by the app-list, and by pinned-app launcher items. - virtual void ActivateApp(const std::string& app_id, int event_flags) OVERRIDE; - - // Returns the launch type of app for the specified id. - virtual extensions::ExtensionPrefs::LaunchType GetLaunchType( - ash::LauncherID id) OVERRIDE; - - // Returns the id of the app for the specified tab. - virtual std::string GetAppID(content::WebContents* tab) OVERRIDE; - - virtual ash::LauncherID GetLauncherIDForAppID( - const std::string& app_id) OVERRIDE; - virtual std::string GetAppIDForLauncherID(ash::LauncherID id) OVERRIDE; - - // Set the image for a specific launcher item (e.g. when set by the app). - virtual void SetLauncherItemImage(ash::LauncherID launcher_id, - const gfx::ImageSkia& image) OVERRIDE; - - // Returns true if a pinned launcher item with given |app_id| could be found. - virtual bool IsAppPinned(const std::string& app_id) OVERRIDE; - - // Pins an app with |app_id| to launcher. If there is a running instance in - // launcher, the running instance is pinned. If there is no running instance, - // a new launcher item is created and pinned. - virtual void PinAppWithID(const std::string& app_id) OVERRIDE; - - // Updates the launche type of the app for the specified id to |launch_type|. - virtual void SetLaunchType( - ash::LauncherID id, - extensions::ExtensionPrefs::LaunchType launch_type) OVERRIDE; - - // Unpins any app items whose id is |app_id|. - virtual void UnpinAppsWithID(const std::string& app_id) OVERRIDE; - - // Returns true if the user is currently logged in as a guest. - virtual bool IsLoggedInAsGuest() OVERRIDE; - - // Invoked when user clicks on button in the launcher and there is no last - // used window (or CTRL is held with the click). - virtual void CreateNewWindow() OVERRIDE; - - // Invoked when the user clicks on button in the launcher to create a new - // incognito window. - virtual void CreateNewIncognitoWindow() OVERRIDE; - - // Checks whether the user is allowed to pin apps. Pinning may be disallowed - // by policy in case there is a pre-defined set of pinned apps. - virtual bool CanPin() const OVERRIDE; - - // Updates the pinned pref state. The pinned state consists of a list pref. - // Each item of the list is a dictionary. The key |kAppIDPath| gives the - // id of the app. - virtual void PersistPinnedState() OVERRIDE; - - virtual ash::LauncherModel* model() OVERRIDE; - - virtual Profile* profile() OVERRIDE; - - // Gets the shelf auto-hide behavior on |root_window|. - virtual ash::ShelfAutoHideBehavior GetShelfAutoHideBehavior( - aura::RootWindow* root_window) const OVERRIDE; - - // Returns |true| if the user is allowed to modify the shelf auto-hide - // behavior on |root_window|. - virtual bool CanUserModifyShelfAutoHideBehavior( - aura::RootWindow* root_window) const OVERRIDE; - - // Toggles the shelf auto-hide behavior on |root_window|. Does nothing if the - // user is not allowed to modify the auto-hide behavior. - virtual void ToggleShelfAutoHideBehavior( - aura::RootWindow* root_window) OVERRIDE; - - // The tab no longer represents its previously identified application. - virtual void RemoveTabFromRunningApp(content::WebContents* tab, - const std::string& app_id) OVERRIDE; - - // Notify the controller that the state of an non platform app's tabs - // have changed, - virtual void UpdateAppState(content::WebContents* contents, - AppState app_state) OVERRIDE; - - // Limits application refocusing to urls that match |url| for |id|. - virtual void SetRefocusURLPatternForTest(ash::LauncherID id, - const GURL& url) OVERRIDE; - - // Returns the extension identified by |app_id|. - virtual const extensions::Extension* GetExtensionForAppID( - const std::string& app_id) const OVERRIDE; - - // Activates a |window|. If |allow_minimize| is true and the system allows - // it, the the window will get minimized instead. - virtual void ActivateWindowOrMinimizeIfActive(ui::BaseWindow* window, - bool allow_minimize) OVERRIDE; - - // ash::LauncherDelegate overrides: - virtual void ItemSelected(const ash::LauncherItem& item, - const ui::Event& event) OVERRIDE; - virtual string16 GetTitle(const ash::LauncherItem& item) OVERRIDE; - virtual ui::MenuModel* CreateContextMenu( - const ash::LauncherItem& item, aura::RootWindow* root) OVERRIDE; - virtual ash::LauncherMenuModel* CreateApplicationMenu( - const ash::LauncherItem& item, - int event_flags) OVERRIDE; - virtual ash::LauncherID GetIDByWindow(aura::Window* window) OVERRIDE; - virtual bool IsDraggable(const ash::LauncherItem& item) OVERRIDE; - virtual bool ShouldShowTooltip(const ash::LauncherItem& item) OVERRIDE; - virtual void OnLauncherCreated(ash::Launcher* launcher) OVERRIDE; - virtual void OnLauncherDestroyed(ash::Launcher* launcher) OVERRIDE; - - // ash::LauncherModelObserver overrides: - virtual void LauncherItemAdded(int index) OVERRIDE; - virtual void LauncherItemRemoved(int index, ash::LauncherID id) OVERRIDE; - virtual void LauncherItemMoved(int start_index, int target_index) OVERRIDE; - virtual void LauncherItemChanged(int index, - const ash::LauncherItem& old_item) OVERRIDE; - virtual void LauncherStatusChanged() OVERRIDE; - - // content::NotificationObserver overrides: - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; - - // ash::ShellObserver overrides: - virtual void OnShelfAlignmentChanged(aura::RootWindow* root_window) OVERRIDE; - - // ash::DisplayController::Observer overrides: - virtual void OnDisplayConfigurationChanging() OVERRIDE; - virtual void OnDisplayConfigurationChanged() OVERRIDE; - - // PrefServiceSyncableObserver overrides: - virtual void OnIsSyncingChanged() OVERRIDE; - - // AppSyncUIStateObserver overrides: - virtual void OnAppSyncUIStatusChanged() OVERRIDE; - - // ExtensionEnableFlowDelegate overrides: - virtual void ExtensionEnableFlowFinished() OVERRIDE; - virtual void ExtensionEnableFlowAborted(bool user_initiated) OVERRIDE; - - // extensions::AppIconLoader overrides: - virtual void SetAppImage(const std::string& app_id, - const gfx::ImageSkia& image) OVERRIDE; - - // ash::ShelfLayoutManagerObserver overrides: - virtual void OnAutoHideBehaviorChanged( - aura::RootWindow* root_window, - ash::ShelfAutoHideBehavior new_behavior) OVERRIDE; - - protected: - // ChromeLauncherController overrides: - - // Creates a new app shortcut item and controller on the launcher at |index|. - // Use kInsertItemAtEnd to add a shortcut as the last item. - virtual ash::LauncherID CreateAppShortcutLauncherItem( - const std::string& app_id, - int index) OVERRIDE; - - // Sets the AppTabHelper/AppIconLoader, taking ownership of the helper class. - // These are intended for testing. - virtual void SetAppTabHelperForTest(AppTabHelper* helper) OVERRIDE; - virtual void SetAppIconLoaderForTest( - extensions::AppIconLoader* loader) OVERRIDE; - virtual const std::string& GetAppIdFromLauncherIdForTest( - ash::LauncherID id) OVERRIDE; - - private: - friend class ChromeLauncherControllerPerBrowserTest; - - typedef std::map<ash::LauncherID, LauncherItemController*> - IDToItemControllerMap; - typedef std::list<content::WebContents*> WebContentsList; - typedef std::map<std::string, WebContentsList> AppIDToWebContentsListMap; - typedef std::map<content::WebContents*, std::string> WebContentsToAppIDMap; - - // Returns the profile used for new windows. - Profile* GetProfileForNewWindows(); - - // Invoked when the associated browser or app is closed. - void LauncherItemClosed(ash::LauncherID id); - - // Internal helpers for pinning and unpinning that handle both - // client-triggered and internal pinning operations. - void DoPinAppWithID(const std::string& app_id); - void DoUnpinAppsWithID(const std::string& app_id); - - // Re-syncs launcher model with prefs::kPinnedLauncherApps. - void UpdateAppLaunchersFromPref(); - - // Persists the shelf auto-hide behavior to prefs. - void SetShelfAutoHideBehaviorPrefs(ash::ShelfAutoHideBehavior behavior, - aura::RootWindow* root_window); - - // Sets the shelf auto-hide behavior from prefs. - void SetShelfAutoHideBehaviorFromPrefs(); - - // Sets the shelf alignment from prefs. - void SetShelfAlignmentFromPrefs(); - - // Sets both of auto-hide behavior and alignment from prefs. - void SetShelfBehaviorsFromPrefs(); - - // Returns the most recently active WebContents for an app. - content::WebContents* GetLastActiveWebContents(const std::string& app_id); - - // Creates an app launcher to insert at |index|. Note that |index| may be - // adjusted by the model to meet ordering constraints. - ash::LauncherID InsertAppLauncherItem( - LauncherItemController* controller, - const std::string& app_id, - ash::LauncherItemStatus status, - int index); - - bool HasItemController(ash::LauncherID id) const; - - // Create LauncherItem for Browser Shortcut. - ash::LauncherID CreateBrowserShortcutLauncherItem(); - - // Update browser shortcut's index. - void SetChromeIconIndexToPref(int index); - - // Get browser shortcut's index from pref. - int GetChromeIconIndexFromPref() const; - - // Invoked when browser shortcut is clicked. - void BrowserShortcutClicked(int event_flags); - - // Move an item internally (ignoring pinned state changes) from |index| to - // |target_index|. - void MoveItemWithoutPinnedStateChangeNotification(int source_index, - int target_index); - - ash::LauncherModel* model_; - - // Profile used for prefs and loading extensions. This is NOT necessarily the - // profile new windows are created with. - Profile* profile_; - - IDToItemControllerMap id_to_item_controller_map_; - - // Maintains activation order of web contents for each app. - AppIDToWebContentsListMap app_id_to_web_contents_list_; - - // Direct access to app_id for a web contents. - WebContentsToAppIDMap web_contents_to_app_id_; - - // Used to track shell windows. - scoped_ptr<ShellWindowLauncherController> shell_window_controller_; - - // Used to get app info for tabs. - scoped_ptr<AppTabHelper> app_tab_helper_; - - // Used to load the image for an app item. - scoped_ptr<extensions::AppIconLoader> app_icon_loader_; - - content::NotificationRegistrar notification_registrar_; - - PrefChangeRegistrar pref_change_registrar_; - - AppSyncUIState* app_sync_ui_state_; - - scoped_ptr<ExtensionEnableFlow> extension_enable_flow_; - - // Launchers that are currently being observed. - std::set<ash::Launcher*> launchers_; - - // If true, incoming pinned state changes should be ignored. - bool ignore_persist_pinned_state_change_; - - DISALLOW_COPY_AND_ASSIGN(ChromeLauncherControllerPerBrowser); -}; - -#endif // CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_PER_BROWSER_H_ diff --git a/chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_browser_unittest.cc b/chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_browser_unittest.cc deleted file mode 100644 index f91430b..0000000 --- a/chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_browser_unittest.cc +++ /dev/null @@ -1,462 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_browser.h" - -#include <algorithm> -#include <string> -#include <vector> - -#include "ash/launcher/launcher_model.h" -#include "base/command_line.h" -#include "base/compiler_specific.h" -#include "base/files/file_path.h" -#include "base/memory/scoped_ptr.h" -#include "base/run_loop.h" -#include "base/values.h" -#include "chrome/browser/extensions/extension_service.h" -#include "chrome/browser/extensions/test_extension_system.h" -#include "chrome/browser/ui/ash/chrome_launcher_prefs.h" -#include "chrome/browser/ui/ash/launcher/launcher_item_controller.h" -#include "chrome/common/extensions/extension.h" -#include "chrome/common/pref_names.h" -#include "chrome/test/base/testing_pref_service_syncable.h" -#include "chrome/test/base/testing_profile.h" -#include "content/public/test/test_browser_thread_bundle.h" -#include "testing/gtest/include/gtest/gtest.h" - -#if defined(OS_CHROMEOS) -#include "chrome/browser/chromeos/login/user_manager.h" -#include "chrome/browser/chromeos/settings/cros_settings.h" -#include "chrome/browser/chromeos/settings/device_settings_service.h" -#endif - -using extensions::Extension; -using extensions::Manifest; - -class ChromeLauncherControllerPerBrowserTest : public testing::Test { - protected: - ChromeLauncherControllerPerBrowserTest() - : profile_(new TestingProfile()), - extension_service_(NULL) { - DictionaryValue manifest; - manifest.SetString("name", "launcher controller test extension"); - manifest.SetString("version", "1"); - manifest.SetString("description", "for testing pinned apps"); - - extensions::TestExtensionSystem* extension_system( - static_cast<extensions::TestExtensionSystem*>( - extensions::ExtensionSystem::Get(profile_.get()))); - extension_service_ = extension_system->CreateExtensionService( - CommandLine::ForCurrentProcess(), base::FilePath(), false); - - std::string error; - extension1_ = Extension::Create(base::FilePath(), Manifest::UNPACKED, - manifest, - Extension::NO_FLAGS, - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", - &error); - extension2_ = Extension::Create(base::FilePath(), Manifest::UNPACKED, - manifest, - Extension::NO_FLAGS, - "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", - &error); - // Fake gmail extension. - extension3_ = Extension::Create(base::FilePath(), Manifest::UNPACKED, - manifest, - Extension::NO_FLAGS, - extension_misc::kGmailAppId, - &error); - // Fake search extension. - extension4_ = Extension::Create(base::FilePath(), Manifest::UNPACKED, - manifest, - Extension::NO_FLAGS, - extension_misc::kGoogleSearchAppId, - &error); - } - - virtual void TearDown() OVERRIDE { - profile_.reset(); - // Execute any pending deletion tasks. - base::RunLoop().RunUntilIdle(); - } - - void InsertPrefValue(base::ListValue* pref_value, - int index, - const std::string& extension_id) { - base::DictionaryValue* entry = new DictionaryValue(); - entry->SetString(ash::kPinnedAppsPrefAppIDPath, extension_id); - pref_value->Insert(index, entry); - } - - // Gets the currently configured app launchers from the controller. - void GetAppLaunchers(ChromeLauncherControllerPerBrowser* controller, - std::vector<std::string>* launchers) { - launchers->clear(); - for (ash::LauncherItems::const_iterator iter(model_.items().begin()); - iter != model_.items().end(); ++iter) { - ChromeLauncherControllerPerBrowser::IDToItemControllerMap::const_iterator - entry(controller->id_to_item_controller_map_.find(iter->id)); - if (iter->type == ash::TYPE_APP_SHORTCUT && - entry != controller->id_to_item_controller_map_.end()) { - launchers->push_back(entry->second->app_id()); - } - } - } - - std::string GetPinnedAppStatus( - ChromeLauncherController* launcher_controller) { - std::string result; - for (int i = 0; i < model_.item_count(); i++) { - switch (model_.items()[i].type) { - case ash::TYPE_APP_SHORTCUT: { - const std::string& app = - launcher_controller->GetAppIDForLauncherID( - model_.items()[i].id); - if (app == extension1_->id()) { - result += "App1, "; - EXPECT_TRUE(launcher_controller->IsAppPinned(extension1_->id())); - } else if (app == extension2_->id()) { - result += "App2, "; - EXPECT_TRUE(launcher_controller->IsAppPinned(extension2_->id())); - } else if (app == extension3_->id()) { - result += "App3, "; - EXPECT_TRUE(launcher_controller->IsAppPinned(extension3_->id())); - } else { - result += "unknown"; - } - break; - } - case ash::TYPE_BROWSER_SHORTCUT: - result += "Chrome, "; - break; - case ash::TYPE_APP_LIST: - result += "AppList"; - break; - default: - result += "Unknown"; - break; - } - } - return result; - } - - // Needed for extension service & friends to work. - content::TestBrowserThreadBundle thread_bundle_; - -#if defined OS_CHROMEOS - chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; - chromeos::ScopedTestCrosSettings test_cros_settings_; - chromeos::ScopedTestUserManager test_user_manager_; -#endif - - scoped_refptr<Extension> extension1_; - scoped_refptr<Extension> extension2_; - scoped_refptr<Extension> extension3_; - scoped_refptr<Extension> extension4_; - scoped_ptr<TestingProfile> profile_; - ash::LauncherModel model_; - - ExtensionService* extension_service_; - - DISALLOW_COPY_AND_ASSIGN(ChromeLauncherControllerPerBrowserTest); -}; - -TEST_F(ChromeLauncherControllerPerBrowserTest, DefaultApps) { - ChromeLauncherControllerPerBrowser launcher_controller(profile_.get(), - &model_); - launcher_controller.Init(); - - // Model should only contain the browser shortcut and app list items. - EXPECT_EQ(2, model_.item_count()); - EXPECT_FALSE(launcher_controller.IsAppPinned(extension1_->id())); - EXPECT_FALSE(launcher_controller.IsAppPinned(extension2_->id())); - EXPECT_FALSE(launcher_controller.IsAppPinned(extension3_->id())); - - // Installing |extension3_| should add it to the launcher - behind the - // chrome icon. - extension_service_->AddExtension(extension3_.get()); - EXPECT_EQ("Chrome, App3, AppList", GetPinnedAppStatus(&launcher_controller)); - EXPECT_FALSE(launcher_controller.IsAppPinned(extension1_->id())); - EXPECT_FALSE(launcher_controller.IsAppPinned(extension2_->id())); -} - -// Check that the restauration of launcher items is happening in the same order -// as the user has pinned them (on another system) when they are synced reverse -// order. -TEST_F(ChromeLauncherControllerPerBrowserTest, RestoreDefaultAppsReverseOrder) { - ChromeLauncherControllerPerBrowser launcher_controller(profile_.get(), - &model_); - launcher_controller.Init(); - - base::ListValue policy_value; - InsertPrefValue(&policy_value, 0, extension1_->id()); - InsertPrefValue(&policy_value, 1, extension2_->id()); - InsertPrefValue(&policy_value, 2, extension3_->id()); - profile_->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, - policy_value.DeepCopy()); - EXPECT_EQ(0, profile_->GetPrefs()->GetInteger(prefs::kShelfChromeIconIndex)); - // Model should only contain the browser shortcut and app list items. - EXPECT_FALSE(launcher_controller.IsAppPinned(extension1_->id())); - EXPECT_FALSE(launcher_controller.IsAppPinned(extension2_->id())); - EXPECT_FALSE(launcher_controller.IsAppPinned(extension3_->id())); - EXPECT_EQ("Chrome, AppList", GetPinnedAppStatus(&launcher_controller)); - - // Installing |extension3_| should add it to the launcher - behind the - // chrome icon. - ash::LauncherItem item; - extension_service_->AddExtension(extension3_.get()); - EXPECT_FALSE(launcher_controller.IsAppPinned(extension1_->id())); - EXPECT_FALSE(launcher_controller.IsAppPinned(extension2_->id())); - EXPECT_EQ("Chrome, App3, AppList", GetPinnedAppStatus(&launcher_controller)); - - // Installing |extension2_| should add it to the launcher - behind the - // chrome icon, but in first location. - extension_service_->AddExtension(extension2_.get()); - EXPECT_FALSE(launcher_controller.IsAppPinned(extension1_->id())); - EXPECT_EQ("Chrome, App2, App3, AppList", - GetPinnedAppStatus(&launcher_controller)); - - // Installing |extension1_| should add it to the launcher - behind the - // chrome icon, but in first location. - extension_service_->AddExtension(extension1_.get()); - EXPECT_EQ("Chrome, App1, App2, App3, AppList", - GetPinnedAppStatus(&launcher_controller)); -} - -// Check that the restauration of launcher items is happening in the same order -// as the user has pinned them (on another system) when they are synced random -// order. -TEST_F(ChromeLauncherControllerPerBrowserTest, RestoreDefaultAppsRandomOrder) { - ChromeLauncherControllerPerBrowser launcher_controller(profile_.get(), - &model_); - launcher_controller.Init(); - - base::ListValue policy_value; - InsertPrefValue(&policy_value, 0, extension1_->id()); - InsertPrefValue(&policy_value, 1, extension2_->id()); - InsertPrefValue(&policy_value, 2, extension3_->id()); - profile_->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, - policy_value.DeepCopy()); - EXPECT_EQ(0, profile_->GetPrefs()->GetInteger(prefs::kShelfChromeIconIndex)); - // Model should only contain the browser shortcut and app list items. - EXPECT_FALSE(launcher_controller.IsAppPinned(extension1_->id())); - EXPECT_FALSE(launcher_controller.IsAppPinned(extension2_->id())); - EXPECT_FALSE(launcher_controller.IsAppPinned(extension3_->id())); - EXPECT_EQ("Chrome, AppList", GetPinnedAppStatus(&launcher_controller)); - - // Installing |extension2_| should add it to the launcher - behind the - // chrome icon. - extension_service_->AddExtension(extension2_.get()); - EXPECT_FALSE(launcher_controller.IsAppPinned(extension1_->id())); - EXPECT_FALSE(launcher_controller.IsAppPinned(extension3_->id())); - EXPECT_EQ("Chrome, App2, AppList", GetPinnedAppStatus(&launcher_controller)); - - // Installing |extension1_| should add it to the launcher - behind the - // chrome icon, but in first location. - extension_service_->AddExtension(extension1_.get()); - EXPECT_FALSE(launcher_controller.IsAppPinned(extension3_->id())); - EXPECT_EQ("Chrome, App1, App2, AppList", - GetPinnedAppStatus(&launcher_controller)); - - // Installing |extension3_| should add it to the launcher - behind the - // chrome icon, but in first location. - extension_service_->AddExtension(extension3_.get()); - EXPECT_EQ("Chrome, App1, App2, App3, AppList", - GetPinnedAppStatus(&launcher_controller)); -} - -// Check that the restauration of launcher items is happening in the same order -// as the user has pinned / moved them (on another system) when they are synced -// random order - including the chrome icon. -TEST_F(ChromeLauncherControllerPerBrowserTest, - RestoreDefaultAppsRandomOrderChromeMoved) { - ChromeLauncherControllerPerBrowser launcher_controller(profile_.get(), - &model_); - launcher_controller.Init(); - base::ListValue policy_value; - InsertPrefValue(&policy_value, 0, extension1_->id()); - InsertPrefValue(&policy_value, 1, extension2_->id()); - InsertPrefValue(&policy_value, 2, extension3_->id()); - profile_->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, - policy_value.DeepCopy()); - profile_->GetTestingPrefService()->SetInteger(prefs::kShelfChromeIconIndex, - 1); - // Model should only contain the browser shortcut and app list items. - EXPECT_FALSE(launcher_controller.IsAppPinned(extension1_->id())); - EXPECT_FALSE(launcher_controller.IsAppPinned(extension2_->id())); - EXPECT_FALSE(launcher_controller.IsAppPinned(extension3_->id())); - EXPECT_EQ("Chrome, AppList", GetPinnedAppStatus(&launcher_controller)); - - // Installing |extension2_| should add it to the launcher - behind the - // chrome icon. - ash::LauncherItem item; - extension_service_->AddExtension(extension2_.get()); - EXPECT_FALSE(launcher_controller.IsAppPinned(extension1_->id())); - EXPECT_FALSE(launcher_controller.IsAppPinned(extension3_->id())); - EXPECT_EQ("Chrome, App2, AppList", GetPinnedAppStatus(&launcher_controller)); - - // Installing |extension1_| should add it to the launcher - behind the - // chrome icon, but in first location. - extension_service_->AddExtension(extension1_.get()); - EXPECT_FALSE(launcher_controller.IsAppPinned(extension3_->id())); - EXPECT_EQ("App1, Chrome, App2, AppList", - GetPinnedAppStatus(&launcher_controller)); - - // Installing |extension3_| should add it to the launcher - behind the - // chrome icon, but in first location. - extension_service_->AddExtension(extension3_.get()); - EXPECT_EQ("App1, Chrome, App2, App3, AppList", - GetPinnedAppStatus(&launcher_controller)); -} - -TEST_F(ChromeLauncherControllerPerBrowserTest, Policy) { - extension_service_->AddExtension(extension1_.get()); - extension_service_->AddExtension(extension3_.get()); - - base::ListValue policy_value; - InsertPrefValue(&policy_value, 0, extension1_->id()); - InsertPrefValue(&policy_value, 1, extension2_->id()); - profile_->GetTestingPrefService()->SetManagedPref(prefs::kPinnedLauncherApps, - policy_value.DeepCopy()); - - // Only |extension1_| should get pinned. |extension2_| is specified but not - // installed, and |extension3_| is part of the default set, but that shouldn't - // take effect when the policy override is in place. - ChromeLauncherControllerPerBrowser launcher_controller(profile_.get(), - &model_); - launcher_controller.Init(); - EXPECT_EQ(3, model_.item_count()); - EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_.items()[1].type); - EXPECT_TRUE(launcher_controller.IsAppPinned(extension1_->id())); - EXPECT_FALSE(launcher_controller.IsAppPinned(extension2_->id())); - EXPECT_FALSE(launcher_controller.IsAppPinned(extension3_->id())); - - EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, model_.items()[0].type); - EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_.items()[1].type); - EXPECT_EQ(ash::TYPE_APP_LIST, model_.items()[2].type); - - // Installing |extension2_| should add it to the launcher. - extension_service_->AddExtension(extension2_.get()); - EXPECT_EQ(4, model_.item_count()); - EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, model_.items()[0].type); - EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_.items()[1].type); - EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_.items()[2].type); - EXPECT_EQ(ash::TYPE_APP_LIST, model_.items()[3].type); - EXPECT_TRUE(launcher_controller.IsAppPinned(extension1_->id())); - EXPECT_TRUE(launcher_controller.IsAppPinned(extension2_->id())); - EXPECT_FALSE(launcher_controller.IsAppPinned(extension3_->id())); - - // Removing |extension1_| from the policy should be reflected in the launcher. - policy_value.Remove(0, NULL); - profile_->GetTestingPrefService()->SetManagedPref(prefs::kPinnedLauncherApps, - policy_value.DeepCopy()); - EXPECT_EQ(3, model_.item_count()); - EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_.items()[1].type); - EXPECT_FALSE(launcher_controller.IsAppPinned(extension1_->id())); - EXPECT_TRUE(launcher_controller.IsAppPinned(extension2_->id())); - EXPECT_FALSE(launcher_controller.IsAppPinned(extension3_->id())); -} - -TEST_F(ChromeLauncherControllerPerBrowserTest, UnpinWithUninstall) { - extension_service_->AddExtension(extension3_.get()); - extension_service_->AddExtension(extension4_.get()); - - ChromeLauncherControllerPerBrowser launcher_controller(profile_.get(), - &model_); - launcher_controller.Init(); - - EXPECT_TRUE(launcher_controller.IsAppPinned(extension3_->id())); - EXPECT_TRUE(launcher_controller.IsAppPinned(extension4_->id())); - - extension_service_->UnloadExtension(extension3_->id(), - extension_misc::UNLOAD_REASON_UNINSTALL); - - EXPECT_FALSE(launcher_controller.IsAppPinned(extension3_->id())); - EXPECT_TRUE(launcher_controller.IsAppPinned(extension4_->id())); -} - -TEST_F(ChromeLauncherControllerPerBrowserTest, PrefUpdates) { - extension_service_->AddExtension(extension2_.get()); - extension_service_->AddExtension(extension3_.get()); - extension_service_->AddExtension(extension4_.get()); - ChromeLauncherControllerPerBrowser controller(profile_.get(), &model_); - controller.Init(); - - std::vector<std::string> expected_launchers; - std::vector<std::string> actual_launchers; - base::ListValue pref_value; - profile_->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, - pref_value.DeepCopy()); - GetAppLaunchers(&controller, &actual_launchers); - EXPECT_EQ(expected_launchers, actual_launchers); - - // Unavailable extensions don't create launcher items. - InsertPrefValue(&pref_value, 0, extension1_->id()); - InsertPrefValue(&pref_value, 1, extension2_->id()); - InsertPrefValue(&pref_value, 2, extension4_->id()); - profile_->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, - pref_value.DeepCopy()); - expected_launchers.push_back(extension2_->id()); - expected_launchers.push_back(extension4_->id()); - GetAppLaunchers(&controller, &actual_launchers); - EXPECT_EQ(expected_launchers, actual_launchers); - - // Redundant pref entries show up only once. - InsertPrefValue(&pref_value, 2, extension3_->id()); - InsertPrefValue(&pref_value, 2, extension3_->id()); - InsertPrefValue(&pref_value, 5, extension3_->id()); - profile_->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, - pref_value.DeepCopy()); - expected_launchers.insert(expected_launchers.begin() + 1, extension3_->id()); - GetAppLaunchers(&controller, &actual_launchers); - EXPECT_EQ(expected_launchers, actual_launchers); - - // Order changes are reflected correctly. - pref_value.Clear(); - InsertPrefValue(&pref_value, 0, extension4_->id()); - InsertPrefValue(&pref_value, 1, extension3_->id()); - InsertPrefValue(&pref_value, 2, extension2_->id()); - profile_->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, - pref_value.DeepCopy()); - std::reverse(expected_launchers.begin(), expected_launchers.end()); - GetAppLaunchers(&controller, &actual_launchers); - EXPECT_EQ(expected_launchers, actual_launchers); - - // Clearing works. - pref_value.Clear(); - profile_->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, - pref_value.DeepCopy()); - expected_launchers.clear(); - GetAppLaunchers(&controller, &actual_launchers); - EXPECT_EQ(expected_launchers, actual_launchers); -} - -TEST_F(ChromeLauncherControllerPerBrowserTest, PendingInsertionOrder) { - extension_service_->AddExtension(extension1_.get()); - extension_service_->AddExtension(extension3_.get()); - ChromeLauncherControllerPerBrowser controller(profile_.get(), &model_); - controller.Init(); - - base::ListValue pref_value; - InsertPrefValue(&pref_value, 0, extension1_->id()); - InsertPrefValue(&pref_value, 1, extension2_->id()); - InsertPrefValue(&pref_value, 2, extension3_->id()); - profile_->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, - pref_value.DeepCopy()); - - std::vector<std::string> expected_launchers; - expected_launchers.push_back(extension1_->id()); - expected_launchers.push_back(extension3_->id()); - std::vector<std::string> actual_launchers; - - GetAppLaunchers(&controller, &actual_launchers); - EXPECT_EQ(expected_launchers, actual_launchers); - - // Install |extension2| and verify it shows up between the other two. - extension_service_->AddExtension(extension2_.get()); - expected_launchers.insert(expected_launchers.begin() + 1, extension2_->id()); - GetAppLaunchers(&controller, &actual_launchers); - EXPECT_EQ(expected_launchers, actual_launchers); -} diff --git a/chrome/browser/ui/ash/launcher/launcher_app_tab_helper.h b/chrome/browser/ui/ash/launcher/launcher_app_tab_helper.h index ec763bf..86368fc 100644 --- a/chrome/browser/ui/ash/launcher/launcher_app_tab_helper.h +++ b/chrome/browser/ui/ash/launcher/launcher_app_tab_helper.h @@ -8,7 +8,7 @@ #include <map> #include <string> -#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" +#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app.h" class Profile; diff --git a/chrome/browser/ui/ash/launcher/launcher_application_menu_item_model.cc b/chrome/browser/ui/ash/launcher/launcher_application_menu_item_model.cc index 61c9881..b380e97 100644 --- a/chrome/browser/ui/ash/launcher/launcher_application_menu_item_model.cc +++ b/chrome/browser/ui/ash/launcher/launcher_application_menu_item_model.cc @@ -4,7 +4,7 @@ #include "chrome/browser/ui/ash/launcher/launcher_application_menu_item_model.h" -#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app.h" +#include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h" LauncherApplicationMenuItemModel::LauncherApplicationMenuItemModel( ChromeLauncherAppMenuItems item_list) diff --git a/chrome/browser/ui/ash/launcher/launcher_application_menu_item_model.h b/chrome/browser/ui/ash/launcher/launcher_application_menu_item_model.h index 48816f4..46a483f 100644 --- a/chrome/browser/ui/ash/launcher/launcher_application_menu_item_model.h +++ b/chrome/browser/ui/ash/launcher/launcher_application_menu_item_model.h @@ -7,7 +7,12 @@ #include "ash/launcher/launcher_delegate.h" #include "base/memory/scoped_ptr.h" -#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app.h" +#include "base/memory/scoped_vector.h" + +class ChromeLauncherAppMenuItem; + +// A list of the elements which makes up a simple menu description. +typedef ScopedVector<ChromeLauncherAppMenuItem> ChromeLauncherAppMenuItems; // A menu model that builds the contents of a menu for a launcher item // containing a list of running applications. diff --git a/chrome/browser/ui/ash/launcher/launcher_context_menu.cc b/chrome/browser/ui/ash/launcher/launcher_context_menu.cc index 14930dd..e38fa7b 100644 --- a/chrome/browser/ui/ash/launcher/launcher_context_menu.cc +++ b/chrome/browser/ui/ash/launcher/launcher_context_menu.cc @@ -21,7 +21,7 @@ #include "chrome/browser/prefs/incognito_mode_prefs.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/ash/chrome_shell_delegate.h" -#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" +#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app.h" #include "chrome/common/chrome_switches.h" #include "content/public/common/context_menu_params.h" #include "grit/ash_strings.h" diff --git a/chrome/browser/ui/ash/launcher/launcher_context_menu_unittest.cc b/chrome/browser/ui/ash/launcher/launcher_context_menu_unittest.cc index dbcf723..9242e45 100644 --- a/chrome/browser/ui/ash/launcher/launcher_context_menu_unittest.cc +++ b/chrome/browser/ui/ash/launcher/launcher_context_menu_unittest.cc @@ -12,22 +12,19 @@ #include "chrome/app/chrome_command_ids.h" #include "chrome/browser/prefs/incognito_mode_prefs.h" #include "chrome/browser/profiles/profile.h" -#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" -#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_browser.h" +#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app.h" #include "chrome/test/base/testing_profile.h" #include "ui/aura/root_window.h" -class TestChromeLauncherControllerPerBrowser : - public ChromeLauncherControllerPerBrowser { +class TestChromeLauncherController : public ChromeLauncherController { public: - TestChromeLauncherControllerPerBrowser( - Profile* profile, ash::LauncherModel* model) - : ChromeLauncherControllerPerBrowser(profile, model) {} + TestChromeLauncherController(Profile* profile, ash::LauncherModel* model) + : ChromeLauncherController(profile, model) {} virtual bool IsLoggedInAsGuest() OVERRIDE { return false; } private: - DISALLOW_COPY_AND_ASSIGN(TestChromeLauncherControllerPerBrowser); + DISALLOW_COPY_AND_ASSIGN(TestChromeLauncherController); }; class LauncherContextMenuTest : public ash::test::AshTestBase { @@ -43,8 +40,7 @@ class LauncherContextMenuTest : public ash::test::AshTestBase { virtual void SetUp() OVERRIDE { ash::test::AshTestBase::SetUp(); controller_.reset( - new TestChromeLauncherControllerPerBrowser(profile(), - &launcher_model_)); + new TestChromeLauncherController(profile(), &launcher_model_)); } virtual void TearDown() OVERRIDE { diff --git a/chrome/browser/ui/ash/launcher/launcher_item_controller.cc b/chrome/browser/ui/ash/launcher/launcher_item_controller.cc index d0cb781..41855aa 100644 --- a/chrome/browser/ui/ash/launcher/launcher_item_controller.cc +++ b/chrome/browser/ui/ash/launcher/launcher_item_controller.cc @@ -8,7 +8,7 @@ #include "base/strings/utf_string_conversions.h" #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/profiles/profile.h" -#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" +#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app.h" #include "chrome/common/extensions/extension.h" LauncherItemController::LauncherItemController( diff --git a/chrome/browser/ui/ash/launcher/shell_window_launcher_controller.cc b/chrome/browser/ui/ash/launcher/shell_window_launcher_controller.cc index 618397c..cfd5a01 100644 --- a/chrome/browser/ui/ash/launcher/shell_window_launcher_controller.cc +++ b/chrome/browser/ui/ash/launcher/shell_window_launcher_controller.cc @@ -9,7 +9,7 @@ #include "ash/wm/window_util.h" #include "base/stl_util.h" #include "base/strings/stringprintf.h" -#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" +#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app.h" #include "chrome/browser/ui/ash/launcher/shell_window_launcher_item_controller.h" #include "ui/aura/client/activation_client.h" 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 b4d562d85..5ed3c6c 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 @@ -10,7 +10,6 @@ #include "ash/wm/window_util.h" #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h" #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_v2app.h" -#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app.h" #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h" #include "content/public/browser/web_contents.h" @@ -155,8 +154,7 @@ void ShellWindowLauncherItemController::Clicked(const ui::Event& event) { } else { ShowAndActivateOrMinimize(panel); } - } else if (launcher_controller()->GetPerAppInterface() || - shell_windows_.size() == 1) { + } else { ShellWindow* window_to_show = last_active_shell_window_ ? last_active_shell_window_ : shell_windows_.front(); // If the event was triggered by a keystroke, we try to advance to the next @@ -168,20 +166,6 @@ void ShellWindowLauncherItemController::Clicked(const ui::Event& event) { } else { ShowAndActivateOrMinimize(window_to_show); } - } else { - // TODO(stevenjb): Deprecate - if (!last_active_shell_window_ || - last_active_shell_window_->GetBaseWindow()->IsActive()) { - // Restore all windows since there is no other way to restore them. - for (ShellWindowList::iterator iter = shell_windows_.begin(); - iter != shell_windows_.end(); ++iter) { - ShellWindow* shell_window = *iter; - if (shell_window->GetBaseWindow()->IsMinimized()) - shell_window->GetBaseWindow()->Restore(); - } - } - if (last_active_shell_window_) - ShowAndActivateOrMinimize(last_active_shell_window_); } } @@ -206,7 +190,7 @@ ShellWindowLauncherItemController::GetApplicationList(int event_flags) { shell_window->GetTitle(), image.get(), // Will be copied app_id(), - launcher_controller()->GetPerAppInterface(), + launcher_controller(), index, index == 0 /* has_leading_separator */)); ++index; diff --git a/chrome/chrome_browser_ui.gypi b/chrome/chrome_browser_ui.gypi index d7dc080..95a37f5 100644 --- a/chrome/chrome_browser_ui.gypi +++ b/chrome/chrome_browser_ui.gypi @@ -234,12 +234,8 @@ 'browser/ui/ash/launcher/chrome_launcher_app_menu_item_tab.h', 'browser/ui/ash/launcher/chrome_launcher_app_menu_item_v2app.cc', 'browser/ui/ash/launcher/chrome_launcher_app_menu_item_v2app.h', - 'browser/ui/ash/launcher/chrome_launcher_controller.cc', - 'browser/ui/ash/launcher/chrome_launcher_controller.h', 'browser/ui/ash/launcher/chrome_launcher_controller_per_app.cc', 'browser/ui/ash/launcher/chrome_launcher_controller_per_app.h', - 'browser/ui/ash/launcher/chrome_launcher_controller_per_browser.cc', - 'browser/ui/ash/launcher/chrome_launcher_controller_per_browser.h', 'browser/ui/ash/launcher/launcher_app_tab_helper.cc', 'browser/ui/ash/launcher/launcher_app_tab_helper.h', 'browser/ui/ash/launcher/launcher_context_menu.cc', diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 26f9ad7..20bc94e 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -1550,7 +1550,6 @@ 'browser/ui/app_list/search/webstore_provider_browsertest.cc', 'browser/ui/ash/caps_lock_delegate_chromeos_browsertest.cc', 'browser/ui/ash/chrome_shell_delegate_browsertest.cc', - 'browser/ui/ash/launcher/chrome_launcher_controller_browsertest.cc', 'browser/ui/ash/launcher/chrome_launcher_controller_per_app_browsertest.cc', 'browser/ui/ash/launcher/launcher_favicon_loader_browsertest.cc', 'browser/ui/ash/shelf_browsertest.cc', @@ -1963,7 +1962,6 @@ 'browser/ui/ash/caps_lock_delegate_chromeos_browsertest.cc', 'browser/ui/ash/chrome_shell_delegate_browsertest.cc', 'browser/ui/ash/launcher/chrome_launcher_controller_per_app_browsertest.cc', - 'browser/ui/ash/launcher/chrome_launcher_controller_browsertest.cc', 'browser/ui/ash/launcher/launcher_favicon_loader_browsertest.cc', 'browser/ui/ash/shelf_browsertest.cc', 'browser/ui/views/frame/app_non_client_frame_view_ash_browsertest.cc', diff --git a/chrome/chrome_tests_unit.gypi b/chrome/chrome_tests_unit.gypi index 0eb4569..f7506d6e 100644 --- a/chrome/chrome_tests_unit.gypi +++ b/chrome/chrome_tests_unit.gypi @@ -1354,9 +1354,7 @@ 'browser/ui/android/tab_model/tab_model_unittest.cc', 'browser/ui/ash/event_rewriter_unittest.cc', 'browser/ui/ash/ime_controller_chromeos_unittest.cc', - 'browser/ui/ash/launcher/browser_launcher_item_controller_unittest.cc', 'browser/ui/ash/launcher/chrome_launcher_controller_per_app_unittest.cc', - 'browser/ui/ash/launcher/chrome_launcher_controller_per_browser_unittest.cc', 'browser/ui/ash/launcher/launcher_context_menu_unittest.cc', 'browser/ui/ash/screenshot_taker_unittest.cc', 'browser/ui/ash/window_positioner_unittest.cc', |