diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-17 02:10:45 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-17 02:10:45 +0000 |
commit | bf712f8ee12c3045ed390005887acb28e2bc7d49 (patch) | |
tree | 03769bfbfd2c85160932135dc4f06f6da9e45875 /ppapi | |
parent | dce730aba66fca3b63458a483bb60eeb716f2a79 (diff) | |
download | chromium_src-bf712f8ee12c3045ed390005887acb28e2bc7d49.zip chromium_src-bf712f8ee12c3045ed390005887acb28e2bc7d49.tar.gz chromium_src-bf712f8ee12c3045ed390005887acb28e2bc7d49.tar.bz2 |
Convert the URL loading objects to the API/thunk system.
TEST=PPAPI UI tests
BUG=none
Review URL: http://codereview.chromium.org/7192012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@89439 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi')
-rw-r--r-- | ppapi/proxy/dispatcher.cc | 2 | ||||
-rw-r--r-- | ppapi/proxy/interface_id.h | 1 | ||||
-rw-r--r-- | ppapi/proxy/ppapi_messages.h | 4 | ||||
-rw-r--r-- | ppapi/proxy/ppb_url_loader_proxy.cc | 586 | ||||
-rw-r--r-- | ppapi/proxy/ppb_url_loader_proxy.h | 28 | ||||
-rw-r--r-- | ppapi/proxy/ppb_url_request_info_proxy.cc | 182 | ||||
-rw-r--r-- | ppapi/proxy/ppb_url_request_info_proxy.h | 4 | ||||
-rw-r--r-- | ppapi/proxy/ppb_url_response_info_proxy.cc | 109 | ||||
-rw-r--r-- | ppapi/proxy/ppb_url_response_info_proxy.h | 8 | ||||
-rw-r--r-- | ppapi/proxy/resource_creation_proxy.cc | 11 | ||||
-rw-r--r-- | ppapi/thunk/thunk.h | 8 |
11 files changed, 429 insertions, 514 deletions
diff --git a/ppapi/proxy/dispatcher.cc b/ppapi/proxy/dispatcher.cc index 78b558c..dcc40cf 100644 --- a/ppapi/proxy/dispatcher.cc +++ b/ppapi/proxy/dispatcher.cc @@ -144,7 +144,7 @@ InterfaceList::InterfaceList() { AddPPB(PPB_Surface3D_Proxy::GetInfo()); AddPPB(PPB_Testing_Proxy::GetInfo()); AddPPB(PPB_URLLoader_Proxy::GetInfo()); - AddPPB(PPB_URLLoaderTrusted_Proxy::GetInfo()); + AddPPB(PPB_URLLoader_Proxy::GetTrustedInfo()); AddPPB(PPB_URLRequestInfo_Proxy::GetInfo()); AddPPB(PPB_URLResponseInfo_Proxy::GetInfo()); AddPPB(PPB_URLUtil_Proxy::GetInfo()); diff --git a/ppapi/proxy/interface_id.h b/ppapi/proxy/interface_id.h index 544e727..1e4ced0 100644 --- a/ppapi/proxy/interface_id.h +++ b/ppapi/proxy/interface_id.h @@ -44,7 +44,6 @@ enum InterfaceID { INTERFACE_ID_PPB_SURFACE_3D, INTERFACE_ID_PPB_TESTING, INTERFACE_ID_PPB_URL_LOADER, - INTERFACE_ID_PPB_URL_LOADER_TRUSTED, INTERFACE_ID_PPB_URL_REQUEST_INFO, INTERFACE_ID_PPB_URL_RESPONSE_INFO, INTERFACE_ID_PPB_URL_UTIL, diff --git a/ppapi/proxy/ppapi_messages.h b/ppapi/proxy/ppapi_messages.h index d31b0d7..9b29993 100644 --- a/ppapi/proxy/ppapi_messages.h +++ b/ppapi/proxy/ppapi_messages.h @@ -645,9 +645,7 @@ IPC_MESSAGE_ROUTED2(PpapiHostMsg_PPBURLLoader_FinishStreamingToFile, uint32_t /* serialized_callback */) IPC_MESSAGE_ROUTED1(PpapiHostMsg_PPBURLLoader_Close, pp::proxy::HostResource /* loader */) - -// PPB_URLLoaderTrusted. -IPC_MESSAGE_ROUTED1(PpapiHostMsg_PPBURLLoaderTrusted_GrantUniversalAccess, +IPC_MESSAGE_ROUTED1(PpapiHostMsg_PPBURLLoader_GrantUniversalAccess, pp::proxy::HostResource /* loader */) // PPB_URLRequestInfo. diff --git a/ppapi/proxy/ppb_url_loader_proxy.cc b/ppapi/proxy/ppb_url_loader_proxy.cc index 16fa87d..304e0e1 100644 --- a/ppapi/proxy/ppb_url_loader_proxy.cc +++ b/ppapi/proxy/ppb_url_loader_proxy.cc @@ -16,33 +16,104 @@ #include "ppapi/c/ppb_url_loader.h" #include "ppapi/c/private/ppb_proxy_private.h" #include "ppapi/c/trusted/ppb_url_loader_trusted.h" +#include "ppapi/proxy/enter_proxy.h" #include "ppapi/proxy/host_dispatcher.h" #include "ppapi/proxy/plugin_dispatcher.h" #include "ppapi/proxy/plugin_resource.h" #include "ppapi/proxy/plugin_resource_tracker.h" #include "ppapi/proxy/ppapi_messages.h" #include "ppapi/proxy/ppb_url_response_info_proxy.h" +#include "ppapi/thunk/enter.h" +#include "ppapi/thunk/ppb_url_loader_api.h" +#include "ppapi/thunk/resource_creation_api.h" +#include "ppapi/thunk/thunk.h" #if defined(OS_LINUX) #include <sys/shm.h> #endif +using ppapi::thunk::EnterFunctionNoLock; +using ppapi::thunk::EnterResourceNoLock; +using ppapi::thunk::PPB_URLLoader_API; +using ppapi::thunk::ResourceCreationAPI; + namespace pp { namespace proxy { -class URLLoader : public PluginResource { +namespace { + +// The maximum size we'll read into the plugin without being explicitly +// asked for a larger buffer. +const int32_t kMaxReadBufferSize = 16777216; // 16MB + +// Called in the renderer when the byte counts have changed. We send a message +// to the plugin to synchronize its counts so it can respond to status polls +// from the plugin. +void UpdateResourceLoadStatus(PP_Instance pp_instance, + PP_Resource pp_resource, + int64 bytes_sent, + int64 total_bytes_to_be_sent, + int64 bytes_received, + int64 total_bytes_to_be_received) { + Dispatcher* dispatcher = HostDispatcher::GetForInstance(pp_instance); + if (!dispatcher) + return; + + PPBURLLoader_UpdateProgress_Params params; + params.instance = pp_instance; + params.resource.SetHostResource(pp_instance, pp_resource); + params.bytes_sent = bytes_sent; + params.total_bytes_to_be_sent = total_bytes_to_be_sent; + params.bytes_received = bytes_received; + params.total_bytes_to_be_received = total_bytes_to_be_received; + dispatcher->Send(new PpapiMsg_PPBURLLoader_UpdateProgress( + INTERFACE_ID_PPB_URL_LOADER, params)); +} + +InterfaceProxy* CreateURLLoaderProxy(Dispatcher* dispatcher, + const void* target_interface) { + return new PPB_URLLoader_Proxy(dispatcher, target_interface); +} + +} // namespace + +// URLLoader ------------------------------------------------------------------- + +class URLLoader : public PluginResource, public PPB_URLLoader_API { public: URLLoader(const HostResource& resource); virtual ~URLLoader(); - // Resource overrides. - virtual URLLoader* AsURLLoader() { return this; } - - PP_Resource GetResponseInfo(); - - // Appends the given data to the buffer_. - void PushBuffer(const char* data, size_t data_size); + // ResourceObjectBase overrides. + virtual PPB_URLLoader_API* AsPPB_URLLoader_API() OVERRIDE; + + // PPB_URLLoader_API implementation. + virtual int32_t Open(PP_Resource request_id, + PP_CompletionCallback callback) OVERRIDE; + virtual int32_t FollowRedirect(PP_CompletionCallback callback) OVERRIDE; + virtual PP_Bool GetUploadProgress(int64_t* bytes_sent, + int64_t* total_bytes_to_be_sent) OVERRIDE; + virtual PP_Bool GetDownloadProgress( + int64_t* bytes_received, + int64_t* total_bytes_to_be_received) OVERRIDE; + virtual PP_Resource GetResponseInfo() OVERRIDE; + virtual int32_t ReadResponseBody(void* buffer, + int32_t bytes_to_read, + PP_CompletionCallback callback) OVERRIDE; + virtual int32_t FinishStreamingToFile( + PP_CompletionCallback callback) OVERRIDE; + virtual void Close() OVERRIDE; + virtual void GrantUniversalAccess() OVERRIDE; + virtual void SetStatusCallback( + PP_URLLoaderTrusted_StatusCallback cb) OVERRIDE; + + // Called when the browser has new up/download progress to report. + void UpdateProgress(const PPBURLLoader_UpdateProgress_Params& params); + + // Called when the browser responds to our ReadResponseBody request. + void ReadResponseBodyAck(int32 result, const std::string& data); + private: // Reads the give bytes out of the buffer_, placing them in the given output // buffer, and removes the bytes from the buffer. // @@ -100,157 +171,83 @@ URLLoader::~URLLoader() { PluginResourceTracker::GetInstance()->ReleaseResource(response_info_); } -PP_Resource URLLoader::GetResponseInfo() { - if (!response_info_) { - PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance()); - if (!dispatcher) - return 0; - - HostResource response_id; - dispatcher->Send(new PpapiHostMsg_PPBURLLoader_GetResponseInfo( - INTERFACE_ID_PPB_URL_LOADER, host_resource(), &response_id)); - if (response_id.is_null()) - return 0; - - response_info_ = PPB_URLResponseInfo_Proxy::CreateResponseForResource( - response_id); - } - - // The caller expects to get a ref, and we want to keep holding ours. - PluginResourceTracker::GetInstance()->AddRefResource(response_info_); - return response_info_; +PPB_URLLoader_API* URLLoader::AsPPB_URLLoader_API() { + return this; } -void URLLoader::PushBuffer(const char* data, size_t data_size) { - buffer_.insert(buffer_.end(), data, data + data_size); -} - -void URLLoader::PopBuffer(void* output_buffer, int32_t output_size) { - CHECK(output_size <= static_cast<int32_t>(buffer_.size())); - std::copy(buffer_.begin(), - buffer_.begin() + output_size, - static_cast<char*>(output_buffer)); - buffer_.erase(buffer_.begin(), - buffer_.begin() + output_size); -} - -namespace { - -// The maximum size we'll read into the plugin without being explicitly -// asked for a larger buffer. -static const int32_t kMaxReadBufferSize = 16777216; // 16MB - -// Converts the given loader ID to the dispatcher associated with it and the -// loader object. Returns true if the object was found. -bool RoutingDataFromURLLoader(PP_Resource loader_id, - URLLoader** loader_object, - PluginDispatcher** dispatcher) { - *loader_object = PluginResource::GetAs<URLLoader>(loader_id); - if (!*loader_object) - return false; - *dispatcher = PluginDispatcher::GetForInstance((*loader_object)->instance()); - return !!*dispatcher; -} - -// Plugin PPB_URLLoader implmentation ------------------------------------------ - -PP_Resource Create(PP_Instance instance_id) { - PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id); - if (!dispatcher) - return 0; - - HostResource result; - dispatcher->Send(new PpapiHostMsg_PPBURLLoader_Create( - INTERFACE_ID_PPB_URL_LOADER, instance_id, &result)); - if (result.is_null()) - return 0; - return PPB_URLLoader_Proxy::TrackPluginResource(result); -} - -PP_Bool IsURLLoader(PP_Resource resource) { - URLLoader* object = PluginResource::GetAs<URLLoader>(resource); - return BoolToPPBool(!!object); -} - -int32_t Open(PP_Resource loader_id, - PP_Resource request_id, - PP_CompletionCallback callback) { - URLLoader* loader_object; - PluginDispatcher* dispatcher; - if (!RoutingDataFromURLLoader(loader_id, &loader_object, &dispatcher)) - return PP_ERROR_BADRESOURCE; +int32_t URLLoader::Open(PP_Resource request_id, + PP_CompletionCallback callback) { PluginResource* request_object = PluginResourceTracker::GetInstance()->GetResourceObject(request_id); if (!request_object) - return PP_ERROR_BADRESOURCE; + return PP_ERROR_BADARGUMENT; - dispatcher->Send(new PpapiHostMsg_PPBURLLoader_Open( - INTERFACE_ID_PPB_URL_LOADER, loader_object->host_resource(), + // TODO(brettw) http://crbug.com/86279: SendCallback doesn't ensure that + // the proper callback semantics happen if the object is deleted. + GetDispatcher()->Send(new PpapiHostMsg_PPBURLLoader_Open( + INTERFACE_ID_PPB_URL_LOADER, host_resource(), request_object->host_resource(), - dispatcher->callback_tracker().SendCallback(callback))); + GetDispatcher()->callback_tracker().SendCallback(callback))); return PP_OK_COMPLETIONPENDING; } -int32_t FollowRedirect(PP_Resource loader_id, - PP_CompletionCallback callback) { - URLLoader* loader_object; - PluginDispatcher* dispatcher; - if (!RoutingDataFromURLLoader(loader_id, &loader_object, &dispatcher)) - return PP_ERROR_BADRESOURCE; - - dispatcher->Send(new PpapiHostMsg_PPBURLLoader_FollowRedirect( - INTERFACE_ID_PPB_URL_LOADER, loader_object->host_resource(), - dispatcher->callback_tracker().SendCallback(callback))); +int32_t URLLoader::FollowRedirect(PP_CompletionCallback callback) { + // TODO(brettw) http://crbug.com/86279: SendCallback doesn't ensure that + // the proper callback semantics happen if the object is deleted. + GetDispatcher()->Send(new PpapiHostMsg_PPBURLLoader_FollowRedirect( + INTERFACE_ID_PPB_URL_LOADER, host_resource(), + GetDispatcher()->callback_tracker().SendCallback(callback))); return PP_OK_COMPLETIONPENDING; } -PP_Bool GetUploadProgress(PP_Resource loader_id, - int64_t* bytes_sent, - int64_t* total_bytes_to_be_sent) { - URLLoader* object = PluginResource::GetAs<URLLoader>(loader_id); - if (!object || object->bytes_sent_ == -1) { +PP_Bool URLLoader::GetUploadProgress(int64_t* bytes_sent, + int64_t* total_bytes_to_be_sent) { + if (bytes_sent_ == -1) { *bytes_sent = 0; *total_bytes_to_be_sent = 0; return PP_FALSE; } - *bytes_sent = object->bytes_sent_; - *total_bytes_to_be_sent = object->total_bytes_to_be_sent_; + *bytes_sent = bytes_sent_; + *total_bytes_to_be_sent = total_bytes_to_be_sent_; return PP_TRUE; } -PP_Bool GetDownloadProgress(PP_Resource loader_id, - int64_t* bytes_received, - int64_t* total_bytes_to_be_received) { - URLLoader* object = PluginResource::GetAs<URLLoader>(loader_id); - if (!object || object->bytes_received_ == -1) { +PP_Bool URLLoader::GetDownloadProgress( + int64_t* bytes_received, + int64_t* total_bytes_to_be_received) { + if (bytes_received_ == -1) { *bytes_received = 0; *total_bytes_to_be_received = 0; return PP_FALSE; } - *bytes_received = object->bytes_received_; - *total_bytes_to_be_received = object->total_bytes_to_be_received_; + *bytes_received = bytes_received_; + *total_bytes_to_be_received = total_bytes_to_be_received_; return PP_TRUE; } -PP_Resource GetResponseInfo(PP_Resource loader_id) { - URLLoader* object = PluginResource::GetAs<URLLoader>(loader_id); - if (!object) - return 0; - return object->GetResponseInfo(); -} +PP_Resource URLLoader::GetResponseInfo() { + if (!response_info_) { + HostResource response_id; + GetDispatcher()->Send(new PpapiHostMsg_PPBURLLoader_GetResponseInfo( + INTERFACE_ID_PPB_URL_LOADER, host_resource(), &response_id)); + if (response_id.is_null()) + return 0; + + response_info_ = PPB_URLResponseInfo_Proxy::CreateResponseForResource( + response_id); + } -int32_t ReadResponseBody(PP_Resource loader_id, - void* buffer, - int32_t bytes_to_read, - PP_CompletionCallback callback) { - URLLoader* object; - PluginDispatcher* dispatcher; - if (!RoutingDataFromURLLoader(loader_id, &object, &dispatcher)) - return PP_ERROR_BADRESOURCE; + // The caller expects to get a ref, and we want to keep holding ours. + PluginResourceTracker::GetInstance()->AddRefResource(response_info_); + return response_info_; +} +int32_t URLLoader::ReadResponseBody(void* buffer, + int32_t bytes_to_read, + PP_CompletionCallback callback) { if (!buffer || bytes_to_read <= 0) return PP_ERROR_BADARGUMENT; // Must specify an output buffer. - if (object->current_read_callback_.func) + if (current_read_callback_.func) return PP_ERROR_INPROGRESS; // Can only have one request pending. // Currently we don't support sync calls to read. We'll need to revisit @@ -258,110 +255,88 @@ int32_t ReadResponseBody(PP_Resource loader_id, if (!callback.func) return PP_ERROR_BADARGUMENT; - if (static_cast<size_t>(bytes_to_read) <= object->buffer_.size()) { + if (static_cast<size_t>(bytes_to_read) <= buffer_.size()) { // Special case: we've buffered enough data to be able to synchronously // return data to the caller. Do so without making IPCs. - object->PopBuffer(buffer, bytes_to_read); + PopBuffer(buffer, bytes_to_read); return bytes_to_read; } - object->current_read_callback_ = callback; - object->current_read_buffer_ = buffer; - object->current_read_buffer_size_ = bytes_to_read; + current_read_callback_ = callback; + current_read_buffer_ = buffer; + current_read_buffer_size_ = bytes_to_read; - dispatcher->Send(new PpapiHostMsg_PPBURLLoader_ReadResponseBody( - INTERFACE_ID_PPB_URL_LOADER, - object->host_resource(), bytes_to_read)); + GetDispatcher()->Send(new PpapiHostMsg_PPBURLLoader_ReadResponseBody( + INTERFACE_ID_PPB_URL_LOADER, host_resource(), bytes_to_read)); return PP_OK_COMPLETIONPENDING; } -int32_t FinishStreamingToFile(PP_Resource loader_id, - PP_CompletionCallback callback) { - URLLoader* loader_object; - PluginDispatcher* dispatcher; - if (!RoutingDataFromURLLoader(loader_id, &loader_object, &dispatcher)) - return PP_ERROR_BADRESOURCE; - - dispatcher->Send(new PpapiHostMsg_PPBURLLoader_FinishStreamingToFile( - INTERFACE_ID_PPB_URL_LOADER, loader_object->host_resource(), - dispatcher->callback_tracker().SendCallback(callback))); +int32_t URLLoader::FinishStreamingToFile(PP_CompletionCallback callback) { + GetDispatcher()->Send(new PpapiHostMsg_PPBURLLoader_FinishStreamingToFile( + INTERFACE_ID_PPB_URL_LOADER, host_resource(), + GetDispatcher()->callback_tracker().SendCallback(callback))); return PP_OK_COMPLETIONPENDING; } -void Close(PP_Resource loader_id) { - URLLoader* loader_object; - PluginDispatcher* dispatcher; - if (!RoutingDataFromURLLoader(loader_id, &loader_object, &dispatcher)) - return; +void URLLoader::Close() { + GetDispatcher()->Send(new PpapiHostMsg_PPBURLLoader_Close( + INTERFACE_ID_PPB_URL_LOADER, host_resource())); +} - dispatcher->Send(new PpapiHostMsg_PPBURLLoader_Close( - INTERFACE_ID_PPB_URL_LOADER, loader_object->host_resource())); -} - -const PPB_URLLoader urlloader_interface = { - &Create, - &IsURLLoader, - &Open, - &FollowRedirect, - &GetUploadProgress, - &GetDownloadProgress, - &GetResponseInfo, - &ReadResponseBody, - &FinishStreamingToFile, - &Close -}; +void URLLoader::GrantUniversalAccess() { + GetDispatcher()->Send( + new PpapiHostMsg_PPBURLLoader_GrantUniversalAccess( + INTERFACE_ID_PPB_URL_LOADER, host_resource())); +} -InterfaceProxy* CreateURLLoaderProxy(Dispatcher* dispatcher, - const void* target_interface) { - return new PPB_URLLoader_Proxy(dispatcher, target_interface); +void URLLoader::SetStatusCallback( + PP_URLLoaderTrusted_StatusCallback cb) { + // Not implemented in the proxied version, this is for implementing the + // proxy itself in the host. } -// Plugin URLLoaderTrusted implementation -------------------------------------- +void URLLoader::UpdateProgress( + const PPBURLLoader_UpdateProgress_Params& params) { + bytes_sent_ = params.bytes_sent; + total_bytes_to_be_sent_ = params.total_bytes_to_be_sent; + bytes_received_ = params.bytes_received; + total_bytes_to_be_received_ = params.total_bytes_to_be_received; +} -void GrantUniversalAccess(PP_Resource loader_id) { - URLLoader* loader_object; - PluginDispatcher* dispatcher; - if (!RoutingDataFromURLLoader(loader_id, &loader_object, &dispatcher)) +void URLLoader::ReadResponseBodyAck(int32 result, const std::string& data) { + if (!current_read_callback_.func || !current_read_buffer_) { + NOTREACHED(); return; + } - dispatcher->Send( - new PpapiHostMsg_PPBURLLoaderTrusted_GrantUniversalAccess( - INTERFACE_ID_PPB_URL_LOADER_TRUSTED, loader_object->host_resource())); -} + // Append the data we requested to the internal buffer. + // TODO(brettw) avoid double-copying data that's coming from IPC and going + // into the plugin buffer (we can skip the internal buffer in this case). + buffer_.insert(buffer_.end(), data.begin(), data.end()); -const PPB_URLLoaderTrusted urlloader_trusted_interface = { - &GrantUniversalAccess, - NULL, // RegisterStatusCallback is used internally by the proxy only. -}; + if (result >= 0) { + // Fill the user buffer. We may get fewer bytes than requested in the + // case of stream end. + int32_t bytes_to_return = std::min(current_read_buffer_size_, + static_cast<int32_t>(buffer_.size())); + PopBuffer(current_read_buffer_, bytes_to_return); + result = bytes_to_return; + } -InterfaceProxy* CreateURLLoaderTrustedProxy(Dispatcher* dispatcher, - const void* target_interface) { - return new PPB_URLLoaderTrusted_Proxy(dispatcher, target_interface); + // The plugin should be able to make a new request from their callback, so + // we have to clear our copy first. + PP_RunAndClearCompletionCallback(¤t_read_callback_, result); } -// Called in the renderer when the byte counts have changed. We send a message -// to the plugin to synchronize its counts so it can respond to status polls -// from the plugin. -void UpdateResourceLoadStatus(PP_Instance pp_instance, - PP_Resource pp_resource, - int64 bytes_sent, - int64 total_bytes_to_be_sent, - int64 bytes_received, - int64 total_bytes_to_be_received) { - Dispatcher* dispatcher = HostDispatcher::GetForInstance(pp_instance); - PPBURLLoader_UpdateProgress_Params params; - params.instance = pp_instance; - params.resource.SetHostResource(pp_instance, pp_resource); - params.bytes_sent = bytes_sent; - params.total_bytes_to_be_sent = total_bytes_to_be_sent; - params.bytes_received = bytes_received; - params.total_bytes_to_be_received = total_bytes_to_be_received; - dispatcher->Send(new PpapiMsg_PPBURLLoader_UpdateProgress( - INTERFACE_ID_PPB_URL_LOADER, params)); +void URLLoader::PopBuffer(void* output_buffer, int32_t output_size) { + CHECK(output_size <= static_cast<int32_t>(buffer_.size())); + std::copy(buffer_.begin(), + buffer_.begin() + output_size, + static_cast<char*>(output_buffer)); + buffer_.erase(buffer_.begin(), + buffer_.begin() + output_size); } -} // namespace - // PPB_URLLoader_Proxy --------------------------------------------------------- struct PPB_URLLoader_Proxy::ReadCallbackInfo { @@ -389,7 +364,7 @@ PP_Resource PPB_URLLoader_Proxy::TrackPluginResource( // static const InterfaceProxy::Info* PPB_URLLoader_Proxy::GetInfo() { static const Info info = { - &urlloader_interface, + ::ppapi::thunk::GetPPB_URLLoader_Thunk(), PPB_URLLOADER_INTERFACE, INTERFACE_ID_PPB_URL_LOADER, false, @@ -398,6 +373,32 @@ const InterfaceProxy::Info* PPB_URLLoader_Proxy::GetInfo() { return &info; } +// static +const InterfaceProxy::Info* PPB_URLLoader_Proxy::GetTrustedInfo() { + static const Info info = { + ::ppapi::thunk::GetPPB_URLLoaderTrusted_Thunk(), + PPB_URLLOADERTRUSTED_INTERFACE, + INTERFACE_ID_NONE, // URL_LOADER is the canonical one. + false, + &CreateURLLoaderProxy + }; + return &info; +} + +// static +PP_Resource PPB_URLLoader_Proxy::CreateProxyResource(PP_Instance pp_instance) { + PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(pp_instance); + if (!dispatcher) + return 0; + + HostResource result; + dispatcher->Send(new PpapiHostMsg_PPBURLLoader_Create( + INTERFACE_ID_PPB_URL_LOADER, pp_instance, &result)); + if (result.is_null()) + return 0; + return PPB_URLLoader_Proxy::TrackPluginResource(result); +} + bool PPB_URLLoader_Proxy::OnMessageReceived(const IPC::Message& msg) { bool handled = true; IPC_BEGIN_MESSAGE_MAP(PPB_URLLoader_Proxy, msg) @@ -415,6 +416,8 @@ bool PPB_URLLoader_Proxy::OnMessageReceived(const IPC::Message& msg) { OnMsgFinishStreamingToFile) IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLLoader_Close, OnMsgClose) + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLLoader_GrantUniversalAccess, + OnMsgGrantUniversalAccess) IPC_MESSAGE_HANDLER(PpapiMsg_PPBURLLoader_UpdateProgress, OnMsgUpdateProgress) @@ -430,21 +433,31 @@ void PPB_URLLoader_Proxy::PrepareURLLoaderForSendingToPlugin( PP_Resource resource) { // So the plugin can query load status, we need to register our status // callback before sending any URLLoader to the plugin. - RegisterStatusCallback(resource); + EnterResourceNoLock<PPB_URLLoader_API> enter(resource, false); + if (enter.succeeded()) + enter.object()->SetStatusCallback(&UpdateResourceLoadStatus); + else + NOTREACHED(); // Only called internally, resource should be valid. } void PPB_URLLoader_Proxy::OnMsgCreate(PP_Instance instance, HostResource* result) { - result->SetHostResource(instance, ppb_url_loader_target()->Create(instance)); - PrepareURLLoaderForSendingToPlugin(result->host_resource()); + EnterFunctionNoLock<ResourceCreationAPI> enter(instance, true); + if (enter.succeeded()) { + result->SetHostResource(instance, + enter.functions()->CreateURLLoader(instance)); + PrepareURLLoaderForSendingToPlugin(result->host_resource()); + } } void PPB_URLLoader_Proxy::OnMsgOpen(const HostResource& loader, const HostResource& request_info, uint32_t serialized_callback) { + EnterHostFromHostResource<PPB_URLLoader_API> enter(loader); PP_CompletionCallback callback = ReceiveCallback(serialized_callback); - int32_t result = ppb_url_loader_target()->Open( - loader.host_resource(), request_info.host_resource(), callback); + int32_t result = PP_ERROR_BADRESOURCE; + if (enter.succeeded()) + result = enter.object()->Open(request_info.host_resource(), callback); if (result != PP_OK_COMPLETIONPENDING) PP_RunCompletionCallback(&callback, result); // TODO(brettw) bug 73236 register for the status callbacks. @@ -453,17 +466,22 @@ void PPB_URLLoader_Proxy::OnMsgOpen(const HostResource& loader, void PPB_URLLoader_Proxy::OnMsgFollowRedirect( const HostResource& loader, uint32_t serialized_callback) { + EnterHostFromHostResource<PPB_URLLoader_API> enter(loader); PP_CompletionCallback callback = ReceiveCallback(serialized_callback); - int32_t result = ppb_url_loader_target()->FollowRedirect( - loader.host_resource(), callback); + int32_t result = PP_ERROR_BADRESOURCE; + if (enter.succeeded()) + result = enter.object()->FollowRedirect(callback); if (result != PP_OK_COMPLETIONPENDING) PP_RunCompletionCallback(&callback, result); } void PPB_URLLoader_Proxy::OnMsgGetResponseInfo(const HostResource& loader, HostResource* result) { - result->SetHostResource(loader.instance(), - ppb_url_loader_target()->GetResponseInfo(loader.host_resource())); + EnterHostFromHostResource<PPB_URLLoader_API> enter(loader); + if (enter.succeeded()) { + result->SetHostResource(loader.instance(), + enter.object()->GetResponseInfo()); + } } void PPB_URLLoader_Proxy::OnMsgReadResponseBody( @@ -502,9 +520,13 @@ void PPB_URLLoader_Proxy::OnMsgReadResponseBody( CompletionCallback callback = callback_factory_.NewCallback( &PPB_URLLoader_Proxy::OnReadCallback, info); - int32_t result = ppb_url_loader_target()->ReadResponseBody( - loader.host_resource(), const_cast<char*>(info->read_buffer.c_str()), - bytes_to_read, callback.pp_completion_callback()); + EnterHostFromHostResource<PPB_URLLoader_API> enter(loader); + int32_t result = PP_ERROR_BADRESOURCE; + if (enter.succeeded()) { + result = enter.object()->ReadResponseBody( + const_cast<char*>(info->read_buffer.c_str()), + bytes_to_read, callback.pp_completion_callback()); + } if (result != PP_OK_COMPLETIONPENDING) { // Send error (or perhaps success for synchronous reads) back to plugin. // The callback function is already set up to do this and also delete the @@ -516,33 +538,34 @@ void PPB_URLLoader_Proxy::OnMsgReadResponseBody( void PPB_URLLoader_Proxy::OnMsgFinishStreamingToFile( const HostResource& loader, uint32_t serialized_callback) { + EnterHostFromHostResource<PPB_URLLoader_API> enter(loader); PP_CompletionCallback callback = ReceiveCallback(serialized_callback); - int32_t result = ppb_url_loader_target()->FinishStreamingToFile( - loader.host_resource(), callback); + int32_t result = PP_ERROR_BADRESOURCE; + if (enter.succeeded()) + result = enter.object()->FinishStreamingToFile(callback); if (result != PP_OK_COMPLETIONPENDING) PP_RunCompletionCallback(&callback, result); } void PPB_URLLoader_Proxy::OnMsgClose(const HostResource& loader) { - ppb_url_loader_target()->Close(loader.host_resource()); + EnterHostFromHostResource<PPB_URLLoader_API> enter(loader); + if (enter.succeeded()) + enter.object()->Close(); +} + +void PPB_URLLoader_Proxy::OnMsgGrantUniversalAccess( + const HostResource& loader) { + EnterHostFromHostResource<PPB_URLLoader_API> enter(loader); + if (enter.succeeded()) + enter.object()->GrantUniversalAccess(); } // Called in the Plugin. void PPB_URLLoader_Proxy::OnMsgUpdateProgress( const PPBURLLoader_UpdateProgress_Params& params) { - PP_Resource plugin_resource = - PluginResourceTracker::GetInstance()->PluginResourceForHostResource( - params.resource); - if (!plugin_resource) - return; - URLLoader* object = PluginResource::GetAs<URLLoader>(plugin_resource); - if (!object) - return; - - object->bytes_sent_ = params.bytes_sent; - object->total_bytes_to_be_sent_ = params.total_bytes_to_be_sent; - object->bytes_received_ = params.bytes_received; - object->total_bytes_to_be_received_ = params.total_bytes_to_be_received; + EnterPluginFromHostResource<PPB_URLLoader_API> enter(params.resource); + if (enter.succeeded()) + static_cast<URLLoader*>(enter.object())->UpdateProgress(params); } // Called in the Plugin. @@ -550,55 +573,9 @@ void PPB_URLLoader_Proxy::OnMsgReadResponseBodyAck( const HostResource& host_resource, int32 result, const std::string& data) { - PP_Resource plugin_resource = - PluginResourceTracker::GetInstance()->PluginResourceForHostResource( - host_resource); - if (!plugin_resource) - return; - URLLoader* object = PluginResource::GetAs<URLLoader>(plugin_resource); - if (!object) - return; - - if (!object->current_read_callback_.func || !object->current_read_buffer_) { - NOTREACHED(); - return; - } - - // Append the data we requested to the internal buffer. - // TODO(brettw) avoid double-copying data that's coming from IPC and going - // into the plugin buffer (we can skip the internal buffer in this case). - object->PushBuffer(data.data(), data.length()); - - if (result >= 0) { - // Fill the user buffer. We may get fewer bytes than requested in the - // case of stream end. - int32_t bytes_to_return = - std::min(object->current_read_buffer_size_, - static_cast<int32_t>(object->buffer_.size())); - object->PopBuffer(object->current_read_buffer_, bytes_to_return); - result = bytes_to_return; - } - - // The plugin should be able to make a new request from their callback, so - // we have to clear our copy first. - PP_RunAndClearCompletionCallback(&object->current_read_callback_, result); -} - -void PPB_URLLoader_Proxy::RegisterStatusCallback(PP_Resource resource) { - DCHECK(!dispatcher()->IsPlugin()); - if (!host_urlloader_trusted_interface_) { - host_urlloader_trusted_interface_ = - static_cast<const PPB_URLLoaderTrusted*>( - dispatcher()->GetLocalInterface(PPB_URLLOADERTRUSTED_INTERFACE)); - if (!host_urlloader_trusted_interface_) { - NOTREACHED(); - return; - } - } - - host_urlloader_trusted_interface_->RegisterStatusCallback( - resource, - &UpdateResourceLoadStatus); + EnterPluginFromHostResource<PPB_URLLoader_API> enter(host_resource); + if (enter.succeeded()) + static_cast<URLLoader*>(enter.object())->ReadResponseBodyAck(result, data); } void PPB_URLLoader_Proxy::OnReadCallback(int32_t result, @@ -614,44 +591,5 @@ void PPB_URLLoader_Proxy::OnReadCallback(int32_t result, delete info; } -// PPB_URLLoaderTrusted_Proxy -------------------------------------------------- - -PPB_URLLoaderTrusted_Proxy::PPB_URLLoaderTrusted_Proxy( - Dispatcher* dispatcher, - const void* target_interface) - : InterfaceProxy(dispatcher, target_interface) { -} - -PPB_URLLoaderTrusted_Proxy::~PPB_URLLoaderTrusted_Proxy() { -} - -// static -const InterfaceProxy::Info* PPB_URLLoaderTrusted_Proxy::GetInfo() { - static const Info info = { - &urlloader_trusted_interface, - PPB_URLLOADERTRUSTED_INTERFACE, - INTERFACE_ID_PPB_URL_LOADER_TRUSTED, - true, - &CreateURLLoaderTrustedProxy, - }; - return &info; -} - -bool PPB_URLLoaderTrusted_Proxy::OnMessageReceived(const IPC::Message& msg) { - bool handled = true; - IPC_BEGIN_MESSAGE_MAP(PPB_URLLoaderTrusted_Proxy, msg) - IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLLoaderTrusted_GrantUniversalAccess, - OnMsgGrantUniversalAccess) - IPC_MESSAGE_UNHANDLED(handled = false) - IPC_END_MESSAGE_MAP(); - // TODO(brettw) handle bad messages! - return handled; -} - -void PPB_URLLoaderTrusted_Proxy::OnMsgGrantUniversalAccess( - const HostResource& loader) { - ppb_url_loader_trusted_target()->GrantUniversalAccess(loader.host_resource()); -} - } // namespace proxy } // namespace pp diff --git a/ppapi/proxy/ppb_url_loader_proxy.h b/ppapi/proxy/ppb_url_loader_proxy.h index b2a57e5..0ff7b7e 100644 --- a/ppapi/proxy/ppb_url_loader_proxy.h +++ b/ppapi/proxy/ppb_url_loader_proxy.h @@ -30,6 +30,9 @@ class PPB_URLLoader_Proxy : public InterfaceProxy { virtual ~PPB_URLLoader_Proxy(); static const Info* GetInfo(); + static const Info* GetTrustedInfo(); + + static PP_Resource CreateProxyResource(PP_Instance instance); // URLLoader objects are normally allocated by the Create function, but // they are also provided to PPP_Instance.OnMsgHandleDocumentLoad. This @@ -70,6 +73,7 @@ class PPB_URLLoader_Proxy : public InterfaceProxy { void OnMsgFinishStreamingToFile(const HostResource& loader, uint32_t serialized_callback); void OnMsgClose(const HostResource& loader); + void OnMsgGrantUniversalAccess(const HostResource& loader); // Renderer->plugin message handlers. void OnMsgUpdateProgress( @@ -78,10 +82,6 @@ class PPB_URLLoader_Proxy : public InterfaceProxy { int32_t result, const std::string& data); - // Hooks the given URLLoader resource up in the host for receiving download - // and upload status callbacks. - void RegisterStatusCallback(PP_Resource resource); - // Handles callbacks for read complete messages. Takes ownership of the info // pointer. void OnReadCallback(int32_t result, ReadCallbackInfo* info); @@ -94,26 +94,6 @@ class PPB_URLLoader_Proxy : public InterfaceProxy { const PPB_URLLoaderTrusted* host_urlloader_trusted_interface_; }; -class PPB_URLLoaderTrusted_Proxy : public InterfaceProxy { - public: - PPB_URLLoaderTrusted_Proxy(Dispatcher* dispatcher, - const void* target_interface); - virtual ~PPB_URLLoaderTrusted_Proxy(); - - static const Info* GetInfo(); - - const PPB_URLLoaderTrusted* ppb_url_loader_trusted_target() const { - return reinterpret_cast<const PPB_URLLoaderTrusted*>(target_interface()); - } - - // InterfaceProxy implementation. - virtual bool OnMessageReceived(const IPC::Message& msg); - - private: - // Plugin->renderer message handlers. - void OnMsgGrantUniversalAccess(const HostResource& loader); -}; - } // namespace proxy } // namespace pp diff --git a/ppapi/proxy/ppb_url_request_info_proxy.cc b/ppapi/proxy/ppb_url_request_info_proxy.cc index 1492a37..9d545a2 100644 --- a/ppapi/proxy/ppb_url_request_info_proxy.cc +++ b/ppapi/proxy/ppb_url_request_info_proxy.cc @@ -5,88 +5,78 @@ #include "ppapi/proxy/ppb_url_request_info_proxy.h" #include "ppapi/c/ppb_url_request_info.h" +#include "ppapi/proxy/enter_proxy.h" #include "ppapi/proxy/plugin_dispatcher.h" #include "ppapi/proxy/plugin_resource.h" #include "ppapi/proxy/ppapi_messages.h" +#include "ppapi/thunk/ppb_url_request_info_api.h" +#include "ppapi/thunk/resource_creation_api.h" +#include "ppapi/thunk/thunk.h" + +using ppapi::thunk::EnterFunctionNoLock; +using ppapi::thunk::PPB_URLRequestInfo_API; +using ppapi::thunk::ResourceCreationAPI; namespace pp { namespace proxy { -class URLRequestInfo : public PluginResource { +namespace { + +InterfaceProxy* CreateURLRequestInfoProxy(Dispatcher* dispatcher, + const void* target_interface) { + return new PPB_URLRequestInfo_Proxy(dispatcher, target_interface); +} + +} // namespace + +class URLRequestInfo : public PluginResource, + public PPB_URLRequestInfo_API { public: - URLRequestInfo(const HostResource& resource) : PluginResource(resource) { - } - virtual ~URLRequestInfo() { - } + URLRequestInfo(const HostResource& resource); + virtual ~URLRequestInfo(); - // Resource overrides. - virtual URLRequestInfo* AsURLRequestInfo() { return this; } + virtual PPB_URLRequestInfo_API* AsPPB_URLRequestInfo_API() OVERRIDE; + + // PPB_URLRequestInfo_API implementation. + virtual PP_Bool SetProperty(PP_URLRequestProperty property, + PP_Var var) OVERRIDE; + virtual PP_Bool AppendDataToBody(const void* data, uint32_t len) OVERRIDE; + virtual PP_Bool AppendFileToBody( + PP_Resource file_ref, + int64_t start_offset, + int64_t number_of_bytes, + PP_Time expected_last_modified_time) OVERRIDE; private: DISALLOW_COPY_AND_ASSIGN(URLRequestInfo); }; -namespace { - -// Computes the dispatcher and request object for the given plugin resource, -// returning true on success. -bool DispatcherFromURLRequestInfo(PP_Resource resource, - PluginDispatcher** dispatcher, - URLRequestInfo** request_info) { - *request_info = PluginResource::GetAs<URLRequestInfo>(resource); - if (!*request_info) - return false; - *dispatcher = PluginDispatcher::GetForInstance((*request_info)->instance()); - return !!*dispatcher; +URLRequestInfo::URLRequestInfo(const HostResource& resource) + : PluginResource(resource) { } -PP_Resource Create(PP_Instance instance) { - PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); - if (!dispatcher) - return 0; - - HostResource result; - dispatcher->Send(new PpapiHostMsg_PPBURLRequestInfo_Create( - INTERFACE_ID_PPB_URL_REQUEST_INFO, instance, &result)); - if (result.is_null()) - return 0; - - linked_ptr<URLRequestInfo> object(new URLRequestInfo(result)); - return PluginResourceTracker::GetInstance()->AddResource(object); +URLRequestInfo::~URLRequestInfo() { } -PP_Bool IsURLRequestInfo(PP_Resource resource) { - URLRequestInfo* object = PluginResource::GetAs<URLRequestInfo>(resource); - return BoolToPPBool(!!object); +PPB_URLRequestInfo_API* URLRequestInfo::AsPPB_URLRequestInfo_API() { + return this; } -PP_Bool SetProperty(PP_Resource request_id, - PP_URLRequestProperty property, - PP_Var var) { - PluginDispatcher* dispatcher; - URLRequestInfo* request_info; - if (!DispatcherFromURLRequestInfo(request_id, &dispatcher, &request_info)) - return PP_FALSE; - - dispatcher->Send(new PpapiHostMsg_PPBURLRequestInfo_SetProperty( - INTERFACE_ID_PPB_URL_REQUEST_INFO, request_info->host_resource(), +PP_Bool URLRequestInfo::SetProperty(PP_URLRequestProperty property, + PP_Var var) { + GetDispatcher()->Send(new PpapiHostMsg_PPBURLRequestInfo_SetProperty( + INTERFACE_ID_PPB_URL_REQUEST_INFO, host_resource(), static_cast<int32_t>(property), - SerializedVarSendInput(dispatcher, var))); + SerializedVarSendInput(GetDispatcher(), var))); // TODO(brettw) do some validation on the types. We should be able to tell on // the plugin side whether the request will succeed or fail in the renderer. return PP_TRUE; } -PP_Bool AppendDataToBody(PP_Resource request_id, - const void* data, uint32_t len) { - PluginDispatcher* dispatcher; - URLRequestInfo* request_info; - if (!DispatcherFromURLRequestInfo(request_id, &dispatcher, &request_info)) - return PP_FALSE; - - dispatcher->Send(new PpapiHostMsg_PPBURLRequestInfo_AppendDataToBody( - INTERFACE_ID_PPB_URL_REQUEST_INFO, request_info->host_resource(), +PP_Bool URLRequestInfo::AppendDataToBody(const void* data, uint32_t len) { + GetDispatcher()->Send(new PpapiHostMsg_PPBURLRequestInfo_AppendDataToBody( + INTERFACE_ID_PPB_URL_REQUEST_INFO, host_resource(), std::string(static_cast<const char*>(data), len))); // TODO(brettw) do some validation. We should be able to tell on the plugin @@ -94,22 +84,17 @@ PP_Bool AppendDataToBody(PP_Resource request_id, return PP_TRUE; } -PP_Bool AppendFileToBody(PP_Resource request_id, - PP_Resource file_ref_id, - int64_t start_offset, - int64_t number_of_bytes, - PP_Time expected_last_modified_time) { - PluginDispatcher* dispatcher; - URLRequestInfo* request_info; - if (!DispatcherFromURLRequestInfo(request_id, &dispatcher, &request_info)) - return PP_FALSE; +PP_Bool URLRequestInfo::AppendFileToBody(PP_Resource file_ref, + int64_t start_offset, + int64_t number_of_bytes, + PP_Time expected_last_modified_time) { PluginResource* file_ref_object = - PluginResourceTracker::GetInstance()->GetResourceObject(file_ref_id); + PluginResourceTracker::GetInstance()->GetResourceObject(file_ref); if (!file_ref_object) return PP_FALSE; - dispatcher->Send(new PpapiHostMsg_PPBURLRequestInfo_AppendFileToBody( - INTERFACE_ID_PPB_URL_REQUEST_INFO, request_info->host_resource(), + GetDispatcher()->Send(new PpapiHostMsg_PPBURLRequestInfo_AppendFileToBody( + INTERFACE_ID_PPB_URL_REQUEST_INFO, host_resource(), file_ref_object->host_resource(), start_offset, number_of_bytes, expected_last_modified_time)); @@ -118,20 +103,7 @@ PP_Bool AppendFileToBody(PP_Resource request_id, return PP_TRUE; } -const PPB_URLRequestInfo urlrequestinfo_interface = { - &Create, - &IsURLRequestInfo, - &SetProperty, - &AppendDataToBody, - &AppendFileToBody -}; - -InterfaceProxy* CreateURLRequestInfoProxy(Dispatcher* dispatcher, - const void* target_interface) { - return new PPB_URLRequestInfo_Proxy(dispatcher, target_interface); -} - -} // namespace +// PPB_URLRequestInfo_Proxy ---------------------------------------------------- PPB_URLRequestInfo_Proxy::PPB_URLRequestInfo_Proxy( Dispatcher* dispatcher, @@ -145,7 +117,7 @@ PPB_URLRequestInfo_Proxy::~PPB_URLRequestInfo_Proxy() { // static const InterfaceProxy::Info* PPB_URLRequestInfo_Proxy::GetInfo() { static const Info info = { - &urlrequestinfo_interface, + ::ppapi::thunk::GetPPB_URLRequestInfo_Thunk(), PPB_URLREQUESTINFO_INTERFACE, INTERFACE_ID_PPB_URL_REQUEST_INFO, false, @@ -154,6 +126,23 @@ const InterfaceProxy::Info* PPB_URLRequestInfo_Proxy::GetInfo() { return &info; } +// static +PP_Resource PPB_URLRequestInfo_Proxy::CreateProxyResource( + PP_Instance instance) { + PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); + if (!dispatcher) + return 0; + + HostResource result; + dispatcher->Send(new PpapiHostMsg_PPBURLRequestInfo_Create( + INTERFACE_ID_PPB_URL_REQUEST_INFO, instance, &result)); + if (result.is_null()) + return 0; + + linked_ptr<URLRequestInfo> object(new URLRequestInfo(result)); + return PluginResourceTracker::GetInstance()->AddResource(object); +} + bool PPB_URLRequestInfo_Proxy::OnMessageReceived(const IPC::Message& msg) { bool handled = true; IPC_BEGIN_MESSAGE_MAP(PPB_URLRequestInfo_Proxy, msg) @@ -173,24 +162,30 @@ bool PPB_URLRequestInfo_Proxy::OnMessageReceived(const IPC::Message& msg) { void PPB_URLRequestInfo_Proxy::OnMsgCreate( PP_Instance instance, HostResource* result) { - result->SetHostResource(instance, - ppb_url_request_info_target()->Create(instance)); + EnterFunctionNoLock<ResourceCreationAPI> enter(instance, true); + if (enter.succeeded()) { + result->SetHostResource(instance, + enter.functions()->CreateURLRequestInfo(instance)); + } } void PPB_URLRequestInfo_Proxy::OnMsgSetProperty( HostResource request, int32_t property, SerializedVarReceiveInput value) { - ppb_url_request_info_target()->SetProperty(request.host_resource(), - static_cast<PP_URLRequestProperty>(property), - value.Get(dispatcher())); + EnterHostFromHostResource<PPB_URLRequestInfo_API> enter(request); + if (enter.succeeded()) { + enter.object()->SetProperty(static_cast<PP_URLRequestProperty>(property), + value.Get(dispatcher())); + } } void PPB_URLRequestInfo_Proxy::OnMsgAppendDataToBody( HostResource request, const std::string& data) { - ppb_url_request_info_target()->AppendDataToBody(request.host_resource(), - data.c_str(), data.size()); + EnterHostFromHostResource<PPB_URLRequestInfo_API> enter(request); + if (enter.succeeded()) + enter.object()->AppendDataToBody(data.c_str(), data.size()); } void PPB_URLRequestInfo_Proxy::OnMsgAppendFileToBody( @@ -199,9 +194,12 @@ void PPB_URLRequestInfo_Proxy::OnMsgAppendFileToBody( int64_t start_offset, int64_t number_of_bytes, double expected_last_modified_time) { - ppb_url_request_info_target()->AppendFileToBody( - request.host_resource(), file_ref.host_resource(), - start_offset, number_of_bytes, expected_last_modified_time); + EnterHostFromHostResource<PPB_URLRequestInfo_API> enter(request); + if (enter.succeeded()) { + enter.object()->AppendFileToBody( + file_ref.host_resource(), start_offset, number_of_bytes, + expected_last_modified_time); + } } } // namespace proxy diff --git a/ppapi/proxy/ppb_url_request_info_proxy.h b/ppapi/proxy/ppb_url_request_info_proxy.h index aea077f..5bfb4d4 100644 --- a/ppapi/proxy/ppb_url_request_info_proxy.h +++ b/ppapi/proxy/ppb_url_request_info_proxy.h @@ -26,9 +26,7 @@ class PPB_URLRequestInfo_Proxy : public InterfaceProxy { static const Info* GetInfo(); - const PPB_URLRequestInfo* ppb_url_request_info_target() const { - return static_cast<const PPB_URLRequestInfo*>(target_interface()); - } + static PP_Resource CreateProxyResource(PP_Instance instance); // InterfaceProxy implementation. virtual bool OnMessageReceived(const IPC::Message& msg); diff --git a/ppapi/proxy/ppb_url_response_info_proxy.cc b/ppapi/proxy/ppb_url_response_info_proxy.cc index 575e016..7d6f17d 100644 --- a/ppapi/proxy/ppb_url_response_info_proxy.cc +++ b/ppapi/proxy/ppb_url_response_info_proxy.cc @@ -5,85 +5,79 @@ #include "ppapi/proxy/ppb_url_response_info_proxy.h" #include "ppapi/c/ppb_url_response_info.h" +#include "ppapi/proxy/enter_proxy.h" #include "ppapi/proxy/host_dispatcher.h" #include "ppapi/proxy/plugin_dispatcher.h" #include "ppapi/proxy/plugin_resource.h" #include "ppapi/proxy/ppapi_messages.h" #include "ppapi/proxy/ppb_file_ref_proxy.h" #include "ppapi/proxy/serialized_var.h" +#include "ppapi/thunk/ppb_url_response_info_api.h" +#include "ppapi/thunk/thunk.h" + +using ppapi::thunk::PPB_URLResponseInfo_API; namespace pp { namespace proxy { -class URLResponseInfo : public PluginResource { +namespace { + +InterfaceProxy* CreateURLResponseInfoProxy(Dispatcher* dispatcher, + const void* target_interface) { + return new PPB_URLResponseInfo_Proxy(dispatcher, target_interface); +} + +} // namespace + +// URLResponseInfo ------------------------------------------------------------- + +class URLResponseInfo : public PluginResource, + public PPB_URLResponseInfo_API { public: - URLResponseInfo(const HostResource& resource) - : PluginResource(resource) { - } - virtual ~URLResponseInfo() {} + URLResponseInfo(const HostResource& resource); + virtual ~URLResponseInfo(); + + // ResourceObjectBase override. + virtual PPB_URLResponseInfo_API* AsPPB_URLResponseInfo_API() OVERRIDE; - // Resource overrides. - virtual URLResponseInfo* AsURLResponseInfo() { return this; } + // PPB_URLResponseInfo_API implementation. + virtual PP_Var GetProperty(PP_URLResponseProperty property) OVERRIDE; + virtual PP_Resource GetBodyAsFileRef() OVERRIDE; private: DISALLOW_COPY_AND_ASSIGN(URLResponseInfo); }; -namespace { +URLResponseInfo::URLResponseInfo(const HostResource& resource) + : PluginResource(resource) { +} -PP_Bool IsURLResponseInfo(PP_Resource resource) { - URLResponseInfo* object = PluginResource::GetAs<URLResponseInfo>(resource); - return BoolToPPBool(!!object); +URLResponseInfo::~URLResponseInfo() { } -PP_Var GetProperty(PP_Resource response, PP_URLResponseProperty property) { - URLResponseInfo* object = PluginResource::GetAs<URLResponseInfo>(response); - if (!object) - return PP_MakeUndefined(); - PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance( - object->instance()); - if (!dispatcher) - return PP_MakeUndefined(); +PPB_URLResponseInfo_API* URLResponseInfo::AsPPB_URLResponseInfo_API() { + return this; +} +PP_Var URLResponseInfo::GetProperty(PP_URLResponseProperty property) { ReceiveSerializedVarReturnValue result; - dispatcher->Send(new PpapiHostMsg_PPBURLResponseInfo_GetProperty( - INTERFACE_ID_PPB_URL_RESPONSE_INFO, object->host_resource(), property, - &result)); - return result.Return(dispatcher); + GetDispatcher()->Send(new PpapiHostMsg_PPBURLResponseInfo_GetProperty( + INTERFACE_ID_PPB_URL_RESPONSE_INFO, host_resource(), property, &result)); + return result.Return(GetDispatcher()); } -PP_Resource GetBodyAsFileRef(PP_Resource response) { - URLResponseInfo* object = PluginResource::GetAs<URLResponseInfo>(response); - if (!object) - return 0; - PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance( - object->instance()); - if (!dispatcher) - return 0; - +PP_Resource URLResponseInfo::GetBodyAsFileRef() { // This could be more efficient by having the host automatically send us the // file ref when the request is streaming to a file and it's in the state // where the file is ready. This will prevent us from having to do this sync // IPC here. PPBFileRef_CreateInfo create_info; - dispatcher->Send(new PpapiHostMsg_PPBURLResponseInfo_GetBodyAsFileRef( - INTERFACE_ID_PPB_URL_RESPONSE_INFO, - object->host_resource(), &create_info)); + GetDispatcher()->Send(new PpapiHostMsg_PPBURLResponseInfo_GetBodyAsFileRef( + INTERFACE_ID_PPB_URL_RESPONSE_INFO, host_resource(), &create_info)); return PPB_FileRef_Proxy::DeserializeFileRef(create_info); } -const PPB_URLResponseInfo urlresponseinfo_interface = { - &IsURLResponseInfo, - &GetProperty, - &GetBodyAsFileRef -}; - -InterfaceProxy* CreateURLResponseInfoProxy(Dispatcher* dispatcher, - const void* target_interface) { - return new PPB_URLResponseInfo_Proxy(dispatcher, target_interface); -} - -} // namespace +// PPB_URLResponseInfo_Proxy --------------------------------------------------- PPB_URLResponseInfo_Proxy::PPB_URLResponseInfo_Proxy( Dispatcher* dispatcher, @@ -97,7 +91,7 @@ PPB_URLResponseInfo_Proxy::~PPB_URLResponseInfo_Proxy() { // static const InterfaceProxy::Info* PPB_URLResponseInfo_Proxy::GetInfo() { static const Info info = { - &urlresponseinfo_interface, + ppapi::thunk::GetPPB_URLResponseInfo_Thunk(), PPB_URLRESPONSEINFO_INTERFACE, INTERFACE_ID_PPB_URL_RESPONSE_INFO, false, @@ -127,18 +121,25 @@ bool PPB_URLResponseInfo_Proxy::OnMessageReceived(const IPC::Message& msg) { } void PPB_URLResponseInfo_Proxy::OnMsgGetProperty( - HostResource response, + const HostResource& response, int32_t property, SerializedVarReturnValue result) { - result.Return(dispatcher(), ppb_url_response_info_target()->GetProperty( - response.host_resource(), static_cast<PP_URLResponseProperty>(property))); + EnterHostFromHostResource<PPB_URLResponseInfo_API> enter(response); + PP_Var result_var = PP_MakeUndefined(); + if (enter.succeeded()) { + result_var = enter.object()->GetProperty( + static_cast<PP_URLResponseProperty>(property)); + } + result.Return(dispatcher(), result_var); } void PPB_URLResponseInfo_Proxy::OnMsgGetBodyAsFileRef( - HostResource response, + const HostResource& response, PPBFileRef_CreateInfo* result) { - PP_Resource file_ref = ppb_url_response_info_target()->GetBodyAsFileRef( - response.host_resource()); + EnterHostFromHostResource<PPB_URLResponseInfo_API> enter(response); + PP_Resource file_ref = 0; + if (enter.succeeded()) + file_ref = enter.object()->GetBodyAsFileRef(); // Use the FileRef proxy to serialize. DCHECK(!dispatcher()->IsPlugin()); diff --git a/ppapi/proxy/ppb_url_response_info_proxy.h b/ppapi/proxy/ppb_url_response_info_proxy.h index e22e9a8..ed6fb43 100644 --- a/ppapi/proxy/ppb_url_response_info_proxy.h +++ b/ppapi/proxy/ppb_url_response_info_proxy.h @@ -35,19 +35,15 @@ class PPB_URLResponseInfo_Proxy : public InterfaceProxy { // new resource. static PP_Resource CreateResponseForResource(const HostResource& resource); - const PPB_URLResponseInfo* ppb_url_response_info_target() const { - return static_cast<const PPB_URLResponseInfo*>(target_interface()); - } - // InterfaceProxy implementation. virtual bool OnMessageReceived(const IPC::Message& msg); private: // Message handlers. - void OnMsgGetProperty(HostResource response, + void OnMsgGetProperty(const HostResource& response, int32_t property, SerializedVarReturnValue result); - void OnMsgGetBodyAsFileRef(HostResource response, + void OnMsgGetBodyAsFileRef(const HostResource& response, PPBFileRef_CreateInfo* result); DISALLOW_COPY_AND_ASSIGN(PPB_URLResponseInfo_Proxy); diff --git a/ppapi/proxy/resource_creation_proxy.cc b/ppapi/proxy/resource_creation_proxy.cc index 012c800..31385c0 100644 --- a/ppapi/proxy/resource_creation_proxy.cc +++ b/ppapi/proxy/resource_creation_proxy.cc @@ -24,6 +24,8 @@ #include "ppapi/proxy/ppb_font_proxy.h" #include "ppapi/proxy/ppb_graphics_2d_proxy.h" #include "ppapi/proxy/ppb_image_data_proxy.h" +#include "ppapi/proxy/ppb_url_loader_proxy.h" +#include "ppapi/proxy/ppb_url_request_info_proxy.h" #include "ppapi/shared_impl/font_impl.h" #include "ppapi/shared_impl/function_group_base.h" #include "ppapi/thunk/enter.h" @@ -41,8 +43,7 @@ ResourceCreationProxy::ResourceCreationProxy(Dispatcher* dispatcher) ResourceCreationProxy::~ResourceCreationProxy() { } -::ppapi::thunk::ResourceCreationAPI* -ResourceCreationProxy::AsResourceCreationAPI() { +ResourceCreationAPI* ResourceCreationProxy::AsResourceCreationAPI() { return this; } @@ -169,13 +170,11 @@ PP_Resource ResourceCreationProxy::CreateSurface3D( } PP_Resource ResourceCreationProxy::CreateURLLoader(PP_Instance instance) { - NOTREACHED(); - return 0; + return PPB_URLLoader_Proxy::CreateProxyResource(instance); } PP_Resource ResourceCreationProxy::CreateURLRequestInfo(PP_Instance instance) { - NOTREACHED(); - return 0; + return PPB_URLRequestInfo_Proxy::CreateProxyResource(instance); } bool ResourceCreationProxy::Send(IPC::Message* msg) { diff --git a/ppapi/thunk/thunk.h b/ppapi/thunk/thunk.h index 8662729..840b27e 100644 --- a/ppapi/thunk/thunk.h +++ b/ppapi/thunk/thunk.h @@ -29,6 +29,10 @@ struct PPB_ImageData; struct PPB_Instance; struct PPB_Instance_Private; struct PPB_ImageDataTrusted; +struct PPB_URLLoader; +struct PPB_URLLoaderTrusted; +struct PPB_URLRequestInfo; +struct PPB_URLResponseInfo; #ifdef PPAPI_INSTANCE_REMOVE_SCRIPTING struct PPB_Instance_0_4; @@ -66,6 +70,10 @@ const PPB_Instance_0_4* GetPPB_Instance_0_4_Thunk(); const PPB_Instance_0_5* GetPPB_Instance_0_5_Thunk(); const PPB_Instance_Private* GetPPB_Instance_Private_Thunk(); const PPB_ImageDataTrusted* GetPPB_ImageDataTrusted_Thunk(); +const PPB_URLLoader* GetPPB_URLLoader_Thunk(); +const PPB_URLLoaderTrusted* GetPPB_URLLoaderTrusted_Thunk(); +const PPB_URLRequestInfo* GetPPB_URLRequestInfo_Thunk(); +const PPB_URLResponseInfo* GetPPB_URLResponseInfo_Thunk(); } // namespace thunk } // namespace ppapi |