Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(170)

Side by Side Diff: ppapi/proxy/ppb_url_response_info_proxy.cc

Issue 10993031: Refactor the URLResponseInfo to use new design (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: revert shim Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLResponseInfo_GetProperty,
91 OnMsgGetProperty)
92 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLResponseInfo_GetBodyAsFileRef,
93 OnMsgGetBodyAsFileRef)
94 IPC_MESSAGE_UNHANDLED(handled = false)
95 IPC_END_MESSAGE_MAP()
96 // TODO(brettw): handle bad messages.
97 return handled;
98 }
99
100 void PPB_URLResponseInfo_Proxy::OnMsgGetProperty(
101 const HostResource& response,
102 int32_t property,
103 SerializedVarReturnValue result) {
104 EnterHostFromHostResource<PPB_URLResponseInfo_API> enter(response);
105 PP_Var result_var = PP_MakeUndefined();
106 if (enter.succeeded()) {
107 result_var = enter.object()->GetProperty(
108 static_cast<PP_URLResponseProperty>(property));
109 }
110 result.Return(dispatcher(), result_var);
111 }
112
113 void PPB_URLResponseInfo_Proxy::OnMsgGetBodyAsFileRef(
114 const HostResource& response,
115 PPB_FileRef_CreateInfo* result) {
116 EnterHostFromHostResource<PPB_URLResponseInfo_API> enter(response);
117 PP_Resource file_ref = 0;
118 if (enter.succeeded())
119 file_ref = enter.object()->GetBodyAsFileRef();
120
121 // Use the FileRef proxy to serialize.
122 PPB_FileRef_Proxy* file_ref_proxy = static_cast<PPB_FileRef_Proxy*>(
123 dispatcher()->GetInterfaceProxy(API_ID_PPB_FILE_REF));
124 file_ref_proxy->SerializeFileRef(file_ref, result);
125 }
126
127 } // namespace proxy
128 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698