blob: 2c195bc09a6726983479aa364615d2599aced92e (
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
62
63
64
65
66
67
68
69
70
71
|
// Copyright (c) 2010 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_PLUGIN_RESOURCE_H_
#define PPAPI_PROXY_PLUGIN_RESOURCE_H_
#include "base/basictypes.h"
#include "ppapi/proxy/plugin_dispatcher.h"
#include "ppapi/proxy/plugin_resource_tracker.h"
// If you inherit from resource, make sure you add the class name here.
#define FOR_ALL_RESOURCES(F) \
F(Audio) \
F(AudioConfig) \
F(Buffer) \
F(Font) \
F(Graphics2D) \
F(ImageData) \
F(PrivateFontFile) \
F(URLLoader) \
F(URLRequestInfo)\
F(URLResponseInfo)
namespace pp {
namespace proxy {
// Forward declaration of Resource classes.
#define DECLARE_RESOURCE_CLASS(RESOURCE) class RESOURCE;
FOR_ALL_RESOURCES(DECLARE_RESOURCE_CLASS)
#undef DECLARE_RESOURCE_CLASS
class PluginResource {
public:
PluginResource();
virtual ~PluginResource();
// Returns NULL if the resource is invalid or is a different type.
template<typename T> static T* GetAs(PP_Resource res) {
PluginResource* resource =
PluginDispatcher::Get()->plugin_resource_tracker()->GetResourceObject(
res);
return resource ? resource->Cast<T>() : NULL;
}
template <typename T> T* Cast() { return NULL; }
private:
// Type-specific getters for individual resource types. These will return
// NULL if the resource does not match the specified type. Used by the Cast()
// function.
#define DEFINE_TYPE_GETTER(RESOURCE) \
virtual RESOURCE* As##RESOURCE();
FOR_ALL_RESOURCES(DEFINE_TYPE_GETTER)
#undef DEFINE_TYPE_GETTER
DISALLOW_COPY_AND_ASSIGN(PluginResource);
};
// Cast() specializations.
#define DEFINE_RESOURCE_CAST(Type) \
template <> inline Type* PluginResource::Cast<Type>() { \
return As##Type(); \
}
FOR_ALL_RESOURCES(DEFINE_RESOURCE_CAST)
#undef DEFINE_RESOURCE_CAST
} // namespace proxy
} // namespace pp
#endif // PPAPI_PROXY_PLUGIN_RESOURCE_H_
|