This source file includes following definitions.
- OverrideTaskRunnerForMessage
- OnResourceMessageReceived
- OnHostMsgGetFontFamilies
#include "content/browser/renderer_host/pepper/pepper_browser_font_singleton_host.h"
#include "base/threading/sequenced_worker_pool.h"
#include "base/values.h"
#include "content/common/font_list.h"
#include "content/public/browser/browser_ppapi_host.h"
#include "content/public/browser/browser_thread.h"
#include "ppapi/host/dispatch_host_message.h"
#include "ppapi/host/resource_message_filter.h"
#include "ppapi/proxy/ppapi_messages.h"
namespace content {
namespace {
class FontMessageFilter : public ppapi::host::ResourceMessageFilter {
public:
FontMessageFilter();
virtual scoped_refptr<base::TaskRunner> OverrideTaskRunnerForMessage(
const IPC::Message& msg) OVERRIDE;
virtual int32_t OnResourceMessageReceived(
const IPC::Message& msg,
ppapi::host::HostMessageContext* context) OVERRIDE;
private:
virtual ~FontMessageFilter();
int32_t OnHostMsgGetFontFamilies(ppapi::host::HostMessageContext* context);
DISALLOW_COPY_AND_ASSIGN(FontMessageFilter);
};
FontMessageFilter::FontMessageFilter() {
}
FontMessageFilter::~FontMessageFilter() {
}
scoped_refptr<base::TaskRunner> FontMessageFilter::OverrideTaskRunnerForMessage(
const IPC::Message& msg) {
base::SequencedWorkerPool* pool = BrowserThread::GetBlockingPool();
return pool->GetSequencedTaskRunner(
pool->GetNamedSequenceToken(kFontListSequenceToken));
}
int32_t FontMessageFilter::OnResourceMessageReceived(
const IPC::Message& msg,
ppapi::host::HostMessageContext* context) {
IPC_BEGIN_MESSAGE_MAP(FontMessageFilter, msg)
PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(
PpapiHostMsg_BrowserFontSingleton_GetFontFamilies,
OnHostMsgGetFontFamilies)
IPC_END_MESSAGE_MAP()
return PP_ERROR_FAILED;
}
int32_t FontMessageFilter::OnHostMsgGetFontFamilies(
ppapi::host::HostMessageContext* context) {
scoped_ptr<base::ListValue> list(GetFontList_SlowBlocking());
std::string output;
for (size_t i = 0; i < list->GetSize(); i++) {
base::ListValue* cur_font;
if (!list->GetList(i, &cur_font))
continue;
std::string font_name;
if (!cur_font->GetString(0, &font_name))
continue;
output.append(font_name);
output.push_back(0);
}
context->reply_msg =
PpapiPluginMsg_BrowserFontSingleton_GetFontFamiliesReply(output);
return PP_OK;
}
}
PepperBrowserFontSingletonHost::PepperBrowserFontSingletonHost(
BrowserPpapiHost* host,
PP_Instance instance,
PP_Resource resource)
: ResourceHost(host->GetPpapiHost(), instance, resource) {
AddFilter(scoped_refptr<ppapi::host::ResourceMessageFilter>(
new FontMessageFilter()));
}
PepperBrowserFontSingletonHost::~PepperBrowserFontSingletonHost() {
}
}