| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/plugin_dispatcher.h" | 8 #include "ppapi/proxy/plugin_dispatcher.h" |
| 9 #include "ppapi/proxy/plugin_resource.h" | 9 #include "ppapi/proxy/plugin_resource.h" |
| 10 #include "ppapi/proxy/ppapi_messages.h" | 10 #include "ppapi/proxy/ppapi_messages.h" |
| 11 #include "ppapi/proxy/serialized_var.h" | 11 #include "ppapi/proxy/serialized_var.h" |
| 12 | 12 |
| 13 namespace pp { | 13 namespace pp { |
| 14 namespace proxy { | 14 namespace proxy { |
| 15 | 15 |
| 16 class URLResponseInfo : public PluginResource { | 16 class URLResponseInfo : public PluginResource { |
| 17 public: | 17 public: |
| 18 URLResponseInfo(PP_Instance instance) : PluginResource(instance) {} | 18 URLResponseInfo(PP_Instance instance, SerializedResource resource) |
| 19 : PluginResource(instance, resource) { |
| 20 } |
| 19 virtual ~URLResponseInfo() {} | 21 virtual ~URLResponseInfo() {} |
| 20 | 22 |
| 21 // Resource overrides. | 23 // Resource overrides. |
| 22 virtual URLResponseInfo* AsURLResponseInfo() { return this; } | 24 virtual URLResponseInfo* AsURLResponseInfo() { return this; } |
| 23 | 25 |
| 24 private: | 26 private: |
| 25 DISALLOW_COPY_AND_ASSIGN(URLResponseInfo); | 27 DISALLOW_COPY_AND_ASSIGN(URLResponseInfo); |
| 26 }; | 28 }; |
| 27 | 29 |
| 28 namespace { | 30 namespace { |
| 29 | 31 |
| 30 PP_Bool IsURLResponseInfo(PP_Resource resource) { | 32 PP_Bool IsURLResponseInfo(PP_Resource resource) { |
| 31 URLResponseInfo* object = PluginResource::GetAs<URLResponseInfo>(resource); | 33 URLResponseInfo* object = PluginResource::GetAs<URLResponseInfo>(resource); |
| 32 return BoolToPPBool(!!object); | 34 return BoolToPPBool(!!object); |
| 33 } | 35 } |
| 34 | 36 |
| 35 PP_Var GetProperty(PP_Resource response, PP_URLResponseProperty property) { | 37 PP_Var GetProperty(PP_Resource response, PP_URLResponseProperty property) { |
| 36 URLResponseInfo* object = PluginResource::GetAs<URLResponseInfo>(response); | 38 URLResponseInfo* object = PluginResource::GetAs<URLResponseInfo>(response); |
| 37 if (!object) | 39 if (!object) |
| 38 return PP_MakeUndefined(); | 40 return PP_MakeUndefined(); |
| 39 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance( | 41 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance( |
| 40 object->instance()); | 42 object->instance()); |
| 41 if (!dispatcher) | 43 if (!dispatcher) |
| 42 return PP_MakeUndefined(); | 44 return PP_MakeUndefined(); |
| 43 | 45 |
| 44 ReceiveSerializedVarReturnValue result; | 46 ReceiveSerializedVarReturnValue result; |
| 45 dispatcher->Send(new PpapiHostMsg_PPBURLResponseInfo_GetProperty( | 47 dispatcher->Send(new PpapiHostMsg_PPBURLResponseInfo_GetProperty( |
| 46 INTERFACE_ID_PPB_URL_RESPONSE_INFO, response, property, &result)); | 48 INTERFACE_ID_PPB_URL_RESPONSE_INFO, object->host_resource(), property, |
| 49 &result)); |
| 47 return result.Return(dispatcher); | 50 return result.Return(dispatcher); |
| 48 } | 51 } |
| 49 | 52 |
| 50 PP_Resource GetBodyAsFileRef(PP_Resource response) { | 53 PP_Resource GetBodyAsFileRef(PP_Resource response) { |
| 51 PP_Resource result = 0; | |
| 52 /* | 54 /* |
| 53 dispatcher->Send(new PpapiHostMsg_PPBURLResponseInfo_GetBodyAsFileRef( | 55 dispatcher->Send(new PpapiHostMsg_PPBURLResponseInfo_GetBodyAsFileRef( |
| 54 INTERFACE_ID_PPB_URL_RESPONSE_INFO, response, &result)); | 56 INTERFACE_ID_PPB_URL_RESPONSE_INFO, response, &result)); |
| 55 // TODO(brettw) when we have FileRef proxied, make an object from that | 57 // TODO(brettw) when we have FileRef proxied, make an object from that |
| 56 // ref so we can track it properly and then uncomment this. | 58 // ref so we can track it properly and then uncomment this. |
| 57 */ | 59 */ |
| 58 return result; | 60 return 0; |
| 59 } | 61 } |
| 60 | 62 |
| 61 const PPB_URLResponseInfo ppb_urlresponseinfo = { | 63 const PPB_URLResponseInfo ppb_urlresponseinfo = { |
| 62 &IsURLResponseInfo, | 64 &IsURLResponseInfo, |
| 63 &GetProperty, | 65 &GetProperty, |
| 64 &GetBodyAsFileRef | 66 &GetBodyAsFileRef |
| 65 }; | 67 }; |
| 66 | 68 |
| 67 } // namespace | 69 } // namespace |
| 68 | 70 |
| 69 PPB_URLResponseInfo_Proxy::PPB_URLResponseInfo_Proxy( | 71 PPB_URLResponseInfo_Proxy::PPB_URLResponseInfo_Proxy( |
| 70 Dispatcher* dispatcher, | 72 Dispatcher* dispatcher, |
| 71 const void* target_interface) | 73 const void* target_interface) |
| 72 : InterfaceProxy(dispatcher, target_interface) { | 74 : InterfaceProxy(dispatcher, target_interface) { |
| 73 } | 75 } |
| 74 | 76 |
| 75 PPB_URLResponseInfo_Proxy::~PPB_URLResponseInfo_Proxy() { | 77 PPB_URLResponseInfo_Proxy::~PPB_URLResponseInfo_Proxy() { |
| 76 } | 78 } |
| 77 | 79 |
| 78 // static | 80 // static |
| 79 void PPB_URLResponseInfo_Proxy::TrackPluginResource( | 81 PP_Resource PPB_URLResponseInfo_Proxy::CreateResponseForResource( |
| 80 PP_Instance instance, | 82 PP_Instance instance, |
| 81 PP_Resource response_resource) { | 83 SerializedResource resource) { |
| 82 linked_ptr<URLResponseInfo> object(new URLResponseInfo(instance)); | 84 linked_ptr<URLResponseInfo> object(new URLResponseInfo(instance, resource)); |
| 83 PluginResourceTracker::GetInstance()->AddResource( | 85 return PluginResourceTracker::GetInstance()->AddResource(object); |
| 84 response_resource, object); | |
| 85 } | 86 } |
| 86 | 87 |
| 87 const void* PPB_URLResponseInfo_Proxy::GetSourceInterface() const { | 88 const void* PPB_URLResponseInfo_Proxy::GetSourceInterface() const { |
| 88 return &ppb_urlresponseinfo; | 89 return &ppb_urlresponseinfo; |
| 89 } | 90 } |
| 90 | 91 |
| 91 InterfaceID PPB_URLResponseInfo_Proxy::GetInterfaceId() const { | 92 InterfaceID PPB_URLResponseInfo_Proxy::GetInterfaceId() const { |
| 92 return INTERFACE_ID_PPB_URL_RESPONSE_INFO; | 93 return INTERFACE_ID_PPB_URL_RESPONSE_INFO; |
| 93 } | 94 } |
| 94 | 95 |
| 95 bool PPB_URLResponseInfo_Proxy::OnMessageReceived(const IPC::Message& msg) { | 96 bool PPB_URLResponseInfo_Proxy::OnMessageReceived(const IPC::Message& msg) { |
| 96 bool handled = true; | 97 bool handled = true; |
| 97 IPC_BEGIN_MESSAGE_MAP(PPB_URLResponseInfo_Proxy, msg) | 98 IPC_BEGIN_MESSAGE_MAP(PPB_URLResponseInfo_Proxy, msg) |
| 98 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLResponseInfo_GetProperty, | 99 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLResponseInfo_GetProperty, |
| 99 OnMsgGetProperty) | 100 OnMsgGetProperty) |
| 100 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLResponseInfo_GetBodyAsFileRef, | 101 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLResponseInfo_GetBodyAsFileRef, |
| 101 OnMsgGetBodyAsFileRef) | 102 OnMsgGetBodyAsFileRef) |
| 102 IPC_MESSAGE_UNHANDLED(handled = false) | 103 IPC_MESSAGE_UNHANDLED(handled = false) |
| 103 IPC_END_MESSAGE_MAP() | 104 IPC_END_MESSAGE_MAP() |
| 104 // TODO(brettw): handle bad messages. | 105 // TODO(brettw): handle bad messages. |
| 105 return handled; | 106 return handled; |
| 106 } | 107 } |
| 107 | 108 |
| 108 void PPB_URLResponseInfo_Proxy::OnMsgGetProperty( | 109 void PPB_URLResponseInfo_Proxy::OnMsgGetProperty( |
| 109 PP_Resource response, | 110 SerializedResource response, |
| 110 int32_t property, | 111 int32_t property, |
| 111 SerializedVarReturnValue result) { | 112 SerializedVarReturnValue result) { |
| 112 result.Return(dispatcher(), ppb_url_response_info_target()->GetProperty( | 113 result.Return(dispatcher(), ppb_url_response_info_target()->GetProperty( |
| 113 response, static_cast<PP_URLResponseProperty>(property))); | 114 response.host_resource(), static_cast<PP_URLResponseProperty>(property))); |
| 114 } | 115 } |
| 115 | 116 |
| 116 void PPB_URLResponseInfo_Proxy::OnMsgGetBodyAsFileRef( | 117 void PPB_URLResponseInfo_Proxy::OnMsgGetBodyAsFileRef( |
| 117 PP_Resource response, | 118 SerializedResource response, |
| 118 PP_Resource* file_ref_result) { | 119 SerializedResource* file_ref_result) { |
| 119 *file_ref_result = ppb_url_response_info_target()->GetBodyAsFileRef(response); | 120 file_ref_result->set_host_resource( |
| 121 ppb_url_response_info_target()->GetBodyAsFileRef( |
| 122 response.host_resource())); |
| 120 } | 123 } |
| 121 | 124 |
| 122 } // namespace proxy | 125 } // namespace proxy |
| 123 } // namespace pp | 126 } // namespace pp |
| OLD | NEW |