| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "components/html_viewer/web_cookie_jar_impl.h" | |
| 6 | |
| 7 #include <utility> | |
| 8 | |
| 9 #include "base/bind.h" | |
| 10 #include "third_party/WebKit/public/platform/WebURL.h" | |
| 11 | |
| 12 using mojo::String; | |
| 13 | |
| 14 namespace html_viewer { | |
| 15 namespace { | |
| 16 | |
| 17 void CopyBool(bool* output, bool input) { | |
| 18 *output = input; | |
| 19 } | |
| 20 | |
| 21 void CopyString(String* output, const String& input) { | |
| 22 *output = input; | |
| 23 } | |
| 24 | |
| 25 } // namespace | |
| 26 | |
| 27 WebCookieJarImpl::WebCookieJarImpl(mojo::CookieStorePtr store) | |
| 28 : store_(std::move(store)) {} | |
| 29 | |
| 30 WebCookieJarImpl::~WebCookieJarImpl() { | |
| 31 } | |
| 32 | |
| 33 void WebCookieJarImpl::setCookie(const blink::WebURL& url, | |
| 34 const blink::WebURL& first_party_for_cookies, | |
| 35 const blink::WebString& cookie) { | |
| 36 bool success; | |
| 37 store_->Set(url.string().utf8(), cookie.utf8(), | |
| 38 base::Bind(&CopyBool, &success)); | |
| 39 | |
| 40 // Wait to ensure the cookie was set before advancing. That way any | |
| 41 // subsequent URL request will see the changes to the cookie store. | |
| 42 // | |
| 43 // TODO(darin): Consider using associated message pipes for the CookieStore | |
| 44 // and URLLoader, so that we could let this method call run asynchronously | |
| 45 // without suffering an ordering problem. See crbug/386825. | |
| 46 // | |
| 47 store_.WaitForIncomingResponse(); | |
| 48 } | |
| 49 | |
| 50 blink::WebString WebCookieJarImpl::cookies( | |
| 51 const blink::WebURL& url, | |
| 52 const blink::WebURL& first_party_for_cookies) { | |
| 53 String result; | |
| 54 store_->Get(url.string().utf8(), base::Bind(&CopyString, &result)); | |
| 55 | |
| 56 // Wait for the result. Since every outbound request we make to the cookie | |
| 57 // store is followed up with WaitForIncomingResponse, we can be sure that | |
| 58 // the next incoming method call will be the response to our request. | |
| 59 store_.WaitForIncomingResponse(); | |
| 60 if (!result) | |
| 61 return blink::WebString(); | |
| 62 | |
| 63 return blink::WebString::fromUTF8(result); | |
| 64 } | |
| 65 | |
| 66 blink::WebString WebCookieJarImpl::cookieRequestHeaderFieldValue( | |
| 67 const blink::WebURL& url, | |
| 68 const blink::WebURL& first_party_for_cookies) { | |
| 69 return cookies(url, first_party_for_cookies); | |
| 70 } | |
| 71 | |
| 72 } // namespace html_viewer | |
| OLD | NEW |