| OLD | NEW |
| 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 889 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 900 } | 900 } |
| 901 | 901 |
| 902 void ExtensionService::GrantPermissions(const Extension* extension) { | 902 void ExtensionService::GrantPermissions(const Extension* extension) { |
| 903 CHECK(extension); | 903 CHECK(extension); |
| 904 | 904 |
| 905 // We only maintain the granted permissions prefs for INTERNAL extensions. | 905 // We only maintain the granted permissions prefs for INTERNAL extensions. |
| 906 CHECK_EQ(Extension::INTERNAL, extension->location()); | 906 CHECK_EQ(Extension::INTERNAL, extension->location()); |
| 907 | 907 |
| 908 URLPatternSet effective_hosts = extension->GetEffectiveHostPermissions(); | 908 URLPatternSet effective_hosts = extension->GetEffectiveHostPermissions(); |
| 909 extension_prefs_->AddGrantedPermissions(extension->id(), | 909 extension_prefs_->AddGrantedPermissions(extension->id(), |
| 910 extension->HasFullPermissions(), | 910 extension->permission_set()); |
| 911 extension->api_permissions(), | |
| 912 effective_hosts); | |
| 913 } | 911 } |
| 914 | 912 |
| 915 void ExtensionService::GrantPermissionsAndEnableExtension( | 913 void ExtensionService::GrantPermissionsAndEnableExtension( |
| 916 const Extension* extension) { | 914 const Extension* extension) { |
| 917 CHECK(extension); | 915 CHECK(extension); |
| 918 RecordPermissionMessagesHistogram( | 916 RecordPermissionMessagesHistogram( |
| 919 extension, "Extensions.Permissions_ReEnable"); | 917 extension, "Extensions.Permissions_ReEnable"); |
| 920 GrantPermissions(extension); | 918 GrantPermissions(extension); |
| 921 extension_prefs_->SetDidExtensionEscalatePermissions(extension, false); | 919 extension_prefs_->SetDidExtensionEscalatePermissions(extension, false); |
| 922 EnableExtension(extension->id()); | 920 EnableExtension(extension->id()); |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1120 } | 1118 } |
| 1121 | 1119 |
| 1122 // static | 1120 // static |
| 1123 void ExtensionService::RecordPermissionMessagesHistogram( | 1121 void ExtensionService::RecordPermissionMessagesHistogram( |
| 1124 const Extension* e, const char* histogram) { | 1122 const Extension* e, const char* histogram) { |
| 1125 // Since this is called from multiple sources, and since the Histogram macros | 1123 // Since this is called from multiple sources, and since the Histogram macros |
| 1126 // use statics, we need to manually lookup the Histogram ourselves. | 1124 // use statics, we need to manually lookup the Histogram ourselves. |
| 1127 base::Histogram* counter = base::LinearHistogram::FactoryGet( | 1125 base::Histogram* counter = base::LinearHistogram::FactoryGet( |
| 1128 histogram, | 1126 histogram, |
| 1129 1, | 1127 1, |
| 1130 Extension::PermissionMessage::ID_ENUM_BOUNDARY, | 1128 ExtensionPermissionMessage::ID_ENUM_BOUNDARY, |
| 1131 Extension::PermissionMessage::ID_ENUM_BOUNDARY + 1, | 1129 ExtensionPermissionMessage::ID_ENUM_BOUNDARY + 1, |
| 1132 base::Histogram::kUmaTargetedHistogramFlag); | 1130 base::Histogram::kUmaTargetedHistogramFlag); |
| 1133 | 1131 |
| 1134 std::vector<Extension::PermissionMessage> permissions = | 1132 std::vector<ExtensionPermissionMessage> permissions = |
| 1135 e->GetPermissionMessages(); | 1133 e->GetPermissionMessages(); |
| 1136 if (permissions.empty()) { | 1134 if (permissions.empty()) { |
| 1137 counter->Add(Extension::PermissionMessage::ID_NONE); | 1135 counter->Add(ExtensionPermissionMessage::ID_NONE); |
| 1138 } else { | 1136 } else { |
| 1139 std::vector<Extension::PermissionMessage>::iterator it; | 1137 std::vector<ExtensionPermissionMessage>::iterator it; |
| 1140 for (it = permissions.begin(); it != permissions.end(); ++it) | 1138 for (it = permissions.begin(); it != permissions.end(); ++it) |
| 1141 counter->Add(it->message_id()); | 1139 counter->Add(it->message_id()); |
| 1142 } | 1140 } |
| 1143 } | 1141 } |
| 1144 | 1142 |
| 1145 void ExtensionService::LoadInstalledExtension(const ExtensionInfo& info, | 1143 void ExtensionService::LoadInstalledExtension(const ExtensionInfo& info, |
| 1146 bool write_to_prefs) { | 1144 bool write_to_prefs) { |
| 1147 std::string error; | 1145 std::string error; |
| 1148 scoped_refptr<const Extension> extension(NULL); | 1146 scoped_refptr<const Extension> extension(NULL); |
| 1149 if (!extension_prefs_->IsExtensionAllowedByPolicy(info.extension_id)) { | 1147 if (!extension_prefs_->IsExtensionAllowedByPolicy(info.extension_id)) { |
| (...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1832 // will record the permissions it recognized, not including "omnibox." | 1830 // will record the permissions it recognized, not including "omnibox." |
| 1833 // When upgrading to Chrome 10, "omnibox" will be recognized and Chrome | 1831 // When upgrading to Chrome 10, "omnibox" will be recognized and Chrome |
| 1834 // will disable the extension and prompt the user to approve the increase | 1832 // will disable the extension and prompt the user to approve the increase |
| 1835 // in privileges. The extension could then release a new version that | 1833 // in privileges. The extension could then release a new version that |
| 1836 // removes the "omnibox" permission. When the user upgrades, Chrome will | 1834 // removes the "omnibox" permission. When the user upgrades, Chrome will |
| 1837 // still remember that "omnibox" had been granted, so that if the | 1835 // still remember that "omnibox" had been granted, so that if the |
| 1838 // extension once again includes "omnibox" in an upgrade, the extension | 1836 // extension once again includes "omnibox" in an upgrade, the extension |
| 1839 // can upgrade without requiring this user's approval. | 1837 // can upgrade without requiring this user's approval. |
| 1840 const Extension* old = GetExtensionByIdInternal(extension->id(), | 1838 const Extension* old = GetExtensionByIdInternal(extension->id(), |
| 1841 true, true, false); | 1839 true, true, false); |
| 1842 bool granted_full_access; | |
| 1843 std::set<std::string> granted_apis; | |
| 1844 URLPatternSet granted_extent; | |
| 1845 | |
| 1846 bool is_extension_upgrade = old != NULL; | 1840 bool is_extension_upgrade = old != NULL; |
| 1847 bool is_privilege_increase = false; | 1841 bool is_privilege_increase = false; |
| 1848 | 1842 |
| 1849 // We only record the granted permissions for INTERNAL extensions, since | 1843 // We only record the granted permissions for INTERNAL extensions, since |
| 1850 // they can't silently increase privileges. | 1844 // they can't silently increase privileges. |
| 1851 if (extension->location() == Extension::INTERNAL) { | 1845 if (extension->location() == Extension::INTERNAL) { |
| 1852 // Add all the recognized permissions if the granted permissions list | 1846 // Add all the recognized permissions if the granted permissions list |
| 1853 // hasn't been initialized yet. | 1847 // hasn't been initialized yet. |
| 1854 if (!extension_prefs_->GetGrantedPermissions(extension->id(), | 1848 bool initialized = false; |
| 1855 &granted_full_access, | 1849 scoped_ptr<ExtensionPermissionSet> granted_permissions( |
| 1856 &granted_apis, | 1850 extension_prefs_->GetGrantedPermissions(extension->id(), &initialized)); |
| 1857 &granted_extent)) { | 1851 if (!initialized) { |
| 1858 GrantPermissions(extension); | 1852 GrantPermissions(extension); |
| 1859 CHECK(extension_prefs_->GetGrantedPermissions(extension->id(), | 1853 granted_permissions.reset( |
| 1860 &granted_full_access, | 1854 extension_prefs_->GetGrantedPermissions(extension->id(), NULL)); |
| 1861 &granted_apis, | 1855 CHECK(granted_permissions.get()); |
| 1862 &granted_extent)); | |
| 1863 } | 1856 } |
| 1864 | 1857 |
| 1865 // Here, we check if an extension's privileges have increased in a manner | 1858 // Here, we check if an extension's privileges have increased in a manner |
| 1866 // that requires the user's approval. This could occur because the browser | 1859 // that requires the user's approval. This could occur because the browser |
| 1867 // upgraded and recognized additional privileges, or an extension upgrades | 1860 // upgraded and recognized additional privileges, or an extension upgrades |
| 1868 // to a version that requires additional privileges. | 1861 // to a version that requires additional privileges. |
| 1869 is_privilege_increase = Extension::IsPrivilegeIncrease( | 1862 is_privilege_increase = |
| 1870 granted_full_access, granted_apis, granted_extent, extension); | 1863 granted_permissions->HasLessPrivilegesThan(extension->permission_set()); |
| 1871 } | 1864 } |
| 1872 | 1865 |
| 1873 if (is_extension_upgrade) { | 1866 if (is_extension_upgrade) { |
| 1874 // Other than for unpacked extensions, CrxInstaller should have guaranteed | 1867 // Other than for unpacked extensions, CrxInstaller should have guaranteed |
| 1875 // that we aren't downgrading. | 1868 // that we aren't downgrading. |
| 1876 if (extension->location() != Extension::LOAD) | 1869 if (extension->location() != Extension::LOAD) |
| 1877 CHECK(extension->version()->CompareTo(*(old->version())) >= 0); | 1870 CHECK(extension->version()->CompareTo(*(old->version())) >= 0); |
| 1878 | 1871 |
| 1879 // Extensions get upgraded if the privileges are allowed to increase or | 1872 // Extensions get upgraded if the privileges are allowed to increase or |
| 1880 // the privileges haven't increased. | 1873 // the privileges haven't increased. |
| (...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2331 | 2324 |
| 2332 ExtensionService::NaClModuleInfoList::iterator | 2325 ExtensionService::NaClModuleInfoList::iterator |
| 2333 ExtensionService::FindNaClModule(const GURL& url) { | 2326 ExtensionService::FindNaClModule(const GURL& url) { |
| 2334 for (NaClModuleInfoList::iterator iter = nacl_module_list_.begin(); | 2327 for (NaClModuleInfoList::iterator iter = nacl_module_list_.begin(); |
| 2335 iter != nacl_module_list_.end(); ++iter) { | 2328 iter != nacl_module_list_.end(); ++iter) { |
| 2336 if (iter->url == url) | 2329 if (iter->url == url) |
| 2337 return iter; | 2330 return iter; |
| 2338 } | 2331 } |
| 2339 return nacl_module_list_.end(); | 2332 return nacl_module_list_.end(); |
| 2340 } | 2333 } |
| OLD | NEW |