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

Side by Side Diff: chrome/browser/ui/views/ash/launcher/chrome_launcher_controller.cc

Issue 10445043: browser: Handle the registration of ChromeLauncher prefs outside of views. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 7 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 | Annotate | Revision Log
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/ash/launcher/chrome_launcher_controller.h" 5 #include "chrome/browser/ui/views/ash/launcher/chrome_launcher_controller.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/shell.h" 9 #include "ash/shell.h"
10 #include "ash/wm/window_util.h" 10 #include "ash/wm/window_util.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "chrome/browser/defaults.h" 14 #include "chrome/browser/defaults.h"
15 #include "chrome/browser/extensions/extension_service.h" 15 #include "chrome/browser/extensions/extension_service.h"
16 #include "chrome/browser/prefs/incognito_mode_prefs.h" 16 #include "chrome/browser/prefs/incognito_mode_prefs.h"
17 #include "chrome/browser/prefs/pref_service.h" 17 #include "chrome/browser/prefs/pref_service.h"
18 #include "chrome/browser/prefs/scoped_user_pref_update.h" 18 #include "chrome/browser/prefs/scoped_user_pref_update.h"
19 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/profiles/profile_manager.h" 20 #include "chrome/browser/profiles/profile_manager.h"
21 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h"
21 #include "chrome/browser/ui/browser.h" 22 #include "chrome/browser/ui/browser.h"
22 #include "chrome/browser/ui/browser_finder.h" 23 #include "chrome/browser/ui/browser_finder.h"
23 #include "chrome/browser/ui/browser_window.h" 24 #include "chrome/browser/ui/browser_window.h"
24 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 25 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
25 #include "chrome/browser/ui/tabs/tab_strip_model.h" 26 #include "chrome/browser/ui/tabs/tab_strip_model.h"
26 #include "chrome/browser/ui/views/ash/extension_utils.h" 27 #include "chrome/browser/ui/views/ash/extension_utils.h"
27 #include "chrome/browser/ui/views/ash/launcher/browser_launcher_item_controller. h" 28 #include "chrome/browser/ui/views/ash/launcher/browser_launcher_item_controller. h"
28 #include "chrome/browser/ui/views/ash/launcher/launcher_app_icon_loader.h" 29 #include "chrome/browser/ui/views/ash/launcher/launcher_app_icon_loader.h"
29 #include "chrome/browser/ui/views/ash/launcher/launcher_context_menu.h" 30 #include "chrome/browser/ui/views/ash/launcher/launcher_context_menu.h"
30 #include "chrome/browser/web_applications/web_app.h" 31 #include "chrome/browser/web_applications/web_app.h"
31 #include "chrome/common/chrome_notification_types.h" 32 #include "chrome/common/chrome_notification_types.h"
32 #include "chrome/common/extensions/extension.h" 33 #include "chrome/common/extensions/extension.h"
33 #include "chrome/common/extensions/extension_resource.h" 34 #include "chrome/common/extensions/extension_resource.h"
34 #include "chrome/common/pref_names.h" 35 #include "chrome/common/pref_names.h"
35 #include "content/public/browser/notification_service.h" 36 #include "content/public/browser/notification_service.h"
36 #include "content/public/browser/web_contents.h" 37 #include "content/public/browser/web_contents.h"
37 #include "grit/theme_resources.h" 38 #include "grit/theme_resources.h"
38 #include "ui/aura/client/activation_client.h" 39 #include "ui/aura/client/activation_client.h"
39 #include "ui/aura/window.h" 40 #include "ui/aura/window.h"
40 #include "ui/views/widget/widget.h" 41 #include "ui/views/widget/widget.h"
41 42
42 using extensions::Extension; 43 using extensions::Extension;
43 44
44 namespace {
45
46 // Values used for prefs::kShelfAutoHideBehavior.
47 const char kShelfAutoHideBehaviorAlways[] = "Always";
48 const char kShelfAutoHideBehaviorDefault[] = "Default";
49 const char kShelfAutoHideBehaviorNever[] = "Never";
50
51 // App ID of default pinned apps.
52 const char* kDefaultPinnedApps[] = {
53 "pjkljhegncpnkpknbcohdijeoejaedia", // Gmail
54 "coobgpohoikkiipiblmjeljniedjpjpf", // Search
55 "apdfllckaahabafndbhieahigkjlhalf", // Doc
56 "blpcfgokakmgnkcojhhkbfbldkacnbeo", // YouTube
57 };
58
59 base::DictionaryValue* CreateAppDict(const std::string& app_id) {
60 scoped_ptr<base::DictionaryValue> app_value(new base::DictionaryValue);
61 app_value->SetString(ChromeLauncherController::kPinnedAppsPrefAppIDPath,
62 app_id);
63 return app_value.release();
64 }
65
66 base::ListValue* CreateDefaultPinnedAppsList() {
67 scoped_ptr<base::ListValue> apps(new base::ListValue);
68 for (size_t i = 0; i < arraysize(kDefaultPinnedApps); ++i)
69 apps->Append(CreateAppDict(kDefaultPinnedApps[i]));
70
71 return apps.release();
72 }
73
74 } // namespace
75
76 // ChromeLauncherController::Item ---------------------------------------------- 45 // ChromeLauncherController::Item ----------------------------------------------
77 46
78 ChromeLauncherController::Item::Item() 47 ChromeLauncherController::Item::Item()
79 : item_type(TYPE_TABBED_BROWSER), 48 : item_type(TYPE_TABBED_BROWSER),
80 controller(NULL) { 49 controller(NULL) {
81 } 50 }
82 51
83 ChromeLauncherController::Item::~Item() { 52 ChromeLauncherController::Item::~Item() {
84 } 53 }
85 54
86 // ChromeLauncherController ---------------------------------------------------- 55 // ChromeLauncherController ----------------------------------------------------
87 56
88 // static 57 // static
89 const char ChromeLauncherController::kPinnedAppsPrefAppIDPath[] = "id";
90
91 // static
92 ChromeLauncherController* ChromeLauncherController::instance_ = NULL; 58 ChromeLauncherController* ChromeLauncherController::instance_ = NULL;
93 59
94 ChromeLauncherController::ChromeLauncherController(Profile* profile, 60 ChromeLauncherController::ChromeLauncherController(Profile* profile,
95 ash::LauncherModel* model) 61 ash::LauncherModel* model)
96 : model_(model), 62 : model_(model),
97 profile_(profile) { 63 profile_(profile) {
98 if (!profile_) { 64 if (!profile_) {
99 // Use the original profile as on chromeos we may get a temporary off the 65 // Use the original profile as on chromeos we may get a temporary off the
100 // record profile. 66 // record profile.
101 profile_ = ProfileManager::GetDefaultProfile()->GetOriginalProfile(); 67 profile_ = ProfileManager::GetDefaultProfile()->GetOriginalProfile();
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 } 118 }
153 119
154 CreateAppLaunchersFromPref(); 120 CreateAppLaunchersFromPref();
155 121
156 // TODO(sky): update unit test so that this test isn't necessary. 122 // TODO(sky): update unit test so that this test isn't necessary.
157 if (ash::Shell::HasInstance()) { 123 if (ash::Shell::HasInstance()) {
158 std::string behavior_value( 124 std::string behavior_value(
159 profile_->GetPrefs()->GetString(prefs::kShelfAutoHideBehavior)); 125 profile_->GetPrefs()->GetString(prefs::kShelfAutoHideBehavior));
160 ash::ShelfAutoHideBehavior behavior = 126 ash::ShelfAutoHideBehavior behavior =
161 ash::SHELF_AUTO_HIDE_BEHAVIOR_DEFAULT; 127 ash::SHELF_AUTO_HIDE_BEHAVIOR_DEFAULT;
162 if (behavior_value == kShelfAutoHideBehaviorNever) 128 if (behavior_value == ash::kShelfAutoHideBehaviorNever)
163 behavior = ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER; 129 behavior = ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER;
164 else if (behavior_value == kShelfAutoHideBehaviorAlways) 130 else if (behavior_value == ash::kShelfAutoHideBehaviorAlways)
165 behavior = ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS; 131 behavior = ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS;
166 ash::Shell::GetInstance()->SetShelfAutoHideBehavior(behavior); 132 ash::Shell::GetInstance()->SetShelfAutoHideBehavior(behavior);
167 } 133 }
168 } 134 }
169 135
170 // static
171 void ChromeLauncherController::RegisterUserPrefs(PrefService* user_prefs) {
172 // TODO: If we want to support multiple profiles this will likely need to be
173 // pushed to local state and we'll need to track profile per item.
174 user_prefs->RegisterBooleanPref(prefs::kUseDefaultPinnedApps,
175 true,
176 PrefService::SYNCABLE_PREF);
177 user_prefs->RegisterListPref(prefs::kPinnedLauncherApps,
178 CreateDefaultPinnedAppsList(),
179 PrefService::SYNCABLE_PREF);
180 user_prefs->RegisterStringPref(prefs::kShelfAutoHideBehavior,
181 kShelfAutoHideBehaviorDefault,
182 PrefService::SYNCABLE_PREF);
183 }
184
185 ash::LauncherID ChromeLauncherController::CreateTabbedLauncherItem( 136 ash::LauncherID ChromeLauncherController::CreateTabbedLauncherItem(
186 BrowserLauncherItemController* controller, 137 BrowserLauncherItemController* controller,
187 IncognitoState is_incognito, 138 IncognitoState is_incognito,
188 ash::LauncherItemStatus status) { 139 ash::LauncherItemStatus status) {
189 ash::LauncherID id = model_->next_id(); 140 ash::LauncherID id = model_->next_id();
190 ash::LauncherItem item; 141 ash::LauncherItem item;
191 item.type = ash::TYPE_TABBED; 142 item.type = ash::TYPE_TABBED;
192 item.is_incognito = (is_incognito == STATE_INCOGNITO); 143 item.is_incognito = (is_incognito == STATE_INCOGNITO);
193 item.status = status; 144 item.status = status;
194 model_->Add(item); 145 model_->Add(item);
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 profile_->GetPrefs()->FindPreference(prefs::kPinnedLauncherApps); 345 profile_->GetPrefs()->FindPreference(prefs::kPinnedLauncherApps);
395 return pref && pref->IsUserModifiable(); 346 return pref && pref->IsUserModifiable();
396 } 347 }
397 348
398 void ChromeLauncherController::SetAutoHideBehavior( 349 void ChromeLauncherController::SetAutoHideBehavior(
399 ash::ShelfAutoHideBehavior behavior) { 350 ash::ShelfAutoHideBehavior behavior) {
400 ash::Shell::GetInstance()->SetShelfAutoHideBehavior(behavior); 351 ash::Shell::GetInstance()->SetShelfAutoHideBehavior(behavior);
401 const char* value = NULL; 352 const char* value = NULL;
402 switch (behavior) { 353 switch (behavior) {
403 case ash::SHELF_AUTO_HIDE_BEHAVIOR_DEFAULT: 354 case ash::SHELF_AUTO_HIDE_BEHAVIOR_DEFAULT:
404 value = kShelfAutoHideBehaviorDefault; 355 value = ash::kShelfAutoHideBehaviorDefault;
405 break; 356 break;
406 case ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS: 357 case ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS:
407 value = kShelfAutoHideBehaviorAlways; 358 value = ash::kShelfAutoHideBehaviorAlways;
408 break; 359 break;
409 case ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER: 360 case ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER:
410 value = kShelfAutoHideBehaviorNever; 361 value = ash::kShelfAutoHideBehaviorNever;
411 break; 362 break;
412 } 363 }
413 profile_->GetPrefs()->SetString(prefs::kShelfAutoHideBehavior, value); 364 profile_->GetPrefs()->SetString(prefs::kShelfAutoHideBehavior, value);
414 } 365 }
415 366
416 void ChromeLauncherController::CreateNewTab() { 367 void ChromeLauncherController::CreateNewTab() {
417 Browser *last_browser = browser::FindTabbedBrowser( 368 Browser *last_browser = browser::FindTabbedBrowser(
418 GetProfileForNewWindows(), true); 369 GetProfileForNewWindows(), true);
419 370
420 if (!last_browser) { 371 if (!last_browser) {
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 // listener. 552 // listener.
602 pref_change_registrar_.Remove(prefs::kPinnedLauncherApps, this); 553 pref_change_registrar_.Remove(prefs::kPinnedLauncherApps, this);
603 { 554 {
604 ListPrefUpdate updater(profile_->GetPrefs(), prefs::kPinnedLauncherApps); 555 ListPrefUpdate updater(profile_->GetPrefs(), prefs::kPinnedLauncherApps);
605 updater->Clear(); 556 updater->Clear();
606 for (size_t i = 0; i < model_->items().size(); ++i) { 557 for (size_t i = 0; i < model_->items().size(); ++i) {
607 if (model_->items()[i].type == ash::TYPE_APP_SHORTCUT) { 558 if (model_->items()[i].type == ash::TYPE_APP_SHORTCUT) {
608 ash::LauncherID id = model_->items()[i].id; 559 ash::LauncherID id = model_->items()[i].id;
609 if (id_to_item_map_.find(id) != id_to_item_map_.end() && 560 if (id_to_item_map_.find(id) != id_to_item_map_.end() &&
610 IsPinned(id)) { 561 IsPinned(id)) {
611 base::DictionaryValue* app_value = CreateAppDict( 562 base::DictionaryValue* app_value = ash::CreateAppDict(
612 id_to_item_map_[id].app_id); 563 id_to_item_map_[id].app_id);
613 if (app_value) 564 if (app_value)
614 updater->Append(app_value); 565 updater->Append(app_value);
615 } 566 }
616 } 567 }
617 } 568 }
618 } 569 }
619 pref_change_registrar_.Add(prefs::kPinnedLauncherApps, this); 570 pref_change_registrar_.Add(prefs::kPinnedLauncherApps, this);
620 } 571 }
621 572
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 } 611 }
661 } 612 }
662 613
663 void ChromeLauncherController::CreateAppLaunchersFromPref() { 614 void ChromeLauncherController::CreateAppLaunchersFromPref() {
664 const base::ListValue* pinned_apps = 615 const base::ListValue* pinned_apps =
665 profile_->GetPrefs()->GetList(prefs::kPinnedLauncherApps); 616 profile_->GetPrefs()->GetList(prefs::kPinnedLauncherApps);
666 for (size_t i = 0; i < pinned_apps->GetSize(); ++i) { 617 for (size_t i = 0; i < pinned_apps->GetSize(); ++i) {
667 DictionaryValue* app = NULL; 618 DictionaryValue* app = NULL;
668 if (pinned_apps->GetDictionary(i, &app)) { 619 if (pinned_apps->GetDictionary(i, &app)) {
669 std::string app_id; 620 std::string app_id;
670 if (app->GetString(kPinnedAppsPrefAppIDPath, &app_id)) { 621 if (app->GetString(ash::kPinnedAppsPrefAppIDPath, &app_id)) {
671 if (app_icon_loader_->IsValidID(app_id)) { 622 if (app_icon_loader_->IsValidID(app_id)) {
672 CreateAppLauncherItem(NULL, app_id, ash::STATUS_CLOSED); 623 CreateAppLauncherItem(NULL, app_id, ash::STATUS_CLOSED);
673 } else { 624 } else {
674 Item pending_item; 625 Item pending_item;
675 pending_item.item_type = TYPE_APP; 626 pending_item.item_type = TYPE_APP;
676 pending_item.app_id = app_id; 627 pending_item.app_id = app_id;
677 pending_pinned_apps_.push_back(pending_item); 628 pending_pinned_apps_.push_back(pending_item);
678 } 629 }
679 } 630 }
680 } 631 }
681 } 632 }
682 } 633 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698