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