blob: 7e894c61ef2b835247018b4005f0cf682fc0895a [file] [log] [blame]
Avi Drissman4e1b7bc32022-09-15 14:03:501// Copyright 2014 The Chromium Authors
[email protected]b2183af2014-08-11 02:59:122// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CONTENT_RENDERER_PEPPER_V8OBJECT_VAR_H_
6#define CONTENT_RENDERER_PEPPER_V8OBJECT_VAR_H_
7
Kalvin Leebc3754ae2023-10-01 22:37:348#include "base/memory/raw_ptr.h"
[email protected]b2183af2014-08-11 02:59:129#include "content/common/content_export.h"
10#include "ppapi/c/pp_instance.h"
11#include "ppapi/shared_impl/var.h"
Dan Elphickc9256736002021-09-16 09:30:1112#include "v8/include/v8-forward.h"
13#include "v8/include/v8-persistent-handle.h"
[email protected]b2183af2014-08-11 02:59:1214
[email protected]7f1e19e2014-08-13 03:47:2215namespace content {
16class PepperPluginInstanceImpl;
17} // namespace content
18
[email protected]b2183af2014-08-11 02:59:1219namespace ppapi {
20
21// V8ObjectVar -----------------------------------------------------------------
22
23// Represents a JavaScript object Var. By itself, this represents random
24// v8 objects that a given plugin (identified by the resource's module) wants to
raymesa9d77322014-09-09 03:42:4625// reference. If two different modules reference the same v8 object (like the
[email protected]b2183af2014-08-11 02:59:1226// "window" object), then there will be different V8ObjectVar's (and hence
27// PP_Var IDs) for each module. This allows us to track all references owned by
28// a given module and free them when the plugin exits independently of other
29// plugins that may be running at the same time.
raymes2515b7d2014-09-04 23:01:2930class CONTENT_EXPORT V8ObjectVar : public Var {
[email protected]b2183af2014-08-11 02:59:1231 public:
deepak.s750d68f2015-04-30 07:32:4132 V8ObjectVar(PP_Instance instance, v8::Local<v8::Object> v8_object);
[email protected]b2183af2014-08-11 02:59:1233
Peter Boström9b036532021-10-28 23:37:2834 V8ObjectVar(const V8ObjectVar&) = delete;
35 V8ObjectVar& operator=(const V8ObjectVar&) = delete;
36
[email protected]b2183af2014-08-11 02:59:1237 // Var overrides.
dcheng6d18e402014-10-21 12:32:5238 V8ObjectVar* AsV8ObjectVar() override;
39 PP_VarType GetType() const override;
[email protected]b2183af2014-08-11 02:59:1240
41 // Returns the underlying v8 object corresponding to this V8ObjectVar. This
42 // should only be used on the stack.
43 v8::Local<v8::Object> GetHandle() const;
44
45 // Notification that the instance was deleted, the internal reference will be
46 // zeroed out.
47 void InstanceDeleted();
48
[email protected]7f1e19e2014-08-13 03:47:2249 // Possibly NULL if the object has outlived its instance.
50 content::PepperPluginInstanceImpl* instance() const { return instance_; }
[email protected]b2183af2014-08-11 02:59:1251
52 // Helper function that converts a PP_Var to an object. This will return NULL
53 // if the PP_Var is not of object type or the object is invalid.
raymes2515b7d2014-09-04 23:01:2954 static scoped_refptr<V8ObjectVar> FromPPVar(PP_Var var);
[email protected]b2183af2014-08-11 02:59:1255
56 private:
dcheng6d18e402014-10-21 12:32:5257 ~V8ObjectVar() override;
[email protected]b2183af2014-08-11 02:59:1258
Bartek Nowierskif473c24b2024-02-20 17:51:1559 raw_ptr<content::PepperPluginInstanceImpl> instance_;
[email protected]b2183af2014-08-11 02:59:1260
61 v8::Persistent<v8::Object> v8_object_;
[email protected]b2183af2014-08-11 02:59:1262};
63
64} // ppapi
65
66#endif // CONTENT_RENDERER_PEPPER_V8OBJECT_VAR_H_