Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: sw=2 ts=2 et :
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef dom_plugins_PluginIdentifierParent_h
8 #define dom_plugins_PluginIdentifierParent_h
10 #include "mozilla/plugins/PPluginIdentifierParent.h"
12 #include "npapi.h"
13 #include "npruntime.h"
15 namespace mozilla {
16 namespace plugins {
18 class PluginInstanceParent;
20 class PluginIdentifierParent : public PPluginIdentifierParent
21 {
22 friend class PluginModuleParent;
24 public:
25 NPIdentifier ToNPIdentifier()
26 {
27 return mIdentifier;
28 }
30 bool IsTemporary() {
31 return !!mTemporaryRefs;
32 }
34 /**
35 * Holds a perhaps-temporary identifier for the current stack frame.
36 */
37 class MOZ_STACK_CLASS StackIdentifier
38 {
39 public:
40 StackIdentifier(PluginInstanceParent* inst, NPIdentifier aIdentifier);
41 StackIdentifier(NPObject* aObject, NPIdentifier aIdentifier);
42 ~StackIdentifier();
44 operator PluginIdentifierParent*() {
45 return mIdentifier;
46 }
48 private:
49 DISALLOW_COPY_AND_ASSIGN(StackIdentifier);
51 PluginIdentifierParent* mIdentifier;
52 };
54 protected:
55 PluginIdentifierParent(NPIdentifier aIdentifier, bool aTemporary)
56 : mIdentifier(aIdentifier)
57 , mTemporaryRefs(aTemporary ? 1 : 0)
58 {
59 MOZ_COUNT_CTOR(PluginIdentifierParent);
60 }
62 virtual ~PluginIdentifierParent()
63 {
64 MOZ_COUNT_DTOR(PluginIdentifierParent);
65 }
67 virtual bool RecvRetain() MOZ_OVERRIDE;
69 void AddTemporaryRef() {
70 mTemporaryRefs++;
71 }
73 /**
74 * @returns true if the last temporary reference was removed.
75 */
76 bool RemoveTemporaryRef() {
77 --mTemporaryRefs;
78 return !mTemporaryRefs;
79 }
81 private:
82 NPIdentifier mIdentifier;
83 unsigned int mTemporaryRefs;
84 };
86 } // namespace plugins
87 } // namespace mozilla
89 #endif // dom_plugins_PluginIdentifierParent_h