blob: 8f2194ad581807f9653f814eec4a5705e3ab000a [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
[email protected]5b8865c2013-10-24 13:27:477#include "base/values.h"
mukai077089f2014-09-11 18:41:528#include "components/content_settings/core/common/content_settings.h"
brettwe1f0af8b2015-10-09 21:30:469#include "components/content_settings/core/common/pref_names.h"
[email protected]f6c403b2013-12-05 19:01:2510#include "components/policy/core/browser/policy_error_map.h"
[email protected]c4a138a2013-11-21 19:54:5711#include "components/policy/core/common/policy_map.h"
brettw39d6ba42016-08-24 16:56:3812#include "components/policy/policy_constants.h"
brettwb1fc1b82016-02-02 00:19:0813#include "components/prefs/pref_value_map.h"
thestig4a2e88e2016-08-27 23:23:5114#include "components/strings/grit/components_strings.h"
[email protected]5b8865c2013-10-24 13:27:4715
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 &&
jdoerriedc72ee942016-12-07 15:43:2830 !javascript_enabled->IsType(base::Value::Type::BOOLEAN)) {
thestige7615d6c2016-07-19 19:43:4631 errors->AddError(key::kJavascriptEnabled, IDS_POLICY_TYPE_ERROR,
jdoerriedc72ee942016-12-07 15:43:2832 base::Value::GetTypeName(base::Value::Type::BOOLEAN));
[email protected]5b8865c2013-10-24 13:27:4733 }
34
jdoerriedc72ee942016-12-07 15:43:2835 if (default_setting && !default_setting->IsType(base::Value::Type::INTEGER)) {
thestige7615d6c2016-07-19 19:43:4636 errors->AddError(key::kDefaultJavaScriptSetting, IDS_POLICY_TYPE_ERROR,
jdoerriedc72ee942016-12-07 15:43:2837 base::Value::GetTypeName(base::Value::Type::INTEGER));
[email protected]5b8865c2013-10-24 13:27:4738 }
39
40 if (javascript_enabled && default_setting) {
41 errors->AddError(key::kJavascriptEnabled,
42 IDS_POLICY_OVERRIDDEN,
43 key::kDefaultJavaScriptSetting);
44 }
45
46 return true;
47}
48
49void JavascriptPolicyHandler::ApplyPolicySettings(const PolicyMap& policies,
50 PrefValueMap* prefs) {
51 int setting = CONTENT_SETTING_DEFAULT;
52 const base::Value* default_setting =
53 policies.GetValue(key::kDefaultJavaScriptSetting);
54
55 if (default_setting) {
56 default_setting->GetAsInteger(&setting);
57 } else {
58 const base::Value* javascript_enabled =
59 policies.GetValue(key::kJavascriptEnabled);
60 bool enabled = true;
61 if (javascript_enabled &&
62 javascript_enabled->GetAsBoolean(&enabled) &&
63 !enabled) {
64 setting = CONTENT_SETTING_BLOCK;
65 }
66 }
67
[email protected]a7965a42014-07-22 02:35:5668 if (setting != CONTENT_SETTING_DEFAULT)
69 prefs->SetInteger(prefs::kManagedDefaultJavaScriptSetting, setting);
[email protected]5b8865c2013-10-24 13:27:4770}
71
72} // namespace policy