OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/browser/plugin_loader.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "content/common/utility_messages.h" |
| 9 #include "webkit/plugins/npapi/plugin_list.h" |
| 10 |
| 11 PluginLoader::PluginLoader() : process_host_(NULL) { |
| 12 } |
| 13 |
| 14 PluginLoader::~PluginLoader() { |
| 15 } |
| 16 |
| 17 void PluginLoader::LoadPlugins( |
| 18 base::MessageLoopProxy* target_loop, |
| 19 const PluginService::GetPluginsCallback& callback) { |
| 20 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 21 callbacks_.push_back(PendingCallback(target_loop, callback)); |
| 22 StartLoadingIfNecessary(); |
| 23 } |
| 24 |
| 25 void PluginLoader::StartLoadingIfNecessary() { |
| 26 if (process_host_) |
| 27 return; |
| 28 |
| 29 process_host_ = new UtilityProcessHost(this, BrowserThread::IO); |
| 30 process_host_->set_no_sandbox(true); |
| 31 #if defined(OS_MACOSX) |
| 32 process_host_->set_child_flags( |
| 33 ChildProcessHost::CHILD_ALLOW_HEAP_EXECUTION); |
| 34 #endif |
| 35 |
| 36 std::vector<FilePath> extra_plugin_paths; |
| 37 std::vector<FilePath> extra_plugin_dirs; |
| 38 std::vector<webkit::WebPluginInfo> internal_plugins; |
| 39 webkit::npapi::PluginList::Singleton()->GetPluginPathListsToLoad( |
| 40 &extra_plugin_paths, &extra_plugin_dirs, &internal_plugins); |
| 41 |
| 42 process_host_->Send(new UtilityMsg_LoadPlugins( |
| 43 extra_plugin_paths, extra_plugin_dirs, internal_plugins)); |
| 44 } |
| 45 |
| 46 bool PluginLoader::OnMessageReceived(const IPC::Message& message) { |
| 47 bool handled = true; |
| 48 IPC_BEGIN_MESSAGE_MAP(PluginLoader, message) |
| 49 IPC_MESSAGE_HANDLER(UtilityHostMsg_LoadedPlugins, OnGotPlugins) |
| 50 IPC_MESSAGE_UNHANDLED(handled = false) |
| 51 IPC_END_MESSAGE_MAP() |
| 52 return handled; |
| 53 } |
| 54 |
| 55 void PluginLoader::OnProcessCrashed(int exit_code) { |
| 56 LOG(ERROR) << "Out-of-process plugin loader crashed with code " << exit_code |
| 57 << ". You will have no plugins!"; |
| 58 // Don't leave callers hanging. |
| 59 OnGotPlugins(std::vector<webkit::WebPluginInfo>()); |
| 60 } |
| 61 |
| 62 PluginLoader::PendingCallback::PendingCallback( |
| 63 scoped_refptr<base::MessageLoopProxy> loop, |
| 64 const PluginService::GetPluginsCallback& callback) |
| 65 : target_loop(loop), |
| 66 callback(callback) {} |
| 67 |
| 68 PluginLoader::PendingCallback::~PendingCallback() {} |
| 69 |
| 70 void PluginLoader::OnGotPlugins( |
| 71 const std::vector<webkit::WebPluginInfo>& plugins) { |
| 72 webkit::npapi::PluginList::Singleton()->SetPlugins(plugins); |
| 73 for (size_t i = 0; i < callbacks_.size(); ++i) { |
| 74 callbacks_[i].target_loop->PostTask(FROM_HERE, |
| 75 base::Bind(callbacks_[i].callback, plugins)); |
| 76 } |
| 77 |
| 78 // Reset our state. |
| 79 process_host_ = NULL; |
| 80 callbacks_.clear(); |
| 81 } |
OLD | NEW |