dom/plugins/ipc/PluginScriptableObjectChild.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/plugins/ipc/PluginScriptableObjectChild.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,238 @@
     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_PluginScriptableObjectChild_h
    1.11 +#define dom_plugins_PluginScriptableObjectChild_h 1
    1.12 +
    1.13 +#include "mozilla/plugins/PPluginScriptableObjectChild.h"
    1.14 +#include "mozilla/plugins/PluginMessageUtils.h"
    1.15 +
    1.16 +#include "npruntime.h"
    1.17 +
    1.18 +namespace mozilla {
    1.19 +namespace plugins {
    1.20 +
    1.21 +class PluginInstanceChild;
    1.22 +class PluginScriptableObjectChild;
    1.23 +class PPluginIdentifierChild;
    1.24 +
    1.25 +struct ChildNPObject : NPObject
    1.26 +{
    1.27 +  ChildNPObject()
    1.28 +    : NPObject(), parent(nullptr), invalidated(false)
    1.29 +  {
    1.30 +    MOZ_COUNT_CTOR(ChildNPObject);
    1.31 +  }
    1.32 +
    1.33 +  ~ChildNPObject()
    1.34 +  {
    1.35 +    MOZ_COUNT_DTOR(ChildNPObject);
    1.36 +  }
    1.37 +
    1.38 +  // |parent| is always valid as long as the actor is alive. Once the actor is
    1.39 +  // destroyed this will be set to null.
    1.40 +  PluginScriptableObjectChild* parent;
    1.41 +  bool invalidated;
    1.42 +};
    1.43 +
    1.44 +class PluginScriptableObjectChild : public PPluginScriptableObjectChild
    1.45 +{
    1.46 +  friend class PluginInstanceChild;
    1.47 +
    1.48 +public:
    1.49 +  PluginScriptableObjectChild(ScriptableObjectType aType);
    1.50 +  virtual ~PluginScriptableObjectChild();
    1.51 +
    1.52 +  void
    1.53 +  InitializeProxy();
    1.54 +
    1.55 +  void
    1.56 +  InitializeLocal(NPObject* aObject);
    1.57 +
    1.58 +
    1.59 +  virtual bool
    1.60 +  AnswerInvalidate() MOZ_OVERRIDE;
    1.61 +
    1.62 +  virtual bool
    1.63 +  AnswerHasMethod(PPluginIdentifierChild* aId,
    1.64 +                  bool* aHasMethod) MOZ_OVERRIDE;
    1.65 +
    1.66 +  virtual bool
    1.67 +  AnswerInvoke(PPluginIdentifierChild* aId,
    1.68 +               const InfallibleTArray<Variant>& aArgs,
    1.69 +               Variant* aResult,
    1.70 +               bool* aSuccess) MOZ_OVERRIDE;
    1.71 +
    1.72 +  virtual bool
    1.73 +  AnswerInvokeDefault(const InfallibleTArray<Variant>& aArgs,
    1.74 +                      Variant* aResult,
    1.75 +                      bool* aSuccess) MOZ_OVERRIDE;
    1.76 +
    1.77 +  virtual bool
    1.78 +  AnswerHasProperty(PPluginIdentifierChild* aId,
    1.79 +                    bool* aHasProperty) MOZ_OVERRIDE;
    1.80 +
    1.81 +  virtual bool
    1.82 +  AnswerGetChildProperty(PPluginIdentifierChild* aId,
    1.83 +                         bool* aHasProperty,
    1.84 +                         bool* aHasMethod,
    1.85 +                         Variant* aResult,
    1.86 +                         bool* aSuccess) MOZ_OVERRIDE;
    1.87 +
    1.88 +  virtual bool
    1.89 +  AnswerSetProperty(PPluginIdentifierChild* aId,
    1.90 +                    const Variant& aValue,
    1.91 +                    bool* aSuccess) MOZ_OVERRIDE;
    1.92 +
    1.93 +  virtual bool
    1.94 +  AnswerRemoveProperty(PPluginIdentifierChild* aId,
    1.95 +                       bool* aSuccess) MOZ_OVERRIDE;
    1.96 +
    1.97 +  virtual bool
    1.98 +  AnswerEnumerate(InfallibleTArray<PPluginIdentifierChild*>* aProperties,
    1.99 +                  bool* aSuccess) MOZ_OVERRIDE;
   1.100 +
   1.101 +  virtual bool
   1.102 +  AnswerConstruct(const InfallibleTArray<Variant>& aArgs,
   1.103 +                  Variant* aResult,
   1.104 +                  bool* aSuccess) MOZ_OVERRIDE;
   1.105 +
   1.106 +  virtual bool
   1.107 +  RecvProtect() MOZ_OVERRIDE;
   1.108 +
   1.109 +  virtual bool
   1.110 +  RecvUnprotect() MOZ_OVERRIDE;
   1.111 +
   1.112 +  NPObject*
   1.113 +  GetObject(bool aCanResurrect);
   1.114 +
   1.115 +  static const NPClass*
   1.116 +  GetClass()
   1.117 +  {
   1.118 +    return &sNPClass;
   1.119 +  }
   1.120 +
   1.121 +  PluginInstanceChild*
   1.122 +  GetInstance() const
   1.123 +  {
   1.124 +    return mInstance;
   1.125 +  }
   1.126 +
   1.127 +  // Protect only affects LocalObject actors. It is called by the
   1.128 +  // ProtectedVariant/Actor helper classes before the actor is used as an
   1.129 +  // argument to an IPC call and when the parent process resurrects a
   1.130 +  // proxy object to the NPObject associated with this actor.
   1.131 +  void Protect();
   1.132 +
   1.133 +  // Unprotect only affects LocalObject actors. It is called by the
   1.134 +  // ProtectedVariant/Actor helper classes after the actor is used as an
   1.135 +  // argument to an IPC call and when the parent process is no longer using
   1.136 +  // this actor.
   1.137 +  void Unprotect();
   1.138 +
   1.139 +  // DropNPObject is only used for Proxy actors and is called when the child
   1.140 +  // process is no longer using the NPObject associated with this actor. The
   1.141 +  // parent process may subsequently use this actor again in which case a new
   1.142 +  // NPObject will be created and associated with this actor (see
   1.143 +  // ResurrectProxyObject).
   1.144 +  void DropNPObject();
   1.145 +
   1.146 +  /**
   1.147 +   * After NPP_Destroy, all NPObjects associated with an instance are
   1.148 +   * destroyed. We are informed of this destruction. This should only be called
   1.149 +   * on Local actors.
   1.150 +   */
   1.151 +  void NPObjectDestroyed();
   1.152 +
   1.153 +  bool
   1.154 +  Evaluate(NPString* aScript,
   1.155 +           NPVariant* aResult);
   1.156 +
   1.157 +  ScriptableObjectType
   1.158 +  Type() const {
   1.159 +    return mType;
   1.160 +  }
   1.161 +
   1.162 +private:
   1.163 +  static NPObject*
   1.164 +  ScriptableAllocate(NPP aInstance,
   1.165 +                     NPClass* aClass);
   1.166 +
   1.167 +  static void
   1.168 +  ScriptableInvalidate(NPObject* aObject);
   1.169 +
   1.170 +  static void
   1.171 +  ScriptableDeallocate(NPObject* aObject);
   1.172 +
   1.173 +  static bool
   1.174 +  ScriptableHasMethod(NPObject* aObject,
   1.175 +                      NPIdentifier aName);
   1.176 +
   1.177 +  static bool
   1.178 +  ScriptableInvoke(NPObject* aObject,
   1.179 +                   NPIdentifier aName,
   1.180 +                   const NPVariant* aArgs,
   1.181 +                   uint32_t aArgCount,
   1.182 +                   NPVariant* aResult);
   1.183 +
   1.184 +  static bool
   1.185 +  ScriptableInvokeDefault(NPObject* aObject,
   1.186 +                          const NPVariant* aArgs,
   1.187 +                          uint32_t aArgCount,
   1.188 +                          NPVariant* aResult);
   1.189 +
   1.190 +  static bool
   1.191 +  ScriptableHasProperty(NPObject* aObject,
   1.192 +                        NPIdentifier aName);
   1.193 +
   1.194 +  static bool
   1.195 +  ScriptableGetProperty(NPObject* aObject,
   1.196 +                        NPIdentifier aName,
   1.197 +                        NPVariant* aResult);
   1.198 +
   1.199 +  static bool
   1.200 +  ScriptableSetProperty(NPObject* aObject,
   1.201 +                        NPIdentifier aName,
   1.202 +                        const NPVariant* aValue);
   1.203 +
   1.204 +  static bool
   1.205 +  ScriptableRemoveProperty(NPObject* aObject,
   1.206 +                           NPIdentifier aName);
   1.207 +
   1.208 +  static bool
   1.209 +  ScriptableEnumerate(NPObject* aObject,
   1.210 +                      NPIdentifier** aIdentifiers,
   1.211 +                      uint32_t* aCount);
   1.212 +
   1.213 +  static bool
   1.214 +  ScriptableConstruct(NPObject* aObject,
   1.215 +                      const NPVariant* aArgs,
   1.216 +                      uint32_t aArgCount,
   1.217 +                      NPVariant* aResult);
   1.218 +
   1.219 +  NPObject*
   1.220 +  CreateProxyObject();
   1.221 +
   1.222 +  // ResurrectProxyObject is only used with Proxy actors. It is called when the
   1.223 +  // parent process uses an actor whose NPObject was deleted by the child
   1.224 +  // process.
   1.225 +  bool ResurrectProxyObject();
   1.226 +
   1.227 +private:
   1.228 +  PluginInstanceChild* mInstance;
   1.229 +  NPObject* mObject;
   1.230 +  bool mInvalidated;
   1.231 +  int mProtectCount;
   1.232 +
   1.233 +  ScriptableObjectType mType;
   1.234 +
   1.235 +  static const NPClass sNPClass;
   1.236 +};
   1.237 +
   1.238 +} /* namespace plugins */
   1.239 +} /* namespace mozilla */
   1.240 +
   1.241 +#endif /* dom_plugins_PluginScriptableObjectChild_h */

mercurial