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

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

Issue 5574001: Move ContentSettingsDetails and Pattern out of HostContentSettingsMap as separate classes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/chrome/browser/content_settings
Patch Set: updates Created 10 years 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 | Annotate | Revision Log
OLDNEW
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/content_settings/host_content_settings_map.h" 12 #include "chrome/browser/content_settings/host_content_settings_map.h"
13 #include "chrome/browser/gtk/gtk_util.h" 13 #include "chrome/browser/gtk/gtk_util.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 #include "grit/theme_resources.h" 16 #include "grit/theme_resources.h"
17 17
18 ContentExceptionEditor::ContentExceptionEditor( 18 ContentExceptionEditor::ContentExceptionEditor(
19 GtkWindow* parent, 19 GtkWindow* parent,
20 ContentExceptionEditor::Delegate* delegate, 20 ContentExceptionEditor::Delegate* delegate,
21 ContentExceptionsTableModel* model, 21 ContentExceptionsTableModel* model,
22 bool allow_off_the_record, 22 bool allow_off_the_record,
23 int index, 23 int index,
24 const HostContentSettingsMap::Pattern& pattern, 24 const ContentSettingsPattern& pattern,
25 ContentSetting setting, 25 ContentSetting setting,
26 bool is_off_the_record) 26 bool is_off_the_record)
27 : delegate_(delegate), 27 : delegate_(delegate),
28 model_(model), 28 model_(model),
29 cb_model_(model->content_type()), 29 cb_model_(model->content_type()),
30 index_(index), 30 index_(index),
31 pattern_(pattern), 31 pattern_(pattern),
32 setting_(setting) { 32 setting_(setting) {
33 dialog_ = gtk_dialog_new_with_buttons( 33 dialog_ = gtk_dialog_new_with_buttons(
34 l10n_util::GetStringUTF8(is_new() ? 34 l10n_util::GetStringUTF8(is_new() ?
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 // Prime the state of the buttons. 84 // Prime the state of the buttons.
85 OnEntryChanged(entry_); 85 OnEntryChanged(entry_);
86 86
87 gtk_util::ShowDialog(dialog_); 87 gtk_util::ShowDialog(dialog_);
88 88
89 g_signal_connect(dialog_, "response", G_CALLBACK(OnResponseThunk), this); 89 g_signal_connect(dialog_, "response", G_CALLBACK(OnResponseThunk), this);
90 g_signal_connect(dialog_, "destroy", G_CALLBACK(OnWindowDestroyThunk), this); 90 g_signal_connect(dialog_, "destroy", G_CALLBACK(OnWindowDestroyThunk), this);
91 } 91 }
92 92
93 bool ContentExceptionEditor::IsPatternValid( 93 bool ContentExceptionEditor::IsPatternValid(
94 const HostContentSettingsMap::Pattern& pattern, 94 const ContentSettingsPattern& pattern,
95 bool is_off_the_record) const { 95 bool is_off_the_record) const {
96 bool is_valid_pattern = pattern.IsValid() && 96 bool is_valid_pattern = pattern.IsValid() &&
97 (model_->IndexOfExceptionByPattern(pattern, is_off_the_record) == -1); 97 (model_->IndexOfExceptionByPattern(pattern, is_off_the_record) == -1);
98 98
99 return is_new() ? is_valid_pattern : (!pattern.AsString().empty() && 99 return is_new() ? is_valid_pattern : (!pattern.AsString().empty() &&
100 ((pattern_ == pattern) || is_valid_pattern)); 100 ((pattern_ == pattern) || is_valid_pattern));
101 } 101 }
102 102
103 void ContentExceptionEditor::UpdateImage(GtkWidget* image, bool is_valid) { 103 void ContentExceptionEditor::UpdateImage(GtkWidget* image, bool is_valid) {
104 return gtk_image_set_from_pixbuf(GTK_IMAGE(image), 104 return gtk_image_set_from_pixbuf(GTK_IMAGE(image),
105 ResourceBundle::GetSharedInstance().GetPixbufNamed( 105 ResourceBundle::GetSharedInstance().GetPixbufNamed(
106 is_valid ? IDR_INPUT_GOOD : IDR_INPUT_ALERT)); 106 is_valid ? IDR_INPUT_GOOD : IDR_INPUT_ALERT));
107 } 107 }
108 108
109 void ContentExceptionEditor::OnEntryChanged(GtkWidget* entry) { 109 void ContentExceptionEditor::OnEntryChanged(GtkWidget* entry) {
110 HostContentSettingsMap::Pattern new_pattern( 110 ContentSettingsPattern new_pattern(gtk_entry_get_text(GTK_ENTRY(entry)));
111 gtk_entry_get_text(GTK_ENTRY(entry)));
112 bool is_off_the_record = 111 bool is_off_the_record =
113 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(otr_checkbox_)); 112 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(otr_checkbox_));
114 bool is_valid = IsPatternValid(new_pattern, is_off_the_record); 113 bool is_valid = IsPatternValid(new_pattern, is_off_the_record);
115 gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog_), 114 gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog_),
116 GTK_RESPONSE_OK, is_valid); 115 GTK_RESPONSE_OK, is_valid);
117 UpdateImage(pattern_image_, is_valid); 116 UpdateImage(pattern_image_, is_valid);
118 } 117 }
119 118
120 void ContentExceptionEditor::OnResponse(GtkWidget* sender, int response_id) { 119 void ContentExceptionEditor::OnResponse(GtkWidget* sender, int response_id) {
121 if (response_id == GTK_RESPONSE_OK) { 120 if (response_id == GTK_RESPONSE_OK) {
122 // Notify our delegate to update everything. 121 // Notify our delegate to update everything.
123 HostContentSettingsMap::Pattern new_pattern( 122 ContentSettingsPattern new_pattern(gtk_entry_get_text(GTK_ENTRY(entry_)));
124 gtk_entry_get_text(GTK_ENTRY(entry_)));
125 ContentSetting setting = cb_model_.SettingForIndex( 123 ContentSetting setting = cb_model_.SettingForIndex(
126 gtk_combo_box_get_active(GTK_COMBO_BOX(action_combo_))); 124 gtk_combo_box_get_active(GTK_COMBO_BOX(action_combo_)));
127 bool is_off_the_record = 125 bool is_off_the_record =
128 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(otr_checkbox_)); 126 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(otr_checkbox_));
129 delegate_->AcceptExceptionEdit( 127 delegate_->AcceptExceptionEdit(
130 new_pattern, setting, is_off_the_record, index_, is_new()); 128 new_pattern, setting, is_off_the_record, index_, is_new());
131 } 129 }
132 130
133 gtk_widget_destroy(dialog_); 131 gtk_widget_destroy(dialog_);
134 } 132 }
135 133
136 void ContentExceptionEditor::OnWindowDestroy(GtkWidget* widget) { 134 void ContentExceptionEditor::OnWindowDestroy(GtkWidget* widget) {
137 MessageLoop::current()->DeleteSoon(FROM_HERE, this); 135 MessageLoop::current()->DeleteSoon(FROM_HERE, this);
138 } 136 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698