summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/cocoa/cookie_details.h
blob: 614c87cab3338c62c209a7db8e27120a31ca9c08 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
// 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 "chrome/browser/browsing_data_database_helper.h"
#include "chrome/browser/browsing_data_indexed_db_helper.h"
#include "chrome/browser/browsing_data_local_storage_helper.h"
#include "base/scoped_nsobject.h"
#include "net/base/cookie_monster.h"
#include "webkit/appcache/appcache_service.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,

  // Detailed information about a web database used for
  // display in the cookie tree.
  kCocoaCookieDetailsTypeTreeDatabase,

  // Detailed information about local storage used for
  // display in the cookie tree.
  kCocoaCookieDetailsTypeTreeLocalStorage,

  // Detailed information about an appcache used for display in the
  // cookie tree.
  kCocoaCookieDetailsTypeTreeAppCache,

  // Detailed information about an IndexedDB used for display in the
  // cookie tree.
  kCocoaCookieDetailsTypeTreeIndexedDB,

  // Detailed information about a web database used for display
  // in the cookie prompt dialog.
  kCocoaCookieDetailsTypePromptDatabase,

  // Detailed information about local storage used for display
  // in the cookie prompt dialog.
  kCocoaCookieDetailsTypePromptLocalStorage,

  // Detailed information about app caches used for display
  // in the cookie prompt dialog.
  kCocoaCookieDetailsTypePromptAppCache
};

// 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_;

  // 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_;

  // Only set for type kCocoaCookieDetailsTypeCookie.
  scoped_nsobject<NSString> content_;
  scoped_nsobject<NSString> path_;
  scoped_nsobject<NSString> sendFor_;
  // Stringifed dates.
  scoped_nsobject<NSString> expires_;

  // Only set for type kCocoaCookieDetailsTypeCookie and
  // kCocoaCookieDetailsTypeTreeAppCache nodes.
  scoped_nsobject<NSString> created_;

  // Only set for types kCocoaCookieDetailsTypeCookie, and
  // kCocoaCookieDetailsTypePromptDatabase nodes.
  scoped_nsobject<NSString> name_;

  // Only set for type kCocoaCookieDetailsTypeTreeLocalStorage,
  // kCocoaCookieDetailsTypeTreeDatabase,
  // kCocoaCookieDetailsTypePromptDatabase,
  // kCocoaCookieDetailsTypeTreeIndexedDB, and
  // kCocoaCookieDetailsTypeTreeAppCache nodes.
  scoped_nsobject<NSString> fileSize_;

  // Only set for types kCocoaCookieDetailsTypeTreeLocalStorage,
  // kCocoaCookieDetailsTypeTreeDatabase, and
  // kCocoaCookieDetailsTypeTreeIndexedDB nodes.
  scoped_nsobject<NSString> lastModified_;

  // Only set for type kCocoaCookieDetailsTypeTreeAppCache nodes.
  scoped_nsobject<NSString> lastAccessed_;

  // Only set for type kCocoaCookieDetailsTypeCookie,
  // kCocoaCookieDetailsTypePromptDatabase,
  // kCocoaCookieDetailsTypePromptLocalStorage, and
  // kCocoaCookieDetailsTypeTreeIndexedDB nodes.
  scoped_nsobject<NSString> domain_;

  // Only set for type kCocoaCookieTreeNodeTypeDatabaseStorage and
  // kCocoaCookieDetailsTypePromptDatabase nodes.
  scoped_nsobject<NSString> databaseDescription_;

  // Only set for type kCocoaCookieDetailsTypePromptLocalStorage.
  scoped_nsobject<NSString> localStorageKey_;
  scoped_nsobject<NSString> localStorageValue_;

  // Only set for type kCocoaCookieDetailsTypeTreeAppCache and
  // kCocoaCookieDetailsTypePromptAppCache.
  scoped_nsobject<NSString> manifestURL_;
}

@property (nonatomic, readonly) BOOL canEditExpiration;
@property (nonatomic) BOOL hasExpiration;
@property (nonatomic, 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)shouldShowLocalStoragePromptDetailsView;
- (BOOL)shouldShowDatabaseTreeDetailsView;
- (BOOL)shouldShowDatabasePromptDetailsView;
- (BOOL)shouldShowAppCachePromptDetailsView;
- (BOOL)shouldShowAppCacheTreeDetailsView;
- (BOOL)shouldShowIndexedDBTreeDetailsView;

- (NSString*)name;
- (NSString*)content;
- (NSString*)domain;
- (NSString*)path;
- (NSString*)sendFor;
- (NSString*)created;
- (NSString*)expires;
- (NSString*)fileSize;
- (NSString*)lastModified;
- (NSString*)lastAccessed;
- (NSString*)databaseDescription;
- (NSString*)localStorageKey;
- (NSString*)localStorageValue;
- (NSString*)manifestURL;

// 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
   canEditExpiration:(BOOL)canEditExpiration;

// 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
          databaseName:(const string16&)databaseName
   databaseDescription:(const string16&)databaseDescription
              fileSize:(unsigned long)fileSize;

// -initWithAppCacheInfo: creates a cookie details with the manifest URL plus
// all of this additional information that is available after an appcache is
// actually created, including it's creation date, size and last accessed time.
- (id)initWithAppCacheInfo:(const appcache::AppCacheInfo*)appcacheInfo;

// Used for local storage details in the cookie prompt dialog.
- (id)initWithLocalStorage:(const std::string&)domain
                       key:(const string16&)key
                     value:(const string16&)value;

// -initWithAppCacheManifestURL: is called when the cookie prompt is displayed
// for an appcache, at that time only the manifest URL of the appcache is known.
- (id)initWithAppCacheManifestURL:(const std::string&)manifestURL;

// Used for IndexedDB details in the cookie tree.
- (id)initWithIndexedDBInfo:
    (const BrowsingDataIndexedDBHelper::IndexedDBInfo*)indexedDB;

// A factory method to create a configured instance given a node from
// the cookie tree in |treeNode|.
+ (CocoaCookieDetails*)createFromCookieTreeNode:(CookieTreeNode*)treeNode;

@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