OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "content/browser/renderer_host/pepper/pepper_browser_font_singleton_hos t.h" | |
6 | |
7 #include "base/threading/sequenced_worker_pool.h" | |
8 #include "base/values.h" | |
9 #include "content/common/font_list.h" | |
10 #include "content/public/browser/browser_ppapi_host.h" | |
11 #include "content/public/browser/browser_thread.h" | |
12 #include "ppapi/host/dispatch_host_message.h" | |
13 #include "ppapi/proxy/ppapi_messages.h" | |
14 | |
15 namespace content { | |
16 | |
17 namespace { | |
18 | |
19 // Handles the font list request on the blocking pool. | |
20 class FontMessageFilter : public ppapi::host::ResourceMessageFilter { | |
21 public: | |
22 FontMessageFilter(); | |
23 | |
24 // ppapi::host::ResourceMessageFilter implementation. | |
25 virtual scoped_refptr<base::TaskRunner> OverrideTaskRunnerForMessage( | |
26 const IPC::Message& msg) OVERRIDE; | |
27 virtual int32_t OnResourceMessageReceived( | |
28 const IPC::Message& msg, | |
29 ppapi::host::HostMessageContext* context) OVERRIDE; | |
30 | |
31 private: | |
32 virtual ~FontMessageFilter(); | |
33 | |
34 // Message handler. | |
35 int32_t OnHostMsgGetFontFamilies(ppapi::host::HostMessageContext* context); | |
36 | |
37 DISALLOW_COPY_AND_ASSIGN(FontMessageFilter); | |
38 }; | |
39 | |
40 FontMessageFilter::FontMessageFilter() { | |
41 } | |
42 | |
43 FontMessageFilter::~FontMessageFilter() { | |
44 } | |
45 | |
46 scoped_refptr<base::TaskRunner> FontMessageFilter::OverrideTaskRunnerForMessage( | |
47 const IPC::Message& msg) { | |
48 // Use the blocking pool to get the font list (currently the only message | |
49 // so we can always just return it). | |
50 return scoped_refptr<base::TaskRunner>(BrowserThread::GetBlockingPool()); | |
51 } | |
52 | |
53 int32_t FontMessageFilter::OnResourceMessageReceived( | |
54 const IPC::Message& msg, | |
55 ppapi::host::HostMessageContext* context) { | |
56 IPC_BEGIN_MESSAGE_MAP(FontMessageFilter, msg) | |
57 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0( | |
58 PpapiHostMsg_BrowserFontSingleton_GetFontFamilies, | |
59 OnHostMsgGetFontFamilies) | |
60 IPC_END_MESSAGE_MAP() | |
61 return PP_ERROR_FAILED; | |
62 } | |
63 | |
64 int32_t FontMessageFilter::OnHostMsgGetFontFamilies( | |
65 ppapi::host::HostMessageContext* context) { | |
66 // OK to use "slow blocking" version since we're on the blocking pool. | |
67 scoped_ptr<base::ListValue> list(GetFontList_SlowBlocking()); | |
68 | |
69 std::string output; | |
70 for (size_t i = 0; i < list->GetSize(); i++) { | |
71 base::ListValue* cur_font; | |
72 if (!list->GetList(i, &cur_font)) | |
73 continue; | |
74 | |
75 // Each entry is actually a list of (font name, localized name). | |
76 // We only care about the regular name. | |
77 std::string font_name; | |
78 if (!cur_font->GetString(0, &font_name)) | |
79 continue; | |
80 | |
81 // Font names are separated with nulls. We also want an explicit null at | |
82 // the end of the string (Pepper strings aren't null terminated so since | |
83 // we specify there will be a null, it should actually be in the string). | |
84 output.append(font_name); | |
85 output.push_back(0); | |
86 } | |
87 | |
88 ppapi::host::ReplyMessageContext reply_context = | |
89 context->MakeReplyMessageContext(); | |
90 SendReply(reply_context, | |
91 PpapiPluginMsg_BrowserFontSingleton_GetFontFamiliesReply( | |
92 output)); | |
93 return PP_OK_COMPLETIONPENDING; | |
raymes
2012/12/17 00:08:29
You can actually change the above few lines to:
co
| |
94 } | |
95 | |
96 } // namespace | |
97 | |
98 PepperBrowserFontSingletonHost::PepperBrowserFontSingletonHost( | |
raymes
2012/12/17 00:08:29
We seem to be having this pattern quite a lot wher
| |
99 BrowserPpapiHost* host, | |
100 PP_Instance instance, | |
101 PP_Resource resource) | |
102 : ResourceHost(host->GetPpapiHost(), instance, resource) { | |
103 AddFilter(scoped_refptr<ppapi::host::ResourceMessageFilter>( | |
104 new FontMessageFilter())); | |
105 } | |
106 | |
107 PepperBrowserFontSingletonHost::~PepperBrowserFontSingletonHost() { | |
108 } | |
109 | |
110 } // namespace content | |
OLD | NEW |