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

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 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 return; 176 return;
176 } 177 }
177 178
178 if (!service_->is_ready()) 179 if (!service_->is_ready())
179 return; 180 return;
180 181
181 const Extension* extension = NULL; 182 const Extension* extension = NULL;
182 if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED) { 183 if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED) {
183 extension = content::Details<extensions::UnloadedExtensionInfo>( 184 extension = content::Details<extensions::UnloadedExtensionInfo>(
184 details)->extension; 185 details)->extension;
186 } else if (type ==
187 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED) {
188 extension = service_->GetExtensionById(
189 *content::Details<const std::string>(details).ptr(), true);
185 } else { 190 } else {
186 extension = content::Details<const Extension>(details).ptr(); 191 extension = content::Details<const Extension>(details).ptr();
187 } 192 }
188 if (type == chrome::NOTIFICATION_EXTENSION_LOADED) { 193 if (type == chrome::NOTIFICATION_EXTENSION_LOADED) {
189 // We don't want to add the same extension twice. It may have already been 194 // We don't want to add the same extension twice. It may have already been
190 // added by EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED below, if the user 195 // added by EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED below, if the user
191 // hides the browser action and then disables and enables the extension. 196 // hides the browser action and then disables and enables the extension.
192 for (size_t i = 0; i < toolbar_items_.size(); i++) { 197 for (size_t i = 0; i < toolbar_items_.size(); i++) {
193 if (toolbar_items_[i].get() == extension) 198 if (toolbar_items_[i].get() == extension)
194 return; // Already exists. 199 return; // Already exists.
195 } 200 }
196 if (service_->extension_prefs()->GetBrowserActionVisibility(extension)) 201 if (extensions::ExtensionActionAPI::GetBrowserActionVisibility(
202 service_->extension_prefs(), extension->id())) {
197 AddExtension(extension); 203 AddExtension(extension);
204 }
198 } else if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED) { 205 } else if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED) {
199 RemoveExtension(extension); 206 RemoveExtension(extension);
200 } else if (type == chrome::NOTIFICATION_EXTENSION_UNINSTALLED) { 207 } else if (type == chrome::NOTIFICATION_EXTENSION_UNINSTALLED) {
201 UninstalledExtension(extension); 208 UninstalledExtension(extension);
202 } else if (type == 209 } else if (type ==
203 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED) { 210 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED) {
204 if (service_->extension_prefs()->GetBrowserActionVisibility(extension)) 211 if (extensions::ExtensionActionAPI::GetBrowserActionVisibility(
212 service_->extension_prefs(), extension->id())) {
205 AddExtension(extension); 213 AddExtension(extension);
206 else 214 } else {
207 RemoveExtension(extension); 215 RemoveExtension(extension);
216 }
208 } else { 217 } else {
209 NOTREACHED() << "Received unexpected notification"; 218 NOTREACHED() << "Received unexpected notification";
210 } 219 }
211 } 220 }
212 221
213 size_t ExtensionToolbarModel::FindNewPositionFromLastKnownGood( 222 size_t ExtensionToolbarModel::FindNewPositionFromLastKnownGood(
214 const Extension* extension) { 223 const Extension* extension) {
215 // See if we have last known good position for this extension. 224 // See if we have last known good position for this extension.
216 size_t new_index = 0; 225 size_t new_index = 0;
217 // Loop through the ID list of known positions, to count the number of visible 226 // Loop through the ID list of known positions, to count the number of visible
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 330
322 extensions::ExtensionActionManager* extension_action_manager = 331 extensions::ExtensionActionManager* extension_action_manager =
323 extensions::ExtensionActionManager::Get(service_->profile()); 332 extensions::ExtensionActionManager::Get(service_->profile());
324 333
325 // Create the lists. 334 // Create the lists.
326 for (ExtensionSet::const_iterator it = service_->extensions()->begin(); 335 for (ExtensionSet::const_iterator it = service_->extensions()->begin();
327 it != service_->extensions()->end(); ++it) { 336 it != service_->extensions()->end(); ++it) {
328 const Extension* extension = *it; 337 const Extension* extension = *it;
329 if (!extension_action_manager->GetBrowserAction(*extension)) 338 if (!extension_action_manager->GetBrowserAction(*extension))
330 continue; 339 continue;
331 if (!service_->extension_prefs()->GetBrowserActionVisibility(extension)) 340 if (!extensions::ExtensionActionAPI::GetBrowserActionVisibility(
341 service_->extension_prefs(), extension->id())) {
332 continue; 342 continue;
343 }
333 344
334 extensions::ExtensionIdList::const_iterator pos = 345 extensions::ExtensionIdList::const_iterator pos =
335 std::find(positions.begin(), positions.end(), extension->id()); 346 std::find(positions.begin(), positions.end(), extension->id());
336 if (pos != positions.end()) 347 if (pos != positions.end())
337 sorted[pos - positions.begin()] = extension; 348 sorted[pos - positions.begin()] = extension;
338 else 349 else
339 unsorted.push_back(make_scoped_refptr(extension)); 350 unsorted.push_back(make_scoped_refptr(extension));
340 } 351 }
341 352
342 // Erase current icons. 353 // Erase current icons.
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 452
442 if (last_known_positions_.size() > pref_position_size) { 453 if (last_known_positions_.size() > pref_position_size) {
443 // Need to update pref because we have extra icons. But can't call 454 // Need to update pref because we have extra icons. But can't call
444 // UpdatePrefs() directly within observation closure. 455 // UpdatePrefs() directly within observation closure.
445 base::MessageLoop::current()->PostTask( 456 base::MessageLoop::current()->PostTask(
446 FROM_HERE, 457 FROM_HERE,
447 base::Bind(&ExtensionToolbarModel::UpdatePrefs, 458 base::Bind(&ExtensionToolbarModel::UpdatePrefs,
448 weak_ptr_factory_.GetWeakPtr())); 459 weak_ptr_factory_.GetWeakPtr()));
449 } 460 }
450 } 461 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698