diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-05 22:52:48 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-05 22:52:48 +0000 |
commit | 1054c07eebc637b448f0126bbffdf36075124b9e (patch) | |
tree | 1a0d5c7230dd7888e0ac998fffe2baf545250885 /ppapi | |
parent | 6f472b61b02e472c67b35181030a8ea36408e482 (diff) | |
download | chromium_src-1054c07eebc637b448f0126bbffdf36075124b9e.zip chromium_src-1054c07eebc637b448f0126bbffdf36075124b9e.tar.gz chromium_src-1054c07eebc637b448f0126bbffdf36075124b9e.tar.bz2 |
Add proxies for URLResponseInfo, URLRequestInfo, and Testing. The URLLoader
tests now pass, except for the one that uses FileRef which isn't implemented
yet.
BUG=none
TEST=URLLoader pepper test
Review URL: http://codereview.chromium.org/4605001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@65268 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi')
-rw-r--r-- | ppapi/proxy/ppb_testing_proxy.cc | 105 | ||||
-rw-r--r-- | ppapi/proxy/ppb_testing_proxy.h | 49 | ||||
-rw-r--r-- | ppapi/proxy/ppb_url_request_info_proxy.cc | 160 | ||||
-rw-r--r-- | ppapi/proxy/ppb_url_request_info_proxy.h | 55 | ||||
-rw-r--r-- | ppapi/proxy/ppb_url_response_info_proxy.cc | 112 | ||||
-rw-r--r-- | ppapi/proxy/ppb_url_response_info_proxy.h | 53 |
6 files changed, 534 insertions, 0 deletions
diff --git a/ppapi/proxy/ppb_testing_proxy.cc b/ppapi/proxy/ppb_testing_proxy.cc new file mode 100644 index 0000000..3eefada --- /dev/null +++ b/ppapi/proxy/ppb_testing_proxy.cc @@ -0,0 +1,105 @@ +// Copyright (c) 2010 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. + +#include "ppapi/proxy/ppb_testing_proxy.h" + +#include "base/message_loop.h" +#include "ppapi/c/dev/ppb_testing_dev.h" +#include "ppapi/proxy/plugin_dispatcher.h" +#include "ppapi/proxy/ppapi_messages.h" + +namespace pp { +namespace proxy { + +namespace { + +bool ReadImageData(PP_Resource device_context_2d, + PP_Resource image, + const PP_Point* top_left) { + bool result = false; + PluginDispatcher::Get()->Send(new PpapiHostMsg_PPBTesting_ReadImageData( + INTERFACE_ID_PPB_TESTING, device_context_2d, image, *top_left, &result)); + return result; +} + +void RunMessageLoop() { + bool old_state = MessageLoop::current()->NestableTasksAllowed(); + MessageLoop::current()->SetNestableTasksAllowed(true); + MessageLoop::current()->Run(); + MessageLoop::current()->SetNestableTasksAllowed(old_state); +} + +void QuitMessageLoop() { + MessageLoop::current()->QuitNow(); +} + +uint32_t GetLiveObjectCount(PP_Module module_id) { + uint32_t result = 0; + PluginDispatcher::Get()->Send(new PpapiHostMsg_PPBTesting_GetLiveObjectCount( + INTERFACE_ID_PPB_TESTING, module_id, &result)); + return result; +} + +const PPB_Testing_Dev testing_interface = { + &ReadImageData, + &RunMessageLoop, + &QuitMessageLoop, + &GetLiveObjectCount +}; + +} // namespace + +PPB_Testing_Proxy::PPB_Testing_Proxy(Dispatcher* dispatcher, + const void* target_interface) + : InterfaceProxy(dispatcher, target_interface) { +} + +PPB_Testing_Proxy::~PPB_Testing_Proxy() { +} + +const void* PPB_Testing_Proxy::GetSourceInterface() const { + return &testing_interface; +} + +InterfaceID PPB_Testing_Proxy::GetInterfaceId() const { + return INTERFACE_ID_PPB_TESTING; +} + +void PPB_Testing_Proxy::OnMessageReceived(const IPC::Message& msg) { + IPC_BEGIN_MESSAGE_MAP(PPB_Testing_Proxy, msg) + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTesting_ReadImageData, + OnMsgReadImageData) + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTesting_RunMessageLoop, + OnMsgRunMessageLoop) + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTesting_QuitMessageLoop, + OnMsgQuitMessageLoop) + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTesting_GetLiveObjectCount, + OnMsgGetLiveObjectCount) + IPC_END_MESSAGE_MAP() +} + +void PPB_Testing_Proxy::OnMsgReadImageData(PP_Resource device_context_2d, + PP_Resource image, + const PP_Point& top_left, + bool* result) { + *result = ppb_testing_target()->ReadImageData( + device_context_2d, image, &top_left); +} + +void PPB_Testing_Proxy::OnMsgRunMessageLoop(bool* dummy) { + ppb_testing_target()->RunMessageLoop(); + *dummy = false; +} + +void PPB_Testing_Proxy::OnMsgQuitMessageLoop() { + ppb_testing_target()->QuitMessageLoop(); +} + +void PPB_Testing_Proxy::OnMsgGetLiveObjectCount(PP_Module module_id, + uint32_t* result) { + *result = ppb_testing_target()->GetLiveObjectCount(module_id); +} + +} // namespace proxy +} // namespace pp diff --git a/ppapi/proxy/ppb_testing_proxy.h b/ppapi/proxy/ppb_testing_proxy.h new file mode 100644 index 0000000..3f4013e --- /dev/null +++ b/ppapi/proxy/ppb_testing_proxy.h @@ -0,0 +1,49 @@ +// Copyright (c) 2010 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. + +#ifndef PPAPI_PROXY_PPB_TESTING_PROXY_H_ +#define PPAPI_PROXY_PPB_TESTING_PROXY_H_ + +#include "base/basictypes.h" +#include "ppapi/c/pp_module.h" +#include "ppapi/c/pp_resource.h" +#include "ppapi/proxy/interface_proxy.h" + +struct PP_Point; +struct PPB_Testing_Dev; + +namespace pp { +namespace proxy { + +class PPB_Testing_Proxy : public InterfaceProxy { + public: + PPB_Testing_Proxy(Dispatcher* dispatcher, const void* target_interface); + virtual ~PPB_Testing_Proxy(); + + const PPB_Testing_Dev* ppb_testing_target() const { + return static_cast<const PPB_Testing_Dev*>(target_interface()); + } + + // InterfaceProxy implementation. + virtual const void* GetSourceInterface() const; + virtual InterfaceID GetInterfaceId() const; + virtual void OnMessageReceived(const IPC::Message& msg); + + private: + // Message handlers. + void OnMsgReadImageData(PP_Resource device_context_2d, + PP_Resource image, + const PP_Point& top_left, + bool* result); + void OnMsgRunMessageLoop(bool* dummy); + void OnMsgQuitMessageLoop(); + void OnMsgGetLiveObjectCount(PP_Module module_id, uint32_t* result); + + DISALLOW_COPY_AND_ASSIGN(PPB_Testing_Proxy); +}; + +} // namespace proxy +} // namespace pp + +#endif // PPAPI_PROXY_PPB_TESTING_PROXY_H_ diff --git a/ppapi/proxy/ppb_url_request_info_proxy.cc b/ppapi/proxy/ppb_url_request_info_proxy.cc new file mode 100644 index 0000000..51ab4bb --- /dev/null +++ b/ppapi/proxy/ppb_url_request_info_proxy.cc @@ -0,0 +1,160 @@ +// Copyright (c) 2010 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. + +#include "ppapi/proxy/ppb_url_request_info_proxy.h" + +#include "ppapi/c/dev/ppb_url_request_info_dev.h" +#include "ppapi/proxy/plugin_dispatcher.h" +#include "ppapi/proxy/plugin_resource.h" +#include "ppapi/proxy/ppapi_messages.h" + +namespace pp { +namespace proxy { + +class URLRequestInfo : public PluginResource { + public: + URLRequestInfo() {} + virtual ~URLRequestInfo() {} + + // Resource overrides. + virtual URLRequestInfo* AsURLRequestInfo() { return this; } + + private: + DISALLOW_COPY_AND_ASSIGN(URLRequestInfo); +}; + +namespace { + +PP_Resource Create(PP_Module module_id) { + PP_Resource result; + PluginDispatcher::Get()->Send(new PpapiHostMsg_PPBURLRequestInfo_Create( + INTERFACE_ID_PPB_URL_REQUEST_INFO, module_id, &result)); + if (result) { + linked_ptr<URLRequestInfo> object(new URLRequestInfo); + PluginDispatcher::Get()->plugin_resource_tracker()->AddResource( + result, object); + } + return result; +} + +bool IsURLRequestInfo(PP_Resource resource) { + URLRequestInfo* object = PluginResource::GetAs<URLRequestInfo>(resource); + return !!object; +} + +bool SetProperty(PP_Resource request_id, + PP_URLRequestProperty_Dev property, + PP_Var var) { + Dispatcher* dispatcher = PluginDispatcher::Get(); + dispatcher->Send(new PpapiHostMsg_PPBURLRequestInfo_SetProperty( + INTERFACE_ID_PPB_URL_REQUEST_INFO, request_id, + static_cast<int32_t>(property), + SerializedVarSendInput(dispatcher, 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 true; +} + +bool AppendDataToBody(PP_Resource request_id, const char* data, uint32_t len) { + PluginDispatcher::Get()->Send( + new PpapiHostMsg_PPBURLRequestInfo_AppendDataToBody( + INTERFACE_ID_PPB_URL_REQUEST_INFO, request_id, + std::string(data, len))); + + // TODO(brettw) do some validation. We should be able to tell on the plugin + // side whether the request will succeed or fail in the renderer. + return true; +} + +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::Get()->Send( + new PpapiHostMsg_PPBURLRequestInfo_AppendFileToBody( + INTERFACE_ID_PPB_URL_REQUEST_INFO, request_id, file_ref_id, + start_offset, number_of_bytes, expected_last_modified_time)); + + // TODO(brettw) do some validation. We should be able to tell on the plugin + // side whether the request will succeed or fail in the renderer. + return true; +} + +const PPB_URLRequestInfo_Dev ppb_urlrequestinfo = { + &Create, + &IsURLRequestInfo, + &SetProperty, + &AppendDataToBody, + &AppendFileToBody +}; + +} // namespace + +PPB_URLRequestInfo_Proxy::PPB_URLRequestInfo_Proxy( + Dispatcher* dispatcher, + const void* target_interface) + : InterfaceProxy(dispatcher, target_interface) { +} + +PPB_URLRequestInfo_Proxy::~PPB_URLRequestInfo_Proxy() { +} + +const void* PPB_URLRequestInfo_Proxy::GetSourceInterface() const { + return &ppb_urlrequestinfo; +} + +InterfaceID PPB_URLRequestInfo_Proxy::GetInterfaceId() const { + return INTERFACE_ID_PPB_URL_REQUEST_INFO; +} + +void PPB_URLRequestInfo_Proxy::OnMessageReceived(const IPC::Message& msg) { + IPC_BEGIN_MESSAGE_MAP(PPB_URLRequestInfo_Proxy, msg) + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLRequestInfo_Create, OnMsgCreate) + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLRequestInfo_SetProperty, + OnMsgSetProperty) + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLRequestInfo_AppendDataToBody, + OnMsgAppendDataToBody) + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLRequestInfo_AppendFileToBody, + OnMsgAppendFileToBody) + IPC_END_MESSAGE_MAP() + // TODO(brettw): handle bad messages. +} + +void PPB_URLRequestInfo_Proxy::OnMsgCreate( + PP_Module module, + PP_Resource* result) { + *result = ppb_url_request_info_target()->Create(module); +} + +void PPB_URLRequestInfo_Proxy::OnMsgSetProperty( + PP_Resource request, + int32_t property, + SerializedVarReceiveInput value) { + ppb_url_request_info_target()->SetProperty(request, + static_cast<PP_URLRequestProperty_Dev>(property), + value.Get(dispatcher())); +} + +void PPB_URLRequestInfo_Proxy::OnMsgAppendDataToBody( + PP_Resource request, + const std::string& data) { + ppb_url_request_info_target()->AppendDataToBody(request, data.c_str(), + data.size()); +} + +void PPB_URLRequestInfo_Proxy::OnMsgAppendFileToBody( + PP_Resource request, + PP_Resource file_ref, + int64_t start_offset, + int64_t number_of_bytes, + double expected_last_modified_time) { + ppb_url_request_info_target()->AppendFileToBody( + request, file_ref, start_offset, number_of_bytes, + expected_last_modified_time); +} + +} // namespace proxy +} // namespace pp diff --git a/ppapi/proxy/ppb_url_request_info_proxy.h b/ppapi/proxy/ppb_url_request_info_proxy.h new file mode 100644 index 0000000..c0f98e9 --- /dev/null +++ b/ppapi/proxy/ppb_url_request_info_proxy.h @@ -0,0 +1,55 @@ +// Copyright (c) 2010 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. + +#ifndef PPAPI_PROXY_PPB_URL_REQUEST_INFO_PROXY_H_ +#define PPAPI_PROXY_PPB_URL_REQUEST_INFO_PROXY_H_ + +#include "base/basictypes.h" +#include "ppapi/c/pp_module.h" +#include "ppapi/c/pp_resource.h" +#include "ppapi/proxy/interface_proxy.h" + +struct PPB_URLRequestInfo_Dev; + +namespace pp { +namespace proxy { + +class SerializedVarReceiveInput; + +class PPB_URLRequestInfo_Proxy : public InterfaceProxy { + public: + PPB_URLRequestInfo_Proxy(Dispatcher* dispatcher, + const void* target_interface); + virtual ~PPB_URLRequestInfo_Proxy(); + + const PPB_URLRequestInfo_Dev* ppb_url_request_info_target() const { + return static_cast<const PPB_URLRequestInfo_Dev*>(target_interface()); + } + + // InterfaceProxy implementation. + virtual const void* GetSourceInterface() const; + virtual InterfaceID GetInterfaceId() const; + virtual void OnMessageReceived(const IPC::Message& msg); + + private: + // Message handlers. + void OnMsgCreate(PP_Module module, PP_Resource* result); + void OnMsgSetProperty(PP_Resource request, + int32_t property, + SerializedVarReceiveInput value); + void OnMsgAppendDataToBody(PP_Resource request, + const std::string& request); + void OnMsgAppendFileToBody(PP_Resource request, + PP_Resource file_ref, + int64_t start_offset, + int64_t number_of_bytes, + double expected_last_modified_time); + + DISALLOW_COPY_AND_ASSIGN(PPB_URLRequestInfo_Proxy); +}; + +} // namespace proxy +} // namespace pp + +#endif // PPAPI_PROXY_PPB_URL_REQUEST_INFO_PROXY_H_ diff --git a/ppapi/proxy/ppb_url_response_info_proxy.cc b/ppapi/proxy/ppb_url_response_info_proxy.cc new file mode 100644 index 0000000..4412eeb --- /dev/null +++ b/ppapi/proxy/ppb_url_response_info_proxy.cc @@ -0,0 +1,112 @@ +// Copyright (c) 2010 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. + +#include "ppapi/proxy/ppb_url_response_info_proxy.h" + +#include "ppapi/c/dev/ppb_url_response_info_dev.h" +#include "ppapi/proxy/plugin_dispatcher.h" +#include "ppapi/proxy/plugin_resource.h" +#include "ppapi/proxy/ppapi_messages.h" +#include "ppapi/proxy/serialized_var.h" + +namespace pp { +namespace proxy { + +class URLResponseInfo : public PluginResource { + public: + URLResponseInfo() {} + virtual ~URLResponseInfo() {} + + // Resource overrides. + virtual URLResponseInfo* AsURLResponseInfo() { return this; } + + private: + DISALLOW_COPY_AND_ASSIGN(URLResponseInfo); +}; + +namespace { + +bool IsURLResponseInfo(PP_Resource resource) { + URLResponseInfo* object = PluginResource::GetAs<URLResponseInfo>(resource); + return !!object; +} + +PP_Var GetProperty(PP_Resource response, PP_URLResponseProperty_Dev property) { + Dispatcher* dispatcher = PluginDispatcher::Get(); + ReceiveSerializedVarReturnValue result; + dispatcher->Send(new PpapiHostMsg_PPBURLResponseInfo_GetProperty( + INTERFACE_ID_PPB_URL_RESPONSE_INFO, response, property, &result)); + return result.Return(dispatcher); +} + +PP_Resource GetBody(PP_Resource response) { + PP_Resource result = 0; + /* + Dispatcher* dispatcher = PluginDispatcher::Get(); + dispatcher->Send(new PpapiHostMsg_PPBURLResponseInfo_GetBody( + INTERFACE_ID_PPB_URL_RESPONSE_INFO, response, &result)); + // TODO(brettw) when we have FileRef proxied, make an object from that + // ref so we can track it properly and then uncomment this. + */ + return result; +} + +const PPB_URLResponseInfo_Dev ppb_urlresponseinfo = { + &IsURLResponseInfo, + &GetProperty, + &GetBody +}; + +} // namespace + +PPB_URLResponseInfo_Proxy::PPB_URLResponseInfo_Proxy( + Dispatcher* dispatcher, + const void* target_interface) + : InterfaceProxy(dispatcher, target_interface) { +} + +PPB_URLResponseInfo_Proxy::~PPB_URLResponseInfo_Proxy() { +} + +// static +void PPB_URLResponseInfo_Proxy::TrackPluginResource( + PP_Resource response_resource) { + linked_ptr<URLResponseInfo> object(new URLResponseInfo); + PluginDispatcher::Get()->plugin_resource_tracker()->AddResource( + response_resource, object); +} + +const void* PPB_URLResponseInfo_Proxy::GetSourceInterface() const { + return &ppb_urlresponseinfo; +} + +InterfaceID PPB_URLResponseInfo_Proxy::GetInterfaceId() const { + return INTERFACE_ID_PPB_URL_RESPONSE_INFO; +} + +void PPB_URLResponseInfo_Proxy::OnMessageReceived(const IPC::Message& msg) { + IPC_BEGIN_MESSAGE_MAP(PPB_URLResponseInfo_Proxy, msg) + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLResponseInfo_GetProperty, + OnMsgGetProperty) + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLResponseInfo_GetBody, + OnMsgGetBody) + IPC_END_MESSAGE_MAP() + // TODO(brettw): handle bad messages. +} + +void PPB_URLResponseInfo_Proxy::OnMsgGetProperty( + PP_Resource response, + int32_t property, + SerializedVarReturnValue result) { + result.Return(dispatcher(), ppb_url_response_info_target()->GetProperty( + response, static_cast<PP_URLResponseProperty_Dev>(property))); +} + +void PPB_URLResponseInfo_Proxy::OnMsgGetBody(PP_Resource response, + PP_Resource* file_ref_result) { + *file_ref_result = ppb_url_response_info_target()->GetBody(response); +} + +} // namespace proxy +} // namespace pp diff --git a/ppapi/proxy/ppb_url_response_info_proxy.h b/ppapi/proxy/ppb_url_response_info_proxy.h new file mode 100644 index 0000000..639ddbe --- /dev/null +++ b/ppapi/proxy/ppb_url_response_info_proxy.h @@ -0,0 +1,53 @@ +// Copyright (c) 2010 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. + +#ifndef PPAPI_PROXY_PPB_URL_RESPONSE_INFO_PROXY_H_ +#define PPAPI_PROXY_PPB_URL_RESPONSE_INFO_PROXY_H_ + +#include "base/basictypes.h" +#include "ppapi/c/pp_module.h" +#include "ppapi/c/pp_resource.h" +#include "ppapi/proxy/interface_proxy.h" + +struct PPB_URLResponseInfo_Dev; + +namespace pp { +namespace proxy { + +class SerializedVarReturnValue; + +class PPB_URLResponseInfo_Proxy : public InterfaceProxy { + public: + PPB_URLResponseInfo_Proxy(Dispatcher* dispatcher, + const void* target_interface); + virtual ~PPB_URLResponseInfo_Proxy(); + + // URLResponseInfo objects are actually returned by the URLLoader class. + // This function allows the URLLoader proxy to start the tracking of + // a response info object in the plugin. + static void TrackPluginResource(PP_Resource response_resource); + + const PPB_URLResponseInfo_Dev* ppb_url_response_info_target() const { + return static_cast<const PPB_URLResponseInfo_Dev*>(target_interface()); + } + + // InterfaceProxy implementation. + virtual const void* GetSourceInterface() const; + virtual InterfaceID GetInterfaceId() const; + virtual void OnMessageReceived(const IPC::Message& msg); + + private: + // Message handlers. + void OnMsgGetProperty(PP_Resource response, + int32_t property, + SerializedVarReturnValue result); + void OnMsgGetBody(PP_Resource response, PP_Resource* file_ref_result); + + DISALLOW_COPY_AND_ASSIGN(PPB_URLResponseInfo_Proxy); +}; + +} // namespace proxy +} // namespace pp + +#endif // PPAPI_PROXY_PPB_URL_RESPONSE_INFO_PROXY_H_ |