diff options
Diffstat (limited to 'ppapi')
-rw-r--r-- | ppapi/c/ppb_core.h | 22 | ||||
-rw-r--r-- | ppapi/cpp/core.h | 18 | ||||
-rw-r--r-- | ppapi/cpp/dev/scriptable_object_deprecated.cc | 10 | ||||
-rw-r--r-- | ppapi/cpp/private/var_private.cc | 5 | ||||
-rw-r--r-- | ppapi/cpp/var.cc | 7 | ||||
-rw-r--r-- | ppapi/example/example.cc | 8 | ||||
-rw-r--r-- | ppapi/proxy/ppb_char_set_proxy.cc | 12 | ||||
-rw-r--r-- | ppapi/proxy/ppb_core_proxy.cc | 2 | ||||
-rw-r--r-- | ppapi/shared_impl/char_set_impl.cc | 16 | ||||
-rw-r--r-- | ppapi/shared_impl/char_set_impl.h | 6 | ||||
-rw-r--r-- | ppapi/tests/test_char_set.cc | 17 |
11 files changed, 50 insertions, 73 deletions
diff --git a/ppapi/c/ppb_core.h b/ppapi/c/ppb_core.h index 50da6db..964d442 100644 --- a/ppapi/c/ppb_core.h +++ b/ppapi/c/ppb_core.h @@ -12,8 +12,8 @@ struct PP_CompletionCallback; -#define PPB_CORE_INTERFACE_0_5 "PPB_Core;0.5" -#define PPB_CORE_INTERFACE PPB_CORE_INTERFACE_0_5 +#define PPB_CORE_INTERFACE_1_0 "PPB_Core;1.0" +#define PPB_CORE_INTERFACE PPB_CORE_INTERFACE_1_0 /** * @file @@ -49,24 +49,6 @@ struct PPB_Core { void (*ReleaseResource)(PP_Resource resource); /** - * MemAlloc() allocates memory. - * - * @param[in] num_bytes A number of bytes to allocate. - * - * @return A pointer to the memory if successful, <code>NULL</code> If the - * allocation fails. - */ - void* (*MemAlloc)(uint32_t num_bytes); - - /** - * <code>MemFree()</code> deallocates memory. - * - * @param[in] ptr A pointer to the memory to deallocate. It is safe to - * pass <code>NULL</code> to this function. - */ - void (*MemFree)(void* ptr); - - /** * GetTime() returns the "wall clock time" according to the * browser. * diff --git a/ppapi/cpp/core.h b/ppapi/cpp/core.h index 45a90c3..0b0f3ee 100644 --- a/ppapi/cpp/core.h +++ b/ppapi/cpp/core.h @@ -40,24 +40,6 @@ class Core { interface_->ReleaseResource(resource); } - /// MemAlloc() allocates memory. - /// - /// @param[in] num_bytes A number of bytes to allocate. - /// - /// @return A pointer to the memory if successful, <code>NULL</code> If the - /// allocation fails. - void* MemAlloc(uint32_t num_bytes) { - return interface_->MemAlloc(num_bytes); - } - - /// MemFree() deallocates memory. - /// - /// @param[in] ptr A pointer to the memory to deallocate. It is safe to - /// pass <code>NULL</code> to this function. - void MemFree(void* ptr) { - interface_->MemFree(ptr); - } - /// GetTime() returns the "wall clock time" according to the /// browser. /// diff --git a/ppapi/cpp/dev/scriptable_object_deprecated.cc b/ppapi/cpp/dev/scriptable_object_deprecated.cc index 59f44d1..449e760 100644 --- a/ppapi/cpp/dev/scriptable_object_deprecated.cc +++ b/ppapi/cpp/dev/scriptable_object_deprecated.cc @@ -1,9 +1,9 @@ -// 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. #include "ppapi/cpp/dev/scriptable_object_deprecated.h" - +#include "ppapi/c/dev/ppb_memory_dev.h" #include "ppapi/c/dev/ppp_class_deprecated.h" #include "ppapi/cpp/module.h" #include "ppapi/cpp/var.h" @@ -70,8 +70,12 @@ void GetAllPropertyNames(void* object, if (props.empty()) return; *property_count = static_cast<uint32_t>(props.size()); + + const PPB_Memory_Dev* memory_if = static_cast<const PPB_Memory_Dev*>( + pp::Module::Get()->GetBrowserInterface(PPB_MEMORY_DEV_INTERFACE)); *properties = static_cast<PP_Var*>( - Module::Get()->core()->MemAlloc(sizeof(PP_Var) * props.size())); + memory_if->MemAlloc(sizeof(PP_Var) * props.size())); + for (size_t i = 0; i < props.size(); ++i) (*properties)[i] = props[i].Detach(); } diff --git a/ppapi/cpp/private/var_private.cc b/ppapi/cpp/private/var_private.cc index 5db0aa3..8b3228b 100644 --- a/ppapi/cpp/private/var_private.cc +++ b/ppapi/cpp/private/var_private.cc @@ -4,6 +4,7 @@ #include "ppapi/cpp/private/var_private.h" +#include "ppapi/c/dev/ppb_memory_dev.h" #include "ppapi/c/dev/ppb_var_deprecated.h" #include "ppapi/cpp/private/instance_private.h" #include "ppapi/cpp/logging.h" @@ -83,7 +84,9 @@ void VarPrivate::GetAllPropertyNames(std::vector<Var>* properties, Var temp(PassRef(), props[i]); (*properties)[i] = temp; } - Module::Get()->core()->MemFree(props); + const PPB_Memory_Dev* memory_if = static_cast<const PPB_Memory_Dev*>( + pp::Module::Get()->GetBrowserInterface(PPB_MEMORY_DEV_INTERFACE)); + memory_if->MemFree(props); } void VarPrivate::SetProperty(const Var& name, const Var& value, diff --git a/ppapi/cpp/var.cc b/ppapi/cpp/var.cc index b655e98..bedd257 100644 --- a/ppapi/cpp/var.cc +++ b/ppapi/cpp/var.cc @@ -9,10 +9,11 @@ #include <algorithm> -#include "ppapi/c/pp_var.h" +#include "ppapi/c/dev/ppb_memory_dev.h" #ifndef PPAPI_VAR_REMOVE_SCRIPTING # include "ppapi/c/dev/ppb_var_deprecated.h" #endif +#include "ppapi/c/pp_var.h" #include "ppapi/c/ppb_var.h" #include "ppapi/cpp/instance.h" #include "ppapi/cpp/logging.h" @@ -274,7 +275,9 @@ void Var::GetAllPropertyNames(std::vector<Var>* properties, Var temp(PassRef(), props[i]); (*properties)[i] = temp; } - Module::Get()->core()->MemFree(props); + const PPB_Memory_Dev* memory_if = static_cast<const PPB_Memory_Dev*>( + pp::Module::Get()->GetBrowserInterface(PPB_MEMORY_DEV_INTERFACE)); + memory_if->MemFree(props); } void Var::SetProperty(const Var& name, const Var& value, Var* exception) { diff --git a/ppapi/example/example.cc b/ppapi/example/example.cc index 3eaafcd..2b5ab76 100644 --- a/ppapi/example/example.cc +++ b/ppapi/example/example.cc @@ -19,6 +19,7 @@ #include "ppapi/c/pp_errors.h" #include "ppapi/c/pp_rect.h" #include "ppapi/cpp/completion_callback.h" +#include "ppapi/cpp/dev/memory_dev.h" #include "ppapi/cpp/dev/scriptable_object_deprecated.h" #include "ppapi/cpp/graphics_2d.h" #include "ppapi/cpp/image_data.h" @@ -327,12 +328,13 @@ int gettimeofday(struct timeval *tv, struct timezone*) { } // Print interfaces. + // TODO(mball,dmichael) Replace this with the PPP_PRINTING_DEV_USE_0_4 version virtual PP_PrintOutputFormat_Dev* QuerySupportedPrintOutputFormats( uint32_t* format_count) { + pp::Memory_Dev memory; PP_PrintOutputFormat_Dev* format = - reinterpret_cast<PP_PrintOutputFormat_Dev*>( - pp::Module::Get()->core()->MemAlloc( - sizeof(PP_PrintOutputFormat_Dev))); + static_cast<PP_PrintOutputFormat_Dev*>( + memory.MemAlloc(sizeof(PP_PrintOutputFormat_Dev))); *format = PP_PRINTOUTPUTFORMAT_RASTER; *format_count = 1; return format; diff --git a/ppapi/proxy/ppb_char_set_proxy.cc b/ppapi/proxy/ppb_char_set_proxy.cc index 1887549..4701ded 100644 --- a/ppapi/proxy/ppb_char_set_proxy.cc +++ b/ppapi/proxy/ppb_char_set_proxy.cc @@ -6,7 +6,7 @@ #include "base/basictypes.h" #include "ppapi/c/dev/ppb_char_set_dev.h" -#include "ppapi/c/ppb_core.h" +#include "ppapi/c/dev/ppb_memory_dev.h" #include "ppapi/proxy/plugin_dispatcher.h" #include "ppapi/proxy/ppapi_messages.h" #include "ppapi/proxy/serialized_var.h" @@ -19,9 +19,9 @@ namespace proxy { namespace { -const PPB_Core* GetCoreInterface() { - return static_cast<const PPB_Core*>( - PluginDispatcher::GetInterfaceFromDispatcher(PPB_CORE_INTERFACE)); +const PPB_Memory_Dev* GetMemoryDevInterface() { + return static_cast<const PPB_Memory_Dev*>( + PluginDispatcher::GetInterfaceFromDispatcher(PPB_MEMORY_DEV_INTERFACE)); } InterfaceProxy* CreateCharSetProxy(Dispatcher* dispatcher, @@ -63,7 +63,7 @@ char* PPB_CharSet_Proxy::UTF16ToCharSet( PP_CharSet_ConversionError on_error, uint32_t* output_length) { return ppapi::CharSetImpl::UTF16ToCharSet( - GetCoreInterface(), utf16, utf16_len, output_char_set, on_error, + GetMemoryDevInterface(), utf16, utf16_len, output_char_set, on_error, output_length); } @@ -74,7 +74,7 @@ uint16_t* PPB_CharSet_Proxy::CharSetToUTF16( PP_CharSet_ConversionError on_error, uint32_t* output_length) { return ppapi::CharSetImpl::CharSetToUTF16( - GetCoreInterface(), input, input_len, input_char_set, on_error, + GetMemoryDevInterface(), input, input_len, input_char_set, on_error, output_length); } diff --git a/ppapi/proxy/ppb_core_proxy.cc b/ppapi/proxy/ppb_core_proxy.cc index 7dd632a..06d5974 100644 --- a/ppapi/proxy/ppb_core_proxy.cc +++ b/ppapi/proxy/ppb_core_proxy.cc @@ -80,8 +80,6 @@ PP_Bool IsMainThread() { const PPB_Core core_interface = { &AddRefResource, &ReleaseResource, - &MemAlloc, - &MemFree, &GetTime, &GetTimeTicks, &CallOnMainThread, diff --git a/ppapi/shared_impl/char_set_impl.cc b/ppapi/shared_impl/char_set_impl.cc index cad3142..06b9893 100644 --- a/ppapi/shared_impl/char_set_impl.cc +++ b/ppapi/shared_impl/char_set_impl.cc @@ -5,7 +5,7 @@ #include "ppapi/shared_impl/char_set_impl.h" #include "base/i18n/icu_string_conversions.h" -#include "ppapi/c/ppb_core.h" +#include "ppapi/c/dev/ppb_memory_dev.h" #include "unicode/ucnv.h" #include "unicode/ucnv_cb.h" #include "unicode/ucnv_err.h" @@ -42,13 +42,13 @@ bool PPToBaseConversionError(PP_CharSet_ConversionError on_error, // implementation in base, so we partially duplicate the code from // icu_string_conversions.cc with the correct error handling setup required // by the PPAPI interface. -char* CharSetImpl::UTF16ToCharSet(const PPB_Core* core, +char* CharSetImpl::UTF16ToCharSet(const PPB_Memory_Dev* memory, const uint16_t* utf16, uint32_t utf16_len, const char* output_char_set, PP_CharSet_ConversionError on_error, uint32_t* output_length) { - if (!core || !utf16 || !output_char_set || !output_length) + if (!memory || !utf16 || !output_char_set || !output_length) return NULL; *output_length = 0; @@ -101,13 +101,13 @@ char* CharSetImpl::UTF16ToCharSet(const PPB_Core* core, } // ucnv_fromUChars returns size not including terminating null. - char* encoded = static_cast<char*>(core->MemAlloc(encoded_max_length + 1)); + char* encoded = static_cast<char*>(memory->MemAlloc(encoded_max_length + 1)); int actual_size = ucnv_fromUChars(converter, encoded, encoded_max_length, reinterpret_cast<const UChar*>(utf16), utf16_len, &status); ucnv_close(converter); if (!U_SUCCESS(status)) { - core->MemFree(encoded); + memory->MemFree(encoded); return NULL; } encoded[actual_size] = 0; @@ -116,13 +116,13 @@ char* CharSetImpl::UTF16ToCharSet(const PPB_Core* core, } // static -uint16_t* CharSetImpl::CharSetToUTF16(const PPB_Core* core, +uint16_t* CharSetImpl::CharSetToUTF16(const PPB_Memory_Dev* memory, const char* input, uint32_t input_len, const char* input_char_set, PP_CharSet_ConversionError on_error, uint32_t* output_length) { - if (!core || !input || !input_char_set || !output_length) + if (!memory || !input || !input_char_set || !output_length) return NULL; *output_length = 0; @@ -139,7 +139,7 @@ uint16_t* CharSetImpl::CharSetToUTF16(const PPB_Core* core, return NULL; uint16_t* ret_buf = static_cast<uint16_t*>( - core->MemAlloc((output.size() + 1) * sizeof(uint16_t))); + memory->MemAlloc((output.size() + 1) * sizeof(uint16_t))); if (!ret_buf) return NULL; diff --git a/ppapi/shared_impl/char_set_impl.h b/ppapi/shared_impl/char_set_impl.h index 41411a4..4891346 100644 --- a/ppapi/shared_impl/char_set_impl.h +++ b/ppapi/shared_impl/char_set_impl.h @@ -8,7 +8,7 @@ #include "base/basictypes.h" #include "ppapi/c/dev/ppb_char_set_dev.h" -struct PPB_Core; +struct PPB_Memory_Dev; namespace ppapi { @@ -16,14 +16,14 @@ namespace ppapi { // between the proxy and the renderer. class CharSetImpl { public: - static char* UTF16ToCharSet(const PPB_Core* core, + static char* UTF16ToCharSet(const PPB_Memory_Dev* memory, const uint16_t* utf16, uint32_t utf16_len, const char* output_char_set, PP_CharSet_ConversionError on_error, uint32_t* output_length); - static uint16_t* CharSetToUTF16(const PPB_Core* core, + static uint16_t* CharSetToUTF16(const PPB_Memory_Dev* memory, const char* input, uint32_t input_len, const char* input_char_set, diff --git a/ppapi/tests/test_char_set.cc b/ppapi/tests/test_char_set.cc index dc417a0..5c7ae69 100644 --- a/ppapi/tests/test_char_set.cc +++ b/ppapi/tests/test_char_set.cc @@ -1,10 +1,11 @@ -// 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. #include "ppapi/tests/test_char_set.h" #include "ppapi/c/dev/ppb_char_set_dev.h" +#include "ppapi/cpp/dev/memory_dev.h" #include "ppapi/cpp/module.h" #include "ppapi/tests/testing_instance.h" @@ -32,13 +33,14 @@ std::string TestCharSet::TestUTF16ToCharSet() { std::vector<uint16_t> utf16; utf16.push_back(0); uint32_t utf8result_len = 0; + pp::Memory_Dev memory; char* utf8result = char_set_interface_->UTF16ToCharSet( instance_->pp_instance(), &utf16[0], 0, "latin1", PP_CHARSET_CONVERSIONERROR_SUBSTITUTE, &utf8result_len); ASSERT_TRUE(utf8result); ASSERT_TRUE(utf8result[0] == 0); ASSERT_TRUE(utf8result_len == 0); - pp::Module::Get()->core()->MemFree(utf8result); + memory.MemFree(utf8result); // Try round-tripping some English & Chinese from UTF-8 through UTF-16 std::string utf8source("Hello, world. \xe4\xbd\xa0\xe5\xa5\xbd"); @@ -47,7 +49,7 @@ std::string TestCharSet::TestUTF16ToCharSet() { instance_->pp_instance(), &utf16[0], static_cast<uint32_t>(utf16.size()), "Utf-8", PP_CHARSET_CONVERSIONERROR_FAIL, &utf8result_len); ASSERT_TRUE(utf8source == std::string(utf8result, utf8result_len)); - pp::Module::Get()->core()->MemFree(utf8result); + memory.MemFree(utf8result); // Test an un-encodable character with various modes. utf16 = UTF8ToUTF16("h\xe4\xbd\xa0i"); @@ -67,7 +69,7 @@ std::string TestCharSet::TestUTF16ToCharSet() { ASSERT_TRUE(utf8result_len == 2); ASSERT_TRUE(utf8result[0] == 'h' && utf8result[1] == 'i' && utf8result[2] == 0); - pp::Module::Get()->core()->MemFree(utf8result); + memory.MemFree(utf8result); // Substitute mode. utf8result = char_set_interface_->UTF16ToCharSet( @@ -76,7 +78,7 @@ std::string TestCharSet::TestUTF16ToCharSet() { ASSERT_TRUE(utf8result_len == 3); ASSERT_TRUE(utf8result[0] == 'h' && utf8result[1] == '?' && utf8result[2] == 'i' && utf8result[3] == 0); - pp::Module::Get()->core()->MemFree(utf8result); + memory.MemFree(utf8result); // Try some invalid input encoding. utf16.clear(); @@ -88,7 +90,7 @@ std::string TestCharSet::TestUTF16ToCharSet() { ASSERT_TRUE(utf8result_len == 2); ASSERT_TRUE(utf8result[0] == '?' && utf8result[1] == 'A' && utf8result[2] == 0); - pp::Module::Get()->core()->MemFree(utf8result); + memory.MemFree(utf8result); // Invalid encoding name. utf8result = char_set_interface_->UTF16ToCharSet( @@ -182,6 +184,7 @@ std::vector<uint16_t> TestCharSet::UTF8ToUTF16(const std::string& utf8) { return result_vector; result_vector.assign(result, &result[result_len]); - pp::Module::Get()->core()->MemFree(result); + pp::Memory_Dev memory; + memory.MemFree(result); return result_vector; } |