Index: content/browser/renderer_host/fontmgr_message_filter.cc |
=================================================================== |
--- content/browser/renderer_host/fontmgr_message_filter.cc (revision 0) |
+++ content/browser/renderer_host/fontmgr_message_filter.cc (working copy) |
@@ -0,0 +1,103 @@ |
+// Copyright (c) 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "content/browser/renderer_host/fontmgr_message_filter.h" |
+ |
+#include "content/common/fontmgr_messages.h" |
+#include "ipc/ipc_message_macros.h" |
+#include "third_party/skia/include/core/SkDataTable.h" |
+#include "third_party/skia/include/core/SkStream.h" |
+#include "third_party/skia/include/ports/SkRemotableFontMgr.h" |
+#include "third_party/skia/include/ports/SkTypeface_win.h" |
+ |
+namespace content { |
+ |
+FontMgrMessageFilter::FontMgrMessageFilter( |
+ const skia::RefPtr<SkRemotableFontMgr>& font_manager) |
+ : BrowserMessageFilter(FontMsgStart), |
+ font_manager_(skia::SharePtr(font_manager.get())) { |
+} |
+ |
+bool FontMgrMessageFilter::OnMessageReceived(const IPC::Message& message, |
+ bool* message_was_ok) { |
+ bool handled = true; |
+ IPC_BEGIN_MESSAGE_MAP_EX(FontMgrMessageFilter, message, *message_was_ok) |
+ IPC_MESSAGE_HANDLER(FontMsg_GetFamilyNames, OnFontMsg_GetFamilyNames) |
+ IPC_MESSAGE_HANDLER(FontMsg_GetIndex, OnFontMsg_GetIndex) |
+ IPC_MESSAGE_HANDLER(FontMsg_MatchIndexStyle, OnFontMsg_MatchIndexStyle) |
+ IPC_MESSAGE_HANDLER(FontMsg_MatchName, OnFontMsg_MatchName) |
+ IPC_MESSAGE_HANDLER(FontMsg_MatchNameStyle, OnFontMsg_MatchNameStyle) |
+ IPC_MESSAGE_HANDLER(FontMsg_MatchNameStyleCharacter, |
+ OnFontMsg_MatchNameStyleCharacter) |
+ IPC_MESSAGE_HANDLER(FontMsg_GetData, OnFontMsg_GetData) |
+ IPC_MESSAGE_UNHANDLED(handled = false) |
+ IPC_END_MESSAGE_MAP_EX() |
+ return handled; |
+} |
+ |
+FontMgrMessageFilter::~FontMgrMessageFilter() { |
+} |
+ |
+void FontMgrMessageFilter::OnFontMsg_GetFamilyNames( |
+ skia::RefPtr<SkDataTable>* family_names) { |
+ *family_names = skia::AdoptRef(font_manager_->getFamilyNames()); |
+} |
+ |
+void FontMgrMessageFilter::OnFontMsg_GetIndex( |
+ int family_index, |
+ skia::RefPtr<SkRemotableFontIdentitySet>* styles) { |
+ *styles = skia::AdoptRef(font_manager_->getIndex(family_index)); |
+} |
+ |
+void FontMgrMessageFilter::OnFontMsg_MatchIndexStyle( |
+ int family_index, |
+ SkFontStyle style, |
+ SkFontIdentity* identity) { |
+ *identity = font_manager_->matchIndexStyle(family_index, style); |
+} |
+ |
+void FontMgrMessageFilter::OnFontMsg_MatchName( |
+ IPC::Optional<std::string> family_name_remotable, |
+ skia::RefPtr<SkRemotableFontIdentitySet>* styles) { |
+ const char* family_name = NULL; |
+ if (family_name_remotable) |
+ family_name = family_name_remotable->c_str(); |
+ *styles = skia::AdoptRef(font_manager_->matchName(family_name)); |
+} |
+ |
+void FontMgrMessageFilter::OnFontMsg_MatchNameStyle( |
+ IPC::Optional<std::string> family_name_remotable, |
+ SkFontStyle style, |
+ SkFontIdentity* identity) { |
+ const char* family_name = NULL; |
+ if (family_name_remotable) |
+ family_name = family_name_remotable->c_str(); |
+ *identity = font_manager_->matchNameStyle(family_name, style); |
+} |
+ |
+void FontMgrMessageFilter::OnFontMsg_MatchNameStyleCharacter( |
+ IPC::Optional<std::string> family_name_remotable, |
+ SkFontStyle style, |
+ IPC::Optional<std::string> bpc47_remotable, |
+ SkUnichar character, |
+ SkFontIdentity* identity) { |
+ const char* family_name = NULL; |
+ if (family_name_remotable) |
+ family_name = family_name_remotable->c_str(); |
+ const char* bpc47 = NULL; |
+ if (bpc47_remotable) |
+ bpc47 = bpc47_remotable->c_str(); |
+ *identity = font_manager_->matchNameStyleCharacter(family_name, |
+ style, |
+ bpc47, |
+ character); |
+} |
+ |
+void FontMgrMessageFilter::OnFontMsg_GetData( |
+ uint32_t data_id, |
+ skia::RefPtr<SkStreamAsset>* font_data) { |
+ *font_data = skia::AdoptRef(font_manager_->getData(data_id)); |
+} |
+ |
+} // namespace content |