1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 : * vim: sw=2 ts=2 et :
3 : * ***** BEGIN LICENSE BLOCK *****
4 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 : *
6 : * The contents of this file are subject to the Mozilla Public License Version
7 : * 1.1 (the "License"); you may not use this file except in compliance with
8 : * the License. You may obtain a copy of the License at
9 : * http://www.mozilla.org/MPL/
10 : *
11 : * Software distributed under the License is distributed on an "AS IS" basis,
12 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 : * for the specific language governing rights and limitations under the
14 : * License.
15 : *
16 : * The Original Code is Mozilla Plugins.
17 : *
18 : * The Initial Developer of the Original Code is
19 : * Mozilla Foundation.
20 : * Portions created by the Initial Developer are Copyright (C) 2010
21 : * the Initial Developer. All Rights Reserved.
22 : *
23 : * Contributor(s):
24 : * Ben Turner <bent.mozilla@gmail.com>
25 : *
26 : * Alternatively, the contents of this file may be used under the terms of
27 : * either the GNU General Public License Version 2 or later (the "GPL"), or
28 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 : * in which case the provisions of the GPL or the LGPL are applicable instead
30 : * of those above. If you wish to allow use of your version of this file only
31 : * under the terms of either the GPL or the LGPL, and not to allow others to
32 : * use your version of this file under the terms of the MPL, indicate your
33 : * decision by deleting the provisions above and replace them with the notice
34 : * and other provisions required by the GPL or the LGPL. If you do not delete
35 : * the provisions above, a recipient may use your version of this file under
36 : * the terms of any one of the MPL, the GPL or the LGPL.
37 : *
38 : * ***** END LICENSE BLOCK ***** */
39 :
40 : #include "PluginIdentifierChild.h"
41 : #include "PluginModuleChild.h"
42 :
43 : namespace mozilla {
44 : namespace plugins {
45 :
46 : void
47 0 : PluginIdentifierChild::MakePermanent()
48 : {
49 0 : if (mCanonicalIdentifier) {
50 0 : NS_ASSERTION(mCanonicalIdentifier->mHashed && mCanonicalIdentifier->mTemporaryRefs == 0,
51 : "Canonical identifiers should always be permanent.");
52 0 : return; // nothing to do
53 : }
54 :
55 0 : if (!mHashed) {
56 0 : NS_ASSERTION(mTemporaryRefs == 0, "Not hashed, but temporary refs?");
57 :
58 0 : PluginIdentifierChild* c = GetCanonical();
59 0 : if (c) {
60 0 : NS_ASSERTION(c != this, "How did I get in the hash?");
61 0 : mCanonicalIdentifier = c;
62 0 : NS_ASSERTION(mCanonicalIdentifier->mHashed && mCanonicalIdentifier->mTemporaryRefs == 0,
63 : "Canonical identifiers should always be permanent.");
64 0 : return;
65 : }
66 :
67 0 : Hash();
68 0 : mHashed = true;
69 0 : return;
70 : }
71 :
72 0 : if (mTemporaryRefs) {
73 0 : SendRetain();
74 0 : mTemporaryRefs = 0;
75 : }
76 : }
77 :
78 : void
79 0 : PluginIdentifierChild::StartTemporary()
80 : {
81 0 : if (mCanonicalIdentifier) {
82 0 : NS_ASSERTION(mCanonicalIdentifier->mHashed && mCanonicalIdentifier->mTemporaryRefs == 0,
83 : "Canonical identifiers should always be permanent.");
84 0 : return; // nothing to do
85 : }
86 :
87 0 : if (!mHashed) {
88 0 : NS_ASSERTION(mTemporaryRefs == 0, "Not hashed, but temporary refs?");
89 :
90 0 : PluginIdentifierChild* c = GetCanonical();
91 0 : if (c) {
92 0 : NS_ASSERTION(c != this, "How did I get in the hash?");
93 0 : mCanonicalIdentifier = c;
94 0 : NS_ASSERTION(mCanonicalIdentifier->mHashed && mCanonicalIdentifier->mTemporaryRefs == 0,
95 : "Canonical identifiers should always be permanent.");
96 0 : return;
97 : }
98 :
99 0 : Hash();
100 0 : mHashed = true;
101 0 : mTemporaryRefs = 1;
102 0 : return;
103 : }
104 :
105 0 : if (mTemporaryRefs)
106 0 : ++mTemporaryRefs;
107 : }
108 :
109 : void
110 0 : PluginIdentifierChild::FinishTemporary()
111 : {
112 0 : if (mCanonicalIdentifier)
113 0 : return;
114 :
115 0 : NS_ASSERTION(mHashed, "Finishing unhashed identifier?");
116 0 : if (!mTemporaryRefs)
117 0 : return;
118 :
119 0 : --mTemporaryRefs;
120 0 : if (mTemporaryRefs)
121 0 : return;
122 :
123 0 : Unhash();
124 0 : mHashed = false;
125 : }
126 :
127 : PluginIdentifierChild*
128 0 : PluginIdentifierChildString::GetCanonical()
129 : {
130 0 : PluginModuleChild* module = static_cast<PluginModuleChild*>(Manager());
131 0 : return module->mStringIdentifiers.Get(mString);
132 : }
133 :
134 : void
135 0 : PluginIdentifierChildString::Hash()
136 : {
137 0 : PluginModuleChild* module = static_cast<PluginModuleChild*>(Manager());
138 0 : NS_ASSERTION(module->mStringIdentifiers.Get(mString) == NULL, "Replacing Hash?");
139 0 : module->mStringIdentifiers.Put(mString, this);
140 0 : }
141 :
142 : void
143 0 : PluginIdentifierChildString::Unhash()
144 : {
145 0 : PluginModuleChild* module = static_cast<PluginModuleChild*>(Manager());
146 0 : NS_ASSERTION(module->mStringIdentifiers.Get(mString) == this, "Incorrect identifier hash?");
147 0 : module->mStringIdentifiers.Remove(mString);
148 0 : }
149 :
150 : PluginIdentifierChild*
151 0 : PluginIdentifierChildInt::GetCanonical()
152 : {
153 0 : PluginModuleChild* module = static_cast<PluginModuleChild*>(Manager());
154 0 : return module->mIntIdentifiers.Get(mInt);
155 : }
156 :
157 : void
158 0 : PluginIdentifierChildInt::Hash()
159 : {
160 0 : PluginModuleChild* module = static_cast<PluginModuleChild*>(Manager());
161 0 : NS_ASSERTION(module->mIntIdentifiers.Get(mInt) == NULL, "Replacing Hash?");
162 0 : module->mIntIdentifiers.Put(mInt, this);
163 0 : }
164 :
165 : void
166 0 : PluginIdentifierChildInt::Unhash()
167 : {
168 0 : PluginModuleChild* module = static_cast<PluginModuleChild*>(Manager());
169 0 : NS_ASSERTION(module->mIntIdentifiers.Get(mInt) == this, "Incorrect identifier hash?");
170 0 : module->mIntIdentifiers.Remove(mInt);
171 0 : }
172 :
173 : } // namespace mozilla::plugins
174 : } // namespace mozilla
|