Index: content/browser/plugin_loader.cc |
diff --git a/content/browser/plugin_loader.cc b/content/browser/plugin_loader.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..6677a49ab8b3e64d52ae07146fc706fd9e10d59e |
--- /dev/null |
+++ b/content/browser/plugin_loader.cc |
@@ -0,0 +1,81 @@ |
+// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "content/browser/plugin_loader.h" |
+ |
+#include "base/bind.h" |
+#include "content/common/utility_messages.h" |
+#include "webkit/plugins/npapi/plugin_list.h" |
+ |
+PluginLoader::PluginLoader() : process_host_(NULL) { |
+} |
+ |
+PluginLoader::~PluginLoader() { |
+} |
+ |
+void PluginLoader::LoadPlugins( |
+ base::MessageLoopProxy* target_loop, |
+ const PluginService::GetPluginsCallback& callback) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
+ callbacks_.push_back(PendingCallback(target_loop, callback)); |
+ StartLoadingIfNecessary(); |
+} |
+ |
+void PluginLoader::StartLoadingIfNecessary() { |
+ if (process_host_) |
+ return; |
+ |
+ process_host_ = new UtilityProcessHost(this, BrowserThread::IO); |
+ process_host_->set_no_sandbox(true); |
+#if defined(OS_MACOSX) |
+ process_host_->set_child_flags( |
+ ChildProcessHost::CHILD_ALLOW_HEAP_EXECUTION); |
+#endif |
+ |
+ std::vector<FilePath> extra_plugin_paths; |
+ std::vector<FilePath> extra_plugin_dirs; |
+ std::vector<webkit::WebPluginInfo> internal_plugins; |
+ webkit::npapi::PluginList::Singleton()->GetPluginPathListsToLoad( |
+ &extra_plugin_paths, &extra_plugin_dirs, &internal_plugins); |
+ |
+ process_host_->Send(new UtilityMsg_LoadPlugins( |
+ extra_plugin_paths, extra_plugin_dirs, internal_plugins)); |
+} |
+ |
+bool PluginLoader::OnMessageReceived(const IPC::Message& message) { |
+ bool handled = true; |
+ IPC_BEGIN_MESSAGE_MAP(PluginLoader, message) |
+ IPC_MESSAGE_HANDLER(UtilityHostMsg_LoadedPlugins, OnGotPlugins) |
+ IPC_MESSAGE_UNHANDLED(handled = false) |
+ IPC_END_MESSAGE_MAP() |
+ return handled; |
+} |
+ |
+void PluginLoader::OnProcessCrashed(int exit_code) { |
+ LOG(ERROR) << "Out-of-process plugin loader crashed with code " << exit_code |
+ << ". You will have no plugins!"; |
+ // Don't leave callers hanging. |
+ OnGotPlugins(std::vector<webkit::WebPluginInfo>()); |
+} |
+ |
+PluginLoader::PendingCallback::PendingCallback( |
+ scoped_refptr<base::MessageLoopProxy> loop, |
+ const PluginService::GetPluginsCallback& callback) |
+ : target_loop(loop), |
+ callback(callback) {} |
+ |
+PluginLoader::PendingCallback::~PendingCallback() {} |
+ |
+void PluginLoader::OnGotPlugins( |
+ const std::vector<webkit::WebPluginInfo>& plugins) { |
+ webkit::npapi::PluginList::Singleton()->SetPlugins(plugins); |
+ for (size_t i = 0; i < callbacks_.size(); ++i) { |
+ callbacks_[i].target_loop->PostTask(FROM_HERE, |
+ base::Bind(callbacks_[i].callback, plugins)); |
+ } |
+ |
+ // Reset our state. |
+ process_host_ = NULL; |
+ callbacks_.clear(); |
+} |