dom/plugins/ipc/PluginIdentifierChild.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/plugins/ipc/PluginIdentifierChild.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,141 @@
     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 +#include "PluginIdentifierChild.h"
    1.11 +#include "PluginModuleChild.h"
    1.12 +
    1.13 +namespace mozilla {
    1.14 +namespace plugins {
    1.15 +
    1.16 +void
    1.17 +PluginIdentifierChild::MakePermanent()
    1.18 +{
    1.19 +  if (mCanonicalIdentifier) {
    1.20 +    NS_ASSERTION(mCanonicalIdentifier->mHashed && mCanonicalIdentifier->mTemporaryRefs == 0,
    1.21 +                 "Canonical identifiers should always be permanent.");
    1.22 +    return; // nothing to do
    1.23 +  }
    1.24 +
    1.25 +  if (!mHashed) {
    1.26 +    NS_ASSERTION(mTemporaryRefs == 0, "Not hashed, but temporary refs?");
    1.27 +
    1.28 +    PluginIdentifierChild* c = GetCanonical();
    1.29 +    if (c) {
    1.30 +      NS_ASSERTION(c != this, "How did I get in the hash?");
    1.31 +      mCanonicalIdentifier = c;
    1.32 +      NS_ASSERTION(mCanonicalIdentifier->mHashed && mCanonicalIdentifier->mTemporaryRefs == 0,
    1.33 +                   "Canonical identifiers should always be permanent.");
    1.34 +      return;
    1.35 +    }
    1.36 +
    1.37 +    Hash();
    1.38 +    mHashed = true;
    1.39 +    return;
    1.40 +  }
    1.41 +
    1.42 +  if (mTemporaryRefs) {
    1.43 +    SendRetain();
    1.44 +    mTemporaryRefs = 0;
    1.45 +  }
    1.46 +}
    1.47 +
    1.48 +void
    1.49 +PluginIdentifierChild::StartTemporary()
    1.50 +{
    1.51 +  if (mCanonicalIdentifier) {
    1.52 +    NS_ASSERTION(mCanonicalIdentifier->mHashed && mCanonicalIdentifier->mTemporaryRefs == 0,
    1.53 +                 "Canonical identifiers should always be permanent.");
    1.54 +    return; // nothing to do
    1.55 +  }
    1.56 +
    1.57 +  if (!mHashed) {
    1.58 +    NS_ASSERTION(mTemporaryRefs == 0, "Not hashed, but temporary refs?");
    1.59 +
    1.60 +    PluginIdentifierChild* c = GetCanonical();
    1.61 +    if (c) {
    1.62 +      NS_ASSERTION(c != this, "How did I get in the hash?");
    1.63 +      mCanonicalIdentifier = c;
    1.64 +      NS_ASSERTION(mCanonicalIdentifier->mHashed && mCanonicalIdentifier->mTemporaryRefs == 0,
    1.65 +                   "Canonical identifiers should always be permanent.");
    1.66 +      return;
    1.67 +    }
    1.68 +
    1.69 +    Hash();
    1.70 +    mHashed = true;
    1.71 +    mTemporaryRefs = 1;
    1.72 +    return;
    1.73 +  }
    1.74 +
    1.75 +  if (mTemporaryRefs)
    1.76 +    ++mTemporaryRefs;
    1.77 +}
    1.78 +
    1.79 +void
    1.80 +PluginIdentifierChild::FinishTemporary()
    1.81 +{
    1.82 +  if (mCanonicalIdentifier)
    1.83 +    return;
    1.84 +
    1.85 +  NS_ASSERTION(mHashed, "Finishing unhashed identifier?");
    1.86 +  if (!mTemporaryRefs)
    1.87 +    return;
    1.88 +
    1.89 +  --mTemporaryRefs;
    1.90 +  if (mTemporaryRefs)
    1.91 +    return;
    1.92 +
    1.93 +  Unhash();
    1.94 +  mHashed = false;
    1.95 +}
    1.96 +
    1.97 +PluginIdentifierChild*
    1.98 +PluginIdentifierChildString::GetCanonical()
    1.99 +{
   1.100 +  PluginModuleChild* module = static_cast<PluginModuleChild*>(Manager());
   1.101 +  return module->mStringIdentifiers.Get(mString);
   1.102 +}
   1.103 +
   1.104 +void
   1.105 +PluginIdentifierChildString::Hash()
   1.106 +{
   1.107 +  PluginModuleChild* module = static_cast<PluginModuleChild*>(Manager());
   1.108 +  NS_ASSERTION(module->mStringIdentifiers.Get(mString) == nullptr, "Replacing Hash?");
   1.109 +  module->mStringIdentifiers.Put(mString, this);
   1.110 +}
   1.111 +
   1.112 +void
   1.113 +PluginIdentifierChildString::Unhash()
   1.114 +{
   1.115 +  PluginModuleChild* module = static_cast<PluginModuleChild*>(Manager());
   1.116 +  NS_ASSERTION(module->mStringIdentifiers.Get(mString) == this, "Incorrect identifier hash?");
   1.117 +  module->mStringIdentifiers.Remove(mString);
   1.118 +}
   1.119 +
   1.120 +PluginIdentifierChild*
   1.121 +PluginIdentifierChildInt::GetCanonical()
   1.122 +{
   1.123 +  PluginModuleChild* module = static_cast<PluginModuleChild*>(Manager());
   1.124 +  return module->mIntIdentifiers.Get(mInt);
   1.125 +}
   1.126 +
   1.127 +void
   1.128 +PluginIdentifierChildInt::Hash()
   1.129 +{
   1.130 +  PluginModuleChild* module = static_cast<PluginModuleChild*>(Manager());
   1.131 +  NS_ASSERTION(module->mIntIdentifiers.Get(mInt) == nullptr, "Replacing Hash?");
   1.132 +  module->mIntIdentifiers.Put(mInt, this);
   1.133 +}
   1.134 +
   1.135 +void
   1.136 +PluginIdentifierChildInt::Unhash()
   1.137 +{
   1.138 +  PluginModuleChild* module = static_cast<PluginModuleChild*>(Manager());
   1.139 +  NS_ASSERTION(module->mIntIdentifiers.Get(mInt) == this, "Incorrect identifier hash?");
   1.140 +  module->mIntIdentifiers.Remove(mInt);
   1.141 +}
   1.142 +
   1.143 +} // namespace mozilla::plugins
   1.144 +} // namespace mozilla

mercurial