OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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_SHARED_IMPL_RESOURCE_VAR_H_ | 5 #ifndef PPAPI_SHARED_IMPL_RESOURCE_VAR_H_ |
6 #define PPAPI_SHARED_IMPL_RESOURCE_VAR_H_ | 6 #define PPAPI_SHARED_IMPL_RESOURCE_VAR_H_ |
7 | 7 |
8 #include "ipc/ipc_message.h" | |
9 #include "ppapi/c/pp_resource.h" | 8 #include "ppapi/c/pp_resource.h" |
10 #include "ppapi/c/pp_var.h" | 9 #include "ppapi/c/pp_var.h" |
11 #include "ppapi/shared_impl/ppapi_shared_export.h" | 10 #include "ppapi/shared_impl/ppapi_shared_export.h" |
12 #include "ppapi/shared_impl/var.h" | 11 #include "ppapi/shared_impl/var.h" |
13 | 12 |
| 13 namespace IPC { |
| 14 class Message; |
| 15 } |
| 16 |
14 namespace ppapi { | 17 namespace ppapi { |
15 | 18 |
16 // Represents a resource Var. | 19 // Represents a resource Var. |
17 class PPAPI_SHARED_EXPORT ResourceVar : public Var { | 20 class PPAPI_SHARED_EXPORT ResourceVar : public Var { |
18 public: | 21 public: |
19 // Makes a null resource var. | 22 // Gets the resource ID associated with this var. |
20 ResourceVar(); | 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; |
21 | 27 |
22 // Makes a resource var with an existing plugin-side resource. | 28 // Gets the message for creating a plugin-side resource. Returns NULL if the |
23 explicit ResourceVar(PP_Resource pp_resource); | 29 // message is empty (which is always true on the plugin side). |
24 | 30 virtual const IPC::Message* GetCreationMessage() const; |
25 // Makes a resource var with a pending resource host. | |
26 // The |creation_message| contains instructions on how to create the | |
27 // plugin-side resource. Its type depends on the type of resource. | |
28 explicit ResourceVar(const IPC::Message& creation_message); | |
29 | |
30 virtual ~ResourceVar(); | |
31 | |
32 // Gets the resource ID associated with this var. | |
33 // This is 0 if a resource is still pending. | |
34 PP_Resource pp_resource() const { return pp_resource_; } | |
35 | |
36 // Gets the message for creating a plugin-side resource. | |
37 // May be an empty message. | |
38 const IPC::Message& creation_message() const { return creation_message_; } | |
39 | 31 |
40 // Determines whether this is a pending resource. | 32 // Determines whether this is a pending resource. |
41 // This is true if the pp_resource is 0 and there is a non-empty | 33 // This is true if, on the host side, the there is a creation_message and no |
42 // creation_message. | 34 // PP_Resource. |
43 bool IsPending() const; | 35 virtual bool IsPending() const = 0; |
44 | 36 |
45 // Var override. | 37 // Var override. |
46 virtual ResourceVar* AsResourceVar() OVERRIDE; | 38 virtual ResourceVar* AsResourceVar() OVERRIDE; |
47 virtual PP_VarType GetType() const OVERRIDE; | 39 virtual PP_VarType GetType() const OVERRIDE; |
48 | 40 |
49 // Helper function that converts a PP_Var to a ResourceVar. This will | 41 // Helper function that converts a PP_Var to a ResourceVar. This will |
50 // return NULL if the PP_Var is not of Resource type. | 42 // return NULL if the PP_Var is not of Resource type. |
51 static ResourceVar* FromPPVar(PP_Var var); | 43 static ResourceVar* FromPPVar(PP_Var var); |
52 | 44 |
| 45 protected: |
| 46 ResourceVar(); |
| 47 |
| 48 virtual ~ResourceVar(); |
| 49 |
53 private: | 50 private: |
54 // Real resource ID in the plugin. 0 if one has not yet been created | |
55 // (indicating that there is a pending host resource). | |
56 PP_Resource pp_resource_; | |
57 | |
58 // If the plugin-side resource has not yet been created, carries a message to | |
59 // create a resource of the specific type on the plugin side. | |
60 // Otherwise, carries an empty message. | |
61 IPC::Message creation_message_; | |
62 | |
63 DISALLOW_COPY_AND_ASSIGN(ResourceVar); | 51 DISALLOW_COPY_AND_ASSIGN(ResourceVar); |
64 }; | 52 }; |
65 | 53 |
66 } // namespace ppapi | 54 } // namespace ppapi |
67 | 55 |
68 #endif // PPAPI_SHARED_IMPL_RESOURCE_VAR_H_ | 56 #endif // PPAPI_SHARED_IMPL_RESOURCE_VAR_H_ |
OLD | NEW |