Index: chrome/browser/plugins/plugin_policy_handler.cc |
diff --git a/chrome/browser/plugins/plugin_policy_handler.cc b/chrome/browser/plugins/plugin_policy_handler.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..ce98a70c833e5a9eab4e43cfe6b77cc0ae2585ff |
--- /dev/null |
+++ b/chrome/browser/plugins/plugin_policy_handler.cc |
@@ -0,0 +1,124 @@ |
+// Copyright (c) 2012 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/plugin_policy_handler.h" |
+ |
+#include <string> |
+ |
+#include "base/memory/ptr_util.h" |
+#include "base/strings/pattern.h" |
+#include "base/strings/string_util.h" |
+#include "base/values.h" |
+#include "chrome/browser/plugins/plugin_prefs.h" |
+#include "chrome/common/chrome_content_client.h" |
+#include "chrome/common/pref_names.h" |
+#include "components/content_settings/core/common/pref_names.h" |
+#include "components/policy/core/browser/policy_error_map.h" |
+#include "components/strings/grit/components_strings.h" |
+ |
+namespace { |
+ |
+const char kAdobeFlashPlayerName[] = "Adobe Flash Player"; |
+ |
+// Retrieves a list typed policy or nullptr if not present or not a list. |
+const base::ListValue* GetListPolicy(const policy::PolicyMap& policies, |
+ const std::string& policy) { |
+ const base::Value* value = policies.GetValue(policy); |
+ if (!value) |
+ return nullptr; |
+ |
+ const base::ListValue* policy_value = nullptr; |
+ value->GetAsList(&policy_value); |
+ return policy_value; |
+} |
+ |
+} // namespace |
+ |
+PluginPolicyHandler::PluginPolicyHandler() {} |
+ |
+PluginPolicyHandler::~PluginPolicyHandler() {} |
+ |
+void PluginPolicyHandler::ProcessPolicy(const policy::PolicyMap& policies, |
+ PrefValueMap* prefs, |
+ const std::string& policy, |
+ bool disable_pdf_plugin, |
+ ContentSetting flash_content_setting) { |
+ const base::ListValue* plugins = GetListPolicy(policies, policy); |
+ if (!plugins) |
+ return; |
+ |
+ const int size = plugins->GetSize(); |
+ for (int i = 0; i < size; ++i) { |
+ std::string plugin; |
+ if (!plugins->GetString(i, &plugin)) |
+ continue; |
+ plugin = base::ToUpperASCII(plugin); |
Bernhard Bauer
2016/10/14 11:49:45
I think this is also not necessary -- if MatchPatt
pastarmovj
2016/10/14 12:38:59
I am upper-casing the name below as well so it is
Bernhard Bauer
2016/10/14 15:27:05
Wasn't case sensitive? PluginPrefs::IsStringMatche
pastarmovj
2016/10/17 09:07:09
Seems like I might be remembering wrong. Removed c
|
+ if ((plugin == "*" || |
Bernhard Bauer
2016/10/14 11:49:45
This is also not necessary -- * will match anythin
pastarmovj
2016/10/14 12:38:59
Right now that we rotated it around :)
|
+ base::MatchPattern( |
+ base::ToUpperASCII(ChromeContentClient::kPDFPluginName), |
+ plugin)) && |
+ !policies.GetValue(policy::key::kAlwaysOpenPdfExternally)) { |
+ prefs->SetValue( |
+ prefs::kPluginsAlwaysOpenPdfExternally, |
+ base::MakeUnique<base::FundamentalValue>(disable_pdf_plugin)); |
+ } |
+ if ((plugin == "*" || |
+ base::MatchPattern(base::ToUpperASCII(kAdobeFlashPlayerName), |
Bernhard Bauer
2016/10/14 11:49:45
For extra resilience, you could attempt to match c
pastarmovj
2016/10/14 12:38:59
Done.
|
+ plugin)) && |
+ !policies.GetValue(policy::key::kDefaultPluginsSetting)) { |
+ prefs->SetValue( |
+ prefs::kManagedDefaultPluginsSetting, |
+ base::MakeUnique<base::FundamentalValue>(flash_content_setting)); |
+ } |
+ } |
+} |
+ |
+bool PluginPolicyHandler::CheckPolicySettings(const policy::PolicyMap& policies, |
+ policy::PolicyErrorMap* errors) { |
+ const std::string checked_policies[] = { |
+ policy::key::kEnabledPlugins, policy::key::kDisabledPlugins, |
+ policy::key::kDisabledPluginsExceptions}; |
+ bool ok = true; |
+ for (size_t i = 0; i < arraysize(checked_policies); ++i) { |
+ const base::Value* value = policies.GetValue(checked_policies[i]); |
+ if (value && !value->IsType(base::Value::TYPE_LIST)) { |
+ errors->AddError(checked_policies[i], IDS_POLICY_TYPE_ERROR, |
+ base::Value::GetTypeName(base::Value::TYPE_LIST)); |
+ ok = false; |
+ } |
+ } |
+ return ok; |
+} |
+ |
+void PluginPolicyHandler::ApplyPolicySettings(const policy::PolicyMap& policies, |
+ PrefValueMap* prefs) { |
+ // This order makes enabled plugins take precedence as is now. |
+ ProcessPolicy(policies, prefs, policy::key::kDisabledPlugins, true, |
+ CONTENT_SETTING_BLOCK); |
+ ProcessPolicy(policies, prefs, policy::key::kEnabledPlugins, false, |
+ CONTENT_SETTING_ALLOW); |
+ |
+ // Finally check if any of the two is in the exceptions list and remove the |
+ // policy changes. |
+ const base::ListValue* plugins = |
+ GetListPolicy(policies, policy::key::kDisabledPluginsExceptions); |
+ if (!plugins) |
+ return; |
+ const int size = plugins->GetSize(); |
+ for (int i = 0; i < size; ++i) { |
+ std::string plugin; |
+ if (!plugins->GetString(i, &plugin)) |
+ continue; |
+ plugin = base::ToUpperASCII(plugin); |
+ if (base::MatchPattern( |
+ base::ToUpperASCII(ChromeContentClient::kPDFPluginName), plugin) && |
+ !policies.GetValue(policy::key::kAlwaysOpenPdfExternally)) { |
+ prefs->RemoveValue(prefs::kPluginsAlwaysOpenPdfExternally); |
+ } |
+ if (base::MatchPattern(base::ToUpperASCII(kAdobeFlashPlayerName), plugin) && |
+ !policies.GetValue(policy::key::kDefaultPluginsSetting)) { |
+ prefs->RemoveValue(prefs::kManagedDefaultPluginsSetting); |
+ } |
+ } |
+} |