diff options
author | yzshen@chromium.org <yzshen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-07 00:51:01 +0000 |
---|---|---|
committer | yzshen@chromium.org <yzshen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-07 00:51:01 +0000 |
commit | 6117b82da99a439a5e2c02acfc320291d1c3abc2 (patch) | |
tree | c4fc666f220604f716b8e291ea8fa5c9766c0846 | |
parent | cec568d6f1e79bda1362bd5d64f494ccd79e6d08 (diff) | |
download | chromium_src-6117b82da99a439a5e2c02acfc320291d1c3abc2.zip chromium_src-6117b82da99a439a5e2c02acfc320291d1c3abc2.tar.gz chromium_src-6117b82da99a439a5e2c02acfc320291d1c3abc2.tar.bz2 |
Introduce PPB_ResourceArray_Dev.
TEST=test_resource_array.{h,cc}
BUG=None
Review URL: http://codereview.chromium.org/9111008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@116789 0039d316-1c4b-4281-b951-d872f2087c98
23 files changed, 662 insertions, 9 deletions
diff --git a/chrome/test/ui/ppapi_uitest.cc b/chrome/test/ui/ppapi_uitest.cc index bf7faa4..fcd6a4b 100644 --- a/chrome/test/ui/ppapi_uitest.cc +++ b/chrome/test/ui/ppapi_uitest.cc @@ -743,4 +743,13 @@ TEST_PPAPI_IN_PROCESS(View_ClipChange); TEST_PPAPI_OUT_OF_PROCESS(View_ClipChange); TEST_PPAPI_NACL_VIA_HTTP(View_ClipChange); +TEST_PPAPI_IN_PROCESS(ResourceArray_Basics) +TEST_PPAPI_IN_PROCESS(ResourceArray_OutOfRangeAccess) +TEST_PPAPI_IN_PROCESS(ResourceArray_EmptyArray) +TEST_PPAPI_IN_PROCESS(ResourceArray_InvalidElement) +TEST_PPAPI_OUT_OF_PROCESS(ResourceArray_Basics) +TEST_PPAPI_OUT_OF_PROCESS(ResourceArray_OutOfRangeAccess) +TEST_PPAPI_OUT_OF_PROCESS(ResourceArray_EmptyArray) +TEST_PPAPI_OUT_OF_PROCESS(ResourceArray_InvalidElement) + #endif // ADDRESS_SANITIZER diff --git a/ppapi/api/dev/ppb_resource_array_dev.idl b/ppapi/api/dev/ppb_resource_array_dev.idl new file mode 100755 index 0000000..fb8d257 --- /dev/null +++ b/ppapi/api/dev/ppb_resource_array_dev.idl @@ -0,0 +1,65 @@ +/* Copyright (c) 2012 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. + */ + +/** + * This file defines the <code>PPB_ResourceArray_Dev</code> interface. + */ +label Chrome { + M18 = 0.1 +}; + +/** + * A resource array holds a list of resources and retains a reference to each of + * them. + */ +interface PPB_ResourceArray_Dev { + /** + * Creates a resource array. + * Note: It will add a reference to each of the elements. + * + * @param[in] elements <code>PP_Resource</code>s to be stored in the created + * resource array. + * @param[in] size The number of elements. + * + * @return A <code>PP_Resource</code> corresponding to a resource array if + * successful; 0 if failed. + */ + PP_Resource Create([in] PP_Instance instance, + [in, size_as=size] PP_Resource[] elements, + [in] uint32_t size); + + /** + * Determines if the provided resource is a resource array. + * + * @param[in] resource A <code>PP_Resource</code> corresponding to a generic + * resource. + * + * @return A <code>PP_Bool</code> that is <code>PP_TRUE</code> if the given + * resource is a resource array, otherwise <code>PP_FALSE</code>. + */ + PP_Bool IsResourceArray([in] PP_Resource resource); + + /** + * Gets the array size. + * + * @param[in] resource_array The resource array. + * + * @return How many elements are there in the array. + */ + uint32_t GetSize([in] PP_Resource resource_array); + + /** + * Gets the element at the specified position. + * Note: It doesn't add a reference to the returned resource for the caller. + * + * @param[in] resource_array The resource array. + * @param[in] index An integer indicating a position in the array. + * + * @return A <code>PP_Resource</code>. Returns 0 if the index is out of range. + */ + PP_Resource GetAt( + [in] PP_Resource resource_array, + [in] uint32_t index); +}; diff --git a/ppapi/c/dev/ppb_resource_array_dev.h b/ppapi/c/dev/ppb_resource_array_dev.h new file mode 100644 index 0000000..03a811e --- /dev/null +++ b/ppapi/c/dev/ppb_resource_array_dev.h @@ -0,0 +1,85 @@ +/* Copyright (c) 2012 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. + */ + +/* From dev/ppb_resource_array_dev.idl modified Fri Jan 6 11:59:21 2012. */ + +#ifndef PPAPI_C_DEV_PPB_RESOURCE_ARRAY_DEV_H_ +#define PPAPI_C_DEV_PPB_RESOURCE_ARRAY_DEV_H_ + +#include "ppapi/c/pp_bool.h" +#include "ppapi/c/pp_instance.h" +#include "ppapi/c/pp_macros.h" +#include "ppapi/c/pp_resource.h" +#include "ppapi/c/pp_stdint.h" + +#define PPB_RESOURCEARRAY_DEV_INTERFACE_0_1 "PPB_ResourceArray(Dev);0.1" +#define PPB_RESOURCEARRAY_DEV_INTERFACE PPB_RESOURCEARRAY_DEV_INTERFACE_0_1 + +/** + * @file + * This file defines the <code>PPB_ResourceArray_Dev</code> interface. + */ + + +/** + * @addtogroup Interfaces + * @{ + */ +/** + * A resource array holds a list of resources and retains a reference to each of + * them. + */ +struct PPB_ResourceArray_Dev_0_1 { + /** + * Creates a resource array. + * Note: It will add a reference to each of the elements. + * + * @param[in] elements <code>PP_Resource</code>s to be stored in the created + * resource array. + * @param[in] size The number of elements. + * + * @return A <code>PP_Resource</code> corresponding to a resource array if + * successful; 0 if failed. + */ + PP_Resource (*Create)(PP_Instance instance, + const PP_Resource elements[], + uint32_t size); + /** + * Determines if the provided resource is a resource array. + * + * @param[in] resource A <code>PP_Resource</code> corresponding to a generic + * resource. + * + * @return A <code>PP_Bool</code> that is <code>PP_TRUE</code> if the given + * resource is a resource array, otherwise <code>PP_FALSE</code>. + */ + PP_Bool (*IsResourceArray)(PP_Resource resource); + /** + * Gets the array size. + * + * @param[in] resource_array The resource array. + * + * @return How many elements are there in the array. + */ + uint32_t (*GetSize)(PP_Resource resource_array); + /** + * Gets the element at the specified position. + * Note: It doesn't add a reference to the returned resource for the caller. + * + * @param[in] resource_array The resource array. + * @param[in] index An integer indicating a position in the array. + * + * @return A <code>PP_Resource</code>. Returns 0 if the index is out of range. + */ + PP_Resource (*GetAt)(PP_Resource resource_array, uint32_t index); +}; + +typedef struct PPB_ResourceArray_Dev_0_1 PPB_ResourceArray_Dev; +/** + * @} + */ + +#endif /* PPAPI_C_DEV_PPB_RESOURCE_ARRAY_DEV_H_ */ + diff --git a/ppapi/cpp/dev/resource_array_dev.cc b/ppapi/cpp/dev/resource_array_dev.cc new file mode 100644 index 0000000..4193e0f --- /dev/null +++ b/ppapi/cpp/dev/resource_array_dev.cc @@ -0,0 +1,62 @@ +// Copyright (c) 2012 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/cpp/dev/resource_array_dev.h" + +#include "ppapi/c/dev/ppb_resource_array_dev.h" +#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/module_impl.h" + +namespace pp { + +namespace { + +template <> const char* interface_name<PPB_ResourceArray_Dev>() { + return PPB_RESOURCEARRAY_DEV_INTERFACE; +} + +} // namespace + +ResourceArray_Dev::ResourceArray_Dev() { +} + +ResourceArray_Dev::ResourceArray_Dev(PassRef, PP_Resource resource) { + PassRefFromConstructor(resource); +} + +ResourceArray_Dev::ResourceArray_Dev(const ResourceArray_Dev& other) + : Resource(other) { +} + +ResourceArray_Dev::ResourceArray_Dev(Instance* instance, + const PP_Resource elements[], + uint32_t size) { + if (has_interface<PPB_ResourceArray_Dev>() && instance) { + PassRefFromConstructor(get_interface<PPB_ResourceArray_Dev>()->Create( + instance->pp_instance(), elements, size)); + } +} + +ResourceArray_Dev::~ResourceArray_Dev() { +} + +ResourceArray_Dev& ResourceArray_Dev::operator=( + const ResourceArray_Dev& other) { + Resource::operator=(other); + return *this; +} + +uint32_t ResourceArray_Dev::size() const { + if (!has_interface<PPB_ResourceArray_Dev>()) + return 0; + return get_interface<PPB_ResourceArray_Dev>()->GetSize(pp_resource()); +} + +PP_Resource ResourceArray_Dev::operator[](uint32_t index) const { + if (!has_interface<PPB_ResourceArray_Dev>()) + return 0; + return get_interface<PPB_ResourceArray_Dev>()->GetAt(pp_resource(), index); +} + +} // namespace pp diff --git a/ppapi/cpp/dev/resource_array_dev.h b/ppapi/cpp/dev/resource_array_dev.h new file mode 100644 index 0000000..1d5a25f --- /dev/null +++ b/ppapi/cpp/dev/resource_array_dev.h @@ -0,0 +1,40 @@ +// Copyright (c) 2012 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_CPP_DEV_RESOURCE_ARRAY_DEV_H_ +#define PPAPI_CPP_DEV_RESOURCE_ARRAY_DEV_H_ + +#include "ppapi/c/pp_stdint.h" +#include "ppapi/cpp/resource.h" + +namespace pp { + +class Instance; + +class ResourceArray_Dev : public Resource { + public: + ResourceArray_Dev(); + + struct PassRef {}; + + ResourceArray_Dev(PassRef, PP_Resource resource); + + ResourceArray_Dev(const ResourceArray_Dev& other); + + ResourceArray_Dev(Instance* instance, + const PP_Resource elements[], + uint32_t size); + + virtual ~ResourceArray_Dev(); + + ResourceArray_Dev& operator=(const ResourceArray_Dev& other); + + uint32_t size() const; + + PP_Resource operator[](uint32_t index) const; +}; + +} // namespace pp + +#endif // PPAPI_CPP_DEV_RESOURCE_ARRAY_DEV_H_ diff --git a/ppapi/ppapi_shared.gypi b/ppapi/ppapi_shared.gypi index adc64b4..0cafb51 100644 --- a/ppapi/ppapi_shared.gypi +++ b/ppapi/ppapi_shared.gypi @@ -1,4 +1,4 @@ -# Copyright (c) 2011 The Chromium Authors. All rights reserved. +# Copyright (c) 2012 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. @@ -71,6 +71,8 @@ 'shared_impl/ppb_memory_shared.cc', 'shared_impl/ppb_opengles2_shared.cc', 'shared_impl/ppb_opengles2_shared.h', + 'shared_impl/ppb_resource_array_shared.cc', + 'shared_impl/ppb_resource_array_shared.h', 'shared_impl/ppb_url_request_info_shared.cc', 'shared_impl/ppb_url_request_info_shared.h', 'shared_impl/ppb_url_util_shared.cc', @@ -172,6 +174,8 @@ 'thunk/ppb_messaging_thunk.cc', 'thunk/ppb_mouse_lock_thunk.cc', 'thunk/ppb_pdf_api.h', + 'thunk/ppb_resource_array_api.h', + 'thunk/ppb_resource_array_thunk.cc', 'thunk/ppb_scrollbar_api.h', 'thunk/ppb_scrollbar_thunk.cc', 'thunk/ppb_tcp_socket_private_api.h', diff --git a/ppapi/ppapi_sources.gypi b/ppapi/ppapi_sources.gypi index df86cf8..f517a12 100644 --- a/ppapi/ppapi_sources.gypi +++ b/ppapi/ppapi_sources.gypi @@ -1,4 +1,4 @@ -# Copyright (c) 2011 The Chromium Authors. All rights reserved. +# Copyright (c) 2012 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. @@ -63,6 +63,7 @@ 'c/dev/ppb_fullscreen_dev.h', 'c/dev/ppb_ime_input_event_dev.h', 'c/dev/ppb_memory_dev.h', + 'c/dev/ppb_resource_array_dev.h', 'c/dev/ppb_scrollbar_dev.h', 'c/dev/ppb_testing_dev.h', 'c/dev/ppb_url_util_dev.h', @@ -191,6 +192,8 @@ 'cpp/dev/memory_dev.h', 'cpp/dev/printing_dev.cc', 'cpp/dev/printing_dev.h', + 'cpp/dev/resource_array_dev.cc', + 'cpp/dev/resource_array_dev.h', 'cpp/dev/scrollbar_dev.cc', 'cpp/dev/scrollbar_dev.h', 'cpp/dev/selection_dev.cc', @@ -361,6 +364,8 @@ 'tests/test_paint_aggregator.h', 'tests/test_post_message.cc', 'tests/test_post_message.h', + 'tests/test_resource_array.cc', + 'tests/test_resource_array.h', 'tests/test_scrollbar.cc', 'tests/test_scrollbar.h', 'tests/test_struct_sizes.c', diff --git a/ppapi/proxy/interface_list.cc b/ppapi/proxy/interface_list.cc index 746935f..b7eec94 100644 --- a/ppapi/proxy/interface_list.cc +++ b/ppapi/proxy/interface_list.cc @@ -16,6 +16,7 @@ #include "ppapi/c/dev/ppb_gles_chromium_texture_mapping_dev.h" #include "ppapi/c/dev/ppb_ime_input_event_dev.h" #include "ppapi/c/dev/ppb_memory_dev.h" +#include "ppapi/c/dev/ppb_resource_array_dev.h" #include "ppapi/c/dev/ppb_testing_dev.h" #include "ppapi/c/dev/ppb_text_input_dev.h" #include "ppapi/c/dev/ppb_url_util_dev.h" diff --git a/ppapi/proxy/resource_creation_proxy.cc b/ppapi/proxy/resource_creation_proxy.cc index e758035..02f2723 100644 --- a/ppapi/proxy/resource_creation_proxy.cc +++ b/ppapi/proxy/resource_creation_proxy.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -35,6 +35,7 @@ #include "ppapi/shared_impl/ppb_audio_config_shared.h" #include "ppapi/shared_impl/ppb_font_shared.h" #include "ppapi/shared_impl/ppb_input_event_shared.h" +#include "ppapi/shared_impl/ppb_resource_array_shared.h" #include "ppapi/shared_impl/ppb_url_request_info_shared.h" #include "ppapi/shared_impl/var.h" #include "ppapi/thunk/enter.h" @@ -246,6 +247,15 @@ PP_Resource ResourceCreationProxy::CreateGraphics3DRaw( return 0; } +PP_Resource ResourceCreationProxy::CreateResourceArray( + PP_Instance instance, + const PP_Resource elements[], + uint32_t size) { + PPB_ResourceArray_Shared* object = new PPB_ResourceArray_Shared( + PPB_ResourceArray_Shared::InitAsProxy(), instance, elements, size); + return object->GetReference(); +} + PP_Resource ResourceCreationProxy::CreateScrollbar(PP_Instance instance, PP_Bool vertical) { NOTIMPLEMENTED(); // Not proxied yet. diff --git a/ppapi/proxy/resource_creation_proxy.h b/ppapi/proxy/resource_creation_proxy.h index da269e9..6fed5e9 100644 --- a/ppapi/proxy/resource_creation_proxy.h +++ b/ppapi/proxy/resource_creation_proxy.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -100,6 +100,9 @@ class ResourceCreationProxy : public InterfaceProxy, const PP_Point* mouse_position, int32_t click_count, const PP_Point* mouse_movement) OVERRIDE; + virtual PP_Resource CreateResourceArray(PP_Instance instance, + const PP_Resource elements[], + uint32_t size) OVERRIDE; virtual PP_Resource CreateScrollbar(PP_Instance instance, PP_Bool vertical) OVERRIDE; virtual PP_Resource CreateTCPSocketPrivate(PP_Instance instance) OVERRIDE; diff --git a/ppapi/shared_impl/ppb_resource_array_shared.cc b/ppapi/shared_impl/ppb_resource_array_shared.cc new file mode 100644 index 0000000..9949fd5 --- /dev/null +++ b/ppapi/shared_impl/ppb_resource_array_shared.cc @@ -0,0 +1,64 @@ +// Copyright (c) 2012 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/shared_impl/ppb_resource_array_shared.h" + +#include "base/logging.h" +#include "ppapi/shared_impl/ppapi_globals.h" +#include "ppapi/shared_impl/resource_tracker.h" + +using ppapi::thunk::PPB_ResourceArray_API; + +namespace ppapi { + +PPB_ResourceArray_Shared::PPB_ResourceArray_Shared(const InitAsImpl&, + PP_Instance instance, + const PP_Resource elements[], + uint32_t size) + : Resource(instance) { + Initialize(elements, size); +} + +PPB_ResourceArray_Shared::PPB_ResourceArray_Shared(const InitAsProxy&, + PP_Instance instance, + const PP_Resource elements[], + uint32_t size) + : Resource(HostResource::MakeInstanceOnly(instance)) { + Initialize(elements, size); +} + +PPB_ResourceArray_Shared::~PPB_ResourceArray_Shared() { + for (std::vector<PP_Resource>::iterator iter = resources_.begin(); + iter != resources_.end(); ++iter) { + if (*iter) + PpapiGlobals::Get()->GetResourceTracker()->ReleaseResource(*iter); + } +} + +PPB_ResourceArray_API* PPB_ResourceArray_Shared::AsPPB_ResourceArray_API() { + return this; +} + +uint32_t PPB_ResourceArray_Shared::GetSize() { + return static_cast<uint32_t>(resources_.size()); +} + +PP_Resource PPB_ResourceArray_Shared::GetAt(uint32_t index) { + return index < resources_.size() ? resources_[index] : 0; +} + +void PPB_ResourceArray_Shared::Initialize(const PP_Resource elements[], + uint32_t size) { + DCHECK(resources_.empty()); + + resources_.reserve(size); + for (uint32_t index = 0; index < size; ++index) { + PP_Resource element = elements[index]; + if (element) + PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(element); + resources_.push_back(element); + } +} + +} // namespace ppapi diff --git a/ppapi/shared_impl/ppb_resource_array_shared.h b/ppapi/shared_impl/ppb_resource_array_shared.h new file mode 100644 index 0000000..55342e0 --- /dev/null +++ b/ppapi/shared_impl/ppb_resource_array_shared.h @@ -0,0 +1,54 @@ +// Copyright (c) 2012 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_SHARED_IMPL_PPB_RESOURCE_ARRAY_SHARED_H_ +#define PPAPI_SHARED_IMPL_PPB_RESOURCE_ARRAY_SHARED_H_ + +#include <vector> + +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "ppapi/shared_impl/resource.h" +#include "ppapi/thunk/ppb_resource_array_api.h" + +namespace ppapi { + +class PPAPI_SHARED_EXPORT PPB_ResourceArray_Shared + : public Resource, + public thunk::PPB_ResourceArray_API { + public: + struct InitAsImpl {}; + struct InitAsProxy {}; + + // The dummy arguments control which version of Resource's constructor is + // called for this base class. + PPB_ResourceArray_Shared(const InitAsImpl&, + PP_Instance instance, + const PP_Resource elements[], + uint32_t size); + PPB_ResourceArray_Shared(const InitAsProxy&, + PP_Instance instance, + const PP_Resource elements[], + uint32_t size); + + virtual ~PPB_ResourceArray_Shared(); + + // Resource overrides. + virtual PPB_ResourceArray_API* AsPPB_ResourceArray_API() OVERRIDE; + + // PPB_ResourceArray_API implementation. + virtual uint32_t GetSize() OVERRIDE; + virtual PP_Resource GetAt(uint32_t index) OVERRIDE; + + private: + void Initialize(const PP_Resource elements[], uint32_t size); + + std::vector<PP_Resource> resources_; + + DISALLOW_IMPLICIT_CONSTRUCTORS(PPB_ResourceArray_Shared); +}; + +} // namespace ppapi + +#endif // PPAPI_SHARED_IMPL_PPB_RESOURCE_ARRAY_SHARED_H_ diff --git a/ppapi/shared_impl/resource.h b/ppapi/shared_impl/resource.h index 11038fa..15571fa 100644 --- a/ppapi/shared_impl/resource.h +++ b/ppapi/shared_impl/resource.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -39,6 +39,7 @@ F(PPB_InputEvent_API) \ F(PPB_LayerCompositor_API) \ F(PPB_PDFFont_API) \ + F(PPB_ResourceArray_API) \ F(PPB_Scrollbar_API) \ F(PPB_TCPSocket_Private_API) \ F(PPB_Transport_API) \ diff --git a/ppapi/tests/all_c_includes.h b/ppapi/tests/all_c_includes.h index 97fa532..10b66d3 100644 --- a/ppapi/tests/all_c_includes.h +++ b/ppapi/tests/all_c_includes.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2011 The Chromium Authors. All rights reserved. +/* Copyright (c) 2012 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. * @@ -24,6 +24,7 @@ #include "ppapi/c/dev/ppb_ime_input_event_dev.h" #include "ppapi/c/dev/ppb_layer_compositor_dev.h" #include "ppapi/c/dev/ppb_memory_dev.h" +#include "ppapi/c/dev/ppb_resource_array_dev.h" #include "ppapi/c/dev/ppb_scrollbar_dev.h" #include "ppapi/c/dev/ppb_testing_dev.h" #include "ppapi/c/dev/ppb_text_input_dev.h" diff --git a/ppapi/tests/test_resource_array.cc b/ppapi/tests/test_resource_array.cc new file mode 100644 index 0000000..333505e --- /dev/null +++ b/ppapi/tests/test_resource_array.cc @@ -0,0 +1,123 @@ +// Copyright (c) 2012 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/tests/test_resource_array.h" + +#include "ppapi/cpp/dev/resource_array_dev.h" +#include "ppapi/cpp/image_data.h" +#include "ppapi/cpp/input_event.h" +#include "ppapi/tests/testing_instance.h" + +REGISTER_TEST_CASE(ResourceArray); + +namespace { + +pp::InputEvent CreateMouseEvent(pp::Instance* instance, + PP_InputEvent_Type type, + PP_InputEvent_MouseButton buttons) { + return pp::MouseInputEvent( + instance, + type, + 100, // time_stamp + 0, // modifiers + buttons, + pp::Point(), // position + 1, // click count + pp::Point()); // movement +} + +pp::ImageData CreateImageData(pp::Instance* instance) { + return pp::ImageData( + instance, + PP_IMAGEDATAFORMAT_RGBA_PREMUL, + pp::Size(1, 1), + true); +} + +} // namespace + +TestResourceArray::TestResourceArray(TestingInstance* instance) + : TestCase(instance) { +} + +TestResourceArray::~TestResourceArray() { +} + +void TestResourceArray::RunTests(const std::string& filter) { + RUN_TEST(Basics, filter); + RUN_TEST(OutOfRangeAccess, filter); + RUN_TEST(EmptyArray, filter); + RUN_TEST(InvalidElement, filter); +} + +std::string TestResourceArray::TestBasics() { + pp::InputEvent mouse_event_1 = CreateMouseEvent( + instance_, PP_INPUTEVENT_TYPE_MOUSEDOWN, PP_INPUTEVENT_MOUSEBUTTON_LEFT); + pp::InputEvent mouse_event_2 = CreateMouseEvent( + instance_, PP_INPUTEVENT_TYPE_MOUSEUP, PP_INPUTEVENT_MOUSEBUTTON_RIGHT); + pp::ImageData image_data = CreateImageData(instance_); + + PP_Resource elements[] = { + mouse_event_1.pp_resource(), + mouse_event_2.pp_resource(), + image_data.pp_resource() + }; + size_t size = sizeof(elements) / sizeof(elements[0]); + + pp::ResourceArray_Dev resource_array(instance_, elements, size); + + ASSERT_EQ(size, resource_array.size()); + for (uint32_t index = 0; index < size; ++index) + ASSERT_EQ(elements[index], resource_array[index]); + + PASS(); +} + +std::string TestResourceArray::TestOutOfRangeAccess() { + pp::InputEvent mouse_event_1 = CreateMouseEvent( + instance_, PP_INPUTEVENT_TYPE_MOUSEDOWN, PP_INPUTEVENT_MOUSEBUTTON_LEFT); + pp::InputEvent mouse_event_2 = CreateMouseEvent( + instance_, PP_INPUTEVENT_TYPE_MOUSEUP, PP_INPUTEVENT_MOUSEBUTTON_RIGHT); + pp::ImageData image_data = CreateImageData(instance_); + + PP_Resource elements[] = { + mouse_event_1.pp_resource(), + mouse_event_2.pp_resource(), + image_data.pp_resource() + }; + size_t size = sizeof(elements) / sizeof(elements[0]); + + pp::ResourceArray_Dev resource_array(instance_, elements, size); + ASSERT_EQ(0, resource_array[size]); + ASSERT_EQ(0, resource_array[size + 1]); + + PASS(); +} + +std::string TestResourceArray::TestEmptyArray() { + pp::ResourceArray_Dev resource_array(instance_, NULL, 0); + ASSERT_EQ(0, resource_array.size()); + PASS(); +} + +std::string TestResourceArray::TestInvalidElement() { + pp::InputEvent mouse_event = CreateMouseEvent( + instance_, PP_INPUTEVENT_TYPE_MOUSEDOWN, PP_INPUTEVENT_MOUSEBUTTON_LEFT); + pp::ImageData image_data = CreateImageData(instance_); + + PP_Resource elements[] = { + mouse_event.pp_resource(), + 0, + image_data.pp_resource() + }; + size_t size = sizeof(elements) / sizeof(elements[0]); + + pp::ResourceArray_Dev resource_array(instance_, elements, size); + + ASSERT_EQ(size, resource_array.size()); + for (uint32_t index = 0; index < size; ++index) + ASSERT_EQ(elements[index], resource_array[index]); + + PASS(); +} diff --git a/ppapi/tests/test_resource_array.h b/ppapi/tests/test_resource_array.h new file mode 100644 index 0000000..b5dfcc9 --- /dev/null +++ b/ppapi/tests/test_resource_array.h @@ -0,0 +1,28 @@ +// Copyright (c) 2012 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_TESTS_TEST_RESOURCE_ARRAY_H_ +#define PPAPI_TESTS_TEST_RESOURCE_ARRAY_H_ + +#include <string> + +#include "ppapi/tests/test_case.h" + +class TestResourceArray : public TestCase { + public: + explicit TestResourceArray(TestingInstance* instance); + virtual ~TestResourceArray(); + + // TestCase implementation. + virtual void RunTests(const std::string& test_filter); + + private: + std::string TestBasics(); + std::string TestOutOfRangeAccess(); + std::string TestEmptyArray(); + std::string TestInvalidElement(); +}; + +#endif // PPAPI_TESTS_TEST_RESOURCE_ARRAY_H_ + diff --git a/ppapi/thunk/interfaces_ppb_public_dev.h b/ppapi/thunk/interfaces_ppb_public_dev.h index 7161449..f72fa7c 100644 --- a/ppapi/thunk/interfaces_ppb_public_dev.h +++ b/ppapi/thunk/interfaces_ppb_public_dev.h @@ -48,6 +48,8 @@ UNPROXIED_IFACE(PPB_Instance, PPB_ZOOM_DEV_INTERFACE_0_2, PPB_Zoom_Dev_0_2) UNPROXIED_IFACE(PPB_LayerCompositor, PPB_LAYER_COMPOSITOR_DEV_INTERFACE_0_2, PPB_LayerCompositor_Dev_0_2) PROXIED_IFACE(NoAPIName, PPB_MEMORY_DEV_INTERFACE_0_1, PPB_Memory_Dev_0_1) +PROXIED_IFACE(NoAPIName, PPB_RESOURCEARRAY_DEV_INTERFACE_0_1, + PPB_ResourceArray_Dev_0_1) UNPROXIED_IFACE(PPB_Scrollbar, PPB_SCROLLBAR_DEV_INTERFACE_0_5, PPB_Scrollbar_Dev_0_5) PROXIED_IFACE(PPB_TextInput, PPB_TEXTINPUT_DEV_INTERFACE_0_1, diff --git a/ppapi/thunk/ppb_resource_array_api.h b/ppapi/thunk/ppb_resource_array_api.h new file mode 100644 index 0000000..ec37f9e --- /dev/null +++ b/ppapi/thunk/ppb_resource_array_api.h @@ -0,0 +1,25 @@ +// Copyright (c) 2012 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_THUNK_PPB_RESOURCE_ARRAY_API_H_ +#define PPAPI_THUNK_PPB_RESOURCE_ARRAY_API_H_ + +#include "ppapi/c/dev/ppb_resource_array_dev.h" +#include "ppapi/thunk/ppapi_thunk_export.h" + +namespace ppapi { +namespace thunk { + +class PPAPI_THUNK_EXPORT PPB_ResourceArray_API { + public: + virtual ~PPB_ResourceArray_API() {} + + virtual uint32_t GetSize() = 0; + virtual PP_Resource GetAt(uint32_t index) = 0; +}; + +} // namespace thunk +} // namespace ppapi + +#endif // PPAPI_THUNK_PPB_RESOURCE_ARRAY_API_H_ diff --git a/ppapi/thunk/ppb_resource_array_thunk.cc b/ppapi/thunk/ppb_resource_array_thunk.cc new file mode 100644 index 0000000..1526028 --- /dev/null +++ b/ppapi/thunk/ppb_resource_array_thunk.cc @@ -0,0 +1,53 @@ +// Copyright (c) 2012 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/thunk/enter.h" +#include "ppapi/thunk/ppb_resource_array_api.h" +#include "ppapi/thunk/resource_creation_api.h" +#include "ppapi/thunk/thunk.h" + +namespace ppapi { +namespace thunk { + +namespace { + +PP_Resource Create(PP_Instance instance, + const PP_Resource elements[], + uint32_t size) { + EnterFunction<ResourceCreationAPI> enter(instance, true); + if (enter.failed()) + return 0; + return enter.functions()->CreateResourceArray(instance, elements, size); +} + +PP_Bool IsResourceArray(PP_Resource resource) { + EnterResource<PPB_ResourceArray_API> enter(resource, false); + return enter.succeeded() ? PP_TRUE : PP_FALSE; +} + +uint32_t GetSize(PP_Resource resource_array) { + EnterResource<PPB_ResourceArray_API> enter(resource_array, true); + return enter.succeeded() ? enter.object()->GetSize() : 0; +} + +PP_Resource GetAt(PP_Resource resource_array, uint32_t index) { + EnterResource<PPB_ResourceArray_API> enter(resource_array, true); + return enter.succeeded() ? enter.object()->GetAt(index) : 0; +} + +const PPB_ResourceArray_Dev g_ppb_resource_array_thunk = { + &Create, + &IsResourceArray, + &GetSize, + &GetAt +}; + +} // namespace + +const PPB_ResourceArray_Dev_0_1* GetPPB_ResourceArray_Dev_0_1_Thunk() { + return &g_ppb_resource_array_thunk; +} + +} // namespace thunk +} // namespace ppapi diff --git a/ppapi/thunk/resource_creation_api.h b/ppapi/thunk/resource_creation_api.h index ecab7cd..90442ed 100644 --- a/ppapi/thunk/resource_creation_api.h +++ b/ppapi/thunk/resource_creation_api.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -103,6 +103,9 @@ class ResourceCreationAPI { const PP_Point* mouse_position, int32_t click_count, const PP_Point* mouse_movement) = 0; + virtual PP_Resource CreateResourceArray(PP_Instance instance, + const PP_Resource elements[], + uint32_t size) = 0; virtual PP_Resource CreateScrollbar(PP_Instance instance, PP_Bool vertical) = 0; virtual PP_Resource CreateTCPSocketPrivate(PP_Instance instace) = 0; diff --git a/webkit/plugins/ppapi/plugin_module.cc b/webkit/plugins/ppapi/plugin_module.cc index 0fe64d8..c6af869 100644 --- a/webkit/plugins/ppapi/plugin_module.cc +++ b/webkit/plugins/ppapi/plugin_module.cc @@ -27,6 +27,7 @@ #include "ppapi/c/dev/ppb_gles_chromium_texture_mapping_dev.h" #include "ppapi/c/dev/ppb_layer_compositor_dev.h" #include "ppapi/c/dev/ppb_memory_dev.h" +#include "ppapi/c/dev/ppb_resource_array_dev.h" #include "ppapi/c/dev/ppb_scrollbar_dev.h" #include "ppapi/c/dev/ppb_testing_dev.h" #include "ppapi/c/dev/ppb_text_input_dev.h" diff --git a/webkit/plugins/ppapi/resource_creation_impl.cc b/webkit/plugins/ppapi/resource_creation_impl.cc index 4b2e364..1f3943b 100644 --- a/webkit/plugins/ppapi/resource_creation_impl.cc +++ b/webkit/plugins/ppapi/resource_creation_impl.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -7,6 +7,7 @@ #include "ppapi/c/pp_size.h" #include "ppapi/shared_impl/ppb_audio_config_shared.h" #include "ppapi/shared_impl/ppb_input_event_shared.h" +#include "ppapi/shared_impl/ppb_resource_array_shared.h" #include "ppapi/shared_impl/var.h" #include "webkit/plugins/ppapi/common.h" #include "webkit/plugins/ppapi/ppb_audio_impl.h" @@ -37,6 +38,7 @@ using ppapi::InputEventData; using ppapi::PPB_InputEvent_Shared; +using ppapi::PPB_ResourceArray_Shared; using ppapi::StringVar; namespace webkit { @@ -234,6 +236,15 @@ PP_Resource ResourceCreationImpl::CreateScrollbar(PP_Instance instance, return PPB_Scrollbar_Impl::Create(instance, PP_ToBool(vertical)); } +PP_Resource ResourceCreationImpl::CreateResourceArray( + PP_Instance instance, + const PP_Resource elements[], + uint32_t size) { + PPB_ResourceArray_Shared* object = new PPB_ResourceArray_Shared( + PPB_ResourceArray_Shared::InitAsImpl(), instance, elements, size); + return object->GetReference(); +} + PP_Resource ResourceCreationImpl::CreateTCPSocketPrivate(PP_Instance instance) { return PPB_TCPSocket_Private_Impl::CreateResource(instance); } diff --git a/webkit/plugins/ppapi/resource_creation_impl.h b/webkit/plugins/ppapi/resource_creation_impl.h index ae19755..d70f21c 100644 --- a/webkit/plugins/ppapi/resource_creation_impl.h +++ b/webkit/plugins/ppapi/resource_creation_impl.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -87,6 +87,9 @@ class ResourceCreationImpl : public ::ppapi::FunctionGroupBase, const PP_Point* mouse_position, int32_t click_count, const PP_Point* mouse_movement) OVERRIDE; + virtual PP_Resource CreateResourceArray(PP_Instance instance, + const PP_Resource elements[], + uint32_t size) OVERRIDE; virtual PP_Resource CreateScrollbar(PP_Instance instance, PP_Bool vertical) OVERRIDE; virtual PP_Resource CreateTCPSocketPrivate(PP_Instance instance) OVERRIDE; |