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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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.IsPersistent()); |
74 if (cookie.DoesExpire()) { | 74 if (cookie.IsPersistent()) { |
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 DictionaryValue* CreateCookieStoreValue(Profile* profile, |
84 ListValue* tab_ids) { | 84 ListValue* tab_ids) { |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 : details_(details) { | 148 : details_(details) { |
149 DCHECK(details_); | 149 DCHECK(details_); |
150 } | 150 } |
151 | 151 |
152 bool MatchFilter::MatchesCookie( | 152 bool MatchFilter::MatchesCookie( |
153 const net::CookieMonster::CanonicalCookie& cookie) { | 153 const net::CookieMonster::CanonicalCookie& cookie) { |
154 return MatchesString(keys::kNameKey, cookie.Name()) && | 154 return MatchesString(keys::kNameKey, cookie.Name()) && |
155 MatchesDomain(cookie.Domain()) && | 155 MatchesDomain(cookie.Domain()) && |
156 MatchesString(keys::kPathKey, cookie.Path()) && | 156 MatchesString(keys::kPathKey, cookie.Path()) && |
157 MatchesBoolean(keys::kSecureKey, cookie.IsSecure()) && | 157 MatchesBoolean(keys::kSecureKey, cookie.IsSecure()) && |
158 MatchesBoolean(keys::kSessionKey, !cookie.DoesExpire()); | 158 MatchesBoolean(keys::kSessionKey, !cookie.IsPersistent()); |
159 } | 159 } |
160 | 160 |
161 bool MatchFilter::MatchesString(const char* key, const std::string& value) { | 161 bool MatchFilter::MatchesString(const char* key, const std::string& value) { |
162 if (!details_->HasKey(key)) | 162 if (!details_->HasKey(key)) |
163 return true; | 163 return true; |
164 std::string filter_value; | 164 std::string filter_value; |
165 return (details_->GetString(key, &filter_value) && | 165 return (details_->GetString(key, &filter_value) && |
166 value == filter_value); | 166 value == filter_value); |
167 } | 167 } |
168 | 168 |
(...skipping 27 matching lines...) Expand all 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 |