Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Side by Side Diff: chrome/browser/extensions/plugin_manager.cc

Issue 263513004: Forward MIME types to BrowserPlugin when a viewer is specified. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix unittests Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/manifest_handlers/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
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 && !handler->handler_url().empty()) {
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
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 && !handler->handler_url().empty()) {
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
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 =
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 }
175 } 219 }
176 220
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
177 NaClModuleInfo::List::iterator PluginManager::FindNaClModule(const GURL& url) { 231 NaClModuleInfo::List::iterator PluginManager::FindNaClModule(const GURL& url) {
178 for (NaClModuleInfo::List::iterator iter = nacl_module_list_.begin(); 232 for (NaClModuleInfo::List::iterator iter = nacl_module_list_.begin();
179 iter != nacl_module_list_.end(); ++iter) { 233 iter != nacl_module_list_.end(); ++iter) {
180 if (iter->url == url) 234 if (iter->url == url)
181 return iter; 235 return iter;
182 } 236 }
183 return nacl_module_list_.end(); 237 return nacl_module_list_.end();
184 } 238 }
185 239
186 } // namespace extensions 240 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/plugin_manager.h ('k') | chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698