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