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/extensions/extension_toolbar_model.h" | 5 #include "chrome/browser/extensions/extension_toolbar_model.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
11 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" | 11 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" |
12 #include "chrome/browser/extensions/extension_action.h" | 12 #include "chrome/browser/extensions/extension_action.h" |
13 #include "chrome/browser/extensions/extension_action_manager.h" | 13 #include "chrome/browser/extensions/extension_action_manager.h" |
14 #include "chrome/browser/extensions/extension_prefs.h" | 14 #include "chrome/browser/extensions/extension_prefs.h" |
15 #include "chrome/browser/extensions/extension_service.h" | 15 #include "chrome/browser/extensions/extension_service.h" |
16 #include "chrome/browser/extensions/extension_tab_util.h" | 16 #include "chrome/browser/extensions/extension_tab_util.h" |
17 #include "chrome/browser/extensions/extension_toolbar_model_factory.h" | 17 #include "chrome/browser/extensions/extension_toolbar_model_factory.h" |
18 #include "chrome/browser/extensions/extension_util.h" | 18 #include "chrome/browser/extensions/extension_util.h" |
19 #include "chrome/browser/extensions/tab_helper.h" | 19 #include "chrome/browser/extensions/tab_helper.h" |
20 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
21 #include "chrome/browser/ui/browser.h" | 21 #include "chrome/browser/ui/browser.h" |
22 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 22 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
23 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
24 #include "content/public/browser/notification_details.h" | 24 #include "content/public/browser/notification_details.h" |
25 #include "content/public/browser/notification_source.h" | 25 #include "content/public/browser/notification_source.h" |
26 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
| 27 #include "extensions/browser/pref_names.h" |
27 #include "extensions/common/extension.h" | 28 #include "extensions/common/extension.h" |
28 #include "extensions/common/extension_set.h" | 29 #include "extensions/common/extension_set.h" |
29 #include "extensions/common/feature_switch.h" | 30 #include "extensions/common/feature_switch.h" |
30 | 31 |
31 using extensions::Extension; | 32 using extensions::Extension; |
32 using extensions::ExtensionIdList; | 33 using extensions::ExtensionIdList; |
33 using extensions::ExtensionList; | 34 using extensions::ExtensionList; |
34 | 35 |
35 bool ExtensionToolbarModel::Observer::BrowserActionShowPopup( | 36 bool ExtensionToolbarModel::Observer::BrowserActionShowPopup( |
36 const extensions::Extension* extension) { | 37 const extensions::Extension* extension) { |
(...skipping 13 matching lines...) Expand all Loading... |
50 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 51 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
51 content::Source<Profile>(profile_)); | 52 content::Source<Profile>(profile_)); |
52 registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY, | 53 registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY, |
53 content::Source<Profile>(profile_)); | 54 content::Source<Profile>(profile_)); |
54 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED, | 55 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED, |
55 content::Source<Profile>(profile_)); | 56 content::Source<Profile>(profile_)); |
56 registrar_.Add( | 57 registrar_.Add( |
57 this, chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED, | 58 this, chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED, |
58 content::Source<extensions::ExtensionPrefs>(extension_prefs_)); | 59 content::Source<extensions::ExtensionPrefs>(extension_prefs_)); |
59 | 60 |
60 visible_icon_count_ = prefs_->GetInteger(prefs::kExtensionToolbarSize); | 61 visible_icon_count_ = prefs_->GetInteger( |
| 62 extensions::pref_names::kToolbarSize); |
61 | 63 |
62 pref_change_registrar_.Init(prefs_); | 64 pref_change_registrar_.Init(prefs_); |
63 pref_change_callback_ = | 65 pref_change_callback_ = |
64 base::Bind(&ExtensionToolbarModel::OnExtensionToolbarPrefChange, | 66 base::Bind(&ExtensionToolbarModel::OnExtensionToolbarPrefChange, |
65 base::Unretained(this)); | 67 base::Unretained(this)); |
66 pref_change_registrar_.Add(prefs::kExtensionToolbar, pref_change_callback_); | 68 pref_change_registrar_.Add(extensions::pref_names::kToolbar, |
| 69 pref_change_callback_); |
67 } | 70 } |
68 | 71 |
69 ExtensionToolbarModel::~ExtensionToolbarModel() { | 72 ExtensionToolbarModel::~ExtensionToolbarModel() { |
70 } | 73 } |
71 | 74 |
72 // static | 75 // static |
73 ExtensionToolbarModel* ExtensionToolbarModel::Get(Profile* profile) { | 76 ExtensionToolbarModel* ExtensionToolbarModel::Get(Profile* profile) { |
74 return ExtensionToolbarModelFactory::GetForProfile(profile); | 77 return ExtensionToolbarModelFactory::GetForProfile(profile); |
75 } | 78 } |
76 | 79 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 } | 162 } |
160 | 163 |
161 extensions::ExtensionActionAPI::BrowserActionExecuted( | 164 extensions::ExtensionActionAPI::BrowserActionExecuted( |
162 browser->profile(), *browser_action, web_contents); | 165 browser->profile(), *browser_action, web_contents); |
163 return ACTION_NONE; | 166 return ACTION_NONE; |
164 } | 167 } |
165 | 168 |
166 void ExtensionToolbarModel::SetVisibleIconCount(int count) { | 169 void ExtensionToolbarModel::SetVisibleIconCount(int count) { |
167 visible_icon_count_ = | 170 visible_icon_count_ = |
168 count == static_cast<int>(toolbar_items_.size()) ? -1 : count; | 171 count == static_cast<int>(toolbar_items_.size()) ? -1 : count; |
169 prefs_->SetInteger(prefs::kExtensionToolbarSize, visible_icon_count_); | 172 prefs_->SetInteger(extensions::pref_names::kToolbarSize, visible_icon_count_); |
170 } | 173 } |
171 | 174 |
172 void ExtensionToolbarModel::Observe( | 175 void ExtensionToolbarModel::Observe( |
173 int type, | 176 int type, |
174 const content::NotificationSource& source, | 177 const content::NotificationSource& source, |
175 const content::NotificationDetails& details) { | 178 const content::NotificationDetails& details) { |
176 ExtensionService* extension_service = | 179 ExtensionService* extension_service = |
177 extensions::ExtensionSystem::Get(profile_)->extension_service(); | 180 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
178 if (!extension_service || !extension_service->is_ready()) | 181 if (!extension_service || !extension_service->is_ready()) |
179 return; | 182 return; |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 FOR_EACH_OBSERVER( | 387 FOR_EACH_OBSERVER( |
385 Observer, observers_, BrowserActionAdded(toolbar_items_[i].get(), i)); | 388 Observer, observers_, BrowserActionAdded(toolbar_items_[i].get(), i)); |
386 } | 389 } |
387 } | 390 } |
388 | 391 |
389 void ExtensionToolbarModel::UpdatePrefs() { | 392 void ExtensionToolbarModel::UpdatePrefs() { |
390 if (!extension_prefs_) | 393 if (!extension_prefs_) |
391 return; | 394 return; |
392 | 395 |
393 // Don't observe change caused by self. | 396 // Don't observe change caused by self. |
394 pref_change_registrar_.Remove(prefs::kExtensionToolbar); | 397 pref_change_registrar_.Remove(extensions::pref_names::kToolbar); |
395 extension_prefs_->SetToolbarOrder(last_known_positions_); | 398 extension_prefs_->SetToolbarOrder(last_known_positions_); |
396 pref_change_registrar_.Add(prefs::kExtensionToolbar, pref_change_callback_); | 399 pref_change_registrar_.Add(extensions::pref_names::kToolbar, |
| 400 pref_change_callback_); |
397 } | 401 } |
398 | 402 |
399 int ExtensionToolbarModel::IncognitoIndexToOriginal(int incognito_index) { | 403 int ExtensionToolbarModel::IncognitoIndexToOriginal(int incognito_index) { |
400 int original_index = 0, i = 0; | 404 int original_index = 0, i = 0; |
401 ExtensionService* extension_service = | 405 ExtensionService* extension_service = |
402 extensions::ExtensionSystem::Get(profile_)->extension_service(); | 406 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
403 for (ExtensionList::iterator iter = toolbar_items_.begin(); | 407 for (ExtensionList::iterator iter = toolbar_items_.begin(); |
404 iter != toolbar_items_.end(); | 408 iter != toolbar_items_.end(); |
405 ++iter, ++original_index) { | 409 ++iter, ++original_index) { |
406 if (extension_util::IsIncognitoEnabled((*iter)->id(), extension_service)) { | 410 if (extension_util::IsIncognitoEnabled((*iter)->id(), extension_service)) { |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
494 for (ExtensionList::const_iterator extension = toolbar_items_.begin(); | 498 for (ExtensionList::const_iterator extension = toolbar_items_.begin(); |
495 extension != toolbar_items_.end(); ++extension) { | 499 extension != toolbar_items_.end(); ++extension) { |
496 if ((*extension)->id() == (*it)) { | 500 if ((*extension)->id() == (*it)) { |
497 if (extension - toolbar_items_.begin() >= visible_icon_count_) | 501 if (extension - toolbar_items_.begin() >= visible_icon_count_) |
498 MoveBrowserAction(*extension, 0); | 502 MoveBrowserAction(*extension, 0); |
499 break; | 503 break; |
500 } | 504 } |
501 } | 505 } |
502 } | 506 } |
503 } | 507 } |
OLD | NEW |