summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordanno@chromium.org <danno@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-25 09:38:02 +0000
committerdanno@chromium.org <danno@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-25 09:38:02 +0000
commitc7ae70250e69ce895b8c1bb98b0af5ae6c045cc9 (patch)
treec2e21cfe1b27f92a300ebb65f88c037ecda34b0a
parent6cca3e8d0074773db63858def6cbcfb34670134c (diff)
downloadchromium_src-c7ae70250e69ce895b8c1bb98b0af5ae6c045cc9.zip
chromium_src-c7ae70250e69ce895b8c1bb98b0af5ae6c045cc9.tar.gz
chromium_src-c7ae70250e69ce895b8c1bb98b0af5ae6c045cc9.tar.bz2
[Mac] Allow user to change cookie expiration date in cookie prompt
Added the necessary code and madde xib changes to make it possible to select "When I close my browser" as the expiration for a cookie in the cookie prompt dialog. xib changes: - Add explicit outlet to details view controller for the layout tweaker so that can be called explicitly from code. - Modify already existing popup menu for selecting cookie expiration to have the right menu items: item 1 is content.details.expires and item 2 is ^IDS_COOKIES_COOKIE_EXPIRES_SESSION. - Wire the hidden binding of the expiration menu to the key value path content.details.canEditExpiration with a NSNegateBoolean transformer. - Wire the visibility of the "expires" text in cookie details to the key value path content.details.canEditExpiration. BUG=http://crbug.com/38405 TEST=manual testing, new units tests Review URL: http://codereview.chromium.org/1134005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@42590 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/app/nibs/CookieDetailsView.xib124
-rw-r--r--chrome/browser/cocoa/cookie_details.h32
-rw-r--r--chrome/browser/cocoa/cookie_details.mm36
-rw-r--r--chrome/browser/cocoa/cookie_details_unittest.mm3
-rw-r--r--chrome/browser/cocoa/cookie_details_view_controller.h18
-rw-r--r--chrome/browser/cocoa/cookie_details_view_controller.mm26
-rw-r--r--chrome/browser/cocoa/cookie_details_view_controller_unittest.mm169
-rw-r--r--chrome/browser/cocoa/cookie_prompt_window_controller.mm49
-rwxr-xr-xchrome/chrome_browser.gypi4
9 files changed, 279 insertions, 182 deletions
diff --git a/chrome/app/nibs/CookieDetailsView.xib b/chrome/app/nibs/CookieDetailsView.xib
index 3c30664..f106391 100644
--- a/chrome/app/nibs/CookieDetailsView.xib
+++ b/chrome/app/nibs/CookieDetailsView.xib
@@ -314,12 +314,12 @@
</object>
<object class="NSCustomView" id="440361667">
<reference key="NSNextResponder" ref="430082147"/>
- <int key="NSvFlags">-2147483380</int>
+ <int key="NSvFlags">268</int>
<object class="NSMutableArray" key="NSSubviews">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSPopUpButton" id="161048022">
<reference key="NSNextResponder" ref="440361667"/>
- <int key="NSvFlags">266</int>
+ <int key="NSvFlags">268</int>
<string key="NSFrameSize">{200, 26}</string>
<reference key="NSSuperview" ref="440361667"/>
<bool key="NSEnabled">YES</bool>
@@ -360,7 +360,7 @@
<reference ref="628665972"/>
<object class="NSMenuItem" id="735521972">
<reference key="NSMenu" ref="424593479"/>
- <string key="NSTitle">Item 2</string>
+ <string key="NSTitle">^IDS_COOKIES_COOKIE_EXPIRES_SESSION</string>
<string key="NSKeyEquiv"/>
<int key="NSKeyEquivModMask">1048576</int>
<int key="NSMnemonicLoc">2147483647</int>
@@ -920,6 +920,8 @@
<string>details.shouldShowDatabaseTreeDetailsView</string>
<string>details.shouldShowLocalStorageTreeDetailsView</string>
<string>details.shouldHideCookieDetailsView</string>
+ <string>details.isExpirationImmutable</string>
+ <string>details.canEditExpiration</string>
</object>
<string key="NSObjectClassName">CocoaCookieTreeNode</string>
<bool key="NSEditable">YES</bool>
@@ -1770,35 +1772,95 @@
</object>
<object class="IBConnectionRecord">
<object class="IBBindingConnection" key="connection">
- <string key="label">value: content.details.expires</string>
- <reference key="source" ref="628665972"/>
+ <string key="label">hidden: content.details.shouldHideCookieDetailsView</string>
+ <reference key="source" ref="238462753"/>
<reference key="destination" ref="581169699"/>
<object class="NSNibBindingConnector" key="connector">
- <reference key="NSSource" ref="628665972"/>
+ <reference key="NSSource" ref="238462753"/>
<reference key="NSDestination" ref="581169699"/>
- <string key="NSLabel">value: content.details.expires</string>
- <string key="NSBinding">value</string>
- <string key="NSKeyPath">content.details.expires</string>
+ <string key="NSLabel">hidden: content.details.shouldHideCookieDetailsView</string>
+ <string key="NSBinding">hidden</string>
+ <string key="NSKeyPath">content.details.shouldHideCookieDetailsView</string>
<int key="NSNibBindingConnectorVersion">2</int>
</object>
</object>
- <int key="connectionID">609</int>
+ <int key="connectionID">611</int>
</object>
<object class="IBConnectionRecord">
<object class="IBBindingConnection" key="connection">
- <string key="label">hidden: content.details.shouldHideCookieDetailsView</string>
- <reference key="source" ref="238462753"/>
+ <string key="label">hidden: content.details.canEditExpiration</string>
+ <reference key="source" ref="860444829"/>
<reference key="destination" ref="581169699"/>
<object class="NSNibBindingConnector" key="connector">
- <reference key="NSSource" ref="238462753"/>
+ <reference key="NSSource" ref="860444829"/>
<reference key="NSDestination" ref="581169699"/>
- <string key="NSLabel">hidden: content.details.shouldHideCookieDetailsView</string>
+ <string key="NSLabel">hidden: content.details.canEditExpiration</string>
<string key="NSBinding">hidden</string>
- <string key="NSKeyPath">content.details.shouldHideCookieDetailsView</string>
+ <string key="NSKeyPath">content.details.canEditExpiration</string>
<int key="NSNibBindingConnectorVersion">2</int>
</object>
</object>
- <int key="connectionID">611</int>
+ <int key="connectionID">622</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBBindingConnection" key="connection">
+ <string key="label">hidden: content.details.canEditExpiration</string>
+ <reference key="source" ref="440361667"/>
+ <reference key="destination" ref="581169699"/>
+ <object class="NSNibBindingConnector" key="connector">
+ <reference key="NSSource" ref="440361667"/>
+ <reference key="NSDestination" ref="581169699"/>
+ <string key="NSLabel">hidden: content.details.canEditExpiration</string>
+ <string key="NSBinding">hidden</string>
+ <string key="NSKeyPath">content.details.canEditExpiration</string>
+ <object class="NSDictionary" key="NSOptions">
+ <string key="NS.key.0">NSValueTransformerName</string>
+ <string key="NS.object.0">NSNegateBoolean</string>
+ </object>
+ <int key="NSNibBindingConnectorVersion">2</int>
+ </object>
+ </object>
+ <int key="connectionID">624</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBBindingConnection" key="connection">
+ <string key="label">title: content.details.expires</string>
+ <reference key="source" ref="628665972"/>
+ <reference key="destination" ref="581169699"/>
+ <object class="NSNibBindingConnector" key="connector">
+ <reference key="NSSource" ref="628665972"/>
+ <reference key="NSDestination" ref="581169699"/>
+ <string key="NSLabel">title: content.details.expires</string>
+ <string key="NSBinding">title</string>
+ <string key="NSKeyPath">content.details.expires</string>
+ <int key="NSNibBindingConnectorVersion">2</int>
+ </object>
+ </object>
+ <int key="connectionID">626</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">tweaker_</string>
+ <reference key="source" ref="1001"/>
+ <reference key="destination" ref="75408757"/>
+ </object>
+ <int key="connectionID">629</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBActionConnection" key="connection">
+ <string key="label">setCookieDoesntHaveExplicitExpiration:</string>
+ <reference key="source" ref="1001"/>
+ <reference key="destination" ref="735521972"/>
+ </object>
+ <int key="connectionID">633</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBActionConnection" key="connection">
+ <string key="label">setCookieHasExplicitExpiration:</string>
+ <reference key="source" ref="1001"/>
+ <reference key="destination" ref="628665972"/>
+ </object>
+ <int key="connectionID">634</int>
</object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
@@ -2690,7 +2752,7 @@
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string>{{28, 111}, {464, 191}}</string>
+ <string>{{514, 271}, {464, 191}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
@@ -2801,7 +2863,7 @@
</object>
</object>
<nil key="sourceID"/>
- <int key="maxID">611</int>
+ <int key="maxID">634</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
@@ -2817,9 +2879,31 @@
<object class="IBPartialClassDescription">
<string key="className">CookieDetailsViewController</string>
<string key="superclassName">NSViewController</string>
+ <object class="NSMutableDictionary" key="actions">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="NSMutableArray" key="dict.sortedKeys">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>setCookieDoesntHaveExplicitExpiration:</string>
+ <string>setCookieHasExplicitExpiration:</string>
+ </object>
+ <object class="NSMutableArray" key="dict.values">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>id</string>
+ <string>id</string>
+ </object>
+ </object>
<object class="NSMutableDictionary" key="outlets">
- <string key="NS.key.0">objectController_</string>
- <string key="NS.object.0">NSObjectController</string>
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="NSMutableArray" key="dict.sortedKeys">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>objectController_</string>
+ <string>tweaker_</string>
+ </object>
+ <object class="NSMutableArray" key="dict.values">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>NSObjectController</string>
+ <string>GTMUILocalizerAndLayoutTweaker</string>
+ </object>
</object>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
diff --git a/chrome/browser/cocoa/cookie_details.h b/chrome/browser/cocoa/cookie_details.h
index 2ce6dfa..e6ff00a 100644
--- a/chrome/browser/cocoa/cookie_details.h
+++ b/chrome/browser/cocoa/cookie_details.h
@@ -50,6 +50,14 @@ enum CocoaCookieDetailsType {
@private
CocoaCookieDetailsType type_;
+ // Used for type kCocoaCookieDetailsTypeCookie to indicate whether
+ // it should be possible to edit the expiration.
+ BOOL canEditExpiration_;
+
+ // Indicates whether a cookie has an explcit expiration. If not
+ // it will expire with the session.
+ BOOL hasExpiration_;
+
// These members are only set for type kCocoaCookieDetailsTypeCookie.
scoped_nsobject<NSString> content_;
scoped_nsobject<NSString> path_;
@@ -80,6 +88,8 @@ enum CocoaCookieDetailsType {
scoped_nsobject<NSString> localStorageValue_;
}
+@property (readonly) BOOL canEditExpiration;
+@property BOOL hasExpiration;
@property (readonly) CocoaCookieDetailsType type;
// The following methods are used in the bindings of subviews inside
@@ -115,7 +125,8 @@ enum CocoaCookieDetailsType {
// Used for cookie details in both the cookie tree and the cookie prompt dialog.
- (id)initWithCookie:(const net::CookieMonster::CanonicalCookie*)treeNode
- origin:(NSString*)origin;
+ origin:(NSString*)origin
+ canEditExpiration:(BOOL)canEditExpiration;
// Used for database details in the cookie tree.
- (id)initWithDatabase:
@@ -144,3 +155,22 @@ enum CocoaCookieDetailsType {
(CookiePromptModalDialog*)dialog;
@end
+
+// 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 CookiePromptContentDetailsAdapter : NSObject {
+ @private
+ scoped_nsobject<CocoaCookieDetails> details_;
+}
+
+- (CocoaCookieDetails*)details;
+
+// The adapter assumes ownership of the details object
+// in its initializer.
+- (id)initWithDetails:(CocoaCookieDetails*)details;
+@end
+
diff --git a/chrome/browser/cocoa/cookie_details.mm b/chrome/browser/cocoa/cookie_details.mm
index 8f5a5d3..49ff5d9 100644
--- a/chrome/browser/cocoa/cookie_details.mm
+++ b/chrome/browser/cocoa/cookie_details.mm
@@ -11,8 +11,12 @@
#include "chrome/browser/cookie_modal_dialog.h"
#include "chrome/browser/cookies_tree_model.h"
+#pragma mark Cocoa Cookie Details
+
@implementation CocoaCookieDetails
+@synthesize canEditExpiration = canEditExpiration_;
+@synthesize hasExpiration = hasExpiration_;
@synthesize type = type_;
- (BOOL)shouldHideCookieDetailsView {
@@ -92,9 +96,12 @@
}
- (id)initWithCookie:(const net::CookieMonster::CanonicalCookie*)cookie
- origin:(NSString*)origin {
+ origin:(NSString*)origin
+ canEditExpiration:(BOOL)canEditExpiration {
if ((self = [super init])) {
type_ = kCocoaCookieDetailsTypeCookie;
+ hasExpiration_ = cookie->DoesExpire();
+ canEditExpiration_ = canEditExpiration && hasExpiration_;
name_.reset([base::SysUTF8ToNSString(cookie->Name()) retain]);
content_.reset([base::SysUTF8ToNSString(cookie->Value()) retain]);
path_.reset([base::SysUTF8ToNSString(cookie->Path()) retain]);
@@ -126,6 +133,7 @@
databaseInfo {
if ((self = [super init])) {
type_ = kCocoaCookieDetailsTypeTreeDatabase;
+ canEditExpiration_ = NO;
databaseDescription_.reset([base::SysUTF8ToNSString(
databaseInfo->description) retain]);
fileSize_.reset([base::SysWideToNSString(FormatBytes(databaseInfo->size,
@@ -141,6 +149,7 @@
const BrowsingDataLocalStorageHelper::LocalStorageInfo*)storageInfo {
if ((self = [super init])) {
type_ = kCocoaCookieDetailsTypeTreeLocalStorage;
+ canEditExpiration_ = NO;
domain_.reset([base::SysUTF8ToNSString(storageInfo->origin) retain]);
fileSize_.reset([base::SysWideToNSString(FormatBytes(storageInfo->size,
GetByteDisplayUnits(storageInfo->size), true)) retain]);
@@ -155,6 +164,7 @@
name:(const string16&)name {
if ((self = [super init])) {
type_ = kCocoaCookieDetailsTypePromptDatabase;
+ canEditExpiration_ = NO;
name_.reset([base::SysUTF16ToNSString(name) retain]);
domain_.reset([base::SysUTF8ToNSString(domain) retain]);
}
@@ -166,6 +176,7 @@
value:(const string16&)value {
if ((self = [super init])) {
type_ = kCocoaCookieDetailsTypePromptLocalStorage;
+ canEditExpiration_ = NO;
domain_.reset([base::SysUTF8ToNSString(domain) retain]);
localStorageKey_.reset([base::SysUTF16ToNSString(key) retain]);
localStorageValue_.reset([base::SysUTF16ToNSString(value) retain]);
@@ -179,7 +190,8 @@
if (nodeType == CookieTreeNode::DetailedInfo::TYPE_COOKIE) {
NSString* origin = base::SysWideToNSString(info.origin.c_str());
return [[[CocoaCookieDetails alloc] initWithCookie:&(info.cookie->second)
- origin:origin] autorelease];
+ origin:origin
+ canEditExpiration:NO] autorelease];
} else if (nodeType == CookieTreeNode::DetailedInfo::TYPE_DATABASE) {
return [[[CocoaCookieDetails alloc]
initWithDatabase:info.database_info] autorelease];
@@ -202,7 +214,8 @@
dialog->origin().host());
NSString* domainString = base::SysUTF8ToNSString(domain);
details = [[CocoaCookieDetails alloc] initWithCookie:&cookie
- origin:domainString];
+ origin:domainString
+ canEditExpiration:YES];
} else if (type == CookiePromptModalDialog::DIALOG_TYPE_LOCAL_STORAGE) {
details = [[CocoaCookieDetails alloc]
initWithLocalStorage:dialog->origin().host()
@@ -225,3 +238,20 @@
}
@end
+
+#pragma mark Content Object Adapter
+
+@implementation CookiePromptContentDetailsAdapter
+
+- (id)initWithDetails:(CocoaCookieDetails*)details {
+ if ((self = [super init])) {
+ details_.reset([details retain]);
+ }
+ return self;
+}
+
+- (CocoaCookieDetails*)details {
+ return details_.get();
+}
+
+@end
diff --git a/chrome/browser/cocoa/cookie_details_unittest.mm b/chrome/browser/cocoa/cookie_details_unittest.mm
index a600a8d..55cbe00 100644
--- a/chrome/browser/cocoa/cookie_details_unittest.mm
+++ b/chrome/browser/cocoa/cookie_details_unittest.mm
@@ -28,7 +28,8 @@ TEST_F(CookiesDetailsTest, CreateForCookie) {
net::CookieMonster::CanonicalCookie cookie(url, pc);
NSString* origin = base::SysUTF8ToNSString("http://chromium.org");
details.reset([[CocoaCookieDetails alloc] initWithCookie:&cookie
- origin:origin]);
+ origin:origin
+ canEditExpiration:NO]);
EXPECT_EQ([details.get() type], kCocoaCookieDetailsTypeCookie);
EXPECT_TRUE([@"PHPSESSID" isEqualToString:[details.get() name]]);
diff --git a/chrome/browser/cocoa/cookie_details_view_controller.h b/chrome/browser/cocoa/cookie_details_view_controller.h
index 04b8db7..3d4eae2 100644
--- a/chrome/browser/cocoa/cookie_details_view_controller.h
+++ b/chrome/browser/cocoa/cookie_details_view_controller.h
@@ -10,6 +10,7 @@
#include "net/base/cookie_monster.h"
@class CocoaCookieTreeNode;
+@class GTMUILocalizerAndLayoutTweaker;
// Controller for the view that displays the details of a cookie,
// used both in the cookie prompt dialog as well as the
@@ -19,8 +20,16 @@
// Allows direct access to the object controller for
// the displayed cookie information.
IBOutlet NSObjectController* objectController_;
+
+ // This explicit reference to the layout tweaker is
+ // required because it's necessary to reformat the view when
+ // the content object changes, since the content object may
+ // alter the widths of some of the fields displayed in the view.
+ IBOutlet GTMUILocalizerAndLayoutTweaker* tweaker_;
}
+@property (readonly) BOOL hasExpiration;
+
- (id)init;
// Configures the cookie detail view that is managed by the controller
@@ -36,5 +45,14 @@
// the the detail view's object controller and the tree controller.
// This binding allows the cookie tree to use the detail view unmodified.
- (void)configureBindingsForTreeController:(NSTreeController*)controller;
+
+// Action sent by the expiration date popup when the user
+// selects the menu item "When I close my browser".
+- (IBAction)setCookieDoesntHaveExplicitExpiration:(id)sender;
+
+// Action sent by the expiration date popup when the user
+// selects the menu item with an explicit date/time of expiration.
+- (IBAction)setCookieHasExplicitExpiration:(id)sender;
+
@end
diff --git a/chrome/browser/cocoa/cookie_details_view_controller.mm b/chrome/browser/cocoa/cookie_details_view_controller.mm
index 70da2a5..ea1801f 100644
--- a/chrome/browser/cocoa/cookie_details_view_controller.mm
+++ b/chrome/browser/cocoa/cookie_details_view_controller.mm
@@ -10,6 +10,7 @@
#include "base/sys_string_conversions.h"
#import "chrome/browser/cocoa/cookie_tree_node.h"
#import "chrome/browser/cookie_modal_dialog.h"
+#import "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h"
namespace {
static const int kMinimalLabelOffsetFromViewBottom = 20;
@@ -48,7 +49,18 @@ static const int kMinimalLabelOffsetFromViewBottom = 20;
}
- (void)setContentObject:(id)content {
+ // Make sure the view is loaded before we set the content object,
+ // otherwise, the KVO notifications to update the content don't
+ // reach the view and all of the detail values are default
+ // strings.
+ NSView* view = [self view];
+
[objectController_ setValue:content forKey:@"content"];
+
+ // View needs to be re-tweaked after setting the content object,
+ // since the expiration date may have changed, changing the
+ // size of the expiration popup.
+ [tweaker_ tweakUI:view];
}
- (void)shrinkViewToFit {
@@ -77,4 +89,18 @@ static const int kMinimalLabelOffsetFromViewBottom = 20;
options:nil];
}
+- (IBAction)setCookieDoesntHaveExplicitExpiration:(id)sender {
+ [[[objectController_ content] details] setHasExpiration:NO];
+}
+
+- (IBAction)setCookieHasExplicitExpiration:(id)sender {
+ [[[objectController_ content] details] setHasExpiration:YES];
+}
+
+@dynamic hasExpiration;
+
+- (BOOL)hasExpiration {
+ return [[[objectController_ content] details] hasExpiration];
+}
+
@end
diff --git a/chrome/browser/cocoa/cookie_details_view_controller_unittest.mm b/chrome/browser/cocoa/cookie_details_view_controller_unittest.mm
index a1d6a67..b75b925 100644
--- a/chrome/browser/cocoa/cookie_details_view_controller_unittest.mm
+++ b/chrome/browser/cocoa/cookie_details_view_controller_unittest.mm
@@ -2,141 +2,84 @@
// 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"
#include "chrome/browser/cocoa/cocoa_test_helper.h"
+#include "chrome/browser/cocoa/cookie_details.h"
#include "chrome/browser/cocoa/cookie_details_view_controller.h"
#include "chrome/browser/cookie_modal_dialog.h"
-// Mock apapter that returns dummy values for the details view
-@interface MockCookieDetailsViewContentAdapter : NSObject {
- @private
- // The type of fake cookie data to display
- CookiePromptModalDialog::DialogType promptType_;
-}
-
-- (id)initWithType:(CookiePromptModalDialog::DialogType)type;
-
-// 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;
-
-@end
-
-@implementation MockCookieDetailsViewContentAdapter
-
-- (id)initWithType:(CookiePromptModalDialog::DialogType)type {
- if ((self = [super init])) {
- promptType_ = type;
- }
- 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 @"dummyName";
-}
-
-- (NSString*)content {
- return @"dummyContent";
-}
-
-- (NSString*)domain {
- return @"dummyDomain";
-}
-
-- (NSString*)path {
- return @"dummyPath";
-}
-
-- (NSString*)sendFor {
- return @"dummySendFor";
-}
-
-- (NSString*)created {
- return @"dummyCreated";
-}
-
-- (NSString*)expires {
- return @"dummyExpires";
-}
+namespace {
-- (NSString*)fileSize {
- return @"dummyFileSize";
-}
+class CookieDetailsViewControllerTest : public CocoaTest {
+};
-- (NSString*)lastModified {
- return @"dummyLastModified";
+static CocoaCookieDetails* CreateTestCookieDetails(BOOL canEditExpiration) {
+ 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");
+ CocoaCookieDetails* details = [CocoaCookieDetails alloc];
+ [details initWithCookie:&cookie
+ origin:origin
+ canEditExpiration:canEditExpiration];
+ return [details autorelease];
}
-- (NSString*)databaseDescription {
- return @"dummyDatabaseDescription";
+static CookiePromptContentDetailsAdapter* CreateCookieTestContent(
+ BOOL canEditExpiration) {
+ CocoaCookieDetails* details = CreateTestCookieDetails(canEditExpiration);
+ return [[[CookiePromptContentDetailsAdapter alloc] initWithDetails:details]
+ autorelease];
}
-- (NSString*)localStorageKey {
- return @"dummyLocalStorageKey";
+static CocoaCookieDetails* CreateTestDatabaseDetails() {
+ std::string domain("chromium.org");
+ string16 name(base::SysNSStringToUTF16(@"wicked_name"));
+ CocoaCookieDetails* details = [CocoaCookieDetails alloc];
+ [details initWithDatabase:domain name:name];
+ return [details autorelease];
}
-- (NSString*)localStorageValue {
- return @"dummyLocalStorageValue";
+static CookiePromptContentDetailsAdapter* CreateDatabaseTestContent() {
+ CocoaCookieDetails* details = CreateTestDatabaseDetails();
+ return [[[CookiePromptContentDetailsAdapter alloc] initWithDetails:details]
+ autorelease];
}
-@end
-
-namespace {
-
-class CookieDetailsViewControllerTest : public CocoaTest {
-};
-
TEST_F(CookieDetailsViewControllerTest, Create) {
- scoped_nsobject<CookieDetailsViewController> detailsViewController;
- detailsViewController.reset([[CookieDetailsViewController alloc] init]);
+ scoped_nsobject<CookieDetailsViewController> detailsViewController(
+ [[CookieDetailsViewController alloc] init]);
}
TEST_F(CookieDetailsViewControllerTest, ShrinkToFit) {
- scoped_nsobject<CookieDetailsViewController> detailsViewController;
- detailsViewController.reset([[CookieDetailsViewController alloc] init]);
- scoped_nsobject<MockCookieDetailsViewContentAdapter> mockAdapter;
- mockAdapter.reset([[MockCookieDetailsViewContentAdapter alloc]
- initWithType:CookiePromptModalDialog::DIALOG_TYPE_DATABASE]);
- [detailsViewController.get() setContentObject:mockAdapter.get()];
+ scoped_nsobject<CookieDetailsViewController> detailsViewController(
+ [[CookieDetailsViewController alloc] init]);
+ scoped_nsobject<CookiePromptContentDetailsAdapter> adapter(
+ [CreateDatabaseTestContent() retain]);
+ [detailsViewController.get() setContentObject:adapter.get()];
NSRect beforeFrame = [[detailsViewController.get() view] frame];
[detailsViewController.get() shrinkViewToFit];
NSRect afterFrame = [[detailsViewController.get() view] frame];
+
EXPECT_TRUE(afterFrame.size.height < beforeFrame.size.width);
}
+TEST_F(CookieDetailsViewControllerTest, ExpirationEditability) {
+ scoped_nsobject<CookieDetailsViewController> detailsViewController(
+ [[CookieDetailsViewController alloc] init]);
+ [detailsViewController view];
+ scoped_nsobject<CookiePromptContentDetailsAdapter> adapter(
+ [CreateCookieTestContent(YES) retain]);
+ [detailsViewController.get() setContentObject:adapter.get()];
+
+ EXPECT_FALSE([detailsViewController.get() hasExpiration]);
+ [detailsViewController.get() setCookieHasExplicitExpiration:adapter.get()];
+ EXPECT_TRUE([detailsViewController.get() hasExpiration]);
+ [detailsViewController.get()
+ setCookieDoesntHaveExplicitExpiration:adapter.get()];
+ EXPECT_FALSE([detailsViewController.get() hasExpiration]);
+}
+
} // namespace
diff --git a/chrome/browser/cocoa/cookie_prompt_window_controller.mm b/chrome/browser/cocoa/cookie_prompt_window_controller.mm
index 8881e93..a00e84d 100644
--- a/chrome/browser/cocoa/cookie_prompt_window_controller.mm
+++ b/chrome/browser/cocoa/cookie_prompt_window_controller.mm
@@ -19,42 +19,6 @@
#include "grit/generated_resources.h"
#import "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h"
-#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
- scoped_nsobject<CocoaCookieDetails> details_;
-}
-
-- (CocoaCookieDetails*)details;
-- (id)initWithDetails:(CocoaCookieDetails*)details;
-@end
-
-@implementation CookiePromptSelectionAdapter
-
-// The adapter assumes ownership of the details object
-// in its initializer.
-- (id)initWithDetails:(CocoaCookieDetails*)details {
- if ((self = [super init])) {
- details_.reset([details retain]);
- }
- return self;
-}
-
-- (CocoaCookieDetails*)details {
- return details_.get();
-}
-
-@end
-
-#pragma mark Window Controller
-
@implementation CookiePromptWindowController
- (id)initWithDialog:(CookiePromptModalDialog*)dialog {
@@ -65,7 +29,7 @@
dialog_ = dialog;
CocoaCookieDetails* details = [CocoaCookieDetails
createFromPromptModalDialog:dialog];
- selectionAdapterObject_.reset([[CookiePromptSelectionAdapter alloc]
+ selectionAdapterObject_.reset([[CookiePromptContentDetailsAdapter alloc]
initWithDetails:details]);
}
return self;
@@ -142,10 +106,14 @@
- (void)replaceCookieDetailsView {
detailsViewController_.reset([[CookieDetailsViewController alloc] init]);
+ [detailsViewController_ setContentObject:selectionAdapterObject_.get()];
+
NSRect viewFrameRect = [disclosedViewPlaceholder_ frame];
[[disclosedViewPlaceholder_ superview]
replaceSubview:disclosedViewPlaceholder_
- with:[detailsViewController_.get() view]];
+ with:[detailsViewController_ view]];
+
+ [detailsViewController_ shrinkViewToFit];
}
- (void)awakeFromNib {
@@ -158,9 +126,6 @@
[self doLayoutTweaks];
[self replaceCookieDetailsView];
- [detailsViewController_ setContentObject:selectionAdapterObject_.get()];
- [detailsViewController_ shrinkViewToFit];
-
[[detailsViewController_ view] setHidden:YES];
}
@@ -176,7 +141,7 @@
bool remember = [radioGroupMatrix_ selectedRow] == 0;
switch (returnCode) {
case NSAlertFirstButtonReturn: { // OK
- bool sessionExpire = false;
+ bool sessionExpire = ![detailsViewController_.get() hasExpiration];
bridge->AllowSiteData(remember, sessionExpire);
break;
}
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 26e87a1..7f8f8d7 100755
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -566,12 +566,12 @@
'browser/cocoa/cookie_details.mm',
'browser/cocoa/cookie_details_view_controller.h',
'browser/cocoa/cookie_details_view_controller.mm',
+ 'browser/cocoa/cookie_prompt_window_controller.h',
+ 'browser/cocoa/cookie_prompt_window_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',
- 'browser/cocoa/cookie_prompt_window_controller.mm',
'browser/cocoa/custom_home_pages_model.h',
'browser/cocoa/custom_home_pages_model.mm',
'browser/cocoa/delayedmenu_button.h',