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

Unified 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 side-by-side diff with in-line comments
Download patch
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..3e71c13c40b2ccbab0d29d2306f370fd79a777d1 100644
--- a/chrome/browser/policy/configuration_policy_handler.cc
+++ b/chrome/browser/policy/configuration_policy_handler.cc
@@ -964,48 +964,111 @@ 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;
+ if (!restore_on_startup_value->GetAsInteger(&restore_on_startup))
+ 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;
+ if (!homepage_is_new_tab_page_value->GetAsBoolean(&homepage_is_new_tab_page))
+ 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 || !homepage_value->IsType(base::Value::TYPE_STRING)) {
+ // 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);
- }
-
- 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);
+ if (restore_policy->GetAsInteger(&restore_value)) {
+ switch (restore_value) {
+ case SessionStartupPref::kPrefValueHomePage:
+ // TODO(tbreisacher): AddError indicating this value is deprecated.
+ break;
+ case 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);
+ }
+ break;
+ }
+ case SessionStartupPref::kPrefValueURLs:
+ case SessionStartupPref::kPrefValueNewTab:
+ // No error
+ break;
+ default:
+ errors->AddError(policy_name(),
+ IDS_POLICY_OUT_OF_RANGE_ERROR,
+ base::IntToString(restore_value));
}
}
}
« 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