Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Side by Side Diff: chrome/browser/policy/configuration_policy_handler.cc

Issue 10035043: Update RestoreOnStartupPolicyHandler to translate to the correct preferences (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: \n Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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)
984 ApplyPolicySettingsFromHomePage(policies, prefs);
985 else
986 prefs->SetInteger(prefs::kRestoreOnStartup, restore_on_startup);
987 }
988 }
989
990 void RestoreOnStartupPolicyHandler::ApplyPolicySettingsFromHomePage(
991 const PolicyMap& policies,
992 PrefValueMap* prefs) {
993 const base::Value* homepage_is_new_tab_page_value =
994 policies.GetValue(key::kHomepageIsNewTabPage);
995 if (!homepage_is_new_tab_page_value) {
996 // The policy is enforcing 'open the homepage on startup' but not
997 // enforcing what the homepage should be. Don't set any prefs.
998 return;
999 }
1000
1001 bool homepage_is_new_tab_page;
1002 if (!homepage_is_new_tab_page_value->GetAsBoolean(&homepage_is_new_tab_page))
1003 return;
1004
1005 if (homepage_is_new_tab_page) {
1006 prefs->SetInteger(prefs::kRestoreOnStartup,
1007 SessionStartupPref::kPrefValueNewTab);
1008 } else {
1009 const base::Value* homepage_value =
1010 policies.GetValue(key::kHomepageLocation);
1011 if (!homepage_value || !homepage_value->IsType(base::Value::TYPE_STRING)) {
1012 // The policy is enforcing 'open the homepage on startup' but not
1013 // enforcing what the homepage should be. Don't set any prefs.
1014 return;
1015 }
1016 ListValue* url_list = new ListValue();
1017 url_list->Append(homepage_value->DeepCopy());
1018 prefs->SetInteger(prefs::kRestoreOnStartup,
1019 SessionStartupPref::kPrefValueURLs);
1020 prefs->SetValue(prefs::kURLsToRestoreOnStartup, url_list);
1021 }
1022 }
1023
975 bool RestoreOnStartupPolicyHandler::CheckPolicySettings( 1024 bool RestoreOnStartupPolicyHandler::CheckPolicySettings(
976 const PolicyMap& policies, 1025 const PolicyMap& policies,
977 PolicyErrorMap* errors) { 1026 PolicyErrorMap* errors) {
978 if (!SimplePolicyHandler::CheckPolicySettings(policies, errors)) 1027 if (!TypeCheckingPolicyHandler::CheckPolicySettings(policies, errors))
979 return false; 1028 return false;
980 1029
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); 1030 const base::Value* restore_policy = policies.GetValue(key::kRestoreOnStartup);
985 1031
986 if (restore_policy) { 1032 if (restore_policy) {
987 int restore_value; 1033 int restore_value;
988 if (restore_policy->GetAsInteger(&restore_value) && 1034 if (restore_policy->GetAsInteger(&restore_value)) {
989 SessionStartupPref::PrefValueToType(restore_value) == 1035 switch (restore_value) {
990 SessionStartupPref::LAST) { 1036 case SessionStartupPref::kPrefValueHomePage:
1037 // TODO(tbreisacher): AddError indicating this value is deprecated.
1038 break;
1039 case SessionStartupPref::kPrefValueLast: {
1040 // If the "restore last session" policy is set, session cookies are
1041 // treated as permanent cookies and site data needed to restore the
1042 // session is not cleared so we have to warn the user in that case.
1043 const base::Value* cookies_policy =
1044 policies.GetValue(key::kCookiesSessionOnlyForUrls);
1045 const base::ListValue *cookies_value;
1046 if (cookies_policy && cookies_policy->GetAsList(&cookies_value) &&
1047 !cookies_value->empty()) {
1048 errors->AddError(key::kCookiesSessionOnlyForUrls,
1049 IDS_POLICY_OVERRIDDEN,
1050 key::kRestoreOnStartup);
1051 }
991 1052
992 const base::Value* cookies_policy = 1053 const base::Value* exit_policy =
993 policies.GetValue(key::kCookiesSessionOnlyForUrls); 1054 policies.GetValue(key::kClearSiteDataOnExit);
994 const base::ListValue *cookies_value; 1055 bool exit_value;
995 if (cookies_policy && cookies_policy->GetAsList(&cookies_value) && 1056 if (exit_policy &&
996 !cookies_value->empty()) { 1057 exit_policy->GetAsBoolean(&exit_value) && exit_value) {
997 errors->AddError(key::kCookiesSessionOnlyForUrls, 1058 errors->AddError(key::kClearSiteDataOnExit,
998 IDS_POLICY_OVERRIDDEN, 1059 IDS_POLICY_OVERRIDDEN,
999 key::kRestoreOnStartup); 1060 key::kRestoreOnStartup);
1000 } 1061 }
1001 1062 break;
1002 const base::Value* exit_policy = 1063 }
1003 policies.GetValue(key::kClearSiteDataOnExit); 1064 case SessionStartupPref::kPrefValueURLs:
1004 bool exit_value; 1065 case SessionStartupPref::kPrefValueNewTab:
1005 if (exit_policy && exit_policy->GetAsBoolean(&exit_value) && exit_value) { 1066 // No error
1006 errors->AddError(key::kClearSiteDataOnExit, 1067 break;
1007 IDS_POLICY_OVERRIDDEN, 1068 default:
1008 key::kRestoreOnStartup); 1069 errors->AddError(policy_name(),
1070 IDS_POLICY_OUT_OF_RANGE_ERROR,
1071 base::IntToString(restore_value));
1009 } 1072 }
1010 } 1073 }
1011 } 1074 }
1012 return true; 1075 return true;
1013 } 1076 }
1014 1077
1015 } // namespace policy 1078 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/configuration_policy_handler.h ('k') | chrome/browser/policy/configuration_policy_reader_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698