Avi Drissman | 4e1b7bc3 | 2022-09-15 14:03:50 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors |
[email protected] | b2183af | 2014-08-11 02:59:12 | [diff] [blame] | 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 CONTENT_RENDERER_PEPPER_V8OBJECT_VAR_H_ | ||||
6 | #define CONTENT_RENDERER_PEPPER_V8OBJECT_VAR_H_ | ||||
7 | |||||
Kalvin Lee | bc3754ae | 2023-10-01 22:37:34 | [diff] [blame] | 8 | #include "base/memory/raw_ptr.h" |
[email protected] | b2183af | 2014-08-11 02:59:12 | [diff] [blame] | 9 | #include "content/common/content_export.h" |
10 | #include "ppapi/c/pp_instance.h" | ||||
11 | #include "ppapi/shared_impl/var.h" | ||||
Dan Elphick | c925673600 | 2021-09-16 09:30:11 | [diff] [blame] | 12 | #include "v8/include/v8-forward.h" |
13 | #include "v8/include/v8-persistent-handle.h" | ||||
[email protected] | b2183af | 2014-08-11 02:59:12 | [diff] [blame] | 14 | |
[email protected] | 7f1e19e | 2014-08-13 03:47:22 | [diff] [blame] | 15 | namespace content { |
16 | class PepperPluginInstanceImpl; | ||||
17 | } // namespace content | ||||
18 | |||||
[email protected] | b2183af | 2014-08-11 02:59:12 | [diff] [blame] | 19 | namespace 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 | ||||
raymes | a9d7732 | 2014-09-09 03:42:46 | [diff] [blame] | 25 | // reference. If two different modules reference the same v8 object (like the |
[email protected] | b2183af | 2014-08-11 02:59:12 | [diff] [blame] | 26 | // "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. | ||||
raymes | 2515b7d | 2014-09-04 23:01:29 | [diff] [blame] | 30 | class CONTENT_EXPORT V8ObjectVar : public Var { |
[email protected] | b2183af | 2014-08-11 02:59:12 | [diff] [blame] | 31 | public: |
deepak.s | 750d68f | 2015-04-30 07:32:41 | [diff] [blame] | 32 | V8ObjectVar(PP_Instance instance, v8::Local<v8::Object> v8_object); |
[email protected] | b2183af | 2014-08-11 02:59:12 | [diff] [blame] | 33 | |
Peter Boström | 9b03653 | 2021-10-28 23:37:28 | [diff] [blame] | 34 | V8ObjectVar(const V8ObjectVar&) = delete; |
35 | V8ObjectVar& operator=(const V8ObjectVar&) = delete; | ||||
36 | |||||
[email protected] | b2183af | 2014-08-11 02:59:12 | [diff] [blame] | 37 | // Var overrides. |
dcheng | 6d18e40 | 2014-10-21 12:32:52 | [diff] [blame] | 38 | V8ObjectVar* AsV8ObjectVar() override; |
39 | PP_VarType GetType() const override; | ||||
[email protected] | b2183af | 2014-08-11 02:59:12 | [diff] [blame] | 40 | |
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] | 7f1e19e | 2014-08-13 03:47:22 | [diff] [blame] | 49 | // Possibly NULL if the object has outlived its instance. |
50 | content::PepperPluginInstanceImpl* instance() const { return instance_; } | ||||
[email protected] | b2183af | 2014-08-11 02:59:12 | [diff] [blame] | 51 | |
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. | ||||
raymes | 2515b7d | 2014-09-04 23:01:29 | [diff] [blame] | 54 | static scoped_refptr<V8ObjectVar> FromPPVar(PP_Var var); |
[email protected] | b2183af | 2014-08-11 02:59:12 | [diff] [blame] | 55 | |
56 | private: | ||||
dcheng | 6d18e40 | 2014-10-21 12:32:52 | [diff] [blame] | 57 | ~V8ObjectVar() override; |
[email protected] | b2183af | 2014-08-11 02:59:12 | [diff] [blame] | 58 | |
Bartek Nowierski | f473c24b | 2024-02-20 17:51:15 | [diff] [blame] | 59 | raw_ptr<content::PepperPluginInstanceImpl> instance_; |
[email protected] | b2183af | 2014-08-11 02:59:12 | [diff] [blame] | 60 | |
61 | v8::Persistent<v8::Object> v8_object_; | ||||
[email protected] | b2183af | 2014-08-11 02:59:12 | [diff] [blame] | 62 | }; |
63 | |||||
64 | } // ppapi | ||||
65 | |||||
66 | #endif // CONTENT_RENDERER_PEPPER_V8OBJECT_VAR_H_ |