1// Copyright 2014 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 CONTENT_BROWSER_RENDERER_HOST_PEPPER_PEPPER_TRUETYPE_FONT_HOST_H_
6#define CONTENT_BROWSER_RENDERER_HOST_PEPPER_PEPPER_TRUETYPE_FONT_HOST_H_
7
8#include <string>
9#include <vector>
10
11#include "base/compiler_specific.h"
12#include "base/memory/scoped_ptr.h"
13#include "base/memory/weak_ptr.h"
14#include "base/sequenced_task_runner.h"
15#include "content/browser/renderer_host/pepper/pepper_truetype_font.h"
16#include "content/common/content_export.h"
17#include "ppapi/host/host_message_context.h"
18#include "ppapi/host/resource_host.h"
19
20namespace content {
21
22class BrowserPpapiHost;
23
24class CONTENT_EXPORT PepperTrueTypeFontHost : public ppapi::host::ResourceHost {
25 public:
26  PepperTrueTypeFontHost(BrowserPpapiHost* host,
27                         PP_Instance instance,
28                         PP_Resource resource,
29                         const ppapi::proxy::SerializedTrueTypeFontDesc& desc);
30
31  virtual ~PepperTrueTypeFontHost();
32
33  virtual int32_t OnResourceMessageReceived(
34      const IPC::Message& msg,
35      ppapi::host::HostMessageContext* context) OVERRIDE;
36
37 private:
38  int32_t OnHostMsgGetTableTags(ppapi::host::HostMessageContext* context);
39  int32_t OnHostMsgGetTable(ppapi::host::HostMessageContext* context,
40                            uint32_t table,
41                            int32_t offset,
42                            int32_t max_data_length);
43
44  void OnInitializeComplete(ppapi::proxy::SerializedTrueTypeFontDesc* desc,
45                            int32_t result);
46  void OnGetTableTagsComplete(std::vector<uint32_t>* tags,
47                              ppapi::host::ReplyMessageContext reply_context,
48                              int32_t result);
49  void OnGetTableComplete(std::string* data,
50                          ppapi::host::ReplyMessageContext reply_context,
51                          int32_t result);
52
53  // We use a SequencedTaskRunner to run potentially slow font operations and
54  // ensure that Initialize completes before we make any calls to get font data.
55  // Even though we allow multiple pending GetTableTags and GetTable calls, this
56  // implies that they run serially.
57  scoped_refptr<base::SequencedTaskRunner> task_runner_;
58
59  scoped_refptr<PepperTrueTypeFont> font_;
60  bool initialize_completed_;
61
62  base::WeakPtrFactory<PepperTrueTypeFontHost> weak_factory_;
63
64  DISALLOW_COPY_AND_ASSIGN(PepperTrueTypeFontHost);
65};
66
67}  // namespace content
68
69#endif  // CONTENT_BROWSER_RENDERER_HOST_PEPPER_PEPPER_TRUETYPE_FONT_HOST_H_
70