Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(717)

Side by Side Diff: chrome/browser/ui/views/aura/launcher/chrome_launcher_delegate.cc

Issue 9590001: Launch panels as popup windows in Aura, and add separate launcher icon logic for panels. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Eliminate ash::TYPE_PANEL Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/aura/launcher/chrome_launcher_delegate.h" 5 #include "chrome/browser/ui/views/aura/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
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
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
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 app_icon_loader_->FetchImage(app_id);
187 return id; 194 return id;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 if (updater) { 292 if (updater) {
286 updater->window()->Show(); 293 updater->window()->Show();
287 ash::wm::ActivateWindow(updater->window()); 294 ash::wm::ActivateWindow(updater->window());
288 TabContentsWrapper* tab = updater->GetTab(id); 295 TabContentsWrapper* tab = updater->GetTab(id);
289 if (tab) { 296 if (tab) {
290 updater->tab_model()->ActivateTabAt( 297 updater->tab_model()->ActivateTabAt(
291 updater->tab_model()->GetIndexOfTabContents(tab), true); 298 updater->tab_model()->GetIndexOfTabContents(tab), true);
292 } 299 }
293 } else { 300 } else {
294 DCHECK_EQ(TYPE_APP, id_to_item_map_[id].item_type); 301 DCHECK_EQ(TYPE_APP, id_to_item_map_[id].item_type);
295 if (id_to_item_map_[id].app_type == APP_TYPE_TAB) { 302 AppType app_type = id_to_item_map_[id].app_type;
303 if (app_type == APP_TYPE_TAB) {
296 const Extension* extension = 304 const Extension* extension =
297 profile_->GetExtensionService()->GetInstalledExtension( 305 profile_->GetExtensionService()->GetInstalledExtension(
298 id_to_item_map_[id].app_id); 306 id_to_item_map_[id].app_id);
299 DCHECK(extension); 307 DCHECK(extension);
300 Browser::OpenApplicationTab(GetProfileForNewWindows(), extension, GURL(), 308 Browser::OpenApplicationTab(GetProfileForNewWindows(), extension, GURL(),
301 NEW_FOREGROUND_TAB); 309 NEW_FOREGROUND_TAB);
302 if (id_to_item_map_[id].updater) 310 if (id_to_item_map_[id].updater)
303 id_to_item_map_[id].updater->window()->Show(); 311 id_to_item_map_[id].updater->window()->Show();
304 } else { 312 } else {
305 std::string app_name = web_app::GenerateApplicationNameFromExtensionId( 313 std::string app_name = web_app::GenerateApplicationNameFromExtensionId(
306 id_to_item_map_[id].app_id); 314 id_to_item_map_[id].app_id);
315 Browser::Type browser_type = (app_type == APP_TYPE_PANEL) ?
316 Browser::TYPE_PANEL : Browser::TYPE_POPUP;
307 Browser* browser = Browser::CreateForApp( 317 Browser* browser = Browser::CreateForApp(
308 Browser::TYPE_POPUP, app_name, gfx::Rect(), 318 browser_type, app_name, gfx::Rect(), GetProfileForNewWindows());
309 GetProfileForNewWindows());
310 browser->window()->Show(); 319 browser->window()->Show();
311 } 320 }
312 } 321 }
313 } 322 }
314 323
315 void ChromeLauncherDelegate::Close(ash::LauncherID id) { 324 void ChromeLauncherDelegate::Close(ash::LauncherID id) {
316 if (id_to_item_map_.find(id) == id_to_item_map_.end()) 325 if (id_to_item_map_.find(id) == id_to_item_map_.end())
317 return; // May happen if menu closed. 326 return; // May happen if menu closed.
318 327
319 if (!id_to_item_map_[id].updater) 328 if (!id_to_item_map_[id].updater)
(...skipping 25 matching lines...) Expand all
345 DCHECK(id_to_item_map_.find(id) != id_to_item_map_.end()); 354 DCHECK(id_to_item_map_.find(id) != id_to_item_map_.end());
346 return id_to_item_map_[id].app_type; 355 return id_to_item_map_[id].app_type;
347 } 356 }
348 357
349 std::string ChromeLauncherDelegate::GetAppID(TabContentsWrapper* tab) { 358 std::string ChromeLauncherDelegate::GetAppID(TabContentsWrapper* tab) {
350 return app_icon_loader_->GetAppID(tab); 359 return app_icon_loader_->GetAppID(tab);
351 } 360 }
352 361
353 void ChromeLauncherDelegate::SetAppImage(const std::string& id, 362 void ChromeLauncherDelegate::SetAppImage(const std::string& id,
354 SkBitmap* image) { 363 SkBitmap* image) {
364 if (!image)
365 return;
355 for (IDToItemMap::const_iterator i = id_to_item_map_.begin(); 366 for (IDToItemMap::const_iterator i = id_to_item_map_.begin();
356 i != id_to_item_map_.end(); ++i) { 367 i != id_to_item_map_.end(); ++i) {
357 if (i->second.app_id == id) { 368 if (i->second.app_id == id &&
369 (!i->second.updater ||
370 i->second.updater->type() != LauncherUpdater::TYPE_PANEL)) {
sky 2012/03/05 15:20:25 Rather than this if, could you avoid asking for th
stevenjb 2012/03/05 19:50:06 Looking through the code again (with a bit more fa
358 int index = model_->ItemIndexByID(i->first); 371 int index = model_->ItemIndexByID(i->first);
359 ash::LauncherItem item = model_->items()[index]; 372 ash::LauncherItem item = model_->items()[index];
360 item.image = image ? *image : Extension::GetDefaultIcon(true); 373 item.image = *image;
361 model_->Set(index, item); 374 model_->Set(index, item);
362 // It's possible we're waiting on more than one item, so don't break. 375 // It's possible we're waiting on more than one item, so don't break.
363 } 376 }
364 } 377 }
365 } 378 }
366 379
367 void ChromeLauncherDelegate::CreateNewWindow() { 380 void ChromeLauncherDelegate::CreateNewWindow() {
368 Browser::OpenEmptyWindow(GetProfileForNewWindows()); 381 Browser::OpenEmptyWindow(GetProfileForNewWindows());
369 } 382 }
370 383
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 void ChromeLauncherDelegate::PersistPinnedState() { 449 void ChromeLauncherDelegate::PersistPinnedState() {
437 ListPrefUpdate updater(profile_->GetPrefs(), prefs::kPinnedLauncherApps); 450 ListPrefUpdate updater(profile_->GetPrefs(), prefs::kPinnedLauncherApps);
438 updater.Get()->Clear(); 451 updater.Get()->Clear();
439 for (size_t i = 0; i < model_->items().size(); ++i) { 452 for (size_t i = 0; i < model_->items().size(); ++i) {
440 if (model_->items()[i].type == ash::TYPE_APP) { 453 if (model_->items()[i].type == ash::TYPE_APP) {
441 ash::LauncherID id = model_->items()[i].id; 454 ash::LauncherID id = model_->items()[i].id;
442 if (id_to_item_map_.find(id) != id_to_item_map_.end() && 455 if (id_to_item_map_.find(id) != id_to_item_map_.end() &&
443 id_to_item_map_[id].pinned) { 456 id_to_item_map_[id].pinned) {
444 base::DictionaryValue* app_value = new base::DictionaryValue; 457 base::DictionaryValue* app_value = new base::DictionaryValue;
445 app_value->SetString(kAppIDPath, id_to_item_map_[id].app_id); 458 app_value->SetString(kAppIDPath, id_to_item_map_[id].app_id);
446 const char* app_type_string = 459 const char* app_type_string;
447 id_to_item_map_[id].app_type == APP_TYPE_WINDOW ? 460 if (id_to_item_map_[id].app_type == APP_TYPE_WINDOW)
448 kAppTypeWindow : kAppTypeTab; 461 app_type_string = kAppTypeWindow;
462 else if (id_to_item_map_[id].app_type == APP_TYPE_PANEL)
463 app_type_string = kAppTypePanel;
464 else
465 app_type_string = kAppTypeTab;
449 app_value->SetString(kAppTypePath, app_type_string); 466 app_value->SetString(kAppTypePath, app_type_string);
450 updater.Get()->Append(app_value); 467 updater.Get()->Append(app_value);
451 } 468 }
452 } 469 }
453 } 470 }
454 } 471 }
455 472
456 void ChromeLauncherDelegate::UnpinAppsWithID(const std::string& app_id) { 473 void ChromeLauncherDelegate::UnpinAppsWithID(const std::string& app_id) {
457 for (IDToItemMap::iterator i = id_to_item_map_.begin(); 474 for (IDToItemMap::iterator i = id_to_item_map_.begin();
458 i != id_to_item_map_.end(); ) { 475 i != id_to_item_map_.end(); ) {
(...skipping 11 matching lines...) Expand all
470 Profile* ChromeLauncherDelegate::GetProfileForNewWindows() { 487 Profile* ChromeLauncherDelegate::GetProfileForNewWindows() {
471 Profile* profile = ProfileManager::GetDefaultProfile(); 488 Profile* profile = ProfileManager::GetDefaultProfile();
472 if (browser_defaults::kAlwaysOpenIncognitoWindow && 489 if (browser_defaults::kAlwaysOpenIncognitoWindow &&
473 IncognitoModePrefs::ShouldLaunchIncognito( 490 IncognitoModePrefs::ShouldLaunchIncognito(
474 *CommandLine::ForCurrentProcess(), 491 *CommandLine::ForCurrentProcess(),
475 profile->GetPrefs())) { 492 profile->GetPrefs())) {
476 profile = profile->GetOffTheRecordProfile(); 493 profile = profile->GetOffTheRecordProfile();
477 } 494 }
478 return profile; 495 return profile;
479 } 496 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698