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

Side by Side Diff: chrome/browser/gtk/options/advanced_contents_gtk.cc

Issue 149574: Add cookie behavior combobox. (Closed)
Patch Set: use gtk_combo_box_new_text Created 11 years, 5 months 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/net/dns_global.h"
12 #include "chrome/browser/options_page_base.h" 12 #include "chrome/browser/options_page_base.h"
13 #include "chrome/browser/profile.h" 13 #include "chrome/browser/profile.h"
14 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 14 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
15 #include "chrome/common/gtk_util.h" 15 #include "chrome/common/gtk_util.h"
16 #include "chrome/common/pref_member.h" 16 #include "chrome/common/pref_member.h"
17 #include "chrome/common/pref_names.h" 17 #include "chrome/common/pref_names.h"
18 #include "chrome/installer/util/google_update_settings.h" 18 #include "chrome/installer/util/google_update_settings.h"
19 #include "grit/chromium_strings.h" 19 #include "grit/chromium_strings.h"
20 #include "grit/generated_resources.h" 20 #include "grit/generated_resources.h"
21 #include "net/base/cookie_policy.h"
21 22
22 namespace { 23 namespace {
23 24
24 // The pixel width we wrap labels at. 25 // The pixel width we wrap labels at.
25 // TODO(evanm): make the labels wrap at the appropriate width. 26 // TODO(evanm): make the labels wrap at the appropriate width.
26 const int kWrapWidth = 475; 27 const int kWrapWidth = 475;
27 28
28 GtkWidget* CreateWrappedLabel(int string_id) { 29 GtkWidget* CreateWrappedLabel(int string_id) {
29 GtkWidget* label = gtk_label_new( 30 GtkWidget* label = gtk_label_new(
30 l10n_util::GetStringUTF8(string_id).c_str()); 31 l10n_util::GetStringUTF8(string_id).c_str());
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 static void OnEnableLinkDoctorChange(GtkWidget* widget, 116 static void OnEnableLinkDoctorChange(GtkWidget* widget,
116 PrivacySection* options_window); 117 PrivacySection* options_window);
117 static void OnEnableSuggestChange(GtkWidget* widget, 118 static void OnEnableSuggestChange(GtkWidget* widget,
118 PrivacySection* options_window); 119 PrivacySection* options_window);
119 static void OnDNSPrefetchingChange(GtkWidget* widget, 120 static void OnDNSPrefetchingChange(GtkWidget* widget,
120 PrivacySection* options_window); 121 PrivacySection* options_window);
121 static void OnSafeBrowsingChange(GtkWidget* widget, 122 static void OnSafeBrowsingChange(GtkWidget* widget,
122 PrivacySection* options_window); 123 PrivacySection* options_window);
123 static void OnLoggingChange(GtkWidget* widget, 124 static void OnLoggingChange(GtkWidget* widget,
124 PrivacySection* options_window); 125 PrivacySection* options_window);
126 static void OnCookieBehaviorChanged(GtkComboBox* combo_box,
127 PrivacySection* privacy_section);
125 128
126 // The widget containing the options for this section. 129 // The widget containing the options for this section.
127 GtkWidget* page_; 130 GtkWidget* page_;
128 131
129 // The widgets for the privacy options. 132 // The widgets for the privacy options.
130 GtkWidget* enable_link_doctor_checkbox_; 133 GtkWidget* enable_link_doctor_checkbox_;
131 GtkWidget* enable_suggest_checkbox_; 134 GtkWidget* enable_suggest_checkbox_;
132 GtkWidget* enable_dns_prefetching_checkbox_; 135 GtkWidget* enable_dns_prefetching_checkbox_;
133 GtkWidget* enable_safe_browsing_checkbox_; 136 GtkWidget* enable_safe_browsing_checkbox_;
134 GtkWidget* reporting_enabled_checkbox_; 137 GtkWidget* reporting_enabled_checkbox_;
138 GtkWidget* cookie_behavior_combobox_;
135 139
136 // Preferences for this section: 140 // Preferences for this section:
137 BooleanPrefMember alternate_error_pages_; 141 BooleanPrefMember alternate_error_pages_;
138 BooleanPrefMember use_suggest_; 142 BooleanPrefMember use_suggest_;
139 BooleanPrefMember dns_prefetch_enabled_; 143 BooleanPrefMember dns_prefetch_enabled_;
140 BooleanPrefMember safe_browsing_; 144 BooleanPrefMember safe_browsing_;
141 BooleanPrefMember enable_metrics_recording_; 145 BooleanPrefMember enable_metrics_recording_;
142 IntegerPrefMember cookie_behavior_; 146 IntegerPrefMember cookie_behavior_;
143 147
144 // Flag to ignore gtk callbacks while we are loading prefs, to avoid 148 // Flag to ignore gtk callbacks while we are loading prefs, to avoid
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 g_signal_connect(enable_safe_browsing_checkbox_, "clicked", 193 g_signal_connect(enable_safe_browsing_checkbox_, "clicked",
190 G_CALLBACK(OnSafeBrowsingChange), this); 194 G_CALLBACK(OnSafeBrowsingChange), this);
191 195
192 reporting_enabled_checkbox_ = CreateCheckButtonWithWrappedLabel( 196 reporting_enabled_checkbox_ = CreateCheckButtonWithWrappedLabel(
193 IDS_OPTIONS_ENABLE_LOGGING); 197 IDS_OPTIONS_ENABLE_LOGGING);
194 gtk_box_pack_start(GTK_BOX(page_), reporting_enabled_checkbox_, 198 gtk_box_pack_start(GTK_BOX(page_), reporting_enabled_checkbox_,
195 FALSE, FALSE, 0); 199 FALSE, FALSE, 0);
196 g_signal_connect(reporting_enabled_checkbox_, "clicked", 200 g_signal_connect(reporting_enabled_checkbox_, "clicked",
197 G_CALLBACK(OnLoggingChange), this); 201 G_CALLBACK(OnLoggingChange), this);
198 202
199 // TODO(mattm): cookie combobox and button 203 cookie_behavior_combobox_ = gtk_combo_box_new_text();
204 gtk_combo_box_append_text(
205 GTK_COMBO_BOX(cookie_behavior_combobox_),
206 l10n_util::GetStringUTF8(IDS_OPTIONS_COOKIES_ACCEPT_ALL_COOKIES).c_str());
207 gtk_combo_box_append_text(
208 GTK_COMBO_BOX(cookie_behavior_combobox_),
209 l10n_util::GetStringUTF8(
210 IDS_OPTIONS_COOKIES_RESTRICT_THIRD_PARTY_COOKIES).c_str());
211 gtk_combo_box_append_text(
212 GTK_COMBO_BOX(cookie_behavior_combobox_),
213 l10n_util::GetStringUTF8(IDS_OPTIONS_COOKIES_BLOCK_ALL_COOKIES).c_str());
214 g_signal_connect(G_OBJECT(cookie_behavior_combobox_), "changed",
215 G_CALLBACK(OnCookieBehaviorChanged), this);
216
217 GtkWidget* cookie_controls = gtk_util::CreateLabeledControlsGroup(
218 l10n_util::GetStringUTF8(IDS_OPTIONS_COOKIES_ACCEPT_LABEL).c_str(),
219 cookie_behavior_combobox_,
220 NULL);
221 gtk_box_pack_start(GTK_BOX(page_), cookie_controls, FALSE, FALSE, 0);
222
223 // TODO(mattm): show cookies button
200 gtk_box_pack_start(GTK_BOX(page_), 224 gtk_box_pack_start(GTK_BOX(page_),
201 gtk_label_new("TODO rest of the privacy options"), 225 gtk_label_new("TODO rest of the privacy options"),
202 FALSE, FALSE, 0); 226 FALSE, FALSE, 0);
203 227
204 // Init member prefs so we can update the controls if prefs change. 228 // Init member prefs so we can update the controls if prefs change.
205 alternate_error_pages_.Init(prefs::kAlternateErrorPagesEnabled, 229 alternate_error_pages_.Init(prefs::kAlternateErrorPagesEnabled,
206 profile->GetPrefs(), this); 230 profile->GetPrefs(), this);
207 use_suggest_.Init(prefs::kSearchSuggestEnabled, 231 use_suggest_.Init(prefs::kSearchSuggestEnabled,
208 profile->GetPrefs(), this); 232 profile->GetPrefs(), this);
209 dns_prefetch_enabled_.Init(prefs::kDnsPrefetchingEnabled, 233 dns_prefetch_enabled_.Init(prefs::kDnsPrefetchingEnabled,
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 enabled ? 311 enabled ?
288 L"Options_MetricsReportingCheckbox_Enable" : 312 L"Options_MetricsReportingCheckbox_Enable" :
289 L"Options_MetricsReportingCheckbox_Disable", 313 L"Options_MetricsReportingCheckbox_Disable",
290 privacy_section->profile()->GetPrefs()); 314 privacy_section->profile()->GetPrefs());
291 // TODO(mattm): ResolveMetricsReportingEnabled? 315 // TODO(mattm): ResolveMetricsReportingEnabled?
292 // TODO(mattm): show browser must be restarted message? 316 // TODO(mattm): show browser must be restarted message?
293 privacy_section->enable_metrics_recording_.SetValue(enabled); 317 privacy_section->enable_metrics_recording_.SetValue(enabled);
294 GoogleUpdateSettings::SetCollectStatsConsent(enabled); 318 GoogleUpdateSettings::SetCollectStatsConsent(enabled);
295 } 319 }
296 320
321 // static
322 void PrivacySection::OnCookieBehaviorChanged(GtkComboBox* combo_box,
323 PrivacySection* privacy_section) {
324 if (privacy_section->initializing_)
325 return;
326 net::CookiePolicy::Type cookie_policy =
327 net::CookiePolicy::FromInt(gtk_combo_box_get_active(combo_box));
328 const wchar_t* kUserMetrics[] = {
329 L"Options_AllowAllCookies",
330 L"Options_BlockThirdPartyCookies",
331 L"Options_BlockAllCookies"
332 };
333 if (cookie_policy < 0 ||
334 static_cast<size_t>(cookie_policy) >= arraysize(kUserMetrics)) {
335 NOTREACHED();
336 return;
337 }
338 privacy_section->UserMetricsRecordAction(
339 kUserMetrics[cookie_policy], privacy_section->profile()->GetPrefs());
340 privacy_section->cookie_behavior_.SetValue(cookie_policy);
341 }
342
297 void PrivacySection::NotifyPrefChanged(const std::wstring* pref_name) { 343 void PrivacySection::NotifyPrefChanged(const std::wstring* pref_name) {
298 initializing_ = true; 344 initializing_ = true;
299 if (!pref_name || *pref_name == prefs::kAlternateErrorPagesEnabled) { 345 if (!pref_name || *pref_name == prefs::kAlternateErrorPagesEnabled) {
300 gtk_toggle_button_set_active( 346 gtk_toggle_button_set_active(
301 GTK_TOGGLE_BUTTON(enable_link_doctor_checkbox_), 347 GTK_TOGGLE_BUTTON(enable_link_doctor_checkbox_),
302 alternate_error_pages_.GetValue()); 348 alternate_error_pages_.GetValue());
303 } 349 }
304 if (!pref_name || *pref_name == prefs::kSearchSuggestEnabled) { 350 if (!pref_name || *pref_name == prefs::kSearchSuggestEnabled) {
305 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(enable_suggest_checkbox_), 351 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(enable_suggest_checkbox_),
306 use_suggest_.GetValue()); 352 use_suggest_.GetValue());
307 } 353 }
308 if (!pref_name || *pref_name == prefs::kDnsPrefetchingEnabled) { 354 if (!pref_name || *pref_name == prefs::kDnsPrefetchingEnabled) {
309 bool enabled = dns_prefetch_enabled_.GetValue(); 355 bool enabled = dns_prefetch_enabled_.GetValue();
310 gtk_toggle_button_set_active( 356 gtk_toggle_button_set_active(
311 GTK_TOGGLE_BUTTON(enable_dns_prefetching_checkbox_), enabled); 357 GTK_TOGGLE_BUTTON(enable_dns_prefetching_checkbox_), enabled);
312 chrome_browser_net::EnableDnsPrefetch(enabled); 358 chrome_browser_net::EnableDnsPrefetch(enabled);
313 } 359 }
314 if (!pref_name || *pref_name == prefs::kSafeBrowsingEnabled) { 360 if (!pref_name || *pref_name == prefs::kSafeBrowsingEnabled) {
315 gtk_toggle_button_set_active( 361 gtk_toggle_button_set_active(
316 GTK_TOGGLE_BUTTON(enable_safe_browsing_checkbox_), 362 GTK_TOGGLE_BUTTON(enable_safe_browsing_checkbox_),
317 safe_browsing_.GetValue()); 363 safe_browsing_.GetValue());
318 } 364 }
319 if (!pref_name || *pref_name == prefs::kMetricsReportingEnabled) { 365 if (!pref_name || *pref_name == prefs::kMetricsReportingEnabled) {
320 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(reporting_enabled_checkbox_), 366 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(reporting_enabled_checkbox_),
321 enable_metrics_recording_.GetValue()); 367 enable_metrics_recording_.GetValue());
322 // TODO(mattm): ResolveMetricsReportingEnabled()? 368 // TODO(mattm): ResolveMetricsReportingEnabled()?
323 } 369 }
324 if (!pref_name || *pref_name == prefs::kCookieBehavior) { 370 if (!pref_name || *pref_name == prefs::kCookieBehavior) {
325 // TODO(mattm): set cookie combobox state 371 gtk_combo_box_set_active(
372 GTK_COMBO_BOX(cookie_behavior_combobox_),
373 net::CookiePolicy::FromInt(cookie_behavior_.GetValue()));
326 } 374 }
327 initializing_ = false; 375 initializing_ = false;
328 } 376 }
329 377
330 /////////////////////////////////////////////////////////////////////////////// 378 ///////////////////////////////////////////////////////////////////////////////
331 // SecuritySection 379 // SecuritySection
332 380
333 class SecuritySection : public OptionsPageBase { 381 class SecuritySection : public OptionsPageBase {
334 public: 382 public:
335 explicit SecuritySection(Profile* profile); 383 explicit SecuritySection(Profile* profile);
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 l10n_util::GetStringUTF8(IDS_OPTIONS_ADVANCED_SECTION_TITLE_CONTENT), 461 l10n_util::GetStringUTF8(IDS_OPTIONS_ADVANCED_SECTION_TITLE_CONTENT),
414 web_content_section_->get_page_widget(), false); 462 web_content_section_->get_page_widget(), false);
415 463
416 security_section_.reset(new SecuritySection(profile_)); 464 security_section_.reset(new SecuritySection(profile_));
417 options_builder.AddOptionGroup( 465 options_builder.AddOptionGroup(
418 l10n_util::GetStringUTF8(IDS_OPTIONS_ADVANCED_SECTION_TITLE_SECURITY), 466 l10n_util::GetStringUTF8(IDS_OPTIONS_ADVANCED_SECTION_TITLE_SECURITY),
419 security_section_->get_page_widget(), false); 467 security_section_->get_page_widget(), false);
420 468
421 page_ = options_builder.get_page_widget(); 469 page_ = options_builder.get_page_widget();
422 } 470 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698