1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/plugins/ipc/PluginIdentifierParent.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,89 @@ 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_PluginIdentifierParent_h 1.11 +#define dom_plugins_PluginIdentifierParent_h 1.12 + 1.13 +#include "mozilla/plugins/PPluginIdentifierParent.h" 1.14 + 1.15 +#include "npapi.h" 1.16 +#include "npruntime.h" 1.17 + 1.18 +namespace mozilla { 1.19 +namespace plugins { 1.20 + 1.21 +class PluginInstanceParent; 1.22 + 1.23 +class PluginIdentifierParent : public PPluginIdentifierParent 1.24 +{ 1.25 + friend class PluginModuleParent; 1.26 + 1.27 +public: 1.28 + NPIdentifier ToNPIdentifier() 1.29 + { 1.30 + return mIdentifier; 1.31 + } 1.32 + 1.33 + bool IsTemporary() { 1.34 + return !!mTemporaryRefs; 1.35 + } 1.36 + 1.37 + /** 1.38 + * Holds a perhaps-temporary identifier for the current stack frame. 1.39 + */ 1.40 + class MOZ_STACK_CLASS StackIdentifier 1.41 + { 1.42 + public: 1.43 + StackIdentifier(PluginInstanceParent* inst, NPIdentifier aIdentifier); 1.44 + StackIdentifier(NPObject* aObject, NPIdentifier aIdentifier); 1.45 + ~StackIdentifier(); 1.46 + 1.47 + operator PluginIdentifierParent*() { 1.48 + return mIdentifier; 1.49 + } 1.50 + 1.51 + private: 1.52 + DISALLOW_COPY_AND_ASSIGN(StackIdentifier); 1.53 + 1.54 + PluginIdentifierParent* mIdentifier; 1.55 + }; 1.56 + 1.57 +protected: 1.58 + PluginIdentifierParent(NPIdentifier aIdentifier, bool aTemporary) 1.59 + : mIdentifier(aIdentifier) 1.60 + , mTemporaryRefs(aTemporary ? 1 : 0) 1.61 + { 1.62 + MOZ_COUNT_CTOR(PluginIdentifierParent); 1.63 + } 1.64 + 1.65 + virtual ~PluginIdentifierParent() 1.66 + { 1.67 + MOZ_COUNT_DTOR(PluginIdentifierParent); 1.68 + } 1.69 + 1.70 + virtual bool RecvRetain() MOZ_OVERRIDE; 1.71 + 1.72 + void AddTemporaryRef() { 1.73 + mTemporaryRefs++; 1.74 + } 1.75 + 1.76 + /** 1.77 + * @returns true if the last temporary reference was removed. 1.78 + */ 1.79 + bool RemoveTemporaryRef() { 1.80 + --mTemporaryRefs; 1.81 + return !mTemporaryRefs; 1.82 + } 1.83 + 1.84 +private: 1.85 + NPIdentifier mIdentifier; 1.86 + unsigned int mTemporaryRefs; 1.87 +}; 1.88 + 1.89 +} // namespace plugins 1.90 +} // namespace mozilla 1.91 + 1.92 +#endif // dom_plugins_PluginIdentifierParent_h