OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Implements common functionality for the Chrome Extensions Cookies API. | 5 // Implements common functionality for the Chrome Extensions Cookies API. |
6 | 6 |
7 #include "chrome/browser/extensions/api/cookies/cookies_helpers.h" | 7 #include "chrome/browser/extensions/api/cookies/cookies_helpers.h" |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 return profile->GetOffTheRecordProfile(); | 44 return profile->GetOffTheRecordProfile(); |
45 return NULL; | 45 return NULL; |
46 } | 46 } |
47 | 47 |
48 const char* GetStoreIdFromProfile(Profile* profile) { | 48 const char* GetStoreIdFromProfile(Profile* profile) { |
49 DCHECK(profile); | 49 DCHECK(profile); |
50 return profile->IsOffTheRecord() ? | 50 return profile->IsOffTheRecord() ? |
51 kOffTheRecordProfileStoreId : kOriginalProfileStoreId; | 51 kOffTheRecordProfileStoreId : kOriginalProfileStoreId; |
52 } | 52 } |
53 | 53 |
54 DictionaryValue* CreateCookieValue( | 54 base::DictionaryValue* CreateCookieValue( |
55 const net::CookieMonster::CanonicalCookie& cookie, | 55 const net::CookieMonster::CanonicalCookie& cookie, |
56 const std::string& store_id) { | 56 const std::string& store_id) { |
57 DictionaryValue* result = new DictionaryValue(); | 57 DictionaryValue* result = new DictionaryValue(); |
58 | 58 |
59 // A cookie is a raw byte sequence. By explicitly parsing it as UTF8, we | 59 // A cookie is a raw byte sequence. By explicitly parsing it as UTF8, we |
60 // apply error correction, so the string can be safely passed to the | 60 // apply error correction, so the string can be safely passed to the |
61 // renderer. | 61 // renderer. |
62 result->SetString(keys::kNameKey, UTF8ToUTF16(cookie.Name())); | 62 result->SetString(keys::kNameKey, UTF8ToUTF16(cookie.Name())); |
63 result->SetString(keys::kValueKey, UTF8ToUTF16(cookie.Value())); | 63 result->SetString(keys::kValueKey, UTF8ToUTF16(cookie.Value())); |
64 result->SetString(keys::kDomainKey, cookie.Domain()); | 64 result->SetString(keys::kDomainKey, cookie.Domain()); |
65 result->SetBoolean(keys::kHostOnlyKey, | 65 result->SetBoolean(keys::kHostOnlyKey, |
66 net::cookie_util::DomainIsHostOnly(cookie.Domain())); | 66 net::cookie_util::DomainIsHostOnly(cookie.Domain())); |
67 | 67 |
68 // A non-UTF8 path is invalid, so we just replace it with an empty string. | 68 // A non-UTF8 path is invalid, so we just replace it with an empty string. |
69 result->SetString(keys::kPathKey, | 69 result->SetString(keys::kPathKey, |
70 IsStringUTF8(cookie.Path()) ? cookie.Path() : ""); | 70 IsStringUTF8(cookie.Path()) ? cookie.Path() : ""); |
71 result->SetBoolean(keys::kSecureKey, cookie.IsSecure()); | 71 result->SetBoolean(keys::kSecureKey, cookie.IsSecure()); |
72 result->SetBoolean(keys::kHttpOnlyKey, cookie.IsHttpOnly()); | 72 result->SetBoolean(keys::kHttpOnlyKey, cookie.IsHttpOnly()); |
73 result->SetBoolean(keys::kSessionKey, !cookie.DoesExpire()); | 73 result->SetBoolean(keys::kSessionKey, !cookie.DoesExpire()); |
74 if (cookie.DoesExpire()) { | 74 if (cookie.DoesExpire()) { |
75 result->SetDouble(keys::kExpirationDateKey, | 75 result->SetDouble(keys::kExpirationDateKey, |
76 cookie.ExpiryDate().ToDoubleT()); | 76 cookie.ExpiryDate().ToDoubleT()); |
77 } | 77 } |
78 result->SetString(keys::kStoreIdKey, store_id); | 78 result->SetString(keys::kStoreIdKey, store_id); |
79 | 79 |
80 return result; | 80 return result; |
81 } | 81 } |
82 | 82 |
83 DictionaryValue* CreateCookieStoreValue(Profile* profile, | 83 base::DictionaryValue* CreateCookieStoreValue(Profile* profile, |
84 ListValue* tab_ids) { | 84 ListValue* tab_ids) { |
85 DCHECK(profile); | 85 DCHECK(profile); |
86 DCHECK(tab_ids); | 86 DCHECK(tab_ids); |
87 DictionaryValue* result = new DictionaryValue(); | 87 DictionaryValue* result = new DictionaryValue(); |
88 result->SetString(keys::kIdKey, GetStoreIdFromProfile(profile)); | 88 result->SetString(keys::kIdKey, GetStoreIdFromProfile(profile)); |
89 result->Set(keys::kTabIdsKey, tab_ids); | 89 result->Set(keys::kTabIdsKey, tab_ids); |
90 return result; | 90 return result; |
91 } | 91 } |
92 | 92 |
93 void GetCookieListFromStore( | 93 void GetCookieListFromStore( |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 if (sub_domain == filter_value) | 196 if (sub_domain == filter_value) |
197 return true; | 197 return true; |
198 const size_t next_dot = sub_domain.find('.', 1); // Skip over leading dot. | 198 const size_t next_dot = sub_domain.find('.', 1); // Skip over leading dot. |
199 sub_domain.erase(0, next_dot); | 199 sub_domain.erase(0, next_dot); |
200 } | 200 } |
201 return false; | 201 return false; |
202 } | 202 } |
203 | 203 |
204 } // namespace cookies_helpers | 204 } // namespace cookies_helpers |
205 } // namespace extension | 205 } // namespace extension |
OLD | NEW |