| 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/bind.h" | 10 #include "base/bind.h" |
| (...skipping 780 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 791 OnStateChanged(); | 791 OnStateChanged(); |
| 792 } | 792 } |
| 793 | 793 |
| 794 void BrowserOptionsHandler::PageLoadStarted() { | 794 void BrowserOptionsHandler::PageLoadStarted() { |
| 795 page_initialized_ = false; | 795 page_initialized_ = false; |
| 796 } | 796 } |
| 797 | 797 |
| 798 void BrowserOptionsHandler::InitializeHandler() { | 798 void BrowserOptionsHandler::InitializeHandler() { |
| 799 Profile* profile = Profile::FromWebUI(web_ui()); | 799 Profile* profile = Profile::FromWebUI(web_ui()); |
| 800 PrefService* prefs = profile->GetPrefs(); | 800 PrefService* prefs = profile->GetPrefs(); |
| 801 chrome::ChromeZoomLevelPrefs* zoom_level_prefs = profile->GetZoomLevelPrefs(); |
| 802 // Only regular profiles are able to edit default zoom level, or delete per- |
| 803 // host zoom levels, via the settings menu. We only require a zoom_level_prefs |
| 804 // if the profile is able to change these preference types. |
| 805 DCHECK(zoom_level_prefs || |
| 806 profile->GetProfileType() != Profile::REGULAR_PROFILE); |
| 807 if (zoom_level_prefs) { |
| 808 default_zoom_level_subscription_ = |
| 809 zoom_level_prefs->RegisterDefaultZoomLevelCallback( |
| 810 base::Bind(&BrowserOptionsHandler::SetupPageZoomSelector, |
| 811 base::Unretained(this))); |
| 812 } |
| 801 | 813 |
| 802 ProfileSyncService* sync_service( | 814 ProfileSyncService* sync_service( |
| 803 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile)); | 815 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile)); |
| 804 // TODO(blundell): Use a ScopedObserver to observe the PSS so that cleanup on | 816 // TODO(blundell): Use a ScopedObserver to observe the PSS so that cleanup on |
| 805 // destruction is automatic. | 817 // destruction is automatic. |
| 806 if (sync_service) | 818 if (sync_service) |
| 807 sync_service->AddObserver(this); | 819 sync_service->AddObserver(this); |
| 808 | 820 |
| 809 SigninManagerBase* signin_manager( | 821 SigninManagerBase* signin_manager( |
| 810 SigninManagerFactory::GetInstance()->GetForProfile(profile)); | 822 SigninManagerFactory::GetInstance()->GetForProfile(profile)); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 847 #endif | 859 #endif |
| 848 | 860 |
| 849 // No preferences below this point may be modified by guest profiles. | 861 // No preferences below this point may be modified by guest profiles. |
| 850 if (Profile::FromWebUI(web_ui())->IsGuestSession()) | 862 if (Profile::FromWebUI(web_ui())->IsGuestSession()) |
| 851 return; | 863 return; |
| 852 | 864 |
| 853 auto_open_files_.Init( | 865 auto_open_files_.Init( |
| 854 prefs::kDownloadExtensionsToOpen, prefs, | 866 prefs::kDownloadExtensionsToOpen, prefs, |
| 855 base::Bind(&BrowserOptionsHandler::SetupAutoOpenFileTypes, | 867 base::Bind(&BrowserOptionsHandler::SetupAutoOpenFileTypes, |
| 856 base::Unretained(this))); | 868 base::Unretained(this))); |
| 857 default_zoom_level_.Init( | |
| 858 prefs::kDefaultZoomLevel, prefs, | |
| 859 base::Bind(&BrowserOptionsHandler::SetupPageZoomSelector, | |
| 860 base::Unretained(this))); | |
| 861 profile_pref_registrar_.Init(prefs); | 869 profile_pref_registrar_.Init(prefs); |
| 862 profile_pref_registrar_.Add( | 870 profile_pref_registrar_.Add( |
| 863 prefs::kNetworkPredictionOptions, | 871 prefs::kNetworkPredictionOptions, |
| 864 base::Bind(&BrowserOptionsHandler::SetupNetworkPredictionControl, | 872 base::Bind(&BrowserOptionsHandler::SetupNetworkPredictionControl, |
| 865 base::Unretained(this))); | 873 base::Unretained(this))); |
| 866 profile_pref_registrar_.Add( | 874 profile_pref_registrar_.Add( |
| 867 prefs::kWebKitDefaultFontSize, | 875 prefs::kWebKitDefaultFontSize, |
| 868 base::Bind(&BrowserOptionsHandler::SetupFontSizeSelector, | 876 base::Bind(&BrowserOptionsHandler::SetupFontSizeSelector, |
| 869 base::Unretained(this))); | 877 base::Unretained(this))); |
| 870 profile_pref_registrar_.Add( | 878 profile_pref_registrar_.Add( |
| (...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1518 pref_service->SetInteger(prefs::kWebKitDefaultFontSize, font_size); | 1526 pref_service->SetInteger(prefs::kWebKitDefaultFontSize, font_size); |
| 1519 SetupFontSizeSelector(); | 1527 SetupFontSizeSelector(); |
| 1520 } | 1528 } |
| 1521 } | 1529 } |
| 1522 } | 1530 } |
| 1523 | 1531 |
| 1524 void BrowserOptionsHandler::HandleDefaultZoomFactor( | 1532 void BrowserOptionsHandler::HandleDefaultZoomFactor( |
| 1525 const base::ListValue* args) { | 1533 const base::ListValue* args) { |
| 1526 double zoom_factor; | 1534 double zoom_factor; |
| 1527 if (ExtractDoubleValue(args, &zoom_factor)) { | 1535 if (ExtractDoubleValue(args, &zoom_factor)) { |
| 1528 default_zoom_level_.SetValue(content::ZoomFactorToZoomLevel(zoom_factor)); | 1536 Profile::FromWebUI(web_ui())->GetZoomLevelPrefs()->SetDefaultZoomLevelPref( |
| 1537 content::ZoomFactorToZoomLevel(zoom_factor)); |
| 1529 } | 1538 } |
| 1530 } | 1539 } |
| 1531 | 1540 |
| 1532 void BrowserOptionsHandler::HandleRestartBrowser(const base::ListValue* args) { | 1541 void BrowserOptionsHandler::HandleRestartBrowser(const base::ListValue* args) { |
| 1533 #if defined(OS_WIN) && defined(USE_ASH) | 1542 #if defined(OS_WIN) && defined(USE_ASH) |
| 1534 // If hardware acceleration is disabled then we need to force restart | 1543 // If hardware acceleration is disabled then we need to force restart |
| 1535 // browser in desktop mode. | 1544 // browser in desktop mode. |
| 1536 // TODO(shrikant): Remove this once we fix start mode logic for browser. | 1545 // TODO(shrikant): Remove this once we fix start mode logic for browser. |
| 1537 // Currently there are issues with determining correct browser mode | 1546 // Currently there are issues with determining correct browser mode |
| 1538 // at startup. | 1547 // at startup. |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1775 dict.SetString("controlledBy", "policy"); | 1784 dict.SetString("controlledBy", "policy"); |
| 1776 } else if (default_font_size->IsExtensionControlled() || | 1785 } else if (default_font_size->IsExtensionControlled() || |
| 1777 default_fixed_font_size->IsExtensionControlled()) { | 1786 default_fixed_font_size->IsExtensionControlled()) { |
| 1778 dict.SetString("controlledBy", "extension"); | 1787 dict.SetString("controlledBy", "extension"); |
| 1779 } | 1788 } |
| 1780 | 1789 |
| 1781 web_ui()->CallJavascriptFunction("BrowserOptions.setFontSize", dict); | 1790 web_ui()->CallJavascriptFunction("BrowserOptions.setFontSize", dict); |
| 1782 } | 1791 } |
| 1783 | 1792 |
| 1784 void BrowserOptionsHandler::SetupPageZoomSelector() { | 1793 void BrowserOptionsHandler::SetupPageZoomSelector() { |
| 1785 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); | 1794 double default_zoom_level = |
| 1786 double default_zoom_level = pref_service->GetDouble(prefs::kDefaultZoomLevel); | 1795 content::HostZoomMap::GetDefaultForBrowserContext( |
| 1796 Profile::FromWebUI(web_ui()))->GetDefaultZoomLevel(); |
| 1787 double default_zoom_factor = | 1797 double default_zoom_factor = |
| 1788 content::ZoomLevelToZoomFactor(default_zoom_level); | 1798 content::ZoomLevelToZoomFactor(default_zoom_level); |
| 1789 | 1799 |
| 1790 // Generate a vector of zoom factors from an array of known presets along with | 1800 // Generate a vector of zoom factors from an array of known presets along with |
| 1791 // the default factor added if necessary. | 1801 // the default factor added if necessary. |
| 1792 std::vector<double> zoom_factors = | 1802 std::vector<double> zoom_factors = |
| 1793 chrome_page_zoom::PresetZoomFactors(default_zoom_factor); | 1803 chrome_page_zoom::PresetZoomFactors(default_zoom_factor); |
| 1794 | 1804 |
| 1795 // Iterate through the zoom factors and and build the contents of the | 1805 // Iterate through the zoom factors and and build the contents of the |
| 1796 // selector that will be sent to the javascript handler. | 1806 // selector that will be sent to the javascript handler. |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1966 | 1976 |
| 1967 void BrowserOptionsHandler::SetMetricsReportingCheckbox(bool checked, | 1977 void BrowserOptionsHandler::SetMetricsReportingCheckbox(bool checked, |
| 1968 bool disabled) { | 1978 bool disabled) { |
| 1969 web_ui()->CallJavascriptFunction( | 1979 web_ui()->CallJavascriptFunction( |
| 1970 "BrowserOptions.setMetricsReportingCheckboxState", | 1980 "BrowserOptions.setMetricsReportingCheckboxState", |
| 1971 base::FundamentalValue(checked), | 1981 base::FundamentalValue(checked), |
| 1972 base::FundamentalValue(disabled)); | 1982 base::FundamentalValue(disabled)); |
| 1973 } | 1983 } |
| 1974 | 1984 |
| 1975 } // namespace options | 1985 } // namespace options |
| OLD | NEW |