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_PluginIdentifierParent_h michael@0: #define dom_plugins_PluginIdentifierParent_h michael@0: michael@0: #include "mozilla/plugins/PPluginIdentifierParent.h" michael@0: michael@0: #include "npapi.h" michael@0: #include "npruntime.h" michael@0: michael@0: namespace mozilla { michael@0: namespace plugins { michael@0: michael@0: class PluginInstanceParent; michael@0: michael@0: class PluginIdentifierParent : public PPluginIdentifierParent michael@0: { michael@0: friend class PluginModuleParent; michael@0: michael@0: public: michael@0: NPIdentifier ToNPIdentifier() michael@0: { michael@0: return mIdentifier; michael@0: } michael@0: michael@0: bool IsTemporary() { michael@0: return !!mTemporaryRefs; michael@0: } michael@0: michael@0: /** michael@0: * Holds a perhaps-temporary identifier for the current stack frame. michael@0: */ michael@0: class MOZ_STACK_CLASS StackIdentifier michael@0: { michael@0: public: michael@0: StackIdentifier(PluginInstanceParent* inst, NPIdentifier aIdentifier); michael@0: StackIdentifier(NPObject* aObject, NPIdentifier aIdentifier); michael@0: ~StackIdentifier(); michael@0: michael@0: operator PluginIdentifierParent*() { michael@0: return mIdentifier; michael@0: } michael@0: michael@0: private: michael@0: DISALLOW_COPY_AND_ASSIGN(StackIdentifier); michael@0: michael@0: PluginIdentifierParent* mIdentifier; michael@0: }; michael@0: michael@0: protected: michael@0: PluginIdentifierParent(NPIdentifier aIdentifier, bool aTemporary) michael@0: : mIdentifier(aIdentifier) michael@0: , mTemporaryRefs(aTemporary ? 1 : 0) michael@0: { michael@0: MOZ_COUNT_CTOR(PluginIdentifierParent); michael@0: } michael@0: michael@0: virtual ~PluginIdentifierParent() michael@0: { michael@0: MOZ_COUNT_DTOR(PluginIdentifierParent); michael@0: } michael@0: michael@0: virtual bool RecvRetain() MOZ_OVERRIDE; michael@0: michael@0: void AddTemporaryRef() { michael@0: mTemporaryRefs++; michael@0: } michael@0: michael@0: /** michael@0: * @returns true if the last temporary reference was removed. michael@0: */ michael@0: bool RemoveTemporaryRef() { michael@0: --mTemporaryRefs; michael@0: return !mTemporaryRefs; michael@0: } michael@0: michael@0: private: michael@0: NPIdentifier mIdentifier; michael@0: unsigned int mTemporaryRefs; michael@0: }; michael@0: michael@0: } // namespace plugins michael@0: } // namespace mozilla michael@0: michael@0: #endif // dom_plugins_PluginIdentifierParent_h