1 // 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.
5 #include "chrome/browser/policy/javascript_policy_handler.h"
7 #include "base/prefs/pref_value_map.h"
8 #include "base/values.h"
9 #include "chrome/common/pref_names.h"
10 #include "components/content_settings/core/common/content_settings.h"
11 #include "components/policy/core/browser/policy_error_map.h"
12 #include "components/policy/core/common/policy_map.h"
13 #include "grit/components_strings.h"
14 #include "policy/policy_constants.h"
18 JavascriptPolicyHandler::JavascriptPolicyHandler() {}
20 JavascriptPolicyHandler::~JavascriptPolicyHandler() {}
22 bool 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
);
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
));
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
));
42 if (javascript_enabled
&& default_setting
) {
43 errors
->AddError(key::kJavascriptEnabled
,
44 IDS_POLICY_OVERRIDDEN
,
45 key::kDefaultJavaScriptSetting
);
51 void 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
);
57 if (default_setting
) {
58 default_setting
->GetAsInteger(&setting
);
60 const base::Value
* javascript_enabled
=
61 policies
.GetValue(key::kJavascriptEnabled
);
63 if (javascript_enabled
&&
64 javascript_enabled
->GetAsBoolean(&enabled
) &&
66 setting
= CONTENT_SETTING_BLOCK
;
70 if (setting
!= CONTENT_SETTING_DEFAULT
)
71 prefs
->SetInteger(prefs::kManagedDefaultJavaScriptSetting
, setting
);