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

Side by Side Diff: webkit/glue/plugins/pepper_private.cc

Issue 3044029: Hook up the new font API to WebKit. This moves the existing GetFontTable API ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 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
« no previous file with comments | « webkit/glue/plugins/pepper_font.cc ('k') | webkit/glue/plugins/pepper_resource.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #include "webkit/glue/plugins/pepper_private.h" 7 #include "webkit/glue/plugins/pepper_private.h"
8 8
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "grit/webkit_strings.h" 10 #include "grit/webkit_strings.h"
11 #include "webkit/glue/webkit_glue.h" 11 #include "webkit/glue/webkit_glue.h"
12 #include "webkit/glue/plugins/pepper_plugin_module.h"
12 #include "webkit/glue/plugins/pepper_var.h" 13 #include "webkit/glue/plugins/pepper_var.h"
13 #include "webkit/glue/plugins/ppb_private.h" 14 #include "webkit/glue/plugins/ppb_private.h"
14 15
15 namespace pepper { 16 namespace pepper {
16 17
18 #if defined(OS_LINUX)
19 class PrivateFontFile : public Resource {
20 public:
21 PrivateFontFile(PluginModule* module, int fd) : Resource(module), fd_(fd) {}
22 virtual ~PrivateFontFile() {}
23
24 // Resource overrides.
25 PrivateFontFile* AsPrivateFontFile() { return this; }
26
27 bool GetFontTable(uint32_t table,
28 void* output,
29 uint32_t* output_length);
30
31 private:
32 int fd_;
33 };
34 #endif
35
17 namespace { 36 namespace {
18 37
19 PP_Var GetLocalizedString(PP_ResourceString string_id) { 38 PP_Var GetLocalizedString(PP_ResourceString string_id) {
20 std::string rv; 39 std::string rv;
21 if (string_id == PP_RESOURCESTRING_PDFGETPASSWORD) 40 if (string_id == PP_RESOURCESTRING_PDFGETPASSWORD)
22 rv = UTF16ToUTF8(webkit_glue::GetLocalizedString(IDS_PDF_NEED_PASSWORD)); 41 rv = UTF16ToUTF8(webkit_glue::GetLocalizedString(IDS_PDF_NEED_PASSWORD));
23 42
24 return StringToPPVar(rv); 43 return StringToPPVar(rv);
25 } 44 }
26 45
46 PP_Resource GetFontFileWithFallback(
47 PP_Module module_id,
48 const PP_PrivateFontFileDescription* description) {
49 #if defined(OS_LINUX)
50 PluginModule* module = PluginModule::FromPPModule(module_id);
51 if (!module)
52 return NULL;
53
54 int fd = webkit_glue::MatchFontWithFallback(description->face,
55 description->weight >= 700,
56 description->italic,
57 description->charset);
58 if (fd == -1)
59 return NULL;
60
61 scoped_refptr<PrivateFontFile> font(new PrivateFontFile(module, fd));
62
63 return font->GetReference();
64 #else
65 // For trusted pepper plugins, this is only needed in Linux since font loading
66 // on Windows and Mac works through the renderer sandbox.
67 return false;
68 #endif
69 }
70
71 bool GetFontTableForPrivateFontFile(PP_Resource font_file,
72 uint32_t table,
73 void* output,
74 uint32_t* output_length) {
75 #if defined(OS_LINUX)
76 scoped_refptr<PrivateFontFile> font(
77 Resource::GetAs<PrivateFontFile>(font_file));
78 if (!font.get())
79 return false;
80 return font->GetFontTable(table, output, output_length);
81 #else
82 return false;
83 #endif
84 }
85
27 const PPB_Private ppb_private = { 86 const PPB_Private ppb_private = {
28 &GetLocalizedString, 87 &GetLocalizedString,
88 &GetFontFileWithFallback,
89 &GetFontTableForPrivateFontFile,
29 }; 90 };
30 91
31 } // namespace 92 } // namespace
32 93
33 // static 94 // static
34 const PPB_Private* Private::GetInterface() { 95 const PPB_Private* Private::GetInterface() {
35 return &ppb_private; 96 return &ppb_private;
36 } 97 }
37 98
99 #if defined(OS_LINUX)
100 bool PrivateFontFile::GetFontTable(uint32_t table,
101 void* output,
102 uint32_t* output_length) {
103 size_t temp_size = static_cast<size_t>(*output_length);
104 bool rv = webkit_glue::GetFontTable(
105 fd_, table, static_cast<uint8_t*>(output), &temp_size);
106 *output_length = static_cast<uint32_t>(temp_size);
107 return rv;
108 }
109 #endif
110
38 } // namespace pepper 111 } // namespace pepper
OLDNEW
« no previous file with comments | « webkit/glue/plugins/pepper_font.cc ('k') | webkit/glue/plugins/pepper_resource.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698