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 | /* |
michael@0 | 3 | * Copyright 2006 The Android Open Source Project |
michael@0 | 4 | * |
michael@0 | 5 | * Use of this source code is governed by a BSD-style license that can be |
michael@0 | 6 | * found in the LICENSE file. |
michael@0 | 7 | */ |
michael@0 | 8 | |
michael@0 | 9 | |
michael@0 | 10 | #include "SkDisplayMath.h" |
michael@0 | 11 | |
michael@0 | 12 | enum SkDisplayMath_Properties { |
michael@0 | 13 | SK_PROPERTY(E), |
michael@0 | 14 | SK_PROPERTY(LN10), |
michael@0 | 15 | SK_PROPERTY(LN2), |
michael@0 | 16 | SK_PROPERTY(LOG10E), |
michael@0 | 17 | SK_PROPERTY(LOG2E), |
michael@0 | 18 | SK_PROPERTY(PI), |
michael@0 | 19 | SK_PROPERTY(SQRT1_2), |
michael@0 | 20 | SK_PROPERTY(SQRT2) |
michael@0 | 21 | }; |
michael@0 | 22 | |
michael@0 | 23 | const SkScalar SkDisplayMath::gConstants[] = { |
michael@0 | 24 | 2.718281828f, // E |
michael@0 | 25 | 2.302585093f, // LN10 |
michael@0 | 26 | 0.693147181f, // LN2 |
michael@0 | 27 | 0.434294482f, // LOG10E |
michael@0 | 28 | 1.442695041f, // LOG2E |
michael@0 | 29 | 3.141592654f, // PI |
michael@0 | 30 | 0.707106781f, // SQRT1_2 |
michael@0 | 31 | 1.414213562f // SQRT2 |
michael@0 | 32 | }; |
michael@0 | 33 | |
michael@0 | 34 | enum SkDisplayMath_Functions { |
michael@0 | 35 | SK_FUNCTION(abs), |
michael@0 | 36 | SK_FUNCTION(acos), |
michael@0 | 37 | SK_FUNCTION(asin), |
michael@0 | 38 | SK_FUNCTION(atan), |
michael@0 | 39 | SK_FUNCTION(atan2), |
michael@0 | 40 | SK_FUNCTION(ceil), |
michael@0 | 41 | SK_FUNCTION(cos), |
michael@0 | 42 | SK_FUNCTION(exp), |
michael@0 | 43 | SK_FUNCTION(floor), |
michael@0 | 44 | SK_FUNCTION(log), |
michael@0 | 45 | SK_FUNCTION(max), |
michael@0 | 46 | SK_FUNCTION(min), |
michael@0 | 47 | SK_FUNCTION(pow), |
michael@0 | 48 | SK_FUNCTION(random), |
michael@0 | 49 | SK_FUNCTION(round), |
michael@0 | 50 | SK_FUNCTION(sin), |
michael@0 | 51 | SK_FUNCTION(sqrt), |
michael@0 | 52 | SK_FUNCTION(tan) |
michael@0 | 53 | }; |
michael@0 | 54 | |
michael@0 | 55 | const SkFunctionParamType SkDisplayMath::fFunctionParameters[] = { |
michael@0 | 56 | (SkFunctionParamType) SkType_Float, // abs |
michael@0 | 57 | (SkFunctionParamType) 0, |
michael@0 | 58 | (SkFunctionParamType) SkType_Float, // acos |
michael@0 | 59 | (SkFunctionParamType) 0, |
michael@0 | 60 | (SkFunctionParamType) SkType_Float, // asin |
michael@0 | 61 | (SkFunctionParamType) 0, |
michael@0 | 62 | (SkFunctionParamType) SkType_Float, // atan |
michael@0 | 63 | (SkFunctionParamType) 0, |
michael@0 | 64 | (SkFunctionParamType) SkType_Float, // atan2 |
michael@0 | 65 | (SkFunctionParamType) SkType_Float, |
michael@0 | 66 | (SkFunctionParamType) 0, |
michael@0 | 67 | (SkFunctionParamType) SkType_Float, // ceil |
michael@0 | 68 | (SkFunctionParamType) 0, |
michael@0 | 69 | (SkFunctionParamType) SkType_Float, // cos |
michael@0 | 70 | (SkFunctionParamType) 0, |
michael@0 | 71 | (SkFunctionParamType) SkType_Float, // exp |
michael@0 | 72 | (SkFunctionParamType) 0, |
michael@0 | 73 | (SkFunctionParamType) SkType_Float, // floor |
michael@0 | 74 | (SkFunctionParamType) 0, |
michael@0 | 75 | (SkFunctionParamType) SkType_Float, // log |
michael@0 | 76 | (SkFunctionParamType) 0, |
michael@0 | 77 | (SkFunctionParamType) SkType_Array, // max |
michael@0 | 78 | (SkFunctionParamType) 0, |
michael@0 | 79 | (SkFunctionParamType) SkType_Array, // min |
michael@0 | 80 | (SkFunctionParamType) 0, |
michael@0 | 81 | (SkFunctionParamType) SkType_Float, // pow |
michael@0 | 82 | (SkFunctionParamType) SkType_Float, |
michael@0 | 83 | (SkFunctionParamType) 0, |
michael@0 | 84 | (SkFunctionParamType) SkType_Float, // random |
michael@0 | 85 | (SkFunctionParamType) 0, |
michael@0 | 86 | (SkFunctionParamType) SkType_Float, // round |
michael@0 | 87 | (SkFunctionParamType) 0, |
michael@0 | 88 | (SkFunctionParamType) SkType_Float, // sin |
michael@0 | 89 | (SkFunctionParamType) 0, |
michael@0 | 90 | (SkFunctionParamType) SkType_Float, // sqrt |
michael@0 | 91 | (SkFunctionParamType) 0, |
michael@0 | 92 | (SkFunctionParamType) SkType_Float, // tan |
michael@0 | 93 | (SkFunctionParamType) 0 |
michael@0 | 94 | }; |
michael@0 | 95 | |
michael@0 | 96 | #if SK_USE_CONDENSED_INFO == 0 |
michael@0 | 97 | |
michael@0 | 98 | const SkMemberInfo SkDisplayMath::fInfo[] = { |
michael@0 | 99 | SK_MEMBER_PROPERTY(E, Float), |
michael@0 | 100 | SK_MEMBER_PROPERTY(LN10, Float), |
michael@0 | 101 | SK_MEMBER_PROPERTY(LN2, Float), |
michael@0 | 102 | SK_MEMBER_PROPERTY(LOG10E, Float), |
michael@0 | 103 | SK_MEMBER_PROPERTY(LOG2E, Float), |
michael@0 | 104 | SK_MEMBER_PROPERTY(PI, Float), |
michael@0 | 105 | SK_MEMBER_PROPERTY(SQRT1_2, Float), |
michael@0 | 106 | SK_MEMBER_PROPERTY(SQRT2, Float), |
michael@0 | 107 | SK_MEMBER_FUNCTION(abs, Float), |
michael@0 | 108 | SK_MEMBER_FUNCTION(acos, Float), |
michael@0 | 109 | SK_MEMBER_FUNCTION(asin, Float), |
michael@0 | 110 | SK_MEMBER_FUNCTION(atan, Float), |
michael@0 | 111 | SK_MEMBER_FUNCTION(atan2, Float), |
michael@0 | 112 | SK_MEMBER_FUNCTION(ceil, Float), |
michael@0 | 113 | SK_MEMBER_FUNCTION(cos, Float), |
michael@0 | 114 | SK_MEMBER_FUNCTION(exp, Float), |
michael@0 | 115 | SK_MEMBER_FUNCTION(floor, Float), |
michael@0 | 116 | SK_MEMBER_FUNCTION(log, Float), |
michael@0 | 117 | SK_MEMBER_FUNCTION(max, Float), |
michael@0 | 118 | SK_MEMBER_FUNCTION(min, Float), |
michael@0 | 119 | SK_MEMBER_FUNCTION(pow, Float), |
michael@0 | 120 | SK_MEMBER_FUNCTION(random, Float), |
michael@0 | 121 | SK_MEMBER_FUNCTION(round, Float), |
michael@0 | 122 | SK_MEMBER_FUNCTION(sin, Float), |
michael@0 | 123 | SK_MEMBER_FUNCTION(sqrt, Float), |
michael@0 | 124 | SK_MEMBER_FUNCTION(tan, Float) |
michael@0 | 125 | }; |
michael@0 | 126 | |
michael@0 | 127 | #endif |
michael@0 | 128 | |
michael@0 | 129 | DEFINE_GET_MEMBER(SkDisplayMath); |
michael@0 | 130 | |
michael@0 | 131 | void SkDisplayMath::executeFunction(SkDisplayable* target, int index, |
michael@0 | 132 | SkTDArray<SkScriptValue>& parameters, SkDisplayTypes type, |
michael@0 | 133 | SkScriptValue* scriptValue) { |
michael@0 | 134 | if (scriptValue == NULL) |
michael@0 | 135 | return; |
michael@0 | 136 | SkASSERT(target == this); |
michael@0 | 137 | SkScriptValue* array = parameters.begin(); |
michael@0 | 138 | SkScriptValue* end = parameters.end(); |
michael@0 | 139 | SkScalar input = parameters[0].fOperand.fScalar; |
michael@0 | 140 | SkScalar scalarResult; |
michael@0 | 141 | switch (index) { |
michael@0 | 142 | case SK_FUNCTION(abs): |
michael@0 | 143 | scalarResult = SkScalarAbs(input); |
michael@0 | 144 | break; |
michael@0 | 145 | case SK_FUNCTION(acos): |
michael@0 | 146 | scalarResult = SkScalarACos(input); |
michael@0 | 147 | break; |
michael@0 | 148 | case SK_FUNCTION(asin): |
michael@0 | 149 | scalarResult = SkScalarASin(input); |
michael@0 | 150 | break; |
michael@0 | 151 | case SK_FUNCTION(atan): |
michael@0 | 152 | scalarResult = SkScalarATan2(input, SK_Scalar1); |
michael@0 | 153 | break; |
michael@0 | 154 | case SK_FUNCTION(atan2): |
michael@0 | 155 | scalarResult = SkScalarATan2(input, parameters[1].fOperand.fScalar); |
michael@0 | 156 | break; |
michael@0 | 157 | case SK_FUNCTION(ceil): |
michael@0 | 158 | scalarResult = SkScalarCeilToScalar(input); |
michael@0 | 159 | break; |
michael@0 | 160 | case SK_FUNCTION(cos): |
michael@0 | 161 | scalarResult = SkScalarCos(input); |
michael@0 | 162 | break; |
michael@0 | 163 | case SK_FUNCTION(exp): |
michael@0 | 164 | scalarResult = SkScalarExp(input); |
michael@0 | 165 | break; |
michael@0 | 166 | case SK_FUNCTION(floor): |
michael@0 | 167 | scalarResult = SkScalarFloorToScalar(input); |
michael@0 | 168 | break; |
michael@0 | 169 | case SK_FUNCTION(log): |
michael@0 | 170 | scalarResult = SkScalarLog(input); |
michael@0 | 171 | break; |
michael@0 | 172 | case SK_FUNCTION(max): |
michael@0 | 173 | scalarResult = -SK_ScalarMax; |
michael@0 | 174 | while (array < end) { |
michael@0 | 175 | scalarResult = SkMaxScalar(scalarResult, array->fOperand.fScalar); |
michael@0 | 176 | array++; |
michael@0 | 177 | } |
michael@0 | 178 | break; |
michael@0 | 179 | case SK_FUNCTION(min): |
michael@0 | 180 | scalarResult = SK_ScalarMax; |
michael@0 | 181 | while (array < end) { |
michael@0 | 182 | scalarResult = SkMinScalar(scalarResult, array->fOperand.fScalar); |
michael@0 | 183 | array++; |
michael@0 | 184 | } |
michael@0 | 185 | break; |
michael@0 | 186 | case SK_FUNCTION(pow): |
michael@0 | 187 | // not the greatest -- but use x^y = e^(y * ln(x)) |
michael@0 | 188 | scalarResult = SkScalarLog(input); |
michael@0 | 189 | scalarResult = SkScalarMul(parameters[1].fOperand.fScalar, scalarResult); |
michael@0 | 190 | scalarResult = SkScalarExp(scalarResult); |
michael@0 | 191 | break; |
michael@0 | 192 | case SK_FUNCTION(random): |
michael@0 | 193 | scalarResult = fRandom.nextUScalar1(); |
michael@0 | 194 | break; |
michael@0 | 195 | case SK_FUNCTION(round): |
michael@0 | 196 | scalarResult = SkScalarRoundToScalar(input); |
michael@0 | 197 | break; |
michael@0 | 198 | case SK_FUNCTION(sin): |
michael@0 | 199 | scalarResult = SkScalarSin(input); |
michael@0 | 200 | break; |
michael@0 | 201 | case SK_FUNCTION(sqrt): { |
michael@0 | 202 | SkASSERT(parameters.count() == 1); |
michael@0 | 203 | SkASSERT(type == SkType_Float); |
michael@0 | 204 | scalarResult = SkScalarSqrt(input); |
michael@0 | 205 | } break; |
michael@0 | 206 | case SK_FUNCTION(tan): |
michael@0 | 207 | scalarResult = SkScalarTan(input); |
michael@0 | 208 | break; |
michael@0 | 209 | default: |
michael@0 | 210 | SkASSERT(0); |
michael@0 | 211 | scalarResult = SK_ScalarNaN; |
michael@0 | 212 | } |
michael@0 | 213 | scriptValue->fOperand.fScalar = scalarResult; |
michael@0 | 214 | scriptValue->fType = SkType_Float; |
michael@0 | 215 | } |
michael@0 | 216 | |
michael@0 | 217 | const SkFunctionParamType* SkDisplayMath::getFunctionsParameters() { |
michael@0 | 218 | return fFunctionParameters; |
michael@0 | 219 | } |
michael@0 | 220 | |
michael@0 | 221 | bool SkDisplayMath::getProperty(int index, SkScriptValue* value) const { |
michael@0 | 222 | if ((unsigned)index < SK_ARRAY_COUNT(gConstants)) { |
michael@0 | 223 | value->fOperand.fScalar = gConstants[index]; |
michael@0 | 224 | value->fType = SkType_Float; |
michael@0 | 225 | return true; |
michael@0 | 226 | } |
michael@0 | 227 | SkASSERT(0); |
michael@0 | 228 | return false; |
michael@0 | 229 | } |