blob: 6cde0518c0bb0888a3c7e5be674b79cf295993b4 (
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
|
// Copyright (c) 2012 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.
#include "chrome/browser/ui/cocoa/content_settings/cookie_details.h"
#import "base/i18n/time_formatting.h"
#include "base/strings/sys_string_conversions.h"
#include "chrome/browser/browsing_data/cookies_tree_model.h"
#include "grit/generated_resources.h"
#include "net/cookies/canonical_cookie.h"
#include "ui/base/l10n/l10n_util_mac.h"
#include "ui/base/text/bytes_formatting.h"
#include "webkit/browser/appcache/appcache_service.h"
#pragma mark Cocoa Cookie Details
@implementation CocoaCookieDetails
@synthesize canEditExpiration = canEditExpiration_;
@synthesize hasExpiration = hasExpiration_;
@synthesize type = type_;
- (BOOL)shouldHideCookieDetailsView {
return type_ != kCocoaCookieDetailsTypeFolder &&
type_ != kCocoaCookieDetailsTypeCookie;
}
- (BOOL)shouldShowLocalStorageTreeDetailsView {
return type_ == kCocoaCookieDetailsTypeTreeLocalStorage;
}
- (BOOL)shouldShowLocalStoragePromptDetailsView {
return type_ == kCocoaCookieDetailsTypePromptLocalStorage;
}
- (BOOL)shouldShowDatabaseTreeDetailsView {
return type_ == kCocoaCookieDetailsTypeTreeDatabase;
}
- (BOOL)shouldShowAppCacheTreeDetailsView {
return type_ == kCocoaCookieDetailsTypeTreeAppCache;
}
- (BOOL)shouldShowDatabasePromptDetailsView {
return type_ == kCocoaCookieDetailsTypePromptDatabase;
}
- (BOOL)shouldShowAppCachePromptDetailsView {
return type_ == kCocoaCookieDetailsTypePromptAppCache;
}
- (BOOL)shouldShowIndexedDBTreeDetailsView {
return type_ == kCocoaCookieDetailsTypeTreeIndexedDB;
}
- (NSString*)name {
return name_.get();
}
- (NSString*)content {
return content_.get();
}
- (NSString*)domain {
return domain_.get();
}
- (NSString*)path {
return path_.get();
}
- (NSString*)sendFor {
return sendFor_.get();
}
- (NSString*)created {
return created_.get();
}
- (NSString*)expires {
return expires_.get();
}
- (NSString*)fileSize {
return fileSize_.get();
}
- (NSString*)lastModified {
return lastModified_.get();
}
- (NSString*)lastAccessed {
return lastAccessed_.get();
}
- (NSString*)databaseDescription {
return databaseDescription_.get();
}
- (NSString*)localStorageKey {
return localStorageKey_.get();
}
- (NSString*)localStorageValue {
return localStorageValue_.get();
}
- (NSString*)manifestURL {
return manifestURL_.get();
}
- (id)initAsFolder {
if ((self = [super init])) {
type_ = kCocoaCookieDetailsTypeFolder;
}
return self;
}
- (id)initWithCookie:(const net::CanonicalCookie*)cookie
canEditExpiration:(BOOL)canEditExpiration {
if ((self = [super init])) {
type_ = kCocoaCookieDetailsTypeCookie;
hasExpiration_ = cookie->IsPersistent();
canEditExpiration_ = canEditExpiration && hasExpiration_;
name_.reset([base::SysUTF8ToNSString(cookie->Name()) retain]);
content_.reset([base::SysUTF8ToNSString(cookie->Value()) retain]);
path_.reset([base::SysUTF8ToNSString(cookie->Path()) retain]);
domain_.reset([base::SysUTF8ToNSString(cookie->Domain()) retain]);
if (cookie->IsPersistent()) {
expires_.reset([base::SysUTF16ToNSString(
base::TimeFormatFriendlyDateAndTime(cookie->ExpiryDate())) retain]);
} else {
expires_.reset([l10n_util::GetNSStringWithFixup(
IDS_COOKIES_COOKIE_EXPIRES_SESSION) retain]);
}
created_.reset([base::SysUTF16ToNSString(
base::TimeFormatFriendlyDateAndTime(cookie->CreationDate())) retain]);
if (cookie->IsSecure()) {
sendFor_.reset([l10n_util::GetNSStringWithFixup(
IDS_COOKIES_COOKIE_SENDFOR_SECURE) retain]);
} else {
sendFor_.reset([l10n_util::GetNSStringWithFixup(
IDS_COOKIES_COOKIE_SENDFOR_ANY) retain]);
}
}
return self;
}
- (id)initWithDatabase:(const BrowsingDataDatabaseHelper::DatabaseInfo*)
databaseInfo {
if ((self = [super init])) {
type_ = kCocoaCookieDetailsTypeTreeDatabase;
canEditExpiration_ = NO;
databaseDescription_.reset([base::SysUTF8ToNSString(
databaseInfo->description) retain]);
fileSize_.reset([base::SysUTF16ToNSString(
ui::FormatBytes(databaseInfo->size)) retain]);
lastModified_.reset([base::SysUTF16ToNSString(
base::TimeFormatFriendlyDateAndTime(
databaseInfo->last_modified)) retain]);
}
return self;
}
- (id)initWithLocalStorage:(
const BrowsingDataLocalStorageHelper::LocalStorageInfo*)storageInfo {
if ((self = [super init])) {
type_ = kCocoaCookieDetailsTypeTreeLocalStorage;
canEditExpiration_ = NO;
domain_.reset(
[base::SysUTF8ToNSString(storageInfo->origin_url.spec()) retain]);
fileSize_.reset(
[base::SysUTF16ToNSString(ui::FormatBytes(storageInfo->size)) retain]);
lastModified_.reset([base::SysUTF16ToNSString(
base::TimeFormatFriendlyDateAndTime(
storageInfo->last_modified)) retain]);
}
return self;
}
- (id)initWithAppCacheInfo:(const appcache::AppCacheInfo*)appcacheInfo {
if ((self = [super init])) {
type_ = kCocoaCookieDetailsTypeTreeAppCache;
canEditExpiration_ = NO;
manifestURL_.reset([base::SysUTF8ToNSString(
appcacheInfo->manifest_url.spec()) retain]);
fileSize_.reset([base::SysUTF16ToNSString(
ui::FormatBytes(appcacheInfo->size)) retain]);
created_.reset([base::SysUTF16ToNSString(
base::TimeFormatFriendlyDateAndTime(
appcacheInfo->creation_time)) retain]);
lastAccessed_.reset([base::SysUTF16ToNSString(
base::TimeFormatFriendlyDateAndTime(
appcacheInfo->last_access_time)) retain]);
}
return self;
}
- (id)initWithDatabase:(const std::string&)domain
databaseName:(const string16&)databaseName
databaseDescription:(const string16&)databaseDescription
fileSize:(unsigned long)fileSize {
if ((self = [super init])) {
type_ = kCocoaCookieDetailsTypePromptDatabase;
canEditExpiration_ = NO;
name_.reset([base::SysUTF16ToNSString(databaseName) retain]);
domain_.reset([base::SysUTF8ToNSString(domain) retain]);
databaseDescription_.reset(
[base::SysUTF16ToNSString(databaseDescription) retain]);
fileSize_.reset(
[base::SysUTF16ToNSString(ui::FormatBytes(fileSize)) retain]);
}
return self;
}
- (id)initWithLocalStorage:(const std::string&)domain
key:(const string16&)key
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]);
}
return self;
}
- (id)initWithAppCacheManifestURL:(const std::string&)manifestURL {
if ((self = [super init])) {
type_ = kCocoaCookieDetailsTypePromptAppCache;
canEditExpiration_ = NO;
manifestURL_.reset([base::SysUTF8ToNSString(manifestURL) retain]);
}
return self;
}
- (id)initWithIndexedDBInfo:
(const content::IndexedDBInfo*)indexedDBInfo {
if ((self = [super init])) {
type_ = kCocoaCookieDetailsTypeTreeIndexedDB;
canEditExpiration_ = NO;
domain_.reset([base::SysUTF8ToNSString(
indexedDBInfo->origin_.spec()) retain]);
fileSize_.reset([base::SysUTF16ToNSString(
ui::FormatBytes(indexedDBInfo->size_)) retain]);
lastModified_.reset([base::SysUTF16ToNSString(
base::TimeFormatFriendlyDateAndTime(
indexedDBInfo->last_modified_)) retain]);
}
return self;
}
+ (CocoaCookieDetails*)createFromCookieTreeNode:(CookieTreeNode*)treeNode {
CookieTreeNode::DetailedInfo info = treeNode->GetDetailedInfo();
CookieTreeNode::DetailedInfo::NodeType nodeType = info.node_type;
switch (nodeType) {
case CookieTreeNode::DetailedInfo::TYPE_COOKIE:
return [[[CocoaCookieDetails alloc] initWithCookie:info.cookie
canEditExpiration:NO] autorelease];
case CookieTreeNode::DetailedInfo::TYPE_DATABASE:
return [[[CocoaCookieDetails alloc]
initWithDatabase:info.database_info] autorelease];
case CookieTreeNode::DetailedInfo::TYPE_LOCAL_STORAGE:
return [[[CocoaCookieDetails alloc]
initWithLocalStorage:info.local_storage_info] autorelease];
case CookieTreeNode::DetailedInfo::TYPE_APPCACHE:
return [[[CocoaCookieDetails alloc]
initWithAppCacheInfo:info.appcache_info] autorelease];
case CookieTreeNode::DetailedInfo::TYPE_INDEXED_DB:
return [[[CocoaCookieDetails alloc]
initWithIndexedDBInfo:info.indexed_db_info] autorelease];
default:
return [[[CocoaCookieDetails alloc] initAsFolder] autorelease];
}
}
@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
|