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 bool result = restore_on_startup_value->GetAsInteger(&restore_on_startup); | |
| 981 if (!result) | |
|
Mattias Nissler (ping if slow)
2012/04/20 09:20:24
nit: how about dropping the result local and just
Tyler Breisacher (Chromium)
2012/04/20 18:39:44
I think that's more consistent with Chrome code, t
| |
| 982 return; | |
| 983 | |
| 984 if (restore_on_startup == SessionStartupPref::kPrefValueHomePage) { | |
| 985 ApplyPolicySettingsFromHomePage(policies, prefs); | |
| 986 } else { | |
| 987 prefs->SetInteger(prefs::kRestoreOnStartup, restore_on_startup); | |
| 988 } | |
| 989 } | |
| 990 } | |
| 991 | |
| 992 void RestoreOnStartupPolicyHandler::ApplyPolicySettingsFromHomePage( | |
| 993 const PolicyMap& policies, | |
| 994 PrefValueMap* prefs) { | |
| 995 | |
| 996 const base::Value* homepage_is_new_tab_page_value = | |
| 997 policies.GetValue(key::kHomepageIsNewTabPage); | |
| 998 if (!homepage_is_new_tab_page_value) { | |
| 999 // The policy is enforcing 'open the homepage on startup' but not | |
| 1000 // enforcing what the homepage should be. Don't set any prefs. | |
| 1001 return; | |
| 1002 } | |
| 1003 | |
| 1004 bool homepage_is_new_tab_page; | |
| 1005 bool result = homepage_is_new_tab_page_value->GetAsBoolean( | |
| 1006 &homepage_is_new_tab_page); | |
| 1007 if (!result) | |
|
Mattias Nissler (ping if slow)
2012/04/20 09:20:24
nit: could drop the result local here as well.
Tyler Breisacher (Chromium)
2012/04/20 18:39:44
Done.
| |
| 1008 return; | |
| 1009 | |
| 1010 if (homepage_is_new_tab_page) { | |
| 1011 prefs->SetInteger( | |
| 1012 prefs::kRestoreOnStartup, | |
| 1013 SessionStartupPref::kPrefValueNewTab); | |
| 1014 } else { | |
| 1015 const base::Value* homepage_value = | |
| 1016 policies.GetValue(key::kHomepageLocation); | |
| 1017 if (!homepage_value) { | |
| 1018 // The policy is enforcing 'open the homepage on startup' but not | |
| 1019 // enforcing what the homepage should be. Don't set any prefs. | |
| 1020 return; | |
| 1021 } | |
| 1022 ListValue* url_list = new ListValue(); | |
| 1023 url_list->Append(homepage_value->DeepCopy()); | |
| 1024 prefs->SetInteger( | |
| 1025 prefs::kRestoreOnStartup, | |
| 1026 SessionStartupPref::kPrefValueURLs); | |
| 1027 prefs->SetValue(prefs::kURLsToRestoreOnStartup, url_list); | |
| 1028 } | |
| 1029 } | |
| 1030 | |
| 975 bool RestoreOnStartupPolicyHandler::CheckPolicySettings( | 1031 bool RestoreOnStartupPolicyHandler::CheckPolicySettings( |
| 976 const PolicyMap& policies, | 1032 const PolicyMap& policies, |
| 977 PolicyErrorMap* errors) { | 1033 PolicyErrorMap* errors) { |
| 978 if (!SimplePolicyHandler::CheckPolicySettings(policies, errors)) | 1034 if (!TypeCheckingPolicyHandler::CheckPolicySettings(policies, errors)) |
| 979 return false; | 1035 return false; |
| 980 | 1036 |
| 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); | 1037 const base::Value* restore_policy = policies.GetValue(key::kRestoreOnStartup); |
| 985 | 1038 |
| 986 if (restore_policy) { | 1039 if (restore_policy) { |
| 987 int restore_value; | 1040 int restore_value; |
| 988 if (restore_policy->GetAsInteger(&restore_value) && | 1041 bool result = restore_policy->GetAsInteger(&restore_value); |
| 989 SessionStartupPref::PrefValueToType(restore_value) == | 1042 if (result) { |
|
Mattias Nissler (ping if slow)
2012/04/20 09:20:24
nit: same thing
Tyler Breisacher (Chromium)
2012/04/20 18:39:44
Done.
| |
| 990 SessionStartupPref::LAST) { | 1043 if (restore_value == SessionStartupPref::kPrefValueHomePage) { |
| 1044 errors->AddError(policy_name(), | |
| 1045 IDS_POLICY_VALUE_DEPRECATED); | |
| 1046 } else if (restore_value == SessionStartupPref::kPrefValueLast) { | |
| 1047 // If the "restore last session" policy is set, session cookies are | |
| 1048 // treated as permanent cookies and site data needed to restore the | |
| 1049 // session is not cleared so we have to warn the user in that case. | |
| 1050 const base::Value* cookies_policy = | |
| 1051 policies.GetValue(key::kCookiesSessionOnlyForUrls); | |
| 1052 const base::ListValue *cookies_value; | |
| 1053 if (cookies_policy && cookies_policy->GetAsList(&cookies_value) && | |
| 1054 !cookies_value->empty()) { | |
| 1055 errors->AddError(key::kCookiesSessionOnlyForUrls, | |
| 1056 IDS_POLICY_OVERRIDDEN, | |
| 1057 key::kRestoreOnStartup); | |
| 1058 } | |
| 991 | 1059 |
| 992 const base::Value* cookies_policy = | 1060 const base::Value* exit_policy = |
| 993 policies.GetValue(key::kCookiesSessionOnlyForUrls); | 1061 policies.GetValue(key::kClearSiteDataOnExit); |
| 994 const base::ListValue *cookies_value; | 1062 bool exit_value; |
| 995 if (cookies_policy && cookies_policy->GetAsList(&cookies_value) && | 1063 if (exit_policy && |
| 996 !cookies_value->empty()) { | 1064 exit_policy->GetAsBoolean(&exit_value) && exit_value) { |
| 997 errors->AddError(key::kCookiesSessionOnlyForUrls, | 1065 errors->AddError(key::kClearSiteDataOnExit, |
| 998 IDS_POLICY_OVERRIDDEN, | 1066 IDS_POLICY_OVERRIDDEN, |
| 999 key::kRestoreOnStartup); | 1067 key::kRestoreOnStartup); |
| 1000 } | 1068 } |
| 1001 | |
| 1002 const base::Value* exit_policy = | |
| 1003 policies.GetValue(key::kClearSiteDataOnExit); | |
| 1004 bool exit_value; | |
| 1005 if (exit_policy && exit_policy->GetAsBoolean(&exit_value) && exit_value) { | |
| 1006 errors->AddError(key::kClearSiteDataOnExit, | |
| 1007 IDS_POLICY_OVERRIDDEN, | |
| 1008 key::kRestoreOnStartup); | |
| 1009 } | 1069 } |
|
Mattias Nissler (ping if slow)
2012/04/20 09:20:24
Another small request while you're at it: It would
Tyler Breisacher (Chromium)
2012/04/20 18:39:44
Done.
| |
| 1010 } | 1070 } |
| 1011 } | 1071 } |
| 1012 return true; | 1072 return true; |
| 1013 } | 1073 } |
| 1014 | 1074 |
| 1015 } // namespace policy | 1075 } // namespace policy |
| OLD | NEW |