Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(157)

Side by Side Diff: ppapi/native_client/src/trusted/plugin/scriptable_handle.h

Issue 9390028: Remove browser support for non-PPAPI nexes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 // The browser scriptable container class. The methods on this class
6 // are defined in the specific API directories.
7
8 #ifndef NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_SCRIPTABLE_HANDLE_H_
9 #define NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_SCRIPTABLE_HANDLE_H_
10
11 #include "native_client/src/trusted/plugin/scriptable_handle.h"
12
13 #include <stdio.h>
14 #include <string.h>
15
16 #include <set>
17 #include <string>
18 #include <vector>
19
20 #include "native_client/src/include/checked_cast.h"
21 #include "native_client/src/include/nacl_macros.h"
22 #include "native_client/src/include/nacl_string.h"
23 #include "native_client/src/include/portability.h"
24 #include "native_client/src/trusted/plugin/utility.h"
25 #include "ppapi/cpp/dev/scriptable_object_deprecated.h"
26 #include "ppapi/cpp/private/var_private.h"
27
28 namespace plugin {
29
30 // Forward declarations for externals.
31 class DescBasedHandle;
32 class Plugin;
33
34 // ScriptableHandle encapsulates objects that are scriptable from the browser.
35 class ScriptableHandle : public pp::deprecated::ScriptableObject {
36 public:
37 // Factory methods for creation.
38 static ScriptableHandle* NewPlugin(Plugin* plugin);
39 static ScriptableHandle* NewDescHandle(DescBasedHandle* desc_handle);
40
41 // If not NULL, this var should be reused to pass this object to the browser.
42 pp::VarPrivate* var() { return var_; }
43
44 // Check that a pointer is to a validly created ScriptableHandle.
45 static bool is_valid(const ScriptableHandle* handle);
46 static void Unref(ScriptableHandle** handle);
47
48 // Get the contained plugin object. NULL if this contains a descriptor.
49 Plugin* plugin() const { return plugin_; }
50
51 // Get the contained descriptor object. NULL if this contains a plugin.
52 // OBSOLETE -- this support is only needed for SRPC descriptor passing.
53 // TODO(polina): Remove this support when SRPC descriptor passing is removed.
54 DescBasedHandle* desc_handle() const { return desc_handle_; }
55
56 // This function is called when we are about to share the object owned by the
57 // plugin with the browser. Since reference counting on the browser side is
58 // handled via pp::Var's, we create the var() here if not created already.
59 ScriptableHandle* AddRef();
60 // Remove a browser reference to this object.
61 // Delete the object when the ref count becomes 0.
62 // If var() is set, we delete it. Otherwise, we delete the object itself.
63 // Therefore, this cannot be called more than once.
64 void Unref();
65
66 // ------ Methods inherited from pp::deprecated::ScriptableObject:
67
68 // Returns true for preloaded NaCl Plugin properties.
69 // Does not set |exception|.
70 virtual bool HasProperty(const pp::Var& name, pp::Var* exception);
71 // Returns true for preloaded NaCl Plugin methods and SRPC methods exported
72 // from a NaCl module. Does not set |exception|.
73 virtual bool HasMethod(const pp::Var& name, pp::Var* exception);
74
75 // Gets the value of a preloaded NaCl Plugin property.
76 // Sets |exception| on failure.
77 virtual pp::Var GetProperty(const pp::Var& name, pp::Var* exception);
78 // Sets the value of a preloaded NaCl Plugin property.
79 // Does not add new properties. Sets |exception| of failure.
80 virtual void SetProperty(const pp::Var& name, const pp::Var& value,
81 pp::Var* exception);
82 // Set |exception| to indicate that property removal is not supported.
83 virtual void RemoveProperty(const pp::Var& name, pp::Var* exception);
84 // Returns a list of all preloaded NaCl Plugin |properties|.
85 // Does not set |exception|.
86 virtual void GetAllPropertyNames(std::vector<pp::Var>* properties,
87 pp::Var* exception);
88
89 // Calls preloaded NaCl Plugin methods or SRPC methods exported from
90 // a NaCl module. Sets |exception| on failure.
91 virtual pp::Var Call(const pp::Var& name, const std::vector<pp::Var>& args,
92 pp::Var* exception);
93
94 // Sets |exception| to indicate that constructor is not supported.
95 virtual pp::Var Construct(const std::vector<pp::Var>& args,
96 pp::Var* exception);
97
98 private:
99 NACL_DISALLOW_COPY_AND_ASSIGN(ScriptableHandle);
100 // Prevent construction from outside the class: must use factory New()
101 // method instead.
102 explicit ScriptableHandle(Plugin* plugin);
103 explicit ScriptableHandle(DescBasedHandle* desc_handle);
104 // This will be called when both the plugin and the browser clear all
105 // references to this object.
106 virtual ~ScriptableHandle();
107
108 // When we pass the object owned by the plugin to the browser, we need to wrap
109 // it in a pp::VarPrivate, which also registers the object with the browser
110 // for refcounting. It must be registered only once with all other var
111 // references being copies of the original one. Thus, we record the
112 // pp::VarPrivate here and reuse it when satisfiying additional browser
113 // requests. This way we also ensure that when the browser clears its
114 // references, this object does not get deallocated while we still hold ours.
115 // This is never set for objects that are not shared with the browser nor for
116 // objects created during SRPC calls as they are taken over by the browser on
117 // return.
118 pp::VarPrivate* var_;
119
120 // We should have no more than one internal plugin owner for this object,
121 // and only that owner should call Unref(). To CHECK for that keep a counter.
122 int num_unref_calls_;
123
124 // The contained plugin object.
125 Plugin* plugin_;
126 // OBSOLETE -- this support is only needed for SRPC descriptor passing.
127 // TODO(polina): Remove this support when SRPC descriptor passing is removed.
128 // The contained descriptor handle object.
129 DescBasedHandle* desc_handle_;
130 };
131
132 } // namespace plugin
133
134 #endif // NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_SCRIPTABLE_HANDLE_H_
OLDNEW
« no previous file with comments | « ppapi/native_client/src/trusted/plugin/pnacl_resources.cc ('k') | ppapi/native_client/src/trusted/plugin/scriptable_handle.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698