1 // Copyright (c) 2011 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.
5 #ifndef PPAPI_SHARED_IMPL_HOST_RESOURCE_H_
6 #define PPAPI_SHARED_IMPL_HOST_RESOURCE_H_
8 #include "ppapi/c/pp_instance.h"
9 #include "ppapi/c/pp_resource.h"
10 #include "ppapi/shared_impl/ppapi_shared_export.h"
14 // Represents a PP_Resource sent over the wire. This just wraps a PP_Resource.
15 // The point is to prevent mistakes where the wrong resource value is sent.
16 // Resource values are remapped in the plugin so that it can talk to multiple
17 // hosts. If all values were PP_Resource, it would be easy to forget to do
18 // this transformation.
20 // To get the corresponding plugin PP_Resource for a HostResource, use
21 // PluginResourceTracker::PluginResourceForHostResource().
23 // All HostResources respresent IDs valid in the host.
24 class PPAPI_SHARED_EXPORT HostResource
{
28 bool is_null() const {
29 return !host_resource_
;
32 // Some resources are plugin-side only and don't have a corresponding
33 // resource in the host. Yet these resources still need an instance to be
34 // associated with. This function creates a HostResource with the given
35 // instances and a 0 host resource ID for these cases.
36 static HostResource
MakeInstanceOnly(PP_Instance instance
);
38 // Sets and retrieves the internal PP_Resource which is valid for the host
39 // (a.k.a. renderer, as opposed to the plugin) process.
41 // DO NOT CALL THESE FUNCTIONS IN THE PLUGIN SIDE OF THE PROXY. The values
42 // will be invalid. See the class comment above.
43 void SetHostResource(PP_Instance instance
, PP_Resource resource
);
44 PP_Resource
host_resource() const {
45 return host_resource_
;
48 PP_Instance
instance() const { return instance_
; }
50 // This object is used in maps so we need to provide this sorting operator.
51 bool operator<(const HostResource
& other
) const {
52 if (instance_
!= other
.instance_
)
53 return instance_
< other
.instance_
;
54 return host_resource_
< other
.host_resource_
;
58 PP_Instance instance_
;
59 PP_Resource host_resource_
;
64 #endif // PPAPI_SHARED_IMPL_HOST_RESOURCE_H_