| OLD | NEW |
| 1 // Copyright (c) 2010 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_request_info_proxy.h" | 5 #include "ppapi/proxy/ppb_url_request_info_proxy.h" |
| 6 | 6 |
| 7 #include "ppapi/c/ppb_url_request_info.h" | 7 #include "ppapi/c/ppb_url_request_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 | 11 |
| 12 namespace pp { | 12 namespace pp { |
| 13 namespace proxy { | 13 namespace proxy { |
| 14 | 14 |
| 15 class URLRequestInfo : public PluginResource { | 15 class URLRequestInfo : public PluginResource { |
| 16 public: | 16 public: |
| 17 URLRequestInfo() {} | 17 URLRequestInfo(PP_Instance instance) : PluginResource(instance) {} |
| 18 virtual ~URLRequestInfo() {} | 18 virtual ~URLRequestInfo() {} |
| 19 | 19 |
| 20 // Resource overrides. | 20 // Resource overrides. |
| 21 virtual URLRequestInfo* AsURLRequestInfo() { return this; } | 21 virtual URLRequestInfo* AsURLRequestInfo() { return this; } |
| 22 | 22 |
| 23 private: | 23 private: |
| 24 DISALLOW_COPY_AND_ASSIGN(URLRequestInfo); | 24 DISALLOW_COPY_AND_ASSIGN(URLRequestInfo); |
| 25 }; | 25 }; |
| 26 | 26 |
| 27 namespace { | 27 namespace { |
| 28 | 28 |
| 29 // Returns the dispatcher associated with the given URLRequestInfo, or NULL if |
| 30 // none exists. |
| 31 PluginDispatcher* DispatcherFromURLRequestInfo(PP_Resource resource) { |
| 32 URLRequestInfo* object = PluginResource::GetAs<URLRequestInfo>(resource); |
| 33 if (!object) |
| 34 return NULL; |
| 35 return PluginDispatcher::GetForInstance(object->instance()); |
| 36 } |
| 37 |
| 29 PP_Resource Create(PP_Instance instance) { | 38 PP_Resource Create(PP_Instance instance) { |
| 39 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); |
| 40 if (!dispatcher) |
| 41 return 0; |
| 42 |
| 30 PP_Resource result; | 43 PP_Resource result; |
| 31 PluginDispatcher::Get()->Send(new PpapiHostMsg_PPBURLRequestInfo_Create( | 44 dispatcher->Send(new PpapiHostMsg_PPBURLRequestInfo_Create( |
| 32 INTERFACE_ID_PPB_URL_REQUEST_INFO, instance, &result)); | 45 INTERFACE_ID_PPB_URL_REQUEST_INFO, instance, &result)); |
| 33 if (result) { | 46 if (result) { |
| 34 linked_ptr<URLRequestInfo> object(new URLRequestInfo); | 47 linked_ptr<URLRequestInfo> object(new URLRequestInfo(instance)); |
| 35 PluginDispatcher::Get()->plugin_resource_tracker()->AddResource( | 48 PluginResourceTracker::GetInstance()->AddResource(result, object); |
| 36 result, object); | |
| 37 } | 49 } |
| 38 return result; | 50 return result; |
| 39 } | 51 } |
| 40 | 52 |
| 41 PP_Bool IsURLRequestInfo(PP_Resource resource) { | 53 PP_Bool IsURLRequestInfo(PP_Resource resource) { |
| 42 URLRequestInfo* object = PluginResource::GetAs<URLRequestInfo>(resource); | 54 URLRequestInfo* object = PluginResource::GetAs<URLRequestInfo>(resource); |
| 43 return BoolToPPBool(!!object); | 55 return BoolToPPBool(!!object); |
| 44 } | 56 } |
| 45 | 57 |
| 46 PP_Bool SetProperty(PP_Resource request_id, | 58 PP_Bool SetProperty(PP_Resource request_id, |
| 47 PP_URLRequestProperty property, | 59 PP_URLRequestProperty property, |
| 48 PP_Var var) { | 60 PP_Var var) { |
| 49 Dispatcher* dispatcher = PluginDispatcher::Get(); | 61 PluginDispatcher* dispatcher = DispatcherFromURLRequestInfo(request_id); |
| 62 if (!dispatcher) |
| 63 return PP_FALSE; |
| 64 |
| 50 dispatcher->Send(new PpapiHostMsg_PPBURLRequestInfo_SetProperty( | 65 dispatcher->Send(new PpapiHostMsg_PPBURLRequestInfo_SetProperty( |
| 51 INTERFACE_ID_PPB_URL_REQUEST_INFO, request_id, | 66 INTERFACE_ID_PPB_URL_REQUEST_INFO, request_id, |
| 52 static_cast<int32_t>(property), | 67 static_cast<int32_t>(property), |
| 53 SerializedVarSendInput(dispatcher, var))); | 68 SerializedVarSendInput(dispatcher, var))); |
| 54 | 69 |
| 55 // TODO(brettw) do some validation on the types. We should be able to tell on | 70 // TODO(brettw) do some validation on the types. We should be able to tell on |
| 56 // the plugin side whether the request will succeed or fail in the renderer. | 71 // the plugin side whether the request will succeed or fail in the renderer. |
| 57 return PP_TRUE; | 72 return PP_TRUE; |
| 58 } | 73 } |
| 59 | 74 |
| 60 PP_Bool AppendDataToBody(PP_Resource request_id, | 75 PP_Bool AppendDataToBody(PP_Resource request_id, |
| 61 const char* data, uint32_t len) { | 76 const char* data, uint32_t len) { |
| 62 PluginDispatcher::Get()->Send( | 77 PluginDispatcher* dispatcher = DispatcherFromURLRequestInfo(request_id); |
| 63 new PpapiHostMsg_PPBURLRequestInfo_AppendDataToBody( | 78 if (!dispatcher) |
| 64 INTERFACE_ID_PPB_URL_REQUEST_INFO, request_id, | 79 return PP_FALSE; |
| 65 std::string(data, len))); | 80 |
| 81 dispatcher->Send(new PpapiHostMsg_PPBURLRequestInfo_AppendDataToBody( |
| 82 INTERFACE_ID_PPB_URL_REQUEST_INFO, request_id, std::string(data, len))); |
| 66 | 83 |
| 67 // TODO(brettw) do some validation. We should be able to tell on the plugin | 84 // TODO(brettw) do some validation. We should be able to tell on the plugin |
| 68 // side whether the request will succeed or fail in the renderer. | 85 // side whether the request will succeed or fail in the renderer. |
| 69 return PP_TRUE; | 86 return PP_TRUE; |
| 70 } | 87 } |
| 71 | 88 |
| 72 PP_Bool AppendFileToBody(PP_Resource request_id, | 89 PP_Bool AppendFileToBody(PP_Resource request_id, |
| 73 PP_Resource file_ref_id, | 90 PP_Resource file_ref_id, |
| 74 int64_t start_offset, | 91 int64_t start_offset, |
| 75 int64_t number_of_bytes, | 92 int64_t number_of_bytes, |
| 76 PP_Time expected_last_modified_time) { | 93 PP_Time expected_last_modified_time) { |
| 77 PluginDispatcher::Get()->Send( | 94 PluginDispatcher* dispatcher = DispatcherFromURLRequestInfo(request_id); |
| 78 new PpapiHostMsg_PPBURLRequestInfo_AppendFileToBody( | 95 if (!dispatcher) |
| 79 INTERFACE_ID_PPB_URL_REQUEST_INFO, request_id, file_ref_id, | 96 return PP_FALSE; |
| 80 start_offset, number_of_bytes, expected_last_modified_time)); | 97 |
| 98 dispatcher->Send(new PpapiHostMsg_PPBURLRequestInfo_AppendFileToBody( |
| 99 INTERFACE_ID_PPB_URL_REQUEST_INFO, request_id, file_ref_id, |
| 100 start_offset, number_of_bytes, expected_last_modified_time)); |
| 81 | 101 |
| 82 // TODO(brettw) do some validation. We should be able to tell on the plugin | 102 // TODO(brettw) do some validation. We should be able to tell on the plugin |
| 83 // side whether the request will succeed or fail in the renderer. | 103 // side whether the request will succeed or fail in the renderer. |
| 84 return PP_TRUE; | 104 return PP_TRUE; |
| 85 } | 105 } |
| 86 | 106 |
| 87 const PPB_URLRequestInfo ppb_urlrequestinfo = { | 107 const PPB_URLRequestInfo ppb_urlrequestinfo = { |
| 88 &Create, | 108 &Create, |
| 89 &IsURLRequestInfo, | 109 &IsURLRequestInfo, |
| 90 &SetProperty, | 110 &SetProperty, |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 int64_t start_offset, | 175 int64_t start_offset, |
| 156 int64_t number_of_bytes, | 176 int64_t number_of_bytes, |
| 157 double expected_last_modified_time) { | 177 double expected_last_modified_time) { |
| 158 ppb_url_request_info_target()->AppendFileToBody( | 178 ppb_url_request_info_target()->AppendFileToBody( |
| 159 request, file_ref, start_offset, number_of_bytes, | 179 request, file_ref, start_offset, number_of_bytes, |
| 160 expected_last_modified_time); | 180 expected_last_modified_time); |
| 161 } | 181 } |
| 162 | 182 |
| 163 } // namespace proxy | 183 } // namespace proxy |
| 164 } // namespace pp | 184 } // namespace pp |
| OLD | NEW |