| 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_GLUE_PLUGINS_PEPPER_RESOURCE_H_ |
| 6 #define WEBKIT_GLUE_PLUGINS_PEPPER_RESOURCE_H_ | 6 #define WEBKIT_GLUE_PLUGINS_PEPPER_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 "third_party/ppapi/c/pp_resource.h" | 10 #include "third_party/ppapi/c/pp_resource.h" |
| 11 #include "webkit/glue/plugins/pepper_resource_tracker.h" | 11 #include "webkit/glue/plugins/pepper_resource_tracker.h" |
| 12 | 12 |
| 13 namespace pepper { | 13 namespace pepper { |
| 14 | 14 |
| 15 class Buffer; | 15 class Buffer; |
| 16 class DeviceContext2D; | 16 class DeviceContext2D; |
| 17 class DirectoryReader; | 17 class DirectoryReader; |
| 18 class FileChooser; | 18 class FileChooser; |
| 19 class FileIO; | 19 class FileIO; |
| 20 class FileRef; | 20 class FileRef; |
| 21 class ImageData; | 21 class ImageData; |
| 22 class PluginModule; | 22 class PluginModule; |
| 23 class Scrollbar; |
| 23 class URLLoader; | 24 class URLLoader; |
| 24 class URLRequestInfo; | 25 class URLRequestInfo; |
| 25 class URLResponseInfo; | 26 class URLResponseInfo; |
| 27 class Widget; |
| 26 | 28 |
| 27 class Resource : public base::RefCountedThreadSafe<Resource> { | 29 class Resource : public base::RefCountedThreadSafe<Resource> { |
| 28 public: | 30 public: |
| 29 explicit Resource(PluginModule* module); | 31 explicit Resource(PluginModule* module); |
| 30 virtual ~Resource(); | 32 virtual ~Resource(); |
| 31 | 33 |
| 32 // Returns NULL if the resource is invalid or is a different type. | 34 // Returns NULL if the resource is invalid or is a different type. |
| 33 template<typename T> | 35 template<typename T> |
| 34 static scoped_refptr<T> GetAs(PP_Resource res) { | 36 static scoped_refptr<T> GetAs(PP_Resource res) { |
| 35 scoped_refptr<Resource> resource = ResourceTracker::Get()->GetResource(res); | 37 scoped_refptr<Resource> resource = ResourceTracker::Get()->GetResource(res); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 49 // Type-specific getters for individual resource types. These will return | 51 // 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() | 52 // NULL if the resource does not match the specified type. Used by the Cast() |
| 51 // function. | 53 // function. |
| 52 virtual Buffer* AsBuffer() { return NULL; } | 54 virtual Buffer* AsBuffer() { return NULL; } |
| 53 virtual DeviceContext2D* AsDeviceContext2D() { return NULL; } | 55 virtual DeviceContext2D* AsDeviceContext2D() { return NULL; } |
| 54 virtual DirectoryReader* AsDirectoryReader() { return NULL; } | 56 virtual DirectoryReader* AsDirectoryReader() { return NULL; } |
| 55 virtual FileChooser* AsFileChooser() { return NULL; } | 57 virtual FileChooser* AsFileChooser() { return NULL; } |
| 56 virtual FileIO* AsFileIO() { return NULL; } | 58 virtual FileIO* AsFileIO() { return NULL; } |
| 57 virtual FileRef* AsFileRef() { return NULL; } | 59 virtual FileRef* AsFileRef() { return NULL; } |
| 58 virtual ImageData* AsImageData() { return NULL; } | 60 virtual ImageData* AsImageData() { return NULL; } |
| 61 virtual Scrollbar* AsScrollbar() { return NULL; } |
| 59 virtual URLLoader* AsURLLoader() { return NULL; } | 62 virtual URLLoader* AsURLLoader() { return NULL; } |
| 60 virtual URLRequestInfo* AsURLRequestInfo() { return NULL; } | 63 virtual URLRequestInfo* AsURLRequestInfo() { return NULL; } |
| 61 virtual URLResponseInfo* AsURLResponseInfo() { return NULL; } | 64 virtual URLResponseInfo* AsURLResponseInfo() { return NULL; } |
| 65 virtual Widget* AsWidget() { return NULL; } |
| 62 | 66 |
| 63 PluginModule* module_; // Non-owning pointer to our module. | 67 PluginModule* module_; // Non-owning pointer to our module. |
| 64 | 68 |
| 65 DISALLOW_COPY_AND_ASSIGN(Resource); | 69 DISALLOW_COPY_AND_ASSIGN(Resource); |
| 66 }; | 70 }; |
| 67 | 71 |
| 68 // Cast() specializations. | 72 // Cast() specializations. |
| 69 #define DEFINE_RESOURCE_CAST(Type) \ | 73 #define DEFINE_RESOURCE_CAST(Type) \ |
| 70 template <> inline Type* Resource::Cast<Type>() { \ | 74 template <> inline Type* Resource::Cast<Type>() { \ |
| 71 return As##Type(); \ | 75 return As##Type(); \ |
| 72 } | 76 } |
| 73 | 77 |
| 74 DEFINE_RESOURCE_CAST(Buffer) | 78 DEFINE_RESOURCE_CAST(Buffer) |
| 75 DEFINE_RESOURCE_CAST(DeviceContext2D) | 79 DEFINE_RESOURCE_CAST(DeviceContext2D) |
| 76 DEFINE_RESOURCE_CAST(DirectoryReader) | 80 DEFINE_RESOURCE_CAST(DirectoryReader) |
| 77 DEFINE_RESOURCE_CAST(FileChooser) | 81 DEFINE_RESOURCE_CAST(FileChooser) |
| 78 DEFINE_RESOURCE_CAST(FileIO) | 82 DEFINE_RESOURCE_CAST(FileIO) |
| 79 DEFINE_RESOURCE_CAST(FileRef) | 83 DEFINE_RESOURCE_CAST(FileRef) |
| 80 DEFINE_RESOURCE_CAST(ImageData) | 84 DEFINE_RESOURCE_CAST(ImageData) |
| 85 DEFINE_RESOURCE_CAST(Scrollbar) |
| 81 DEFINE_RESOURCE_CAST(URLLoader) | 86 DEFINE_RESOURCE_CAST(URLLoader) |
| 82 DEFINE_RESOURCE_CAST(URLRequestInfo) | 87 DEFINE_RESOURCE_CAST(URLRequestInfo) |
| 83 DEFINE_RESOURCE_CAST(URLResponseInfo) | 88 DEFINE_RESOURCE_CAST(URLResponseInfo) |
| 89 DEFINE_RESOURCE_CAST(Widget) |
| 84 | 90 |
| 85 #undef DEFINE_RESOURCE_CAST | 91 #undef DEFINE_RESOURCE_CAST |
| 86 } // namespace pepper | 92 } // namespace pepper |
| 87 | 93 |
| 88 #endif // WEBKIT_GLUE_PLUGINS_PEPPER_RESOURCE_H_ | 94 #endif // WEBKIT_GLUE_PLUGINS_PEPPER_RESOURCE_H_ |
| OLD | NEW |