| 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/host_resource.h" |
| 10 #include "ppapi/proxy/plugin_dispatcher.h" | 11 #include "ppapi/proxy/plugin_dispatcher.h" |
| 11 #include "ppapi/proxy/plugin_resource_tracker.h" | 12 #include "ppapi/proxy/plugin_resource_tracker.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(const HostResource& 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 host_resource_.instance(); } |
| 51 |
| 52 // Returns the host resource ID for sending to the host process. |
| 53 const HostResource& host_resource() const { |
| 54 return host_resource_; |
| 55 } |
| 49 | 56 |
| 50 private: | 57 private: |
| 51 // Type-specific getters for individual resource types. These will return | 58 // 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() | 59 // NULL if the resource does not match the specified type. Used by the Cast() |
| 53 // function. | 60 // function. |
| 54 #define DEFINE_TYPE_GETTER(RESOURCE) \ | 61 #define DEFINE_TYPE_GETTER(RESOURCE) \ |
| 55 virtual RESOURCE* As##RESOURCE(); | 62 virtual RESOURCE* As##RESOURCE(); |
| 56 FOR_ALL_PLUGIN_RESOURCES(DEFINE_TYPE_GETTER) | 63 FOR_ALL_PLUGIN_RESOURCES(DEFINE_TYPE_GETTER) |
| 57 #undef DEFINE_TYPE_GETTER | 64 #undef DEFINE_TYPE_GETTER |
| 58 | 65 |
| 59 // Instance this resource is associated with. | 66 // The resource ID in the host that this object corresponds to. Inside the |
| 60 PP_Instance instance_; | 67 // plugin we'll remap the resource IDs so we can have many host processes |
| 68 // each independently generating resources (which may conflict) but the IDs |
| 69 // in the plugin will all be unique. |
| 70 HostResource host_resource_; |
| 61 | 71 |
| 62 DISALLOW_COPY_AND_ASSIGN(PluginResource); | 72 DISALLOW_COPY_AND_ASSIGN(PluginResource); |
| 63 }; | 73 }; |
| 64 | 74 |
| 65 // Cast() specializations. | 75 // Cast() specializations. |
| 66 #define DEFINE_RESOURCE_CAST(Type) \ | 76 #define DEFINE_RESOURCE_CAST(Type) \ |
| 67 template <> inline Type* PluginResource::Cast<Type>() { \ | 77 template <> inline Type* PluginResource::Cast<Type>() { \ |
| 68 return As##Type(); \ | 78 return As##Type(); \ |
| 69 } | 79 } |
| 70 FOR_ALL_PLUGIN_RESOURCES(DEFINE_RESOURCE_CAST) | 80 FOR_ALL_PLUGIN_RESOURCES(DEFINE_RESOURCE_CAST) |
| 71 #undef DEFINE_RESOURCE_CAST | 81 #undef DEFINE_RESOURCE_CAST |
| 72 | 82 |
| 73 } // namespace proxy | 83 } // namespace proxy |
| 74 } // namespace pp | 84 } // namespace pp |
| 75 | 85 |
| 76 #endif // PPAPI_PROXY_PLUGIN_RESOURCE_H_ | 86 #endif // PPAPI_PROXY_PLUGIN_RESOURCE_H_ |
| OLD | NEW |