diff options
author | jochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-10 18:13:40 +0000 |
---|---|---|
committer | jochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-10 18:13:40 +0000 |
commit | b5c6e3061b38fc9936063c4b95a6fdb36dcd494d (patch) | |
tree | c33e9e39fe93750f0947b046f686df44d5ca5182 /chrome/browser/views | |
parent | 042c368e489772c0ff89f25beb396a948659a268 (diff) | |
download | chromium_src-b5c6e3061b38fc9936063c4b95a6fdb36dcd494d.zip chromium_src-b5c6e3061b38fc9936063c4b95a6fdb36dcd494d.tar.gz chromium_src-b5c6e3061b38fc9936063c4b95a6fdb36dcd494d.tar.bz2 |
Add support for HTML5 databases to the cookie tree model.
BUG=34633
TEST=create local databases, open cookie tree view from prefs.
Review URL: http://codereview.chromium.org/596009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38635 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views')
-rwxr-xr-x | chrome/browser/views/database_info_view.cc | 131 | ||||
-rwxr-xr-x | chrome/browser/views/database_info_view.h | 57 | ||||
-rw-r--r-- | chrome/browser/views/options/cookies_view.cc | 26 | ||||
-rw-r--r-- | chrome/browser/views/options/cookies_view.h | 7 |
4 files changed, 213 insertions, 8 deletions
diff --git a/chrome/browser/views/database_info_view.cc b/chrome/browser/views/database_info_view.cc new file mode 100755 index 0000000..aff6df5 --- /dev/null +++ b/chrome/browser/views/database_info_view.cc @@ -0,0 +1,131 @@ +// Copyright (c) 2010 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 "chrome/browser/views/database_info_view.h" + +#include <algorithm> + +#include "app/gfx/color_utils.h" +#include "app/l10n_util.h" +#include "base/i18n/time_formatting.h" +#include "base/string_util.h" +#include "grit/generated_resources.h" +#include "views/grid_layout.h" +#include "views/controls/label.h" +#include "views/controls/textfield/textfield.h" +#include "views/standard_layout.h" + +static const int kDatabaseInfoViewBorderSize = 1; +static const int kDatabaseInfoViewInsetSize = 3; + +/////////////////////////////////////////////////////////////////////////////// +// DatabaseInfoView, public: + +DatabaseInfoView::DatabaseInfoView() + : description_value_field_(NULL), + size_value_field_(NULL), + last_modified_value_field_(NULL) { +} + +DatabaseInfoView::~DatabaseInfoView() { +} + +void DatabaseInfoView::SetDatabaseInfo( + const BrowsingDataDatabaseHelper::DatabaseInfo& database_info) { + description_value_field_->SetText(UTF8ToWide(database_info.description)); + size_value_field_->SetText( + FormatBytes(database_info.size, + GetByteDisplayUnits(database_info.size), + true)); + last_modified_value_field_->SetText( + base::TimeFormatFriendlyDateAndTime(database_info.last_modified)); + EnableDatabaseDisplay(true); +} + +void DatabaseInfoView::EnableDatabaseDisplay(bool enabled) { + description_value_field_->SetEnabled(enabled); + size_value_field_->SetEnabled(enabled); + last_modified_value_field_->SetEnabled(enabled); +} + +void DatabaseInfoView::ClearDatabaseDisplay() { + std::wstring no_cookie_string = + l10n_util::GetString(IDS_COOKIES_COOKIE_NONESELECTED); + description_value_field_->SetText(no_cookie_string); + size_value_field_->SetText(no_cookie_string); + last_modified_value_field_->SetText(no_cookie_string); + EnableDatabaseDisplay(false); +} + +/////////////////////////////////////////////////////////////////////////////// +// DatabaseInfoView, views::View overrides: + +void DatabaseInfoView::ViewHierarchyChanged(bool is_add, + views::View* parent, + views::View* child) { + if (is_add && child == this) + Init(); +} + +/////////////////////////////////////////////////////////////////////////////// +// DatabaseInfoView, private: + +void DatabaseInfoView::Init() { + SkColor border_color = color_utils::GetSysSkColor(COLOR_3DSHADOW); + views::Border* border = views::Border::CreateSolidBorder( + kDatabaseInfoViewBorderSize, border_color); + set_border(border); + + views::Label* description_label = new views::Label( + l10n_util::GetString(IDS_COOKIES_WEB_DATABASE_DESCRIPTION_LABEL)); + description_value_field_ = new views::Textfield; + views::Label* size_label = new views::Label( + l10n_util::GetString(IDS_COOKIES_LOCAL_STORAGE_SIZE_ON_DISK_LABEL)); + size_value_field_ = new views::Textfield; + views::Label* 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; + + GridLayout* layout = new GridLayout(this); + layout->SetInsets(kDatabaseInfoViewInsetSize, + kDatabaseInfoViewInsetSize, + kDatabaseInfoViewInsetSize, + kDatabaseInfoViewInsetSize); + SetLayoutManager(layout); + + int three_column_layout_id = 0; + views::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(description_label); + layout->AddView(description_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. + description_value_field_->SetReadOnly(true); + description_value_field_->RemoveBorder(); + description_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); +} diff --git a/chrome/browser/views/database_info_view.h b/chrome/browser/views/database_info_view.h new file mode 100755 index 0000000..a3b6743 --- /dev/null +++ b/chrome/browser/views/database_info_view.h @@ -0,0 +1,57 @@ +// Copyright (c) 2010 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_VIEWS_DATABASE_INFO_VIEW_H_ +#define CHROME_BROWSER_VIEWS_DATABASE_INFO_VIEW_H_ + +#include <string> +#include <vector> + +#include "views/view.h" +#include "chrome/browser/browsing_data_database_helper.h" + +namespace views { +class Label; +class Textfield; +} + +/////////////////////////////////////////////////////////////////////////////// +// DatabaseInfoView +// +// Responsible for displaying a tabular grid of Database information. +class DatabaseInfoView : public views::View { + public: + DatabaseInfoView(); + virtual ~DatabaseInfoView(); + + // Update the display from the specified Database info. + void SetDatabaseInfo( + const BrowsingDataDatabaseHelper::DatabaseInfo& database_info); + + // Clears the cookie display to indicate that no or multiple databases are + // selected. + void ClearDatabaseDisplay(); + + // Enables or disables the database property text fields. + void EnableDatabaseDisplay(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::Textfield* description_value_field_; + views::Textfield* size_value_field_; + views::Textfield* last_modified_value_field_; + + DISALLOW_COPY_AND_ASSIGN(DatabaseInfoView); +}; + + +#endif // CHROME_BROWSER_VIEWS_DATABASE_INFO_VIEW_H_ diff --git a/chrome/browser/views/options/cookies_view.cc b/chrome/browser/views/options/cookies_view.cc index 3e80cf1..bcfa0a20 100644 --- a/chrome/browser/views/options/cookies_view.cc +++ b/chrome/browser/views/options/cookies_view.cc @@ -15,6 +15,7 @@ #include "chrome/browser/cookies_tree_model.h" #include "chrome/browser/profile.h" #include "chrome/browser/views/cookie_info_view.h" +#include "chrome/browser/views/database_info_view.h" #include "chrome/browser/views/local_storage_info_view.h" #include "grit/generated_resources.h" #include "grit/locale_settings.h" @@ -92,7 +93,7 @@ void CookiesView::ButtonPressed( if (cookies_tree_model_->GetRoot()->GetChildCount() == 0) UpdateForEmptyState(); } else if (sender == remove_all_button_) { - cookies_tree_model_->DeleteAllCookies(); + cookies_tree_model_->DeleteAllStoredObjects(); UpdateForEmptyState(); } else if (sender == clear_search_button_) { ResetSearchQuery(); @@ -184,6 +185,10 @@ void CookiesView::OnTreeViewSelectionChanged(views::TreeView* tree_view) { cookie_info_view_->SetCookie(detailed_info.cookie->first, detailed_info.cookie->second); } else if (detailed_info.node_type == + CookieTreeNode::DetailedInfo::TYPE_DATABASE) { + UpdateVisibleDetailedInfo(database_info_view_); + database_info_view_->SetDatabaseInfo(*detailed_info.database_info); + } else if (detailed_info.node_type == CookieTreeNode::DetailedInfo::TYPE_LOCAL_STORAGE) { UpdateVisibleDetailedInfo(local_storage_info_view_); local_storage_info_view_->SetLocalStorageInfo( @@ -210,6 +215,7 @@ CookiesView::CookiesView(Profile* profile) description_label_(NULL), cookies_tree_(NULL), cookie_info_view_(NULL), + database_info_view_(NULL), local_storage_info_view_(NULL), remove_button_(NULL), remove_all_button_(NULL), @@ -237,9 +243,11 @@ 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_, new BrowsingDataLocalStorageHelper(profile_))); + cookies_tree_model_.reset(new CookiesTreeModel(profile_, + new BrowsingDataDatabaseHelper(profile_), + new BrowsingDataLocalStorageHelper(profile_))); cookie_info_view_ = new CookieInfoView(false); + database_info_view_ = new DatabaseInfoView; local_storage_info_view_ = new LocalStorageInfoView; cookies_tree_ = new CookiesTreeView(cookies_tree_model_.get()); remove_button_ = new views::NativeButton( @@ -291,6 +299,9 @@ void CookiesView::Init() { layout->AddView(cookie_info_view_, 1, 2); layout->StartRow(0, single_column_layout_id); + layout->AddView(database_info_view_); + + layout->StartRow(0, single_column_layout_id); layout->AddView(local_storage_info_view_); // Add the Remove/Remove All buttons to the ClientView @@ -318,7 +329,10 @@ void CookiesView::UpdateForEmptyState() { 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); + if (view != cookie_info_view_) + cookie_info_view_->SetVisible(false); + if (view != database_info_view_) + database_info_view_->SetVisible(false); + if (view != local_storage_info_view_) + local_storage_info_view_->SetVisible(false); } diff --git a/chrome/browser/views/options/cookies_view.h b/chrome/browser/views/options/cookies_view.h index 070120e..0010fbc 100644 --- a/chrome/browser/views/options/cookies_view.h +++ b/chrome/browser/views/options/cookies_view.h @@ -8,7 +8,6 @@ #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" @@ -25,10 +24,10 @@ class NativeButton; } // namespace views -class BrowsingDataLocalStorageHelper; class CookieInfoView; class CookiesTreeModel; class CookiesTreeView; +class DatabaseInfoView; class LocalStorageInfoView; class Profile; class Timer; @@ -102,6 +101,9 @@ class CookiesView : public views::View, // Update the UI when a cookie is selected. void UpdateForCookieState(); + // Update the UI when a database is selected. + void UpdateForDatabaseState(); + // Update the UI when a local storage is selected. void UpdateForLocalStorageState(); @@ -115,6 +117,7 @@ class CookiesView : public views::View, views::Label* description_label_; CookiesTreeView* cookies_tree_; CookieInfoView* cookie_info_view_; + DatabaseInfoView* database_info_view_; LocalStorageInfoView* local_storage_info_view_; views::NativeButton* remove_button_; views::NativeButton* remove_all_button_; |