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