|
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 #include "PluginIdentifierChild.h" |
|
8 #include "PluginModuleChild.h" |
|
9 |
|
10 namespace mozilla { |
|
11 namespace plugins { |
|
12 |
|
13 void |
|
14 PluginIdentifierChild::MakePermanent() |
|
15 { |
|
16 if (mCanonicalIdentifier) { |
|
17 NS_ASSERTION(mCanonicalIdentifier->mHashed && mCanonicalIdentifier->mTemporaryRefs == 0, |
|
18 "Canonical identifiers should always be permanent."); |
|
19 return; // nothing to do |
|
20 } |
|
21 |
|
22 if (!mHashed) { |
|
23 NS_ASSERTION(mTemporaryRefs == 0, "Not hashed, but temporary refs?"); |
|
24 |
|
25 PluginIdentifierChild* c = GetCanonical(); |
|
26 if (c) { |
|
27 NS_ASSERTION(c != this, "How did I get in the hash?"); |
|
28 mCanonicalIdentifier = c; |
|
29 NS_ASSERTION(mCanonicalIdentifier->mHashed && mCanonicalIdentifier->mTemporaryRefs == 0, |
|
30 "Canonical identifiers should always be permanent."); |
|
31 return; |
|
32 } |
|
33 |
|
34 Hash(); |
|
35 mHashed = true; |
|
36 return; |
|
37 } |
|
38 |
|
39 if (mTemporaryRefs) { |
|
40 SendRetain(); |
|
41 mTemporaryRefs = 0; |
|
42 } |
|
43 } |
|
44 |
|
45 void |
|
46 PluginIdentifierChild::StartTemporary() |
|
47 { |
|
48 if (mCanonicalIdentifier) { |
|
49 NS_ASSERTION(mCanonicalIdentifier->mHashed && mCanonicalIdentifier->mTemporaryRefs == 0, |
|
50 "Canonical identifiers should always be permanent."); |
|
51 return; // nothing to do |
|
52 } |
|
53 |
|
54 if (!mHashed) { |
|
55 NS_ASSERTION(mTemporaryRefs == 0, "Not hashed, but temporary refs?"); |
|
56 |
|
57 PluginIdentifierChild* c = GetCanonical(); |
|
58 if (c) { |
|
59 NS_ASSERTION(c != this, "How did I get in the hash?"); |
|
60 mCanonicalIdentifier = c; |
|
61 NS_ASSERTION(mCanonicalIdentifier->mHashed && mCanonicalIdentifier->mTemporaryRefs == 0, |
|
62 "Canonical identifiers should always be permanent."); |
|
63 return; |
|
64 } |
|
65 |
|
66 Hash(); |
|
67 mHashed = true; |
|
68 mTemporaryRefs = 1; |
|
69 return; |
|
70 } |
|
71 |
|
72 if (mTemporaryRefs) |
|
73 ++mTemporaryRefs; |
|
74 } |
|
75 |
|
76 void |
|
77 PluginIdentifierChild::FinishTemporary() |
|
78 { |
|
79 if (mCanonicalIdentifier) |
|
80 return; |
|
81 |
|
82 NS_ASSERTION(mHashed, "Finishing unhashed identifier?"); |
|
83 if (!mTemporaryRefs) |
|
84 return; |
|
85 |
|
86 --mTemporaryRefs; |
|
87 if (mTemporaryRefs) |
|
88 return; |
|
89 |
|
90 Unhash(); |
|
91 mHashed = false; |
|
92 } |
|
93 |
|
94 PluginIdentifierChild* |
|
95 PluginIdentifierChildString::GetCanonical() |
|
96 { |
|
97 PluginModuleChild* module = static_cast<PluginModuleChild*>(Manager()); |
|
98 return module->mStringIdentifiers.Get(mString); |
|
99 } |
|
100 |
|
101 void |
|
102 PluginIdentifierChildString::Hash() |
|
103 { |
|
104 PluginModuleChild* module = static_cast<PluginModuleChild*>(Manager()); |
|
105 NS_ASSERTION(module->mStringIdentifiers.Get(mString) == nullptr, "Replacing Hash?"); |
|
106 module->mStringIdentifiers.Put(mString, this); |
|
107 } |
|
108 |
|
109 void |
|
110 PluginIdentifierChildString::Unhash() |
|
111 { |
|
112 PluginModuleChild* module = static_cast<PluginModuleChild*>(Manager()); |
|
113 NS_ASSERTION(module->mStringIdentifiers.Get(mString) == this, "Incorrect identifier hash?"); |
|
114 module->mStringIdentifiers.Remove(mString); |
|
115 } |
|
116 |
|
117 PluginIdentifierChild* |
|
118 PluginIdentifierChildInt::GetCanonical() |
|
119 { |
|
120 PluginModuleChild* module = static_cast<PluginModuleChild*>(Manager()); |
|
121 return module->mIntIdentifiers.Get(mInt); |
|
122 } |
|
123 |
|
124 void |
|
125 PluginIdentifierChildInt::Hash() |
|
126 { |
|
127 PluginModuleChild* module = static_cast<PluginModuleChild*>(Manager()); |
|
128 NS_ASSERTION(module->mIntIdentifiers.Get(mInt) == nullptr, "Replacing Hash?"); |
|
129 module->mIntIdentifiers.Put(mInt, this); |
|
130 } |
|
131 |
|
132 void |
|
133 PluginIdentifierChildInt::Unhash() |
|
134 { |
|
135 PluginModuleChild* module = static_cast<PluginModuleChild*>(Manager()); |
|
136 NS_ASSERTION(module->mIntIdentifiers.Get(mInt) == this, "Incorrect identifier hash?"); |
|
137 module->mIntIdentifiers.Remove(mInt); |
|
138 } |
|
139 |
|
140 } // namespace mozilla::plugins |
|
141 } // namespace mozilla |