| 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 "mojo/services/html_viewer/web_cookie_jar_impl.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "third_party/WebKit/public/platform/WebURL.h" | |
| 9 | |
| 10 using mojo::String; | |
| 11 | |
| 12 namespace html_viewer { | |
| 13 namespace { | |
| 14 | |
| 15 void CopyBool(bool* output, bool input) { | |
| 16 *output = input; | |
| 17 } | |
| 18 | |
| 19 void CopyString(String* output, const String& input) { | |
| 20 *output = input; | |
| 21 } | |
| 22 | |
| 23 } // namespace | |
| 24 | |
| 25 WebCookieJarImpl::WebCookieJarImpl(mojo::CookieStorePtr store) | |
| 26 : store_(store.Pass()) { | |
| 27 } | |
| 28 | |
| 29 WebCookieJarImpl::~WebCookieJarImpl() { | |
| 30 } | |
| 31 | |
| 32 void WebCookieJarImpl::setCookie(const blink::WebURL& url, | |
| 33 const blink::WebURL& first_party_for_cookies, | |
| 34 const blink::WebString& cookie) { | |
| 35 bool success; | |
| 36 store_->Set(url.string().utf8(), cookie.utf8(), | |
| 37 base::Bind(&CopyBool, &success)); | |
| 38 | |
| 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. | |
| 41 // | |
| 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. | |
| 45 // | |
| 46 store_.WaitForIncomingMethodCall(); | |
| 47 } | |
| 48 | |
| 49 blink::WebString WebCookieJarImpl::cookies( | |
| 50 const blink::WebURL& url, | |
| 51 const blink::WebURL& first_party_for_cookies) { | |
| 52 String result; | |
| 53 store_->Get(url.string().utf8(), base::Bind(&CopyString, &result)); | |
| 54 | |
| 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(); | |
| 59 if (!result) | |
| 60 return blink::WebString(); | |
| 61 | |
| 62 return blink::WebString::fromUTF8(result); | |
| 63 } | |
| 64 | |
| 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); | |
| 69 } | |
| 70 | |
| 71 } // namespace html_viewer | |
| OLD | NEW |