OLD | NEW |
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/callback.h" | 10 #include "base/callback.h" |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 | 218 |
219 } | 219 } |
220 | 220 |
221 WebUIMessageHandler* AdvancedOptionsHandler::Attach(WebUI* web_ui) { | 221 WebUIMessageHandler* AdvancedOptionsHandler::Attach(WebUI* web_ui) { |
222 // Call through to superclass. | 222 // Call through to superclass. |
223 WebUIMessageHandler* handler = OptionsPageUIHandler::Attach(web_ui); | 223 WebUIMessageHandler* handler = OptionsPageUIHandler::Attach(web_ui); |
224 | 224 |
225 // Register for preferences that we need to observe manually. These have | 225 // Register for preferences that we need to observe manually. These have |
226 // special behaviors that aren't handled by the standard prefs UI. | 226 // special behaviors that aren't handled by the standard prefs UI. |
227 DCHECK(web_ui_); | 227 DCHECK(web_ui_); |
228 PrefService* prefs = web_ui_->GetProfile()->GetPrefs(); | 228 PrefService* prefs = Profile::FromWebUI(web_ui_)->GetPrefs(); |
229 #if !defined(OS_CHROMEOS) | 229 #if !defined(OS_CHROMEOS) |
230 enable_metrics_recording_.Init(prefs::kMetricsReportingEnabled, | 230 enable_metrics_recording_.Init(prefs::kMetricsReportingEnabled, |
231 g_browser_process->local_state(), this); | 231 g_browser_process->local_state(), this); |
232 cloud_print_proxy_email_.Init(prefs::kCloudPrintEmail, prefs, this); | 232 cloud_print_proxy_email_.Init(prefs::kCloudPrintEmail, prefs, this); |
233 cloud_print_proxy_enabled_.Init(prefs::kCloudPrintProxyEnabled, prefs, this); | 233 cloud_print_proxy_enabled_.Init(prefs::kCloudPrintProxyEnabled, prefs, this); |
234 #endif | 234 #endif |
235 | 235 |
236 #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS) | 236 #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS) |
237 background_mode_enabled_.Init(prefs::kBackgroundModeEnabled, | 237 background_mode_enabled_.Init(prefs::kBackgroundModeEnabled, |
238 g_browser_process->local_state(), | 238 g_browser_process->local_state(), |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS) | 325 #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS) |
326 } else if (*pref_name == prefs::kBackgroundModeEnabled) { | 326 } else if (*pref_name == prefs::kBackgroundModeEnabled) { |
327 SetupBackgroundModeSettings(); | 327 SetupBackgroundModeSettings(); |
328 #endif | 328 #endif |
329 } | 329 } |
330 } | 330 } |
331 } | 331 } |
332 | 332 |
333 void AdvancedOptionsHandler::HandleSelectDownloadLocation( | 333 void AdvancedOptionsHandler::HandleSelectDownloadLocation( |
334 const ListValue* args) { | 334 const ListValue* args) { |
335 PrefService* pref_service = web_ui_->GetProfile()->GetPrefs(); | 335 PrefService* pref_service = Profile::FromWebUI(web_ui_)->GetPrefs(); |
336 select_folder_dialog_ = SelectFileDialog::Create(this); | 336 select_folder_dialog_ = SelectFileDialog::Create(this); |
337 select_folder_dialog_->SelectFile( | 337 select_folder_dialog_->SelectFile( |
338 SelectFileDialog::SELECT_FOLDER, | 338 SelectFileDialog::SELECT_FOLDER, |
339 l10n_util::GetStringUTF16(IDS_OPTIONS_DOWNLOADLOCATION_BROWSE_TITLE), | 339 l10n_util::GetStringUTF16(IDS_OPTIONS_DOWNLOADLOCATION_BROWSE_TITLE), |
340 pref_service->GetFilePath(prefs::kDownloadDefaultDirectory), | 340 pref_service->GetFilePath(prefs::kDownloadDefaultDirectory), |
341 NULL, 0, FILE_PATH_LITERAL(""), web_ui_->tab_contents(), | 341 NULL, 0, FILE_PATH_LITERAL(""), web_ui_->tab_contents(), |
342 web_ui_->tab_contents()->view()->GetTopLevelNativeWindow(), NULL); | 342 web_ui_->tab_contents()->view()->GetTopLevelNativeWindow(), NULL); |
343 } | 343 } |
344 | 344 |
345 void AdvancedOptionsHandler::HandlePromptForDownload( | 345 void AdvancedOptionsHandler::HandlePromptForDownload( |
(...skipping 11 matching lines...) Expand all Loading... |
357 | 357 |
358 void AdvancedOptionsHandler::OnCloudPrintSetupClosed() { | 358 void AdvancedOptionsHandler::OnCloudPrintSetupClosed() { |
359 #if !defined(OS_CHROMEOS) | 359 #if !defined(OS_CHROMEOS) |
360 if (cloud_print_proxy_ui_enabled_) | 360 if (cloud_print_proxy_ui_enabled_) |
361 SetupCloudPrintProxySection(); | 361 SetupCloudPrintProxySection(); |
362 #endif | 362 #endif |
363 } | 363 } |
364 | 364 |
365 void AdvancedOptionsHandler::HandleAutoOpenButton(const ListValue* args) { | 365 void AdvancedOptionsHandler::HandleAutoOpenButton(const ListValue* args) { |
366 UserMetrics::RecordAction(UserMetricsAction("Options_ResetAutoOpenFiles")); | 366 UserMetrics::RecordAction(UserMetricsAction("Options_ResetAutoOpenFiles")); |
367 DownloadManager* manager = web_ui_->GetProfile()->GetDownloadManager(); | 367 DownloadManager* manager = |
| 368 web_ui_->tab_contents()->browser_context()->GetDownloadManager(); |
368 if (manager) | 369 if (manager) |
369 manager->download_prefs()->ResetAutoOpen(); | 370 manager->download_prefs()->ResetAutoOpen(); |
370 } | 371 } |
371 | 372 |
372 void AdvancedOptionsHandler::HandleMetricsReportingCheckbox( | 373 void AdvancedOptionsHandler::HandleMetricsReportingCheckbox( |
373 const ListValue* args) { | 374 const ListValue* args) { |
374 #if defined(GOOGLE_CHROME_BUILD) && !defined(OS_CHROMEOS) | 375 #if defined(GOOGLE_CHROME_BUILD) && !defined(OS_CHROMEOS) |
375 std::string checked_str = UTF16ToUTF8(ExtractStringValue(args)); | 376 std::string checked_str = UTF16ToUTF8(ExtractStringValue(args)); |
376 bool enabled = checked_str == "true"; | 377 bool enabled = checked_str == "true"; |
377 UserMetrics::RecordAction( | 378 UserMetrics::RecordAction( |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 #if !defined(USE_NSS) && !defined(USE_OPENSSL) | 423 #if !defined(USE_NSS) && !defined(USE_OPENSSL) |
423 void AdvancedOptionsHandler::ShowManageSSLCertificates(const ListValue* args) { | 424 void AdvancedOptionsHandler::ShowManageSSLCertificates(const ListValue* args) { |
424 UserMetrics::RecordAction(UserMetricsAction("Options_ManageSSLCertificates")); | 425 UserMetrics::RecordAction(UserMetricsAction("Options_ManageSSLCertificates")); |
425 AdvancedOptionsUtilities::ShowManageSSLCertificates(web_ui_->tab_contents()); | 426 AdvancedOptionsUtilities::ShowManageSSLCertificates(web_ui_->tab_contents()); |
426 } | 427 } |
427 #endif | 428 #endif |
428 | 429 |
429 void AdvancedOptionsHandler::ShowCloudPrintManagePage(const ListValue* args) { | 430 void AdvancedOptionsHandler::ShowCloudPrintManagePage(const ListValue* args) { |
430 UserMetrics::RecordAction(UserMetricsAction("Options_ManageCloudPrinters")); | 431 UserMetrics::RecordAction(UserMetricsAction("Options_ManageCloudPrinters")); |
431 // Open a new tab in the current window for the management page. | 432 // Open a new tab in the current window for the management page. |
| 433 Profile* profile = Profile::FromWebUI(web_ui_); |
432 web_ui_->tab_contents()->OpenURL( | 434 web_ui_->tab_contents()->OpenURL( |
433 CloudPrintURL(web_ui_->GetProfile()).GetCloudPrintServiceManageURL(), | 435 CloudPrintURL(profile).GetCloudPrintServiceManageURL(), |
434 GURL(), NEW_FOREGROUND_TAB, PageTransition::LINK); | 436 GURL(), NEW_FOREGROUND_TAB, PageTransition::LINK); |
435 } | 437 } |
436 | 438 |
437 #if !defined(OS_CHROMEOS) | 439 #if !defined(OS_CHROMEOS) |
438 void AdvancedOptionsHandler::ShowCloudPrintSetupDialog(const ListValue* args) { | 440 void AdvancedOptionsHandler::ShowCloudPrintSetupDialog(const ListValue* args) { |
439 UserMetrics::RecordAction(UserMetricsAction("Options_EnableCloudPrintProxy")); | 441 UserMetrics::RecordAction(UserMetricsAction("Options_EnableCloudPrintProxy")); |
440 // Open the connector enable page in the current tab. | 442 // Open the connector enable page in the current tab. |
| 443 Profile* profile = Profile::FromWebUI(web_ui_); |
441 web_ui_->tab_contents()->OpenURL( | 444 web_ui_->tab_contents()->OpenURL( |
442 CloudPrintURL(web_ui_->GetProfile()).GetCloudPrintServiceEnableURL( | 445 CloudPrintURL(profile).GetCloudPrintServiceEnableURL( |
443 CloudPrintProxyServiceFactory::GetForProfile( | 446 CloudPrintProxyServiceFactory::GetForProfile(profile)->proxy_id()), |
444 web_ui_->GetProfile())->proxy_id()), | |
445 GURL(), CURRENT_TAB, PageTransition::LINK); | 447 GURL(), CURRENT_TAB, PageTransition::LINK); |
446 } | 448 } |
447 | 449 |
448 void AdvancedOptionsHandler::HandleDisableCloudPrintProxy( | 450 void AdvancedOptionsHandler::HandleDisableCloudPrintProxy( |
449 const ListValue* args) { | 451 const ListValue* args) { |
450 UserMetrics::RecordAction( | 452 UserMetrics::RecordAction( |
451 UserMetricsAction("Options_DisableCloudPrintProxy")); | 453 UserMetricsAction("Options_DisableCloudPrintProxy")); |
452 CloudPrintProxyServiceFactory::GetForProfile(web_ui_->GetProfile())-> | 454 CloudPrintProxyServiceFactory::GetForProfile(Profile::FromWebUI(web_ui_))-> |
453 DisableForUser(); | 455 DisableForUser(); |
454 } | 456 } |
455 | 457 |
456 void AdvancedOptionsHandler::RefreshCloudPrintStatusFromService() { | 458 void AdvancedOptionsHandler::RefreshCloudPrintStatusFromService() { |
457 DCHECK(web_ui_); | 459 DCHECK(web_ui_); |
458 if (cloud_print_proxy_ui_enabled_) | 460 if (cloud_print_proxy_ui_enabled_) |
459 CloudPrintProxyServiceFactory::GetForProfile(web_ui_->GetProfile())-> | 461 CloudPrintProxyServiceFactory::GetForProfile(Profile::FromWebUI(web_ui_))-> |
460 RefreshStatusFromService(); | 462 RefreshStatusFromService(); |
461 } | 463 } |
462 | 464 |
463 void AdvancedOptionsHandler::SetupCloudPrintProxySection() { | 465 void AdvancedOptionsHandler::SetupCloudPrintProxySection() { |
464 if (!CloudPrintProxyServiceFactory::GetForProfile(web_ui_->GetProfile())) { | 466 Profile* profile = Profile::FromWebUI(web_ui_); |
| 467 if (!CloudPrintProxyServiceFactory::GetForProfile(profile)) { |
465 cloud_print_proxy_ui_enabled_ = false; | 468 cloud_print_proxy_ui_enabled_ = false; |
466 RemoveCloudPrintProxySection(); | 469 RemoveCloudPrintProxySection(); |
467 return; | 470 return; |
468 } | 471 } |
469 | 472 |
470 bool cloud_print_proxy_allowed = | 473 bool cloud_print_proxy_allowed = |
471 !cloud_print_proxy_enabled_.IsManaged() || | 474 !cloud_print_proxy_enabled_.IsManaged() || |
472 cloud_print_proxy_enabled_.GetValue(); | 475 cloud_print_proxy_enabled_.GetValue(); |
473 FundamentalValue allowed(cloud_print_proxy_allowed); | 476 FundamentalValue allowed(cloud_print_proxy_allowed); |
474 | 477 |
475 std::string email; | 478 std::string email; |
476 if (web_ui_->GetProfile()->GetPrefs()->HasPrefPath(prefs::kCloudPrintEmail) && | 479 if (profile->GetPrefs()->HasPrefPath(prefs::kCloudPrintEmail) && |
477 cloud_print_proxy_allowed) { | 480 cloud_print_proxy_allowed) { |
478 email = web_ui_->GetProfile()->GetPrefs()->GetString( | 481 email = profile->GetPrefs()->GetString(prefs::kCloudPrintEmail); |
479 prefs::kCloudPrintEmail); | |
480 } | 482 } |
481 FundamentalValue disabled(email.empty()); | 483 FundamentalValue disabled(email.empty()); |
482 | 484 |
483 string16 label_str; | 485 string16 label_str; |
484 if (email.empty()) { | 486 if (email.empty()) { |
485 label_str = l10n_util::GetStringUTF16( | 487 label_str = l10n_util::GetStringUTF16( |
486 IDS_OPTIONS_CLOUD_PRINT_PROXY_DISABLED_LABEL); | 488 IDS_OPTIONS_CLOUD_PRINT_PROXY_DISABLED_LABEL); |
487 } else { | 489 } else { |
488 label_str = l10n_util::GetStringFUTF16( | 490 label_str = l10n_util::GetStringFUTF16( |
489 IDS_OPTIONS_CLOUD_PRINT_PROXY_ENABLED_LABEL, UTF8ToUTF16(email)); | 491 IDS_OPTIONS_CLOUD_PRINT_PROXY_ENABLED_LABEL, UTF8ToUTF16(email)); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 // be changed. | 551 // be changed. |
550 FundamentalValue disabled(default_download_location_.IsManaged() || | 552 FundamentalValue disabled(default_download_location_.IsManaged() || |
551 !allow_file_selection_dialogs_.GetValue()); | 553 !allow_file_selection_dialogs_.GetValue()); |
552 web_ui_->CallJavascriptFunction( | 554 web_ui_->CallJavascriptFunction( |
553 "options.AdvancedOptions.SetPromptForDownload", checked, disabled); | 555 "options.AdvancedOptions.SetPromptForDownload", checked, disabled); |
554 } | 556 } |
555 | 557 |
556 void AdvancedOptionsHandler::SetupAutoOpenFileTypesDisabledAttribute() { | 558 void AdvancedOptionsHandler::SetupAutoOpenFileTypesDisabledAttribute() { |
557 // Set the enabled state for the AutoOpenFileTypesResetToDefault button. | 559 // Set the enabled state for the AutoOpenFileTypesResetToDefault button. |
558 // We enable the button if the user has any auto-open file types registered. | 560 // We enable the button if the user has any auto-open file types registered. |
559 DownloadManager* manager = web_ui_->GetProfile()->GetDownloadManager(); | 561 DownloadManager* manager = |
| 562 web_ui_->tab_contents()->browser_context()->GetDownloadManager(); |
560 bool disabled = !(manager && manager->download_prefs()->IsAutoOpenUsed()); | 563 bool disabled = !(manager && manager->download_prefs()->IsAutoOpenUsed()); |
561 FundamentalValue value(disabled); | 564 FundamentalValue value(disabled); |
562 web_ui_->CallJavascriptFunction( | 565 web_ui_->CallJavascriptFunction( |
563 "options.AdvancedOptions.SetAutoOpenFileTypesDisabledAttribute", value); | 566 "options.AdvancedOptions.SetAutoOpenFileTypesDisabledAttribute", value); |
564 } | 567 } |
565 | 568 |
566 void AdvancedOptionsHandler::SetupProxySettingsSection() { | 569 void AdvancedOptionsHandler::SetupProxySettingsSection() { |
567 // Disable the button if proxy settings are managed by a sysadmin or | 570 // Disable the button if proxy settings are managed by a sysadmin or |
568 // overridden by an extension. | 571 // overridden by an extension. |
569 PrefService* pref_service = web_ui_->GetProfile()->GetPrefs(); | 572 PrefService* pref_service = Profile::FromWebUI(web_ui_)->GetPrefs(); |
570 const PrefService::Preference* proxy_config = | 573 const PrefService::Preference* proxy_config = |
571 pref_service->FindPreference(prefs::kProxy); | 574 pref_service->FindPreference(prefs::kProxy); |
572 bool is_extension_controlled = (proxy_config && | 575 bool is_extension_controlled = (proxy_config && |
573 proxy_config->IsExtensionControlled()); | 576 proxy_config->IsExtensionControlled()); |
574 | 577 |
575 FundamentalValue disabled(proxy_prefs_->IsManaged() || | 578 FundamentalValue disabled(proxy_prefs_->IsManaged() || |
576 is_extension_controlled); | 579 is_extension_controlled); |
577 | 580 |
578 // Get the appropriate info string to describe the button. | 581 // Get the appropriate info string to describe the button. |
579 string16 label_str; | 582 string16 label_str; |
580 if (is_extension_controlled) { | 583 if (is_extension_controlled) { |
581 label_str = l10n_util::GetStringUTF16(IDS_OPTIONS_EXTENSION_PROXIES_LABEL); | 584 label_str = l10n_util::GetStringUTF16(IDS_OPTIONS_EXTENSION_PROXIES_LABEL); |
582 } else { | 585 } else { |
583 label_str = l10n_util::GetStringFUTF16(IDS_OPTIONS_SYSTEM_PROXIES_LABEL, | 586 label_str = l10n_util::GetStringFUTF16(IDS_OPTIONS_SYSTEM_PROXIES_LABEL, |
584 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); | 587 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); |
585 } | 588 } |
586 StringValue label(label_str); | 589 StringValue label(label_str); |
587 | 590 |
588 web_ui_->CallJavascriptFunction( | 591 web_ui_->CallJavascriptFunction( |
589 "options.AdvancedOptions.SetupProxySettingsSection", disabled, label); | 592 "options.AdvancedOptions.SetupProxySettingsSection", disabled, label); |
590 } | 593 } |
OLD | NEW |