summaryrefslogtreecommitdiff
path: root/chromium/content/renderer/renderer_webcookiejar_impl.cc
blob: 7478ca2ef773d766ec27b9d1e49efa7f249eebd5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright (c) 2010 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 "content/renderer/renderer_webcookiejar_impl.h"

#include "base/strings/utf_string_conversions.h"
#include "content/common/frame_messages.h"
#include "content/public/renderer/content_renderer_client.h"
#include "content/renderer/render_frame_impl.h"
#include "content/renderer/render_thread_impl.h"

using blink::WebString;
using blink::WebURL;

namespace content {

void RendererWebCookieJarImpl::SetCookie(const WebURL& url,
                                         const WebURL& first_party_for_cookies,
                                         const WebString& value) {
  std::string value_utf8 =
      value.Utf8(WebString::UTF8ConversionMode::kStrictReplacingErrorsWithFFFD);
  RenderThreadImpl::current()->render_frame_message_filter()->SetCookie(
      sender_->GetRoutingID(), url, first_party_for_cookies, value_utf8);
}

WebString RendererWebCookieJarImpl::Cookies(
    const WebURL& url,
    const WebURL& first_party_for_cookies) {
  std::string value_utf8;
  RenderThreadImpl::current()->render_frame_message_filter()->GetCookies(
      sender_->GetRoutingID(), url, first_party_for_cookies, &value_utf8);
  return WebString::FromUTF8(value_utf8);
}

bool RendererWebCookieJarImpl::CookiesEnabled(
    const WebURL& url,
    const WebURL& first_party_for_cookies) {
  bool cookies_enabled = false;
  sender_->Send(new FrameHostMsg_CookiesEnabled(
      sender_->GetRoutingID(), url, first_party_for_cookies, &cookies_enabled));
  return cookies_enabled;
}

}  // namespace content