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

Side by Side Diff: ppapi/proxy/ppb_pdf_proxy.cc

Issue 7629017: Add a unified resource tracker shared between the proxy and the impl. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review comments Created 9 years, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ppapi/proxy/ppb_pdf_proxy.h" 5 #include "ppapi/proxy/ppb_pdf_proxy.h"
6 6
7 #include <string.h> // For memcpy. 7 #include <string.h> // For memcpy.
8 8
9 #include <map> 9 #include <map>
10 10
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/linked_ptr.h" 12 #include "base/memory/linked_ptr.h"
13 #include "build/build_config.h" 13 #include "build/build_config.h"
14 #include "ppapi/c/private/ppb_pdf.h" 14 #include "ppapi/c/private/ppb_pdf.h"
15 #include "ppapi/proxy/plugin_dispatcher.h" 15 #include "ppapi/proxy/plugin_dispatcher.h"
16 #include "ppapi/proxy/plugin_resource.h"
17 #include "ppapi/proxy/plugin_resource_tracker.h" 16 #include "ppapi/proxy/plugin_resource_tracker.h"
18 #include "ppapi/proxy/ppapi_messages.h" 17 #include "ppapi/proxy/ppapi_messages.h"
19 #include "ppapi/thunk/enter.h" 18 #include "ppapi/thunk/enter.h"
20 #include "ppapi/thunk/ppb_pdf_api.h" 19 #include "ppapi/thunk/ppb_pdf_api.h"
21 20
22 using ppapi::HostResource; 21 using ppapi::HostResource;
22 using ppapi::Resource;
23 using ppapi::thunk::PPB_PDFFont_API; 23 using ppapi::thunk::PPB_PDFFont_API;
24 using ppapi::thunk::EnterResource; 24 using ppapi::thunk::EnterResource;
25 25
26 namespace pp { 26 namespace pp {
27 namespace proxy { 27 namespace proxy {
28 28
29 class PrivateFontFile : public PluginResource, 29 class PrivateFontFile : public Resource,
30 public PPB_PDFFont_API { 30 public PPB_PDFFont_API {
31 public: 31 public:
32 PrivateFontFile(const HostResource& resource) : PluginResource(resource) { 32 PrivateFontFile(const HostResource& resource) : Resource(resource) {
33 } 33 }
34 virtual ~PrivateFontFile() {} 34 virtual ~PrivateFontFile() {}
35 35
36 PPB_PDFFont_API* AsPPB_PDFFont_API() { return this; } 36 PPB_PDFFont_API* AsPPB_PDFFont_API() { return this; }
37 37
38 // Sees if we have a cache of the font table and returns a pointer to it. 38 // Sees if we have a cache of the font table and returns a pointer to it.
39 // Returns NULL if we don't have it. 39 // Returns NULL if we don't have it.
40 std::string* GetFontTable(uint32_t table) const; 40 std::string* GetFontTable(uint32_t table) const;
41 41
42 std::string* AddFontTable(uint32_t table, const std::string& contents); 42 std::string* AddFontTable(uint32_t table, const std::string& contents);
(...skipping 30 matching lines...) Expand all
73 return 0; 73 return 0;
74 74
75 SerializedFontDescription desc; 75 SerializedFontDescription desc;
76 desc.SetFromPPFontDescription(dispatcher, *description, true); 76 desc.SetFromPPFontDescription(dispatcher, *description, true);
77 77
78 HostResource result; 78 HostResource result;
79 dispatcher->Send(new PpapiHostMsg_PPBPDF_GetFontFileWithFallback( 79 dispatcher->Send(new PpapiHostMsg_PPBPDF_GetFontFileWithFallback(
80 INTERFACE_ID_PPB_PDF, instance, desc, charset, &result)); 80 INTERFACE_ID_PPB_PDF, instance, desc, charset, &result));
81 if (result.is_null()) 81 if (result.is_null())
82 return 0; 82 return 0;
83 83 return (new PrivateFontFile(result))->GetReference();
84 return PluginResourceTracker::GetInstance()->AddResource(
85 new PrivateFontFile(result));
86 } 84 }
87 85
88 bool GetFontTableForPrivateFontFile(PP_Resource font_file, 86 bool GetFontTableForPrivateFontFile(PP_Resource font_file,
89 uint32_t table, 87 uint32_t table,
90 void* output, 88 void* output,
91 uint32_t* output_length) { 89 uint32_t* output_length) {
92 EnterResource<PPB_PDFFont_API> enter(font_file, true); 90 EnterResource<PPB_PDFFont_API> enter(font_file, true);
93 if (enter.failed()) 91 if (enter.failed())
94 return false; 92 return false;
95 93
96 PrivateFontFile* object = static_cast<PrivateFontFile*>(enter.object()); 94 PrivateFontFile* object = static_cast<PrivateFontFile*>(enter.object());
97 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance( 95 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(
98 object->instance()); 96 object->pp_instance());
99 if (!dispatcher) 97 if (!dispatcher)
100 return false; 98 return false;
101 99
102 std::string* contents = object->GetFontTable(table); 100 std::string* contents = object->GetFontTable(table);
103 if (!contents) { 101 if (!contents) {
104 std::string deserialized; 102 std::string deserialized;
105 dispatcher->Send(new PpapiHostMsg_PPBPDF_GetFontTableForPrivateFontFile( 103 dispatcher->Send(new PpapiHostMsg_PPBPDF_GetFontTableForPrivateFontFile(
106 INTERFACE_ID_PPB_PDF, object->host_resource(), table, &deserialized)); 104 INTERFACE_ID_PPB_PDF, object->host_resource(), table, &deserialized));
107 if (deserialized.empty()) 105 if (deserialized.empty())
108 return false; 106 return false;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 font_file.host_resource(), table, NULL, &table_length)) 183 font_file.host_resource(), table, NULL, &table_length))
186 return; 184 return;
187 185
188 result->resize(table_length); 186 result->resize(table_length);
189 ppb_pdf_target()->GetFontTableForPrivateFontFile(font_file.host_resource(), 187 ppb_pdf_target()->GetFontTableForPrivateFontFile(font_file.host_resource(),
190 table, const_cast<char*>(result->c_str()), &table_length); 188 table, const_cast<char*>(result->c_str()), &table_length);
191 } 189 }
192 190
193 } // namespace proxy 191 } // namespace proxy
194 } // namespace pp 192 } // namespace pp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698