Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(217)

Unified Diff: ppapi/proxy/flash_font_file_resource.cc

Issue 10905227: Introduce PPB_Flash_Font. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ppapi/proxy/flash_font_file_resource.h ('k') | ppapi/proxy/interface_list.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ppapi/proxy/flash_font_file_resource.cc
diff --git a/ppapi/proxy/flash_font_file_resource.cc b/ppapi/proxy/flash_font_file_resource.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ecb8bc2ee4deb2f6372bfd9c3f3fc129cc6b14b7
--- /dev/null
+++ b/ppapi/proxy/flash_font_file_resource.cc
@@ -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.
+
+#include "ppapi/proxy/flash_font_file_resource.h"
+
+#include <cstring>
+
+#include "ppapi/c/dev/ppb_font_dev.h"
+#include "ppapi/c/pp_errors.h"
+#include "ppapi/proxy/ppapi_messages.h"
+
+namespace ppapi {
+namespace proxy {
+
+FlashFontFileResource::FlashFontFileResource(
+ Connection connection,
+ PP_Instance instance,
+ const PP_FontDescription_Dev* description,
+ PP_PrivateFontCharset charset)
+ : PluginResource(connection, instance),
+ charset_(charset) {
+ description_.SetFromPPFontDescription(*description);
+}
+
+FlashFontFileResource::~FlashFontFileResource() {
+}
+
+thunk::PPB_Flash_FontFile_API*
+ FlashFontFileResource::AsPPB_Flash_FontFile_API() {
+ return this;
+}
+
+PP_Bool FlashFontFileResource::GetFontTable(uint32_t table,
+ void* output,
+ uint32_t* output_length) {
+ if (!output_length)
+ return PP_FALSE;
+
+ if (!sent_create_to_renderer()) {
+ SendCreateToRenderer(
+ PpapiHostMsg_FlashFontFile_Create(description_, charset_));
+ }
+
+ std::string* contents = GetFontTable(table);
+ if (!contents) {
+ IPC::Message reply;
+ int32_t result = CallRendererSync(
+ PpapiHostMsg_FlashFontFile_GetFontTable(table), &reply);
+ if (result != PP_OK)
+ return PP_FALSE;
+
+ PpapiPluginMsg_FlashFontFile_GetFontTableReply::Param param;
+ if (!PpapiPluginMsg_FlashFontFile_GetFontTableReply::Read(&reply, &param))
+ return PP_FALSE;
+
+ contents = AddFontTable(table, param.a);
+ }
+
+ // If we are going to copy the data into |output|, it must be big enough.
+ if (output && *output_length < contents->size())
+ return PP_FALSE;
+
+ *output_length = static_cast<uint32_t>(contents->size());
+ if (output)
+ memcpy(output, contents->c_str(), *output_length);
+ return PP_TRUE;
+}
+
+std::string* FlashFontFileResource::GetFontTable(uint32_t table) const {
+ FontTableMap::const_iterator found = font_tables_.find(table);
+ if (found == font_tables_.end())
+ return NULL;
+ return found->second.get();
+}
+
+std::string* FlashFontFileResource::AddFontTable(uint32_t table,
+ const std::string& contents) {
+ linked_ptr<std::string> heap_string(new std::string(contents));
+ font_tables_[table] = heap_string;
+ return heap_string.get();
+}
+
+} // namespace proxy
+} // namespace ppapi
« no previous file with comments | « ppapi/proxy/flash_font_file_resource.h ('k') | ppapi/proxy/interface_list.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698