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

Side by Side Diff: content/browser/plugin_service.cc

Issue 9006036: Create an API around PluginService and use it from Chrome. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years 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
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/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/file_path.h" 10 #include "base/file_path.h"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 } 90 }
91 #elif defined(OS_POSIX) && !defined(OS_OPENBSD) 91 #elif defined(OS_POSIX) && !defined(OS_OPENBSD)
92 // Delegate class for monitoring directories. 92 // Delegate class for monitoring directories.
93 class PluginDirWatcherDelegate : public FilePathWatcher::Delegate { 93 class PluginDirWatcherDelegate : public FilePathWatcher::Delegate {
94 virtual void OnFilePathChanged(const FilePath& path) OVERRIDE { 94 virtual void OnFilePathChanged(const FilePath& path) OVERRIDE {
95 VLOG(1) << "Watched path changed: " << path.value(); 95 VLOG(1) << "Watched path changed: " << path.value();
96 // Make the plugin list update itself 96 // Make the plugin list update itself
97 webkit::npapi::PluginList::Singleton()->RefreshPlugins(); 97 webkit::npapi::PluginList::Singleton()->RefreshPlugins();
98 BrowserThread::PostTask( 98 BrowserThread::PostTask(
99 BrowserThread::UI, FROM_HERE, 99 BrowserThread::UI, FROM_HERE,
100 base::Bind(&PluginService::PurgePluginListCache, 100 base::Bind(&content::PluginService::PurgePluginListCache,
101 static_cast<content::BrowserContext*>(NULL), false)); 101 static_cast<content::BrowserContext*>(NULL), false));
102 } 102 }
103 103
104 virtual void OnFilePathError(const FilePath& path) OVERRIDE { 104 virtual void OnFilePathError(const FilePath& path) OVERRIDE {
105 // TODO(pastarmovj): Add some sensible error handling. Maybe silently 105 // TODO(pastarmovj): Add some sensible error handling. Maybe silently
106 // stopping the watcher would be enough. Or possibly restart it. 106 // stopping the watcher would be enough. Or possibly restart it.
107 NOTREACHED(); 107 NOTREACHED();
108 } 108 }
109 }; 109 };
110 #endif 110 #endif
111 111
112 namespace content {
113 // static
114 PluginService* PluginService::GetInstance() {
115 return ::PluginService::GetInstance();
116 }
117
118 void PluginService::PurgePluginListCache(BrowserContext* browser_context,
119 bool reload_pages) {
120 for (RenderProcessHost::iterator it = RenderProcessHost::AllHostsIterator();
121 !it.IsAtEnd(); it.Advance()) {
122 RenderProcessHost* host = it.GetCurrentValue();
123 if (!browser_context || host->GetBrowserContext() == browser_context)
124 host->Send(new ViewMsg_PurgePluginListCache(reload_pages));
125 }
126 }
127
128 } // namespace content
129
112 // static 130 // static
113 PluginService* PluginService::GetInstance() { 131 PluginService* PluginService::GetInstance() {
114 return Singleton<PluginService>::get(); 132 return Singleton<PluginService>::get();
115 } 133 }
116 134
117 PluginService::PluginService() 135 PluginService::PluginService()
118 : plugin_list_(NULL), 136 : plugin_list_(NULL),
119 ui_locale_( 137 ui_locale_(
120 content::GetContentClient()->browser()->GetApplicationLocale()), 138 content::GetContentClient()->browser()->GetApplicationLocale()),
121 filter_(NULL) { 139 filter_(NULL) {
(...skipping 10 matching lines...) Expand all
132 hklm_event_->Release(); 150 hklm_event_->Release();
133 #endif 151 #endif
134 // Make sure no plugin channel requests have been leaked. 152 // Make sure no plugin channel requests have been leaked.
135 DCHECK(pending_plugin_clients_.empty()); 153 DCHECK(pending_plugin_clients_.empty());
136 } 154 }
137 155
138 void PluginService::Init() { 156 void PluginService::Init() {
139 if (!plugin_list_) 157 if (!plugin_list_)
140 plugin_list_ = webkit::npapi::PluginList::Singleton(); 158 plugin_list_ = webkit::npapi::PluginList::Singleton();
141 159
142 plugin_list()->set_will_load_plugins_callback( 160 plugin_list_->set_will_load_plugins_callback(
143 base::Bind(&WillLoadPluginsCallback)); 161 base::Bind(&WillLoadPluginsCallback));
144 162
145 RegisterPepperPlugins(); 163 RegisterPepperPlugins();
146 164
147 content::GetContentClient()->AddNPAPIPlugins(plugin_list()); 165 content::GetContentClient()->AddNPAPIPlugins(plugin_list_);
148 166
149 // Load any specified on the command line as well. 167 // Load any specified on the command line as well.
150 const CommandLine* command_line = CommandLine::ForCurrentProcess(); 168 const CommandLine* command_line = CommandLine::ForCurrentProcess();
151 FilePath path = command_line->GetSwitchValuePath(switches::kLoadPlugin); 169 FilePath path = command_line->GetSwitchValuePath(switches::kLoadPlugin);
152 if (!path.empty()) 170 if (!path.empty())
153 AddExtraPluginPath(path); 171 AddExtraPluginPath(path);
154 path = command_line->GetSwitchValuePath(switches::kExtraPluginDir); 172 path = command_line->GetSwitchValuePath(switches::kExtraPluginDir);
155 if (!path.empty()) 173 if (!path.empty())
156 plugin_list()->AddExtraPluginDir(path); 174 plugin_list_->AddExtraPluginDir(path);
157 175
158 #if defined(OS_MACOSX) 176 #if defined(OS_MACOSX)
159 // We need to know when the browser comes forward so we can bring modal plugin 177 // We need to know when the browser comes forward so we can bring modal plugin
160 // windows forward too. 178 // windows forward too.
161 registrar_.Add(this, content::NOTIFICATION_APP_ACTIVATED, 179 registrar_.Add(this, content::NOTIFICATION_APP_ACTIVATED,
162 content::NotificationService::AllSources()); 180 content::NotificationService::AllSources());
163 #endif 181 #endif
164 } 182 }
165 183
166 void PluginService::StartWatchingPlugins() { 184 void PluginService::StartWatchingPlugins() {
(...skipping 19 matching lines...) Expand all
186 } 204 }
187 #elif defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_OPENBSD) 205 #elif defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_OPENBSD)
188 // The FilePathWatcher produces too many false positives on MacOS (access time 206 // The FilePathWatcher produces too many false positives on MacOS (access time
189 // updates?) which will lead to enforcing updates of the plugins way too often. 207 // updates?) which will lead to enforcing updates of the plugins way too often.
190 // On ChromeOS the user can't install plugins anyway and on Windows all 208 // On ChromeOS the user can't install plugins anyway and on Windows all
191 // important plugins register themselves in the registry so no need to do that. 209 // important plugins register themselves in the registry so no need to do that.
192 file_watcher_delegate_ = new PluginDirWatcherDelegate(); 210 file_watcher_delegate_ = new PluginDirWatcherDelegate();
193 // Get the list of all paths for registering the FilePathWatchers 211 // Get the list of all paths for registering the FilePathWatchers
194 // that will track and if needed reload the list of plugins on runtime. 212 // that will track and if needed reload the list of plugins on runtime.
195 std::vector<FilePath> plugin_dirs; 213 std::vector<FilePath> plugin_dirs;
196 plugin_list()->GetPluginDirectories(&plugin_dirs); 214 plugin_list_->GetPluginDirectories(&plugin_dirs);
197 215
198 for (size_t i = 0; i < plugin_dirs.size(); ++i) { 216 for (size_t i = 0; i < plugin_dirs.size(); ++i) {
199 // FilePathWatcher can not handle non-absolute paths under windows. 217 // FilePathWatcher can not handle non-absolute paths under windows.
200 // We don't watch for file changes in windows now but if this should ever 218 // We don't watch for file changes in windows now but if this should ever
201 // be extended to Windows these lines might save some time of debugging. 219 // be extended to Windows these lines might save some time of debugging.
202 #if defined(OS_WIN) 220 #if defined(OS_WIN)
203 if (!plugin_dirs[i].IsAbsolute()) 221 if (!plugin_dirs[i].IsAbsolute())
204 continue; 222 continue;
205 #endif 223 #endif
206 FilePathWatcher* watcher = new FilePathWatcher(); 224 FilePathWatcher* watcher = new FilePathWatcher();
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 } 449 }
432 } 450 }
433 451
434 bool PluginService::GetPluginInfoArray( 452 bool PluginService::GetPluginInfoArray(
435 const GURL& url, 453 const GURL& url,
436 const std::string& mime_type, 454 const std::string& mime_type,
437 bool allow_wildcard, 455 bool allow_wildcard,
438 std::vector<webkit::WebPluginInfo>* plugins, 456 std::vector<webkit::WebPluginInfo>* plugins,
439 std::vector<std::string>* actual_mime_types) { 457 std::vector<std::string>* actual_mime_types) {
440 bool use_stale = false; 458 bool use_stale = false;
441 plugin_list()->GetPluginInfoArray(url, mime_type, allow_wildcard, 459 plugin_list_->GetPluginInfoArray(url, mime_type, allow_wildcard,
442 &use_stale, plugins, actual_mime_types); 460 &use_stale, plugins, actual_mime_types);
443 return use_stale; 461 return use_stale;
444 } 462 }
445 463
446 bool PluginService::GetPluginInfo(int render_process_id, 464 bool PluginService::GetPluginInfo(int render_process_id,
447 int render_view_id, 465 int render_view_id,
448 const content::ResourceContext& context, 466 const content::ResourceContext& context,
449 const GURL& url, 467 const GURL& url,
450 const GURL& page_url, 468 const GURL& page_url,
451 const std::string& mime_type, 469 const std::string& mime_type,
452 bool allow_wildcard, 470 bool allow_wildcard,
(...skipping 26 matching lines...) Expand all
479 *actual_mime_type = mime_types[i]; 497 *actual_mime_type = mime_types[i];
480 return true; 498 return true;
481 } 499 }
482 } 500 }
483 return false; 501 return false;
484 } 502 }
485 503
486 bool PluginService::GetPluginInfoByPath(const FilePath& plugin_path, 504 bool PluginService::GetPluginInfoByPath(const FilePath& plugin_path,
487 webkit::WebPluginInfo* info) { 505 webkit::WebPluginInfo* info) {
488 std::vector<webkit::WebPluginInfo> plugins; 506 std::vector<webkit::WebPluginInfo> plugins;
489 plugin_list()->GetPluginsIfNoRefreshNeeded(&plugins); 507 plugin_list_->GetPluginsIfNoRefreshNeeded(&plugins);
490 508
491 for (std::vector<webkit::WebPluginInfo>::iterator it = plugins.begin(); 509 for (std::vector<webkit::WebPluginInfo>::iterator it = plugins.begin();
492 it != plugins.end(); 510 it != plugins.end();
493 ++it) { 511 ++it) {
494 if (it->path == plugin_path) { 512 if (it->path == plugin_path) {
495 *info = *it; 513 *info = *it;
496 return true; 514 return true;
497 } 515 }
498 } 516 }
499 517
500 return false; 518 return false;
501 } 519 }
502 520
503 void PluginService::GetPlugins(const GetPluginsCallback& callback) { 521 void PluginService::GetPlugins(const GetPluginsCallback& callback) {
504 scoped_refptr<base::MessageLoopProxy> target_loop( 522 scoped_refptr<base::MessageLoopProxy> target_loop(
505 MessageLoop::current()->message_loop_proxy()); 523 MessageLoop::current()->message_loop_proxy());
506 524
507 #if defined(OS_WIN) 525 #if defined(OS_WIN)
508 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 526 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
509 base::Bind(&PluginService::GetPluginsInternal, base::Unretained(this), 527 base::Bind(&PluginService::GetPluginsInternal, base::Unretained(this),
510 target_loop, callback)); 528 target_loop, callback));
511 #else 529 #else
512 std::vector<webkit::WebPluginInfo> cached_plugins; 530 std::vector<webkit::WebPluginInfo> cached_plugins;
513 if (plugin_list()->GetPluginsIfNoRefreshNeeded(&cached_plugins)) { 531 if (plugin_list_->GetPluginsIfNoRefreshNeeded(&cached_plugins)) {
514 // Can't assume the caller is reentrant. 532 // Can't assume the caller is reentrant.
515 target_loop->PostTask(FROM_HERE, 533 target_loop->PostTask(FROM_HERE,
516 base::Bind(&RunGetPluginsCallback, callback, cached_plugins)); 534 base::Bind(&RunGetPluginsCallback, callback, cached_plugins));
517 } else { 535 } else {
518 // If we switch back to loading plugins in process, then we need to make 536 // If we switch back to loading plugins in process, then we need to make
519 // sure g_thread_init() gets called since plugins may call glib at load. 537 // sure g_thread_init() gets called since plugins may call glib at load.
520 if (!plugin_loader_.get()) 538 if (!plugin_loader_.get())
521 plugin_loader_ = new PluginLoaderPosix; 539 plugin_loader_ = new PluginLoaderPosix;
522 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 540 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
523 base::Bind(&PluginLoaderPosix::LoadPlugins, plugin_loader_, 541 base::Bind(&PluginLoaderPosix::LoadPlugins, plugin_loader_,
524 target_loop, callback)); 542 target_loop, callback));
525 } 543 }
526 #endif 544 #endif
527 } 545 }
528 546
529 void PluginService::GetPluginGroups(const GetPluginGroupsCallback& callback) { 547 void PluginService::GetPluginGroups(const GetPluginGroupsCallback& callback) {
530 GetPlugins(base::Bind(&GetPluginsForGroupsCallback, callback)); 548 GetPlugins(base::Bind(&GetPluginsForGroupsCallback, callback));
531 } 549 }
532 550
533 void PluginService::GetPluginsInternal( 551 void PluginService::GetPluginsInternal(
534 base::MessageLoopProxy* target_loop, 552 base::MessageLoopProxy* target_loop,
535 const PluginService::GetPluginsCallback& callback) { 553 const PluginService::GetPluginsCallback& callback) {
536 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 554 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
537 555
538 std::vector<webkit::WebPluginInfo> plugins; 556 std::vector<webkit::WebPluginInfo> plugins;
539 plugin_list()->GetPlugins(&plugins); 557 plugin_list_->GetPlugins(&plugins);
540 558
541 target_loop->PostTask(FROM_HERE, 559 target_loop->PostTask(FROM_HERE,
542 base::Bind(&RunGetPluginsCallback, callback, plugins)); 560 base::Bind(&RunGetPluginsCallback, callback, plugins));
543 } 561 }
544 562
545 void PluginService::OnWaitableEventSignaled( 563 void PluginService::OnWaitableEventSignaled(
546 base::WaitableEvent* waitable_event) { 564 base::WaitableEvent* waitable_event) {
547 #if defined(OS_WIN) 565 #if defined(OS_WIN)
548 if (waitable_event == hkcu_event_.get()) { 566 if (waitable_event == hkcu_event_.get()) {
549 hkcu_key_.StartWatching(); 567 hkcu_key_.StartWatching();
550 } else { 568 } else {
551 hklm_key_.StartWatching(); 569 hklm_key_.StartWatching();
552 } 570 }
553 571
554 plugin_list()->RefreshPlugins(); 572 plugin_list_->RefreshPlugins();
555 PurgePluginListCache(NULL, false); 573 PurgePluginListCache(NULL, false);
556 #else 574 #else
557 // This event should only get signaled on a Windows machine. 575 // This event should only get signaled on a Windows machine.
558 NOTREACHED(); 576 NOTREACHED();
559 #endif // defined(OS_WIN) 577 #endif // defined(OS_WIN)
560 } 578 }
561 579
562 void PluginService::Observe(int type, 580 void PluginService::Observe(int type,
563 const content::NotificationSource& source, 581 const content::NotificationSource& source,
564 const content::NotificationDetails& details) { 582 const content::NotificationDetails& details) {
565 #if defined(OS_MACOSX) 583 #if defined(OS_MACOSX)
566 if (type == content::NOTIFICATION_APP_ACTIVATED) { 584 if (type == content::NOTIFICATION_APP_ACTIVATED) {
567 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 585 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
568 base::Bind(&NotifyPluginsOfActivation)); 586 base::Bind(&NotifyPluginsOfActivation));
569 return; 587 return;
570 } 588 }
571 #endif 589 #endif
572 NOTREACHED(); 590 NOTREACHED();
573 } 591 }
574 592
575 void PluginService::PurgePluginListCache(
576 content::BrowserContext* browser_context,
577 bool reload_pages) {
578 for (content::RenderProcessHost::iterator it =
579 content::RenderProcessHost::AllHostsIterator();
580 !it.IsAtEnd(); it.Advance()) {
581 content::RenderProcessHost* host = it.GetCurrentValue();
582 if (!browser_context || host->GetBrowserContext() == browser_context)
583 host->Send(new ViewMsg_PurgePluginListCache(reload_pages));
584 }
585 }
586
587 void PluginService::RegisterPepperPlugins() { 593 void PluginService::RegisterPepperPlugins() {
588 // TODO(abarth): It seems like the PepperPluginRegistry should do this work. 594 // TODO(abarth): It seems like the PepperPluginRegistry should do this work.
589 PepperPluginRegistry::ComputeList(&ppapi_plugins_); 595 PepperPluginRegistry::ComputeList(&ppapi_plugins_);
590 for (size_t i = 0; i < ppapi_plugins_.size(); ++i) { 596 for (size_t i = 0; i < ppapi_plugins_.size(); ++i) {
591 RegisterInternalPlugin(ppapi_plugins_[i].ToWebPluginInfo()); 597 RegisterInternalPlugin(ppapi_plugins_[i].ToWebPluginInfo());
592 } 598 }
593 } 599 }
594 600
595 // There should generally be very few plugins so a brute-force search is fine. 601 // There should generally be very few plugins so a brute-force search is fine.
596 content::PepperPluginInfo* PluginService::GetRegisteredPpapiPluginInfo( 602 content::PepperPluginInfo* PluginService::GetRegisteredPpapiPluginInfo(
(...skipping 26 matching lines...) Expand all
623 // static 629 // static
624 void PluginService::RegisterFilePathWatcher( 630 void PluginService::RegisterFilePathWatcher(
625 FilePathWatcher *watcher, 631 FilePathWatcher *watcher,
626 const FilePath& path, 632 const FilePath& path,
627 FilePathWatcher::Delegate* delegate) { 633 FilePathWatcher::Delegate* delegate) {
628 bool result = watcher->Watch(path, delegate); 634 bool result = watcher->Watch(path, delegate);
629 DCHECK(result); 635 DCHECK(result);
630 } 636 }
631 #endif 637 #endif
632 638
639 void PluginService::SetFilter(content::PluginServiceFilter* filter) {
640 filter_ = filter;
641 }
642
643 content::PluginServiceFilter* PluginService::GetFilter() {
644 return filter_;
645 }
646
633 void PluginService::RefreshPlugins() { 647 void PluginService::RefreshPlugins() {
634 plugin_list()->RefreshPlugins(); 648 plugin_list_->RefreshPlugins();
635 } 649 }
636 650
637 void PluginService::AddExtraPluginPath(const FilePath& path) { 651 void PluginService::AddExtraPluginPath(const FilePath& path) {
638 plugin_list()->AddExtraPluginPath(path); 652 plugin_list_->AddExtraPluginPath(path);
639 } 653 }
640 654
641 void PluginService::RemoveExtraPluginPath(const FilePath& path) { 655 void PluginService::RemoveExtraPluginPath(const FilePath& path) {
642 plugin_list()->RemoveExtraPluginPath(path); 656 plugin_list_->RemoveExtraPluginPath(path);
643 } 657 }
644 658
645 void PluginService::UnregisterInternalPlugin(const FilePath& path) { 659 void PluginService::UnregisterInternalPlugin(const FilePath& path) {
646 plugin_list()->UnregisterInternalPlugin(path); 660 plugin_list_->UnregisterInternalPlugin(path);
647 } 661 }
648 662
649 void PluginService::SetPluginListForTesting( 663 void PluginService::SetPluginListForTesting(
650 webkit::npapi::PluginList* plugin_list) { 664 webkit::npapi::PluginList* plugin_list) {
651 plugin_list_ = plugin_list; 665 plugin_list_ = plugin_list;
652 } 666 }
653 667
654 void PluginService::RegisterInternalPlugin(const webkit::WebPluginInfo& info) { 668 void PluginService::RegisterInternalPlugin(const webkit::WebPluginInfo& info) {
655 plugin_list()->RegisterInternalPlugin(info); 669 plugin_list_->RegisterInternalPlugin(info);
656 } 670 }
657 671
658 string16 PluginService::GetPluginGroupName(const std::string& plugin_name) { 672 string16 PluginService::GetPluginGroupName(const std::string& plugin_name) {
659 return plugin_list()->GetPluginGroupName(plugin_name); 673 return plugin_list_->GetPluginGroupName(plugin_name);
660 } 674 }
675
676 webkit::npapi::PluginList* PluginService::GetPluginList() {
677 return plugin_list_;
678 }
OLDNEW
« no previous file with comments | « content/browser/plugin_service.h ('k') | content/browser/renderer_host/render_message_filter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698