summaryrefslogtreecommitdiffstats
path: root/chrome/browser/views
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/views')
-rw-r--r--chrome/browser/views/browser_views.vcproj8
-rw-r--r--chrome/browser/views/options/content_page_view.cc21
-rw-r--r--chrome/browser/views/options/content_page_view.h1
-rwxr-xr-xchrome/browser/views/password_manager_exceptions_view.cc243
-rwxr-xr-xchrome/browser/views/password_manager_exceptions_view.h93
-rw-r--r--chrome/browser/views/password_manager_view.h9
6 files changed, 369 insertions, 6 deletions
diff --git a/chrome/browser/views/browser_views.vcproj b/chrome/browser/views/browser_views.vcproj
index c94205c..994adf9 100644
--- a/chrome/browser/views/browser_views.vcproj
+++ b/chrome/browser/views/browser_views.vcproj
@@ -658,6 +658,14 @@
>
</File>
<File
+ RelativePath=".\password_manager_exceptions_view.cc"
+ >
+ </File>
+ <File
+ RelativePath=".\password_manager_exceptions_view.h"
+ >
+ </File>
+ <File
RelativePath=".\password_manager_view.cc"
>
</File>
diff --git a/chrome/browser/views/options/content_page_view.cc b/chrome/browser/views/options/content_page_view.cc
index a534a4b..579158e8 100644
--- a/chrome/browser/views/options/content_page_view.cc
+++ b/chrome/browser/views/options/content_page_view.cc
@@ -17,6 +17,7 @@
#include "chrome/browser/views/options/fonts_languages_window_view.h"
#include "chrome/browser/views/options/options_group_view.h"
#include "chrome/browser/views/password_manager_view.h"
+#include "chrome/browser/views/password_manager_exceptions_view.h"
#include "chrome/browser/views/standard_layout.h"
#include "chrome/common/gfx/chrome_canvas.h"
#include "chrome/common/l10n_util.h"
@@ -161,6 +162,7 @@ ContentPageView::ContentPageView(Profile* profile)
download_browse_button_(NULL),
download_ask_for_save_location_checkbox_(NULL),
select_file_dialog_(SelectFileDialog::Create(this)),
+ passwords_exceptions_button_(NULL),
passwords_group_(NULL),
passwords_asktosave_radio_(NULL),
passwords_neversave_radio_(NULL),
@@ -223,7 +225,10 @@ void ContentPageView::ButtonPressed(views::NativeButton* sender) {
profile()->GetPrefs());
}
ask_to_save_passwords_.SetValue(enabled);
- } else if (sender == passwords_show_passwords_button_) {
+ } else if (sender == passwords_exceptions_button_) {
+ UserMetricsRecordAction(L"Options_ShowPasswordManagerExceptions", NULL);
+ PasswordManagerExceptionsView::Show(profile());
+ }else if (sender == passwords_show_passwords_button_) {
UserMetricsRecordAction(L"Options_ShowPasswordManager", NULL);
PasswordManagerView::Show(profile());
} else if (sender == form_autofill_checkbox_) {
@@ -396,6 +401,9 @@ void ContentPageView::InitPasswordSavingGroup() {
passwords_show_passwords_button_ = new views::NativeButton(
l10n_util::GetString(IDS_OPTIONS_PASSWORDS_SHOWPASSWORDS));
passwords_show_passwords_button_->SetListener(this);
+ passwords_exceptions_button_ = new views::NativeButton(
+ l10n_util::GetString(IDS_OPTIONS_PASSWORDS_EXCEPTIONS));
+ passwords_exceptions_button_->SetListener(this);
using views::GridLayout;
using views::ColumnSet;
@@ -409,14 +417,23 @@ void ContentPageView::InitPasswordSavingGroup() {
column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 1,
GridLayout::USE_PREF, 0, 0);
+ const int double_column_view_set_id = 0;
+ column_set = layout->AddColumnSet(double_column_view_set_id);
+ column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0,
+ GridLayout::USE_PREF, 0, 0);
+ column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing);
+ column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0,
+ GridLayout::USE_PREF, 0, 0);
+
layout->StartRow(0, single_column_view_set_id);
layout->AddView(passwords_asktosave_radio_);
layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
layout->StartRow(0, single_column_view_set_id);
layout->AddView(passwords_neversave_radio_);
layout->AddPaddingRow(0, kUnrelatedControlVerticalSpacing);
- layout->StartRow(0, single_column_view_set_id);
+ layout->StartRow(0, double_column_view_set_id);
layout->AddView(passwords_show_passwords_button_);
+ layout->AddView(passwords_exceptions_button_);
passwords_group_ = new OptionsGroupView(
contents, l10n_util::GetString(IDS_OPTIONS_PASSWORDS_GROUP_NAME), L"",
diff --git a/chrome/browser/views/options/content_page_view.h b/chrome/browser/views/options/content_page_view.h
index 93a3a49..c6c7127 100644
--- a/chrome/browser/views/options/content_page_view.h
+++ b/chrome/browser/views/options/content_page_view.h
@@ -65,6 +65,7 @@ class ContentPageView : public OptionsPageView,
scoped_refptr<SelectFileDialog> select_file_dialog_;
// Controls for the Password Saving group
+ views::NativeButton* passwords_exceptions_button_;
OptionsGroupView* passwords_group_;
views::RadioButton* passwords_asktosave_radio_;
views::RadioButton* passwords_neversave_radio_;
diff --git a/chrome/browser/views/password_manager_exceptions_view.cc b/chrome/browser/views/password_manager_exceptions_view.cc
new file mode 100755
index 0000000..b12d471
--- /dev/null
+++ b/chrome/browser/views/password_manager_exceptions_view.cc
@@ -0,0 +1,243 @@
+// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/string_util.h"
+#include "chrome/common/l10n_util.h"
+#include "chrome/browser/profile.h"
+#include "chrome/browser/views/password_manager_exceptions_view.h"
+#include "chrome/browser/views/standard_layout.h"
+#include "chrome/common/pref_names.h"
+#include "chrome/common/pref_service.h"
+#include "chrome/views/background.h"
+#include "chrome/views/grid_layout.h"
+#include "chrome/views/native_button.h"
+
+#include "generated_resources.h"
+
+using views::ColumnSet;
+using views::GridLayout;
+
+// We can only have one PasswordManagerExceptionsView at a time.
+static PasswordManagerExceptionsView* instance_ = NULL;
+
+static const int kDefaultWindowWidth = 530;
+static const int kDefaultWindowHeight = 240;
+
+////////////////////////////////////////////////////////////////////
+// PasswordManagerExceptionsTableModel
+PasswordManagerExceptionsTableModel::PasswordManagerExceptionsTableModel(
+ Profile* profile) : PasswordManagerTableModel(profile) {
+}
+
+PasswordManagerExceptionsTableModel::~PasswordManagerExceptionsTableModel() {
+}
+
+std::wstring PasswordManagerExceptionsTableModel::GetText(int row, int col_id) {
+ DCHECK_EQ(col_id, IDS_PASSWORD_MANAGER_VIEW_SITE_COLUMN);
+ return PasswordManagerTableModel::GetText(row, col_id);
+}
+
+int PasswordManagerExceptionsTableModel::CompareValues(int row1, int row2,
+ int col_id) {
+ DCHECK_EQ(col_id, IDS_PASSWORD_MANAGER_VIEW_SITE_COLUMN);
+ return PasswordManagerTableModel::CompareValues(row1, row2, col_id);
+}
+
+void PasswordManagerExceptionsTableModel::GetAllExceptionsForProfile() {
+ DCHECK(!pending_login_query_);
+ pending_login_query_ = web_data_service()->GetAllLogins(this);
+}
+
+void PasswordManagerExceptionsTableModel::OnWebDataServiceRequestDone(
+ WebDataService::Handle h,
+ const WDTypedResult* result) {
+ DCHECK_EQ(pending_login_query_, h);
+ pending_login_query_ = NULL;
+
+ if (!result)
+ return;
+
+ DCHECK(result->GetType() == PASSWORD_RESULT);
+
+ // Get the result from the database into a useable form.
+ const WDResult<std::vector<PasswordForm*> >* r =
+ static_cast<const WDResult<std::vector<PasswordForm*> >*>(result);
+ std::vector<PasswordForm*> rows = r->GetValue();
+ STLDeleteElements<PasswordRows>(&saved_signons_);
+ std::wstring languages =
+ profile_->GetPrefs()->GetString(prefs::kAcceptLanguages);
+ for (size_t i = 0; i < rows.size(); ++i) {
+ if (rows[i]->blacklisted_by_user) {
+ saved_signons_.push_back(new PasswordRow(
+ gfx::SortedDisplayURL(rows[i]->origin, languages), rows[i]));
+ }
+ }
+ if (observer_)
+ observer_->OnModelChanged();
+}
+
+//////////////////////////////////////////////////////////////////////
+// PasswordManagerExceptionsView
+
+// static
+void PasswordManagerExceptionsView::Show(Profile* profile) {
+ DCHECK(profile);
+ if (!instance_) {
+ instance_ = new PasswordManagerExceptionsView(profile);
+
+ // manager is owned by the dialog window, so Close() will delete it.
+ views::Window::CreateChromeWindow(NULL, gfx::Rect(), instance_);
+ }
+ if (!instance_->window()->IsVisible()) {
+ instance_->window()->Show();
+ } else {
+ instance_->window()->Activate();
+ }
+}
+
+PasswordManagerExceptionsView::PasswordManagerExceptionsView(Profile* profile)
+ : remove_button_(l10n_util::GetString(
+ IDS_PASSWORD_MANAGER_EXCEPTIONS_VIEW_REMOVE_BUTTON)),
+ remove_all_button_(l10n_util::GetString(
+ IDS_PASSWORD_MANAGER_EXCEPTIONS_VIEW_REMOVE_ALL_BUTTON)),
+ table_model_(profile) {
+ Init();
+}
+
+void PasswordManagerExceptionsView::SetupTable() {
+ // Creates the different columns for the table.
+ // The float resize values are the result of much tinkering.
+ std::vector<views::TableColumn> columns;
+ columns.push_back(views::TableColumn(
+ IDS_PASSWORD_MANAGER_VIEW_SITE_COLUMN,
+ views::TableColumn::LEFT, -1, 0.55f));
+ columns.back().sortable = true;
+ table_view_ = new views::TableView(&table_model_, columns, views::TEXT_ONLY,
+ true, true, true);
+ // Make the table initially sorted by host.
+ views::TableView::SortDescriptors sort;
+ sort.push_back(views::TableView::SortDescriptor(
+ IDS_PASSWORD_MANAGER_VIEW_SITE_COLUMN, true));
+ table_view_->SetSortDescriptors(sort);
+ table_view_->SetObserver(this);
+}
+
+void PasswordManagerExceptionsView::SetupButtons() {
+ // Tell View not to delete class stack allocated views.
+
+ remove_button_.SetParentOwned(false);
+ remove_button_.SetListener(this);
+ remove_button_.SetEnabled(false);
+
+ remove_all_button_.SetParentOwned(false);
+ remove_all_button_.SetListener(this);
+}
+
+void PasswordManagerExceptionsView::Init() {
+ // Configure the background and view elements (buttons, labels, table).
+ SetupButtons();
+ SetupTable();
+
+ // Do the layout thing.
+ const int column_set_id = 0;
+ GridLayout* layout = CreatePanelGridLayout(this);
+ SetLayoutManager(layout);
+
+ // Design the grid.
+ ColumnSet* column_set = layout->AddColumnSet(column_set_id);
+ column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1,
+ GridLayout::FIXED, 300, 0);
+ column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing);
+ column_set->AddColumn(GridLayout::FILL, GridLayout::LEADING, 0,
+ GridLayout::USE_PREF, 0, 0);
+
+ // Fill the grid.
+ layout->StartRow(0.05f, column_set_id);
+ layout->AddView(table_view_);
+ layout->AddView(&remove_button_);
+
+ // Ask the database for exception data.
+ table_model_.GetAllExceptionsForProfile();
+}
+
+PasswordManagerExceptionsView::~PasswordManagerExceptionsView() {
+}
+
+void PasswordManagerExceptionsView::Layout() {
+ GetLayoutManager()->Layout(this);
+
+ // Manually lay out the Remove All button in the same row as
+ // the close button.
+ gfx::Rect parent_bounds = GetParent()->GetLocalBounds(false);
+ gfx::Size prefsize = remove_all_button_.GetPreferredSize();
+ int button_y =
+ parent_bounds.bottom() - prefsize.height() - kButtonVEdgeMargin;
+ remove_all_button_.SetBounds(kPanelHorizMargin, button_y, prefsize.width(),
+ prefsize.height());
+}
+
+gfx::Size PasswordManagerExceptionsView::GetPreferredSize() {
+ return gfx::Size(kDefaultWindowWidth, kDefaultWindowHeight);
+}
+
+void PasswordManagerExceptionsView::ViewHierarchyChanged(bool is_add,
+ views::View* parent,
+ views::View* child) {
+ if (child == this) {
+ // Add and remove the Remove All button from the ClientView's hierarchy.
+ if (is_add) {
+ parent->AddChildView(&remove_all_button_);
+ } else {
+ parent->RemoveChildView(&remove_all_button_);
+ }
+ }
+}
+
+void PasswordManagerExceptionsView::OnSelectionChanged() {
+ bool has_selection = table_view_->SelectedRowCount() > 0;
+ remove_button_.SetEnabled(has_selection);
+}
+
+int PasswordManagerExceptionsView::GetDialogButtons() const {
+ return DIALOGBUTTON_CANCEL;
+}
+
+std::wstring PasswordManagerExceptionsView::GetWindowTitle() const {
+ return l10n_util::GetString(IDS_PASSWORD_MANAGER_EXCEPTIONS_VIEW_TITLE);
+}
+
+void PasswordManagerExceptionsView::ButtonPressed(views::NativeButton* sender) {
+ DCHECK(window());
+ // Close will result in our destruction.
+ if (sender == &remove_all_button_) {
+ table_model_.ForgetAndRemoveAllSignons();
+ return;
+ }
+
+ // The following require a selection (and only one, since table is single-
+ // select only).
+ views::TableSelectionIterator iter = table_view_->SelectionBegin();
+ int row = *iter;
+ PasswordForm* selected = table_model_.GetPasswordFormAt(row);
+ DCHECK(++iter == table_view_->SelectionEnd());
+
+ if (sender == &remove_button_) {
+ table_model_.ForgetAndRemoveSignon(row);
+ } else {
+ NOTREACHED() << "Invalid button.";
+ }
+}
+
+void PasswordManagerExceptionsView::WindowClosing() {
+ // The table model will be deleted before the table view, so detach it.
+ table_view_->SetModel(NULL);
+
+ // Clear the static instance so the next time Show() is called, a new
+ // instance is created.
+ instance_ = NULL;
+}
+
+views::View* PasswordManagerExceptionsView::GetContentsView() {
+ return this;
+}
diff --git a/chrome/browser/views/password_manager_exceptions_view.h b/chrome/browser/views/password_manager_exceptions_view.h
new file mode 100755
index 0000000..1ae684c
--- /dev/null
+++ b/chrome/browser/views/password_manager_exceptions_view.h
@@ -0,0 +1,93 @@
+// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_PASSWORD_MANAGER_EXCEPTIONS_VIEW_H__
+#define CHROME_BROWSER_PASSWORD_MANAGER_EXCEPTIONS_VIEW_H__
+
+#include <vector>
+
+#include "base/scoped_ptr.h"
+#include "chrome/browser/views/password_manager_view.h"
+#include "chrome/browser/webdata/web_data_service.h"
+#include "chrome/common/stl_util-inl.h"
+#include "chrome/common/gfx/text_elider.h"
+#include "chrome/views/dialog_delegate.h"
+#include "chrome/views/label.h"
+#include "chrome/views/native_button.h"
+#include "chrome/views/table_view.h"
+#include "chrome/views/window.h"
+#include "webkit/glue/password_form.h"
+
+class PasswordManagerExceptionsTableModel : public PasswordManagerTableModel {
+ public:
+ explicit PasswordManagerExceptionsTableModel(Profile* profile);
+ virtual ~PasswordManagerExceptionsTableModel();
+
+ // TableModel methods.
+ virtual std::wstring GetText(int row, int column);
+ virtual int CompareValues(int row1, int row2, int col_id);
+
+ // WebDataServiceConsumer implementation.
+ virtual void OnWebDataServiceRequestDone(WebDataService::Handle h,
+ const WDTypedResult* result);
+ // Request all logins data.
+ void GetAllExceptionsForProfile();
+};
+
+class PasswordManagerExceptionsView : public views::View,
+ public views::DialogDelegate,
+ public views::TableViewObserver,
+ public views::NativeButton::Listener {
+ public:
+ explicit PasswordManagerExceptionsView(Profile* profile);
+ virtual ~PasswordManagerExceptionsView();
+
+ // Show the PasswordManagerExceptionsView for the given profile.
+ static void Show(Profile* profile);
+
+ // View methods.
+ virtual void Layout();
+ virtual gfx::Size GetPreferredSize();
+ virtual void ViewHierarchyChanged(bool is_add, views::View* parent,
+ views::View* child);
+
+ // views::TableViewObserver implementation.
+ virtual void OnSelectionChanged();
+
+ // NativeButton::Listener implementation.
+ virtual void ButtonPressed(views::NativeButton* sender);
+
+ // views::DialogDelegate methods:
+ virtual int GetDialogButtons() const;
+ virtual bool CanResize() const { return true; }
+ virtual bool CanMaximize() const { return false; }
+ virtual bool IsAlwaysOnTop() const { return false; }
+ virtual bool HasAlwaysOnTopMenu() const { return false; }
+ virtual std::wstring GetWindowTitle() const;
+ virtual void WindowClosing();
+ virtual views::View* GetContentsView();
+
+ private:
+ // Wire up buttons, the model, and the table view, and query the DB for
+ // exception data tied to the given profile.
+ void Init();
+
+ // Helper to configure our buttons and labels.
+ void SetupButtons();
+
+ // Helper to configure our table view.
+ void SetupTable();
+
+ // Components in this view.
+ PasswordManagerExceptionsTableModel table_model_;
+ views::TableView* table_view_;
+
+ // The buttons and labels.
+ views::NativeButton remove_button_;
+ views::NativeButton remove_all_button_;
+
+ DISALLOW_EVIL_CONSTRUCTORS(PasswordManagerExceptionsView);
+};
+#endif // CHROME_BROWSER_PASSWORD_MANAGER_EXCEPTIONS_VIEW_H__
+
diff --git a/chrome/browser/views/password_manager_view.h b/chrome/browser/views/password_manager_view.h
index 1a02914..c3a1b1a 100644
--- a/chrome/browser/views/password_manager_view.h
+++ b/chrome/browser/views/password_manager_view.h
@@ -49,7 +49,7 @@ class PasswordManagerTableModel : public views::TableModel,
// Return the PasswordForm at the specified index.
PasswordForm* GetPasswordFormAt(int row);
- private:
+ protected:
// Wraps the PasswordForm from the database and caches the display URL for
// quick sorting.
struct PasswordRow {
@@ -64,9 +64,6 @@ class PasswordManagerTableModel : public views::TableModel,
scoped_ptr<PasswordForm> form;
};
- // Cancel any pending login query involving a callback.
- void CancelLoginsQuery();
-
// The web data service associated with the currently active profile.
WebDataService* web_data_service() {
return profile_->GetWebDataService(Profile::EXPLICIT_ACCESS);
@@ -85,6 +82,10 @@ class PasswordManagerTableModel : public views::TableModel,
Profile* profile_;
+ private:
+ // Cancel any pending login query involving a callback.
+ void CancelLoginsQuery();
+
DISALLOW_EVIL_CONSTRUCTORS(PasswordManagerTableModel);
};