Simplify ChildProcessLauncher
[chromium-blink-merge.git] / content / browser / renderer_host / pepper / pepper_browser_font_singleton_host.cc
blobe2c909c9ae5ebdde1db0a3715c80b4cbeca7959c
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.
5 #include "content/browser/renderer_host/pepper/pepper_browser_font_singleton_host.h"
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/host/resource_message_filter.h"
14 #include "ppapi/proxy/ppapi_messages.h"
16 namespace content {
18 namespace {
20 // Handles the font list request on the blocking pool.
21 class FontMessageFilter : public ppapi::host::ResourceMessageFilter {
22 public:
23 FontMessageFilter();
25 // ppapi::host::ResourceMessageFilter implementation.
26 scoped_refptr<base::TaskRunner> OverrideTaskRunnerForMessage(
27 const IPC::Message& msg) override;
28 int32_t OnResourceMessageReceived(
29 const IPC::Message& msg,
30 ppapi::host::HostMessageContext* context) override;
32 private:
33 ~FontMessageFilter() override;
35 // Message handler.
36 int32_t OnHostMsgGetFontFamilies(ppapi::host::HostMessageContext* context);
38 DISALLOW_COPY_AND_ASSIGN(FontMessageFilter);
41 FontMessageFilter::FontMessageFilter() {}
43 FontMessageFilter::~FontMessageFilter() {}
45 scoped_refptr<base::TaskRunner> FontMessageFilter::OverrideTaskRunnerForMessage(
46 const IPC::Message& msg) {
47 // Use the blocking pool to get the font list (currently the only message)
48 // Since getting the font list is non-threadsafe on Linux (for versions of
49 // Pango predating 2013), use a sequenced task runner.
50 base::SequencedWorkerPool* pool = BrowserThread::GetBlockingPool();
51 return pool->GetSequencedTaskRunner(
52 pool->GetNamedSequenceToken(kFontListSequenceToken));
55 int32_t FontMessageFilter::OnResourceMessageReceived(
56 const IPC::Message& msg,
57 ppapi::host::HostMessageContext* context) {
58 PPAPI_BEGIN_MESSAGE_MAP(FontMessageFilter, msg)
59 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(
60 PpapiHostMsg_BrowserFontSingleton_GetFontFamilies,
61 OnHostMsgGetFontFamilies)
62 PPAPI_END_MESSAGE_MAP()
63 return PP_ERROR_FAILED;
66 int32_t FontMessageFilter::OnHostMsgGetFontFamilies(
67 ppapi::host::HostMessageContext* context) {
68 // OK to use "slow blocking" version since we're on the blocking pool.
69 scoped_ptr<base::ListValue> list(GetFontList_SlowBlocking());
71 std::string output;
72 for (size_t i = 0; i < list->GetSize(); i++) {
73 base::ListValue* cur_font;
74 if (!list->GetList(i, &cur_font))
75 continue;
77 // Each entry is actually a list of (font name, localized name).
78 // We only care about the regular name.
79 std::string font_name;
80 if (!cur_font->GetString(0, &font_name))
81 continue;
83 // Font names are separated with nulls. We also want an explicit null at
84 // the end of the string (Pepper strings aren't null terminated so since
85 // we specify there will be a null, it should actually be in the string).
86 output.append(font_name);
87 output.push_back(0);
90 context->reply_msg =
91 PpapiPluginMsg_BrowserFontSingleton_GetFontFamiliesReply(output);
92 return PP_OK;
95 } // namespace
97 PepperBrowserFontSingletonHost::PepperBrowserFontSingletonHost(
98 BrowserPpapiHost* host,
99 PP_Instance instance,
100 PP_Resource resource)
101 : ResourceHost(host->GetPpapiHost(), instance, resource) {
102 AddFilter(scoped_refptr<ppapi::host::ResourceMessageFilter>(
103 new FontMessageFilter()));
106 PepperBrowserFontSingletonHost::~PepperBrowserFontSingletonHost() {}
108 } // namespace content