Ignore non-active fullscreen windows for shelf state.
[chromium-blink-merge.git] / content / browser / renderer_host / pepper / pepper_browser_font_singleton_host.cc
blob99a8e04fc7031a14d9ee43509cfc326b59406d8a
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 virtual scoped_refptr<base::TaskRunner> OverrideTaskRunnerForMessage(
27 const IPC::Message& msg) OVERRIDE;
28 virtual int32_t OnResourceMessageReceived(
29 const IPC::Message& msg,
30 ppapi::host::HostMessageContext* context) OVERRIDE;
32 private:
33 virtual ~FontMessageFilter();
35 // Message handler.
36 int32_t OnHostMsgGetFontFamilies(ppapi::host::HostMessageContext* context);
38 DISALLOW_COPY_AND_ASSIGN(FontMessageFilter);
41 FontMessageFilter::FontMessageFilter() {
44 FontMessageFilter::~FontMessageFilter() {
47 scoped_refptr<base::TaskRunner> FontMessageFilter::OverrideTaskRunnerForMessage(
48 const IPC::Message& msg) {
49 // Use the blocking pool to get the font list (currently the only message)
50 // Since getting the font list is non-threadsafe on Linux (for versions of
51 // Pango predating 2013), use a sequenced task runner.
52 base::SequencedWorkerPool* pool = BrowserThread::GetBlockingPool();
53 return pool->GetSequencedTaskRunner(
54 pool->GetNamedSequenceToken(kFontListSequenceToken));
57 int32_t FontMessageFilter::OnResourceMessageReceived(
58 const IPC::Message& msg,
59 ppapi::host::HostMessageContext* context) {
60 IPC_BEGIN_MESSAGE_MAP(FontMessageFilter, msg)
61 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(
62 PpapiHostMsg_BrowserFontSingleton_GetFontFamilies,
63 OnHostMsgGetFontFamilies)
64 IPC_END_MESSAGE_MAP()
65 return PP_ERROR_FAILED;
68 int32_t FontMessageFilter::OnHostMsgGetFontFamilies(
69 ppapi::host::HostMessageContext* context) {
70 // OK to use "slow blocking" version since we're on the blocking pool.
71 scoped_ptr<base::ListValue> list(GetFontList_SlowBlocking());
73 std::string output;
74 for (size_t i = 0; i < list->GetSize(); i++) {
75 base::ListValue* cur_font;
76 if (!list->GetList(i, &cur_font))
77 continue;
79 // Each entry is actually a list of (font name, localized name).
80 // We only care about the regular name.
81 std::string font_name;
82 if (!cur_font->GetString(0, &font_name))
83 continue;
85 // Font names are separated with nulls. We also want an explicit null at
86 // the end of the string (Pepper strings aren't null terminated so since
87 // we specify there will be a null, it should actually be in the string).
88 output.append(font_name);
89 output.push_back(0);
92 context->reply_msg =
93 PpapiPluginMsg_BrowserFontSingleton_GetFontFamiliesReply(output);
94 return PP_OK;
97 } // namespace
99 PepperBrowserFontSingletonHost::PepperBrowserFontSingletonHost(
100 BrowserPpapiHost* host,
101 PP_Instance instance,
102 PP_Resource resource)
103 : ResourceHost(host->GetPpapiHost(), instance, resource) {
104 AddFilter(scoped_refptr<ppapi::host::ResourceMessageFilter>(
105 new FontMessageFilter()));
108 PepperBrowserFontSingletonHost::~PepperBrowserFontSingletonHost() {
111 } // namespace content