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" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
| 14 #include "base/path_service.h" |
14 #include "base/stl_util-inl.h" | 15 #include "base/stl_util-inl.h" |
15 #include "base/string16.h" | 16 #include "base/string16.h" |
16 #include "base/string_number_conversions.h" | 17 #include "base/string_number_conversions.h" |
17 #include "base/string_util.h" | 18 #include "base/string_util.h" |
18 #include "base/stringprintf.h" | 19 #include "base/stringprintf.h" |
19 #include "base/threading/thread_restrictions.h" | 20 #include "base/threading/thread_restrictions.h" |
20 #include "base/time.h" | 21 #include "base/time.h" |
21 #include "base/utf_string_conversions.h" | 22 #include "base/utf_string_conversions.h" |
22 #include "base/values.h" | 23 #include "base/values.h" |
23 #include "base/version.h" | 24 #include "base/version.h" |
(...skipping 22 matching lines...) Expand all Loading... |
46 #include "chrome/browser/extensions/external_extension_provider_interface.h" | 47 #include "chrome/browser/extensions/external_extension_provider_interface.h" |
47 #include "chrome/browser/extensions/pending_extension_manager.h" | 48 #include "chrome/browser/extensions/pending_extension_manager.h" |
48 #include "chrome/browser/net/chrome_url_request_context.h" | 49 #include "chrome/browser/net/chrome_url_request_context.h" |
49 #include "chrome/browser/prefs/pref_service.h" | 50 #include "chrome/browser/prefs/pref_service.h" |
50 #include "chrome/browser/profiles/profile.h" | 51 #include "chrome/browser/profiles/profile.h" |
51 #include "chrome/browser/search_engines/template_url_model.h" | 52 #include "chrome/browser/search_engines/template_url_model.h" |
52 #include "chrome/browser/themes/theme_service.h" | 53 #include "chrome/browser/themes/theme_service.h" |
53 #include "chrome/browser/themes/theme_service_factory.h" | 54 #include "chrome/browser/themes/theme_service_factory.h" |
54 #include "chrome/browser/ui/webui/shown_sections_handler.h" | 55 #include "chrome/browser/ui/webui/shown_sections_handler.h" |
55 #include "chrome/common/child_process_logging.h" | 56 #include "chrome/common/child_process_logging.h" |
| 57 #include "chrome/common/chrome_paths.h" |
56 #include "chrome/common/chrome_switches.h" | 58 #include "chrome/common/chrome_switches.h" |
57 #include "chrome/common/extensions/extension.h" | 59 #include "chrome/common/extensions/extension.h" |
58 #include "chrome/common/extensions/extension_constants.h" | 60 #include "chrome/common/extensions/extension_constants.h" |
59 #include "chrome/common/extensions/extension_error_utils.h" | 61 #include "chrome/common/extensions/extension_error_utils.h" |
60 #include "chrome/common/extensions/extension_file_util.h" | 62 #include "chrome/common/extensions/extension_file_util.h" |
61 #include "chrome/common/extensions/extension_l10n_util.h" | 63 #include "chrome/common/extensions/extension_l10n_util.h" |
62 #include "chrome/common/extensions/extension_resource.h" | 64 #include "chrome/common/extensions/extension_resource.h" |
63 #include "chrome/common/pepper_plugin_registry.h" | |
64 #include "chrome/common/pref_names.h" | 65 #include "chrome/common/pref_names.h" |
65 #include "chrome/common/url_constants.h" | 66 #include "chrome/common/url_constants.h" |
66 #include "content/browser/browser_thread.h" | 67 #include "content/browser/browser_thread.h" |
67 #include "content/browser/plugin_process_host.h" | 68 #include "content/browser/plugin_process_host.h" |
68 #include "content/browser/plugin_service.h" | 69 #include "content/browser/plugin_service.h" |
69 #include "content/common/json_value_serializer.h" | 70 #include "content/common/json_value_serializer.h" |
70 #include "content/common/notification_service.h" | 71 #include "content/common/notification_service.h" |
71 #include "content/common/notification_type.h" | 72 #include "content/common/notification_type.h" |
| 73 #include "content/common/pepper_plugin_registry.h" |
72 #include "googleurl/src/gurl.h" | 74 #include "googleurl/src/gurl.h" |
73 #include "net/base/registry_controlled_domain.h" | 75 #include "net/base/registry_controlled_domain.h" |
74 #include "webkit/database/database_tracker.h" | 76 #include "webkit/database/database_tracker.h" |
75 #include "webkit/database/database_util.h" | 77 #include "webkit/database/database_util.h" |
76 #include "webkit/plugins/npapi/plugin_list.h" | 78 #include "webkit/plugins/npapi/plugin_list.h" |
77 | 79 |
78 #if defined(OS_CHROMEOS) | 80 #if defined(OS_CHROMEOS) |
79 #include "chrome/browser/chromeos/extensions/file_browser_event_router.h" | 81 #include "chrome/browser/chromeos/extensions/file_browser_event_router.h" |
80 #include "webkit/fileapi/file_system_context.h" | 82 #include "webkit/fileapi/file_system_context.h" |
81 #include "webkit/fileapi/file_system_mount_point_provider.h" | 83 #include "webkit/fileapi/file_system_mount_point_provider.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 } // namespace | 134 } // namespace |
133 | 135 |
134 ExtensionService::ExtensionRuntimeData::ExtensionRuntimeData() | 136 ExtensionService::ExtensionRuntimeData::ExtensionRuntimeData() |
135 : background_page_ready(false), | 137 : background_page_ready(false), |
136 being_upgraded(false) { | 138 being_upgraded(false) { |
137 } | 139 } |
138 | 140 |
139 ExtensionService::ExtensionRuntimeData::~ExtensionRuntimeData() { | 141 ExtensionService::ExtensionRuntimeData::~ExtensionRuntimeData() { |
140 } | 142 } |
141 | 143 |
| 144 ExtensionService::NaClModuleInfo::NaClModuleInfo() { |
| 145 } |
| 146 |
| 147 ExtensionService::NaClModuleInfo::~NaClModuleInfo() { |
| 148 } |
| 149 |
142 // ExtensionService. | 150 // ExtensionService. |
143 | 151 |
144 const char* ExtensionService::kInstallDirectoryName = "Extensions"; | 152 const char* ExtensionService::kInstallDirectoryName = "Extensions"; |
145 const char* ExtensionService::kCurrentVersionFileName = "Current Version"; | 153 const char* ExtensionService::kCurrentVersionFileName = "Current Version"; |
146 | 154 |
147 // Implements IO for the ExtensionService. | 155 // Implements IO for the ExtensionService. |
148 | 156 |
149 class ExtensionServiceBackend | 157 class ExtensionServiceBackend |
150 : public base::RefCountedThreadSafe<ExtensionServiceBackend> { | 158 : public base::RefCountedThreadSafe<ExtensionServiceBackend> { |
151 public: | 159 public: |
(...skipping 902 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1054 plugins_changed = true; | 1062 plugins_changed = true; |
1055 if (!plugin.is_public) { | 1063 if (!plugin.is_public) { |
1056 PluginService::GetInstance()->RestrictPluginToUrl( | 1064 PluginService::GetInstance()->RestrictPluginToUrl( |
1057 plugin.path, extension->url()); | 1065 plugin.path, extension->url()); |
1058 } | 1066 } |
1059 } | 1067 } |
1060 | 1068 |
1061 bool nacl_modules_changed = false; | 1069 bool nacl_modules_changed = false; |
1062 for (size_t i = 0; i < extension->nacl_modules().size(); ++i) { | 1070 for (size_t i = 0; i < extension->nacl_modules().size(); ++i) { |
1063 const Extension::NaClModuleInfo& module = extension->nacl_modules()[i]; | 1071 const Extension::NaClModuleInfo& module = extension->nacl_modules()[i]; |
1064 PepperPluginRegistry::GetInstance()->RegisterNaClModule(module.url, | 1072 RegisterNaClModule(module.url, module.mime_type); |
1065 module.mime_type); | |
1066 nacl_modules_changed = true; | 1073 nacl_modules_changed = true; |
1067 } | 1074 } |
1068 | 1075 |
1069 if (nacl_modules_changed) | 1076 if (nacl_modules_changed) |
1070 PepperPluginRegistry::GetInstance()->UpdatePluginListWithNaClModules(); | 1077 UpdatePluginListWithNaClModules(); |
1071 | 1078 |
1072 if (plugins_changed || nacl_modules_changed) | 1079 if (plugins_changed || nacl_modules_changed) |
1073 PluginService::GetInstance()->PurgePluginListCache(false); | 1080 PluginService::GetInstance()->PurgePluginListCache(false); |
1074 } | 1081 } |
1075 | 1082 |
1076 void ExtensionService::NotifyExtensionUnloaded( | 1083 void ExtensionService::NotifyExtensionUnloaded( |
1077 const Extension* extension, UnloadedExtensionInfo::Reason reason) { | 1084 const Extension* extension, UnloadedExtensionInfo::Reason reason) { |
1078 UnloadedExtensionInfo details(extension, reason); | 1085 UnloadedExtensionInfo details(extension, reason); |
1079 NotificationService::current()->Notify( | 1086 NotificationService::current()->Notify( |
1080 NotificationType::EXTENSION_UNLOADED, | 1087 NotificationType::EXTENSION_UNLOADED, |
(...skipping 25 matching lines...) Expand all Loading... |
1106 webkit::npapi::PluginList::Singleton()->RemoveExtraPluginPath( | 1113 webkit::npapi::PluginList::Singleton()->RemoveExtraPluginPath( |
1107 plugin.path); | 1114 plugin.path); |
1108 plugins_changed = true; | 1115 plugins_changed = true; |
1109 if (!plugin.is_public) | 1116 if (!plugin.is_public) |
1110 PluginService::GetInstance()->RestrictPluginToUrl(plugin.path, GURL()); | 1117 PluginService::GetInstance()->RestrictPluginToUrl(plugin.path, GURL()); |
1111 } | 1118 } |
1112 | 1119 |
1113 bool nacl_modules_changed = false; | 1120 bool nacl_modules_changed = false; |
1114 for (size_t i = 0; i < extension->nacl_modules().size(); ++i) { | 1121 for (size_t i = 0; i < extension->nacl_modules().size(); ++i) { |
1115 const Extension::NaClModuleInfo& module = extension->nacl_modules()[i]; | 1122 const Extension::NaClModuleInfo& module = extension->nacl_modules()[i]; |
1116 PepperPluginRegistry::GetInstance()->UnregisterNaClModule(module.url); | 1123 UnregisterNaClModule(module.url); |
1117 nacl_modules_changed = true; | 1124 nacl_modules_changed = true; |
1118 } | 1125 } |
1119 | 1126 |
1120 if (nacl_modules_changed) | 1127 if (nacl_modules_changed) |
1121 PepperPluginRegistry::GetInstance()->UpdatePluginListWithNaClModules(); | 1128 UpdatePluginListWithNaClModules(); |
1122 | 1129 |
1123 if (plugins_changed || nacl_modules_changed) | 1130 if (plugins_changed || nacl_modules_changed) |
1124 PluginService::GetInstance()->PurgePluginListCache(false); | 1131 PluginService::GetInstance()->PurgePluginListCache(false); |
1125 } | 1132 } |
1126 | 1133 |
1127 void ExtensionService::UpdateExtensionBlacklist( | 1134 void ExtensionService::UpdateExtensionBlacklist( |
1128 const std::vector<std::string>& blacklist) { | 1135 const std::vector<std::string>& blacklist) { |
1129 // Use this set to indicate if an extension in the blacklist has been used. | 1136 // Use this set to indicate if an extension in the blacklist has been used. |
1130 std::set<std::string> blacklist_set; | 1137 std::set<std::string> blacklist_set; |
1131 for (unsigned int i = 0; i < blacklist.size(); ++i) { | 1138 for (unsigned int i = 0; i < blacklist.size(); ++i) { |
(...skipping 845 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1977 } | 1984 } |
1978 | 1985 |
1979 void ExtensionService::SetBeingUpgraded(const Extension* extension, | 1986 void ExtensionService::SetBeingUpgraded(const Extension* extension, |
1980 bool value) { | 1987 bool value) { |
1981 extension_runtime_data_[extension->id()].being_upgraded = value; | 1988 extension_runtime_data_[extension->id()].being_upgraded = value; |
1982 } | 1989 } |
1983 | 1990 |
1984 PropertyBag* ExtensionService::GetPropertyBag(const Extension* extension) { | 1991 PropertyBag* ExtensionService::GetPropertyBag(const Extension* extension) { |
1985 return &extension_runtime_data_[extension->id()].property_bag; | 1992 return &extension_runtime_data_[extension->id()].property_bag; |
1986 } | 1993 } |
| 1994 |
| 1995 void ExtensionService::RegisterNaClModule(const GURL& url, |
| 1996 const std::string& mime_type) { |
| 1997 NaClModuleInfo info; |
| 1998 info.url = url; |
| 1999 info.mime_type = mime_type; |
| 2000 |
| 2001 DCHECK(FindNaClModule(url) == nacl_module_list_.end()); |
| 2002 nacl_module_list_.push_front(info); |
| 2003 } |
| 2004 |
| 2005 void ExtensionService::UnregisterNaClModule(const GURL& url) { |
| 2006 NaClModuleInfoList::iterator iter = FindNaClModule(url); |
| 2007 DCHECK(iter != nacl_module_list_.end()); |
| 2008 nacl_module_list_.erase(iter); |
| 2009 } |
| 2010 |
| 2011 void ExtensionService::UpdatePluginListWithNaClModules() { |
| 2012 FilePath path; |
| 2013 PathService::Get(chrome::FILE_NACL_PLUGIN, &path); |
| 2014 |
| 2015 webkit::npapi::PluginList::Singleton()->UnregisterInternalPlugin(path); |
| 2016 |
| 2017 const PepperPluginInfo* pepper_info = |
| 2018 PepperPluginRegistry::GetInstance()->GetInfoForPlugin(path); |
| 2019 webkit::npapi::WebPluginInfo info = pepper_info->ToWebPluginInfo(); |
| 2020 |
| 2021 DCHECK(nacl_module_list_.size() <= 1); |
| 2022 for (NaClModuleInfoList::iterator iter = nacl_module_list_.begin(); |
| 2023 iter != nacl_module_list_.end(); ++iter) { |
| 2024 webkit::npapi::WebPluginMimeType mime_type_info; |
| 2025 mime_type_info.mime_type = iter->mime_type; |
| 2026 mime_type_info.additional_param_names.push_back(UTF8ToUTF16("nacl")); |
| 2027 mime_type_info.additional_param_values.push_back( |
| 2028 UTF8ToUTF16(iter->url.spec())); |
| 2029 info.mime_types.push_back(mime_type_info); |
| 2030 } |
| 2031 |
| 2032 webkit::npapi::PluginList::Singleton()->RefreshPlugins(); |
| 2033 webkit::npapi::PluginList::Singleton()->RegisterInternalPlugin(info); |
| 2034 } |
| 2035 |
| 2036 ExtensionService::NaClModuleInfoList::iterator |
| 2037 ExtensionService::FindNaClModule(const GURL& url) { |
| 2038 for (NaClModuleInfoList::iterator iter = nacl_module_list_.begin(); |
| 2039 iter != nacl_module_list_.end(); ++iter) { |
| 2040 if (iter->url == url) |
| 2041 return iter; |
| 2042 } |
| 2043 return nacl_module_list_.end(); |
| 2044 } |
OLD | NEW |