OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 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 "ppapi/proxy/ppb_url_response_info_proxy.h" | |
6 | |
7 #include "ppapi/c/ppb_url_response_info.h" | |
8 #include "ppapi/proxy/enter_proxy.h" | |
9 #include "ppapi/proxy/host_dispatcher.h" | |
10 #include "ppapi/proxy/plugin_dispatcher.h" | |
11 #include "ppapi/proxy/ppapi_messages.h" | |
12 #include "ppapi/proxy/ppb_file_ref_proxy.h" | |
13 #include "ppapi/proxy/serialized_var.h" | |
14 #include "ppapi/shared_impl/resource.h" | |
15 #include "ppapi/thunk/ppb_url_response_info_api.h" | |
16 #include "ppapi/thunk/thunk.h" | |
17 | |
18 using ppapi::thunk::PPB_URLResponseInfo_API; | |
19 | |
20 namespace ppapi { | |
21 namespace proxy { | |
22 | |
23 // URLResponseInfo ------------------------------------------------------------- | |
24 | |
25 class URLResponseInfo : public Resource, public PPB_URLResponseInfo_API { | |
26 public: | |
27 URLResponseInfo(const HostResource& resource); | |
28 virtual ~URLResponseInfo(); | |
29 | |
30 // Resource override. | |
31 virtual PPB_URLResponseInfo_API* AsPPB_URLResponseInfo_API() OVERRIDE; | |
32 | |
33 // PPB_URLResponseInfo_API implementation. | |
34 virtual PP_Var GetProperty(PP_URLResponseProperty property) OVERRIDE; | |
35 virtual PP_Resource GetBodyAsFileRef() OVERRIDE; | |
36 | |
37 private: | |
38 DISALLOW_COPY_AND_ASSIGN(URLResponseInfo); | |
39 }; | |
40 | |
41 URLResponseInfo::URLResponseInfo(const HostResource& resource) | |
42 : Resource(OBJECT_IS_PROXY, resource) { | |
43 } | |
44 | |
45 URLResponseInfo::~URLResponseInfo() { | |
46 } | |
47 | |
48 PPB_URLResponseInfo_API* URLResponseInfo::AsPPB_URLResponseInfo_API() { | |
49 return this; | |
50 } | |
51 | |
52 PP_Var URLResponseInfo::GetProperty(PP_URLResponseProperty property) { | |
53 PluginDispatcher* dispatcher = PluginDispatcher::GetForResource(this); | |
54 ReceiveSerializedVarReturnValue result; | |
55 dispatcher->Send(new PpapiHostMsg_PPBURLResponseInfo_GetProperty( | |
56 API_ID_PPB_URL_RESPONSE_INFO, host_resource(), property, &result)); | |
57 return result.Return(dispatcher); | |
58 } | |
59 | |
60 PP_Resource URLResponseInfo::GetBodyAsFileRef() { | |
61 // This could be more efficient by having the host automatically send us the | |
62 // file ref when the request is streaming to a file and it's in the state | |
63 // where the file is ready. This will prevent us from having to do this sync | |
64 // IPC here. | |
65 PPB_FileRef_CreateInfo create_info; | |
66 PluginDispatcher::GetForResource(this)->Send( | |
67 new PpapiHostMsg_PPBURLResponseInfo_GetBodyAsFileRef( | |
68 API_ID_PPB_URL_RESPONSE_INFO, host_resource(), &create_info)); | |
69 return PPB_FileRef_Proxy::DeserializeFileRef(create_info); | |
70 } | |
71 | |
72 // PPB_URLResponseInfo_Proxy --------------------------------------------------- | |
73 | |
74 PPB_URLResponseInfo_Proxy::PPB_URLResponseInfo_Proxy(Dispatcher* dispatcher) | |
75 : InterfaceProxy(dispatcher) { | |
76 } | |
77 | |
78 PPB_URLResponseInfo_Proxy::~PPB_URLResponseInfo_Proxy() { | |
79 } | |
80 | |
81 // static | |
82 PP_Resource PPB_URLResponseInfo_Proxy::CreateResponseForResource( | |
83 const HostResource& resource) { | |
84 return (new URLResponseInfo(resource))->GetReference(); | |
85 } | |
86 | |
87 bool PPB_URLResponseInfo_Proxy::OnMessageReceived(const IPC::Message& msg) { | |
88 bool handled = true; | |
89 IPC_BEGIN_MESSAGE_MAP(PPB_URLResponseInfo_Proxy, msg) | |
90 #if !defined(OS_NACL) | |
91 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLResponseInfo_GetProperty, | |
92 OnMsgGetProperty) | |
93 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLResponseInfo_GetBodyAsFileRef, | |
94 OnMsgGetBodyAsFileRef) | |
95 #endif | |
96 IPC_MESSAGE_UNHANDLED(handled = false) | |
97 IPC_END_MESSAGE_MAP() | |
98 // TODO(brettw): handle bad messages. | |
99 return handled; | |
100 } | |
101 | |
102 #if !defined(OS_NACL) | |
103 void PPB_URLResponseInfo_Proxy::OnMsgGetProperty( | |
104 const HostResource& response, | |
105 int32_t property, | |
106 SerializedVarReturnValue result) { | |
107 EnterHostFromHostResource<PPB_URLResponseInfo_API> enter(response); | |
108 PP_Var result_var = PP_MakeUndefined(); | |
109 if (enter.succeeded()) { | |
110 result_var = enter.object()->GetProperty( | |
111 static_cast<PP_URLResponseProperty>(property)); | |
112 } | |
113 result.Return(dispatcher(), result_var); | |
114 } | |
115 | |
116 void PPB_URLResponseInfo_Proxy::OnMsgGetBodyAsFileRef( | |
117 const HostResource& response, | |
118 PPB_FileRef_CreateInfo* result) { | |
119 EnterHostFromHostResource<PPB_URLResponseInfo_API> enter(response); | |
120 PP_Resource file_ref = 0; | |
121 if (enter.succeeded()) | |
122 file_ref = enter.object()->GetBodyAsFileRef(); | |
123 | |
124 // Use the FileRef proxy to serialize. | |
125 PPB_FileRef_Proxy* file_ref_proxy = static_cast<PPB_FileRef_Proxy*>( | |
126 dispatcher()->GetInterfaceProxy(API_ID_PPB_FILE_REF)); | |
127 file_ref_proxy->SerializeFileRef(file_ref, result); | |
128 } | |
129 #endif // !defined(OS_NACL) | |
130 | |
131 } // namespace proxy | |
132 } // namespace ppapi | |
OLD | NEW |