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.
5 #include "components/html_viewer/web_cookie_jar_impl.h"
8 #include "third_party/WebKit/public/platform/WebURL.h"
12 namespace html_viewer
{
15 void CopyBool(bool* output
, bool input
) {
19 void CopyString(String
* output
, const String
& input
) {
25 WebCookieJarImpl::WebCookieJarImpl(mojo::CookieStorePtr store
)
26 : store_(store
.Pass()) {
29 WebCookieJarImpl::~WebCookieJarImpl() {
32 void WebCookieJarImpl::setCookie(const blink::WebURL
& url
,
33 const blink::WebURL
& first_party_for_cookies
,
34 const blink::WebString
& cookie
) {
36 store_
->Set(url
.string().utf8(), cookie
.utf8(),
37 base::Bind(&CopyBool
, &success
));
39 // Wait to ensure the cookie was set before advancing. That way any
40 // subsequent URL request will see the changes to the cookie store.
42 // TODO(darin): Consider using associated message pipes for the CookieStore
43 // and URLLoader, so that we could let this method call run asynchronously
44 // without suffering an ordering problem. See crbug/386825.
46 store_
.WaitForIncomingMethodCall();
49 blink::WebString
WebCookieJarImpl::cookies(
50 const blink::WebURL
& url
,
51 const blink::WebURL
& first_party_for_cookies
) {
53 store_
->Get(url
.string().utf8(), base::Bind(&CopyString
, &result
));
55 // Wait for the result. Since every outbound request we make to the cookie
56 // store is followed up with WaitForIncomingMethodCall, we can be sure that
57 // the next incoming method call will be the response to our request.
58 store_
.WaitForIncomingMethodCall();
60 return blink::WebString();
62 return blink::WebString::fromUTF8(result
);
65 blink::WebString
WebCookieJarImpl::cookieRequestHeaderFieldValue(
66 const blink::WebURL
& url
,
67 const blink::WebURL
& first_party_for_cookies
) {
68 return cookies(url
, first_party_for_cookies
);
71 } // namespace html_viewer