diff options
20 files changed, 692 insertions, 990 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 diff --git a/webkit/plugins/ppapi/plugin_module.cc b/webkit/plugins/ppapi/plugin_module.cc index 5204a90..06e97a8 100644 --- a/webkit/plugins/ppapi/plugin_module.cc +++ b/webkit/plugins/ppapi/plugin_module.cc @@ -90,9 +90,6 @@ #include "webkit/plugins/ppapi/ppb_scrollbar_impl.h" #include "webkit/plugins/ppapi/ppb_transport_impl.h" #include "webkit/plugins/ppapi/ppb_uma_private_impl.h" -#include "webkit/plugins/ppapi/ppb_url_loader_impl.h" -#include "webkit/plugins/ppapi/ppb_url_request_info_impl.h" -#include "webkit/plugins/ppapi/ppb_url_response_info_impl.h" #include "webkit/plugins/ppapi/ppb_url_util_impl.h" #include "webkit/plugins/ppapi/ppb_video_decoder_impl.h" #include "webkit/plugins/ppapi/ppb_video_layer_impl.h" @@ -314,13 +311,13 @@ const void* GetInterface(const char* name) { if (strcmp(name, PPB_UMA_PRIVATE_INTERFACE) == 0) return PPB_UMA_Private_Impl::GetInterface(); if (strcmp(name, PPB_URLLOADER_INTERFACE) == 0) - return PPB_URLLoader_Impl::GetInterface(); + return ::ppapi::thunk::GetPPB_URLLoader_Thunk(); if (strcmp(name, PPB_URLLOADERTRUSTED_INTERFACE) == 0) - return PPB_URLLoader_Impl::GetTrustedInterface(); + return ::ppapi::thunk::GetPPB_URLLoaderTrusted_Thunk(); if (strcmp(name, PPB_URLREQUESTINFO_INTERFACE) == 0) - return PPB_URLRequestInfo_Impl::GetInterface(); + return ::ppapi::thunk::GetPPB_URLRequestInfo_Thunk(); if (strcmp(name, PPB_URLRESPONSEINFO_INTERFACE) == 0) - return PPB_URLResponseInfo_Impl::GetInterface(); + return ::ppapi::thunk::GetPPB_URLResponseInfo_Thunk(); if (strcmp(name, PPB_URLUTIL_DEV_INTERFACE) == 0) return PPB_URLUtil_Impl::GetInterface(); if (strcmp(name, PPB_VAR_DEPRECATED_INTERFACE) == 0) diff --git a/webkit/plugins/ppapi/ppb_url_loader_impl.cc b/webkit/plugins/ppapi/ppb_url_loader_impl.cc index 193b461..3b57d12 100644 --- a/webkit/plugins/ppapi/ppb_url_loader_impl.cc +++ b/webkit/plugins/ppapi/ppb_url_loader_impl.cc @@ -10,6 +10,7 @@ #include "ppapi/c/pp_errors.h" #include "ppapi/c/ppb_url_loader.h" #include "ppapi/c/trusted/ppb_url_loader_trusted.h" +#include "ppapi/thunk/enter.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" @@ -30,6 +31,9 @@ #include "webkit/plugins/ppapi/ppb_url_response_info_impl.h" using appcache::WebApplicationCacheHostImpl; +using ppapi::thunk::EnterResourceNoLock; +using ppapi::thunk::PPB_URLLoader_API; +using ppapi::thunk::PPB_URLRequestInfo_API; using WebKit::WebFrame; using WebKit::WebString; using WebKit::WebURL; @@ -47,157 +51,6 @@ using WebKit::WebURLResponse; namespace webkit { namespace ppapi { -namespace { - -PP_Resource Create(PP_Instance instance_id) { - PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); - if (!instance) - return 0; - - PPB_URLLoader_Impl* loader = new PPB_URLLoader_Impl(instance, false); - return loader->GetReference(); -} - -PP_Bool IsURLLoader(PP_Resource resource) { - return BoolToPPBool(!!Resource::GetAs<PPB_URLLoader_Impl>(resource)); -} - -int32_t Open(PP_Resource loader_id, - PP_Resource request_id, - PP_CompletionCallback callback) { - scoped_refptr<PPB_URLLoader_Impl> loader( - Resource::GetAs<PPB_URLLoader_Impl>(loader_id)); - if (!loader) - return PP_ERROR_BADRESOURCE; - - scoped_refptr<PPB_URLRequestInfo_Impl> request( - Resource::GetAs<PPB_URLRequestInfo_Impl>(request_id)); - if (!request) - return PP_ERROR_BADRESOURCE; - - return loader->Open(request, callback); -} - -int32_t FollowRedirect(PP_Resource loader_id, - PP_CompletionCallback callback) { - scoped_refptr<PPB_URLLoader_Impl> loader( - Resource::GetAs<PPB_URLLoader_Impl>(loader_id)); - if (!loader) - return PP_ERROR_BADRESOURCE; - - return loader->FollowRedirect(callback); -} - -PP_Bool GetUploadProgress(PP_Resource loader_id, - int64_t* bytes_sent, - int64_t* total_bytes_to_be_sent) { - scoped_refptr<PPB_URLLoader_Impl> loader( - Resource::GetAs<PPB_URLLoader_Impl>(loader_id)); - if (!loader) - return PP_FALSE; - - return BoolToPPBool(loader->GetUploadProgress(bytes_sent, - total_bytes_to_be_sent)); -} - -PP_Bool GetDownloadProgress(PP_Resource loader_id, - int64_t* bytes_received, - int64_t* total_bytes_to_be_received) { - scoped_refptr<PPB_URLLoader_Impl> loader( - Resource::GetAs<PPB_URLLoader_Impl>(loader_id)); - if (!loader) - return PP_FALSE; - - return BoolToPPBool(loader->GetDownloadProgress(bytes_received, - total_bytes_to_be_received)); -} - -PP_Resource GetResponseInfo(PP_Resource loader_id) { - scoped_refptr<PPB_URLLoader_Impl> loader( - Resource::GetAs<PPB_URLLoader_Impl>(loader_id)); - if (!loader) - return 0; - - PPB_URLResponseInfo_Impl* response_info = loader->response_info(); - if (!response_info) - return 0; - - return response_info->GetReference(); -} - -int32_t ReadResponseBody(PP_Resource loader_id, - void* buffer, - int32_t bytes_to_read, - PP_CompletionCallback callback) { - scoped_refptr<PPB_URLLoader_Impl> loader( - Resource::GetAs<PPB_URLLoader_Impl>(loader_id)); - if (!loader) - return PP_ERROR_BADRESOURCE; - - return loader->ReadResponseBody(buffer, bytes_to_read, callback); -} - -int32_t FinishStreamingToFile(PP_Resource loader_id, - PP_CompletionCallback callback) { - scoped_refptr<PPB_URLLoader_Impl> loader( - Resource::GetAs<PPB_URLLoader_Impl>(loader_id)); - if (!loader) - return PP_ERROR_BADRESOURCE; - - return loader->FinishStreamingToFile(callback); -} - -void Close(PP_Resource loader_id) { - scoped_refptr<PPB_URLLoader_Impl> loader( - Resource::GetAs<PPB_URLLoader_Impl>(loader_id)); - if (!loader) - return; - - loader->Close(); -} - -const PPB_URLLoader ppb_urlloader = { - &Create, - &IsURLLoader, - &Open, - &FollowRedirect, - &GetUploadProgress, - &GetDownloadProgress, - &GetResponseInfo, - &ReadResponseBody, - &FinishStreamingToFile, - &Close -}; - -void GrantUniversalAccess(PP_Resource loader_id) { - scoped_refptr<PPB_URLLoader_Impl> loader( - Resource::GetAs<PPB_URLLoader_Impl>(loader_id)); - if (!loader) - return; - - loader->GrantUniversalAccess(); -} - -void SetStatusCallback(PP_Resource loader_id, - PP_URLLoaderTrusted_StatusCallback cb) { - scoped_refptr<PPB_URLLoader_Impl> loader( - Resource::GetAs<PPB_URLLoader_Impl>(loader_id)); - if (!loader) - return; - loader->SetStatusCallback(cb); -} - -const PPB_URLLoaderTrusted ppb_urlloadertrusted = { - &GrantUniversalAccess, - &SetStatusCallback -}; - -WebFrame* GetFrame(PluginInstance* instance) { - return instance->container()->element().document().frame(); -} - -} // namespace - PPB_URLLoader_Impl::PPB_URLLoader_Impl(PluginInstance* instance, bool main_document_loader) : Resource(instance), @@ -220,16 +73,16 @@ PPB_URLLoader_Impl::~PPB_URLLoader_Impl() { } // static -const PPB_URLLoader* PPB_URLLoader_Impl::GetInterface() { - return &ppb_urlloader; -} +PP_Resource PPB_URLLoader_Impl::Create(PP_Instance pp_instance) { + PluginInstance* instance = ResourceTracker::Get()->GetInstance(pp_instance); + if (!instance) + return 0; -// static -const PPB_URLLoaderTrusted* PPB_URLLoader_Impl::GetTrustedInterface() { - return &ppb_urlloadertrusted; + PPB_URLLoader_Impl* loader = new PPB_URLLoader_Impl(instance, false); + return loader->GetReference(); } -PPB_URLLoader_Impl* PPB_URLLoader_Impl::AsPPB_URLLoader_Impl() { +PPB_URLLoader_API* PPB_URLLoader_Impl::AsPPB_URLLoader_API() { return this; } @@ -242,8 +95,14 @@ void PPB_URLLoader_Impl::LastPluginRefWasDeleted(bool instance_destroyed) { } } -int32_t PPB_URLLoader_Impl::Open(PPB_URLRequestInfo_Impl* request, +int32_t PPB_URLLoader_Impl::Open(PP_Resource request_id, PP_CompletionCallback callback) { + EnterResourceNoLock<PPB_URLRequestInfo_API> enter_request(request_id, true); + if (enter_request.failed()) + return PP_ERROR_BADARGUMENT; + PPB_URLRequestInfo_Impl* request = static_cast<PPB_URLRequestInfo_Impl*>( + enter_request.object()); + int32_t rv = ValidateCallback(callback); if (rv != PP_OK) return rv; @@ -254,7 +113,7 @@ int32_t PPB_URLLoader_Impl::Open(PPB_URLRequestInfo_Impl* request, if (loader_.get()) return PP_ERROR_INPROGRESS; - WebFrame* frame = GetFrame(instance()); + WebFrame* frame = instance()->container()->element().document().frame(); if (!frame) return PP_ERROR_FAILED; WebURLRequest web_request(request->ToWebURLRequest(frame)); @@ -303,29 +162,35 @@ int32_t PPB_URLLoader_Impl::FollowRedirect(PP_CompletionCallback callback) { return PP_OK_COMPLETIONPENDING; } -bool PPB_URLLoader_Impl::GetUploadProgress(int64_t* bytes_sent, - int64_t* total_bytes_to_be_sent) { +PP_Bool PPB_URLLoader_Impl::GetUploadProgress(int64_t* bytes_sent, + int64_t* total_bytes_to_be_sent) { if (!RecordUploadProgress()) { *bytes_sent = 0; *total_bytes_to_be_sent = 0; - return false; + return PP_FALSE; } *bytes_sent = bytes_sent_; *total_bytes_to_be_sent = total_bytes_to_be_sent_; - return true; + return PP_TRUE; } -bool PPB_URLLoader_Impl::GetDownloadProgress( +PP_Bool PPB_URLLoader_Impl::GetDownloadProgress( int64_t* bytes_received, int64_t* total_bytes_to_be_received) { if (!RecordDownloadProgress()) { *bytes_received = 0; *total_bytes_to_be_received = 0; - return false; + return PP_FALSE; } *bytes_received = bytes_received_; *total_bytes_to_be_received = total_bytes_to_be_received_; - return true; + return PP_TRUE; +} + +PP_Resource PPB_URLLoader_Impl::GetResponseInfo() { + if (!response_info_) + return 0; + return response_info_->GetReference(); } int32_t PPB_URLLoader_Impl::ReadResponseBody(void* buffer, diff --git a/webkit/plugins/ppapi/ppb_url_loader_impl.h b/webkit/plugins/ppapi/ppb_url_loader_impl.h index 878ce65..f931406 100644 --- a/webkit/plugins/ppapi/ppb_url_loader_impl.h +++ b/webkit/plugins/ppapi/ppb_url_loader_impl.h @@ -11,14 +11,12 @@ #include "base/memory/scoped_ptr.h" #include "ppapi/c/pp_completion_callback.h" #include "ppapi/c/trusted/ppb_url_loader_trusted.h" +#include "ppapi/thunk/ppb_url_loader_api.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLLoaderClient.h" #include "webkit/plugins/ppapi/callbacks.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" #include "webkit/plugins/ppapi/resource.h" -struct PPB_URLLoader; -struct PPB_URLLoaderTrusted; - namespace WebKit { class WebFrame; class WebURL; @@ -31,39 +29,40 @@ class PluginInstance; class PPB_URLRequestInfo_Impl; class PPB_URLResponseInfo_Impl; -class PPB_URLLoader_Impl : public Resource, public WebKit::WebURLLoaderClient { +class PPB_URLLoader_Impl : public Resource, + public ::ppapi::thunk::PPB_URLLoader_API, + public WebKit::WebURLLoaderClient { public: PPB_URLLoader_Impl(PluginInstance* instance, bool main_document_loader); virtual ~PPB_URLLoader_Impl(); - // Returns a pointer to the interface implementing PPB_URLLoader that is - // exposed to the plugin. - static const PPB_URLLoader* GetInterface(); + static PP_Resource Create(PP_Instance instance); - // Returns a pointer to the interface implementing PPB_URLLoaderTrusted that - // is exposed to the plugin. - static const PPB_URLLoaderTrusted* GetTrustedInterface(); + // ResourceObjectBase overrides. + virtual ::ppapi::thunk::PPB_URLLoader_API* AsPPB_URLLoader_API() OVERRIDE; // Resource overrides. - virtual PPB_URLLoader_Impl* AsPPB_URLLoader_Impl(); - virtual void LastPluginRefWasDeleted(bool instance_destroyed); - - // PPB_URLLoader implementation. - int32_t Open(PPB_URLRequestInfo_Impl* request, - PP_CompletionCallback callback); - int32_t FollowRedirect(PP_CompletionCallback callback); - bool GetUploadProgress(int64_t* bytes_sent, - int64_t* total_bytes_to_be_sent); - bool GetDownloadProgress(int64_t* bytes_received, - int64_t* total_bytes_to_be_received); - int32_t ReadResponseBody(void* buffer, int32_t bytes_to_read, - PP_CompletionCallback callback); - int32_t FinishStreamingToFile(PP_CompletionCallback callback); - void Close(); - - // PPB_URLLoaderTrusted implementation. - void GrantUniversalAccess(); - void SetStatusCallback(PP_URLLoaderTrusted_StatusCallback cb); + virtual void LastPluginRefWasDeleted(bool instance_destroyed) 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; // WebKit::WebURLLoaderClient implementation. virtual void willSendRequest(WebKit::WebURLLoader* loader, diff --git a/webkit/plugins/ppapi/ppb_url_request_info_impl.cc b/webkit/plugins/ppapi/ppb_url_request_info_impl.cc index 185ab2a..64c3f59 100644 --- a/webkit/plugins/ppapi/ppb_url_request_info_impl.cc +++ b/webkit/plugins/ppapi/ppb_url_request_info_impl.cc @@ -10,6 +10,8 @@ #include "googleurl/src/url_util.h" #include "net/http/http_util.h" #include "ppapi/c/pp_var.h" +#include "ppapi/thunk/enter.h" +#include "ppapi/thunk/ppb_file_ref_api.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebData.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" @@ -23,6 +25,9 @@ #include "webkit/plugins/ppapi/var.h" #include "webkit/glue/webkit_glue.h" +using ppapi::thunk::EnterResourceNoLock; +using ppapi::thunk::PPB_FileRef_API; +using ppapi::thunk::PPB_URLRequestInfo_API; using WebKit::WebData; using WebKit::WebHTTPBody; using WebKit::WebString; @@ -85,96 +90,6 @@ bool AreValidHeaders(const std::string& headers) { return true; } -PP_Resource Create(PP_Instance instance_id) { - PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); - if (!instance) - return 0; - - PPB_URLRequestInfo_Impl* request = new PPB_URLRequestInfo_Impl(instance); - - return request->GetReference(); -} - -PP_Bool IsURLRequestInfo(PP_Resource resource) { - return BoolToPPBool(!!Resource::GetAs<PPB_URLRequestInfo_Impl>(resource)); -} - -PP_Bool SetProperty(PP_Resource request_id, - PP_URLRequestProperty property, - PP_Var var) { - scoped_refptr<PPB_URLRequestInfo_Impl> request( - Resource::GetAs<PPB_URLRequestInfo_Impl>(request_id)); - if (!request) - return PP_FALSE; - - PP_Bool result = PP_FALSE; - switch (var.type) { - case PP_VARTYPE_UNDEFINED: - result = BoolToPPBool(request->SetUndefinedProperty(property)); - break; - case PP_VARTYPE_BOOL: - result = BoolToPPBool( - request->SetBooleanProperty(property, - PPBoolToBool(var.value.as_bool))); - break; - case PP_VARTYPE_INT32: - result = BoolToPPBool( - request->SetIntegerProperty(property, var.value.as_int)); - break; - case PP_VARTYPE_STRING: { - scoped_refptr<StringVar> string(StringVar::FromPPVar(var)); - if (string) - result = BoolToPPBool(request->SetStringProperty(property, - string->value())); - break; - } - default: - break; - } - return result; -} - -PP_Bool AppendDataToBody(PP_Resource request_id, - const void* data, - uint32_t len) { - scoped_refptr<PPB_URLRequestInfo_Impl> request( - Resource::GetAs<PPB_URLRequestInfo_Impl>(request_id)); - if (!request) - return PP_FALSE; - - return BoolToPPBool(request->AppendDataToBody(std::string( - static_cast<const char*>(data), len))); -} - -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) { - scoped_refptr<PPB_URLRequestInfo_Impl> request( - Resource::GetAs<PPB_URLRequestInfo_Impl>(request_id)); - if (!request) - return PP_FALSE; - - scoped_refptr<PPB_FileRef_Impl> file_ref( - Resource::GetAs<PPB_FileRef_Impl>(file_ref_id)); - if (!file_ref) - return PP_FALSE; - - return BoolToPPBool(request->AppendFileToBody(file_ref, - start_offset, - number_of_bytes, - expected_last_modified_time)); -} - -const PPB_URLRequestInfo ppb_urlrequestinfo = { - &Create, - &IsURLRequestInfo, - &SetProperty, - &AppendDataToBody, - &AppendFileToBody -}; - } // namespace struct PPB_URLRequestInfo_Impl::BodyItem { @@ -220,14 +135,139 @@ PPB_URLRequestInfo_Impl::~PPB_URLRequestInfo_Impl() { } // static -const PPB_URLRequestInfo* PPB_URLRequestInfo_Impl::GetInterface() { - return &ppb_urlrequestinfo; +PP_Resource PPB_URLRequestInfo_Impl::Create(PP_Instance pp_instance) { + PluginInstance* instance = ResourceTracker::Get()->GetInstance(pp_instance); + if (!instance) + return 0; + + PPB_URLRequestInfo_Impl* request = new PPB_URLRequestInfo_Impl(instance); + return request->GetReference(); } -PPB_URLRequestInfo_Impl* PPB_URLRequestInfo_Impl::AsPPB_URLRequestInfo_Impl() { +PPB_URLRequestInfo_API* PPB_URLRequestInfo_Impl::AsPPB_URLRequestInfo_API() { return this; } +PP_Bool PPB_URLRequestInfo_Impl::SetProperty(PP_URLRequestProperty property, + PP_Var var) { + PP_Bool result = PP_FALSE; + switch (var.type) { + case PP_VARTYPE_UNDEFINED: + result = PP_FromBool(SetUndefinedProperty(property)); + break; + case PP_VARTYPE_BOOL: + result = PP_FromBool( + SetBooleanProperty(property, PP_ToBool(var.value.as_bool))); + break; + case PP_VARTYPE_INT32: + result = PP_FromBool( + SetIntegerProperty(property, var.value.as_int)); + break; + case PP_VARTYPE_STRING: { + scoped_refptr<StringVar> string(StringVar::FromPPVar(var)); + if (string) + result = PP_FromBool(SetStringProperty(property, string->value())); + break; + } + default: + break; + } + return result; +} + +PP_Bool PPB_URLRequestInfo_Impl::AppendDataToBody(const void* data, + uint32_t len) { + if (len > 0) + body_.push_back(BodyItem(std::string(static_cast<const char*>(data), len))); + return PP_TRUE; +} + +PP_Bool PPB_URLRequestInfo_Impl::AppendFileToBody( + PP_Resource file_ref, + int64_t start_offset, + int64_t number_of_bytes, + PP_Time expected_last_modified_time) { + // Ignore a call to append nothing. + if (number_of_bytes == 0) + return PP_TRUE; + + // Check for bad values. (-1 means read until end of file.) + if (start_offset < 0 || number_of_bytes < -1) + return PP_FALSE; + + EnterResourceNoLock<PPB_FileRef_API> enter(file_ref, true); + if (enter.failed()) + return PP_FALSE; + + body_.push_back(BodyItem(static_cast<PPB_FileRef_Impl*>(enter.object()), + start_offset, + number_of_bytes, + expected_last_modified_time)); + return PP_TRUE; +} + +WebURLRequest PPB_URLRequestInfo_Impl::ToWebURLRequest(WebFrame* frame) const { + WebURLRequest web_request; + web_request.initialize(); + web_request.setURL(frame->document().completeURL(WebString::fromUTF8(url_))); + web_request.setDownloadToFile(stream_to_file_); + web_request.setReportUploadProgress(record_upload_progress()); + + if (!method_.empty()) + web_request.setHTTPMethod(WebString::fromUTF8(method_)); + + if (!headers_.empty()) { + net::HttpUtil::HeadersIterator it(headers_.begin(), headers_.end(), "\n"); + while (it.GetNext()) { + web_request.addHTTPHeaderField( + WebString::fromUTF8(it.name()), + WebString::fromUTF8(it.values())); + } + } + + if (!body_.empty()) { + WebHTTPBody http_body; + http_body.initialize(); + for (size_t i = 0; i < body_.size(); ++i) { + if (body_[i].file_ref) { + http_body.appendFileRange( + webkit_glue::FilePathToWebString( + body_[i].file_ref->GetSystemPath()), + body_[i].start_offset, + body_[i].number_of_bytes, + body_[i].expected_last_modified_time); + } else { + DCHECK(!body_[i].data.empty()); + http_body.appendData(WebData(body_[i].data)); + } + } + web_request.setHTTPBody(http_body); + } + + if (has_custom_referrer_url_) { + if (!custom_referrer_url_.empty()) + frame->setReferrerForRequest(web_request, GURL(custom_referrer_url_)); + } else if (!allow_cross_origin_requests_) { + // Use default, except for cross-origin requests, since 'referer' is not + // whitelisted and will cause the request to fail. + frame->setReferrerForRequest(web_request, WebURL()); + } + + if (has_custom_content_transfer_encoding_) { + if (!custom_content_transfer_encoding_.empty()) { + web_request.addHTTPHeaderField( + WebString::fromUTF8("Content-Transfer-Encoding"), + WebString::fromUTF8(custom_content_transfer_encoding_)); + } + } + + return web_request; +} + +bool PPB_URLRequestInfo_Impl::RequiresUniversalAccess() const { + return has_custom_referrer_url_ || has_custom_content_transfer_encoding_; +} + bool PPB_URLRequestInfo_Impl::SetUndefinedProperty( PP_URLRequestProperty property) { switch (property) { @@ -315,93 +355,5 @@ bool PPB_URLRequestInfo_Impl::SetStringProperty(PP_URLRequestProperty property, } } -bool PPB_URLRequestInfo_Impl::AppendDataToBody(const std::string& data) { - if (!data.empty()) - body_.push_back(BodyItem(data)); - return true; -} - -bool PPB_URLRequestInfo_Impl::AppendFileToBody( - PPB_FileRef_Impl* file_ref, - int64_t start_offset, - int64_t number_of_bytes, - PP_Time expected_last_modified_time) { - // Ignore a call to append nothing. - if (number_of_bytes == 0) - return true; - - // Check for bad values. (-1 means read until end of file.) - if (start_offset < 0 || number_of_bytes < -1) - return false; - - body_.push_back(BodyItem(file_ref, - start_offset, - number_of_bytes, - expected_last_modified_time)); - return true; -} - -WebURLRequest PPB_URLRequestInfo_Impl::ToWebURLRequest(WebFrame* frame) const { - WebURLRequest web_request; - web_request.initialize(); - web_request.setURL(frame->document().completeURL(WebString::fromUTF8(url_))); - web_request.setDownloadToFile(stream_to_file_); - web_request.setReportUploadProgress(record_upload_progress()); - - if (!method_.empty()) - web_request.setHTTPMethod(WebString::fromUTF8(method_)); - - if (!headers_.empty()) { - net::HttpUtil::HeadersIterator it(headers_.begin(), headers_.end(), "\n"); - while (it.GetNext()) { - web_request.addHTTPHeaderField( - WebString::fromUTF8(it.name()), - WebString::fromUTF8(it.values())); - } - } - - if (!body_.empty()) { - WebHTTPBody http_body; - http_body.initialize(); - for (size_t i = 0; i < body_.size(); ++i) { - if (body_[i].file_ref) { - http_body.appendFileRange( - webkit_glue::FilePathToWebString( - body_[i].file_ref->GetSystemPath()), - body_[i].start_offset, - body_[i].number_of_bytes, - body_[i].expected_last_modified_time); - } else { - DCHECK(!body_[i].data.empty()); - http_body.appendData(WebData(body_[i].data)); - } - } - web_request.setHTTPBody(http_body); - } - - if (has_custom_referrer_url_) { - if (!custom_referrer_url_.empty()) - frame->setReferrerForRequest(web_request, GURL(custom_referrer_url_)); - } else if (!allow_cross_origin_requests_) { - // Use default, except for cross-origin requests, since 'referer' is not - // whitelisted and will cause the request to fail. - frame->setReferrerForRequest(web_request, WebURL()); - } - - if (has_custom_content_transfer_encoding_) { - if (!custom_content_transfer_encoding_.empty()) { - web_request.addHTTPHeaderField( - WebString::fromUTF8("Content-Transfer-Encoding"), - WebString::fromUTF8(custom_content_transfer_encoding_)); - } - } - - return web_request; -} - -bool PPB_URLRequestInfo_Impl::RequiresUniversalAccess() const { - return has_custom_referrer_url_ || has_custom_content_transfer_encoding_; -} - } // namespace ppapi } // namespace webkit diff --git a/webkit/plugins/ppapi/ppb_url_request_info_impl.h b/webkit/plugins/ppapi/ppb_url_request_info_impl.h index 2cdf3e4..872e498 100644 --- a/webkit/plugins/ppapi/ppb_url_request_info_impl.h +++ b/webkit/plugins/ppapi/ppb_url_request_info_impl.h @@ -10,6 +10,7 @@ #include "base/memory/ref_counted.h" #include "ppapi/c/ppb_url_request_info.h" +#include "ppapi/thunk/ppb_url_request_info_api.h" #include "webkit/plugins/ppapi/resource.h" namespace WebKit { @@ -22,34 +23,38 @@ namespace ppapi { class PPB_FileRef_Impl; -class PPB_URLRequestInfo_Impl : public Resource { +class PPB_URLRequestInfo_Impl : public Resource, + public ::ppapi::thunk::PPB_URLRequestInfo_API { public: explicit PPB_URLRequestInfo_Impl(PluginInstance* instance); virtual ~PPB_URLRequestInfo_Impl(); - // Returns a pointer to the interface implementing PPB_URLRequestInfo that is - // exposed to the plugin. - static const PPB_URLRequestInfo* GetInterface(); + static PP_Resource Create(PP_Instance instance); - // Resource overrides. - virtual PPB_URLRequestInfo_Impl* AsPPB_URLRequestInfo_Impl(); + // ResourceObjectBase overrides. + virtual PPB_URLRequestInfo_API* AsPPB_URLRequestInfo_API() OVERRIDE; // PPB_URLRequestInfo 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; + + WebKit::WebURLRequest ToWebURLRequest(WebKit::WebFrame* frame) const; + + // Whether universal access is required to use this request. + bool RequiresUniversalAccess() const; + bool SetUndefinedProperty(PP_URLRequestProperty property); bool SetBooleanProperty(PP_URLRequestProperty property, bool value); bool SetIntegerProperty(PP_URLRequestProperty property, int32_t value); bool SetStringProperty(PP_URLRequestProperty property, const std::string& value); - bool AppendDataToBody(const std::string& data); - bool AppendFileToBody(PPB_FileRef_Impl* file_ref, - int64_t start_offset, - int64_t number_of_bytes, - PP_Time expected_last_modified_time); - - WebKit::WebURLRequest ToWebURLRequest(WebKit::WebFrame* frame) const; - // Whether universal access is required to use this request. - bool RequiresUniversalAccess() const; bool follow_redirects() { return follow_redirects_; } diff --git a/webkit/plugins/ppapi/ppb_url_response_info_impl.cc b/webkit/plugins/ppapi/ppb_url_response_info_impl.cc index b097fd2..4160e6b 100644 --- a/webkit/plugins/ppapi/ppb_url_response_info_impl.cc +++ b/webkit/plugins/ppapi/ppb_url_response_info_impl.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -16,6 +16,7 @@ #include "webkit/plugins/ppapi/var.h" #include "webkit/glue/webkit_glue.h" +using ppapi::thunk::PPB_URLResponseInfo_API; using WebKit::WebHTTPHeaderVisitor; using WebKit::WebString; using WebKit::WebURLResponse; @@ -41,40 +42,6 @@ class HeaderFlattener : public WebHTTPHeaderVisitor { std::string buffer_; }; -PP_Bool IsURLResponseInfo(PP_Resource resource) { - return BoolToPPBool(!!Resource::GetAs<PPB_URLResponseInfo_Impl>(resource)); -} - -PP_Var GetProperty(PP_Resource response_id, - PP_URLResponseProperty property) { - scoped_refptr<PPB_URLResponseInfo_Impl> response( - Resource::GetAs<PPB_URLResponseInfo_Impl>(response_id)); - if (!response) - return PP_MakeUndefined(); - - return response->GetProperty(property); -} - -PP_Resource GetBody(PP_Resource response_id) { - scoped_refptr<PPB_URLResponseInfo_Impl> response( - Resource::GetAs<PPB_URLResponseInfo_Impl>(response_id)); - if (!response.get()) - return 0; - - PPB_FileRef_Impl* body = response->body(); - if (!body) - return 0; - body->AddRef(); // AddRef for the caller. - - return body->GetReference(); -} - -const PPB_URLResponseInfo ppb_urlresponseinfo = { - &IsURLResponseInfo, - &GetProperty, - &GetBody -}; - bool IsRedirect(int32_t status) { return status >= 300 && status <= 399; } @@ -89,13 +56,28 @@ PPB_URLResponseInfo_Impl::PPB_URLResponseInfo_Impl(PluginInstance* instance) PPB_URLResponseInfo_Impl::~PPB_URLResponseInfo_Impl() { } -// static -const PPB_URLResponseInfo* PPB_URLResponseInfo_Impl::GetInterface() { - return &ppb_urlresponseinfo; +bool PPB_URLResponseInfo_Impl::Initialize(const WebURLResponse& response) { + url_ = response.url().spec(); + status_code_ = response.httpStatusCode(); + status_text_ = response.httpStatusText().utf8(); + if (IsRedirect(status_code_)) { + redirect_url_ = response.httpHeaderField( + WebString::fromUTF8("Location")).utf8(); + } + + HeaderFlattener flattener; + response.visitHTTPHeaderFields(&flattener); + headers_ = flattener.buffer(); + + WebString file_path = response.downloadFilePath(); + if (!file_path.isEmpty()) { + body_ = new PPB_FileRef_Impl(instance(), + webkit_glue::WebStringToFilePath(file_path)); + } + return true; } -PPB_URLResponseInfo_Impl* -PPB_URLResponseInfo_Impl::AsPPB_URLResponseInfo_Impl() { +PPB_URLResponseInfo_API* PPB_URLResponseInfo_Impl::AsPPB_URLResponseInfo_API() { return this; } @@ -122,24 +104,11 @@ PP_Var PPB_URLResponseInfo_Impl::GetProperty(PP_URLResponseProperty property) { return PP_MakeUndefined(); } -bool PPB_URLResponseInfo_Impl::Initialize(const WebURLResponse& response) { - url_ = response.url().spec(); - status_code_ = response.httpStatusCode(); - status_text_ = response.httpStatusText().utf8(); - if (IsRedirect(status_code_)) { - redirect_url_ = response.httpHeaderField( - WebString::fromUTF8("Location")).utf8(); - } - - HeaderFlattener flattener; - response.visitHTTPHeaderFields(&flattener); - headers_ = flattener.buffer(); - - WebString file_path = response.downloadFilePath(); - if (!file_path.isEmpty()) - body_ = new PPB_FileRef_Impl(instance(), - webkit_glue::WebStringToFilePath(file_path)); - return true; +PP_Resource PPB_URLResponseInfo_Impl::GetBodyAsFileRef() { + if (!body_.get()) + return 0; + body_->AddRef(); // AddRef for the caller. + return body_->GetReference(); } } // namespace ppapi diff --git a/webkit/plugins/ppapi/ppb_url_response_info_impl.h b/webkit/plugins/ppapi/ppb_url_response_info_impl.h index fa916d9..10f44ea 100644 --- a/webkit/plugins/ppapi/ppb_url_response_info_impl.h +++ b/webkit/plugins/ppapi/ppb_url_response_info_impl.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -9,6 +9,7 @@ #include "base/basictypes.h" #include "ppapi/c/ppb_url_response_info.h" +#include "ppapi/thunk/ppb_url_response_info_api.h" #include "webkit/plugins/ppapi/resource.h" namespace WebKit { @@ -20,25 +21,23 @@ namespace ppapi { class PPB_FileRef_Impl; -class PPB_URLResponseInfo_Impl : public Resource { +class PPB_URLResponseInfo_Impl + : public Resource, + public ::ppapi::thunk::PPB_URLResponseInfo_API { public: explicit PPB_URLResponseInfo_Impl(PluginInstance* instance); virtual ~PPB_URLResponseInfo_Impl(); - // Returns a pointer to the interface implementing PPB_URLResponseInfo that - // is exposed to the plugin. - static const PPB_URLResponseInfo* GetInterface(); - - // Resource overrides. - virtual PPB_URLResponseInfo_Impl* AsPPB_URLResponseInfo_Impl(); + bool Initialize(const WebKit::WebURLResponse& response); - // PPB_URLResponseInfo implementation. - PP_Var GetProperty(PP_URLResponseProperty property); + // ResourceObjectBase overrides. + virtual PPB_URLResponseInfo_API* AsPPB_URLResponseInfo_API() OVERRIDE; - bool Initialize(const WebKit::WebURLResponse& response); + // PPB_URLResponseInfo_API implementation. + virtual PP_Var GetProperty(PP_URLResponseProperty property) OVERRIDE; + virtual PP_Resource GetBodyAsFileRef() OVERRIDE; PPB_FileRef_Impl* body() { return body_; } - std::string redirect_url() { return redirect_url_; } private: diff --git a/webkit/plugins/ppapi/resource_creation_impl.cc b/webkit/plugins/ppapi/resource_creation_impl.cc index 8e18864..a8caf76 100644 --- a/webkit/plugins/ppapi/resource_creation_impl.cc +++ b/webkit/plugins/ppapi/resource_creation_impl.cc @@ -20,6 +20,8 @@ #include "webkit/plugins/ppapi/ppb_font_impl.h" #include "webkit/plugins/ppapi/ppb_graphics_2d_impl.h" #include "webkit/plugins/ppapi/ppb_image_data_impl.h" +#include "webkit/plugins/ppapi/ppb_url_loader_impl.h" +#include "webkit/plugins/ppapi/ppb_url_request_info_impl.h" namespace webkit { namespace ppapi { @@ -173,13 +175,11 @@ PP_Resource ResourceCreationImpl::CreateSurface3D( } PP_Resource ResourceCreationImpl::CreateURLLoader(PP_Instance instance) { - NOTIMPLEMENTED(); - return 0; + return PPB_URLLoader_Impl::Create(instance); } PP_Resource ResourceCreationImpl::CreateURLRequestInfo(PP_Instance instance) { - NOTIMPLEMENTED(); - return 0; + return PPB_URLRequestInfo_Impl::Create(instance); } } // namespace ppapi diff --git a/webkit/plugins/ppapi/url_request_info_unittest.cc b/webkit/plugins/ppapi/url_request_info_unittest.cc index e3af414..5234ff2 100644 --- a/webkit/plugins/ppapi/url_request_info_unittest.cc +++ b/webkit/plugins/ppapi/url_request_info_unittest.cc @@ -2,11 +2,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "ppapi/thunk/thunk.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrameClient.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" - #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" #include "webkit/plugins/ppapi/ppb_url_request_info_impl.h" #include "webkit/plugins/ppapi/ppapi_unittest.h" @@ -95,7 +95,8 @@ WebView* URLRequestInfoTest::web_view_; WebFrame* URLRequestInfoTest::frame_; TEST_F(URLRequestInfoTest, GetInterface) { - const PPB_URLRequestInfo* interface = info_->GetInterface(); + const PPB_URLRequestInfo* interface = + ::ppapi::thunk::GetPPB_URLRequestInfo_Thunk(); ASSERT_TRUE(interface); ASSERT_TRUE(interface->Create); ASSERT_TRUE(interface->IsURLRequestInfo); @@ -107,7 +108,7 @@ TEST_F(URLRequestInfoTest, GetInterface) { } TEST_F(URLRequestInfoTest, AsURLRequestInfo) { - ASSERT_EQ(info_, info_->AsPPB_URLRequestInfo_Impl()); + ASSERT_EQ(info_, info_->AsPPB_URLRequestInfo_API()); } TEST_F(URLRequestInfoTest, StreamToFile) { |