OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/views/ash/launcher/chrome_launcher_delegate.h" | 5 #include "chrome/browser/ui/views/ash/launcher/chrome_launcher_delegate.h" |
6 | 6 |
7 #include "ash/launcher/launcher_model.h" | 7 #include "ash/launcher/launcher_model.h" |
8 #include "ash/launcher/launcher_types.h" | 8 #include "ash/launcher/launcher_types.h" |
9 #include "ash/wm/window_util.h" | 9 #include "ash/wm/window_util.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 #include "content/public/browser/notification_service.h" | 32 #include "content/public/browser/notification_service.h" |
33 #include "content/public/browser/web_contents.h" | 33 #include "content/public/browser/web_contents.h" |
34 #include "grit/theme_resources.h" | 34 #include "grit/theme_resources.h" |
35 #include "ui/aura/window.h" | 35 #include "ui/aura/window.h" |
36 #include "ui/views/widget/widget.h" | 36 #include "ui/views/widget/widget.h" |
37 | 37 |
38 namespace { | 38 namespace { |
39 | 39 |
40 // See description in PersistPinnedState(). | 40 // See description in PersistPinnedState(). |
41 const char kAppIDPath[] = "id"; | 41 const char kAppIDPath[] = "id"; |
| 42 const char kAppTypePanel[] = "panel"; |
42 const char kAppTypePath[] = "type"; | 43 const char kAppTypePath[] = "type"; |
43 const char kAppTypeTab[] = "tab"; | 44 const char kAppTypeTab[] = "tab"; |
44 const char kAppTypeWindow[] = "window"; | 45 const char kAppTypeWindow[] = "window"; |
45 | 46 |
46 } // namespace | 47 } // namespace |
47 | 48 |
48 // ChromeLauncherDelegate::Item ------------------------------------------------ | 49 // ChromeLauncherDelegate::Item ------------------------------------------------ |
49 | 50 |
50 ChromeLauncherDelegate::Item::Item() | 51 ChromeLauncherDelegate::Item::Item() |
51 : item_type(TYPE_TABBED_BROWSER), | 52 : item_type(TYPE_TABBED_BROWSER), |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 void ChromeLauncherDelegate::Init() { | 93 void ChromeLauncherDelegate::Init() { |
93 const base::ListValue* pinned_apps = | 94 const base::ListValue* pinned_apps = |
94 profile_->GetPrefs()->GetList(prefs::kPinnedLauncherApps); | 95 profile_->GetPrefs()->GetList(prefs::kPinnedLauncherApps); |
95 for (size_t i = 0; i < pinned_apps->GetSize(); ++i) { | 96 for (size_t i = 0; i < pinned_apps->GetSize(); ++i) { |
96 DictionaryValue* app = NULL; | 97 DictionaryValue* app = NULL; |
97 if (pinned_apps->GetDictionary(i, &app)) { | 98 if (pinned_apps->GetDictionary(i, &app)) { |
98 std::string app_id, type_string; | 99 std::string app_id, type_string; |
99 if (app->GetString(kAppIDPath, &app_id) && | 100 if (app->GetString(kAppIDPath, &app_id) && |
100 app->GetString(kAppTypePath, &type_string) && | 101 app->GetString(kAppTypePath, &type_string) && |
101 app_icon_loader_->IsValidID(app_id)) { | 102 app_icon_loader_->IsValidID(app_id)) { |
102 AppType app_type = (type_string == kAppTypeWindow) ? | 103 AppType app_type; |
103 APP_TYPE_WINDOW : APP_TYPE_TAB; | 104 if (type_string == kAppTypeWindow) |
| 105 app_type = APP_TYPE_WINDOW; |
| 106 else if (type_string == kAppTypePanel) |
| 107 app_type = APP_TYPE_PANEL; |
| 108 else |
| 109 app_type = APP_TYPE_TAB; |
104 CreateAppLauncherItem(NULL, app_id, app_type); | 110 CreateAppLauncherItem(NULL, app_id, app_type); |
105 } | 111 } |
106 } | 112 } |
107 } | 113 } |
108 } | 114 } |
109 | 115 |
110 // static | 116 // static |
111 void ChromeLauncherDelegate::RegisterUserPrefs(PrefService* user_prefs) { | 117 void ChromeLauncherDelegate::RegisterUserPrefs(PrefService* user_prefs) { |
112 // TODO: If we want to support multiple profiles this will likely need to be | 118 // TODO: If we want to support multiple profiles this will likely need to be |
113 // pushed to local state and we'll need to track profile per item. | 119 // pushed to local state and we'll need to track profile per item. |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 min_tab_index = | 174 min_tab_index = |
169 std::min(min_app_index, model_->ItemIndexByID(i->first)); | 175 std::min(min_app_index, model_->ItemIndexByID(i->first)); |
170 } | 176 } |
171 } | 177 } |
172 } | 178 } |
173 } | 179 } |
174 int insert_index = min_app_index != item_count ? | 180 int insert_index = min_app_index != item_count ? |
175 min_app_index : std::min(item_count, min_tab_index + 1); | 181 min_app_index : std::min(item_count, min_tab_index + 1); |
176 ash::LauncherID id = model_->next_id(); | 182 ash::LauncherID id = model_->next_id(); |
177 ash::LauncherItem item(ash::TYPE_APP); | 183 ash::LauncherItem item(ash::TYPE_APP); |
| 184 item.image = Extension::GetDefaultIcon(true); |
178 model_->Add(insert_index, item); | 185 model_->Add(insert_index, item); |
179 DCHECK(id_to_item_map_.find(id) == id_to_item_map_.end()); | 186 DCHECK(id_to_item_map_.find(id) == id_to_item_map_.end()); |
180 id_to_item_map_[id].item_type = TYPE_APP; | 187 id_to_item_map_[id].item_type = TYPE_APP; |
181 id_to_item_map_[id].app_type = app_type; | 188 id_to_item_map_[id].app_type = app_type; |
182 id_to_item_map_[id].app_id = app_id; | 189 id_to_item_map_[id].app_id = app_id; |
183 id_to_item_map_[id].updater = updater; | 190 id_to_item_map_[id].updater = updater; |
184 id_to_item_map_[id].pinned = updater == NULL; | 191 id_to_item_map_[id].pinned = updater == NULL; |
185 | 192 |
186 app_icon_loader_->FetchImage(app_id); | 193 if (app_type != APP_TYPE_PANEL) |
| 194 app_icon_loader_->FetchImage(app_id); |
187 return id; | 195 return id; |
188 } | 196 } |
189 | 197 |
190 void ChromeLauncherDelegate::ConvertAppToTabbed(ash::LauncherID id) { | 198 void ChromeLauncherDelegate::ConvertAppToTabbed(ash::LauncherID id) { |
191 DCHECK(id_to_item_map_.find(id) != id_to_item_map_.end()); | 199 DCHECK(id_to_item_map_.find(id) != id_to_item_map_.end()); |
192 DCHECK_EQ(TYPE_APP, id_to_item_map_[id].item_type); | 200 DCHECK_EQ(TYPE_APP, id_to_item_map_[id].item_type); |
193 DCHECK(!id_to_item_map_[id].pinned); | 201 DCHECK(!id_to_item_map_[id].pinned); |
194 id_to_item_map_[id].item_type = TYPE_TABBED_BROWSER; | 202 id_to_item_map_[id].item_type = TYPE_TABBED_BROWSER; |
195 id_to_item_map_[id].app_id.clear(); | 203 id_to_item_map_[id].app_id.clear(); |
196 } | 204 } |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 if (updater) { | 293 if (updater) { |
286 updater->window()->Show(); | 294 updater->window()->Show(); |
287 ash::wm::ActivateWindow(updater->window()); | 295 ash::wm::ActivateWindow(updater->window()); |
288 TabContentsWrapper* tab = updater->GetTab(id); | 296 TabContentsWrapper* tab = updater->GetTab(id); |
289 if (tab) { | 297 if (tab) { |
290 updater->tab_model()->ActivateTabAt( | 298 updater->tab_model()->ActivateTabAt( |
291 updater->tab_model()->GetIndexOfTabContents(tab), true); | 299 updater->tab_model()->GetIndexOfTabContents(tab), true); |
292 } | 300 } |
293 } else { | 301 } else { |
294 DCHECK_EQ(TYPE_APP, id_to_item_map_[id].item_type); | 302 DCHECK_EQ(TYPE_APP, id_to_item_map_[id].item_type); |
295 if (id_to_item_map_[id].app_type == APP_TYPE_TAB) { | 303 AppType app_type = id_to_item_map_[id].app_type; |
| 304 if (app_type == APP_TYPE_TAB) { |
296 const Extension* extension = | 305 const Extension* extension = |
297 profile_->GetExtensionService()->GetInstalledExtension( | 306 profile_->GetExtensionService()->GetInstalledExtension( |
298 id_to_item_map_[id].app_id); | 307 id_to_item_map_[id].app_id); |
299 DCHECK(extension); | 308 DCHECK(extension); |
300 Browser::OpenApplicationTab(GetProfileForNewWindows(), extension, GURL(), | 309 Browser::OpenApplicationTab(GetProfileForNewWindows(), extension, GURL(), |
301 NEW_FOREGROUND_TAB); | 310 NEW_FOREGROUND_TAB); |
302 if (id_to_item_map_[id].updater) | 311 if (id_to_item_map_[id].updater) |
303 id_to_item_map_[id].updater->window()->Show(); | 312 id_to_item_map_[id].updater->window()->Show(); |
304 } else { | 313 } else { |
305 std::string app_name = web_app::GenerateApplicationNameFromExtensionId( | 314 std::string app_name = web_app::GenerateApplicationNameFromExtensionId( |
306 id_to_item_map_[id].app_id); | 315 id_to_item_map_[id].app_id); |
| 316 Browser::Type browser_type = (app_type == APP_TYPE_PANEL) ? |
| 317 Browser::TYPE_PANEL : Browser::TYPE_POPUP; |
307 Browser* browser = Browser::CreateForApp( | 318 Browser* browser = Browser::CreateForApp( |
308 Browser::TYPE_POPUP, app_name, gfx::Rect(), | 319 browser_type, app_name, gfx::Rect(), GetProfileForNewWindows()); |
309 GetProfileForNewWindows()); | |
310 browser->window()->Show(); | 320 browser->window()->Show(); |
311 } | 321 } |
312 } | 322 } |
313 } | 323 } |
314 | 324 |
315 void ChromeLauncherDelegate::Close(ash::LauncherID id) { | 325 void ChromeLauncherDelegate::Close(ash::LauncherID id) { |
316 if (id_to_item_map_.find(id) == id_to_item_map_.end()) | 326 if (id_to_item_map_.find(id) == id_to_item_map_.end()) |
317 return; // May happen if menu closed. | 327 return; // May happen if menu closed. |
318 | 328 |
319 if (!id_to_item_map_[id].updater) | 329 if (!id_to_item_map_[id].updater) |
(...skipping 27 matching lines...) Expand all Loading... |
347 } | 357 } |
348 | 358 |
349 std::string ChromeLauncherDelegate::GetAppID(TabContentsWrapper* tab) { | 359 std::string ChromeLauncherDelegate::GetAppID(TabContentsWrapper* tab) { |
350 return app_icon_loader_->GetAppID(tab); | 360 return app_icon_loader_->GetAppID(tab); |
351 } | 361 } |
352 | 362 |
353 void ChromeLauncherDelegate::SetAppImage(const std::string& id, | 363 void ChromeLauncherDelegate::SetAppImage(const std::string& id, |
354 const SkBitmap* image) { | 364 const SkBitmap* image) { |
355 for (IDToItemMap::const_iterator i = id_to_item_map_.begin(); | 365 for (IDToItemMap::const_iterator i = id_to_item_map_.begin(); |
356 i != id_to_item_map_.end(); ++i) { | 366 i != id_to_item_map_.end(); ++i) { |
357 if (i->second.app_id == id) { | 367 if (i->second.app_id != id) |
358 int index = model_->ItemIndexByID(i->first); | 368 continue; |
359 ash::LauncherItem item = model_->items()[index]; | 369 // Panel items may share the same app_id as the app that created them, |
| 370 // but they set their icon image in LauncherUpdater::UpdateLauncher(), |
| 371 // so do not set panel images here. |
| 372 if (i->second.app_type == APP_TYPE_PANEL) |
| 373 continue; |
| 374 int index = model_->ItemIndexByID(i->first); |
| 375 ash::LauncherItem item = model_->items()[index]; |
360 item.image = image ? *image : Extension::GetDefaultIcon(true); | 376 item.image = image ? *image : Extension::GetDefaultIcon(true); |
361 model_->Set(index, item); | 377 model_->Set(index, item); |
362 // It's possible we're waiting on more than one item, so don't break. | 378 // It's possible we're waiting on more than one item, so don't break. |
363 } | |
364 } | 379 } |
365 } | 380 } |
366 | 381 |
367 void ChromeLauncherDelegate::CreateNewWindow() { | 382 void ChromeLauncherDelegate::CreateNewWindow() { |
368 Browser::OpenEmptyWindow(GetProfileForNewWindows()); | 383 Browser::OpenEmptyWindow(GetProfileForNewWindows()); |
369 } | 384 } |
370 | 385 |
371 void ChromeLauncherDelegate::ItemClicked(const ash::LauncherItem& item) { | 386 void ChromeLauncherDelegate::ItemClicked(const ash::LauncherItem& item) { |
372 DCHECK(id_to_item_map_.find(item.id) != id_to_item_map_.end()); | 387 DCHECK(id_to_item_map_.find(item.id) != id_to_item_map_.end()); |
373 Open(item.id); | 388 Open(item.id); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 void ChromeLauncherDelegate::PersistPinnedState() { | 451 void ChromeLauncherDelegate::PersistPinnedState() { |
437 ListPrefUpdate updater(profile_->GetPrefs(), prefs::kPinnedLauncherApps); | 452 ListPrefUpdate updater(profile_->GetPrefs(), prefs::kPinnedLauncherApps); |
438 updater.Get()->Clear(); | 453 updater.Get()->Clear(); |
439 for (size_t i = 0; i < model_->items().size(); ++i) { | 454 for (size_t i = 0; i < model_->items().size(); ++i) { |
440 if (model_->items()[i].type == ash::TYPE_APP) { | 455 if (model_->items()[i].type == ash::TYPE_APP) { |
441 ash::LauncherID id = model_->items()[i].id; | 456 ash::LauncherID id = model_->items()[i].id; |
442 if (id_to_item_map_.find(id) != id_to_item_map_.end() && | 457 if (id_to_item_map_.find(id) != id_to_item_map_.end() && |
443 id_to_item_map_[id].pinned) { | 458 id_to_item_map_[id].pinned) { |
444 base::DictionaryValue* app_value = new base::DictionaryValue; | 459 base::DictionaryValue* app_value = new base::DictionaryValue; |
445 app_value->SetString(kAppIDPath, id_to_item_map_[id].app_id); | 460 app_value->SetString(kAppIDPath, id_to_item_map_[id].app_id); |
446 const char* app_type_string = | 461 const char* app_type_string; |
447 id_to_item_map_[id].app_type == APP_TYPE_WINDOW ? | 462 if (id_to_item_map_[id].app_type == APP_TYPE_WINDOW) |
448 kAppTypeWindow : kAppTypeTab; | 463 app_type_string = kAppTypeWindow; |
| 464 else if (id_to_item_map_[id].app_type == APP_TYPE_PANEL) |
| 465 app_type_string = kAppTypePanel; |
| 466 else |
| 467 app_type_string = kAppTypeTab; |
449 app_value->SetString(kAppTypePath, app_type_string); | 468 app_value->SetString(kAppTypePath, app_type_string); |
450 updater.Get()->Append(app_value); | 469 updater.Get()->Append(app_value); |
451 } | 470 } |
452 } | 471 } |
453 } | 472 } |
454 } | 473 } |
455 | 474 |
456 void ChromeLauncherDelegate::UnpinAppsWithID(const std::string& app_id) { | 475 void ChromeLauncherDelegate::UnpinAppsWithID(const std::string& app_id) { |
457 for (IDToItemMap::iterator i = id_to_item_map_.begin(); | 476 for (IDToItemMap::iterator i = id_to_item_map_.begin(); |
458 i != id_to_item_map_.end(); ) { | 477 i != id_to_item_map_.end(); ) { |
(...skipping 11 matching lines...) Expand all Loading... |
470 Profile* ChromeLauncherDelegate::GetProfileForNewWindows() { | 489 Profile* ChromeLauncherDelegate::GetProfileForNewWindows() { |
471 Profile* profile = ProfileManager::GetDefaultProfile(); | 490 Profile* profile = ProfileManager::GetDefaultProfile(); |
472 if (browser_defaults::kAlwaysOpenIncognitoWindow && | 491 if (browser_defaults::kAlwaysOpenIncognitoWindow && |
473 IncognitoModePrefs::ShouldLaunchIncognito( | 492 IncognitoModePrefs::ShouldLaunchIncognito( |
474 *CommandLine::ForCurrentProcess(), | 493 *CommandLine::ForCurrentProcess(), |
475 profile->GetPrefs())) { | 494 profile->GetPrefs())) { |
476 profile = profile->GetOffTheRecordProfile(); | 495 profile = profile->GetOffTheRecordProfile(); |
477 } | 496 } |
478 return profile; | 497 return profile; |
479 } | 498 } |
OLD | NEW |