xpcom/reflect/xptcall/public/xptcall.h

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 /* Public declarations for xptcall. */
     8 #ifndef xptcall_h___
     9 #define xptcall_h___
    11 #include "nscore.h"
    12 #include "nsISupports.h"
    13 #include "xpt_struct.h"
    14 #include "xptinfo.h"
    15 #include "js/Value.h"
    17 struct nsXPTCMiniVariant
    18 {
    19 // No ctors or dtors so that we can use arrays of these on the stack
    20 // with no penalty.
    21     union
    22     {
    23         int8_t    i8;
    24         int16_t   i16;
    25         int32_t   i32;
    26         int64_t   i64;
    27         uint8_t   u8;
    28         uint16_t  u16;
    29         uint32_t  u32;
    30         uint64_t  u64;
    31         float     f;
    32         double    d;
    33         bool      b;
    34         char      c;
    35         char16_t wc;
    36         void*     p;
    38         // Types below here are unknown to the assembly implementations, and
    39         // therefore _must_ be passed with indirect semantics. We put them in
    40         // the union here for type safety, so that we can avoid void* tricks.
    41         JS::Value j;
    42     } val;
    43 };
    45 struct nsXPTCVariant : public nsXPTCMiniVariant
    46 {
    47 // No ctors or dtors so that we can use arrays of these on the stack
    48 // with no penalty.
    50     // inherits 'val' here
    51     void*     ptr;
    52     nsXPTType type;
    53     uint8_t   flags;
    55     enum
    56     {
    57         //
    58         // Bitflag definitions
    59         //
    61         // Indicates that ptr (above, and distinct from val.p) is the value that
    62         // should be passed on the stack.
    63         //
    64         // In theory, ptr could point anywhere. But in practice it always points
    65         // to &val. So this flag is used to pass 'val' by reference, letting us
    66         // avoid the extra allocation we would incur if we were to use val.p.
    67         //
    68         // Various parts of XPConnect assume that ptr==&val, so we enforce it
    69         // explicitly with SetIndirect() and IsIndirect().
    70         //
    71         // Since ptr always points to &val, the semantics of this flag are kind of
    72         // dumb, since the ptr field is unnecessary. But changing them would
    73         // require changing dozens of assembly files, so they're likely to stay
    74         // the way they are.
    75         PTR_IS_DATA    = 0x1,
    77         // Indicates that the value we hold requires some sort of cleanup (memory
    78         // deallocation, interface release, JS::Value unrooting, etc). The precise
    79         // cleanup that is performed depends on the 'type' field above.
    80         // If the value is an array, this flag specifies whether the elements
    81         // within the array require cleanup (we always clean up the array itself,
    82         // so this flag would be redundant for that purpose).
    83         VAL_NEEDS_CLEANUP = 0x2
    84     };
    86     void ClearFlags()         {flags = 0;}
    87     void SetIndirect()        {ptr = &val; flags |= PTR_IS_DATA;}
    88     void SetValNeedsCleanup() {flags |= VAL_NEEDS_CLEANUP;}
    90     bool IsIndirect()         const  {return 0 != (flags & PTR_IS_DATA);}
    91     bool DoesValNeedCleanup() const  {return 0 != (flags & VAL_NEEDS_CLEANUP);}
    93     // Internal use only. Use IsIndirect() instead.
    94     bool IsPtrData()       const  {return 0 != (flags & PTR_IS_DATA);}
    96     void Init(const nsXPTCMiniVariant& mv, const nsXPTType& t, uint8_t f)
    97     {
    98         type = t;
    99         flags = f;
   101         if(f & PTR_IS_DATA)
   102         {
   103             ptr = mv.val.p;
   104             val.p = nullptr;
   105         }
   106         else
   107         {
   108             ptr = nullptr;
   109             val.p = nullptr; // make sure 'val.p' is always initialized
   110             switch(t.TagPart()) {
   111               case nsXPTType::T_I8:                val.i8  = mv.val.i8;  break;
   112               case nsXPTType::T_I16:               val.i16 = mv.val.i16; break;
   113               case nsXPTType::T_I32:               val.i32 = mv.val.i32; break;
   114               case nsXPTType::T_I64:               val.i64 = mv.val.i64; break;
   115               case nsXPTType::T_U8:                val.u8  = mv.val.u8;  break;
   116               case nsXPTType::T_U16:               val.u16 = mv.val.u16; break;
   117               case nsXPTType::T_U32:               val.u32 = mv.val.u32; break;
   118               case nsXPTType::T_U64:               val.u64 = mv.val.u64; break;
   119               case nsXPTType::T_FLOAT:             val.f   = mv.val.f;   break;
   120               case nsXPTType::T_DOUBLE:            val.d   = mv.val.d;   break;
   121               case nsXPTType::T_BOOL:              val.b   = mv.val.b;   break;
   122               case nsXPTType::T_CHAR:              val.c   = mv.val.c;   break;
   123               case nsXPTType::T_WCHAR:             val.wc  = mv.val.wc;  break;
   124               case nsXPTType::T_VOID:              /* fall through */
   125               case nsXPTType::T_IID:               /* fall through */
   126               case nsXPTType::T_DOMSTRING:         /* fall through */
   127               case nsXPTType::T_CHAR_STR:          /* fall through */
   128               case nsXPTType::T_WCHAR_STR:         /* fall through */
   129               case nsXPTType::T_INTERFACE:         /* fall through */
   130               case nsXPTType::T_INTERFACE_IS:      /* fall through */
   131               case nsXPTType::T_ARRAY:             /* fall through */
   132               case nsXPTType::T_PSTRING_SIZE_IS:   /* fall through */
   133               case nsXPTType::T_PWSTRING_SIZE_IS:  /* fall through */
   134               case nsXPTType::T_UTF8STRING:        /* fall through */
   135               case nsXPTType::T_CSTRING:           /* fall through */              
   136               default:                             val.p   = mv.val.p;   break;
   137             }
   138         }
   139     }
   140 };
   142 class nsIXPTCProxy : public nsISupports
   143 {
   144 public:
   145     NS_IMETHOD CallMethod(uint16_t aMethodIndex,
   146                           const XPTMethodDescriptor *aInfo,
   147                           nsXPTCMiniVariant *aParams) = 0;
   148 };
   150 /**
   151  * This is a typedef to avoid confusion between the canonical
   152  * nsISupports* that provides object identity and an interface pointer
   153  * for inheriting interfaces that aren't known at compile-time.
   154  */
   155 typedef nsISupports nsISomeInterface;
   157 /**
   158  * Get a proxy object to implement the specified interface.
   159  *
   160  * @param aIID    The IID of the interface to implement.
   161  * @param aOuter  An object to receive method calls from the proxy object.
   162  *                The stub forwards QueryInterface/AddRef/Release to the
   163  *                outer object. The proxy object does not hold a reference to
   164  *                the outer object; it is the caller's responsibility to
   165  *                ensure that this pointer remains valid until the stub has
   166  *                been destroyed.
   167  * @param aStub   Out parameter for the new proxy object. The object is
   168  *                not addrefed. The object never destroys itself. It must be
   169  *                explicitly destroyed by calling
   170  *                NS_DestroyXPTCallStub when it is no longer needed.
   171  */
   172 XPCOM_API(nsresult)
   173 NS_GetXPTCallStub(REFNSIID aIID, nsIXPTCProxy* aOuter,
   174                   nsISomeInterface* *aStub);
   176 /**
   177  * Destroys an XPTCall stub previously created with NS_GetXPTCallStub.
   178  */
   179 XPCOM_API(void)
   180 NS_DestroyXPTCallStub(nsISomeInterface* aStub);
   182 XPCOM_API(nsresult)
   183 NS_InvokeByIndex(nsISupports* that, uint32_t methodIndex,
   184                  uint32_t paramCount, nsXPTCVariant* params);
   186 #endif /* xptcall_h___ */

mercurial