diff options
| author | wfh <wfh@chromium.org> | 2015-04-10 19:24:00 -0700 | 
|---|---|---|
| committer | Commit bot <commit-bot@chromium.org> | 2015-04-11 02:24:30 +0000 | 
| commit | 26d09db19381c2236a2890c045761465c78bc958 (patch) | |
| tree | abafedd0ec0c700d3a9a91d8574ea782c3ae902e | |
| parent | cd7a39ac205a3c9c8110ef9f2d42f44196fa49c9 (diff) | |
| download | chromium_src-26d09db19381c2236a2890c045761465c78bc958.zip chromium_src-26d09db19381c2236a2890c045761465c78bc958.tar.gz chromium_src-26d09db19381c2236a2890c045761465c78bc958.tar.bz2 | |
Enable NPAPI if policy has plugin policies.
BUG=472648
TEST=manual - verify that NPAPI plugins appear in chrome://plugins when either a machine or user plugin policy is set.
Review URL: https://codereview.chromium.org/1071713004
Cr-Commit-Position: refs/heads/master@{#324754}
| -rw-r--r-- | chrome/browser/BUILD.gn | 5 | ||||
| -rw-r--r-- | chrome/browser/plugins/enable_npapi_plugins_policy_handler.cc | 46 | ||||
| -rw-r--r-- | chrome/browser/plugins/enable_npapi_plugins_policy_handler.h | 37 | ||||
| -rw-r--r-- | chrome/browser/plugins/plugin_prefs.cc | 11 | ||||
| -rw-r--r-- | chrome/browser/plugins/plugin_prefs.h | 3 | ||||
| -rw-r--r-- | chrome/browser/plugins/plugin_prefs_factory.cc | 4 | ||||
| -rw-r--r-- | chrome/browser/policy/chrome_browser_policy_connector.cc | 26 | ||||
| -rw-r--r-- | chrome/browser/policy/chrome_browser_policy_connector.h | 2 | ||||
| -rw-r--r-- | chrome/browser/policy/configuration_policy_handler_list_factory.cc | 8 | ||||
| -rw-r--r-- | chrome/chrome_browser.gypi | 8 | ||||
| -rw-r--r-- | chrome/common/pref_names.cc | 3 | ||||
| -rw-r--r-- | chrome/common/pref_names.h | 1 | ||||
| -rw-r--r-- | content/browser/plugin_service_impl.cc | 10 | ||||
| -rw-r--r-- | content/browser/plugin_service_impl.h | 2 | ||||
| -rw-r--r-- | content/public/browser/plugin_service.h | 4 | ||||
| -rw-r--r-- | content/test/fake_plugin_service.cc | 2 | ||||
| -rw-r--r-- | content/test/fake_plugin_service.h | 2 | 
17 files changed, 140 insertions, 34 deletions
| diff --git a/chrome/browser/BUILD.gn b/chrome/browser/BUILD.gn index 24abe29..4fbc826 100644 --- a/chrome/browser/BUILD.gn +++ b/chrome/browser/BUILD.gn @@ -387,6 +387,11 @@ source_set("browser") {                               ".",                               "//chrome")      } +    if (enable_plugins) { +      sources += rebase_path(gypi_values.chrome_browser_policy_plugin_sources, +                             ".", +                             "//chrome") +    }      if (is_android || is_ios) {        sources += rebase_path(gypi_values.chrome_browser_policy_mobile_sources,                               ".", diff --git a/chrome/browser/plugins/enable_npapi_plugins_policy_handler.cc b/chrome/browser/plugins/enable_npapi_plugins_policy_handler.cc new file mode 100644 index 0000000..c3419c9 --- /dev/null +++ b/chrome/browser/plugins/enable_npapi_plugins_policy_handler.cc @@ -0,0 +1,46 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/plugins/enable_npapi_plugins_policy_handler.h" + +#include "base/logging.h" +#include "base/prefs/pref_value_map.h" +#include "base/values.h" +#include "chrome/common/pref_names.h" +#include "components/policy/core/browser/policy_error_map.h" +#include "components/policy/core/common/policy_map.h" +#include "policy/policy_constants.h" + +namespace policy { + +EnableNpapiPluginsPolicyHandler::EnableNpapiPluginsPolicyHandler() { +} + +EnableNpapiPluginsPolicyHandler::~EnableNpapiPluginsPolicyHandler() { +} + +void EnableNpapiPluginsPolicyHandler::ApplyPolicySettings( +    const PolicyMap& policies, +    PrefValueMap* prefs) { +  const std::string plugin_policies[] = {key::kEnabledPlugins, +                                         key::kPluginsAllowedForUrls, +                                         key::kPluginsBlockedForUrls, +                                         key::kDisabledPluginsExceptions, +                                         key::kDisabledPlugins}; + +  for (auto policy : plugin_policies) { +    if (policies.GetValue(policy)) { +      prefs->SetBoolean(prefs::kEnableNpapi, true); +      break; +    } +  } +} + +bool EnableNpapiPluginsPolicyHandler::CheckPolicySettings( +    const PolicyMap& policies, +    PolicyErrorMap* prefs) { +  return true; +} + +}  // namespace policy diff --git a/chrome/browser/plugins/enable_npapi_plugins_policy_handler.h b/chrome/browser/plugins/enable_npapi_plugins_policy_handler.h new file mode 100644 index 0000000..4ce549a --- /dev/null +++ b/chrome/browser/plugins/enable_npapi_plugins_policy_handler.h @@ -0,0 +1,37 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_PLUGINS_ENABLE_NPAPI_PLUGINS_POLICY_HANDLER_H_ +#define CHROME_BROWSER_PLUGINS_ENABLE_NPAPI_PLUGINS_POLICY_HANDLER_H_ + +#include "base/macros.h" +#include "components/policy/core/browser/configuration_policy_handler.h" + +class PrefValueMap; + +namespace policy { + +class PolicyErrorMap; +class PolicyMap; + +// ConfigurationPolicyHandler for the plugin policies that re-enable NPAPI. +class EnableNpapiPluginsPolicyHandler : public ConfigurationPolicyHandler { + public: +  EnableNpapiPluginsPolicyHandler(); + +  ~EnableNpapiPluginsPolicyHandler() override; + +  // ConfigurationPolicyHandler methods: +  void ApplyPolicySettings(const PolicyMap& policies, +                           PrefValueMap* prefs) override; +  // ConfigurationPolicyHandler methods: +  bool CheckPolicySettings(const PolicyMap& policies, +                           PolicyErrorMap* prefs) override; + +  DISALLOW_COPY_AND_ASSIGN(EnableNpapiPluginsPolicyHandler); +}; + +}  // namespace policy + +#endif  // CHROME_BROWSER_PLUGINS_ENABLE_NPAPI_PLUGINS_POLICY_HANDLER_H_ diff --git a/chrome/browser/plugins/plugin_prefs.cc b/chrome/browser/plugins/plugin_prefs.cc index 97dcf99..ad57001 100644 --- a/chrome/browser/plugins/plugin_prefs.cc +++ b/chrome/browser/plugins/plugin_prefs.cc @@ -280,6 +280,11 @@ void PluginPrefs::UpdatePatternsAndNotify(std::set<base::string16>* patterns,    NotifyPluginStatusChanged();  } +void PluginPrefs::EnableNpapi() { +  PluginService::GetInstance()->EnableNpapiPlugins(); +  NotifyPluginStatusChanged(); +} +  /*static*/  bool PluginPrefs::IsStringMatchedInSet(      const base::string16& name, @@ -486,6 +491,9 @@ void PluginPrefs::SetPrefs(PrefService* prefs) {    ListValueToStringSet(prefs_->GetList(prefs::kPluginsEnabledPlugins),                         &policy_enabled_plugin_patterns_); +  if (prefs_->GetBoolean(prefs::kEnableNpapi)) +    EnableNpapi(); +    registrar_.Init(prefs_);    // Because pointers to our own members will remain unchanged for the @@ -504,6 +512,9 @@ void PluginPrefs::SetPrefs(PrefService* prefs) {                   base::Bind(&PluginPrefs::UpdatePatternsAndNotify,                              base::Unretained(this),                              &policy_enabled_plugin_patterns_)); +  registrar_.Add(prefs::kEnableNpapi, +                 base::Bind(&PluginPrefs::EnableNpapi, +                            base::Unretained(this)));    NotifyPluginStatusChanged();  } diff --git a/chrome/browser/plugins/plugin_prefs.h b/chrome/browser/plugins/plugin_prefs.h index d95db2d..0407f1f 100644 --- a/chrome/browser/plugins/plugin_prefs.h +++ b/chrome/browser/plugins/plugin_prefs.h @@ -107,6 +107,9 @@ class PluginPrefs : public RefcountedKeyedService {    void UpdatePatternsAndNotify(std::set<base::string16>* patterns,                                 const std::string& pref_name); +  // Called to enable NPAPI if kEnableNpapi gets set by policy. +  void EnableNpapi(); +    // Allows unit tests to directly set enforced plugin patterns.    void SetPolicyEnforcedPluginPatterns(        const std::set<base::string16>& disabled_patterns, diff --git a/chrome/browser/plugins/plugin_prefs_factory.cc b/chrome/browser/plugins/plugin_prefs_factory.cc index 22b0f56..862fa91 100644 --- a/chrome/browser/plugins/plugin_prefs_factory.cc +++ b/chrome/browser/plugins/plugin_prefs_factory.cc @@ -75,6 +75,10 @@ void PluginPrefsFactory::RegisterProfilePrefs(                               user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);    registry->RegisterListPref(prefs::kPluginsEnabledPlugins,                               user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); +  registry->RegisterBooleanPref( +      prefs::kEnableNpapi, +      false, +      user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);  }  content::BrowserContext* PluginPrefsFactory::GetBrowserContextToUse( diff --git a/chrome/browser/policy/chrome_browser_policy_connector.cc b/chrome/browser/policy/chrome_browser_policy_connector.cc index cb8d071..df1b348 100644 --- a/chrome/browser/policy/chrome_browser_policy_connector.cc +++ b/chrome/browser/policy/chrome_browser_policy_connector.cc @@ -88,8 +88,6 @@ void ChromeBrowserPolicyConnector::Init(    BrowserPolicyConnector::Init(        local_state, request_context, device_management_service.Pass()); - -  AppendExtraFlagsPerPolicy();  }  ConfigurationPolicyProvider* @@ -123,28 +121,4 @@ ConfigurationPolicyProvider*  #endif  } -void ChromeBrowserPolicyConnector::AppendExtraFlagsPerPolicy() { -  PolicyService* policy_service = GetPolicyService(); -  PolicyNamespace chrome_ns = PolicyNamespace(POLICY_DOMAIN_CHROME, ""); -  const PolicyMap& chrome_policy = policy_service->GetPolicies(chrome_ns); -  base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); - -  if (command_line->HasSwitch(switches::kEnableNpapi)) -    return; - -  // The list of Plugin related policies that re-enable NPAPI. Remove once NPAPI -  // is dead. -  const std::string plugin_policies[] = { key::kEnabledPlugins, -                                          key::kPluginsAllowedForUrls, -                                          key::kPluginsBlockedForUrls, -                                          key::kDisabledPluginsExceptions, -                                          key::kDisabledPlugins }; -  for (auto policy : plugin_policies) { -    if (chrome_policy.GetValue(policy)) { -      command_line->AppendSwitch(switches::kEnableNpapi); -      break; -    } -  } -} -  }  // namespace policy diff --git a/chrome/browser/policy/chrome_browser_policy_connector.h b/chrome/browser/policy/chrome_browser_policy_connector.h index 1421a3e..ba24431 100644 --- a/chrome/browser/policy/chrome_browser_policy_connector.h +++ b/chrome/browser/policy/chrome_browser_policy_connector.h @@ -40,8 +40,6 @@ class ChromeBrowserPolicyConnector : public BrowserPolicyConnector {   private:    ConfigurationPolicyProvider* CreatePlatformProvider(); -  void AppendExtraFlagsPerPolicy(); -    DISALLOW_COPY_AND_ASSIGN(ChromeBrowserPolicyConnector);  }; diff --git a/chrome/browser/policy/configuration_policy_handler_list_factory.cc b/chrome/browser/policy/configuration_policy_handler_list_factory.cc index 97d2e311..0a26524 100644 --- a/chrome/browser/policy/configuration_policy_handler_list_factory.cc +++ b/chrome/browser/policy/configuration_policy_handler_list_factory.cc @@ -61,6 +61,10 @@  #include "extensions/common/manifest.h"  #endif +#if defined(ENABLE_PLUGINS) +#include "chrome/browser/plugins/enable_npapi_plugins_policy_handler.h" +#endif +  namespace policy {  namespace { @@ -598,6 +602,10 @@ scoped_ptr<ConfigurationPolicyHandlerList> BuildHandlerList(        new extensions::ExtensionSettingsPolicyHandler(chrome_schema)));  #endif +#if defined(ENABLE_PLUGINS) +  handlers->AddHandler(make_scoped_ptr(new EnableNpapiPluginsPolicyHandler())); +#endif +  #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) && !defined(OS_IOS)    handlers->AddHandler(make_scoped_ptr(new DiskCacheDirPolicyHandler())); diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index a0de3f2..2d6a49b 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -2111,6 +2111,11 @@        'browser/upgrade_detector_impl.cc',        'browser/upgrade_detector_impl.h',      ], +    # Policy sources used if plugins are enabled. +    'chrome_browser_policy_plugin_sources': [ +      'browser/plugins/enable_npapi_plugins_policy_handler.cc', +      'browser/plugins/enable_npapi_plugins_policy_handler.h', +    ],      'chrome_browser_predictor_sources': [        'browser/predictors/autocomplete_action_predictor.cc',        'browser/predictors/autocomplete_action_predictor.h', @@ -3291,6 +3296,9 @@              ['OS=="win" or OS=="mac" or desktop_linux==1', {                'sources': [ '<@(chrome_browser_policy_desktop_sources)' ],              }], +            ['enable_plugins==1', { +              'sources': [ '<@(chrome_browser_policy_plugin_sources)' ], +            }],              ['OS=="android" or OS=="ios"', {  # Mobile.                'sources': [ '<@(chrome_browser_policy_mobile_sources)' ],              }, {  # Non-mobile. diff --git a/chrome/common/pref_names.cc b/chrome/common/pref_names.cc index c033a37..b8e0e74 100644 --- a/chrome/common/pref_names.cc +++ b/chrome/common/pref_names.cc @@ -937,6 +937,9 @@ const char kPluginsDisabledPluginsExceptions[] =  // List pref containing names of plugins that are enabled by policy.  const char kPluginsEnabledPlugins[] = "plugins.plugins_enabled"; +// Whether NPAPI plugins are enabled. +const char kEnableNpapi[] = "plugins.enable_npapi"; +  // When bundled NPAPI Flash is removed, if at that point it is enabled while  // Pepper Flash is disabled, we would like to turn on Pepper Flash. And we will  // want to do so only once. diff --git a/chrome/common/pref_names.h b/chrome/common/pref_names.h index ba88eac..2ebb866 100644 --- a/chrome/common/pref_names.h +++ b/chrome/common/pref_names.h @@ -314,6 +314,7 @@ extern const char kPluginsPluginsList[];  extern const char kPluginsDisabledPlugins[];  extern const char kPluginsDisabledPluginsExceptions[];  extern const char kPluginsEnabledPlugins[]; +extern const char kEnableNpapi[];  extern const char kPluginsMigratedToPepperFlash[];  extern const char kPluginsRemovedOldComponentPepperFlashSettings[];  #if !defined(OS_ANDROID) diff --git a/content/browser/plugin_service_impl.cc b/content/browser/plugin_service_impl.cc index 4c52514..286bbd4 100644 --- a/content/browser/plugin_service_impl.cc +++ b/content/browser/plugin_service_impl.cc @@ -789,6 +789,9 @@ void PluginServiceImpl::GetInternalPlugins(  }  bool PluginServiceImpl::NPAPIPluginsSupported() { +  if (npapi_plugins_enabled_) +    return true; +    static bool command_line_checked = false;    if (!command_line_checked) { @@ -812,8 +815,13 @@ void PluginServiceImpl::DisablePluginsDiscoveryForTesting() {    PluginList::Singleton()->DisablePluginsDiscovery();  } -void PluginServiceImpl::EnableNpapiPluginsForTesting() { +void PluginServiceImpl::EnableNpapiPlugins() {    npapi_plugins_enabled_ = true; +  RefreshPlugins(); +  BrowserThread::PostTask( +      BrowserThread::UI, FROM_HERE, +      base::Bind(&PluginService::PurgePluginListCache, +                 static_cast<BrowserContext*>(NULL), false));  }  #if defined(OS_MACOSX) diff --git a/content/browser/plugin_service_impl.h b/content/browser/plugin_service_impl.h index 326eb4f..fae8dda 100644 --- a/content/browser/plugin_service_impl.h +++ b/content/browser/plugin_service_impl.h @@ -106,7 +106,7 @@ class CONTENT_EXPORT PluginServiceImpl    void UnregisterInternalPlugin(const base::FilePath& path) override;    void GetInternalPlugins(std::vector<WebPluginInfo>* plugins) override;    bool NPAPIPluginsSupported() override; -  void EnableNpapiPluginsForTesting() override; +  void EnableNpapiPlugins() override;    void DisablePluginsDiscoveryForTesting() override;  #if defined(OS_MACOSX)    void AppActivated() override; diff --git a/content/public/browser/plugin_service.h b/content/public/browser/plugin_service.h index 9420f3e..c09331e 100644 --- a/content/public/browser/plugin_service.h +++ b/content/public/browser/plugin_service.h @@ -143,8 +143,8 @@ class PluginService {    // This can be called from any thread.    virtual bool NPAPIPluginsSupported() = 0; -  // This is equivalent to specifying kEnableNpapi, but is useful for unittests. -  virtual void EnableNpapiPluginsForTesting() = 0; +  // This is equivalent to specifying kEnableNpapi. +  virtual void EnableNpapiPlugins() = 0;    // This is equivalent to specifying kDisablePluginsDiscovery, but is useful    // for unittests. diff --git a/content/test/fake_plugin_service.cc b/content/test/fake_plugin_service.cc index 75e35d4..ae7d7a6 100644 --- a/content/test/fake_plugin_service.cc +++ b/content/test/fake_plugin_service.cc @@ -101,7 +101,7 @@ bool FakePluginService::NPAPIPluginsSupported() {    return false;  } -void FakePluginService::EnableNpapiPluginsForTesting() { +void FakePluginService::EnableNpapiPlugins() {  }  void FakePluginService::DisablePluginsDiscoveryForTesting() { diff --git a/content/test/fake_plugin_service.h b/content/test/fake_plugin_service.h index ed8450c..3a19932 100644 --- a/content/test/fake_plugin_service.h +++ b/content/test/fake_plugin_service.h @@ -52,7 +52,7 @@ class FakePluginService : public PluginService {    void UnregisterInternalPlugin(const base::FilePath& path) override;    void GetInternalPlugins(std::vector<WebPluginInfo>* plugins) override;    bool NPAPIPluginsSupported() override; -  void EnableNpapiPluginsForTesting() override; +  void EnableNpapiPlugins() override;    void DisablePluginsDiscoveryForTesting() override;  #if defined(OS_MACOSX)    void AppActivated() override; | 
