| Index: content/browser/renderer_host/pepper/pepper_truetype_font_host.cc
|
| diff --git a/content/browser/renderer_host/pepper/pepper_truetype_font_host.cc b/content/browser/renderer_host/pepper/pepper_truetype_font_host.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..a72b82524dfc81ba653b782ddaa3a993b8275284
|
| --- /dev/null
|
| +++ b/content/browser/renderer_host/pepper/pepper_truetype_font_host.cc
|
| @@ -0,0 +1,164 @@
|
| +// 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_host.h"
|
| +
|
| +#include "base/callback.h"
|
| +#include "base/task_runner_util.h"
|
| +#include "base/threading/sequenced_worker_pool.h"
|
| +#include "content/browser/renderer_host/pepper/pepper_truetype_font.h"
|
| +#include "content/public/browser/browser_ppapi_host.h"
|
| +#include "content/public/browser/browser_thread.h"
|
| +#include "ppapi/c/pp_errors.h"
|
| +#include "ppapi/host/dispatch_host_message.h"
|
| +#include "ppapi/host/ppapi_host.h"
|
| +#include "ppapi/proxy/ppapi_messages.h"
|
| +
|
| +using ppapi::host::HostMessageContext;
|
| +using ppapi::host::ReplyMessageContext;
|
| +using ppapi::proxy::SerializedTrueTypeFontDesc;
|
| +
|
| +namespace content {
|
| +
|
| +namespace {
|
| +
|
| +int32_t DoDescribe(scoped_refptr<PepperTrueTypeFont> font,
|
| + SerializedTrueTypeFontDesc* desc) {
|
| + return font->Describe(desc);
|
| +}
|
| +
|
| +int32_t DoGetTableTags(scoped_refptr<PepperTrueTypeFont> font,
|
| + std::vector<uint32_t>* tags) {
|
| + return font->GetTableTags(tags);
|
| +}
|
| +
|
| +int32_t DoGetTable(scoped_refptr<PepperTrueTypeFont> font,
|
| + uint32_t table,
|
| + int32_t offset,
|
| + int32_t max_data_length,
|
| + std::string* data) {
|
| + return font->GetTable(table, offset, max_data_length, data);
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +PepperTrueTypeFontHost::PepperTrueTypeFontHost(
|
| + BrowserPpapiHost* host,
|
| + PP_Instance instance,
|
| + PP_Resource resource,
|
| + const SerializedTrueTypeFontDesc& desc)
|
| + : ResourceHost(host->GetPpapiHost(), instance, resource),
|
| + browser_ppapi_host_(host),
|
| + font_(PepperTrueTypeFont::Create(desc)),
|
| + weak_factory_(this) {
|
| +}
|
| +
|
| +PepperTrueTypeFontHost::~PepperTrueTypeFontHost() {
|
| +}
|
| +
|
| +int32_t PepperTrueTypeFontHost::OnResourceMessageReceived(
|
| + const IPC::Message& msg,
|
| + HostMessageContext* context) {
|
| + if (!host()->permissions().HasPermission(ppapi::PERMISSION_DEV))
|
| + return PP_ERROR_FAILED;
|
| +
|
| + PPAPI_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)
|
| + PPAPI_END_MESSAGE_MAP()
|
| + return PP_ERROR_FAILED;
|
| +}
|
| +
|
| +int32_t PepperTrueTypeFontHost::OnHostMsgDescribe(HostMessageContext* context) {
|
| + if (!font_)
|
| + return PP_ERROR_FAILED;
|
| +
|
| + // Get font data on a thread that allows slow blocking operations.
|
| + SerializedTrueTypeFontDesc* desc = new SerializedTrueTypeFontDesc();
|
| + base::PostTaskAndReplyWithResult(
|
| + BrowserThread::GetBlockingPool(),
|
| + FROM_HERE,
|
| + base::Bind(&DoDescribe, font_, desc),
|
| + base::Bind(&PepperTrueTypeFontHost::OnDescribeComplete,
|
| + weak_factory_.GetWeakPtr(),
|
| + base::Owned(desc),
|
| + context->MakeReplyMessageContext()));
|
| +
|
| + return PP_OK_COMPLETIONPENDING;
|
| +}
|
| +
|
| +int32_t PepperTrueTypeFontHost::OnHostMsgGetTableTags(
|
| + HostMessageContext* context) {
|
| + if (!font_)
|
| + return PP_ERROR_FAILED;
|
| +
|
| + // Get font data on a thread that allows slow blocking operations.
|
| + std::vector<uint32_t>* tags = new std::vector<uint32_t>();
|
| + base::PostTaskAndReplyWithResult(
|
| + BrowserThread::GetBlockingPool(),
|
| + FROM_HERE,
|
| + base::Bind(&DoGetTableTags, font_, tags),
|
| + base::Bind(&PepperTrueTypeFontHost::OnGetTableTagsComplete,
|
| + weak_factory_.GetWeakPtr(),
|
| + base::Owned(tags),
|
| + context->MakeReplyMessageContext()));
|
| +
|
| + return PP_OK_COMPLETIONPENDING;
|
| +}
|
| +
|
| +int32_t PepperTrueTypeFontHost::OnHostMsgGetTable(HostMessageContext* context,
|
| + uint32_t table,
|
| + int32_t offset,
|
| + int32_t max_data_length) {
|
| + if (!font_)
|
| + return PP_ERROR_FAILED;
|
| + if (offset < 0 || max_data_length < 0)
|
| + return PP_ERROR_BADARGUMENT;
|
| +
|
| + // Get font data on a thread that allows slow blocking operations.
|
| + std::string* data = new std::string();
|
| + base::PostTaskAndReplyWithResult(
|
| + BrowserThread::GetBlockingPool(),
|
| + FROM_HERE,
|
| + base::Bind(&DoGetTable, font_, table, offset, max_data_length, data),
|
| + base::Bind(&PepperTrueTypeFontHost::OnGetTableComplete,
|
| + weak_factory_.GetWeakPtr(),
|
| + base::Owned(data),
|
| + context->MakeReplyMessageContext()));
|
| +
|
| + return PP_OK_COMPLETIONPENDING;
|
| +}
|
| +
|
| +void PepperTrueTypeFontHost::OnDescribeComplete(
|
| + SerializedTrueTypeFontDesc* desc,
|
| + ReplyMessageContext reply_context,
|
| + int32_t result) {
|
| + reply_context.params.set_result(result);
|
| + host()->SendReply(reply_context,
|
| + PpapiPluginMsg_TrueTypeFont_DescribeReply(*desc));
|
| +}
|
| +
|
| +void PepperTrueTypeFontHost::OnGetTableTagsComplete(
|
| + std::vector<uint32_t>* tags,
|
| + ReplyMessageContext reply_context,
|
| + int32_t result) {
|
| + reply_context.params.set_result(result);
|
| + host()->SendReply(reply_context,
|
| + PpapiPluginMsg_TrueTypeFont_GetTableTagsReply(*tags));
|
| +}
|
| +
|
| +void PepperTrueTypeFontHost::OnGetTableComplete(
|
| + std::string* data,
|
| + ReplyMessageContext reply_context,
|
| + int32_t result) {
|
| + reply_context.params.set_result(result);
|
| + host()->SendReply(reply_context,
|
| + PpapiPluginMsg_TrueTypeFont_GetTableReply(*data));
|
| +}
|
| +
|
| +} // namespace content
|
|
|