summaryrefslogtreecommitdiffstats
path: root/ppapi/proxy/flash_font_file_resource.h
blob: 5bc633a4fe6fe58a9b8f480bbc9a4449ddd41e7b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright (c) 2012 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.

#ifndef PPAPI_PROXY_FLASH_FONT_FILE_RESOURCE_H_
#define PPAPI_PROXY_FLASH_FONT_FILE_RESOURCE_H_

#include <map>
#include <string>

#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/memory/linked_ptr.h"
#include "ppapi/c/private/pp_private_font_charset.h"
#include "ppapi/proxy/plugin_resource.h"
#include "ppapi/proxy/serialized_structs.h"
#include "ppapi/thunk/ppb_flash_font_file_api.h"

struct PP_BrowserFont_Trusted_Description;

namespace ppapi {
namespace proxy {

// TODO(yzshen): write unittest and browser test.
class FlashFontFileResource : public PluginResource,
                              public thunk::PPB_Flash_FontFile_API {
 public:
  FlashFontFileResource(Connection connection,
                        PP_Instance instance,
                        const PP_BrowserFont_Trusted_Description* description,
                        PP_PrivateFontCharset charset);
  virtual ~FlashFontFileResource();

  // Resource overrides.
  virtual thunk::PPB_Flash_FontFile_API* AsPPB_Flash_FontFile_API() OVERRIDE;

  // PPB_Flash_FontFile_API.
  virtual PP_Bool GetFontTable(uint32_t table,
                               void* output,
                               uint32_t* output_length) OVERRIDE;

 private:
  // Sees if we have a cache of the font table and returns a pointer to it.
  // Returns NULL if we don't have it.
  std::string* GetFontTable(uint32_t table) const;

  std::string* AddFontTable(uint32_t table, const std::string& contents);

  typedef std::map<uint32_t, linked_ptr<std::string> > FontTableMap;
  FontTableMap font_tables_;

  SerializedFontDescription description_;
  PP_PrivateFontCharset charset_;

  DISALLOW_COPY_AND_ASSIGN(FlashFontFileResource);
};

}  // namespace proxy
}  // namespace ppapi

#endif  // PPAPI_PROXY_FLASH_FONT_FILE_RESOURCE_H_