OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/content_exception_editor.h" | 5 #include "chrome/browser/gtk/options/content_exception_editor.h" |
6 | 6 |
7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
11 #include "chrome/browser/content_exceptions_table_model.h" | 11 #include "chrome/browser/content_exceptions_table_model.h" |
12 #include "chrome/browser/gtk/gtk_util.h" | 12 #include "chrome/browser/gtk/gtk_util.h" |
13 #include "chrome/browser/host_content_settings_map.h" | 13 #include "chrome/browser/host_content_settings_map.h" |
14 #include "grit/app_resources.h" | 14 #include "grit/app_resources.h" |
15 #include "grit/generated_resources.h" | 15 #include "grit/generated_resources.h" |
16 | 16 |
17 ContentExceptionEditor::ContentExceptionEditor( | 17 ContentExceptionEditor::ContentExceptionEditor( |
18 GtkWindow* parent, | 18 GtkWindow* parent, |
19 ContentExceptionEditor::Delegate* delegate, | 19 ContentExceptionEditor::Delegate* delegate, |
20 ContentExceptionsTableModel* model, | 20 ContentExceptionsTableModel* model, |
| 21 bool allow_off_the_record, |
21 int index, | 22 int index, |
22 const HostContentSettingsMap::Pattern& pattern, | 23 const HostContentSettingsMap::Pattern& pattern, |
23 ContentSetting setting) | 24 ContentSetting setting, |
| 25 bool is_off_the_record) |
24 : delegate_(delegate), | 26 : delegate_(delegate), |
25 model_(model), | 27 model_(model), |
26 cb_model_(model->content_type() == CONTENT_SETTINGS_TYPE_COOKIES), | 28 cb_model_(model->content_type() == CONTENT_SETTINGS_TYPE_COOKIES), |
27 index_(index), | 29 index_(index), |
28 pattern_(pattern), | 30 pattern_(pattern), |
29 setting_(setting) { | 31 setting_(setting) { |
30 dialog_ = gtk_dialog_new_with_buttons( | 32 dialog_ = gtk_dialog_new_with_buttons( |
31 l10n_util::GetStringUTF8(is_new() ? | 33 l10n_util::GetStringUTF8(is_new() ? |
32 IDS_EXCEPTION_EDITOR_NEW_TITLE : | 34 IDS_EXCEPTION_EDITOR_NEW_TITLE : |
33 IDS_EXCEPTION_EDITOR_TITLE).c_str(), | 35 IDS_EXCEPTION_EDITOR_TITLE).c_str(), |
(...skipping 15 matching lines...) Expand all Loading... |
49 pattern_image_ = gtk_image_new_from_pixbuf(NULL); | 51 pattern_image_ = gtk_image_new_from_pixbuf(NULL); |
50 | 52 |
51 action_combo_ = gtk_combo_box_new_text(); | 53 action_combo_ = gtk_combo_box_new_text(); |
52 for (int i = 0; i < cb_model_.GetItemCount(); ++i) { | 54 for (int i = 0; i < cb_model_.GetItemCount(); ++i) { |
53 gtk_combo_box_append_text(GTK_COMBO_BOX(action_combo_), | 55 gtk_combo_box_append_text(GTK_COMBO_BOX(action_combo_), |
54 WideToUTF8(cb_model_.GetItemAt(i)).c_str()); | 56 WideToUTF8(cb_model_.GetItemAt(i)).c_str()); |
55 } | 57 } |
56 gtk_combo_box_set_active(GTK_COMBO_BOX(action_combo_), | 58 gtk_combo_box_set_active(GTK_COMBO_BOX(action_combo_), |
57 cb_model_.IndexForSetting(setting_)); | 59 cb_model_.IndexForSetting(setting_)); |
58 | 60 |
| 61 otr_checkbox_ = gtk_check_button_new_with_label( |
| 62 l10n_util::GetStringUTF8(IDS_EXCEPTION_EDITOR_OTR_TITLE).c_str()); |
| 63 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(otr_checkbox_), |
| 64 is_off_the_record); |
| 65 |
59 GtkWidget* table = gtk_util::CreateLabeledControlsGroup( | 66 GtkWidget* table = gtk_util::CreateLabeledControlsGroup( |
60 NULL, | 67 NULL, |
61 l10n_util::GetStringUTF8(IDS_EXCEPTION_EDITOR_PATTERN_TITLE).c_str(), | 68 l10n_util::GetStringUTF8(IDS_EXCEPTION_EDITOR_PATTERN_TITLE).c_str(), |
62 gtk_util::CreateEntryImageHBox(entry_, pattern_image_), | 69 gtk_util::CreateEntryImageHBox(entry_, pattern_image_), |
63 l10n_util::GetStringUTF8(IDS_EXCEPTION_EDITOR_ACTION_TITLE).c_str(), | 70 l10n_util::GetStringUTF8(IDS_EXCEPTION_EDITOR_ACTION_TITLE).c_str(), |
64 action_combo_, | 71 action_combo_, |
65 NULL); | 72 NULL); |
| 73 if (allow_off_the_record) { |
| 74 gtk_table_attach(GTK_TABLE(table), otr_checkbox_, |
| 75 0, 2, 2, 3, GTK_FILL, GTK_FILL, 0, 0); |
| 76 } |
66 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog_)->vbox), table, | 77 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog_)->vbox), table, |
67 FALSE, FALSE, 0); | 78 FALSE, FALSE, 0); |
68 | 79 |
69 gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(dialog_)->vbox), | 80 gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(dialog_)->vbox), |
70 gtk_util::kContentAreaSpacing); | 81 gtk_util::kContentAreaSpacing); |
71 | 82 |
72 // Prime the state of the buttons. | 83 // Prime the state of the buttons. |
73 OnEntryChanged(entry_); | 84 OnEntryChanged(entry_); |
74 | 85 |
75 gtk_util::ShowDialog(dialog_); | 86 gtk_util::ShowDialog(dialog_); |
76 | 87 |
77 g_signal_connect(dialog_, "response", G_CALLBACK(OnResponseThunk), this); | 88 g_signal_connect(dialog_, "response", G_CALLBACK(OnResponseThunk), this); |
78 g_signal_connect(dialog_, "destroy", G_CALLBACK(OnWindowDestroyThunk), this); | 89 g_signal_connect(dialog_, "destroy", G_CALLBACK(OnWindowDestroyThunk), this); |
79 } | 90 } |
80 | 91 |
81 bool ContentExceptionEditor::IsPatternValid( | 92 bool ContentExceptionEditor::IsPatternValid( |
82 const HostContentSettingsMap::Pattern& pattern) const { | 93 const HostContentSettingsMap::Pattern& pattern, |
| 94 bool is_off_the_record) const { |
83 bool is_valid_pattern = pattern.IsValid() && | 95 bool is_valid_pattern = pattern.IsValid() && |
84 (model_->IndexOfExceptionByPattern(pattern) == -1); | 96 (model_->IndexOfExceptionByPattern(pattern, is_off_the_record) == -1); |
85 | 97 |
86 return is_new() ? is_valid_pattern : (!pattern.AsString().empty() && | 98 return is_new() ? is_valid_pattern : (!pattern.AsString().empty() && |
87 ((pattern_ == pattern) || is_valid_pattern)); | 99 ((pattern_ == pattern) || is_valid_pattern)); |
88 } | 100 } |
89 | 101 |
90 void ContentExceptionEditor::UpdateImage(GtkWidget* image, bool is_valid) { | 102 void ContentExceptionEditor::UpdateImage(GtkWidget* image, bool is_valid) { |
91 return gtk_image_set_from_pixbuf(GTK_IMAGE(image), | 103 return gtk_image_set_from_pixbuf(GTK_IMAGE(image), |
92 ResourceBundle::GetSharedInstance().GetPixbufNamed( | 104 ResourceBundle::GetSharedInstance().GetPixbufNamed( |
93 is_valid ? IDR_INPUT_GOOD : IDR_INPUT_ALERT)); | 105 is_valid ? IDR_INPUT_GOOD : IDR_INPUT_ALERT)); |
94 } | 106 } |
95 | 107 |
96 void ContentExceptionEditor::OnEntryChanged(GtkWidget* entry) { | 108 void ContentExceptionEditor::OnEntryChanged(GtkWidget* entry) { |
97 HostContentSettingsMap::Pattern new_pattern( | 109 HostContentSettingsMap::Pattern new_pattern( |
98 gtk_entry_get_text(GTK_ENTRY(entry))); | 110 gtk_entry_get_text(GTK_ENTRY(entry))); |
99 bool is_valid = IsPatternValid(new_pattern); | 111 bool is_off_the_record = |
| 112 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(otr_checkbox_)); |
| 113 bool is_valid = IsPatternValid(new_pattern, is_off_the_record); |
100 gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog_), | 114 gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog_), |
101 GTK_RESPONSE_OK, is_valid); | 115 GTK_RESPONSE_OK, is_valid); |
102 UpdateImage(pattern_image_, is_valid); | 116 UpdateImage(pattern_image_, is_valid); |
103 } | 117 } |
104 | 118 |
105 void ContentExceptionEditor::OnResponse(GtkWidget* sender, int response_id) { | 119 void ContentExceptionEditor::OnResponse(GtkWidget* sender, int response_id) { |
106 if (response_id == GTK_RESPONSE_OK) { | 120 if (response_id == GTK_RESPONSE_OK) { |
107 // Notify our delegate to update everything. | 121 // Notify our delegate to update everything. |
108 HostContentSettingsMap::Pattern new_pattern( | 122 HostContentSettingsMap::Pattern new_pattern( |
109 gtk_entry_get_text(GTK_ENTRY(entry_))); | 123 gtk_entry_get_text(GTK_ENTRY(entry_))); |
110 ContentSetting setting = cb_model_.SettingForIndex( | 124 ContentSetting setting = cb_model_.SettingForIndex( |
111 gtk_combo_box_get_active(GTK_COMBO_BOX(action_combo_))); | 125 gtk_combo_box_get_active(GTK_COMBO_BOX(action_combo_))); |
112 delegate_->AcceptExceptionEdit(new_pattern, setting, index_, is_new()); | 126 bool is_off_the_record = |
| 127 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(otr_checkbox_)); |
| 128 delegate_->AcceptExceptionEdit( |
| 129 new_pattern, setting, is_off_the_record, index_, is_new()); |
113 } | 130 } |
114 | 131 |
115 gtk_widget_destroy(dialog_); | 132 gtk_widget_destroy(dialog_); |
116 } | 133 } |
117 | 134 |
118 void ContentExceptionEditor::OnWindowDestroy(GtkWidget* widget) { | 135 void ContentExceptionEditor::OnWindowDestroy(GtkWidget* widget) { |
119 MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 136 MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
120 } | 137 } |
OLD | NEW |