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