OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "build/build_config.h" | 5 #include "build/build_config.h" |
6 | 6 |
7 #include "chrome/browser/plugin_service.h" | 7 #include "chrome/browser/plugin_service.h" |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 } | 200 } |
201 | 201 |
202 const std::string& PluginService::GetUILocale() { | 202 const std::string& PluginService::GetUILocale() { |
203 return ui_locale_; | 203 return ui_locale_; |
204 } | 204 } |
205 | 205 |
206 PluginProcessHost* PluginService::FindPluginProcess( | 206 PluginProcessHost* PluginService::FindPluginProcess( |
207 const FilePath& plugin_path) { | 207 const FilePath& plugin_path) { |
208 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 208 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
209 | 209 |
210 if (plugin_path.value().empty()) { | |
211 NOTREACHED() << "should only be called if we have a plugin to load"; | |
212 return NULL; | |
213 } | |
214 | |
215 for (BrowserChildProcessHost::Iterator iter(ChildProcessInfo::PLUGIN_PROCESS); | 210 for (BrowserChildProcessHost::Iterator iter(ChildProcessInfo::PLUGIN_PROCESS); |
216 !iter.Done(); ++iter) { | 211 !iter.Done(); ++iter) { |
217 PluginProcessHost* plugin = static_cast<PluginProcessHost*>(*iter); | 212 PluginProcessHost* plugin = static_cast<PluginProcessHost*>(*iter); |
218 if (plugin->info().path == plugin_path) | 213 if (plugin->info().path == plugin_path) |
219 return plugin; | 214 return plugin; |
220 } | 215 } |
221 | 216 |
222 return NULL; | 217 return NULL; |
223 } | 218 } |
224 | 219 |
225 PluginProcessHost* PluginService::FindOrStartPluginProcess( | 220 PluginProcessHost* PluginService::FindOrStartPluginProcess( |
226 const FilePath& plugin_path) { | 221 const FilePath& plugin_path) { |
227 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 222 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
228 | 223 |
229 PluginProcessHost *plugin_host = FindPluginProcess(plugin_path); | 224 PluginProcessHost* plugin_host = FindPluginProcess(plugin_path); |
230 if (plugin_host) | 225 if (plugin_host) |
231 return plugin_host; | 226 return plugin_host; |
232 | 227 |
233 WebPluginInfo info; | 228 WebPluginInfo info; |
234 if (!NPAPI::PluginList::Singleton()->GetPluginInfoByPath( | 229 if (!NPAPI::PluginList::Singleton()->GetPluginInfoByPath( |
235 plugin_path, &info)) { | 230 plugin_path, &info)) { |
236 DCHECK(false); | 231 NOTREACHED(); |
237 return NULL; | 232 return NULL; |
238 } | 233 } |
239 | 234 |
240 // This plugin isn't loaded by any plugin process, so create a new process. | 235 // This plugin isn't loaded by any plugin process, so create a new process. |
241 plugin_host = new PluginProcessHost(); | 236 scoped_ptr<PluginProcessHost> new_host(new PluginProcessHost()); |
242 if (!plugin_host->Init(info, ui_locale_)) { | 237 if (!new_host->Init(info, ui_locale_)) { |
243 DCHECK(false); // Init is not expected to fail | 238 NOTREACHED(); // Init is not expected to fail |
244 delete plugin_host; | |
245 return NULL; | 239 return NULL; |
246 } | 240 } |
247 | 241 |
248 return plugin_host; | 242 return new_host.release(); |
249 } | 243 } |
250 | 244 |
251 void PluginService::OpenChannelToPlugin( | 245 void PluginService::OpenChannelToPlugin( |
252 const GURL& url, | 246 const GURL& url, |
253 const std::string& mime_type, | 247 const std::string& mime_type, |
254 PluginProcessHost::Client* client) { | 248 PluginProcessHost::Client* client) { |
255 // The PluginList::GetFirstAllowedPluginInfo may need to load the | 249 // The PluginList::GetFirstAllowedPluginInfo may need to load the |
256 // plugins. Don't do it on the IO thread. | 250 // plugins. Don't do it on the IO thread. |
257 BrowserThread::PostTask( | 251 BrowserThread::PostTask( |
258 BrowserThread::FILE, FROM_HERE, | 252 BrowserThread::FILE, FROM_HERE, |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 info.mime_types = ASCIIToWide(JoinString(plugins[i].mime_types, '|')); | 432 info.mime_types = ASCIIToWide(JoinString(plugins[i].mime_types, '|')); |
439 | 433 |
440 // These NPAPI entry points will never be called. TODO(darin): Come up | 434 // These NPAPI entry points will never be called. TODO(darin): Come up |
441 // with a cleaner way to register pepper plugins with the NPAPI PluginList, | 435 // with a cleaner way to register pepper plugins with the NPAPI PluginList, |
442 // or perhaps refactor the PluginList to be less specific to NPAPI. | 436 // or perhaps refactor the PluginList to be less specific to NPAPI. |
443 memset(&info.entry_points, 0, sizeof(info.entry_points)); | 437 memset(&info.entry_points, 0, sizeof(info.entry_points)); |
444 | 438 |
445 NPAPI::PluginList::Singleton()->RegisterInternalPlugin(info); | 439 NPAPI::PluginList::Singleton()->RegisterInternalPlugin(info); |
446 } | 440 } |
447 } | 441 } |
OLD | NEW |