Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 <iterator> | 8 #include <iterator> |
| 9 #include <set> | 9 #include <set> |
| 10 | 10 |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 122 using content::BrowserContext; | 122 using content::BrowserContext; |
| 123 using content::BrowserThread; | 123 using content::BrowserThread; |
| 124 using content::DevToolsAgentHost; | 124 using content::DevToolsAgentHost; |
| 125 using content::PluginService; | 125 using content::PluginService; |
| 126 using extensions::CrxInstaller; | 126 using extensions::CrxInstaller; |
| 127 using extensions::Extension; | 127 using extensions::Extension; |
| 128 using extensions::ExtensionIdSet; | 128 using extensions::ExtensionIdSet; |
| 129 using extensions::ExtensionInfo; | 129 using extensions::ExtensionInfo; |
| 130 using extensions::FeatureSwitch; | 130 using extensions::FeatureSwitch; |
| 131 using extensions::Manifest; | 131 using extensions::Manifest; |
| 132 using extensions::NaClModuleInfo; | |
| 132 using extensions::PermissionMessage; | 133 using extensions::PermissionMessage; |
| 133 using extensions::PermissionMessages; | 134 using extensions::PermissionMessages; |
| 134 using extensions::PermissionSet; | 135 using extensions::PermissionSet; |
| 135 using extensions::UnloadedExtensionInfo; | 136 using extensions::UnloadedExtensionInfo; |
| 136 | 137 |
| 137 namespace errors = extension_manifest_errors; | 138 namespace errors = extension_manifest_errors; |
| 138 | 139 |
| 139 namespace { | 140 namespace { |
| 140 | 141 |
| 141 // Histogram values for logging events related to externally installed | 142 // Histogram values for logging events related to externally installed |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 171 | 172 |
| 172 ExtensionService::ExtensionRuntimeData::ExtensionRuntimeData() | 173 ExtensionService::ExtensionRuntimeData::ExtensionRuntimeData() |
| 173 : background_page_ready(false), | 174 : background_page_ready(false), |
| 174 being_upgraded(false), | 175 being_upgraded(false), |
| 175 has_used_webrequest(false) { | 176 has_used_webrequest(false) { |
| 176 } | 177 } |
| 177 | 178 |
| 178 ExtensionService::ExtensionRuntimeData::~ExtensionRuntimeData() { | 179 ExtensionService::ExtensionRuntimeData::~ExtensionRuntimeData() { |
| 179 } | 180 } |
| 180 | 181 |
| 181 ExtensionService::NaClModuleInfo::NaClModuleInfo() { | |
| 182 } | |
| 183 | |
| 184 ExtensionService::NaClModuleInfo::~NaClModuleInfo() { | |
| 185 } | |
| 186 | |
| 187 // ExtensionService. | 182 // ExtensionService. |
| 188 | 183 |
| 189 const char ExtensionService::kLocalAppSettingsDirectoryName[] = | 184 const char ExtensionService::kLocalAppSettingsDirectoryName[] = |
| 190 "Local App Settings"; | 185 "Local App Settings"; |
| 191 const char ExtensionService::kLocalExtensionSettingsDirectoryName[] = | 186 const char ExtensionService::kLocalExtensionSettingsDirectoryName[] = |
| 192 "Local Extension Settings"; | 187 "Local Extension Settings"; |
| 193 const char ExtensionService::kSyncAppSettingsDirectoryName[] = | 188 const char ExtensionService::kSyncAppSettingsDirectoryName[] = |
| 194 "Sync App Settings"; | 189 "Sync App Settings"; |
| 195 const char ExtensionService::kSyncExtensionSettingsDirectoryName[] = | 190 const char ExtensionService::kSyncExtensionSettingsDirectoryName[] = |
| 196 "Sync Extension Settings"; | 191 "Sync Extension Settings"; |
| (...skipping 889 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1086 | 1081 |
| 1087 // Same for chrome://thumb/ resources. | 1082 // Same for chrome://thumb/ resources. |
| 1088 if (extensions::PermissionsData::HasHostPermission( | 1083 if (extensions::PermissionsData::HasHostPermission( |
| 1089 extension, GURL(chrome::kChromeUIThumbnailURL))) { | 1084 extension, GURL(chrome::kChromeUIThumbnailURL))) { |
| 1090 ThumbnailSource* thumbnail_source = new ThumbnailSource(profile_); | 1085 ThumbnailSource* thumbnail_source = new ThumbnailSource(profile_); |
| 1091 content::URLDataSource::Add(profile_, thumbnail_source); | 1086 content::URLDataSource::Add(profile_, thumbnail_source); |
| 1092 } | 1087 } |
| 1093 | 1088 |
| 1094 #if defined(ENABLE_PLUGINS) | 1089 #if defined(ENABLE_PLUGINS) |
| 1095 // TODO(mpcomplete): This ends up affecting all profiles. See crbug.com/80757. | 1090 // TODO(mpcomplete): This ends up affecting all profiles. See crbug.com/80757. |
| 1096 bool plugins_changed = false; | 1091 bool plugins_or_nacl_changed = false; |
|
not at google - send to devlin
2013/05/29 16:29:21
Without picking through the source code of all of
not at google - send to devlin
2013/05/29 16:32:09
s/ExtensionSystem/a PKS/g
Yoyo Zhou
2013/05/29 22:27:47
Yeah, it's definitely possible; it was all dumped
| |
| 1097 if (extensions::PluginInfo::HasPlugins(extension)) { | 1092 if (extensions::PluginInfo::HasPlugins(extension)) { |
| 1098 const extensions::PluginInfo::PluginVector* plugins = | 1093 const extensions::PluginInfo::PluginVector* plugins = |
| 1099 extensions::PluginInfo::GetPlugins(extension); | 1094 extensions::PluginInfo::GetPlugins(extension); |
| 1100 CHECK(plugins); | 1095 CHECK(plugins); |
| 1101 plugins_changed = true; | 1096 plugins_or_nacl_changed = true; |
| 1102 for (extensions::PluginInfo::PluginVector::const_iterator plugin = | 1097 for (extensions::PluginInfo::PluginVector::const_iterator plugin = |
| 1103 plugins->begin(); | 1098 plugins->begin(); |
| 1104 plugin != plugins->end(); ++plugin) { | 1099 plugin != plugins->end(); ++plugin) { |
| 1105 PluginService::GetInstance()->RefreshPlugins(); | 1100 PluginService::GetInstance()->RefreshPlugins(); |
| 1106 PluginService::GetInstance()->AddExtraPluginPath(plugin->path); | 1101 PluginService::GetInstance()->AddExtraPluginPath(plugin->path); |
| 1107 ChromePluginServiceFilter* filter = | 1102 ChromePluginServiceFilter* filter = |
| 1108 ChromePluginServiceFilter::GetInstance(); | 1103 ChromePluginServiceFilter::GetInstance(); |
| 1109 if (plugin->is_public) { | 1104 if (plugin->is_public) { |
| 1110 filter->RestrictPluginToProfileAndOrigin( | 1105 filter->RestrictPluginToProfileAndOrigin( |
| 1111 plugin->path, profile_, GURL()); | 1106 plugin->path, profile_, GURL()); |
| 1112 } else { | 1107 } else { |
| 1113 filter->RestrictPluginToProfileAndOrigin( | 1108 filter->RestrictPluginToProfileAndOrigin( |
| 1114 plugin->path, profile_, extension->url()); | 1109 plugin->path, profile_, extension->url()); |
| 1115 } | 1110 } |
| 1116 } | 1111 } |
| 1117 } | 1112 } |
| 1118 | 1113 |
| 1119 bool nacl_modules_changed = false; | 1114 const NaClModuleInfo::List* nacl_modules = |
| 1120 for (size_t i = 0; i < extension->nacl_modules().size(); ++i) { | 1115 NaClModuleInfo::GetNaClModules(extension); |
| 1121 const Extension::NaClModuleInfo& module = extension->nacl_modules()[i]; | 1116 if (nacl_modules) { |
| 1122 RegisterNaClModule(module.url, module.mime_type); | 1117 plugins_or_nacl_changed = true; |
| 1123 nacl_modules_changed = true; | 1118 for (NaClModuleInfo::List::const_iterator module = nacl_modules->begin(); |
| 1119 module != nacl_modules->end(); ++module) { | |
| 1120 RegisterNaClModule(*module); | |
| 1121 } | |
| 1122 UpdatePluginListWithNaClModules(); | |
| 1124 } | 1123 } |
| 1125 | 1124 |
| 1126 if (nacl_modules_changed) | 1125 if (plugins_or_nacl_changed) |
| 1127 UpdatePluginListWithNaClModules(); | |
| 1128 | |
| 1129 if (plugins_changed || nacl_modules_changed) | |
| 1130 PluginService::GetInstance()->PurgePluginListCache(profile_, false); | 1126 PluginService::GetInstance()->PurgePluginListCache(profile_, false); |
| 1131 #endif // defined(ENABLE_PLUGINS) | 1127 #endif // defined(ENABLE_PLUGINS) |
| 1132 } | 1128 } |
| 1133 | 1129 |
| 1134 void ExtensionService::NotifyExtensionUnloaded( | 1130 void ExtensionService::NotifyExtensionUnloaded( |
| 1135 const Extension* extension, | 1131 const Extension* extension, |
| 1136 extension_misc::UnloadedExtensionReason reason) { | 1132 extension_misc::UnloadedExtensionReason reason) { |
| 1137 UnloadedExtensionInfo details(extension, reason); | 1133 UnloadedExtensionInfo details(extension, reason); |
| 1138 content::NotificationService::current()->Notify( | 1134 content::NotificationService::current()->Notify( |
| 1139 chrome::NOTIFICATION_EXTENSION_UNLOADED, | 1135 chrome::NOTIFICATION_EXTENSION_UNLOADED, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1175 GetFileSystemContext(); | 1171 GetFileSystemContext(); |
| 1176 if (filesystem_context && filesystem_context->external_provider()) { | 1172 if (filesystem_context && filesystem_context->external_provider()) { |
| 1177 filesystem_context->external_provider()-> | 1173 filesystem_context->external_provider()-> |
| 1178 RevokeAccessForExtension(extension->id()); | 1174 RevokeAccessForExtension(extension->id()); |
| 1179 } | 1175 } |
| 1180 #endif | 1176 #endif |
| 1181 | 1177 |
| 1182 UpdateActiveExtensionsInCrashReporter(); | 1178 UpdateActiveExtensionsInCrashReporter(); |
| 1183 | 1179 |
| 1184 #if defined(ENABLE_PLUGINS) | 1180 #if defined(ENABLE_PLUGINS) |
| 1185 bool plugins_changed = false; | 1181 bool plugins_or_nacl_changed = false; |
| 1186 if (extensions::PluginInfo::HasPlugins(extension)) { | 1182 if (extensions::PluginInfo::HasPlugins(extension)) { |
| 1187 const extensions::PluginInfo::PluginVector* plugins = | 1183 const extensions::PluginInfo::PluginVector* plugins = |
| 1188 extensions::PluginInfo::GetPlugins(extension); | 1184 extensions::PluginInfo::GetPlugins(extension); |
| 1189 plugins_changed = true; | 1185 plugins_or_nacl_changed = true; |
| 1190 for (extensions::PluginInfo::PluginVector::const_iterator plugin = | 1186 for (extensions::PluginInfo::PluginVector::const_iterator plugin = |
| 1191 plugins->begin(); | 1187 plugins->begin(); |
| 1192 plugin != plugins->end(); ++plugin) { | 1188 plugin != plugins->end(); ++plugin) { |
| 1193 PluginService::GetInstance()->ForcePluginShutdown(plugin->path); | 1189 PluginService::GetInstance()->ForcePluginShutdown(plugin->path); |
| 1194 PluginService::GetInstance()->RefreshPlugins(); | 1190 PluginService::GetInstance()->RefreshPlugins(); |
| 1195 PluginService::GetInstance()->RemoveExtraPluginPath(plugin->path); | 1191 PluginService::GetInstance()->RemoveExtraPluginPath(plugin->path); |
| 1196 ChromePluginServiceFilter::GetInstance()->UnrestrictPlugin(plugin->path); | 1192 ChromePluginServiceFilter::GetInstance()->UnrestrictPlugin(plugin->path); |
| 1197 } | 1193 } |
| 1198 } | 1194 } |
| 1199 | 1195 |
| 1200 bool nacl_modules_changed = false; | 1196 const NaClModuleInfo::List* nacl_modules = |
| 1201 for (size_t i = 0; i < extension->nacl_modules().size(); ++i) { | 1197 NaClModuleInfo::GetNaClModules(extension); |
| 1202 const Extension::NaClModuleInfo& module = extension->nacl_modules()[i]; | 1198 if (nacl_modules) { |
| 1203 UnregisterNaClModule(module.url); | 1199 plugins_or_nacl_changed = true; |
| 1204 nacl_modules_changed = true; | 1200 for (NaClModuleInfo::List::const_iterator module = nacl_modules->begin(); |
| 1201 module != nacl_modules->end(); ++module) { | |
| 1202 UnregisterNaClModule(*module); | |
| 1203 } | |
| 1204 UpdatePluginListWithNaClModules(); | |
| 1205 } | 1205 } |
| 1206 | 1206 |
| 1207 if (nacl_modules_changed) | 1207 if (plugins_or_nacl_changed) |
| 1208 UpdatePluginListWithNaClModules(); | |
| 1209 | |
| 1210 if (plugins_changed || nacl_modules_changed) | |
| 1211 PluginService::GetInstance()->PurgePluginListCache(profile_, false); | 1208 PluginService::GetInstance()->PurgePluginListCache(profile_, false); |
| 1212 #endif // defined(ENABLE_PLUGINS) | 1209 #endif // defined(ENABLE_PLUGINS) |
| 1213 } | 1210 } |
| 1214 | 1211 |
| 1215 Profile* ExtensionService::profile() { | 1212 Profile* ExtensionService::profile() { |
| 1216 return profile_; | 1213 return profile_; |
| 1217 } | 1214 } |
| 1218 | 1215 |
| 1219 extensions::ExtensionPrefs* ExtensionService::extension_prefs() { | 1216 extensions::ExtensionPrefs* ExtensionService::extension_prefs() { |
| 1220 return extension_prefs_; | 1217 return extension_prefs_; |
| (...skipping 1592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2813 extension_runtime_data_.find(extension->id()); | 2810 extension_runtime_data_.find(extension->id()); |
| 2814 return it == extension_runtime_data_.end() ? false : | 2811 return it == extension_runtime_data_.end() ? false : |
| 2815 it->second.has_used_webrequest; | 2812 it->second.has_used_webrequest; |
| 2816 } | 2813 } |
| 2817 | 2814 |
| 2818 void ExtensionService::SetHasUsedWebRequest(const Extension* extension, | 2815 void ExtensionService::SetHasUsedWebRequest(const Extension* extension, |
| 2819 bool value) { | 2816 bool value) { |
| 2820 extension_runtime_data_[extension->id()].has_used_webrequest = value; | 2817 extension_runtime_data_[extension->id()].has_used_webrequest = value; |
| 2821 } | 2818 } |
| 2822 | 2819 |
| 2823 void ExtensionService::RegisterNaClModule(const GURL& url, | 2820 void ExtensionService::RegisterNaClModule(const NaClModuleInfo& info) { |
| 2824 const std::string& mime_type) { | 2821 DCHECK(FindNaClModule(info.url) == nacl_module_list_.end()); |
| 2825 NaClModuleInfo info; | |
| 2826 info.url = url; | |
| 2827 info.mime_type = mime_type; | |
| 2828 | |
| 2829 DCHECK(FindNaClModule(url) == nacl_module_list_.end()); | |
| 2830 nacl_module_list_.push_front(info); | 2822 nacl_module_list_.push_front(info); |
| 2831 } | 2823 } |
| 2832 | 2824 |
| 2833 void ExtensionService::UnregisterNaClModule(const GURL& url) { | 2825 void ExtensionService::UnregisterNaClModule(const NaClModuleInfo& info) { |
| 2834 NaClModuleInfoList::iterator iter = FindNaClModule(url); | 2826 NaClModuleInfo::List::iterator iter = FindNaClModule(info.url); |
| 2835 DCHECK(iter != nacl_module_list_.end()); | 2827 DCHECK(iter != nacl_module_list_.end()); |
| 2836 nacl_module_list_.erase(iter); | 2828 nacl_module_list_.erase(iter); |
| 2837 } | 2829 } |
| 2838 | 2830 |
| 2839 void ExtensionService::UpdatePluginListWithNaClModules() { | 2831 void ExtensionService::UpdatePluginListWithNaClModules() { |
| 2840 // An extension has been added which has a nacl_module component, which means | 2832 // An extension has been added which has a nacl_module component, which means |
| 2841 // there is a MIME type that module wants to handle, so we need to add that | 2833 // there is a MIME type that module wants to handle, so we need to add that |
| 2842 // MIME type to plugins which handle NaCl modules in order to allow the | 2834 // MIME type to plugins which handle NaCl modules in order to allow the |
| 2843 // individual modules to handle these types. | 2835 // individual modules to handle these types. |
| 2844 base::FilePath path; | 2836 base::FilePath path; |
| 2845 if (!PathService::Get(chrome::FILE_NACL_PLUGIN, &path)) | 2837 if (!PathService::Get(chrome::FILE_NACL_PLUGIN, &path)) |
| 2846 return; | 2838 return; |
| 2847 const content::PepperPluginInfo* pepper_info = | 2839 const content::PepperPluginInfo* pepper_info = |
| 2848 PluginService::GetInstance()->GetRegisteredPpapiPluginInfo(path); | 2840 PluginService::GetInstance()->GetRegisteredPpapiPluginInfo(path); |
| 2849 if (!pepper_info) | 2841 if (!pepper_info) |
| 2850 return; | 2842 return; |
| 2851 | 2843 |
| 2852 std::vector<webkit::WebPluginMimeType>::const_iterator mime_iter; | 2844 std::vector<webkit::WebPluginMimeType>::const_iterator mime_iter; |
| 2853 // Check each MIME type the plugins handle for the NaCl MIME type. | 2845 // Check each MIME type the plugins handle for the NaCl MIME type. |
| 2854 for (mime_iter = pepper_info->mime_types.begin(); | 2846 for (mime_iter = pepper_info->mime_types.begin(); |
| 2855 mime_iter != pepper_info->mime_types.end(); ++mime_iter) { | 2847 mime_iter != pepper_info->mime_types.end(); ++mime_iter) { |
| 2856 if (mime_iter->mime_type == kNaClPluginMimeType) { | 2848 if (mime_iter->mime_type == kNaClPluginMimeType) { |
| 2857 // This plugin handles "application/x-nacl". | 2849 // This plugin handles "application/x-nacl". |
| 2858 | 2850 |
| 2859 PluginService::GetInstance()-> | 2851 PluginService::GetInstance()-> |
| 2860 UnregisterInternalPlugin(pepper_info->path); | 2852 UnregisterInternalPlugin(pepper_info->path); |
| 2861 | 2853 |
| 2862 webkit::WebPluginInfo info = pepper_info->ToWebPluginInfo(); | 2854 webkit::WebPluginInfo info = pepper_info->ToWebPluginInfo(); |
| 2863 | 2855 |
| 2864 for (ExtensionService::NaClModuleInfoList::const_iterator iter = | 2856 for (NaClModuleInfo::List::const_iterator iter = |
| 2865 nacl_module_list_.begin(); | 2857 nacl_module_list_.begin(); |
| 2866 iter != nacl_module_list_.end(); ++iter) { | 2858 iter != nacl_module_list_.end(); ++iter) { |
| 2867 // Add the MIME type specified in the extension to this NaCl plugin, | 2859 // Add the MIME type specified in the extension to this NaCl plugin, |
| 2868 // With an extra "nacl" argument to specify the location of the NaCl | 2860 // With an extra "nacl" argument to specify the location of the NaCl |
| 2869 // manifest file. | 2861 // manifest file. |
| 2870 webkit::WebPluginMimeType mime_type_info; | 2862 webkit::WebPluginMimeType mime_type_info; |
| 2871 mime_type_info.mime_type = iter->mime_type; | 2863 mime_type_info.mime_type = iter->mime_type; |
| 2872 mime_type_info.additional_param_names.push_back(UTF8ToUTF16("nacl")); | 2864 mime_type_info.additional_param_names.push_back(UTF8ToUTF16("nacl")); |
| 2873 mime_type_info.additional_param_values.push_back( | 2865 mime_type_info.additional_param_values.push_back( |
| 2874 UTF8ToUTF16(iter->url.spec())); | 2866 UTF8ToUTF16(iter->url.spec())); |
| 2875 info.mime_types.push_back(mime_type_info); | 2867 info.mime_types.push_back(mime_type_info); |
| 2876 } | 2868 } |
| 2877 | 2869 |
| 2878 PluginService::GetInstance()->RefreshPlugins(); | 2870 PluginService::GetInstance()->RefreshPlugins(); |
| 2879 PluginService::GetInstance()->RegisterInternalPlugin(info, true); | 2871 PluginService::GetInstance()->RegisterInternalPlugin(info, true); |
| 2880 // This plugin has been modified, no need to check the rest of its | 2872 // This plugin has been modified, no need to check the rest of its |
| 2881 // types, but continue checking other plugins. | 2873 // types, but continue checking other plugins. |
| 2882 break; | 2874 break; |
| 2883 } | 2875 } |
| 2884 } | 2876 } |
| 2885 } | 2877 } |
| 2886 | 2878 |
| 2887 ExtensionService::NaClModuleInfoList::iterator | 2879 NaClModuleInfo::List::iterator |
| 2888 ExtensionService::FindNaClModule(const GURL& url) { | 2880 ExtensionService::FindNaClModule(const GURL& url) { |
| 2889 for (NaClModuleInfoList::iterator iter = nacl_module_list_.begin(); | 2881 for (NaClModuleInfo::List::iterator iter = nacl_module_list_.begin(); |
| 2890 iter != nacl_module_list_.end(); ++iter) { | 2882 iter != nacl_module_list_.end(); ++iter) { |
| 2891 if (iter->url == url) | 2883 if (iter->url == url) |
| 2892 return iter; | 2884 return iter; |
| 2893 } | 2885 } |
| 2894 return nacl_module_list_.end(); | 2886 return nacl_module_list_.end(); |
| 2895 } | 2887 } |
| 2896 | 2888 |
| 2897 void ExtensionService::DoPostLoadTasks(const Extension* extension) { | 2889 void ExtensionService::DoPostLoadTasks(const Extension* extension) { |
| 2898 std::map<std::string, int>::iterator it = | 2890 std::map<std::string, int>::iterator it = |
| 2899 on_load_events_.find(extension->id()); | 2891 on_load_events_.find(extension->id()); |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3106 } | 3098 } |
| 3107 | 3099 |
| 3108 void ExtensionService::AddUpdateObserver(extensions::UpdateObserver* observer) { | 3100 void ExtensionService::AddUpdateObserver(extensions::UpdateObserver* observer) { |
| 3109 update_observers_.AddObserver(observer); | 3101 update_observers_.AddObserver(observer); |
| 3110 } | 3102 } |
| 3111 | 3103 |
| 3112 void ExtensionService::RemoveUpdateObserver( | 3104 void ExtensionService::RemoveUpdateObserver( |
| 3113 extensions::UpdateObserver* observer) { | 3105 extensions::UpdateObserver* observer) { |
| 3114 update_observers_.RemoveObserver(observer); | 3106 update_observers_.RemoveObserver(observer); |
| 3115 } | 3107 } |
| OLD | NEW |