diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-03 03:22:33 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-03 03:22:33 +0000 |
commit | c2932f5e2101022f6fe59dabd462ccc328788d4e (patch) | |
tree | 0690f2db30f3f1591c8dec15fbd4d0c63c662899 /ppapi/proxy/plugin_resource.h | |
parent | 685b7699b2845fd74e601a3a9f74cf3b63c9f38a (diff) | |
download | chromium_src-c2932f5e2101022f6fe59dabd462ccc328788d4e.zip chromium_src-c2932f5e2101022f6fe59dabd462ccc328788d4e.tar.gz chromium_src-c2932f5e2101022f6fe59dabd462ccc328788d4e.tar.bz2 |
Core PPAPI proxy files. This includes the dispatcher which is the control point
on each end of the IPC channel. It includes the IPC message definitions. It
also includes the base class for the interface proxying, and the core resource
and var tracking.
BUG=none
TEST=none
Review=http://codereview.chromium.org/4229002/show
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@64874 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/proxy/plugin_resource.h')
-rw-r--r-- | ppapi/proxy/plugin_resource.h | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/ppapi/proxy/plugin_resource.h b/ppapi/proxy/plugin_resource.h new file mode 100644 index 0000000..9a70266 --- /dev/null +++ b/ppapi/proxy/plugin_resource.h @@ -0,0 +1,64 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_PROXY_PLUGIN_RESOURCE_H_ +#define PPAPI_PROXY_PLUGIN_RESOURCE_H_ + +#include "base/basictypes.h" +#include "ppapi/proxy/plugin_dispatcher.h" +#include "ppapi/proxy/plugin_resource_tracker.h" + +// If you inherit from resource, make sure you add the class name here. +#define FOR_ALL_RESOURCES(F) \ + F(Graphics2D) \ + F(ImageData) \ + F(URLLoader) + +namespace pp { +namespace proxy { + +// Forward declaration of Resource classes. +#define DECLARE_RESOURCE_CLASS(RESOURCE) class RESOURCE; +FOR_ALL_RESOURCES(DECLARE_RESOURCE_CLASS) +#undef DECLARE_RESOURCE_CLASS + +class PluginResource { + public: + PluginResource(); + virtual ~PluginResource(); + + // Returns NULL if the resource is invalid or is a different type. + template<typename T> static T* GetAs(PP_Resource res) { + PluginResource* resource = + PluginDispatcher::Get()->plugin_resource_tracker()->GetResourceObject( + res); + return resource ? resource->Cast<T>() : NULL; + } + + 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. Used by the Cast() + // function. + #define DEFINE_TYPE_GETTER(RESOURCE) \ + virtual RESOURCE* As##RESOURCE() { return NULL; } + FOR_ALL_RESOURCES(DEFINE_TYPE_GETTER) + #undef DEFINE_TYPE_GETTER + + DISALLOW_COPY_AND_ASSIGN(PluginResource); +}; + +// Cast() specializations. +#define DEFINE_RESOURCE_CAST(Type) \ + template <> inline Type* PluginResource::Cast<Type>() { \ + return As##Type(); \ + } +FOR_ALL_RESOURCES(DEFINE_RESOURCE_CAST) +#undef DEFINE_RESOURCE_CAST + +} // namespace proxy +} // namespace pp + +#endif // PPAPI_PROXY_PLUGIN_RESOURCE_H_ |