| 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/ui/webui/options/browser_options_handler.h" | 5 #include "chrome/browser/ui/webui/options/browser_options_handler.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 cloud_print_connector_ui_enabled_ = true; | 138 cloud_print_connector_ui_enabled_ = true; |
| 139 #endif | 139 #endif |
| 140 } | 140 } |
| 141 | 141 |
| 142 BrowserOptionsHandler::~BrowserOptionsHandler() { | 142 BrowserOptionsHandler::~BrowserOptionsHandler() { |
| 143 ProfileSyncService* sync_service(ProfileSyncServiceFactory:: | 143 ProfileSyncService* sync_service(ProfileSyncServiceFactory:: |
| 144 GetInstance()->GetForProfile(Profile::FromWebUI(web_ui()))); | 144 GetInstance()->GetForProfile(Profile::FromWebUI(web_ui()))); |
| 145 if (sync_service) | 145 if (sync_service) |
| 146 sync_service->RemoveObserver(this); | 146 sync_service->RemoveObserver(this); |
| 147 | 147 |
| 148 profile_pref_registrar_.RemoveAll(); |
| 148 if (default_browser_worker_.get()) | 149 if (default_browser_worker_.get()) |
| 149 default_browser_worker_->ObserverDestroyed(); | 150 default_browser_worker_->ObserverDestroyed(); |
| 150 if (template_url_service_) | 151 if (template_url_service_) |
| 151 template_url_service_->RemoveObserver(this); | 152 template_url_service_->RemoveObserver(this); |
| 152 // There may be pending file dialogs, we need to tell them that we've gone | 153 // There may be pending file dialogs, we need to tell them that we've gone |
| 153 // away so they don't try and call back to us. | 154 // away so they don't try and call back to us. |
| 154 if (select_folder_dialog_.get()) | 155 if (select_folder_dialog_.get()) |
| 155 select_folder_dialog_->ListenerDestroyed(); | 156 select_folder_dialog_->ListenerDestroyed(); |
| 156 } | 157 } |
| 157 | 158 |
| (...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 #endif | 576 #endif |
| 576 } | 577 } |
| 577 | 578 |
| 578 void BrowserOptionsHandler::OnStateChanged() { | 579 void BrowserOptionsHandler::OnStateChanged() { |
| 579 web_ui()->CallJavascriptFunction("BrowserOptions.updateSyncState", | 580 web_ui()->CallJavascriptFunction("BrowserOptions.updateSyncState", |
| 580 *GetSyncStateDictionary()); | 581 *GetSyncStateDictionary()); |
| 581 | 582 |
| 582 SendProfilesInfo(); | 583 SendProfilesInfo(); |
| 583 } | 584 } |
| 584 | 585 |
| 586 void BrowserOptionsHandler::OnSigninAllowedPrefChange() { |
| 587 web_ui()->CallJavascriptFunction("BrowserOptions.updateSyncState", |
| 588 *GetSyncStateDictionary()); |
| 589 |
| 590 SendProfilesInfo(); |
| 591 } |
| 592 |
| 585 void BrowserOptionsHandler::PageLoadStarted() { | 593 void BrowserOptionsHandler::PageLoadStarted() { |
| 586 page_initialized_ = false; | 594 page_initialized_ = false; |
| 587 } | 595 } |
| 588 | 596 |
| 589 void BrowserOptionsHandler::InitializeHandler() { | 597 void BrowserOptionsHandler::InitializeHandler() { |
| 590 Profile* profile = Profile::FromWebUI(web_ui()); | 598 Profile* profile = Profile::FromWebUI(web_ui()); |
| 591 PrefService* prefs = profile->GetPrefs(); | 599 PrefService* prefs = profile->GetPrefs(); |
| 592 | 600 |
| 593 ProfileSyncService* sync_service( | 601 ProfileSyncService* sync_service( |
| 594 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile)); | 602 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile)); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 645 base::Bind(&BrowserOptionsHandler::SetupAutoOpenFileTypes, | 653 base::Bind(&BrowserOptionsHandler::SetupAutoOpenFileTypes, |
| 646 base::Unretained(this))); | 654 base::Unretained(this))); |
| 647 default_font_size_.Init( | 655 default_font_size_.Init( |
| 648 prefs::kWebKitDefaultFontSize, prefs, | 656 prefs::kWebKitDefaultFontSize, prefs, |
| 649 base::Bind(&BrowserOptionsHandler::SetupFontSizeSelector, | 657 base::Bind(&BrowserOptionsHandler::SetupFontSizeSelector, |
| 650 base::Unretained(this))); | 658 base::Unretained(this))); |
| 651 default_zoom_level_.Init( | 659 default_zoom_level_.Init( |
| 652 prefs::kDefaultZoomLevel, prefs, | 660 prefs::kDefaultZoomLevel, prefs, |
| 653 base::Bind(&BrowserOptionsHandler::SetupPageZoomSelector, | 661 base::Bind(&BrowserOptionsHandler::SetupPageZoomSelector, |
| 654 base::Unretained(this))); | 662 base::Unretained(this))); |
| 663 profile_pref_registrar_.Init(prefs); |
| 664 profile_pref_registrar_.Add( |
| 665 prefs::kSigninAllowed, |
| 666 base::Bind(&BrowserOptionsHandler::OnSigninAllowedPrefChange, |
| 667 base::Unretained(this))); |
| 655 #if !defined(OS_CHROMEOS) | 668 #if !defined(OS_CHROMEOS) |
| 656 proxy_prefs_.Init(prefs); | 669 profile_pref_registrar_.Add( |
| 657 proxy_prefs_.Add(prefs::kProxy, | 670 prefs::kProxy, |
| 658 base::Bind(&BrowserOptionsHandler::SetupProxySettingsSection, | 671 base::Bind(&BrowserOptionsHandler::SetupProxySettingsSection, |
| 659 base::Unretained(this))); | 672 base::Unretained(this))); |
| 660 #endif // !defined(OS_CHROMEOS) | 673 #endif // !defined(OS_CHROMEOS) |
| 661 } | 674 } |
| 662 | 675 |
| 663 void BrowserOptionsHandler::InitializePage() { | 676 void BrowserOptionsHandler::InitializePage() { |
| 664 page_initialized_ = true; | 677 page_initialized_ = true; |
| 665 OnTemplateURLServiceChanged(); | 678 OnTemplateURLServiceChanged(); |
| 666 ObserveThemeChanged(); | 679 ObserveThemeChanged(); |
| 667 OnStateChanged(); | 680 OnStateChanged(); |
| 668 UpdateDefaultBrowserState(); | 681 UpdateDefaultBrowserState(); |
| 669 | 682 |
| (...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1068 base::StringValue email_value(email); | 1081 base::StringValue email_value(email); |
| 1069 web_ui()->CallJavascriptFunction("BrowserOptions.updateAccountPicture", | 1082 web_ui()->CallJavascriptFunction("BrowserOptions.updateAccountPicture", |
| 1070 email_value); | 1083 email_value); |
| 1071 } | 1084 } |
| 1072 } | 1085 } |
| 1073 #endif | 1086 #endif |
| 1074 | 1087 |
| 1075 scoped_ptr<DictionaryValue> BrowserOptionsHandler::GetSyncStateDictionary() { | 1088 scoped_ptr<DictionaryValue> BrowserOptionsHandler::GetSyncStateDictionary() { |
| 1076 scoped_ptr<DictionaryValue> sync_status(new DictionaryValue); | 1089 scoped_ptr<DictionaryValue> sync_status(new DictionaryValue); |
| 1077 Profile* profile = Profile::FromWebUI(web_ui()); | 1090 Profile* profile = Profile::FromWebUI(web_ui()); |
| 1078 sync_status->SetBoolean("signinAllowed", !profile->IsGuestSession()); | |
| 1079 if (profile->IsGuestSession()) { | 1091 if (profile->IsGuestSession()) { |
| 1080 // Cannot display signin status when running in guest mode on chromeos | 1092 // Cannot display signin status when running in guest mode on chromeos |
| 1081 // because there is no SigninManager. | 1093 // because there is no SigninManager. |
| 1094 sync_status->SetBoolean("signinAllowed", false); |
| 1082 return sync_status.Pass(); | 1095 return sync_status.Pass(); |
| 1083 } | 1096 } |
| 1084 | 1097 |
| 1085 // Signout is not allowed if the user has policy (crbug.com/172204). | 1098 // Signout is not allowed if the user has policy (crbug.com/172204). |
| 1086 bool signout_allowed = true; | 1099 bool signout_allowed = true; |
| 1087 #if defined(ENABLE_CONFIGURATION_POLICY) && !defined(OS_CHROMEOS) | 1100 #if defined(ENABLE_CONFIGURATION_POLICY) && !defined(OS_CHROMEOS) |
| 1088 policy::UserCloudPolicyManager* policy_manager = | 1101 policy::UserCloudPolicyManager* policy_manager = |
| 1089 policy::UserCloudPolicyManagerFactory::GetForProfile(profile); | 1102 policy::UserCloudPolicyManagerFactory::GetForProfile(profile); |
| 1090 if (policy_manager) | 1103 if (policy_manager) |
| 1091 signout_allowed = !policy_manager->IsClientRegistered(); | 1104 signout_allowed = !policy_manager->IsClientRegistered(); |
| 1092 #endif | 1105 #endif |
| 1093 sync_status->SetBoolean("signoutAllowed", signout_allowed); | 1106 sync_status->SetBoolean("signoutAllowed", signout_allowed); |
| 1094 ProfileSyncService* service( | 1107 ProfileSyncService* service( |
| 1095 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile)); | 1108 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile)); |
| 1109 SigninManager* signin(SigninManagerFactory::GetForProfile(profile)); |
| 1110 DCHECK(signin); |
| 1111 sync_status->SetBoolean("signinAllowed", signin->IsSigninAllowed()); |
| 1096 sync_status->SetBoolean("syncSystemEnabled", !!service); | 1112 sync_status->SetBoolean("syncSystemEnabled", !!service); |
| 1097 sync_status->SetBoolean("setupCompleted", | 1113 sync_status->SetBoolean("setupCompleted", |
| 1098 service && service->HasSyncSetupCompleted()); | 1114 service && service->HasSyncSetupCompleted()); |
| 1099 sync_status->SetBoolean("setupInProgress", | 1115 sync_status->SetBoolean("setupInProgress", |
| 1100 service && !service->IsManaged() && service->FirstSetupInProgress()); | 1116 service && !service->IsManaged() && service->FirstSetupInProgress()); |
| 1101 | 1117 |
| 1102 string16 status_label; | 1118 string16 status_label; |
| 1103 string16 link_label; | 1119 string16 link_label; |
| 1104 SigninManager* signin = SigninManagerFactory::GetForProfile(profile); | |
| 1105 DCHECK(signin); | |
| 1106 bool status_has_error = sync_ui_util::GetStatusLabels( | 1120 bool status_has_error = sync_ui_util::GetStatusLabels( |
| 1107 service, *signin, sync_ui_util::WITH_HTML, &status_label, &link_label) == | 1121 service, *signin, sync_ui_util::WITH_HTML, &status_label, &link_label) == |
| 1108 sync_ui_util::SYNC_ERROR; | 1122 sync_ui_util::SYNC_ERROR; |
| 1109 sync_status->SetString("statusText", status_label); | 1123 sync_status->SetString("statusText", status_label); |
| 1110 sync_status->SetString("actionLinkText", link_label); | 1124 sync_status->SetString("actionLinkText", link_label); |
| 1111 sync_status->SetBoolean("hasError", status_has_error); | 1125 sync_status->SetBoolean("hasError", status_has_error); |
| 1112 | 1126 |
| 1113 sync_status->SetBoolean("managed", service && service->IsManaged()); | 1127 sync_status->SetBoolean("managed", service && service->IsManaged()); |
| 1114 sync_status->SetBoolean("signedIn", | 1128 sync_status->SetBoolean("signedIn", |
| 1115 !signin->GetAuthenticatedUsername().empty()); | 1129 !signin->GetAuthenticatedUsername().empty()); |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1429 void BrowserOptionsHandler::SetupProxySettingsSection() { | 1443 void BrowserOptionsHandler::SetupProxySettingsSection() { |
| 1430 #if !defined(OS_CHROMEOS) | 1444 #if !defined(OS_CHROMEOS) |
| 1431 // Disable the button if proxy settings are managed by a sysadmin or | 1445 // Disable the button if proxy settings are managed by a sysadmin or |
| 1432 // overridden by an extension. | 1446 // overridden by an extension. |
| 1433 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); | 1447 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); |
| 1434 const PrefService::Preference* proxy_config = | 1448 const PrefService::Preference* proxy_config = |
| 1435 pref_service->FindPreference(prefs::kProxy); | 1449 pref_service->FindPreference(prefs::kProxy); |
| 1436 bool is_extension_controlled = (proxy_config && | 1450 bool is_extension_controlled = (proxy_config && |
| 1437 proxy_config->IsExtensionControlled()); | 1451 proxy_config->IsExtensionControlled()); |
| 1438 | 1452 |
| 1439 base::FundamentalValue disabled(proxy_prefs_.IsManaged() || | 1453 base::FundamentalValue disabled(profile_pref_registrar_.IsManaged() || |
| 1440 is_extension_controlled); | 1454 is_extension_controlled); |
| 1441 base::FundamentalValue extension_controlled(is_extension_controlled); | 1455 base::FundamentalValue extension_controlled(is_extension_controlled); |
| 1442 web_ui()->CallJavascriptFunction("BrowserOptions.setupProxySettingsSection", | 1456 web_ui()->CallJavascriptFunction("BrowserOptions.setupProxySettingsSection", |
| 1443 disabled, extension_controlled); | 1457 disabled, extension_controlled); |
| 1444 | 1458 |
| 1445 #endif // !defined(OS_CHROMEOS) | 1459 #endif // !defined(OS_CHROMEOS) |
| 1446 } | 1460 } |
| 1447 | 1461 |
| 1448 } // namespace options | 1462 } // namespace options |
| OLD | NEW |