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