summaryrefslogtreecommitdiffstats
path: root/chrome/browser/views/options
diff options
context:
space:
mode:
authorbulach@chromium.org <bulach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-25 13:50:48 +0000
committerbulach@chromium.org <bulach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-25 13:50:48 +0000
commit8f9aefdd9324680937c83b2137ecba8584322245 (patch)
tree7ace3e1ab52d41b24f8f268c8e29592253019ac9 /chrome/browser/views/options
parent099fdcd5ff79ae6815f052060a605ad9a3454ad5 (diff)
downloadchromium_src-8f9aefdd9324680937c83b2137ecba8584322245.zip
chromium_src-8f9aefdd9324680937c83b2137ecba8584322245.tar.gz
chromium_src-8f9aefdd9324680937c83b2137ecba8584322245.tar.bz2
Adds local storage nodes to cookie tree model and cookies view.
BUG=none TEST=The show cookie dialog box should have a new node "local storage" when appropriate. When selected, it should display details of local storage (name, size on disk, last modified) in the details frame. Review URL: http://codereview.chromium.org/523139 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@37001 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views/options')
-rw-r--r--chrome/browser/views/options/cookies_view.cc166
-rw-r--r--chrome/browser/views/options/cookies_view.h57
2 files changed, 208 insertions, 15 deletions
diff --git a/chrome/browser/views/options/cookies_view.cc b/chrome/browser/views/options/cookies_view.cc
index 7e5f0b4..2500e7e 100644
--- a/chrome/browser/views/options/cookies_view.cc
+++ b/chrome/browser/views/options/cookies_view.cc
@@ -31,7 +31,6 @@ static const int kCookieInfoViewBorderSize = 1;
static const int kCookieInfoViewInsetSize = 3;
static const int kSearchFilterDelayMs = 500;
-
///////////////////////////////////////////////////////////////////////////////
// CookiesTreeView
// Overridden to handle Delete key presses
@@ -49,20 +48,19 @@ class CookiesTreeView : public views::TreeView {
};
CookiesTreeView::CookiesTreeView(CookiesTreeModel* cookies_model) {
- SetModel(cookies_model);
- SetRootShown(false);
- SetEditable(false);
+ SetModel(cookies_model);
+ SetRootShown(false);
+ SetEditable(false);
}
void CookiesTreeView::RemoveSelectedItems() {
TreeModelNode* selected_node = GetSelectedNode();
if (selected_node) {
static_cast<CookiesTreeModel*>(model())->DeleteCookieNode(
- static_cast<CookieTreeCookieNode*>(GetSelectedNode()));
+ static_cast<CookieTreeNode*>(GetSelectedNode()));
}
}
-
///////////////////////////////////////////////////////////////////////////////
// CookieInfoView, public:
@@ -253,6 +251,123 @@ void CookieInfoView::Init() {
}
///////////////////////////////////////////////////////////////////////////////
+// LocalStorageInfoView, public:
+
+LocalStorageInfoView::LocalStorageInfoView()
+ : origin_label_(NULL),
+ origin_value_field_(NULL),
+ size_label_(NULL),
+ size_value_field_(NULL),
+ last_modified_label_(NULL),
+ last_modified_value_field_(NULL) {
+}
+
+LocalStorageInfoView::~LocalStorageInfoView() {
+}
+
+void LocalStorageInfoView::SetLocalStorageInfo(
+ const BrowsingDataLocalStorageHelper::LocalStorageInfo&
+ local_storage_info) {
+ origin_value_field_->SetText(UTF8ToWide(local_storage_info.origin));
+ size_value_field_->SetText(
+ FormatBytes(local_storage_info.size,
+ GetByteDisplayUnits(local_storage_info.size),
+ true));
+ last_modified_value_field_->SetText(
+ base::TimeFormatFriendlyDateAndTime(local_storage_info.last_modified));
+ EnableLocalStorageDisplay(true);
+}
+
+void LocalStorageInfoView::EnableLocalStorageDisplay(bool enabled) {
+ origin_value_field_->SetEnabled(enabled);
+ size_value_field_->SetEnabled(enabled);
+ last_modified_value_field_->SetEnabled(enabled);
+}
+
+void LocalStorageInfoView::ClearLocalStorageDisplay() {
+ std::wstring no_cookie_string =
+ l10n_util::GetString(IDS_COOKIES_COOKIE_NONESELECTED);
+ origin_value_field_->SetText(no_cookie_string);
+ size_value_field_->SetText(no_cookie_string);
+ last_modified_value_field_->SetText(no_cookie_string);
+ EnableLocalStorageDisplay(false);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// LocalStorageInfoView, views::View overrides:
+
+void LocalStorageInfoView::ViewHierarchyChanged(bool is_add,
+ views::View* parent,
+ views::View* child) {
+ if (is_add && child == this)
+ Init();
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// LocalStorageInfoView, private:
+
+void LocalStorageInfoView::Init() {
+ SkColor border_color = color_utils::GetSysSkColor(COLOR_3DSHADOW);
+ views::Border* border = views::Border::CreateSolidBorder(
+ kCookieInfoViewBorderSize, border_color);
+ set_border(border);
+
+ origin_label_ = new views::Label(
+ l10n_util::GetString(IDS_COOKIES_LOCAL_STORAGE_ORIGIN_LABEL));
+ origin_value_field_ = new views::Textfield;
+ size_label_ = new views::Label(
+ l10n_util::GetString(IDS_COOKIES_LOCAL_STORAGE_SIZE_ON_DISK_LABEL));
+ size_value_field_ = new views::Textfield;
+ last_modified_label_ = new views::Label(
+ l10n_util::GetString(IDS_COOKIES_LOCAL_STORAGE_LAST_MODIFIED_LABEL));
+ last_modified_value_field_ = new views::Textfield;
+
+ using views::GridLayout;
+ using views::ColumnSet;
+
+ GridLayout* layout = new GridLayout(this);
+ layout->SetInsets(kCookieInfoViewInsetSize,
+ kCookieInfoViewInsetSize,
+ kCookieInfoViewInsetSize,
+ kCookieInfoViewInsetSize);
+ SetLayoutManager(layout);
+
+ int three_column_layout_id = 0;
+ ColumnSet* column_set = layout->AddColumnSet(three_column_layout_id);
+ column_set->AddColumn(GridLayout::TRAILING, GridLayout::CENTER, 0,
+ GridLayout::USE_PREF, 0, 0);
+ column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing);
+ column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1,
+ GridLayout::USE_PREF, 0, 0);
+
+ layout->StartRow(0, three_column_layout_id);
+ layout->AddView(origin_label_);
+ layout->AddView(origin_value_field_);
+ layout->AddPaddingRow(0, kRelatedControlSmallVerticalSpacing);
+ layout->StartRow(0, three_column_layout_id);
+ layout->AddView(size_label_);
+ layout->AddView(size_value_field_);
+ layout->AddPaddingRow(0, kRelatedControlSmallVerticalSpacing);
+ layout->StartRow(0, three_column_layout_id);
+ layout->AddView(last_modified_label_);
+ layout->AddView(last_modified_value_field_);
+
+ // Color these borderless text areas the same as the containing dialog.
+ SkColor text_area_background = color_utils::GetSysSkColor(COLOR_3DFACE);
+ // Now that the Textfields are in the view hierarchy, we can initialize them.
+ origin_value_field_->SetReadOnly(true);
+ origin_value_field_->RemoveBorder();
+ origin_value_field_->SetBackgroundColor(text_area_background);
+ size_value_field_->SetReadOnly(true);
+ size_value_field_->RemoveBorder();
+ size_value_field_->SetBackgroundColor(text_area_background);
+ last_modified_value_field_->SetReadOnly(true);
+ last_modified_value_field_->RemoveBorder();
+ last_modified_value_field_->SetBackgroundColor(text_area_background);
+}
+
+
+///////////////////////////////////////////////////////////////////////////////
// CookiesView, public:
// static
@@ -371,10 +486,17 @@ void CookiesView::OnTreeViewSelectionChanged(views::TreeView* tree_view) {
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);
+ UpdateVisibleDetailedInfo(cookie_info_view_);
+ cookie_info_view_->SetCookie(detailed_info.cookie->first,
+ detailed_info.cookie->second);
+ } else if (detailed_info.node_type ==
+ CookieTreeNode::DetailedInfo::TYPE_LOCAL_STORAGE) {
+ UpdateVisibleDetailedInfo(local_storage_info_view_);
+ local_storage_info_view_->SetLocalStorageInfo(
+ *detailed_info.local_storage_info);
} else {
- info_view_->ClearCookieDisplay();
+ UpdateVisibleDetailedInfo(cookie_info_view_);
+ cookie_info_view_->ClearCookieDisplay();
}
}
@@ -393,7 +515,8 @@ CookiesView::CookiesView(Profile* profile)
clear_search_button_(NULL),
description_label_(NULL),
cookies_tree_(NULL),
- info_view_(NULL),
+ cookie_info_view_(NULL),
+ local_storage_info_view_(NULL),
remove_button_(NULL),
remove_all_button_(NULL),
profile_(profile),
@@ -420,8 +543,10 @@ void CookiesView::Init() {
description_label_ = new views::Label(
l10n_util::GetString(IDS_COOKIES_INFO_LABEL));
description_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
- cookies_tree_model_.reset(new CookiesTreeModel(profile_));
- info_view_ = new CookieInfoView;
+ cookies_tree_model_.reset(new CookiesTreeModel(
+ profile_, new BrowsingDataLocalStorageHelper(profile_)));
+ cookie_info_view_ = new CookieInfoView;
+ local_storage_info_view_ = new LocalStorageInfoView;
cookies_tree_ = new CookiesTreeView(cookies_tree_model_.get());
remove_button_ = new views::NativeButton(
this, l10n_util::GetString(IDS_COOKIES_REMOVE_LABEL));
@@ -469,7 +594,10 @@ void CookiesView::Init() {
layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
layout->StartRow(0, single_column_layout_id);
- layout->AddView(info_view_);
+ layout->AddView(cookie_info_view_, 1, 2);
+
+ layout->StartRow(0, single_column_layout_id);
+ layout->AddView(local_storage_info_view_);
// Add the Remove/Remove All buttons to the ClientView
View* parent = GetParent();
@@ -477,6 +605,8 @@ void CookiesView::Init() {
parent->AddChildView(remove_all_button_);
if (!cookies_tree_model_.get()->GetRoot()->GetChildCount())
UpdateForEmptyState();
+ else
+ UpdateVisibleDetailedInfo(cookie_info_view_);
}
void CookiesView::ResetSearchQuery() {
@@ -486,7 +616,15 @@ void CookiesView::ResetSearchQuery() {
}
void CookiesView::UpdateForEmptyState() {
- info_view_->ClearCookieDisplay();
+ cookie_info_view_->ClearCookieDisplay();
remove_button_->SetEnabled(false);
remove_all_button_->SetEnabled(false);
+ UpdateVisibleDetailedInfo(cookie_info_view_);
+}
+
+void CookiesView::UpdateVisibleDetailedInfo(views::View* view) {
+ view->SetVisible(true);
+ views::View* other = local_storage_info_view_;
+ if (view == local_storage_info_view_) other = cookie_info_view_;
+ other->SetVisible(false);
}
diff --git a/chrome/browser/views/options/cookies_view.h b/chrome/browser/views/options/cookies_view.h
index d7c1b23..91d6cf4a 100644
--- a/chrome/browser/views/options/cookies_view.h
+++ b/chrome/browser/views/options/cookies_view.h
@@ -8,6 +8,7 @@
#include <string>
#include "base/task.h"
+#include "chrome/browser/browsing_data_local_storage_helper.h"
#include "net/base/cookie_monster.h"
#include "views/controls/button/button.h"
#include "views/controls/tree/tree_view.h"
@@ -24,9 +25,11 @@ class NativeButton;
} // namespace views
+class BrowsingDataLocalStorageHelper;
class CookieInfoView;
class CookiesTreeModel;
class CookiesTreeView;
+class LocalStorageInfoView;
class Profile;
class Timer;
@@ -96,13 +99,23 @@ class CookiesView : public views::View,
// Update the UI when there are no cookies.
void UpdateForEmptyState();
+ // Update the UI when a cookie is selected.
+ void UpdateForCookieState();
+
+ // Update the UI when a local storage is selected.
+ void UpdateForLocalStorageState();
+
+ // Updates view to be visible inside detailed_info_view_;
+ void UpdateVisibleDetailedInfo(views::View* view);
+
// Assorted dialog controls
views::Label* search_label_;
views::Textfield* search_field_;
views::NativeButton* clear_search_button_;
views::Label* description_label_;
CookiesTreeView* cookies_tree_;
- CookieInfoView* info_view_;
+ CookieInfoView* cookie_info_view_;
+ LocalStorageInfoView* local_storage_info_view_;
views::NativeButton* remove_button_;
views::NativeButton* remove_all_button_;
@@ -172,4 +185,46 @@ class CookieInfoView : public views::View {
DISALLOW_COPY_AND_ASSIGN(CookieInfoView);
};
+///////////////////////////////////////////////////////////////////////////////
+// LocalStorageInfoView
+//
+// Responsible for displaying a tabular grid of Local Storage information.
+class LocalStorageInfoView : public views::View {
+ public:
+ LocalStorageInfoView();
+ virtual ~LocalStorageInfoView();
+
+ // Update the display from the specified Local Storage info.
+ void SetLocalStorageInfo(
+ const BrowsingDataLocalStorageHelper::LocalStorageInfo&
+ local_storage_info);
+
+ // Clears the cookie display to indicate that no or multiple local storages
+ // are selected.
+ void ClearLocalStorageDisplay();
+
+ // Enables or disables the local storate property text fields.
+ void EnableLocalStorageDisplay(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* origin_label_;
+ views::Textfield* origin_value_field_;
+ views::Label* size_label_;
+ views::Textfield* size_value_field_;
+ views::Label* last_modified_label_;
+ views::Textfield* last_modified_value_field_;
+
+ DISALLOW_COPY_AND_ASSIGN(LocalStorageInfoView);
+};
+
+
#endif // CHROME_BROWSER_VIEWS_OPTIONS_COOKIES_VIEW_H_