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

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

Issue 8493026: Revert r108760 / reland r108744, r108753 w/ fix (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rename plugin list accessor to plugin_list() Created 9 years, 1 month 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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 109
110 // static 110 // static
111 PluginService* PluginService::GetInstance() { 111 PluginService* PluginService::GetInstance() {
112 return Singleton<PluginService>::get(); 112 return Singleton<PluginService>::get();
113 } 113 }
114 114
115 PluginService::PluginService() 115 PluginService::PluginService()
116 : ui_locale_( 116 : ui_locale_(
117 content::GetContentClient()->browser()->GetApplicationLocale()), 117 content::GetContentClient()->browser()->GetApplicationLocale()),
118 filter_(NULL) { 118 filter_(NULL) {
119 webkit::npapi::PluginList::Singleton()->set_will_load_plugins_callback( 119 plugin_list()->set_will_load_plugins_callback(
120 base::Bind(&WillLoadPluginsCallback)); 120 base::Bind(&WillLoadPluginsCallback));
121 121
122 RegisterPepperPlugins(); 122 RegisterPepperPlugins();
123 123
124 content::GetContentClient()->AddNPAPIPlugins(plugin_list());
125
124 // Load any specified on the command line as well. 126 // Load any specified on the command line as well.
125 const CommandLine* command_line = CommandLine::ForCurrentProcess(); 127 const CommandLine* command_line = CommandLine::ForCurrentProcess();
126 FilePath path = command_line->GetSwitchValuePath(switches::kLoadPlugin); 128 FilePath path = command_line->GetSwitchValuePath(switches::kLoadPlugin);
127 if (!path.empty()) 129 if (!path.empty())
128 webkit::npapi::PluginList::Singleton()->AddExtraPluginPath(path); 130 AddExtraPluginPath(path);
129 path = command_line->GetSwitchValuePath(switches::kExtraPluginDir); 131 path = command_line->GetSwitchValuePath(switches::kExtraPluginDir);
130 if (!path.empty()) 132 if (!path.empty())
131 webkit::npapi::PluginList::Singleton()->AddExtraPluginDir(path); 133 plugin_list()->AddExtraPluginDir(path);
132 134
133 #if defined(OS_MACOSX) 135 #if defined(OS_MACOSX)
134 // We need to know when the browser comes forward so we can bring modal plugin 136 // We need to know when the browser comes forward so we can bring modal plugin
135 // windows forward too. 137 // windows forward too.
136 registrar_.Add(this, content::NOTIFICATION_APP_ACTIVATED, 138 registrar_.Add(this, content::NOTIFICATION_APP_ACTIVATED,
137 content::NotificationService::AllSources()); 139 content::NotificationService::AllSources());
138 #endif 140 #endif
139 } 141 }
140 142
141 PluginService::~PluginService() { 143 PluginService::~PluginService() {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 } 177 }
176 #elif defined(OS_POSIX) && !defined(OS_MACOSX) 178 #elif defined(OS_POSIX) && !defined(OS_MACOSX)
177 // The FilePathWatcher produces too many false positives on MacOS (access time 179 // The FilePathWatcher produces too many false positives on MacOS (access time
178 // updates?) which will lead to enforcing updates of the plugins way too often. 180 // updates?) which will lead to enforcing updates of the plugins way too often.
179 // On ChromeOS the user can't install plugins anyway and on Windows all 181 // On ChromeOS the user can't install plugins anyway and on Windows all
180 // important plugins register themselves in the registry so no need to do that. 182 // important plugins register themselves in the registry so no need to do that.
181 file_watcher_delegate_ = new PluginDirWatcherDelegate(); 183 file_watcher_delegate_ = new PluginDirWatcherDelegate();
182 // Get the list of all paths for registering the FilePathWatchers 184 // Get the list of all paths for registering the FilePathWatchers
183 // that will track and if needed reload the list of plugins on runtime. 185 // that will track and if needed reload the list of plugins on runtime.
184 std::vector<FilePath> plugin_dirs; 186 std::vector<FilePath> plugin_dirs;
185 webkit::npapi::PluginList::Singleton()->GetPluginDirectories( 187 plugin_list()->GetPluginDirectories(&plugin_dirs);
186 &plugin_dirs);
187 188
188 for (size_t i = 0; i < plugin_dirs.size(); ++i) { 189 for (size_t i = 0; i < plugin_dirs.size(); ++i) {
189 // FilePathWatcher can not handle non-absolute paths under windows. 190 // FilePathWatcher can not handle non-absolute paths under windows.
190 // We don't watch for file changes in windows now but if this should ever 191 // We don't watch for file changes in windows now but if this should ever
191 // be extended to Windows these lines might save some time of debugging. 192 // be extended to Windows these lines might save some time of debugging.
192 #if defined(OS_WIN) 193 #if defined(OS_WIN)
193 if (!plugin_dirs[i].IsAbsolute()) 194 if (!plugin_dirs[i].IsAbsolute())
194 continue; 195 continue;
195 #endif 196 #endif
196 FilePathWatcher* watcher = new FilePathWatcher(); 197 FilePathWatcher* watcher = new FilePathWatcher();
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 } 422 }
422 } 423 }
423 424
424 bool PluginService::GetPluginInfoArray( 425 bool PluginService::GetPluginInfoArray(
425 const GURL& url, 426 const GURL& url,
426 const std::string& mime_type, 427 const std::string& mime_type,
427 bool allow_wildcard, 428 bool allow_wildcard,
428 std::vector<webkit::WebPluginInfo>* plugins, 429 std::vector<webkit::WebPluginInfo>* plugins,
429 std::vector<std::string>* actual_mime_types) { 430 std::vector<std::string>* actual_mime_types) {
430 bool use_stale = false; 431 bool use_stale = false;
431 webkit::npapi::PluginList::Singleton()->GetPluginInfoArray( 432 plugin_list()->GetPluginInfoArray(url, mime_type, allow_wildcard,
432 url, mime_type, allow_wildcard, &use_stale, plugins, actual_mime_types); 433 &use_stale, plugins, actual_mime_types);
433 return use_stale; 434 return use_stale;
434 } 435 }
435 436
436 bool PluginService::GetPluginInfo(int render_process_id, 437 bool PluginService::GetPluginInfo(int render_process_id,
437 int render_view_id, 438 int render_view_id,
438 const content::ResourceContext& context, 439 const content::ResourceContext& context,
439 const GURL& url, 440 const GURL& url,
440 const GURL& page_url, 441 const GURL& page_url,
441 const std::string& mime_type, 442 const std::string& mime_type,
442 bool allow_wildcard, 443 bool allow_wildcard,
(...skipping 26 matching lines...) Expand all
469 *actual_mime_type = mime_types[i]; 470 *actual_mime_type = mime_types[i];
470 return true; 471 return true;
471 } 472 }
472 } 473 }
473 return false; 474 return false;
474 } 475 }
475 476
476 bool PluginService::GetPluginInfoByPath(const FilePath& plugin_path, 477 bool PluginService::GetPluginInfoByPath(const FilePath& plugin_path,
477 webkit::WebPluginInfo* info) { 478 webkit::WebPluginInfo* info) {
478 std::vector<webkit::WebPluginInfo> plugins; 479 std::vector<webkit::WebPluginInfo> plugins;
479 webkit::npapi::PluginList::Singleton()->GetPluginsIfNoRefreshNeeded( 480 plugin_list()->GetPluginsIfNoRefreshNeeded(&plugins);
480 &plugins);
481 481
482 for (std::vector<webkit::WebPluginInfo>::iterator it = plugins.begin(); 482 for (std::vector<webkit::WebPluginInfo>::iterator it = plugins.begin();
483 it != plugins.end(); 483 it != plugins.end();
484 ++it) { 484 ++it) {
485 if (it->path == plugin_path) { 485 if (it->path == plugin_path) {
486 *info = *it; 486 *info = *it;
487 return true; 487 return true;
488 } 488 }
489 } 489 }
490 490
491 return false; 491 return false;
492 } 492 }
493 493
494 void PluginService::RefreshPluginList() {
495 webkit::npapi::PluginList::Singleton()->RefreshPlugins();
496 }
497
498 void PluginService::GetPlugins(const GetPluginsCallback& callback) { 494 void PluginService::GetPlugins(const GetPluginsCallback& callback) {
499 scoped_refptr<base::MessageLoopProxy> target_loop( 495 scoped_refptr<base::MessageLoopProxy> target_loop(
500 MessageLoop::current()->message_loop_proxy()); 496 MessageLoop::current()->message_loop_proxy());
501 497
502 #if defined(OS_WIN) 498 #if defined(OS_WIN)
503 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 499 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
504 base::Bind(&PluginService::GetPluginsInternal, base::Unretained(this), 500 base::Bind(&PluginService::GetPluginsInternal, base::Unretained(this),
505 target_loop, callback)); 501 target_loop, callback));
506 #else 502 #else
507 std::vector<webkit::WebPluginInfo> cached_plugins; 503 std::vector<webkit::WebPluginInfo> cached_plugins;
508 if (webkit::npapi::PluginList::Singleton()->GetPluginsIfNoRefreshNeeded( 504 if (plugin_list()->GetPluginsIfNoRefreshNeeded(&cached_plugins)) {
509 &cached_plugins)) {
510 // Can't assume the caller is reentrant. 505 // Can't assume the caller is reentrant.
511 target_loop->PostTask(FROM_HERE, 506 target_loop->PostTask(FROM_HERE,
512 base::Bind(&RunGetPluginsCallback, callback, cached_plugins)); 507 base::Bind(&RunGetPluginsCallback, callback, cached_plugins));
513 } else { 508 } else {
514 // If we switch back to loading plugins in process, then we need to make 509 // If we switch back to loading plugins in process, then we need to make
515 // sure g_thread_init() gets called since plugins may call glib at load. 510 // sure g_thread_init() gets called since plugins may call glib at load.
516 if (!plugin_loader_.get()) 511 if (!plugin_loader_.get())
517 plugin_loader_ = new PluginLoaderPosix; 512 plugin_loader_ = new PluginLoaderPosix;
518 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 513 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
519 base::Bind(&PluginLoaderPosix::LoadPlugins, plugin_loader_, 514 base::Bind(&PluginLoaderPosix::LoadPlugins, plugin_loader_,
520 target_loop, callback)); 515 target_loop, callback));
521 } 516 }
522 #endif 517 #endif
523 } 518 }
524 519
525 void PluginService::GetPluginGroups(const GetPluginGroupsCallback& callback) { 520 void PluginService::GetPluginGroups(const GetPluginGroupsCallback& callback) {
526 GetPlugins(base::Bind(&GetPluginsForGroupsCallback, callback)); 521 GetPlugins(base::Bind(&GetPluginsForGroupsCallback, callback));
527 } 522 }
528 523
529 void PluginService::GetPluginsInternal( 524 void PluginService::GetPluginsInternal(
530 base::MessageLoopProxy* target_loop, 525 base::MessageLoopProxy* target_loop,
531 const PluginService::GetPluginsCallback& callback) { 526 const PluginService::GetPluginsCallback& callback) {
532 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 527 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
533 528
534 std::vector<webkit::WebPluginInfo> plugins; 529 std::vector<webkit::WebPluginInfo> plugins;
535 webkit::npapi::PluginList::Singleton()->GetPlugins(&plugins); 530 plugin_list()->GetPlugins(&plugins);
536 531
537 target_loop->PostTask(FROM_HERE, 532 target_loop->PostTask(FROM_HERE,
538 base::Bind(&RunGetPluginsCallback, callback, plugins)); 533 base::Bind(&RunGetPluginsCallback, callback, plugins));
539 } 534 }
540 535
541 void PluginService::OnWaitableEventSignaled( 536 void PluginService::OnWaitableEventSignaled(
542 base::WaitableEvent* waitable_event) { 537 base::WaitableEvent* waitable_event) {
543 #if defined(OS_WIN) 538 #if defined(OS_WIN)
544 if (waitable_event == hkcu_event_.get()) { 539 if (waitable_event == hkcu_event_.get()) {
545 hkcu_key_.StartWatching(); 540 hkcu_key_.StartWatching();
546 } else { 541 } else {
547 hklm_key_.StartWatching(); 542 hklm_key_.StartWatching();
548 } 543 }
549 544
550 webkit::npapi::PluginList::Singleton()->RefreshPlugins(); 545 plugin_list()->RefreshPlugins();
551 PurgePluginListCache(NULL, false); 546 PurgePluginListCache(NULL, false);
552 #else 547 #else
553 // This event should only get signaled on a Windows machine. 548 // This event should only get signaled on a Windows machine.
554 NOTREACHED(); 549 NOTREACHED();
555 #endif // defined(OS_WIN) 550 #endif // defined(OS_WIN)
556 } 551 }
557 552
558 void PluginService::Observe(int type, 553 void PluginService::Observe(int type,
559 const content::NotificationSource& source, 554 const content::NotificationSource& source,
560 const content::NotificationDetails& details) { 555 const content::NotificationDetails& details) {
(...skipping 15 matching lines...) Expand all
576 RenderProcessHost* host = it.GetCurrentValue(); 571 RenderProcessHost* host = it.GetCurrentValue();
577 if (!browser_context || host->browser_context() == browser_context) 572 if (!browser_context || host->browser_context() == browser_context)
578 host->Send(new ViewMsg_PurgePluginListCache(reload_pages)); 573 host->Send(new ViewMsg_PurgePluginListCache(reload_pages));
579 } 574 }
580 } 575 }
581 576
582 void PluginService::RegisterPepperPlugins() { 577 void PluginService::RegisterPepperPlugins() {
583 // TODO(abarth): It seems like the PepperPluginRegistry should do this work. 578 // TODO(abarth): It seems like the PepperPluginRegistry should do this work.
584 PepperPluginRegistry::ComputeList(&ppapi_plugins_); 579 PepperPluginRegistry::ComputeList(&ppapi_plugins_);
585 for (size_t i = 0; i < ppapi_plugins_.size(); ++i) { 580 for (size_t i = 0; i < ppapi_plugins_.size(); ++i) {
586 webkit::npapi::PluginList::Singleton()->RegisterInternalPlugin( 581 RegisterInternalPlugin(ppapi_plugins_[i].ToWebPluginInfo());
587 ppapi_plugins_[i].ToWebPluginInfo());
588 } 582 }
589 } 583 }
590 584
591 // There should generally be very few plugins so a brute-force search is fine. 585 // There should generally be very few plugins so a brute-force search is fine.
592 content::PepperPluginInfo* PluginService::GetRegisteredPpapiPluginInfo( 586 content::PepperPluginInfo* PluginService::GetRegisteredPpapiPluginInfo(
593 const FilePath& plugin_path) { 587 const FilePath& plugin_path) {
594 content::PepperPluginInfo* info = NULL; 588 content::PepperPluginInfo* info = NULL;
595 for (size_t i = 0; i < ppapi_plugins_.size(); i++) { 589 for (size_t i = 0; i < ppapi_plugins_.size(); i++) {
596 if (ppapi_plugins_[i].path == plugin_path) { 590 if (ppapi_plugins_[i].path == plugin_path) {
597 info = &ppapi_plugins_[i]; 591 info = &ppapi_plugins_[i];
(...skipping 20 matching lines...) Expand all
618 #if defined(OS_POSIX) && !defined(OS_MACOSX) 612 #if defined(OS_POSIX) && !defined(OS_MACOSX)
619 // static 613 // static
620 void PluginService::RegisterFilePathWatcher( 614 void PluginService::RegisterFilePathWatcher(
621 FilePathWatcher *watcher, 615 FilePathWatcher *watcher,
622 const FilePath& path, 616 const FilePath& path,
623 FilePathWatcher::Delegate* delegate) { 617 FilePathWatcher::Delegate* delegate) {
624 bool result = watcher->Watch(path, delegate); 618 bool result = watcher->Watch(path, delegate);
625 DCHECK(result); 619 DCHECK(result);
626 } 620 }
627 #endif 621 #endif
622
623 void PluginService::RefreshPlugins() {
624 plugin_list()->RefreshPlugins();
625 }
626
627 void PluginService::AddExtraPluginPath(const FilePath& path) {
628 plugin_list()->AddExtraPluginPath(path);
629 }
630
631 void PluginService::RemoveExtraPluginPath(const FilePath& path) {
632 plugin_list()->RemoveExtraPluginPath(path);
633 }
634
635 void PluginService::UnregisterInternalPlugin(const FilePath& path) {
636 plugin_list()->UnregisterInternalPlugin(path);
637 }
638
639 webkit::npapi::PluginList* PluginService::plugin_list() {
640 return webkit::npapi::PluginList::Singleton();
641 }
642
643 void PluginService::RegisterInternalPlugin(const webkit::WebPluginInfo& info) {
644 plugin_list()->RegisterInternalPlugin(info);
645 }
646
647 string16 PluginService::GetPluginGroupName(const std::string& plugin_name) {
648 return plugin_list()->GetPluginGroupName(plugin_name);
649 }
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