summaryrefslogtreecommitdiffstats
path: root/chrome/browser/views/options/cookies_view.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/views/options/cookies_view.cc')
-rw-r--r--chrome/browser/views/options/cookies_view.cc263
1 files changed, 62 insertions, 201 deletions
diff --git a/chrome/browser/views/options/cookies_view.cc b/chrome/browser/views/options/cookies_view.cc
index 924480c..2fe5ac7 100644
--- a/chrome/browser/views/options/cookies_view.cc
+++ b/chrome/browser/views/options/cookies_view.cc
@@ -12,7 +12,7 @@
#include "base/i18n/time_formatting.h"
#include "base/message_loop.h"
#include "base/string_util.h"
-#include "chrome/browser/cookies_table_model.h"
+#include "chrome/browser/cookies_tree_model.h"
#include "chrome/browser/profile.h"
#include "grit/generated_resources.h"
#include "grit/locale_settings.h"
@@ -21,7 +21,7 @@
#include "views/grid_layout.h"
#include "views/controls/label.h"
#include "views/controls/button/native_button.h"
-#include "views/controls/table/table_view.h"
+#include "views/controls/tree/tree_view.h"
#include "views/controls/textfield/textfield.h"
#include "views/standard_layout.h"
@@ -29,116 +29,42 @@
views::Window* CookiesView::instance_ = NULL;
static const int kCookieInfoViewBorderSize = 1;
static const int kCookieInfoViewInsetSize = 3;
-static const int kSearchFilterDelayMs = 500;
+
///////////////////////////////////////////////////////////////////////////////
-// CookiesTableView
+// CookiesTreeView
// Overridden to handle Delete key presses
-class CookiesTableView : public views::TableView {
+class CookiesTreeView : public views::TreeView {
public:
- CookiesTableView(CookiesTableModel* cookies_model,
- std::vector<TableColumn> columns);
- virtual ~CookiesTableView() {}
+ explicit CookiesTreeView(CookiesTreeModel* cookies_model);
+ virtual ~CookiesTreeView() {}
- // Removes the cookies associated with the selected rows in the TableView.
- void RemoveSelectedCookies();
+ // Removes the items associated with the selected node in the TreeView
+ void RemoveSelectedItems();
private:
- // Our model, as a CookiesTableModel.
- CookiesTableModel* cookies_model_;
+ // Our model, as a CookiesTreeModel.
+ CookiesTreeModel* cookies_model_;
- DISALLOW_COPY_AND_ASSIGN(CookiesTableView);
+ DISALLOW_COPY_AND_ASSIGN(CookiesTreeView);
};
-CookiesTableView::CookiesTableView(
- CookiesTableModel* cookies_model,
- std::vector<TableColumn> columns)
- : views::TableView(cookies_model, columns, views::ICON_AND_TEXT, false,
- true, true),
- cookies_model_(cookies_model) {
+CookiesTreeView::CookiesTreeView(CookiesTreeModel* cookies_model)
+ : cookies_model_(cookies_model) {
+ SetModel(cookies_model_);
+ SetRootShown(false);
+ SetEditable(false);
}
-void CookiesTableView::RemoveSelectedCookies() {
- // It's possible that we don't have anything selected.
- if (SelectedRowCount() <= 0)
- return;
-
- if (SelectedRowCount() == cookies_model_->RowCount()) {
- cookies_model_->RemoveAllShownCookies();
- return;
- }
-
- // Remove the selected cookies. This iterates over the rows backwards, which
- // is required when calling RemoveCookies, see bug 2994.
- int last_selected_view_row = -1;
- int remove_count = 0;
- for (views::TableView::iterator i = SelectionBegin();
- i != SelectionEnd(); ++i) {
- int selected_model_row = *i;
- ++remove_count;
- if (last_selected_view_row == -1) {
- // Store the view row since the view to model mapping changes when
- // we delete.
- last_selected_view_row = model_to_view(selected_model_row);
- }
- cookies_model_->RemoveCookies(selected_model_row, 1);
+void CookiesTreeView::RemoveSelectedItems() {
+ TreeModelNode* selected_node = GetSelectedNode();
+ if (selected_node) {
+ cookies_model_->DeleteCookieNode(static_cast<CookieTreeCookieNode*>(
+ GetSelectedNode()));
}
-
- // Select the next row after the last row deleted (unless removing last row).
- DCHECK(RowCount() > 0 && last_selected_view_row != -1);
- Select(view_to_model(std::min(RowCount() - 1,
- last_selected_view_row - remove_count + 1)));
}
-///////////////////////////////////////////////////////////////////////////////
-// CookieInfoView
-//
-// Responsible for displaying a tabular grid of Cookie information.
-class CookieInfoView : public views::View {
- public:
- CookieInfoView();
- virtual ~CookieInfoView();
-
- // Update the display from the specified CookieNode.
- void SetCookie(const std::string& domain,
- const net::CookieMonster::CanonicalCookie& cookie_node);
-
- // Clears the cookie display to indicate that no or multiple cookies are
- // selected.
- void ClearCookieDisplay();
-
- // Enables or disables the cookie proerty text fields.
- void EnableCookieDisplay(bool enabled);
-
- protected:
- // views::View overrides:
- virtual void ViewHierarchyChanged(bool is_add,
- views::View* parent,
- views::View* child);
-
- private:
- // Set up the view layout
- void Init();
-
- // Individual property labels
- views::Label* name_label_;
- views::Textfield* name_value_field_;
- views::Label* content_label_;
- views::Textfield* content_value_field_;
- views::Label* domain_label_;
- views::Textfield* domain_value_field_;
- views::Label* path_label_;
- views::Textfield* path_value_field_;
- views::Label* send_for_label_;
- views::Textfield* send_for_value_field_;
- views::Label* created_label_;
- views::Textfield* created_value_field_;
- views::Label* expires_label_;
- views::Textfield* expires_value_field_;
-
- DISALLOW_COPY_AND_ASSIGN(CookieInfoView);
-};
///////////////////////////////////////////////////////////////////////////////
// CookieInfoView, public:
@@ -347,12 +273,7 @@ void CookiesView::ShowCookiesWindow(Profile* profile) {
}
CookiesView::~CookiesView() {
- cookies_table_->SetModel(NULL);
-}
-
-void CookiesView::UpdateSearchResults() {
- cookies_table_model_->UpdateSearchResults(search_field_->text());
- remove_all_button_->SetEnabled(cookies_table_model_->RowCount() > 0);
+ cookies_tree_->SetModel(NULL);
}
///////////////////////////////////////////////////////////////////////////////
@@ -361,67 +282,18 @@ void CookiesView::UpdateSearchResults() {
void CookiesView::ButtonPressed(
views::Button* sender, const views::Event& event) {
if (sender == remove_button_) {
- cookies_table_->RemoveSelectedCookies();
+ cookies_tree_->RemoveSelectedItems();
} else if (sender == remove_all_button_) {
- // Delete all the Cookies shown.
- cookies_table_model_->RemoveAllShownCookies();
- UpdateForEmptyState();
- } else if (sender == clear_search_button_) {
- ResetSearchQuery();
- }
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// CookiesView, views::TableViewObserver implementation:
-void CookiesView::OnSelectionChanged() {
- int selected_row_count = cookies_table_->SelectedRowCount();
- if (selected_row_count == 1) {
- int selected_index = cookies_table_->FirstSelectedRow();
- if (selected_index >= 0 &&
- selected_index < cookies_table_model_->RowCount()) {
- info_view_->SetCookie(cookies_table_model_->GetDomainAt(selected_index),
- cookies_table_model_->GetCookieAt(selected_index));
- }
- } else {
- info_view_->ClearCookieDisplay();
- }
- remove_button_->SetEnabled(selected_row_count != 0);
- if (cookies_table_->RowCount() == 0)
+ cookies_tree_model_->DeleteAllCookies();
UpdateForEmptyState();
-}
-
-void CookiesView::OnTableViewDelete(views::TableView* table_view) {
- cookies_table_->RemoveSelectedCookies();
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// CookiesView, views::Textfield::Controller implementation:
-
-void CookiesView::ContentsChanged(views::Textfield* sender,
- const std::wstring& new_contents) {
- clear_search_button_->SetEnabled(!search_field_->text().empty());
- search_update_factory_.RevokeAll();
- MessageLoop::current()->PostDelayedTask(FROM_HERE,
- search_update_factory_.NewRunnableMethod(
- &CookiesView::UpdateSearchResults), kSearchFilterDelayMs);
-}
-
-bool CookiesView::HandleKeystroke(views::Textfield* sender,
- const views::Textfield::Keystroke& key) {
- if (key.GetKeyboardCode() == base::VKEY_ESCAPE) {
- ResetSearchQuery();
- } else if (key.GetKeyboardCode() == base::VKEY_RETURN) {
- search_update_factory_.RevokeAll();
- UpdateSearchResults();
}
- return false;
}
///////////////////////////////////////////////////////////////////////////////
// CookiesView, views::DialogDelegate implementation:
std::wstring CookiesView::GetWindowTitle() const {
- return l10n_util::GetString(IDS_COOKIES_WINDOW_TITLE);
+ return l10n_util::GetString(IDS_COOKIES_WEBSITE_PERMISSIONS_WINDOW_TITLE);
}
void CookiesView::WindowClosing() {
@@ -468,50 +340,49 @@ void CookiesView::ViewHierarchyChanged(bool is_add,
}
///////////////////////////////////////////////////////////////////////////////
+// CookiesView, views::TreeViewController overrides:
+
+void CookiesView::OnTreeViewSelectionChanged(views::TreeView* tree_view) {
+ CookieTreeNode::DetailedInfo detailed_info =
+ static_cast<CookieTreeNode*>(tree_view->GetSelectedNode())->
+ GetDetailedInfo();
+ if (detailed_info.node_type == CookieTreeNode::DetailedInfo::TYPE_COOKIE) {
+ info_view_->SetCookie(detailed_info.cookie->first,
+ detailed_info.cookie->second);
+ } else {
+ info_view_->ClearCookieDisplay();
+ }
+}
+
+void CookiesView::OnTreeViewKeyDown(base::KeyboardCode keycode) {
+ if (keycode == base::VKEY_DELETE)
+ cookies_tree_->RemoveSelectedItems();
+}
+
+///////////////////////////////////////////////////////////////////////////////
// CookiesView, private:
CookiesView::CookiesView(Profile* profile)
- : search_label_(NULL),
- search_field_(NULL),
- clear_search_button_(NULL),
+ :
description_label_(NULL),
- cookies_table_(NULL),
+ cookies_tree_(NULL),
info_view_(NULL),
remove_button_(NULL),
remove_all_button_(NULL),
- profile_(profile),
- ALLOW_THIS_IN_INITIALIZER_LIST(search_update_factory_(this)) {
+ profile_(profile) {
+}
+
+views::View* CookiesView::GetInitiallyFocusedView() {
+ return cookies_tree_;
}
void CookiesView::Init() {
- search_label_ = new views::Label(
- l10n_util::GetString(IDS_COOKIES_SEARCH_LABEL));
- search_field_ = new views::Textfield;
- search_field_->SetController(this);
- clear_search_button_ = new views::NativeButton(
- this, l10n_util::GetString(IDS_COOKIES_CLEAR_SEARCH_LABEL));
- clear_search_button_->SetEnabled(false);
description_label_ = new views::Label(
l10n_util::GetString(IDS_COOKIES_INFO_LABEL));
description_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
-
- cookies_table_model_.reset(new CookiesTableModel(profile_));
+ cookies_tree_model_.reset(new CookiesTreeModel(profile_));
info_view_ = new CookieInfoView;
- std::vector<TableColumn> columns;
- columns.push_back(TableColumn(IDS_COOKIES_DOMAIN_COLUMN_HEADER,
- TableColumn::LEFT, 200, 0.5f));
- columns.back().sortable = true;
- columns.push_back(TableColumn(IDS_COOKIES_NAME_COLUMN_HEADER,
- TableColumn::LEFT, 150, 0.5f));
- columns.back().sortable = true;
- cookies_table_ = new CookiesTableView(cookies_table_model_.get(), columns);
- cookies_table_->SetObserver(this);
- // Make the table initially sorted by domain.
- views::TableView::SortDescriptors sort;
- sort.push_back(
- views::TableView::SortDescriptor(IDS_COOKIES_DOMAIN_COLUMN_HEADER,
- true));
- cookies_table_->SetSortDescriptors(sort);
+ cookies_tree_ = new CookiesTreeView(cookies_tree_model_.get());
remove_button_ = new views::NativeButton(
this, l10n_util::GetString(IDS_COOKIES_REMOVE_LABEL));
remove_all_button_ = new views::NativeButton(
@@ -539,16 +410,16 @@ void CookiesView::Init() {
column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1,
GridLayout::USE_PREF, 0, 0);
- layout->StartRow(0, five_column_layout_id);
- layout->AddView(search_label_);
- layout->AddView(search_field_);
- layout->AddView(clear_search_button_);
- layout->AddPaddingRow(0, kUnrelatedControlVerticalSpacing);
layout->StartRow(0, single_column_layout_id);
layout->AddView(description_label_);
+
layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
layout->StartRow(1, single_column_layout_id);
- layout->AddView(cookies_table_);
+ layout->AddView(cookies_tree_);
+ cookies_tree_->ExpandAll();
+
+ cookies_tree_->SetController(this);
+
layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
layout->StartRow(0, single_column_layout_id);
layout->AddView(info_view_);
@@ -557,18 +428,8 @@ void CookiesView::Init() {
View* parent = GetParent();
parent->AddChildView(remove_button_);
parent->AddChildView(remove_all_button_);
-
- if (cookies_table_->RowCount() > 0) {
- cookies_table_->Select(0);
- } else {
+ if (!cookies_tree_model_.get()->GetRoot()->GetChildCount())
UpdateForEmptyState();
- }
-}
-
-void CookiesView::ResetSearchQuery() {
- search_field_->SetText(EmptyWString());
- clear_search_button_->SetEnabled(false);
- UpdateSearchResults();
}
void CookiesView::UpdateForEmptyState() {