| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" | 5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "ash/ash_switches.h" | 9 #include "ash/ash_switches.h" |
| 10 #include "ash/desktop_background/desktop_background_controller.h" | 10 #include "ash/desktop_background/desktop_background_controller.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 #include "chrome/browser/ui/ash/app_sync_ui_state.h" | 36 #include "chrome/browser/ui/ash/app_sync_ui_state.h" |
| 37 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h" | 37 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h" |
| 38 #include "chrome/browser/ui/ash/launcher/app_shortcut_launcher_item_controller.h
" | 38 #include "chrome/browser/ui/ash/launcher/app_shortcut_launcher_item_controller.h
" |
| 39 #include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controll
er.h" | 39 #include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controll
er.h" |
| 40 #include "chrome/browser/ui/ash/launcher/browser_status_monitor.h" | 40 #include "chrome/browser/ui/ash/launcher/browser_status_monitor.h" |
| 41 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h" | 41 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h" |
| 42 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_browser.h
" | 42 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_browser.h
" |
| 43 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_tab.h" | 43 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_tab.h" |
| 44 #include "chrome/browser/ui/ash/launcher/chrome_launcher_types.h" | 44 #include "chrome/browser/ui/ash/launcher/chrome_launcher_types.h" |
| 45 #include "chrome/browser/ui/ash/launcher/launcher_app_tab_helper.h" | 45 #include "chrome/browser/ui/ash/launcher/launcher_app_tab_helper.h" |
| 46 #include "chrome/browser/ui/ash/launcher/launcher_application_menu_item_model.h" | |
| 47 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h" | |
| 48 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h" | 46 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h" |
| 49 #include "chrome/browser/ui/ash/launcher/shell_window_launcher_controller.h" | 47 #include "chrome/browser/ui/ash/launcher/shell_window_launcher_controller.h" |
| 50 #include "chrome/browser/ui/ash/launcher/shell_window_launcher_item_controller.h
" | 48 #include "chrome/browser/ui/ash/launcher/shell_window_launcher_item_controller.h
" |
| 51 #include "chrome/browser/ui/browser.h" | 49 #include "chrome/browser/ui/browser.h" |
| 52 #include "chrome/browser/ui/browser_commands.h" | 50 #include "chrome/browser/ui/browser_commands.h" |
| 53 #include "chrome/browser/ui/browser_finder.h" | 51 #include "chrome/browser/ui/browser_finder.h" |
| 54 #include "chrome/browser/ui/browser_list.h" | 52 #include "chrome/browser/ui/browser_list.h" |
| 55 #include "chrome/browser/ui/browser_tabstrip.h" | 53 #include "chrome/browser/ui/browser_tabstrip.h" |
| 56 #include "chrome/browser/ui/browser_window.h" | 54 #include "chrome/browser/ui/browser_window.h" |
| 57 #include "chrome/browser/ui/extensions/application_launch.h" | 55 #include "chrome/browser/ui/extensions/application_launch.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 76 #include "grit/generated_resources.h" | 74 #include "grit/generated_resources.h" |
| 77 #include "grit/theme_resources.h" | 75 #include "grit/theme_resources.h" |
| 78 #include "grit/ui_resources.h" | 76 #include "grit/ui_resources.h" |
| 79 #include "net/base/url_util.h" | 77 #include "net/base/url_util.h" |
| 80 #include "ui/aura/root_window.h" | 78 #include "ui/aura/root_window.h" |
| 81 #include "ui/aura/window.h" | 79 #include "ui/aura/window.h" |
| 82 #include "ui/base/l10n/l10n_util.h" | 80 #include "ui/base/l10n/l10n_util.h" |
| 83 #include "ui/views/corewm/window_animations.h" | 81 #include "ui/views/corewm/window_animations.h" |
| 84 | 82 |
| 85 #if defined(OS_CHROMEOS) | 83 #if defined(OS_CHROMEOS) |
| 86 #include "chrome/browser/chromeos/login/default_pinned_apps_field_trial.h" | |
| 87 #include "chrome/browser/chromeos/login/user_manager.h" | 84 #include "chrome/browser/chromeos/login/user_manager.h" |
| 88 #include "chrome/browser/chromeos/login/wallpaper_manager.h" | 85 #include "chrome/browser/chromeos/login/wallpaper_manager.h" |
| 89 #include "chrome/browser/ui/ash/chrome_shell_delegate.h" | 86 #include "chrome/browser/ui/ash/chrome_shell_delegate.h" |
| 90 #endif | 87 #endif |
| 91 | 88 |
| 92 using extensions::Extension; | 89 using extensions::Extension; |
| 93 using extension_misc::kGmailAppId; | 90 using extension_misc::kGmailAppId; |
| 94 using content::WebContents; | 91 using content::WebContents; |
| 95 | 92 |
| 96 // static | 93 // static |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 // and wallpapers are not synchronized across multiple desktops. | 246 // and wallpapers are not synchronized across multiple desktops. |
| 250 if (chromeos::WallpaperManager::Get()) | 247 if (chromeos::WallpaperManager::Get()) |
| 251 chromeos::WallpaperManager::Get()->SetUserWallpaper(user_email); | 248 chromeos::WallpaperManager::Get()->SetUserWallpaper(user_email); |
| 252 } | 249 } |
| 253 #endif | 250 #endif |
| 254 | 251 |
| 255 ChromeLauncherController::ChromeLauncherController( | 252 ChromeLauncherController::ChromeLauncherController( |
| 256 Profile* profile, | 253 Profile* profile, |
| 257 ash::LauncherModel* model) | 254 ash::LauncherModel* model) |
| 258 : model_(model), | 255 : model_(model), |
| 256 item_delegate_manager_(NULL), |
| 259 profile_(profile), | 257 profile_(profile), |
| 260 app_sync_ui_state_(NULL), | 258 app_sync_ui_state_(NULL), |
| 261 ignore_persist_pinned_state_change_(false) { | 259 ignore_persist_pinned_state_change_(false) { |
| 262 if (!profile_) { | 260 if (!profile_) { |
| 263 // Use the original profile as on chromeos we may get a temporary off the | 261 // Use the original profile as on chromeos we may get a temporary off the |
| 264 // record profile. | 262 // record profile. |
| 265 profile_ = ProfileManager::GetDefaultProfile()->GetOriginalProfile(); | 263 profile_ = ProfileManager::GetDefaultProfile()->GetOriginalProfile(); |
| 266 | 264 |
| 267 app_sync_ui_state_ = AppSyncUIState::Get(profile_); | 265 app_sync_ui_state_ = AppSyncUIState::Get(profile_); |
| 268 if (app_sync_ui_state_) | 266 if (app_sync_ui_state_) |
| 269 app_sync_ui_state_->AddObserver(this); | 267 app_sync_ui_state_->AddObserver(this); |
| 270 } | 268 } |
| 271 | 269 |
| 272 // All profile relevant settings get bound to the current profile. | 270 // All profile relevant settings get bound to the current profile. |
| 273 AttachProfile(profile_); | 271 AttachProfile(profile_); |
| 274 | 272 |
| 275 browser_status_monitor_.reset(new BrowserStatusMonitor(this)); | 273 browser_status_monitor_.reset(new BrowserStatusMonitor(this)); |
| 276 model_->AddObserver(this); | 274 model_->AddObserver(this); |
| 277 // Right now ash::Shell isn't created for tests. | 275 // Right now ash::Shell isn't created for tests. |
| 278 // TODO(mukai): Allows it to observe display change and write tests. | 276 // TODO(mukai): Allows it to observe display change and write tests. |
| 279 if (ash::Shell::HasInstance()) | 277 if (ash::Shell::HasInstance()) { |
| 280 ash::Shell::GetInstance()->display_controller()->AddObserver(this); | 278 ash::Shell::GetInstance()->display_controller()->AddObserver(this); |
| 279 item_delegate_manager_ = |
| 280 ash::Shell::GetInstance()->launcher_item_delegate_manager(); |
| 281 } |
| 281 // TODO(stevenjb): Find a better owner for shell_window_controller_? | 282 // TODO(stevenjb): Find a better owner for shell_window_controller_? |
| 282 shell_window_controller_.reset(new ShellWindowLauncherController(this)); | 283 shell_window_controller_.reset(new ShellWindowLauncherController(this)); |
| 283 | 284 |
| 284 notification_registrar_.Add(this, | 285 notification_registrar_.Add(this, |
| 285 chrome::NOTIFICATION_EXTENSION_LOADED, | 286 chrome::NOTIFICATION_EXTENSION_LOADED, |
| 286 content::Source<Profile>(profile_)); | 287 content::Source<Profile>(profile_)); |
| 287 notification_registrar_.Add(this, | 288 notification_registrar_.Add(this, |
| 288 chrome::NOTIFICATION_EXTENSION_UNLOADED, | 289 chrome::NOTIFICATION_EXTENSION_UNLOADED, |
| 289 content::Source<Profile>(profile_)); | 290 content::Source<Profile>(profile_)); |
| 290 | 291 |
| 291 // This check is needed for win7_aura. Without this, all tests in | |
| 292 // ChromeLauncherControllerTest will fail by win7_aura. | |
| 293 if (ash::Shell::HasInstance()) | |
| 294 RegisterLauncherItemDelegate(); | |
| 295 | |
| 296 #if defined(OS_CHROMEOS) | 292 #if defined(OS_CHROMEOS) |
| 297 // On Chrome OS using multi profile we want to switch the content of the shelf | 293 // On Chrome OS using multi profile we want to switch the content of the shelf |
| 298 // with a user change. Note that for unit tests the instance can be NULL. | 294 // with a user change. Note that for unit tests the instance can be NULL. |
| 299 if (ChromeShellDelegate::instance() && | 295 if (ChromeShellDelegate::instance() && |
| 300 ChromeShellDelegate::instance()->IsMultiProfilesEnabled()) { | 296 ChromeShellDelegate::instance()->IsMultiProfilesEnabled()) { |
| 301 user_switch_observer_.reset( | 297 user_switch_observer_.reset( |
| 302 new ChromeLauncherControllerUserSwitchObserverChromeOS(this)); | 298 new ChromeLauncherControllerUserSwitchObserverChromeOS(this)); |
| 303 } | 299 } |
| 304 #endif | 300 #endif |
| 305 } | 301 } |
| 306 | 302 |
| 307 ChromeLauncherController::~ChromeLauncherController() { | 303 ChromeLauncherController::~ChromeLauncherController() { |
| 308 // Reset the BrowserStatusMonitor as it has a weak pointer to this. | 304 // Reset the BrowserStatusMonitor as it has a weak pointer to this. |
| 309 browser_status_monitor_.reset(); | 305 browser_status_monitor_.reset(); |
| 310 | 306 |
| 311 // Reset the shell window controller here since it has a weak pointer to this. | 307 // Reset the shell window controller here since it has a weak pointer to this. |
| 312 shell_window_controller_.reset(); | 308 shell_window_controller_.reset(); |
| 313 | 309 |
| 314 for (std::set<ash::Launcher*>::iterator iter = launchers_.begin(); | 310 for (std::set<ash::Launcher*>::iterator iter = launchers_.begin(); |
| 315 iter != launchers_.end(); | 311 iter != launchers_.end(); |
| 316 ++iter) | 312 ++iter) |
| 317 (*iter)->shelf_widget()->shelf_layout_manager()->RemoveObserver(this); | 313 (*iter)->shelf_widget()->shelf_layout_manager()->RemoveObserver(this); |
| 318 | 314 |
| 319 model_->RemoveObserver(this); | 315 model_->RemoveObserver(this); |
| 320 if (ash::Shell::HasInstance()) | 316 if (ash::Shell::HasInstance()) |
| 321 ash::Shell::GetInstance()->display_controller()->RemoveObserver(this); | 317 ash::Shell::GetInstance()->display_controller()->RemoveObserver(this); |
| 322 for (IDToItemControllerMap::iterator i = id_to_item_controller_map_.begin(); | 318 for (IDToItemControllerMap::iterator i = id_to_item_controller_map_.begin(); |
| 323 i != id_to_item_controller_map_.end(); ++i) { | 319 i != id_to_item_controller_map_.end(); ++i) { |
| 324 i->second->OnRemoved(); | |
| 325 int index = model_->ItemIndexByID(i->first); | 320 int index = model_->ItemIndexByID(i->first); |
| 326 // A "browser proxy" is not known to the model and this removal does | 321 // A "browser proxy" is not known to the model and this removal does |
| 327 // therefore not need to be propagated to the model. | 322 // therefore not need to be propagated to the model. |
| 328 if (index != -1 && | 323 if (index != -1 && |
| 329 model_->items()[index].type != ash::TYPE_BROWSER_SHORTCUT) | 324 model_->items()[index].type != ash::TYPE_BROWSER_SHORTCUT) |
| 330 model_->RemoveItemAt(index); | 325 model_->RemoveItemAt(index); |
| 331 } | 326 } |
| 332 | 327 |
| 333 if (ash::Shell::HasInstance()) | 328 if (ash::Shell::HasInstance()) |
| 334 ash::Shell::GetInstance()->RemoveShellObserver(this); | 329 ash::Shell::GetInstance()->RemoveShellObserver(this); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 model_->Set(index, item); | 394 model_->Set(index, item); |
| 400 } | 395 } |
| 401 } | 396 } |
| 402 | 397 |
| 403 void ChromeLauncherController::SetItemController( | 398 void ChromeLauncherController::SetItemController( |
| 404 ash::LauncherID id, | 399 ash::LauncherID id, |
| 405 LauncherItemController* controller) { | 400 LauncherItemController* controller) { |
| 406 CHECK(controller); | 401 CHECK(controller); |
| 407 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); | 402 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); |
| 408 CHECK(iter != id_to_item_controller_map_.end()); | 403 CHECK(iter != id_to_item_controller_map_.end()); |
| 409 iter->second->OnRemoved(); | 404 controller->set_launcher_id(id); |
| 410 iter->second = controller; | 405 iter->second = controller; |
| 411 controller->set_launcher_id(id); | 406 // Existing controller is destroyed and replaced by registering again. |
| 407 SetLauncherItemDelegate(id, controller); |
| 412 } | 408 } |
| 413 | 409 |
| 414 void ChromeLauncherController::CloseLauncherItem(ash::LauncherID id) { | 410 void ChromeLauncherController::CloseLauncherItem(ash::LauncherID id) { |
| 415 CHECK(id); | 411 CHECK(id); |
| 416 if (IsPinned(id)) { | 412 if (IsPinned(id)) { |
| 417 // Create a new shortcut controller. | 413 // Create a new shortcut controller. |
| 418 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); | 414 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); |
| 419 CHECK(iter != id_to_item_controller_map_.end()); | 415 CHECK(iter != id_to_item_controller_map_.end()); |
| 420 SetItemStatus(id, ash::STATUS_CLOSED); | 416 SetItemStatus(id, ash::STATUS_CLOSED); |
| 421 std::string app_id = iter->second->app_id(); | 417 std::string app_id = iter->second->app_id(); |
| 422 iter->second->OnRemoved(); | |
| 423 iter->second = new AppShortcutLauncherItemController(app_id, this); | 418 iter->second = new AppShortcutLauncherItemController(app_id, this); |
| 424 iter->second->set_launcher_id(id); | 419 iter->second->set_launcher_id(id); |
| 420 // Existing controller is destroyed and replaced by registering again. |
| 421 SetLauncherItemDelegate(id, iter->second); |
| 425 } else { | 422 } else { |
| 426 LauncherItemClosed(id); | 423 LauncherItemClosed(id); |
| 427 } | 424 } |
| 428 } | 425 } |
| 429 | 426 |
| 430 void ChromeLauncherController::Pin(ash::LauncherID id) { | 427 void ChromeLauncherController::Pin(ash::LauncherID id) { |
| 431 DCHECK(HasItemController(id)); | 428 DCHECK(HasItemController(id)); |
| 432 | 429 |
| 433 int index = model_->ItemIndexByID(id); | 430 int index = model_->ItemIndexByID(id); |
| 434 DCHECK_GE(index, 0); | 431 DCHECK_GE(index, 0); |
| (...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 938 views::corewm::WINDOW_ANIMATION_TYPE_BOUNCE); | 935 views::corewm::WINDOW_ANIMATION_TYPE_BOUNCE); |
| 939 } else { | 936 } else { |
| 940 window->Minimize(); | 937 window->Minimize(); |
| 941 } | 938 } |
| 942 } else { | 939 } else { |
| 943 window->Show(); | 940 window->Show(); |
| 944 window->Activate(); | 941 window->Activate(); |
| 945 } | 942 } |
| 946 } | 943 } |
| 947 | 944 |
| 948 void ChromeLauncherController::ItemSelected(const ash::LauncherItem& item, | |
| 949 const ui::Event& event) { | |
| 950 DCHECK(HasItemController(item.id)); | |
| 951 LauncherItemController* item_controller = id_to_item_controller_map_[item.id]; | |
| 952 #if defined(OS_CHROMEOS) | |
| 953 if (!item_controller->app_id().empty()) { | |
| 954 chromeos::default_pinned_apps_field_trial::RecordShelfAppClick( | |
| 955 item_controller->app_id()); | |
| 956 } | |
| 957 #endif | |
| 958 item_controller->Clicked(event); | |
| 959 } | |
| 960 | |
| 961 string16 ChromeLauncherController::GetTitle(const ash::LauncherItem& item) { | |
| 962 DCHECK(HasItemController(item.id)); | |
| 963 return id_to_item_controller_map_[item.id]->GetTitle(); | |
| 964 } | |
| 965 | |
| 966 ui::MenuModel* ChromeLauncherController::CreateContextMenu( | |
| 967 const ash::LauncherItem& item, | |
| 968 aura::RootWindow* root_window) { | |
| 969 return new LauncherContextMenu(this, &item, root_window); | |
| 970 } | |
| 971 | |
| 972 ash::LauncherMenuModel* ChromeLauncherController::CreateApplicationMenu( | |
| 973 const ash::LauncherItem& item, | |
| 974 int event_flags) { | |
| 975 return new LauncherApplicationMenuItemModel(GetApplicationList(item, | |
| 976 event_flags)); | |
| 977 } | |
| 978 | |
| 979 ash::LauncherID ChromeLauncherController::GetIDByWindow(aura::Window* window) { | 945 ash::LauncherID ChromeLauncherController::GetIDByWindow(aura::Window* window) { |
| 980 int browser_index = ash::GetBrowserItemIndex(*model_); | 946 int browser_index = ash::GetBrowserItemIndex(*model_); |
| 981 DCHECK_GE(browser_index, 0); | 947 DCHECK_GE(browser_index, 0); |
| 982 ash::LauncherID browser_id = model_->items()[browser_index].id; | 948 ash::LauncherID browser_id = model_->items()[browser_index].id; |
| 983 | 949 |
| 984 IDToItemControllerMap::const_iterator i = id_to_item_controller_map_.begin(); | 950 IDToItemControllerMap::const_iterator i = id_to_item_controller_map_.begin(); |
| 985 for (; i != id_to_item_controller_map_.end(); ++i) { | 951 for (; i != id_to_item_controller_map_.end(); ++i) { |
| 986 // Since a |window| can be used by multiple applications, an explicit | 952 // Since a |window| can be used by multiple applications, an explicit |
| 987 // application always gets chosen over the generic browser. | 953 // application always gets chosen over the generic browser. |
| 988 if (i->first != browser_id && i->second->IsCurrentlyShownInWindow(window)) | 954 if (i->first != browser_id && i->second->IsCurrentlyShownInWindow(window)) |
| 989 return i->first; | 955 return i->first; |
| 990 } | 956 } |
| 991 | 957 |
| 992 if (i == id_to_item_controller_map_.end() && | 958 if (i == id_to_item_controller_map_.end() && |
| 993 GetBrowserShortcutLauncherItemController()-> | 959 GetBrowserShortcutLauncherItemController()-> |
| 994 IsCurrentlyShownInWindow(window)) | 960 IsCurrentlyShownInWindow(window)) |
| 995 return browser_id; | 961 return browser_id; |
| 996 | 962 |
| 997 return 0; | 963 return 0; |
| 998 } | 964 } |
| 999 | 965 |
| 1000 bool ChromeLauncherController::IsDraggable(const ash::LauncherItem& item) { | |
| 1001 return (item.type == ash::TYPE_APP_SHORTCUT || | |
| 1002 item.type == ash::TYPE_WINDOWED_APP) ? CanPin() : true; | |
| 1003 } | |
| 1004 | |
| 1005 bool ChromeLauncherController::ShouldShowTooltip( | |
| 1006 const ash::LauncherItem& item) { | |
| 1007 if (item.type == ash::TYPE_APP_PANEL && | |
| 1008 id_to_item_controller_map_[item.id]->IsVisible()) | |
| 1009 return false; | |
| 1010 return true; | |
| 1011 } | |
| 1012 | |
| 1013 void ChromeLauncherController::OnLauncherCreated(ash::Launcher* launcher) { | 966 void ChromeLauncherController::OnLauncherCreated(ash::Launcher* launcher) { |
| 1014 launchers_.insert(launcher); | 967 launchers_.insert(launcher); |
| 1015 launcher->shelf_widget()->shelf_layout_manager()->AddObserver(this); | 968 launcher->shelf_widget()->shelf_layout_manager()->AddObserver(this); |
| 1016 } | 969 } |
| 1017 | 970 |
| 1018 void ChromeLauncherController::OnLauncherDestroyed(ash::Launcher* launcher) { | 971 void ChromeLauncherController::OnLauncherDestroyed(ash::Launcher* launcher) { |
| 1019 launchers_.erase(launcher); | 972 launchers_.erase(launcher); |
| 1020 // RemoveObserver is not called here, since by the time this method is called | 973 // RemoveObserver is not called here, since by the time this method is called |
| 1021 // Launcher is already in its destructor. | 974 // Launcher is already in its destructor. |
| 1022 } | 975 } |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1282 void ChromeLauncherController::SetAppIconLoaderForTest( | 1235 void ChromeLauncherController::SetAppIconLoaderForTest( |
| 1283 extensions::AppIconLoader* loader) { | 1236 extensions::AppIconLoader* loader) { |
| 1284 app_icon_loader_.reset(loader); | 1237 app_icon_loader_.reset(loader); |
| 1285 } | 1238 } |
| 1286 | 1239 |
| 1287 const std::string& ChromeLauncherController::GetAppIdFromLauncherIdForTest( | 1240 const std::string& ChromeLauncherController::GetAppIdFromLauncherIdForTest( |
| 1288 ash::LauncherID id) { | 1241 ash::LauncherID id) { |
| 1289 return id_to_item_controller_map_[id]->app_id(); | 1242 return id_to_item_controller_map_[id]->app_id(); |
| 1290 } | 1243 } |
| 1291 | 1244 |
| 1245 void ChromeLauncherController::SetLauncherItemDelegateManagerForTest( |
| 1246 ash::LauncherItemDelegateManager* manager) { |
| 1247 item_delegate_manager_ = manager; |
| 1248 } |
| 1249 |
| 1292 ash::LauncherID ChromeLauncherController::CreateAppShortcutLauncherItemWithType( | 1250 ash::LauncherID ChromeLauncherController::CreateAppShortcutLauncherItemWithType( |
| 1293 const std::string& app_id, | 1251 const std::string& app_id, |
| 1294 int index, | 1252 int index, |
| 1295 ash::LauncherItemType launcher_item_type) { | 1253 ash::LauncherItemType launcher_item_type) { |
| 1296 AppShortcutLauncherItemController* controller = | 1254 AppShortcutLauncherItemController* controller = |
| 1297 new AppShortcutLauncherItemController(app_id, this); | 1255 new AppShortcutLauncherItemController(app_id, this); |
| 1298 ash::LauncherID launcher_id = InsertAppLauncherItem( | 1256 ash::LauncherID launcher_id = InsertAppLauncherItem( |
| 1299 controller, app_id, ash::STATUS_CLOSED, index, launcher_item_type); | 1257 controller, app_id, ash::STATUS_CLOSED, index, launcher_item_type); |
| 1300 return launcher_id; | 1258 return launcher_id; |
| 1301 } | 1259 } |
| 1302 | 1260 |
| 1261 LauncherItemController* ChromeLauncherController::GetLauncherItemController( |
| 1262 const ash::LauncherID id) { |
| 1263 if (!HasItemController(id)) |
| 1264 return NULL; |
| 1265 return id_to_item_controller_map_[id]; |
| 1266 } |
| 1267 |
| 1303 Profile* ChromeLauncherController::GetProfileForNewWindows() { | 1268 Profile* ChromeLauncherController::GetProfileForNewWindows() { |
| 1304 return ProfileManager::GetDefaultProfileOrOffTheRecord(); | 1269 return ProfileManager::GetDefaultProfileOrOffTheRecord(); |
| 1305 } | 1270 } |
| 1306 | 1271 |
| 1307 void ChromeLauncherController::LauncherItemClosed(ash::LauncherID id) { | 1272 void ChromeLauncherController::LauncherItemClosed(ash::LauncherID id) { |
| 1308 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); | 1273 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); |
| 1309 CHECK(iter != id_to_item_controller_map_.end()); | 1274 CHECK(iter != id_to_item_controller_map_.end()); |
| 1310 CHECK(iter->second); | 1275 CHECK(iter->second); |
| 1311 app_icon_loader_->ClearImage(iter->second->app_id()); | 1276 app_icon_loader_->ClearImage(iter->second->app_id()); |
| 1312 iter->second->OnRemoved(); | |
| 1313 id_to_item_controller_map_.erase(iter); | 1277 id_to_item_controller_map_.erase(iter); |
| 1314 int index = model_->ItemIndexByID(id); | 1278 int index = model_->ItemIndexByID(id); |
| 1315 // A "browser proxy" is not known to the model and this removal does | 1279 // A "browser proxy" is not known to the model and this removal does |
| 1316 // therefore not need to be propagated to the model. | 1280 // therefore not need to be propagated to the model. |
| 1317 if (index != -1) | 1281 if (index != -1) |
| 1318 model_->RemoveItemAt(index); | 1282 model_->RemoveItemAt(index); |
| 1319 } | 1283 } |
| 1320 | 1284 |
| 1321 void ChromeLauncherController::DoPinAppWithID(const std::string& app_id) { | 1285 void ChromeLauncherController::DoPinAppWithID(const std::string& app_id) { |
| 1322 // If there is an item, do nothing and return. | 1286 // If there is an item, do nothing and return. |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1620 status = ash::STATUS_ACTIVE; | 1584 status = ash::STATUS_ACTIVE; |
| 1621 else | 1585 else |
| 1622 status = ash::STATUS_RUNNING; | 1586 status = ash::STATUS_RUNNING; |
| 1623 } | 1587 } |
| 1624 item.status = status; | 1588 item.status = status; |
| 1625 | 1589 |
| 1626 model_->AddAt(index, item); | 1590 model_->AddAt(index, item); |
| 1627 | 1591 |
| 1628 app_icon_loader_->FetchImage(app_id); | 1592 app_icon_loader_->FetchImage(app_id); |
| 1629 | 1593 |
| 1594 SetLauncherItemDelegate(id, controller); |
| 1595 |
| 1630 return id; | 1596 return id; |
| 1631 } | 1597 } |
| 1632 | 1598 |
| 1633 bool ChromeLauncherController::HasItemController(ash::LauncherID id) const { | 1599 bool ChromeLauncherController::HasItemController(ash::LauncherID id) const { |
| 1634 return id_to_item_controller_map_.find(id) != | 1600 return id_to_item_controller_map_.find(id) != |
| 1635 id_to_item_controller_map_.end(); | 1601 id_to_item_controller_map_.end(); |
| 1636 } | 1602 } |
| 1637 | 1603 |
| 1638 std::vector<content::WebContents*> | 1604 std::vector<content::WebContents*> |
| 1639 ChromeLauncherController::GetV1ApplicationsFromController( | 1605 ChromeLauncherController::GetV1ApplicationsFromController( |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1662 } | 1628 } |
| 1663 | 1629 |
| 1664 ash::LauncherID ChromeLauncherController::CreateBrowserShortcutLauncherItem() { | 1630 ash::LauncherID ChromeLauncherController::CreateBrowserShortcutLauncherItem() { |
| 1665 ash::LauncherItem browser_shortcut; | 1631 ash::LauncherItem browser_shortcut; |
| 1666 browser_shortcut.type = ash::TYPE_BROWSER_SHORTCUT; | 1632 browser_shortcut.type = ash::TYPE_BROWSER_SHORTCUT; |
| 1667 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 1633 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 1668 browser_shortcut.image = *rb.GetImageSkiaNamed(IDR_PRODUCT_LOGO_32); | 1634 browser_shortcut.image = *rb.GetImageSkiaNamed(IDR_PRODUCT_LOGO_32); |
| 1669 ash::LauncherID id = model_->next_id(); | 1635 ash::LauncherID id = model_->next_id(); |
| 1670 size_t index = GetChromeIconIndexForCreation(); | 1636 size_t index = GetChromeIconIndexForCreation(); |
| 1671 model_->AddAt(index, browser_shortcut); | 1637 model_->AddAt(index, browser_shortcut); |
| 1672 browser_item_controller_.reset( | 1638 id_to_item_controller_map_[id] = |
| 1673 new BrowserShortcutLauncherItemController(this)); | 1639 new BrowserShortcutLauncherItemController(this); |
| 1674 id_to_item_controller_map_[id] = browser_item_controller_.get(); | |
| 1675 id_to_item_controller_map_[id]->set_launcher_id(id); | 1640 id_to_item_controller_map_[id]->set_launcher_id(id); |
| 1641 // LauncherItemDelegateManager owns BrowserShortcutLauncherItemController. |
| 1642 SetLauncherItemDelegate(id, id_to_item_controller_map_[id]); |
| 1676 return id; | 1643 return id; |
| 1677 } | 1644 } |
| 1678 | 1645 |
| 1679 void ChromeLauncherController::PersistChromeItemIndex(int index) { | 1646 void ChromeLauncherController::PersistChromeItemIndex(int index) { |
| 1680 profile_->GetPrefs()->SetInteger(prefs::kShelfChromeIconIndex, index); | 1647 profile_->GetPrefs()->SetInteger(prefs::kShelfChromeIconIndex, index); |
| 1681 } | 1648 } |
| 1682 | 1649 |
| 1683 int ChromeLauncherController::GetChromeIconIndexFromPref() const { | 1650 int ChromeLauncherController::GetChromeIconIndexFromPref() const { |
| 1684 size_t index = profile_->GetPrefs()->GetInteger(prefs::kShelfChromeIconIndex); | 1651 size_t index = profile_->GetPrefs()->GetInteger(prefs::kShelfChromeIconIndex); |
| 1685 const base::ListValue* pinned_apps_pref = | 1652 const base::ListValue* pinned_apps_pref = |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1840 browser_to_close.push_back(browser); | 1807 browser_to_close.push_back(browser); |
| 1841 } | 1808 } |
| 1842 } | 1809 } |
| 1843 while (!browser_to_close.empty()) { | 1810 while (!browser_to_close.empty()) { |
| 1844 TabStripModel* tab_strip = browser_to_close.back()->tab_strip_model(); | 1811 TabStripModel* tab_strip = browser_to_close.back()->tab_strip_model(); |
| 1845 tab_strip->CloseWebContentsAt(0, TabStripModel::CLOSE_NONE); | 1812 tab_strip->CloseWebContentsAt(0, TabStripModel::CLOSE_NONE); |
| 1846 browser_to_close.pop_back(); | 1813 browser_to_close.pop_back(); |
| 1847 } | 1814 } |
| 1848 } | 1815 } |
| 1849 | 1816 |
| 1850 void ChromeLauncherController::RegisterLauncherItemDelegate() { | 1817 void ChromeLauncherController::SetLauncherItemDelegate( |
| 1851 // TODO(simon.hong81): Register LauncherItemDelegate when LauncherItemDelegate | 1818 ash::LauncherID id, |
| 1852 // is created. | 1819 ash::LauncherItemDelegate* item_delegate) { |
| 1853 ash::LauncherItemDelegateManager* manager = | 1820 DCHECK_GT(id, 0); |
| 1854 ash::Shell::GetInstance()->launcher_item_delegate_manager(); | 1821 DCHECK(item_delegate); |
| 1855 manager->RegisterLauncherItemDelegate(ash::TYPE_APP_PANEL, this); | 1822 DCHECK(item_delegate_manager_); |
| 1856 manager->RegisterLauncherItemDelegate(ash::TYPE_APP_SHORTCUT, this); | 1823 item_delegate_manager_->SetLauncherItemDelegate(id, |
| 1857 manager->RegisterLauncherItemDelegate(ash::TYPE_BROWSER_SHORTCUT, this); | 1824 scoped_ptr<ash::LauncherItemDelegate>(item_delegate).Pass()); |
| 1858 manager->RegisterLauncherItemDelegate(ash::TYPE_PLATFORM_APP, this); | |
| 1859 manager->RegisterLauncherItemDelegate(ash::TYPE_WINDOWED_APP, this); | |
| 1860 } | 1825 } |
| 1861 | 1826 |
| 1862 void ChromeLauncherController::AttachProfile(Profile* profile) { | 1827 void ChromeLauncherController::AttachProfile(Profile* profile) { |
| 1863 profile_ = profile; | 1828 profile_ = profile; |
| 1864 // Either add the profile to the list of known profiles and make it the active | 1829 // Either add the profile to the list of known profiles and make it the active |
| 1865 // one for some functions of AppTabHelper or create a new one. | 1830 // one for some functions of AppTabHelper or create a new one. |
| 1866 if (!app_tab_helper_.get()) | 1831 if (!app_tab_helper_.get()) |
| 1867 app_tab_helper_.reset(new LauncherAppTabHelper(profile_)); | 1832 app_tab_helper_.reset(new LauncherAppTabHelper(profile_)); |
| 1868 else | 1833 else |
| 1869 app_tab_helper_->SetCurrentUser(profile_); | 1834 app_tab_helper_->SetCurrentUser(profile_); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1896 } | 1861 } |
| 1897 | 1862 |
| 1898 void ChromeLauncherController::ReleaseProfile() { | 1863 void ChromeLauncherController::ReleaseProfile() { |
| 1899 if (app_sync_ui_state_) | 1864 if (app_sync_ui_state_) |
| 1900 app_sync_ui_state_->RemoveObserver(this); | 1865 app_sync_ui_state_->RemoveObserver(this); |
| 1901 | 1866 |
| 1902 PrefServiceSyncable::FromProfile(profile_)->RemoveObserver(this); | 1867 PrefServiceSyncable::FromProfile(profile_)->RemoveObserver(this); |
| 1903 | 1868 |
| 1904 pref_change_registrar_.RemoveAll(); | 1869 pref_change_registrar_.RemoveAll(); |
| 1905 } | 1870 } |
| OLD | NEW |