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

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

Issue 8733004: Make ExtensionService use ExtensionSet. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: = Created 9 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_service.h" 5 #include "chrome/browser/extensions/extension_service.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 omnibox_popup_icon_manager_.set_monochrome(true); 434 omnibox_popup_icon_manager_.set_monochrome(true);
435 omnibox_icon_manager_.set_monochrome(true); 435 omnibox_icon_manager_.set_monochrome(true);
436 omnibox_icon_manager_.set_padding(gfx::Insets(0, kOmniboxIconPaddingLeft, 436 omnibox_icon_manager_.set_padding(gfx::Insets(0, kOmniboxIconPaddingLeft,
437 0, kOmniboxIconPaddingRight)); 437 0, kOmniboxIconPaddingRight));
438 438
439 // How long is the path to the Extensions directory? 439 // How long is the path to the Extensions directory?
440 UMA_HISTOGRAM_CUSTOM_COUNTS("Extensions.ExtensionRootPathLength", 440 UMA_HISTOGRAM_CUSTOM_COUNTS("Extensions.ExtensionRootPathLength",
441 install_directory_.value().length(), 0, 500, 100); 441 install_directory_.value().length(), 0, 500, 100);
442 } 442 }
443 443
444 const ExtensionList* ExtensionService::extensions() const { 444 const ExtensionSet* ExtensionService::extensions() const {
445 return &extensions_; 445 return &extensions_;
446 } 446 }
447 447
448 const ExtensionList* ExtensionService::disabled_extensions() const { 448 const ExtensionSet* ExtensionService::disabled_extensions() const {
449 return &disabled_extensions_; 449 return &disabled_extensions_;
450 } 450 }
451 451
452 const ExtensionList* ExtensionService::terminated_extensions() const { 452 const ExtensionSet* ExtensionService::terminated_extensions() const {
453 return &terminated_extensions_; 453 return &terminated_extensions_;
454 } 454 }
455 455
456 PendingExtensionManager* ExtensionService::pending_extension_manager() { 456 PendingExtensionManager* ExtensionService::pending_extension_manager() {
457 return &pending_extension_manager_; 457 return &pending_extension_manager_;
458 } 458 }
459 459
460 ExtensionService::~ExtensionService() { 460 ExtensionService::~ExtensionService() {
461 // No need to unload extensions here because they are profile-scoped, and the 461 // No need to unload extensions here because they are profile-scoped, and the
462 // profile is in the process of being deleted. 462 // profile is in the process of being deleted.
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
794 extension_prefs_->SetExtensionState(extension_id, Extension::ENABLED); 794 extension_prefs_->SetExtensionState(extension_id, Extension::ENABLED);
795 795
796 const Extension* extension = 796 const Extension* extension =
797 GetExtensionByIdInternal(extension_id, false, true, false); 797 GetExtensionByIdInternal(extension_id, false, true, false);
798 // This can happen if sync enables an extension that is not 798 // This can happen if sync enables an extension that is not
799 // installed yet. 799 // installed yet.
800 if (!extension) 800 if (!extension)
801 return; 801 return;
802 802
803 // Move it over to the enabled list. 803 // Move it over to the enabled list.
804 extensions_.push_back(make_scoped_refptr(extension)); 804 extensions_.Insert(make_scoped_refptr(extension));
805 ExtensionList::iterator iter = std::find(disabled_extensions_.begin(), 805 disabled_extensions_.Remove(extension->id());
806 disabled_extensions_.end(),
807 extension);
808 disabled_extensions_.erase(iter);
809 806
810 // Make sure any browser action contained within it is not hidden. 807 // Make sure any browser action contained within it is not hidden.
811 extension_prefs_->SetBrowserActionVisibility(extension, true); 808 extension_prefs_->SetBrowserActionVisibility(extension, true);
812 809
813 NotifyExtensionLoaded(extension); 810 NotifyExtensionLoaded(extension);
814 811
815 SyncExtensionChangeIfNeeded(*extension); 812 SyncExtensionChangeIfNeeded(*extension);
816 } 813 }
817 814
818 void ExtensionService::DisableExtension(const std::string& extension_id) { 815 void ExtensionService::DisableExtension(const std::string& extension_id) {
819 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 816 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
820 817
821 // The extension may have been disabled already. 818 // The extension may have been disabled already.
822 if (!IsExtensionEnabled(extension_id)) 819 if (!IsExtensionEnabled(extension_id))
823 return; 820 return;
824 821
825 const Extension* extension = GetInstalledExtension(extension_id); 822 const Extension* extension = GetInstalledExtension(extension_id);
826 // |extension| can be NULL if sync disables an extension that is not 823 // |extension| can be NULL if sync disables an extension that is not
827 // installed yet. 824 // installed yet.
828 if (extension && !Extension::UserMayDisable(extension->location())) 825 if (extension && !Extension::UserMayDisable(extension->location()))
829 return; 826 return;
830 827
831 extension_prefs_->SetExtensionState(extension_id, Extension::DISABLED); 828 extension_prefs_->SetExtensionState(extension_id, Extension::DISABLED);
832 829
833 extension = GetExtensionByIdInternal(extension_id, true, false, true); 830 extension = GetExtensionByIdInternal(extension_id, true, false, true);
834 if (!extension) 831 if (!extension)
835 return; 832 return;
836 833
837 // Move it over to the disabled list. 834 // Move it over to the disabled list.
838 disabled_extensions_.push_back(make_scoped_refptr(extension)); 835 disabled_extensions_.Insert(make_scoped_refptr(extension));
839 ExtensionList::iterator iter = std::find(extensions_.begin(), 836 if (extensions_.Contains(extension->id()))
840 extensions_.end(), 837 extensions_.Remove(extension->id());
841 extension); 838 else
842 if (iter != extensions_.end()) { 839 terminated_extensions_.Remove(extension->id());
843 extensions_.erase(iter);
844 } else {
845 iter = std::find(terminated_extensions_.begin(),
846 terminated_extensions_.end(),
847 extension);
848 terminated_extensions_.erase(iter);
849 }
850 840
851 NotifyExtensionUnloaded(extension, extension_misc::UNLOAD_REASON_DISABLE); 841 NotifyExtensionUnloaded(extension, extension_misc::UNLOAD_REASON_DISABLE);
852 842
853 SyncExtensionChangeIfNeeded(*extension); 843 SyncExtensionChangeIfNeeded(*extension);
854 844
855 // Deactivating one extension might have solved the problems of others. 845 // Deactivating one extension might have solved the problems of others.
856 // Therefore, we clear warnings of this type for all extensions. 846 // Therefore, we clear warnings of this type for all extensions.
857 std::set<ExtensionWarningSet::WarningType> warnings; 847 std::set<ExtensionWarningSet::WarningType> warnings;
858 extension_warnings_.GetWarningsAffectingExtension(extension_id, &warnings); 848 extension_warnings_.GetWarningsAffectingExtension(extension_id, &warnings);
859 extension_warnings_.ClearWarnings(warnings); 849 extension_warnings_.ClearWarnings(warnings);
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
1108 // Use this set to indicate if an extension in the blacklist has been used. 1098 // Use this set to indicate if an extension in the blacklist has been used.
1109 std::set<std::string> blacklist_set; 1099 std::set<std::string> blacklist_set;
1110 for (unsigned int i = 0; i < blacklist.size(); ++i) { 1100 for (unsigned int i = 0; i < blacklist.size(); ++i) {
1111 if (Extension::IdIsValid(blacklist[i])) { 1101 if (Extension::IdIsValid(blacklist[i])) {
1112 blacklist_set.insert(blacklist[i]); 1102 blacklist_set.insert(blacklist[i]);
1113 } 1103 }
1114 } 1104 }
1115 extension_prefs_->UpdateBlacklist(blacklist_set); 1105 extension_prefs_->UpdateBlacklist(blacklist_set);
1116 std::vector<std::string> to_be_removed; 1106 std::vector<std::string> to_be_removed;
1117 // Loop current extensions, unload installed extensions. 1107 // Loop current extensions, unload installed extensions.
1118 for (ExtensionList::const_iterator iter = extensions_.begin(); 1108 for (ExtensionSet::const_iterator iter = extensions_.begin();
1119 iter != extensions_.end(); ++iter) { 1109 iter != extensions_.end(); ++iter) {
1120 const Extension* extension = (*iter); 1110 const Extension* extension = (*iter);
1121 if (blacklist_set.find(extension->id()) != blacklist_set.end()) { 1111 if (blacklist_set.find(extension->id()) != blacklist_set.end()) {
1122 to_be_removed.push_back(extension->id()); 1112 to_be_removed.push_back(extension->id());
1123 } 1113 }
1124 } 1114 }
1125 1115
1126 // UnloadExtension will change the extensions_ list. So, we should 1116 // UnloadExtension will change the extensions_ list. So, we should
1127 // call it outside the iterator loop. 1117 // call it outside the iterator loop.
1128 for (unsigned int i = 0; i < to_be_removed.size(); ++i) { 1118 for (unsigned int i = 0; i < to_be_removed.size(); ++i) {
(...skipping 22 matching lines...) Expand all
1151 return ready_; 1141 return ready_;
1152 } 1142 }
1153 1143
1154 ExtensionUpdater* ExtensionService::updater() { 1144 ExtensionUpdater* ExtensionService::updater() {
1155 return updater_.get(); 1145 return updater_.get();
1156 } 1146 }
1157 1147
1158 void ExtensionService::CheckAdminBlacklist() { 1148 void ExtensionService::CheckAdminBlacklist() {
1159 std::vector<std::string> to_be_removed; 1149 std::vector<std::string> to_be_removed;
1160 // Loop through extensions list, unload installed extensions. 1150 // Loop through extensions list, unload installed extensions.
1161 for (ExtensionList::const_iterator iter = extensions_.begin(); 1151 for (ExtensionSet::const_iterator iter = extensions_.begin();
1162 iter != extensions_.end(); ++iter) { 1152 iter != extensions_.end(); ++iter) {
1163 const Extension* extension = (*iter); 1153 const Extension* extension = (*iter);
1164 if (!extension_prefs_->IsExtensionAllowedByPolicy(extension->id(), 1154 if (!extension_prefs_->IsExtensionAllowedByPolicy(extension->id(),
1165 extension->location())) { 1155 extension->location())) {
1166 to_be_removed.push_back(extension->id()); 1156 to_be_removed.push_back(extension->id());
1167 } 1157 }
1168 } 1158 }
1169 1159
1170 // UnloadExtension will change the extensions_ list. So, we should 1160 // UnloadExtension will change the extensions_ list. So, we should
1171 // call it outside the iterator loop. 1161 // call it outside the iterator loop.
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
1352 bundle->synced_extensions.erase(extension_sync_data.id()); 1342 bundle->synced_extensions.erase(extension_sync_data.id());
1353 else 1343 else
1354 bundle->synced_extensions.insert(extension_sync_data.id()); 1344 bundle->synced_extensions.insert(extension_sync_data.id());
1355 ProcessExtensionSyncData(extension_sync_data, *bundle); 1345 ProcessExtensionSyncData(extension_sync_data, *bundle);
1356 } 1346 }
1357 1347
1358 return SyncError(); 1348 return SyncError();
1359 } 1349 }
1360 1350
1361 void ExtensionService::GetSyncDataListHelper( 1351 void ExtensionService::GetSyncDataListHelper(
1362 const ExtensionList& extensions, 1352 const ExtensionSet& extensions,
1363 const SyncBundle& bundle, 1353 const SyncBundle& bundle,
1364 std::vector<ExtensionSyncData>* sync_data_list) const { 1354 std::vector<ExtensionSyncData>* sync_data_list) const {
1365 for (ExtensionList::const_iterator it = extensions.begin(); 1355 for (ExtensionSet::const_iterator it = extensions.begin();
1366 it != extensions.end(); ++it) { 1356 it != extensions.end(); ++it) {
1367 const Extension& extension = **it; 1357 const Extension& extension = **it;
1368 if (bundle.filter(extension) && 1358 if (bundle.filter(extension) &&
1369 // If we have pending extension data for this extension, then this 1359 // If we have pending extension data for this extension, then this
1370 // version is out of date. We'll sync back the version we got from 1360 // version is out of date. We'll sync back the version we got from
1371 // sync. 1361 // sync.
1372 !bundle.HasPendingExtensionId(extension.id())) { 1362 !bundle.HasPendingExtensionId(extension.id())) {
1373 sync_data_list->push_back(ExtensionSyncData( 1363 sync_data_list->push_back(ExtensionSyncData(
1374 extension, 1364 extension,
1375 IsExtensionEnabled(extension.id()), 1365 IsExtensionEnabled(extension.id()),
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
1486 1476
1487 // Broadcast unloaded and loaded events to update browser state. Only bother 1477 // Broadcast unloaded and loaded events to update browser state. Only bother
1488 // if the value changed and the extension is actually enabled, since there is 1478 // if the value changed and the extension is actually enabled, since there is
1489 // no UI otherwise. 1479 // no UI otherwise.
1490 bool old_enabled = extension_prefs_->IsIncognitoEnabled(extension_id); 1480 bool old_enabled = extension_prefs_->IsIncognitoEnabled(extension_id);
1491 if (enabled == old_enabled) 1481 if (enabled == old_enabled)
1492 return; 1482 return;
1493 1483
1494 extension_prefs_->SetIsIncognitoEnabled(extension_id, enabled); 1484 extension_prefs_->SetIsIncognitoEnabled(extension_id, enabled);
1495 1485
1496 bool extension_is_enabled = std::find(extensions_.begin(), extensions_.end(), 1486 bool extension_is_enabled = extensions_.Contains(extension->id());
1497 extension) != extensions_.end();
1498 1487
1499 // When we reload the extension the ID may be invalidated if we've passed it 1488 // When we reload the extension the ID may be invalidated if we've passed it
1500 // by const ref everywhere. Make a copy to be safe. 1489 // by const ref everywhere. Make a copy to be safe.
1501 std::string id = extension_id; 1490 std::string id = extension_id;
1502 if (extension_is_enabled) 1491 if (extension_is_enabled)
1503 ReloadExtension(extension->id()); 1492 ReloadExtension(extension->id());
1504 1493
1505 // Reloading the extension invalidates the |extension| pointer. 1494 // Reloading the extension invalidates the |extension| pointer.
1506 extension = GetInstalledExtension(id); 1495 extension = GetInstalledExtension(id);
1507 if (extension) 1496 if (extension)
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1564 void ExtensionService::SetAllowFileAccess(const Extension* extension, 1553 void ExtensionService::SetAllowFileAccess(const Extension* extension,
1565 bool allow) { 1554 bool allow) {
1566 // Reload to update browser state. Only bother if the value changed and the 1555 // Reload to update browser state. Only bother if the value changed and the
1567 // extension is actually enabled, since there is no UI otherwise. 1556 // extension is actually enabled, since there is no UI otherwise.
1568 bool old_allow = AllowFileAccess(extension); 1557 bool old_allow = AllowFileAccess(extension);
1569 if (allow == old_allow) 1558 if (allow == old_allow)
1570 return; 1559 return;
1571 1560
1572 extension_prefs_->SetAllowFileAccess(extension->id(), allow); 1561 extension_prefs_->SetAllowFileAccess(extension->id(), allow);
1573 1562
1574 bool extension_is_enabled = std::find(extensions_.begin(), extensions_.end(), 1563 bool extension_is_enabled = extensions_.Contains(extension->id());
1575 extension) != extensions_.end();
1576 if (extension_is_enabled) 1564 if (extension_is_enabled)
1577 ReloadExtension(extension->id()); 1565 ReloadExtension(extension->id());
1578 } 1566 }
1579 1567
1580 bool ExtensionService::GetBrowserActionVisibility(const Extension* extension) { 1568 bool ExtensionService::GetBrowserActionVisibility(const Extension* extension) {
1581 return extension_prefs_->GetBrowserActionVisibility(extension); 1569 return extension_prefs_->GetBrowserActionVisibility(extension);
1582 } 1570 }
1583 1571
1584 void ExtensionService::SetBrowserActionVisibility(const Extension* extension, 1572 void ExtensionService::SetBrowserActionVisibility(const Extension* extension,
1585 bool visible) { 1573 bool visible) {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1669 switches::kEnableExtensionAlerts)) { 1657 switches::kEnableExtensionAlerts)) {
1670 return; // TODO(miket): enable unconditionally when done. 1658 return; // TODO(miket): enable unconditionally when done.
1671 } 1659 }
1672 1660
1673 // Build up the lists of extensions that require acknowledgment. 1661 // Build up the lists of extensions that require acknowledgment.
1674 // If this is the first time, grandfather extensions that would have 1662 // If this is the first time, grandfather extensions that would have
1675 // caused notification. 1663 // caused notification.
1676 scoped_ptr<ExtensionGlobalError> global_error( 1664 scoped_ptr<ExtensionGlobalError> global_error(
1677 new ExtensionGlobalError(AsWeakPtr())); 1665 new ExtensionGlobalError(AsWeakPtr()));
1678 bool needs_alert = false; 1666 bool needs_alert = false;
1679 for (ExtensionList::const_iterator iter = extensions_.begin(); 1667 for (ExtensionSet::const_iterator iter = extensions_.begin();
1680 iter != extensions_.end(); ++iter) { 1668 iter != extensions_.end(); ++iter) {
1681 const Extension* e = *iter; 1669 const Extension* e = *iter;
1682 if (!IsExtensionEnabled(e->id())) {
Aaron Boodman 2011/12/01 08:27:12 Because all those extensions would be in disabled_
Yoyo Zhou 2011/12/05 19:34:09 Yeah, all IsExtensionEnabled does is check that it
1683 continue;
1684 }
1685 if (Extension::IsExternalLocation(e->location())) { 1670 if (Extension::IsExternalLocation(e->location())) {
1686 if (!extension_prefs_->IsExternalExtensionAcknowledged(e->id())) { 1671 if (!extension_prefs_->IsExternalExtensionAcknowledged(e->id())) {
1687 global_error->AddExternalExtension(e->id()); 1672 global_error->AddExternalExtension(e->id());
1688 needs_alert = true; 1673 needs_alert = true;
1689 } 1674 }
1690 } 1675 }
1691 if (extension_prefs_->IsExtensionBlacklisted(e->id())) { 1676 if (extension_prefs_->IsExtensionBlacklisted(e->id())) {
1692 if (!extension_prefs_->IsBlacklistedExtensionAcknowledged(e->id())) { 1677 if (!extension_prefs_->IsBlacklistedExtensionAcknowledged(e->id())) {
1693 global_error->AddBlacklistedExtension(e->id()); 1678 global_error->AddBlacklistedExtension(e->id());
1694 needs_alert = true; 1679 needs_alert = true;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1774 // Keep information about the extension so that we can reload it later 1759 // Keep information about the extension so that we can reload it later
1775 // even if it's not permanently installed. 1760 // even if it's not permanently installed.
1776 unloaded_extension_paths_[extension->id()] = extension->path(); 1761 unloaded_extension_paths_[extension->id()] = extension->path();
1777 1762
1778 // Clean up if the extension is meant to be enabled after a reload. 1763 // Clean up if the extension is meant to be enabled after a reload.
1779 disabled_extension_paths_.erase(extension->id()); 1764 disabled_extension_paths_.erase(extension->id());
1780 1765
1781 // Clean up runtime data. 1766 // Clean up runtime data.
1782 extension_runtime_data_.erase(extension_id); 1767 extension_runtime_data_.erase(extension_id);
1783 1768
1784 ExtensionList::iterator iter = std::find(disabled_extensions_.begin(), 1769 if (disabled_extensions_.Contains(extension->id())) {
1785 disabled_extensions_.end(),
1786 extension.get());
1787 if (iter != disabled_extensions_.end()) {
1788 UnloadedExtensionInfo details(extension, reason); 1770 UnloadedExtensionInfo details(extension, reason);
1789 details.already_disabled = true; 1771 details.already_disabled = true;
1790 disabled_extensions_.erase(iter); 1772 disabled_extensions_.Remove(extension->id());
1791 content::NotificationService::current()->Notify( 1773 content::NotificationService::current()->Notify(
1792 chrome::NOTIFICATION_EXTENSION_UNLOADED, 1774 chrome::NOTIFICATION_EXTENSION_UNLOADED,
1793 content::Source<Profile>(profile_), 1775 content::Source<Profile>(profile_),
1794 content::Details<UnloadedExtensionInfo>(&details)); 1776 content::Details<UnloadedExtensionInfo>(&details));
1795 // Make sure the profile cleans up its RequestContexts when an already 1777 // Make sure the profile cleans up its RequestContexts when an already
1796 // disabled extension is unloaded (since they are also tracking the disabled 1778 // disabled extension is unloaded (since they are also tracking the disabled
1797 // extensions). 1779 // extensions).
1798 profile_->UnregisterExtensionWithRequestContexts(extension_id, reason); 1780 profile_->UnregisterExtensionWithRequestContexts(extension_id, reason);
1799 return; 1781 return;
1800 } 1782 }
1801 1783
1802 iter = std::find(extensions_.begin(), extensions_.end(), extension.get()); 1784 // Remove the extension from our list.
1803 1785 extensions_.Remove(extension->id());
1804 // Remove the extension from our list.
1805 extensions_.erase(iter);
1806 1786
1807 NotifyExtensionUnloaded(extension.get(), reason); 1787 NotifyExtensionUnloaded(extension.get(), reason);
1808 } 1788 }
1809 1789
1810 void ExtensionService::UnloadAllExtensions() { 1790 void ExtensionService::UnloadAllExtensions() {
1811 profile_->GetExtensionSpecialStoragePolicy()-> 1791 profile_->GetExtensionSpecialStoragePolicy()->
1812 RevokeRightsForAllExtensions(); 1792 RevokeRightsForAllExtensions();
1813 1793
1814 extensions_.clear(); 1794 extensions_.Clear();
1815 disabled_extensions_.clear(); 1795 disabled_extensions_.Clear();
1816 terminated_extension_ids_.clear(); 1796 terminated_extensions_.Clear();
1817 terminated_extensions_.clear();
1818 extension_runtime_data_.clear(); 1797 extension_runtime_data_.clear();
1819 1798
1820 // TODO(erikkay) should there be a notification for this? We can't use 1799 // TODO(erikkay) should there be a notification for this? We can't use
1821 // EXTENSION_UNLOADED since that implies that the extension has been disabled 1800 // EXTENSION_UNLOADED since that implies that the extension has been disabled
1822 // or uninstalled, and UnloadAll is just part of shutdown. 1801 // or uninstalled, and UnloadAll is just part of shutdown.
1823 } 1802 }
1824 1803
1825 void ExtensionService::ReloadExtensions() { 1804 void ExtensionService::ReloadExtensions() {
1826 UnloadAllExtensions(); 1805 UnloadAllExtensions();
1827 component_loader_->LoadAll(); 1806 component_loader_->LoadAll();
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1891 // If the extension was disabled for a reload, then enable it. 1870 // If the extension was disabled for a reload, then enable it.
1892 if (disabled_extension_paths_.erase(extension->id()) > 0) 1871 if (disabled_extension_paths_.erase(extension->id()) > 0)
1893 EnableExtension(extension->id()); 1872 EnableExtension(extension->id());
1894 1873
1895 // Check if the extension's privileges have changed and disable the 1874 // Check if the extension's privileges have changed and disable the
1896 // extension if necessary. 1875 // extension if necessary.
1897 InitializePermissions(extension); 1876 InitializePermissions(extension);
1898 1877
1899 bool disabled = extension_prefs_->IsExtensionDisabled(extension->id()); 1878 bool disabled = extension_prefs_->IsExtensionDisabled(extension->id());
1900 if (disabled) { 1879 if (disabled) {
1901 disabled_extensions_.push_back(scoped_extension); 1880 disabled_extensions_.Insert(scoped_extension);
1902 // TODO(aa): This seems dodgy. It seems that AddExtension() could get called 1881 // TODO(aa): This seems dodgy. AddExtension() could get called with a
1903 // with a disabled extension for other reasons other than that an update was 1882 // disabled extension for other reasons other than that an update was
1904 // disabled. 1883 // disabled, e.g. as in ExtensionManagementTest.InstallRequiresConfirm.
Aaron Boodman 2011/12/01 08:27:12 heh
1905 content::NotificationService::current()->Notify( 1884 content::NotificationService::current()->Notify(
1906 chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED, 1885 chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED,
1907 content::Source<Profile>(profile_), 1886 content::Source<Profile>(profile_),
1908 content::Details<const Extension>(extension)); 1887 content::Details<const Extension>(extension));
1909 SyncExtensionChangeIfNeeded(*extension); 1888 SyncExtensionChangeIfNeeded(*extension);
1910 return; 1889 return;
1911 } 1890 }
1912 1891
1913 extensions_.push_back(scoped_extension); 1892 extensions_.Insert(scoped_extension);
1914 SyncExtensionChangeIfNeeded(*extension); 1893 SyncExtensionChangeIfNeeded(*extension);
1915 NotifyExtensionLoaded(extension); 1894 NotifyExtensionLoaded(extension);
1916 IdentifyAlertableExtensions(); 1895 IdentifyAlertableExtensions();
1917 } 1896 }
1918 1897
1919 void ExtensionService::InitializePermissions(const Extension* extension) { 1898 void ExtensionService::InitializePermissions(const Extension* extension) {
1920 // If the extension has used the optional permissions API, it will have a 1899 // If the extension has used the optional permissions API, it will have a
1921 // custom set of active permissions defined in the extension prefs. Here, 1900 // custom set of active permissions defined in the extension prefs. Here,
1922 // we update the extension's active permissions based on the prefs. 1901 // we update the extension's active permissions based on the prefs.
1923 scoped_refptr<ExtensionPermissionSet> active_permissions = 1902 scoped_refptr<ExtensionPermissionSet> active_permissions =
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
2015 RecordPermissionMessagesHistogram( 1994 RecordPermissionMessagesHistogram(
2016 extension, "Extensions.Permissions_AutoDisable"); 1995 extension, "Extensions.Permissions_AutoDisable");
2017 } 1996 }
2018 extension_prefs_->SetExtensionState(extension->id(), Extension::DISABLED); 1997 extension_prefs_->SetExtensionState(extension->id(), Extension::DISABLED);
2019 extension_prefs_->SetDidExtensionEscalatePermissions(extension, true); 1998 extension_prefs_->SetDidExtensionEscalatePermissions(extension, true);
2020 } 1999 }
2021 } 2000 }
2022 2001
2023 void ExtensionService::UpdateActiveExtensionsInCrashReporter() { 2002 void ExtensionService::UpdateActiveExtensionsInCrashReporter() {
2024 std::set<std::string> extension_ids; 2003 std::set<std::string> extension_ids;
2025 for (size_t i = 0; i < extensions_.size(); ++i) { 2004 for (ExtensionSet::const_iterator iter = extensions_.begin();
2026 if (!extensions_[i]->is_theme() && 2005 iter != extensions_.end(); ++iter) {
2027 extensions_[i]->location() != Extension::COMPONENT) 2006 const Extension* extension = *iter;
2028 extension_ids.insert(extensions_[i]->id()); 2007 if (!extension->is_theme() && extension->location() != Extension::COMPONENT)
2008 extension_ids.insert(extension->id());
2029 } 2009 }
2030 2010
2031 child_process_logging::SetActiveExtensions(extension_ids); 2011 child_process_logging::SetActiveExtensions(extension_ids);
2032 } 2012 }
2033 2013
2034 void ExtensionService::OnExtensionInstalled( 2014 void ExtensionService::OnExtensionInstalled(
2035 const Extension* extension, bool from_webstore, int page_index) { 2015 const Extension* extension, bool from_webstore, int page_index) {
2036 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2016 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2037 2017
2038 // Ensure extension is deleted unless we transfer ownership. 2018 // Ensure extension is deleted unless we transfer ownership.
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
2111 2091
2112 // Transfer ownership of |extension| to AddExtension. 2092 // Transfer ownership of |extension| to AddExtension.
2113 AddExtension(scoped_extension); 2093 AddExtension(scoped_extension);
2114 } 2094 }
2115 2095
2116 const Extension* ExtensionService::GetExtensionByIdInternal( 2096 const Extension* ExtensionService::GetExtensionByIdInternal(
2117 const std::string& id, bool include_enabled, bool include_disabled, 2097 const std::string& id, bool include_enabled, bool include_disabled,
2118 bool include_terminated) const { 2098 bool include_terminated) const {
2119 std::string lowercase_id = StringToLowerASCII(id); 2099 std::string lowercase_id = StringToLowerASCII(id);
2120 if (include_enabled) { 2100 if (include_enabled) {
2121 for (ExtensionList::const_iterator iter = extensions_.begin(); 2101 const Extension* extension = extensions_.GetByID(lowercase_id);
2122 iter != extensions_.end(); ++iter) { 2102 if (extension)
2123 if ((*iter)->id() == lowercase_id) 2103 return extension;
2124 return *iter;
2125 }
2126 } 2104 }
2127 if (include_disabled) { 2105 if (include_disabled) {
2128 for (ExtensionList::const_iterator iter = disabled_extensions_.begin(); 2106 const Extension* extension = disabled_extensions_.GetByID(lowercase_id);
2129 iter != disabled_extensions_.end(); ++iter) { 2107 if (extension)
2130 if ((*iter)->id() == lowercase_id) 2108 return extension;
2131 return *iter;
2132 }
2133 } 2109 }
2134 if (include_terminated) { 2110 if (include_terminated) {
2135 for (ExtensionList::const_iterator iter = terminated_extensions_.begin(); 2111 const Extension* extension = terminated_extensions_.GetByID(lowercase_id);
2136 iter != terminated_extensions_.end(); ++iter) { 2112 if (extension)
2137 if ((*iter)->id() == lowercase_id) 2113 return extension;
2138 return *iter;
2139 }
2140 } 2114 }
2141 return NULL; 2115 return NULL;
2142 } 2116 }
2143 2117
2144 void ExtensionService::TrackTerminatedExtension(const Extension* extension) { 2118 void ExtensionService::TrackTerminatedExtension(const Extension* extension) {
2145 if (terminated_extension_ids_.insert(extension->id()).second) 2119 if (!terminated_extensions_.Contains(extension->id()))
2146 terminated_extensions_.push_back(make_scoped_refptr(extension)); 2120 terminated_extensions_.Insert(make_scoped_refptr(extension));
2147 2121
2148 // TODO(yoz): Listen to navcontrollers for that extension. Is this a todo?
2149
2150 // TODO(yoz): make sure this is okay in *ALL* the listeners!
2151 UnloadExtension(extension->id(), extension_misc::UNLOAD_REASON_TERMINATE); 2122 UnloadExtension(extension->id(), extension_misc::UNLOAD_REASON_TERMINATE);
2152 } 2123 }
2153 2124
2154 void ExtensionService::UntrackTerminatedExtension(const std::string& id) { 2125 void ExtensionService::UntrackTerminatedExtension(const std::string& id) {
2155 std::string lowercase_id = StringToLowerASCII(id); 2126 std::string lowercase_id = StringToLowerASCII(id);
2156 if (terminated_extension_ids_.erase(lowercase_id) <= 0) 2127 terminated_extensions_.Remove(lowercase_id);
2157 return;
2158
2159 for (ExtensionList::iterator iter = terminated_extensions_.begin();
2160 iter != terminated_extensions_.end(); ++iter) {
2161 if ((*iter)->id() == lowercase_id) {
2162 terminated_extensions_.erase(iter);
2163 return;
2164 }
2165 }
2166 } 2128 }
2167 2129
2168 const Extension* ExtensionService::GetTerminatedExtension( 2130 const Extension* ExtensionService::GetTerminatedExtension(
2169 const std::string& id) const { 2131 const std::string& id) const {
2170 return GetExtensionByIdInternal(id, false, false, true); 2132 return GetExtensionByIdInternal(id, false, false, true);
2171 } 2133 }
2172 2134
2173 const Extension* ExtensionService::GetInstalledExtension( 2135 const Extension* ExtensionService::GetInstalledExtension(
2174 const std::string& id) const { 2136 const std::string& id) const {
2175 return GetExtensionByIdInternal(id, true, true, true); 2137 return GetExtensionByIdInternal(id, true, true, true);
2176 } 2138 }
2177 2139
2178 const Extension* ExtensionService::GetWebStoreApp() { 2140 const Extension* ExtensionService::GetWebStoreApp() {
2179 return GetExtensionById(extension_misc::kWebStoreAppId, false); 2141 return GetExtensionById(extension_misc::kWebStoreAppId, false);
2180 } 2142 }
2181 2143
2182 const Extension* ExtensionService::GetExtensionByURL(const GURL& url) { 2144 const Extension* ExtensionService::GetExtensionByURL(const GURL& url) {
2183 return url.scheme() != chrome::kExtensionScheme ? NULL : 2145 return url.scheme() != chrome::kExtensionScheme ? NULL :
2184 GetExtensionById(url.host(), false); 2146 GetExtensionById(url.host(), false);
2185 } 2147 }
2186 2148
2187 const Extension* ExtensionService::GetExtensionByWebExtent(const GURL& url) { 2149 const Extension* ExtensionService::GetExtensionByWebExtent(const GURL& url) {
2188 for (size_t i = 0; i < extensions_.size(); ++i) { 2150 // TODO(yoz): Should be Set::GetByURL.
2189 if (extensions_[i]->web_extent().MatchesURL(url)) 2151 for (ExtensionSet::const_iterator iter = extensions_.begin();
2190 return extensions_[i]; 2152 iter != extensions_.end(); ++iter) {
2153 if ((*iter)->web_extent().MatchesURL(url))
2154 return *iter;
2191 } 2155 }
2192 return NULL; 2156 return NULL;
2193 } 2157 }
2194 2158
2195 const Extension* ExtensionService::GetDisabledExtensionByWebExtent( 2159 const Extension* ExtensionService::GetDisabledExtensionByWebExtent(
2196 const GURL& url) { 2160 const GURL& url) {
2197 for (size_t i = 0; i < disabled_extensions_.size(); ++i) { 2161 // TODO(yoz): Should be Set::GetByURL.
2198 if (disabled_extensions_[i]->web_extent().MatchesURL(url)) 2162 for (ExtensionSet::const_iterator iter = disabled_extensions_.begin();
2199 return disabled_extensions_[i]; 2163 iter != disabled_extensions_.end(); ++iter) {
2164 if ((*iter)->web_extent().MatchesURL(url))
2165 return *iter;
2200 } 2166 }
2201 return NULL; 2167 return NULL;
2202 } 2168 }
2203 2169
2204 bool ExtensionService::ExtensionBindingsAllowed(const GURL& url) { 2170 bool ExtensionService::ExtensionBindingsAllowed(const GURL& url) {
2205 // Allow bindings for all packaged extensions. 2171 // Allow bindings for all packaged extensions.
2206 // Note that GetExtensionByURL may return an Extension for hosted apps 2172 // Note that GetExtensionByURL may return an Extension for hosted apps
2207 // (excluding bookmark apps) if the URL came from GetEffectiveURL. 2173 // (excluding bookmark apps) if the URL came from GetEffectiveURL.
2208 const Extension* extension = GetExtensionByURL(url); 2174 const Extension* extension = GetExtensionByURL(url);
2209 if (extension && extension->GetType() != Extension::TYPE_HOSTED_APP) 2175 if (extension && extension->GetType() != Extension::TYPE_HOSTED_APP)
2210 return true; 2176 return true;
2211 2177
2212 // Allow bindings for all component, hosted apps. 2178 // Allow bindings for all component, hosted apps.
2213 if (!extension) 2179 if (!extension)
2214 extension = GetExtensionByWebExtent(url); 2180 extension = GetExtensionByWebExtent(url);
2215 return (extension && extension->location() == Extension::COMPONENT); 2181 return (extension && extension->location() == Extension::COMPONENT);
2216 } 2182 }
2217 2183
2218 const Extension* ExtensionService::GetExtensionByOverlappingWebExtent( 2184 const Extension* ExtensionService::GetExtensionByOverlappingWebExtent(
2219 const URLPatternSet& extent) { 2185 const URLPatternSet& extent) {
2220 for (size_t i = 0; i < extensions_.size(); ++i) { 2186 // TODO(yoz): unclear here, but at least should be in Set?
2221 if (extensions_[i]->web_extent().OverlapsWith(extent)) 2187 // only used in CrxInstaller check
2222 return extensions_[i]; 2188 for (ExtensionSet::const_iterator iter = extensions_.begin();
2189 iter != extensions_.end(); ++iter) {
2190 if ((*iter)->web_extent().OverlapsWith(extent))
2191 return *iter;
2223 } 2192 }
2224 2193
2225 return NULL; 2194 return NULL;
2226 } 2195 }
2227 2196
2228 const SkBitmap& ExtensionService::GetOmniboxIcon( 2197 const SkBitmap& ExtensionService::GetOmniboxIcon(
2229 const std::string& extension_id) { 2198 const std::string& extension_id) {
2230 return omnibox_icon_manager_.GetIcon(extension_id); 2199 return omnibox_icon_manager_.GetIcon(extension_id);
2231 } 2200 }
2232 2201
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
2345 ExtensionFunctionDispatcher::GetAllFunctionNames(&function_names); 2314 ExtensionFunctionDispatcher::GetAllFunctionNames(&function_names);
2346 process->Send(new ExtensionMsg_SetFunctionNames(function_names)); 2315 process->Send(new ExtensionMsg_SetFunctionNames(function_names));
2347 2316
2348 // Scripting whitelist. This is modified by tests and must be communicated 2317 // Scripting whitelist. This is modified by tests and must be communicated
2349 // to renderers. 2318 // to renderers.
2350 process->Send(new ExtensionMsg_SetScriptingWhitelist( 2319 process->Send(new ExtensionMsg_SetScriptingWhitelist(
2351 *Extension::GetScriptingWhitelist())); 2320 *Extension::GetScriptingWhitelist()));
2352 2321
2353 // Loaded extensions. 2322 // Loaded extensions.
2354 std::vector<ExtensionMsg_Loaded_Params> loaded_extensions; 2323 std::vector<ExtensionMsg_Loaded_Params> loaded_extensions;
2355 for (size_t i = 0; i < extensions_.size(); ++i) { 2324 for (ExtensionSet::const_iterator iter = extensions_.begin();
2356 loaded_extensions.push_back( 2325 iter != extensions_.end(); ++iter) {
2357 ExtensionMsg_Loaded_Params(extensions_[i])); 2326 loaded_extensions.push_back(ExtensionMsg_Loaded_Params(*iter));
2358 } 2327 }
2359 process->Send(new ExtensionMsg_Loaded(loaded_extensions)); 2328 process->Send(new ExtensionMsg_Loaded(loaded_extensions));
2360 break; 2329 break;
2361 } 2330 }
2362 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: { 2331 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: {
2363 content::RenderProcessHost* process = 2332 content::RenderProcessHost* process =
2364 content::Source<content::RenderProcessHost>(source).ptr(); 2333 content::Source<content::RenderProcessHost>(source).ptr();
2365 Profile* host_profile = 2334 Profile* host_profile =
2366 Profile::FromBrowserContext(process->GetBrowserContext()); 2335 Profile::FromBrowserContext(process->GetBrowserContext());
2367 if (!profile_->IsSameProfile(host_profile->GetOriginalProfile())) 2336 if (!profile_->IsSameProfile(host_profile->GetOriginalProfile()))
(...skipping 30 matching lines...) Expand all
2398 NOTREACHED() << "Unexpected notification type."; 2367 NOTREACHED() << "Unexpected notification type.";
2399 } 2368 }
2400 } 2369 }
2401 2370
2402 bool ExtensionService::HasApps() const { 2371 bool ExtensionService::HasApps() const {
2403 return !GetAppIds().empty(); 2372 return !GetAppIds().empty();
2404 } 2373 }
2405 2374
2406 ExtensionIdSet ExtensionService::GetAppIds() const { 2375 ExtensionIdSet ExtensionService::GetAppIds() const {
2407 ExtensionIdSet result; 2376 ExtensionIdSet result;
2408 for (ExtensionList::const_iterator it = extensions_.begin(); 2377 for (ExtensionSet::const_iterator it = extensions_.begin();
2409 it != extensions_.end(); ++it) { 2378 it != extensions_.end(); ++it) {
2410 if ((*it)->is_app() && (*it)->location() != Extension::COMPONENT) 2379 if ((*it)->is_app() && (*it)->location() != Extension::COMPONENT)
2411 result.insert((*it)->id()); 2380 result.insert((*it)->id());
2412 } 2381 }
2413 2382
2414 return result; 2383 return result;
2415 } 2384 }
2416 2385
2417 bool ExtensionService::IsBackgroundPageReady(const Extension* extension) { 2386 bool ExtensionService::IsBackgroundPageReady(const Extension* extension) {
2418 return (extension->background_url().is_empty() || 2387 return (extension->background_url().is_empty() ||
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
2517 2486
2518 ExtensionService::NaClModuleInfoList::iterator 2487 ExtensionService::NaClModuleInfoList::iterator
2519 ExtensionService::FindNaClModule(const GURL& url) { 2488 ExtensionService::FindNaClModule(const GURL& url) {
2520 for (NaClModuleInfoList::iterator iter = nacl_module_list_.begin(); 2489 for (NaClModuleInfoList::iterator iter = nacl_module_list_.begin();
2521 iter != nacl_module_list_.end(); ++iter) { 2490 iter != nacl_module_list_.end(); ++iter) {
2522 if (iter->url == url) 2491 if (iter->url == url)
2523 return iter; 2492 return iter;
2524 } 2493 }
2525 return nacl_module_list_.end(); 2494 return nacl_module_list_.end();
2526 } 2495 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698