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 948 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
959 | 959 |
960 RestoreOnStartupPolicyHandler::RestoreOnStartupPolicyHandler() | 960 RestoreOnStartupPolicyHandler::RestoreOnStartupPolicyHandler() |
961 : SimplePolicyHandler(key::kRestoreOnStartup, | 961 : SimplePolicyHandler(key::kRestoreOnStartup, |
962 prefs::kRestoreOnStartup, | 962 prefs::kRestoreOnStartup, |
963 Value::TYPE_INTEGER) { | 963 Value::TYPE_INTEGER) { |
964 } | 964 } |
965 | 965 |
966 RestoreOnStartupPolicyHandler::~RestoreOnStartupPolicyHandler() { | 966 RestoreOnStartupPolicyHandler::~RestoreOnStartupPolicyHandler() { |
967 } | 967 } |
968 | 968 |
969 void RestoreOnStartupPolicyHandler::ApplyPolicySettings( | |
970 const PolicyMap& policies, | |
971 PrefValueMap* prefs) { | |
972 const Value* restore_on_startup_value = policies.GetValue(policy_name()); | |
973 int restore_on_startup = -1; | |
974 if (restore_on_startup_value) | |
975 restore_on_startup_value->GetAsInteger(&restore_on_startup); | |
976 | |
977 if (restore_on_startup == SessionStartupPref::kPrefValueHomePage) { | |
978 ApplyPolicySettingsFromHomePage(policies, prefs); | |
979 } else { | |
980 SimplePolicyHandler::ApplyPolicySettings(policies, prefs); | |
Mattias Nissler (ping if slow)
2012/04/19 13:15:55
This would be just prefs->SetValue() if you don't
Tyler Breisacher (Chromium)
2012/04/19 19:07:56
Done.
| |
981 } | |
982 } | |
983 | |
984 void RestoreOnStartupPolicyHandler::ApplyPolicySettingsFromHomePage( | |
985 const PolicyMap& policies, | |
986 PrefValueMap* prefs) { | |
987 | |
988 const base::Value* homepage_is_new_tab_page_value = | |
989 policies.GetValue(key::kHomepageIsNewTabPage); | |
990 if (!homepage_is_new_tab_page_value) { | |
991 // The policy is enforcing 'open the homepage on startup' but not | |
992 // enforcing what the homepage should be. Don't set any prefs. | |
Mattias Nissler (ping if slow)
2012/04/19 13:15:55
So the policy doesn't have the homepage_is_new_tab
Tyler Breisacher (Chromium)
2012/04/19 19:07:56
In Chrome 18, if a policy has RestoreOnStartup=0 a
Mattias Nissler (ping if slow)
2012/04/20 09:20:24
You're right.
| |
993 return; | |
994 } | |
995 | |
996 bool homepage_is_new_tab_page; | |
997 bool result = homepage_is_new_tab_page_value->GetAsBoolean( | |
998 &homepage_is_new_tab_page); | |
999 DCHECK(result); | |
Mattias Nissler (ping if slow)
2012/04/19 13:15:55
This DCHECK is inappropriate. The Value you get he
Tyler Breisacher (Chromium)
2012/04/19 19:07:56
Done. (Also did the same thing above for homepage_
| |
1000 | |
1001 if (homepage_is_new_tab_page) { | |
1002 prefs->SetInteger( | |
1003 prefs::kRestoreOnStartup, | |
1004 SessionStartupPref::kPrefValueNewTab); | |
1005 } else { | |
1006 const base::Value* homepage_value = | |
1007 policies.GetValue(key::kHomepageLocation); | |
1008 if (!homepage_value) { | |
1009 // The policy is enforcing 'open the homepage on startup' but not | |
1010 // enforcing what the homepage should be. Don't set any prefs. | |
1011 return; | |
1012 } | |
1013 ListValue* url_list = new ListValue(); | |
1014 url_list->Append(homepage_value->DeepCopy()); | |
1015 prefs->SetInteger( | |
1016 prefs::kRestoreOnStartup, | |
1017 SessionStartupPref::kPrefValueURLs); | |
1018 prefs->SetValue(prefs::kURLsToRestoreOnStartup, url_list); | |
1019 } | |
1020 } | |
1021 | |
969 bool RestoreOnStartupPolicyHandler::CheckPolicySettings( | 1022 bool RestoreOnStartupPolicyHandler::CheckPolicySettings( |
970 const PolicyMap& policies, | 1023 const PolicyMap& policies, |
971 PolicyErrorMap* errors) { | 1024 PolicyErrorMap* errors) { |
972 if (!SimplePolicyHandler::CheckPolicySettings(policies, errors)) | 1025 if (!SimplePolicyHandler::CheckPolicySettings(policies, errors)) |
973 return false; | 1026 return false; |
974 | 1027 |
Mattias Nissler (ping if slow)
2012/04/19 13:15:55
Ideally, you should add a check here that marks th
Tyler Breisacher (Chromium)
2012/04/19 19:07:56
Done, but I'm pretty sure we'll want to merge this
Mattias Nissler (ping if slow)
2012/04/20 09:20:24
Yes, it is too late. I'm OK with merging an adjust
| |
975 // If the restore urls at start up policy is set, session cookies are treated | 1028 // If the restore urls at start up policy is set, session cookies are treated |
976 // as permanent cookies and site data needed to restore the session is not | 1029 // as permanent cookies and site data needed to restore the session is not |
977 // cleared so we have to warn the user in that case. | 1030 // cleared so we have to warn the user in that case. |
978 const base::Value* restore_policy = policies.GetValue(key::kRestoreOnStartup); | 1031 const base::Value* restore_policy = policies.GetValue(key::kRestoreOnStartup); |
979 | 1032 |
980 if (restore_policy) { | 1033 if (restore_policy) { |
981 int restore_value; | 1034 int restore_value; |
982 if (restore_policy->GetAsInteger(&restore_value) && | 1035 if (restore_policy->GetAsInteger(&restore_value) && |
983 SessionStartupPref::PrefValueToType(restore_value) == | 1036 restore_value == SessionStartupPref::kPrefValueLast) { |
984 SessionStartupPref::LAST) { | |
985 | 1037 |
986 const base::Value* cookies_policy = | 1038 const base::Value* cookies_policy = |
987 policies.GetValue(key::kCookiesSessionOnlyForUrls); | 1039 policies.GetValue(key::kCookiesSessionOnlyForUrls); |
988 const base::ListValue *cookies_value; | 1040 const base::ListValue *cookies_value; |
989 if (cookies_policy && cookies_policy->GetAsList(&cookies_value) && | 1041 if (cookies_policy && cookies_policy->GetAsList(&cookies_value) && |
990 !cookies_value->empty()) { | 1042 !cookies_value->empty()) { |
991 errors->AddError(key::kCookiesSessionOnlyForUrls, | 1043 errors->AddError(key::kCookiesSessionOnlyForUrls, |
992 IDS_POLICY_OVERRIDDEN, | 1044 IDS_POLICY_OVERRIDDEN, |
993 key::kRestoreOnStartup); | 1045 key::kRestoreOnStartup); |
994 } | 1046 } |
995 | 1047 |
996 const base::Value* exit_policy = | 1048 const base::Value* exit_policy = |
997 policies.GetValue(key::kClearSiteDataOnExit); | 1049 policies.GetValue(key::kClearSiteDataOnExit); |
998 bool exit_value; | 1050 bool exit_value; |
999 if (exit_policy && exit_policy->GetAsBoolean(&exit_value) && exit_value) { | 1051 if (exit_policy && exit_policy->GetAsBoolean(&exit_value) && exit_value) { |
1000 errors->AddError(key::kClearSiteDataOnExit, | 1052 errors->AddError(key::kClearSiteDataOnExit, |
1001 IDS_POLICY_OVERRIDDEN, | 1053 IDS_POLICY_OVERRIDDEN, |
1002 key::kRestoreOnStartup); | 1054 key::kRestoreOnStartup); |
1003 } | 1055 } |
1004 } | 1056 } |
1005 } | 1057 } |
1006 return true; | 1058 return true; |
1007 } | 1059 } |
1008 | 1060 |
1009 } // namespace policy | 1061 } // namespace policy |
OLD | NEW |