This source file includes following definitions.
- OverrideTaskRunnerForMessage
- OnResourceMessageReceived
- OnHostMsgGetFontFamilies
- OnHostMsgGetFontsInFamily
#include "content/browser/renderer_host/pepper/pepper_truetype_font_list_host.h"
#include <algorithm>
#include "base/numerics/safe_conversions.h"
#include "base/threading/sequenced_worker_pool.h"
#include "content/browser/renderer_host/pepper/pepper_truetype_font_list.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/host_message_context.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);
int32_t OnHostMsgGetFontsInFamily(ppapi::host::HostMessageContext* context,
const std::string& family);
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_TrueTypeFontSingleton_GetFontFamilies,
OnHostMsgGetFontFamilies)
PPAPI_DISPATCH_HOST_RESOURCE_CALL(
PpapiHostMsg_TrueTypeFontSingleton_GetFontsInFamily,
OnHostMsgGetFontsInFamily)
IPC_END_MESSAGE_MAP()
return PP_ERROR_FAILED;
}
int32_t FontMessageFilter::OnHostMsgGetFontFamilies(
ppapi::host::HostMessageContext* context) {
std::vector<std::string> font_families;
GetFontFamilies_SlowBlocking(&font_families);
std::sort(font_families.begin(), font_families.end());
context->reply_msg =
PpapiPluginMsg_TrueTypeFontSingleton_GetFontFamiliesReply(font_families);
return base::checked_cast<int32_t>(font_families.size());
}
int32_t FontMessageFilter::OnHostMsgGetFontsInFamily(
ppapi::host::HostMessageContext* context,
const std::string& family) {
std::vector<ppapi::proxy::SerializedTrueTypeFontDesc> fonts_in_family;
GetFontsInFamily_SlowBlocking(family, &fonts_in_family);
context->reply_msg =
PpapiPluginMsg_TrueTypeFontSingleton_GetFontsInFamilyReply(
fonts_in_family);
return base::checked_cast<int32_t>(fonts_in_family.size());
}
}
PepperTrueTypeFontListHost::PepperTrueTypeFontListHost(
BrowserPpapiHost* host,
PP_Instance instance,
PP_Resource resource)
: ResourceHost(host->GetPpapiHost(), instance, resource) {
AddFilter(scoped_refptr<ppapi::host::ResourceMessageFilter>(
new FontMessageFilter()));
}
PepperTrueTypeFontListHost::~PepperTrueTypeFontListHost() {
}
}