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/views/options/exception_editor_view.h" | 5 #include "chrome/browser/views/options/exception_editor_view.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/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/content_exceptions_table_model.h" | 10 #include "chrome/browser/content_exceptions_table_model.h" |
11 #include "googleurl/src/url_canon.h" | 11 #include "googleurl/src/url_canon.h" |
12 #include "googleurl/src/url_parse.h" | 12 #include "googleurl/src/url_parse.h" |
13 #include "grit/app_resources.h" | 13 #include "grit/app_resources.h" |
14 #include "grit/generated_resources.h" | 14 #include "grit/generated_resources.h" |
15 #include "views/grid_layout.h" | 15 #include "views/grid_layout.h" |
16 #include "views/controls/image_view.h" | 16 #include "views/controls/image_view.h" |
17 #include "views/controls/label.h" | 17 #include "views/controls/label.h" |
18 #include "views/standard_layout.h" | 18 #include "views/standard_layout.h" |
19 #include "views/window/window.h" | 19 #include "views/window/window.h" |
20 | 20 |
21 ExceptionEditorView::ExceptionEditorView( | 21 ExceptionEditorView::ExceptionEditorView( |
22 Delegate* delegate, | 22 Delegate* delegate, |
23 ContentExceptionsTableModel* model, | 23 ContentExceptionsTableModel* model, |
| 24 bool allow_off_the_record, |
24 int index, | 25 int index, |
25 const HostContentSettingsMap::Pattern& pattern, | 26 const HostContentSettingsMap::Pattern& pattern, |
26 ContentSetting setting) | 27 ContentSetting setting, |
| 28 bool is_off_the_record) |
27 : delegate_(delegate), | 29 : delegate_(delegate), |
28 model_(model), | 30 model_(model), |
29 cb_model_(model->content_type() == CONTENT_SETTINGS_TYPE_COOKIES), | 31 cb_model_(model->content_type() == CONTENT_SETTINGS_TYPE_COOKIES), |
| 32 allow_off_the_record_(allow_off_the_record), |
30 index_(index), | 33 index_(index), |
31 pattern_(pattern), | 34 pattern_(pattern), |
32 setting_(setting) { | 35 setting_(setting), |
| 36 is_off_the_record_(is_off_the_record) { |
33 Init(); | 37 Init(); |
34 } | 38 } |
35 | 39 |
36 void ExceptionEditorView::Show(gfx::NativeWindow parent) { | 40 void ExceptionEditorView::Show(gfx::NativeWindow parent) { |
37 views::Window* window = | 41 views::Window* window = |
38 views::Window::CreateChromeWindow(parent, gfx::Rect(), this); | 42 views::Window::CreateChromeWindow(parent, gfx::Rect(), this); |
39 window->Show(); | 43 window->Show(); |
40 GetDialogClientView()->UpdateDialogButtons(); | 44 GetDialogClientView()->UpdateDialogButtons(); |
41 pattern_tf_->SelectAll(); | 45 pattern_tf_->SelectAll(); |
42 pattern_tf_->RequestFocus(); | 46 pattern_tf_->RequestFocus(); |
43 } | 47 } |
44 | 48 |
45 bool ExceptionEditorView::IsModal() const { | 49 bool ExceptionEditorView::IsModal() const { |
46 return true; | 50 return true; |
47 } | 51 } |
48 | 52 |
49 std::wstring ExceptionEditorView::GetWindowTitle() const { | 53 std::wstring ExceptionEditorView::GetWindowTitle() const { |
50 return is_new() ? l10n_util::GetString(IDS_EXCEPTION_EDITOR_NEW_TITLE) : | 54 return is_new() ? l10n_util::GetString(IDS_EXCEPTION_EDITOR_NEW_TITLE) : |
51 l10n_util::GetString(IDS_EXCEPTION_EDITOR_TITLE); | 55 l10n_util::GetString(IDS_EXCEPTION_EDITOR_TITLE); |
52 } | 56 } |
53 | 57 |
54 bool ExceptionEditorView::IsDialogButtonEnabled( | 58 bool ExceptionEditorView::IsDialogButtonEnabled( |
55 MessageBoxFlags::DialogButton button) const { | 59 MessageBoxFlags::DialogButton button) const { |
56 if (button == MessageBoxFlags::DIALOGBUTTON_OK) { | 60 if (button == MessageBoxFlags::DIALOGBUTTON_OK) { |
57 return IsPatternValid(HostContentSettingsMap::Pattern( | 61 return IsPatternValid(HostContentSettingsMap::Pattern( |
58 UTF16ToUTF8(pattern_tf_->text()))); | 62 UTF16ToUTF8(pattern_tf_->text())), |
| 63 incognito_cb_->checked()); |
59 } | 64 } |
60 return true; | 65 return true; |
61 } | 66 } |
62 | 67 |
63 bool ExceptionEditorView::Cancel() { | 68 bool ExceptionEditorView::Cancel() { |
64 return true; | 69 return true; |
65 } | 70 } |
66 | 71 |
67 bool ExceptionEditorView::Accept() { | 72 bool ExceptionEditorView::Accept() { |
68 HostContentSettingsMap::Pattern new_pattern(UTF16ToUTF8(pattern_tf_->text())); | 73 HostContentSettingsMap::Pattern new_pattern(UTF16ToUTF8(pattern_tf_->text())); |
69 ContentSetting setting = | 74 ContentSetting setting = |
70 cb_model_.SettingForIndex(action_cb_->selected_item()); | 75 cb_model_.SettingForIndex(action_cb_->selected_item()); |
71 delegate_->AcceptExceptionEdit(new_pattern, setting, index_, is_new()); | 76 bool is_off_the_record = incognito_cb_->checked(); |
| 77 delegate_->AcceptExceptionEdit( |
| 78 new_pattern, setting, is_off_the_record, index_, is_new()); |
72 return true; | 79 return true; |
73 } | 80 } |
74 | 81 |
75 views::View* ExceptionEditorView::GetContentsView() { | 82 views::View* ExceptionEditorView::GetContentsView() { |
76 return this; | 83 return this; |
77 } | 84 } |
78 | 85 |
79 void ExceptionEditorView::ContentsChanged(views::Textfield* sender, | 86 void ExceptionEditorView::ContentsChanged(views::Textfield* sender, |
80 const std::wstring& new_contents) { | 87 const std::wstring& new_contents) { |
81 GetDialogClientView()->UpdateDialogButtons(); | 88 GetDialogClientView()->UpdateDialogButtons(); |
82 UpdateImageView(pattern_iv_, IsPatternValid(HostContentSettingsMap::Pattern( | 89 UpdateImageView(pattern_iv_, IsPatternValid(HostContentSettingsMap::Pattern( |
83 UTF16ToUTF8(pattern_tf_->text())))); | 90 UTF16ToUTF8(pattern_tf_->text())), incognito_cb_->checked())); |
84 } | 91 } |
85 | 92 |
86 bool ExceptionEditorView::HandleKeystroke( | 93 bool ExceptionEditorView::HandleKeystroke( |
87 views::Textfield* sender, | 94 views::Textfield* sender, |
88 const views::Textfield::Keystroke& key) { | 95 const views::Textfield::Keystroke& key) { |
89 return false; | 96 return false; |
90 } | 97 } |
91 | 98 |
92 void ExceptionEditorView::Init() { | 99 void ExceptionEditorView::Init() { |
93 using views::GridLayout; | 100 using views::GridLayout; |
94 | 101 |
95 pattern_tf_ = new views::Textfield(); | 102 pattern_tf_ = new views::Textfield(); |
96 pattern_tf_->SetText(UTF8ToUTF16(pattern_.AsString())); | 103 pattern_tf_->SetText(UTF8ToUTF16(pattern_.AsString())); |
97 pattern_tf_->SetController(this); | 104 pattern_tf_->SetController(this); |
98 | 105 |
99 pattern_iv_ = new views::ImageView; | 106 pattern_iv_ = new views::ImageView; |
100 | 107 |
101 UpdateImageView(pattern_iv_, IsPatternValid(HostContentSettingsMap::Pattern( | 108 UpdateImageView(pattern_iv_, IsPatternValid(HostContentSettingsMap::Pattern( |
102 UTF16ToUTF8(pattern_tf_->text())))); | 109 UTF16ToUTF8(pattern_tf_->text())), is_off_the_record_)); |
103 | 110 |
104 action_cb_ = new views::Combobox(&cb_model_); | 111 action_cb_ = new views::Combobox(&cb_model_); |
105 if (!is_new()) | 112 if (!is_new()) |
106 action_cb_->SetSelectedItem(cb_model_.IndexForSetting(setting_)); | 113 action_cb_->SetSelectedItem(cb_model_.IndexForSetting(setting_)); |
107 | 114 |
| 115 incognito_cb_ = new views::Checkbox( |
| 116 l10n_util::GetString(IDS_EXCEPTION_EDITOR_OTR_TITLE)); |
| 117 incognito_cb_->SetChecked(is_off_the_record_); |
| 118 |
108 GridLayout* layout = CreatePanelGridLayout(this); | 119 GridLayout* layout = CreatePanelGridLayout(this); |
109 SetLayoutManager(layout); | 120 SetLayoutManager(layout); |
110 | 121 |
111 // For the Textfields. | 122 // For the Textfields. |
112 views::ColumnSet* column_set = layout->AddColumnSet(1); | 123 views::ColumnSet* column_set = layout->AddColumnSet(1); |
113 column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, | 124 column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, |
114 GridLayout::USE_PREF, 0, 0); | 125 GridLayout::USE_PREF, 0, 0); |
115 column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); | 126 column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); |
116 column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1, | 127 column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1, |
117 GridLayout::USE_PREF, 0, 0); | 128 GridLayout::USE_PREF, 0, 0); |
118 column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); | 129 column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); |
119 column_set->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, | 130 column_set->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, |
120 GridLayout::USE_PREF, 0, 0); | 131 GridLayout::USE_PREF, 0, 0); |
121 | 132 |
122 // Add the contents. | 133 // Add the contents. |
123 layout->StartRow(0, 1); | 134 layout->StartRow(0, 1); |
124 layout->AddView(CreateLabel(IDS_EXCEPTION_EDITOR_PATTERN_TITLE)); | 135 layout->AddView(CreateLabel(IDS_EXCEPTION_EDITOR_PATTERN_TITLE)); |
125 layout->AddView(pattern_tf_); | 136 layout->AddView(pattern_tf_); |
126 layout->AddView(pattern_iv_); | 137 layout->AddView(pattern_iv_); |
127 | 138 |
128 layout->StartRowWithPadding(0, 1, 0, kRelatedControlVerticalSpacing); | 139 layout->StartRowWithPadding(0, 1, 0, kRelatedControlVerticalSpacing); |
129 layout->AddView(CreateLabel(IDS_EXCEPTION_EDITOR_ACTION_TITLE)); | 140 layout->AddView(CreateLabel(IDS_EXCEPTION_EDITOR_ACTION_TITLE)); |
130 layout->AddView(action_cb_); | 141 layout->AddView(action_cb_); |
| 142 |
| 143 if (allow_off_the_record_) { |
| 144 layout->StartRowWithPadding(0, 1, 0, kRelatedControlVerticalSpacing); |
| 145 layout->AddView(incognito_cb_, 3, 1, GridLayout::FILL, GridLayout::FILL); |
| 146 } |
131 } | 147 } |
132 | 148 |
133 views::Label* ExceptionEditorView::CreateLabel(int message_id) { | 149 views::Label* ExceptionEditorView::CreateLabel(int message_id) { |
134 views::Label* label = new views::Label(l10n_util::GetString(message_id)); | 150 views::Label* label = new views::Label(l10n_util::GetString(message_id)); |
135 label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 151 label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
136 return label; | 152 return label; |
137 } | 153 } |
138 | 154 |
139 bool ExceptionEditorView::IsPatternValid( | 155 bool ExceptionEditorView::IsPatternValid( |
140 const HostContentSettingsMap::Pattern& pattern) const { | 156 const HostContentSettingsMap::Pattern& pattern, |
| 157 bool is_off_the_record) const { |
141 bool is_valid_pattern = pattern.IsValid() && | 158 bool is_valid_pattern = pattern.IsValid() && |
142 (model_->IndexOfExceptionByPattern(pattern) == -1); | 159 (model_->IndexOfExceptionByPattern(pattern, is_off_the_record) == -1); |
143 | 160 |
144 return is_new() ? is_valid_pattern : (!pattern.AsString().empty() && | 161 return is_new() ? is_valid_pattern : (!pattern.AsString().empty() && |
145 ((pattern_ == pattern) || is_valid_pattern)); | 162 ((pattern_ == pattern) || is_valid_pattern)); |
146 } | 163 } |
147 | 164 |
148 void ExceptionEditorView::UpdateImageView(views::ImageView* image_view, | 165 void ExceptionEditorView::UpdateImageView(views::ImageView* image_view, |
149 bool is_valid) { | 166 bool is_valid) { |
150 return image_view->SetImage( | 167 return image_view->SetImage( |
151 ResourceBundle::GetSharedInstance().GetBitmapNamed( | 168 ResourceBundle::GetSharedInstance().GetBitmapNamed( |
152 is_valid ? IDR_INPUT_GOOD : IDR_INPUT_ALERT)); | 169 is_valid ? IDR_INPUT_GOOD : IDR_INPUT_ALERT)); |
153 } | 170 } |
OLD | NEW |