Sat, 03 Jan 2015 20:18:00 +0100
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 | /* |
michael@0 | 2 | * Copyright 2013 Google, Inc. |
michael@0 | 3 | * |
michael@0 | 4 | * Use of this source code is governed by a BSD-style license that can be |
michael@0 | 5 | * found in the LICENSE file. |
michael@0 | 6 | */ |
michael@0 | 7 | |
michael@0 | 8 | |
michael@0 | 9 | #ifndef SkRTConf_DEFINED |
michael@0 | 10 | #define SkRTConf_DEFINED |
michael@0 | 11 | |
michael@0 | 12 | #include "SkString.h" |
michael@0 | 13 | #include "SkStream.h" |
michael@0 | 14 | |
michael@0 | 15 | #include "SkTDict.h" |
michael@0 | 16 | #include "SkTArray.h" |
michael@0 | 17 | |
michael@0 | 18 | /** \class SkRTConfBase |
michael@0 | 19 | Non-templated base class for the runtime configs |
michael@0 | 20 | */ |
michael@0 | 21 | |
michael@0 | 22 | class SkRTConfBase { |
michael@0 | 23 | public: |
michael@0 | 24 | SkRTConfBase(const char *name) : fName(name) {} |
michael@0 | 25 | virtual ~SkRTConfBase() {} |
michael@0 | 26 | virtual const char *getName() const { return fName.c_str(); } |
michael@0 | 27 | virtual bool isDefault() const = 0; |
michael@0 | 28 | virtual void print(SkWStream *o) const = 0; |
michael@0 | 29 | virtual bool equals(const SkRTConfBase *conf) const = 0; |
michael@0 | 30 | protected: |
michael@0 | 31 | SkString fName; |
michael@0 | 32 | }; |
michael@0 | 33 | |
michael@0 | 34 | /** \class SkRTConf |
michael@0 | 35 | A class to provide runtime configurability. |
michael@0 | 36 | */ |
michael@0 | 37 | template<typename T> class SkRTConf: public SkRTConfBase { |
michael@0 | 38 | public: |
michael@0 | 39 | SkRTConf(const char *name, const T &defaultValue, const char *description); |
michael@0 | 40 | operator const T&() const { return fValue; } |
michael@0 | 41 | void print(SkWStream *o) const; |
michael@0 | 42 | bool equals(const SkRTConfBase *conf) const; |
michael@0 | 43 | bool isDefault() const { return fDefault == fValue; } |
michael@0 | 44 | void set(const T& value) { fValue = value; } |
michael@0 | 45 | protected: |
michael@0 | 46 | void doPrint(char *s) const; |
michael@0 | 47 | |
michael@0 | 48 | T fValue; |
michael@0 | 49 | T fDefault; |
michael@0 | 50 | SkString fDescription; |
michael@0 | 51 | }; |
michael@0 | 52 | |
michael@0 | 53 | #ifdef SK_DEVELOPER |
michael@0 | 54 | #define SK_CONF_DECLARE(confType, varName, confName, defaultValue, description) static SkRTConf<confType> varName(confName, defaultValue, description) |
michael@0 | 55 | #define SK_CONF_SET(confname, value) \ |
michael@0 | 56 | skRTConfRegistry().set(confname, value, true) |
michael@0 | 57 | /* SK_CONF_TRY_SET() is like SK_CONF_SET(), but doesn't complain if |
michael@0 | 58 | confname can't be found. This is useful if the SK_CONF_DECLARE is |
michael@0 | 59 | inside a source file whose linkage is dependent on the system. */ |
michael@0 | 60 | #define SK_CONF_TRY_SET(confname, value) \ |
michael@0 | 61 | skRTConfRegistry().set(confname, value, false) |
michael@0 | 62 | #else |
michael@0 | 63 | #define SK_CONF_DECLARE(confType, varName, confName, defaultValue, description) static confType varName = defaultValue |
michael@0 | 64 | #define SK_CONF_SET(confname, value) (void) confname, (void) value |
michael@0 | 65 | #define SK_CONF_TRY_SET(confname, value) (void) confname, (void) value |
michael@0 | 66 | #endif |
michael@0 | 67 | |
michael@0 | 68 | /** \class SkRTConfRegistry |
michael@0 | 69 | A class that maintains a systemwide registry of all runtime configuration |
michael@0 | 70 | parameters. Mainly used for printing them out and handling multiply-defined |
michael@0 | 71 | knobs. |
michael@0 | 72 | */ |
michael@0 | 73 | |
michael@0 | 74 | class SkRTConfRegistry { |
michael@0 | 75 | public: |
michael@0 | 76 | SkRTConfRegistry(); |
michael@0 | 77 | ~SkRTConfRegistry(); |
michael@0 | 78 | void printAll(const char *fname = NULL) const; |
michael@0 | 79 | bool hasNonDefault() const; |
michael@0 | 80 | void printNonDefault(const char *fname = NULL) const; |
michael@0 | 81 | const char *configFileLocation() const; |
michael@0 | 82 | void possiblyDumpFile() const; |
michael@0 | 83 | void validate() const; |
michael@0 | 84 | template <typename T> void set(const char *confname, |
michael@0 | 85 | T value, |
michael@0 | 86 | bool warnIfNotFound = true); |
michael@0 | 87 | #ifdef SK_SUPPORT_UNITTEST |
michael@0 | 88 | static void UnitTest(); |
michael@0 | 89 | #endif |
michael@0 | 90 | private: |
michael@0 | 91 | template<typename T> friend class SkRTConf; |
michael@0 | 92 | |
michael@0 | 93 | void registerConf(SkRTConfBase *conf); |
michael@0 | 94 | template <typename T> bool parse(const char *name, T* value); |
michael@0 | 95 | |
michael@0 | 96 | SkTDArray<SkString *> fConfigFileKeys, fConfigFileValues; |
michael@0 | 97 | typedef SkTDict< SkTDArray<SkRTConfBase *> * > ConfMap; |
michael@0 | 98 | ConfMap fConfs; |
michael@0 | 99 | #ifdef SK_SUPPORT_UNITTEST |
michael@0 | 100 | SkRTConfRegistry(bool); |
michael@0 | 101 | #endif |
michael@0 | 102 | }; |
michael@0 | 103 | |
michael@0 | 104 | // our singleton registry |
michael@0 | 105 | |
michael@0 | 106 | SkRTConfRegistry &skRTConfRegistry(); |
michael@0 | 107 | |
michael@0 | 108 | template<typename T> |
michael@0 | 109 | SkRTConf<T>::SkRTConf(const char *name, const T &defaultValue, const char *description) |
michael@0 | 110 | : SkRTConfBase(name) |
michael@0 | 111 | , fValue(defaultValue) |
michael@0 | 112 | , fDefault(defaultValue) |
michael@0 | 113 | , fDescription(description) { |
michael@0 | 114 | |
michael@0 | 115 | T value; |
michael@0 | 116 | if (skRTConfRegistry().parse(fName.c_str(), &value)) { |
michael@0 | 117 | fValue = value; |
michael@0 | 118 | } |
michael@0 | 119 | skRTConfRegistry().registerConf(this); |
michael@0 | 120 | } |
michael@0 | 121 | |
michael@0 | 122 | template<typename T> |
michael@0 | 123 | void SkRTConf<T>::print(SkWStream *o) const { |
michael@0 | 124 | char outline[200]; // should be ok because we specify a max. width for everything here. |
michael@0 | 125 | char *outptr; |
michael@0 | 126 | if (strlen(getName()) >= 30) { |
michael@0 | 127 | o->writeText(getName()); |
michael@0 | 128 | o->writeText(" "); |
michael@0 | 129 | outptr = &(outline[0]); |
michael@0 | 130 | } else { |
michael@0 | 131 | sprintf(outline, "%-30.30s", getName()); |
michael@0 | 132 | outptr = &(outline[30]); |
michael@0 | 133 | } |
michael@0 | 134 | |
michael@0 | 135 | doPrint(outptr); |
michael@0 | 136 | sprintf(outptr+30, " %.128s", fDescription.c_str()); |
michael@0 | 137 | for (size_t i = strlen(outline); i --> 0 && ' ' == outline[i];) { |
michael@0 | 138 | outline[i] = '\0'; |
michael@0 | 139 | } |
michael@0 | 140 | o->writeText(outline); |
michael@0 | 141 | } |
michael@0 | 142 | |
michael@0 | 143 | template<typename T> |
michael@0 | 144 | void SkRTConf<T>::doPrint(char *s) const { |
michael@0 | 145 | sprintf(s, "%-30.30s", "How do I print myself??"); |
michael@0 | 146 | } |
michael@0 | 147 | |
michael@0 | 148 | template<> inline void SkRTConf<bool>::doPrint(char *s) const { |
michael@0 | 149 | char tmp[30]; |
michael@0 | 150 | sprintf(tmp, "%s # [%s]", fValue ? "true" : "false", fDefault ? "true" : "false"); |
michael@0 | 151 | sprintf(s, "%-30.30s", tmp); |
michael@0 | 152 | } |
michael@0 | 153 | |
michael@0 | 154 | template<> inline void SkRTConf<int>::doPrint(char *s) const { |
michael@0 | 155 | char tmp[30]; |
michael@0 | 156 | sprintf(tmp, "%d # [%d]", fValue, fDefault); |
michael@0 | 157 | sprintf(s, "%-30.30s", tmp); |
michael@0 | 158 | } |
michael@0 | 159 | |
michael@0 | 160 | template<> inline void SkRTConf<unsigned int>::doPrint(char *s) const { |
michael@0 | 161 | char tmp[30]; |
michael@0 | 162 | sprintf(tmp, "%u # [%u]", fValue, fDefault); |
michael@0 | 163 | sprintf(s, "%-30.30s", tmp); |
michael@0 | 164 | } |
michael@0 | 165 | |
michael@0 | 166 | template<> inline void SkRTConf<float>::doPrint(char *s) const { |
michael@0 | 167 | char tmp[30]; |
michael@0 | 168 | sprintf(tmp, "%6.6f # [%6.6f]", fValue, fDefault); |
michael@0 | 169 | sprintf(s, "%-30.30s", tmp); |
michael@0 | 170 | } |
michael@0 | 171 | |
michael@0 | 172 | template<> inline void SkRTConf<double>::doPrint(char *s) const { |
michael@0 | 173 | char tmp[30]; |
michael@0 | 174 | sprintf(tmp, "%6.6f # [%6.6f]", fValue, fDefault); |
michael@0 | 175 | sprintf(s, "%-30.30s", tmp); |
michael@0 | 176 | } |
michael@0 | 177 | |
michael@0 | 178 | template<> inline void SkRTConf<const char *>::doPrint(char *s) const { |
michael@0 | 179 | char tmp[30]; |
michael@0 | 180 | sprintf(tmp, "%s # [%s]", fValue, fDefault); |
michael@0 | 181 | sprintf(s, "%-30.30s", tmp); |
michael@0 | 182 | } |
michael@0 | 183 | |
michael@0 | 184 | template<typename T> |
michael@0 | 185 | bool SkRTConf<T>::equals(const SkRTConfBase *conf) const { |
michael@0 | 186 | // static_cast here is okay because there's only one kind of child class. |
michael@0 | 187 | const SkRTConf<T> *child_pointer = static_cast<const SkRTConf<T> *>(conf); |
michael@0 | 188 | return child_pointer && |
michael@0 | 189 | fName == child_pointer->fName && |
michael@0 | 190 | fDescription == child_pointer->fDescription && |
michael@0 | 191 | fValue == child_pointer->fValue && |
michael@0 | 192 | fDefault == child_pointer->fDefault; |
michael@0 | 193 | } |
michael@0 | 194 | |
michael@0 | 195 | #endif |