michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * vim: sw=2 ts=2 et : michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef dom_plugins_PluginScriptableObjectParent_h michael@0: #define dom_plugins_PluginScriptableObjectParent_h 1 michael@0: michael@0: #include "mozilla/plugins/PPluginScriptableObjectParent.h" michael@0: #include "mozilla/plugins/PluginMessageUtils.h" michael@0: michael@0: #include "npfunctions.h" michael@0: #include "npruntime.h" michael@0: michael@0: namespace mozilla { michael@0: namespace plugins { michael@0: michael@0: class PluginInstanceParent; michael@0: class PluginScriptableObjectParent; michael@0: class PPluginIdentifierParent; michael@0: michael@0: struct ParentNPObject : NPObject michael@0: { michael@0: ParentNPObject() michael@0: : NPObject(), parent(nullptr), invalidated(false) { } michael@0: michael@0: // |parent| is always valid as long as the actor is alive. Once the actor is michael@0: // destroyed this will be set to null. michael@0: PluginScriptableObjectParent* parent; michael@0: bool invalidated; michael@0: }; michael@0: michael@0: class PluginScriptableObjectParent : public PPluginScriptableObjectParent michael@0: { michael@0: friend class PluginInstanceParent; michael@0: michael@0: public: michael@0: PluginScriptableObjectParent(ScriptableObjectType aType); michael@0: virtual ~PluginScriptableObjectParent(); michael@0: michael@0: void michael@0: InitializeProxy(); michael@0: michael@0: void michael@0: InitializeLocal(NPObject* aObject); michael@0: michael@0: virtual bool michael@0: AnswerHasMethod(PPluginIdentifierParent* aId, michael@0: bool* aHasMethod) MOZ_OVERRIDE; michael@0: michael@0: virtual bool michael@0: AnswerInvoke(PPluginIdentifierParent* aId, michael@0: const InfallibleTArray& aArgs, michael@0: Variant* aResult, michael@0: bool* aSuccess) MOZ_OVERRIDE; michael@0: michael@0: virtual bool michael@0: AnswerInvokeDefault(const InfallibleTArray& aArgs, michael@0: Variant* aResult, michael@0: bool* aSuccess) MOZ_OVERRIDE; michael@0: michael@0: virtual bool michael@0: AnswerHasProperty(PPluginIdentifierParent* aId, michael@0: bool* aHasProperty) MOZ_OVERRIDE; michael@0: michael@0: virtual bool michael@0: AnswerGetParentProperty(PPluginIdentifierParent* aId, michael@0: Variant* aResult, michael@0: bool* aSuccess) MOZ_OVERRIDE; michael@0: michael@0: virtual bool michael@0: AnswerSetProperty(PPluginIdentifierParent* aId, michael@0: const Variant& aValue, michael@0: bool* aSuccess) MOZ_OVERRIDE; michael@0: michael@0: virtual bool michael@0: AnswerRemoveProperty(PPluginIdentifierParent* aId, michael@0: bool* aSuccess) MOZ_OVERRIDE; michael@0: michael@0: virtual bool michael@0: AnswerEnumerate(InfallibleTArray* aProperties, michael@0: bool* aSuccess) MOZ_OVERRIDE; michael@0: michael@0: virtual bool michael@0: AnswerConstruct(const InfallibleTArray& aArgs, michael@0: Variant* aResult, michael@0: bool* aSuccess) MOZ_OVERRIDE; michael@0: michael@0: virtual bool michael@0: AnswerNPN_Evaluate(const nsCString& aScript, michael@0: Variant* aResult, michael@0: bool* aSuccess) MOZ_OVERRIDE; michael@0: michael@0: virtual bool michael@0: RecvProtect() MOZ_OVERRIDE; michael@0: michael@0: virtual bool michael@0: RecvUnprotect() MOZ_OVERRIDE; michael@0: michael@0: static const NPClass* michael@0: GetClass() michael@0: { michael@0: return &sNPClass; michael@0: } michael@0: michael@0: PluginInstanceParent* michael@0: GetInstance() const michael@0: { michael@0: return mInstance; michael@0: } michael@0: michael@0: NPObject* michael@0: GetObject(bool aCanResurrect); michael@0: michael@0: // Protect only affects LocalObject actors. It is called by the michael@0: // ProtectedVariant/Actor helper classes before the actor is used as an michael@0: // argument to an IPC call and when the child process resurrects a michael@0: // proxy object to the NPObject associated with this actor. michael@0: void Protect(); michael@0: michael@0: // Unprotect only affects LocalObject actors. It is called by the michael@0: // ProtectedVariant/Actor helper classes after the actor is used as an michael@0: // argument to an IPC call and when the child process is no longer using this michael@0: // actor. michael@0: void Unprotect(); michael@0: michael@0: // DropNPObject is only used for Proxy actors and is called when the parent michael@0: // process is no longer using the NPObject associated with this actor. The michael@0: // child process may subsequently use this actor again in which case a new michael@0: // NPObject will be created and associated with this actor (see michael@0: // ResurrectProxyObject). michael@0: void DropNPObject(); michael@0: michael@0: ScriptableObjectType michael@0: Type() const { michael@0: return mType; michael@0: } michael@0: michael@0: bool GetPropertyHelper(NPIdentifier aName, michael@0: bool* aHasProperty, michael@0: bool* aHasMethod, michael@0: NPVariant* aResult); michael@0: michael@0: private: michael@0: static NPObject* michael@0: ScriptableAllocate(NPP aInstance, michael@0: NPClass* aClass); michael@0: michael@0: static void michael@0: ScriptableInvalidate(NPObject* aObject); michael@0: michael@0: static void michael@0: ScriptableDeallocate(NPObject* aObject); michael@0: michael@0: static bool michael@0: ScriptableHasMethod(NPObject* aObject, michael@0: NPIdentifier aName); michael@0: michael@0: static bool michael@0: ScriptableInvoke(NPObject* aObject, michael@0: NPIdentifier aName, michael@0: const NPVariant* aArgs, michael@0: uint32_t aArgCount, michael@0: NPVariant* aResult); michael@0: michael@0: static bool michael@0: ScriptableInvokeDefault(NPObject* aObject, michael@0: const NPVariant* aArgs, michael@0: uint32_t aArgCount, michael@0: NPVariant* aResult); michael@0: michael@0: static bool michael@0: ScriptableHasProperty(NPObject* aObject, michael@0: NPIdentifier aName); michael@0: michael@0: static bool michael@0: ScriptableGetProperty(NPObject* aObject, michael@0: NPIdentifier aName, michael@0: NPVariant* aResult); michael@0: michael@0: static bool michael@0: ScriptableSetProperty(NPObject* aObject, michael@0: NPIdentifier aName, michael@0: const NPVariant* aValue); michael@0: michael@0: static bool michael@0: ScriptableRemoveProperty(NPObject* aObject, michael@0: NPIdentifier aName); michael@0: michael@0: static bool michael@0: ScriptableEnumerate(NPObject* aObject, michael@0: NPIdentifier** aIdentifiers, michael@0: uint32_t* aCount); michael@0: michael@0: static bool michael@0: ScriptableConstruct(NPObject* aObject, michael@0: const NPVariant* aArgs, michael@0: uint32_t aArgCount, michael@0: NPVariant* aResult); michael@0: michael@0: NPObject* michael@0: CreateProxyObject(); michael@0: michael@0: // ResurrectProxyObject is only used with Proxy actors. It is called when the michael@0: // child process uses an actor whose NPObject was deleted by the parent michael@0: // process. michael@0: bool ResurrectProxyObject(); michael@0: michael@0: private: michael@0: PluginInstanceParent* mInstance; michael@0: michael@0: // This may be a ParentNPObject or some other kind depending on who created michael@0: // it. Have to check its class to find out. michael@0: NPObject* mObject; michael@0: int mProtectCount; michael@0: michael@0: ScriptableObjectType mType; michael@0: michael@0: static const NPClass sNPClass; michael@0: }; michael@0: michael@0: } /* namespace plugins */ michael@0: } /* namespace mozilla */ michael@0: michael@0: #endif /* dom_plugins_PluginScriptableObjectParent_h */