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

Side by Side Diff: chrome/browser/chrome_plugin_service_helper.cc

Issue 7387010: Add PluginServiceFilter interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add resource_context Created 9 years, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 "chrome/browser/chrome_plugin_service_helper.h"
6
7 #include "base/logging.h"
8 #include "chrome/common/chrome_notification_types.h"
9 #include "content/browser/browser_thread.h"
10 #include "content/browser/plugin_service.h"
11 #include "content/browser/renderer_host/render_process_host.h"
12 #include "content/browser/resource_context.h"
13 #include "content/common/notification_service.h"
14 #include "webkit/plugins/npapi/plugin_list.h"
15 #include "webkit/plugins/npapi/webplugininfo.h"
16
17 namespace {
18
19 class ChromePluginFilter : public PluginService::Filter {
20 public:
21 ChromePluginFilter(int render_process_id,
22 int render_view_id,
23 const content::ResourceContext& context,
24 const GURL& url,
25 const GURL& policy_url);
26 virtual ~ChromePluginFilter();
27
28 // PluginService::Filter implementation:
29 virtual bool ShouldUsePlugin(webkit::npapi::WebPluginInfo* plugin) OVERRIDE;
30
31 private:
32 GURL policy_url_;
33
34 scoped_ptr<webkit::npapi::WebPluginInfo> overridden_plugin_;
35 bool use_default_plugin_;
36 };
37
38 ChromePluginFilter::ChromePluginFilter(
39 int render_process_id,
40 int render_view_id,
41 const content::ResourceContext& resource_context,
42 const GURL& url,
43 const GURL& policy_url)
44 : policy_url_(policy_url),
45 use_default_plugin_(true) {
46 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
47 ChromePluginServiceHelper* helper = ChromePluginServiceHelper::GetInstance();
48 overridden_plugin_.reset(helper->FindOverriddenPluginForTab(
49 render_process_id, render_view_id, url));
50 }
51
52 ChromePluginFilter::~ChromePluginFilter() {
53 }
54
55 bool ChromePluginFilter::ShouldUsePlugin(webkit::npapi::WebPluginInfo* plugin) {
56 // Check whether the plugin is overridden.
57 if (overridden_plugin_.get()) {
58 if (overridden_plugin_->path != plugin->path)
59 return false;
60 *plugin = *overridden_plugin_;
61 return true;
62 }
63
64 // Check whether the plugin is disabled.
65 if (!webkit::npapi::IsPluginEnabled(*plugin)) {
66 // Don't use the default plug-in to handle a disabled plug-in (because
67 // offering to install an already installed plug-in would be confusing to
68 // the user).
69 // TODO(bauerb): Implement the default plug-in functionality directly
70 // without using a plug-in and get rid of all this hackery.
71 use_default_plugin_ = false;
72 return false;
73 }
74
75 if (!use_default_plugin_ &&
76 plugin->path.value() == webkit::npapi::kDefaultPluginLibraryName) {
77 return false;
78 }
79
80 // Check whether the plugin is restricted to a URL.
81 ChromePluginServiceHelper* helper = ChromePluginServiceHelper::GetInstance();
82 GURL restricted_url = helper->FindRestrictedURLForPlugin(plugin->path);
83 if (!restricted_url.is_empty() &&
84 (policy_url_.scheme() != restricted_url.scheme() ||
85 policy_url_.host() != restricted_url.host())) {
86 return false;
87 }
88
89 return true;
90 }
91
92 } // namespace
93
94 // static
95 ChromePluginServiceHelper* ChromePluginServiceHelper::GetInstance() {
96 return Singleton<ChromePluginServiceHelper>::get();
97 }
98
99 void ChromePluginServiceHelper::OverridePluginForTab(
100 const OverriddenPlugin& plugin) {
101 base::AutoLock auto_lock(lock_);
102 overridden_plugins_.push_back(plugin);
103 }
104
105 webkit::npapi::WebPluginInfo*
106 ChromePluginServiceHelper::FindOverriddenPluginForTab(
107 int render_process_id,
108 int render_view_id,
109 const GURL& url) {
110 base::AutoLock auto_lock(lock_);
111 for (size_t i = 0; i < overridden_plugins_.size(); ++i) {
112 if (overridden_plugins_[i].render_process_id == render_process_id &&
113 overridden_plugins_[i].render_view_id == render_view_id &&
114 overridden_plugins_[i].url == url) {
115 return new webkit::npapi::WebPluginInfo(overridden_plugins_[i].plugin);
116 }
117 }
118 return NULL;
119 }
120
121 void ChromePluginServiceHelper::RestrictPluginToUrl(const FilePath& plugin_path,
122 const GURL& url) {
123 base::AutoLock auto_lock(lock_);
124 if (url.is_empty())
125 restricted_plugins_.erase(plugin_path);
126 else
127 restricted_plugins_[plugin_path] = url;
128 }
129
130 GURL ChromePluginServiceHelper::FindRestrictedURLForPlugin(
131 const FilePath& plugin_path) {
132 base::AutoLock auto_lock(lock_);
133 RestrictedPluginMap::iterator it = restricted_plugins_.find(plugin_path);
134 if (it != restricted_plugins_.end())
135 return it->second;
136 return GURL();
137 }
138
139 PluginService::Filter* ChromePluginServiceHelper::CreatePluginFilter(
140 int render_process_id,
141 int render_view_id,
142 const content::ResourceContext& resource_context,
143 const GURL& url,
144 const GURL& policy_url) {
145 return new ChromePluginFilter(
146 render_process_id, render_view_id, resource_context, url, policy_url);
147 }
148
149 ChromePluginServiceHelper::ChromePluginServiceHelper() {
150 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
151 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED,
152 NotificationService::AllSources());
153 registrar_.Add(this, chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED,
154 NotificationService::AllSources());
155 }
156
157 ChromePluginServiceHelper::~ChromePluginServiceHelper() {
158 }
159
160 void ChromePluginServiceHelper::Observe(int type,
161 const NotificationSource& source,
162 const NotificationDetails& details) {
163 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
164 switch (type) {
165 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: {
166 int render_process_id = Source<RenderProcessHost>(source).ptr()->id();
167
168 base::AutoLock auto_lock(lock_);
169 for (size_t i = 0; i < overridden_plugins_.size(); ++i) {
170 if (overridden_plugins_[i].render_process_id == render_process_id) {
171 overridden_plugins_.erase(overridden_plugins_.begin() + i);
172 break;
173 }
174 }
175 break;
176 }
177 case chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED: {
178 PluginService::GetInstance()->PurgePluginListCache(false);
179 break;
180 }
181 default: {
182 NOTREACHED();
183 }
184 }
185 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698