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/launcher/launcher.h" | 10 #include "ash/launcher/launcher.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 #include "chrome/browser/profiles/profile_manager.h" | 34 #include "chrome/browser/profiles/profile_manager.h" |
35 #include "chrome/browser/ui/ash/app_sync_ui_state.h" | 35 #include "chrome/browser/ui/ash/app_sync_ui_state.h" |
36 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h" | 36 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h" |
37 #include "chrome/browser/ui/ash/launcher/app_shortcut_launcher_item_controller.h
" | 37 #include "chrome/browser/ui/ash/launcher/app_shortcut_launcher_item_controller.h
" |
38 #include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controll
er.h" | 38 #include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controll
er.h" |
39 #include "chrome/browser/ui/ash/launcher/browser_status_monitor.h" | 39 #include "chrome/browser/ui/ash/launcher/browser_status_monitor.h" |
40 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h" | 40 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h" |
41 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_browser.h
" | 41 #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_tab.h" | 42 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_tab.h" |
43 #include "chrome/browser/ui/ash/launcher/launcher_app_tab_helper.h" | 43 #include "chrome/browser/ui/ash/launcher/launcher_app_tab_helper.h" |
44 #include "chrome/browser/ui/ash/launcher/launcher_application_menu_item_model.h" | |
45 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h" | |
46 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h" | 44 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h" |
47 #include "chrome/browser/ui/ash/launcher/shell_window_launcher_controller.h" | 45 #include "chrome/browser/ui/ash/launcher/shell_window_launcher_controller.h" |
48 #include "chrome/browser/ui/ash/launcher/shell_window_launcher_item_controller.h
" | 46 #include "chrome/browser/ui/ash/launcher/shell_window_launcher_item_controller.h
" |
49 #include "chrome/browser/ui/browser.h" | 47 #include "chrome/browser/ui/browser.h" |
50 #include "chrome/browser/ui/browser_commands.h" | 48 #include "chrome/browser/ui/browser_commands.h" |
51 #include "chrome/browser/ui/browser_finder.h" | 49 #include "chrome/browser/ui/browser_finder.h" |
52 #include "chrome/browser/ui/browser_list.h" | 50 #include "chrome/browser/ui/browser_list.h" |
53 #include "chrome/browser/ui/browser_tabstrip.h" | 51 #include "chrome/browser/ui/browser_tabstrip.h" |
54 #include "chrome/browser/ui/browser_window.h" | 52 #include "chrome/browser/ui/browser_window.h" |
55 #include "chrome/browser/ui/extensions/application_launch.h" | 53 #include "chrome/browser/ui/extensions/application_launch.h" |
(...skipping 15 matching lines...) Expand all Loading... |
71 #include "grit/ash_resources.h" | 69 #include "grit/ash_resources.h" |
72 #include "grit/chromium_strings.h" | 70 #include "grit/chromium_strings.h" |
73 #include "grit/generated_resources.h" | 71 #include "grit/generated_resources.h" |
74 #include "grit/theme_resources.h" | 72 #include "grit/theme_resources.h" |
75 #include "grit/ui_resources.h" | 73 #include "grit/ui_resources.h" |
76 #include "ui/aura/root_window.h" | 74 #include "ui/aura/root_window.h" |
77 #include "ui/aura/window.h" | 75 #include "ui/aura/window.h" |
78 #include "ui/base/l10n/l10n_util.h" | 76 #include "ui/base/l10n/l10n_util.h" |
79 #include "ui/views/corewm/window_animations.h" | 77 #include "ui/views/corewm/window_animations.h" |
80 | 78 |
81 #if defined(OS_CHROMEOS) | |
82 #include "chrome/browser/chromeos/login/default_pinned_apps_field_trial.h" | |
83 #endif | |
84 | |
85 using extensions::Extension; | 79 using extensions::Extension; |
86 using extension_misc::kGmailAppId; | 80 using extension_misc::kGmailAppId; |
87 using content::WebContents; | 81 using content::WebContents; |
88 | 82 |
89 // static | 83 // static |
90 ChromeLauncherController* ChromeLauncherController::instance_ = NULL; | 84 ChromeLauncherController* ChromeLauncherController::instance_ = NULL; |
91 | 85 |
92 namespace { | 86 namespace { |
93 | 87 |
94 std::string GetPrefKeyForRootWindow(aura::RootWindow* root_window) { | 88 std::string GetPrefKeyForRootWindow(aura::RootWindow* root_window) { |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 base::Unretained(this))); | 232 base::Unretained(this))); |
239 pref_change_registrar_.Add( | 233 pref_change_registrar_.Add( |
240 prefs::kShelfAutoHideBehaviorLocal, | 234 prefs::kShelfAutoHideBehaviorLocal, |
241 base::Bind(&ChromeLauncherController:: | 235 base::Bind(&ChromeLauncherController:: |
242 SetShelfAutoHideBehaviorFromPrefs, | 236 SetShelfAutoHideBehaviorFromPrefs, |
243 base::Unretained(this))); | 237 base::Unretained(this))); |
244 pref_change_registrar_.Add( | 238 pref_change_registrar_.Add( |
245 prefs::kShelfPreferences, | 239 prefs::kShelfPreferences, |
246 base::Bind(&ChromeLauncherController::SetShelfBehaviorsFromPrefs, | 240 base::Bind(&ChromeLauncherController::SetShelfBehaviorsFromPrefs, |
247 base::Unretained(this))); | 241 base::Unretained(this))); |
248 | |
249 // This check is needed for win7_aura. Without this, all tests in | |
250 // ChromeLauncherControllerTest will fail by win7_aura. | |
251 if (ash::Shell::HasInstance()) | |
252 RegisterLauncherItemDelegate(); | |
253 } | 242 } |
254 | 243 |
255 ChromeLauncherController::~ChromeLauncherController() { | 244 ChromeLauncherController::~ChromeLauncherController() { |
256 // Reset the shell window controller here since it has a weak pointer to this. | 245 // Reset the shell window controller here since it has a weak pointer to this. |
257 shell_window_controller_.reset(); | 246 shell_window_controller_.reset(); |
258 | 247 |
259 for (std::set<ash::Launcher*>::iterator iter = launchers_.begin(); | 248 for (std::set<ash::Launcher*>::iterator iter = launchers_.begin(); |
260 iter != launchers_.end(); | 249 iter != launchers_.end(); |
261 ++iter) | 250 ++iter) |
262 (*iter)->shelf_widget()->shelf_layout_manager()->RemoveObserver(this); | 251 (*iter)->shelf_widget()->shelf_layout_manager()->RemoveObserver(this); |
263 | 252 |
264 model_->RemoveObserver(this); | 253 model_->RemoveObserver(this); |
265 if (ash::Shell::HasInstance()) | 254 if (ash::Shell::HasInstance()) |
266 ash::Shell::GetInstance()->display_controller()->RemoveObserver(this); | 255 ash::Shell::GetInstance()->display_controller()->RemoveObserver(this); |
267 for (IDToItemControllerMap::iterator i = id_to_item_controller_map_.begin(); | 256 for (IDToItemControllerMap::iterator i = id_to_item_controller_map_.begin(); |
268 i != id_to_item_controller_map_.end(); ++i) { | 257 i != id_to_item_controller_map_.end(); ++i) { |
269 i->second->OnRemoved(); | |
270 int index = model_->ItemIndexByID(i->first); | 258 int index = model_->ItemIndexByID(i->first); |
271 // A "browser proxy" is not known to the model and this removal does | 259 // A "browser proxy" is not known to the model and this removal does |
272 // therefore not need to be propagated to the model. | 260 // therefore not need to be propagated to the model. |
273 if (index != -1 && | 261 if (index != -1 && |
274 model_->items()[index].type != ash::TYPE_BROWSER_SHORTCUT) | 262 model_->items()[index].type != ash::TYPE_BROWSER_SHORTCUT) |
275 model_->RemoveItemAt(index); | 263 model_->RemoveItemAt(index); |
276 } | 264 } |
277 | 265 |
278 if (ash::Shell::HasInstance()) | 266 if (ash::Shell::HasInstance()) |
279 ash::Shell::GetInstance()->RemoveShellObserver(this); | 267 ash::Shell::GetInstance()->RemoveShellObserver(this); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 model_->Set(index, item); | 338 model_->Set(index, item); |
351 } | 339 } |
352 } | 340 } |
353 | 341 |
354 void ChromeLauncherController::SetItemController( | 342 void ChromeLauncherController::SetItemController( |
355 ash::LauncherID id, | 343 ash::LauncherID id, |
356 LauncherItemController* controller) { | 344 LauncherItemController* controller) { |
357 CHECK(controller); | 345 CHECK(controller); |
358 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); | 346 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); |
359 CHECK(iter != id_to_item_controller_map_.end()); | 347 CHECK(iter != id_to_item_controller_map_.end()); |
360 iter->second->OnRemoved(); | |
361 iter->second = controller; | 348 iter->second = controller; |
362 controller->set_launcher_id(id); | 349 controller->set_launcher_id(id); |
| 350 UpdateLauncherItemDelegate(id, controller); |
363 } | 351 } |
364 | 352 |
365 void ChromeLauncherController::CloseLauncherItem(ash::LauncherID id) { | 353 void ChromeLauncherController::CloseLauncherItem(ash::LauncherID id) { |
366 CHECK(id); | 354 CHECK(id); |
367 if (IsPinned(id)) { | 355 if (IsPinned(id)) { |
368 // Create a new shortcut controller. | 356 // Create a new shortcut controller. |
369 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); | 357 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); |
370 CHECK(iter != id_to_item_controller_map_.end()); | 358 CHECK(iter != id_to_item_controller_map_.end()); |
371 SetItemStatus(id, ash::STATUS_CLOSED); | 359 SetItemStatus(id, ash::STATUS_CLOSED); |
372 std::string app_id = iter->second->app_id(); | 360 std::string app_id = iter->second->app_id(); |
373 iter->second->OnRemoved(); | |
374 iter->second = new AppShortcutLauncherItemController(app_id, this); | 361 iter->second = new AppShortcutLauncherItemController(app_id, this); |
375 iter->second->set_launcher_id(id); | 362 iter->second->set_launcher_id(id); |
| 363 UpdateLauncherItemDelegate(id, iter->second); |
376 } else { | 364 } else { |
377 LauncherItemClosed(id); | 365 LauncherItemClosed(id); |
378 } | 366 } |
379 } | 367 } |
380 | 368 |
381 void ChromeLauncherController::Pin(ash::LauncherID id) { | 369 void ChromeLauncherController::Pin(ash::LauncherID id) { |
382 DCHECK(HasItemController(id)); | 370 DCHECK(HasItemController(id)); |
383 | 371 |
384 int index = model_->ItemIndexByID(id); | 372 int index = model_->ItemIndexByID(id); |
385 DCHECK_GE(index, 0); | 373 DCHECK_GE(index, 0); |
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
884 views::corewm::WINDOW_ANIMATION_TYPE_BOUNCE); | 872 views::corewm::WINDOW_ANIMATION_TYPE_BOUNCE); |
885 } else { | 873 } else { |
886 window->Minimize(); | 874 window->Minimize(); |
887 } | 875 } |
888 } else { | 876 } else { |
889 window->Show(); | 877 window->Show(); |
890 window->Activate(); | 878 window->Activate(); |
891 } | 879 } |
892 } | 880 } |
893 | 881 |
894 void ChromeLauncherController::ItemSelected(const ash::LauncherItem& item, | |
895 const ui::Event& event) { | |
896 DCHECK(HasItemController(item.id)); | |
897 LauncherItemController* item_controller = id_to_item_controller_map_[item.id]; | |
898 #if defined(OS_CHROMEOS) | |
899 if (!item_controller->app_id().empty()) { | |
900 chromeos::default_pinned_apps_field_trial::RecordShelfAppClick( | |
901 item_controller->app_id()); | |
902 } | |
903 #endif | |
904 item_controller->Clicked(event); | |
905 } | |
906 | |
907 string16 ChromeLauncherController::GetTitle(const ash::LauncherItem& item) { | |
908 DCHECK(HasItemController(item.id)); | |
909 return id_to_item_controller_map_[item.id]->GetTitle(); | |
910 } | |
911 | |
912 ui::MenuModel* ChromeLauncherController::CreateContextMenu( | |
913 const ash::LauncherItem& item, | |
914 aura::RootWindow* root_window) { | |
915 return new LauncherContextMenu(this, &item, root_window); | |
916 } | |
917 | |
918 ash::LauncherMenuModel* ChromeLauncherController::CreateApplicationMenu( | |
919 const ash::LauncherItem& item, | |
920 int event_flags) { | |
921 return new LauncherApplicationMenuItemModel(GetApplicationList(item, | |
922 event_flags)); | |
923 } | |
924 | |
925 ash::LauncherID ChromeLauncherController::GetIDByWindow(aura::Window* window) { | 882 ash::LauncherID ChromeLauncherController::GetIDByWindow(aura::Window* window) { |
926 int browser_index = ash::launcher::GetBrowserItemIndex(*model_); | 883 int browser_index = ash::launcher::GetBrowserItemIndex(*model_); |
927 DCHECK_GE(browser_index, 0); | 884 DCHECK_GE(browser_index, 0); |
928 ash::LauncherID browser_id = model_->items()[browser_index].id; | 885 ash::LauncherID browser_id = model_->items()[browser_index].id; |
929 | 886 |
930 IDToItemControllerMap::const_iterator i = id_to_item_controller_map_.begin(); | 887 IDToItemControllerMap::const_iterator i = id_to_item_controller_map_.begin(); |
931 for (; i != id_to_item_controller_map_.end(); ++i) { | 888 for (; i != id_to_item_controller_map_.end(); ++i) { |
932 // Since a |window| can be used by multiple applications, an explicit | 889 // Since a |window| can be used by multiple applications, an explicit |
933 // application always gets chosen over the generic browser. | 890 // application always gets chosen over the generic browser. |
934 if (i->first != browser_id && i->second->IsCurrentlyShownInWindow(window)) | 891 if (i->first != browser_id && i->second->IsCurrentlyShownInWindow(window)) |
935 return i->first; | 892 return i->first; |
936 } | 893 } |
937 | 894 |
938 if (i == id_to_item_controller_map_.end() && | 895 if (i == id_to_item_controller_map_.end() && |
939 GetBrowserShortcutLauncherItemController()-> | 896 GetBrowserShortcutLauncherItemController()-> |
940 IsCurrentlyShownInWindow(window)) | 897 IsCurrentlyShownInWindow(window)) |
941 return browser_id; | 898 return browser_id; |
942 | 899 |
943 return 0; | 900 return 0; |
944 } | 901 } |
945 | 902 |
946 bool ChromeLauncherController::IsDraggable(const ash::LauncherItem& item) { | |
947 return (item.type == ash::TYPE_APP_SHORTCUT || | |
948 item.type == ash::TYPE_WINDOWED_APP) ? CanPin() : true; | |
949 } | |
950 | |
951 bool ChromeLauncherController::ShouldShowTooltip( | |
952 const ash::LauncherItem& item) { | |
953 if (item.type == ash::TYPE_APP_PANEL && | |
954 id_to_item_controller_map_[item.id]->IsVisible()) | |
955 return false; | |
956 return true; | |
957 } | |
958 | |
959 void ChromeLauncherController::OnLauncherCreated(ash::Launcher* launcher) { | 903 void ChromeLauncherController::OnLauncherCreated(ash::Launcher* launcher) { |
960 launchers_.insert(launcher); | 904 launchers_.insert(launcher); |
961 launcher->shelf_widget()->shelf_layout_manager()->AddObserver(this); | 905 launcher->shelf_widget()->shelf_layout_manager()->AddObserver(this); |
962 } | 906 } |
963 | 907 |
964 void ChromeLauncherController::OnLauncherDestroyed(ash::Launcher* launcher) { | 908 void ChromeLauncherController::OnLauncherDestroyed(ash::Launcher* launcher) { |
965 launchers_.erase(launcher); | 909 launchers_.erase(launcher); |
966 // RemoveObserver is not called here, since by the time this method is called | 910 // RemoveObserver is not called here, since by the time this method is called |
967 // Launcher is already in its destructor. | 911 // Launcher is already in its destructor. |
968 } | 912 } |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1214 const std::string& app_id, | 1158 const std::string& app_id, |
1215 int index, | 1159 int index, |
1216 ash::LauncherItemType launcher_item_type) { | 1160 ash::LauncherItemType launcher_item_type) { |
1217 AppShortcutLauncherItemController* controller = | 1161 AppShortcutLauncherItemController* controller = |
1218 new AppShortcutLauncherItemController(app_id, this); | 1162 new AppShortcutLauncherItemController(app_id, this); |
1219 ash::LauncherID launcher_id = InsertAppLauncherItem( | 1163 ash::LauncherID launcher_id = InsertAppLauncherItem( |
1220 controller, app_id, ash::STATUS_CLOSED, index, launcher_item_type); | 1164 controller, app_id, ash::STATUS_CLOSED, index, launcher_item_type); |
1221 return launcher_id; | 1165 return launcher_id; |
1222 } | 1166 } |
1223 | 1167 |
| 1168 LauncherItemController* ChromeLauncherController::GetLauncherItemController( |
| 1169 const ash::LauncherID id) { |
| 1170 if (!HasItemController(id)) |
| 1171 return NULL; |
| 1172 return id_to_item_controller_map_[id]; |
| 1173 } |
| 1174 |
1224 Profile* ChromeLauncherController::GetProfileForNewWindows() { | 1175 Profile* ChromeLauncherController::GetProfileForNewWindows() { |
1225 return ProfileManager::GetDefaultProfileOrOffTheRecord(); | 1176 return ProfileManager::GetDefaultProfileOrOffTheRecord(); |
1226 } | 1177 } |
1227 | 1178 |
1228 void ChromeLauncherController::LauncherItemClosed(ash::LauncherID id) { | 1179 void ChromeLauncherController::LauncherItemClosed(ash::LauncherID id) { |
1229 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); | 1180 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); |
1230 CHECK(iter != id_to_item_controller_map_.end()); | 1181 CHECK(iter != id_to_item_controller_map_.end()); |
1231 CHECK(iter->second); | 1182 CHECK(iter->second); |
1232 app_icon_loader_->ClearImage(iter->second->app_id()); | 1183 app_icon_loader_->ClearImage(iter->second->app_id()); |
1233 iter->second->OnRemoved(); | |
1234 id_to_item_controller_map_.erase(iter); | 1184 id_to_item_controller_map_.erase(iter); |
1235 int index = model_->ItemIndexByID(id); | 1185 int index = model_->ItemIndexByID(id); |
1236 // A "browser proxy" is not known to the model and this removal does | 1186 // A "browser proxy" is not known to the model and this removal does |
1237 // therefore not need to be propagated to the model. | 1187 // therefore not need to be propagated to the model. |
1238 if (index != -1) | 1188 if (index != -1) |
1239 model_->RemoveItemAt(index); | 1189 model_->RemoveItemAt(index); |
1240 } | 1190 } |
1241 | 1191 |
1242 void ChromeLauncherController::DoPinAppWithID(const std::string& app_id) { | 1192 void ChromeLauncherController::DoPinAppWithID(const std::string& app_id) { |
1243 // If there is an item, do nothing and return. | 1193 // If there is an item, do nothing and return. |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1468 status = ash::STATUS_ACTIVE; | 1418 status = ash::STATUS_ACTIVE; |
1469 else | 1419 else |
1470 status = ash::STATUS_RUNNING; | 1420 status = ash::STATUS_RUNNING; |
1471 } | 1421 } |
1472 item.status = status; | 1422 item.status = status; |
1473 | 1423 |
1474 model_->AddAt(index, item); | 1424 model_->AddAt(index, item); |
1475 | 1425 |
1476 app_icon_loader_->FetchImage(app_id); | 1426 app_icon_loader_->FetchImage(app_id); |
1477 | 1427 |
| 1428 RegisterLauncherItemDelegate(id, controller); |
| 1429 |
1478 return id; | 1430 return id; |
1479 } | 1431 } |
1480 | 1432 |
1481 bool ChromeLauncherController::HasItemController(ash::LauncherID id) const { | 1433 bool ChromeLauncherController::HasItemController(ash::LauncherID id) const { |
1482 return id_to_item_controller_map_.find(id) != | 1434 return id_to_item_controller_map_.find(id) != |
1483 id_to_item_controller_map_.end(); | 1435 id_to_item_controller_map_.end(); |
1484 } | 1436 } |
1485 | 1437 |
1486 std::vector<content::WebContents*> | 1438 std::vector<content::WebContents*> |
1487 ChromeLauncherController::GetV1ApplicationsFromController( | 1439 ChromeLauncherController::GetV1ApplicationsFromController( |
(...skipping 22 matching lines...) Expand all Loading... |
1510 } | 1462 } |
1511 | 1463 |
1512 ash::LauncherID ChromeLauncherController::CreateBrowserShortcutLauncherItem() { | 1464 ash::LauncherID ChromeLauncherController::CreateBrowserShortcutLauncherItem() { |
1513 ash::LauncherItem browser_shortcut; | 1465 ash::LauncherItem browser_shortcut; |
1514 browser_shortcut.type = ash::TYPE_BROWSER_SHORTCUT; | 1466 browser_shortcut.type = ash::TYPE_BROWSER_SHORTCUT; |
1515 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 1467 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
1516 browser_shortcut.image = *rb.GetImageSkiaNamed(IDR_PRODUCT_LOGO_32); | 1468 browser_shortcut.image = *rb.GetImageSkiaNamed(IDR_PRODUCT_LOGO_32); |
1517 ash::LauncherID id = model_->next_id(); | 1469 ash::LauncherID id = model_->next_id(); |
1518 size_t index = GetChromeIconIndexFromPref(); | 1470 size_t index = GetChromeIconIndexFromPref(); |
1519 model_->AddAt(index, browser_shortcut); | 1471 model_->AddAt(index, browser_shortcut); |
1520 browser_item_controller_.reset( | 1472 id_to_item_controller_map_[id] = |
1521 new BrowserShortcutLauncherItemController(this, profile_)); | 1473 new BrowserShortcutLauncherItemController(this, profile_); |
1522 id_to_item_controller_map_[id] = browser_item_controller_.get(); | |
1523 id_to_item_controller_map_[id]->set_launcher_id(id); | 1474 id_to_item_controller_map_[id]->set_launcher_id(id); |
| 1475 // LauncherItemDelegateManager owns BrowserShortcutLauncherItemController. |
| 1476 RegisterLauncherItemDelegate(id, id_to_item_controller_map_[id]); |
1524 return id; | 1477 return id; |
1525 } | 1478 } |
1526 | 1479 |
1527 void ChromeLauncherController::PersistChromeItemIndex(int index) { | 1480 void ChromeLauncherController::PersistChromeItemIndex(int index) { |
1528 profile_->GetPrefs()->SetInteger(prefs::kShelfChromeIconIndex, index); | 1481 profile_->GetPrefs()->SetInteger(prefs::kShelfChromeIconIndex, index); |
1529 } | 1482 } |
1530 | 1483 |
1531 int ChromeLauncherController::GetChromeIconIndexFromPref() const { | 1484 int ChromeLauncherController::GetChromeIconIndexFromPref() const { |
1532 size_t index = profile_->GetPrefs()->GetInteger(prefs::kShelfChromeIconIndex); | 1485 size_t index = profile_->GetPrefs()->GetInteger(prefs::kShelfChromeIconIndex); |
1533 const base::ListValue* pinned_apps_pref = | 1486 const base::ListValue* pinned_apps_pref = |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1572 } | 1525 } |
1573 } | 1526 } |
1574 | 1527 |
1575 void | 1528 void |
1576 ChromeLauncherController::MoveItemWithoutPinnedStateChangeNotification( | 1529 ChromeLauncherController::MoveItemWithoutPinnedStateChangeNotification( |
1577 int source_index, int target_index) { | 1530 int source_index, int target_index) { |
1578 base::AutoReset<bool> auto_reset(&ignore_persist_pinned_state_change_, true); | 1531 base::AutoReset<bool> auto_reset(&ignore_persist_pinned_state_change_, true); |
1579 model_->Move(source_index, target_index); | 1532 model_->Move(source_index, target_index); |
1580 } | 1533 } |
1581 | 1534 |
1582 void ChromeLauncherController::RegisterLauncherItemDelegate() { | 1535 void ChromeLauncherController::RegisterLauncherItemDelegate( |
1583 // TODO(simon.hong81): Register LauncherItemDelegate when LauncherItemDelegate | 1536 ash::LauncherID id, |
1584 // is created. | 1537 ash::LauncherItemDelegate* item_delegate) { |
| 1538 DCHECK_GT(id, 0); |
| 1539 DCHECK(item_delegate); |
| 1540 // This check needs for win7_aura. RegisterLauncherItemDelegate() access |
| 1541 // Shell. Without this ChromeLauncherControllerTest.BrowserMenuGeneration test |
| 1542 // will fail. |
| 1543 if (!ash::Shell::HasInstance()) |
| 1544 return; |
| 1545 |
1585 ash::LauncherItemDelegateManager* manager = | 1546 ash::LauncherItemDelegateManager* manager = |
1586 ash::Shell::GetInstance()->launcher_item_delegate_manager(); | 1547 ash::Shell::GetInstance()->launcher_item_delegate_manager(); |
1587 manager->RegisterLauncherItemDelegate(ash::TYPE_APP_PANEL, this); | 1548 manager->RegisterLauncherItemDelegate(id, item_delegate); |
1588 manager->RegisterLauncherItemDelegate(ash::TYPE_APP_SHORTCUT, this); | |
1589 manager->RegisterLauncherItemDelegate(ash::TYPE_BROWSER_SHORTCUT, this); | |
1590 manager->RegisterLauncherItemDelegate(ash::TYPE_PLATFORM_APP, this); | |
1591 manager->RegisterLauncherItemDelegate(ash::TYPE_WINDOWED_APP, this); | |
1592 } | 1549 } |
| 1550 |
| 1551 void ChromeLauncherController::UpdateLauncherItemDelegate( |
| 1552 ash::LauncherID id, |
| 1553 ash::LauncherItemDelegate* item_delegate) { |
| 1554 DCHECK_GT(id, 0); |
| 1555 // This check needs for win7_aura. UpdateLauncherItemDelegate() access Shell. |
| 1556 // Without this ChromeLauncherControllerTest.BrowserMenuGeneration test will |
| 1557 // fail. |
| 1558 |
| 1559 if (!ash::Shell::HasInstance()) |
| 1560 return; |
| 1561 |
| 1562 // Don't remove BrowserShortcutLauncherItemDelegate. It can be removed only |
| 1563 // after Launcher is destroyed. |
| 1564 DCHECK(id != ash::launcher::GetBrowserItemID(*model_)); |
| 1565 |
| 1566 ash::LauncherItemDelegateManager* manager = |
| 1567 ash::Shell::GetInstance()->launcher_item_delegate_manager(); |
| 1568 manager->UpdateLauncherItemDelegate(id, item_delegate); |
| 1569 } |
OLD | NEW |