summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-24 22:06:43 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-24 22:06:43 +0000
commitbc611a0aa62dbbce73d4ab13c65ae981d5511a4a (patch)
tree1cc1064e60242820b39ee3ea7cbef73daa333a4d
parent91ebf88c146bc777ae0d1432ce8ab61455cbaec0 (diff)
downloadchromium_src-bc611a0aa62dbbce73d4ab13c65ae981d5511a4a.zip
chromium_src-bc611a0aa62dbbce73d4ab13c65ae981d5511a4a.tar.gz
chromium_src-bc611a0aa62dbbce73d4ab13c65ae981d5511a4a.tar.bz2
Merge 39931 - Add a host validity status icon to the content settings exception editor. Original patch by Thiago Farina (see http://codereview.chromium.org/650011 ), r=me.
BUG=34181 TEST=Open the content settings exception editor, hit add, type a hostname, observe how status icon changes. TBR=pkasting@chromium.org Review URL: http://codereview.chromium.org/661021 git-svn-id: svn://svn.chromium.org/chrome/branches/249/src@39932 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/views/options/exception_editor_view.cc54
-rw-r--r--chrome/browser/views/options/exception_editor_view.h6
2 files changed, 43 insertions, 17 deletions
diff --git a/chrome/browser/views/options/exception_editor_view.cc b/chrome/browser/views/options/exception_editor_view.cc
index 63265781..f171bb4 100644
--- a/chrome/browser/views/options/exception_editor_view.cc
+++ b/chrome/browser/views/options/exception_editor_view.cc
@@ -5,28 +5,33 @@
#include "chrome/browser/views/options/exception_editor_view.h"
#include "app/l10n_util.h"
+#include "app/resource_bundle.h"
#include "chrome/browser/host_content_settings_map.h"
#include "chrome/browser/views/options/content_exceptions_table_model.h"
#include "googleurl/src/url_canon.h"
#include "googleurl/src/url_parse.h"
+#include "grit/app_resources.h"
#include "grit/generated_resources.h"
#include "net/base/net_util.h"
#include "views/grid_layout.h"
+#include "views/controls/image_view.h"
#include "views/controls/label.h"
#include "views/standard_layout.h"
#include "views/window/window.h"
-// The settings shown in the combobox if show_ask_ is false;
-static const ContentSetting kNoAskSettings[] = { CONTENT_SETTING_ALLOW,
- CONTENT_SETTING_BLOCK };
+namespace {
-// The settings shown in the combobox if show_ask_ is true;
-static const ContentSetting kAskSettings[] = { CONTENT_SETTING_ALLOW,
- CONTENT_SETTING_ASK,
- CONTENT_SETTING_BLOCK };
+// The settings shown in the combobox if show_ask_ is false.
+const ContentSetting kNoAskSettings[] = { CONTENT_SETTING_ALLOW,
+ CONTENT_SETTING_BLOCK };
+
+// The settings shown in the combobox if show_ask_ is true.
+const ContentSetting kAskSettings[] = { CONTENT_SETTING_ALLOW,
+ CONTENT_SETTING_ASK,
+ CONTENT_SETTING_BLOCK };
// Returns true if the host name is valid.
-static bool ValidHost(const std::string& host) {
+bool ValidHost(const std::string& host) {
if (host.empty())
return false;
@@ -34,6 +39,8 @@ static bool ValidHost(const std::string& host) {
return !net::CanonicalizeHost(host, &host_info).empty();
}
+} // namespace
+
int ExceptionEditorView::ActionComboboxModel::GetItemCount() {
return show_ask_ ? arraysize(kAskSettings) : arraysize(kNoAskSettings);
}
@@ -101,15 +108,7 @@ std::wstring ExceptionEditorView::GetWindowTitle() const {
bool ExceptionEditorView::IsDialogButtonEnabled(
MessageBoxFlags::DialogButton button) const {
if (button == MessageBoxFlags::DIALOGBUTTON_OK) {
- std::string new_host = UTF16ToUTF8(host_tf_->text());
- if (is_new()) {
- return ValidHost(new_host) &&
- (model_->IndexOfExceptionByHost(new_host) == -1);
- }
- return !new_host.empty() &&
- (host_ == new_host ||
- (ValidHost(new_host) &&
- model_->IndexOfExceptionByHost(new_host) == -1));
+ return IsHostValid(UTF16ToUTF8(host_tf_->text()));
}
return true;
}
@@ -133,6 +132,7 @@ views::View* ExceptionEditorView::GetContentsView() {
void ExceptionEditorView::ContentsChanged(views::Textfield* sender,
const std::wstring& new_contents) {
GetDialogClientView()->UpdateDialogButtons();
+ UpdateImageView(host_iv_, IsHostValid(UTF16ToUTF8(host_tf_->text())));
}
bool ExceptionEditorView::HandleKeystroke(
@@ -148,6 +148,10 @@ void ExceptionEditorView::Init() {
host_tf_->SetText(UTF8ToUTF16(host_));
host_tf_->SetController(this);
+ host_iv_ = new views::ImageView;
+
+ UpdateImageView(host_iv_, IsHostValid(UTF16ToUTF8(host_tf_->text())));
+
action_cb_ = new views::Combobox(&cb_model_);
if (!is_new())
action_cb_->SetSelectedItem(cb_model_.index_for_setting(setting_));
@@ -170,6 +174,7 @@ void ExceptionEditorView::Init() {
layout->StartRow(0, 1);
layout->AddView(CreateLabel(IDS_EXCEPTION_EDITOR_HOST_TITLE));
layout->AddView(host_tf_);
+ layout->AddView(host_iv_);
layout->StartRowWithPadding(0, 1, 0, kRelatedControlVerticalSpacing);
layout->AddView(CreateLabel(IDS_EXCEPTION_EDITOR_ACTION_TITLE));
@@ -181,3 +186,18 @@ views::Label* ExceptionEditorView::CreateLabel(int message_id) {
label->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
return label;
}
+
+bool ExceptionEditorView::IsHostValid(const std::string& host) const {
+ bool is_valid_host = ValidHost(host) &&
+ (model_->IndexOfExceptionByHost(host) == -1);
+
+ return is_new() ? is_valid_host : (!host.empty() &&
+ ((host_ == host) || is_valid_host));
+}
+
+void ExceptionEditorView::UpdateImageView(views::ImageView* image_view,
+ bool is_valid) {
+ return image_view->SetImage(
+ ResourceBundle::GetSharedInstance().GetBitmapNamed(
+ is_valid ? IDR_INPUT_GOOD : IDR_INPUT_ALERT));
+}
diff --git a/chrome/browser/views/options/exception_editor_view.h b/chrome/browser/views/options/exception_editor_view.h
index 6a86f79..5523e9c 100644
--- a/chrome/browser/views/options/exception_editor_view.h
+++ b/chrome/browser/views/options/exception_editor_view.h
@@ -15,6 +15,7 @@
#include "views/controls/textfield/textfield.h"
namespace views {
+class ImageView;
class Label;
}
@@ -96,6 +97,10 @@ class ExceptionEditorView : public views::View,
// Returns true if we're adding a new item.
bool is_new() const { return index_ == -1; }
+ bool IsHostValid(const std::string& host) const;
+
+ void UpdateImageView(views::ImageView* image_view, bool is_valid);
+
Delegate* delegate_;
ContentExceptionsTableModel* model_;
ActionComboboxModel cb_model_;
@@ -106,6 +111,7 @@ class ExceptionEditorView : public views::View,
const ContentSetting setting_;
views::Textfield* host_tf_;
+ views::ImageView* host_iv_;
views::Combobox* action_cb_;
DISALLOW_COPY_AND_ASSIGN(ExceptionEditorView);