summaryrefslogtreecommitdiffstats
path: root/ppapi/proxy/ppb_url_response_info_proxy.cc
blob: 2fbd4526fb7c28b8d4929ef7661eed34b1d6867d (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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// 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 "ppapi/proxy/ppb_url_response_info_proxy.h"

#include "ppapi/c/dev/ppb_url_response_info_dev.h"
#include "ppapi/proxy/plugin_dispatcher.h"
#include "ppapi/proxy/plugin_resource.h"
#include "ppapi/proxy/ppapi_messages.h"
#include "ppapi/proxy/serialized_var.h"

namespace pp {
namespace proxy {

class URLResponseInfo : public PluginResource {
 public:
  URLResponseInfo() {}
  virtual ~URLResponseInfo() {}

  // Resource overrides.
  virtual URLResponseInfo* AsURLResponseInfo() { return this; }

 private:
  DISALLOW_COPY_AND_ASSIGN(URLResponseInfo);
};

namespace {

PP_Bool IsURLResponseInfo(PP_Resource resource) {
  URLResponseInfo* object = PluginResource::GetAs<URLResponseInfo>(resource);
  return BoolToPPBool(!!object);
}

PP_Var GetProperty(PP_Resource response, PP_URLResponseProperty_Dev property) {
  Dispatcher* dispatcher = PluginDispatcher::Get();
  ReceiveSerializedVarReturnValue result;
  dispatcher->Send(new PpapiHostMsg_PPBURLResponseInfo_GetProperty(
      INTERFACE_ID_PPB_URL_RESPONSE_INFO, response, property, &result));
  return result.Return(dispatcher);
}

PP_Resource GetBody(PP_Resource response) {
  PP_Resource result = 0;
  /*
  Dispatcher* dispatcher = PluginDispatcher::Get();
  dispatcher->Send(new PpapiHostMsg_PPBURLResponseInfo_GetBody(
      INTERFACE_ID_PPB_URL_RESPONSE_INFO, response, &result));
  // TODO(brettw) when we have FileRef proxied, make an object from that
  // ref so we can track it properly and then uncomment this.
  */
  return result;
}

const PPB_URLResponseInfo_Dev ppb_urlresponseinfo = {
  &IsURLResponseInfo,
  &GetProperty,
  &GetBody
};

}  // namespace

PPB_URLResponseInfo_Proxy::PPB_URLResponseInfo_Proxy(
    Dispatcher* dispatcher,
    const void* target_interface)
    : InterfaceProxy(dispatcher, target_interface) {
}

PPB_URLResponseInfo_Proxy::~PPB_URLResponseInfo_Proxy() {
}

// static
void PPB_URLResponseInfo_Proxy::TrackPluginResource(
    PP_Resource response_resource) {
  linked_ptr<URLResponseInfo> object(new URLResponseInfo);
  PluginDispatcher::Get()->plugin_resource_tracker()->AddResource(
      response_resource, object);
}

const void* PPB_URLResponseInfo_Proxy::GetSourceInterface() const {
  return &ppb_urlresponseinfo;
}

InterfaceID PPB_URLResponseInfo_Proxy::GetInterfaceId() const {
  return INTERFACE_ID_PPB_URL_RESPONSE_INFO;
}

void PPB_URLResponseInfo_Proxy::OnMessageReceived(const IPC::Message& msg) {
  IPC_BEGIN_MESSAGE_MAP(PPB_URLResponseInfo_Proxy, msg)
    IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLResponseInfo_GetProperty,
                        OnMsgGetProperty)
    IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLResponseInfo_GetBody,
                        OnMsgGetBody)
  IPC_END_MESSAGE_MAP()
  // TODO(brettw): handle bad messages.
}

void PPB_URLResponseInfo_Proxy::OnMsgGetProperty(
    PP_Resource response,
    int32_t property,
    SerializedVarReturnValue result) {
  result.Return(dispatcher(), ppb_url_response_info_target()->GetProperty(
      response, static_cast<PP_URLResponseProperty_Dev>(property)));
}

void PPB_URLResponseInfo_Proxy::OnMsgGetBody(PP_Resource response,
                                             PP_Resource* file_ref_result) {
  *file_ref_result = ppb_url_response_info_target()->GetBody(response);
}

}  // namespace proxy
}  // namespace pp