Index: chrome/browser/ui/ash/launcher/chrome_launcher_controller.cc |
diff --git a/chrome/browser/ui/ash/launcher/chrome_launcher_controller.cc b/chrome/browser/ui/ash/launcher/chrome_launcher_controller.cc |
index 4fb9cddadf53eb7b2507c6d2a15bf265e8df946b..76447f6cf7bfe4066430dec2e45292d58c112d56 100644 |
--- a/chrome/browser/ui/ash/launcher/chrome_launcher_controller.cc |
+++ b/chrome/browser/ui/ash/launcher/chrome_launcher_controller.cc |
@@ -41,8 +41,6 @@ |
#include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_browser.h" |
#include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_tab.h" |
#include "chrome/browser/ui/ash/launcher/launcher_app_tab_helper.h" |
-#include "chrome/browser/ui/ash/launcher/launcher_application_menu_item_model.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/ash/launcher/shell_window_launcher_item_controller.h" |
@@ -78,10 +76,6 @@ |
#include "ui/base/l10n/l10n_util.h" |
#include "ui/views/corewm/window_animations.h" |
-#if defined(OS_CHROMEOS) |
-#include "chrome/browser/chromeos/login/default_pinned_apps_field_trial.h" |
-#endif |
- |
using extensions::Extension; |
using extension_misc::kGmailAppId; |
using content::WebContents; |
@@ -245,11 +239,6 @@ ChromeLauncherController::ChromeLauncherController( |
prefs::kShelfPreferences, |
base::Bind(&ChromeLauncherController::SetShelfBehaviorsFromPrefs, |
base::Unretained(this))); |
- |
- // This check is needed for win7_aura. Without this, all tests in |
- // ChromeLauncherControllerTest will fail by win7_aura. |
- if (ash::Shell::HasInstance()) |
- RegisterLauncherItemDelegate(); |
} |
ChromeLauncherController::~ChromeLauncherController() { |
@@ -266,7 +255,6 @@ ChromeLauncherController::~ChromeLauncherController() { |
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(); |
int index = model_->ItemIndexByID(i->first); |
// A "browser proxy" is not known to the model and this removal does |
// therefore not need to be propagated to the model. |
@@ -357,9 +345,9 @@ void ChromeLauncherController::SetItemController( |
CHECK(controller); |
IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); |
CHECK(iter != id_to_item_controller_map_.end()); |
- iter->second->OnRemoved(); |
iter->second = controller; |
controller->set_launcher_id(id); |
+ UpdateLauncherItemDelegate(id, controller); |
} |
void ChromeLauncherController::CloseLauncherItem(ash::LauncherID id) { |
@@ -370,9 +358,9 @@ void ChromeLauncherController::CloseLauncherItem(ash::LauncherID id) { |
CHECK(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); |
+ UpdateLauncherItemDelegate(id, iter->second); |
} else { |
LauncherItemClosed(id); |
} |
@@ -891,37 +879,6 @@ void ChromeLauncherController::ActivateWindowOrMinimizeIfActive( |
} |
} |
-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) |
- if (!item_controller->app_id().empty()) { |
- chromeos::default_pinned_apps_field_trial::RecordShelfAppClick( |
- item_controller->app_id()); |
- } |
-#endif |
- item_controller->Clicked(event); |
-} |
- |
-string16 ChromeLauncherController::GetTitle(const ash::LauncherItem& item) { |
- DCHECK(HasItemController(item.id)); |
- return id_to_item_controller_map_[item.id]->GetTitle(); |
-} |
- |
-ui::MenuModel* ChromeLauncherController::CreateContextMenu( |
- const ash::LauncherItem& item, |
- aura::RootWindow* root_window) { |
- return new LauncherContextMenu(this, &item, root_window); |
-} |
- |
-ash::LauncherMenuModel* ChromeLauncherController::CreateApplicationMenu( |
- const ash::LauncherItem& item, |
- int event_flags) { |
- return new LauncherApplicationMenuItemModel(GetApplicationList(item, |
- event_flags)); |
-} |
- |
ash::LauncherID ChromeLauncherController::GetIDByWindow(aura::Window* window) { |
int browser_index = ash::launcher::GetBrowserItemIndex(*model_); |
DCHECK_GE(browser_index, 0); |
@@ -943,19 +900,6 @@ ash::LauncherID ChromeLauncherController::GetIDByWindow(aura::Window* window) { |
return 0; |
} |
-bool ChromeLauncherController::IsDraggable(const ash::LauncherItem& item) { |
- return (item.type == ash::TYPE_APP_SHORTCUT || |
- item.type == ash::TYPE_WINDOWED_APP) ? CanPin() : true; |
-} |
- |
-bool ChromeLauncherController::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 ChromeLauncherController::OnLauncherCreated(ash::Launcher* launcher) { |
launchers_.insert(launcher); |
launcher->shelf_widget()->shelf_layout_manager()->AddObserver(this); |
@@ -1221,6 +1165,13 @@ ash::LauncherID ChromeLauncherController::CreateAppShortcutLauncherItemWithType( |
return launcher_id; |
} |
+LauncherItemController* ChromeLauncherController::GetLauncherItemController( |
+ const ash::LauncherID id) { |
+ if (!HasItemController(id)) |
+ return NULL; |
+ return id_to_item_controller_map_[id]; |
+} |
+ |
Profile* ChromeLauncherController::GetProfileForNewWindows() { |
return ProfileManager::GetDefaultProfileOrOffTheRecord(); |
} |
@@ -1230,7 +1181,6 @@ void ChromeLauncherController::LauncherItemClosed(ash::LauncherID id) { |
CHECK(iter != id_to_item_controller_map_.end()); |
CHECK(iter->second); |
app_icon_loader_->ClearImage(iter->second->app_id()); |
- iter->second->OnRemoved(); |
id_to_item_controller_map_.erase(iter); |
int index = model_->ItemIndexByID(id); |
// A "browser proxy" is not known to the model and this removal does |
@@ -1475,6 +1425,8 @@ ash::LauncherID ChromeLauncherController::InsertAppLauncherItem( |
app_icon_loader_->FetchImage(app_id); |
+ RegisterLauncherItemDelegate(id, controller); |
+ |
return id; |
} |
@@ -1517,10 +1469,11 @@ ash::LauncherID ChromeLauncherController::CreateBrowserShortcutLauncherItem() { |
ash::LauncherID id = model_->next_id(); |
size_t index = GetChromeIconIndexFromPref(); |
model_->AddAt(index, browser_shortcut); |
- browser_item_controller_.reset( |
- new BrowserShortcutLauncherItemController(this, profile_)); |
- id_to_item_controller_map_[id] = browser_item_controller_.get(); |
+ id_to_item_controller_map_[id] = |
+ new BrowserShortcutLauncherItemController(this, profile_); |
id_to_item_controller_map_[id]->set_launcher_id(id); |
+ // LauncherItemDelegateManager owns BrowserShortcutLauncherItemController. |
+ RegisterLauncherItemDelegate(id, id_to_item_controller_map_[id]); |
return id; |
} |
@@ -1579,14 +1532,38 @@ ChromeLauncherController::MoveItemWithoutPinnedStateChangeNotification( |
model_->Move(source_index, target_index); |
} |
-void ChromeLauncherController::RegisterLauncherItemDelegate() { |
- // TODO(simon.hong81): Register LauncherItemDelegate when LauncherItemDelegate |
- // is created. |
+void ChromeLauncherController::RegisterLauncherItemDelegate( |
+ ash::LauncherID id, |
+ ash::LauncherItemDelegate* item_delegate) { |
+ DCHECK_GT(id, 0); |
+ DCHECK(item_delegate); |
+ // This check needs for win7_aura. RegisterLauncherItemDelegate() access |
+ // Shell. Without this ChromeLauncherControllerTest.BrowserMenuGeneration test |
+ // will fail. |
+ if (!ash::Shell::HasInstance()) |
+ return; |
+ |
+ ash::LauncherItemDelegateManager* manager = |
+ ash::Shell::GetInstance()->launcher_item_delegate_manager(); |
+ manager->RegisterLauncherItemDelegate(id, item_delegate); |
+} |
+ |
+void ChromeLauncherController::UpdateLauncherItemDelegate( |
+ ash::LauncherID id, |
+ ash::LauncherItemDelegate* item_delegate) { |
+ DCHECK_GT(id, 0); |
+ // This check needs for win7_aura. UpdateLauncherItemDelegate() access Shell. |
+ // Without this ChromeLauncherControllerTest.BrowserMenuGeneration test will |
+ // fail. |
+ |
+ if (!ash::Shell::HasInstance()) |
+ return; |
+ |
+ // Don't remove BrowserShortcutLauncherItemDelegate. It can be removed only |
+ // after Launcher is destroyed. |
+ DCHECK(id != ash::launcher::GetBrowserItemID(*model_)); |
+ |
ash::LauncherItemDelegateManager* manager = |
ash::Shell::GetInstance()->launcher_item_delegate_manager(); |
- manager->RegisterLauncherItemDelegate(ash::TYPE_APP_PANEL, this); |
- manager->RegisterLauncherItemDelegate(ash::TYPE_APP_SHORTCUT, this); |
- manager->RegisterLauncherItemDelegate(ash::TYPE_BROWSER_SHORTCUT, this); |
- manager->RegisterLauncherItemDelegate(ash::TYPE_PLATFORM_APP, this); |
- manager->RegisterLauncherItemDelegate(ash::TYPE_WINDOWED_APP, this); |
+ manager->UpdateLauncherItemDelegate(id, item_delegate); |
} |