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 WEBKIT_GLUE_PLUGINS_PEPPER_RESOURCE_H_ | 5 #ifndef WEBKIT_PLUGINS_PPAPI_RESOURCE_H_ |
6 #define WEBKIT_GLUE_PLUGINS_PEPPER_RESOURCE_H_ | 6 #define WEBKIT_PLUGINS_PPAPI_RESOURCE_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/ref_counted.h" | 9 #include "base/ref_counted.h" |
10 #include "ppapi/c/pp_resource.h" | 10 #include "ppapi/c/pp_resource.h" |
11 #include "webkit/glue/plugins/pepper_resource_tracker.h" | 11 #include "webkit/plugins/ppapi/resource_tracker.h" |
12 | 12 |
13 namespace pepper { | 13 namespace webkit { |
| 14 namespace ppapi { |
14 | 15 |
15 // If you inherit from resource, make sure you add the class name here. | 16 // If you inherit from resource, make sure you add the class name here. |
16 #define FOR_ALL_RESOURCES(F) \ | 17 #define FOR_ALL_RESOURCES(F) \ |
17 F(Audio) \ | |
18 F(AudioConfig) \ | |
19 F(Buffer) \ | |
20 F(DirectoryReader) \ | |
21 F(FileChooser) \ | |
22 F(FileIO) \ | |
23 F(FileRef) \ | |
24 F(FileSystem) \ | |
25 F(Font) \ | |
26 F(Graphics2D) \ | |
27 F(Graphics3D) \ | |
28 F(ImageData) \ | |
29 F(MockResource) \ | 18 F(MockResource) \ |
30 F(ObjectVar) \ | 19 F(ObjectVar) \ |
31 F(PluginModule) \ | 20 F(PPB_AudioConfig_Impl) \ |
| 21 F(PPB_Audio_Impl) \ |
| 22 F(PPB_Buffer_Impl) \ |
| 23 F(PPB_DirectoryReader_Impl) \ |
| 24 F(PPB_FileChooser_Impl) \ |
| 25 F(PPB_FileIO_Impl) \ |
| 26 F(PPB_FileRef_Impl) \ |
| 27 F(PPB_FileSystem_Impl) \ |
| 28 F(PPB_Font_Impl) \ |
| 29 F(PPB_Graphics2D_Impl) \ |
| 30 F(PPB_Graphics3D_Impl) \ |
| 31 F(PPB_ImageData_Impl) \ |
| 32 F(PPB_Scrollbar_Impl) \ |
| 33 F(PPB_Transport_Impl) \ |
| 34 F(PPB_URLLoader_Impl) \ |
| 35 F(PPB_URLRequestInfo_Impl) \ |
| 36 F(PPB_URLResponseInfo_Impl) \ |
| 37 F(PPB_VideoDecoder_Impl) \ |
| 38 F(PPB_Widget_Impl) \ |
32 F(PrivateFontFile) \ | 39 F(PrivateFontFile) \ |
33 F(Scrollbar) \ | |
34 F(StringVar) \ | 40 F(StringVar) \ |
35 F(Transport) \ | |
36 F(URLLoader) \ | |
37 F(URLRequestInfo) \ | |
38 F(URLResponseInfo) \ | |
39 F(Var) \ | 41 F(Var) \ |
40 F(VarObjectClass) \ | 42 F(VarObjectClass) |
41 F(VideoDecoder) \ | |
42 F(Widget) | |
43 | 43 |
44 // Forward declaration of Resource classes. | 44 // Forward declaration of Resource classes. |
45 #define DECLARE_RESOURCE_CLASS(RESOURCE) class RESOURCE; | 45 #define DECLARE_RESOURCE_CLASS(RESOURCE) class RESOURCE; |
46 FOR_ALL_RESOURCES(DECLARE_RESOURCE_CLASS) | 46 FOR_ALL_RESOURCES(DECLARE_RESOURCE_CLASS) |
47 #undef DECLARE_RESOURCE_CLASS | 47 #undef DECLARE_RESOURCE_CLASS |
48 | 48 |
49 class Resource : public base::RefCountedThreadSafe<Resource> { | 49 class Resource : public base::RefCountedThreadSafe<Resource> { |
50 public: | 50 public: |
51 explicit Resource(PluginModule* module); | 51 explicit Resource(PluginModule* module); |
52 virtual ~Resource(); | 52 virtual ~Resource(); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 ResourceTracker::Get()->UnrefResource(id); | 96 ResourceTracker::Get()->UnrefResource(id); |
97 } | 97 } |
98 const PP_Resource id; | 98 const PP_Resource id; |
99 }; | 99 }; |
100 | 100 |
101 private: | 101 private: |
102 // Type-specific getters for individual resource types. These will return | 102 // Type-specific getters for individual resource types. These will return |
103 // NULL if the resource does not match the specified type. Used by the Cast() | 103 // NULL if the resource does not match the specified type. Used by the Cast() |
104 // function. | 104 // function. |
105 #define DEFINE_TYPE_GETTER(RESOURCE) \ | 105 #define DEFINE_TYPE_GETTER(RESOURCE) \ |
106 virtual RESOURCE* As##RESOURCE() { return NULL; } | 106 virtual RESOURCE* As##RESOURCE(); |
107 FOR_ALL_RESOURCES(DEFINE_TYPE_GETTER) | 107 FOR_ALL_RESOURCES(DEFINE_TYPE_GETTER) |
108 #undef DEFINE_TYPE_GETTER | 108 #undef DEFINE_TYPE_GETTER |
109 | 109 |
110 // If referenced by a plugin, holds the id of this resource object. Do not | 110 // If referenced by a plugin, holds the id of this resource object. Do not |
111 // access this member directly, because it is possible that the plugin holds | 111 // access this member directly, because it is possible that the plugin holds |
112 // no references to the object, and therefore the resource_id_ is zero. Use | 112 // no references to the object, and therefore the resource_id_ is zero. Use |
113 // either GetReference() to obtain a new resource_id and increase the | 113 // either GetReference() to obtain a new resource_id and increase the |
114 // refcount, or TemporaryReference when you do not want to increase the | 114 // refcount, or TemporaryReference when you do not want to increase the |
115 // refcount. | 115 // refcount. |
116 PP_Resource resource_id_; | 116 PP_Resource resource_id_; |
117 | 117 |
118 // Non-owning pointer to our module. | 118 // Non-owning pointer to our module. |
119 PluginModule* module_; | 119 PluginModule* module_; |
120 | 120 |
121 // Called by the resource tracker when the last plugin reference has been | 121 // Called by the resource tracker when the last plugin reference has been |
122 // dropped. | 122 // dropped. |
123 friend class ResourceTracker; | 123 friend class ResourceTracker; |
124 void StoppedTracking(); | 124 void StoppedTracking(); |
125 | 125 |
126 DISALLOW_COPY_AND_ASSIGN(Resource); | 126 DISALLOW_COPY_AND_ASSIGN(Resource); |
127 }; | 127 }; |
128 | 128 |
129 // Cast() specializations. | 129 // Cast() specializations. |
130 #define DEFINE_RESOURCE_CAST(Type) \ | 130 #define DEFINE_RESOURCE_CAST(Type) \ |
131 template <> inline Type* Resource::Cast<Type>() { \ | 131 template <> inline Type* Resource::Cast<Type>() { \ |
132 return As##Type(); \ | 132 return As##Type(); \ |
133 } | 133 } |
134 | 134 |
135 FOR_ALL_RESOURCES(DEFINE_RESOURCE_CAST) | 135 FOR_ALL_RESOURCES(DEFINE_RESOURCE_CAST) |
136 #undef DEFINE_RESOURCE_CAST | 136 #undef DEFINE_RESOURCE_CAST |
137 | 137 |
138 #undef FOR_ALL_RESOURCES | 138 } // namespace ppapi |
139 } // namespace pepper | 139 } // namespace webkit |
140 | 140 |
141 #endif // WEBKIT_GLUE_PLUGINS_PEPPER_RESOURCE_H_ | 141 #endif // WEBKIT_PLUGINS_PPAPI_RESOURCE_H_ |
OLD | NEW |