OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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/sessions/restore_on_startup_policy_handler.h" | 5 #include "chrome/browser/sessions/restore_on_startup_policy_handler.h" |
6 | 6 |
7 #include "base/prefs/pref_value_map.h" | 7 #include "base/prefs/pref_value_map.h" |
8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "chrome/browser/prefs/session_startup_pref.h" | 10 #include "chrome/browser/prefs/session_startup_pref.h" |
(...skipping 15 matching lines...) Expand all Loading... | |
26 void RestoreOnStartupPolicyHandler::ApplyPolicySettings( | 26 void RestoreOnStartupPolicyHandler::ApplyPolicySettings( |
27 const PolicyMap& policies, | 27 const PolicyMap& policies, |
28 PrefValueMap* prefs) { | 28 PrefValueMap* prefs) { |
29 const base::Value* restore_on_startup_value = | 29 const base::Value* restore_on_startup_value = |
30 policies.GetValue(policy_name()); | 30 policies.GetValue(policy_name()); |
31 if (restore_on_startup_value) { | 31 if (restore_on_startup_value) { |
32 int restore_on_startup; | 32 int restore_on_startup; |
33 if (!restore_on_startup_value->GetAsInteger(&restore_on_startup)) | 33 if (!restore_on_startup_value->GetAsInteger(&restore_on_startup)) |
34 return; | 34 return; |
35 | 35 |
36 if (restore_on_startup == SessionStartupPref::kPrefValueHomePage) | 36 prefs->SetInteger(prefs::kRestoreOnStartup, restore_on_startup); |
37 ApplyPolicySettingsFromHomePage(policies, prefs); | |
38 else | |
39 prefs->SetInteger(prefs::kRestoreOnStartup, restore_on_startup); | |
40 } | 37 } |
41 } | 38 } |
42 | 39 |
43 void RestoreOnStartupPolicyHandler::ApplyPolicySettingsFromHomePage( | |
44 const PolicyMap& policies, | |
45 PrefValueMap* prefs) { | |
46 const base::Value* homepage_is_new_tab_page_value = | |
47 policies.GetValue(key::kHomepageIsNewTabPage); | |
48 if (!homepage_is_new_tab_page_value) { | |
49 // The policy is enforcing 'open the homepage on startup' but not | |
50 // enforcing what the homepage should be. Don't set any prefs. | |
51 return; | |
52 } | |
53 | |
54 bool homepage_is_new_tab_page; | |
55 if (!homepage_is_new_tab_page_value->GetAsBoolean(&homepage_is_new_tab_page)) | |
56 return; | |
57 | |
58 if (homepage_is_new_tab_page) { | |
59 prefs->SetInteger(prefs::kRestoreOnStartup, | |
60 SessionStartupPref::kPrefValueNewTab); | |
61 } else { | |
62 const base::Value* homepage_value = | |
63 policies.GetValue(key::kHomepageLocation); | |
64 if (!homepage_value || !homepage_value->IsType(base::Value::TYPE_STRING)) { | |
65 // The policy is enforcing 'open the homepage on startup' but not | |
66 // enforcing what the homepage should be. Don't set any prefs. | |
67 return; | |
68 } | |
69 scoped_ptr<base::ListValue> url_list(new base::ListValue()); | |
70 url_list->Append(homepage_value->CreateDeepCopy()); | |
71 prefs->SetInteger(prefs::kRestoreOnStartup, | |
72 SessionStartupPref::kPrefValueURLs); | |
73 prefs->SetValue(prefs::kURLsToRestoreOnStartup, url_list.Pass()); | |
74 } | |
75 } | |
76 | |
77 bool RestoreOnStartupPolicyHandler::CheckPolicySettings( | 40 bool RestoreOnStartupPolicyHandler::CheckPolicySettings( |
78 const PolicyMap& policies, | 41 const PolicyMap& policies, |
79 PolicyErrorMap* errors) { | 42 PolicyErrorMap* errors) { |
80 if (!TypeCheckingPolicyHandler::CheckPolicySettings(policies, errors)) | 43 if (!TypeCheckingPolicyHandler::CheckPolicySettings(policies, errors)) |
81 return false; | 44 return false; |
82 | 45 |
83 const base::Value* restore_policy = policies.GetValue(key::kRestoreOnStartup); | 46 const base::Value* restore_policy = policies.GetValue(key::kRestoreOnStartup); |
84 | 47 |
85 if (restore_policy) { | 48 if (restore_policy) { |
86 int restore_value; | 49 int restore_value; |
87 CHECK(restore_policy->GetAsInteger(&restore_value)); // Passed type check. | 50 CHECK(restore_policy->GetAsInteger(&restore_value)); // Passed type check. |
88 switch (restore_value) { | 51 switch (restore_value) { |
89 case SessionStartupPref::kPrefValueHomePage: | |
90 errors->AddError(policy_name(), IDS_POLICY_VALUE_DEPRECATED); | |
bartfab (slow)
2015/08/31 15:36:43
Please remove the string from components/policy_st
sdefresne
2015/09/02 11:30:19
Done.
| |
91 break; | |
92 case SessionStartupPref::kPrefValueLast: { | 52 case SessionStartupPref::kPrefValueLast: { |
93 // If the "restore last session" policy is set, session cookies are | 53 // If the "restore last session" policy is set, session cookies are |
94 // treated as permanent cookies and site data needed to restore the | 54 // treated as permanent cookies and site data needed to restore the |
95 // session is not cleared so we have to warn the user in that case. | 55 // session is not cleared so we have to warn the user in that case. |
96 const base::Value* cookies_policy = | 56 const base::Value* cookies_policy = |
97 policies.GetValue(key::kCookiesSessionOnlyForUrls); | 57 policies.GetValue(key::kCookiesSessionOnlyForUrls); |
98 const base::ListValue* cookies_value; | 58 const base::ListValue* cookies_value; |
99 if (cookies_policy && cookies_policy->GetAsList(&cookies_value) && | 59 if (cookies_policy && cookies_policy->GetAsList(&cookies_value) && |
100 !cookies_value->empty()) { | 60 !cookies_value->empty()) { |
101 errors->AddError(key::kCookiesSessionOnlyForUrls, | 61 errors->AddError(key::kCookiesSessionOnlyForUrls, |
(...skipping 19 matching lines...) Expand all Loading... | |
121 default: | 81 default: |
122 errors->AddError(policy_name(), | 82 errors->AddError(policy_name(), |
123 IDS_POLICY_OUT_OF_RANGE_ERROR, | 83 IDS_POLICY_OUT_OF_RANGE_ERROR, |
124 base::IntToString(restore_value)); | 84 base::IntToString(restore_value)); |
125 } | 85 } |
126 } | 86 } |
127 return true; | 87 return true; |
128 } | 88 } |
129 | 89 |
130 } // namespace policy | 90 } // namespace policy |
OLD | NEW |