Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(654)

Unified Diff: chrome/browser/views/collected_cookies_win.cc

Issue 3108029: Display an infobar when content settings were created. (Closed)
Patch Set: updates Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/views/collected_cookies_win.cc
diff --git a/chrome/browser/views/collected_cookies_win.cc b/chrome/browser/views/collected_cookies_win.cc
index 1a7f4055e56d59e5430fef27f81110be09cb7407..3f25992d838a6b13d0e7f8072314d89f44438a7e 100644
--- a/chrome/browser/views/collected_cookies_win.cc
+++ b/chrome/browser/views/collected_cookies_win.cc
@@ -5,15 +5,23 @@
#include "chrome/browser/views/collected_cookies_win.h"
#include "app/l10n_util.h"
+#include "app/resource_bundle.h"
#include "chrome/browser/cookies_tree_model.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/common/notification_service.h"
+#include "gfx/color_utils.h"
#include "grit/generated_resources.h"
#include "grit/locale_settings.h"
-#include "views/controls/label.h"
+#include "grit/theme_resources.h"
+#include "views/box_layout.h"
#include "views/controls/button/native_button.h"
+#include "views/controls/image_view.h"
+#include "views/controls/label.h"
+#include "views/controls/separator.h"
#include "views/standard_layout.h"
+#include "views/widget/root_view.h"
+#include "views/widget/widget_win.h"
#include "views/window/window.h"
namespace browser {
@@ -27,6 +35,119 @@ void ShowCollectedCookiesDialog(gfx::NativeWindow parent_window,
} // namespace browser
+namespace {
+// Spacing between the infobar frame and its contents.
+const int kInfobarVerticalPadding = 3;
+const int kInfobarHorizontalPadding = 8;
+
+// Width of the infobar frame.
+const int kInfobarBorderSize = 1;
+
+// Dimensions of the tree views.
+const int kTreeViewWidth = 400;
+const int kTreeViewHeight = 125;
+
+} // namespace
+
+// A custom view that conditionally displays an infobar.
+class InfobarView : public views::View {
+ public:
+ InfobarView() {
+ content_ = new views::View;
+ SkColor border_color = color_utils::GetSysSkColor(COLOR_3DSHADOW);
+ views::Border* border = views::Border::CreateSolidBorder(
+ kInfobarBorderSize, border_color);
+ content_->set_border(border);
+
+ ResourceBundle& rb = ResourceBundle::GetSharedInstance();
+ info_image_ = new views::ImageView();
+ info_image_->SetImage(rb.GetBitmapNamed(IDR_INFO));
+ label_ = new views::Label();
+ }
+ virtual ~InfobarView() {}
+
+ // Update the visibility of the infobar. If |is_visible| is true, a rule for
+ // |setting| on |domain_name| was created.
+ void UpdateVisibility(bool is_visible,
+ ContentSetting setting,
+ const std::wstring& domain_name) {
+ if (!is_visible) {
+ SetVisible(false);
+ return;
+ }
+
+ std::wstring label;
+ switch (setting) {
+ case CONTENT_SETTING_BLOCK:
+ label = l10n_util::GetStringF(
+ IDS_COLLECTED_COOKIES_BLOCK_RULE_CREATED, domain_name);
+ break;
+
+ case CONTENT_SETTING_ALLOW:
+ label = l10n_util::GetStringF(
+ IDS_COLLECTED_COOKIES_ALLOW_RULE_CREATED, domain_name);
+ break;
+
+ case CONTENT_SETTING_SESSION_ONLY:
+ label = l10n_util::GetStringF(
+ IDS_COLLECTED_COOKIES_SESSION_RULE_CREATED, domain_name);
+ break;
+
+ default:
+ NOTREACHED();
+ }
+ label_->SetText(label);
+ content_->Layout();
+ SetVisible(true);
+ }
+
+ private:
+ // Initialize contents and layout.
+ void Init() {
+ AddChildView(content_);
+ content_->SetLayoutManager(
+ new views::BoxLayout(views::BoxLayout::kHorizontal,
+ kInfobarHorizontalPadding,
+ kInfobarVerticalPadding,
+ kRelatedControlSmallHorizontalSpacing));
+ content_->AddChildView(info_image_);
+ content_->AddChildView(label_);
+ UpdateVisibility(false, CONTENT_SETTING_BLOCK, std::wstring());
+ }
+
+ // views::View overrides.
+ virtual gfx::Size GetPreferredSize() {
+ if (!IsVisible())
+ return gfx::Size();
+
+ // Add space around the banner.
+ gfx::Size size(content_->GetPreferredSize());
+ size.Enlarge(0, 2 * kRelatedControlVerticalSpacing);
+ return size;
+ }
+
+ virtual void Layout() {
+ content_->SetBounds(
+ 0, kRelatedControlVerticalSpacing,
+ width(), height() - kRelatedControlVerticalSpacing);
+ }
+
+ virtual void ViewHierarchyChanged(bool is_add,
+ views::View* parent,
+ views::View* child) {
+ if (is_add && child == this)
+ Init();
+ }
+
+ // Holds the info icon image and text label and renders the border.
+ views::View* content_;
+ // Info icon image.
+ views::ImageView* info_image_;
+ // The label responsible for rendering the text.
+ views::Label* label_;
+
+ DISALLOW_COPY_AND_ASSIGN(InfobarView);
+};
///////////////////////////////////////////////////////////////////////////////
// CollectedCookiesWin, constructor and destructor:
@@ -40,7 +161,8 @@ CollectedCookiesWin::CollectedCookiesWin(gfx::NativeWindow parent_window,
blocked_cookies_tree_(NULL),
block_allowed_button_(NULL),
allow_blocked_button_(NULL),
- for_session_blocked_button_(NULL) {
+ for_session_blocked_button_(NULL),
+ infobar_(NULL) {
TabSpecificContentSettings* content_settings =
tab_contents->GetTabSpecificContentSettings();
registrar_.Add(this, NotificationType::COLLECTED_COOKIES_SHOWN,
@@ -59,6 +181,8 @@ CollectedCookiesWin::~CollectedCookiesWin() {
void CollectedCookiesWin::Init() {
TabSpecificContentSettings* content_settings =
tab_contents_->GetTabSpecificContentSettings();
+ HostContentSettingsMap* host_content_settings_map =
+ tab_contents_->profile()->GetHostContentSettingsMap();
// Allowed Cookie list.
allowed_label_ = new views::Label(
@@ -75,7 +199,12 @@ void CollectedCookiesWin::Init() {
// Blocked Cookie list.
blocked_label_ = new views::Label(
- l10n_util::GetString(IDS_COLLECTED_COOKIES_BLOCKED_COOKIES_LABEL));
+ l10n_util::GetString(
+ host_content_settings_map->BlockThirdPartyCookies() ?
+ IDS_COLLECTED_COOKIES_BLOCKED_THIRD_PARTY_BLOCKING_ENABLED :
+ IDS_COLLECTED_COOKIES_BLOCKED_COOKIES_LABEL));
+ blocked_label_->SetMultiLine(true);
+ blocked_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
blocked_cookies_tree_model_.reset(
content_settings->GetBlockedCookiesTreeModel());
blocked_cookies_tree_ = new views::TreeView();
@@ -110,7 +239,8 @@ void CollectedCookiesWin::Init() {
layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
layout->StartRow(1, single_column_layout_id);
layout->AddView(
- allowed_cookies_tree_, 1, 1, GridLayout::FILL, GridLayout::FILL);
+ allowed_cookies_tree_, 1, 1, GridLayout::FILL, GridLayout::FILL,
+ kTreeViewWidth, kTreeViewHeight);
layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
layout->StartRow(0, single_column_layout_id);
@@ -121,12 +251,18 @@ void CollectedCookiesWin::Init() {
layout->AddPaddingRow(0, kUnrelatedControlVerticalSpacing);
layout->StartRow(0, single_column_layout_id);
- layout->AddView(blocked_label_);
+ layout->AddView(
+ new views::Separator(), 1, 1, GridLayout::FILL, GridLayout::FILL);
+ layout->AddPaddingRow(0, kUnrelatedControlVerticalSpacing);
+
+ layout->StartRow(0, single_column_layout_id);
+ layout->AddView(blocked_label_, 1, 1, GridLayout::FILL, GridLayout::FILL);
layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
layout->StartRow(1, single_column_layout_id);
layout->AddView(
- blocked_cookies_tree_, 1, 1, GridLayout::FILL, GridLayout::FILL);
+ blocked_cookies_tree_, 1, 1, GridLayout::FILL, GridLayout::FILL,
+ kTreeViewWidth, kTreeViewHeight);
layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
layout->StartRow(0, three_columns_layout_id);
@@ -137,6 +273,10 @@ void CollectedCookiesWin::Init() {
this, l10n_util::GetString(IDS_COLLECTED_COOKIES_SESSION_ONLY_BUTTON));
layout->AddView(for_session_blocked_button_);
+ layout->StartRow(0, single_column_layout_id);
+ infobar_ = new InfobarView();
+ layout->AddView(infobar_, 1, 1, GridLayout::FILL, GridLayout::FILL);
+
EnableControls();
}
@@ -190,15 +330,6 @@ void CollectedCookiesWin::OnTreeViewSelectionChanged(
}
///////////////////////////////////////////////////////////////////////////////
-// views::View implementation.
-
-gfx::Size CollectedCookiesWin::GetPreferredSize() {
- return gfx::Size(views::Window::GetLocalizedContentsSize(
- IDS_COOKIES_DIALOG_WIDTH_CHARS,
- IDS_COOKIES_DIALOG_HEIGHT_LINES));
-}
-
-///////////////////////////////////////////////////////////////////////////////
// CollectedCookiesWin, private methods.
void CollectedCookiesWin::EnableControls() {
@@ -234,6 +365,17 @@ void CollectedCookiesWin::AddContentException(views::TreeView* tree_view,
static_cast<CookieTreeOriginNode*>(tree_view->GetSelectedNode());
origin_node->CreateContentException(
tab_contents_->profile()->GetHostContentSettingsMap(), setting);
+ infobar_->UpdateVisibility(true, setting, origin_node->GetTitle());
+ gfx::Rect bounds;
+ GetWidget()->GetBounds(&bounds, false);
+ // WidgetWin::GetBounds returns the bounds relative to the parent window,
+ // while WidgetWin::SetBounds wants screen coordinates. Do the translation
+ // here until http://crbug.com/52851 is fixed.
+ POINT topleft = {bounds.x(), bounds.y()};
+ MapWindowPoints(HWND_DESKTOP, tab_contents_->GetNativeView(), &topleft, 1);
+ gfx::Size size = GetRootView()->GetPreferredSize();
+ bounds.SetRect(topleft.x, topleft.y, size.width(), size.height());
+ GetWidget()->SetBounds(bounds);
}
///////////////////////////////////////////////////////////////////////////////
« no previous file with comments | « chrome/browser/views/collected_cookies_win.h ('k') | chrome/browser/views/options/managed_prefs_banner_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698