dom/plugins/ipc/PluginIdentifierParent.h

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:47af1a9262a5
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/. */
6
7 #ifndef dom_plugins_PluginIdentifierParent_h
8 #define dom_plugins_PluginIdentifierParent_h
9
10 #include "mozilla/plugins/PPluginIdentifierParent.h"
11
12 #include "npapi.h"
13 #include "npruntime.h"
14
15 namespace mozilla {
16 namespace plugins {
17
18 class PluginInstanceParent;
19
20 class PluginIdentifierParent : public PPluginIdentifierParent
21 {
22 friend class PluginModuleParent;
23
24 public:
25 NPIdentifier ToNPIdentifier()
26 {
27 return mIdentifier;
28 }
29
30 bool IsTemporary() {
31 return !!mTemporaryRefs;
32 }
33
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();
43
44 operator PluginIdentifierParent*() {
45 return mIdentifier;
46 }
47
48 private:
49 DISALLOW_COPY_AND_ASSIGN(StackIdentifier);
50
51 PluginIdentifierParent* mIdentifier;
52 };
53
54 protected:
55 PluginIdentifierParent(NPIdentifier aIdentifier, bool aTemporary)
56 : mIdentifier(aIdentifier)
57 , mTemporaryRefs(aTemporary ? 1 : 0)
58 {
59 MOZ_COUNT_CTOR(PluginIdentifierParent);
60 }
61
62 virtual ~PluginIdentifierParent()
63 {
64 MOZ_COUNT_DTOR(PluginIdentifierParent);
65 }
66
67 virtual bool RecvRetain() MOZ_OVERRIDE;
68
69 void AddTemporaryRef() {
70 mTemporaryRefs++;
71 }
72
73 /**
74 * @returns true if the last temporary reference was removed.
75 */
76 bool RemoveTemporaryRef() {
77 --mTemporaryRefs;
78 return !mTemporaryRefs;
79 }
80
81 private:
82 NPIdentifier mIdentifier;
83 unsigned int mTemporaryRefs;
84 };
85
86 } // namespace plugins
87 } // namespace mozilla
88
89 #endif // dom_plugins_PluginIdentifierParent_h

mercurial