| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/gtk/options/advanced_contents_gtk.h" | 5 #include "chrome/browser/gtk/options/advanced_contents_gtk.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/gtk/options/options_layout_gtk.h" | 10 #include "chrome/browser/gtk/options/options_layout_gtk.h" |
| 11 #include "chrome/browser/net/dns_global.h" |
| 11 #include "chrome/browser/options_page_base.h" | 12 #include "chrome/browser/options_page_base.h" |
| 12 #include "chrome/browser/profile.h" | 13 #include "chrome/browser/profile.h" |
| 14 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 13 #include "chrome/common/gtk_util.h" | 15 #include "chrome/common/gtk_util.h" |
| 16 #include "chrome/common/pref_member.h" |
| 14 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
| 15 #include "chrome/installer/util/google_update_settings.h" | 18 #include "chrome/installer/util/google_update_settings.h" |
| 16 #include "grit/chromium_strings.h" | 19 #include "grit/chromium_strings.h" |
| 17 #include "grit/generated_resources.h" | 20 #include "grit/generated_resources.h" |
| 18 | 21 |
| 22 namespace { |
| 23 |
| 24 // The pixel width we wrap labels at. |
| 25 // TODO(evanm): make the labels wrap at the appropriate width. |
| 26 const int kWrapWidth = 475; |
| 27 |
| 28 GtkWidget* CreateWrappedLabel(int string_id) { |
| 29 GtkWidget* label = gtk_label_new( |
| 30 l10n_util::GetStringUTF8(string_id).c_str()); |
| 31 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); |
| 32 gtk_widget_set_size_request(label, kWrapWidth, -1); |
| 33 return label; |
| 34 } |
| 35 |
| 36 GtkWidget* CreateCheckButtonWithWrappedLabel(int string_id) { |
| 37 GtkWidget* checkbox = gtk_check_button_new(); |
| 38 gtk_container_add(GTK_CONTAINER(checkbox), |
| 39 CreateWrappedLabel(string_id)); |
| 40 return checkbox; |
| 41 } |
| 42 |
| 43 } // anonymous namespace |
| 44 |
| 19 | 45 |
| 20 /////////////////////////////////////////////////////////////////////////////// | 46 /////////////////////////////////////////////////////////////////////////////// |
| 21 // DownloadSection | 47 // DownloadSection |
| 22 | 48 |
| 23 class DownloadSection : public OptionsPageBase { | 49 class DownloadSection : public OptionsPageBase { |
| 24 public: | 50 public: |
| 25 explicit DownloadSection(Profile* profile); | 51 explicit DownloadSection(Profile* profile); |
| 26 virtual ~DownloadSection() {} | 52 virtual ~DownloadSection() {} |
| 27 | 53 |
| 28 GtkWidget* get_page_widget() const { | 54 GtkWidget* get_page_widget() const { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 class PrivacySection : public OptionsPageBase { | 101 class PrivacySection : public OptionsPageBase { |
| 76 public: | 102 public: |
| 77 explicit PrivacySection(Profile* profile); | 103 explicit PrivacySection(Profile* profile); |
| 78 virtual ~PrivacySection() {} | 104 virtual ~PrivacySection() {} |
| 79 | 105 |
| 80 GtkWidget* get_page_widget() const { | 106 GtkWidget* get_page_widget() const { |
| 81 return page_; | 107 return page_; |
| 82 } | 108 } |
| 83 | 109 |
| 84 private: | 110 private: |
| 85 // This is the callback function for Stats reporting checkbox. | 111 // Overridden from OptionsPageBase. |
| 112 virtual void NotifyPrefChanged(const std::wstring* pref_name); |
| 113 |
| 114 // The callback functions for the options widgets. |
| 115 static void OnEnableLinkDoctorChange(GtkWidget* widget, |
| 116 PrivacySection* options_window); |
| 117 static void OnEnableSuggestChange(GtkWidget* widget, |
| 118 PrivacySection* options_window); |
| 119 static void OnDNSPrefetchingChange(GtkWidget* widget, |
| 120 PrivacySection* options_window); |
| 121 static void OnSafeBrowsingChange(GtkWidget* widget, |
| 122 PrivacySection* options_window); |
| 86 static void OnLoggingChange(GtkWidget* widget, | 123 static void OnLoggingChange(GtkWidget* widget, |
| 87 PrivacySection* options_window); | 124 PrivacySection* options_window); |
| 88 | 125 |
| 89 // This function gets called when stats reporting option is changed. | |
| 90 void LoggingChanged(GtkWidget* widget); | |
| 91 | |
| 92 // The widget containing the options for this section. | 126 // The widget containing the options for this section. |
| 93 GtkWidget* page_; | 127 GtkWidget* page_; |
| 94 | 128 |
| 129 // The widgets for the privacy options. |
| 130 GtkWidget* enable_link_doctor_checkbox_; |
| 131 GtkWidget* enable_suggest_checkbox_; |
| 132 GtkWidget* enable_dns_prefetching_checkbox_; |
| 133 GtkWidget* enable_safe_browsing_checkbox_; |
| 134 GtkWidget* reporting_enabled_checkbox_; |
| 135 |
| 136 // Preferences for this section: |
| 137 BooleanPrefMember alternate_error_pages_; |
| 138 BooleanPrefMember use_suggest_; |
| 139 BooleanPrefMember dns_prefetch_enabled_; |
| 140 BooleanPrefMember safe_browsing_; |
| 141 BooleanPrefMember enable_metrics_recording_; |
| 142 IntegerPrefMember cookie_behavior_; |
| 143 |
| 144 // Flag to ignore gtk callbacks while we are loading prefs, to avoid |
| 145 // then turning around and saving them again. |
| 146 bool initializing_; |
| 147 |
| 95 DISALLOW_COPY_AND_ASSIGN(PrivacySection); | 148 DISALLOW_COPY_AND_ASSIGN(PrivacySection); |
| 96 }; | 149 }; |
| 97 | 150 |
| 98 PrivacySection::PrivacySection(Profile* profile) : OptionsPageBase(profile) { | 151 PrivacySection::PrivacySection(Profile* profile) |
| 152 : OptionsPageBase(profile), |
| 153 initializing_(true) { |
| 99 page_ = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); | 154 page_ = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); |
| 100 | 155 |
| 101 GtkWidget* metrics = gtk_check_button_new(); | 156 GtkWidget* section_description_label = CreateWrappedLabel( |
| 102 GtkWidget* metrics_label = gtk_label_new( | 157 IDS_OPTIONS_DISABLE_SERVICES); |
| 103 l10n_util::GetStringUTF8(IDS_OPTIONS_ENABLE_LOGGING).c_str()); | 158 gtk_misc_set_alignment(GTK_MISC(section_description_label), 0, 0); |
| 104 gtk_label_set_line_wrap(GTK_LABEL(metrics_label), TRUE); | 159 gtk_box_pack_start(GTK_BOX(page_), section_description_label, |
| 105 // TODO(evanm): make the label wrap at the appropriate width. | 160 FALSE, FALSE, 0); |
| 106 gtk_widget_set_size_request(metrics_label, 475, -1); | 161 |
| 107 gtk_container_add(GTK_CONTAINER(metrics), metrics_label); | 162 // TODO(mattm): Learn more link |
| 108 gtk_box_pack_start(GTK_BOX(page_), metrics, FALSE, FALSE, 0); | 163 |
| 164 enable_link_doctor_checkbox_ = CreateCheckButtonWithWrappedLabel( |
| 165 IDS_OPTIONS_LINKDOCTOR_PREF); |
| 166 gtk_box_pack_start(GTK_BOX(page_), enable_link_doctor_checkbox_, |
| 167 FALSE, FALSE, 0); |
| 168 g_signal_connect(enable_link_doctor_checkbox_, "clicked", |
| 169 G_CALLBACK(OnEnableLinkDoctorChange), this); |
| 170 |
| 171 enable_suggest_checkbox_ = CreateCheckButtonWithWrappedLabel( |
| 172 IDS_OPTIONS_SUGGEST_PREF); |
| 173 gtk_box_pack_start(GTK_BOX(page_), enable_suggest_checkbox_, |
| 174 FALSE, FALSE, 0); |
| 175 g_signal_connect(enable_suggest_checkbox_, "clicked", |
| 176 G_CALLBACK(OnEnableSuggestChange), this); |
| 177 |
| 178 enable_dns_prefetching_checkbox_ = CreateCheckButtonWithWrappedLabel( |
| 179 IDS_NETWORK_DNS_PREFETCH_ENABLED_DESCRIPTION); |
| 180 gtk_box_pack_start(GTK_BOX(page_), enable_dns_prefetching_checkbox_, |
| 181 FALSE, FALSE, 0); |
| 182 g_signal_connect(enable_dns_prefetching_checkbox_, "clicked", |
| 183 G_CALLBACK(OnDNSPrefetchingChange), this); |
| 184 |
| 185 enable_safe_browsing_checkbox_ = CreateCheckButtonWithWrappedLabel( |
| 186 IDS_OPTIONS_SAFEBROWSING_ENABLEPROTECTION); |
| 187 gtk_box_pack_start(GTK_BOX(page_), enable_safe_browsing_checkbox_, |
| 188 FALSE, FALSE, 0); |
| 189 g_signal_connect(enable_safe_browsing_checkbox_, "clicked", |
| 190 G_CALLBACK(OnSafeBrowsingChange), this); |
| 191 |
| 192 reporting_enabled_checkbox_ = CreateCheckButtonWithWrappedLabel( |
| 193 IDS_OPTIONS_ENABLE_LOGGING); |
| 194 gtk_box_pack_start(GTK_BOX(page_), reporting_enabled_checkbox_, |
| 195 FALSE, FALSE, 0); |
| 196 g_signal_connect(reporting_enabled_checkbox_, "clicked", |
| 197 G_CALLBACK(OnLoggingChange), this); |
| 198 |
| 199 // TODO(mattm): cookie combobox and button |
| 109 gtk_box_pack_start(GTK_BOX(page_), | 200 gtk_box_pack_start(GTK_BOX(page_), |
| 110 gtk_label_new("TODO rest of the privacy options"), | 201 gtk_label_new("TODO rest of the privacy options"), |
| 111 FALSE, FALSE, 0); | 202 FALSE, FALSE, 0); |
| 112 bool logging = g_browser_process->local_state()->GetBoolean( | 203 |
| 113 prefs::kMetricsReportingEnabled); | 204 // Init member prefs so we can update the controls if prefs change. |
| 114 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(metrics), logging); | 205 alternate_error_pages_.Init(prefs::kAlternateErrorPagesEnabled, |
| 115 g_signal_connect(metrics, "clicked", G_CALLBACK(OnLoggingChange), this); | 206 profile->GetPrefs(), this); |
| 207 use_suggest_.Init(prefs::kSearchSuggestEnabled, |
| 208 profile->GetPrefs(), this); |
| 209 dns_prefetch_enabled_.Init(prefs::kDnsPrefetchingEnabled, |
| 210 profile->GetPrefs(), this); |
| 211 safe_browsing_.Init(prefs::kSafeBrowsingEnabled, profile->GetPrefs(), this); |
| 212 enable_metrics_recording_.Init(prefs::kMetricsReportingEnabled, |
| 213 g_browser_process->local_state(), this); |
| 214 cookie_behavior_.Init(prefs::kCookieBehavior, profile->GetPrefs(), this); |
| 215 |
| 216 NotifyPrefChanged(NULL); |
| 217 } |
| 218 |
| 219 // static |
| 220 void PrivacySection::OnEnableLinkDoctorChange(GtkWidget* widget, |
| 221 PrivacySection* privacy_section) { |
| 222 if (privacy_section->initializing_) |
| 223 return; |
| 224 bool enabled = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); |
| 225 privacy_section->UserMetricsRecordAction( |
| 226 enabled ? |
| 227 L"Options_LinkDoctorCheckbox_Enable" : |
| 228 L"Options_LinkDoctorCheckbox_Disable", |
| 229 privacy_section->profile()->GetPrefs()); |
| 230 privacy_section->alternate_error_pages_.SetValue(enabled); |
| 231 } |
| 232 |
| 233 // static |
| 234 void PrivacySection::OnEnableSuggestChange(GtkWidget* widget, |
| 235 PrivacySection* privacy_section) { |
| 236 if (privacy_section->initializing_) |
| 237 return; |
| 238 bool enabled = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); |
| 239 privacy_section->UserMetricsRecordAction( |
| 240 enabled ? |
| 241 L"Options_UseSuggestCheckbox_Enable" : |
| 242 L"Options_UseSuggestCheckbox_Disable", |
| 243 privacy_section->profile()->GetPrefs()); |
| 244 privacy_section->use_suggest_.SetValue(enabled); |
| 245 } |
| 246 |
| 247 // static |
| 248 void PrivacySection::OnDNSPrefetchingChange(GtkWidget* widget, |
| 249 PrivacySection* privacy_section) { |
| 250 if (privacy_section->initializing_) |
| 251 return; |
| 252 bool enabled = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); |
| 253 privacy_section->UserMetricsRecordAction( |
| 254 enabled ? |
| 255 L"Options_DnsPrefetchCheckbox_Enable" : |
| 256 L"Options_DnsPrefetchCheckbox_Disable", |
| 257 privacy_section->profile()->GetPrefs()); |
| 258 privacy_section->dns_prefetch_enabled_.SetValue(enabled); |
| 259 chrome_browser_net::EnableDnsPrefetch(enabled); |
| 260 } |
| 261 |
| 262 // static |
| 263 void PrivacySection::OnSafeBrowsingChange(GtkWidget* widget, |
| 264 PrivacySection* privacy_section) { |
| 265 if (privacy_section->initializing_) |
| 266 return; |
| 267 bool enabled = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); |
| 268 privacy_section->UserMetricsRecordAction( |
| 269 enabled ? |
| 270 L"Options_SafeBrowsingCheckbox_Enable" : |
| 271 L"Options_SafeBrowsingCheckbox_Disable", |
| 272 privacy_section->profile()->GetPrefs()); |
| 273 privacy_section->safe_browsing_.SetValue(enabled); |
| 274 SafeBrowsingService* safe_browsing_service = |
| 275 g_browser_process->resource_dispatcher_host()->safe_browsing_service(); |
| 276 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( |
| 277 safe_browsing_service, &SafeBrowsingService::OnEnable, enabled)); |
| 116 } | 278 } |
| 117 | 279 |
| 118 // static | 280 // static |
| 119 void PrivacySection::OnLoggingChange(GtkWidget* widget, | 281 void PrivacySection::OnLoggingChange(GtkWidget* widget, |
| 120 PrivacySection* privacy_section) { | 282 PrivacySection* privacy_section) { |
| 121 privacy_section->LoggingChanged(widget); | 283 if (privacy_section->initializing_) |
| 122 } | 284 return; |
| 123 | 285 bool enabled = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); |
| 124 void PrivacySection::LoggingChanged(GtkWidget* metrics) { | 286 privacy_section->UserMetricsRecordAction( |
| 125 bool logging = (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(metrics)) == | 287 enabled ? |
| 126 TRUE); | 288 L"Options_MetricsReportingCheckbox_Enable" : |
| 127 g_browser_process->local_state()->SetBoolean(prefs::kMetricsReportingEnabled, | 289 L"Options_MetricsReportingCheckbox_Disable", |
| 128 logging); | 290 privacy_section->profile()->GetPrefs()); |
| 129 GoogleUpdateSettings::SetCollectStatsConsent(logging); | 291 // TODO(mattm): ResolveMetricsReportingEnabled? |
| 292 // TODO(mattm): show browser must be restarted message? |
| 293 privacy_section->enable_metrics_recording_.SetValue(enabled); |
| 294 GoogleUpdateSettings::SetCollectStatsConsent(enabled); |
| 295 } |
| 296 |
| 297 void PrivacySection::NotifyPrefChanged(const std::wstring* pref_name) { |
| 298 initializing_ = true; |
| 299 if (!pref_name || *pref_name == prefs::kAlternateErrorPagesEnabled) { |
| 300 gtk_toggle_button_set_active( |
| 301 GTK_TOGGLE_BUTTON(enable_link_doctor_checkbox_), |
| 302 alternate_error_pages_.GetValue()); |
| 303 } |
| 304 if (!pref_name || *pref_name == prefs::kSearchSuggestEnabled) { |
| 305 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(enable_suggest_checkbox_), |
| 306 use_suggest_.GetValue()); |
| 307 } |
| 308 if (!pref_name || *pref_name == prefs::kDnsPrefetchingEnabled) { |
| 309 bool enabled = dns_prefetch_enabled_.GetValue(); |
| 310 gtk_toggle_button_set_active( |
| 311 GTK_TOGGLE_BUTTON(enable_dns_prefetching_checkbox_), enabled); |
| 312 chrome_browser_net::EnableDnsPrefetch(enabled); |
| 313 } |
| 314 if (!pref_name || *pref_name == prefs::kSafeBrowsingEnabled) { |
| 315 gtk_toggle_button_set_active( |
| 316 GTK_TOGGLE_BUTTON(enable_safe_browsing_checkbox_), |
| 317 safe_browsing_.GetValue()); |
| 318 } |
| 319 if (!pref_name || *pref_name == prefs::kMetricsReportingEnabled) { |
| 320 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(reporting_enabled_checkbox_), |
| 321 enable_metrics_recording_.GetValue()); |
| 322 // TODO(mattm): ResolveMetricsReportingEnabled()? |
| 323 } |
| 324 if (!pref_name || *pref_name == prefs::kCookieBehavior) { |
| 325 // TODO(mattm): set cookie combobox state |
| 326 } |
| 327 initializing_ = false; |
| 130 } | 328 } |
| 131 | 329 |
| 132 /////////////////////////////////////////////////////////////////////////////// | 330 /////////////////////////////////////////////////////////////////////////////// |
| 133 // SecuritySection | 331 // SecuritySection |
| 134 | 332 |
| 135 class SecuritySection : public OptionsPageBase { | 333 class SecuritySection : public OptionsPageBase { |
| 136 public: | 334 public: |
| 137 explicit SecuritySection(Profile* profile); | 335 explicit SecuritySection(Profile* profile); |
| 138 virtual ~SecuritySection() {} | 336 virtual ~SecuritySection() {} |
| 139 | 337 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 l10n_util::GetStringUTF8(IDS_OPTIONS_ADVANCED_SECTION_TITLE_CONTENT), | 413 l10n_util::GetStringUTF8(IDS_OPTIONS_ADVANCED_SECTION_TITLE_CONTENT), |
| 216 web_content_section_->get_page_widget(), false); | 414 web_content_section_->get_page_widget(), false); |
| 217 | 415 |
| 218 security_section_.reset(new SecuritySection(profile_)); | 416 security_section_.reset(new SecuritySection(profile_)); |
| 219 options_builder.AddOptionGroup( | 417 options_builder.AddOptionGroup( |
| 220 l10n_util::GetStringUTF8(IDS_OPTIONS_ADVANCED_SECTION_TITLE_SECURITY), | 418 l10n_util::GetStringUTF8(IDS_OPTIONS_ADVANCED_SECTION_TITLE_SECURITY), |
| 221 security_section_->get_page_widget(), false); | 419 security_section_->get_page_widget(), false); |
| 222 | 420 |
| 223 page_ = options_builder.get_page_widget(); | 421 page_ = options_builder.get_page_widget(); |
| 224 } | 422 } |
| OLD | NEW |