OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef PPAPI_PROXY_PLUGIN_RESOURCE_H_ | 5 #ifndef PPAPI_PROXY_PLUGIN_RESOURCE_H_ |
6 #define PPAPI_PROXY_PLUGIN_RESOURCE_H_ | 6 #define PPAPI_PROXY_PLUGIN_RESOURCE_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "ppapi/proxy/plugin_dispatcher.h" | 9 #include "ppapi/proxy/plugin_dispatcher.h" |
10 #include "ppapi/proxy/plugin_resource_tracker.h" | 10 #include "ppapi/proxy/plugin_resource_tracker.h" |
11 | 11 |
12 // If you inherit from resource, make sure you add the class name here. | 12 // If you inherit from resource, make sure you add the class name here. |
13 #define FOR_ALL_RESOURCES(F) \ | 13 #define FOR_ALL_PLUGIN_RESOURCES(F) \ |
14 F(Audio) \ | 14 F(Audio) \ |
15 F(AudioConfig) \ | 15 F(AudioConfig) \ |
16 F(Buffer) \ | 16 F(Buffer) \ |
17 F(Font) \ | 17 F(Font) \ |
18 F(Graphics2D) \ | 18 F(Graphics2D) \ |
19 F(ImageData) \ | 19 F(ImageData) \ |
20 F(PrivateFontFile) \ | 20 F(PrivateFontFile) \ |
21 F(URLLoader) \ | 21 F(URLLoader) \ |
22 F(URLRequestInfo)\ | 22 F(URLRequestInfo)\ |
23 F(URLResponseInfo) | 23 F(URLResponseInfo) |
24 | 24 |
25 namespace pp { | 25 namespace pp { |
26 namespace proxy { | 26 namespace proxy { |
27 | 27 |
28 // Forward declaration of Resource classes. | 28 // Forward declaration of Resource classes. |
29 #define DECLARE_RESOURCE_CLASS(RESOURCE) class RESOURCE; | 29 #define DECLARE_RESOURCE_CLASS(RESOURCE) class RESOURCE; |
30 FOR_ALL_RESOURCES(DECLARE_RESOURCE_CLASS) | 30 FOR_ALL_PLUGIN_RESOURCES(DECLARE_RESOURCE_CLASS) |
31 #undef DECLARE_RESOURCE_CLASS | 31 #undef DECLARE_RESOURCE_CLASS |
32 | 32 |
33 class PluginResource { | 33 class PluginResource { |
34 public: | 34 public: |
35 PluginResource(); | 35 PluginResource(); |
36 virtual ~PluginResource(); | 36 virtual ~PluginResource(); |
37 | 37 |
38 // Returns NULL if the resource is invalid or is a different type. | 38 // Returns NULL if the resource is invalid or is a different type. |
39 template<typename T> static T* GetAs(PP_Resource res) { | 39 template<typename T> static T* GetAs(PP_Resource res) { |
40 PluginResource* resource = | 40 PluginResource* resource = |
41 PluginDispatcher::Get()->plugin_resource_tracker()->GetResourceObject( | 41 PluginDispatcher::Get()->plugin_resource_tracker()->GetResourceObject( |
42 res); | 42 res); |
43 return resource ? resource->Cast<T>() : NULL; | 43 return resource ? resource->Cast<T>() : NULL; |
44 } | 44 } |
45 | 45 |
46 template <typename T> T* Cast() { return NULL; } | 46 template <typename T> T* Cast() { return NULL; } |
47 | 47 |
48 private: | 48 private: |
49 // Type-specific getters for individual resource types. These will return | 49 // Type-specific getters for individual resource types. These will return |
50 // NULL if the resource does not match the specified type. Used by the Cast() | 50 // NULL if the resource does not match the specified type. Used by the Cast() |
51 // function. | 51 // function. |
52 #define DEFINE_TYPE_GETTER(RESOURCE) \ | 52 #define DEFINE_TYPE_GETTER(RESOURCE) \ |
53 virtual RESOURCE* As##RESOURCE(); | 53 virtual RESOURCE* As##RESOURCE(); |
54 FOR_ALL_RESOURCES(DEFINE_TYPE_GETTER) | 54 FOR_ALL_PLUGIN_RESOURCES(DEFINE_TYPE_GETTER) |
55 #undef DEFINE_TYPE_GETTER | 55 #undef DEFINE_TYPE_GETTER |
56 | 56 |
57 DISALLOW_COPY_AND_ASSIGN(PluginResource); | 57 DISALLOW_COPY_AND_ASSIGN(PluginResource); |
58 }; | 58 }; |
59 | 59 |
60 // Cast() specializations. | 60 // Cast() specializations. |
61 #define DEFINE_RESOURCE_CAST(Type) \ | 61 #define DEFINE_RESOURCE_CAST(Type) \ |
62 template <> inline Type* PluginResource::Cast<Type>() { \ | 62 template <> inline Type* PluginResource::Cast<Type>() { \ |
63 return As##Type(); \ | 63 return As##Type(); \ |
64 } | 64 } |
65 FOR_ALL_RESOURCES(DEFINE_RESOURCE_CAST) | 65 FOR_ALL_PLUGIN_RESOURCES(DEFINE_RESOURCE_CAST) |
66 #undef DEFINE_RESOURCE_CAST | 66 #undef DEFINE_RESOURCE_CAST |
67 | 67 |
68 } // namespace proxy | 68 } // namespace proxy |
69 } // namespace pp | 69 } // namespace pp |
70 | 70 |
71 #endif // PPAPI_PROXY_PLUGIN_RESOURCE_H_ | 71 #endif // PPAPI_PROXY_PLUGIN_RESOURCE_H_ |
OLD | NEW |