Index: content/browser/plugin_service.cc |
diff --git a/content/browser/plugin_service.cc b/content/browser/plugin_service.cc |
index 0a6007cca5605a32918307d332004e418edaef85..ae7a5075de6ff28dd6162250e7d78e487a3789e7 100644 |
--- a/content/browser/plugin_service.cc |
+++ b/content/browser/plugin_service.cc |
@@ -4,9 +4,12 @@ |
#include "content/browser/plugin_service.h" |
+#include "base/bind.h" |
#include "base/command_line.h" |
#include "base/compiler_specific.h" |
#include "base/file_path.h" |
+#include "base/message_loop.h" |
+#include "base/message_loop_proxy.h" |
#include "base/path_service.h" |
#include "base/string_util.h" |
#include "base/synchronization/waitable_event.h" |
@@ -26,7 +29,9 @@ |
#include "content/common/pepper_plugin_registry.h" |
#include "content/common/plugin_messages.h" |
#include "content/common/view_messages.h" |
+#include "webkit/plugins/npapi/mock_plugin_list.h" |
#include "webkit/plugins/npapi/plugin_constants_win.h" |
+#include "webkit/plugins/npapi/plugin_group.h" |
#include "webkit/plugins/npapi/plugin_list.h" |
#include "webkit/plugins/webplugininfo.h" |
@@ -36,6 +41,28 @@ using ::base::files::FilePathWatcher; |
using content::PluginServiceFilter; |
+namespace { |
+ |
+// Helper function that merely runs the callback with the result. Called on the |
+// thread on which the original GetPlugins() call was made. |
+static void RunGetPluginsCallback( |
+ const PluginService::GetPluginsCallback& callback, |
+ std::vector<webkit::WebPluginInfo> result) { |
Bernhard Bauer
2011/09/21 14:31:26
Nit: This should probably be const ref as well?
Robert Sesek
2011/09/21 16:46:52
Done.
|
+ callback.Run(result); |
+} |
+ |
+// A callback for GetPlugins() that then gets the freshly loaded plugin groups |
+// and runs the callback for GetPluginGroups(). |
+static void GetPluginsForGroupsCallback( |
+ const PluginService::GetPluginGroupsCallback& callback, |
+ const std::vector<webkit::WebPluginInfo>& plugins) { |
+ std::vector<webkit::npapi::PluginGroup> groups; |
+ PluginService::GetInstance()->GetCachedPluginGroups(&groups); |
+ callback.Run(groups); |
+} |
+ |
+} // namespace |
+ |
#if defined(OS_MACOSX) |
static void NotifyPluginsOfActivation() { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
@@ -70,7 +97,8 @@ PluginService* PluginService::GetInstance() { |
PluginService::PluginService() |
: ui_locale_( |
content::GetContentClient()->browser()->GetApplicationLocale()), |
- filter_(NULL) { |
+ filter_(NULL), |
+ plugin_list_(NULL) { |
RegisterPepperPlugins(); |
// Load any specified on the command line as well. |
@@ -134,8 +162,7 @@ void PluginService::StartWatchingPlugins() { |
// Get the list of all paths for registering the FilePathWatchers |
// that will track and if needed reload the list of plugins on runtime. |
std::vector<FilePath> plugin_dirs; |
- webkit::npapi::PluginList::Singleton()->GetPluginDirectories( |
- &plugin_dirs); |
+ GetPluginList()->GetPluginDirectories(&plugin_dirs); |
for (size_t i = 0; i < plugin_dirs.size(); ++i) { |
// FilePathWatcher can not handle non-absolute paths under windows. |
@@ -216,8 +243,7 @@ PluginProcessHost* PluginService::FindOrStartNpapiPluginProcess( |
return plugin_host; |
webkit::WebPluginInfo info; |
- if (!webkit::npapi::PluginList::Singleton()->GetPluginInfoByPath( |
- plugin_path, &info)) { |
+ if (!GetPluginList()->GetPluginInfoByPath(plugin_path, &info)) { |
return NULL; |
} |
@@ -384,8 +410,7 @@ bool PluginService::GetPluginInfo(int render_process_id, |
bool* use_stale, |
webkit::WebPluginInfo* info, |
std::string* actual_mime_type) { |
- webkit::npapi::PluginList* plugin_list = |
- webkit::npapi::PluginList::Singleton(); |
+ webkit::npapi::PluginList* plugin_list = GetPluginList(); |
// GetPluginInfoArray may need to load the plugins, so we need to be |
// on the FILE thread. |
DCHECK(use_stale || BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
@@ -417,31 +442,81 @@ bool PluginService::GetPluginInfo(int render_process_id, |
return false; |
} |
-void PluginService::GetPlugins( |
- const content::ResourceContext& context, |
- std::vector<webkit::WebPluginInfo>* plugins) { |
- // GetPlugins may need to load the plugins, so we need to be |
- // on the FILE thread. |
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
- webkit::npapi::PluginList* plugin_list = |
- webkit::npapi::PluginList::Singleton(); |
+void PluginService::RefreshPluginList() { |
+ GetPluginList()->RefreshPlugins(); |
+} |
+ |
+void PluginService::GetPlugins(const content::ResourceContext& context, |
+ const PluginService::GetPluginsCallback& callback) { |
+ BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
+ base::Bind(&PluginService::GetPluginsInternal, base::Unretained(this), |
+ base::Unretained(&context), |
+ MessageLoop::current()->message_loop_proxy(), |
+ callback)); |
+} |
+ |
+void PluginService::GetPlugins(const GetPluginsCallback& callback) { |
+ BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
+ base::Bind(&PluginService::GetPluginsInternal, base::Unretained(this), |
+ base::Unretained(static_cast<content::ResourceContext*>(NULL)), |
+ MessageLoop::current()->message_loop_proxy(), |
+ callback)); |
+} |
+ |
+void PluginService::GetCachedPluginGroups( |
+ std::vector<webkit::npapi::PluginGroup>* groups) { |
+ GetPluginList()->GetPluginGroups(false, groups); |
+} |
+ |
+void PluginService::GetPluginGroups(const GetPluginGroupsCallback& callback) { |
+ GetPlugins(base::Bind(&GetPluginsForGroupsCallback, callback)); |
+} |
+ |
+void PluginService::GetPluginsInternal(const content::ResourceContext* context, |
+ base::MessageLoopProxy* target_loop, |
+ const PluginService::GetPluginsCallback& callback) { |
+ // Load all the plugins synchronously. |
+ webkit::npapi::PluginList* plugin_list = GetPluginList(); |
std::vector<webkit::WebPluginInfo> all_plugins; |
plugin_list->GetPlugins(&all_plugins); |
- int child_process_id = -1; |
- int routing_id = MSG_ROUTING_NONE; |
- for (size_t i = 0; i < all_plugins.size(); ++i) { |
- if (!filter_ || filter_->ShouldUsePlugin(child_process_id, |
- routing_id, |
- &context, |
- GURL(), |
- GURL(), |
- &all_plugins[i])) { |
- plugins->push_back(all_plugins[i]); |
+ if (context) { |
+ // If there is a context, filter plugins. |
+ std::vector<webkit::WebPluginInfo> plugins; |
+ |
+ int child_process_id = -1; |
+ int routing_id = MSG_ROUTING_NONE; |
+ for (size_t i = 0; i < all_plugins.size(); ++i) { |
+ if (!filter_ || filter_->ShouldUsePlugin(child_process_id, |
+ routing_id, |
+ context, |
+ GURL(), |
+ GURL(), |
+ &all_plugins[i])) { |
+ plugins.push_back(all_plugins[i]); |
+ } |
} |
+ |
+ target_loop->PostTask(FROM_HERE, |
+ base::Bind(&RunGetPluginsCallback, callback, plugins)); |
+ } else { |
+ // Otherwise, return all plugins. |
+ target_loop->PostTask(FROM_HERE, |
+ base::Bind(&RunGetPluginsCallback, callback, all_plugins)); |
} |
} |
+void PluginService::SetPluginListForTesting( |
+ webkit::npapi::MockPluginList* plugin_list) { |
+ plugin_list_ = plugin_list; |
+} |
+ |
+webkit::npapi::PluginList* PluginService::GetPluginList() { |
+ if (plugin_list_) |
+ return plugin_list_; |
+ return webkit::npapi::PluginList::Singleton(); |
+} |
+ |
void PluginService::OnWaitableEventSignaled( |
base::WaitableEvent* waitable_event) { |
#if defined(OS_WIN) |
@@ -451,7 +526,7 @@ void PluginService::OnWaitableEventSignaled( |
hklm_key_.StartWatching(); |
} |
- webkit::npapi::PluginList::Singleton()->RefreshPlugins(); |
+ GetPluginList()->RefreshPlugins(); |
PurgePluginListCache(true); |
#else |
// This event should only get signaled on a Windows machine. |
@@ -483,7 +558,7 @@ void PluginService::RegisterPepperPlugins() { |
// TODO(abarth): It seems like the PepperPluginRegistry should do this work. |
PepperPluginRegistry::ComputeList(&ppapi_plugins_); |
for (size_t i = 0; i < ppapi_plugins_.size(); ++i) { |
- webkit::npapi::PluginList::Singleton()->RegisterInternalPlugin( |
+ GetPluginList()->RegisterInternalPlugin( |
ppapi_plugins_[i].ToWebPluginInfo()); |
} |
} |
@@ -506,8 +581,7 @@ PepperPluginInfo* PluginService::GetRegisteredPpapiPluginInfo( |
// construct it and add it to the list. This same deal needs to be done |
// in the renderer side in PepperPluginRegistry. |
webkit::WebPluginInfo webplugin_info; |
- if (!webkit::npapi::PluginList::Singleton()->GetPluginInfoByPath( |
- plugin_path, &webplugin_info)) |
+ if (!GetPluginList()->GetPluginInfoByPath(plugin_path, &webplugin_info)) |
return NULL; |
PepperPluginInfo new_pepper_info; |
if (!MakePepperPluginInfo(webplugin_info, &new_pepper_info)) |