dom/plugins/ipc/PluginIdentifierChild.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

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 #include "PluginIdentifierChild.h"
     8 #include "PluginModuleChild.h"
    10 namespace mozilla {
    11 namespace plugins {
    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   }
    22   if (!mHashed) {
    23     NS_ASSERTION(mTemporaryRefs == 0, "Not hashed, but temporary refs?");
    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     }
    34     Hash();
    35     mHashed = true;
    36     return;
    37   }
    39   if (mTemporaryRefs) {
    40     SendRetain();
    41     mTemporaryRefs = 0;
    42   }
    43 }
    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   }
    54   if (!mHashed) {
    55     NS_ASSERTION(mTemporaryRefs == 0, "Not hashed, but temporary refs?");
    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     }
    66     Hash();
    67     mHashed = true;
    68     mTemporaryRefs = 1;
    69     return;
    70   }
    72   if (mTemporaryRefs)
    73     ++mTemporaryRefs;
    74 }
    76 void
    77 PluginIdentifierChild::FinishTemporary()
    78 {
    79   if (mCanonicalIdentifier)
    80     return;
    82   NS_ASSERTION(mHashed, "Finishing unhashed identifier?");
    83   if (!mTemporaryRefs)
    84     return;
    86   --mTemporaryRefs;
    87   if (mTemporaryRefs)
    88     return;
    90   Unhash();
    91   mHashed = false;
    92 }
    94 PluginIdentifierChild*
    95 PluginIdentifierChildString::GetCanonical()
    96 {
    97   PluginModuleChild* module = static_cast<PluginModuleChild*>(Manager());
    98   return module->mStringIdentifiers.Get(mString);
    99 }
   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 }
   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 }
   117 PluginIdentifierChild*
   118 PluginIdentifierChildInt::GetCanonical()
   119 {
   120   PluginModuleChild* module = static_cast<PluginModuleChild*>(Manager());
   121   return module->mIntIdentifiers.Get(mInt);
   122 }
   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 }
   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 }
   140 } // namespace mozilla::plugins
   141 } // namespace mozilla

mercurial