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

Side by Side Diff: chrome/browser/ui/webui/options/advanced_options_handler.cc

Issue 8528011: Page zoom improvements (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Minor cleanups Created 9 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/advanced_options_handler.h" 5 #include "chrome/browser/ui/webui/options/advanced_options_handler.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 15 matching lines...) Expand all
26 #include "chrome/common/chrome_notification_types.h" 26 #include "chrome/common/chrome_notification_types.h"
27 #include "chrome/common/chrome_switches.h" 27 #include "chrome/common/chrome_switches.h"
28 #include "chrome/common/pref_names.h" 28 #include "chrome/common/pref_names.h"
29 #include "chrome/common/url_constants.h" 29 #include "chrome/common/url_constants.h"
30 #include "content/browser/download/download_manager.h" 30 #include "content/browser/download/download_manager.h"
31 #include "content/browser/tab_contents/tab_contents.h" 31 #include "content/browser/tab_contents/tab_contents.h"
32 #include "content/browser/tab_contents/tab_contents_view.h" 32 #include "content/browser/tab_contents/tab_contents_view.h"
33 #include "content/browser/user_metrics.h" 33 #include "content/browser/user_metrics.h"
34 #include "content/public/browser/notification_details.h" 34 #include "content/public/browser/notification_details.h"
35 #include "content/public/browser/notification_types.h" 35 #include "content/public/browser/notification_types.h"
36 #include "content/public/common/page_zoom.h"
36 #include "grit/chromium_strings.h" 37 #include "grit/chromium_strings.h"
37 #include "grit/generated_resources.h" 38 #include "grit/generated_resources.h"
38 #include "grit/locale_settings.h" 39 #include "grit/locale_settings.h"
40 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
39 #include "ui/base/l10n/l10n_util.h" 41 #include "ui/base/l10n/l10n_util.h"
40 42
41 #if !defined(OS_CHROMEOS) 43 #if !defined(OS_CHROMEOS)
42 #include "chrome/browser/printing/cloud_print/cloud_print_setup_handler.h" 44 #include "chrome/browser/printing/cloud_print/cloud_print_setup_handler.h"
43 #include "chrome/browser/ui/webui/options/advanced_options_utils.h" 45 #include "chrome/browser/ui/webui/options/advanced_options_utils.h"
44 #endif 46 #endif
45 47
46 AdvancedOptionsHandler::AdvancedOptionsHandler() { 48 AdvancedOptionsHandler::AdvancedOptionsHandler() {
47 49
48 #if(!defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN)) 50 #if(!defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN))
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 { "privacyClearDataButton", 109 { "privacyClearDataButton",
108 IDS_OPTIONS_PRIVACY_CLEAR_DATA_BUTTON }, 110 IDS_OPTIONS_PRIVACY_CLEAR_DATA_BUTTON },
109 { "linkDoctorPref", 111 { "linkDoctorPref",
110 IDS_OPTIONS_LINKDOCTOR_PREF }, 112 IDS_OPTIONS_LINKDOCTOR_PREF },
111 { "suggestPref", 113 { "suggestPref",
112 IDS_OPTIONS_SUGGEST_PREF }, 114 IDS_OPTIONS_SUGGEST_PREF },
113 { "tabsToLinksPref", 115 { "tabsToLinksPref",
114 IDS_OPTIONS_TABS_TO_LINKS_PREF }, 116 IDS_OPTIONS_TABS_TO_LINKS_PREF },
115 { "fontSettingsInfo", 117 { "fontSettingsInfo",
116 IDS_OPTIONS_FONTSETTINGS_INFO }, 118 IDS_OPTIONS_FONTSETTINGS_INFO },
117 { "defaultZoomLevelLabel", 119 { "defaultZoomFactorLabel",
118 IDS_OPTIONS_DEFAULT_ZOOM_LEVEL_LABEL }, 120 IDS_OPTIONS_DEFAULT_ZOOM_LEVEL_LABEL },
119 { "defaultFontSizeLabel", 121 { "defaultFontSizeLabel",
120 IDS_OPTIONS_DEFAULT_FONT_SIZE_LABEL }, 122 IDS_OPTIONS_DEFAULT_FONT_SIZE_LABEL },
121 { "fontSizeLabelVerySmall", 123 { "fontSizeLabelVerySmall",
122 IDS_OPTIONS_FONT_SIZE_LABEL_VERY_SMALL }, 124 IDS_OPTIONS_FONT_SIZE_LABEL_VERY_SMALL },
123 { "fontSizeLabelSmall", 125 { "fontSizeLabelSmall",
124 IDS_OPTIONS_FONT_SIZE_LABEL_SMALL }, 126 IDS_OPTIONS_FONT_SIZE_LABEL_SMALL },
125 { "fontSizeLabelMedium", 127 { "fontSizeLabelMedium",
126 IDS_OPTIONS_FONT_SIZE_LABEL_MEDIUM }, 128 IDS_OPTIONS_FONT_SIZE_LABEL_MEDIUM },
127 { "fontSizeLabelLarge", 129 { "fontSizeLabelLarge",
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 localized_strings->SetString("cloudPrintLearnMoreURL", 196 localized_strings->SetString("cloudPrintLearnMoreURL",
195 google_util::AppendGoogleLocaleParam( 197 google_util::AppendGoogleLocaleParam(
196 GURL(chrome::kCloudPrintLearnMoreURL)).spec()); 198 GURL(chrome::kCloudPrintLearnMoreURL)).spec());
197 #endif 199 #endif
198 } 200 }
199 201
200 void AdvancedOptionsHandler::Initialize() { 202 void AdvancedOptionsHandler::Initialize() {
201 DCHECK(web_ui_); 203 DCHECK(web_ui_);
202 SetupMetricsReportingCheckbox(); 204 SetupMetricsReportingCheckbox();
203 SetupMetricsReportingSettingVisibility(); 205 SetupMetricsReportingSettingVisibility();
204 SetupFontSizeLabel(); 206 SetupFontSizeSelector();
207 SetupPageZoomSelector();
205 SetupAutoOpenFileTypesDisabledAttribute(); 208 SetupAutoOpenFileTypesDisabledAttribute();
206 SetupProxySettingsSection(); 209 SetupProxySettingsSection();
207 SetupSSLConfigSettings(); 210 SetupSSLConfigSettings();
208 #if !defined(OS_CHROMEOS) 211 #if !defined(OS_CHROMEOS)
209 if (cloud_print_proxy_ui_enabled_) { 212 if (cloud_print_proxy_ui_enabled_) {
210 SetupCloudPrintProxySection(); 213 SetupCloudPrintProxySection();
211 RefreshCloudPrintStatusFromService(); 214 RefreshCloudPrintStatusFromService();
212 } else { 215 } else {
213 RemoveCloudPrintProxySection(); 216 RemoveCloudPrintProxySection();
214 } 217 }
(...skipping 23 matching lines...) Expand all
238 g_browser_process->local_state(), this); 241 g_browser_process->local_state(), this);
239 242
240 #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS) 243 #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS)
241 background_mode_enabled_.Init(prefs::kBackgroundModeEnabled, 244 background_mode_enabled_.Init(prefs::kBackgroundModeEnabled,
242 g_browser_process->local_state(), 245 g_browser_process->local_state(),
243 this); 246 this);
244 #endif 247 #endif
245 248
246 auto_open_files_.Init(prefs::kDownloadExtensionsToOpen, prefs, this); 249 auto_open_files_.Init(prefs::kDownloadExtensionsToOpen, prefs, this);
247 default_font_size_.Init(prefs::kWebKitDefaultFontSize, prefs, this); 250 default_font_size_.Init(prefs::kWebKitDefaultFontSize, prefs, this);
251 default_zoom_level_.Init(prefs::kDefaultZoomLevel, prefs, this);
248 #if !defined(OS_CHROMEOS) 252 #if !defined(OS_CHROMEOS)
249 proxy_prefs_.reset( 253 proxy_prefs_.reset(
250 PrefSetObserver::CreateProxyPrefSetObserver(prefs, this)); 254 PrefSetObserver::CreateProxyPrefSetObserver(prefs, this));
251 #endif // !defined(OS_CHROMEOS) 255 #endif // !defined(OS_CHROMEOS)
252 256
253 // Return result from the superclass. 257 // Return result from the superclass.
254 return handler; 258 return handler;
255 } 259 }
256 260
257 void AdvancedOptionsHandler::RegisterMessages() { 261 void AdvancedOptionsHandler::RegisterMessages() {
258 // Setup handlers specific to this panel. 262 // Setup handlers specific to this panel.
259 DCHECK(web_ui_); 263 DCHECK(web_ui_);
260 web_ui_->RegisterMessageCallback("selectDownloadLocation", 264 web_ui_->RegisterMessageCallback("selectDownloadLocation",
261 base::Bind(&AdvancedOptionsHandler::HandleSelectDownloadLocation, 265 base::Bind(&AdvancedOptionsHandler::HandleSelectDownloadLocation,
262 base::Unretained(this))); 266 base::Unretained(this)));
263 web_ui_->RegisterMessageCallback("autoOpenFileTypesAction", 267 web_ui_->RegisterMessageCallback("autoOpenFileTypesAction",
264 base::Bind(&AdvancedOptionsHandler::HandleAutoOpenButton, 268 base::Bind(&AdvancedOptionsHandler::HandleAutoOpenButton,
265 base::Unretained(this))); 269 base::Unretained(this)));
266 web_ui_->RegisterMessageCallback("defaultFontSizeAction", 270 web_ui_->RegisterMessageCallback("defaultFontSizeAction",
267 base::Bind(&AdvancedOptionsHandler::HandleDefaultFontSize, 271 base::Bind(&AdvancedOptionsHandler::HandleDefaultFontSize,
268 base::Unretained(this))); 272 base::Unretained(this)));
273 web_ui_->RegisterMessageCallback("defaultZoomFactorAction",
274 base::Bind(&AdvancedOptionsHandler::HandleDefaultZoomFactor,
275 base::Unretained(this)));
269 #if !defined(OS_CHROMEOS) 276 #if !defined(OS_CHROMEOS)
270 web_ui_->RegisterMessageCallback("metricsReportingCheckboxAction", 277 web_ui_->RegisterMessageCallback("metricsReportingCheckboxAction",
271 base::Bind(&AdvancedOptionsHandler::HandleMetricsReportingCheckbox, 278 base::Bind(&AdvancedOptionsHandler::HandleMetricsReportingCheckbox,
272 base::Unretained(this))); 279 base::Unretained(this)));
273 #endif 280 #endif
274 #if !defined(USE_NSS) && !defined(USE_OPENSSL) 281 #if !defined(USE_NSS) && !defined(USE_OPENSSL)
275 web_ui_->RegisterMessageCallback("showManageSSLCertificates", 282 web_ui_->RegisterMessageCallback("showManageSSLCertificates",
276 base::Bind(&AdvancedOptionsHandler::ShowManageSSLCertificates, 283 base::Bind(&AdvancedOptionsHandler::ShowManageSSLCertificates,
277 base::Unretained(this))); 284 base::Unretained(this)));
278 #endif 285 #endif
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 } else if (proxy_prefs_->IsObserved(*pref_name)) { 321 } else if (proxy_prefs_->IsObserved(*pref_name)) {
315 SetupProxySettingsSection(); 322 SetupProxySettingsSection();
316 #endif // !defined(OS_CHROMEOS) 323 #endif // !defined(OS_CHROMEOS)
317 } else if ((*pref_name == prefs::kCloudPrintEmail) || 324 } else if ((*pref_name == prefs::kCloudPrintEmail) ||
318 (*pref_name == prefs::kCloudPrintProxyEnabled)) { 325 (*pref_name == prefs::kCloudPrintProxyEnabled)) {
319 #if !defined(OS_CHROMEOS) 326 #if !defined(OS_CHROMEOS)
320 if (cloud_print_proxy_ui_enabled_) 327 if (cloud_print_proxy_ui_enabled_)
321 SetupCloudPrintProxySection(); 328 SetupCloudPrintProxySection();
322 #endif 329 #endif
323 } else if (*pref_name == prefs::kWebKitDefaultFontSize) { 330 } else if (*pref_name == prefs::kWebKitDefaultFontSize) {
324 SetupFontSizeLabel(); 331 SetupFontSizeSelector();
332 } else if (*pref_name == prefs::kDefaultZoomLevel) {
333 SetupPageZoomSelector();
325 #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS) 334 #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS)
326 } else if (*pref_name == prefs::kBackgroundModeEnabled) { 335 } else if (*pref_name == prefs::kBackgroundModeEnabled) {
327 SetupBackgroundModeSettings(); 336 SetupBackgroundModeSettings();
328 #endif 337 #endif
329 } 338 }
330 } 339 }
331 } 340 }
332 341
333 void AdvancedOptionsHandler::HandleSelectDownloadLocation( 342 void AdvancedOptionsHandler::HandleSelectDownloadLocation(
334 const ListValue* args) { 343 const ListValue* args) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 enable_metrics_recording_.SetValue(is_enabled); 386 enable_metrics_recording_.SetValue(is_enabled);
378 SetupMetricsReportingCheckbox(); 387 SetupMetricsReportingCheckbox();
379 #endif 388 #endif
380 } 389 }
381 390
382 void AdvancedOptionsHandler::HandleDefaultFontSize(const ListValue* args) { 391 void AdvancedOptionsHandler::HandleDefaultFontSize(const ListValue* args) {
383 int font_size; 392 int font_size;
384 if (ExtractIntegerValue(args, &font_size)) { 393 if (ExtractIntegerValue(args, &font_size)) {
385 if (font_size > 0) { 394 if (font_size > 0) {
386 default_font_size_.SetValue(font_size); 395 default_font_size_.SetValue(font_size);
387 SetupFontSizeLabel(); 396 SetupFontSizeSelector();
388 } 397 }
389 } 398 }
390 } 399 }
391 400
401 void AdvancedOptionsHandler::HandleDefaultZoomFactor(const ListValue* args) {
402 double zoom_factor;
403 if (ExtractDoubleValue(args, &zoom_factor)) {
404 default_zoom_level_.SetValue(
405 WebKit::WebView::zoomFactorToZoomLevel(zoom_factor));
406 }
407 }
408
392 void AdvancedOptionsHandler::HandleCheckRevocationCheckbox( 409 void AdvancedOptionsHandler::HandleCheckRevocationCheckbox(
393 const ListValue* args) { 410 const ListValue* args) {
394 std::string checked_str = UTF16ToUTF8(ExtractStringValue(args)); 411 std::string checked_str = UTF16ToUTF8(ExtractStringValue(args));
395 bool enabled = checked_str == "true"; 412 bool enabled = checked_str == "true";
396 UserMetrics::RecordAction( 413 UserMetrics::RecordAction(
397 enabled ? 414 enabled ?
398 UserMetricsAction("Options_CheckCertRevocation_Enable") : 415 UserMetricsAction("Options_CheckCertRevocation_Enable") :
399 UserMetricsAction("Options_CheckCertRevocation_Disable")); 416 UserMetricsAction("Options_CheckCertRevocation_Disable"));
400 rev_checking_enabled_.SetValue(enabled); 417 rev_checking_enabled_.SetValue(enabled);
401 } 418 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 471
455 void AdvancedOptionsHandler::HandleDisableCloudPrintProxy( 472 void AdvancedOptionsHandler::HandleDisableCloudPrintProxy(
456 const ListValue* args) { 473 const ListValue* args) {
457 UserMetrics::RecordAction( 474 UserMetrics::RecordAction(
458 UserMetricsAction("Options_DisableCloudPrintProxy")); 475 UserMetricsAction("Options_DisableCloudPrintProxy"));
459 CloudPrintProxyServiceFactory::GetForProfile(Profile::FromWebUI(web_ui_))-> 476 CloudPrintProxyServiceFactory::GetForProfile(Profile::FromWebUI(web_ui_))->
460 DisableForUser(); 477 DisableForUser();
461 } 478 }
462 479
463 void AdvancedOptionsHandler::RefreshCloudPrintStatusFromService() { 480 void AdvancedOptionsHandler::RefreshCloudPrintStatusFromService() {
464 DCHECK(web_ui_);
465 if (cloud_print_proxy_ui_enabled_) 481 if (cloud_print_proxy_ui_enabled_)
466 CloudPrintProxyServiceFactory::GetForProfile(Profile::FromWebUI(web_ui_))-> 482 CloudPrintProxyServiceFactory::GetForProfile(Profile::FromWebUI(web_ui_))->
467 RefreshStatusFromService(); 483 RefreshStatusFromService();
468 } 484 }
469 485
470 void AdvancedOptionsHandler::SetupCloudPrintProxySection() { 486 void AdvancedOptionsHandler::SetupCloudPrintProxySection() {
471 Profile* profile = Profile::FromWebUI(web_ui_); 487 Profile* profile = Profile::FromWebUI(web_ui_);
472 if (!CloudPrintProxyServiceFactory::GetForProfile(profile)) { 488 if (!CloudPrintProxyServiceFactory::GetForProfile(profile)) {
473 cloud_print_proxy_ui_enabled_ = false; 489 cloud_print_proxy_ui_enabled_ = false;
474 RemoveCloudPrintProxySection(); 490 RemoveCloudPrintProxySection();
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 // Don't show the reporting setting if we are in the guest mode. 540 // Don't show the reporting setting if we are in the guest mode.
525 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kGuestSession)) { 541 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kGuestSession)) {
526 base::FundamentalValue visible(false); 542 base::FundamentalValue visible(false);
527 web_ui_->CallJavascriptFunction( 543 web_ui_->CallJavascriptFunction(
528 "options.AdvancedOptions.SetMetricsReportingSettingVisibility", 544 "options.AdvancedOptions.SetMetricsReportingSettingVisibility",
529 visible); 545 visible);
530 } 546 }
531 #endif 547 #endif
532 } 548 }
533 549
534 void AdvancedOptionsHandler::SetupFontSizeLabel() { 550 void AdvancedOptionsHandler::SetupFontSizeSelector() {
535 // We're only interested in integer values, so convert to int. 551 // We're only interested in integer values, so convert to int.
536 base::FundamentalValue font_size(default_font_size_.GetValue()); 552 base::FundamentalValue font_size(default_font_size_.GetValue());
537 web_ui_->CallJavascriptFunction( 553 web_ui_->CallJavascriptFunction(
538 "options.AdvancedOptions.SetFontSize", font_size); 554 "options.AdvancedOptions.SetFontSize", font_size);
539 } 555 }
540 556
557 void AdvancedOptionsHandler::SetupPageZoomSelector() {
558 PrefService* pref_service = Profile::FromWebUI(web_ui_)->GetPrefs();
559 double default_zoom_level = pref_service->GetDouble(prefs::kDefaultZoomLevel);
560 double default_zoom_factor =
561 WebKit::WebView::zoomLevelToZoomFactor(default_zoom_level);
562
563 // Generate a vector of zoom factors from an array of known presets along with
564 // the default factor added if necessary.
565 std::vector<double> zoom_factors =
566 content::PageZoomHelpers::PresetFactorsWithCustomValue(
567 default_zoom_factor);
568
569 // Iterate through the zoom factors and and build the contents of the
570 // selector that will be sent to the javascript handler.
571 // Each item in the list has the following parameters:
572 // 1. Title (string).
573 // 2. Value (double).
574 // 3. Is selected? (bool).
575 ListValue zoom_factors_value;
576 for (std::vector<double>::const_iterator i = zoom_factors.begin();
577 i != zoom_factors.end(); ++i) {
578 ListValue* option = new ListValue();
579 double factor = *i;
580 int percent = static_cast<int>(factor * 100 + 0.5);
581 option->Append(Value::CreateStringValue(
582 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, percent)));
583 option->Append(Value::CreateDoubleValue(factor));
584 bool selected =
585 content::PageZoomHelpers::ZoomValuesEqual(factor, default_zoom_factor);
586 option->Append(Value::CreateBooleanValue(selected));
587 zoom_factors_value.Append(option);
588 }
589
590 web_ui_->CallJavascriptFunction(
591 "options.AdvancedOptions.SetupPageZoomSelector", zoom_factors_value);
592 }
593
541 void AdvancedOptionsHandler::SetupAutoOpenFileTypesDisabledAttribute() { 594 void AdvancedOptionsHandler::SetupAutoOpenFileTypesDisabledAttribute() {
542 // Set the enabled state for the AutoOpenFileTypesResetToDefault button. 595 // Set the enabled state for the AutoOpenFileTypesResetToDefault button.
543 // We enable the button if the user has any auto-open file types registered. 596 // We enable the button if the user has any auto-open file types registered.
544 DownloadManager* manager = 597 DownloadManager* manager =
545 web_ui_->tab_contents()->browser_context()->GetDownloadManager(); 598 web_ui_->tab_contents()->browser_context()->GetDownloadManager();
546 bool disabled = !(manager && 599 bool disabled = !(manager &&
547 DownloadPrefs::FromDownloadManager(manager)->IsAutoOpenUsed()); 600 DownloadPrefs::FromDownloadManager(manager)->IsAutoOpenUsed());
548 base::FundamentalValue value(disabled); 601 base::FundamentalValue value(disabled);
549 web_ui_->CallJavascriptFunction( 602 web_ui_->CallJavascriptFunction(
550 "options.AdvancedOptions.SetAutoOpenFileTypesDisabledAttribute", value); 603 "options.AdvancedOptions.SetAutoOpenFileTypesDisabledAttribute", value);
(...skipping 29 matching lines...) Expand all
580 633
581 void AdvancedOptionsHandler::SetupSSLConfigSettings() { 634 void AdvancedOptionsHandler::SetupSSLConfigSettings() {
582 { 635 {
583 base::FundamentalValue checked(rev_checking_enabled_.GetValue()); 636 base::FundamentalValue checked(rev_checking_enabled_.GetValue());
584 base::FundamentalValue disabled(rev_checking_enabled_.IsManaged()); 637 base::FundamentalValue disabled(rev_checking_enabled_.IsManaged());
585 web_ui_->CallJavascriptFunction( 638 web_ui_->CallJavascriptFunction(
586 "options.AdvancedOptions.SetCheckRevocationCheckboxState", checked, 639 "options.AdvancedOptions.SetCheckRevocationCheckboxState", checked,
587 disabled); 640 disabled);
588 } 641 }
589 } 642 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698