OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/plugin_service.h" | 5 #include "content/browser/plugin_service.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/file_path.h" |
9 #include "base/path_service.h" | 10 #include "base/path_service.h" |
10 #include "base/string_util.h" | 11 #include "base/string_util.h" |
11 #include "base/synchronization/waitable_event.h" | 12 #include "base/synchronization/waitable_event.h" |
12 #include "base/threading/thread.h" | 13 #include "base/threading/thread.h" |
13 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
14 #include "base/values.h" | 15 #include "base/values.h" |
15 #include "content/browser/browser_thread.h" | 16 #include "content/browser/browser_thread.h" |
16 #include "content/browser/content_browser_client.h" | 17 #include "content/browser/content_browser_client.h" |
| 18 #include "content/browser/plugin_service_filter.h" |
17 #include "content/browser/ppapi_plugin_process_host.h" | 19 #include "content/browser/ppapi_plugin_process_host.h" |
18 #include "content/browser/renderer_host/render_process_host.h" | 20 #include "content/browser/renderer_host/render_process_host.h" |
19 #include "content/browser/renderer_host/render_view_host.h" | 21 #include "content/browser/renderer_host/render_view_host.h" |
20 #include "content/browser/resource_context.h" | 22 #include "content/browser/resource_context.h" |
21 #include "content/common/content_notification_types.h" | 23 #include "content/common/content_notification_types.h" |
22 #include "content/common/content_switches.h" | 24 #include "content/common/content_switches.h" |
23 #include "content/common/notification_service.h" | 25 #include "content/common/notification_service.h" |
24 #include "content/common/pepper_plugin_registry.h" | 26 #include "content/common/pepper_plugin_registry.h" |
25 #include "content/common/plugin_messages.h" | 27 #include "content/common/plugin_messages.h" |
26 #include "content/common/view_messages.h" | 28 #include "content/common/view_messages.h" |
27 #include "webkit/plugins/npapi/plugin_constants_win.h" | 29 #include "webkit/plugins/npapi/plugin_constants_win.h" |
28 #include "webkit/plugins/npapi/plugin_list.h" | 30 #include "webkit/plugins/npapi/plugin_list.h" |
29 #include "webkit/plugins/webplugininfo.h" | 31 #include "webkit/plugins/webplugininfo.h" |
30 | 32 |
31 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 33 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
32 using ::base::files::FilePathWatcher; | 34 using ::base::files::FilePathWatcher; |
33 #endif | 35 #endif |
34 | 36 |
| 37 using content::PluginServiceFilter; |
| 38 |
35 #if defined(OS_MACOSX) | 39 #if defined(OS_MACOSX) |
36 static void NotifyPluginsOfActivation() { | 40 static void NotifyPluginsOfActivation() { |
37 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 41 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
38 | 42 |
39 for (BrowserChildProcessHost::Iterator iter(ChildProcessInfo::PLUGIN_PROCESS); | 43 for (BrowserChildProcessHost::Iterator iter(ChildProcessInfo::PLUGIN_PROCESS); |
40 !iter.Done(); ++iter) { | 44 !iter.Done(); ++iter) { |
41 PluginProcessHost* plugin = static_cast<PluginProcessHost*>(*iter); | 45 PluginProcessHost* plugin = static_cast<PluginProcessHost*>(*iter); |
42 plugin->OnAppActivation(); | 46 plugin->OnAppActivation(); |
43 } | 47 } |
44 } | 48 } |
(...skipping 13 matching lines...) Expand all Loading... |
58 }; | 62 }; |
59 #endif | 63 #endif |
60 | 64 |
61 // static | 65 // static |
62 PluginService* PluginService::GetInstance() { | 66 PluginService* PluginService::GetInstance() { |
63 return Singleton<PluginService>::get(); | 67 return Singleton<PluginService>::get(); |
64 } | 68 } |
65 | 69 |
66 PluginService::PluginService() | 70 PluginService::PluginService() |
67 : ui_locale_( | 71 : ui_locale_( |
68 content::GetContentClient()->browser()->GetApplicationLocale()) { | 72 content::GetContentClient()->browser()->GetApplicationLocale()), |
| 73 filter_(NULL) { |
69 RegisterPepperPlugins(); | 74 RegisterPepperPlugins(); |
70 | 75 |
71 // Load any specified on the command line as well. | 76 // Load any specified on the command line as well. |
72 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 77 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
73 FilePath path = command_line->GetSwitchValuePath(switches::kLoadPlugin); | 78 FilePath path = command_line->GetSwitchValuePath(switches::kLoadPlugin); |
74 if (!path.empty()) | 79 if (!path.empty()) |
75 webkit::npapi::PluginList::Singleton()->AddExtraPluginPath(path); | 80 webkit::npapi::PluginList::Singleton()->AddExtraPluginPath(path); |
76 path = command_line->GetSwitchValuePath(switches::kExtraPluginDir); | 81 path = command_line->GetSwitchValuePath(switches::kExtraPluginDir); |
77 if (!path.empty()) | 82 if (!path.empty()) |
78 webkit::npapi::PluginList::Singleton()->AddExtraPluginDir(path); | 83 webkit::npapi::PluginList::Singleton()->AddExtraPluginDir(path); |
79 | 84 |
| 85 #if defined(OS_MACOSX) |
| 86 // We need to know when the browser comes forward so we can bring modal plugin |
| 87 // windows forward too. |
| 88 registrar_.Add(this, content::NOTIFICATION_APP_ACTIVATED, |
| 89 NotificationService::AllSources()); |
| 90 #endif |
| 91 } |
| 92 |
| 93 PluginService::~PluginService() { |
| 94 #if defined(OS_WIN) |
| 95 // Release the events since they're owned by RegKey, not WaitableEvent. |
| 96 hkcu_watcher_.StopWatching(); |
| 97 hklm_watcher_.StopWatching(); |
| 98 if (hkcu_event_.get()) |
| 99 hkcu_event_->Release(); |
| 100 if (hklm_event_.get()) |
| 101 hklm_event_->Release(); |
| 102 #endif |
| 103 } |
| 104 |
| 105 void PluginService::StartWatchingPlugins() { |
80 // Start watching for changes in the plugin list. This means watching | 106 // Start watching for changes in the plugin list. This means watching |
81 // for changes in the Windows registry keys and on both Windows and POSIX | 107 // for changes in the Windows registry keys and on both Windows and POSIX |
82 // watch for changes in the paths that are expected to contain plugins. | 108 // watch for changes in the paths that are expected to contain plugins. |
83 #if defined(OS_WIN) | 109 #if defined(OS_WIN) |
84 if (hkcu_key_.Create(HKEY_CURRENT_USER, | 110 if (hkcu_key_.Create(HKEY_CURRENT_USER, |
85 webkit::npapi::kRegistryMozillaPlugins, | 111 webkit::npapi::kRegistryMozillaPlugins, |
86 KEY_NOTIFY) == ERROR_SUCCESS) { | 112 KEY_NOTIFY) == ERROR_SUCCESS) { |
87 if (hkcu_key_.StartWatching() == ERROR_SUCCESS) { | 113 if (hkcu_key_.StartWatching() == ERROR_SUCCESS) { |
88 hkcu_event_.reset(new base::WaitableEvent(hkcu_key_.watch_event())); | 114 hkcu_event_.reset(new base::WaitableEvent(hkcu_key_.watch_event())); |
89 hkcu_watcher_.StartWatching(hkcu_event_.get(), this); | 115 hkcu_watcher_.StartWatching(hkcu_event_.get(), this); |
90 } | 116 } |
91 } | 117 } |
92 if (hklm_key_.Create(HKEY_LOCAL_MACHINE, | 118 if (hklm_key_.Create(HKEY_LOCAL_MACHINE, |
93 webkit::npapi::kRegistryMozillaPlugins, | 119 webkit::npapi::kRegistryMozillaPlugins, |
94 KEY_NOTIFY) == ERROR_SUCCESS) { | 120 KEY_NOTIFY) == ERROR_SUCCESS) { |
95 if (hklm_key_.StartWatching() == ERROR_SUCCESS) { | 121 if (hklm_key_.StartWatching() == ERROR_SUCCESS) { |
96 hklm_event_.reset(new base::WaitableEvent(hklm_key_.watch_event())); | 122 hklm_event_.reset(new base::WaitableEvent(hklm_key_.watch_event())); |
97 hklm_watcher_.StartWatching(hklm_event_.get(), this); | 123 hklm_watcher_.StartWatching(hklm_event_.get(), this); |
98 } | 124 } |
99 } | 125 } |
100 #elif defined(OS_MACOSX) | 126 #elif defined(OS_POSIX) && !defined(OS_MACOSX) |
101 // We need to know when the browser comes forward so we can bring modal plugin | |
102 // windows forward too. | |
103 registrar_.Add(this, content::NOTIFICATION_APP_ACTIVATED, | |
104 NotificationService::AllSources()); | |
105 #elif defined(OS_POSIX) | |
106 // The FilePathWatcher produces too many false positives on MacOS (access time | 127 // The FilePathWatcher produces too many false positives on MacOS (access time |
107 // updates?) which will lead to enforcing updates of the plugins way too often. | 128 // updates?) which will lead to enforcing updates of the plugins way too often. |
108 // On ChromeOS the user can't install plugins anyway and on Windows all | 129 // On ChromeOS the user can't install plugins anyway and on Windows all |
109 // important plugins register themselves in the registry so no need to do that. | 130 // important plugins register themselves in the registry so no need to do that. |
110 file_watcher_delegate_ = new PluginDirWatcherDelegate(); | 131 file_watcher_delegate_ = new PluginDirWatcherDelegate(); |
111 // Get the list of all paths for registering the FilePathWatchers | 132 // Get the list of all paths for registering the FilePathWatchers |
112 // that will track and if needed reload the list of plugins on runtime. | 133 // that will track and if needed reload the list of plugins on runtime. |
113 std::vector<FilePath> plugin_dirs; | 134 std::vector<FilePath> plugin_dirs; |
114 webkit::npapi::PluginList::Singleton()->GetPluginDirectories( | 135 webkit::npapi::PluginList::Singleton()->GetPluginDirectories( |
115 &plugin_dirs); | 136 &plugin_dirs); |
116 | 137 |
117 for (size_t i = 0; i < plugin_dirs.size(); ++i) { | 138 for (size_t i = 0; i < plugin_dirs.size(); ++i) { |
118 // FilePathWatcher can not handle non-absolute paths under windows. | 139 // FilePathWatcher can not handle non-absolute paths under windows. |
119 // We don't watch for file changes in windows now but if this should ever | 140 // We don't watch for file changes in windows now but if this should ever |
120 // be extended to Windows these lines might save some time of debugging. | 141 // be extended to Windows these lines might save some time of debugging. |
121 #if defined(OS_WIN) | 142 #if defined(OS_WIN) |
122 if (!plugin_dirs[i].IsAbsolute()) | 143 if (!plugin_dirs[i].IsAbsolute()) |
123 continue; | 144 continue; |
124 #endif | 145 #endif |
125 FilePathWatcher* watcher = new FilePathWatcher(); | 146 FilePathWatcher* watcher = new FilePathWatcher(); |
126 VLOG(1) << "Watching for changes in: " << plugin_dirs[i].value(); | 147 VLOG(1) << "Watching for changes in: " << plugin_dirs[i].value(); |
127 BrowserThread::PostTask( | 148 BrowserThread::PostTask( |
128 BrowserThread::FILE, FROM_HERE, | 149 BrowserThread::FILE, FROM_HERE, |
129 NewRunnableFunction( | 150 NewRunnableFunction( |
130 &PluginService::RegisterFilePathWatcher, | 151 &PluginService::RegisterFilePathWatcher, |
131 watcher, plugin_dirs[i], file_watcher_delegate_)); | 152 watcher, plugin_dirs[i], file_watcher_delegate_)); |
132 file_watchers_.push_back(watcher); | 153 file_watchers_.push_back(watcher); |
133 } | 154 } |
134 #endif | 155 #endif |
135 registrar_.Add(this, content::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, | |
136 NotificationService::AllSources()); | |
137 registrar_.Add(this, | |
138 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | |
139 NotificationService::AllSources()); | |
140 } | |
141 | |
142 PluginService::~PluginService() { | |
143 #if defined(OS_WIN) | |
144 // Release the events since they're owned by RegKey, not WaitableEvent. | |
145 hkcu_watcher_.StopWatching(); | |
146 hklm_watcher_.StopWatching(); | |
147 if (hkcu_event_.get()) | |
148 hkcu_event_->Release(); | |
149 if (hklm_event_.get()) | |
150 hklm_event_->Release(); | |
151 #endif | |
152 } | 156 } |
153 | 157 |
154 const std::string& PluginService::GetUILocale() { | 158 const std::string& PluginService::GetUILocale() { |
155 return ui_locale_; | 159 return ui_locale_; |
156 } | 160 } |
157 | 161 |
158 PluginProcessHost* PluginService::FindNpapiPluginProcess( | 162 PluginProcessHost* PluginService::FindNpapiPluginProcess( |
159 const FilePath& plugin_path) { | 163 const FilePath& plugin_path) { |
160 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 164 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
161 | 165 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 NOTREACHED(); // Init is not expected to fail. | 275 NOTREACHED(); // Init is not expected to fail. |
272 return NULL; | 276 return NULL; |
273 } | 277 } |
274 return new_host.release(); | 278 return new_host.release(); |
275 } | 279 } |
276 | 280 |
277 void PluginService::OpenChannelToNpapiPlugin( | 281 void PluginService::OpenChannelToNpapiPlugin( |
278 int render_process_id, | 282 int render_process_id, |
279 int render_view_id, | 283 int render_view_id, |
280 const GURL& url, | 284 const GURL& url, |
| 285 const GURL& page_url, |
281 const std::string& mime_type, | 286 const std::string& mime_type, |
282 PluginProcessHost::Client* client) { | 287 PluginProcessHost::Client* client) { |
283 // The PluginList::GetPluginInfo may need to load the plugins. Don't do it on | 288 // The PluginList::GetPluginInfo may need to load the plugins. Don't do it on |
284 // the IO thread. | 289 // the IO thread. |
285 BrowserThread::PostTask( | 290 BrowserThread::PostTask( |
286 BrowserThread::FILE, FROM_HERE, | 291 BrowserThread::FILE, FROM_HERE, |
287 NewRunnableMethod( | 292 NewRunnableMethod( |
288 this, &PluginService::GetAllowedPluginForOpenChannelToPlugin, | 293 this, &PluginService::GetAllowedPluginForOpenChannelToPlugin, |
289 render_process_id, render_view_id, url, mime_type, client)); | 294 render_process_id, render_view_id, url, page_url, mime_type, |
| 295 client)); |
290 } | 296 } |
291 | 297 |
292 void PluginService::OpenChannelToPpapiPlugin( | 298 void PluginService::OpenChannelToPpapiPlugin( |
293 const FilePath& path, | 299 const FilePath& path, |
294 PpapiPluginProcessHost::Client* client) { | 300 PpapiPluginProcessHost::Client* client) { |
295 PpapiPluginProcessHost* plugin_host = FindOrStartPpapiPluginProcess( | 301 PpapiPluginProcessHost* plugin_host = FindOrStartPpapiPluginProcess( |
296 path, client); | 302 path, client); |
297 if (plugin_host) | 303 if (plugin_host) |
298 plugin_host->OpenChannelToPlugin(client); | 304 plugin_host->OpenChannelToPlugin(client); |
299 else // Send error. | 305 else // Send error. |
300 client->OnChannelOpened(base::kNullProcessHandle, IPC::ChannelHandle()); | 306 client->OnChannelOpened(base::kNullProcessHandle, IPC::ChannelHandle()); |
301 } | 307 } |
302 | 308 |
303 void PluginService::OpenChannelToPpapiBroker( | 309 void PluginService::OpenChannelToPpapiBroker( |
304 const FilePath& path, | 310 const FilePath& path, |
305 PpapiBrokerProcessHost::Client* client) { | 311 PpapiBrokerProcessHost::Client* client) { |
306 PpapiBrokerProcessHost* plugin_host = FindOrStartPpapiBrokerProcess(path); | 312 PpapiBrokerProcessHost* plugin_host = FindOrStartPpapiBrokerProcess(path); |
307 if (plugin_host) | 313 if (plugin_host) |
308 plugin_host->OpenChannelToPpapiBroker(client); | 314 plugin_host->OpenChannelToPpapiBroker(client); |
309 else // Send error. | 315 else // Send error. |
310 client->OnChannelOpened(base::kNullProcessHandle, IPC::ChannelHandle()); | 316 client->OnChannelOpened(base::kNullProcessHandle, IPC::ChannelHandle()); |
311 } | 317 } |
312 | 318 |
313 void PluginService::GetAllowedPluginForOpenChannelToPlugin( | 319 void PluginService::GetAllowedPluginForOpenChannelToPlugin( |
314 int render_process_id, | 320 int render_process_id, |
315 int render_view_id, | 321 int render_view_id, |
316 const GURL& url, | 322 const GURL& url, |
| 323 const GURL& page_url, |
317 const std::string& mime_type, | 324 const std::string& mime_type, |
318 PluginProcessHost::Client* client) { | 325 PluginProcessHost::Client* client) { |
319 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 326 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
320 webkit::WebPluginInfo info; | 327 webkit::WebPluginInfo info; |
| 328 bool allow_wildcard = true; |
321 bool found = GetPluginInfo( | 329 bool found = GetPluginInfo( |
322 render_process_id, render_view_id, url, mime_type, &info, NULL); | 330 render_process_id, render_view_id, client->GetResourceContext(), |
| 331 url, page_url, mime_type, allow_wildcard, |
| 332 NULL, &info, NULL); |
323 FilePath plugin_path; | 333 FilePath plugin_path; |
324 if (found) | 334 if (found) |
325 plugin_path = FilePath(info.path); | 335 plugin_path = info.path; |
326 | 336 |
327 // Now we jump back to the IO thread to finish opening the channel. | 337 // Now we jump back to the IO thread to finish opening the channel. |
328 BrowserThread::PostTask( | 338 BrowserThread::PostTask( |
329 BrowserThread::IO, FROM_HERE, | 339 BrowserThread::IO, FROM_HERE, |
330 NewRunnableMethod( | 340 NewRunnableMethod( |
331 this, &PluginService::FinishOpenChannelToPlugin, | 341 this, &PluginService::FinishOpenChannelToPlugin, |
332 plugin_path, client)); | 342 plugin_path, client)); |
333 } | 343 } |
334 | 344 |
335 void PluginService::FinishOpenChannelToPlugin( | 345 void PluginService::FinishOpenChannelToPlugin( |
336 const FilePath& plugin_path, | 346 const FilePath& plugin_path, |
337 PluginProcessHost::Client* client) { | 347 PluginProcessHost::Client* client) { |
338 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 348 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
339 | 349 |
340 PluginProcessHost* plugin_host = FindOrStartNpapiPluginProcess(plugin_path); | 350 PluginProcessHost* plugin_host = FindOrStartNpapiPluginProcess(plugin_path); |
341 if (plugin_host) | 351 if (plugin_host) |
342 plugin_host->OpenChannelToPlugin(client); | 352 plugin_host->OpenChannelToPlugin(client); |
343 else | 353 else |
344 client->OnError(); | 354 client->OnError(); |
345 } | 355 } |
346 | 356 |
347 bool PluginService::GetPluginInfo(int render_process_id, | 357 bool PluginService::GetPluginInfo(int render_process_id, |
348 int render_view_id, | 358 int render_view_id, |
| 359 const content::ResourceContext& context, |
349 const GURL& url, | 360 const GURL& url, |
| 361 const GURL& page_url, |
350 const std::string& mime_type, | 362 const std::string& mime_type, |
| 363 bool allow_wildcard, |
| 364 bool* use_stale, |
351 webkit::WebPluginInfo* info, | 365 webkit::WebPluginInfo* info, |
352 std::string* actual_mime_type) { | 366 std::string* actual_mime_type) { |
| 367 webkit::npapi::PluginList* plugin_list = |
| 368 webkit::npapi::PluginList::Singleton(); |
353 // GetPluginInfoArray may need to load the plugins, so we need to be | 369 // GetPluginInfoArray may need to load the plugins, so we need to be |
354 // on the FILE thread. | 370 // on the FILE thread. |
355 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 371 DCHECK(use_stale || BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
356 { | |
357 base::AutoLock auto_lock(overridden_plugins_lock_); | |
358 for (size_t i = 0; i < overridden_plugins_.size(); ++i) { | |
359 if (overridden_plugins_[i].render_process_id == render_process_id && | |
360 overridden_plugins_[i].render_view_id == render_view_id && | |
361 (overridden_plugins_[i].url == url || | |
362 overridden_plugins_[i].url.is_empty())) { | |
363 if (actual_mime_type) | |
364 *actual_mime_type = mime_type; | |
365 *info = overridden_plugins_[i].plugin; | |
366 return true; | |
367 } | |
368 } | |
369 } | |
370 bool allow_wildcard = true; | |
371 std::vector<webkit::WebPluginInfo> plugins; | 372 std::vector<webkit::WebPluginInfo> plugins; |
372 std::vector<std::string> mime_types; | 373 std::vector<std::string> mime_types; |
373 webkit::npapi::PluginList::Singleton()->GetPluginInfoArray( | 374 plugin_list->GetPluginInfoArray( |
374 url, mime_type, allow_wildcard, NULL, &plugins, &mime_types); | 375 url, mime_type, allow_wildcard, use_stale, &plugins, &mime_types); |
| 376 if (plugins.size() > 1 && |
| 377 plugins.back().path == |
| 378 FilePath(webkit::npapi::kDefaultPluginLibraryName)) { |
| 379 // If there is at least one plug-in handling the required MIME type (apart |
| 380 // from the default plug-in), we don't need the default plug-in. |
| 381 plugins.pop_back(); |
| 382 } |
| 383 |
375 for (size_t i = 0; i < plugins.size(); ++i) { | 384 for (size_t i = 0; i < plugins.size(); ++i) { |
376 if (webkit::IsPluginEnabled(plugins[i])) { | 385 if (!filter_ || filter_->ShouldUsePlugin(render_process_id, |
| 386 render_view_id, |
| 387 &context, |
| 388 url, |
| 389 page_url, |
| 390 &plugins[i])) { |
377 *info = plugins[i]; | 391 *info = plugins[i]; |
378 if (actual_mime_type) | 392 if (actual_mime_type) |
379 *actual_mime_type = mime_types[i]; | 393 *actual_mime_type = mime_types[i]; |
380 return true; | 394 return true; |
381 } | 395 } |
382 } | 396 } |
383 return false; | 397 return false; |
384 } | 398 } |
385 | 399 |
| 400 void PluginService::GetPlugins( |
| 401 const content::ResourceContext& context, |
| 402 std::vector<webkit::WebPluginInfo>* plugins) { |
| 403 // GetPlugins may need to load the plugins, so we need to be |
| 404 // on the FILE thread. |
| 405 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 406 webkit::npapi::PluginList* plugin_list = |
| 407 webkit::npapi::PluginList::Singleton(); |
| 408 std::vector<webkit::WebPluginInfo> all_plugins; |
| 409 plugin_list->GetPlugins(&all_plugins); |
| 410 |
| 411 int child_process_id = -1; |
| 412 int routing_id = MSG_ROUTING_NONE; |
| 413 for (size_t i = 0; i < all_plugins.size(); ++i) { |
| 414 if (!filter_ || filter_->ShouldUsePlugin(child_process_id, |
| 415 routing_id, |
| 416 &context, |
| 417 GURL(), |
| 418 GURL(), |
| 419 &all_plugins[i])) { |
| 420 plugins->push_back(all_plugins[i]); |
| 421 } |
| 422 } |
| 423 } |
| 424 |
386 void PluginService::OnWaitableEventSignaled( | 425 void PluginService::OnWaitableEventSignaled( |
387 base::WaitableEvent* waitable_event) { | 426 base::WaitableEvent* waitable_event) { |
388 #if defined(OS_WIN) | 427 #if defined(OS_WIN) |
389 if (waitable_event == hkcu_event_.get()) { | 428 if (waitable_event == hkcu_event_.get()) { |
390 hkcu_key_.StartWatching(); | 429 hkcu_key_.StartWatching(); |
391 } else { | 430 } else { |
392 hklm_key_.StartWatching(); | 431 hklm_key_.StartWatching(); |
393 } | 432 } |
394 | 433 |
395 webkit::npapi::PluginList::Singleton()->RefreshPlugins(); | 434 webkit::npapi::PluginList::Singleton()->RefreshPlugins(); |
396 PurgePluginListCache(true); | 435 PurgePluginListCache(true); |
397 #else | 436 #else |
398 // This event should only get signaled on a Windows machine. | 437 // This event should only get signaled on a Windows machine. |
399 NOTREACHED(); | 438 NOTREACHED(); |
400 #endif // defined(OS_WIN) | 439 #endif // defined(OS_WIN) |
401 } | 440 } |
402 | 441 |
403 void PluginService::Observe(int type, | 442 void PluginService::Observe(int type, |
404 const NotificationSource& source, | 443 const NotificationSource& source, |
405 const NotificationDetails& details) { | 444 const NotificationDetails& details) { |
406 switch (type) { | |
407 #if defined(OS_MACOSX) | 445 #if defined(OS_MACOSX) |
408 case content::NOTIFICATION_APP_ACTIVATED: { | 446 if (type == content::NOTIFICATION_APP_ACTIVATED) { |
409 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 447 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
410 NewRunnableFunction(&NotifyPluginsOfActivation)); | 448 NewRunnableFunction(&NotifyPluginsOfActivation)); |
411 break; | 449 return; |
412 } | 450 } |
413 #endif | 451 #endif |
414 | 452 NOTREACHED(); |
415 case content::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED: { | |
416 webkit::npapi::PluginList::Singleton()->RefreshPlugins(); | |
417 PurgePluginListCache(false); | |
418 break; | |
419 } | |
420 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: { | |
421 int render_process_id = Source<RenderProcessHost>(source).ptr()->id(); | |
422 | |
423 base::AutoLock auto_lock(overridden_plugins_lock_); | |
424 for (size_t i = 0; i < overridden_plugins_.size(); ++i) { | |
425 if (overridden_plugins_[i].render_process_id == render_process_id) { | |
426 overridden_plugins_.erase(overridden_plugins_.begin() + i); | |
427 break; | |
428 } | |
429 } | |
430 break; | |
431 } | |
432 default: | |
433 NOTREACHED(); | |
434 } | |
435 } | |
436 | |
437 void PluginService::OverridePluginForTab(const OverriddenPlugin& plugin) { | |
438 base::AutoLock auto_lock(overridden_plugins_lock_); | |
439 overridden_plugins_.push_back(plugin); | |
440 } | 453 } |
441 | 454 |
442 void PluginService::PurgePluginListCache(bool reload_pages) { | 455 void PluginService::PurgePluginListCache(bool reload_pages) { |
443 for (RenderProcessHost::iterator it = RenderProcessHost::AllHostsIterator(); | 456 for (RenderProcessHost::iterator it = RenderProcessHost::AllHostsIterator(); |
444 !it.IsAtEnd(); it.Advance()) { | 457 !it.IsAtEnd(); it.Advance()) { |
445 it.GetCurrentValue()->Send(new ViewMsg_PurgePluginListCache(reload_pages)); | 458 it.GetCurrentValue()->Send(new ViewMsg_PurgePluginListCache(reload_pages)); |
446 } | 459 } |
447 } | 460 } |
448 | 461 |
449 void PluginService::RestrictPluginToUrl(const FilePath& plugin_path, | |
450 const GURL& url) { | |
451 base::AutoLock auto_lock(restricted_plugin_lock_); | |
452 if (url.is_empty()) { | |
453 restricted_plugin_.erase(plugin_path); | |
454 } else { | |
455 restricted_plugin_[plugin_path] = url; | |
456 } | |
457 } | |
458 | |
459 bool PluginService::PluginAllowedForURL(const FilePath& plugin_path, | |
460 const GURL& url) { | |
461 if (url.is_empty()) | |
462 return true; // Caller wants all plugins. | |
463 | |
464 base::AutoLock auto_lock(restricted_plugin_lock_); | |
465 | |
466 RestrictedPluginMap::iterator it = restricted_plugin_.find(plugin_path); | |
467 if (it == restricted_plugin_.end()) | |
468 return true; // This plugin is not restricted, so it's allowed everywhere. | |
469 | |
470 const GURL& required_url = it->second; | |
471 return (url.scheme() == required_url.scheme() && | |
472 url.host() == required_url.host()); | |
473 } | |
474 | |
475 void PluginService::RegisterPepperPlugins() { | 462 void PluginService::RegisterPepperPlugins() { |
476 // TODO(abarth): It seems like the PepperPluginRegistry should do this work. | 463 // TODO(abarth): It seems like the PepperPluginRegistry should do this work. |
477 PepperPluginRegistry::ComputeList(&ppapi_plugins_); | 464 PepperPluginRegistry::ComputeList(&ppapi_plugins_); |
478 for (size_t i = 0; i < ppapi_plugins_.size(); ++i) { | 465 for (size_t i = 0; i < ppapi_plugins_.size(); ++i) { |
479 webkit::npapi::PluginList::Singleton()->RegisterInternalPlugin( | 466 webkit::npapi::PluginList::Singleton()->RegisterInternalPlugin( |
480 ppapi_plugins_[i].ToWebPluginInfo()); | 467 ppapi_plugins_[i].ToWebPluginInfo()); |
481 } | 468 } |
482 } | 469 } |
483 | 470 |
484 // There should generally be very few plugins so a brute-force search is fine. | 471 // There should generally be very few plugins so a brute-force search is fine. |
(...skipping 27 matching lines...) Expand all Loading... |
512 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 499 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
513 // static | 500 // static |
514 void PluginService::RegisterFilePathWatcher( | 501 void PluginService::RegisterFilePathWatcher( |
515 FilePathWatcher *watcher, | 502 FilePathWatcher *watcher, |
516 const FilePath& path, | 503 const FilePath& path, |
517 FilePathWatcher::Delegate* delegate) { | 504 FilePathWatcher::Delegate* delegate) { |
518 bool result = watcher->Watch(path, delegate); | 505 bool result = watcher->Watch(path, delegate); |
519 DCHECK(result); | 506 DCHECK(result); |
520 } | 507 } |
521 #endif | 508 #endif |
OLD | NEW |