- add sources.
[platform/framework/web/crosswalk.git] / src / ppapi / shared_impl / resource_var.h
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef PPAPI_SHARED_IMPL_RESOURCE_VAR_H_
6 #define PPAPI_SHARED_IMPL_RESOURCE_VAR_H_
7
8 #include "ppapi/c/pp_resource.h"
9 #include "ppapi/c/pp_var.h"
10 #include "ppapi/shared_impl/ppapi_shared_export.h"
11 #include "ppapi/shared_impl/var.h"
12
13 namespace IPC {
14 class Message;
15 }
16
17 namespace ppapi {
18
19 // Represents a resource Var.
20 class PPAPI_SHARED_EXPORT ResourceVar : public Var {
21  public:
22   // Gets the resource ID associated with this var.
23   // This is 0 if a resource is still pending (only possible on the host side).
24   // NOTE: This can return a PP_Resource with a reference count of 0 on the
25   // plugin side. It should be AddRef'd if the resource is passed to the user.
26   virtual PP_Resource GetPPResource() const = 0;
27
28   // Gets the pending resource host ID in the renderer.
29   virtual int GetPendingRendererHostId() const;
30
31   // Gets the pending resource host ID in the browser.
32   virtual int GetPendingBrowserHostId() const;
33
34   // Gets the message for creating a plugin-side resource. Returns NULL if the
35   // message is empty (which is always true on the plugin side).
36   virtual const IPC::Message* GetCreationMessage() const;
37
38   // Determines whether this is a pending resource.
39   // This is true if, on the host side, the there is a creation_message and no
40   // PP_Resource.
41   virtual bool IsPending() const = 0;
42
43   // Var override.
44   virtual ResourceVar* AsResourceVar() OVERRIDE;
45   virtual PP_VarType GetType() const OVERRIDE;
46
47   // Helper function that converts a PP_Var to a ResourceVar. This will
48   // return NULL if the PP_Var is not of Resource type.
49   static ResourceVar* FromPPVar(PP_Var var);
50
51  protected:
52   ResourceVar();
53
54   virtual ~ResourceVar();
55
56  private:
57   DISALLOW_COPY_AND_ASSIGN(ResourceVar);
58 };
59
60 }  // namespace ppapi
61
62 #endif  // PPAPI_SHARED_IMPL_RESOURCE_VAR_H_