xpcom/glue/nsID.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
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 #ifndef nsID_h__
michael@0 7 #define nsID_h__
michael@0 8
michael@0 9 #include <string.h>
michael@0 10
michael@0 11 #include "nscore.h"
michael@0 12
michael@0 13 #define NSID_LENGTH 39
michael@0 14
michael@0 15 /**
michael@0 16 * A "unique identifier". This is modeled after OSF DCE UUIDs.
michael@0 17 */
michael@0 18
michael@0 19 struct nsID {
michael@0 20 /**
michael@0 21 * @name Identifier values
michael@0 22 */
michael@0 23
michael@0 24 //@{
michael@0 25 uint32_t m0;
michael@0 26 uint16_t m1;
michael@0 27 uint16_t m2;
michael@0 28 uint8_t m3[8];
michael@0 29 //@}
michael@0 30
michael@0 31 /**
michael@0 32 * @name Methods
michael@0 33 */
michael@0 34
michael@0 35 //@{
michael@0 36 /**
michael@0 37 * Equivalency method. Compares this nsID with another.
michael@0 38 * @return <b>true</b> if they are the same, <b>false</b> if not.
michael@0 39 */
michael@0 40
michael@0 41 inline bool Equals(const nsID& other) const {
michael@0 42 // Unfortunately memcmp isn't faster than this.
michael@0 43 return
michael@0 44 ((((uint32_t*) &m0)[0] == ((uint32_t*) &other.m0)[0]) &&
michael@0 45 (((uint32_t*) &m0)[1] == ((uint32_t*) &other.m0)[1]) &&
michael@0 46 (((uint32_t*) &m0)[2] == ((uint32_t*) &other.m0)[2]) &&
michael@0 47 (((uint32_t*) &m0)[3] == ((uint32_t*) &other.m0)[3]));
michael@0 48 }
michael@0 49
michael@0 50 /**
michael@0 51 * nsID Parsing method. Turns a {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
michael@0 52 * string into an nsID
michael@0 53 */
michael@0 54 NS_COM_GLUE bool Parse(const char *aIDStr);
michael@0 55
michael@0 56 #ifndef XPCOM_GLUE_AVOID_NSPR
michael@0 57 /**
michael@0 58 * nsID string encoder. Returns an allocated string in
michael@0 59 * {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} format. Caller should free string.
michael@0 60 * YOU SHOULD ONLY USE THIS IF YOU CANNOT USE ToProvidedString() BELOW.
michael@0 61 */
michael@0 62 NS_COM_GLUE char* ToString() const;
michael@0 63
michael@0 64 /**
michael@0 65 * nsID string encoder. Builds a string in
michael@0 66 * {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} format, into a char[NSID_LENGTH]
michael@0 67 * buffer provided by the caller (for instance, on the stack).
michael@0 68 */
michael@0 69 NS_COM_GLUE void ToProvidedString(char (&dest)[NSID_LENGTH]) const;
michael@0 70
michael@0 71 #endif // XPCOM_GLUE_AVOID_NSPR
michael@0 72
michael@0 73 //@}
michael@0 74 };
michael@0 75
michael@0 76 /*
michael@0 77 * Class IDs
michael@0 78 */
michael@0 79
michael@0 80 typedef nsID nsCID;
michael@0 81
michael@0 82 // Define an CID
michael@0 83 #define NS_DEFINE_CID(_name, _cidspec) \
michael@0 84 const nsCID _name = _cidspec
michael@0 85
michael@0 86 #define NS_DEFINE_NAMED_CID(_name) \
michael@0 87 static nsCID k##_name = _name
michael@0 88
michael@0 89 #define REFNSCID const nsCID&
michael@0 90
michael@0 91 /**
michael@0 92 * An "interface id" which can be used to uniquely identify a given
michael@0 93 * interface.
michael@0 94 */
michael@0 95
michael@0 96 typedef nsID nsIID;
michael@0 97
michael@0 98 /**
michael@0 99 * A macro shorthand for <tt>const nsIID&<tt>
michael@0 100 */
michael@0 101
michael@0 102 #define REFNSIID const nsIID&
michael@0 103
michael@0 104 /**
michael@0 105 * Define an IID
michael@0 106 * obsolete - do not use this macro
michael@0 107 */
michael@0 108
michael@0 109 #define NS_DEFINE_IID(_name, _iidspec) \
michael@0 110 const nsIID _name = _iidspec
michael@0 111
michael@0 112 /**
michael@0 113 * A macro to build the static const IID accessor method. The Dummy
michael@0 114 * template parameter only exists so that the kIID symbol will be linked
michael@0 115 * properly (weak symbol on linux, gnu_linkonce on mac, multiple-definitions
michael@0 116 * merged on windows). Dummy should always be instantiated as "int".
michael@0 117 */
michael@0 118
michael@0 119 #define NS_DECLARE_STATIC_IID_ACCESSOR(the_iid) \
michael@0 120 template <class Dummy> \
michael@0 121 struct COMTypeInfo \
michael@0 122 { \
michael@0 123 static const nsIID kIID NS_HIDDEN; \
michael@0 124 };
michael@0 125
michael@0 126 #define NS_DEFINE_STATIC_IID_ACCESSOR(the_interface, the_iid) \
michael@0 127 template <class Dummy> \
michael@0 128 const nsIID the_interface::COMTypeInfo<Dummy>::kIID NS_HIDDEN = the_iid;
michael@0 129
michael@0 130 /**
michael@0 131 * A macro to build the static const CID accessor method
michael@0 132 */
michael@0 133
michael@0 134 #define NS_DEFINE_STATIC_CID_ACCESSOR(the_cid) \
michael@0 135 static const nsID& GetCID() {static const nsID cid = the_cid; return cid;}
michael@0 136
michael@0 137 #define NS_GET_IID(T) (T::COMTypeInfo<int>::kIID)
michael@0 138 #define NS_GET_TEMPLATE_IID(T) (T::template COMTypeInfo<int>::kIID)
michael@0 139
michael@0 140 #endif

mercurial