summaryrefslogtreecommitdiffstats
path: root/chrome/browser/views
diff options
context:
space:
mode:
authorjochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-16 13:05:48 +0000
committerjochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-16 13:05:48 +0000
commita503c97cdef81306da6906f117fed3285e032f0e (patch)
tree06939dea41c651133467b098af4dcbb5d49620bb /chrome/browser/views
parentaffa5904ccff332075eedfb2a10797dd1ca8b0f6 (diff)
downloadchromium_src-a503c97cdef81306da6906f117fed3285e032f0e.zip
chromium_src-a503c97cdef81306da6906f117fed3285e032f0e.tar.gz
chromium_src-a503c97cdef81306da6906f117fed3285e032f0e.tar.bz2
Reland r52486. Display a tab modal dialog of the allowed/blocked cookies.
BUG=45230 TEST=CollectedCookiesTest.* Review URL: http://codereview.chromium.org/3034007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@52655 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views')
-rw-r--r--chrome/browser/views/browser_dialogs.h4
-rw-r--r--chrome/browser/views/collected_cookies_win.cc157
-rw-r--r--chrome/browser/views/collected_cookies_win.h79
-rw-r--r--chrome/browser/views/dialog_stubs_gtk.cc6
-rw-r--r--chrome/browser/views/frame/browser_view.cc4
-rw-r--r--chrome/browser/views/frame/browser_view.h1
6 files changed, 251 insertions, 0 deletions
diff --git a/chrome/browser/views/browser_dialogs.h b/chrome/browser/views/browser_dialogs.h
index 1697f13..2adac51 100644
--- a/chrome/browser/views/browser_dialogs.h
+++ b/chrome/browser/views/browser_dialogs.h
@@ -113,6 +113,10 @@ void ShowContentSettingsWindow(gfx::NativeWindow parent_window,
ContentSettingsType content_type,
Profile* profile);
+// Shows the collected cookies dialog box.
+void ShowCollectedCookiesDialog(gfx::NativeWindow parent_window,
+ TabContents* tab_contents);
+
// Shows the create web app shortcut dialog box.
void ShowCreateShortcutsDialog(gfx::NativeWindow parent_window,
TabContents* tab_contents);
diff --git a/chrome/browser/views/collected_cookies_win.cc b/chrome/browser/views/collected_cookies_win.cc
new file mode 100644
index 0000000..b5e5c3c
--- /dev/null
+++ b/chrome/browser/views/collected_cookies_win.cc
@@ -0,0 +1,157 @@
+// 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/collected_cookies_win.h"
+
+#include "app/l10n_util.h"
+#include "chrome/browser/cookies_tree_model.h"
+#include "chrome/browser/tab_contents/tab_contents.h"
+#include "chrome/common/notification_service.h"
+#include "grit/generated_resources.h"
+#include "grit/locale_settings.h"
+#include "views/controls/label.h"
+#include "views/controls/tree/tree_view.h"
+#include "views/standard_layout.h"
+#include "views/window/window.h"
+
+namespace browser {
+
+// Declared in browser_dialogs.h so others don't have to depend on our header.
+void ShowCollectedCookiesDialog(gfx::NativeWindow parent_window,
+ TabContents* tab_contents) {
+ // Deletes itself on close.
+ new CollectedCookiesWin(parent_window, tab_contents);
+}
+
+} // namespace browser
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CollectedCookiesWin, constructor and destructor:
+
+CollectedCookiesWin::CollectedCookiesWin(gfx::NativeWindow parent_window,
+ TabContents* tab_contents)
+ : tab_contents_(tab_contents) {
+ TabSpecificContentSettings* content_settings =
+ tab_contents->GetTabSpecificContentSettings();
+ registrar_.Add(this, NotificationType::COLLECTED_COOKIES_SHOWN,
+ Source<TabSpecificContentSettings>(content_settings));
+
+ Init();
+
+ window_ = tab_contents_->CreateConstrainedDialog(this);
+}
+
+CollectedCookiesWin::~CollectedCookiesWin() {
+ allowed_cookies_tree_->SetModel(NULL);
+ blocked_cookies_tree_->SetModel(NULL);
+}
+
+void CollectedCookiesWin::Init() {
+ TabSpecificContentSettings* content_settings =
+ tab_contents_->GetTabSpecificContentSettings();
+
+ // Allowed Cookie list.
+ allowed_label_ = new views::Label(
+ l10n_util::GetString(IDS_COLLECTED_COOKIES_ALLOWED_COOKIES_LABEL));
+ allowed_cookies_tree_model_.reset(
+ content_settings->GetAllowedCookiesTreeModel());
+ allowed_cookies_tree_ = new views::TreeView();
+ allowed_cookies_tree_->SetModel(allowed_cookies_tree_model_.get());
+ allowed_cookies_tree_->SetRootShown(false);
+ allowed_cookies_tree_->SetEditable(false);
+ allowed_cookies_tree_->set_lines_at_root(true);
+ allowed_cookies_tree_->set_auto_expand_children(true);
+
+ // Blocked Cookie list.
+ blocked_label_ = new views::Label(
+ l10n_util::GetString(IDS_COLLECTED_COOKIES_BLOCKED_COOKIES_LABEL));
+ blocked_cookies_tree_model_.reset(
+ content_settings->GetBlockedCookiesTreeModel());
+ blocked_cookies_tree_ = new views::TreeView();
+ blocked_cookies_tree_->SetModel(blocked_cookies_tree_model_.get());
+ blocked_cookies_tree_->SetRootShown(false);
+ blocked_cookies_tree_->SetEditable(false);
+ blocked_cookies_tree_->set_lines_at_root(true);
+ blocked_cookies_tree_->set_auto_expand_children(true);
+
+ using views::GridLayout;
+
+ GridLayout* layout = CreatePanelGridLayout(this);
+ SetLayoutManager(layout);
+
+ const int single_column_layout_id = 0;
+ views::ColumnSet* column_set = layout->AddColumnSet(single_column_layout_id);
+ column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1,
+ GridLayout::USE_PREF, 0, 0);
+
+ layout->StartRow(0, single_column_layout_id);
+ layout->AddView(allowed_label_);
+
+ layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
+ layout->StartRow(1, single_column_layout_id);
+ layout->AddView(
+ allowed_cookies_tree_, 1, 1, GridLayout::FILL, GridLayout::FILL);
+ layout->AddPaddingRow(0, kUnrelatedControlVerticalSpacing);
+
+ layout->StartRow(0, single_column_layout_id);
+ layout->AddView(blocked_label_);
+
+ layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
+ layout->StartRow(1, single_column_layout_id);
+ layout->AddView(
+ blocked_cookies_tree_, 1, 1, GridLayout::FILL, GridLayout::FILL);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// views::DialogDelegate implementation.
+
+std::wstring CollectedCookiesWin::GetWindowTitle() const {
+ return l10n_util::GetString(IDS_COLLECTED_COOKIES_DIALOG_TITLE);
+}
+
+int CollectedCookiesWin::GetDialogButtons() const {
+ return MessageBoxFlags::DIALOGBUTTON_CANCEL;
+}
+
+std::wstring CollectedCookiesWin::GetDialogButtonLabel(
+ MessageBoxFlags::DialogButton button) const {
+ return l10n_util::GetString(IDS_CLOSE);
+}
+
+void CollectedCookiesWin::DeleteDelegate() {
+ delete this;
+}
+
+bool CollectedCookiesWin::Cancel() {
+ return true;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// views::WindowDelegate implementation.
+
+views::View* CollectedCookiesWin::GetContentsView() {
+ return this;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// views::View implementation.
+
+gfx::Size CollectedCookiesWin::GetPreferredSize() {
+ return gfx::Size(views::Window::GetLocalizedContentsSize(
+ IDS_COOKIES_DIALOG_WIDTH_CHARS,
+ IDS_COOKIES_DIALOG_HEIGHT_LINES));
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// NotificationObserver implementation.
+
+void CollectedCookiesWin::Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ DCHECK(type == NotificationType::COLLECTED_COOKIES_SHOWN);
+ DCHECK_EQ(Source<TabSpecificContentSettings>(source).ptr(),
+ tab_contents_->GetTabSpecificContentSettings());
+ window_->CloseConstrainedWindow();
+}
diff --git a/chrome/browser/views/collected_cookies_win.h b/chrome/browser/views/collected_cookies_win.h
new file mode 100644
index 0000000..16b5f89
--- /dev/null
+++ b/chrome/browser/views/collected_cookies_win.h
@@ -0,0 +1,79 @@
+// 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.
+
+// This is the Views implementation of the collected Cookies dialog.
+
+#ifndef CHROME_BROWSER_VIEWS_COLLECTED_COOKIES_WIN_H_
+#define CHROME_BROWSER_VIEWS_COLLECTED_COOKIES_WIN_H_
+
+#include "chrome/browser/tab_contents/constrained_window.h"
+#include "chrome/common/notification_registrar.h"
+#include "views/window/dialog_delegate.h"
+
+class ConstrainedWindow;
+class CookiesTreeModel;
+class TabContents;
+namespace views {
+class Label;
+class TreeView;
+}
+
+// CollectedCookiesWin is a dialog that displays the allowed and blocked
+// cookies of the current tab contents. To display the dialog, invoke
+// ShowCollectedCookiesDialog() on the delegate of the tab contents.
+
+class CollectedCookiesWin : public ConstrainedDialogDelegate,
+ NotificationObserver,
+ views::View {
+ public:
+ // Use BrowserWindow::ShowCollectedCookiesDialog to show.
+ CollectedCookiesWin(gfx::NativeWindow parent_window,
+ TabContents* tab_contents);
+
+ // views::DialogDelegate implementation.
+ virtual std::wstring GetWindowTitle() const;
+ virtual int GetDialogButtons() const;
+ virtual std::wstring GetDialogButtonLabel(
+ MessageBoxFlags::DialogButton button) const;
+ virtual void DeleteDelegate();
+
+ virtual bool Cancel();
+
+ // views::WindowDelegate implementation.
+ virtual views::View* GetContentsView();
+
+ // views::View implementation.
+ gfx::Size GetPreferredSize();
+
+ private:
+ virtual ~CollectedCookiesWin();
+
+ void Init();
+
+ // Notification Observer implementation.
+ void Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details);
+
+ NotificationRegistrar registrar_;
+
+ ConstrainedWindow* window_;
+
+ // The tab contents.
+ TabContents* tab_contents_;
+
+ // Assorted views.
+ views::Label* allowed_label_;
+ views::Label* blocked_label_;
+
+ views::TreeView* allowed_cookies_tree_;
+ views::TreeView* blocked_cookies_tree_;
+
+ scoped_ptr<CookiesTreeModel> allowed_cookies_tree_model_;
+ scoped_ptr<CookiesTreeModel> blocked_cookies_tree_model_;
+
+ DISALLOW_COPY_AND_ASSIGN(CollectedCookiesWin);
+};
+
+#endif // CHROME_BROWSER_VIEWS_COLLECTED_COOKIES_WIN_H_
diff --git a/chrome/browser/views/dialog_stubs_gtk.cc b/chrome/browser/views/dialog_stubs_gtk.cc
index 7e06c23..a8e4535 100644
--- a/chrome/browser/views/dialog_stubs_gtk.cc
+++ b/chrome/browser/views/dialog_stubs_gtk.cc
@@ -11,6 +11,7 @@
#include "chrome/browser/gtk/about_chrome_dialog.h"
#include "chrome/browser/fonts_languages_window.h"
#include "chrome/browser/gtk/clear_browsing_data_dialog_gtk.h"
+#include "chrome/browser/gtk/collected_cookies_gtk.h"
#include "chrome/browser/gtk/edit_search_engine_dialog.h"
#include "chrome/browser/gtk/keyword_editor_view.h"
#include "chrome/browser/gtk/options/content_settings_window_gtk.h"
@@ -70,4 +71,9 @@ void ShowContentSettingsWindow(gfx::NativeWindow parent_window,
ContentSettingsWindowGtk::Show(parent_window, content_type, profile);
}
+void ShowCollectedCookiesDialog(gfx::NativeWindow parent_window,
+ TabContents* tab_contents) {
+ new CollectedCookiesGtk(GTK_WINDOW(parent_window), tab_contents);
+}
+
} // namespace browser
diff --git a/chrome/browser/views/frame/browser_view.cc b/chrome/browser/views/frame/browser_view.cc
index 7b019bb..304f6fc 100644
--- a/chrome/browser/views/frame/browser_view.cc
+++ b/chrome/browser/views/frame/browser_view.cc
@@ -1089,6 +1089,10 @@ void BrowserView::ShowContentSettingsWindow(ContentSettingsType content_type,
browser::ShowContentSettingsWindow(GetNativeHandle(), content_type, profile);
}
+void BrowserView::ShowCollectedCookiesDialog(TabContents* tab_contents) {
+ browser::ShowCollectedCookiesDialog(GetNativeHandle(), tab_contents);
+}
+
void BrowserView::ShowProfileErrorDialog(int message_id) {
#if defined(OS_WIN)
std::wstring title = l10n_util::GetString(IDS_PRODUCT_NAME);
diff --git a/chrome/browser/views/frame/browser_view.h b/chrome/browser/views/frame/browser_view.h
index ab89256..1300bc4 100644
--- a/chrome/browser/views/frame/browser_view.h
+++ b/chrome/browser/views/frame/browser_view.h
@@ -311,6 +311,7 @@ class BrowserView : public BrowserBubbleHost,
virtual void ShowRepostFormWarningDialog(TabContents* tab_contents);
virtual void ShowContentSettingsWindow(ContentSettingsType content_type,
Profile* profile);
+ virtual void ShowCollectedCookiesDialog(TabContents* tab_contents);
virtual void ShowProfileErrorDialog(int message_id);
virtual void ShowThemeInstallBubble();
virtual void ConfirmBrowserCloseWithPendingDownloads();