| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "base/files/file_path.h" | 5 #include "base/files/file_path.h" |
| 6 #include "base/lazy_instance.h" | 6 #include "base/lazy_instance.h" |
| 7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/extensions/extension_service.h" |
| 9 #include "chrome/browser/extensions/plugin_manager.h" | 10 #include "chrome/browser/extensions/plugin_manager.h" |
| 10 #include "chrome/browser/plugins/chrome_plugin_service_filter.h" | 11 #include "chrome/browser/plugins/chrome_plugin_service_filter.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/common/chrome_paths.h" | 13 #include "chrome/common/chrome_paths.h" |
| 13 #include "chrome/common/extensions/api/plugins/plugins_handler.h" | 14 #include "chrome/common/extensions/api/plugins/plugins_handler.h" |
| 15 #include "chrome/common/extensions/mime_types_handler.h" |
| 14 #include "content/public/browser/plugin_service.h" | 16 #include "content/public/browser/plugin_service.h" |
| 15 #include "content/public/common/pepper_plugin_info.h" | 17 #include "content/public/common/pepper_plugin_info.h" |
| 16 #include "extensions/browser/extension_registry.h" | 18 #include "extensions/browser/extension_registry.h" |
| 17 #include "extensions/common/extension.h" | 19 #include "extensions/common/extension.h" |
| 18 #include "url/gurl.h" | 20 #include "url/gurl.h" |
| 19 | 21 |
| 20 using content::PluginService; | 22 using content::PluginService; |
| 21 | 23 |
| 22 static const char kNaClPluginMimeType[] = "application/x-nacl"; | 24 static const char kNaClPluginMimeType[] = "application/x-nacl"; |
| 23 | 25 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 if (nacl_modules) { | 72 if (nacl_modules) { |
| 71 plugins_or_nacl_changed = true; | 73 plugins_or_nacl_changed = true; |
| 72 for (NaClModuleInfo::List::const_iterator module = nacl_modules->begin(); | 74 for (NaClModuleInfo::List::const_iterator module = nacl_modules->begin(); |
| 73 module != nacl_modules->end(); | 75 module != nacl_modules->end(); |
| 74 ++module) { | 76 ++module) { |
| 75 RegisterNaClModule(*module); | 77 RegisterNaClModule(*module); |
| 76 } | 78 } |
| 77 UpdatePluginListWithNaClModules(); | 79 UpdatePluginListWithNaClModules(); |
| 78 } | 80 } |
| 79 | 81 |
| 82 const MimeTypesHandler* handler = MimeTypesHandler::GetHandler(extension); |
| 83 if (handler) { |
| 84 plugins_or_nacl_changed = true; |
| 85 RegisterMimeTypeHandler(handler->extension_id()); |
| 86 UpdatePluginListWithNaClModules(); |
| 87 } |
| 88 |
| 80 if (plugins_or_nacl_changed) | 89 if (plugins_or_nacl_changed) |
| 81 PluginService::GetInstance()->PurgePluginListCache(profile_, false); | 90 PluginService::GetInstance()->PurgePluginListCache(profile_, false); |
| 82 } | 91 } |
| 83 | 92 |
| 84 void PluginManager::OnExtensionUnloaded( | 93 void PluginManager::OnExtensionUnloaded( |
| 85 content::BrowserContext* browser_context, | 94 content::BrowserContext* browser_context, |
| 86 const Extension* extension, | 95 const Extension* extension, |
| 87 UnloadedExtensionInfo::Reason reason) { | 96 UnloadedExtensionInfo::Reason reason) { |
| 88 bool plugins_or_nacl_changed = false; | 97 bool plugins_or_nacl_changed = false; |
| 89 if (PluginInfo::HasPlugins(extension)) { | 98 if (PluginInfo::HasPlugins(extension)) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 104 if (nacl_modules) { | 113 if (nacl_modules) { |
| 105 plugins_or_nacl_changed = true; | 114 plugins_or_nacl_changed = true; |
| 106 for (NaClModuleInfo::List::const_iterator module = nacl_modules->begin(); | 115 for (NaClModuleInfo::List::const_iterator module = nacl_modules->begin(); |
| 107 module != nacl_modules->end(); | 116 module != nacl_modules->end(); |
| 108 ++module) { | 117 ++module) { |
| 109 UnregisterNaClModule(*module); | 118 UnregisterNaClModule(*module); |
| 110 } | 119 } |
| 111 UpdatePluginListWithNaClModules(); | 120 UpdatePluginListWithNaClModules(); |
| 112 } | 121 } |
| 113 | 122 |
| 123 const MimeTypesHandler* handler = MimeTypesHandler::GetHandler(extension); |
| 124 if (handler) { |
| 125 plugins_or_nacl_changed = true; |
| 126 UnregisterMimeTypeHandler(handler->extension_id()); |
| 127 } |
| 128 |
| 114 if (plugins_or_nacl_changed) | 129 if (plugins_or_nacl_changed) |
| 115 PluginService::GetInstance()->PurgePluginListCache(profile_, false); | 130 PluginService::GetInstance()->PurgePluginListCache(profile_, false); |
| 116 } | 131 } |
| 117 | 132 |
| 118 void PluginManager::RegisterNaClModule(const NaClModuleInfo& info) { | 133 void PluginManager::RegisterNaClModule(const NaClModuleInfo& info) { |
| 119 DCHECK(FindNaClModule(info.url) == nacl_module_list_.end()); | 134 DCHECK(FindNaClModule(info.url) == nacl_module_list_.end()); |
| 120 nacl_module_list_.push_front(info); | 135 nacl_module_list_.push_front(info); |
| 121 } | 136 } |
| 122 | 137 |
| 123 void PluginManager::UnregisterNaClModule(const NaClModuleInfo& info) { | 138 void PluginManager::UnregisterNaClModule(const NaClModuleInfo& info) { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 info.mime_types.push_back(mime_type_info); | 180 info.mime_types.push_back(mime_type_info); |
| 166 } | 181 } |
| 167 | 182 |
| 168 PluginService::GetInstance()->RefreshPlugins(); | 183 PluginService::GetInstance()->RefreshPlugins(); |
| 169 PluginService::GetInstance()->RegisterInternalPlugin(info, true); | 184 PluginService::GetInstance()->RegisterInternalPlugin(info, true); |
| 170 // This plugin has been modified, no need to check the rest of its | 185 // This plugin has been modified, no need to check the rest of its |
| 171 // types, but continue checking other plugins. | 186 // types, but continue checking other plugins. |
| 172 break; | 187 break; |
| 173 } | 188 } |
| 174 } | 189 } |
| 190 |
| 191 for (std::set<std::string>::iterator ix = mime_type_handler_.begin(); |
| 192 ix != mime_type_handler_.end(); ++ix) { |
| 193 const std::string& extension_id = *ix; |
| 194 const Extension* extension = |
| 195 profile_->GetExtensionService()->GetExtensionById(extension_id, false); |
| 196 const MimeTypesHandler* handler = MimeTypesHandler::GetHandler(extension); |
| 197 if (handler) { |
| 198 PluginService::GetInstance()->UnregisterInternalPlugin( |
| 199 base::FilePath::FromUTF8Unsafe(extension_id)); |
| 200 |
| 201 content::WebPluginInfo info; |
| 202 info.type = content::WebPluginInfo::PLUGIN_TYPE_BROWSER_PLUGIN; |
| 203 info.name = base::UTF8ToUTF16(extension_id); |
| 204 info.path = base::FilePath::FromUTF8Unsafe(extension_id); |
| 205 |
| 206 for (std::set<std::string>::const_iterator mime_type = |
| 207 handler->mime_type_set().begin(); |
| 208 mime_type != handler->mime_type_set().end(); ++mime_type) { |
| 209 content::WebPluginMimeType mime_type_info; |
| 210 mime_type_info.mime_type = *mime_type; |
| 211 info.mime_types.push_back(mime_type_info); |
| 212 } |
| 213 |
| 214 PluginService::GetInstance()->RefreshPlugins(); |
| 215 PluginService::GetInstance()->RegisterInternalPlugin(info, true); |
| 216 } |
| 217 } |
| 175 } | 218 } |
| 176 | 219 |
| 220 void PluginManager::RegisterMimeTypeHandler(const std::string& extension_id) { |
| 221 mime_type_handler_.insert(extension_id); |
| 222 } |
| 223 |
| 224 void PluginManager::UnregisterMimeTypeHandler(const std::string& extension_id) { |
| 225 mime_type_handler_.erase(extension_id); |
| 226 PluginService::GetInstance()->UnregisterInternalPlugin( |
| 227 base::FilePath::FromUTF8Unsafe(extension_id)); |
| 228 } |
| 229 |
| 177 NaClModuleInfo::List::iterator PluginManager::FindNaClModule(const GURL& url) { | 230 NaClModuleInfo::List::iterator PluginManager::FindNaClModule(const GURL& url) { |
| 178 for (NaClModuleInfo::List::iterator iter = nacl_module_list_.begin(); | 231 for (NaClModuleInfo::List::iterator iter = nacl_module_list_.begin(); |
| 179 iter != nacl_module_list_.end(); ++iter) { | 232 iter != nacl_module_list_.end(); ++iter) { |
| 180 if (iter->url == url) | 233 if (iter->url == url) |
| 181 return iter; | 234 return iter; |
| 182 } | 235 } |
| 183 return nacl_module_list_.end(); | 236 return nacl_module_list_.end(); |
| 184 } | 237 } |
| 185 | 238 |
| 186 } // namespace extensions | 239 } // namespace extensions |
| OLD | NEW |