Chromium Code Reviews| 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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 183 base::FilePath path = | 183 base::FilePath path = |
| 184 command_line->GetSwitchValuePath(switches::kLoadPlugin); | 184 command_line->GetSwitchValuePath(switches::kLoadPlugin); |
| 185 if (!path.empty()) | 185 if (!path.empty()) |
| 186 AddExtraPluginPath(path); | 186 AddExtraPluginPath(path); |
| 187 path = command_line->GetSwitchValuePath(switches::kExtraPluginDir); | 187 path = command_line->GetSwitchValuePath(switches::kExtraPluginDir); |
| 188 if (!path.empty()) | 188 if (!path.empty()) |
| 189 PluginList::Singleton()->AddExtraPluginDir(path); | 189 PluginList::Singleton()->AddExtraPluginDir(path); |
| 190 | 190 |
| 191 if (command_line->HasSwitch(switches::kDisablePluginsDiscovery)) | 191 if (command_line->HasSwitch(switches::kDisablePluginsDiscovery)) |
| 192 PluginList::Singleton()->DisablePluginsDiscovery(); | 192 PluginList::Singleton()->DisablePluginsDiscovery(); |
| 193 #if defined(OS_WIN) || defined(OS_MACOSX) | |
| 194 npapi_plugins_enabled_ = command_line->HasSwitch(switches::kEnableNpapi); | |
| 195 NPAPIPluginStatus status = | |
| 196 npapi_plugins_enabled_ ? NPAPI_STATUS_ENABLED : NPAPI_STATUS_DISABLED; | |
| 197 #else | |
| 198 NPAPIPluginStatus status = NPAPI_STATUS_UNSUPPORTED; | |
| 199 #endif | |
| 200 UMA_HISTOGRAM_ENUMERATION("Plugin.NPAPIStatus", status, | |
| 201 NPAPI_STATUS_ENUM_COUNT); | |
| 202 } | 193 } |
| 203 | 194 |
| 204 void PluginServiceImpl::StartWatchingPlugins() { | 195 void PluginServiceImpl::StartWatchingPlugins() { |
| 205 // Start watching for changes in the plugin list. This means watching | 196 // Start watching for changes in the plugin list. This means watching |
| 206 // for changes in the Windows registry keys and on both Windows and POSIX | 197 // for changes in the Windows registry keys and on both Windows and POSIX |
| 207 // watch for changes in the paths that are expected to contain plugins. | 198 // watch for changes in the paths that are expected to contain plugins. |
| 208 #if defined(OS_WIN) | 199 #if defined(OS_WIN) |
| 209 if (hkcu_key_.Create(HKEY_CURRENT_USER, | 200 if (hkcu_key_.Create(HKEY_CURRENT_USER, |
| 210 kRegistryMozillaPlugins, | 201 kRegistryMozillaPlugins, |
| 211 KEY_NOTIFY) == ERROR_SUCCESS) { | 202 KEY_NOTIFY) == ERROR_SUCCESS) { |
| (...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 772 PluginList::Singleton()->RemoveExtraPluginPath(path); | 763 PluginList::Singleton()->RemoveExtraPluginPath(path); |
| 773 } | 764 } |
| 774 | 765 |
| 775 void PluginServiceImpl::AddExtraPluginDir(const base::FilePath& path) { | 766 void PluginServiceImpl::AddExtraPluginDir(const base::FilePath& path) { |
| 776 PluginList::Singleton()->AddExtraPluginDir(path); | 767 PluginList::Singleton()->AddExtraPluginDir(path); |
| 777 } | 768 } |
| 778 | 769 |
| 779 void PluginServiceImpl::RegisterInternalPlugin( | 770 void PluginServiceImpl::RegisterInternalPlugin( |
| 780 const WebPluginInfo& info, | 771 const WebPluginInfo& info, |
| 781 bool add_at_beginning) { | 772 bool add_at_beginning) { |
| 782 if (!NPAPIPluginsSupported() && | 773 // Internal plugins should never be NPAPI. |
| 783 info.type == WebPluginInfo::PLUGIN_TYPE_NPAPI) { | 774 DCHECK_NE(info.type, WebPluginInfo::PLUGIN_TYPE_NPAPI); |
|
jam
2015/02/19 23:46:48
nit: i'd make that a CHECK_NE
Will Harris
2015/02/20 03:55:50
Done.
| |
| 775 if (info.type == WebPluginInfo::PLUGIN_TYPE_NPAPI) { | |
| 784 DVLOG(0) << "Don't register NPAPI plugins when they're not supported"; | 776 DVLOG(0) << "Don't register NPAPI plugins when they're not supported"; |
| 785 return; | 777 return; |
| 786 } | 778 } |
| 787 PluginList::Singleton()->RegisterInternalPlugin(info, add_at_beginning); | 779 PluginList::Singleton()->RegisterInternalPlugin(info, add_at_beginning); |
| 788 } | 780 } |
| 789 | 781 |
| 790 void PluginServiceImpl::UnregisterInternalPlugin(const base::FilePath& path) { | 782 void PluginServiceImpl::UnregisterInternalPlugin(const base::FilePath& path) { |
| 791 PluginList::Singleton()->UnregisterInternalPlugin(path); | 783 PluginList::Singleton()->UnregisterInternalPlugin(path); |
| 792 } | 784 } |
| 793 | 785 |
| 794 void PluginServiceImpl::GetInternalPlugins( | 786 void PluginServiceImpl::GetInternalPlugins( |
| 795 std::vector<WebPluginInfo>* plugins) { | 787 std::vector<WebPluginInfo>* plugins) { |
| 796 PluginList::Singleton()->GetInternalPlugins(plugins); | 788 PluginList::Singleton()->GetInternalPlugins(plugins); |
| 797 } | 789 } |
| 798 | 790 |
| 799 bool PluginServiceImpl::NPAPIPluginsSupported() { | 791 bool PluginServiceImpl::NPAPIPluginsSupported() { |
| 792 static bool command_line_checked = false; | |
| 793 | |
| 794 if (!command_line_checked) { | |
| 795 #if defined(OS_WIN) || defined(OS_MACOSX) | |
| 796 const base::CommandLine* command_line = | |
| 797 base::CommandLine::ForCurrentProcess(); | |
| 798 npapi_plugins_enabled_ = command_line->HasSwitch(switches::kEnableNpapi); | |
| 799 NPAPIPluginStatus status = | |
| 800 npapi_plugins_enabled_ ? NPAPI_STATUS_ENABLED : NPAPI_STATUS_DISABLED; | |
| 801 #else | |
| 802 NPAPIPluginStatus status = NPAPI_STATUS_UNSUPPORTED; | |
| 803 #endif | |
| 804 UMA_HISTOGRAM_ENUMERATION("Plugin.NPAPIStatus", status, | |
| 805 NPAPI_STATUS_ENUM_COUNT); | |
| 806 } | |
| 807 | |
| 800 return npapi_plugins_enabled_; | 808 return npapi_plugins_enabled_; |
| 801 } | 809 } |
| 802 | 810 |
| 803 void PluginServiceImpl::DisablePluginsDiscoveryForTesting() { | 811 void PluginServiceImpl::DisablePluginsDiscoveryForTesting() { |
| 804 PluginList::Singleton()->DisablePluginsDiscovery(); | 812 PluginList::Singleton()->DisablePluginsDiscovery(); |
| 805 } | 813 } |
| 806 | 814 |
| 807 void PluginServiceImpl::EnableNpapiPluginsForTesting() { | 815 void PluginServiceImpl::EnableNpapiPluginsForTesting() { |
| 808 npapi_plugins_enabled_ = true; | 816 npapi_plugins_enabled_ = true; |
| 809 } | 817 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 856 #endif | 864 #endif |
| 857 | 865 |
| 858 bool PluginServiceImpl::PpapiDevChannelSupported( | 866 bool PluginServiceImpl::PpapiDevChannelSupported( |
| 859 BrowserContext* browser_context, | 867 BrowserContext* browser_context, |
| 860 const GURL& document_url) { | 868 const GURL& document_url) { |
| 861 return content::GetContentClient()->browser()-> | 869 return content::GetContentClient()->browser()-> |
| 862 IsPluginAllowedToUseDevChannelAPIs(browser_context, document_url); | 870 IsPluginAllowedToUseDevChannelAPIs(browser_context, document_url); |
| 863 } | 871 } |
| 864 | 872 |
| 865 } // namespace content | 873 } // namespace content |
| OLD | NEW |