| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/extension_cookies_helpers.h" | 7 #include "chrome/browser/extensions/extension_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" |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "chrome/browser/extensions/extension_cookies_api_constants.h" | 13 #include "chrome/browser/extensions/extension_cookies_api_constants.h" |
| 14 #include "chrome/browser/extensions/extension_tab_util.h" | 14 #include "chrome/browser/extensions/extension_tab_util.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/tabs/tab_strip_model.h" | 16 #include "chrome/browser/tabs/tab_strip_model.h" |
| 17 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
| 18 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 18 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 19 #include "chrome/common/extensions/extension.h" | 19 #include "chrome/common/extensions/extension.h" |
| 20 #include "chrome/common/url_constants.h" | 20 #include "chrome/common/url_constants.h" |
| 21 #include "googleurl/src/gurl.h" | 21 #include "googleurl/src/gurl.h" |
| 22 #include "net/base/cookie_utils.h" | |
| 23 | 22 |
| 24 namespace keys = extension_cookies_api_constants; | 23 namespace keys = extension_cookies_api_constants; |
| 25 | 24 |
| 26 namespace extension_cookies_helpers { | 25 namespace extension_cookies_helpers { |
| 27 | 26 |
| 28 static const char kOriginalProfileStoreId[] = "0"; | 27 static const char kOriginalProfileStoreId[] = "0"; |
| 29 static const char kOffTheRecordProfileStoreId[] = "1"; | 28 static const char kOffTheRecordProfileStoreId[] = "1"; |
| 30 | 29 |
| 31 Profile* ChooseProfileFromStoreId(const std::string& store_id, | 30 Profile* ChooseProfileFromStoreId(const std::string& store_id, |
| 32 Profile* profile, | 31 Profile* profile, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 53 const std::string& store_id) { | 52 const std::string& store_id) { |
| 54 DictionaryValue* result = new DictionaryValue(); | 53 DictionaryValue* result = new DictionaryValue(); |
| 55 | 54 |
| 56 // A cookie is a raw byte sequence. By explicitly parsing it as UTF8, we | 55 // A cookie is a raw byte sequence. By explicitly parsing it as UTF8, we |
| 57 // apply error correction, so the string can be safely passed to the | 56 // apply error correction, so the string can be safely passed to the |
| 58 // renderer. | 57 // renderer. |
| 59 result->SetString(keys::kNameKey, UTF8ToUTF16(cookie.Name())); | 58 result->SetString(keys::kNameKey, UTF8ToUTF16(cookie.Name())); |
| 60 result->SetString(keys::kValueKey, UTF8ToUTF16(cookie.Value())); | 59 result->SetString(keys::kValueKey, UTF8ToUTF16(cookie.Value())); |
| 61 result->SetString(keys::kDomainKey, cookie.Domain()); | 60 result->SetString(keys::kDomainKey, cookie.Domain()); |
| 62 result->SetBoolean(keys::kHostOnlyKey, | 61 result->SetBoolean(keys::kHostOnlyKey, |
| 63 net::cookie_utils::DomainIsHostOnly(cookie.Domain())); | 62 net::CookieMonster::DomainIsHostOnly(cookie.Domain())); |
| 64 | 63 |
| 65 // A non-UTF8 path is invalid, so we just replace it with an empty string. | 64 // A non-UTF8 path is invalid, so we just replace it with an empty string. |
| 66 result->SetString(keys::kPathKey, | 65 result->SetString(keys::kPathKey, |
| 67 IsStringUTF8(cookie.Path()) ? cookie.Path() : ""); | 66 IsStringUTF8(cookie.Path()) ? cookie.Path() : ""); |
| 68 result->SetBoolean(keys::kSecureKey, cookie.IsSecure()); | 67 result->SetBoolean(keys::kSecureKey, cookie.IsSecure()); |
| 69 result->SetBoolean(keys::kHttpOnlyKey, cookie.IsHttpOnly()); | 68 result->SetBoolean(keys::kHttpOnlyKey, cookie.IsHttpOnly()); |
| 70 result->SetBoolean(keys::kSessionKey, !cookie.DoesExpire()); | 69 result->SetBoolean(keys::kSessionKey, !cookie.DoesExpire()); |
| 71 if (cookie.DoesExpire()) { | 70 if (cookie.DoesExpire()) { |
| 72 result->SetDouble(keys::kExpirationDateKey, | 71 result->SetDouble(keys::kExpirationDateKey, |
| 73 cookie.ExpiryDate().ToDoubleT()); | 72 cookie.ExpiryDate().ToDoubleT()); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 } | 171 } |
| 173 | 172 |
| 174 bool MatchFilter::MatchesDomain(const std::string& domain) { | 173 bool MatchFilter::MatchesDomain(const std::string& domain) { |
| 175 if (!details_->HasKey(keys::kDomainKey)) | 174 if (!details_->HasKey(keys::kDomainKey)) |
| 176 return true; | 175 return true; |
| 177 | 176 |
| 178 std::string filter_value; | 177 std::string filter_value; |
| 179 if (!details_->GetString(keys::kDomainKey, &filter_value)) | 178 if (!details_->GetString(keys::kDomainKey, &filter_value)) |
| 180 return false; | 179 return false; |
| 181 // Add a leading '.' character to the filter domain if it doesn't exist. | 180 // Add a leading '.' character to the filter domain if it doesn't exist. |
| 182 if (net::cookie_utils::DomainIsHostOnly(filter_value)) | 181 if (net::CookieMonster::DomainIsHostOnly(filter_value)) |
| 183 filter_value.insert(0, "."); | 182 filter_value.insert(0, "."); |
| 184 | 183 |
| 185 std::string sub_domain(domain); | 184 std::string sub_domain(domain); |
| 186 // Strip any leading '.' character from the input cookie domain. | 185 // Strip any leading '.' character from the input cookie domain. |
| 187 if (!net::cookie_utils::DomainIsHostOnly(sub_domain)) | 186 if (!net::CookieMonster::DomainIsHostOnly(sub_domain)) |
| 188 sub_domain = sub_domain.substr(1); | 187 sub_domain = sub_domain.substr(1); |
| 189 | 188 |
| 190 // Now check whether the domain argument is a subdomain of the filter domain. | 189 // Now check whether the domain argument is a subdomain of the filter domain. |
| 191 for (sub_domain.insert(0, "."); | 190 for (sub_domain.insert(0, "."); |
| 192 sub_domain.length() >= filter_value.length();) { | 191 sub_domain.length() >= filter_value.length();) { |
| 193 if (sub_domain == filter_value) | 192 if (sub_domain == filter_value) |
| 194 return true; | 193 return true; |
| 195 const size_t next_dot = sub_domain.find('.', 1); // Skip over leading dot. | 194 const size_t next_dot = sub_domain.find('.', 1); // Skip over leading dot. |
| 196 sub_domain.erase(0, next_dot); | 195 sub_domain.erase(0, next_dot); |
| 197 } | 196 } |
| 198 return false; | 197 return false; |
| 199 } | 198 } |
| 200 | 199 |
| 201 } // namespace extension_cookies_helpers | 200 } // namespace extension_cookies_helpers |
| OLD | NEW |