blob: 3b31e66c21f52e50951fffb0681e3f3a8516884e [file] [log] [blame]
[email protected]5b8865c2013-10-24 13:27:471// Copyright 2013 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/policy/javascript_policy_handler.h"
6
7#include "base/prefs/pref_value_map.h"
8#include "base/values.h"
mukai077089f2014-09-11 18:41:529#include "components/content_settings/core/common/content_settings.h"
brettwe1f0af8b2015-10-09 21:30:4610#include "components/content_settings/core/common/pref_names.h"
[email protected]f6c403b2013-12-05 19:01:2511#include "components/policy/core/browser/policy_error_map.h"
[email protected]c4a138a2013-11-21 19:54:5712#include "components/policy/core/common/policy_map.h"
[email protected]426d676a2014-05-28 14:41:0313#include "grit/components_strings.h"
[email protected]5b8865c2013-10-24 13:27:4714#include "policy/policy_constants.h"
15
16namespace policy {
17
18JavascriptPolicyHandler::JavascriptPolicyHandler() {}
19
20JavascriptPolicyHandler::~JavascriptPolicyHandler() {}
21
22bool JavascriptPolicyHandler::CheckPolicySettings(const PolicyMap& policies,
23 PolicyErrorMap* errors) {
24 const base::Value* javascript_enabled =
25 policies.GetValue(key::kJavascriptEnabled);
26 const base::Value* default_setting =
27 policies.GetValue(key::kDefaultJavaScriptSetting);
28
29 if (javascript_enabled &&
30 !javascript_enabled->IsType(base::Value::TYPE_BOOLEAN)) {
31 errors->AddError(key::kJavascriptEnabled,
32 IDS_POLICY_TYPE_ERROR,
33 ValueTypeToString(base::Value::TYPE_BOOLEAN));
34 }
35
36 if (default_setting && !default_setting->IsType(base::Value::TYPE_INTEGER)) {
37 errors->AddError(key::kDefaultJavaScriptSetting,
38 IDS_POLICY_TYPE_ERROR,
39 ValueTypeToString(base::Value::TYPE_INTEGER));
40 }
41
42 if (javascript_enabled && default_setting) {
43 errors->AddError(key::kJavascriptEnabled,
44 IDS_POLICY_OVERRIDDEN,
45 key::kDefaultJavaScriptSetting);
46 }
47
48 return true;
49}
50
51void JavascriptPolicyHandler::ApplyPolicySettings(const PolicyMap& policies,
52 PrefValueMap* prefs) {
53 int setting = CONTENT_SETTING_DEFAULT;
54 const base::Value* default_setting =
55 policies.GetValue(key::kDefaultJavaScriptSetting);
56
57 if (default_setting) {
58 default_setting->GetAsInteger(&setting);
59 } else {
60 const base::Value* javascript_enabled =
61 policies.GetValue(key::kJavascriptEnabled);
62 bool enabled = true;
63 if (javascript_enabled &&
64 javascript_enabled->GetAsBoolean(&enabled) &&
65 !enabled) {
66 setting = CONTENT_SETTING_BLOCK;
67 }
68 }
69
[email protected]a7965a42014-07-22 02:35:5670 if (setting != CONTENT_SETTING_DEFAULT)
71 prefs->SetInteger(prefs::kManagedDefaultJavaScriptSetting, setting);
[email protected]5b8865c2013-10-24 13:27:4772}
73
74} // namespace policy