| 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 "chrome/browser/extensions/extension_prefs.h" | 7 #include "chrome/browser/extensions/extension_prefs.h" |
| 8 #include "chrome/browser/extensions/extension_service.h" | 8 #include "chrome/browser/extensions/extension_service.h" |
| 9 #include "chrome/browser/prefs/pref_service.h" | 9 #include "chrome/browser/prefs/pref_service.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 extensions_initialized_(false) { | 21 extensions_initialized_(false) { |
| 22 DCHECK(service_); | 22 DCHECK(service_); |
| 23 | 23 |
| 24 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, | 24 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
| 25 content::Source<Profile>(service_->profile())); | 25 content::Source<Profile>(service_->profile())); |
| 26 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 26 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
| 27 content::Source<Profile>(service_->profile())); | 27 content::Source<Profile>(service_->profile())); |
| 28 registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY, | 28 registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY, |
| 29 content::Source<Profile>(service_->profile())); | 29 content::Source<Profile>(service_->profile())); |
| 30 registrar_.Add( | 30 registrar_.Add( |
| 31 this, chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED, | 31 this, chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_PINED_CHANGED, |
| 32 content::Source<ExtensionPrefs>(service_->extension_prefs())); | 32 content::Source<ExtensionPrefs>(service_->extension_prefs())); |
| 33 | 33 |
| 34 visible_icon_count_ = prefs_->GetInteger(prefs::kExtensionToolbarSize); | 34 visible_icon_count_ = prefs_->GetInteger(prefs::kExtensionToolbarSize); |
| 35 } | 35 } |
| 36 | 36 |
| 37 ExtensionToolbarModel::~ExtensionToolbarModel() { | 37 ExtensionToolbarModel::~ExtensionToolbarModel() { |
| 38 } | 38 } |
| 39 | 39 |
| 40 void ExtensionToolbarModel::AddObserver(Observer* observer) { | 40 void ExtensionToolbarModel::AddObserver(Observer* observer) { |
| 41 observers_.AddObserver(observer); | 41 observers_.AddObserver(observer); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 extension = content::Details<const Extension>(details).ptr(); | 106 extension = content::Details<const Extension>(details).ptr(); |
| 107 } | 107 } |
| 108 if (type == chrome::NOTIFICATION_EXTENSION_LOADED) { | 108 if (type == chrome::NOTIFICATION_EXTENSION_LOADED) { |
| 109 // We don't want to add the same extension twice. It may have already been | 109 // We don't want to add the same extension twice. It may have already been |
| 110 // added by EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED below, if the user | 110 // added by EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED below, if the user |
| 111 // hides the browser action and then disables and enables the extension. | 111 // hides the browser action and then disables and enables the extension. |
| 112 for (size_t i = 0; i < toolitems_.size(); i++) { | 112 for (size_t i = 0; i < toolitems_.size(); i++) { |
| 113 if (toolitems_[i].get() == extension) | 113 if (toolitems_[i].get() == extension) |
| 114 return; // Already exists. | 114 return; // Already exists. |
| 115 } | 115 } |
| 116 if (service_->GetBrowserActionVisibility(extension)) | 116 if (service_->extension_prefs()->GetBrowserActionPined(extension)) |
| 117 AddExtension(extension); | 117 AddExtension(extension); |
| 118 } else if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED) { | 118 } else if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED) { |
| 119 RemoveExtension(extension); | 119 RemoveExtension(extension); |
| 120 } else if ( | 120 } else if ( |
| 121 type == | 121 type == |
| 122 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED) { | 122 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_PINED_CHANGED) { |
| 123 if (service_->GetBrowserActionVisibility(extension)) | 123 if (service_->extension_prefs()->GetBrowserActionPined(extension)) |
| 124 AddExtension(extension); | 124 AddExtension(extension); |
| 125 else | 125 else |
| 126 RemoveExtension(extension); | 126 RemoveExtension(extension); |
| 127 } else { | 127 } else { |
| 128 NOTREACHED() << "Received unexpected notification"; | 128 NOTREACHED() << "Received unexpected notification"; |
| 129 } | 129 } |
| 130 } | 130 } |
| 131 | 131 |
| 132 void ExtensionToolbarModel::AddExtension(const Extension* extension) { | 132 void ExtensionToolbarModel::AddExtension(const Extension* extension) { |
| 133 // We only care about extensions with browser actions. | 133 // We only care about extensions with browser actions. |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 sorted.resize(pref_order.size(), NULL); | 185 sorted.resize(pref_order.size(), NULL); |
| 186 // The items that don't have a pref for their position. | 186 // The items that don't have a pref for their position. |
| 187 ExtensionList unsorted; | 187 ExtensionList unsorted; |
| 188 | 188 |
| 189 // Create the lists. | 189 // Create the lists. |
| 190 for (ExtensionSet::const_iterator it = service_->extensions()->begin(); | 190 for (ExtensionSet::const_iterator it = service_->extensions()->begin(); |
| 191 it != service_->extensions()->end(); ++it) { | 191 it != service_->extensions()->end(); ++it) { |
| 192 const Extension* extension = *it; | 192 const Extension* extension = *it; |
| 193 if (!extension->browser_action()) | 193 if (!extension->browser_action()) |
| 194 continue; | 194 continue; |
| 195 if (!service_->GetBrowserActionVisibility(extension)) | 195 if (!service_->extension_prefs()->GetBrowserActionPined(extension)) |
| 196 continue; | 196 continue; |
| 197 | 197 |
| 198 std::vector<std::string>::iterator pos = | 198 std::vector<std::string>::iterator pos = |
| 199 std::find(pref_order.begin(), pref_order.end(), extension->id()); | 199 std::find(pref_order.begin(), pref_order.end(), extension->id()); |
| 200 if (pos != pref_order.end()) { | 200 if (pos != pref_order.end()) { |
| 201 int index = std::distance(pref_order.begin(), pos); | 201 int index = std::distance(pref_order.begin(), pos); |
| 202 sorted[index] = extension; | 202 sorted[index] = extension; |
| 203 } else { | 203 } else { |
| 204 unsorted.push_back(make_scoped_refptr(extension)); | 204 unsorted.push_back(make_scoped_refptr(extension)); |
| 205 } | 205 } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 int incognito_index = 0, i = 0; | 258 int incognito_index = 0, i = 0; |
| 259 for (ExtensionList::iterator iter = begin(); iter != end(); | 259 for (ExtensionList::iterator iter = begin(); iter != end(); |
| 260 ++iter, ++i) { | 260 ++iter, ++i) { |
| 261 if (original_index == i) | 261 if (original_index == i) |
| 262 break; | 262 break; |
| 263 if (service_->IsIncognitoEnabled((*iter)->id())) | 263 if (service_->IsIncognitoEnabled((*iter)->id())) |
| 264 ++incognito_index; | 264 ++incognito_index; |
| 265 } | 265 } |
| 266 return incognito_index; | 266 return incognito_index; |
| 267 } | 267 } |
| OLD | NEW |