OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/plugins/plugin_policy_handler.h" |
| 6 |
| 7 #include <string> |
| 8 |
| 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/strings/pattern.h" |
| 11 #include "base/strings/string_util.h" |
| 12 #include "base/values.h" |
| 13 #include "chrome/browser/plugins/plugin_prefs.h" |
| 14 #include "chrome/common/chrome_content_client.h" |
| 15 #include "chrome/common/pref_names.h" |
| 16 #include "components/content_settings/core/common/pref_names.h" |
| 17 #include "components/policy/core/browser/policy_error_map.h" |
| 18 #include "components/strings/grit/components_strings.h" |
| 19 #include "content/public/common/content_constants.h" |
| 20 |
| 21 namespace { |
| 22 |
| 23 const char kAdobeFlashPlayerName[] = "Adobe Flash Player"; |
| 24 |
| 25 // Retrieves a list typed policy or nullptr if not present or not a list. |
| 26 const base::ListValue* GetListPolicy(const policy::PolicyMap& policies, |
| 27 const std::string& policy) { |
| 28 const base::Value* value = policies.GetValue(policy); |
| 29 if (!value) |
| 30 return nullptr; |
| 31 |
| 32 const base::ListValue* policy_value = nullptr; |
| 33 value->GetAsList(&policy_value); |
| 34 return policy_value; |
| 35 } |
| 36 |
| 37 } // namespace |
| 38 |
| 39 PluginPolicyHandler::PluginPolicyHandler() {} |
| 40 |
| 41 PluginPolicyHandler::~PluginPolicyHandler() {} |
| 42 |
| 43 void PluginPolicyHandler::ProcessPolicy(const policy::PolicyMap& policies, |
| 44 PrefValueMap* prefs, |
| 45 const std::string& policy, |
| 46 bool disable_pdf_plugin, |
| 47 ContentSetting flash_content_setting) { |
| 48 const base::ListValue* plugins = GetListPolicy(policies, policy); |
| 49 if (!plugins) |
| 50 return; |
| 51 |
| 52 const int size = plugins->GetSize(); |
| 53 for (int i = 0; i < size; ++i) { |
| 54 std::string plugin; |
| 55 if (!plugins->GetString(i, &plugin)) |
| 56 continue; |
| 57 if (base::MatchPattern(ChromeContentClient::kPDFPluginName, plugin) && |
| 58 !policies.GetValue(policy::key::kAlwaysOpenPdfExternally)) { |
| 59 prefs->SetValue( |
| 60 prefs::kPluginsAlwaysOpenPdfExternally, |
| 61 base::MakeUnique<base::FundamentalValue>(disable_pdf_plugin)); |
| 62 } |
| 63 if ((base::MatchPattern(kAdobeFlashPlayerName, plugin) || |
| 64 base::MatchPattern(content::kFlashPluginName, plugin)) && |
| 65 !policies.GetValue(policy::key::kDefaultPluginsSetting)) { |
| 66 prefs->SetValue( |
| 67 prefs::kManagedDefaultPluginsSetting, |
| 68 base::MakeUnique<base::FundamentalValue>(flash_content_setting)); |
| 69 } |
| 70 } |
| 71 } |
| 72 |
| 73 bool PluginPolicyHandler::CheckPolicySettings(const policy::PolicyMap& policies, |
| 74 policy::PolicyErrorMap* errors) { |
| 75 const std::string checked_policies[] = { |
| 76 policy::key::kEnabledPlugins, policy::key::kDisabledPlugins, |
| 77 policy::key::kDisabledPluginsExceptions}; |
| 78 bool ok = true; |
| 79 for (size_t i = 0; i < arraysize(checked_policies); ++i) { |
| 80 const base::Value* value = policies.GetValue(checked_policies[i]); |
| 81 if (value && !value->IsType(base::Value::TYPE_LIST)) { |
| 82 errors->AddError(checked_policies[i], IDS_POLICY_TYPE_ERROR, |
| 83 base::Value::GetTypeName(base::Value::TYPE_LIST)); |
| 84 ok = false; |
| 85 } |
| 86 } |
| 87 return ok; |
| 88 } |
| 89 |
| 90 void PluginPolicyHandler::ApplyPolicySettings(const policy::PolicyMap& policies, |
| 91 PrefValueMap* prefs) { |
| 92 // This order makes enabled plugins take precedence as is now. |
| 93 ProcessPolicy(policies, prefs, policy::key::kDisabledPlugins, true, |
| 94 CONTENT_SETTING_BLOCK); |
| 95 ProcessPolicy(policies, prefs, policy::key::kEnabledPlugins, false, |
| 96 CONTENT_SETTING_ALLOW); |
| 97 |
| 98 // Finally check if any of the two is in the exceptions list and remove the |
| 99 // policy changes. |
| 100 const base::ListValue* plugins = |
| 101 GetListPolicy(policies, policy::key::kDisabledPluginsExceptions); |
| 102 if (!plugins) |
| 103 return; |
| 104 const int size = plugins->GetSize(); |
| 105 for (int i = 0; i < size; ++i) { |
| 106 std::string plugin; |
| 107 if (!plugins->GetString(i, &plugin)) |
| 108 continue; |
| 109 if (base::MatchPattern(ChromeContentClient::kPDFPluginName, plugin) && |
| 110 !policies.GetValue(policy::key::kAlwaysOpenPdfExternally)) { |
| 111 prefs->RemoveValue(prefs::kPluginsAlwaysOpenPdfExternally); |
| 112 } |
| 113 if ((base::MatchPattern(kAdobeFlashPlayerName, plugin) || |
| 114 base::MatchPattern(content::kFlashPluginName, plugin)) && |
| 115 !policies.GetValue(policy::key::kDefaultPluginsSetting)) { |
| 116 prefs->RemoveValue(prefs::kManagedDefaultPluginsSetting); |
| 117 } |
| 118 } |
| 119 } |
OLD | NEW |