Index: content/common/fontmgr_messages.h |
=================================================================== |
--- content/common/fontmgr_messages.h (revision 0) |
+++ content/common/fontmgr_messages.h (working copy) |
@@ -0,0 +1,166 @@ |
+// 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. |
+ |
+// IPC messages for font discovery. |
+// Multiply-included message file, hence no include guard. |
+ |
+#include <string> |
+ |
+#include "content/common/content_export.h" |
+#include "content/common/content_param_traits.h" |
+#include "content/public/common/common_param_traits.h" |
+#include "ipc/ipc_message_macros.h" |
+#include "skia/ext/refptr.h" |
+#include "third_party/skia/include/core/SkDataTable.h" |
+#include "third_party/skia/include/core/SkStream.h" |
+#include "third_party/skia/include/ports/SkFontStyle.h" |
+#include "third_party/skia/include/ports/SkRemotableFontMgr.h" |
+ |
+#undef IPC_MESSAGE_EXPORT |
+#define IPC_MESSAGE_EXPORT CONTENT_EXPORT |
+ |
+#ifdef IPC_MESSAGE_START |
+#error IPC_MESSAGE_START |
+#endif |
+ |
+#define IPC_MESSAGE_START FontMsgStart |
+ |
+#ifndef CONTENT_COMMON_FONTMGR_MESSAGES_H_ |
+#define CONTENT_COMMON_FONTMGR_MESSAGES_H_ |
+ |
+namespace IPC { |
+ |
+template<class T> |
+class Optional { |
+ public: |
+ Optional() : set_(false) {} |
+ |
+ void emplace(const T& value) { |
+ value_ = value; |
+ set_ = true; |
+ } |
+ |
+ void setHasValue() { set_ = true; } |
+ |
+ const T& value() const { return value_; } |
+ T& value() { return value_; } |
+ |
+ const T* operator->() const { return &value_; } |
+ T* operator->() { return &value_; } |
+ const T& operator*() const { return value_ } |
+ T& operator*() { return value_ } |
+ |
+ typedef bool Optional::*unspecified_bool_type; |
+ operator unspecified_bool_type() const { |
+ return set_ ? &Optional::set_ : NULL; |
+ } |
+ |
+ private: |
+ bool set_; |
+ T value_; |
+}; |
+ |
+template <class P> |
+struct ParamTraits<Optional<P> > { |
+ typedef Optional<P> param_type; |
+ static void Write(Message* m, const param_type& p) { |
+ m->WriteBool(p); |
+ if (p) |
+ WriteParam(m, p.value()); |
+ } |
+ static bool Read(const Message* m, PickleIterator* iter, param_type* r) { |
+ bool has_value; |
+ if (!m->ReadBool(iter, &has_value)) |
+ return false; |
+ |
+ if (has_value) { |
+ if (!ReadParam(m, iter, &r->value())) |
+ return false; |
+ r->setHasValue(); |
+ } |
+ return true; |
+ } |
+ static void Log(const param_type& p, std::string* l) { |
+ l->append(p ? "Optional (has value)" : "Optional (no value)"); |
+ if (p) |
+ LogParam(p.value(), l); |
+ } |
+}; |
+ |
+// SkStream is not default constructable, no ParamTraits<T>. |
+template<> |
+struct ParamTraits<skia::RefPtr<SkStreamAsset> > { |
+ typedef skia::RefPtr<SkStreamAsset> param_type; |
+ static void Write(Message* m, const param_type& p); |
+ static bool Read(const Message* m, PickleIterator* iter, param_type* r); |
+ static void Log(const param_type& p, std::string* l); |
+}; |
+ |
+// SkDataTable is not default constructable, no ParamTraits<T>. |
+template<> |
+struct ParamTraits<skia::RefPtr<SkDataTable> > { |
+ typedef skia::RefPtr<SkDataTable> param_type; |
+ static void Write(Message* m, const param_type& p); |
+ static bool Read(const Message* m, PickleIterator* iter, param_type* r); |
+ static void Log(const param_type& p, std::string* l); |
+}; |
+ |
+// SkRemotableFontIdentitySet not default constructable, no ParamTraits<T>. |
+template<> |
+struct ParamTraits<skia::RefPtr<SkRemotableFontIdentitySet> > { |
+ typedef skia::RefPtr<SkRemotableFontIdentitySet> param_type; |
+ static void Write(Message* m, const param_type& p); |
+ static bool Read(const Message* m, PickleIterator* iter, param_type* r); |
+ static void Log(const param_type& p, std::string* l); |
+}; |
+ |
+template<> |
+struct ParamTraits<SkFontStyle> { |
+ typedef SkFontStyle param_type; |
+ static void Write(Message* m, const param_type& p); |
+ static bool Read(const Message* m, PickleIterator* iter, param_type* r); |
+ static void Log(const param_type& p, std::string* l); |
+}; |
+ |
+} // namespace IPC |
+ |
+#endif // CONTENT_COMMON_FONTMGR_MESSAGES_H_ |
+ |
+IPC_STRUCT_TRAITS_BEGIN(SkFontIdentity) |
+ IPC_STRUCT_TRAITS_MEMBER(fDataId) |
+ IPC_STRUCT_TRAITS_MEMBER(fTtcIndex) |
+ IPC_STRUCT_TRAITS_MEMBER(fFontStyle) |
+IPC_STRUCT_TRAITS_END() |
+ |
+IPC_SYNC_MESSAGE_ROUTED0_1(FontMsg_GetFamilyNames, |
+ skia::RefPtr<SkDataTable> /*family_names*/) |
+ |
+IPC_SYNC_MESSAGE_ROUTED1_1(FontMsg_GetIndex, |
+ int /*family_index*/, |
+ skia::RefPtr<SkRemotableFontIdentitySet> /*styles*/) |
+ |
+IPC_SYNC_MESSAGE_ROUTED2_1(FontMsg_MatchIndexStyle, |
+ int /*family_index*/, |
+ SkFontStyle /*style*/, |
+ SkFontIdentity /*identity*/) |
+ |
+IPC_SYNC_MESSAGE_ROUTED1_1(FontMsg_MatchName, |
+ IPC::Optional<std::string> /*family_name*/, |
+ skia::RefPtr<SkRemotableFontIdentitySet> /*styles*/) |
+ |
+IPC_SYNC_MESSAGE_ROUTED2_1(FontMsg_MatchNameStyle, |
+ IPC::Optional<std::string> /*family_name*/, |
+ SkFontStyle /*style*/, |
+ SkFontIdentity /*identity*/) |
+ |
+IPC_SYNC_MESSAGE_ROUTED4_1(FontMsg_MatchNameStyleCharacter, |
+ IPC::Optional<std::string> /*family_name*/, |
+ SkFontStyle /*style*/, |
+ IPC::Optional<std::string> /*bpc47*/, |
+ uint32_t /*character*/, |
+ SkFontIdentity /*identity*/) |
+ |
+IPC_SYNC_MESSAGE_ROUTED1_1(FontMsg_GetData, |
+ int /*data_id*/, |
+ skia::RefPtr<SkStreamAsset> /* font_data */) |