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

Side by Side Diff: chrome/browser/extensions/extension_toolbar_model.cc

Issue 14699002: Move BrowserAction references from ExtensionPrefs to ExtensionActionAPI (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 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
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/extensions/extension_toolbar_model.h" 5 #include "chrome/browser/extensions/extension_toolbar_model.h"
6 6
7 #include "base/prefs/pref_service.h" 7 #include "base/prefs/pref_service.h"
8 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h"
8 #include "chrome/browser/extensions/browser_event_router.h" 9 #include "chrome/browser/extensions/browser_event_router.h"
9 #include "chrome/browser/extensions/extension_action.h" 10 #include "chrome/browser/extensions/extension_action.h"
10 #include "chrome/browser/extensions/extension_action_manager.h" 11 #include "chrome/browser/extensions/extension_action_manager.h"
11 #include "chrome/browser/extensions/extension_prefs.h" 12 #include "chrome/browser/extensions/extension_prefs.h"
12 #include "chrome/browser/extensions/extension_service.h" 13 #include "chrome/browser/extensions/extension_service.h"
13 #include "chrome/browser/extensions/extension_tab_util.h" 14 #include "chrome/browser/extensions/extension_tab_util.h"
14 #include "chrome/browser/extensions/tab_helper.h" 15 #include "chrome/browser/extensions/tab_helper.h"
15 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/ui/browser.h" 17 #include "chrome/browser/ui/browser.h"
17 #include "chrome/browser/ui/tabs/tab_strip_model.h" 18 #include "chrome/browser/ui/tabs/tab_strip_model.h"
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 extension = content::Details<const Extension>(details).ptr(); 180 extension = content::Details<const Extension>(details).ptr();
180 } 181 }
181 if (type == chrome::NOTIFICATION_EXTENSION_LOADED) { 182 if (type == chrome::NOTIFICATION_EXTENSION_LOADED) {
182 // We don't want to add the same extension twice. It may have already been 183 // We don't want to add the same extension twice. It may have already been
183 // added by EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED below, if the user 184 // added by EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED below, if the user
184 // hides the browser action and then disables and enables the extension. 185 // hides the browser action and then disables and enables the extension.
185 for (size_t i = 0; i < toolbar_items_.size(); i++) { 186 for (size_t i = 0; i < toolbar_items_.size(); i++) {
186 if (toolbar_items_[i].get() == extension) 187 if (toolbar_items_[i].get() == extension)
187 return; // Already exists. 188 return; // Already exists.
188 } 189 }
189 if (service_->extension_prefs()->GetBrowserActionVisibility(extension)) 190 if (extensions::ExtensionActionAPI::GetBrowserActionVisibility(
191 service_->extension_prefs(), extension->id())) {
190 AddExtension(extension); 192 AddExtension(extension);
193 }
191 } else if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED) { 194 } else if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED) {
192 RemoveExtension(extension); 195 RemoveExtension(extension);
193 } else if (type == chrome::NOTIFICATION_EXTENSION_UNINSTALLED) { 196 } else if (type == chrome::NOTIFICATION_EXTENSION_UNINSTALLED) {
194 UninstalledExtension(extension); 197 UninstalledExtension(extension);
195 } else if (type == 198 } else if (type ==
196 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED) { 199 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED) {
197 if (service_->extension_prefs()->GetBrowserActionVisibility(extension)) 200 if (extensions::ExtensionActionAPI::GetBrowserActionVisibility(
201 service_->extension_prefs(), extension->id())) {
198 AddExtension(extension); 202 AddExtension(extension);
199 else 203 } else {
200 RemoveExtension(extension); 204 RemoveExtension(extension);
205 }
201 } else { 206 } else {
202 NOTREACHED() << "Received unexpected notification"; 207 NOTREACHED() << "Received unexpected notification";
203 } 208 }
204 } 209 }
205 210
206 size_t ExtensionToolbarModel::FindNewPositionFromLastKnownGood( 211 size_t ExtensionToolbarModel::FindNewPositionFromLastKnownGood(
207 const Extension* extension) { 212 const Extension* extension) {
208 // See if we have last known good position for this extension. 213 // See if we have last known good position for this extension.
209 size_t new_index = 0; 214 size_t new_index = 0;
210 // Loop through the ID list of known positions, to count the number of visible 215 // Loop through the ID list of known positions, to count the number of visible
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 322
318 extensions::ExtensionActionManager* extension_action_manager = 323 extensions::ExtensionActionManager* extension_action_manager =
319 extensions::ExtensionActionManager::Get(service_->profile()); 324 extensions::ExtensionActionManager::Get(service_->profile());
320 325
321 // Create the lists. 326 // Create the lists.
322 for (ExtensionSet::const_iterator it = service_->extensions()->begin(); 327 for (ExtensionSet::const_iterator it = service_->extensions()->begin();
323 it != service_->extensions()->end(); ++it) { 328 it != service_->extensions()->end(); ++it) {
324 const Extension* extension = *it; 329 const Extension* extension = *it;
325 if (!extension_action_manager->GetBrowserAction(*extension)) 330 if (!extension_action_manager->GetBrowserAction(*extension))
326 continue; 331 continue;
327 if (!service_->extension_prefs()->GetBrowserActionVisibility(extension)) 332 if (!extensions::ExtensionActionAPI::GetBrowserActionVisibility(
333 service_->extension_prefs(), extension->id())) {
328 continue; 334 continue;
335 }
329 336
330 extensions::ExtensionIdList::const_iterator pos = 337 extensions::ExtensionIdList::const_iterator pos =
331 std::find(pref_order.begin(), pref_order.end(), extension->id()); 338 std::find(pref_order.begin(), pref_order.end(), extension->id());
332 if (pos != pref_order.end()) 339 if (pos != pref_order.end())
333 sorted[pos - pref_order.begin()] = extension; 340 sorted[pos - pref_order.begin()] = extension;
334 else 341 else
335 unsorted.push_back(make_scoped_refptr(extension)); 342 unsorted.push_back(make_scoped_refptr(extension));
336 } 343 }
337 344
338 // Merge the lists. 345 // Merge the lists.
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 for (ExtensionList::iterator iter = toolbar_items_.begin(); 404 for (ExtensionList::iterator iter = toolbar_items_.begin();
398 iter != toolbar_items_.end(); 405 iter != toolbar_items_.end();
399 ++iter, ++i) { 406 ++iter, ++i) {
400 if (original_index == i) 407 if (original_index == i)
401 break; 408 break;
402 if (service_->IsIncognitoEnabled((*iter)->id())) 409 if (service_->IsIncognitoEnabled((*iter)->id()))
403 ++incognito_index; 410 ++incognito_index;
404 } 411 }
405 return incognito_index; 412 return incognito_index;
406 } 413 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698