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 "mojo/services/html_viewer/webcookiejar_impl.h"
8 #include "third_party/WebKit/public/platform/WebURL.h"
13 void CopyBool(bool* output
, bool input
) {
17 void CopyString(String
* output
, const String
& input
) {
23 WebCookieJarImpl::WebCookieJarImpl(CookieStorePtr store
)
24 : store_(store
.Pass()) {
27 WebCookieJarImpl::~WebCookieJarImpl() {
30 void WebCookieJarImpl::setCookie(const blink::WebURL
& url
,
31 const blink::WebURL
& first_party_for_cookies
,
32 const blink::WebString
& cookie
) {
34 store_
->Set(url
.string().utf8(), cookie
.utf8(),
35 base::Bind(&CopyBool
, &success
));
37 // Wait to ensure the cookie was set before advancing. That way any
38 // subsequent URL request will see the changes to the cookie store.
40 // TODO(darin): Consider using associated message pipes for the CookieStore
41 // and URLLoader, so that we could let this method call run asynchronously
42 // without suffering an ordering problem. See crbug/386825.
44 store_
.WaitForIncomingMethodCall();
47 blink::WebString
WebCookieJarImpl::cookies(
48 const blink::WebURL
& url
,
49 const blink::WebURL
& first_party_for_cookies
) {
51 store_
->Get(url
.string().utf8(), base::Bind(&CopyString
, &result
));
53 // Wait for the result. Since every outbound request we make to the cookie
54 // store is followed up with WaitForIncomingMethodCall, we can be sure that
55 // the next incoming method call will be the response to our request.
56 store_
.WaitForIncomingMethodCall();
58 return blink::WebString();
60 return blink::WebString::fromUTF8(result
);
63 blink::WebString
WebCookieJarImpl::cookieRequestHeaderFieldValue(
64 const blink::WebURL
& url
,
65 const blink::WebURL
& first_party_for_cookies
) {
66 return cookies(url
, first_party_for_cookies
);