From 68e2c8bd1effcbd87ddd166b6053706479a49c5e Mon Sep 17 00:00:00 2001 From: "danno@chromium.org" Date: Thu, 18 Mar 2010 13:11:41 +0000 Subject: [Mac] Better code sharing between cookie tree and cookie prompt Refactored code so that the class that encapsulates cookies details is shared between the cookie tree and cookie prompt on the mac. xib changes: Fixed the bindings in all of the subviews in the details view to use the new shared details class. Also added a currently hidden popup menu for selecting the cookie expiration time in the prompt details view--this needs to be wired up in a separate CL. BUG=http://crbug.com/38348 TEST=added unit tests for the new class, manual testing of cookie tree and cookie prompt dialog Review URL: http://codereview.chromium.org/1025003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@41949 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/app/nibs/CookieDetailsView.xib | 478 ++++++++++++++------- chrome/browser/cocoa/cookie_details.h | 146 +++++++ chrome/browser/cocoa/cookie_details.mm | 221 ++++++++++ chrome/browser/cocoa/cookie_details_unittest.mm | 140 ++++++ .../cocoa/cookie_prompt_window_controller.mm | 223 +--------- chrome/browser/cocoa/cookie_tree_node.h | 72 +--- chrome/browser/cocoa/cookie_tree_node.mm | 156 +------ .../cocoa/cookies_window_controller_unittest.mm | 92 ++-- chrome/chrome_browser.gypi | 6 +- chrome/chrome_tests.gypi | 1 + 10 files changed, 910 insertions(+), 625 deletions(-) create mode 100644 chrome/browser/cocoa/cookie_details.h create mode 100644 chrome/browser/cocoa/cookie_details.mm create mode 100644 chrome/browser/cocoa/cookie_details_unittest.mm diff --git a/chrome/app/nibs/CookieDetailsView.xib b/chrome/app/nibs/CookieDetailsView.xib index 6cd519c..3c30664 100644 --- a/chrome/app/nibs/CookieDetailsView.xib +++ b/chrome/app/nibs/CookieDetailsView.xib @@ -312,6 +312,76 @@ + + + -2147483380 + + YES + + + 266 + {200, 26} + + YES + + -2076049856 + 2048 + + + 109199615 + 129 + + + 400 + 75 + + + Item 1 + + 1048576 + 2147483647 + 1 + + NSImage + NSMenuCheckmark + + + NSImage + NSMenuMixedState + + _popUpItemAction: + + + YES + + OtherViews + + YES + + + + Item 2 + + 1048576 + 2147483647 + + + _popUpItemAction: + + + + + 1 + YES + YES + 2 + + + + {{3, 16}, {200, 26}} + + GTMWidthBasedTweaker + {{76, -18}, {386, 207}} @@ -832,25 +902,24 @@ YES - name - content - domain - path - sendFor - created - expires - fileSize - lastModified - databaseDescription - isLocalStorageTreeDetails - isFolderOrCookieTreeDetails - isDatabaseTreeDetails - isDatabasePromptDetails - isLocalStoragePromptDetails - localStorageKey - localStorageValue - count @count + details.expires + details.created + details.sendFor + details.path + details.domain + details.content + details.name + details.lastModified + details.fileSize + details.databaseDescription + details.localStorageValue + details.localStorageKey + details.shouldShowLocalStoragePromptDetailsView + details.shouldShowDatabasePromptDetailsView + details.shouldShowDatabaseTreeDetailsView + details.shouldShowLocalStorageTreeDetailsView + details.shouldHideCookieDetailsView CocoaCookieTreeNode YES @@ -948,15 +1017,15 @@ - value: content.expires + value: content.details.expires - value: content.expires + value: content.details.expires value - content.expires + content.details.expires YES @@ -977,19 +1046,19 @@ 2 - 539 + 582 - value: content.created + value: content.details.created - value: content.created + value: content.details.created value - content.created + content.details.created YES @@ -1010,19 +1079,19 @@ 2 - 540 + 583 - value: content.sendFor + value: content.details.sendFor - value: content.sendFor + value: content.details.sendFor value - content.sendFor + content.details.sendFor YES @@ -1043,19 +1112,19 @@ 2 - 541 + 584 - value: content.path + value: content.details.path - value: content.path + value: content.details.path value - content.path + content.details.path YES @@ -1076,19 +1145,19 @@ 2 - 542 + 585 - value: content.domain + value: content.details.domain - value: content.domain + value: content.details.domain value - content.domain + content.details.domain YES @@ -1109,19 +1178,19 @@ 2 - 543 + 586 - value: content.content + value: content.details.content - value: content.content + value: content.details.content value - content.content + content.details.content YES @@ -1142,19 +1211,19 @@ 2 - 544 + 587 - value: content.name + value: content.details.name - value: content.name + value: content.details.name value - content.name + content.details.name YES @@ -1175,19 +1244,19 @@ 2 - 545 + 588 - value: content.lastModified + value: content.details.lastModified - value: content.lastModified + value: content.details.lastModified value - content.lastModified + content.details.lastModified YES @@ -1208,19 +1277,19 @@ 2 - 546 + 589 - value: content.fileSize + value: content.details.fileSize - value: content.fileSize + value: content.details.fileSize value - content.fileSize + content.details.fileSize YES @@ -1241,19 +1310,19 @@ 2 - 547 + 590 - value: content.domain + value: content.details.domain - value: content.domain + value: content.details.domain value - content.domain + content.details.domain YES @@ -1274,19 +1343,19 @@ 2 - 548 + 591 - value: content.lastModified + value: content.details.lastModified - value: content.lastModified + value: content.details.lastModified value - content.lastModified + content.details.lastModified YES @@ -1307,19 +1376,19 @@ 2 - 549 + 592 - value: content.fileSize + value: content.details.fileSize - value: content.fileSize + value: content.details.fileSize value - content.fileSize + content.details.fileSize YES @@ -1340,19 +1409,19 @@ 2 - 550 + 593 - value: content.databaseDescription + value: content.details.databaseDescription - value: content.databaseDescription + value: content.details.databaseDescription value - content.databaseDescription + content.details.databaseDescription YES @@ -1373,19 +1442,19 @@ 2 - 551 + 594 - value: content.domain - + value: content.details.name + - + - value: content.domain + value: content.details.name value - content.domain + content.details.name NSRaisesForNotApplicableKeys @@ -1393,19 +1462,19 @@ 2 - 552 + 595 - value: content.name - + value: content.details.domain + - + - value: content.name + value: content.details.domain value - content.name + content.details.domain NSRaisesForNotApplicableKeys @@ -1413,19 +1482,19 @@ 2 - 553 + 596 - value: content.domain - + value: content.details.localStorageValue + - + - value: content.domain + value: content.details.localStorageValue value - content.domain + content.details.localStorageValue NSRaisesForNotApplicableKeys @@ -1433,19 +1502,19 @@ 2 - 554 + 597 - value: content.localStorageKey + value: content.details.localStorageKey - value: content.localStorageKey + value: content.details.localStorageKey value - content.localStorageKey + content.details.localStorageKey NSRaisesForNotApplicableKeys @@ -1453,19 +1522,19 @@ 2 - 555 + 598 - value: content.localStorageValue - + value: content.details.domain + - + - value: content.localStorageValue + value: content.details.domain value - content.localStorageValue + content.details.domain NSRaisesForNotApplicableKeys @@ -1473,19 +1542,19 @@ 2 - 556 + 599 - hidden: content.isLocalStorageTreeDetails - + hidden: content.details.shouldShowLocalStoragePromptDetailsView + - - + + - hidden: content.isLocalStorageTreeDetails + hidden: content.details.shouldShowLocalStoragePromptDetailsView hidden - content.isLocalStorageTreeDetails + content.details.shouldShowLocalStoragePromptDetailsView NSValueTransformerName NSNegateBoolean @@ -1493,15 +1562,15 @@ 2 - 557 + 600 hidden2: selection.@count - + - + hidden2: selection.@count hidden2 @@ -1525,43 +1594,23 @@ NSNegateBoolean - - 2 - - - 558 - - - - hidden: content.isFolderOrCookieTreeDetails - - - - - - hidden: content.isFolderOrCookieTreeDetails - hidden - content.isFolderOrCookieTreeDetails - - NSValueTransformerName - NSNegateBoolean - + 2 - 559 + 601 - hidden: content.isDatabaseTreeDetails - + hidden: content.details.shouldShowDatabasePromptDetailsView + - - + + - hidden: content.isDatabaseTreeDetails + hidden: content.details.shouldShowDatabasePromptDetailsView hidden - content.isDatabaseTreeDetails + content.details.shouldShowDatabasePromptDetailsView NSValueTransformerName NSNegateBoolean @@ -1569,15 +1618,15 @@ 2 - 560 + 602 hidden2: selection.@count - + - + hidden2: selection.@count hidden2 @@ -1601,23 +1650,23 @@ NSNegateBoolean - + 2 - 561 + 603 - hidden: content.isDatabasePromptDetails - + hidden: content.details.shouldShowDatabaseTreeDetailsView + - - + + - hidden: content.isDatabasePromptDetails + hidden: content.details.shouldShowDatabaseTreeDetailsView hidden - content.isDatabasePromptDetails + content.details.shouldShowDatabaseTreeDetailsView NSValueTransformerName NSNegateBoolean @@ -1625,15 +1674,15 @@ 2 - 562 + 604 hidden2: selection.@count - + - + hidden2: selection.@count hidden2 @@ -1657,23 +1706,23 @@ NSNegateBoolean - + 2 - 563 + 605 - hidden: content.isLocalStoragePromptDetails - + hidden: content.details.shouldShowLocalStorageTreeDetailsView + - - + + - hidden: content.isLocalStoragePromptDetails + hidden: content.details.shouldShowLocalStorageTreeDetailsView hidden - content.isLocalStoragePromptDetails + content.details.shouldShowLocalStorageTreeDetailsView NSValueTransformerName NSNegateBoolean @@ -1681,15 +1730,15 @@ 2 - 564 + 606 hidden2: selection.@count - + - + hidden2: selection.@count hidden2 @@ -1713,11 +1762,43 @@ NSNegateBoolean - + + 2 + + + 607 + + + + value: content.details.expires + + + + + + value: content.details.expires + value + content.details.expires 2 - 565 + 609 + + + + hidden: content.details.shouldHideCookieDetailsView + + + + + + hidden: content.details.shouldHideCookieDetailsView + hidden + content.details.shouldHideCookieDetailsView + 2 + + + 611 @@ -2034,6 +2115,7 @@ + @@ -2457,6 +2539,53 @@ + + 577 + + + YES + + + + + + 566 + + + YES + + + + + + 567 + + + YES + + + + + + 568 + + + YES + + + + + + + 570 + + + + + 569 + + + @@ -2548,13 +2677,23 @@ 482.IBPluginDependency 483.IBPluginDependency 484.IBPluginDependency + 566.IBPluginDependency + 567.IBPluginDependency + 568.IBEditorWindowLastContentRect + 568.IBPluginDependency + 569.IBPluginDependency + 570.IBPluginDependency + 577.IBPluginDependency YES com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{640, 45}, {464, 191}} + {{28, 111}, {464, 191}} + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -2635,6 +2774,10 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + {{702, 79}, {200, 43}} + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -2658,7 +2801,7 @@ - 565 + 611 @@ -2750,6 +2893,13 @@ + NSMenuItem + + IBProjectSource + browser/cocoa/nsmenuitem_additions.h + + + NSObject IBProjectSource diff --git a/chrome/browser/cocoa/cookie_details.h b/chrome/browser/cocoa/cookie_details.h new file mode 100644 index 0000000..2ce6dfa --- /dev/null +++ b/chrome/browser/cocoa/cookie_details.h @@ -0,0 +1,146 @@ +// 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 + +#include "chrome/browser/browsing_data_database_helper.h" +#include "chrome/browser/browsing_data_local_storage_helper.h" +#include "base/scoped_nsobject.h" +#include "net/base/cookie_monster.h" + +class CookieTreeNode; +class CookiePromptModalDialog; + +// This enum specifies the type of information contained in the +// cookie details. +enum CocoaCookieDetailsType { + // Represents grouping of cookie data, used in the cookie tree. + kCocoaCookieDetailsTypeFolder = 0, + + // Detailed information about a cookie, used both in the cookie + // tree and the cookie prompt. + kCocoaCookieDetailsTypeCookie = 1, + + // Detailed information about a web database used for + // display in the cookie tree. + kCocoaCookieDetailsTypeTreeDatabase = 2, + + // Detailed information about local storage used for + // display in the cookie tree. + kCocoaCookieDetailsTypeTreeLocalStorage = 3, + + // Detailed information about a web database used for display + // in the cookie prompt dialog. + kCocoaCookieDetailsTypePromptDatabase = 4, + + // Detailed information about local storage used for display + // in the cookie prompt dialog. + kCocoaCookieDetailsTypePromptLocalStorage = 5 +}; + +// This class contains all of the information that can be displayed in +// a cookie details view. Because the view uses bindings to display +// the cookie information, the methods that provide that information +// for display must be implemented directly on this class and not on any +// of its subclasses. +// If this system is rewritten to not use bindings, this class should be +// subclassed and specialized, rather than using an enum to determine type. +@interface CocoaCookieDetails : NSObject { + @private + CocoaCookieDetailsType type_; + + // These members are only set for type kCocoaCookieDetailsTypeCookie. + scoped_nsobject content_; + scoped_nsobject path_; + scoped_nsobject sendFor_; + // Stringifed dates. + scoped_nsobject created_; + scoped_nsobject expires_; + + // These members are only set for types kCocoaCookieDetailsTypeCookie, + // kCocoaCookieDetailsTypePromptDatabase. + scoped_nsobject name_; + + // Only set for types kCocoaCookieDetailsTypeTreeLocalStorage and + // kCocoaCookieDetailsTypeTreeDatabase nodes. + scoped_nsobject fileSize_; + scoped_nsobject lastModified_; + + // These members are only set for types kCocoaCookieDetailsTypeCookie, + // kCocoaCookieDetailsTypePromptDatabase and + // kCocoaCookieDetailsTypePromptLocalStorage nodes. + scoped_nsobject domain_; + + // Used only for type kCocoaCookieTreeNodeTypeDatabaseStorage. + scoped_nsobject databaseDescription_; + + // Used only for type kCocoaCookieDetailsTypePromptLocalStorage + scoped_nsobject localStorageKey_; + scoped_nsobject localStorageValue_; +} + +@property (readonly) CocoaCookieDetailsType type; + +// The following methods are used in the bindings of subviews inside +// the cookie detail view. Note that the method that tests the +// visibility of the subview for cookie-specific information has a different +// polarity than the other visibility testing methods. This ensures that +// this subview is shown when there is no selection in the cookie tree, +// because a hidden value of |false| is generated when the key value binding +// is evaluated through a nil object. The other methods are bound using a +// |NSNegateBoolean| transformer, so that when there is a empty selection the +// hidden value is |true|. +- (BOOL)shouldHideCookieDetailsView; +- (BOOL)shouldShowLocalStorageTreeDetailsView; +- (BOOL)shouldShowDatabaseTreeDetailsView; +- (BOOL)shouldShowDatabasePromptDetailsView; +- (BOOL)shouldShowLocalStoragePromptDetailsView; + +- (NSString*)name; +- (NSString*)content; +- (NSString*)domain; +- (NSString*)path; +- (NSString*)sendFor; +- (NSString*)created; +- (NSString*)expires; +- (NSString*)fileSize; +- (NSString*)lastModified; +- (NSString*)databaseDescription; +- (NSString*)localStorageKey; +- (NSString*)localStorageValue; + +// Used for folders in the cookie tree. +- (id)initAsFolder; + +// Used for cookie details in both the cookie tree and the cookie prompt dialog. +- (id)initWithCookie:(const net::CookieMonster::CanonicalCookie*)treeNode + origin:(NSString*)origin; + +// Used for database details in the cookie tree. +- (id)initWithDatabase: + (const BrowsingDataDatabaseHelper::DatabaseInfo*)databaseInfo; + +// Used for local storage details in the cookie tree. +- (id)initWithLocalStorage: + (const BrowsingDataLocalStorageHelper::LocalStorageInfo*)localStorageInfo; + +// Used for database details in the cookie prompt dialog. +- (id)initWithDatabase:(const std::string&)domain + name:(const string16&)name; + +// Used for local storage details in the cookie prompt dialog. +- (id)initWithLocalStorage:(const std::string&)domain + key:(const string16&)key + value:(const string16&)value; + +// A factory method to create a configured instance given a node from +// the cookie tree in |treeNode|. ++ (CocoaCookieDetails*)createFromCookieTreeNode:(CookieTreeNode*)treeNode; + +// A factory method to create a configured instance given a cookie prompt +// modal dialog in |dialog|. ++ (CocoaCookieDetails*)createFromPromptModalDialog: + (CookiePromptModalDialog*)dialog; + +@end diff --git a/chrome/browser/cocoa/cookie_details.mm b/chrome/browser/cocoa/cookie_details.mm new file mode 100644 index 0000000..7552c7f --- /dev/null +++ b/chrome/browser/cocoa/cookie_details.mm @@ -0,0 +1,221 @@ +// 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/cocoa/cookie_details.h" + +#include "app/l10n_util_mac.h" +#import "base/i18n/time_formatting.h" +#include "base/sys_string_conversions.h" +#include "grit/generated_resources.h" +#include "chrome/browser/cookie_modal_dialog.h" +#include "chrome/browser/cookies_tree_model.h" + +@implementation CocoaCookieDetails + +@synthesize type = type_; + +- (BOOL)shouldHideCookieDetailsView { + return type_ != kCocoaCookieDetailsTypeFolder && + type_ != kCocoaCookieDetailsTypeCookie; +} + +- (BOOL)shouldShowLocalStorageTreeDetailsView { + return type_ == kCocoaCookieDetailsTypeTreeLocalStorage; +} + +- (BOOL)shouldShowDatabaseTreeDetailsView { + return type_ == kCocoaCookieDetailsTypeTreeDatabase; +} + +- (BOOL)shouldShowDatabasePromptDetailsView { + return type_ == kCocoaCookieDetailsTypePromptDatabase; +} + +- (BOOL)shouldShowLocalStoragePromptDetailsView { + return type_ == kCocoaCookieDetailsTypePromptLocalStorage; +} + +- (NSString*)name { + return name_.get(); +} + +- (NSString*)content { + return content_.get(); +} + +- (NSString*)domain { + return domain_.get(); +} + +- (NSString*)path { + return path_.get(); +} + +- (NSString*)sendFor { + return sendFor_.get(); +} + +- (NSString*)created { + return created_.get(); +} + +- (NSString*)expires { + return expires_.get(); +} + +- (NSString*)fileSize { + return fileSize_.get(); +} + +- (NSString*)lastModified { + return lastModified_.get(); +} + +- (NSString*)databaseDescription { + return databaseDescription_.get(); +} + +- (NSString*)localStorageKey { + return localStorageKey_.get(); +} + +- (NSString*)localStorageValue { + return localStorageValue_.get(); +} + +- (id)initAsFolder { + if ((self = [super init])) { + type_ = kCocoaCookieDetailsTypeFolder; + } + return self; +} + +- (id)initWithCookie:(const net::CookieMonster::CanonicalCookie*)cookie + origin:(NSString*)origin { + if ((self = [super init])) { + type_ = kCocoaCookieDetailsTypeCookie; + name_.reset([base::SysUTF8ToNSString(cookie->Name()) retain]); + content_.reset([base::SysUTF8ToNSString(cookie->Value()) retain]); + path_.reset([base::SysUTF8ToNSString(cookie->Path()) retain]); + domain_.reset([origin retain]); + + if (cookie->DoesExpire()) { + expires_.reset([base::SysWideToNSString( + base::TimeFormatFriendlyDateAndTime(cookie->ExpiryDate())) retain]); + } else { + expires_.reset([l10n_util::GetNSStringWithFixup( + IDS_COOKIES_COOKIE_EXPIRES_SESSION) retain]); + } + + created_.reset([base::SysWideToNSString( + base::TimeFormatFriendlyDateAndTime(cookie->CreationDate())) retain]); + + if (cookie->IsSecure()) { + sendFor_.reset([l10n_util::GetNSStringWithFixup( + IDS_COOKIES_COOKIE_SENDFOR_SECURE) retain]); + } else { + sendFor_.reset([l10n_util::GetNSStringWithFixup( + IDS_COOKIES_COOKIE_SENDFOR_ANY) retain]); + } + } + return self; +} + +- (id)initWithDatabase:(const BrowsingDataDatabaseHelper::DatabaseInfo*) + databaseInfo { + if ((self = [super init])) { + type_ = kCocoaCookieDetailsTypeTreeDatabase; + databaseDescription_.reset([base::SysUTF8ToNSString( + databaseInfo->description) retain]); + fileSize_.reset([base::SysWideToNSString(FormatBytes(databaseInfo->size, + GetByteDisplayUnits(databaseInfo->size), true)) retain]); + lastModified_.reset([base::SysWideToNSString( + base::TimeFormatFriendlyDateAndTime( + databaseInfo->last_modified)) retain]); + } + return self; +} + +- (id)initWithLocalStorage:( + const BrowsingDataLocalStorageHelper::LocalStorageInfo*)storageInfo { + if ((self = [super init])) { + type_ = kCocoaCookieDetailsTypeTreeLocalStorage; + domain_.reset([base::SysUTF8ToNSString(storageInfo->origin) retain]); + fileSize_.reset([base::SysWideToNSString(FormatBytes(storageInfo->size, + GetByteDisplayUnits(storageInfo->size), true)) retain]); + lastModified_.reset([base::SysWideToNSString( + base::TimeFormatFriendlyDateAndTime( + storageInfo->last_modified)) retain]); + } + return self; +} + +- (id)initWithDatabase:(const std::string&)domain + name:(const string16&)name { + if ((self = [super init])) { + type_ = kCocoaCookieDetailsTypePromptDatabase; + name_.reset([base::SysUTF16ToNSString(name) retain]); + domain_.reset([base::SysUTF8ToNSString(domain) retain]); + } + return self; +} + +- (id)initWithLocalStorage:(const std::string&)domain + key:(const string16&)key + value:(const string16&)value { + if ((self = [super init])) { + type_ = kCocoaCookieDetailsTypePromptLocalStorage; + domain_.reset([base::SysUTF8ToNSString(domain) retain]); + localStorageKey_.reset([base::SysUTF16ToNSString(key) retain]); + localStorageValue_.reset([base::SysUTF16ToNSString(value) retain]); + } + return self; +} + ++ (CocoaCookieDetails*)createFromCookieTreeNode:(CookieTreeNode*)treeNode { + CookieTreeNode::DetailedInfo info = treeNode->GetDetailedInfo(); + CookieTreeNode::DetailedInfo::NodeType nodeType = info.node_type; + if (nodeType == CookieTreeNode::DetailedInfo::TYPE_COOKIE) { + NSString* origin = base::SysWideToNSString(info.origin.c_str()); + return [[[CocoaCookieDetails alloc] initWithCookie:&(info.cookie->second) + origin:origin] autorelease]; + } else if (nodeType == CookieTreeNode::DetailedInfo::TYPE_DATABASE) { + return [[[CocoaCookieDetails alloc] + initWithDatabase:info.database_info] autorelease]; + } else if (nodeType == CookieTreeNode::DetailedInfo::TYPE_LOCAL_STORAGE) { + return [[[CocoaCookieDetails alloc] + initWithLocalStorage:info.local_storage_info] autorelease]; + } else { + return [[[CocoaCookieDetails alloc] initAsFolder] autorelease]; + } +} + ++ (CocoaCookieDetails*)createFromPromptModalDialog:(CookiePromptModalDialog*) + dialog { + CookiePromptModalDialog::DialogType type(dialog->dialog_type()); + CocoaCookieDetails* details = nil; + if (type == CookiePromptModalDialog::DIALOG_TYPE_COOKIE) { + net::CookieMonster::ParsedCookie pc(dialog->cookie_line()); + net::CookieMonster::CanonicalCookie cookie(dialog->origin(), pc); + const std::string& domain(pc.HasDomain() ? pc.Domain() : + dialog->origin().host()); + NSString* domainString = base::SysUTF8ToNSString(domain); + details = [[CocoaCookieDetails alloc] initWithCookie:&cookie + origin:domainString]; + } else if (type == CookiePromptModalDialog::DIALOG_TYPE_LOCAL_STORAGE) { + details = [[CocoaCookieDetails alloc] + initWithLocalStorage:dialog->origin().host() + key:dialog->local_storage_key() + value:dialog->local_storage_value()]; + } else if (type == CookiePromptModalDialog::DIALOG_TYPE_DATABASE) { + details = [[CocoaCookieDetails alloc] + initWithDatabase:dialog->origin().host() + name:dialog->database_name()]; + } else { + NOTIMPLEMENTED(); + } + return [details autorelease]; +} + +@end diff --git a/chrome/browser/cocoa/cookie_details_unittest.mm b/chrome/browser/cocoa/cookie_details_unittest.mm new file mode 100644 index 0000000..a600a8d --- /dev/null +++ b/chrome/browser/cocoa/cookie_details_unittest.mm @@ -0,0 +1,140 @@ +// 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 "base/sys_string_conversions.h" +#import "chrome/browser/cocoa/cocoa_test_helper.h" +#include "chrome/browser/cocoa/cookie_details.h" +#include "googleurl/src/gurl.h" + +namespace { + +class CookiesDetailsTest : public CocoaTest { +}; + +TEST_F(CookiesDetailsTest, CreateForFolder) { + scoped_nsobject details; + details.reset([[CocoaCookieDetails alloc] initAsFolder]); + + EXPECT_EQ([details.get() type], kCocoaCookieDetailsTypeFolder); +} + +TEST_F(CookiesDetailsTest, CreateForCookie) { + scoped_nsobject details; + GURL url("http://chromium.org"); + std::string cookieLine( + "PHPSESSID=0123456789abcdef0123456789abcdef; path=/"); + net::CookieMonster::ParsedCookie pc(cookieLine); + net::CookieMonster::CanonicalCookie cookie(url, pc); + NSString* origin = base::SysUTF8ToNSString("http://chromium.org"); + details.reset([[CocoaCookieDetails alloc] initWithCookie:&cookie + origin:origin]); + + EXPECT_EQ([details.get() type], kCocoaCookieDetailsTypeCookie); + EXPECT_TRUE([@"PHPSESSID" isEqualToString:[details.get() name]]); + EXPECT_TRUE([@"0123456789abcdef0123456789abcdef" + isEqualToString:[details.get() content]]); + EXPECT_TRUE([@"http://chromium.org" isEqualToString:[details.get() domain]]); + EXPECT_TRUE([@"/" isEqualToString:[details.get() path]]); + EXPECT_FALSE([@"" isEqualToString:[details.get() lastModified]]); + EXPECT_FALSE([@"" isEqualToString:[details.get() created]]); + EXPECT_FALSE([@"" isEqualToString:[details.get() sendFor]]); + + EXPECT_FALSE([details.get() shouldHideCookieDetailsView]); + EXPECT_FALSE([details.get() shouldShowLocalStorageTreeDetailsView]); + EXPECT_FALSE([details.get() shouldShowDatabaseTreeDetailsView]); + EXPECT_FALSE([details.get() shouldShowLocalStoragePromptDetailsView]); + EXPECT_FALSE([details.get() shouldShowDatabasePromptDetailsView]); +} + +TEST_F(CookiesDetailsTest, CreateForTreeDatabase) { + scoped_nsobject details; + std::string host("http://chromium.org"); + std::string database_name("sassolungo"); + std::string origin_identifier("dolomites"); + std::string description("a great place to climb"); + int64 size = 1234; + base::Time last_modified = base::Time::Now(); + BrowsingDataDatabaseHelper::DatabaseInfo info(host, database_name, + origin_identifier, description, size, last_modified); + details.reset([[CocoaCookieDetails alloc] initWithDatabase:&info]); + + EXPECT_EQ([details.get() type], kCocoaCookieDetailsTypeTreeDatabase); + EXPECT_TRUE([@"a great place to climb" isEqualToString:[details.get() + databaseDescription]]); + EXPECT_TRUE([@"1234 B" isEqualToString:[details.get() fileSize]]); + EXPECT_FALSE([@"" isEqualToString:[details.get() lastModified]]); + + EXPECT_TRUE([details.get() shouldHideCookieDetailsView]); + EXPECT_FALSE([details.get() shouldShowLocalStorageTreeDetailsView]); + EXPECT_TRUE([details.get() shouldShowDatabaseTreeDetailsView]); + EXPECT_FALSE([details.get() shouldShowLocalStoragePromptDetailsView]); + EXPECT_FALSE([details.get() shouldShowDatabasePromptDetailsView]); +} + +TEST_F(CookiesDetailsTest, CreateForTreeLocalStorage) { + scoped_nsobject details; + std::string protocol("http"); + std::string host("chromium.org"); + unsigned short port = 80; + std::string database_identifier("id"); + std::string origin("chromium.org"); + FilePath file_path(FilePath::FromWStringHack(std::wstring(L"/"))); + int64 size = 1234; + base::Time last_modified = base::Time::Now(); + BrowsingDataLocalStorageHelper::LocalStorageInfo info(protocol, host, port, + database_identifier, origin, file_path, size, last_modified); + details.reset([[CocoaCookieDetails alloc] initWithLocalStorage:&info]); + + EXPECT_EQ([details.get() type], kCocoaCookieDetailsTypeTreeLocalStorage); + EXPECT_TRUE([@"chromium.org" isEqualToString:[details.get() domain]]); + EXPECT_TRUE([@"1234 B" isEqualToString:[details.get() fileSize]]); + EXPECT_FALSE([@"" isEqualToString:[details.get() lastModified]]); + + EXPECT_TRUE([details.get() shouldHideCookieDetailsView]); + EXPECT_TRUE([details.get() shouldShowLocalStorageTreeDetailsView]); + EXPECT_FALSE([details.get() shouldShowDatabaseTreeDetailsView]); + EXPECT_FALSE([details.get() shouldShowLocalStoragePromptDetailsView]); + EXPECT_FALSE([details.get() shouldShowDatabasePromptDetailsView]); +} + +TEST_F(CookiesDetailsTest, CreateForPromptDatabase) { + scoped_nsobject details; + std::string domain("chromium.org"); + string16 name(base::SysNSStringToUTF16(@"wicked_name")); + details.reset([[CocoaCookieDetails alloc] initWithDatabase:domain + name:name]); + + EXPECT_EQ([details.get() type], kCocoaCookieDetailsTypePromptDatabase); + EXPECT_TRUE([@"chromium.org" isEqualToString:[details.get() domain]]); + EXPECT_TRUE([@"wicked_name" isEqualToString:[details.get() name]]); + + EXPECT_TRUE([details.get() shouldHideCookieDetailsView]); + EXPECT_FALSE([details.get() shouldShowLocalStorageTreeDetailsView]); + EXPECT_FALSE([details.get() shouldShowDatabaseTreeDetailsView]); + EXPECT_FALSE([details.get() shouldShowLocalStoragePromptDetailsView]); + EXPECT_TRUE([details.get() shouldShowDatabasePromptDetailsView]); +} + +TEST_F(CookiesDetailsTest, CreateForPromptLocalStorage) { + scoped_nsobject details; + std::string domain("chromium.org"); + string16 key(base::SysNSStringToUTF16(@"testKey")); + string16 value(base::SysNSStringToUTF16(@"testValue")); + details.reset([[CocoaCookieDetails alloc] initWithLocalStorage:domain + key:key + value:value]); + + EXPECT_EQ([details.get() type], kCocoaCookieDetailsTypePromptLocalStorage); + EXPECT_TRUE([@"chromium.org" isEqualToString:[details.get() domain]]); + EXPECT_TRUE([@"testKey" isEqualToString:[details.get() localStorageKey]]); + EXPECT_TRUE([@"testValue" isEqualToString:[details.get() localStorageValue]]); + + EXPECT_TRUE([details.get() shouldHideCookieDetailsView]); + EXPECT_FALSE([details.get() shouldShowLocalStorageTreeDetailsView]); + EXPECT_FALSE([details.get() shouldShowDatabaseTreeDetailsView]); + EXPECT_TRUE([details.get() shouldShowLocalStoragePromptDetailsView]); + EXPECT_FALSE([details.get() shouldShowDatabasePromptDetailsView]); +} + +} diff --git a/chrome/browser/cocoa/cookie_prompt_window_controller.mm b/chrome/browser/cocoa/cookie_prompt_window_controller.mm index 5b85397..833423b 100644 --- a/chrome/browser/cocoa/cookie_prompt_window_controller.mm +++ b/chrome/browser/cocoa/cookie_prompt_window_controller.mm @@ -19,206 +19,42 @@ #include "grit/generated_resources.h" #import "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" -#pragma mark Window Controller - -// This class is an apapter allows the cookie details view to be shared -// by the cookie prompt window and the cookie tree in the cookies and -// other site data window. As instance of the class is set as the -// content object of the object controller for the details view and -// implements the methods expected by bindings inside that view. +#pragma mark Selection Adapter + +// The subpanes of the cookie details view expect to be able to bind to methods +// through a key path in the form |content.details.xxxx|. This class serves as +// an adapter that simply wraps a |CocoaCookieDetails| object. An instance of +// this class is set as the content object for cookie details view's object +// controller so that key paths are properly resolved through to the +// |CocoaCookieDetails| object for the cookie prompt. @interface CookiePromptSelectionAdapter : NSObject { @private - // The type of the cookie prompt being displayed, used to - // determine which subview of the details view is visible - CookiePromptModalDialog::DialogType promptType_; - - // The following members are used to hold information used in the - // cookie prompt detailed information for cookies and web databases. - scoped_nsobject name_; - scoped_nsobject domain_; - scoped_nsobject content_; - - // The following members are used to hold information used in the - // cookie prompt detailed information for cookies only. - scoped_nsobject path_; - scoped_nsobject sendFor_; - scoped_nsobject created_; - scoped_nsobject expires_; - - // The following members are used to hold information used in the - // cookie prompt detailed information for local storage only. - scoped_nsobject localStorageKey_; - scoped_nsobject localStorageValue_; + scoped_nsobject details_; } -// Creates and returns an instance approriate for displaying information -// about a cookie. -- (id)initWithCookie:(const std::string&)cookie_line - url:(const GURL&)url; - -// Creates and returns an instance approriate for displaying information -// about a local storage. -- (id)initWithLocalStorage:(const std::string&)domain - key:(const string16&)key - value:(const string16&)value; - -// Creates and returns an instance approriate for displaying information -// about a web database. -- (id)initWithDatabase:(const std::string&)domain - name:(const string16&)name; - -// The following methods are all used in the bindings inside the cookie -// detail view. -@property (readonly) BOOL isFolderOrCookieTreeDetails; -@property (readonly) BOOL isLocalStorageTreeDetails; -@property (readonly) BOOL isDatabaseTreeDetails; -@property (readonly) BOOL isDatabasePromptDetails; -@property (readonly) BOOL isLocalStoragePromptDetails; -@property (readonly) NSString* name; -@property (readonly) NSString* content; -@property (readonly) NSString* domain; -@property (readonly) NSString* path; -@property (readonly) NSString* sendFor; -@property (readonly) NSString* created; -@property (readonly) NSString* expires; -@property (readonly) NSString* fileSize; -@property (readonly) NSString* lastModified; -@property (readonly) NSString* databaseDescription; -@property (readonly) NSString* localStorageKey; -@property (readonly) NSString* localStorageValue; - +- (CocoaCookieDetails*)details; +- (id)initWithDetails:(CocoaCookieDetails*)details; @end @implementation CookiePromptSelectionAdapter -- (id)initWithCookie:(const std::string&)cookie_line - url:(const GURL&)url { - if ((self = [super init])) { - promptType_ = CookiePromptModalDialog::DIALOG_TYPE_COOKIE; - net::CookieMonster::ParsedCookie pc(cookie_line); - net::CookieMonster::CanonicalCookie cookie(url, pc); - const std::string& domain(pc.HasDomain() ? pc.Domain() : url.host()); - domain_.reset([base::SysUTF8ToNSString(domain) retain]); - name_.reset([base::SysUTF8ToNSString(cookie.Name()) retain]); - content_.reset([base::SysUTF8ToNSString(cookie.Value()) retain]); - path_.reset([base::SysUTF8ToNSString(cookie.Path()) retain]); - - if (cookie.DoesExpire()) { - expires_.reset([base::SysWideToNSString( - base::TimeFormatFriendlyDateAndTime(cookie.ExpiryDate())) - retain]); - } else { - expires_.reset([l10n_util::GetNSStringWithFixup( - IDS_COOKIES_COOKIE_EXPIRES_SESSION) retain]); - } - - created_.reset([base::SysWideToNSString( - base::TimeFormatFriendlyDateAndTime(cookie.CreationDate())) - retain]); - - if (cookie.IsSecure()) { - sendFor_.reset([l10n_util::GetNSStringWithFixup( - IDS_COOKIES_COOKIE_SENDFOR_SECURE) retain]); - } else { - sendFor_.reset([l10n_util::GetNSStringWithFixup( - IDS_COOKIES_COOKIE_SENDFOR_ANY) retain]); - } - } - return self; -} - -- (id)initWithLocalStorage:(const std::string&)domain - key:(const string16&)key - value:(const string16&)value { - if ((self = [super init])) { - promptType_ = CookiePromptModalDialog::DIALOG_TYPE_LOCAL_STORAGE; - domain_.reset([base::SysUTF8ToNSString(domain) retain]); - localStorageKey_.reset([base::SysUTF16ToNSString(key) retain]); - localStorageValue_.reset([base::SysUTF16ToNSString(value) retain]); - } - return self; -} - -- (id)initWithDatabase:(const std::string&)domain - name:(const string16&)name { +// The adapter assumes ownership of the details object +// in its initializer. +- (id)initWithDetails:(CocoaCookieDetails*)details { if ((self = [super init])) { - promptType_ = CookiePromptModalDialog::DIALOG_TYPE_DATABASE; - name_.reset([base::SysUTF16ToNSString(name) retain]); - domain_.reset([base::SysUTF8ToNSString(domain) retain]); + details_.reset([details retain]); } return self; } -- (BOOL)isFolderOrCookieTreeDetails { - return promptType_ == CookiePromptModalDialog::DIALOG_TYPE_COOKIE; -} - -- (BOOL)isLocalStorageTreeDetails { - return false; -} - -- (BOOL)isDatabaseTreeDetails { - return false; -} - -- (BOOL) isDatabasePromptDetails { - return promptType_ == CookiePromptModalDialog::DIALOG_TYPE_DATABASE; -} - -- (BOOL) isLocalStoragePromptDetails { - return promptType_ == CookiePromptModalDialog::DIALOG_TYPE_LOCAL_STORAGE; -} - -- (NSString*)name { - return name_; -} - -- (NSString*)content { - return content_; -} - -- (NSString*)domain { - return domain_; -} - -- (NSString*)path { - return path_; -} - -- (NSString*)sendFor { - return sendFor_; -} - -- (NSString*)created { - return created_; -} - -- (NSString*)expires { - return expires_; -} - -- (NSString*)fileSize { - return nil; -} - -- (NSString*)lastModified { - return nil; -} - -- (NSString*)databaseDescription { - return nil; -} - -- (NSString*)localStorageKey { - return localStorageKey_; -} - -- (NSString*)localStorageValue { - return localStorageValue_; +- (CocoaCookieDetails*)details { + return details_.get(); } @end +#pragma mark Window Controller + @implementation CookiePromptWindowController - (id)initWithDialog:(CookiePromptModalDialog*)dialog { @@ -227,23 +63,10 @@ ofType:@"nib"]; if ((self = [super initWithWindowNibPath:nibpath owner:self])) { dialog_ = dialog; - CookiePromptModalDialog::DialogType type(dialog_->dialog_type()); - if (type == CookiePromptModalDialog::DIALOG_TYPE_COOKIE) { - selectionAdapterObject_.reset([[CookiePromptSelectionAdapter alloc] - initWithCookie:dialog_->cookie_line() - url:dialog_->origin()]); - } else if (type == CookiePromptModalDialog::DIALOG_TYPE_LOCAL_STORAGE) { - selectionAdapterObject_.reset([[CookiePromptSelectionAdapter alloc] - initWithLocalStorage:dialog_->origin().host() - key:dialog_->local_storage_key() - value:dialog_->local_storage_value()]); - } else if (type == CookiePromptModalDialog::DIALOG_TYPE_DATABASE) { - selectionAdapterObject_.reset([[CookiePromptSelectionAdapter alloc] - initWithDatabase:dialog_->origin().host() - name:dialog_->database_name()]); - } else { - NOTIMPLEMENTED(); - } + CocoaCookieDetails* details = [CocoaCookieDetails + createFromPromptModalDialog:dialog]; + selectionAdapterObject_.reset([[CookiePromptSelectionAdapter alloc] + initWithDetails:details]); } return self; } diff --git a/chrome/browser/cocoa/cookie_tree_node.h b/chrome/browser/cocoa/cookie_tree_node.h index 66f5851..827c784 100644 --- a/chrome/browser/cocoa/cookie_tree_node.h +++ b/chrome/browser/cocoa/cookie_tree_node.h @@ -6,56 +6,13 @@ #include "base/scoped_nsobject.h" #include "chrome/browser/cookies_tree_model.h" +#include "chrome/browser/cocoa/cookie_details.h" -// This enum specifies the type of display node a CocoaCookieTreeNode is. If -// this system is rewritten to not use bindings, this class should be -// subclassed and specialized, rather than using an enum to determine type. -enum CocoaCookieTreeNodeType { - // Represents grouping data for the actual data. - kCocoaCookieTreeNodeTypeFolder = 0, - - // A cookie node. - kCocoaCookieTreeNodeTypeCookie = 1, - - // A HTML5 database storage node. - kCocoaCookieTreeNodeTypeDatabaseStorage = 2, - - // A local storage node. - kCocoaCookieTreeNodeTypeLocalStorage = 3 -}; - -// This class is used by CookiesWindowController and represents a node in the -// cookie tree view. @interface CocoaCookieTreeNode : NSObject { scoped_nsobject title_; scoped_nsobject children_; - - CocoaCookieTreeNodeType nodeType_; - - // The platform-independent model node. + scoped_nsobject details_; CookieTreeNode* treeNode_; // weak - - // These members are only set for kCocoaCookieTreeNodeTypeCookie nodes. - scoped_nsobject name_; - scoped_nsobject content_; - scoped_nsobject path_; - scoped_nsobject sendFor_; - // Stringifed dates. - scoped_nsobject created_; - scoped_nsobject expires_; - - // These members are only set for kCocoaCookieTreeNodeTypeLocalStorage - // and kCocoaCookieTreeNodeTypeDatabaseStorage nodes. - scoped_nsobject fileSize_; - scoped_nsobject lastModified_; - - // These members are only set for kCocoaCookieTreeNodeTypeCookie and - // kCocoaCookieTreeNodeTypeLocalStorage nodes. - scoped_nsobject domain_; - - // These members are used only for nodes of type - // kCocoaCookieTreeNodeTypeDatabaseStorage. - scoped_nsobject databaseDescription_; } // Designated initializer. @@ -66,7 +23,7 @@ enum CocoaCookieTreeNodeType { // Common getters.. - (NSString*)title; -- (CocoaCookieTreeNodeType)nodeType; +- (CocoaCookieDetailsType)nodeType; - (TreeModelNode*)treeNode; // |-mutableChildren| exists so that the CookiesTreeModelObserverBridge can @@ -75,27 +32,6 @@ enum CocoaCookieTreeNodeType { - (NSArray*)children; - (BOOL)isLeaf; -- (BOOL)isFolderOrCookieTreeDetails; -- (BOOL)isLocalStorageTreeDetails; -- (BOOL)isDatabaseTreeDetails; -- (BOOL)isLocalStoragePromptDetails; -- (BOOL)isDatabasePromptDetails; - -// Used only by kCocoaCookieTreeNodeTypeCookie. Nil for other types. -- (NSString*)name; -- (NSString*)content; -- (NSString*)domain; -- (NSString*)path; -- (NSString*)sendFor; -- (NSString*)created; -- (NSString*)expires; - -// Used by kCocoaCookieTreeNodeTypeLocalStorage and -// kCocoaCookieTreeNodeTypeDatabaseStorage nodes. Nil for other types. -- (NSString*)fileSize; -- (NSString*)lastModified; - -// Used by kCocoaCookieTreeNodeTypeDatabaseStorage nodes. Nil for other types. -- (NSString*)databaseDescription; +- (CocoaCookieDetails*)details; @end diff --git a/chrome/browser/cocoa/cookie_tree_node.mm b/chrome/browser/cocoa/cookie_tree_node.mm index 376df82..553a7bb 100644 --- a/chrome/browser/cocoa/cookie_tree_node.mm +++ b/chrome/browser/cocoa/cookie_tree_node.mm @@ -4,11 +4,7 @@ #import "chrome/browser/cocoa/cookie_tree_node.h" -#include "app/l10n_util_mac.h" -#import "base/i18n/time_formatting.h" #include "base/sys_string_conversions.h" -#include "chrome/browser/browsing_data_local_storage_helper.h" -#include "grit/generated_resources.h" @implementation CocoaCookieTreeNode @@ -24,68 +20,17 @@ - (void)rebuild { title_.reset([base::SysWideToNSString(treeNode_->GetTitle()) retain]); children_.reset(); - nodeType_ = kCocoaCookieTreeNodeTypeFolder; - - CookieTreeNode::DetailedInfo info = treeNode_->GetDetailedInfo(); - CookieTreeNode::DetailedInfo::NodeType nodeType = info.node_type; - if (nodeType == CookieTreeNode::DetailedInfo::TYPE_COOKIE) { - nodeType_ = kCocoaCookieTreeNodeTypeCookie; - net::CookieMonster::CanonicalCookie cookie = info.cookie->second; - - name_.reset([base::SysUTF8ToNSString(cookie.Name()) retain]); - title_.reset([base::SysUTF8ToNSString(cookie.Name()) retain]); - content_.reset([base::SysUTF8ToNSString(cookie.Value()) retain]); - path_.reset([base::SysUTF8ToNSString(cookie.Path()) retain]); - domain_.reset([base::SysWideToNSString(info.origin) retain]); - - if (cookie.DoesExpire()) { - expires_.reset([base::SysWideToNSString( - base::TimeFormatFriendlyDateAndTime(cookie.ExpiryDate())) retain]); - } else { - expires_.reset([l10n_util::GetNSStringWithFixup( - IDS_COOKIES_COOKIE_EXPIRES_SESSION) retain]); - } - - created_.reset([base::SysWideToNSString( - base::TimeFormatFriendlyDateAndTime(cookie.CreationDate())) retain]); - - if (cookie.IsSecure()) { - sendFor_.reset([l10n_util::GetNSStringWithFixup( - IDS_COOKIES_COOKIE_SENDFOR_SECURE) retain]); - } else { - sendFor_.reset([l10n_util::GetNSStringWithFixup( - IDS_COOKIES_COOKIE_SENDFOR_ANY) retain]); - } - } else if (nodeType == CookieTreeNode::DetailedInfo::TYPE_DATABASE) { - const BrowsingDataDatabaseHelper::DatabaseInfo* databaseInfo = - info.database_info; - nodeType_ = kCocoaCookieTreeNodeTypeDatabaseStorage; - databaseDescription_.reset([base::SysUTF8ToNSString( - databaseInfo->description) retain]); - fileSize_.reset([base::SysWideToNSString(FormatBytes(databaseInfo->size, - GetByteDisplayUnits(databaseInfo->size), true)) retain]); - lastModified_.reset([base::SysWideToNSString( - base::TimeFormatFriendlyDateAndTime( - databaseInfo->last_modified)) retain]); - } else if (nodeType == CookieTreeNode::DetailedInfo::TYPE_LOCAL_STORAGE) { - const BrowsingDataLocalStorageHelper::LocalStorageInfo* storageInfo = - info.local_storage_info; - nodeType_ = kCocoaCookieTreeNodeTypeLocalStorage; - domain_.reset([base::SysUTF8ToNSString(storageInfo->origin) retain]); - fileSize_.reset([base::SysWideToNSString(FormatBytes(storageInfo->size, - GetByteDisplayUnits(storageInfo->size), true)) retain]); - lastModified_.reset([base::SysWideToNSString( - base::TimeFormatFriendlyDateAndTime( - storageInfo->last_modified)) retain]); - } + // The tree node assumes ownership of the cookie details object + details_.reset([[CocoaCookieDetails createFromCookieTreeNode:(treeNode_)] + retain]); } - (NSString*)title { return title_.get(); } -- (CocoaCookieTreeNodeType)nodeType { - return nodeType_; +- (CocoaCookieDetailsType)nodeType { + return [details_.get() type]; } - (TreeModelNode*)treeNode { @@ -111,8 +56,8 @@ } - (BOOL)isLeaf { - return nodeType_ != kCocoaCookieTreeNodeTypeFolder; -} + return [self nodeType] != kCocoaCookieDetailsTypeFolder; +}; - (NSString*)description { NSString* format = @@ -121,91 +66,8 @@ [self nodeType], [[self children] count]]; } -- (BOOL)isFolderOrCookieTreeDetails { - return [self nodeType] == kCocoaCookieTreeNodeTypeFolder || - [self nodeType] == kCocoaCookieTreeNodeTypeCookie; -} - -- (BOOL)isDatabaseTreeDetails { - return [self nodeType] == kCocoaCookieTreeNodeTypeDatabaseStorage; -} - -- (BOOL)isLocalStorageTreeDetails { - return [self nodeType] == kCocoaCookieTreeNodeTypeLocalStorage; -} - -- (BOOL)isDatabasePromptDetails { - return false; -} - -- (BOOL)isLocalStoragePromptDetails { - return false; -} - -#pragma mark Cookie Accessors - -- (NSString*)name { - return name_.get(); -} - -- (NSString*)content { - return content_.get(); -} - -- (NSString*)domain { - return domain_.get(); -} - -- (NSString*)path { - return path_.get(); -} - -- (NSString*)sendFor { - return sendFor_.get(); -} - -- (NSString*)created { - return created_.get(); -} - -- (NSString*)expires { - return expires_.get(); -} - -#pragma mark Local Storage and Database Accessors - -- (NSString*)fileSize { - return fileSize_.get(); -} - -- (NSString*)lastModified { - return lastModified_.get(); -} - -#pragma mark Database Accessors - -- (NSString*)databaseDescription { - return databaseDescription_.get(); -} - -#pragma mark Unused Accessors - -// This method is never called for the cookie tree, it is only -// only included because the Cocoa bindings for the shared view -// used to display browser data details always expects the method -// even though it is only used in the cookie prompt window. -- (id)localStorageKey { - NOTIMPLEMENTED(); - return nil; -} - -// This method is never called for the cookie tree, it is only -// only included because the Cocoa bindings for the shared view -// used to display browser data details always expects the method -// even though it is only used in the cookie prompt window. -- (id)localStorageValue { - NOTIMPLEMENTED(); - return nil; +- (CocoaCookieDetails*)details { + return details_; } @end diff --git a/chrome/browser/cocoa/cookies_window_controller_unittest.mm b/chrome/browser/cocoa/cookies_window_controller_unittest.mm index fb19db3..898ed9e 100644 --- a/chrome/browser/cocoa/cookies_window_controller_unittest.mm +++ b/chrome/browser/cocoa/cookies_window_controller_unittest.mm @@ -141,14 +141,15 @@ TEST_F(CookiesWindowControllerTest, CocoaNodeFromTreeNodeCookie) { TreeModelNode* node = model.GetRoot()->GetChild(0)->GetChild(0)->GetChild(0); CocoaCookieTreeNode* cookie = CocoaNodeFromTreeNode(node); - EXPECT_TRUE([@"B" isEqualToString:[cookie content]]); - EXPECT_TRUE([@"When I close my browser" isEqualToString:[cookie expires]]); - EXPECT_TRUE([@"Any kind of connection" isEqualToString:[cookie sendFor]]); + CocoaCookieDetails* details = [cookie details]; + EXPECT_TRUE([@"B" isEqualToString:[details content]]); + EXPECT_TRUE([@"When I close my browser" isEqualToString:[details expires]]); + EXPECT_TRUE([@"Any kind of connection" isEqualToString:[details sendFor]]); EXPECT_TRUE([@"A" isEqualToString:[cookie title]]); - EXPECT_TRUE([@"A" isEqualToString:[cookie name]]); - EXPECT_TRUE([@"/" isEqualToString:[cookie path]]); + EXPECT_TRUE([@"A" isEqualToString:[details name]]); + EXPECT_TRUE([@"/" isEqualToString:[details path]]); EXPECT_EQ(0U, [[cookie children] count]); - EXPECT_TRUE([cookie created]); + EXPECT_TRUE([details created]); EXPECT_TRUE([cookie isLeaf]); EXPECT_EQ(node, [cookie treeNode]); } @@ -179,15 +180,16 @@ TEST_F(CookiesWindowControllerTest, CocoaNodeFromTreeNodeRecursive) { EXPECT_EQ(node->GetChild(0), [cookies treeNode]); // Test cookie node. This is the same as CocoaNodeFromTreeNodeCookie. - EXPECT_TRUE([@"B" isEqualToString:[cookie content]]); - EXPECT_TRUE([@"When I close my browser" isEqualToString:[cookie expires]]); - EXPECT_TRUE([@"Any kind of connection" isEqualToString:[cookie sendFor]]); + CocoaCookieDetails* details = [cookie details]; + EXPECT_TRUE([@"B" isEqualToString:[details content]]); + EXPECT_TRUE([@"When I close my browser" isEqualToString:[details expires]]); + EXPECT_TRUE([@"Any kind of connection" isEqualToString:[details sendFor]]); EXPECT_TRUE([@"A" isEqualToString:[cookie title]]); - EXPECT_TRUE([@"A" isEqualToString:[cookie name]]); - EXPECT_TRUE([@"/" isEqualToString:[cookie path]]); - EXPECT_TRUE([@"foo.com" isEqualToString:[cookie domain]]); + EXPECT_TRUE([@"A" isEqualToString:[details name]]); + EXPECT_TRUE([@"/" isEqualToString:[details path]]); + EXPECT_TRUE([@"foo.com" isEqualToString:[details domain]]); EXPECT_EQ(0U, [[cookie children] count]); - EXPECT_TRUE([cookie created]); + EXPECT_TRUE([details created]); EXPECT_TRUE([cookie isLeaf]); EXPECT_EQ(node->GetChild(0)->GetChild(0), [cookie treeNode]); } @@ -261,7 +263,7 @@ TEST_F(CookiesWindowControllerTest, TreeNodesRemoved) { EXPECT_EQ(1U, [cocoa_children count]); - NSString* title = [[cocoa_children objectAtIndex:0] name]; + NSString* title = [[[cocoa_children objectAtIndex:0] details] name]; EXPECT_TRUE([@"A" isEqualToString:title]); } @@ -286,11 +288,11 @@ TEST_F(CookiesWindowControllerTest, TreeNodeChildrenReordered) { // Check default ordering. CocoaCookieTreeNode* node = [cocoa_children objectAtIndex:0]; - EXPECT_TRUE([@"A" isEqualToString:[node name]]); + EXPECT_TRUE([@"A" isEqualToString:[[node details] name]]); node = [cocoa_children objectAtIndex:1]; - EXPECT_TRUE([@"C" isEqualToString:[node name]]); + EXPECT_TRUE([@"C" isEqualToString:[[node details] name]]); node = [cocoa_children objectAtIndex:2]; - EXPECT_TRUE([@"E" isEqualToString:[node name]]); + EXPECT_TRUE([@"E" isEqualToString:[[node details] name]]); CookiesTreeModel* model = [controller_ treeModel]; // Root --> foo.com --> Cookies. @@ -307,11 +309,11 @@ TEST_F(CookiesWindowControllerTest, TreeNodeChildrenReordered) { // Check the new order. node = [cocoa_children objectAtIndex:0]; - EXPECT_TRUE([@"E" isEqualToString:[node name]]); + EXPECT_TRUE([@"E" isEqualToString:[[node details] name]]); node = [cocoa_children objectAtIndex:1]; - EXPECT_TRUE([@"A" isEqualToString:[node name]]); + EXPECT_TRUE([@"A" isEqualToString:[[node details] name]]); node = [cocoa_children objectAtIndex:2]; - EXPECT_TRUE([@"C" isEqualToString:[node name]]); + EXPECT_TRUE([@"C" isEqualToString:[[node details] name]]); } TEST_F(CookiesWindowControllerTest, TreeNodeChanged) { @@ -590,43 +592,45 @@ TEST_F(CookiesWindowControllerTest, CreateDatabaseStorageNodes) { CocoaCookieTreeNode* node = [[[controller_ cocoaTreeModel] children] objectAtIndex:0]; EXPECT_TRUE([@"gdbhost1" isEqualToString:[node title]]); - EXPECT_EQ(kCocoaCookieTreeNodeTypeFolder, [node nodeType]); + EXPECT_EQ(kCocoaCookieDetailsTypeFolder, [node nodeType]); EXPECT_EQ(1U, [[node children] count]); // host1 --> Web Databases. node = [[node children] lastObject]; EXPECT_TRUE([@"Web Databases" isEqualToString:[node title]]); - EXPECT_EQ(kCocoaCookieTreeNodeTypeFolder, [node nodeType]); + EXPECT_EQ(kCocoaCookieDetailsTypeFolder, [node nodeType]); EXPECT_EQ(1U, [[node children] count]); // Database Storage --> db1. node = [[node children] lastObject]; EXPECT_TRUE([@"db1" isEqualToString:[node title]]); - EXPECT_EQ(kCocoaCookieTreeNodeTypeDatabaseStorage, [node nodeType]); - EXPECT_TRUE([@"description 1" isEqualToString:[node databaseDescription]]); - EXPECT_TRUE([node lastModified]); - EXPECT_TRUE([node fileSize]); + EXPECT_EQ(kCocoaCookieDetailsTypeTreeDatabase, [node nodeType]); + CocoaCookieDetails* details = [node details]; + EXPECT_TRUE([@"description 1" isEqualToString:[details databaseDescription]]); + EXPECT_TRUE([details lastModified]); + EXPECT_TRUE([details fileSize]); // Root --> gdbhost2. node = [[[controller_ cocoaTreeModel] children] objectAtIndex:1]; EXPECT_TRUE([@"gdbhost2" isEqualToString:[node title]]); - EXPECT_EQ(kCocoaCookieTreeNodeTypeFolder, [node nodeType]); + EXPECT_EQ(kCocoaCookieDetailsTypeFolder, [node nodeType]); EXPECT_EQ(1U, [[node children] count]); // host1 --> Web Databases. node = [[node children] lastObject]; EXPECT_TRUE([@"Web Databases" isEqualToString:[node title]]); - EXPECT_EQ(kCocoaCookieTreeNodeTypeFolder, [node nodeType]); + EXPECT_EQ(kCocoaCookieDetailsTypeFolder, [node nodeType]); EXPECT_EQ(1U, [[node children] count]); // Database Storage --> db2. node = [[node children] lastObject]; EXPECT_TRUE([@"db2" isEqualToString:[node title]]); - EXPECT_EQ(kCocoaCookieTreeNodeTypeDatabaseStorage, [node nodeType]); - EXPECT_TRUE([@"description 2" isEqualToString:[node databaseDescription]]); - EXPECT_TRUE([node lastModified]); - EXPECT_TRUE([node fileSize]); + EXPECT_EQ(kCocoaCookieDetailsTypeTreeDatabase, [node nodeType]); + details = [node details]; + EXPECT_TRUE([@"description 2" isEqualToString:[details databaseDescription]]); + EXPECT_TRUE([details lastModified]); + EXPECT_TRUE([details fileSize]); } TEST_F(CookiesWindowControllerTest, CreateLocalStorageNodes) { @@ -649,43 +653,43 @@ TEST_F(CookiesWindowControllerTest, CreateLocalStorageNodes) { CocoaCookieTreeNode* node = [[[controller_ cocoaTreeModel] children] objectAtIndex:2]; EXPECT_TRUE([@"host1" isEqualToString:[node title]]); - EXPECT_EQ(kCocoaCookieTreeNodeTypeFolder, [node nodeType]); + EXPECT_EQ(kCocoaCookieDetailsTypeFolder, [node nodeType]); EXPECT_EQ(1U, [[node children] count]); // host1 --> Local Storage. node = [[node children] lastObject]; EXPECT_TRUE([@"Local Storage" isEqualToString:[node title]]); - EXPECT_EQ(kCocoaCookieTreeNodeTypeFolder, [node nodeType]); + EXPECT_EQ(kCocoaCookieDetailsTypeFolder, [node nodeType]); EXPECT_EQ(1U, [[node children] count]); // Local Storage --> origin1. node = [[node children] lastObject]; EXPECT_TRUE([@"origin1" isEqualToString:[node title]]); - EXPECT_EQ(kCocoaCookieTreeNodeTypeLocalStorage, [node nodeType]); - EXPECT_TRUE([@"origin1" isEqualToString:[node domain]]); - EXPECT_TRUE([node lastModified]); - EXPECT_TRUE([node fileSize]); + EXPECT_EQ(kCocoaCookieDetailsTypeTreeLocalStorage, [node nodeType]); + EXPECT_TRUE([@"origin1" isEqualToString:[[node details] domain]]); + EXPECT_TRUE([[node details] lastModified]); + EXPECT_TRUE([[node details] fileSize]); // Root --> host2. node = [[[controller_ cocoaTreeModel] children] objectAtIndex:3]; EXPECT_TRUE([@"host2" isEqualToString:[node title]]); - EXPECT_EQ(kCocoaCookieTreeNodeTypeFolder, [node nodeType]); + EXPECT_EQ(kCocoaCookieDetailsTypeFolder, [node nodeType]); EXPECT_EQ(1U, [[node children] count]); // host2 --> Local Storage. node = [[node children] lastObject]; EXPECT_TRUE([@"Local Storage" isEqualToString:[node title]]); - EXPECT_EQ(kCocoaCookieTreeNodeTypeFolder, [node nodeType]); + EXPECT_EQ(kCocoaCookieDetailsTypeFolder, [node nodeType]); EXPECT_EQ(1U, [[node children] count]); // Local Storage --> origin2. node = [[node children] lastObject]; EXPECT_TRUE([@"origin2" isEqualToString:[node title]]); - EXPECT_EQ(kCocoaCookieTreeNodeTypeLocalStorage, [node nodeType]); - EXPECT_TRUE([@"origin2" isEqualToString:[node domain]]); - EXPECT_TRUE([node lastModified]); - EXPECT_TRUE([node fileSize]); + EXPECT_EQ(kCocoaCookieDetailsTypeTreeLocalStorage, [node nodeType]); + EXPECT_TRUE([@"origin2" isEqualToString:[[node details] domain]]); + EXPECT_TRUE([[node details] lastModified]); + EXPECT_TRUE([[node details] fileSize]); } } // namespace diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 9560f97..0c399b2 100755 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -546,10 +546,12 @@ 'browser/cocoa/content_exceptions_window_controller.mm', 'browser/cocoa/content_settings_dialog_controller.h', 'browser/cocoa/content_settings_dialog_controller.mm', - 'browser/cocoa/cookie_tree_node.h', - 'browser/cocoa/cookie_tree_node.mm', + 'browser/cocoa/cookie_details.h', + 'browser/cocoa/cookie_details.mm', 'browser/cocoa/cookie_details_view_controller.h', 'browser/cocoa/cookie_details_view_controller.mm', + 'browser/cocoa/cookie_tree_node.h', + 'browser/cocoa/cookie_tree_node.mm', 'browser/cocoa/cookies_window_controller.h', 'browser/cocoa/cookies_window_controller.mm', 'browser/cocoa/cookie_prompt_window_controller.h', diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 97a7f32..c5522a0 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -643,6 +643,7 @@ 'browser/cocoa/content_settings_dialog_controller_unittest.mm', 'browser/cocoa/cookies_window_controller_unittest.mm', 'browser/cocoa/cookie_prompt_window_controller_unittest.mm', + 'browser/cocoa/cookie_details_unittest.mm', 'browser/cocoa/cookie_details_view_controller_unittest.mm', 'browser/cocoa/custom_home_pages_model_unittest.mm', 'browser/cocoa/delayedmenu_button_unittest.mm', -- cgit v1.1