| 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 "grit/theme_resources.h" | 15 #include "grit/theme_resources.h" |
| 16 #include "views/grid_layout.h" | 16 #include "views/grid_layout.h" |
| 17 #include "views/controls/image_view.h" | 17 #include "views/controls/image_view.h" |
| 18 #include "views/controls/label.h" | 18 #include "views/controls/label.h" |
| 19 #include "views/standard_layout.h" | 19 #include "views/standard_layout.h" |
| 20 #include "views/window/window.h" | 20 #include "views/window/window.h" |
| 21 | 21 |
| 22 ExceptionEditorView::ExceptionEditorView( | 22 ExceptionEditorView::ExceptionEditorView( |
| 23 Delegate* delegate, | 23 Delegate* delegate, |
| 24 ContentExceptionsTableModel* model, | 24 ContentExceptionsTableModel* model, |
| 25 bool allow_off_the_record, | 25 bool allow_off_the_record, |
| 26 int index, | 26 int index, |
| 27 const HostContentSettingsMap::Pattern& pattern, | 27 const ContentSettingsPattern& pattern, |
| 28 ContentSetting setting, | 28 ContentSetting setting, |
| 29 bool is_off_the_record) | 29 bool is_off_the_record) |
| 30 : delegate_(delegate), | 30 : delegate_(delegate), |
| 31 model_(model), | 31 model_(model), |
| 32 cb_model_(model->content_type()), | 32 cb_model_(model->content_type()), |
| 33 allow_off_the_record_(allow_off_the_record), | 33 allow_off_the_record_(allow_off_the_record), |
| 34 index_(index), | 34 index_(index), |
| 35 pattern_(pattern), | 35 pattern_(pattern), |
| 36 setting_(setting), | 36 setting_(setting), |
| 37 is_off_the_record_(is_off_the_record) { | 37 is_off_the_record_(is_off_the_record) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 56 } | 56 } |
| 57 | 57 |
| 58 std::wstring ExceptionEditorView::GetWindowTitle() const { | 58 std::wstring ExceptionEditorView::GetWindowTitle() const { |
| 59 return is_new() ? l10n_util::GetString(IDS_EXCEPTION_EDITOR_NEW_TITLE) : | 59 return is_new() ? l10n_util::GetString(IDS_EXCEPTION_EDITOR_NEW_TITLE) : |
| 60 l10n_util::GetString(IDS_EXCEPTION_EDITOR_TITLE); | 60 l10n_util::GetString(IDS_EXCEPTION_EDITOR_TITLE); |
| 61 } | 61 } |
| 62 | 62 |
| 63 bool ExceptionEditorView::IsDialogButtonEnabled( | 63 bool ExceptionEditorView::IsDialogButtonEnabled( |
| 64 MessageBoxFlags::DialogButton button) const { | 64 MessageBoxFlags::DialogButton button) const { |
| 65 if (button == MessageBoxFlags::DIALOGBUTTON_OK) { | 65 if (button == MessageBoxFlags::DIALOGBUTTON_OK) { |
| 66 return IsPatternValid(HostContentSettingsMap::Pattern( | 66 return IsPatternValid(ContentSettingsPattern( |
| 67 UTF16ToUTF8(pattern_tf_->text())), | 67 UTF16ToUTF8(pattern_tf_->text())), |
| 68 incognito_cb_->checked()); | 68 incognito_cb_->checked()); |
| 69 } | 69 } |
| 70 return true; | 70 return true; |
| 71 } | 71 } |
| 72 | 72 |
| 73 bool ExceptionEditorView::Cancel() { | 73 bool ExceptionEditorView::Cancel() { |
| 74 return true; | 74 return true; |
| 75 } | 75 } |
| 76 | 76 |
| 77 bool ExceptionEditorView::Accept() { | 77 bool ExceptionEditorView::Accept() { |
| 78 HostContentSettingsMap::Pattern new_pattern(UTF16ToUTF8(pattern_tf_->text())); | 78 ContentSettingsPattern new_pattern(UTF16ToUTF8(pattern_tf_->text())); |
| 79 ContentSetting setting = | 79 ContentSetting setting = |
| 80 cb_model_.SettingForIndex(action_cb_->selected_item()); | 80 cb_model_.SettingForIndex(action_cb_->selected_item()); |
| 81 bool is_off_the_record = incognito_cb_->checked(); | 81 bool is_off_the_record = incognito_cb_->checked(); |
| 82 delegate_->AcceptExceptionEdit( | 82 delegate_->AcceptExceptionEdit( |
| 83 new_pattern, setting, is_off_the_record, index_, is_new()); | 83 new_pattern, setting, is_off_the_record, index_, is_new()); |
| 84 return true; | 84 return true; |
| 85 } | 85 } |
| 86 | 86 |
| 87 views::View* ExceptionEditorView::GetContentsView() { | 87 views::View* ExceptionEditorView::GetContentsView() { |
| 88 return this; | 88 return this; |
| 89 } | 89 } |
| 90 | 90 |
| 91 void ExceptionEditorView::ContentsChanged(views::Textfield* sender, | 91 void ExceptionEditorView::ContentsChanged(views::Textfield* sender, |
| 92 const std::wstring& new_contents) { | 92 const std::wstring& new_contents) { |
| 93 GetDialogClientView()->UpdateDialogButtons(); | 93 GetDialogClientView()->UpdateDialogButtons(); |
| 94 UpdateImageView(pattern_iv_, IsPatternValid(HostContentSettingsMap::Pattern( | 94 UpdateImageView(pattern_iv_, IsPatternValid(ContentSettingsPattern( |
| 95 UTF16ToUTF8(pattern_tf_->text())), incognito_cb_->checked())); | 95 UTF16ToUTF8(pattern_tf_->text())), incognito_cb_->checked())); |
| 96 } | 96 } |
| 97 | 97 |
| 98 bool ExceptionEditorView::HandleKeystroke( | 98 bool ExceptionEditorView::HandleKeystroke( |
| 99 views::Textfield* sender, | 99 views::Textfield* sender, |
| 100 const views::Textfield::Keystroke& key) { | 100 const views::Textfield::Keystroke& key) { |
| 101 return false; | 101 return false; |
| 102 } | 102 } |
| 103 | 103 |
| 104 void ExceptionEditorView::Init() { | 104 void ExceptionEditorView::Init() { |
| 105 using views::GridLayout; | 105 using views::GridLayout; |
| 106 | 106 |
| 107 pattern_tf_ = new views::Textfield(); | 107 pattern_tf_ = new views::Textfield(); |
| 108 pattern_tf_->SetText(UTF8ToUTF16(pattern_.AsString())); | 108 pattern_tf_->SetText(UTF8ToUTF16(pattern_.AsString())); |
| 109 pattern_tf_->SetController(this); | 109 pattern_tf_->SetController(this); |
| 110 | 110 |
| 111 pattern_iv_ = new views::ImageView; | 111 pattern_iv_ = new views::ImageView; |
| 112 | 112 |
| 113 UpdateImageView(pattern_iv_, IsPatternValid(HostContentSettingsMap::Pattern( | 113 UpdateImageView(pattern_iv_, IsPatternValid(ContentSettingsPattern( |
| 114 UTF16ToUTF8(pattern_tf_->text())), is_off_the_record_)); | 114 UTF16ToUTF8(pattern_tf_->text())), is_off_the_record_)); |
| 115 | 115 |
| 116 action_cb_ = new views::Combobox(&cb_model_); | 116 action_cb_ = new views::Combobox(&cb_model_); |
| 117 if (!is_new()) | 117 if (!is_new()) |
| 118 action_cb_->SetSelectedItem(cb_model_.IndexForSetting(setting_)); | 118 action_cb_->SetSelectedItem(cb_model_.IndexForSetting(setting_)); |
| 119 | 119 |
| 120 incognito_cb_ = new views::Checkbox( | 120 incognito_cb_ = new views::Checkbox( |
| 121 l10n_util::GetString(IDS_EXCEPTION_EDITOR_OTR_TITLE)); | 121 l10n_util::GetString(IDS_EXCEPTION_EDITOR_OTR_TITLE)); |
| 122 incognito_cb_->SetChecked(is_off_the_record_); | 122 incognito_cb_->SetChecked(is_off_the_record_); |
| 123 | 123 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 151 } | 151 } |
| 152 } | 152 } |
| 153 | 153 |
| 154 views::Label* ExceptionEditorView::CreateLabel(int message_id) { | 154 views::Label* ExceptionEditorView::CreateLabel(int message_id) { |
| 155 views::Label* label = new views::Label(l10n_util::GetString(message_id)); | 155 views::Label* label = new views::Label(l10n_util::GetString(message_id)); |
| 156 label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 156 label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
| 157 return label; | 157 return label; |
| 158 } | 158 } |
| 159 | 159 |
| 160 bool ExceptionEditorView::IsPatternValid( | 160 bool ExceptionEditorView::IsPatternValid( |
| 161 const HostContentSettingsMap::Pattern& pattern, | 161 const ContentSettingsPattern& pattern, |
| 162 bool is_off_the_record) const { | 162 bool is_off_the_record) const { |
| 163 bool is_valid_pattern = pattern.IsValid() && | 163 bool is_valid_pattern = pattern.IsValid() && |
| 164 (model_->IndexOfExceptionByPattern(pattern, is_off_the_record) == -1); | 164 (model_->IndexOfExceptionByPattern(pattern, is_off_the_record) == -1); |
| 165 | 165 |
| 166 return is_new() ? is_valid_pattern : (!pattern.AsString().empty() && | 166 return is_new() ? is_valid_pattern : (!pattern.AsString().empty() && |
| 167 ((pattern_ == pattern) || is_valid_pattern)); | 167 ((pattern_ == pattern) || is_valid_pattern)); |
| 168 } | 168 } |
| 169 | 169 |
| 170 void ExceptionEditorView::UpdateImageView(views::ImageView* image_view, | 170 void ExceptionEditorView::UpdateImageView(views::ImageView* image_view, |
| 171 bool is_valid) { | 171 bool is_valid) { |
| 172 return image_view->SetImage( | 172 return image_view->SetImage( |
| 173 ResourceBundle::GetSharedInstance().GetBitmapNamed( | 173 ResourceBundle::GetSharedInstance().GetBitmapNamed( |
| 174 is_valid ? IDR_INPUT_GOOD : IDR_INPUT_ALERT)); | 174 is_valid ? IDR_INPUT_GOOD : IDR_INPUT_ALERT)); |
| 175 } | 175 } |
| OLD | NEW |