| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_impl.h" | 5 #include "content/browser/plugin_service_impl.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/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "content/browser/renderer_host/render_view_host_impl.h" | 21 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 22 #include "content/common/pepper_plugin_registry.h" | 22 #include "content/common/pepper_plugin_registry.h" |
| 23 #include "content/common/plugin_list.h" | 23 #include "content/common/plugin_list.h" |
| 24 #include "content/common/view_messages.h" | 24 #include "content/common/view_messages.h" |
| 25 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
| 26 #include "content/public/browser/content_browser_client.h" | 26 #include "content/public/browser/content_browser_client.h" |
| 27 #include "content/public/browser/plugin_service_filter.h" | 27 #include "content/public/browser/plugin_service_filter.h" |
| 28 #include "content/public/browser/resource_context.h" | 28 #include "content/public/browser/resource_context.h" |
| 29 #include "content/public/common/content_switches.h" | 29 #include "content/public/common/content_switches.h" |
| 30 #include "content/public/common/process_type.h" | 30 #include "content/public/common/process_type.h" |
| 31 #include "webkit/plugins/npapi/plugin_utils.h" | |
| 32 #include "webkit/plugins/plugin_constants.h" | 31 #include "webkit/plugins/plugin_constants.h" |
| 33 #include "webkit/plugins/webplugininfo.h" | 32 #include "webkit/plugins/webplugininfo.h" |
| 34 | 33 |
| 35 #if defined(OS_WIN) | 34 #if defined(OS_WIN) |
| 36 #include "content/common/plugin_constants_win.h" | 35 #include "content/common/plugin_constants_win.h" |
| 36 #include "ui/base/win/hwnd_util.h" |
| 37 #endif | 37 #endif |
| 38 | 38 |
| 39 #if defined(OS_POSIX) | 39 #if defined(OS_POSIX) |
| 40 #include "content/browser/plugin_loader_posix.h" | 40 #include "content/browser/plugin_loader_posix.h" |
| 41 #endif | 41 #endif |
| 42 | 42 |
| 43 #if defined(OS_POSIX) && !defined(OS_OPENBSD) && !defined(OS_ANDROID) | 43 #if defined(OS_POSIX) && !defined(OS_OPENBSD) && !defined(OS_ANDROID) |
| 44 using ::base::FilePathWatcher; | 44 using ::base::FilePathWatcher; |
| 45 #endif | 45 #endif |
| 46 | 46 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 65 return true; | 65 return true; |
| 66 #else | 66 #else |
| 67 // If on POSIX, we don't want to load the list of NPAPI plugins in-process as | 67 // If on POSIX, we don't want to load the list of NPAPI plugins in-process as |
| 68 // that causes instability. | 68 // that causes instability. |
| 69 | 69 |
| 70 // Can't load the plugins on the utility thread when in single process mode | 70 // Can't load the plugins on the utility thread when in single process mode |
| 71 // since that requires GTK which can only be used on the main thread. | 71 // since that requires GTK which can only be used on the main thread. |
| 72 if (RenderProcessHost::run_renderer_in_process()) | 72 if (RenderProcessHost::run_renderer_in_process()) |
| 73 return true; | 73 return true; |
| 74 | 74 |
| 75 return !webkit::npapi::NPAPIPluginsSupported(); | 75 return !PluginService::GetInstance()->NPAPIPluginsSupported(); |
| 76 #endif | 76 #endif |
| 77 } | 77 } |
| 78 | 78 |
| 79 // Callback set on the PluginList to assert that plugin loading happens on the | 79 // Callback set on the PluginList to assert that plugin loading happens on the |
| 80 // correct thread. | 80 // correct thread. |
| 81 void WillLoadPluginsCallback( | 81 void WillLoadPluginsCallback( |
| 82 base::SequencedWorkerPool::SequenceToken token) { | 82 base::SequencedWorkerPool::SequenceToken token) { |
| 83 if (LoadPluginListInProcess()) { | 83 if (LoadPluginListInProcess()) { |
| 84 CHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread( | 84 CHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread( |
| 85 token)); | 85 token)); |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 } | 504 } |
| 505 | 505 |
| 506 bool PluginServiceImpl::GetPluginInfoArray( | 506 bool PluginServiceImpl::GetPluginInfoArray( |
| 507 const GURL& url, | 507 const GURL& url, |
| 508 const std::string& mime_type, | 508 const std::string& mime_type, |
| 509 bool allow_wildcard, | 509 bool allow_wildcard, |
| 510 std::vector<webkit::WebPluginInfo>* plugins, | 510 std::vector<webkit::WebPluginInfo>* plugins, |
| 511 std::vector<std::string>* actual_mime_types) { | 511 std::vector<std::string>* actual_mime_types) { |
| 512 bool use_stale = false; | 512 bool use_stale = false; |
| 513 PluginList::Singleton()->GetPluginInfoArray( | 513 PluginList::Singleton()->GetPluginInfoArray( |
| 514 url, mime_type, allow_wildcard, &use_stale, plugins, actual_mime_types); | 514 url, mime_type, allow_wildcard, &use_stale, NPAPIPluginsSupported(), |
| 515 plugins, actual_mime_types); |
| 515 return use_stale; | 516 return use_stale; |
| 516 } | 517 } |
| 517 | 518 |
| 518 bool PluginServiceImpl::GetPluginInfo(int render_process_id, | 519 bool PluginServiceImpl::GetPluginInfo(int render_process_id, |
| 519 int render_view_id, | 520 int render_view_id, |
| 520 ResourceContext* context, | 521 ResourceContext* context, |
| 521 const GURL& url, | 522 const GURL& url, |
| 522 const GURL& page_url, | 523 const GURL& page_url, |
| 523 const std::string& mime_type, | 524 const std::string& mime_type, |
| 524 bool allow_wildcard, | 525 bool allow_wildcard, |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 618 #endif | 619 #endif |
| 619 } | 620 } |
| 620 | 621 |
| 621 void PluginServiceImpl::GetPluginsInternal( | 622 void PluginServiceImpl::GetPluginsInternal( |
| 622 base::MessageLoopProxy* target_loop, | 623 base::MessageLoopProxy* target_loop, |
| 623 const PluginService::GetPluginsCallback& callback) { | 624 const PluginService::GetPluginsCallback& callback) { |
| 624 DCHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread( | 625 DCHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread( |
| 625 plugin_list_token_)); | 626 plugin_list_token_)); |
| 626 | 627 |
| 627 std::vector<webkit::WebPluginInfo> plugins; | 628 std::vector<webkit::WebPluginInfo> plugins; |
| 628 PluginList::Singleton()->GetPlugins(&plugins); | 629 PluginList::Singleton()->GetPlugins(&plugins, NPAPIPluginsSupported()); |
| 629 | 630 |
| 630 target_loop->PostTask(FROM_HERE, | 631 target_loop->PostTask(FROM_HERE, |
| 631 base::Bind(callback, plugins)); | 632 base::Bind(callback, plugins)); |
| 632 } | 633 } |
| 633 | 634 |
| 634 void PluginServiceImpl::OnWaitableEventSignaled( | 635 void PluginServiceImpl::OnWaitableEventSignaled( |
| 635 base::WaitableEvent* waitable_event) { | 636 base::WaitableEvent* waitable_event) { |
| 636 #if defined(OS_WIN) | 637 #if defined(OS_WIN) |
| 637 if (waitable_event == hkcu_event_) { | 638 if (waitable_event == hkcu_event_) { |
| 638 hkcu_key_.StartWatching(); | 639 hkcu_key_.StartWatching(); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 745 } | 746 } |
| 746 base::TimeDelta delta = base::Time::Now() - i->second[0]; | 747 base::TimeDelta delta = base::Time::Now() - i->second[0]; |
| 747 return delta.InSeconds() <= kCrashesInterval; | 748 return delta.InSeconds() <= kCrashesInterval; |
| 748 } | 749 } |
| 749 | 750 |
| 750 void PluginServiceImpl::RefreshPlugins() { | 751 void PluginServiceImpl::RefreshPlugins() { |
| 751 PluginList::Singleton()->RefreshPlugins(); | 752 PluginList::Singleton()->RefreshPlugins(); |
| 752 } | 753 } |
| 753 | 754 |
| 754 void PluginServiceImpl::AddExtraPluginPath(const base::FilePath& path) { | 755 void PluginServiceImpl::AddExtraPluginPath(const base::FilePath& path) { |
| 756 if (!NPAPIPluginsSupported()) { |
| 757 // TODO(jam): remove and just have CHECK once we're sure this doesn't get |
| 758 // triggered. |
| 759 DLOG(INFO) << "NPAPI plugins not supported"; |
| 760 return; |
| 761 } |
| 755 PluginList::Singleton()->AddExtraPluginPath(path); | 762 PluginList::Singleton()->AddExtraPluginPath(path); |
| 756 } | 763 } |
| 757 | 764 |
| 758 void PluginServiceImpl::RemoveExtraPluginPath(const base::FilePath& path) { | 765 void PluginServiceImpl::RemoveExtraPluginPath(const base::FilePath& path) { |
| 759 PluginList::Singleton()->RemoveExtraPluginPath(path); | 766 PluginList::Singleton()->RemoveExtraPluginPath(path); |
| 760 } | 767 } |
| 761 | 768 |
| 762 void PluginServiceImpl::AddExtraPluginDir(const base::FilePath& path) { | 769 void PluginServiceImpl::AddExtraPluginDir(const base::FilePath& path) { |
| 763 PluginList::Singleton()->AddExtraPluginDir(path); | 770 PluginList::Singleton()->AddExtraPluginDir(path); |
| 764 } | 771 } |
| 765 | 772 |
| 766 void PluginServiceImpl::RegisterInternalPlugin( | 773 void PluginServiceImpl::RegisterInternalPlugin( |
| 767 const webkit::WebPluginInfo& info, | 774 const webkit::WebPluginInfo& info, |
| 768 bool add_at_beginning) { | 775 bool add_at_beginning) { |
| 776 if (!NPAPIPluginsSupported() && |
| 777 info.type == webkit::WebPluginInfo::PLUGIN_TYPE_NPAPI) { |
| 778 DLOG(INFO) << "Don't register NPAPI plugins when they're not supported"; |
| 779 return; |
| 780 } |
| 769 PluginList::Singleton()->RegisterInternalPlugin(info, add_at_beginning); | 781 PluginList::Singleton()->RegisterInternalPlugin(info, add_at_beginning); |
| 770 } | 782 } |
| 771 | 783 |
| 772 void PluginServiceImpl::UnregisterInternalPlugin(const base::FilePath& path) { | 784 void PluginServiceImpl::UnregisterInternalPlugin(const base::FilePath& path) { |
| 773 PluginList::Singleton()->UnregisterInternalPlugin(path); | 785 PluginList::Singleton()->UnregisterInternalPlugin(path); |
| 774 } | 786 } |
| 775 | 787 |
| 776 void PluginServiceImpl::GetInternalPlugins( | 788 void PluginServiceImpl::GetInternalPlugins( |
| 777 std::vector<webkit::WebPluginInfo>* plugins) { | 789 std::vector<webkit::WebPluginInfo>* plugins) { |
| 778 PluginList::Singleton()->GetInternalPlugins(plugins); | 790 PluginList::Singleton()->GetInternalPlugins(plugins); |
| 779 } | 791 } |
| 780 | 792 |
| 793 bool PluginServiceImpl::NPAPIPluginsSupported() { |
| 794 #if defined(OS_WIN) || defined(OS_MACOSX) || (defined(OS_LINUX) && !defined(USE_
AURA)) |
| 795 return true; |
| 796 #else |
| 797 return false; |
| 798 #endif |
| 799 } |
| 800 |
| 781 void PluginServiceImpl::DisablePluginsDiscoveryForTesting() { | 801 void PluginServiceImpl::DisablePluginsDiscoveryForTesting() { |
| 782 PluginList::Singleton()->DisablePluginsDiscovery(); | 802 PluginList::Singleton()->DisablePluginsDiscovery(); |
| 783 } | 803 } |
| 784 | 804 |
| 785 #if defined(OS_MACOSX) | 805 #if defined(OS_MACOSX) |
| 786 void PluginServiceImpl::AppActivated() { | 806 void PluginServiceImpl::AppActivated() { |
| 787 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 807 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 788 base::Bind(&NotifyPluginsOfActivation)); | 808 base::Bind(&NotifyPluginsOfActivation)); |
| 789 } | 809 } |
| 810 #elif defined(OS_WIN) |
| 811 |
| 812 bool GetPluginPropertyFromWindow( |
| 813 HWND window, const wchar_t* plugin_atom_property, |
| 814 base::string16* plugin_property) { |
| 815 ATOM plugin_atom = reinterpret_cast<ATOM>( |
| 816 GetPropW(window, plugin_atom_property)); |
| 817 if (plugin_atom != 0) { |
| 818 WCHAR plugin_property_local[MAX_PATH] = {0}; |
| 819 GlobalGetAtomNameW(plugin_atom, |
| 820 plugin_property_local, |
| 821 ARRAYSIZE(plugin_property_local)); |
| 822 *plugin_property = plugin_property_local; |
| 823 return true; |
| 824 } |
| 825 return false; |
| 826 } |
| 827 |
| 828 bool PluginServiceImpl::GetPluginInfoFromWindow( |
| 829 HWND window, |
| 830 base::string16* plugin_name, |
| 831 base::string16* plugin_version) { |
| 832 if (!IsPluginWindow(window)) |
| 833 return false; |
| 834 |
| 835 GetPluginPropertyFromWindow( |
| 836 window, kPluginNameAtomProperty, plugin_name); |
| 837 GetPluginPropertyFromWindow( |
| 838 window, kPluginVersionAtomProperty, plugin_version); |
| 839 return true; |
| 840 } |
| 841 |
| 842 bool PluginServiceImpl::IsPluginWindow(HWND window) { |
| 843 return ui::GetClassName(window) == base::string16(kNativeWindowClassName); |
| 844 } |
| 790 #endif | 845 #endif |
| 791 | 846 |
| 792 } // namespace content | 847 } // namespace content |
| OLD | NEW |