Index: chrome/browser/ui/webui/options/advanced_options_handler.cc |
=================================================================== |
--- chrome/browser/ui/webui/options/advanced_options_handler.cc (revision 109526) |
+++ chrome/browser/ui/webui/options/advanced_options_handler.cc (working copy) |
@@ -4,6 +4,7 @@ |
#include "chrome/browser/ui/webui/options/advanced_options_handler.h" |
+#include <cmath> |
#include <string> |
#include "base/basictypes.h" |
@@ -33,9 +34,11 @@ |
#include "content/browser/user_metrics.h" |
#include "content/public/browser/notification_details.h" |
#include "content/public/browser/notification_types.h" |
+#include "content/public/common/page_zoom.h" |
#include "grit/chromium_strings.h" |
#include "grit/generated_resources.h" |
#include "grit/locale_settings.h" |
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
#include "ui/base/l10n/l10n_util.h" |
#if !defined(OS_CHROMEOS) |
@@ -114,7 +117,7 @@ |
IDS_OPTIONS_TABS_TO_LINKS_PREF }, |
{ "fontSettingsInfo", |
IDS_OPTIONS_FONTSETTINGS_INFO }, |
- { "defaultZoomLevelLabel", |
+ { "defaultZoomFactorLabel", |
IDS_OPTIONS_DEFAULT_ZOOM_LEVEL_LABEL }, |
{ "defaultFontSizeLabel", |
IDS_OPTIONS_DEFAULT_FONT_SIZE_LABEL }, |
@@ -198,10 +201,11 @@ |
} |
void AdvancedOptionsHandler::Initialize() { |
- DCHECK(web_ui_); |
+ DCHECK(web_ui()); |
SetupMetricsReportingCheckbox(); |
SetupMetricsReportingSettingVisibility(); |
- SetupFontSizeLabel(); |
+ SetupFontSizeSelector(); |
+ SetupPageZoomSelector(); |
SetupAutoOpenFileTypesDisabledAttribute(); |
SetupProxySettingsSection(); |
SetupSSLConfigSettings(); |
@@ -225,8 +229,7 @@ |
// Register for preferences that we need to observe manually. These have |
// special behaviors that aren't handled by the standard prefs UI. |
- DCHECK(web_ui_); |
- PrefService* prefs = Profile::FromWebUI(web_ui_)->GetPrefs(); |
+ PrefService* prefs = Profile::FromWebUI(web_ui)->GetPrefs(); |
#if !defined(OS_CHROMEOS) |
enable_metrics_recording_.Init(prefs::kMetricsReportingEnabled, |
g_browser_process->local_state(), this); |
@@ -245,6 +248,7 @@ |
auto_open_files_.Init(prefs::kDownloadExtensionsToOpen, prefs, this); |
default_font_size_.Init(prefs::kWebKitDefaultFontSize, prefs, this); |
+ default_zoom_level_.Init(prefs::kDefaultZoomLevel, prefs, this); |
#if !defined(OS_CHROMEOS) |
proxy_prefs_.reset( |
PrefSetObserver::CreateProxyPrefSetObserver(prefs, this)); |
@@ -256,47 +260,50 @@ |
void AdvancedOptionsHandler::RegisterMessages() { |
// Setup handlers specific to this panel. |
- DCHECK(web_ui_); |
- web_ui_->RegisterMessageCallback("selectDownloadLocation", |
+ DCHECK(web_ui()); |
+ web_ui()->RegisterMessageCallback("selectDownloadLocation", |
James Hawkins
2011/11/14 18:09:05
Ehhh I'm not really a fan of continuously calling
csilv
2011/11/15 02:26:49
I reverted this change here and below.
On 2011/11
|
base::Bind(&AdvancedOptionsHandler::HandleSelectDownloadLocation, |
base::Unretained(this))); |
- web_ui_->RegisterMessageCallback("autoOpenFileTypesAction", |
+ web_ui()->RegisterMessageCallback("autoOpenFileTypesAction", |
base::Bind(&AdvancedOptionsHandler::HandleAutoOpenButton, |
base::Unretained(this))); |
- web_ui_->RegisterMessageCallback("defaultFontSizeAction", |
+ web_ui()->RegisterMessageCallback("defaultFontSizeAction", |
base::Bind(&AdvancedOptionsHandler::HandleDefaultFontSize, |
base::Unretained(this))); |
+ web_ui()->RegisterMessageCallback("defaultZoomFactorAction", |
+ base::Bind(&AdvancedOptionsHandler::HandleDefaultZoomFactor, |
+ base::Unretained(this))); |
#if !defined(OS_CHROMEOS) |
- web_ui_->RegisterMessageCallback("metricsReportingCheckboxAction", |
+ web_ui()->RegisterMessageCallback("metricsReportingCheckboxAction", |
base::Bind(&AdvancedOptionsHandler::HandleMetricsReportingCheckbox, |
base::Unretained(this))); |
#endif |
#if !defined(USE_NSS) && !defined(USE_OPENSSL) |
- web_ui_->RegisterMessageCallback("showManageSSLCertificates", |
+ web_ui()->RegisterMessageCallback("showManageSSLCertificates", |
base::Bind(&AdvancedOptionsHandler::ShowManageSSLCertificates, |
base::Unretained(this))); |
#endif |
- web_ui_->RegisterMessageCallback("showCloudPrintManagePage", |
+ web_ui()->RegisterMessageCallback("showCloudPrintManagePage", |
base::Bind(&AdvancedOptionsHandler::ShowCloudPrintManagePage, |
base::Unretained(this))); |
#if !defined(OS_CHROMEOS) |
if (cloud_print_proxy_ui_enabled_) { |
- web_ui_->RegisterMessageCallback("showCloudPrintSetupDialog", |
+ web_ui()->RegisterMessageCallback("showCloudPrintSetupDialog", |
base::Bind(&AdvancedOptionsHandler::ShowCloudPrintSetupDialog, |
base::Unretained(this))); |
- web_ui_->RegisterMessageCallback("disableCloudPrintProxy", |
+ web_ui()->RegisterMessageCallback("disableCloudPrintProxy", |
base::Bind(&AdvancedOptionsHandler::HandleDisableCloudPrintProxy, |
base::Unretained(this))); |
} |
- web_ui_->RegisterMessageCallback("showNetworkProxySettings", |
+ web_ui()->RegisterMessageCallback("showNetworkProxySettings", |
base::Bind(&AdvancedOptionsHandler::ShowNetworkProxySettings, |
base::Unretained(this))); |
#endif |
- web_ui_->RegisterMessageCallback("checkRevocationCheckboxAction", |
+ web_ui()->RegisterMessageCallback("checkRevocationCheckboxAction", |
base::Bind(&AdvancedOptionsHandler::HandleCheckRevocationCheckbox, |
base::Unretained(this))); |
#if !defined(OS_MACOSX) && !defined(OS_CHROMEOS) |
- web_ui_->RegisterMessageCallback("backgroundModeAction", |
+ web_ui()->RegisterMessageCallback("backgroundModeAction", |
base::Bind(&AdvancedOptionsHandler::HandleBackgroundModeCheckbox, |
base::Unretained(this))); |
#endif |
@@ -321,7 +328,9 @@ |
SetupCloudPrintProxySection(); |
#endif |
} else if (*pref_name == prefs::kWebKitDefaultFontSize) { |
- SetupFontSizeLabel(); |
+ SetupFontSizeSelector(); |
+ } else if (*pref_name == prefs::kDefaultZoomLevel) { |
+ SetupPageZoomSelector(); |
#if !defined(OS_MACOSX) && !defined(OS_CHROMEOS) |
} else if (*pref_name == prefs::kBackgroundModeEnabled) { |
SetupBackgroundModeSettings(); |
@@ -332,20 +341,20 @@ |
void AdvancedOptionsHandler::HandleSelectDownloadLocation( |
const ListValue* args) { |
- PrefService* pref_service = Profile::FromWebUI(web_ui_)->GetPrefs(); |
+ PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); |
select_folder_dialog_ = SelectFileDialog::Create(this); |
select_folder_dialog_->SelectFile( |
SelectFileDialog::SELECT_FOLDER, |
l10n_util::GetStringUTF16(IDS_OPTIONS_DOWNLOADLOCATION_BROWSE_TITLE), |
pref_service->GetFilePath(prefs::kDownloadDefaultDirectory), |
- NULL, 0, FILE_PATH_LITERAL(""), web_ui_->tab_contents(), |
- web_ui_->tab_contents()->view()->GetTopLevelNativeWindow(), NULL); |
+ NULL, 0, FILE_PATH_LITERAL(""), web_ui()->tab_contents(), |
+ web_ui()->tab_contents()->view()->GetTopLevelNativeWindow(), NULL); |
} |
void AdvancedOptionsHandler::FileSelected(const FilePath& path, int index, |
void* params) { |
UserMetrics::RecordAction(UserMetricsAction("Options_SetDownloadDirectory")); |
- PrefService* pref_service = Profile::FromWebUI(web_ui_)->GetPrefs(); |
+ PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); |
pref_service->SetFilePath(prefs::kDownloadDefaultDirectory, path); |
} |
@@ -359,7 +368,7 @@ |
void AdvancedOptionsHandler::HandleAutoOpenButton(const ListValue* args) { |
UserMetrics::RecordAction(UserMetricsAction("Options_ResetAutoOpenFiles")); |
DownloadManager* manager = |
- web_ui_->tab_contents()->browser_context()->GetDownloadManager(); |
+ web_ui()->tab_contents()->browser_context()->GetDownloadManager(); |
if (manager) |
DownloadPrefs::FromDownloadManager(manager)->ResetAutoOpen(); |
} |
@@ -384,11 +393,19 @@ |
if (ExtractIntegerValue(args, &font_size)) { |
if (font_size > 0) { |
default_font_size_.SetValue(font_size); |
- SetupFontSizeLabel(); |
+ SetupFontSizeSelector(); |
} |
} |
} |
+void AdvancedOptionsHandler::HandleDefaultZoomFactor(const ListValue* args) { |
+ double zoom_factor; |
+ if (ExtractDoubleValue(args, &zoom_factor)) { |
+ default_zoom_level_.SetValue( |
+ WebKit::WebView::zoomFactorToZoomLevel(zoom_factor)); |
+ } |
+} |
+ |
void AdvancedOptionsHandler::HandleCheckRevocationCheckbox( |
const ListValue* args) { |
std::string checked_str = UTF16ToUTF8(ExtractStringValue(args)); |
@@ -413,7 +430,7 @@ |
void AdvancedOptionsHandler::SetupBackgroundModeSettings() { |
base::FundamentalValue checked(background_mode_enabled_.GetValue()); |
- web_ui_->CallJavascriptFunction( |
+ web_ui()->CallJavascriptFunction( |
"options.AdvancedOptions.SetBackgroundModeCheckboxState", checked); |
} |
#endif |
@@ -421,22 +438,22 @@ |
#if !defined(OS_CHROMEOS) |
void AdvancedOptionsHandler::ShowNetworkProxySettings(const ListValue* args) { |
UserMetrics::RecordAction(UserMetricsAction("Options_ShowProxySettings")); |
- AdvancedOptionsUtilities::ShowNetworkProxySettings(web_ui_->tab_contents()); |
+ AdvancedOptionsUtilities::ShowNetworkProxySettings(web_ui()->tab_contents()); |
} |
#endif |
#if !defined(USE_NSS) && !defined(USE_OPENSSL) |
void AdvancedOptionsHandler::ShowManageSSLCertificates(const ListValue* args) { |
UserMetrics::RecordAction(UserMetricsAction("Options_ManageSSLCertificates")); |
- AdvancedOptionsUtilities::ShowManageSSLCertificates(web_ui_->tab_contents()); |
+ AdvancedOptionsUtilities::ShowManageSSLCertificates(web_ui()->tab_contents()); |
} |
#endif |
void AdvancedOptionsHandler::ShowCloudPrintManagePage(const ListValue* args) { |
UserMetrics::RecordAction(UserMetricsAction("Options_ManageCloudPrinters")); |
// Open a new tab in the current window for the management page. |
- Profile* profile = Profile::FromWebUI(web_ui_); |
- web_ui_->tab_contents()->OpenURL( |
+ Profile* profile = Profile::FromWebUI(web_ui()); |
+ web_ui()->tab_contents()->OpenURL( |
CloudPrintURL(profile).GetCloudPrintServiceManageURL(), |
GURL(), NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_LINK); |
} |
@@ -445,8 +462,8 @@ |
void AdvancedOptionsHandler::ShowCloudPrintSetupDialog(const ListValue* args) { |
UserMetrics::RecordAction(UserMetricsAction("Options_EnableCloudPrintProxy")); |
// Open the connector enable page in the current tab. |
- Profile* profile = Profile::FromWebUI(web_ui_); |
- web_ui_->tab_contents()->OpenURL( |
+ Profile* profile = Profile::FromWebUI(web_ui()); |
+ web_ui()->tab_contents()->OpenURL( |
CloudPrintURL(profile).GetCloudPrintServiceEnableURL( |
CloudPrintProxyServiceFactory::GetForProfile(profile)->proxy_id()), |
GURL(), CURRENT_TAB, content::PAGE_TRANSITION_LINK); |
@@ -456,19 +473,19 @@ |
const ListValue* args) { |
UserMetrics::RecordAction( |
UserMetricsAction("Options_DisableCloudPrintProxy")); |
- CloudPrintProxyServiceFactory::GetForProfile(Profile::FromWebUI(web_ui_))-> |
+ CloudPrintProxyServiceFactory::GetForProfile(Profile::FromWebUI(web_ui()))-> |
DisableForUser(); |
} |
void AdvancedOptionsHandler::RefreshCloudPrintStatusFromService() { |
- DCHECK(web_ui_); |
+ DCHECK(web_ui()); |
if (cloud_print_proxy_ui_enabled_) |
- CloudPrintProxyServiceFactory::GetForProfile(Profile::FromWebUI(web_ui_))-> |
+ CloudPrintProxyServiceFactory::GetForProfile(Profile::FromWebUI(web_ui()))-> |
RefreshStatusFromService(); |
} |
void AdvancedOptionsHandler::SetupCloudPrintProxySection() { |
- Profile* profile = Profile::FromWebUI(web_ui_); |
+ Profile* profile = Profile::FromWebUI(web_ui()); |
if (!CloudPrintProxyServiceFactory::GetForProfile(profile)) { |
cloud_print_proxy_ui_enabled_ = false; |
RemoveCloudPrintProxySection(); |
@@ -497,13 +514,13 @@ |
} |
StringValue label(label_str); |
- web_ui_->CallJavascriptFunction( |
+ web_ui()->CallJavascriptFunction( |
"options.AdvancedOptions.SetupCloudPrintProxySection", |
disabled, label, allowed); |
} |
void AdvancedOptionsHandler::RemoveCloudPrintProxySection() { |
- web_ui_->CallJavascriptFunction( |
+ web_ui()->CallJavascriptFunction( |
"options.AdvancedOptions.RemoveCloudPrintProxySection"); |
} |
@@ -513,7 +530,7 @@ |
#if defined(GOOGLE_CHROME_BUILD) && !defined(OS_CHROMEOS) |
base::FundamentalValue checked(enable_metrics_recording_.GetValue()); |
base::FundamentalValue disabled(enable_metrics_recording_.IsManaged()); |
- web_ui_->CallJavascriptFunction( |
+ web_ui()->CallJavascriptFunction( |
"options.AdvancedOptions.SetMetricsReportingCheckboxState", checked, |
disabled); |
#endif |
@@ -524,29 +541,78 @@ |
// Don't show the reporting setting if we are in the guest mode. |
if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kGuestSession)) { |
base::FundamentalValue visible(false); |
- web_ui_->CallJavascriptFunction( |
+ web_ui()->CallJavascriptFunction( |
"options.AdvancedOptions.SetMetricsReportingSettingVisibility", |
visible); |
} |
#endif |
} |
-void AdvancedOptionsHandler::SetupFontSizeLabel() { |
+void AdvancedOptionsHandler::SetupFontSizeSelector() { |
// We're only interested in integer values, so convert to int. |
base::FundamentalValue font_size(default_font_size_.GetValue()); |
- web_ui_->CallJavascriptFunction( |
+ web_ui()->CallJavascriptFunction( |
"options.AdvancedOptions.SetFontSize", font_size); |
} |
+void AdvancedOptionsHandler::SetupPageZoomSelector() { |
+ PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); |
+ double default_zoom_level = pref_service->GetDouble(prefs::kDefaultZoomLevel); |
+ double default_zoom_factor = |
+ WebKit::WebView::zoomLevelToZoomFactor(default_zoom_level); |
+ |
+ // Generate a vector of zoom factors from an array of known preset values. |
James Hawkins
2011/11/14 18:09:05
:-/ This is very similar if not exactly like the c
csilv
2011/11/15 02:26:49
Done.
|
+ // The values in content::kPresetZoomFactors will already be in sorted order. |
+ std::vector<double> zoom_factors; |
+ bool found_default = false; |
+ for (int i = 0; i < content::kPresetZoomFactorsCount; i++) { |
+ double zoom_factor = content::kPresetZoomFactors[i]; |
+ if (std::fabs(zoom_factor - default_zoom_factor) <= |
+ content::kPageZoomEpsilon) |
+ found_default = true; |
+ zoom_factors.push_back(zoom_factor); |
+ } |
+ // If the preset array did not contain the user's default zoom value, |
+ // append it to the vector and then sort. |
+ if (!found_default) { |
+ zoom_factors.push_back(default_zoom_factor); |
+ std::sort(zoom_factors.begin(), zoom_factors.end()); |
+ } |
+ |
+ // Iterate through the zoom factors and and build the contents of the |
+ // selector that will be sent to the javascript handler. |
+ // Each item in the list has the following parameters: |
+ // 1. Title (string). |
+ // 2. Value (double). |
+ // 3. Is selected? (bool). |
+ ListValue zoom_factors_value; |
+ for (std::vector<double>::const_iterator i = zoom_factors.begin(); |
+ i != zoom_factors.end(); ++i) { |
+ ListValue* option = new ListValue(); |
+ double factor = *i; |
+ int percent = static_cast<int>(factor * 100 + 0.5); |
+ option->Append(Value::CreateStringValue( |
+ l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, percent))); |
+ option->Append(Value::CreateDoubleValue(factor)); |
+ bool selected = |
+ (std::fabs(factor - default_zoom_factor) < content::kPageZoomEpsilon); |
+ option->Append(Value::CreateBooleanValue(selected)); |
+ zoom_factors_value.Append(option); |
+ } |
+ |
+ web_ui()->CallJavascriptFunction( |
+ "options.AdvancedOptions.SetupPageZoomSelector", zoom_factors_value); |
+} |
+ |
void AdvancedOptionsHandler::SetupAutoOpenFileTypesDisabledAttribute() { |
// Set the enabled state for the AutoOpenFileTypesResetToDefault button. |
// We enable the button if the user has any auto-open file types registered. |
DownloadManager* manager = |
- web_ui_->tab_contents()->browser_context()->GetDownloadManager(); |
+ web_ui()->tab_contents()->browser_context()->GetDownloadManager(); |
bool disabled = !(manager && |
DownloadPrefs::FromDownloadManager(manager)->IsAutoOpenUsed()); |
base::FundamentalValue value(disabled); |
- web_ui_->CallJavascriptFunction( |
+ web_ui()->CallJavascriptFunction( |
"options.AdvancedOptions.SetAutoOpenFileTypesDisabledAttribute", value); |
} |
@@ -554,7 +620,7 @@ |
#if !defined(OS_CHROMEOS) |
// Disable the button if proxy settings are managed by a sysadmin or |
// overridden by an extension. |
- PrefService* pref_service = Profile::FromWebUI(web_ui_)->GetPrefs(); |
+ PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); |
const PrefService::Preference* proxy_config = |
pref_service->FindPreference(prefs::kProxy); |
bool is_extension_controlled = (proxy_config && |
@@ -573,7 +639,7 @@ |
} |
StringValue label(label_str); |
- web_ui_->CallJavascriptFunction( |
+ web_ui()->CallJavascriptFunction( |
"options.AdvancedOptions.SetupProxySettingsSection", disabled, label); |
#endif // !defined(OS_CHROMEOS) |
} |
@@ -582,7 +648,7 @@ |
{ |
base::FundamentalValue checked(rev_checking_enabled_.GetValue()); |
base::FundamentalValue disabled(rev_checking_enabled_.IsManaged()); |
- web_ui_->CallJavascriptFunction( |
+ web_ui()->CallJavascriptFunction( |
"options.AdvancedOptions.SetCheckRevocationCheckboxState", checked, |
disabled); |
} |