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