1// Copyright (c) 2013 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#ifndef PPAPI_PROXY_TRUETYPE_FONT_RESOURCE_H_
6#define PPAPI_PROXY_TRUETYPE_FONT_RESOURCE_H_
7
8#include <queue>
9#include <string>
10
11#include "ppapi/proxy/connection.h"
12#include "ppapi/proxy/plugin_resource.h"
13#include "ppapi/proxy/ppapi_proxy_export.h"
14#include "ppapi/proxy/serialized_structs.h"
15#include "ppapi/shared_impl/var.h"
16#include "ppapi/thunk/ppb_truetype_font_api.h"
17
18namespace ppapi {
19
20class TrackedCallback;
21
22namespace proxy {
23
24struct SerializedTrueTypeFontDesc;
25
26class PPAPI_PROXY_EXPORT TrueTypeFontResource
27    : public PluginResource,
28      public thunk::PPB_TrueTypeFont_API {
29 public:
30  TrueTypeFontResource(Connection connection,
31                       PP_Instance instance,
32                       const PP_TrueTypeFontDesc_Dev& desc);
33  virtual ~TrueTypeFontResource();
34
35  // Resource implementation.
36  virtual thunk::PPB_TrueTypeFont_API* AsPPB_TrueTypeFont_API() OVERRIDE;
37
38  // PPB_TrueTypeFont_API implementation.
39  virtual int32_t Describe(
40      PP_TrueTypeFontDesc_Dev* desc,
41      scoped_refptr<TrackedCallback> callback) OVERRIDE;
42  virtual int32_t GetTableTags(
43      const PP_ArrayOutput& output,
44      scoped_refptr<TrackedCallback> callback) OVERRIDE;
45  virtual int32_t GetTable(
46      uint32_t table,
47      int32_t offset,
48      int32_t max_data_length,
49      const PP_ArrayOutput& output,
50      scoped_refptr<TrackedCallback> callback) OVERRIDE;
51
52  // PluginResource implementation.
53  virtual void OnReplyReceived(const ResourceMessageReplyParams& params,
54                               const IPC::Message& msg) OVERRIDE;
55
56 private:
57  void OnPluginMsgCreateComplete(
58      const ResourceMessageReplyParams& params,
59      const ppapi::proxy::SerializedTrueTypeFontDesc& desc,
60      int32_t result);
61  void OnPluginMsgGetTableTagsComplete(
62      scoped_refptr<TrackedCallback> callback,
63      PP_ArrayOutput array_output,
64      const ResourceMessageReplyParams& params,
65      const std::vector<uint32_t>& data);
66  void OnPluginMsgGetTableComplete(
67      scoped_refptr<TrackedCallback> callback,
68      PP_ArrayOutput array_output,
69      const ResourceMessageReplyParams& params,
70      const std::string& data);
71
72  int32_t create_result_;
73  // Valid only when create_result_ == PP_OK.
74  ppapi::proxy::SerializedTrueTypeFontDesc desc_;
75
76  // Params for pending Describe call.
77  PP_TrueTypeFontDesc_Dev* describe_desc_;
78  scoped_refptr<TrackedCallback> describe_callback_;
79
80  DISALLOW_COPY_AND_ASSIGN(TrueTypeFontResource);
81};
82
83}  // namespace proxy
84}  // namespace ppapi
85
86#endif  // PPAPI_PROXY_TRUETYPE_FONT_RESOURCE_H_
87