LCOV - code coverage report
Current view: directory - objdir/dist/include/mozilla/plugins - PluginIdentifierChild.h (source / functions) Found Hit Coverage
Test: app.info Lines: 35 0 0.0 %
Date: 2012-06-02 Functions: 12 0 0.0 %

       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                 : #ifndef dom_plugins_PluginIdentifierChild_h
      41                 : #define dom_plugins_PluginIdentifierChild_h
      42                 : 
      43                 : #include "mozilla/plugins/PPluginIdentifierChild.h"
      44                 : #include "npapi.h"
      45                 : #include "npruntime.h"
      46                 : 
      47                 : #include "nsStringGlue.h"
      48                 : 
      49                 : namespace mozilla {
      50                 : namespace plugins {
      51                 : 
      52                 : class PluginModuleChild;
      53                 : 
      54                 : /**
      55                 :  * Plugin identifiers may be "temporary", see the comment on the
      56                 :  * PPluginIdentifier constructor for details. This means that any IPDL method
      57                 :  * which receives a PPluginIdentifierChild* parameter must use StackIdentifier
      58                 :  * to track it.
      59                 :  */
      60                 : class PluginIdentifierChild : public PPluginIdentifierChild
      61                 : {
      62                 :   friend class PluginModuleChild;
      63                 : public:
      64               0 :   bool IsString()
      65                 :   {
      66               0 :     return mIsString;
      67                 :   }
      68                 : 
      69               0 :   NPIdentifier ToNPIdentifier()
      70                 :   {
      71               0 :     if (mCanonicalIdentifier) {
      72               0 :       return mCanonicalIdentifier;
      73                 :     }
      74                 : 
      75               0 :     NS_ASSERTION(mHashed, "Handing out an unhashed identifier?");
      76               0 :     return this;
      77                 :   }
      78                 : 
      79                 :   void MakePermanent();
      80                 : 
      81                 :   class NS_STACK_CLASS StackIdentifier
      82                 :   {
      83                 :   public:
      84               0 :     StackIdentifier(PPluginIdentifierChild* actor)
      85               0 :       : mIdentifier(static_cast<PluginIdentifierChild*>(actor))
      86                 :     {
      87               0 :       if (mIdentifier)
      88               0 :         mIdentifier->StartTemporary();
      89               0 :     }
      90                 : 
      91               0 :     ~StackIdentifier() {
      92               0 :       if (mIdentifier)
      93               0 :         mIdentifier->FinishTemporary();
      94               0 :     }
      95                 : 
      96               0 :     PluginIdentifierChild* operator->() { return mIdentifier; }
      97                 : 
      98                 :   private:
      99                 :     PluginIdentifierChild* mIdentifier;
     100                 :   };
     101                 : 
     102                 : protected:
     103               0 :   PluginIdentifierChild(bool aIsString)
     104                 :     : mCanonicalIdentifier(NULL)
     105                 :     , mHashed(false)
     106                 :     , mTemporaryRefs(0)
     107               0 :     , mIsString(aIsString)
     108                 :   {
     109               0 :     MOZ_COUNT_CTOR(PluginIdentifierChild);
     110               0 :   }
     111                 : 
     112               0 :   virtual ~PluginIdentifierChild()
     113               0 :   {
     114               0 :     MOZ_COUNT_DTOR(PluginIdentifierChild);
     115               0 :   }
     116                 : 
     117                 :   // The following functions are implemented by the subclasses for their
     118                 :   // identifier maps.
     119                 :   virtual PluginIdentifierChild* GetCanonical() = 0;
     120                 :   virtual void Hash() = 0;
     121                 :   virtual void Unhash() = 0;
     122                 : 
     123                 : private:
     124                 :   void StartTemporary();
     125                 :   void FinishTemporary();
     126                 : 
     127                 :   // There's a possibility that we already have an actor that wraps the same
     128                 :   // string or int because we do all this identifier construction
     129                 :   // asynchronously. In this case we need to hand out the canonical version
     130                 :   // created by the child side.
     131                 :   //
     132                 :   // In order to deal with temporary identifiers which appear on the stack,
     133                 :   // identifiers use the following state invariants:
     134                 :   //
     135                 :   // * mCanonicalIdentifier is non-NULL: this is a duplicate identifier, no
     136                 :   //   further information is necessary.
     137                 :   // * mHashed is false: this identifier is a newborn, non-permanent identifier
     138                 :   // * mHashed is true, mTemporaryRefs is 0: this identifier is permanent
     139                 :   // * mHashed is true, mTemporaryRefs is non-0: this identifier is temporary;
     140                 :   //   if NPN_GetFooIdentifier is called for it, we need to retain it. If
     141                 :   //   all stack references are lost, unhash it because it will soon be 
     142                 :   //   deleted.
     143                 : 
     144                 :   PluginIdentifierChild* mCanonicalIdentifier;
     145                 :   bool mHashed;
     146                 :   unsigned int mTemporaryRefs;
     147                 :   bool mIsString;
     148                 : };
     149                 : 
     150                 : class PluginIdentifierChildString : public PluginIdentifierChild
     151                 : {
     152                 :   friend class PluginModuleChild;
     153                 : public:
     154               0 :   NPUTF8* ToString()
     155                 :   {
     156               0 :     return ToNewCString(mString);
     157                 :   }
     158                 : 
     159                 : protected:
     160               0 :   PluginIdentifierChildString(const nsCString& aString)
     161                 :     : PluginIdentifierChild(true),
     162               0 :       mString(aString)
     163               0 :   { }
     164                 : 
     165                 :   virtual PluginIdentifierChild* GetCanonical();
     166                 :   virtual void Hash();
     167                 :   virtual void Unhash();
     168                 : 
     169                 :   nsCString mString;
     170                 : };
     171                 : 
     172                 : class PluginIdentifierChildInt : public PluginIdentifierChild
     173                 : {
     174                 :   friend class PluginModuleChild;
     175                 : public:
     176               0 :   int32_t ToInt()
     177                 :   {
     178               0 :     return mInt;
     179                 :   }
     180                 : 
     181                 : protected:
     182               0 :   PluginIdentifierChildInt(int32_t aInt)
     183                 :     : PluginIdentifierChild(false),
     184               0 :       mInt(aInt)
     185               0 :   { }
     186                 : 
     187                 :   virtual PluginIdentifierChild* GetCanonical();
     188                 :   virtual void Hash();
     189                 :   virtual void Unhash();
     190                 : 
     191                 :   int32_t mInt;
     192                 : };
     193                 : 
     194                 : } // namespace plugins
     195                 : } // namespace mozilla
     196                 : 
     197                 : #endif // dom_plugins_PluginIdentifierChild_h

Generated by: LCOV version 1.7