1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/plugins/ipc/PluginScriptableObjectParent.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,226 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- 1.5 + * vim: sw=2 ts=2 et : 1.6 + * This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef dom_plugins_PluginScriptableObjectParent_h 1.11 +#define dom_plugins_PluginScriptableObjectParent_h 1 1.12 + 1.13 +#include "mozilla/plugins/PPluginScriptableObjectParent.h" 1.14 +#include "mozilla/plugins/PluginMessageUtils.h" 1.15 + 1.16 +#include "npfunctions.h" 1.17 +#include "npruntime.h" 1.18 + 1.19 +namespace mozilla { 1.20 +namespace plugins { 1.21 + 1.22 +class PluginInstanceParent; 1.23 +class PluginScriptableObjectParent; 1.24 +class PPluginIdentifierParent; 1.25 + 1.26 +struct ParentNPObject : NPObject 1.27 +{ 1.28 + ParentNPObject() 1.29 + : NPObject(), parent(nullptr), invalidated(false) { } 1.30 + 1.31 + // |parent| is always valid as long as the actor is alive. Once the actor is 1.32 + // destroyed this will be set to null. 1.33 + PluginScriptableObjectParent* parent; 1.34 + bool invalidated; 1.35 +}; 1.36 + 1.37 +class PluginScriptableObjectParent : public PPluginScriptableObjectParent 1.38 +{ 1.39 + friend class PluginInstanceParent; 1.40 + 1.41 +public: 1.42 + PluginScriptableObjectParent(ScriptableObjectType aType); 1.43 + virtual ~PluginScriptableObjectParent(); 1.44 + 1.45 + void 1.46 + InitializeProxy(); 1.47 + 1.48 + void 1.49 + InitializeLocal(NPObject* aObject); 1.50 + 1.51 + virtual bool 1.52 + AnswerHasMethod(PPluginIdentifierParent* aId, 1.53 + bool* aHasMethod) MOZ_OVERRIDE; 1.54 + 1.55 + virtual bool 1.56 + AnswerInvoke(PPluginIdentifierParent* aId, 1.57 + const InfallibleTArray<Variant>& aArgs, 1.58 + Variant* aResult, 1.59 + bool* aSuccess) MOZ_OVERRIDE; 1.60 + 1.61 + virtual bool 1.62 + AnswerInvokeDefault(const InfallibleTArray<Variant>& aArgs, 1.63 + Variant* aResult, 1.64 + bool* aSuccess) MOZ_OVERRIDE; 1.65 + 1.66 + virtual bool 1.67 + AnswerHasProperty(PPluginIdentifierParent* aId, 1.68 + bool* aHasProperty) MOZ_OVERRIDE; 1.69 + 1.70 + virtual bool 1.71 + AnswerGetParentProperty(PPluginIdentifierParent* aId, 1.72 + Variant* aResult, 1.73 + bool* aSuccess) MOZ_OVERRIDE; 1.74 + 1.75 + virtual bool 1.76 + AnswerSetProperty(PPluginIdentifierParent* aId, 1.77 + const Variant& aValue, 1.78 + bool* aSuccess) MOZ_OVERRIDE; 1.79 + 1.80 + virtual bool 1.81 + AnswerRemoveProperty(PPluginIdentifierParent* aId, 1.82 + bool* aSuccess) MOZ_OVERRIDE; 1.83 + 1.84 + virtual bool 1.85 + AnswerEnumerate(InfallibleTArray<PPluginIdentifierParent*>* aProperties, 1.86 + bool* aSuccess) MOZ_OVERRIDE; 1.87 + 1.88 + virtual bool 1.89 + AnswerConstruct(const InfallibleTArray<Variant>& aArgs, 1.90 + Variant* aResult, 1.91 + bool* aSuccess) MOZ_OVERRIDE; 1.92 + 1.93 + virtual bool 1.94 + AnswerNPN_Evaluate(const nsCString& aScript, 1.95 + Variant* aResult, 1.96 + bool* aSuccess) MOZ_OVERRIDE; 1.97 + 1.98 + virtual bool 1.99 + RecvProtect() MOZ_OVERRIDE; 1.100 + 1.101 + virtual bool 1.102 + RecvUnprotect() MOZ_OVERRIDE; 1.103 + 1.104 + static const NPClass* 1.105 + GetClass() 1.106 + { 1.107 + return &sNPClass; 1.108 + } 1.109 + 1.110 + PluginInstanceParent* 1.111 + GetInstance() const 1.112 + { 1.113 + return mInstance; 1.114 + } 1.115 + 1.116 + NPObject* 1.117 + GetObject(bool aCanResurrect); 1.118 + 1.119 + // Protect only affects LocalObject actors. It is called by the 1.120 + // ProtectedVariant/Actor helper classes before the actor is used as an 1.121 + // argument to an IPC call and when the child process resurrects a 1.122 + // proxy object to the NPObject associated with this actor. 1.123 + void Protect(); 1.124 + 1.125 + // Unprotect only affects LocalObject actors. It is called by the 1.126 + // ProtectedVariant/Actor helper classes after the actor is used as an 1.127 + // argument to an IPC call and when the child process is no longer using this 1.128 + // actor. 1.129 + void Unprotect(); 1.130 + 1.131 + // DropNPObject is only used for Proxy actors and is called when the parent 1.132 + // process is no longer using the NPObject associated with this actor. The 1.133 + // child process may subsequently use this actor again in which case a new 1.134 + // NPObject will be created and associated with this actor (see 1.135 + // ResurrectProxyObject). 1.136 + void DropNPObject(); 1.137 + 1.138 + ScriptableObjectType 1.139 + Type() const { 1.140 + return mType; 1.141 + } 1.142 + 1.143 + bool GetPropertyHelper(NPIdentifier aName, 1.144 + bool* aHasProperty, 1.145 + bool* aHasMethod, 1.146 + NPVariant* aResult); 1.147 + 1.148 +private: 1.149 + static NPObject* 1.150 + ScriptableAllocate(NPP aInstance, 1.151 + NPClass* aClass); 1.152 + 1.153 + static void 1.154 + ScriptableInvalidate(NPObject* aObject); 1.155 + 1.156 + static void 1.157 + ScriptableDeallocate(NPObject* aObject); 1.158 + 1.159 + static bool 1.160 + ScriptableHasMethod(NPObject* aObject, 1.161 + NPIdentifier aName); 1.162 + 1.163 + static bool 1.164 + ScriptableInvoke(NPObject* aObject, 1.165 + NPIdentifier aName, 1.166 + const NPVariant* aArgs, 1.167 + uint32_t aArgCount, 1.168 + NPVariant* aResult); 1.169 + 1.170 + static bool 1.171 + ScriptableInvokeDefault(NPObject* aObject, 1.172 + const NPVariant* aArgs, 1.173 + uint32_t aArgCount, 1.174 + NPVariant* aResult); 1.175 + 1.176 + static bool 1.177 + ScriptableHasProperty(NPObject* aObject, 1.178 + NPIdentifier aName); 1.179 + 1.180 + static bool 1.181 + ScriptableGetProperty(NPObject* aObject, 1.182 + NPIdentifier aName, 1.183 + NPVariant* aResult); 1.184 + 1.185 + static bool 1.186 + ScriptableSetProperty(NPObject* aObject, 1.187 + NPIdentifier aName, 1.188 + const NPVariant* aValue); 1.189 + 1.190 + static bool 1.191 + ScriptableRemoveProperty(NPObject* aObject, 1.192 + NPIdentifier aName); 1.193 + 1.194 + static bool 1.195 + ScriptableEnumerate(NPObject* aObject, 1.196 + NPIdentifier** aIdentifiers, 1.197 + uint32_t* aCount); 1.198 + 1.199 + static bool 1.200 + ScriptableConstruct(NPObject* aObject, 1.201 + const NPVariant* aArgs, 1.202 + uint32_t aArgCount, 1.203 + NPVariant* aResult); 1.204 + 1.205 + NPObject* 1.206 + CreateProxyObject(); 1.207 + 1.208 + // ResurrectProxyObject is only used with Proxy actors. It is called when the 1.209 + // child process uses an actor whose NPObject was deleted by the parent 1.210 + // process. 1.211 + bool ResurrectProxyObject(); 1.212 + 1.213 +private: 1.214 + PluginInstanceParent* mInstance; 1.215 + 1.216 + // This may be a ParentNPObject or some other kind depending on who created 1.217 + // it. Have to check its class to find out. 1.218 + NPObject* mObject; 1.219 + int mProtectCount; 1.220 + 1.221 + ScriptableObjectType mType; 1.222 + 1.223 + static const NPClass sNPClass; 1.224 +}; 1.225 + 1.226 +} /* namespace plugins */ 1.227 +} /* namespace mozilla */ 1.228 + 1.229 +#endif /* dom_plugins_PluginScriptableObjectParent_h */