Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/policy/configuration_policy_handler.h" | 5 #include "chrome/browser/policy/configuration_policy_handler.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
| (...skipping 946 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 957 | 957 |
| 958 if (setting != CONTENT_SETTING_DEFAULT) { | 958 if (setting != CONTENT_SETTING_DEFAULT) { |
| 959 prefs->SetValue(prefs::kManagedDefaultJavaScriptSetting, | 959 prefs->SetValue(prefs::kManagedDefaultJavaScriptSetting, |
| 960 Value::CreateIntegerValue(setting)); | 960 Value::CreateIntegerValue(setting)); |
| 961 } | 961 } |
| 962 } | 962 } |
| 963 | 963 |
| 964 // RestoreOnStartupPolicyHandler implementation -------------------------------- | 964 // RestoreOnStartupPolicyHandler implementation -------------------------------- |
| 965 | 965 |
| 966 RestoreOnStartupPolicyHandler::RestoreOnStartupPolicyHandler() | 966 RestoreOnStartupPolicyHandler::RestoreOnStartupPolicyHandler() |
| 967 : SimplePolicyHandler(key::kRestoreOnStartup, | 967 : TypeCheckingPolicyHandler(key::kRestoreOnStartup, |
| 968 prefs::kRestoreOnStartup, | 968 Value::TYPE_INTEGER) { |
| 969 Value::TYPE_INTEGER) { | |
| 970 } | 969 } |
| 971 | 970 |
| 972 RestoreOnStartupPolicyHandler::~RestoreOnStartupPolicyHandler() { | 971 RestoreOnStartupPolicyHandler::~RestoreOnStartupPolicyHandler() { |
| 973 } | 972 } |
| 974 | 973 |
| 974 void RestoreOnStartupPolicyHandler::ApplyPolicySettings( | |
| 975 const PolicyMap& policies, | |
| 976 PrefValueMap* prefs) { | |
| 977 const Value* restore_on_startup_value = policies.GetValue(policy_name()); | |
| 978 if (restore_on_startup_value) { | |
| 979 int restore_on_startup; | |
| 980 if (!restore_on_startup_value->GetAsInteger(&restore_on_startup)) | |
| 981 return; | |
| 982 | |
| 983 if (restore_on_startup == SessionStartupPref::kPrefValueHomePage) { | |
|
Mattias Nissler (ping if slow)
2012/04/23 09:40:46
If you like, you can remove braces here. I'm fine
Tyler Breisacher (Chromium)
2012/04/23 17:54:03
Done.
| |
| 984 ApplyPolicySettingsFromHomePage(policies, prefs); | |
| 985 } else { | |
| 986 prefs->SetInteger(prefs::kRestoreOnStartup, restore_on_startup); | |
| 987 } | |
| 988 } | |
| 989 } | |
| 990 | |
| 991 void RestoreOnStartupPolicyHandler::ApplyPolicySettingsFromHomePage( | |
| 992 const PolicyMap& policies, | |
| 993 PrefValueMap* prefs) { | |
| 994 | |
|
csilv
2012/04/23 17:57:26
nit, kill this blank line
Tyler Breisacher (Chromium)
2012/04/23 18:00:11
Done.
| |
| 995 const base::Value* homepage_is_new_tab_page_value = | |
| 996 policies.GetValue(key::kHomepageIsNewTabPage); | |
| 997 if (!homepage_is_new_tab_page_value) { | |
| 998 // The policy is enforcing 'open the homepage on startup' but not | |
| 999 // enforcing what the homepage should be. Don't set any prefs. | |
| 1000 return; | |
| 1001 } | |
| 1002 | |
| 1003 bool homepage_is_new_tab_page; | |
| 1004 if (!homepage_is_new_tab_page_value->GetAsBoolean(&homepage_is_new_tab_page)) | |
| 1005 return; | |
| 1006 | |
| 1007 if (homepage_is_new_tab_page) { | |
| 1008 prefs->SetInteger( | |
|
Mattias Nissler (ping if slow)
2012/04/23 09:40:46
nit: could remove the line break after ( and align
Tyler Breisacher (Chromium)
2012/04/23 17:54:03
Done.
| |
| 1009 prefs::kRestoreOnStartup, | |
| 1010 SessionStartupPref::kPrefValueNewTab); | |
| 1011 } else { | |
| 1012 const base::Value* homepage_value = | |
| 1013 policies.GetValue(key::kHomepageLocation); | |
| 1014 if (!homepage_value || !homepage_value->IsType(base::Value::TYPE_STRING)) { | |
| 1015 // The policy is enforcing 'open the homepage on startup' but not | |
| 1016 // enforcing what the homepage should be. Don't set any prefs. | |
| 1017 return; | |
| 1018 } | |
| 1019 ListValue* url_list = new ListValue(); | |
| 1020 url_list->Append(homepage_value->DeepCopy()); | |
| 1021 prefs->SetInteger( | |
|
Mattias Nissler (ping if slow)
2012/04/23 09:40:46
same here.
Tyler Breisacher (Chromium)
2012/04/23 17:54:03
Done.
| |
| 1022 prefs::kRestoreOnStartup, | |
| 1023 SessionStartupPref::kPrefValueURLs); | |
| 1024 prefs->SetValue(prefs::kURLsToRestoreOnStartup, url_list); | |
| 1025 } | |
| 1026 } | |
| 1027 | |
| 975 bool RestoreOnStartupPolicyHandler::CheckPolicySettings( | 1028 bool RestoreOnStartupPolicyHandler::CheckPolicySettings( |
| 976 const PolicyMap& policies, | 1029 const PolicyMap& policies, |
| 977 PolicyErrorMap* errors) { | 1030 PolicyErrorMap* errors) { |
| 978 if (!SimplePolicyHandler::CheckPolicySettings(policies, errors)) | 1031 if (!TypeCheckingPolicyHandler::CheckPolicySettings(policies, errors)) |
| 979 return false; | 1032 return false; |
| 980 | 1033 |
| 981 // If the restore urls at start up policy is set, session cookies are treated | |
| 982 // as permanent cookies and site data needed to restore the session is not | |
| 983 // cleared so we have to warn the user in that case. | |
| 984 const base::Value* restore_policy = policies.GetValue(key::kRestoreOnStartup); | 1034 const base::Value* restore_policy = policies.GetValue(key::kRestoreOnStartup); |
| 985 | 1035 |
| 986 if (restore_policy) { | 1036 if (restore_policy) { |
| 987 int restore_value; | 1037 int restore_value; |
| 988 if (restore_policy->GetAsInteger(&restore_value) && | 1038 if (restore_policy->GetAsInteger(&restore_value)) { |
| 989 SessionStartupPref::PrefValueToType(restore_value) == | 1039 switch (restore_value) { |
| 990 SessionStartupPref::LAST) { | 1040 case SessionStartupPref::kPrefValueHomePage: |
| 1041 // TODO(tbreisacher): AddError indicating this value is deprecated. | |
|
Mattias Nissler (ping if slow)
2012/04/23 09:40:46
Ah, so you are planning to merge this CL without c
Tyler Breisacher (Chromium)
2012/04/23 17:54:03
Yes.
| |
| 1042 break; | |
| 1043 case SessionStartupPref::kPrefValueLast: { | |
| 1044 // If the "restore last session" policy is set, session cookies are | |
| 1045 // treated as permanent cookies and site data needed to restore the | |
| 1046 // session is not cleared so we have to warn the user in that case. | |
| 1047 const base::Value* cookies_policy = | |
| 1048 policies.GetValue(key::kCookiesSessionOnlyForUrls); | |
| 1049 const base::ListValue *cookies_value; | |
| 1050 if (cookies_policy && cookies_policy->GetAsList(&cookies_value) && | |
| 1051 !cookies_value->empty()) { | |
| 1052 errors->AddError(key::kCookiesSessionOnlyForUrls, | |
| 1053 IDS_POLICY_OVERRIDDEN, | |
| 1054 key::kRestoreOnStartup); | |
| 1055 } | |
| 991 | 1056 |
| 992 const base::Value* cookies_policy = | 1057 const base::Value* exit_policy = |
| 993 policies.GetValue(key::kCookiesSessionOnlyForUrls); | 1058 policies.GetValue(key::kClearSiteDataOnExit); |
| 994 const base::ListValue *cookies_value; | 1059 bool exit_value; |
| 995 if (cookies_policy && cookies_policy->GetAsList(&cookies_value) && | 1060 if (exit_policy && |
| 996 !cookies_value->empty()) { | 1061 exit_policy->GetAsBoolean(&exit_value) && exit_value) { |
| 997 errors->AddError(key::kCookiesSessionOnlyForUrls, | 1062 errors->AddError(key::kClearSiteDataOnExit, |
| 998 IDS_POLICY_OVERRIDDEN, | 1063 IDS_POLICY_OVERRIDDEN, |
| 999 key::kRestoreOnStartup); | 1064 key::kRestoreOnStartup); |
| 1000 } | 1065 } |
| 1001 | 1066 break; |
| 1002 const base::Value* exit_policy = | 1067 } |
| 1003 policies.GetValue(key::kClearSiteDataOnExit); | 1068 case SessionStartupPref::kPrefValueURLs: |
| 1004 bool exit_value; | 1069 case SessionStartupPref::kPrefValueNewTab: |
| 1005 if (exit_policy && exit_policy->GetAsBoolean(&exit_value) && exit_value) { | 1070 // No error |
| 1006 errors->AddError(key::kClearSiteDataOnExit, | 1071 break; |
| 1007 IDS_POLICY_OVERRIDDEN, | 1072 default: |
| 1008 key::kRestoreOnStartup); | 1073 errors->AddError(policy_name(), |
| 1074 IDS_POLICY_OUT_OF_RANGE_ERROR, | |
| 1075 base::IntToString(restore_value)); | |
| 1009 } | 1076 } |
| 1010 } | 1077 } |
| 1011 } | 1078 } |
| 1012 return true; | 1079 return true; |
| 1013 } | 1080 } |
| 1014 | 1081 |
| 1015 } // namespace policy | 1082 } // namespace policy |
| OLD | NEW |