xpcom/reflect/xptinfo/src/xptiprivate.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.

michael@0 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 /* Library-private header for Interface Info system. */
michael@0 7
michael@0 8 #ifndef xptiprivate_h___
michael@0 9 #define xptiprivate_h___
michael@0 10
michael@0 11 #include "nscore.h"
michael@0 12 #include <new>
michael@0 13 #include "nsISupports.h"
michael@0 14
michael@0 15 // this after nsISupports, to pick up IID
michael@0 16 // so that xpt stuff doesn't try to define it itself...
michael@0 17 #include "xpt_struct.h"
michael@0 18 #include "xpt_xdr.h"
michael@0 19
michael@0 20 #include "nsIInterfaceInfo.h"
michael@0 21 #include "nsIInterfaceInfoManager.h"
michael@0 22 #include "xptinfo.h"
michael@0 23
michael@0 24 #include "nsIServiceManager.h"
michael@0 25 #include "nsIFile.h"
michael@0 26 #include "nsIDirectoryService.h"
michael@0 27 #include "nsDirectoryServiceDefs.h"
michael@0 28 #include "nsAppDirectoryServiceDefs.h"
michael@0 29 #include "nsIWeakReference.h"
michael@0 30
michael@0 31 #include "mozilla/ReentrantMonitor.h"
michael@0 32 #include "mozilla/Mutex.h"
michael@0 33 #include "mozilla/Attributes.h"
michael@0 34
michael@0 35 #include "nsCRT.h"
michael@0 36 #include "nsMemory.h"
michael@0 37
michael@0 38 #include "nsCOMArray.h"
michael@0 39 #include "nsQuickSort.h"
michael@0 40
michael@0 41 #include "nsXPIDLString.h"
michael@0 42
michael@0 43 #include "nsIInputStream.h"
michael@0 44
michael@0 45 #include "nsHashKeys.h"
michael@0 46 #include "nsDataHashtable.h"
michael@0 47 #include "plstr.h"
michael@0 48 #include "prprf.h"
michael@0 49 #include "prio.h"
michael@0 50 #include "prtime.h"
michael@0 51 #include "prenv.h"
michael@0 52
michael@0 53 #include <stdio.h>
michael@0 54 #include <stdarg.h>
michael@0 55
michael@0 56 /***************************************************************************/
michael@0 57
michael@0 58 #if 0 && defined(DEBUG_jband)
michael@0 59 #define LOG_RESOLVE(x) printf x
michael@0 60 #define LOG_LOAD(x) printf x
michael@0 61 #define LOG_AUTOREG(x) do{printf x; xptiInterfaceInfoManager::WriteToLog x;}while(0)
michael@0 62 #else
michael@0 63 #define LOG_RESOLVE(x) ((void)0)
michael@0 64 #define LOG_LOAD(x) ((void)0)
michael@0 65 #define LOG_AUTOREG(x) ((void)0)
michael@0 66 #endif
michael@0 67
michael@0 68 #if 1 && defined(DEBUG_jband)
michael@0 69 #define SHOW_INFO_COUNT_STATS
michael@0 70 #endif
michael@0 71
michael@0 72 /***************************************************************************/
michael@0 73
michael@0 74 class xptiInterfaceInfo;
michael@0 75 class xptiInterfaceEntry;
michael@0 76 class xptiTypelibGuts;
michael@0 77
michael@0 78 extern XPTArena* gXPTIStructArena;
michael@0 79
michael@0 80 /***************************************************************************/
michael@0 81
michael@0 82 /***************************************************************************/
michael@0 83
michael@0 84 // No virtuals.
michael@0 85 // These are always constructed in the struct arena using placement new.
michael@0 86 // dtor need not be called.
michael@0 87
michael@0 88 class xptiTypelibGuts
michael@0 89 {
michael@0 90 public:
michael@0 91 static xptiTypelibGuts* Create(XPTHeader* aHeader);
michael@0 92
michael@0 93 XPTHeader* GetHeader() {return mHeader;}
michael@0 94 uint16_t GetEntryCount() const {return mHeader->num_interfaces;}
michael@0 95
michael@0 96 void SetEntryAt(uint16_t i, xptiInterfaceEntry* ptr)
michael@0 97 {
michael@0 98 NS_ASSERTION(mHeader,"bad state!");
michael@0 99 NS_ASSERTION(i < GetEntryCount(),"bad param!");
michael@0 100 mEntryArray[i] = ptr;
michael@0 101 }
michael@0 102
michael@0 103 xptiInterfaceEntry* GetEntryAt(uint16_t i);
michael@0 104
michael@0 105 private:
michael@0 106 xptiTypelibGuts(XPTHeader* aHeader)
michael@0 107 : mHeader(aHeader)
michael@0 108 { }
michael@0 109 ~xptiTypelibGuts();
michael@0 110
michael@0 111 private:
michael@0 112 XPTHeader* mHeader; // hold pointer into arena
michael@0 113 xptiInterfaceEntry* mEntryArray[1]; // Always last. Sized to fit.
michael@0 114 };
michael@0 115
michael@0 116 /***************************************************************************/
michael@0 117
michael@0 118 /***************************************************************************/
michael@0 119
michael@0 120 // This class exists to help xptiInterfaceInfo store a 4-state (2 bit) value
michael@0 121 // and a set of bitflags in one 8bit value. See below.
michael@0 122
michael@0 123 class xptiInfoFlags
michael@0 124 {
michael@0 125 enum {STATE_MASK = 3};
michael@0 126 public:
michael@0 127 xptiInfoFlags(uint8_t n) : mData(n) {}
michael@0 128 xptiInfoFlags(const xptiInfoFlags& r) : mData(r.mData) {}
michael@0 129
michael@0 130 static uint8_t GetStateMask()
michael@0 131 {return uint8_t(STATE_MASK);}
michael@0 132
michael@0 133 void Clear()
michael@0 134 {mData = 0;}
michael@0 135
michael@0 136 uint8_t GetData() const
michael@0 137 {return mData;}
michael@0 138
michael@0 139 uint8_t GetState() const
michael@0 140 {return mData & GetStateMask();}
michael@0 141
michael@0 142 void SetState(uint8_t state)
michael@0 143 {mData &= ~GetStateMask(); mData |= state;}
michael@0 144
michael@0 145 void SetFlagBit(uint8_t flag, bool on)
michael@0 146 {if(on)
michael@0 147 mData |= ~GetStateMask() & flag;
michael@0 148 else
michael@0 149 mData &= GetStateMask() | ~flag;}
michael@0 150
michael@0 151 bool GetFlagBit(uint8_t flag) const
michael@0 152 {return (mData & flag) ? true : false;}
michael@0 153
michael@0 154 private:
michael@0 155 uint8_t mData;
michael@0 156 };
michael@0 157
michael@0 158 /****************************************************/
michael@0 159
michael@0 160 // No virtual methods.
michael@0 161 // We always create in the struct arena and construct using "placement new".
michael@0 162 // No members need dtor calls.
michael@0 163
michael@0 164 class xptiInterfaceEntry
michael@0 165 {
michael@0 166 public:
michael@0 167 static xptiInterfaceEntry* Create(const char* name,
michael@0 168 const nsID& iid,
michael@0 169 XPTInterfaceDescriptor* aDescriptor,
michael@0 170 xptiTypelibGuts* aTypelib);
michael@0 171
michael@0 172 enum {
michael@0 173 PARTIALLY_RESOLVED = 1,
michael@0 174 FULLY_RESOLVED = 2,
michael@0 175 RESOLVE_FAILED = 3
michael@0 176 };
michael@0 177
michael@0 178 // Additional bit flags...
michael@0 179 enum {SCRIPTABLE = 4, BUILTINCLASS = 8};
michael@0 180
michael@0 181 uint8_t GetResolveState() const {return mFlags.GetState();}
michael@0 182
michael@0 183 bool IsFullyResolved() const
michael@0 184 {return GetResolveState() == (uint8_t) FULLY_RESOLVED;}
michael@0 185
michael@0 186 void SetScriptableFlag(bool on)
michael@0 187 {mFlags.SetFlagBit(uint8_t(SCRIPTABLE),on);}
michael@0 188 bool GetScriptableFlag() const
michael@0 189 {return mFlags.GetFlagBit(uint8_t(SCRIPTABLE));}
michael@0 190 void SetBuiltinClassFlag(bool on)
michael@0 191 {mFlags.SetFlagBit(uint8_t(BUILTINCLASS),on);}
michael@0 192 bool GetBuiltinClassFlag() const
michael@0 193 {return mFlags.GetFlagBit(uint8_t(BUILTINCLASS));}
michael@0 194
michael@0 195 const nsID* GetTheIID() const {return &mIID;}
michael@0 196 const char* GetTheName() const {return mName;}
michael@0 197
michael@0 198 bool EnsureResolved()
michael@0 199 {return IsFullyResolved() ? true : Resolve();}
michael@0 200
michael@0 201 already_AddRefed<xptiInterfaceInfo> InterfaceInfo();
michael@0 202 bool InterfaceInfoEquals(const xptiInterfaceInfo* info) const
michael@0 203 {return info == mInfo;}
michael@0 204
michael@0 205 void LockedInvalidateInterfaceInfo();
michael@0 206 void LockedInterfaceInfoDeathNotification() {mInfo = nullptr;}
michael@0 207
michael@0 208 xptiInterfaceEntry* Parent() const {
michael@0 209 NS_ASSERTION(IsFullyResolved(), "Parent() called while not resolved?");
michael@0 210 return mParent;
michael@0 211 }
michael@0 212
michael@0 213 const nsID& IID() const { return mIID; }
michael@0 214
michael@0 215 //////////////////////
michael@0 216 // These non-virtual methods handle the delegated nsIInterfaceInfo methods.
michael@0 217
michael@0 218 nsresult GetName(char * *aName);
michael@0 219 nsresult GetIID(nsIID * *aIID);
michael@0 220 nsresult IsScriptable(bool *_retval);
michael@0 221 nsresult IsBuiltinClass(bool *_retval) {
michael@0 222 *_retval = GetBuiltinClassFlag();
michael@0 223 return NS_OK;
michael@0 224 }
michael@0 225 // Except this one.
michael@0 226 //nsresult GetParent(nsIInterfaceInfo * *aParent);
michael@0 227 nsresult GetMethodCount(uint16_t *aMethodCount);
michael@0 228 nsresult GetConstantCount(uint16_t *aConstantCount);
michael@0 229 nsresult GetMethodInfo(uint16_t index, const nsXPTMethodInfo * *info);
michael@0 230 nsresult GetMethodInfoForName(const char *methodName, uint16_t *index, const nsXPTMethodInfo * *info);
michael@0 231 nsresult GetConstant(uint16_t index, const nsXPTConstant * *constant);
michael@0 232 nsresult GetInfoForParam(uint16_t methodIndex, const nsXPTParamInfo * param, nsIInterfaceInfo **_retval);
michael@0 233 nsresult GetIIDForParam(uint16_t methodIndex, const nsXPTParamInfo * param, nsIID * *_retval);
michael@0 234 nsresult GetTypeForParam(uint16_t methodIndex, const nsXPTParamInfo * param, uint16_t dimension, nsXPTType *_retval);
michael@0 235 nsresult GetSizeIsArgNumberForParam(uint16_t methodIndex, const nsXPTParamInfo * param, uint16_t dimension, uint8_t *_retval);
michael@0 236 nsresult GetInterfaceIsArgNumberForParam(uint16_t methodIndex, const nsXPTParamInfo * param, uint8_t *_retval);
michael@0 237 nsresult IsIID(const nsIID * IID, bool *_retval);
michael@0 238 nsresult GetNameShared(const char **name);
michael@0 239 nsresult GetIIDShared(const nsIID * *iid);
michael@0 240 nsresult IsFunction(bool *_retval);
michael@0 241 nsresult HasAncestor(const nsIID * iid, bool *_retval);
michael@0 242 nsresult GetIIDForParamNoAlloc(uint16_t methodIndex, const nsXPTParamInfo * param, nsIID *iid);
michael@0 243
michael@0 244 private:
michael@0 245 xptiInterfaceEntry(const char* name,
michael@0 246 size_t nameLength,
michael@0 247 const nsID& iid,
michael@0 248 XPTInterfaceDescriptor* aDescriptor,
michael@0 249 xptiTypelibGuts* aTypelib);
michael@0 250 ~xptiInterfaceEntry();
michael@0 251
michael@0 252 void SetResolvedState(int state)
michael@0 253 {mFlags.SetState(uint8_t(state));}
michael@0 254
michael@0 255 bool Resolve();
michael@0 256
michael@0 257 // We only call these "*Locked" variants after locking. This is done to
michael@0 258 // allow reentrace as files are loaded and various interfaces resolved
michael@0 259 // without having to worry about the locked state.
michael@0 260
michael@0 261 bool EnsureResolvedLocked()
michael@0 262 {return IsFullyResolved() ? true : ResolveLocked();}
michael@0 263 bool ResolveLocked();
michael@0 264
michael@0 265 // private helpers
michael@0 266
michael@0 267 nsresult GetEntryForParam(uint16_t methodIndex,
michael@0 268 const nsXPTParamInfo * param,
michael@0 269 xptiInterfaceEntry** entry);
michael@0 270
michael@0 271 nsresult GetTypeInArray(const nsXPTParamInfo* param,
michael@0 272 uint16_t dimension,
michael@0 273 const XPTTypeDescriptor** type);
michael@0 274
michael@0 275 private:
michael@0 276 nsID mIID;
michael@0 277 XPTInterfaceDescriptor* mDescriptor;
michael@0 278
michael@0 279 uint16_t mMethodBaseIndex;
michael@0 280 uint16_t mConstantBaseIndex;
michael@0 281 xptiTypelibGuts* mTypelib;
michael@0 282
michael@0 283 xptiInterfaceEntry* mParent; // Valid only when fully resolved
michael@0 284
michael@0 285 xptiInterfaceInfo* mInfo; // May come and go.
michael@0 286 xptiInfoFlags mFlags;
michael@0 287 char mName[1]; // Always last. Sized to fit.
michael@0 288 };
michael@0 289
michael@0 290 class xptiInterfaceInfo MOZ_FINAL : public nsIInterfaceInfo
michael@0 291 {
michael@0 292 public:
michael@0 293 NS_DECL_THREADSAFE_ISUPPORTS
michael@0 294
michael@0 295 // Use delegation to implement (most!) of nsIInterfaceInfo.
michael@0 296 NS_IMETHOD GetName(char * *aName) { return !mEntry ? NS_ERROR_UNEXPECTED : mEntry->GetName(aName); }
michael@0 297 NS_IMETHOD GetInterfaceIID(nsIID * *aIID) { return !mEntry ? NS_ERROR_UNEXPECTED : mEntry->GetIID(aIID); }
michael@0 298 NS_IMETHOD IsScriptable(bool *_retval) { return !mEntry ? NS_ERROR_UNEXPECTED : mEntry->IsScriptable(_retval); }
michael@0 299 NS_IMETHOD IsBuiltinClass(bool *_retval) { return !mEntry ? NS_ERROR_UNEXPECTED : mEntry->IsBuiltinClass(_retval); }
michael@0 300 // Except this one.
michael@0 301 NS_IMETHOD GetParent(nsIInterfaceInfo * *aParent)
michael@0 302 {
michael@0 303 if(!EnsureResolved() || !EnsureParent())
michael@0 304 return NS_ERROR_UNEXPECTED;
michael@0 305 NS_IF_ADDREF(*aParent = mParent);
michael@0 306 return NS_OK;
michael@0 307 }
michael@0 308 NS_IMETHOD GetMethodCount(uint16_t *aMethodCount) { return !mEntry ? NS_ERROR_UNEXPECTED : mEntry->GetMethodCount(aMethodCount); }
michael@0 309 NS_IMETHOD GetConstantCount(uint16_t *aConstantCount) { return !mEntry ? NS_ERROR_UNEXPECTED : mEntry->GetConstantCount(aConstantCount); }
michael@0 310 NS_IMETHOD GetMethodInfo(uint16_t index, const nsXPTMethodInfo * *info) { return !mEntry ? NS_ERROR_UNEXPECTED : mEntry->GetMethodInfo(index, info); }
michael@0 311 NS_IMETHOD GetMethodInfoForName(const char *methodName, uint16_t *index, const nsXPTMethodInfo * *info) { return !mEntry ? NS_ERROR_UNEXPECTED : mEntry->GetMethodInfoForName(methodName, index, info); }
michael@0 312 NS_IMETHOD GetConstant(uint16_t index, const nsXPTConstant * *constant) { return !mEntry ? NS_ERROR_UNEXPECTED : mEntry->GetConstant(index, constant); }
michael@0 313 NS_IMETHOD GetInfoForParam(uint16_t methodIndex, const nsXPTParamInfo * param, nsIInterfaceInfo **_retval) { return !mEntry ? NS_ERROR_UNEXPECTED : mEntry->GetInfoForParam(methodIndex, param, _retval); }
michael@0 314 NS_IMETHOD GetIIDForParam(uint16_t methodIndex, const nsXPTParamInfo * param, nsIID * *_retval) { return !mEntry ? NS_ERROR_UNEXPECTED : mEntry->GetIIDForParam(methodIndex, param, _retval); }
michael@0 315 NS_IMETHOD GetTypeForParam(uint16_t methodIndex, const nsXPTParamInfo * param, uint16_t dimension, nsXPTType *_retval) { return !mEntry ? NS_ERROR_UNEXPECTED : mEntry->GetTypeForParam(methodIndex, param, dimension, _retval); }
michael@0 316 NS_IMETHOD GetSizeIsArgNumberForParam(uint16_t methodIndex, const nsXPTParamInfo * param, uint16_t dimension, uint8_t *_retval) { return !mEntry ? NS_ERROR_UNEXPECTED : mEntry->GetSizeIsArgNumberForParam(methodIndex, param, dimension, _retval); }
michael@0 317 NS_IMETHOD GetInterfaceIsArgNumberForParam(uint16_t methodIndex, const nsXPTParamInfo * param, uint8_t *_retval) { return !mEntry ? NS_ERROR_UNEXPECTED : mEntry->GetInterfaceIsArgNumberForParam(methodIndex, param, _retval); }
michael@0 318 NS_IMETHOD IsIID(const nsIID * IID, bool *_retval) { return !mEntry ? NS_ERROR_UNEXPECTED : mEntry->IsIID(IID, _retval); }
michael@0 319 NS_IMETHOD GetNameShared(const char **name) { return !mEntry ? NS_ERROR_UNEXPECTED : mEntry->GetNameShared(name); }
michael@0 320 NS_IMETHOD GetIIDShared(const nsIID * *iid) { return !mEntry ? NS_ERROR_UNEXPECTED : mEntry->GetIIDShared(iid); }
michael@0 321 NS_IMETHOD IsFunction(bool *_retval) { return !mEntry ? NS_ERROR_UNEXPECTED : mEntry->IsFunction(_retval); }
michael@0 322 NS_IMETHOD HasAncestor(const nsIID * iid, bool *_retval) { return !mEntry ? NS_ERROR_UNEXPECTED : mEntry->HasAncestor(iid, _retval); }
michael@0 323 NS_IMETHOD GetIIDForParamNoAlloc(uint16_t methodIndex, const nsXPTParamInfo * param, nsIID *iid) { return !mEntry ? NS_ERROR_UNEXPECTED : mEntry->GetIIDForParamNoAlloc(methodIndex, param, iid); }
michael@0 324
michael@0 325 public:
michael@0 326 xptiInterfaceInfo(xptiInterfaceEntry* entry);
michael@0 327
michael@0 328 void Invalidate()
michael@0 329 {NS_IF_RELEASE(mParent); mEntry = nullptr;}
michael@0 330
michael@0 331 private:
michael@0 332
michael@0 333 ~xptiInterfaceInfo();
michael@0 334
michael@0 335 // Note that mParent might still end up as nullptr if we don't have one.
michael@0 336 bool EnsureParent()
michael@0 337 {
michael@0 338 NS_ASSERTION(mEntry && mEntry->IsFullyResolved(), "bad EnsureParent call");
michael@0 339 return mParent || !mEntry->Parent() || BuildParent();
michael@0 340 }
michael@0 341
michael@0 342 bool EnsureResolved()
michael@0 343 {
michael@0 344 return mEntry && mEntry->EnsureResolved();
michael@0 345 }
michael@0 346
michael@0 347 bool BuildParent();
michael@0 348
michael@0 349 xptiInterfaceInfo(); // not implemented
michael@0 350
michael@0 351 private:
michael@0 352 xptiInterfaceEntry* mEntry;
michael@0 353 xptiInterfaceInfo* mParent;
michael@0 354 };
michael@0 355
michael@0 356 /***************************************************************************/
michael@0 357
michael@0 358 #endif /* xptiprivate_h___ */

mercurial