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

Side by Side Diff: content/browser/renderer_host/pepper/pepper_browser_font_singleton_host.cc

Issue 11578038: Convert pepper font list to new resource system. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merged Created 8 years 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
OLDNEW
(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/host/resource_message_filter.h"
14 #include "ppapi/proxy/ppapi_messages.h"
15
16 namespace content {
17
18 namespace {
19
20 // Handles the font list request on the blocking pool.
21 class FontMessageFilter : public ppapi::host::ResourceMessageFilter {
22 public:
23 FontMessageFilter();
24
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;
31
32 private:
33 virtual ~FontMessageFilter();
34
35 // Message handler.
36 int32_t OnHostMsgGetFontFamilies(ppapi::host::HostMessageContext* context);
37
38 DISALLOW_COPY_AND_ASSIGN(FontMessageFilter);
39 };
40
41 FontMessageFilter::FontMessageFilter() {
42 }
43
44 FontMessageFilter::~FontMessageFilter() {
45 }
46
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 // so we can always just return it).
51 return scoped_refptr<base::TaskRunner>(BrowserThread::GetBlockingPool());
52 }
53
54 int32_t FontMessageFilter::OnResourceMessageReceived(
55 const IPC::Message& msg,
56 ppapi::host::HostMessageContext* context) {
57 IPC_BEGIN_MESSAGE_MAP(FontMessageFilter, msg)
58 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(
59 PpapiHostMsg_BrowserFontSingleton_GetFontFamilies,
60 OnHostMsgGetFontFamilies)
61 IPC_END_MESSAGE_MAP()
62 return PP_ERROR_FAILED;
63 }
64
65 int32_t FontMessageFilter::OnHostMsgGetFontFamilies(
66 ppapi::host::HostMessageContext* context) {
67 // OK to use "slow blocking" version since we're on the blocking pool.
68 scoped_ptr<base::ListValue> list(GetFontList_SlowBlocking());
69
70 std::string output;
71 for (size_t i = 0; i < list->GetSize(); i++) {
72 base::ListValue* cur_font;
73 if (!list->GetList(i, &cur_font))
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 =
90 PpapiPluginMsg_BrowserFontSingleton_GetFontFamiliesReply(output);
91 return PP_OK;
92 }
93
94 } // namespace
95
96 PepperBrowserFontSingletonHost::PepperBrowserFontSingletonHost(
97 BrowserPpapiHost* host,
98 PP_Instance instance,
99 PP_Resource resource)
100 : ResourceHost(host->GetPpapiHost(), instance, resource) {
101 AddFilter(scoped_refptr<ppapi::host::ResourceMessageFilter>(
102 new FontMessageFilter()));
103 }
104
105 PepperBrowserFontSingletonHost::~PepperBrowserFontSingletonHost() {
106 }
107
108 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698