Chromium Code Reviews| Index: mojo/services/html_viewer/webcookiejar_impl.cc |
| diff --git a/mojo/services/html_viewer/webcookiejar_impl.cc b/mojo/services/html_viewer/webcookiejar_impl.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c6adae65793fbb09cd0e93ca8440449c90b47adc |
| --- /dev/null |
| +++ b/mojo/services/html_viewer/webcookiejar_impl.cc |
| @@ -0,0 +1,64 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "mojo/services/html_viewer/webcookiejar_impl.h" |
| + |
| +#include "base/bind.h" |
| +#include "third_party/WebKit/public/platform/WebURL.h" |
| + |
| +namespace mojo { |
| +namespace { |
| + |
| +void CopyBool(bool* output, bool input) { |
| + *output = input; |
| +} |
| + |
| +void CopyString(String* output, const String& input) { |
| + *output = input; |
| +} |
| + |
| +} // namespace |
| + |
| +WebCookieJarImpl::WebCookieJarImpl(CookieStorePtr store) |
| + : store_(store.Pass()) { |
| +} |
| + |
| +WebCookieJarImpl::~WebCookieJarImpl() { |
| +} |
| + |
| +void WebCookieJarImpl::setCookie(const blink::WebURL& url, |
| + const blink::WebURL& first_party_for_cookies, |
| + const blink::WebString& cookie) { |
| + bool success; |
| + store_->Set(url.string().utf8(), cookie.utf8(), |
| + base::Bind(&CopyBool, &success)); |
| + |
| + // Wait to ensure the cookie was set before advancing. That way any |
|
jamesr
2014/07/22 23:53:44
in content's cookie jar Gets are blocking but Sets
|
| + // subsequent URL request will see the changes to the cookie store. |
| + store_.WaitForIncomingMethodCall(); |
| +} |
| + |
| +blink::WebString WebCookieJarImpl::cookies( |
| + const blink::WebURL& url, |
| + const blink::WebURL& first_party_for_cookies) { |
| + String result; |
| + store_->Get(url.string().utf8(), base::Bind(&CopyString, &result)); |
| + |
| + // Wait for the result. Since every outbound request we make to the cookie |
| + // store is followed up with WaitForIncomingMethodCall, we can be sure that |
| + // the next incoming method call will be the response to our request. |
| + store_.WaitForIncomingMethodCall(); |
|
jamesr
2014/07/22 23:53:44
or is it that if we allow multiple set calls to be
|
| + if (!result) |
| + return blink::WebString(); |
| + |
| + return blink::WebString::fromUTF8(result); |
| +} |
| + |
| +blink::WebString WebCookieJarImpl::cookieRequestHeaderFieldValue( |
| + const blink::WebURL& url, |
| + const blink::WebURL& first_party_for_cookies) { |
| + return cookies(url, first_party_for_cookies); |
| +} |
| + |
| +} // namespace mojo |