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