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

Unified Diff: content/browser/plugin_service.cc

Issue 7387010: Add PluginServiceFilter interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add resource_context Created 9 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/plugin_service.cc
diff --git a/content/browser/plugin_service.cc b/content/browser/plugin_service.cc
index 154d0629103c353424865c234c686c9d6053cb4a..c4b893cf6c1b7f77a5392894900fc4ba73af3836 100644
--- a/content/browser/plugin_service.cc
+++ b/content/browser/plugin_service.cc
@@ -8,6 +8,7 @@
#include "base/command_line.h"
#include "base/compiler_specific.h"
+#include "base/file_path.h"
#include "base/path_service.h"
#include "base/string_util.h"
#include "base/synchronization/waitable_event.h"
@@ -134,11 +135,6 @@ PluginService::PluginService()
file_watchers_.push_back(watcher);
}
#endif
- registrar_.Add(this, content::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED,
- NotificationService::AllSources());
- registrar_.Add(this,
- content::NOTIFICATION_RENDERER_PROCESS_CLOSED,
- NotificationService::AllSources());
}
PluginService::~PluginService() {
@@ -280,15 +276,20 @@ void PluginService::OpenChannelToNpapiPlugin(
int render_process_id,
int render_view_id,
const GURL& url,
+ const GURL& policy_url,
const std::string& mime_type,
PluginProcessHost::Client* client) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ Filter* filter = content::GetContentClient()->browser()->CreatePluginFilter(
+ render_process_id, render_view_id, *client->GetResourceContext(),
+ url, policy_url);
// The PluginList::GetPluginInfo may need to load the plugins. Don't do it on
// the IO thread.
BrowserThread::PostTask(
BrowserThread::FILE, FROM_HERE,
NewRunnableMethod(
this, &PluginService::GetAllowedPluginForOpenChannelToPlugin,
- render_process_id, render_view_id, url, mime_type, client));
+ url, mime_type, filter, client));
}
void PluginService::OpenChannelToPpapiPlugin(
@@ -313,18 +314,18 @@ void PluginService::OpenChannelToPpapiBroker(
}
void PluginService::GetAllowedPluginForOpenChannelToPlugin(
- int render_process_id,
- int render_view_id,
const GURL& url,
const std::string& mime_type,
+ Filter* filter,
PluginProcessHost::Client* client) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
webkit::npapi::WebPluginInfo info;
- bool found = GetPluginInfo(
- render_process_id, render_view_id, url, mime_type, &info, NULL);
+ bool allow_wildcard = true;
+ bool found = GetPluginInfo(url, mime_type, allow_wildcard, filter,
+ NULL, &info, NULL);
FilePath plugin_path;
if (found)
- plugin_path = FilePath(info.path);
+ plugin_path = info.path;
// Now we jump back to the IO thread to finish opening the channel.
BrowserThread::PostTask(
@@ -346,35 +347,26 @@ void PluginService::FinishOpenChannelToPlugin(
client->OnError();
}
-bool PluginService::GetPluginInfo(int render_process_id,
- int render_view_id,
- const GURL& url,
- const std::string& mime_type,
- webkit::npapi::WebPluginInfo* info,
- std::string* actual_mime_type) {
+bool PluginService::GetPluginInfo(
+ const GURL& url,
+ const std::string& mime_type,
+ bool allow_wildcard,
+ Filter* filter,
+ bool* use_stale,
+ webkit::npapi::WebPluginInfo* info,
+ std::string* actual_mime_type) {
+ scoped_ptr<Filter> owned_filter(filter);
+ webkit::npapi::PluginList* plugin_list =
+ webkit::npapi::PluginList::Singleton();
// GetPluginInfoArray may need to load the plugins, so we need to be
// on the FILE thread.
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
- {
- base::AutoLock auto_lock(overridden_plugins_lock_);
- for (size_t i = 0; i < overridden_plugins_.size(); ++i) {
- if (overridden_plugins_[i].render_process_id == render_process_id &&
- overridden_plugins_[i].render_view_id == render_view_id &&
- overridden_plugins_[i].url == url) {
- if (actual_mime_type)
- *actual_mime_type = mime_type;
- *info = overridden_plugins_[i].plugin;
- return true;
- }
- }
- }
- bool allow_wildcard = true;
+ DCHECK(use_stale || BrowserThread::CurrentlyOn(BrowserThread::FILE));
std::vector<webkit::npapi::WebPluginInfo> plugins;
std::vector<std::string> mime_types;
- webkit::npapi::PluginList::Singleton()->GetPluginInfoArray(
- url, mime_type, allow_wildcard, NULL, &plugins, &mime_types);
+ plugin_list->GetPluginInfoArray(
+ url, mime_type, allow_wildcard, use_stale, &plugins, &mime_types);
for (size_t i = 0; i < plugins.size(); ++i) {
- if (webkit::npapi::IsPluginEnabled(plugins[i])) {
+ if (filter->ShouldUsePlugin(&plugins[i])) {
*info = plugins[i];
if (actual_mime_type)
*actual_mime_type = mime_types[i];
@@ -384,6 +376,23 @@ bool PluginService::GetPluginInfo(int render_process_id,
return false;
}
+void PluginService::GetPlugins(
+ Filter* filter,
+ std::vector<webkit::npapi::WebPluginInfo>* plugins) {
+ scoped_ptr<Filter> owned_filter(filter);
+ webkit::npapi::PluginList* plugin_list =
+ webkit::npapi::PluginList::Singleton();
+ // GetPluginInfoArray may need to load the plugins, so we need to be
+ // on the FILE thread.
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
+ std::vector<webkit::npapi::WebPluginInfo> all_plugins;
+ plugin_list->GetPlugins(&all_plugins);
+ for (size_t i = 0; i < all_plugins.size(); ++i) {
+ if (filter->ShouldUsePlugin(&all_plugins[i]))
+ plugins->push_back(all_plugins[i]);
+ }
+}
+
void PluginService::OnWaitableEventSignaled(
base::WaitableEvent* waitable_event) {
#if defined(OS_WIN)
@@ -404,40 +413,14 @@ void PluginService::OnWaitableEventSignaled(
void PluginService::Observe(int type,
const NotificationSource& source,
const NotificationDetails& details) {
- switch (type) {
#if defined(OS_MACOSX)
- case content::NOTIFICATION_APP_ACTIVATED: {
- BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
- NewRunnableFunction(&NotifyPluginsOfActivation));
- break;
- }
-#endif
-
- case content::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED: {
- webkit::npapi::PluginList::Singleton()->RefreshPlugins();
- PurgePluginListCache(false);
- break;
- }
- case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: {
- int render_process_id = Source<RenderProcessHost>(source).ptr()->id();
-
- base::AutoLock auto_lock(overridden_plugins_lock_);
- for (size_t i = 0; i < overridden_plugins_.size(); ++i) {
- if (overridden_plugins_[i].render_process_id == render_process_id) {
- overridden_plugins_.erase(overridden_plugins_.begin() + i);
- break;
- }
- }
- break;
- }
- default:
- NOTREACHED();
+ if (type == content::NOTIFICATION_APP_ACTIVATED) {
+ BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
+ NewRunnableFunction(&NotifyPluginsOfActivation));
+ return;
}
-}
-
-void PluginService::OverridePluginForTab(const OverriddenPlugin& plugin) {
- base::AutoLock auto_lock(overridden_plugins_lock_);
- overridden_plugins_.push_back(plugin);
+#endif
+ NOTREACHED();
}
void PluginService::PurgePluginListCache(bool reload_pages) {
@@ -447,32 +430,6 @@ void PluginService::PurgePluginListCache(bool reload_pages) {
}
}
-void PluginService::RestrictPluginToUrl(const FilePath& plugin_path,
- const GURL& url) {
- base::AutoLock auto_lock(restricted_plugin_lock_);
- if (url.is_empty()) {
- restricted_plugin_.erase(plugin_path);
- } else {
- restricted_plugin_[plugin_path] = url;
- }
-}
-
-bool PluginService::PluginAllowedForURL(const FilePath& plugin_path,
- const GURL& url) {
- if (url.is_empty())
- return true; // Caller wants all plugins.
-
- base::AutoLock auto_lock(restricted_plugin_lock_);
-
- RestrictedPluginMap::iterator it = restricted_plugin_.find(plugin_path);
- if (it == restricted_plugin_.end())
- return true; // This plugin is not restricted, so it's allowed everywhere.
-
- const GURL& required_url = it->second;
- return (url.scheme() == required_url.scheme() &&
- url.host() == required_url.host());
-}
-
void PluginService::RegisterPepperPlugins() {
// TODO(abarth): It seems like the PepperPluginRegistry should do this work.
PepperPluginRegistry::ComputeList(&ppapi_plugins_);

Powered by Google App Engine
This is Rietveld 408576698