| 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/extension_service.h" |
| 10 #include "chrome/browser/extensions/plugin_manager.h" | 10 #include "chrome/browser/extensions/plugin_manager.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 module != nacl_modules->end(); | 75 module != nacl_modules->end(); |
| 76 ++module) { | 76 ++module) { |
| 77 RegisterNaClModule(*module); | 77 RegisterNaClModule(*module); |
| 78 } | 78 } |
| 79 UpdatePluginListWithNaClModules(); | 79 UpdatePluginListWithNaClModules(); |
| 80 } | 80 } |
| 81 | 81 |
| 82 const MimeTypesHandler* handler = MimeTypesHandler::GetHandler(extension); | 82 const MimeTypesHandler* handler = MimeTypesHandler::GetHandler(extension); |
| 83 if (handler && !handler->handler_url().empty()) { | 83 if (handler && !handler->handler_url().empty()) { |
| 84 plugins_or_nacl_changed = true; | 84 plugins_or_nacl_changed = true; |
| 85 RegisterMimeTypeHandler(handler->extension_id()); | 85 |
| 86 UpdatePluginListWithNaClModules(); | 86 content::WebPluginInfo info; |
| 87 info.type = content::WebPluginInfo::PLUGIN_TYPE_BROWSER_PLUGIN; |
| 88 info.name = base::UTF8ToUTF16(handler->extension_id()); |
| 89 info.path = base::FilePath::FromUTF8Unsafe(handler->extension_id()); |
| 90 |
| 91 for (std::set<std::string>::const_iterator mime_type = |
| 92 handler->mime_type_set().begin(); |
| 93 mime_type != handler->mime_type_set().end(); ++mime_type) { |
| 94 content::WebPluginMimeType mime_type_info; |
| 95 mime_type_info.mime_type = *mime_type; |
| 96 info.mime_types.push_back(mime_type_info); |
| 97 } |
| 98 |
| 99 PluginService::GetInstance()->RefreshPlugins(); |
| 100 PluginService::GetInstance()->RegisterInternalPlugin(info, true); |
| 87 } | 101 } |
| 88 | 102 |
| 89 if (plugins_or_nacl_changed) | 103 if (plugins_or_nacl_changed) |
| 90 PluginService::GetInstance()->PurgePluginListCache(profile_, false); | 104 PluginService::GetInstance()->PurgePluginListCache(profile_, false); |
| 91 } | 105 } |
| 92 | 106 |
| 93 void PluginManager::OnExtensionUnloaded( | 107 void PluginManager::OnExtensionUnloaded( |
| 94 content::BrowserContext* browser_context, | 108 content::BrowserContext* browser_context, |
| 95 const Extension* extension, | 109 const Extension* extension, |
| 96 UnloadedExtensionInfo::Reason reason) { | 110 UnloadedExtensionInfo::Reason reason) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 116 module != nacl_modules->end(); | 130 module != nacl_modules->end(); |
| 117 ++module) { | 131 ++module) { |
| 118 UnregisterNaClModule(*module); | 132 UnregisterNaClModule(*module); |
| 119 } | 133 } |
| 120 UpdatePluginListWithNaClModules(); | 134 UpdatePluginListWithNaClModules(); |
| 121 } | 135 } |
| 122 | 136 |
| 123 const MimeTypesHandler* handler = MimeTypesHandler::GetHandler(extension); | 137 const MimeTypesHandler* handler = MimeTypesHandler::GetHandler(extension); |
| 124 if (handler && !handler->handler_url().empty()) { | 138 if (handler && !handler->handler_url().empty()) { |
| 125 plugins_or_nacl_changed = true; | 139 plugins_or_nacl_changed = true; |
| 126 UnregisterMimeTypeHandler(handler->extension_id()); | 140 base::FilePath path = |
| 141 base::FilePath::FromUTF8Unsafe(handler->extension_id()); |
| 142 PluginService::GetInstance()->UnregisterInternalPlugin(path); |
| 143 PluginService::GetInstance()->ForcePluginShutdown(path); |
| 144 PluginService::GetInstance()->RefreshPlugins(); |
| 127 } | 145 } |
| 128 | 146 |
| 129 if (plugins_or_nacl_changed) | 147 if (plugins_or_nacl_changed) |
| 130 PluginService::GetInstance()->PurgePluginListCache(profile_, false); | 148 PluginService::GetInstance()->PurgePluginListCache(profile_, false); |
| 131 } | 149 } |
| 132 | 150 |
| 133 void PluginManager::RegisterNaClModule(const NaClModuleInfo& info) { | 151 void PluginManager::RegisterNaClModule(const NaClModuleInfo& info) { |
| 134 DCHECK(FindNaClModule(info.url) == nacl_module_list_.end()); | 152 DCHECK(FindNaClModule(info.url) == nacl_module_list_.end()); |
| 135 nacl_module_list_.push_front(info); | 153 nacl_module_list_.push_front(info); |
| 136 } | 154 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 info.mime_types.push_back(mime_type_info); | 198 info.mime_types.push_back(mime_type_info); |
| 181 } | 199 } |
| 182 | 200 |
| 183 PluginService::GetInstance()->RefreshPlugins(); | 201 PluginService::GetInstance()->RefreshPlugins(); |
| 184 PluginService::GetInstance()->RegisterInternalPlugin(info, true); | 202 PluginService::GetInstance()->RegisterInternalPlugin(info, true); |
| 185 // This plugin has been modified, no need to check the rest of its | 203 // This plugin has been modified, no need to check the rest of its |
| 186 // types, but continue checking other plugins. | 204 // types, but continue checking other plugins. |
| 187 break; | 205 break; |
| 188 } | 206 } |
| 189 } | 207 } |
| 190 | |
| 191 for (std::set<std::string>::iterator ix = | |
| 192 mime_type_handler_extension_ids_.begin(); | |
| 193 ix != mime_type_handler_extension_ids_.end(); ++ix) { | |
| 194 const std::string& extension_id = *ix; | |
| 195 const Extension* extension = | |
| 196 profile_->GetExtensionService()->GetExtensionById(extension_id, false); | |
| 197 const MimeTypesHandler* handler = MimeTypesHandler::GetHandler(extension); | |
| 198 if (handler && !handler->handler_url().empty()) { | |
| 199 PluginService::GetInstance()->UnregisterInternalPlugin( | |
| 200 base::FilePath::FromUTF8Unsafe(extension_id)); | |
| 201 | |
| 202 content::WebPluginInfo info; | |
| 203 info.type = content::WebPluginInfo::PLUGIN_TYPE_BROWSER_PLUGIN; | |
| 204 info.name = base::UTF8ToUTF16(extension_id); | |
| 205 info.path = base::FilePath::FromUTF8Unsafe(extension_id); | |
| 206 | |
| 207 for (std::set<std::string>::const_iterator mime_type = | |
| 208 handler->mime_type_set().begin(); | |
| 209 mime_type != handler->mime_type_set().end(); ++mime_type) { | |
| 210 content::WebPluginMimeType mime_type_info; | |
| 211 mime_type_info.mime_type = *mime_type; | |
| 212 info.mime_types.push_back(mime_type_info); | |
| 213 } | |
| 214 | |
| 215 PluginService::GetInstance()->RefreshPlugins(); | |
| 216 PluginService::GetInstance()->RegisterInternalPlugin(info, true); | |
| 217 } | |
| 218 } | |
| 219 } | 208 } |
| 220 | 209 |
| 221 void PluginManager::RegisterMimeTypeHandler(const std::string& extension_id) { | |
| 222 mime_type_handler_extension_ids_.insert(extension_id); | |
| 223 } | |
| 224 | |
| 225 void PluginManager::UnregisterMimeTypeHandler(const std::string& extension_id) { | |
| 226 mime_type_handler_extension_ids_.erase(extension_id); | |
| 227 PluginService::GetInstance()->UnregisterInternalPlugin( | |
| 228 base::FilePath::FromUTF8Unsafe(extension_id)); | |
| 229 } | |
| 230 | |
| 231 NaClModuleInfo::List::iterator PluginManager::FindNaClModule(const GURL& url) { | 210 NaClModuleInfo::List::iterator PluginManager::FindNaClModule(const GURL& url) { |
| 232 for (NaClModuleInfo::List::iterator iter = nacl_module_list_.begin(); | 211 for (NaClModuleInfo::List::iterator iter = nacl_module_list_.begin(); |
| 233 iter != nacl_module_list_.end(); ++iter) { | 212 iter != nacl_module_list_.end(); ++iter) { |
| 234 if (iter->url == url) | 213 if (iter->url == url) |
| 235 return iter; | 214 return iter; |
| 236 } | 215 } |
| 237 return nacl_module_list_.end(); | 216 return nacl_module_list_.end(); |
| 238 } | 217 } |
| 239 | 218 |
| 240 } // namespace extensions | 219 } // namespace extensions |
| OLD | NEW |