| 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 <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/linked_ptr.h" | 12 #include "base/memory/linked_ptr.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
| 15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
| 16 #include "base/values.h" | 16 #include "base/values.h" |
| 17 #include "chrome/browser/extensions/api/cookies/cookies_api_constants.h" | 17 #include "chrome/browser/extensions/api/cookies/cookies_api_constants.h" |
| 18 #include "chrome/browser/extensions/extension_tab_util.h" | 18 #include "chrome/browser/extensions/extension_tab_util.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/browser/ui/browser.h" | 20 #include "chrome/browser/ui/browser.h" |
| 21 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 21 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 22 #include "chrome/common/extensions/api/cookies.h" | 22 #include "chrome/common/extensions/api/cookies.h" |
| 23 #include "chrome/common/extensions/extension.h" | 23 #include "chrome/common/extensions/extension.h" |
| 24 #include "chrome/common/extensions/permissions/permissions_data.h" |
| 24 #include "chrome/common/url_constants.h" | 25 #include "chrome/common/url_constants.h" |
| 25 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
| 26 #include "googleurl/src/gurl.h" | 27 #include "googleurl/src/gurl.h" |
| 27 #include "net/cookies/canonical_cookie.h" | 28 #include "net/cookies/canonical_cookie.h" |
| 28 #include "net/cookies/cookie_util.h" | 29 #include "net/cookies/cookie_util.h" |
| 29 | 30 |
| 30 using extensions::api::cookies::Cookie; | 31 using extensions::api::cookies::Cookie; |
| 31 using extensions::api::cookies::CookieStore; | 32 using extensions::api::cookies::CookieStore; |
| 32 | 33 |
| 33 namespace GetAll = extensions::api::cookies::GetAll; | 34 namespace GetAll = extensions::api::cookies::GetAll; |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 void AppendMatchingCookiesToVector(const net::CookieList& all_cookies, | 128 void AppendMatchingCookiesToVector(const net::CookieList& all_cookies, |
| 128 const GURL& url, | 129 const GURL& url, |
| 129 const GetAll::Params::Details* details, | 130 const GetAll::Params::Details* details, |
| 130 const Extension* extension, | 131 const Extension* extension, |
| 131 LinkedCookieVec* match_vector) { | 132 LinkedCookieVec* match_vector) { |
| 132 net::CookieList::const_iterator it; | 133 net::CookieList::const_iterator it; |
| 133 for (it = all_cookies.begin(); it != all_cookies.end(); ++it) { | 134 for (it = all_cookies.begin(); it != all_cookies.end(); ++it) { |
| 134 // Ignore any cookie whose domain doesn't match the extension's | 135 // Ignore any cookie whose domain doesn't match the extension's |
| 135 // host permissions. | 136 // host permissions. |
| 136 GURL cookie_domain_url = GetURLFromCanonicalCookie(*it); | 137 GURL cookie_domain_url = GetURLFromCanonicalCookie(*it); |
| 137 if (!extension->HasHostPermission(cookie_domain_url)) | 138 if (!PermissionsData::HasHostPermission(extension, cookie_domain_url)) |
| 138 continue; | 139 continue; |
| 139 // Filter the cookie using the match filter. | 140 // Filter the cookie using the match filter. |
| 140 cookies_helpers::MatchFilter filter(details); | 141 cookies_helpers::MatchFilter filter(details); |
| 141 if (filter.MatchesCookie(*it)) { | 142 if (filter.MatchesCookie(*it)) { |
| 142 match_vector->push_back(make_linked_ptr( | 143 match_vector->push_back(make_linked_ptr( |
| 143 CreateCookie(*it, *details->store_id).release())); | 144 CreateCookie(*it, *details->store_id).release())); |
| 144 } | 145 } |
| 145 } | 146 } |
| 146 } | 147 } |
| 147 | 148 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 if (sub_domain == *details_->domain) | 200 if (sub_domain == *details_->domain) |
| 200 return true; | 201 return true; |
| 201 const size_t next_dot = sub_domain.find('.', 1); // Skip over leading dot. | 202 const size_t next_dot = sub_domain.find('.', 1); // Skip over leading dot. |
| 202 sub_domain.erase(0, next_dot); | 203 sub_domain.erase(0, next_dot); |
| 203 } | 204 } |
| 204 return false; | 205 return false; |
| 205 } | 206 } |
| 206 | 207 |
| 207 } // namespace cookies_helpers | 208 } // namespace cookies_helpers |
| 208 } // namespace extension | 209 } // namespace extension |
| OLD | NEW |