Implement HasPermission() method in PermissionService.
[chromium-blink-merge.git] / content / renderer / pepper / v8object_var.h
blob0480fbe824555faee3c1257fd4468b1b86cd0e0b
1 // Copyright 2014 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 CONTENT_RENDERER_PEPPER_V8OBJECT_VAR_H_
6 #define CONTENT_RENDERER_PEPPER_V8OBJECT_VAR_H_
8 #include <string>
10 #include "base/compiler_specific.h"
11 #include "content/common/content_export.h"
12 #include "ppapi/c/pp_instance.h"
13 #include "ppapi/shared_impl/var.h"
14 #include "v8/include/v8.h"
16 namespace content {
17 class PepperPluginInstanceImpl;
18 } // namespace content
20 namespace ppapi {
22 // V8ObjectVar -----------------------------------------------------------------
24 // Represents a JavaScript object Var. By itself, this represents random
25 // v8 objects that a given plugin (identified by the resource's module) wants to
26 // reference. If two different modules reference the same v8 object (like the
27 // "window" object), then there will be different V8ObjectVar's (and hence
28 // PP_Var IDs) for each module. This allows us to track all references owned by
29 // a given module and free them when the plugin exits independently of other
30 // plugins that may be running at the same time.
31 class CONTENT_EXPORT V8ObjectVar : public Var {
32 public:
33 V8ObjectVar(PP_Instance instance, v8::Handle<v8::Object> v8_object);
35 // Var overrides.
36 V8ObjectVar* AsV8ObjectVar() override;
37 PP_VarType GetType() const override;
39 // Returns the underlying v8 object corresponding to this V8ObjectVar. This
40 // should only be used on the stack.
41 v8::Local<v8::Object> GetHandle() const;
43 // Notification that the instance was deleted, the internal reference will be
44 // zeroed out.
45 void InstanceDeleted();
47 // Possibly NULL if the object has outlived its instance.
48 content::PepperPluginInstanceImpl* instance() const { return instance_; }
50 // Helper function that converts a PP_Var to an object. This will return NULL
51 // if the PP_Var is not of object type or the object is invalid.
52 static scoped_refptr<V8ObjectVar> FromPPVar(PP_Var var);
54 private:
55 ~V8ObjectVar() override;
57 content::PepperPluginInstanceImpl* instance_;
59 v8::Persistent<v8::Object> v8_object_;
61 DISALLOW_COPY_AND_ASSIGN(V8ObjectVar);
64 } // ppapi
66 #endif // CONTENT_RENDERER_PEPPER_V8OBJECT_VAR_H_