diff options
author | neb@chromium.org <neb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-28 22:05:19 +0000 |
---|---|---|
committer | neb@chromium.org <neb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-28 22:05:19 +0000 |
commit | 0111318c7101cc3e6d414d8a54db257aa06d4f66 (patch) | |
tree | d32865c976322bb18b943980a678e0ec8519ee39 | |
parent | 44eed9ff188a565ebd56d6e1084921eaae4af98d (diff) | |
download | chromium_src-0111318c7101cc3e6d414d8a54db257aa06d4f66.zip chromium_src-0111318c7101cc3e6d414d8a54db257aa06d4f66.tar.gz chromium_src-0111318c7101cc3e6d414d8a54db257aa06d4f66.tar.bz2 |
Add a GetAs<ResourceType> template.
Move all the dependencies of new PP_Resource types into plugin_resource.h.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/2800028
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51056 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | webkit/glue/plugins/pepper_buffer.cc | 12 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_device_context_2d.cc | 22 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_directory_reader.cc | 6 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_file_chooser.cc | 6 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_file_io.cc | 38 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_file_ref.cc | 14 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_image_data.cc | 12 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_plugin_instance.cc | 8 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_plugin_module.cc | 2 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_resource.h | 36 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_resource_tracker.cc | 20 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_resource_tracker.h | 25 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_url_loader.cc | 26 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_url_request_info.cc | 7 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_url_response_info.cc | 5 |
15 files changed, 93 insertions, 146 deletions
diff --git a/webkit/glue/plugins/pepper_buffer.cc b/webkit/glue/plugins/pepper_buffer.cc index f8d1384..4d94975 100644 --- a/webkit/glue/plugins/pepper_buffer.cc +++ b/webkit/glue/plugins/pepper_buffer.cc @@ -14,7 +14,6 @@ #include "third_party/ppapi/c/ppb_buffer.h" #include "webkit/glue/plugins/pepper_plugin_instance.h" #include "webkit/glue/plugins/pepper_plugin_module.h" -#include "webkit/glue/plugins/pepper_resource_tracker.h" namespace pepper { @@ -34,12 +33,11 @@ PP_Resource Create(PP_Module module_id, int32_t size) { } bool IsBuffer(PP_Resource resource) { - return !!ResourceTracker::Get()->GetAsBuffer(resource).get(); + return !!Resource::GetAs<Buffer>(resource).get(); } bool Describe(PP_Resource resource, int32_t* size_in_bytes) { - scoped_refptr<Buffer> buffer( - ResourceTracker::Get()->GetAsBuffer(resource)); + scoped_refptr<Buffer> buffer(Resource::GetAs<Buffer>(resource)); if (!buffer.get()) return false; buffer->Describe(size_in_bytes); @@ -47,16 +45,14 @@ bool Describe(PP_Resource resource, int32_t* size_in_bytes) { } void* Map(PP_Resource resource) { - scoped_refptr<Buffer> buffer( - ResourceTracker::Get()->GetAsBuffer(resource)); + scoped_refptr<Buffer> buffer(Resource::GetAs<Buffer>(resource)); if (!buffer.get()) return NULL; return buffer->Map(); } void Unmap(PP_Resource resource) { - scoped_refptr<Buffer> buffer( - ResourceTracker::Get()->GetAsBuffer(resource)); + scoped_refptr<Buffer> buffer(Resource::GetAs<Buffer>(resource)); if (!buffer) return; return buffer->Unmap(); diff --git a/webkit/glue/plugins/pepper_device_context_2d.cc b/webkit/glue/plugins/pepper_device_context_2d.cc index 3d81fcb..4dcfa5e 100644 --- a/webkit/glue/plugins/pepper_device_context_2d.cc +++ b/webkit/glue/plugins/pepper_device_context_2d.cc @@ -21,7 +21,6 @@ #include "webkit/glue/plugins/pepper_image_data.h" #include "webkit/glue/plugins/pepper_plugin_instance.h" #include "webkit/glue/plugins/pepper_plugin_module.h" -#include "webkit/glue/plugins/pepper_resource_tracker.h" #if defined(OS_MACOSX) #include "base/mac_util.h" @@ -78,14 +77,14 @@ PP_Resource Create(PP_Module module_id, int32_t width, int32_t height, bool IsDeviceContext2D(PP_Resource resource) { scoped_refptr<DeviceContext2D> context( - ResourceTracker::Get()->GetAsDeviceContext2D(resource)); + Resource::GetAs<DeviceContext2D>(resource)); return !!context.get(); } bool Describe(PP_Resource device_context, int32_t* width, int32_t* height, bool* is_always_opaque) { scoped_refptr<DeviceContext2D> context( - ResourceTracker::Get()->GetAsDeviceContext2D(device_context)); + Resource::GetAs<DeviceContext2D>(device_context)); if (!context.get()) return false; return context->Describe(width, height, is_always_opaque); @@ -96,7 +95,7 @@ bool PaintImageData(PP_Resource device_context, int32_t x, int32_t y, const PP_Rect* src_rect) { scoped_refptr<DeviceContext2D> context( - ResourceTracker::Get()->GetAsDeviceContext2D(device_context)); + Resource::GetAs<DeviceContext2D>(device_context)); if (!context.get()) return false; return context->PaintImageData(image, x, y, src_rect); @@ -106,7 +105,7 @@ bool Scroll(PP_Resource device_context, const PP_Rect* clip_rect, int32_t dx, int32_t dy) { scoped_refptr<DeviceContext2D> context( - ResourceTracker::Get()->GetAsDeviceContext2D(device_context)); + Resource::GetAs<DeviceContext2D>(device_context)); if (!context.get()) return false; return context->Scroll(clip_rect, dx, dy); @@ -114,7 +113,7 @@ bool Scroll(PP_Resource device_context, bool ReplaceContents(PP_Resource device_context, PP_Resource image) { scoped_refptr<DeviceContext2D> context( - ResourceTracker::Get()->GetAsDeviceContext2D(device_context)); + Resource::GetAs<DeviceContext2D>(device_context)); if (!context.get()) return false; return context->ReplaceContents(image); @@ -123,7 +122,7 @@ bool ReplaceContents(PP_Resource device_context, PP_Resource image) { int32_t Flush(PP_Resource device_context, PP_CompletionCallback callback) { scoped_refptr<DeviceContext2D> context( - ResourceTracker::Get()->GetAsDeviceContext2D(device_context)); + Resource::GetAs<DeviceContext2D>(device_context)); if (!context.get()) return PP_Error_BadResource; return context->Flush(callback); @@ -209,8 +208,7 @@ bool DeviceContext2D::Describe(int32_t* width, int32_t* height, bool DeviceContext2D::PaintImageData(PP_Resource image, int32_t x, int32_t y, const PP_Rect* src_rect) { - scoped_refptr<ImageData> image_resource( - ResourceTracker::Get()->GetAsImageData(image)); + scoped_refptr<ImageData> image_resource(Resource::GetAs<ImageData>(image)); if (!image_resource.get()) return false; @@ -262,8 +260,7 @@ bool DeviceContext2D::Scroll(const PP_Rect* clip_rect, } bool DeviceContext2D::ReplaceContents(PP_Resource image) { - scoped_refptr<ImageData> image_resource( - ResourceTracker::Get()->GetAsImageData(image)); + scoped_refptr<ImageData> image_resource(Resource::GetAs<ImageData>(image)); if (!image_resource.get()) return false; if (image_resource->format() != PP_IMAGEDATAFORMAT_BGRA_PREMUL) @@ -336,8 +333,7 @@ int32_t DeviceContext2D::Flush(const PP_CompletionCallback& callback) { bool DeviceContext2D::ReadImageData(PP_Resource image, int32_t x, int32_t y) { // Get and validate the image object to paint into. - scoped_refptr<ImageData> image_resource( - ResourceTracker::Get()->GetAsImageData(image)); + scoped_refptr<ImageData> image_resource(Resource::GetAs<ImageData>(image)); if (!image_resource.get()) return false; if (image_resource->format() != PP_IMAGEDATAFORMAT_BGRA_PREMUL) diff --git a/webkit/glue/plugins/pepper_directory_reader.cc b/webkit/glue/plugins/pepper_directory_reader.cc index 3abaa40..429fb24 100644 --- a/webkit/glue/plugins/pepper_directory_reader.cc +++ b/webkit/glue/plugins/pepper_directory_reader.cc @@ -16,7 +16,7 @@ namespace { PP_Resource Create(PP_Resource directory_ref_id) { scoped_refptr<FileRef> directory_ref( - ResourceTracker::Get()->GetAsFileRef(directory_ref_id)); + Resource::GetAs<FileRef>(directory_ref_id)); if (!directory_ref.get()) return 0; @@ -26,14 +26,14 @@ PP_Resource Create(PP_Resource directory_ref_id) { } bool IsDirectoryReader(PP_Resource resource) { - return !!ResourceTracker::Get()->GetAsDirectoryReader(resource).get(); + return !!Resource::GetAs<DirectoryReader>(resource).get(); } int32_t GetNextEntry(PP_Resource reader_id, PP_DirectoryEntry* entry, PP_CompletionCallback callback) { scoped_refptr<DirectoryReader> reader( - ResourceTracker::Get()->GetAsDirectoryReader(reader_id)); + Resource::GetAs<DirectoryReader>(reader_id)); if (!reader.get()) return PP_Error_BadResource; diff --git a/webkit/glue/plugins/pepper_file_chooser.cc b/webkit/glue/plugins/pepper_file_chooser.cc index 8a5e2b0..a2e96b2 100644 --- a/webkit/glue/plugins/pepper_file_chooser.cc +++ b/webkit/glue/plugins/pepper_file_chooser.cc @@ -27,12 +27,12 @@ PP_Resource Create(PP_Instance instance_id, } bool IsFileChooser(PP_Resource resource) { - return !!ResourceTracker::Get()->GetAsFileChooser(resource).get(); + return !!Resource::GetAs<FileChooser>(resource).get(); } int32_t Show(PP_Resource chooser_id, PP_CompletionCallback callback) { scoped_refptr<FileChooser> chooser( - ResourceTracker::Get()->GetAsFileChooser(chooser_id).get()); + Resource::GetAs<FileChooser>(chooser_id).get()); if (!chooser.get()) return PP_Error_BadResource; @@ -41,7 +41,7 @@ int32_t Show(PP_Resource chooser_id, PP_CompletionCallback callback) { PP_Resource GetNextChosenFile(PP_Resource chooser_id) { scoped_refptr<FileChooser> chooser( - ResourceTracker::Get()->GetAsFileChooser(chooser_id).get()); + Resource::GetAs<FileChooser>(chooser_id).get()); if (!chooser.get()) return 0; diff --git a/webkit/glue/plugins/pepper_file_io.cc b/webkit/glue/plugins/pepper_file_io.cc index 72ffc12..926a6db 100644 --- a/webkit/glue/plugins/pepper_file_io.cc +++ b/webkit/glue/plugins/pepper_file_io.cc @@ -28,20 +28,18 @@ PP_Resource Create(PP_Module module_id) { } bool IsFileIO(PP_Resource resource) { - return !!ResourceTracker::Get()->GetAsFileIO(resource).get(); + return !!Resource::GetAs<FileIO>(resource).get(); } int32_t Open(PP_Resource file_io_id, PP_Resource file_ref_id, int32_t open_flags, PP_CompletionCallback callback) { - scoped_refptr<FileIO> file_io( - ResourceTracker::Get()->GetAsFileIO(file_io_id)); + scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); if (!file_io.get()) return PP_Error_BadResource; - scoped_refptr<FileRef> file_ref( - ResourceTracker::Get()->GetAsFileRef(file_ref_id)); + scoped_refptr<FileRef> file_ref(Resource::GetAs<FileRef>(file_ref_id)); if (!file_ref.get()) return PP_Error_BadResource; @@ -51,8 +49,7 @@ int32_t Open(PP_Resource file_io_id, int32_t Query(PP_Resource file_io_id, PP_FileInfo* info, PP_CompletionCallback callback) { - scoped_refptr<FileIO> file_io( - ResourceTracker::Get()->GetAsFileIO(file_io_id)); + scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); if (!file_io.get()) return PP_Error_BadResource; @@ -63,8 +60,7 @@ int32_t Touch(PP_Resource file_io_id, PP_Time last_access_time, PP_Time last_modified_time, PP_CompletionCallback callback) { - scoped_refptr<FileIO> file_io( - ResourceTracker::Get()->GetAsFileIO(file_io_id)); + scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); if (!file_io.get()) return PP_Error_BadResource; @@ -76,8 +72,7 @@ int32_t Read(PP_Resource file_io_id, char* buffer, int32_t bytes_to_read, PP_CompletionCallback callback) { - scoped_refptr<FileIO> file_io( - ResourceTracker::Get()->GetAsFileIO(file_io_id)); + scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); if (!file_io.get()) return PP_Error_BadResource; @@ -89,8 +84,7 @@ int32_t Write(PP_Resource file_io_id, const char* buffer, int32_t bytes_to_write, PP_CompletionCallback callback) { - scoped_refptr<FileIO> file_io( - ResourceTracker::Get()->GetAsFileIO(file_io_id)); + scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); if (!file_io.get()) return PP_Error_BadResource; @@ -100,8 +94,7 @@ int32_t Write(PP_Resource file_io_id, int32_t SetLength(PP_Resource file_io_id, int64_t length, PP_CompletionCallback callback) { - scoped_refptr<FileIO> file_io( - ResourceTracker::Get()->GetAsFileIO(file_io_id)); + scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); if (!file_io.get()) return PP_Error_BadResource; @@ -110,8 +103,7 @@ int32_t SetLength(PP_Resource file_io_id, int32_t Flush(PP_Resource file_io_id, PP_CompletionCallback callback) { - scoped_refptr<FileIO> file_io( - ResourceTracker::Get()->GetAsFileIO(file_io_id)); + scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); if (!file_io.get()) return PP_Error_BadResource; @@ -119,8 +111,7 @@ int32_t Flush(PP_Resource file_io_id, } void Close(PP_Resource file_io_id) { - scoped_refptr<FileIO> file_io( - ResourceTracker::Get()->GetAsFileIO(file_io_id)); + scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); if (!file_io.get()) return; @@ -141,8 +132,7 @@ const PPB_FileIO ppb_fileio = { }; int32_t GetOSFileDescriptor(PP_Resource file_io_id) { - scoped_refptr<FileIO> file_io( - ResourceTracker::Get()->GetAsFileIO(file_io_id)); + scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); if (!file_io.get()) return PP_Error_BadResource; @@ -153,8 +143,7 @@ int32_t WillWrite(PP_Resource file_io_id, int64_t offset, int32_t bytes_to_write, PP_CompletionCallback callback) { - scoped_refptr<FileIO> file_io( - ResourceTracker::Get()->GetAsFileIO(file_io_id)); + scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); if (!file_io.get()) return PP_Error_BadResource; @@ -164,8 +153,7 @@ int32_t WillWrite(PP_Resource file_io_id, int32_t WillSetLength(PP_Resource file_io_id, int64_t length, PP_CompletionCallback callback) { - scoped_refptr<FileIO> file_io( - ResourceTracker::Get()->GetAsFileIO(file_io_id)); + scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); if (!file_io.get()) return PP_Error_BadResource; diff --git a/webkit/glue/plugins/pepper_file_ref.cc b/webkit/glue/plugins/pepper_file_ref.cc index e014ff6..45ec567 100644 --- a/webkit/glue/plugins/pepper_file_ref.cc +++ b/webkit/glue/plugins/pepper_file_ref.cc @@ -63,12 +63,11 @@ PP_Resource CreateTemporaryFileRef(PP_Instance instance_id, const char* path) { } bool IsFileRef(PP_Resource resource) { - return !!ResourceTracker::Get()->GetAsFileRef(resource).get(); + return !!Resource::GetAs<FileRef>(resource).get(); } PP_FileSystemType GetFileSystemType(PP_Resource file_ref_id) { - scoped_refptr<FileRef> file_ref( - ResourceTracker::Get()->GetAsFileRef(file_ref_id)); + scoped_refptr<FileRef> file_ref(Resource::GetAs<FileRef>(file_ref_id)); if (!file_ref.get()) return PP_FileSystemType_External; @@ -76,8 +75,7 @@ PP_FileSystemType GetFileSystemType(PP_Resource file_ref_id) { } PP_Var GetName(PP_Resource file_ref_id) { - scoped_refptr<FileRef> file_ref( - ResourceTracker::Get()->GetAsFileRef(file_ref_id)); + scoped_refptr<FileRef> file_ref(Resource::GetAs<FileRef>(file_ref_id)); if (!file_ref.get()) return PP_MakeVoid(); @@ -85,8 +83,7 @@ PP_Var GetName(PP_Resource file_ref_id) { } PP_Var GetPath(PP_Resource file_ref_id) { - scoped_refptr<FileRef> file_ref( - ResourceTracker::Get()->GetAsFileRef(file_ref_id)); + scoped_refptr<FileRef> file_ref(Resource::GetAs<FileRef>(file_ref_id)); if (!file_ref.get()) return PP_MakeVoid(); @@ -97,8 +94,7 @@ PP_Var GetPath(PP_Resource file_ref_id) { } PP_Resource GetParent(PP_Resource file_ref_id) { - scoped_refptr<FileRef> file_ref( - ResourceTracker::Get()->GetAsFileRef(file_ref_id)); + scoped_refptr<FileRef> file_ref(Resource::GetAs<FileRef>(file_ref_id)); if (!file_ref.get()) return 0; diff --git a/webkit/glue/plugins/pepper_image_data.cc b/webkit/glue/plugins/pepper_image_data.cc index 783f0a1..56cf877e 100644 --- a/webkit/glue/plugins/pepper_image_data.cc +++ b/webkit/glue/plugins/pepper_image_data.cc @@ -16,7 +16,6 @@ #include "third_party/ppapi/c/ppb_image_data.h" #include "webkit/glue/plugins/pepper_plugin_instance.h" #include "webkit/glue/plugins/pepper_plugin_module.h" -#include "webkit/glue/plugins/pepper_resource_tracker.h" namespace pepper { @@ -43,7 +42,7 @@ PP_Resource Create(PP_Module module_id, } bool IsImageData(PP_Resource resource) { - return !!ResourceTracker::Get()->GetAsImageData(resource).get(); + return !!Resource::GetAs<ImageData>(resource).get(); } bool Describe(PP_Resource resource, @@ -51,8 +50,7 @@ bool Describe(PP_Resource resource, // Give predictable values on failure. memset(desc, 0, sizeof(PP_ImageDataDesc)); - scoped_refptr<ImageData> image_data( - ResourceTracker::Get()->GetAsImageData(resource)); + scoped_refptr<ImageData> image_data(Resource::GetAs<ImageData>(resource)); if (!image_data.get()) return false; image_data->Describe(desc); @@ -60,16 +58,14 @@ bool Describe(PP_Resource resource, } void* Map(PP_Resource resource) { - scoped_refptr<ImageData> image_data( - ResourceTracker::Get()->GetAsImageData(resource)); + scoped_refptr<ImageData> image_data(Resource::GetAs<ImageData>(resource)); if (!image_data.get()) return NULL; return image_data->Map(); } void Unmap(PP_Resource resource) { - scoped_refptr<ImageData> image_data( - ResourceTracker::Get()->GetAsImageData(resource)); + scoped_refptr<ImageData> image_data(Resource::GetAs<ImageData>(resource)); if (!image_data) return; return image_data->Unmap(); diff --git a/webkit/glue/plugins/pepper_plugin_instance.cc b/webkit/glue/plugins/pepper_plugin_instance.cc index d86fffc..97ec093 100644 --- a/webkit/glue/plugins/pepper_plugin_instance.cc +++ b/webkit/glue/plugins/pepper_plugin_instance.cc @@ -23,7 +23,6 @@ #include "webkit/glue/plugins/pepper_device_context_2d.h" #include "webkit/glue/plugins/pepper_plugin_delegate.h" #include "webkit/glue/plugins/pepper_plugin_module.h" -#include "webkit/glue/plugins/pepper_resource_tracker.h" #include "webkit/glue/plugins/pepper_var.h" using WebKit::WebFrame; @@ -214,12 +213,9 @@ bool PluginInstance::BindGraphicsDeviceContext(PP_Resource device_id) { return true; } - scoped_refptr<Resource> device_resource = - ResourceTracker::Get()->GetResource(device_id); - if (!device_resource.get()) - return false; + scoped_refptr<DeviceContext2D> device_2d = + Resource::GetAs<DeviceContext2D>(device_id); - DeviceContext2D* device_2d = device_resource->AsDeviceContext2D(); if (device_2d) { if (!device_2d->BindToInstance(this)) return false; // Can't bind to more than one instance. diff --git a/webkit/glue/plugins/pepper_plugin_module.cc b/webkit/glue/plugins/pepper_plugin_module.cc index 4bb5ea11..4752156 100644 --- a/webkit/glue/plugins/pepper_plugin_module.cc +++ b/webkit/glue/plugins/pepper_plugin_module.cc @@ -117,7 +117,7 @@ bool ReadImageData(PP_Resource device_context_2d, PP_Resource image, int32_t x, int32_t y) { scoped_refptr<DeviceContext2D> context( - ResourceTracker::Get()->GetAsDeviceContext2D(device_context_2d)); + Resource::GetAs<DeviceContext2D>(device_context_2d)); if (!context.get()) return false; return context->ReadImageData(image, x, y); diff --git a/webkit/glue/plugins/pepper_resource.h b/webkit/glue/plugins/pepper_resource.h index efcc211..fdb9d01 100644 --- a/webkit/glue/plugins/pepper_resource.h +++ b/webkit/glue/plugins/pepper_resource.h @@ -8,6 +8,7 @@ #include "base/basictypes.h" #include "base/ref_counted.h" #include "third_party/ppapi/c/pp_resource.h" +#include "webkit/glue/plugins/pepper_resource_tracker.h" namespace pepper { @@ -28,12 +29,26 @@ class Resource : public base::RefCountedThreadSafe<Resource> { explicit Resource(PluginModule* module); virtual ~Resource(); + // Returns NULL if the resource is invalid or is a different type. + template<typename T> + static scoped_refptr<T> GetAs(PP_Resource res) { + scoped_refptr<Resource> resource = ResourceTracker::Get()->GetResource(res); + return resource ? resource->Cast<T>() : NULL; + } + PP_Resource GetResource() const; PluginModule* module() const { return module_; } + // Cast the resource into a specified type. This will return NULL if the + // resource does not match the specified type. Specializations of this + // template call into As* functions. + template <typename T> T* Cast() { return NULL; } + + private: // Type-specific getters for individual resource types. These will return - // NULL if the resource does not match the specified type. + // NULL if the resource does not match the specified type. Used by the Cast() + // function. virtual Buffer* AsBuffer() { return NULL; } virtual DeviceContext2D* AsDeviceContext2D() { return NULL; } virtual DirectoryReader* AsDirectoryReader() { return NULL; } @@ -45,12 +60,29 @@ class Resource : public base::RefCountedThreadSafe<Resource> { virtual URLRequestInfo* AsURLRequestInfo() { return NULL; } virtual URLResponseInfo* AsURLResponseInfo() { return NULL; } - private: PluginModule* module_; // Non-owning pointer to our module. DISALLOW_COPY_AND_ASSIGN(Resource); }; +// Cast() specializations. +#define DEFINE_RESOURCE_CAST(Type) \ + template <> inline Type* Resource::Cast<Type>() { \ + return As##Type(); \ + } + +DEFINE_RESOURCE_CAST(Buffer) +DEFINE_RESOURCE_CAST(DeviceContext2D) +DEFINE_RESOURCE_CAST(DirectoryReader) +DEFINE_RESOURCE_CAST(FileChooser) +DEFINE_RESOURCE_CAST(FileIO) +DEFINE_RESOURCE_CAST(FileRef) +DEFINE_RESOURCE_CAST(ImageData) +DEFINE_RESOURCE_CAST(URLLoader) +DEFINE_RESOURCE_CAST(URLRequestInfo) +DEFINE_RESOURCE_CAST(URLResponseInfo) + +#undef DEFINE_RESOURCE_CAST } // namespace pepper #endif // WEBKIT_GLUE_PLUGINS_PEPPER_RESOURCE_H_ diff --git a/webkit/glue/plugins/pepper_resource_tracker.cc b/webkit/glue/plugins/pepper_resource_tracker.cc index 077c95b..c8779e4 100644 --- a/webkit/glue/plugins/pepper_resource_tracker.cc +++ b/webkit/glue/plugins/pepper_resource_tracker.cc @@ -57,24 +57,4 @@ void ResourceTracker::DeleteResource(Resource* resource) { live_resources_.erase(found); } -#define GET_AS_TYPE_IMPL(Type) \ - scoped_refptr<Type> ResourceTracker::GetAs##Type( \ - PP_Resource res) const { \ - scoped_refptr<Resource> resource = GetResource(res); \ - if (!resource.get()) \ - return scoped_refptr<Type>(); \ - return scoped_refptr<Type>(resource->As##Type()); \ - } - -GET_AS_TYPE_IMPL(Buffer) -GET_AS_TYPE_IMPL(DeviceContext2D) -GET_AS_TYPE_IMPL(DirectoryReader) -GET_AS_TYPE_IMPL(FileChooser) -GET_AS_TYPE_IMPL(FileIO) -GET_AS_TYPE_IMPL(FileRef) -GET_AS_TYPE_IMPL(ImageData) -GET_AS_TYPE_IMPL(URLLoader) -GET_AS_TYPE_IMPL(URLRequestInfo) -GET_AS_TYPE_IMPL(URLResponseInfo) - } // namespace pepper diff --git a/webkit/glue/plugins/pepper_resource_tracker.h b/webkit/glue/plugins/pepper_resource_tracker.h index cfe2e68..35c382d 100644 --- a/webkit/glue/plugins/pepper_resource_tracker.h +++ b/webkit/glue/plugins/pepper_resource_tracker.h @@ -16,17 +16,7 @@ namespace pepper { -class Buffer; -class DeviceContext2D; -class DirectoryReader; -class FileChooser; -class FileIO; -class FileRef; -class ImageData; class Resource; -class URLLoader; -class URLRequestInfo; -class URLResponseInfo; // This class maintains a global list of all live pepper resources. It allows // us to check resource ID validity and to map them to a specific module. @@ -39,7 +29,7 @@ class ResourceTracker { // The returned pointer will be NULL if there is no resource. Note that this // return value is a scoped_refptr so that we ensure the resource is valid - // from the point of the loopkup to the point that the calling code needs it. + // from the point of the lookup to the point that the calling code needs it. // Otherwise, the plugin could Release() the resource on another thread and // the object will get deleted out from under us. scoped_refptr<Resource> GetResource(PP_Resource res) const; @@ -50,19 +40,6 @@ class ResourceTracker { void DeleteResource(Resource* resource); - // Helpers for converting resources to a specific type. Returns NULL if the - // resource is invalid or is a different type. - scoped_refptr<Buffer> GetAsBuffer(PP_Resource res) const; - scoped_refptr<DeviceContext2D> GetAsDeviceContext2D(PP_Resource res) const; - scoped_refptr<DirectoryReader> GetAsDirectoryReader(PP_Resource res) const; - scoped_refptr<FileChooser> GetAsFileChooser(PP_Resource res) const; - scoped_refptr<FileIO> GetAsFileIO(PP_Resource res) const; - scoped_refptr<FileRef> GetAsFileRef(PP_Resource res) const; - scoped_refptr<ImageData> GetAsImageData(PP_Resource res) const; - scoped_refptr<URLLoader> GetAsURLLoader(PP_Resource res) const; - scoped_refptr<URLRequestInfo> GetAsURLRequestInfo(PP_Resource res) const; - scoped_refptr<URLResponseInfo> GetAsURLResponseInfo(PP_Resource res) const; - private: friend struct DefaultSingletonTraits<ResourceTracker>; diff --git a/webkit/glue/plugins/pepper_url_loader.cc b/webkit/glue/plugins/pepper_url_loader.cc index 26be21d..4c38ef4 100644 --- a/webkit/glue/plugins/pepper_url_loader.cc +++ b/webkit/glue/plugins/pepper_url_loader.cc @@ -9,7 +9,6 @@ #include "third_party/ppapi/c/pp_errors.h" #include "third_party/ppapi/c/ppb_url_loader.h" #include "webkit/glue/plugins/pepper_plugin_instance.h" -#include "webkit/glue/plugins/pepper_resource_tracker.h" #include "webkit/glue/plugins/pepper_url_request_info.h" #include "webkit/glue/plugins/pepper_url_response_info.h" @@ -29,19 +28,18 @@ PP_Resource Create(PP_Instance instance_id) { } bool IsURLLoader(PP_Resource resource) { - return !!ResourceTracker::Get()->GetAsURLLoader(resource).get(); + return !!Resource::GetAs<URLLoader>(resource).get(); } int32_t Open(PP_Resource loader_id, PP_Resource request_id, PP_CompletionCallback callback) { - scoped_refptr<URLLoader> loader( - ResourceTracker::Get()->GetAsURLLoader(loader_id)); + scoped_refptr<URLLoader> loader(Resource::GetAs<URLLoader>(loader_id)); if (!loader.get()) return PP_Error_BadResource; scoped_refptr<URLRequestInfo> request( - ResourceTracker::Get()->GetAsURLRequestInfo(request_id)); + Resource::GetAs<URLRequestInfo>(request_id)); if (!request.get()) return PP_Error_BadResource; @@ -50,8 +48,7 @@ int32_t Open(PP_Resource loader_id, int32_t FollowRedirect(PP_Resource loader_id, PP_CompletionCallback callback) { - scoped_refptr<URLLoader> loader( - ResourceTracker::Get()->GetAsURLLoader(loader_id)); + scoped_refptr<URLLoader> loader(Resource::GetAs<URLLoader>(loader_id)); if (!loader.get()) return PP_Error_BadResource; @@ -61,8 +58,7 @@ int32_t FollowRedirect(PP_Resource loader_id, bool GetUploadProgress(PP_Resource loader_id, int64_t* bytes_sent, int64_t* total_bytes_to_be_sent) { - scoped_refptr<URLLoader> loader( - ResourceTracker::Get()->GetAsURLLoader(loader_id)); + scoped_refptr<URLLoader> loader(Resource::GetAs<URLLoader>(loader_id)); if (!loader.get()) return false; @@ -74,8 +70,7 @@ bool GetUploadProgress(PP_Resource loader_id, bool GetDownloadProgress(PP_Resource loader_id, int64_t* bytes_received, int64_t* total_bytes_to_be_received) { - scoped_refptr<URLLoader> loader( - ResourceTracker::Get()->GetAsURLLoader(loader_id)); + scoped_refptr<URLLoader> loader(Resource::GetAs<URLLoader>(loader_id)); if (!loader.get()) return false; @@ -85,8 +80,7 @@ bool GetDownloadProgress(PP_Resource loader_id, } PP_Resource GetResponseInfo(PP_Resource loader_id) { - scoped_refptr<URLLoader> loader( - ResourceTracker::Get()->GetAsURLLoader(loader_id)); + scoped_refptr<URLLoader> loader(Resource::GetAs<URLLoader>(loader_id)); if (!loader.get()) return 0; @@ -102,8 +96,7 @@ int32_t ReadResponseBody(PP_Resource loader_id, char* buffer, int32_t bytes_to_read, PP_CompletionCallback callback) { - scoped_refptr<URLLoader> loader( - ResourceTracker::Get()->GetAsURLLoader(loader_id)); + scoped_refptr<URLLoader> loader(Resource::GetAs<URLLoader>(loader_id)); if (!loader.get()) return PP_Error_BadResource; @@ -111,8 +104,7 @@ int32_t ReadResponseBody(PP_Resource loader_id, } void Close(PP_Resource loader_id) { - scoped_refptr<URLLoader> loader( - ResourceTracker::Get()->GetAsURLLoader(loader_id)); + scoped_refptr<URLLoader> loader(Resource::GetAs<URLLoader>(loader_id)); if (!loader.get()) return; diff --git a/webkit/glue/plugins/pepper_url_request_info.cc b/webkit/glue/plugins/pepper_url_request_info.cc index 9eef1f9..0f48a7b 100644 --- a/webkit/glue/plugins/pepper_url_request_info.cc +++ b/webkit/glue/plugins/pepper_url_request_info.cc @@ -7,7 +7,6 @@ #include "base/logging.h" #include "third_party/ppapi/c/pp_var.h" #include "webkit/glue/plugins/pepper_plugin_module.h" -#include "webkit/glue/plugins/pepper_resource_tracker.h" #include "webkit/glue/plugins/pepper_string.h" #include "webkit/glue/plugins/pepper_var.h" @@ -27,14 +26,14 @@ PP_Resource Create(PP_Module module_id) { } bool IsURLRequestInfo(PP_Resource resource) { - return !!ResourceTracker::Get()->GetAsURLRequestInfo(resource).get(); + return !!Resource::GetAs<URLRequestInfo>(resource).get(); } bool SetProperty(PP_Resource request_id, PP_URLRequestProperty property, PP_Var var) { scoped_refptr<URLRequestInfo> request( - ResourceTracker::Get()->GetAsURLRequestInfo(request_id)); + Resource::GetAs<URLRequestInfo>(request_id)); if (!request.get()) return false; @@ -49,7 +48,7 @@ bool SetProperty(PP_Resource request_id, bool AppendDataToBody(PP_Resource request_id, PP_Var var) { scoped_refptr<URLRequestInfo> request( - ResourceTracker::Get()->GetAsURLRequestInfo(request_id)); + Resource::GetAs<URLRequestInfo>(request_id)); if (!request.get()) return false; diff --git a/webkit/glue/plugins/pepper_url_response_info.cc b/webkit/glue/plugins/pepper_url_response_info.cc index 506eb47..ed92c6c 100644 --- a/webkit/glue/plugins/pepper_url_response_info.cc +++ b/webkit/glue/plugins/pepper_url_response_info.cc @@ -6,20 +6,19 @@ #include "base/logging.h" #include "third_party/ppapi/c/pp_var.h" -#include "webkit/glue/plugins/pepper_resource_tracker.h" namespace pepper { namespace { bool IsURLResponseInfo(PP_Resource resource) { - return !!ResourceTracker::Get()->GetAsURLResponseInfo(resource).get(); + return !!Resource::GetAs<URLResponseInfo>(resource).get(); } PP_Var GetProperty(PP_Resource response_id, PP_URLResponseProperty property) { scoped_refptr<URLResponseInfo> response( - ResourceTracker::Get()->GetAsURLResponseInfo(response_id)); + Resource::GetAs<URLResponseInfo>(response_id)); if (!response.get()) return PP_MakeVoid(); |