| 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/host_resource.h" |
| 11 #include "ppapi/proxy/plugin_dispatcher.h" | 11 #include "ppapi/proxy/plugin_dispatcher.h" |
| 12 #include "ppapi/proxy/plugin_resource_tracker.h" | 12 #include "ppapi/proxy/plugin_resource_tracker.h" |
| 13 #include "ppapi/shared_impl/resource_object_base.h" |
| 13 | 14 |
| 14 // If you inherit from resource, make sure you add the class name here. | 15 // If you inherit from resource, make sure you add the class name here. |
| 15 #define FOR_ALL_PLUGIN_RESOURCES(F) \ | 16 #define FOR_ALL_PLUGIN_RESOURCES(F) \ |
| 16 F(Audio) \ | 17 F(Audio) \ |
| 17 F(AudioConfig) \ | 18 F(AudioConfig) \ |
| 18 F(Broker) \ | 19 F(Broker) \ |
| 19 F(Buffer) \ | 20 F(Buffer) \ |
| 20 F(Context3D) \ | 21 F(Context3D) \ |
| 21 F(FileChooser) \ | 22 F(FileChooser) \ |
| 22 F(FileRef) \ | 23 F(FileRef) \ |
| (...skipping 11 matching lines...) Expand all Loading... |
| 34 F(URLResponseInfo) | 35 F(URLResponseInfo) |
| 35 | 36 |
| 36 namespace pp { | 37 namespace pp { |
| 37 namespace proxy { | 38 namespace proxy { |
| 38 | 39 |
| 39 // Forward declaration of Resource classes. | 40 // Forward declaration of Resource classes. |
| 40 #define DECLARE_RESOURCE_CLASS(RESOURCE) class RESOURCE; | 41 #define DECLARE_RESOURCE_CLASS(RESOURCE) class RESOURCE; |
| 41 FOR_ALL_PLUGIN_RESOURCES(DECLARE_RESOURCE_CLASS) | 42 FOR_ALL_PLUGIN_RESOURCES(DECLARE_RESOURCE_CLASS) |
| 42 #undef DECLARE_RESOURCE_CLASS | 43 #undef DECLARE_RESOURCE_CLASS |
| 43 | 44 |
| 44 class PluginResource { | 45 class PluginResource : public ::ppapi::shared_impl::ResourceObjectBase { |
| 45 public: | 46 public: |
| 46 PluginResource(const HostResource& resource); | 47 PluginResource(const HostResource& resource); |
| 47 virtual ~PluginResource(); | 48 virtual ~PluginResource(); |
| 48 | 49 |
| 49 // Returns NULL if the resource is invalid or is a different type. | 50 // Returns NULL if the resource is invalid or is a different type. |
| 50 template<typename T> static T* GetAs(PP_Resource res) { | 51 template<typename T> static T* GetAs(PP_Resource res) { |
| 51 PluginResource* resource = | 52 PluginResource* resource = |
| 52 PluginResourceTracker::GetInstance()->GetResourceObject(res); | 53 PluginResourceTracker::GetInstance()->GetResourceObject(res); |
| 53 return resource ? resource->Cast<T>() : NULL; | 54 return resource ? resource->Cast<T>() : NULL; |
| 54 } | 55 } |
| 55 | 56 |
| 56 template <typename T> T* Cast() { return NULL; } | 57 template <typename T> T* Cast() { return NULL; } |
| 57 | 58 |
| 58 PP_Instance instance() const { return host_resource_.instance(); } | 59 PP_Instance instance() const { return host_resource_.instance(); } |
| 59 | 60 |
| 60 // Returns the host resource ID for sending to the host process. | 61 // Returns the host resource ID for sending to the host process. |
| 61 const HostResource& host_resource() const { | 62 const HostResource& host_resource() const { |
| 62 return host_resource_; | 63 return host_resource_; |
| 63 } | 64 } |
| 64 | 65 |
| 66 PluginDispatcher* GetDispatcher(); |
| 67 |
| 65 private: | 68 private: |
| 66 // Type-specific getters for individual resource types. These will return | 69 // Type-specific getters for individual resource types. These will return |
| 67 // NULL if the resource does not match the specified type. Used by the Cast() | 70 // NULL if the resource does not match the specified type. Used by the Cast() |
| 68 // function. | 71 // function. |
| 69 #define DEFINE_TYPE_GETTER(RESOURCE) \ | 72 #define DEFINE_TYPE_GETTER(RESOURCE) \ |
| 70 virtual RESOURCE* As##RESOURCE(); | 73 virtual RESOURCE* As##RESOURCE(); |
| 71 FOR_ALL_PLUGIN_RESOURCES(DEFINE_TYPE_GETTER) | 74 FOR_ALL_PLUGIN_RESOURCES(DEFINE_TYPE_GETTER) |
| 72 #undef DEFINE_TYPE_GETTER | 75 #undef DEFINE_TYPE_GETTER |
| 73 | 76 |
| 74 // The resource ID in the host that this object corresponds to. Inside the | 77 // The resource ID in the host that this object corresponds to. Inside the |
| (...skipping 10 matching lines...) Expand all Loading... |
| 85 template <> inline Type* PluginResource::Cast<Type>() { \ | 88 template <> inline Type* PluginResource::Cast<Type>() { \ |
| 86 return As##Type(); \ | 89 return As##Type(); \ |
| 87 } | 90 } |
| 88 FOR_ALL_PLUGIN_RESOURCES(DEFINE_RESOURCE_CAST) | 91 FOR_ALL_PLUGIN_RESOURCES(DEFINE_RESOURCE_CAST) |
| 89 #undef DEFINE_RESOURCE_CAST | 92 #undef DEFINE_RESOURCE_CAST |
| 90 | 93 |
| 91 } // namespace proxy | 94 } // namespace proxy |
| 92 } // namespace pp | 95 } // namespace pp |
| 93 | 96 |
| 94 #endif // PPAPI_PROXY_PLUGIN_RESOURCE_H_ | 97 #endif // PPAPI_PROXY_PLUGIN_RESOURCE_H_ |
| OLD | NEW |