Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/c/pp_instance.h" | 9 #include "ppapi/c/pp_instance.h" |
| 10 #include "ppapi/proxy/plugin_dispatcher.h" | 10 #include "ppapi/proxy/plugin_dispatcher.h" |
| 11 #include "ppapi/proxy/plugin_resource_tracker.h" | 11 #include "ppapi/proxy/plugin_resource_tracker.h" |
| 12 #include "ppapi/proxy/serialized_resource.h" | |
| 12 | 13 |
| 13 // If you inherit from resource, make sure you add the class name here. | 14 // If you inherit from resource, make sure you add the class name here. |
| 14 #define FOR_ALL_PLUGIN_RESOURCES(F) \ | 15 #define FOR_ALL_PLUGIN_RESOURCES(F) \ |
| 15 F(Audio) \ | 16 F(Audio) \ |
| 16 F(AudioConfig) \ | 17 F(AudioConfig) \ |
| 17 F(Buffer) \ | 18 F(Buffer) \ |
| 18 F(Font) \ | 19 F(Font) \ |
| 19 F(Graphics2D) \ | 20 F(Graphics2D) \ |
| 20 F(ImageData) \ | 21 F(ImageData) \ |
| 22 F(MockResource) \ | |
| 21 F(PrivateFontFile) \ | 23 F(PrivateFontFile) \ |
| 22 F(URLLoader) \ | 24 F(URLLoader) \ |
| 23 F(URLRequestInfo)\ | 25 F(URLRequestInfo)\ |
| 24 F(URLResponseInfo) | 26 F(URLResponseInfo) |
| 25 | 27 |
| 26 namespace pp { | 28 namespace pp { |
| 27 namespace proxy { | 29 namespace proxy { |
| 28 | 30 |
| 29 // Forward declaration of Resource classes. | 31 // Forward declaration of Resource classes. |
| 30 #define DECLARE_RESOURCE_CLASS(RESOURCE) class RESOURCE; | 32 #define DECLARE_RESOURCE_CLASS(RESOURCE) class RESOURCE; |
| 31 FOR_ALL_PLUGIN_RESOURCES(DECLARE_RESOURCE_CLASS) | 33 FOR_ALL_PLUGIN_RESOURCES(DECLARE_RESOURCE_CLASS) |
| 32 #undef DECLARE_RESOURCE_CLASS | 34 #undef DECLARE_RESOURCE_CLASS |
| 33 | 35 |
| 34 class PluginResource { | 36 class PluginResource { |
| 35 public: | 37 public: |
| 36 PluginResource(PP_Instance instance); | 38 PluginResource(PP_Instance instance, SerializedResource resource); |
| 37 virtual ~PluginResource(); | 39 virtual ~PluginResource(); |
| 38 | 40 |
| 39 // Returns NULL if the resource is invalid or is a different type. | 41 // Returns NULL if the resource is invalid or is a different type. |
| 40 template<typename T> static T* GetAs(PP_Resource res) { | 42 template<typename T> static T* GetAs(PP_Resource res) { |
| 41 PluginResource* resource = | 43 PluginResource* resource = |
| 42 PluginResourceTracker::GetInstance()->GetResourceObject(res); | 44 PluginResourceTracker::GetInstance()->GetResourceObject(res); |
| 43 return resource ? resource->Cast<T>() : NULL; | 45 return resource ? resource->Cast<T>() : NULL; |
| 44 } | 46 } |
| 45 | 47 |
| 46 template <typename T> T* Cast() { return NULL; } | 48 template <typename T> T* Cast() { return NULL; } |
| 47 | 49 |
| 48 PP_Instance instance() const { return instance_; } | 50 PP_Instance instance() const { return instance_; } |
| 49 | 51 |
| 52 // Returns a serialized resource containing the host PP_Resource ID (see | |
| 53 // host_resource_ below) for sending to the host process. | |
| 54 // | |
| 55 // Returned by value since a SerializedResource is just a 32-bit number. | |
| 56 SerializedResource host_resource() const { | |
| 57 return host_resource_; | |
| 58 } | |
| 59 | |
| 50 private: | 60 private: |
| 51 // Type-specific getters for individual resource types. These will return | 61 // Type-specific getters for individual resource types. These will return |
| 52 // NULL if the resource does not match the specified type. Used by the Cast() | 62 // NULL if the resource does not match the specified type. Used by the Cast() |
| 53 // function. | 63 // function. |
| 54 #define DEFINE_TYPE_GETTER(RESOURCE) \ | 64 #define DEFINE_TYPE_GETTER(RESOURCE) \ |
| 55 virtual RESOURCE* As##RESOURCE(); | 65 virtual RESOURCE* As##RESOURCE(); |
| 56 FOR_ALL_PLUGIN_RESOURCES(DEFINE_TYPE_GETTER) | 66 FOR_ALL_PLUGIN_RESOURCES(DEFINE_TYPE_GETTER) |
| 57 #undef DEFINE_TYPE_GETTER | 67 #undef DEFINE_TYPE_GETTER |
| 58 | 68 |
| 59 // Instance this resource is associated with. | 69 // Instance this resource is associated with. |
| 60 PP_Instance instance_; | 70 PP_Instance instance_; |
| 61 | 71 |
| 72 // The resource ID of the host that this object corresponds to. Inside the | |
|
viettrungluu
2011/01/27 16:52:58
I think s/of/in/ would be clearer. (Some people wo
| |
| 73 // plugin we'll remap the resource IDs so we can have many host processes | |
| 74 // each independently generating resources (which may conflict) but the IDs | |
| 75 // in the plugin will all be unique. | |
| 76 SerializedResource host_resource_; | |
| 77 | |
| 62 DISALLOW_COPY_AND_ASSIGN(PluginResource); | 78 DISALLOW_COPY_AND_ASSIGN(PluginResource); |
| 63 }; | 79 }; |
| 64 | 80 |
| 65 // Cast() specializations. | 81 // Cast() specializations. |
| 66 #define DEFINE_RESOURCE_CAST(Type) \ | 82 #define DEFINE_RESOURCE_CAST(Type) \ |
| 67 template <> inline Type* PluginResource::Cast<Type>() { \ | 83 template <> inline Type* PluginResource::Cast<Type>() { \ |
| 68 return As##Type(); \ | 84 return As##Type(); \ |
| 69 } | 85 } |
| 70 FOR_ALL_PLUGIN_RESOURCES(DEFINE_RESOURCE_CAST) | 86 FOR_ALL_PLUGIN_RESOURCES(DEFINE_RESOURCE_CAST) |
| 71 #undef DEFINE_RESOURCE_CAST | 87 #undef DEFINE_RESOURCE_CAST |
| 72 | 88 |
| 73 } // namespace proxy | 89 } // namespace proxy |
| 74 } // namespace pp | 90 } // namespace pp |
| 75 | 91 |
| 76 #endif // PPAPI_PROXY_PLUGIN_RESOURCE_H_ | 92 #endif // PPAPI_PROXY_PLUGIN_RESOURCE_H_ |
| OLD | NEW |