Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: chrome/browser/extensions/api/cookies/cookies_helpers.cc

Issue 10785017: Move CanonicalCookie into separate files (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added missing include Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
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/api/cookies/cookies_api_constants.h" 13 #include "chrome/browser/extensions/api/cookies/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/ui/browser.h" 16 #include "chrome/browser/ui/browser.h"
17 #include "chrome/browser/ui/tab_contents/tab_contents.h" 17 #include "chrome/browser/ui/tab_contents/tab_contents.h"
18 #include "chrome/browser/ui/tabs/tab_strip_model.h" 18 #include "chrome/browser/ui/tabs/tab_strip_model.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 "content/public/browser/web_contents.h" 21 #include "content/public/browser/web_contents.h"
22 #include "googleurl/src/gurl.h" 22 #include "googleurl/src/gurl.h"
23 #include "net/cookies/canonical_cookie.h"
23 #include "net/cookies/cookie_util.h" 24 #include "net/cookies/cookie_util.h"
24 25
25 namespace extensions { 26 namespace extensions {
26 27
27 namespace keys = cookies_api_constants; 28 namespace keys = cookies_api_constants;
28 29
29 namespace cookies_helpers { 30 namespace cookies_helpers {
30 31
31 static const char kOriginalProfileStoreId[] = "0"; 32 static const char kOriginalProfileStoreId[] = "0";
32 static const char kOffTheRecordProfileStoreId[] = "1"; 33 static const char kOffTheRecordProfileStoreId[] = "1";
(...skipping 11 matching lines...) Expand all
44 return profile->GetOffTheRecordProfile(); 45 return profile->GetOffTheRecordProfile();
45 return NULL; 46 return NULL;
46 } 47 }
47 48
48 const char* GetStoreIdFromProfile(Profile* profile) { 49 const char* GetStoreIdFromProfile(Profile* profile) {
49 DCHECK(profile); 50 DCHECK(profile);
50 return profile->IsOffTheRecord() ? 51 return profile->IsOffTheRecord() ?
51 kOffTheRecordProfileStoreId : kOriginalProfileStoreId; 52 kOffTheRecordProfileStoreId : kOriginalProfileStoreId;
52 } 53 }
53 54
54 DictionaryValue* CreateCookieValue( 55 DictionaryValue* CreateCookieValue(const net::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()));
(...skipping 29 matching lines...) Expand all
96 DCHECK(cookie_store); 96 DCHECK(cookie_store);
97 net::CookieMonster* monster = cookie_store->GetCookieMonster(); 97 net::CookieMonster* monster = cookie_store->GetCookieMonster();
98 if (!url.is_empty()) { 98 if (!url.is_empty()) {
99 DCHECK(url.is_valid()); 99 DCHECK(url.is_valid());
100 monster->GetAllCookiesForURLAsync(url, callback); 100 monster->GetAllCookiesForURLAsync(url, callback);
101 } else { 101 } else {
102 monster->GetAllCookiesAsync(callback); 102 monster->GetAllCookiesAsync(callback);
103 } 103 }
104 } 104 }
105 105
106 GURL GetURLFromCanonicalCookie( 106 GURL GetURLFromCanonicalCookie(const net::CanonicalCookie& cookie) {
107 const net::CookieMonster::CanonicalCookie& cookie) {
108 const std::string& domain_key = cookie.Domain(); 107 const std::string& domain_key = cookie.Domain();
109 const std::string scheme = 108 const std::string scheme =
110 cookie.IsSecure() ? chrome::kHttpsScheme : chrome::kHttpScheme; 109 cookie.IsSecure() ? chrome::kHttpsScheme : chrome::kHttpScheme;
111 const std::string host = 110 const std::string host =
112 domain_key.find('.') != 0 ? domain_key : domain_key.substr(1); 111 domain_key.find('.') != 0 ? domain_key : domain_key.substr(1);
113 return GURL(scheme + content::kStandardSchemeSeparator + host + "/"); 112 return GURL(scheme + content::kStandardSchemeSeparator + host + "/");
114 } 113 }
115 114
116 void AppendMatchingCookiesToList( 115 void AppendMatchingCookiesToList(
117 const net::CookieList& all_cookies, 116 const net::CookieList& all_cookies,
(...skipping 24 matching lines...) Expand all
142 ExtensionTabUtil::GetTabId( 141 ExtensionTabUtil::GetTabId(
143 tab_strip->GetTabContentsAt(i)->web_contents()))); 142 tab_strip->GetTabContentsAt(i)->web_contents())));
144 } 143 }
145 } 144 }
146 145
147 MatchFilter::MatchFilter(const DictionaryValue* details) 146 MatchFilter::MatchFilter(const DictionaryValue* details)
148 : details_(details) { 147 : details_(details) {
149 DCHECK(details_); 148 DCHECK(details_);
150 } 149 }
151 150
152 bool MatchFilter::MatchesCookie( 151 bool MatchFilter::MatchesCookie(const net::CanonicalCookie& cookie) {
153 const net::CookieMonster::CanonicalCookie& cookie) {
154 return MatchesString(keys::kNameKey, cookie.Name()) && 152 return MatchesString(keys::kNameKey, cookie.Name()) &&
155 MatchesDomain(cookie.Domain()) && 153 MatchesDomain(cookie.Domain()) &&
156 MatchesString(keys::kPathKey, cookie.Path()) && 154 MatchesString(keys::kPathKey, cookie.Path()) &&
157 MatchesBoolean(keys::kSecureKey, cookie.IsSecure()) && 155 MatchesBoolean(keys::kSecureKey, cookie.IsSecure()) &&
158 MatchesBoolean(keys::kSessionKey, !cookie.IsPersistent()); 156 MatchesBoolean(keys::kSessionKey, !cookie.IsPersistent());
159 } 157 }
160 158
161 bool MatchFilter::MatchesString(const char* key, const std::string& value) { 159 bool MatchFilter::MatchesString(const char* key, const std::string& value) {
162 if (!details_->HasKey(key)) 160 if (!details_->HasKey(key))
163 return true; 161 return true;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 if (sub_domain == filter_value) 194 if (sub_domain == filter_value)
197 return true; 195 return true;
198 const size_t next_dot = sub_domain.find('.', 1); // Skip over leading dot. 196 const size_t next_dot = sub_domain.find('.', 1); // Skip over leading dot.
199 sub_domain.erase(0, next_dot); 197 sub_domain.erase(0, next_dot);
200 } 198 }
201 return false; 199 return false;
202 } 200 }
203 201
204 } // namespace cookies_helpers 202 } // namespace cookies_helpers
205 } // namespace extension 203 } // namespace extension
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698