diff options
Diffstat (limited to 'chrome/browser/views/options/advanced_contents_view.cc')
-rw-r--r-- | chrome/browser/views/options/advanced_contents_view.cc | 346 |
1 files changed, 316 insertions, 30 deletions
diff --git a/chrome/browser/views/options/advanced_contents_view.cc b/chrome/browser/views/options/advanced_contents_view.cc index bbe232f..9472b5e 100644 --- a/chrome/browser/views/options/advanced_contents_view.cc +++ b/chrome/browser/views/options/advanced_contents_view.cc @@ -12,33 +12,39 @@ #include <vsstyle.h> #include <vssym32.h> -#include "app/combobox_model.h" #include "app/l10n_util.h" #include "app/resource_bundle.h" +#include "base/command_line.h" #include "base/file_util.h" #include "base/i18n/rtl.h" #include "base/message_loop.h" #include "base/path_service.h" +#include "base/scoped_callback_factory.h" #include "base/thread.h" +#include "base/utf_string_conversions.h" #include "chrome/browser/browser.h" #include "chrome/browser/browser_list.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/download/download_manager.h" +#include "chrome/browser/download/download_prefs.h" #include "chrome/browser/gears_integration.h" #include "chrome/browser/net/predictor_api.h" #include "chrome/browser/options_util.h" -#include "chrome/browser/pref_member.h" -#include "chrome/browser/pref_service.h" +#include "chrome/browser/prefs/pref_member.h" +#include "chrome/browser/prefs/pref_service.h" +#include "chrome/browser/prefs/pref_set_observer.h" +#include "chrome/browser/printing/cloud_print/cloud_print_setup_flow.h" #include "chrome/browser/profile.h" #include "chrome/browser/renderer_host/resource_dispatcher_host.h" #include "chrome/browser/safe_browsing/safe_browsing_service.h" #include "chrome/browser/shell_dialogs.h" #include "chrome/browser/views/browser_dialogs.h" -#include "chrome/browser/views/clear_browsing_data.h" +#include "chrome/browser/views/clear_data_view.h" #include "chrome/browser/views/list_background.h" #include "chrome/browser/views/options/content_settings_window_view.h" #include "chrome/browser/views/options/fonts_languages_window_view.h" #include "chrome/browser/views/restart_message_box.h" +#include "chrome/common/chrome_switches.h" #include "chrome/common/pref_names.h" #include "gfx/canvas_skia.h" #include "gfx/native_theme_win.h" @@ -436,7 +442,7 @@ class PrivacySection : public AdvancedSection, protected: // OptionsPageView overrides: virtual void InitControlLayout(); - virtual void NotifyPrefChanged(const std::wstring* pref_name); + virtual void NotifyPrefChanged(const std::string* pref_name); private: // Controls for this section: @@ -531,7 +537,7 @@ void PrivacySection::ButtonPressed( views::Window::CreateChromeWindow( GetWindow()->GetNativeWindow(), gfx::Rect(), - new ClearBrowsingDataView(profile()))->Show(); + new ClearDataView(profile()))->Show(); } } @@ -630,36 +636,34 @@ void PrivacySection::InitControlLayout() { safe_browsing_.Init(prefs::kSafeBrowsingEnabled, profile()->GetPrefs(), this); enable_metrics_recording_.Init(prefs::kMetricsReportingEnabled, g_browser_process->local_state(), this); - - - enable_link_doctor_checkbox_->SetEnabled(!alternate_error_pages_.IsManaged()); - enable_suggest_checkbox_->SetEnabled(!use_suggest_.IsManaged()); - enable_dns_prefetching_checkbox_->SetEnabled( - !dns_prefetch_enabled_.IsManaged()); - enable_safe_browsing_checkbox_->SetEnabled(!safe_browsing_.IsManaged()); -#if defined(GOOGLE_CHROME_BUILD) - reporting_enabled_checkbox_->SetEnabled( - !enable_metrics_recording_.IsManaged()); -#endif } -void PrivacySection::NotifyPrefChanged(const std::wstring* pref_name) { +void PrivacySection::NotifyPrefChanged(const std::string* pref_name) { if (!pref_name || *pref_name == prefs::kAlternateErrorPagesEnabled) { + enable_link_doctor_checkbox_->SetEnabled( + !alternate_error_pages_.IsManaged()); enable_link_doctor_checkbox_->SetChecked( alternate_error_pages_.GetValue()); } if (!pref_name || *pref_name == prefs::kSearchSuggestEnabled) { + enable_suggest_checkbox_->SetEnabled(!use_suggest_.IsManaged()); enable_suggest_checkbox_->SetChecked(use_suggest_.GetValue()); } if (!pref_name || *pref_name == prefs::kDnsPrefetchingEnabled) { + enable_dns_prefetching_checkbox_->SetEnabled( + !dns_prefetch_enabled_.IsManaged()); bool enabled = dns_prefetch_enabled_.GetValue(); enable_dns_prefetching_checkbox_->SetChecked(enabled); chrome_browser_net::EnablePredictor(enabled); } - if (!pref_name || *pref_name == prefs::kSafeBrowsingEnabled) + if (!pref_name || *pref_name == prefs::kSafeBrowsingEnabled) { + enable_safe_browsing_checkbox_->SetEnabled(!safe_browsing_.IsManaged()); enable_safe_browsing_checkbox_->SetChecked(safe_browsing_.GetValue()); + } if (reporting_enabled_checkbox_ && (!pref_name || *pref_name == prefs::kMetricsReportingEnabled)) { + reporting_enabled_checkbox_->SetEnabled( + !enable_metrics_recording_.IsManaged()); reporting_enabled_checkbox_->SetChecked( enable_metrics_recording_.GetValue()); ResolveMetricsReportingEnabled(); @@ -786,7 +790,7 @@ class SecuritySection : public AdvancedSection, protected: // OptionsPageView overrides: virtual void InitControlLayout(); - virtual void NotifyPrefChanged(const std::wstring* pref_name); + virtual void NotifyPrefChanged(const std::string* pref_name); private: // Controls for this section: @@ -882,7 +886,7 @@ void SecuritySection::InitControlLayout() { } // This method is called with a null pref_name when the dialog is initialized. -void SecuritySection::NotifyPrefChanged(const std::wstring* pref_name) { +void SecuritySection::NotifyPrefChanged(const std::string* pref_name) { // These SSL options are system settings and stored in the OS. if (!pref_name) { net::SSLConfig config; @@ -946,13 +950,16 @@ class NetworkSection : public AdvancedSection, protected: // OptionsPageView overrides: virtual void InitControlLayout(); - virtual void NotifyPrefChanged(const std::wstring* pref_name); + virtual void NotifyPrefChanged(const std::string* pref_name); private: // Controls for this section: views::Label* change_proxies_label_; views::NativeButton* change_proxies_button_; + // Tracks the proxy preferences. + scoped_ptr<PrefSetObserver> proxy_prefs_; + DISALLOW_COPY_AND_ASSIGN(NetworkSection); }; @@ -998,9 +1005,16 @@ void NetworkSection::InitControlLayout() { true); AddLeadingControl(layout, change_proxies_button_, indented_view_set_id, false); + + proxy_prefs_.reset(PrefSetObserver::CreateProxyPrefSetObserver( + profile()->GetPrefs(), this)); + NotifyPrefChanged(NULL); } -void NetworkSection::NotifyPrefChanged(const std::wstring* pref_name) { +void NetworkSection::NotifyPrefChanged(const std::string* pref_name) { + if (!pref_name || proxy_prefs_->IsObserved(*pref_name)) { + change_proxies_button_->SetEnabled(!proxy_prefs_->IsManaged()); + } } } // namespace @@ -1029,7 +1043,7 @@ class DownloadSection : public AdvancedSection, protected: // OptionsPageView overrides. virtual void InitControlLayout(); - virtual void NotifyPrefChanged(const std::wstring* pref_name); + virtual void NotifyPrefChanged(const std::string* pref_name); private: // Controls for this section. @@ -1092,7 +1106,7 @@ void DownloadSection::ButtonPressed( } ask_for_save_location_.SetValue(enabled); } else if (sender == reset_file_handlers_button_) { - profile()->GetDownloadManager()->ResetAutoOpenFiles(); + profile()->GetDownloadManager()->download_prefs()->ResetAutoOpen(); UserMetricsRecordAction(UserMetricsAction("Options_ResetAutoOpenFiles"), profile()->GetPrefs()); } @@ -1178,7 +1192,7 @@ void DownloadSection::InitControlLayout() { this); } -void DownloadSection::NotifyPrefChanged(const std::wstring* pref_name) { +void DownloadSection::NotifyPrefChanged(const std::string* pref_name) { if (!pref_name || *pref_name == prefs::kDownloadDefaultDirectory) UpdateDownloadDirectoryDisplay(); @@ -1189,7 +1203,7 @@ void DownloadSection::NotifyPrefChanged(const std::wstring* pref_name) { if (!pref_name || *pref_name == prefs::kDownloadExtensionsToOpen) { bool enabled = - profile()->GetDownloadManager()->HasAutoOpenFileTypesRegistered(); + profile()->GetDownloadManager()->download_prefs()->IsAutoOpenUsed(); reset_file_handlers_label_->SetEnabled(enabled); reset_file_handlers_button_->SetEnabled(enabled); } @@ -1215,7 +1229,7 @@ class TranslateSection : public AdvancedSection, protected: // OptionsPageView overrides: virtual void InitControlLayout(); - virtual void NotifyPrefChanged(const std::wstring* pref_name); + virtual void NotifyPrefChanged(const std::string* pref_name); private: // Control for this section: @@ -1261,12 +1275,274 @@ void TranslateSection::InitControlLayout() { enable_translate_.Init(prefs::kEnableTranslate, profile()->GetPrefs(), this); } -void TranslateSection::NotifyPrefChanged(const std::wstring* pref_name) { +void TranslateSection::NotifyPrefChanged(const std::string* pref_name) { if (!pref_name || *pref_name == prefs::kEnableTranslate) enable_translate_checkbox_->SetChecked(enable_translate_.GetValue()); } //////////////////////////////////////////////////////////////////////////////// +// ChromeAppsSection + +class ChromeAppsSection : public AdvancedSection, + public views::ButtonListener, + public views::LinkController { + public: + explicit ChromeAppsSection(Profile* profile); + virtual ~ChromeAppsSection() {} + + // Overridden from views::ButtonListener: + virtual void ButtonPressed(views::Button* sender, const views::Event& event); + // Overridden from views::LinkController: + virtual void LinkActivated(views::Link* source, int event_flags); + + protected: + // OptionsPageView overrides: + virtual void InitControlLayout(); + virtual void NotifyPrefChanged(const std::string* pref_name); + + private: + // Controls for this section: + views::Checkbox* enable_background_mode_checkbox_; + views::Link* learn_more_link_; + + // Preferences for this section: + BooleanPrefMember enable_background_mode_; + + DISALLOW_COPY_AND_ASSIGN(ChromeAppsSection); +}; + +ChromeAppsSection::ChromeAppsSection(Profile* profile) + : enable_background_mode_checkbox_(NULL), + learn_more_link_(NULL), + AdvancedSection(profile, l10n_util::GetString( + IDS_OPTIONS_ADVANCED_SECTION_TITLE_CHROME_APPS)) { +} + +void ChromeAppsSection::ButtonPressed( + views::Button* sender, const views::Event& event) { + DCHECK(sender == enable_background_mode_checkbox_); + bool enabled = enable_background_mode_checkbox_->checked(); + UserMetricsRecordAction(enabled ? + UserMetricsAction("Options_BackgroundMode_Enable") : + UserMetricsAction("Options_BackgroundMode_Disable"), + profile()->GetPrefs()); + enable_background_mode_.SetValue(enabled); +} + +void ChromeAppsSection::LinkActivated(views::Link* source, int event_flags) { + DCHECK(source == learn_more_link_); + Browser::Create(profile())->OpenURL( + GURL(l10n_util::GetString(IDS_LEARN_MORE_BACKGROUND_MODE_URL)), GURL(), + NEW_WINDOW, PageTransition::LINK); +} + +void ChromeAppsSection::InitControlLayout() { + AdvancedSection::InitControlLayout(); + + GridLayout* layout = new GridLayout(contents_); + contents_->SetLayoutManager(layout); + + AddIndentedColumnSet(layout, 0); + + enable_background_mode_checkbox_ = new views::Checkbox( + l10n_util::GetString(IDS_OPTIONS_CHROME_APPS_ENABLE_BACKGROUND_MODE)); + enable_background_mode_checkbox_->set_listener(this); + AddWrappingCheckboxRow(layout, enable_background_mode_checkbox_, 0, true); + + // Init member pref so we can update the controls if prefs change. + enable_background_mode_.Init(prefs::kBackgroundModeEnabled, + profile()->GetPrefs(), this); + + // Add our link to the help center page for this feature. + learn_more_link_ = new views::Link(l10n_util::GetString(IDS_LEARN_MORE)); + learn_more_link_->SetController(this); + AddLeadingControl(layout, learn_more_link_, 0, false); +} + +void ChromeAppsSection::NotifyPrefChanged(const std::string* pref_name) { + if (!pref_name || *pref_name == prefs::kBackgroundModeEnabled) { + enable_background_mode_checkbox_->SetChecked( + enable_background_mode_.GetValue()); + } +} + +//////////////////////////////////////////////////////////////////////////////// +// CloudPrintProxySection + +class CloudPrintProxySection : public AdvancedSection, + public views::ButtonListener, + public CloudPrintSetupFlow::Delegate { + public: + explicit CloudPrintProxySection(Profile* profile); + virtual ~CloudPrintProxySection() {} + + // Overridden from views::ButtonListener: + virtual void ButtonPressed(views::Button* sender, const views::Event& event); + + // Callback that gets the cloud print proxy status. + void StatusCallback(bool enabled, std::string email); + + // CloudPrintSetupFlow::Delegate implementation. + virtual void OnDialogClosed(); + + protected: + // OptionsPageView overrides: + virtual void InitControlLayout(); + virtual void NotifyPrefChanged(const std::string* pref_name); + + private: + bool Enabled() const; + + // Controls for this section: + views::Label* section_description_label_; + views::NativeButton* enable_disable_button_; + views::NativeButton* manage_printer_button_; + + // Preferences we tie things to. + StringPrefMember cloud_print_proxy_email_; + + base::ScopedCallbackFactory<CloudPrintProxySection> factory_; + + DISALLOW_COPY_AND_ASSIGN(CloudPrintProxySection); +}; + +CloudPrintProxySection::CloudPrintProxySection(Profile* profile) + : section_description_label_(NULL), + enable_disable_button_(NULL), + manage_printer_button_(NULL), + factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), + AdvancedSection(profile, + l10n_util::GetString( + IDS_OPTIONS_ADVANCED_SECTION_TITLE_CLOUD_PRINT)) { +} + +void CloudPrintProxySection::ButtonPressed(views::Button* sender, + const views::Event& event) { + if (sender == enable_disable_button_) { + if (Enabled()) { + // Enabled, we must be the disable button. + UserMetricsRecordAction( + UserMetricsAction("Options_DisableCloudPrintProxy"), NULL); + CloudPrintSetupFlow::DisableCloudPrintProxy(profile()); + } else { + UserMetricsRecordAction( + UserMetricsAction("Options_EnableCloudPrintProxy"), NULL); + // We open a new browser window so the Options dialog doesn't + // get lost behind other windows. + enable_disable_button_->SetEnabled(false); + enable_disable_button_->SetLabel( + l10n_util::GetString(IDS_OPTIONS_CLOUD_PRINT_PROXY_ENABLING_BUTTON)); + CloudPrintSetupFlow::OpenDialog(profile(), this, + GetWindow()->GetNativeWindow()); + } + } else if (sender == manage_printer_button_) { + UserMetricsRecordAction( + UserMetricsAction("Options_ManageCloudPrinters"), NULL); + // Open a new browser window for the management tab. The browser + // will go away when the user closes that tab. + Browser* browser = Browser::Create(profile()); + // FIXME(scottbyer): Refactor Cloud Print URL creation. + // http://code.google.com/p/chromium/issues/detail?id=56850 + browser->OpenURL(GURL("https://www.google.com/cloudprint/manage.html"), + GURL(), NEW_WINDOW, PageTransition::LINK); + } +} + +void CloudPrintProxySection::StatusCallback(bool enabled, std::string email) { + profile()->GetPrefs()->SetString(prefs::kCloudPrintEmail, + enabled ? email : std::string()); +} + +void CloudPrintProxySection::OnDialogClosed() { + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); + enable_disable_button_->SetEnabled(true); + // If the dialog is canceled, the preference won't change, and so we + // have to revert the button text back to the disabled state. + if (!Enabled()) { + enable_disable_button_->SetLabel( + l10n_util::GetString(IDS_OPTIONS_CLOUD_PRINT_PROXY_DISABLED_BUTTON)); + } +} + +void CloudPrintProxySection::InitControlLayout() { + AdvancedSection::InitControlLayout(); + + section_description_label_ = new views::Label( + l10n_util::GetString(IDS_OPTIONS_CLOUD_PRINT_PROXY_DISABLED_LABEL)); + enable_disable_button_ = new views::NativeButton(this, + l10n_util::GetString(IDS_OPTIONS_CLOUD_PRINT_PROXY_DISABLED_BUTTON)); + manage_printer_button_ = new views::NativeButton(this, + l10n_util::GetString( + IDS_OPTIONS_CLOUD_PRINT_PROXY_ENABLED_MANAGE_BUTTON)); + + GridLayout* layout = new GridLayout(contents_); + contents_->SetLayoutManager(layout); + + const int single_column_view_set_id = 0; + AddWrappingColumnSet(layout, single_column_view_set_id); + const int control_view_set_id = 1; + AddDependentTwoColumnSet(layout, control_view_set_id); + + // The description label at the top and label. + section_description_label_->SetMultiLine(true); + AddWrappingLabelRow(layout, section_description_label_, + single_column_view_set_id, true); + + // The enable / disable button and manage button. + AddTwoColumnRow(layout, enable_disable_button_, manage_printer_button_, false, + control_view_set_id, kRelatedControlVerticalSpacing); + + // Attach the preferences so we can flip things appropriately. + cloud_print_proxy_email_.Init(prefs::kCloudPrintEmail, + profile()->GetPrefs(), this); + + // Start the UI off in the state we think it should be in. + std::string pref_string(prefs::kCloudPrintEmail); + NotifyPrefChanged(&pref_string); + + // Kick off a task to ask the background service what the real + // answer is. + CloudPrintSetupFlow::RefreshPreferencesFromService( + profile(), + factory_.NewCallback(&CloudPrintProxySection::StatusCallback)); +} + +void CloudPrintProxySection::NotifyPrefChanged(const std::string* pref_name) { + if (pref_name == NULL) + return; + + if (*pref_name == prefs::kCloudPrintEmail) { + if (Enabled()) { + std::string email; + if (profile()->GetPrefs()->HasPrefPath(prefs::kCloudPrintEmail)) + email = profile()->GetPrefs()->GetString(prefs::kCloudPrintEmail); + + section_description_label_->SetText( + l10n_util::GetStringF(IDS_OPTIONS_CLOUD_PRINT_PROXY_ENABLED_LABEL, + UTF8ToWide(email))); + enable_disable_button_->SetLabel( + l10n_util::GetString(IDS_OPTIONS_CLOUD_PRINT_PROXY_ENABLED_BUTTON)); + enable_disable_button_->InvalidateLayout(); + manage_printer_button_->SetVisible(true); + manage_printer_button_->InvalidateLayout(); + } else { + section_description_label_->SetText( + l10n_util::GetString(IDS_OPTIONS_CLOUD_PRINT_PROXY_DISABLED_LABEL)); + enable_disable_button_->SetLabel( + l10n_util::GetString(IDS_OPTIONS_CLOUD_PRINT_PROXY_DISABLED_BUTTON)); + enable_disable_button_->InvalidateLayout(); + manage_printer_button_->SetVisible(false); + } + Layout(); + } +} + +bool CloudPrintProxySection::Enabled() const { + return profile()->GetPrefs()->HasPrefPath(prefs::kCloudPrintEmail) && + !profile()->GetPrefs()->GetString(prefs::kCloudPrintEmail).empty(); +} + +//////////////////////////////////////////////////////////////////////////////// // AdvancedContentsView class AdvancedContentsView : public OptionsPageView { @@ -1363,6 +1639,16 @@ void AdvancedContentsView::InitControlLayout() { layout->AddView(new WebContentSection(profile())); layout->StartRow(0, single_column_view_set_id); layout->AddView(new SecuritySection(profile())); + if (CommandLine::ForCurrentProcess()->HasSwitch( + switches::kEnableCloudPrintProxy)) { + layout->StartRow(0, single_column_view_set_id); + layout->AddView(new CloudPrintProxySection(profile())); + } + if (CommandLine::ForCurrentProcess()->HasSwitch( + switches::kEnableBackgroundMode)) { + layout->StartRow(0, single_column_view_set_id); + layout->AddView(new ChromeAppsSection(profile())); + } } //////////////////////////////////////////////////////////////////////////////// @@ -1372,7 +1658,7 @@ void AdvancedContentsView::InitClass() { static bool initialized = false; if (!initialized) { ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - line_height_ = rb.GetFont(ResourceBundle::BaseFont).height(); + line_height_ = rb.GetFont(ResourceBundle::BaseFont).GetHeight(); initialized = true; } } |