| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // The browser scriptable container class. The methods on this class | 5 // The browser scriptable container class. The methods on this class |
| 6 // are defined in the specific API directories. | 6 // are defined in the specific API directories. |
| 7 | 7 |
| 8 #ifndef NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_SCRIPTABLE_HANDLE_H_ | 8 #ifndef NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_SCRIPTABLE_PLUGIN_H_ |
| 9 #define NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_SCRIPTABLE_HANDLE_H_ | 9 #define NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_SCRIPTABLE_PLUGIN_H_ |
| 10 | 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> | 11 #include <vector> |
| 19 | 12 |
| 20 #include "native_client/src/include/checked_cast.h" | |
| 21 #include "native_client/src/include/nacl_macros.h" | 13 #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" | 14 #include "native_client/src/include/portability.h" |
| 24 #include "native_client/src/trusted/plugin/utility.h" | 15 #include "native_client/src/trusted/plugin/utility.h" |
| 25 #include "ppapi/cpp/dev/scriptable_object_deprecated.h" | 16 #include "ppapi/cpp/dev/scriptable_object_deprecated.h" |
| 26 #include "ppapi/cpp/private/var_private.h" | 17 #include "ppapi/cpp/private/var_private.h" |
| 27 | 18 |
| 28 namespace plugin { | 19 namespace plugin { |
| 29 | 20 |
| 30 // Forward declarations for externals. | 21 // Forward declarations for externals. |
| 31 class DescBasedHandle; | |
| 32 class Plugin; | 22 class Plugin; |
| 33 | 23 |
| 34 // ScriptableHandle encapsulates objects that are scriptable from the browser. | 24 // ScriptablePlugin encapsulates plugins that are scriptable from the browser. |
| 35 class ScriptableHandle : public pp::deprecated::ScriptableObject { | 25 class ScriptablePlugin : public pp::deprecated::ScriptableObject { |
| 36 public: | 26 public: |
| 37 // Factory methods for creation. | 27 // Factory method. |
| 38 static ScriptableHandle* NewPlugin(Plugin* plugin); | 28 static ScriptablePlugin* NewPlugin(Plugin* plugin); |
| 39 static ScriptableHandle* NewDescHandle(DescBasedHandle* desc_handle); | |
| 40 | 29 |
| 41 // If not NULL, this var should be reused to pass this object to the browser. | 30 // If not NULL, this var should be reused to pass this object to the browser. |
| 42 pp::VarPrivate* var() { return var_; } | 31 pp::VarPrivate* var() { return var_; } |
| 43 | 32 |
| 44 // Check that a pointer is to a validly created ScriptableHandle. | 33 static void Unref(ScriptablePlugin** handle); |
| 45 static bool is_valid(const ScriptableHandle* handle); | |
| 46 static void Unref(ScriptableHandle** handle); | |
| 47 | 34 |
| 48 // Get the contained plugin object. NULL if this contains a descriptor. | 35 // Get the contained plugin object. NULL if this contains a descriptor. |
| 49 Plugin* plugin() const { return plugin_; } | 36 Plugin* plugin() const { return plugin_; } |
| 50 | 37 |
| 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 | 38 // 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 | 39 // 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. | 40 // handled via pp::Var's, we create the var() here if not created already. |
| 59 ScriptableHandle* AddRef(); | 41 ScriptablePlugin* AddRef(); |
| 60 // Remove a browser reference to this object. | 42 // Remove a browser reference to this object. |
| 61 // Delete the object when the ref count becomes 0. | 43 // Delete the object when the ref count becomes 0. |
| 62 // If var() is set, we delete it. Otherwise, we delete the object itself. | 44 // If var() is set, we delete it. Otherwise, we delete the object itself. |
| 63 // Therefore, this cannot be called more than once. | 45 // Therefore, this cannot be called more than once. |
| 64 void Unref(); | 46 void Unref(); |
| 65 | 47 |
| 66 // ------ Methods inherited from pp::deprecated::ScriptableObject: | 48 // ------ Methods inherited from pp::deprecated::ScriptableObject: |
| 67 | 49 |
| 68 // Returns true for preloaded NaCl Plugin properties. | 50 // Returns true for preloaded NaCl Plugin properties. |
| 69 // Does not set |exception|. | 51 // Does not set |exception|. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 89 // Calls preloaded NaCl Plugin methods or SRPC methods exported from | 71 // Calls preloaded NaCl Plugin methods or SRPC methods exported from |
| 90 // a NaCl module. Sets |exception| on failure. | 72 // a NaCl module. Sets |exception| on failure. |
| 91 virtual pp::Var Call(const pp::Var& name, const std::vector<pp::Var>& args, | 73 virtual pp::Var Call(const pp::Var& name, const std::vector<pp::Var>& args, |
| 92 pp::Var* exception); | 74 pp::Var* exception); |
| 93 | 75 |
| 94 // Sets |exception| to indicate that constructor is not supported. | 76 // Sets |exception| to indicate that constructor is not supported. |
| 95 virtual pp::Var Construct(const std::vector<pp::Var>& args, | 77 virtual pp::Var Construct(const std::vector<pp::Var>& args, |
| 96 pp::Var* exception); | 78 pp::Var* exception); |
| 97 | 79 |
| 98 private: | 80 private: |
| 99 NACL_DISALLOW_COPY_AND_ASSIGN(ScriptableHandle); | 81 NACL_DISALLOW_COPY_AND_ASSIGN(ScriptablePlugin); |
| 100 // Prevent construction from outside the class: must use factory New() | 82 // Prevent construction from outside the class: must use factory New() |
| 101 // method instead. | 83 // method instead. |
| 102 explicit ScriptableHandle(Plugin* plugin); | 84 explicit ScriptablePlugin(Plugin* plugin); |
| 103 explicit ScriptableHandle(DescBasedHandle* desc_handle); | |
| 104 // This will be called when both the plugin and the browser clear all | 85 // This will be called when both the plugin and the browser clear all |
| 105 // references to this object. | 86 // references to this object. |
| 106 virtual ~ScriptableHandle(); | 87 virtual ~ScriptablePlugin(); |
| 107 | 88 |
| 108 // When we pass the object owned by the plugin to the browser, we need to wrap | 89 // 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 | 90 // 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 | 91 // for refcounting. It must be registered only once with all other var |
| 111 // references being copies of the original one. Thus, we record the | 92 // references being copies of the original one. Thus, we record the |
| 112 // pp::VarPrivate here and reuse it when satisfiying additional browser | 93 // pp::VarPrivate here and reuse it when satisfiying additional browser |
| 113 // requests. This way we also ensure that when the browser clears its | 94 // 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. | 95 // 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 | 96 // 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 | 97 // objects created during SRPC calls as they are taken over by the browser on |
| 117 // return. | 98 // return. |
| 118 pp::VarPrivate* var_; | 99 pp::VarPrivate* var_; |
| 119 | 100 |
| 120 // We should have no more than one internal plugin owner for this object, | 101 // 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. | 102 // and only that owner should call Unref(). To CHECK for that keep a counter. |
| 122 int num_unref_calls_; | 103 int num_unref_calls_; |
| 123 | 104 |
| 124 // The contained plugin object. | 105 // The contained plugin object. |
| 125 Plugin* plugin_; | 106 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 }; | 107 }; |
| 131 | 108 |
| 132 } // namespace plugin | 109 } // namespace plugin |
| 133 | 110 |
| 134 #endif // NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_SCRIPTABLE_HANDLE_H_ | 111 #endif // NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_SCRIPTABLE_PLUGIN_H_ |
| OLD | NEW |