Chromium Code Reviews| Index: chrome/browser/policy/configuration_policy_handler.cc |
| diff --git a/chrome/browser/policy/configuration_policy_handler.cc b/chrome/browser/policy/configuration_policy_handler.cc |
| index 0bae4da6b38e7c2ec1ca63c3208773e560bd6c93..2fe3c90858c2c0482774b7866a40c0e348c4f750 100644 |
| --- a/chrome/browser/policy/configuration_policy_handler.cc |
| +++ b/chrome/browser/policy/configuration_policy_handler.cc |
| @@ -964,48 +964,108 @@ void JavascriptPolicyHandler::ApplyPolicySettings(const PolicyMap& policies, |
| // RestoreOnStartupPolicyHandler implementation -------------------------------- |
| RestoreOnStartupPolicyHandler::RestoreOnStartupPolicyHandler() |
| - : SimplePolicyHandler(key::kRestoreOnStartup, |
| - prefs::kRestoreOnStartup, |
| - Value::TYPE_INTEGER) { |
| + : TypeCheckingPolicyHandler(key::kRestoreOnStartup, |
| + Value::TYPE_INTEGER) { |
| } |
| RestoreOnStartupPolicyHandler::~RestoreOnStartupPolicyHandler() { |
| } |
| +void RestoreOnStartupPolicyHandler::ApplyPolicySettings( |
| + const PolicyMap& policies, |
| + PrefValueMap* prefs) { |
| + const Value* restore_on_startup_value = policies.GetValue(policy_name()); |
| + if (restore_on_startup_value) { |
| + int restore_on_startup; |
| + bool result = restore_on_startup_value->GetAsInteger(&restore_on_startup); |
| + 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
|
| + return; |
| + |
| + if (restore_on_startup == SessionStartupPref::kPrefValueHomePage) { |
| + ApplyPolicySettingsFromHomePage(policies, prefs); |
| + } else { |
| + prefs->SetInteger(prefs::kRestoreOnStartup, restore_on_startup); |
| + } |
| + } |
| +} |
| + |
| +void RestoreOnStartupPolicyHandler::ApplyPolicySettingsFromHomePage( |
| + const PolicyMap& policies, |
| + PrefValueMap* prefs) { |
| + |
| + const base::Value* homepage_is_new_tab_page_value = |
| + policies.GetValue(key::kHomepageIsNewTabPage); |
| + if (!homepage_is_new_tab_page_value) { |
| + // The policy is enforcing 'open the homepage on startup' but not |
| + // enforcing what the homepage should be. Don't set any prefs. |
| + return; |
| + } |
| + |
| + bool homepage_is_new_tab_page; |
| + bool result = homepage_is_new_tab_page_value->GetAsBoolean( |
| + &homepage_is_new_tab_page); |
| + 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.
|
| + return; |
| + |
| + if (homepage_is_new_tab_page) { |
| + prefs->SetInteger( |
| + prefs::kRestoreOnStartup, |
| + SessionStartupPref::kPrefValueNewTab); |
| + } else { |
| + const base::Value* homepage_value = |
| + policies.GetValue(key::kHomepageLocation); |
| + if (!homepage_value) { |
| + // The policy is enforcing 'open the homepage on startup' but not |
| + // enforcing what the homepage should be. Don't set any prefs. |
| + return; |
| + } |
| + ListValue* url_list = new ListValue(); |
| + url_list->Append(homepage_value->DeepCopy()); |
| + prefs->SetInteger( |
| + prefs::kRestoreOnStartup, |
| + SessionStartupPref::kPrefValueURLs); |
| + prefs->SetValue(prefs::kURLsToRestoreOnStartup, url_list); |
| + } |
| +} |
| + |
| bool RestoreOnStartupPolicyHandler::CheckPolicySettings( |
| const PolicyMap& policies, |
| PolicyErrorMap* errors) { |
| - if (!SimplePolicyHandler::CheckPolicySettings(policies, errors)) |
| + if (!TypeCheckingPolicyHandler::CheckPolicySettings(policies, errors)) |
| return false; |
| - // If the restore urls at start up policy is set, session cookies are treated |
| - // as permanent cookies and site data needed to restore the session is not |
| - // cleared so we have to warn the user in that case. |
| const base::Value* restore_policy = policies.GetValue(key::kRestoreOnStartup); |
| if (restore_policy) { |
| int restore_value; |
| - if (restore_policy->GetAsInteger(&restore_value) && |
| - SessionStartupPref::PrefValueToType(restore_value) == |
| - SessionStartupPref::LAST) { |
| - |
| - const base::Value* cookies_policy = |
| - policies.GetValue(key::kCookiesSessionOnlyForUrls); |
| - const base::ListValue *cookies_value; |
| - if (cookies_policy && cookies_policy->GetAsList(&cookies_value) && |
| - !cookies_value->empty()) { |
| - errors->AddError(key::kCookiesSessionOnlyForUrls, |
| - IDS_POLICY_OVERRIDDEN, |
| - key::kRestoreOnStartup); |
| - } |
| + bool result = restore_policy->GetAsInteger(&restore_value); |
| + 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.
|
| + if (restore_value == SessionStartupPref::kPrefValueHomePage) { |
| + errors->AddError(policy_name(), |
| + IDS_POLICY_VALUE_DEPRECATED); |
| + } else if (restore_value == SessionStartupPref::kPrefValueLast) { |
| + // If the "restore last session" policy is set, session cookies are |
| + // treated as permanent cookies and site data needed to restore the |
| + // session is not cleared so we have to warn the user in that case. |
| + const base::Value* cookies_policy = |
| + policies.GetValue(key::kCookiesSessionOnlyForUrls); |
| + const base::ListValue *cookies_value; |
| + if (cookies_policy && cookies_policy->GetAsList(&cookies_value) && |
| + !cookies_value->empty()) { |
| + errors->AddError(key::kCookiesSessionOnlyForUrls, |
| + IDS_POLICY_OVERRIDDEN, |
| + key::kRestoreOnStartup); |
| + } |
| - const base::Value* exit_policy = |
| - policies.GetValue(key::kClearSiteDataOnExit); |
| - bool exit_value; |
| - if (exit_policy && exit_policy->GetAsBoolean(&exit_value) && exit_value) { |
| - errors->AddError(key::kClearSiteDataOnExit, |
| - IDS_POLICY_OVERRIDDEN, |
| - key::kRestoreOnStartup); |
| + const base::Value* exit_policy = |
| + policies.GetValue(key::kClearSiteDataOnExit); |
| + bool exit_value; |
| + if (exit_policy && |
| + exit_policy->GetAsBoolean(&exit_value) && exit_value) { |
| + errors->AddError(key::kClearSiteDataOnExit, |
| + IDS_POLICY_OVERRIDDEN, |
| + key::kRestoreOnStartup); |
| + } |
| } |
|
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.
|
| } |
| } |