1// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#import <Cocoa/Cocoa.h>
6
7#include "base/mac/scoped_nsobject.h"
8#include "chrome/browser/browsing_data/browsing_data_database_helper.h"
9#include "chrome/browser/browsing_data/browsing_data_indexed_db_helper.h"
10#include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h"
11#include "chrome/browser/browsing_data/browsing_data_service_worker_helper.h"
12#include "content/public/browser/appcache_service.h"
13
14class CookieTreeNode;
15
16namespace net {
17class CanonicalCookie;
18}
19
20// This enum specifies the type of information contained in the
21// cookie details.
22enum CocoaCookieDetailsType {
23  // Represents grouping of cookie data, used in the cookie tree.
24  kCocoaCookieDetailsTypeFolder = 0,
25
26  // Detailed information about a cookie, used both in the cookie
27  // tree and the cookie prompt.
28  kCocoaCookieDetailsTypeCookie,
29
30  // Detailed information about a web database used for
31  // display in the cookie tree.
32  kCocoaCookieDetailsTypeTreeDatabase,
33
34  // Detailed information about local storage used for
35  // display in the cookie tree.
36  kCocoaCookieDetailsTypeTreeLocalStorage,
37
38  // Detailed information about an appcache used for display in the
39  // cookie tree.
40  kCocoaCookieDetailsTypeTreeAppCache,
41
42  // Detailed information about an IndexedDB used for display in the
43  // cookie tree.
44  kCocoaCookieDetailsTypeTreeIndexedDB,
45
46  // Detailed information about a Service Worker used for display in the
47  // cookie tree.
48  kCocoaCookieDetailsTypeTreeServiceWorker,
49
50  // Detailed information about a web database used for display
51  // in the cookie prompt dialog.
52  kCocoaCookieDetailsTypePromptDatabase,
53
54  // Detailed information about local storage used for display
55  // in the cookie prompt dialog.
56  kCocoaCookieDetailsTypePromptLocalStorage,
57
58  // Detailed information about app caches used for display
59  // in the cookie prompt dialog.
60  kCocoaCookieDetailsTypePromptAppCache
61};
62
63// This class contains all of the information that can be displayed in
64// a cookie details view. Because the view uses bindings to display
65// the cookie information, the methods that provide that information
66// for display must be implemented directly on this class and not on any
67// of its subclasses.
68// If this system is rewritten to not use bindings, this class should be
69// subclassed and specialized, rather than using an enum to determine type.
70@interface CocoaCookieDetails : NSObject {
71 @private
72  CocoaCookieDetailsType type_;
73
74  // Used for type kCocoaCookieDetailsTypeCookie to indicate whether
75  // it should be possible to edit the expiration.
76  BOOL canEditExpiration_;
77
78  // Indicates whether a cookie has an explcit expiration. If not
79  // it will expire with the session.
80  BOOL hasExpiration_;
81
82  // Only set for type kCocoaCookieDetailsTypeCookie.
83  base::scoped_nsobject<NSString> content_;
84  base::scoped_nsobject<NSString> path_;
85  base::scoped_nsobject<NSString> sendFor_;
86  // Stringifed dates.
87  base::scoped_nsobject<NSString> expires_;
88
89  // Only set for type kCocoaCookieDetailsTypeCookie and
90  // kCocoaCookieDetailsTypeTreeAppCache nodes.
91  base::scoped_nsobject<NSString> created_;
92
93  // Only set for types kCocoaCookieDetailsTypeCookie, and
94  // kCocoaCookieDetailsTypePromptDatabase nodes.
95  base::scoped_nsobject<NSString> name_;
96
97  // Only set for type kCocoaCookieDetailsTypeTreeLocalStorage,
98  // kCocoaCookieDetailsTypeTreeDatabase,
99  // kCocoaCookieDetailsTypePromptDatabase,
100  // kCocoaCookieDetailsTypeTreeIndexedDB,
101  // kCocoaCookieDetailsTypeTreeServiceWorker, and
102  // kCocoaCookieDetailsTypeTreeAppCache nodes.
103  base::scoped_nsobject<NSString> fileSize_;
104
105  // Only set for types kCocoaCookieDetailsTypeTreeLocalStorage,
106  // kCocoaCookieDetailsTypeTreeDatabase,
107  // kCocoaCookieDetailsTypeTreeServiceWorker, and
108  // kCocoaCookieDetailsTypeTreeIndexedDB nodes.
109  base::scoped_nsobject<NSString> lastModified_;
110
111  // Only set for type kCocoaCookieDetailsTypeTreeAppCache nodes.
112  base::scoped_nsobject<NSString> lastAccessed_;
113
114  // Only set for type kCocoaCookieDetailsTypeCookie,
115  // kCocoaCookieDetailsTypePromptDatabase,
116  // kCocoaCookieDetailsTypePromptLocalStorage,
117  // kCocoaCookieDetailsTypePromptServiceWorker, and
118  // kCocoaCookieDetailsTypeTreeIndexedDB nodes.
119  base::scoped_nsobject<NSString> domain_;
120
121  // Only set for type kCocoaCookieTreeNodeTypeDatabaseStorage and
122  // kCocoaCookieDetailsTypePromptDatabase nodes.
123  base::scoped_nsobject<NSString> databaseDescription_;
124
125  // Only set for type kCocoaCookieDetailsTypePromptLocalStorage.
126  base::scoped_nsobject<NSString> localStorageKey_;
127  base::scoped_nsobject<NSString> localStorageValue_;
128
129  // Only set for type kCocoaCookieDetailsTypeTreeAppCache and
130  // kCocoaCookieDetailsTypePromptAppCache.
131  base::scoped_nsobject<NSString> manifestURL_;
132
133  // Only set for type kCocoaCookieDetailsTypeTreeServiceWorker nodes.
134  base::scoped_nsobject<NSString> scopes_;
135}
136
137@property(nonatomic, readonly) BOOL canEditExpiration;
138@property(nonatomic) BOOL hasExpiration;
139@property(nonatomic, readonly) CocoaCookieDetailsType type;
140
141// The following methods are used in the bindings of subviews inside
142// the cookie detail view. Note that the method that tests the
143// visibility of the subview for cookie-specific information has a different
144// polarity than the other visibility testing methods. This ensures that
145// this subview is shown when there is no selection in the cookie tree,
146// because a hidden value of |false| is generated when the key value binding
147// is evaluated through a nil object. The other methods are bound using a
148// |NSNegateBoolean| transformer, so that when there is a empty selection the
149// hidden value is |true|.
150- (BOOL)shouldHideCookieDetailsView;
151- (BOOL)shouldShowLocalStorageTreeDetailsView;
152- (BOOL)shouldShowLocalStoragePromptDetailsView;
153- (BOOL)shouldShowDatabaseTreeDetailsView;
154- (BOOL)shouldShowDatabasePromptDetailsView;
155- (BOOL)shouldShowAppCachePromptDetailsView;
156- (BOOL)shouldShowAppCacheTreeDetailsView;
157- (BOOL)shouldShowIndexedDBTreeDetailsView;
158- (BOOL)shouldShowServiceWorkerTreeDetailsView;
159
160- (NSString*)name;
161- (NSString*)content;
162- (NSString*)domain;
163- (NSString*)path;
164- (NSString*)sendFor;
165- (NSString*)created;
166- (NSString*)expires;
167- (NSString*)fileSize;
168- (NSString*)lastModified;
169- (NSString*)lastAccessed;
170- (NSString*)databaseDescription;
171- (NSString*)localStorageKey;
172- (NSString*)localStorageValue;
173- (NSString*)manifestURL;
174- (NSString*)scopes;
175
176// Used for folders in the cookie tree.
177- (id)initAsFolder;
178
179// Used for cookie details in both the cookie tree and the cookie prompt dialog.
180- (id)initWithCookie:(const net::CanonicalCookie*)treeNode
181   canEditExpiration:(BOOL)canEditExpiration;
182
183// Used for database details in the cookie tree.
184- (id)initWithDatabase:
185    (const BrowsingDataDatabaseHelper::DatabaseInfo*)databaseInfo;
186
187// Used for local storage details in the cookie tree.
188- (id)initWithLocalStorage:
189    (const BrowsingDataLocalStorageHelper::LocalStorageInfo*)localStorageInfo;
190
191// Used for database details in the cookie prompt dialog.
192- (id)initWithDatabase:(const std::string&)domain
193          databaseName:(const base::string16&)databaseName
194   databaseDescription:(const base::string16&)databaseDescription
195              fileSize:(unsigned long)fileSize;
196
197// -initWithAppCacheInfo: creates a cookie details with the manifest URL plus
198// all of this additional information that is available after an appcache is
199// actually created, including its creation date, size and last accessed time.
200- (id)initWithAppCacheInfo:(const content::AppCacheInfo*)appcacheInfo;
201
202// Used for local storage details in the cookie prompt dialog.
203- (id)initWithLocalStorage:(const std::string&)domain
204                       key:(const base::string16&)key
205                     value:(const base::string16&)value;
206
207// -initWithAppCacheManifestURL: is called when the cookie prompt is displayed
208// for an appcache, at that time only the manifest URL of the appcache is known.
209- (id)initWithAppCacheManifestURL:(const std::string&)manifestURL;
210
211// Used for IndexedDB details in the cookie tree.
212- (id)initWithIndexedDBInfo:
213    (const content::IndexedDBInfo*)indexedDB;
214
215// Used for ServiceWorker details in the cookie tree.
216- (id)initWithServiceWorkerUsageInfo:
217    (const content::ServiceWorkerUsageInfo*)serviceWorker;
218
219// A factory method to create a configured instance given a node from
220// the cookie tree in |treeNode|.
221+ (CocoaCookieDetails*)createFromCookieTreeNode:(CookieTreeNode*)treeNode;
222
223@end
224
225// The subpanes of the cookie details view expect to be able to bind to methods
226// through a key path in the form |content.details.xxxx|. This class serves as
227// an adapter that simply wraps a |CocoaCookieDetails| object. An instance of
228// this class is set as the content object for cookie details view's object
229// controller so that key paths are properly resolved through to the
230// |CocoaCookieDetails| object for the cookie prompt.
231@interface CookiePromptContentDetailsAdapter : NSObject {
232 @private
233  base::scoped_nsobject<CocoaCookieDetails> details_;
234}
235
236- (CocoaCookieDetails*)details;
237
238// The adapter assumes ownership of the details object
239// in its initializer.
240- (id)initWithDetails:(CocoaCookieDetails*)details;
241@end
242