Chromium Code Reviews| 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 #include "chrome/browser/chromeos/login/profile_auth_data.h" | 5 #include "chrome/browser/chromeos/login/profile_auth_data.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 37 const char kSAMLStartCookie[] = "google-accounts-saml-start"; | 37 const char kSAMLStartCookie[] = "google-accounts-saml-start"; |
| 38 const char kSAMLEndCookie[] = "google-accounts-saml-end"; | 38 const char kSAMLEndCookie[] = "google-accounts-saml-end"; |
| 39 | 39 |
| 40 // Import |cookies| into |cookie_store|. | 40 // Import |cookies| into |cookie_store|. |
| 41 void ImportCookies(const net::CookieList& cookies, | 41 void ImportCookies(const net::CookieList& cookies, |
| 42 net::CookieStore* cookie_store) { | 42 net::CookieStore* cookie_store) { |
| 43 for (const auto& cookie : cookies) { | 43 for (const auto& cookie : cookies) { |
| 44 // To re-create the original cookie, a domain should only be passed in to | 44 // To re-create the original cookie, a domain should only be passed in to |
| 45 // SetCookieWithDetailsAsync if cookie.Domain() has a leading period, to | 45 // SetCookieWithDetailsAsync if cookie.Domain() has a leading period, to |
| 46 // re-create the original cookie. | 46 // re-create the original cookie. |
| 47 std::string domain; | 47 std::string effective_domain = cookie.Domain(); |
|
achuithb
2016/07/13 09:18:31
Could we add a unit test for this?
mmenke
2016/07/14 17:34:57
The no-dot path was already being tested. Added a
| |
| 48 if (!cookie.Domain().empty() && cookie.Domain()[0] == '.') | 48 std::string host; |
| 49 domain = cookie.Domain(); | 49 if (effective_domain.length() > 1 && effective_domain[0] == '.') { |
| 50 host = effective_domain.substr(1); | |
| 51 } else { | |
| 52 host = effective_domain; | |
| 53 effective_domain = ""; | |
| 54 } | |
| 55 | |
| 56 // Assume HTTPS - since the cookies are being restored from another store, | |
| 57 // they have already gone through the strict secure check. | |
| 58 GURL url(std::string(url::kHttpsScheme) + url::kStandardSchemeSeparator + | |
| 59 host + "/"); | |
| 50 | 60 |
| 51 cookie_store->SetCookieWithDetailsAsync( | 61 cookie_store->SetCookieWithDetailsAsync( |
| 52 cookie.Source(), cookie.Name(), cookie.Value(), domain, cookie.Path(), | 62 url, cookie.Name(), cookie.Value(), effective_domain, cookie.Path(), |
| 53 cookie.CreationDate(), cookie.ExpiryDate(), cookie.LastAccessDate(), | 63 cookie.CreationDate(), cookie.ExpiryDate(), cookie.LastAccessDate(), |
| 54 cookie.IsSecure(), cookie.IsHttpOnly(), cookie.SameSite(), | 64 cookie.IsSecure(), cookie.IsHttpOnly(), cookie.SameSite(), |
| 55 // enforce_strict_secure should have been applied on the original | 65 // enforce_strict_secure should have been applied on the original |
| 56 // cookie, prior to import. | 66 // cookie, prior to import. This allows URL to be treated as an HTTP |
|
Mike West
2016/07/13 09:59:26
Nit: "... to be treated as an _HTTPS_ URL"?
mmenke
2016/07/14 17:34:57
Done
| |
| 67 // URL, whether the cookie was set by an HTTP or HTTPS domain (Something | |
| 68 // that can't be determined by just looking at the CanonicalCookie). | |
| 57 false, cookie.Priority(), net::CookieStore::SetCookiesCallback()); | 69 false, cookie.Priority(), net::CookieStore::SetCookiesCallback()); |
| 58 } | 70 } |
| 59 } | 71 } |
| 60 | 72 |
| 61 class ProfileAuthDataTransferer { | 73 class ProfileAuthDataTransferer { |
| 62 public: | 74 public: |
| 63 ProfileAuthDataTransferer( | 75 ProfileAuthDataTransferer( |
| 64 net::URLRequestContextGetter* from_context, | 76 net::URLRequestContextGetter* from_context, |
| 65 net::URLRequestContextGetter* to_context, | 77 net::URLRequestContextGetter* to_context, |
| 66 bool transfer_auth_cookies_and_channel_ids_on_first_login, | 78 bool transfer_auth_cookies_and_channel_ids_on_first_login, |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 338 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 350 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 339 (new ProfileAuthDataTransferer( | 351 (new ProfileAuthDataTransferer( |
| 340 from_context, | 352 from_context, |
| 341 to_context, | 353 to_context, |
| 342 transfer_auth_cookies_and_channel_ids_on_first_login, | 354 transfer_auth_cookies_and_channel_ids_on_first_login, |
| 343 transfer_saml_auth_cookies_on_subsequent_login, | 355 transfer_saml_auth_cookies_on_subsequent_login, |
| 344 completion_callback))->BeginTransfer(); | 356 completion_callback))->BeginTransfer(); |
| 345 } | 357 } |
| 346 | 358 |
| 347 } // namespace chromeos | 359 } // namespace chromeos |
| OLD | NEW |