OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "content/browser/renderer_host/pepper/pepper_browser_font_singleton_hos
t.h" | 5 #include "content/browser/renderer_host/pepper/pepper_truetype_font_list_host.h" |
6 | 6 |
| 7 #include <algorithm> |
| 8 |
| 9 #include "base/safe_numerics.h" |
7 #include "base/threading/sequenced_worker_pool.h" | 10 #include "base/threading/sequenced_worker_pool.h" |
8 #include "base/values.h" | 11 #include "content/browser/renderer_host/pepper/pepper_truetype_font_list.h" |
9 #include "content/common/font_list.h" | |
10 #include "content/public/browser/browser_ppapi_host.h" | 12 #include "content/public/browser/browser_ppapi_host.h" |
11 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
12 #include "ppapi/host/dispatch_host_message.h" | 14 #include "ppapi/host/dispatch_host_message.h" |
| 15 #include "ppapi/host/host_message_context.h" |
13 #include "ppapi/host/resource_message_filter.h" | 16 #include "ppapi/host/resource_message_filter.h" |
14 #include "ppapi/proxy/ppapi_messages.h" | 17 #include "ppapi/proxy/ppapi_messages.h" |
15 | 18 |
16 namespace content { | 19 namespace content { |
17 | 20 |
18 namespace { | 21 namespace { |
19 | 22 |
20 // Handles the font list request on the blocking pool. | 23 // Handles the font list request on the blocking pool. |
21 class FontMessageFilter : public ppapi::host::ResourceMessageFilter { | 24 class FontMessageFilter : public ppapi::host::ResourceMessageFilter { |
22 public: | 25 public: |
(...skipping 26 matching lines...) Expand all Loading... |
49 // Use the blocking pool to get the font list (currently the only message | 52 // Use the blocking pool to get the font list (currently the only message |
50 // so we can always just return it). | 53 // so we can always just return it). |
51 return scoped_refptr<base::TaskRunner>(BrowserThread::GetBlockingPool()); | 54 return scoped_refptr<base::TaskRunner>(BrowserThread::GetBlockingPool()); |
52 } | 55 } |
53 | 56 |
54 int32_t FontMessageFilter::OnResourceMessageReceived( | 57 int32_t FontMessageFilter::OnResourceMessageReceived( |
55 const IPC::Message& msg, | 58 const IPC::Message& msg, |
56 ppapi::host::HostMessageContext* context) { | 59 ppapi::host::HostMessageContext* context) { |
57 IPC_BEGIN_MESSAGE_MAP(FontMessageFilter, msg) | 60 IPC_BEGIN_MESSAGE_MAP(FontMessageFilter, msg) |
58 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0( | 61 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0( |
59 PpapiHostMsg_BrowserFontSingleton_GetFontFamilies, | 62 PpapiHostMsg_TrueTypeFontSingleton_GetFontFamilies, |
60 OnHostMsgGetFontFamilies) | 63 OnHostMsgGetFontFamilies) |
61 IPC_END_MESSAGE_MAP() | 64 IPC_END_MESSAGE_MAP() |
62 return PP_ERROR_FAILED; | 65 return PP_ERROR_FAILED; |
63 } | 66 } |
64 | 67 |
65 int32_t FontMessageFilter::OnHostMsgGetFontFamilies( | 68 int32_t FontMessageFilter::OnHostMsgGetFontFamilies( |
66 ppapi::host::HostMessageContext* context) { | 69 ppapi::host::HostMessageContext* context) { |
67 // OK to use "slow blocking" version since we're on the blocking pool. | 70 // OK to use "slow blocking" version since we're on the blocking pool. |
68 scoped_ptr<base::ListValue> list(GetFontList_SlowBlocking()); | 71 std::vector<std::string> font_families; |
| 72 GetFontFamilies_SlowBlocking(&font_families); |
| 73 // Sort the names in case the host platform returns them out of order. |
| 74 std::sort(font_families.begin(), font_families.end()); |
69 | 75 |
70 std::string output; | 76 int32_t result = base::checked_numeric_cast<int32_t>(font_families.size()); |
71 for (size_t i = 0; i < list->GetSize(); i++) { | 77 ppapi::host::ReplyMessageContext reply_context = |
72 base::ListValue* cur_font; | 78 context->MakeReplyMessageContext(); |
73 if (!list->GetList(i, &cur_font)) | 79 reply_context.params.set_result(result); |
74 continue; | |
75 | |
76 // Each entry is actually a list of (font name, localized name). | |
77 // We only care about the regular name. | |
78 std::string font_name; | |
79 if (!cur_font->GetString(0, &font_name)) | |
80 continue; | |
81 | |
82 // Font names are separated with nulls. We also want an explicit null at | |
83 // the end of the string (Pepper strings aren't null terminated so since | |
84 // we specify there will be a null, it should actually be in the string). | |
85 output.append(font_name); | |
86 output.push_back(0); | |
87 } | |
88 | |
89 context->reply_msg = | 80 context->reply_msg = |
90 PpapiPluginMsg_BrowserFontSingleton_GetFontFamiliesReply(output); | 81 PpapiPluginMsg_TrueTypeFontSingleton_GetFontFamiliesReply(font_families); |
91 return PP_OK; | 82 return result; |
92 } | 83 } |
93 | 84 |
94 } // namespace | 85 } // namespace |
95 | 86 |
96 PepperBrowserFontSingletonHost::PepperBrowserFontSingletonHost( | 87 PepperTrueTypeFontListHost::PepperTrueTypeFontListHost( |
97 BrowserPpapiHost* host, | 88 BrowserPpapiHost* host, |
98 PP_Instance instance, | 89 PP_Instance instance, |
99 PP_Resource resource) | 90 PP_Resource resource) |
100 : ResourceHost(host->GetPpapiHost(), instance, resource) { | 91 : ResourceHost(host->GetPpapiHost(), instance, resource) { |
101 AddFilter(scoped_refptr<ppapi::host::ResourceMessageFilter>( | 92 AddFilter(scoped_refptr<ppapi::host::ResourceMessageFilter>( |
102 new FontMessageFilter())); | 93 new FontMessageFilter())); |
103 } | 94 } |
104 | 95 |
105 PepperBrowserFontSingletonHost::~PepperBrowserFontSingletonHost() { | 96 PepperTrueTypeFontListHost::~PepperTrueTypeFontListHost() { |
106 } | 97 } |
107 | 98 |
108 } // namespace content | 99 } // namespace content |
OLD | NEW |