OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ppapi/proxy/ppb_url_response_info_proxy.h" | 5 #include "ppapi/proxy/ppb_url_response_info_proxy.h" |
6 | 6 |
7 #include "ppapi/c/ppb_url_response_info.h" | 7 #include "ppapi/c/ppb_url_response_info.h" |
8 #include "ppapi/proxy/enter_proxy.h" | 8 #include "ppapi/proxy/enter_proxy.h" |
9 #include "ppapi/proxy/host_dispatcher.h" | 9 #include "ppapi/proxy/host_dispatcher.h" |
10 #include "ppapi/proxy/plugin_dispatcher.h" | 10 #include "ppapi/proxy/plugin_dispatcher.h" |
11 #include "ppapi/proxy/plugin_resource.h" | |
12 #include "ppapi/proxy/ppapi_messages.h" | 11 #include "ppapi/proxy/ppapi_messages.h" |
13 #include "ppapi/proxy/ppb_file_ref_proxy.h" | 12 #include "ppapi/proxy/ppb_file_ref_proxy.h" |
14 #include "ppapi/proxy/serialized_var.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" | 15 #include "ppapi/thunk/ppb_url_response_info_api.h" |
16 #include "ppapi/thunk/thunk.h" | 16 #include "ppapi/thunk/thunk.h" |
17 | 17 |
18 using ppapi::HostResource; | 18 using ppapi::HostResource; |
| 19 using ppapi::Resource; |
19 using ppapi::thunk::PPB_URLResponseInfo_API; | 20 using ppapi::thunk::PPB_URLResponseInfo_API; |
20 | 21 |
21 namespace pp { | 22 namespace pp { |
22 namespace proxy { | 23 namespace proxy { |
23 | 24 |
24 namespace { | 25 namespace { |
25 | 26 |
26 InterfaceProxy* CreateURLResponseInfoProxy(Dispatcher* dispatcher, | 27 InterfaceProxy* CreateURLResponseInfoProxy(Dispatcher* dispatcher, |
27 const void* target_interface) { | 28 const void* target_interface) { |
28 return new PPB_URLResponseInfo_Proxy(dispatcher, target_interface); | 29 return new PPB_URLResponseInfo_Proxy(dispatcher, target_interface); |
29 } | 30 } |
30 | 31 |
31 } // namespace | 32 } // namespace |
32 | 33 |
33 // URLResponseInfo ------------------------------------------------------------- | 34 // URLResponseInfo ------------------------------------------------------------- |
34 | 35 |
35 class URLResponseInfo : public PluginResource, | 36 class URLResponseInfo : public Resource, public PPB_URLResponseInfo_API { |
36 public PPB_URLResponseInfo_API { | |
37 public: | 37 public: |
38 URLResponseInfo(const HostResource& resource); | 38 URLResponseInfo(const HostResource& resource); |
39 virtual ~URLResponseInfo(); | 39 virtual ~URLResponseInfo(); |
40 | 40 |
41 // ResourceObjectBase override. | 41 // Resource override. |
42 virtual PPB_URLResponseInfo_API* AsPPB_URLResponseInfo_API() OVERRIDE; | 42 virtual PPB_URLResponseInfo_API* AsPPB_URLResponseInfo_API() OVERRIDE; |
43 | 43 |
44 // PPB_URLResponseInfo_API implementation. | 44 // PPB_URLResponseInfo_API implementation. |
45 virtual PP_Var GetProperty(PP_URLResponseProperty property) OVERRIDE; | 45 virtual PP_Var GetProperty(PP_URLResponseProperty property) OVERRIDE; |
46 virtual PP_Resource GetBodyAsFileRef() OVERRIDE; | 46 virtual PP_Resource GetBodyAsFileRef() OVERRIDE; |
47 | 47 |
48 private: | 48 private: |
49 DISALLOW_COPY_AND_ASSIGN(URLResponseInfo); | 49 DISALLOW_COPY_AND_ASSIGN(URLResponseInfo); |
50 }; | 50 }; |
51 | 51 |
52 URLResponseInfo::URLResponseInfo(const HostResource& resource) | 52 URLResponseInfo::URLResponseInfo(const HostResource& resource) |
53 : PluginResource(resource) { | 53 : Resource(resource) { |
54 } | 54 } |
55 | 55 |
56 URLResponseInfo::~URLResponseInfo() { | 56 URLResponseInfo::~URLResponseInfo() { |
57 } | 57 } |
58 | 58 |
59 PPB_URLResponseInfo_API* URLResponseInfo::AsPPB_URLResponseInfo_API() { | 59 PPB_URLResponseInfo_API* URLResponseInfo::AsPPB_URLResponseInfo_API() { |
60 return this; | 60 return this; |
61 } | 61 } |
62 | 62 |
63 PP_Var URLResponseInfo::GetProperty(PP_URLResponseProperty property) { | 63 PP_Var URLResponseInfo::GetProperty(PP_URLResponseProperty property) { |
| 64 PluginDispatcher* dispatcher = PluginDispatcher::GetForResource(this); |
64 ReceiveSerializedVarReturnValue result; | 65 ReceiveSerializedVarReturnValue result; |
65 GetDispatcher()->Send(new PpapiHostMsg_PPBURLResponseInfo_GetProperty( | 66 dispatcher->Send(new PpapiHostMsg_PPBURLResponseInfo_GetProperty( |
66 INTERFACE_ID_PPB_URL_RESPONSE_INFO, host_resource(), property, &result)); | 67 INTERFACE_ID_PPB_URL_RESPONSE_INFO, host_resource(), property, &result)); |
67 return result.Return(GetDispatcher()); | 68 return result.Return(dispatcher); |
68 } | 69 } |
69 | 70 |
70 PP_Resource URLResponseInfo::GetBodyAsFileRef() { | 71 PP_Resource URLResponseInfo::GetBodyAsFileRef() { |
71 // This could be more efficient by having the host automatically send us the | 72 // This could be more efficient by having the host automatically send us the |
72 // file ref when the request is streaming to a file and it's in the state | 73 // file ref when the request is streaming to a file and it's in the state |
73 // where the file is ready. This will prevent us from having to do this sync | 74 // where the file is ready. This will prevent us from having to do this sync |
74 // IPC here. | 75 // IPC here. |
75 PPBFileRef_CreateInfo create_info; | 76 PPBFileRef_CreateInfo create_info; |
76 GetDispatcher()->Send(new PpapiHostMsg_PPBURLResponseInfo_GetBodyAsFileRef( | 77 PluginDispatcher::GetForResource(this)->Send( |
77 INTERFACE_ID_PPB_URL_RESPONSE_INFO, host_resource(), &create_info)); | 78 new PpapiHostMsg_PPBURLResponseInfo_GetBodyAsFileRef( |
| 79 INTERFACE_ID_PPB_URL_RESPONSE_INFO, host_resource(), &create_info)); |
78 return PPB_FileRef_Proxy::DeserializeFileRef(create_info); | 80 return PPB_FileRef_Proxy::DeserializeFileRef(create_info); |
79 } | 81 } |
80 | 82 |
81 // PPB_URLResponseInfo_Proxy --------------------------------------------------- | 83 // PPB_URLResponseInfo_Proxy --------------------------------------------------- |
82 | 84 |
83 PPB_URLResponseInfo_Proxy::PPB_URLResponseInfo_Proxy( | 85 PPB_URLResponseInfo_Proxy::PPB_URLResponseInfo_Proxy( |
84 Dispatcher* dispatcher, | 86 Dispatcher* dispatcher, |
85 const void* target_interface) | 87 const void* target_interface) |
86 : InterfaceProxy(dispatcher, target_interface) { | 88 : InterfaceProxy(dispatcher, target_interface) { |
87 } | 89 } |
88 | 90 |
89 PPB_URLResponseInfo_Proxy::~PPB_URLResponseInfo_Proxy() { | 91 PPB_URLResponseInfo_Proxy::~PPB_URLResponseInfo_Proxy() { |
90 } | 92 } |
91 | 93 |
92 // static | 94 // static |
93 const InterfaceProxy::Info* PPB_URLResponseInfo_Proxy::GetInfo() { | 95 const InterfaceProxy::Info* PPB_URLResponseInfo_Proxy::GetInfo() { |
94 static const Info info = { | 96 static const Info info = { |
95 ppapi::thunk::GetPPB_URLResponseInfo_Thunk(), | 97 ppapi::thunk::GetPPB_URLResponseInfo_Thunk(), |
96 PPB_URLRESPONSEINFO_INTERFACE, | 98 PPB_URLRESPONSEINFO_INTERFACE, |
97 INTERFACE_ID_PPB_URL_RESPONSE_INFO, | 99 INTERFACE_ID_PPB_URL_RESPONSE_INFO, |
98 false, | 100 false, |
99 &CreateURLResponseInfoProxy, | 101 &CreateURLResponseInfoProxy, |
100 }; | 102 }; |
101 return &info; | 103 return &info; |
102 } | 104 } |
103 | 105 |
104 // static | 106 // static |
105 PP_Resource PPB_URLResponseInfo_Proxy::CreateResponseForResource( | 107 PP_Resource PPB_URLResponseInfo_Proxy::CreateResponseForResource( |
106 const HostResource& resource) { | 108 const HostResource& resource) { |
107 return PluginResourceTracker::GetInstance()->AddResource( | 109 return (new URLResponseInfo(resource))->GetReference(); |
108 new URLResponseInfo(resource)); | |
109 } | 110 } |
110 | 111 |
111 bool PPB_URLResponseInfo_Proxy::OnMessageReceived(const IPC::Message& msg) { | 112 bool PPB_URLResponseInfo_Proxy::OnMessageReceived(const IPC::Message& msg) { |
112 bool handled = true; | 113 bool handled = true; |
113 IPC_BEGIN_MESSAGE_MAP(PPB_URLResponseInfo_Proxy, msg) | 114 IPC_BEGIN_MESSAGE_MAP(PPB_URLResponseInfo_Proxy, msg) |
114 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLResponseInfo_GetProperty, | 115 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLResponseInfo_GetProperty, |
115 OnMsgGetProperty) | 116 OnMsgGetProperty) |
116 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLResponseInfo_GetBodyAsFileRef, | 117 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLResponseInfo_GetBodyAsFileRef, |
117 OnMsgGetBodyAsFileRef) | 118 OnMsgGetBodyAsFileRef) |
118 IPC_MESSAGE_UNHANDLED(handled = false) | 119 IPC_MESSAGE_UNHANDLED(handled = false) |
(...skipping 26 matching lines...) Expand all Loading... |
145 // Use the FileRef proxy to serialize. | 146 // Use the FileRef proxy to serialize. |
146 DCHECK(!dispatcher()->IsPlugin()); | 147 DCHECK(!dispatcher()->IsPlugin()); |
147 HostDispatcher* host_disp = static_cast<HostDispatcher*>(dispatcher()); | 148 HostDispatcher* host_disp = static_cast<HostDispatcher*>(dispatcher()); |
148 PPB_FileRef_Proxy* file_ref_proxy = static_cast<PPB_FileRef_Proxy*>( | 149 PPB_FileRef_Proxy* file_ref_proxy = static_cast<PPB_FileRef_Proxy*>( |
149 host_disp->GetOrCreatePPBInterfaceProxy(INTERFACE_ID_PPB_FILE_REF)); | 150 host_disp->GetOrCreatePPBInterfaceProxy(INTERFACE_ID_PPB_FILE_REF)); |
150 file_ref_proxy->SerializeFileRef(file_ref, result); | 151 file_ref_proxy->SerializeFileRef(file_ref, result); |
151 } | 152 } |
152 | 153 |
153 } // namespace proxy | 154 } // namespace proxy |
154 } // namespace pp | 155 } // namespace pp |
OLD | NEW |