diff options
author | jochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-15 15:54:19 +0000 |
---|---|---|
committer | jochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-15 15:54:19 +0000 |
commit | facc6ada0300c8e9a67b0cf283257a2c70fa15c2 (patch) | |
tree | 7abfb80d70b15b344e2c246fc4d3bf13bc8f7d4e /chrome/browser | |
parent | 0dad8074499c8a2784505f826505bd8862d618a1 (diff) | |
download | chromium_src-facc6ada0300c8e9a67b0cf283257a2c70fa15c2.zip chromium_src-facc6ada0300c8e9a67b0cf283257a2c70fa15c2.tar.gz chromium_src-facc6ada0300c8e9a67b0cf283257a2c70fa15c2.tar.bz2 |
Display a tab modal dialog of the allowed/blocked cookies.
BUG=45230
TEST=CollectedCookiesTest.*
Review URL: http://codereview.chromium.org/2907003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@52486 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
25 files changed, 989 insertions, 1 deletions
diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc index 95b524f..08d58fc 100644 --- a/chrome/browser/automation/automation_provider.cc +++ b/chrome/browser/automation/automation_provider.cc @@ -326,6 +326,8 @@ void AutomationProvider::OnMessageReceived(const IPC::Message& message) { IPC_MESSAGE_HANDLER(AutomationMsg_GetCookies, GetCookies) IPC_MESSAGE_HANDLER(AutomationMsg_SetCookie, SetCookie) IPC_MESSAGE_HANDLER(AutomationMsg_DeleteCookie, DeleteCookie) + IPC_MESSAGE_HANDLER(AutomationMsg_ShowCollectedCookiesDialog, + ShowCollectedCookiesDialog) IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_NavigateToURL, NavigateToURL) IPC_MESSAGE_HANDLER_DELAY_REPLY( AutomationMsg_NavigateToURLBlockUntilNavigationsComplete, @@ -1281,6 +1283,17 @@ void AutomationProvider::DeleteCookie(const GURL& url, } } +void AutomationProvider::ShowCollectedCookiesDialog( + int handle, bool* success) { + *success = false; + if (tab_tracker_->ContainsHandle(handle)) { + TabContents* tab_contents = + tab_tracker_->GetResource(handle)->tab_contents(); + tab_contents->delegate()->ShowCollectedCookiesDialog(tab_contents); + *success = true; + } +} + void AutomationProvider::GetTabURL(int handle, bool* success, GURL* url) { *success = false; if (tab_tracker_->ContainsHandle(handle)) { diff --git a/chrome/browser/automation/automation_provider.h b/chrome/browser/automation/automation_provider.h index b4782c3..737e7d5f 100644 --- a/chrome/browser/automation/automation_provider.h +++ b/chrome/browser/automation/automation_provider.h @@ -170,6 +170,7 @@ class AutomationProvider : public base::RefCounted<AutomationProvider>, int* response_value); void DeleteCookie(const GURL& url, const std::string& cookie_name, int handle, bool* success); + void ShowCollectedCookiesDialog(int handle, bool* success); void GetBrowserWindowCount(int* window_count); void GetBrowserLocale(string16* locale); void GetNormalBrowserWindowCount(int* window_count); diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc index d04cb5d..390e7ef 100644 --- a/chrome/browser/browser.cc +++ b/chrome/browser/browser.cc @@ -2878,6 +2878,10 @@ void Browser::ShowContentSettingsWindow(ContentSettingsType content_type) { profile_->GetOriginalProfile()); } +void Browser::ShowCollectedCookiesDialog(TabContents *tab_contents) { + window()->ShowCollectedCookiesDialog(tab_contents); +} + bool Browser::ShouldAddNavigationsToHistory() const { // Don't update history if running as app. return !IsApplication(); diff --git a/chrome/browser/browser.h b/chrome/browser/browser.h index 67ba3dd..c407ffb 100644 --- a/chrome/browser/browser.h +++ b/chrome/browser/browser.h @@ -727,6 +727,7 @@ class Browser : public TabStripModelDelegate, virtual void HandleKeyboardEvent(const NativeWebKeyboardEvent& event); virtual void ShowRepostFormWarningDialog(TabContents* tab_contents); virtual void ShowContentSettingsWindow(ContentSettingsType content_type); + virtual void ShowCollectedCookiesDialog(TabContents* tab_contents); virtual bool ShouldAddNavigationsToHistory() const; virtual void OnDidGetApplicationInfo(TabContents* tab_contents, int32 page_id); diff --git a/chrome/browser/browser_window.h b/chrome/browser/browser_window.h index d806e62..9c50dda 100644 --- a/chrome/browser/browser_window.h +++ b/chrome/browser/browser_window.h @@ -230,6 +230,9 @@ class BrowserWindow { virtual void ShowContentSettingsWindow(ContentSettingsType content_type, Profile* profile) = 0; + // Shows the collected cookies dialog box. + virtual void ShowCollectedCookiesDialog(TabContents* tab_contents) = 0; + // Shows a dialog to the user that something is wrong with the profile. // |message_id| is the ID for a string in the string table which will be // displayed in the dialog. diff --git a/chrome/browser/cocoa/browser_window_cocoa.h b/chrome/browser/cocoa/browser_window_cocoa.h index 56727ca..dad191e 100644 --- a/chrome/browser/cocoa/browser_window_cocoa.h +++ b/chrome/browser/cocoa/browser_window_cocoa.h @@ -83,6 +83,7 @@ class BrowserWindowCocoa : public BrowserWindow, 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(); diff --git a/chrome/browser/cocoa/browser_window_cocoa.mm b/chrome/browser/cocoa/browser_window_cocoa.mm index bd409a2..a0961e3 100644 --- a/chrome/browser/cocoa/browser_window_cocoa.mm +++ b/chrome/browser/cocoa/browser_window_cocoa.mm @@ -17,6 +17,7 @@ #import "chrome/browser/cocoa/bug_report_window_controller.h" #import "chrome/browser/cocoa/chrome_browser_window.h" #import "chrome/browser/cocoa/clear_browsing_data_controller.h" +#import "chrome/browser/cocoa/collected_cookies_mac.h" #import "chrome/browser/cocoa/content_settings_dialog_controller.h" #import "chrome/browser/cocoa/download_shelf_controller.h" #import "chrome/browser/cocoa/edit_search_engine_cocoa_controller.h" @@ -343,6 +344,11 @@ void BrowserWindowCocoa::ShowContentSettingsWindow( profile:profile]; } +void BrowserWindowCocoa::ShowCollectedCookiesDialog(TabContents* tab_contents) { + // Deletes itself on close. + new CollectedCookiesMac(GetNativeHandle(), tab_contents); +} + void BrowserWindowCocoa::ShowProfileErrorDialog(int message_id) { scoped_nsobject<NSAlert> alert([[NSAlert alloc] init]); [alert addButtonWithTitle:l10n_util::GetNSStringWithFixup(IDS_OK)]; diff --git a/chrome/browser/cocoa/collected_cookies_mac.h b/chrome/browser/cocoa/collected_cookies_mac.h new file mode 100644 index 0000000..e47b15b --- /dev/null +++ b/chrome/browser/cocoa/collected_cookies_mac.h @@ -0,0 +1,97 @@ +// 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. + +#import <Cocoa/Cocoa.h> + +#include "app/tree_model.h" +#include "base/cocoa_protocols_mac.h" +#include "base/scoped_nsobject.h" +#include "base/scoped_ptr.h" +#include "chrome/browser/cocoa/constrained_window_mac.h" +#import "chrome/browser/cocoa/cookie_tree_node.h" +#include "chrome/browser/cookies_tree_model.h" +#include "chrome/common/notification_registrar.h" + +@class CollectedCookiesWindowController; +class TabContents; + +// The constrained window delegate reponsible for managing the collected +// cookies dialog. +class CollectedCookiesMac : public ConstrainedWindowMacDelegateCustomSheet, + public NotificationObserver { + public: + CollectedCookiesMac(NSWindow* parent, TabContents* tab_contents); + + void OnSheetDidEnd(NSWindow* sheet); + + // ConstrainedWindowMacDelegateCustomSheet implementation. + virtual void DeleteDelegate(); + + private: + virtual ~CollectedCookiesMac(); + + // NotificationObserver implementation. + void Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details); + + NotificationRegistrar registrar_; + + ConstrainedWindow* window_; + + TabContents* tab_contents_; + + CollectedCookiesWindowController* sheet_controller_; + + DISALLOW_COPY_AND_ASSIGN(CollectedCookiesMac); +}; + +// Controller for the collected cookies dialog. This class stores an internal +// copy of the CookiesTreeModel but with Cocoa-converted values (NSStrings and +// NSImages instead of std::strings and SkBitmaps). Doing this allows us to use +// bindings for the interface. Changes are pushed to this internal model via a +// very thin bridge (see cookies_window_controller.h). +@interface CollectedCookiesWindowController : NSWindowController + <NSOutlineViewDelegate, + NSWindowDelegate> { + @private + // Platform-independent model. + scoped_ptr<CookiesTreeModel> allowedTreeModel_; + scoped_ptr<CookiesTreeModel> blockedTreeModel_; + + // Cached array of icons. + scoped_nsobject<NSMutableArray> icons_; + + // Our Cocoa copy of the model. + scoped_nsobject<CocoaCookieTreeNode> cocoaAllowedTreeModel_; + scoped_nsobject<CocoaCookieTreeNode> cocoaBlockedTreeModel_; + + IBOutlet NSTreeController* allowedTreeController_; + IBOutlet NSTreeController* blockedTreeController_; + IBOutlet NSOutlineView* allowedOutlineView_; + IBOutlet NSOutlineView* blockedOutlineView_; + + TabContents* tabContents_; // weak +} +@property (readonly, nonatomic) NSTreeController* allowedTreeController; +@property (readonly, nonatomic) NSTreeController* blockedTreeController; + +// Designated initializer. TabContents cannot be NULL. +- (id)initWithTabContents:(TabContents*)tabContents; + +// Closes the sheet and ends the modal loop. This will also cleanup the memory. +- (IBAction)closeSheet:(id)sender; + +// Returns the cocoaAllowedTreeModel_ and cocoaBlockedTreeModel_. +- (CocoaCookieTreeNode*)cocoaAllowedTreeModel; +- (CocoaCookieTreeNode*)cocoaBlockedTreeModel; +- (void)setCocoaAllowedTreeModel:(CocoaCookieTreeNode*)model; +- (void)setCocoaBlockedTreeModel:(CocoaCookieTreeNode*)model; + +// Returns the allowedTreeModel_ and blockedTreeModel_. +- (CookiesTreeModel*)allowedTreeModel; +- (CookiesTreeModel*)blockedTreeModel; + +- (void)loadTreeModelFromTabContents; +@end diff --git a/chrome/browser/cocoa/collected_cookies_mac.mm b/chrome/browser/cocoa/collected_cookies_mac.mm new file mode 100644 index 0000000..25cc43c --- /dev/null +++ b/chrome/browser/cocoa/collected_cookies_mac.mm @@ -0,0 +1,203 @@ +// 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. + +#import "chrome/browser/cocoa/collected_cookies_mac.h" + +#include <vector> + +#include "app/l10n_util_mac.h" +#include "app/resource_bundle.h" +#import "base/mac_util.h" +#include "base/sys_string_conversions.h" +#include "chrome/browser/tab_contents/tab_contents.h" +#include "chrome/common/notification_service.h" +#include "grit/generated_resources.h" +#include "grit/theme_resources.h" +#include "skia/ext/skia_utils_mac.h" +#include "third_party/apple/ImageAndTextCell.h" +#include "third_party/skia/include/core/SkBitmap.h" + +#pragma mark Bridge between the constrained window delegate and the sheet + +// The delegate used to forward the events from the sheet to the constrained +// window delegate. +@interface CollectedCookiesSheetBridge : NSObject { + CollectedCookiesMac* collectedCookies_; // weak +} +- (id)initWithCollectedCookiesMac:(CollectedCookiesMac*)collectedCookies; +- (void)sheetDidEnd:(NSWindow*)sheet + returnCode:(int)returnCode + contextInfo:(void*)contextInfo; +@end + +@implementation CollectedCookiesSheetBridge +- (id)initWithCollectedCookiesMac:(CollectedCookiesMac*)collectedCookies { + if ((self = [super init])) { + collectedCookies_ = collectedCookies; + } + return self; +} + +- (void)sheetDidEnd:(NSWindow*)sheet + returnCode:(int)returnCode + contextInfo:(void*)contextInfo { + collectedCookies_->OnSheetDidEnd(sheet); +} +@end + +#pragma mark Constrained window delegate + +CollectedCookiesMac::CollectedCookiesMac(NSWindow* parent, + TabContents* tab_contents) + : ConstrainedWindowMacDelegateCustomSheet( + [[[CollectedCookiesSheetBridge alloc] + initWithCollectedCookiesMac:this] autorelease], + @selector(sheetDidEnd:returnCode:contextInfo:)), + tab_contents_(tab_contents) { + TabSpecificContentSettings* content_settings = + tab_contents->GetTabSpecificContentSettings(); + registrar_.Add(this, NotificationType::COLLECTED_COOKIES_SHOWN, + Source<TabSpecificContentSettings>(content_settings)); + + sheet_controller_ = [[CollectedCookiesWindowController alloc] + initWithTabContents:tab_contents]; + + set_sheet([sheet_controller_ window]); + + window_ = tab_contents->CreateConstrainedDialog(this); +} + +CollectedCookiesMac::~CollectedCookiesMac() { + NSWindow* window = [sheet_controller_ window]; + if (window_ && window && is_sheet_open()) { + window_ = NULL; + [NSApp endSheet:window]; + } +} + +void CollectedCookiesMac::DeleteDelegate() { + delete this; +} + +void CollectedCookiesMac::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(); +} + +void CollectedCookiesMac::OnSheetDidEnd(NSWindow* sheet) { + [sheet orderOut:sheet_controller_]; + if (window_) + window_->CloseConstrainedWindow(); +} + +#pragma mark Window Controller + +@implementation CollectedCookiesWindowController + +@synthesize allowedTreeController = allowedTreeController_; +@synthesize blockedTreeController = blockedTreeController_; + +- (id)initWithTabContents:(TabContents*)tabContents { + DCHECK(tabContents); + NSString* nibpath = + [mac_util::MainAppBundle() pathForResource:@"CollectedCookies" + ofType:@"nib"]; + if ((self = [super initWithWindowNibPath:nibpath owner:self])) { + tabContents_ = tabContents; + + [self loadTreeModelFromTabContents]; + } + return self; +} + +- (void)windowWillClose:(NSNotification*)notif { + [allowedOutlineView_ setDelegate:nil]; + [blockedOutlineView_ setDelegate:nil]; + [self autorelease]; +} + +- (IBAction)closeSheet:(id)sender { + [NSApp endSheet:[self window]]; +} + +- (CocoaCookieTreeNode*)cocoaAllowedTreeModel { + return cocoaAllowedTreeModel_.get(); +} +- (void)setCocoaAllowedTreeModel:(CocoaCookieTreeNode*)model { + cocoaAllowedTreeModel_.reset([model retain]); +} + +- (CookiesTreeModel*)allowedTreeModel { + return allowedTreeModel_.get(); +} + +- (CocoaCookieTreeNode*)cocoaBlockedTreeModel { + return cocoaBlockedTreeModel_.get(); +} +- (void)setCocoaBlockedTreeModel:(CocoaCookieTreeNode*)model { + cocoaBlockedTreeModel_.reset([model retain]); +} + +- (CookiesTreeModel*)blockedTreeModel { + return blockedTreeModel_.get(); +} + +- (void)outlineView:(NSOutlineView*)outlineView + willDisplayCell:(id)cell + forTableColumn:(NSTableColumn*)tableColumn + item:(id)item { + CocoaCookieTreeNode* node = [item representedObject]; + int index; + if (outlineView == allowedOutlineView_) + index = allowedTreeModel_->GetIconIndex([node treeNode]); + else + index = blockedTreeModel_->GetIconIndex([node treeNode]); + NSImage* icon = nil; + if (index >= 0) + icon = [icons_ objectAtIndex:index]; + else + icon = [icons_ lastObject]; + DCHECK([cell isKindOfClass:[ImageAndTextCell class]]); + [static_cast<ImageAndTextCell*>(cell) setImage:icon]; +} + +// Initializes the |allowedTreeModel_| and |blockedTreeModel_|, and builds +// the |cocoaAllowedTreeModel_| and |cocoaBlockedTreeModel_|. +- (void)loadTreeModelFromTabContents { + TabSpecificContentSettings* content_settings = + tabContents_->GetTabSpecificContentSettings(); + allowedTreeModel_.reset(content_settings->GetAllowedCookiesTreeModel()); + blockedTreeModel_.reset(content_settings->GetBlockedCookiesTreeModel()); + + // Convert the model's icons from Skia to Cocoa. + std::vector<SkBitmap> skiaIcons; + allowedTreeModel_->GetIcons(&skiaIcons); + icons_.reset([[NSMutableArray alloc] init]); + for (std::vector<SkBitmap>::iterator it = skiaIcons.begin(); + it != skiaIcons.end(); ++it) { + [icons_ addObject:gfx::SkBitmapToNSImage(*it)]; + } + + // Default icon will be the last item in the array. + ResourceBundle& rb = ResourceBundle::GetSharedInstance(); + // TODO(rsesek): Rename this resource now that it's in multiple places. + [icons_ addObject:rb.GetNSImageNamed(IDR_BOOKMARK_BAR_FOLDER)]; + + // Create the Cocoa model. + CookieTreeNode* root = + static_cast<CookieTreeNode*>(allowedTreeModel_->GetRoot()); + scoped_nsobject<CocoaCookieTreeNode> model( + [[CocoaCookieTreeNode alloc] initWithNode:root]); + [self setCocoaAllowedTreeModel:model.get()]; // Takes ownership. + root = static_cast<CookieTreeNode*>(blockedTreeModel_->GetRoot()); + model.reset( + [[CocoaCookieTreeNode alloc] initWithNode:root]); + [self setCocoaBlockedTreeModel:model.get()]; // Takes ownership. +} + +@end diff --git a/chrome/browser/cocoa/collected_cookies_mac_unittest.mm b/chrome/browser/cocoa/collected_cookies_mac_unittest.mm new file mode 100644 index 0000000..ff6f3c5 --- /dev/null +++ b/chrome/browser/cocoa/collected_cookies_mac_unittest.mm @@ -0,0 +1,38 @@ +// Copyright (c) 2009 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. + +#import <Cocoa/Cocoa.h> + +#import "chrome/browser/cocoa/collected_cookies_mac.h" + +#include "base/ref_counted.h" +#include "chrome/browser/renderer_host/site_instance.h" +#include "chrome/browser/renderer_host/test/test_render_view_host.h" +#include "chrome/browser/tab_contents/test_tab_contents.h" +#include "chrome/browser/profile.h" + +namespace { + +class CollectedCookiesWindowControllerTest : public RenderViewHostTestHarness { +}; + +TEST_F(CollectedCookiesWindowControllerTest, Construction) { + ChromeThread ui_thread(ChromeThread::UI, MessageLoop::current()); + // Create a test tab. SiteInstance will be deleted when tabContents is + // deleted. + SiteInstance* instance = + SiteInstance::CreateSiteInstance(profile_.get()); + TestTabContents* tabContents = new TestTabContents(profile_.get(), + instance); + CollectedCookiesWindowController* controller = + [[CollectedCookiesWindowController alloc] + initWithTabContents:tabContents]; + + [controller release]; + + delete tabContents; +} + +} // namespace + diff --git a/chrome/browser/collected_cookies_uitest.cc b/chrome/browser/collected_cookies_uitest.cc new file mode 100644 index 0000000..1f263b2 --- /dev/null +++ b/chrome/browser/collected_cookies_uitest.cc @@ -0,0 +1,68 @@ +// 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 <string> + +#include "chrome/app/chrome_dll_resource.h" +#include "chrome/browser/net/url_fixer_upper.h" +#include "chrome/common/chrome_switches.h" +#include "chrome/common/url_constants.h" +#include "chrome/test/automation/tab_proxy.h" +#include "chrome/test/automation/browser_proxy.h" +#include "chrome/test/ui/ui_test.h" +#include "net/url_request/url_request_unittest.h" + +namespace { + +const wchar_t kDocRoot[] = L"chrome/test/data"; + +} // namespace + +typedef UITest CollectedCookiesTest; + +TEST_F(CollectedCookiesTest, TestDoubleDisplay) { + scoped_refptr<HTTPTestServer> server = + HTTPTestServer::CreateServer(kDocRoot, NULL); + ASSERT_TRUE(NULL != server.get()); + scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); + ASSERT_TRUE(browser.get()); + + scoped_refptr<TabProxy> tab(browser->GetTab(0)); + ASSERT_TRUE(tab.get()); + + // Disable cookies. + ASSERT_TRUE(browser->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_COOKIES, + CONTENT_SETTING_BLOCK)); + + // Load a page with cookies. + ASSERT_TRUE(tab->NavigateToURL(server->TestServerPage("files/cookie1.html"))); + + // Click on the info link twice. + ASSERT_TRUE(tab->ShowCollectedCookiesDialog()); + ASSERT_TRUE(tab->ShowCollectedCookiesDialog()); +} + +TEST_F(CollectedCookiesTest, NavigateAway) { + scoped_refptr<HTTPTestServer> server = + HTTPTestServer::CreateServer(kDocRoot, NULL); + ASSERT_TRUE(NULL != server.get()); + scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); + ASSERT_TRUE(browser.get()); + + scoped_refptr<TabProxy> tab(browser->GetTab(0)); + ASSERT_TRUE(tab.get()); + + // Disable cookies. + ASSERT_TRUE(browser->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_COOKIES, + CONTENT_SETTING_BLOCK)); + + // Load a page with cookies. + ASSERT_TRUE(tab->NavigateToURL(server->TestServerPage("files/cookie1.html"))); + + // Click on the info link. + ASSERT_TRUE(tab->ShowCollectedCookiesDialog()); + + // Navigate to another page. + ASSERT_TRUE(tab->NavigateToURL(server->TestServerPage("files/cookie2.html"))); +} diff --git a/chrome/browser/content_setting_bubble_model.cc b/chrome/browser/content_setting_bubble_model.cc index 19587a5..6fc78e1 100644 --- a/chrome/browser/content_setting_bubble_model.cc +++ b/chrome/browser/content_setting_bubble_model.cc @@ -95,7 +95,14 @@ class ContentSettingTitleLinkAndInfoModel virtual void OnInfoLinkClicked() { DCHECK(content_type() == CONTENT_SETTINGS_TYPE_COOKIES); - // FIXME(jochen): show cookie info dialog. + if (tab_contents()) { + NotificationService::current()->Notify( + NotificationType::COLLECTED_COOKIES_SHOWN, + Source<TabSpecificContentSettings>( + tab_contents()->GetTabSpecificContentSettings()), + NotificationService::NoDetails()); + tab_contents()->delegate()->ShowCollectedCookiesDialog(tab_contents()); + } } }; diff --git a/chrome/browser/gtk/browser_window_gtk.cc b/chrome/browser/gtk/browser_window_gtk.cc index fe4148b..d5a1691 100644 --- a/chrome/browser/gtk/browser_window_gtk.cc +++ b/chrome/browser/gtk/browser_window_gtk.cc @@ -41,6 +41,7 @@ #include "chrome/browser/gtk/browser_toolbar_gtk.h" #include "chrome/browser/gtk/cairo_cached_surface.h" #include "chrome/browser/gtk/clear_browsing_data_dialog_gtk.h" +#include "chrome/browser/gtk/collected_cookies_gtk.h" #include "chrome/browser/gtk/create_application_shortcuts_dialog_gtk.h" #include "chrome/browser/gtk/download_in_progress_dialog_gtk.h" #include "chrome/browser/gtk/download_shelf_gtk.h" @@ -952,6 +953,11 @@ void BrowserWindowGtk::ShowContentSettingsWindow( ContentSettingsWindowGtk::Show(GetNativeHandle(), content_type, profile); } +void BrowserWindowGtk::ShowCollectedCookiesDialog(TabContents* tab_contents) { + // Deletes itself on close. + new CollectedCookiesGtk(GetNativeHandle(), tab_contents); +} + void BrowserWindowGtk::ShowProfileErrorDialog(int message_id) { std::string title = l10n_util::GetStringUTF8(IDS_PRODUCT_NAME); std::string message = l10n_util::GetStringUTF8(message_id); diff --git a/chrome/browser/gtk/browser_window_gtk.h b/chrome/browser/gtk/browser_window_gtk.h index 08b815f..b672c89 100644 --- a/chrome/browser/gtk/browser_window_gtk.h +++ b/chrome/browser/gtk/browser_window_gtk.h @@ -101,6 +101,7 @@ class BrowserWindowGtk : public BrowserWindow, 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(); diff --git a/chrome/browser/gtk/collected_cookies_gtk.cc b/chrome/browser/gtk/collected_cookies_gtk.cc new file mode 100644 index 0000000..a1bd94a --- /dev/null +++ b/chrome/browser/gtk/collected_cookies_gtk.cc @@ -0,0 +1,183 @@ +// 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/gtk/collected_cookies_gtk.h" + +#include "app/gtk_util.h" +#include "app/l10n_util.h" +#include "chrome/browser/cookies_tree_model.h" +#include "chrome/browser/gtk/gtk_util.h" +#include "chrome/browser/tab_contents/tab_contents.h" +#include "chrome/common/notification_service.h" +#include "grit/generated_resources.h" + +namespace { +// Height of the cookie tree view. +const int kTreeViewHeight = 150; +} // namespace + +CollectedCookiesGtk::CollectedCookiesGtk(GtkWindow* parent, + 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(); +} + +void CollectedCookiesGtk::Init() { + dialog_ = gtk_vbox_new(FALSE, gtk_util::kContentAreaSpacing); + gtk_box_set_spacing(GTK_BOX(dialog_), gtk_util::kContentAreaSpacing); + + GtkWidget* label = gtk_label_new( + l10n_util::GetStringUTF8(IDS_COLLECTED_COOKIES_DIALOG_TITLE).c_str()); + gtk_box_pack_start(GTK_BOX(dialog_), label, TRUE, TRUE, 0); + + // Allowed Cookie list. + GtkWidget* cookie_list_vbox = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); + gtk_box_pack_start(GTK_BOX(dialog_), cookie_list_vbox, TRUE, TRUE, 0); + + label = gtk_label_new( + l10n_util::GetStringUTF8(IDS_COLLECTED_COOKIES_ALLOWED_COOKIES_LABEL). + c_str()); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); + gtk_box_pack_start(GTK_BOX(cookie_list_vbox), label, FALSE, FALSE, 0); + + GtkWidget* scroll_window = gtk_scrolled_window_new(NULL, NULL); + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll_window), + GTK_POLICY_AUTOMATIC, + GTK_POLICY_AUTOMATIC); + gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scroll_window), + GTK_SHADOW_ETCHED_IN); + gtk_box_pack_start(GTK_BOX(cookie_list_vbox), scroll_window, TRUE, TRUE, 0); + + TabSpecificContentSettings* content_settings = + tab_contents_->GetTabSpecificContentSettings(); + + allowed_cookies_tree_model_.reset( + content_settings->GetAllowedCookiesTreeModel()); + allowed_cookies_tree_adapter_.reset( + new gtk_tree::TreeAdapter(this, allowed_cookies_tree_model_.get())); + allowed_tree_ = gtk_tree_view_new_with_model( + GTK_TREE_MODEL(allowed_cookies_tree_adapter_->tree_store())); + gtk_widget_set_size_request(allowed_tree_, -1, kTreeViewHeight); + gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(allowed_tree_), FALSE); + gtk_tree_view_set_enable_tree_lines(GTK_TREE_VIEW(allowed_tree_), TRUE); + gtk_container_add(GTK_CONTAINER(scroll_window), allowed_tree_); + + GtkTreeViewColumn* title_column = gtk_tree_view_column_new(); + GtkCellRenderer* pixbuf_renderer = gtk_cell_renderer_pixbuf_new(); + gtk_tree_view_column_pack_start(title_column, pixbuf_renderer, FALSE); + gtk_tree_view_column_add_attribute(title_column, pixbuf_renderer, "pixbuf", + gtk_tree::TreeAdapter::COL_ICON); + GtkCellRenderer* title_renderer = gtk_cell_renderer_text_new(); + gtk_tree_view_column_pack_start(title_column, title_renderer, TRUE); + gtk_tree_view_column_add_attribute(title_column, title_renderer, "text", + gtk_tree::TreeAdapter::COL_TITLE); + gtk_tree_view_column_set_title( + title_column, l10n_util::GetStringUTF8( + IDS_COOKIES_DOMAIN_COLUMN_HEADER).c_str()); + gtk_tree_view_append_column(GTK_TREE_VIEW(allowed_tree_), title_column); + g_signal_connect(allowed_tree_, "row-expanded", + G_CALLBACK(OnTreeViewRowExpandedThunk), this); + + // Blocked Cookie list. + cookie_list_vbox = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); + gtk_box_pack_start(GTK_BOX(dialog_), cookie_list_vbox, TRUE, TRUE, 0); + + label = gtk_label_new( + l10n_util::GetStringUTF8(IDS_COLLECTED_COOKIES_BLOCKED_COOKIES_LABEL). + c_str()); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); + gtk_box_pack_start(GTK_BOX(cookie_list_vbox), label, FALSE, FALSE, 0); + + scroll_window = gtk_scrolled_window_new(NULL, NULL); + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll_window), + GTK_POLICY_AUTOMATIC, + GTK_POLICY_AUTOMATIC); + gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scroll_window), + GTK_SHADOW_ETCHED_IN); + gtk_box_pack_start(GTK_BOX(cookie_list_vbox), scroll_window, TRUE, TRUE, 0); + + blocked_cookies_tree_model_.reset( + content_settings->GetBlockedCookiesTreeModel()); + blocked_cookies_tree_adapter_.reset( + new gtk_tree::TreeAdapter(this, blocked_cookies_tree_model_.get())); + blocked_tree_ = gtk_tree_view_new_with_model( + GTK_TREE_MODEL(blocked_cookies_tree_adapter_->tree_store())); + gtk_widget_set_size_request(blocked_tree_, -1, kTreeViewHeight); + gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(blocked_tree_), FALSE); + gtk_tree_view_set_enable_tree_lines(GTK_TREE_VIEW(blocked_tree_), TRUE); + gtk_container_add(GTK_CONTAINER(scroll_window), blocked_tree_); + + title_column = gtk_tree_view_column_new(); + pixbuf_renderer = gtk_cell_renderer_pixbuf_new(); + gtk_tree_view_column_pack_start(title_column, pixbuf_renderer, FALSE); + gtk_tree_view_column_add_attribute(title_column, pixbuf_renderer, "pixbuf", + gtk_tree::TreeAdapter::COL_ICON); + title_renderer = gtk_cell_renderer_text_new(); + gtk_tree_view_column_pack_start(title_column, title_renderer, TRUE); + gtk_tree_view_column_add_attribute(title_column, title_renderer, "text", + gtk_tree::TreeAdapter::COL_TITLE); + gtk_tree_view_column_set_title( + title_column, l10n_util::GetStringUTF8( + IDS_COOKIES_DOMAIN_COLUMN_HEADER).c_str()); + gtk_tree_view_append_column(GTK_TREE_VIEW(blocked_tree_), title_column); + g_signal_connect(blocked_tree_, "row-expanded", + G_CALLBACK(OnTreeViewRowExpandedThunk), this); + + // Close button. + GtkWidget* button_box = gtk_hbutton_box_new(); + gtk_button_box_set_layout(GTK_BUTTON_BOX(button_box), GTK_BUTTONBOX_END); + gtk_box_set_spacing(GTK_BOX(button_box), gtk_util::kControlSpacing); + gtk_box_pack_end(GTK_BOX(dialog_), button_box, FALSE, TRUE, 0); + GtkWidget* close = gtk_button_new_from_stock(GTK_STOCK_CLOSE); + gtk_button_set_label(GTK_BUTTON(close), + l10n_util::GetStringUTF8(IDS_CLOSE).c_str()); + g_signal_connect(close, "clicked", G_CALLBACK(OnCloseThunk), this); + gtk_box_pack_end(GTK_BOX(button_box), close, FALSE, TRUE, 0); + + // Show the dialog. + allowed_cookies_tree_adapter_->Init(); + blocked_cookies_tree_adapter_->Init(); + window_ = tab_contents_->CreateConstrainedDialog(this); +} + +CollectedCookiesGtk::~CollectedCookiesGtk() { + gtk_widget_destroy(dialog_); +} + +GtkWidget* CollectedCookiesGtk::GetWidgetRoot() { + return dialog_; +} + +void CollectedCookiesGtk::DeleteDelegate() { + delete this; +} + +void CollectedCookiesGtk::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(); +} + +void CollectedCookiesGtk::OnClose(GtkWidget* close_button) { + window_->CloseConstrainedWindow(); +} + +void CollectedCookiesGtk::OnTreeViewRowExpanded(GtkWidget* tree_view, + GtkTreeIter* iter, + GtkTreePath* path) { + // When a row in the tree is expanded, expand all the children too. + g_signal_handlers_block_by_func( + tree_view, reinterpret_cast<gpointer>(OnTreeViewRowExpandedThunk), this); + gtk_tree_view_expand_row(GTK_TREE_VIEW(tree_view), path, TRUE); + g_signal_handlers_unblock_by_func( + tree_view, reinterpret_cast<gpointer>(OnTreeViewRowExpandedThunk), this); +} diff --git a/chrome/browser/gtk/collected_cookies_gtk.h b/chrome/browser/gtk/collected_cookies_gtk.h new file mode 100644 index 0000000..0691d06 --- /dev/null +++ b/chrome/browser/gtk/collected_cookies_gtk.h @@ -0,0 +1,78 @@ +// 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 Gtk implementation of the collected Cookies dialog. + +#ifndef CHROME_BROWSER_GTK_COLLECTED_COOKIES_GTK_H_ +#define CHROME_BROWSER_GTK_COLLECTED_COOKIES_GTK_H_ + +#include <gtk/gtk.h> + +#include "app/gtk_signal.h" +#include "base/scoped_ptr.h" +#include "chrome/browser/gtk/constrained_window_gtk.h" +#include "chrome/browser/gtk/gtk_tree.h" +#include "chrome/common/notification_registrar.h" + +class CookiesTreeModel; + +// CollectedCookiesGtk 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 CollectedCookiesGtk : public ConstrainedDialogDelegate, + gtk_tree::TreeAdapter::Delegate, + NotificationObserver { + public: + CollectedCookiesGtk(GtkWindow* parent, TabContents* tab_contents); + + // ConstrainedDialogDelegate methods. + virtual GtkWidget* GetWidgetRoot(); + virtual void DeleteDelegate(); + + private: + virtual ~CollectedCookiesGtk(); + + void Init(); + + // Notification Observer implementation. + void Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details); + + // Callbacks. + CHROMEGTK_CALLBACK_2(CollectedCookiesGtk, void, OnTreeViewRowExpanded, + GtkTreeIter*, GtkTreePath*); + CHROMEGTK_CALLBACK_0(CollectedCookiesGtk, void, OnClose); + + NotificationRegistrar registrar_; + + ConstrainedWindow* window_; + + // Widgets of the dialog. + GtkWidget* dialog_; + + GtkWidget* allowed_description_label_; + GtkWidget* blocked_description_label_; + + // The table listing the cookies. + GtkWidget* allowed_tree_; + GtkWidget* blocked_tree_; + + GtkWidget* allowed_cookie_display_; + GtkWidget* blocked_cookie_display_; + + // The tab contents. + TabContents* tab_contents_; + + // The Cookies Table model. + scoped_ptr<CookiesTreeModel> allowed_cookies_tree_model_; + scoped_ptr<CookiesTreeModel> blocked_cookies_tree_model_; + scoped_ptr<gtk_tree::TreeAdapter> allowed_cookies_tree_adapter_; + scoped_ptr<gtk_tree::TreeAdapter> blocked_cookies_tree_adapter_; + + DISALLOW_COPY_AND_ASSIGN(CollectedCookiesGtk); +}; + +#endif // CHROME_BROWSER_GTK_COLLECTED_COOKIES_GTK_H_ diff --git a/chrome/browser/tab_contents/tab_contents_delegate.h b/chrome/browser/tab_contents/tab_contents_delegate.h index 9f80870..fb6fcc63 100644 --- a/chrome/browser/tab_contents/tab_contents_delegate.h +++ b/chrome/browser/tab_contents/tab_contents_delegate.h @@ -259,6 +259,9 @@ class TabContentsDelegate : public AutomationResourceRoutingDelegate { // Shows the Content Settings dialog for a given content type. virtual void ShowContentSettingsWindow(ContentSettingsType content_type) {} + // Shows the cookies collected in the tab contents. + virtual void ShowCollectedCookiesDialog(TabContents* tab_contents) {} + // Allows delegate to override navigation to the history entries. // Returns true to allow TabContents to continue with the default processing. virtual bool OnGoToEntryOffset(int offset) { diff --git a/chrome/browser/tab_contents/tab_specific_content_settings.cc b/chrome/browser/tab_contents/tab_specific_content_settings.cc index fe175f5..57b9a2b 100644 --- a/chrome/browser/tab_contents/tab_specific_content_settings.cc +++ b/chrome/browser/tab_contents/tab_specific_content_settings.cc @@ -8,6 +8,7 @@ #include "chrome/browser/browsing_data_appcache_helper.h" #include "chrome/browser/browsing_data_database_helper.h" #include "chrome/browser/browsing_data_local_storage_helper.h" +#include "chrome/browser/cookies_tree_model.h" #include "net/base/cookie_monster.h" bool TabSpecificContentSettings::IsContentBlocked( @@ -126,6 +127,14 @@ void TabSpecificContentSettings::GeolocationDidNavigate( geolocation_settings_state_.DidNavigate(details); } +CookiesTreeModel* TabSpecificContentSettings::GetAllowedCookiesTreeModel() { + return allowed_local_shared_objects_.GetCookiesTreeModel(); +} + +CookiesTreeModel* TabSpecificContentSettings::GetBlockedCookiesTreeModel() { + return blocked_local_shared_objects_.GetCookiesTreeModel(); +} + TabSpecificContentSettings::LocalSharedObjectsContainer:: LocalSharedObjectsContainer(Profile* profile) : cookies_(new net::CookieMonster(NULL, NULL)), @@ -144,3 +153,9 @@ void TabSpecificContentSettings::LocalSharedObjectsContainer::Reset() { databases_->Reset(); local_storages_->Reset(); } + +CookiesTreeModel* +TabSpecificContentSettings::LocalSharedObjectsContainer::GetCookiesTreeModel() { + return new CookiesTreeModel( + cookies_, databases_, local_storages_, appcaches_); +} diff --git a/chrome/browser/tab_contents/tab_specific_content_settings.h b/chrome/browser/tab_contents/tab_specific_content_settings.h index 18f78d8..12b557f 100644 --- a/chrome/browser/tab_contents/tab_specific_content_settings.h +++ b/chrome/browser/tab_contents/tab_specific_content_settings.h @@ -15,6 +15,7 @@ class CannedBrowsingDataAppCacheHelper; class CannedBrowsingDataDatabaseHelper; class CannedBrowsingDataLocalStorageHelper; +class CookiesTreeModel; class Profile; namespace net { @@ -57,6 +58,12 @@ class TabSpecificContentSettings return geolocation_settings_state_; } + // Returns a CookiesTreeModel object for the recoreded allowed cookies. + CookiesTreeModel* GetAllowedCookiesTreeModel(); + + // Returns a CookiesTreeModel object for the recoreded blocked cookies. + CookiesTreeModel* GetBlockedCookiesTreeModel(); + // RenderViewHostDelegate::ContentSettings implementation. virtual void OnContentBlocked(ContentSettingsType type); virtual void OnCookieAccessed(const GURL& url, @@ -93,6 +100,8 @@ class TabSpecificContentSettings return local_storages_; } + CookiesTreeModel* GetCookiesTreeModel(); + private: DISALLOW_COPY_AND_ASSIGN(LocalSharedObjectsContainer); 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(); |