diff options
45 files changed, 1220 insertions, 0 deletions
diff --git a/content/browser/renderer_host/pepper/content_browser_pepper_host_factory.cc b/content/browser/renderer_host/pepper/content_browser_pepper_host_factory.cc index 99e40a1..4f586ca 100644 --- a/content/browser/renderer_host/pepper/content_browser_pepper_host_factory.cc +++ b/content/browser/renderer_host/pepper/content_browser_pepper_host_factory.cc @@ -11,6 +11,7 @@ #include "content/browser/renderer_host/pepper/pepper_host_resolver_private_message_filter.h" #include "content/browser/renderer_host/pepper/pepper_print_settings_manager.h" #include "content/browser/renderer_host/pepper/pepper_printing_host.h" +#include "content/browser/renderer_host/pepper/pepper_truetype_font_list_host.h" #include "content/browser/renderer_host/pepper/pepper_udp_socket_private_message_filter.h" #include "ppapi/host/message_filter_host.h" #include "ppapi/host/ppapi_host.h" @@ -60,6 +61,10 @@ scoped_ptr<ResourceHost> ContentBrowserPepperHostFactory::CreateResourceHost( host_->GetPpapiHost(), instance, params.pp_resource(), manager.Pass())); } + case PpapiHostMsg_TrueTypeFontSingleton_Create::ID: { + return scoped_ptr<ResourceHost>(new PepperTrueTypeFontListHost( + host_, instance, params.pp_resource())); + } } } diff --git a/content/browser/renderer_host/pepper/pepper_truetype_font_list.h b/content/browser/renderer_host/pepper/pepper_truetype_font_list.h new file mode 100644 index 0000000..c0ce782 --- /dev/null +++ b/content/browser/renderer_host/pepper/pepper_truetype_font_list.h @@ -0,0 +1,21 @@ +// Copyright (c) 2013 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 CONTENT_BROWSER_RENDERER_HOST_PEPPER_PEPPER_TRUETYPE_FONT_LIST_H_ +#define CONTENT_BROWSER_RENDERER_HOST_PEPPER_PEPPER_TRUETYPE_FONT_LIST_H_ + +#include <string> +#include <vector> + +namespace content { + +// Adds font family names on the host platform to the vector of strings. +// +// This function is potentially slow (the system may do a bunch of I/O) so be +// sure not to call this on a time-critical thread like the UI or I/O threads. +void GetFontFamilies_SlowBlocking(std::vector<std::string>* font_families); + +} // namespace content + +#endif // CONTENT_BROWSER_RENDERER_HOST_PEPPER_PEPPER_TRUETYPE_FONT_LIST_H_ diff --git a/content/browser/renderer_host/pepper/pepper_truetype_font_list_android.cc b/content/browser/renderer_host/pepper/pepper_truetype_font_list_android.cc new file mode 100644 index 0000000..9e07fda --- /dev/null +++ b/content/browser/renderer_host/pepper/pepper_truetype_font_list_android.cc @@ -0,0 +1,13 @@ +// Copyright (c) 2013 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 "content/browser/renderer_host/pepper/pepper_truetype_font_list.h" + +namespace content { + +void GetFontFamilies_SlowBlocking(std::vector<std::string>* font_families) { + NOTIMPLEMENTED(); // Font API isn't implemented on Android. +} + +} // namespace content diff --git a/content/browser/renderer_host/pepper/pepper_truetype_font_list_host.cc b/content/browser/renderer_host/pepper/pepper_truetype_font_list_host.cc new file mode 100644 index 0000000..74e8653 --- /dev/null +++ b/content/browser/renderer_host/pepper/pepper_truetype_font_list_host.cc @@ -0,0 +1,99 @@ +// Copyright (c) 2013 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 "content/browser/renderer_host/pepper/pepper_truetype_font_list_host.h" + +#include <algorithm> + +#include "base/safe_numerics.h" +#include "base/threading/sequenced_worker_pool.h" +#include "content/browser/renderer_host/pepper/pepper_truetype_font_list.h" +#include "content/public/browser/browser_ppapi_host.h" +#include "content/public/browser/browser_thread.h" +#include "ppapi/host/dispatch_host_message.h" +#include "ppapi/host/host_message_context.h" +#include "ppapi/host/resource_message_filter.h" +#include "ppapi/proxy/ppapi_messages.h" + +namespace content { + +namespace { + +// Handles the font list request on the blocking pool. +class FontMessageFilter : public ppapi::host::ResourceMessageFilter { + public: + FontMessageFilter(); + + // ppapi::host::ResourceMessageFilter implementation. + virtual scoped_refptr<base::TaskRunner> OverrideTaskRunnerForMessage( + const IPC::Message& msg) OVERRIDE; + virtual int32_t OnResourceMessageReceived( + const IPC::Message& msg, + ppapi::host::HostMessageContext* context) OVERRIDE; + + private: + virtual ~FontMessageFilter(); + + // Message handler. + int32_t OnHostMsgGetFontFamilies(ppapi::host::HostMessageContext* context); + + DISALLOW_COPY_AND_ASSIGN(FontMessageFilter); +}; + +FontMessageFilter::FontMessageFilter() { +} + +FontMessageFilter::~FontMessageFilter() { +} + +scoped_refptr<base::TaskRunner> FontMessageFilter::OverrideTaskRunnerForMessage( + const IPC::Message& msg) { + // Use the blocking pool to get the font list (currently the only message + // so we can always just return it). + return scoped_refptr<base::TaskRunner>(BrowserThread::GetBlockingPool()); +} + +int32_t FontMessageFilter::OnResourceMessageReceived( + const IPC::Message& msg, + ppapi::host::HostMessageContext* context) { + IPC_BEGIN_MESSAGE_MAP(FontMessageFilter, msg) + PPAPI_DISPATCH_HOST_RESOURCE_CALL_0( + PpapiHostMsg_TrueTypeFontSingleton_GetFontFamilies, + OnHostMsgGetFontFamilies) + IPC_END_MESSAGE_MAP() + return PP_ERROR_FAILED; +} + +int32_t FontMessageFilter::OnHostMsgGetFontFamilies( + ppapi::host::HostMessageContext* context) { + // OK to use "slow blocking" version since we're on the blocking pool. + std::vector<std::string> font_families; + GetFontFamilies_SlowBlocking(&font_families); + // Sort the names in case the host platform returns them out of order. + std::sort(font_families.begin(), font_families.end()); + + int32_t result = base::checked_numeric_cast<int32_t>(font_families.size()); + ppapi::host::ReplyMessageContext reply_context = + context->MakeReplyMessageContext(); + reply_context.params.set_result(result); + context->reply_msg = + PpapiPluginMsg_TrueTypeFontSingleton_GetFontFamiliesReply(font_families); + return result; +} + +} // namespace + +PepperTrueTypeFontListHost::PepperTrueTypeFontListHost( + BrowserPpapiHost* host, + PP_Instance instance, + PP_Resource resource) + : ResourceHost(host->GetPpapiHost(), instance, resource) { + AddFilter(scoped_refptr<ppapi::host::ResourceMessageFilter>( + new FontMessageFilter())); +} + +PepperTrueTypeFontListHost::~PepperTrueTypeFontListHost() { +} + +} // namespace content diff --git a/content/browser/renderer_host/pepper/pepper_truetype_font_list_host.h b/content/browser/renderer_host/pepper/pepper_truetype_font_list_host.h new file mode 100644 index 0000000..c67553b --- /dev/null +++ b/content/browser/renderer_host/pepper/pepper_truetype_font_list_host.h @@ -0,0 +1,28 @@ +// Copyright (c) 2013 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 CONTENT_BROWSER_RENDERER_HOST_PEPPER_PEPPER_TRUETYPE_FONT_LIST_HOST_H_ +#define CONTENT_BROWSER_RENDERER_HOST_PEPPER_PEPPER_TRUETYPE_FONT_LIST_HOST_H_ + +#include "base/basictypes.h" +#include "ppapi/host/resource_host.h" + +namespace content { + +class BrowserPpapiHost; + +class PepperTrueTypeFontListHost : public ppapi::host::ResourceHost { + public: + PepperTrueTypeFontListHost(BrowserPpapiHost* host, + PP_Instance instance, + PP_Resource resource); + virtual ~PepperTrueTypeFontListHost(); + + private: + DISALLOW_COPY_AND_ASSIGN(PepperTrueTypeFontListHost); +}; + +} // namespace content + +#endif // CONTENT_BROWSER_RENDERER_HOST_PEPPER_PEPPER_TRUETYPE_FONT_LIST_HOST_H_ diff --git a/content/browser/renderer_host/pepper/pepper_truetype_font_list_linux.cc b/content/browser/renderer_host/pepper/pepper_truetype_font_list_linux.cc new file mode 100644 index 0000000..661266d --- /dev/null +++ b/content/browser/renderer_host/pepper/pepper_truetype_font_list_linux.cc @@ -0,0 +1,25 @@ +// Copyright (c) 2013 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 "content/browser/renderer_host/pepper/pepper_truetype_font_list.h" + +#include <pango/pango.h> +#include <pango/pangocairo.h> + +#include <string> + +namespace content { + +void GetFontFamilies_SlowBlocking(std::vector<std::string>* font_families) { + PangoFontMap* font_map = ::pango_cairo_font_map_get_default(); + PangoFontFamily** families = NULL; + int num_families = 0; + ::pango_font_map_list_families(font_map, &families, &num_families); + + for (int i = 0; i < num_families; i++) + font_families->push_back(::pango_font_family_get_name(families[i])); + g_free(families); +} + +} // namespace content diff --git a/content/browser/renderer_host/pepper/pepper_truetype_font_list_mac.mm b/content/browser/renderer_host/pepper/pepper_truetype_font_list_mac.mm new file mode 100644 index 0000000..9b79e66 --- /dev/null +++ b/content/browser/renderer_host/pepper/pepper_truetype_font_list_mac.mm @@ -0,0 +1,23 @@ +// Copyright (c) 2013 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 "content/browser/renderer_host/pepper/pepper_truetype_font_list.h" + +#import <Cocoa/Cocoa.h> + +#include "base/mac/scoped_nsautorelease_pool.h" +#include "base/sys_string_conversions.h" + +namespace content { + +void GetFontFamilies_SlowBlocking(std::vector<std::string>* font_families) { + base::mac::ScopedNSAutoreleasePool autorelease_pool; + NSFontManager* fontManager = [[[NSFontManager alloc] init] autorelease]; + NSArray* fonts = [fontManager availableFontFamilies]; + font_families->reserve([fonts count]); + for (NSString* family_name in fonts) + font_families->push_back(base::SysNSStringToUTF8(family_name)); +} + +} // namespace content diff --git a/content/browser/renderer_host/pepper/pepper_truetype_font_list_win.cc b/content/browser/renderer_host/pepper/pepper_truetype_font_list_win.cc new file mode 100644 index 0000000..6a3ee0f --- /dev/null +++ b/content/browser/renderer_host/pepper/pepper_truetype_font_list_win.cc @@ -0,0 +1,44 @@ +// Copyright (c) 2013 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 "content/browser/renderer_host/pepper/pepper_truetype_font_list.h" + +#include <windows.h> + +#include "base/utf_string_conversions.h" +#include "base/win/scoped_hdc.h" + +namespace content { + +namespace { + +static int CALLBACK EnumFontFamExProc(ENUMLOGFONTEXW* logical_font, + NEWTEXTMETRICEXW* physical_font, + DWORD font_type, + LPARAM lparam) { + std::vector<std::string>* font_families = + reinterpret_cast<std::vector<std::string>*>(lparam); + if (font_families) { + const LOGFONTW& lf = logical_font->elfLogFont; + if (lf.lfFaceName[0] && lf.lfFaceName[0] != '@' && + lf.lfOutPrecision == OUT_STROKE_PRECIS) { // Outline fonts only. + std::string face_name(UTF16ToUTF8(lf.lfFaceName)); + font_families->push_back(face_name); + } + } + return 1; +} + +} // namespace + +void GetFontFamilies_SlowBlocking(std::vector<std::string>* font_families) { + LOGFONTW logfont; + memset(&logfont, 0, sizeof(logfont)); + logfont.lfCharSet = DEFAULT_CHARSET; + base::win::ScopedCreateDC hdc(::GetDC(NULL)); + ::EnumFontFamiliesExW(hdc, &logfont, (FONTENUMPROCW)&EnumFontFamExProc, + (LPARAM)font_families, 0); +} + +} // namespace content diff --git a/content/content_browser.gypi b/content/content_browser.gypi index b82d96e..c4cc3d8 100644 --- a/content/content_browser.gypi +++ b/content/content_browser.gypi @@ -752,6 +752,13 @@ 'browser/renderer_host/pepper/pepper_tcp_server_socket.h', 'browser/renderer_host/pepper/pepper_tcp_socket.cc', 'browser/renderer_host/pepper/pepper_tcp_socket.h', + 'browser/renderer_host/pepper/pepper_truetype_font_list_android.cc', + 'browser/renderer_host/pepper/pepper_truetype_font_list_host.cc', + 'browser/renderer_host/pepper/pepper_truetype_font_list_host.h', + 'browser/renderer_host/pepper/pepper_truetype_font_list_linux.cc', + 'browser/renderer_host/pepper/pepper_truetype_font_list_mac.mm', + 'browser/renderer_host/pepper/pepper_truetype_font_list_win.cc', + 'browser/renderer_host/pepper/pepper_truetype_font_list.h', 'browser/renderer_host/pepper/pepper_udp_socket_private_message_filter.cc', 'browser/renderer_host/pepper/pepper_udp_socket_private_message_filter.h', 'browser/renderer_host/popup_menu_helper_mac.h', @@ -1124,6 +1131,7 @@ ['use_x11==1', { 'dependencies': [ '../build/linux/system.gyp:x11', + '../build/linux/system.gyp:pangocairo', ], }], ['OS=="android"', { diff --git a/content/content_renderer.gypi b/content/content_renderer.gypi index 5803e3a..67456f6 100644 --- a/content/content_renderer.gypi +++ b/content/content_renderer.gypi @@ -208,6 +208,13 @@ 'renderer/pepper/pepper_plugin_delegate_impl.h', 'renderer/pepper/pepper_proxy_channel_delegate_impl.cc', 'renderer/pepper/pepper_proxy_channel_delegate_impl.h', + 'renderer/pepper/pepper_truetype_font.h', + 'renderer/pepper/pepper_truetype_font_android.cc', + 'renderer/pepper/pepper_truetype_font_host.cc', + 'renderer/pepper/pepper_truetype_font_host.h', + 'renderer/pepper/pepper_truetype_font_linux.cc', + 'renderer/pepper/pepper_truetype_font_mac.mm', + 'renderer/pepper/pepper_truetype_font_win.cc', 'renderer/pepper/pepper_video_capture_host.cc', 'renderer/pepper/pepper_video_capture_host.h', 'renderer/pepper/pepper_websocket_host.cc', diff --git a/content/renderer/pepper/content_renderer_pepper_host_factory.cc b/content/renderer/pepper/content_renderer_pepper_host_factory.cc index bb42068..0e7f380 100644 --- a/content/renderer/pepper/content_renderer_pepper_host_factory.cc +++ b/content/renderer/pepper/content_renderer_pepper_host_factory.cc @@ -5,18 +5,22 @@ #include "content/renderer/pepper/content_renderer_pepper_host_factory.h" #include "base/logging.h" +#include "base/string_util.h" #include "content/renderer/pepper/pepper_audio_input_host.h" #include "content/renderer/pepper/pepper_directory_reader_host.h" #include "content/renderer/pepper/pepper_file_chooser_host.h" #include "content/renderer/pepper/pepper_file_io_host.h" #include "content/renderer/pepper/pepper_graphics_2d_host.h" +#include "content/renderer/pepper/pepper_truetype_font_host.h" #include "content/renderer/pepper/pepper_video_capture_host.h" #include "content/renderer/pepper/pepper_websocket_host.h" #include "content/renderer/pepper/renderer_ppapi_host_impl.h" #include "ppapi/host/resource_host.h" #include "ppapi/proxy/ppapi_messages.h" +#include "ppapi/proxy/serialized_structs.h" using ppapi::host::ResourceHost; +using ppapi::proxy::SerializedTrueTypeFontDesc; namespace content { @@ -72,6 +76,21 @@ scoped_ptr<ResourceHost> ContentRendererPepperHostFactory::CreateResourceHost( case PpapiHostMsg_FileChooser_Create::ID: return scoped_ptr<ResourceHost>(new PepperFileChooserHost( host_, instance, params.pp_resource())); + case PpapiHostMsg_TrueTypeFont_Create::ID: { + PpapiHostMsg_TrueTypeFont_Create::Schema::Param msg_params; + if (!PpapiHostMsg_TrueTypeFont_Create::Read(&message, &msg_params)) { + NOTREACHED(); + return scoped_ptr<ResourceHost>(); + } + // Check that the family name is valid UTF-8 before passing it to the + // host OS. + const SerializedTrueTypeFontDesc& desc = msg_params.a; + if (IsStringUTF8(desc.family)) { + return scoped_ptr<ResourceHost>(new PepperTrueTypeFontHost( + host_, instance, params.pp_resource(), desc)); + } + break; // Drop through and return null host. + } case PpapiHostMsg_VideoCapture_Create::ID: { PepperVideoCaptureHost* host = new PepperVideoCaptureHost( host_, instance, params.pp_resource()); diff --git a/content/renderer/pepper/pepper_in_process_resource_creation.cc b/content/renderer/pepper/pepper_in_process_resource_creation.cc index e6534c9..d9de4de 100644 --- a/content/renderer/pepper/pepper_in_process_resource_creation.cc +++ b/content/renderer/pepper/pepper_in_process_resource_creation.cc @@ -93,6 +93,13 @@ PP_Resource PepperInProcessResourceCreation::CreatePrinting( instance))->GetReference(); } +PP_Resource PepperInProcessResourceCreation::CreateTrueTypeFont( + PP_Instance instance, + const PP_TrueTypeFontDesc_Dev& desc) { + NOTIMPLEMENTED(); + return 0; +} + PP_Resource PepperInProcessResourceCreation::CreateURLRequestInfo( PP_Instance instance, const ::ppapi::URLRequestInfoData& data) { diff --git a/content/renderer/pepper/pepper_in_process_resource_creation.h b/content/renderer/pepper/pepper_in_process_resource_creation.h index 93df2af..4f0d5fa 100644 --- a/content/renderer/pepper/pepper_in_process_resource_creation.h +++ b/content/renderer/pepper/pepper_in_process_resource_creation.h @@ -56,6 +56,9 @@ class PepperInProcessResourceCreation PP_Bool is_always_opaque) OVERRIDE; virtual PP_Resource CreatePrinting( PP_Instance instance) OVERRIDE; + virtual PP_Resource CreateTrueTypeFont( + PP_Instance instance, + const struct PP_TrueTypeFontDesc_Dev& desc) OVERRIDE; virtual PP_Resource CreateURLRequestInfo( PP_Instance instance, const ::ppapi::URLRequestInfoData& data) OVERRIDE; diff --git a/content/renderer/pepper/pepper_truetype_font.h b/content/renderer/pepper/pepper_truetype_font.h new file mode 100644 index 0000000..8eb6bd7 --- /dev/null +++ b/content/renderer/pepper/pepper_truetype_font.h @@ -0,0 +1,50 @@ +// Copyright (c) 2013 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 CONTENT_RENDERER_PEPPER_PEPPER_TRUETYPE_FONT_H_ +#define CONTENT_RENDERER_PEPPER_PEPPER_TRUETYPE_FONT_H_ + +#include <string> +#include <vector> + +#include "ppapi/proxy/serialized_structs.h" + +namespace content { + +class PepperTrueTypeFont { + public: + // Creates a font matching the given descriptor. The exact font that is + // returned will depend on the host platform's font matching and fallback + // algorithm. + static PepperTrueTypeFont* Create( + const ppapi::proxy::SerializedTrueTypeFontDesc& desc); + virtual ~PepperTrueTypeFont() {} + + // Returns true if the font was successfully created, false otherwise. + virtual bool IsValid() = 0; + + // Returns a description of the actual font. Use this to see the actual + // characteristics of the font after running the host platform's font matching + // and fallback algorithm. Returns PP_OK on success, a Pepper error code on + // failure. 'desc' is written only on success. + virtual int32_t Describe(ppapi::proxy::SerializedTrueTypeFontDesc* desc) = 0; + + // Retrieves an array of TrueType table tags contained in this font. Returns + // the number of tags on success, a Pepper error code on failure. 'tags' are + // written only on success. + virtual int32_t GetTableTags(std::vector<uint32_t>* tags) = 0; + + // Gets a TrueType font table corresponding to the given tag. The 'offset' and + // 'max_data_length' parameters determine what part of the table is returned. + // Returns the data size in bytes on success, a Pepper error code on failure. + // 'data' is written only on success. + virtual int32_t GetTable(uint32_t table_tag, + int32_t offset, + int32_t max_data_length, + std::string* data) = 0; +}; + +} // namespace content + +#endif // CONTENT_RENDERER_PEPPER_PEPPER_TRUETYPE_FONT_H_ diff --git a/content/renderer/pepper/pepper_truetype_font_android.cc b/content/renderer/pepper/pepper_truetype_font_android.cc new file mode 100644 index 0000000..39cbacd --- /dev/null +++ b/content/renderer/pepper/pepper_truetype_font_android.cc @@ -0,0 +1,16 @@ +// Copyright (c) 2013 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 "content/renderer/pepper/pepper_truetype_font.h" + +namespace content { + +// static +PepperTrueTypeFont* PepperTrueTypeFont::Create( + const ppapi::proxy::SerializedTrueTypeFontDesc& desc) { + NOTIMPLEMENTED(); // Font API isn't implemented on Android. + return 0; +} + +} // namespace content diff --git a/content/renderer/pepper/pepper_truetype_font_host.cc b/content/renderer/pepper/pepper_truetype_font_host.cc new file mode 100644 index 0000000..c94c1f6 --- /dev/null +++ b/content/renderer/pepper/pepper_truetype_font_host.cc @@ -0,0 +1,96 @@ +// Copyright (c) 2013 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 "content/renderer/pepper/pepper_truetype_font_host.h" + +#include "base/bind.h" +#include "content/public/renderer/renderer_ppapi_host.h" +#include "content/renderer/pepper/pepper_truetype_font.h" +#include "ppapi/c/pp_errors.h" +#include "ppapi/host/dispatch_host_message.h" +#include "ppapi/host/host_message_context.h" +#include "ppapi/host/ppapi_host.h" +#include "ppapi/proxy/ppapi_messages.h" + +using ppapi::host::HostMessageContext; +using ppapi::host::ReplyMessageContext; + +namespace content { + +PepperTrueTypeFontHost::PepperTrueTypeFontHost( + RendererPpapiHost* host, + PP_Instance instance, + PP_Resource resource, + const ppapi::proxy::SerializedTrueTypeFontDesc& desc) + : ResourceHost(host->GetPpapiHost(), instance, resource), + renderer_ppapi_host_(host), + font_(PepperTrueTypeFont::Create(desc)), + weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { +} + +PepperTrueTypeFontHost::~PepperTrueTypeFontHost() { +} + +int32_t PepperTrueTypeFontHost::OnResourceMessageReceived( + const IPC::Message& msg, + HostMessageContext* context) { + if (!host()->permissions().HasPermission(ppapi::PERMISSION_DEV)) + return PP_ERROR_FAILED; + + IPC_BEGIN_MESSAGE_MAP(PepperTrueTypeFontHost, msg) + PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_TrueTypeFont_Describe, + OnHostMsgDescribe) + PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_TrueTypeFont_GetTableTags, + OnHostMsgGetTableTags) + PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_TrueTypeFont_GetTable, + OnHostMsgGetTable) + IPC_END_MESSAGE_MAP() + return PP_ERROR_FAILED; +} + +int32_t PepperTrueTypeFontHost::OnHostMsgDescribe(HostMessageContext* context) { + if (!font_->IsValid()) + return PP_ERROR_FAILED; + + ppapi::proxy::SerializedTrueTypeFontDesc desc; + ReplyMessageContext reply_context = context->MakeReplyMessageContext(); + reply_context.params.set_result(font_->Describe(&desc)); + host()->SendReply(reply_context, + PpapiPluginMsg_TrueTypeFont_DescribeReply(desc)); + return PP_OK_COMPLETIONPENDING; +} + +int32_t PepperTrueTypeFontHost::OnHostMsgGetTableTags( + HostMessageContext* context) { + if (!font_->IsValid()) + return PP_ERROR_FAILED; + + std::vector<uint32_t> tags; + ReplyMessageContext reply_context = context->MakeReplyMessageContext(); + reply_context.params.set_result(font_->GetTableTags(&tags)); + host()->SendReply( + reply_context, + PpapiPluginMsg_TrueTypeFont_GetTableTagsReply(tags)); + return PP_OK_COMPLETIONPENDING; +} + +int32_t PepperTrueTypeFontHost::OnHostMsgGetTable(HostMessageContext* context, + uint32_t table, + int32_t offset, + int32_t max_data_length) { + if (!font_->IsValid()) + return PP_ERROR_FAILED; + if (offset < 0 || max_data_length < 0) + return PP_ERROR_BADARGUMENT; + + std::string data; + ReplyMessageContext reply_context = context->MakeReplyMessageContext(); + reply_context.params.set_result( + font_->GetTable(table, offset, max_data_length, &data)); + host()->SendReply(reply_context, + PpapiPluginMsg_TrueTypeFont_GetTableReply(data)); + return PP_OK_COMPLETIONPENDING; +} + +} // namespace content diff --git a/content/renderer/pepper/pepper_truetype_font_host.h b/content/renderer/pepper/pepper_truetype_font_host.h new file mode 100644 index 0000000..27ff397 --- /dev/null +++ b/content/renderer/pepper/pepper_truetype_font_host.h @@ -0,0 +1,50 @@ +// Copyright (c) 2013 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 CONTENT_RENDERER_PEPPER_PEPPER_TRUETYPE_FONT_HOST_H_ +#define CONTENT_RENDERER_PEPPER_PEPPER_TRUETYPE_FONT_HOST_H_ + +#include "base/compiler_specific.h" +#include "base/memory/scoped_ptr.h" +#include "base/memory/weak_ptr.h" +#include "content/common/content_export.h" +#include "content/renderer/pepper/pepper_truetype_font.h" +#include "ppapi/host/resource_host.h" + +namespace content { + +class RendererPpapiHost; + +class CONTENT_EXPORT PepperTrueTypeFontHost : public ppapi::host::ResourceHost { + public: + PepperTrueTypeFontHost(RendererPpapiHost* host, + PP_Instance instance, + PP_Resource resource, + const ppapi::proxy::SerializedTrueTypeFontDesc& desc); + + virtual ~PepperTrueTypeFontHost(); + + virtual int32_t OnResourceMessageReceived( + const IPC::Message& msg, + ppapi::host::HostMessageContext* context) OVERRIDE; + + private: + int32_t OnHostMsgDescribe(ppapi::host::HostMessageContext* context); + int32_t OnHostMsgGetTableTags(ppapi::host::HostMessageContext* context); + int32_t OnHostMsgGetTable(ppapi::host::HostMessageContext* context, + uint32_t table, + int32_t offset, + int32_t max_data_length); + + RendererPpapiHost* renderer_ppapi_host_; + scoped_ptr<PepperTrueTypeFont> font_; + + base::WeakPtrFactory<PepperTrueTypeFontHost> weak_factory_; + + DISALLOW_COPY_AND_ASSIGN(PepperTrueTypeFontHost); +}; + +} // namespace content + +#endif // CONTENT_RENDERER_PEPPER_PEPPER_TRUETYPE_FONT_HOST_H_ diff --git a/content/renderer/pepper/pepper_truetype_font_linux.cc b/content/renderer/pepper/pepper_truetype_font_linux.cc new file mode 100644 index 0000000..f59df68 --- /dev/null +++ b/content/renderer/pepper/pepper_truetype_font_linux.cc @@ -0,0 +1,16 @@ +// Copyright (c) 2013 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 "content/renderer/pepper/pepper_truetype_font.h" + +namespace content { + +// static +PepperTrueTypeFont* PepperTrueTypeFont::Create( + const ppapi::proxy::SerializedTrueTypeFontDesc& desc) { + NOTIMPLEMENTED(); + return 0; +} + +} // namespace content diff --git a/content/renderer/pepper/pepper_truetype_font_mac.mm b/content/renderer/pepper/pepper_truetype_font_mac.mm new file mode 100644 index 0000000..f59df68 --- /dev/null +++ b/content/renderer/pepper/pepper_truetype_font_mac.mm @@ -0,0 +1,16 @@ +// Copyright (c) 2013 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 "content/renderer/pepper/pepper_truetype_font.h" + +namespace content { + +// static +PepperTrueTypeFont* PepperTrueTypeFont::Create( + const ppapi::proxy::SerializedTrueTypeFontDesc& desc) { + NOTIMPLEMENTED(); + return 0; +} + +} // namespace content diff --git a/content/renderer/pepper/pepper_truetype_font_win.cc b/content/renderer/pepper/pepper_truetype_font_win.cc new file mode 100644 index 0000000..f59df68 --- /dev/null +++ b/content/renderer/pepper/pepper_truetype_font_win.cc @@ -0,0 +1,16 @@ +// Copyright (c) 2013 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 "content/renderer/pepper/pepper_truetype_font.h" + +namespace content { + +// static +PepperTrueTypeFont* PepperTrueTypeFont::Create( + const ppapi::proxy::SerializedTrueTypeFontDesc& desc) { + NOTIMPLEMENTED(); + return 0; +} + +} // namespace content diff --git a/ppapi/ppapi_proxy.gypi b/ppapi/ppapi_proxy.gypi index 92e2238..4a5df15 100644 --- a/ppapi/ppapi_proxy.gypi +++ b/ppapi/ppapi_proxy.gypi @@ -166,6 +166,10 @@ 'proxy/resource_creation_proxy.h', 'proxy/talk_resource.cc', 'proxy/talk_resource.h', + 'proxy/truetype_font_resource.cc', + 'proxy/truetype_font_resource.h', + 'proxy/truetype_font_singleton_resource.cc', + 'proxy/truetype_font_singleton_resource.h', 'proxy/udp_socket_private_resource.cc', 'proxy/udp_socket_private_resource.h', 'proxy/url_request_info_resource.cc', diff --git a/ppapi/ppapi_shared.gypi b/ppapi/ppapi_shared.gypi index 2a8f83f..6bfb2d9 100644 --- a/ppapi/ppapi_shared.gypi +++ b/ppapi/ppapi_shared.gypi @@ -217,6 +217,9 @@ 'thunk/ppb_tcp_socket_private_api.h', 'thunk/ppb_tcp_socket_private_thunk.cc', 'thunk/ppb_text_input_thunk.cc', + 'thunk/ppb_truetype_font_api.h', + 'thunk/ppb_truetype_font_singleton_api.h', + 'thunk/ppb_truetype_font_thunk.cc', 'thunk/ppb_udp_socket_private_api.h', 'thunk/ppb_udp_socket_private_thunk.cc', 'thunk/ppb_url_loader_api.h', diff --git a/ppapi/proxy/interface_list.cc b/ppapi/proxy/interface_list.cc index 71444ce..4beeaab 100644 --- a/ppapi/proxy/interface_list.cc +++ b/ppapi/proxy/interface_list.cc @@ -25,6 +25,7 @@ #include "ppapi/c/dev/ppb_testing_dev.h" #include "ppapi/c/dev/ppb_text_input_dev.h" #include "ppapi/c/dev/ppb_trace_event_dev.h" +#include "ppapi/c/dev/ppb_truetype_font_dev.h" #include "ppapi/c/dev/ppb_url_util_dev.h" #include "ppapi/c/dev/ppb_var_deprecated.h" #include "ppapi/c/dev/ppb_video_capture_dev.h" diff --git a/ppapi/proxy/ppapi_messages.h b/ppapi/proxy/ppapi_messages.h index 4e9c0e2..9ccd930 100644 --- a/ppapi/proxy/ppapi_messages.h +++ b/ppapi/proxy/ppapi_messages.h @@ -22,6 +22,7 @@ #include "ppapi/c/dev/pp_video_dev.h" #include "ppapi/c/dev/ppb_directory_reader_dev.h" #include "ppapi/c/dev/ppb_text_input_dev.h" +#include "ppapi/c/dev/ppb_truetype_font_dev.h" #include "ppapi/c/dev/ppb_url_util_dev.h" #include "ppapi/c/dev/ppp_printing_dev.h" #include "ppapi/c/pp_bool.h" @@ -84,6 +85,11 @@ IPC_ENUM_TRAITS(PP_PrintOutputFormat_Dev) IPC_ENUM_TRAITS(PP_PrintScalingOption_Dev) IPC_ENUM_TRAITS(PP_PrivateFontCharset) IPC_ENUM_TRAITS(PP_TextInput_Type) +IPC_ENUM_TRAITS(PP_TrueTypeFontFamily_Dev) +IPC_ENUM_TRAITS(PP_TrueTypeFontStyle_Dev) +IPC_ENUM_TRAITS(PP_TrueTypeFontWeight_Dev) +IPC_ENUM_TRAITS(PP_TrueTypeFontWidth_Dev) +IPC_ENUM_TRAITS(PP_TrueTypeFontCharset_Dev) IPC_ENUM_TRAITS(PP_VideoDecodeError_Dev) IPC_ENUM_TRAITS(PP_VideoDecoder_Profile) @@ -1414,6 +1420,26 @@ IPC_MESSAGE_CONTROL2(PpapiHostMsg_Graphics2D_ReadImageData, PP_Point /* top_left */) IPC_MESSAGE_CONTROL0(PpapiPluginMsg_Graphics2D_ReadImageDataAck) +// TrueTypeFont. +IPC_MESSAGE_CONTROL0(PpapiHostMsg_TrueTypeFontSingleton_Create) +IPC_MESSAGE_CONTROL0(PpapiHostMsg_TrueTypeFontSingleton_GetFontFamilies) +IPC_MESSAGE_CONTROL1(PpapiPluginMsg_TrueTypeFontSingleton_GetFontFamiliesReply, + std::vector<std::string> /* font_families */) +IPC_MESSAGE_CONTROL1(PpapiHostMsg_TrueTypeFont_Create, + ppapi::proxy::SerializedTrueTypeFontDesc /* desc */) +IPC_MESSAGE_CONTROL0(PpapiHostMsg_TrueTypeFont_Describe) +IPC_MESSAGE_CONTROL1(PpapiPluginMsg_TrueTypeFont_DescribeReply, + ppapi::proxy::SerializedTrueTypeFontDesc /* desc */) +IPC_MESSAGE_CONTROL0(PpapiHostMsg_TrueTypeFont_GetTableTags) +IPC_MESSAGE_CONTROL1(PpapiPluginMsg_TrueTypeFont_GetTableTagsReply, + std::vector<uint32_t> /* tags */) +IPC_MESSAGE_CONTROL3(PpapiHostMsg_TrueTypeFont_GetTable, + uint32_t /* table */, + int32_t /* offset */, + int32_t /* max_data_length */) +IPC_MESSAGE_CONTROL1(PpapiPluginMsg_TrueTypeFont_GetTableReply, + std::string /* data */) + // HostResolverPrivate, plugin -> host -> plugin IPC_MESSAGE_CONTROL0(PpapiHostMsg_HostResolverPrivate_Create) IPC_MESSAGE_CONTROL2(PpapiHostMsg_HostResolverPrivate_Resolve, diff --git a/ppapi/proxy/ppapi_param_traits.cc b/ppapi/proxy/ppapi_param_traits.cc index e457503..b654b22 100644 --- a/ppapi/proxy/ppapi_param_traits.cc +++ b/ppapi/proxy/ppapi_param_traits.cc @@ -560,7 +560,44 @@ void ParamTraits<ppapi::proxy::SerializedFontDescription>::Log( const param_type& p, std::string* l) { } +#endif // !defined(OS_NACL) && !defined(NACL_WIN64) + +// ppapi::proxy::SerializedTrueTypeFontDesc ------------------------------------ + +// static +void ParamTraits<ppapi::proxy::SerializedTrueTypeFontDesc>::Write( + Message* m, + const param_type& p) { + ParamTraits<std::string>::Write(m, p.family); + ParamTraits<PP_TrueTypeFontFamily_Dev>::Write(m, p.generic_family); + ParamTraits<PP_TrueTypeFontStyle_Dev>::Write(m, p.style); + ParamTraits<PP_TrueTypeFontWeight_Dev>::Write(m, p.weight); + ParamTraits<PP_TrueTypeFontWidth_Dev>::Write(m, p.width); + ParamTraits<PP_TrueTypeFontCharset_Dev>::Write(m, p.charset); +} + +// static +bool ParamTraits<ppapi::proxy::SerializedTrueTypeFontDesc>::Read( + const Message* m, + PickleIterator* iter, + param_type* r) { + return + ParamTraits<std::string>::Read(m, iter, &r->family) && + ParamTraits<PP_TrueTypeFontFamily_Dev>::Read(m, iter, + &r->generic_family) && + ParamTraits<PP_TrueTypeFontStyle_Dev>::Read(m, iter, &r->style) && + ParamTraits<PP_TrueTypeFontWeight_Dev>::Read(m, iter, &r->weight) && + ParamTraits<PP_TrueTypeFontWidth_Dev>::Read(m, iter, &r->width) && + ParamTraits<PP_TrueTypeFontCharset_Dev>::Read(m, iter, &r->charset); +} + +// static +void ParamTraits<ppapi::proxy::SerializedTrueTypeFontDesc>::Log( + const param_type& p, + std::string* l) { +} +#if !defined(OS_NACL) && !defined(NACL_WIN64) // ppapi::PepperFilePath ------------------------------------------------------- // static diff --git a/ppapi/proxy/ppapi_param_traits.h b/ppapi/proxy/ppapi_param_traits.h index 7556e35..38ec6f3 100644 --- a/ppapi/proxy/ppapi_param_traits.h +++ b/ppapi/proxy/ppapi_param_traits.h @@ -33,6 +33,7 @@ struct PPBFlash_DrawGlyphs_Params; struct PPBURLLoader_UpdateProgress_Params; struct SerializedDirEntry; struct SerializedFontDescription; +struct SerializedTrueTypeFontDesc; class SerializedFlashMenu; class SerializedHandle; class SerializedVar; @@ -117,6 +118,15 @@ struct PPAPI_PROXY_EXPORT ParamTraits<ppapi::proxy::SerializedFontDescription> { }; template<> +struct PPAPI_PROXY_EXPORT + ParamTraits<ppapi::proxy::SerializedTrueTypeFontDesc> { + typedef ppapi::proxy::SerializedTrueTypeFontDesc param_type; + static void Write(Message* m, const param_type& p); + static bool Read(const Message* m, PickleIterator* iter, param_type* r); + static void Log(const param_type& p, std::string* l); +}; + +template<> struct PPAPI_PROXY_EXPORT ParamTraits<ppapi::proxy::SerializedHandle> { typedef ppapi::proxy::SerializedHandle param_type; static void Write(Message* m, const param_type& p); diff --git a/ppapi/proxy/ppb_instance_proxy.cc b/ppapi/proxy/ppb_instance_proxy.cc index df83edc..58b1593 100644 --- a/ppapi/proxy/ppb_instance_proxy.cc +++ b/ppapi/proxy/ppb_instance_proxy.cc @@ -27,6 +27,7 @@ #include "ppapi/proxy/plugin_dispatcher.h" #include "ppapi/proxy/ppapi_messages.h" #include "ppapi/proxy/serialized_var.h" +#include "ppapi/proxy/truetype_font_singleton_resource.h" #include "ppapi/shared_impl/ppapi_globals.h" #include "ppapi/shared_impl/ppb_url_util_shared.h" #include "ppapi/shared_impl/ppb_view_shared.h" @@ -357,6 +358,9 @@ Resource* PPB_Instance_Proxy::GetSingletonResource(PP_Instance instance, case GAMEPAD_SINGLETON_ID: new_singleton = new GamepadResource(connection, instance); break; + case TRUETYPE_FONT_SINGLETON_ID: + new_singleton = new TrueTypeFontSingletonResource(connection, instance); + break; // Flash/trusted resources aren't needed for NaCl. #if !defined(OS_NACL) && !defined(NACL_WIN64) case BROWSER_FONT_SINGLETON_ID: diff --git a/ppapi/proxy/resource_creation_proxy.cc b/ppapi/proxy/resource_creation_proxy.cc index a821a15..4aec036 100644 --- a/ppapi/proxy/resource_creation_proxy.cc +++ b/ppapi/proxy/resource_creation_proxy.cc @@ -38,6 +38,7 @@ #include "ppapi/proxy/ppb_x509_certificate_private_proxy.h" #include "ppapi/proxy/printing_resource.h" #include "ppapi/proxy/talk_resource.h" +#include "ppapi/proxy/truetype_font_resource.h" #include "ppapi/proxy/udp_socket_private_resource.h" #include "ppapi/proxy/url_request_info_resource.h" #include "ppapi/proxy/url_response_info_resource.h" @@ -143,6 +144,14 @@ PP_Resource ResourceCreationProxy::CreateResourceArray( return object->GetReference(); } +PP_Resource ResourceCreationProxy::CreateTrueTypeFont( + PP_Instance instance, + const PP_TrueTypeFontDesc_Dev& desc) { + return (new TrueTypeFontResource(GetConnection(), + instance, desc))->GetReference(); + +} + PP_Resource ResourceCreationProxy::CreateURLLoader(PP_Instance instance) { return PPB_URLLoader_Proxy::CreateProxyResource(instance); } diff --git a/ppapi/proxy/resource_creation_proxy.h b/ppapi/proxy/resource_creation_proxy.h index 940b254..2a95c12 100644 --- a/ppapi/proxy/resource_creation_proxy.h +++ b/ppapi/proxy/resource_creation_proxy.h @@ -75,6 +75,9 @@ class ResourceCreationProxy : public InterfaceProxy, virtual PP_Resource CreateResourceArray(PP_Instance instance, const PP_Resource elements[], uint32_t size) OVERRIDE; + virtual PP_Resource CreateTrueTypeFont( + PP_Instance instance, + const PP_TrueTypeFontDesc_Dev& desc) OVERRIDE; virtual PP_Resource CreateURLLoader(PP_Instance instance) OVERRIDE; virtual PP_Resource CreateURLRequestInfo( PP_Instance instance, diff --git a/ppapi/proxy/serialized_structs.cc b/ppapi/proxy/serialized_structs.cc index ebd7ed0..8c984d5 100644 --- a/ppapi/proxy/serialized_structs.cc +++ b/ppapi/proxy/serialized_structs.cc @@ -80,6 +80,40 @@ void SerializedFontDescription::SetToPPBrowserFontDescription( desc->word_spacing = word_spacing; } +SerializedTrueTypeFontDesc::SerializedTrueTypeFontDesc() + : family(), + generic_family(), + style(), + weight(), + width(), + charset() { +} + +SerializedTrueTypeFontDesc::~SerializedTrueTypeFontDesc() {} + +void SerializedTrueTypeFontDesc::SetFromPPTrueTypeFontDesc( + const PP_TrueTypeFontDesc_Dev& desc) { + StringVar* string_var = StringVar::FromPPVar(desc.family); + family = string_var ? string_var->value() : std::string(); + + generic_family = desc.generic_family; + style = desc.style; + weight = desc.weight; + width = desc.width; + charset = desc.charset; +} + +void SerializedTrueTypeFontDesc::CopyToPPTrueTypeFontDesc( + PP_TrueTypeFontDesc_Dev* desc) const { + desc->family = StringVar::StringToPPVar(family); + + desc->generic_family = generic_family; + desc->style = style; + desc->weight = weight; + desc->width = width; + desc->charset = charset; +} + PPBFlash_DrawGlyphs_Params::PPBFlash_DrawGlyphs_Params() : instance(0), font_desc(), diff --git a/ppapi/proxy/serialized_structs.h b/ppapi/proxy/serialized_structs.h index dcb99817..4844d6b 100644 --- a/ppapi/proxy/serialized_structs.h +++ b/ppapi/proxy/serialized_structs.h @@ -11,6 +11,7 @@ #include "base/logging.h" #include "base/shared_memory.h" #include "build/build_config.h" +#include "ppapi/c/dev/ppb_truetype_font_dev.h" #include "ppapi/c/pp_bool.h" #include "ppapi/c/pp_instance.h" #include "ppapi/c/pp_point.h" @@ -56,6 +57,30 @@ struct PPAPI_PROXY_EXPORT SerializedFontDescription { int32_t word_spacing; }; +struct PPAPI_PROXY_EXPORT SerializedTrueTypeFontDesc { + SerializedTrueTypeFontDesc(); + ~SerializedTrueTypeFontDesc(); + + // Sets this to correspond to the contents of a PP_TrueTypeFontDesc_Dev. + // + // The reference count of the desc.family PP_Var will be unchanged and the + // caller is responsible for releasing it. + void SetFromPPTrueTypeFontDesc(const PP_TrueTypeFontDesc_Dev& desc); + + // Converts this to a PP_FontDescription_Dev. + // + // The desc.family PP_Var will have one reference assigned to it. The caller + // is responsible for releasing it. + void CopyToPPTrueTypeFontDesc(PP_TrueTypeFontDesc_Dev* desc) const; + + std::string family; + PP_TrueTypeFontFamily_Dev generic_family; + PP_TrueTypeFontStyle_Dev style; + PP_TrueTypeFontWeight_Dev weight; + PP_TrueTypeFontWidth_Dev width; + PP_TrueTypeFontCharset_Dev charset; +}; + struct SerializedDirEntry { std::string name; bool is_dir; diff --git a/ppapi/proxy/truetype_font_resource.cc b/ppapi/proxy/truetype_font_resource.cc new file mode 100644 index 0000000..0b07195 --- /dev/null +++ b/ppapi/proxy/truetype_font_resource.cc @@ -0,0 +1,130 @@ +// Copyright (c) 2013 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/truetype_font_resource.h" + +#include "base/bind.h" +#include "ipc/ipc_message.h" +#include "ppapi/c/pp_errors.h" +#include "ppapi/proxy/ppapi_messages.h" +#include "ppapi/shared_impl/array_writer.h" +#include "ppapi/shared_impl/ppapi_globals.h" +#include "ppapi/shared_impl/resource_tracker.h" +#include "ppapi/shared_impl/var.h" +#include "ppapi/thunk/enter.h" + +using ppapi::thunk::EnterResourceNoLock; +using ppapi::thunk::PPB_TrueTypeFont_API; + +namespace { + +} // namespace + +namespace ppapi { +namespace proxy { + +TrueTypeFontResource::TrueTypeFontResource( + Connection connection, + PP_Instance instance, + const PP_TrueTypeFontDesc_Dev& desc) + : PluginResource(connection, instance) { + SerializedTrueTypeFontDesc serialized_desc; + serialized_desc.SetFromPPTrueTypeFontDesc(desc); + SendCreate(RENDERER, PpapiHostMsg_TrueTypeFont_Create(serialized_desc)); +} + +TrueTypeFontResource::~TrueTypeFontResource() { +} + +PPB_TrueTypeFont_API* TrueTypeFontResource::AsPPB_TrueTypeFont_API() { + return this; +} + +int32_t TrueTypeFontResource::Describe( + PP_TrueTypeFontDesc_Dev* desc, + scoped_refptr<TrackedCallback> callback) { + + Call<PpapiPluginMsg_TrueTypeFont_DescribeReply>(RENDERER, + PpapiHostMsg_TrueTypeFont_Describe(), + base::Bind(&TrueTypeFontResource::OnPluginMsgDescribeComplete, this, + callback, desc)); + return PP_OK_COMPLETIONPENDING; +} + +int32_t TrueTypeFontResource::GetTableTags( + const PP_ArrayOutput& output, + scoped_refptr<TrackedCallback> callback) { + Call<PpapiPluginMsg_TrueTypeFont_GetTableTagsReply>(RENDERER, + PpapiHostMsg_TrueTypeFont_GetTableTags(), + base::Bind(&TrueTypeFontResource::OnPluginMsgGetTableTagsComplete, this, + callback, output)); + return PP_OK_COMPLETIONPENDING; +} + +int32_t TrueTypeFontResource::GetTable( + uint32_t table, + int32_t offset, + int32_t max_data_length, + const PP_ArrayOutput& output, + scoped_refptr<TrackedCallback> callback) { + Call<PpapiPluginMsg_TrueTypeFont_GetTableReply>(RENDERER, + PpapiHostMsg_TrueTypeFont_GetTable(table, offset, max_data_length), + base::Bind(&TrueTypeFontResource::OnPluginMsgGetTableComplete, this, + callback, output)); + return PP_OK_COMPLETIONPENDING; +} + +void TrueTypeFontResource::OnPluginMsgDescribeComplete( + scoped_refptr<TrackedCallback> callback, + PP_TrueTypeFontDesc_Dev* pp_desc, + const ResourceMessageReplyParams& params, + const ppapi::proxy::SerializedTrueTypeFontDesc& desc) { + int32_t result = params.result(); + if (result == PP_OK) + desc.CopyToPPTrueTypeFontDesc(pp_desc); + callback->Run(result); +} + +void TrueTypeFontResource::OnPluginMsgGetTableTagsComplete( + scoped_refptr<TrackedCallback> callback, + PP_ArrayOutput array_output, + const ResourceMessageReplyParams& params, + const std::vector<uint32_t>& tag_array) { + // The result code should contain the data size if it's positive. + int32_t result = params.result(); + DCHECK((result < 0 && tag_array.size() == 0) || + result == static_cast<int32_t>(tag_array.size())); + + ArrayWriter output; + output.set_pp_array_output(array_output); + if (output.is_valid()) + output.StoreArray(&tag_array[0], std::max(0, result)); + else + result = PP_ERROR_FAILED; + + callback->Run(result); +} + +void TrueTypeFontResource::OnPluginMsgGetTableComplete( + scoped_refptr<TrackedCallback> callback, + PP_ArrayOutput array_output, + const ResourceMessageReplyParams& params, + const std::string& data) { + // The result code should contain the data size if it's positive. + int32_t result = params.result(); + DCHECK((result < 0 && data.size() == 0) || + result == static_cast<int32_t>(data.size())); + + ArrayWriter output; + output.set_pp_array_output(array_output); + if (output.is_valid()) + output.StoreArray(data.data(), std::max(0, result)); + else + result = PP_ERROR_FAILED; + + callback->Run(result); +} + +} // namespace proxy +} // namespace ppapi diff --git a/ppapi/proxy/truetype_font_resource.h b/ppapi/proxy/truetype_font_resource.h new file mode 100644 index 0000000..6aac2d5 --- /dev/null +++ b/ppapi/proxy/truetype_font_resource.h @@ -0,0 +1,73 @@ +// Copyright (c) 2013 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_TRUETYPE_FONT_RESOURCE_H_ +#define PPAPI_PROXY_TRUETYPE_FONT_RESOURCE_H_ + +#include <string> + +#include "ppapi/proxy/connection.h" +#include "ppapi/proxy/plugin_resource.h" +#include "ppapi/proxy/ppapi_proxy_export.h" +#include "ppapi/shared_impl/var.h" +#include "ppapi/thunk/ppb_truetype_font_api.h" + +namespace ppapi { + +class TrackedCallback; + +namespace proxy { + +struct SerializedTrueTypeFontDesc; + +class PPAPI_PROXY_EXPORT TrueTypeFontResource + : public PluginResource, + public thunk::PPB_TrueTypeFont_API { + public: + TrueTypeFontResource(Connection connection, + PP_Instance instance, + const PP_TrueTypeFontDesc_Dev& desc); + virtual ~TrueTypeFontResource(); + + // Resource overrides. + virtual thunk::PPB_TrueTypeFont_API* AsPPB_TrueTypeFont_API() OVERRIDE; + + // PPB_TrueTypeFont_API implementation. + virtual int32_t Describe( + PP_TrueTypeFontDesc_Dev* desc, + scoped_refptr<TrackedCallback> callback) OVERRIDE; + virtual int32_t GetTableTags( + const PP_ArrayOutput& output, + scoped_refptr<TrackedCallback> callback) OVERRIDE; + virtual int32_t GetTable( + uint32_t table, + int32_t offset, + int32_t max_data_length, + const PP_ArrayOutput& output, + scoped_refptr<TrackedCallback> callback) OVERRIDE; + + private: + void OnPluginMsgDescribeComplete( + scoped_refptr<TrackedCallback> callback, + PP_TrueTypeFontDesc_Dev* pp_desc, + const ResourceMessageReplyParams& params, + const ppapi::proxy::SerializedTrueTypeFontDesc& desc); + void OnPluginMsgGetTableTagsComplete( + scoped_refptr<TrackedCallback> callback, + PP_ArrayOutput array_output, + const ResourceMessageReplyParams& params, + const std::vector<uint32_t>& data); + void OnPluginMsgGetTableComplete( + scoped_refptr<TrackedCallback> callback, + PP_ArrayOutput array_output, + const ResourceMessageReplyParams& params, + const std::string& data); + + DISALLOW_COPY_AND_ASSIGN(TrueTypeFontResource); +}; + +} // namespace proxy +} // namespace ppapi + +#endif // PPAPI_PROXY_TRUETYPE_FONT_RESOURCE_H_ diff --git a/ppapi/proxy/truetype_font_singleton_resource.cc b/ppapi/proxy/truetype_font_singleton_resource.cc new file mode 100644 index 0000000..b812bf1 --- /dev/null +++ b/ppapi/proxy/truetype_font_singleton_resource.cc @@ -0,0 +1,68 @@ +// Copyright (c) 2013 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/truetype_font_singleton_resource.h" + +#include "ppapi/proxy/ppapi_messages.h" +#include "ppapi/shared_impl/array_writer.h" +#include "ppapi/shared_impl/tracked_callback.h" +#include "ppapi/shared_impl/var.h" + +namespace ppapi { +namespace proxy { + +TrueTypeFontSingletonResource::TrueTypeFontSingletonResource( + Connection connection, + PP_Instance instance) + : PluginResource(connection, instance) { + SendCreate(BROWSER, PpapiHostMsg_TrueTypeFontSingleton_Create()); +} + +TrueTypeFontSingletonResource::~TrueTypeFontSingletonResource() { +} + +thunk::PPB_TrueTypeFont_Singleton_API* +TrueTypeFontSingletonResource::AsPPB_TrueTypeFont_Singleton_API() { + return this; +} + +int32_t TrueTypeFontSingletonResource::GetFontFamilies( + PP_Instance instance, + const PP_ArrayOutput& output, + const scoped_refptr<TrackedCallback>& callback) { + Call<PpapiPluginMsg_TrueTypeFontSingleton_GetFontFamiliesReply>(BROWSER, + PpapiHostMsg_TrueTypeFontSingleton_GetFontFamilies(), + base::Bind( + &TrueTypeFontSingletonResource::OnPluginMsgGetFontFamiliesComplete, + this, callback, output)); + return PP_OK_COMPLETIONPENDING; +} + +void TrueTypeFontSingletonResource::OnPluginMsgGetFontFamiliesComplete( + scoped_refptr<TrackedCallback> callback, + PP_ArrayOutput array_output, + const ResourceMessageReplyParams& params, + const std::vector<std::string>& font_families) { + // The result code should contain the data size if it's positive. + int32_t result = params.result(); + DCHECK((result < 0 && font_families.size() == 0) || + result == static_cast<int32_t>(font_families.size())); + + ArrayWriter output; + output.set_pp_array_output(array_output); + if (output.is_valid()) { + std::vector< scoped_refptr<Var> > font_family_vars; + for (size_t i = 0; i < font_families.size(); i++) + font_family_vars.push_back( + scoped_refptr<Var>(new StringVar(font_families[i]))); + output.StoreVarVector(font_family_vars); + } else { + result = PP_ERROR_FAILED; + } + + callback->Run(result); +} + +} // namespace proxy +} // namespace ppapi diff --git a/ppapi/proxy/truetype_font_singleton_resource.h b/ppapi/proxy/truetype_font_singleton_resource.h new file mode 100644 index 0000000..03c9c7d --- /dev/null +++ b/ppapi/proxy/truetype_font_singleton_resource.h @@ -0,0 +1,55 @@ +// Copyright (c) 2013 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_TRUETYPE_FONT_SINGLETON_RESOURCE_H_ +#define PPAPI_PROXY_TRUETYPE_FONT_SINGLETON_RESOURCE_H_ + +#include <string> +#include <vector> + +#include "ppapi/proxy/connection.h" +#include "ppapi/proxy/plugin_resource.h" +#include "ppapi/thunk/ppb_truetype_font_singleton_api.h" + +namespace ppapi { + +class TrackedCallback; + +namespace proxy { + +struct SerializedTrueTypeFontDescription; + +// This handles the singleton calls (that don't take a PP_Resource parameter) +// on the TrueType font interface. +class TrueTypeFontSingletonResource + : public PluginResource, + public thunk::PPB_TrueTypeFont_Singleton_API { + public: + TrueTypeFontSingletonResource(Connection connection, PP_Instance instance); + virtual ~TrueTypeFontSingletonResource(); + + // Resource override. + virtual thunk::PPB_TrueTypeFont_Singleton_API* + AsPPB_TrueTypeFont_Singleton_API() OVERRIDE; + + // thunk::PPB_TrueTypeFont_Singleton_API implementation. + virtual int32_t GetFontFamilies( + PP_Instance instance, + const PP_ArrayOutput& output, + const scoped_refptr<TrackedCallback>& callback) OVERRIDE; + + private: + void OnPluginMsgGetFontFamiliesComplete( + scoped_refptr<TrackedCallback> callback, + PP_ArrayOutput array_output, + const ResourceMessageReplyParams& params, + const std::vector<std::string>& data); + + DISALLOW_COPY_AND_ASSIGN(TrueTypeFontSingletonResource); +}; + +} // namespace proxy +} // namespace ppapi + +#endif // PPAPI_PROXY_TRUETYPE_FONT_SINGLETON_RESOURCE_H_ diff --git a/ppapi/shared_impl/resource.h b/ppapi/shared_impl/resource.h index 3213e8b..fd86ddd 100644 --- a/ppapi/shared_impl/resource.h +++ b/ppapi/shared_impl/resource.h @@ -59,6 +59,8 @@ F(PPB_ResourceArray_API) \ F(PPB_Scrollbar_API) \ F(PPB_Talk_Private_API) \ + F(PPB_TrueTypeFont_API) \ + F(PPB_TrueTypeFont_Singleton_API) \ F(PPB_TCPServerSocket_Private_API) \ F(PPB_TCPSocket_Private_API) \ F(PPB_UDPSocket_Private_API) \ diff --git a/ppapi/shared_impl/singleton_resource_id.h b/ppapi/shared_impl/singleton_resource_id.h index a63dc40..d7db485 100644 --- a/ppapi/shared_impl/singleton_resource_id.h +++ b/ppapi/shared_impl/singleton_resource_id.h @@ -20,6 +20,7 @@ enum SingletonResourceID { FLASH_FULLSCREEN_SINGLETON_ID, FLASH_SINGLETON_ID, GAMEPAD_SINGLETON_ID, + TRUETYPE_FONT_SINGLETON_ID, }; } // namespace ppapi diff --git a/ppapi/tests/all_c_includes.h b/ppapi/tests/all_c_includes.h index bd6911c..7d7a690 100644 --- a/ppapi/tests/all_c_includes.h +++ b/ppapi/tests/all_c_includes.h @@ -29,6 +29,7 @@ #include "ppapi/c/dev/ppb_testing_dev.h" #include "ppapi/c/dev/ppb_text_input_dev.h" #include "ppapi/c/dev/ppb_trace_event_dev.h" +#include "ppapi/c/dev/ppb_truetype_font_dev.h" #include "ppapi/c/dev/ppb_url_util_dev.h" #include "ppapi/c/dev/ppb_var_deprecated.h" #include "ppapi/c/dev/ppb_video_decoder_dev.h" diff --git a/ppapi/thunk/interfaces_ppb_public_dev.h b/ppapi/thunk/interfaces_ppb_public_dev.h index 708b6ef..d0570d9 100644 --- a/ppapi/thunk/interfaces_ppb_public_dev.h +++ b/ppapi/thunk/interfaces_ppb_public_dev.h @@ -28,6 +28,8 @@ PROXIED_IFACE(NoAPIName, PPB_RESOURCEARRAY_DEV_INTERFACE_0_1, PPB_ResourceArray_Dev_0_1) PROXIED_IFACE(PPB_Instance, PPB_TEXTINPUT_DEV_INTERFACE_0_2, PPB_TextInput_Dev_0_2) +PROXIED_IFACE(NoAPIName, PPB_TRUETYPEFONT_DEV_INTERFACE_0_1, + PPB_TrueTypeFont_Dev_0_1) PROXIED_IFACE(NoAPIName, PPB_VIEW_DEV_INTERFACE_0_1, PPB_View_Dev_0_1) UNPROXIED_IFACE(PPB_Instance, PPB_ZOOM_DEV_INTERFACE_0_2, PPB_Zoom_Dev_0_2) diff --git a/ppapi/thunk/ppb_truetype_font_api.h b/ppapi/thunk/ppb_truetype_font_api.h new file mode 100644 index 0000000..9df6c98 --- /dev/null +++ b/ppapi/thunk/ppb_truetype_font_api.h @@ -0,0 +1,36 @@ +// Copyright (c) 2013 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_TRUETYPE_FONT_API_H_ +#define PPAPI_THUNK_PPB_TRUETYPE_FONT_API_H_ + +#include "base/memory/ref_counted.h" +#include "ppapi/c/dev/ppb_truetype_font_dev.h" +#include "ppapi/thunk/ppapi_thunk_export.h" + +namespace ppapi { + +class TrackedCallback; + +namespace thunk { + +class PPAPI_THUNK_EXPORT PPB_TrueTypeFont_API { + public: + virtual ~PPB_TrueTypeFont_API() {} + + virtual int32_t Describe(PP_TrueTypeFontDesc_Dev* desc, + scoped_refptr<TrackedCallback> callback) = 0; + virtual int32_t GetTableTags(const PP_ArrayOutput& output, + scoped_refptr<TrackedCallback> callback) = 0; + virtual int32_t GetTable(uint32_t table, + int32_t offset, + int32_t max_data_length, + const PP_ArrayOutput& output, + scoped_refptr<TrackedCallback> callback) = 0; +}; + +} // namespace thunk +} // namespace ppapi + +#endif // PPAPI_THUNK_PPB_TRUETYPE_FONT_API_H_ diff --git a/ppapi/thunk/ppb_truetype_font_singleton_api.h b/ppapi/thunk/ppb_truetype_font_singleton_api.h new file mode 100644 index 0000000..514bab1 --- /dev/null +++ b/ppapi/thunk/ppb_truetype_font_singleton_api.h @@ -0,0 +1,34 @@ +// Copyright (c) 2013 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_TRUETYPE_FONT_SINGLETON_API_H_ +#define PPAPI_THUNK_PPB_TRUETYPE_FONT_SINGLETON_API_H_ + +#include "ppapi/c/pp_array_output.h" +#include "ppapi/c/pp_completion_callback.h" +#include "ppapi/c/pp_instance.h" +#include "ppapi/c/pp_var.h" +#include "ppapi/shared_impl/singleton_resource_id.h" +#include "ppapi/shared_impl/tracked_callback.h" + +namespace ppapi { +namespace thunk { + +class PPB_TrueTypeFont_Singleton_API { + public: + virtual ~PPB_TrueTypeFont_Singleton_API() {} + + virtual int32_t GetFontFamilies( + PP_Instance instance, + const PP_ArrayOutput& output, + const scoped_refptr<TrackedCallback>& callback) = 0; + + static const SingletonResourceID kSingletonResourceID = + TRUETYPE_FONT_SINGLETON_ID; +}; + +} // namespace thunk +} // namespace ppapi + +#endif // PPAPI_THUNK_PPB_TRUETYPE_FONT_SINGLETON_API_H_ diff --git a/ppapi/thunk/ppb_truetype_font_thunk.cc b/ppapi/thunk/ppb_truetype_font_thunk.cc new file mode 100644 index 0000000..b941c84 --- /dev/null +++ b/ppapi/thunk/ppb_truetype_font_thunk.cc @@ -0,0 +1,94 @@ +// Copyright (c) 2013 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/c/dev/ppb_truetype_font_dev.h" +#include "ppapi/c/pp_completion_callback.h" +#include "ppapi/c/pp_errors.h" +#include "ppapi/shared_impl/tracked_callback.h" +#include "ppapi/thunk/enter.h" +#include "ppapi/thunk/ppb_instance_api.h" +#include "ppapi/thunk/ppb_truetype_font_api.h" +#include "ppapi/thunk/ppb_truetype_font_singleton_api.h" +#include "ppapi/thunk/resource_creation_api.h" +#include "ppapi/thunk/thunk.h" + +namespace ppapi { +namespace thunk { + +namespace { + +int32_t GetFontFamilies(PP_Instance instance, + PP_ArrayOutput output, + PP_CompletionCallback callback) { + EnterInstanceAPI<PPB_TrueTypeFont_Singleton_API> enter(instance, callback); + if (enter.failed()) + return PP_ERROR_FAILED; + return enter.functions()->GetFontFamilies(instance, output, enter.callback()); +} + +PP_Resource Create(PP_Instance instance, + const PP_TrueTypeFontDesc_Dev* desc) { + EnterResourceCreation enter(instance); + if (enter.failed()) + return 0; + return enter.functions()->CreateTrueTypeFont(instance, *desc); +} + +PP_Bool IsFont(PP_Resource resource) { + EnterResource<PPB_TrueTypeFont_API> enter(resource, false); + return PP_FromBool(enter.succeeded()); +} + +int32_t Describe(PP_Resource font, + PP_TrueTypeFontDesc_Dev* desc, + PP_CompletionCallback callback) { + EnterResource<PPB_TrueTypeFont_API> enter(font, callback, true); + if (enter.failed()) + return enter.retval(); + return enter.SetResult(enter.object()->Describe(desc, enter.callback())); +} + +int32_t GetTableTags(PP_Resource font, + PP_ArrayOutput output, + PP_CompletionCallback callback) { + EnterResource<PPB_TrueTypeFont_API> enter(font, callback, true); + if (enter.failed()) + return enter.retval(); + return enter.SetResult(enter.object()->GetTableTags(output, + enter.callback())); +} + +int32_t GetTable(PP_Resource font, + uint32_t table, + int32_t offset, + int32_t max_data_length, + PP_ArrayOutput output, + PP_CompletionCallback callback) { + EnterResource<PPB_TrueTypeFont_API> enter(font, callback, true); + if (enter.failed()) + return enter.retval(); + return enter.SetResult(enter.object()->GetTable(table, + offset, + max_data_length, + output, + enter.callback())); +} + +const PPB_TrueTypeFont_Dev_0_1 g_ppb_truetypefont_thunk_0_1 = { + &GetFontFamilies, + &Create, + &IsFont, + &Describe, + &GetTableTags, + &GetTable +}; + +} // namespace + +const PPB_TrueTypeFont_Dev_0_1* GetPPB_TrueTypeFont_Dev_0_1_Thunk() { + return &g_ppb_truetypefont_thunk_0_1; +} + +} // namespace thunk +} // namespace ppapi diff --git a/ppapi/thunk/resource_creation_api.h b/ppapi/thunk/resource_creation_api.h index 47c1114..377424a 100644 --- a/ppapi/thunk/resource_creation_api.h +++ b/ppapi/thunk/resource_creation_api.h @@ -17,6 +17,7 @@ #include "ppapi/c/ppb_input_event.h" #include "ppapi/c/ppb_websocket.h" #include "ppapi/c/dev/pp_video_dev.h" +#include "ppapi/c/dev/ppb_truetype_font_dev.h" #include "ppapi/c/private/pp_private_font_charset.h" #include "ppapi/c/private/ppb_network_monitor_private.h" #include "ppapi/shared_impl/api_id.h" @@ -80,6 +81,9 @@ class ResourceCreationAPI { virtual PP_Resource CreateResourceArray(PP_Instance instance, const PP_Resource elements[], uint32_t size) = 0; + virtual PP_Resource CreateTrueTypeFont( + PP_Instance instance, + const PP_TrueTypeFontDesc_Dev& desc) = 0; virtual PP_Resource CreateURLLoader(PP_Instance instance) = 0; virtual PP_Resource CreateURLRequestInfo( PP_Instance instance, diff --git a/webkit/plugins/ppapi/plugin_module.cc b/webkit/plugins/ppapi/plugin_module.cc index 4b917b0f..983c11d 100644 --- a/webkit/plugins/ppapi/plugin_module.cc +++ b/webkit/plugins/ppapi/plugin_module.cc @@ -33,6 +33,7 @@ #include "ppapi/c/dev/ppb_testing_dev.h" #include "ppapi/c/dev/ppb_text_input_dev.h" #include "ppapi/c/dev/ppb_trace_event_dev.h" +#include "ppapi/c/dev/ppb_truetype_font_dev.h" #include "ppapi/c/dev/ppb_url_util_dev.h" #include "ppapi/c/dev/ppb_var_deprecated.h" #include "ppapi/c/dev/ppb_video_capture_dev.h" diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.cc b/webkit/plugins/ppapi/ppapi_plugin_instance.cc index 886338b..10a6457 100644 --- a/webkit/plugins/ppapi/ppapi_plugin_instance.cc +++ b/webkit/plugins/ppapi/ppapi_plugin_instance.cc @@ -2125,6 +2125,7 @@ PP_Bool PluginInstance::GetScreenSize(PP_Instance instance, PP_Size* size) { case ::ppapi::FLASH_FILE_SINGLETON_ID: case ::ppapi::FLASH_FULLSCREEN_SINGLETON_ID: case ::ppapi::FLASH_SINGLETON_ID: + case ::ppapi::TRUETYPE_FONT_SINGLETON_ID: NOTIMPLEMENTED(); return NULL; case ::ppapi::GAMEPAD_SINGLETON_ID: |