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 2012 Google Inc. |
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 | #include "SkObjectParser.h" |
michael@0 | 10 | #include "SkData.h" |
michael@0 | 11 | #include "SkFontDescriptor.h" |
michael@0 | 12 | #include "SkRRect.h" |
michael@0 | 13 | #include "SkShader.h" |
michael@0 | 14 | #include "SkStream.h" |
michael@0 | 15 | #include "SkStringUtils.h" |
michael@0 | 16 | #include "SkTypeface.h" |
michael@0 | 17 | #include "SkUtils.h" |
michael@0 | 18 | |
michael@0 | 19 | /* TODO(chudy): Replace all std::strings with char */ |
michael@0 | 20 | |
michael@0 | 21 | SkString* SkObjectParser::BitmapToString(const SkBitmap& bitmap) { |
michael@0 | 22 | SkString* mBitmap = new SkString("SkBitmap: "); |
michael@0 | 23 | mBitmap->append("W: "); |
michael@0 | 24 | mBitmap->appendS32(bitmap.width()); |
michael@0 | 25 | mBitmap->append(" H: "); |
michael@0 | 26 | mBitmap->appendS32(bitmap.height()); |
michael@0 | 27 | |
michael@0 | 28 | const char* gConfigStrings[] = { |
michael@0 | 29 | "None", "A8", "Index8", "RGB565", "ARGB4444", "ARGB8888" |
michael@0 | 30 | }; |
michael@0 | 31 | SkASSERT(SkBitmap::kConfigCount == SK_ARRAY_COUNT(gConfigStrings)); |
michael@0 | 32 | |
michael@0 | 33 | mBitmap->append(" Config: "); |
michael@0 | 34 | mBitmap->append(gConfigStrings[bitmap.config()]); |
michael@0 | 35 | |
michael@0 | 36 | if (bitmap.isOpaque()) { |
michael@0 | 37 | mBitmap->append(" opaque"); |
michael@0 | 38 | } else { |
michael@0 | 39 | mBitmap->append(" not-opaque"); |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | if (bitmap.isImmutable()) { |
michael@0 | 43 | mBitmap->append(" immutable"); |
michael@0 | 44 | } else { |
michael@0 | 45 | mBitmap->append(" not-immutable"); |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | if (bitmap.isVolatile()) { |
michael@0 | 49 | mBitmap->append(" volatile"); |
michael@0 | 50 | } else { |
michael@0 | 51 | mBitmap->append(" not-volatile"); |
michael@0 | 52 | } |
michael@0 | 53 | |
michael@0 | 54 | mBitmap->append(" genID: "); |
michael@0 | 55 | mBitmap->appendS32(bitmap.getGenerationID()); |
michael@0 | 56 | |
michael@0 | 57 | return mBitmap; |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | SkString* SkObjectParser::BoolToString(bool doAA) { |
michael@0 | 61 | SkString* mBool = new SkString("Bool doAA: "); |
michael@0 | 62 | if (doAA) { |
michael@0 | 63 | mBool->append("True"); |
michael@0 | 64 | } else { |
michael@0 | 65 | mBool->append("False"); |
michael@0 | 66 | } |
michael@0 | 67 | return mBool; |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | SkString* SkObjectParser::CustomTextToString(const char* text) { |
michael@0 | 71 | SkString* mText = new SkString(text); |
michael@0 | 72 | return mText; |
michael@0 | 73 | } |
michael@0 | 74 | |
michael@0 | 75 | SkString* SkObjectParser::IntToString(int x, const char* text) { |
michael@0 | 76 | SkString* mInt = new SkString(text); |
michael@0 | 77 | mInt->append(" "); |
michael@0 | 78 | mInt->appendScalar(SkIntToScalar(x)); |
michael@0 | 79 | return mInt; |
michael@0 | 80 | } |
michael@0 | 81 | |
michael@0 | 82 | SkString* SkObjectParser::IRectToString(const SkIRect& rect) { |
michael@0 | 83 | SkString* mRect = new SkString("SkIRect: "); |
michael@0 | 84 | mRect->append("L: "); |
michael@0 | 85 | mRect->appendS32(rect.left()); |
michael@0 | 86 | mRect->append(", T: "); |
michael@0 | 87 | mRect->appendS32(rect.top()); |
michael@0 | 88 | mRect->append(", R: "); |
michael@0 | 89 | mRect->appendS32(rect.right()); |
michael@0 | 90 | mRect->append(", B: "); |
michael@0 | 91 | mRect->appendS32(rect.bottom()); |
michael@0 | 92 | return mRect; |
michael@0 | 93 | } |
michael@0 | 94 | |
michael@0 | 95 | SkString* SkObjectParser::MatrixToString(const SkMatrix& matrix) { |
michael@0 | 96 | SkString* str = new SkString("SkMatrix: "); |
michael@0 | 97 | #ifndef SK_IGNORE_TO_STRING |
michael@0 | 98 | matrix.toString(str); |
michael@0 | 99 | #endif |
michael@0 | 100 | return str; |
michael@0 | 101 | } |
michael@0 | 102 | |
michael@0 | 103 | SkString* SkObjectParser::PaintToString(const SkPaint& paint) { |
michael@0 | 104 | SkString* str = new SkString; |
michael@0 | 105 | #ifndef SK_IGNORE_TO_STRING |
michael@0 | 106 | paint.toString(str); |
michael@0 | 107 | #endif |
michael@0 | 108 | return str; |
michael@0 | 109 | } |
michael@0 | 110 | |
michael@0 | 111 | SkString* SkObjectParser::PathToString(const SkPath& path) { |
michael@0 | 112 | SkString* mPath = new SkString("Path ("); |
michael@0 | 113 | |
michael@0 | 114 | static const char* gFillStrings[] = { |
michael@0 | 115 | "Winding", "EvenOdd", "InverseWinding", "InverseEvenOdd" |
michael@0 | 116 | }; |
michael@0 | 117 | |
michael@0 | 118 | mPath->append(gFillStrings[path.getFillType()]); |
michael@0 | 119 | mPath->append(", "); |
michael@0 | 120 | |
michael@0 | 121 | static const char* gConvexityStrings[] = { |
michael@0 | 122 | "Unknown", "Convex", "Concave" |
michael@0 | 123 | }; |
michael@0 | 124 | SkASSERT(SkPath::kConcave_Convexity == 2); |
michael@0 | 125 | |
michael@0 | 126 | mPath->append(gConvexityStrings[path.getConvexity()]); |
michael@0 | 127 | mPath->append(", "); |
michael@0 | 128 | |
michael@0 | 129 | if (path.isRect(NULL)) { |
michael@0 | 130 | mPath->append("isRect, "); |
michael@0 | 131 | } else { |
michael@0 | 132 | mPath->append("isNotRect, "); |
michael@0 | 133 | } |
michael@0 | 134 | |
michael@0 | 135 | mPath->appendS32(path.countVerbs()); |
michael@0 | 136 | mPath->append("V, "); |
michael@0 | 137 | mPath->appendS32(path.countPoints()); |
michael@0 | 138 | mPath->append("P): "); |
michael@0 | 139 | |
michael@0 | 140 | static const char* gVerbStrings[] = { |
michael@0 | 141 | "Move", "Line", "Quad", "Conic", "Cubic", "Close", "Done" |
michael@0 | 142 | }; |
michael@0 | 143 | static const int gPtsPerVerb[] = { 1, 1, 2, 2, 3, 0, 0 }; |
michael@0 | 144 | static const int gPtOffsetPerVerb[] = { 0, 1, 1, 1, 1, 0, 0 }; |
michael@0 | 145 | SkASSERT(SkPath::kDone_Verb == 6); |
michael@0 | 146 | |
michael@0 | 147 | SkPath::Iter iter(const_cast<SkPath&>(path), false); |
michael@0 | 148 | SkPath::Verb verb; |
michael@0 | 149 | SkPoint points[4]; |
michael@0 | 150 | |
michael@0 | 151 | for(verb = iter.next(points, false); |
michael@0 | 152 | verb != SkPath::kDone_Verb; |
michael@0 | 153 | verb = iter.next(points, false)) { |
michael@0 | 154 | |
michael@0 | 155 | mPath->append(gVerbStrings[verb]); |
michael@0 | 156 | mPath->append(" "); |
michael@0 | 157 | |
michael@0 | 158 | for (int i = 0; i < gPtsPerVerb[verb]; ++i) { |
michael@0 | 159 | mPath->append("("); |
michael@0 | 160 | mPath->appendScalar(points[gPtOffsetPerVerb[verb]+i].fX); |
michael@0 | 161 | mPath->append(", "); |
michael@0 | 162 | mPath->appendScalar(points[gPtOffsetPerVerb[verb]+i].fY); |
michael@0 | 163 | mPath->append(")"); |
michael@0 | 164 | } |
michael@0 | 165 | |
michael@0 | 166 | if (SkPath::kConic_Verb == verb) { |
michael@0 | 167 | mPath->append("("); |
michael@0 | 168 | mPath->appendScalar(iter.conicWeight()); |
michael@0 | 169 | mPath->append(")"); |
michael@0 | 170 | } |
michael@0 | 171 | |
michael@0 | 172 | mPath->append(" "); |
michael@0 | 173 | } |
michael@0 | 174 | |
michael@0 | 175 | SkString* boundStr = SkObjectParser::RectToString(path.getBounds(), " Bound: "); |
michael@0 | 176 | |
michael@0 | 177 | if (NULL != boundStr) { |
michael@0 | 178 | mPath->append(*boundStr); |
michael@0 | 179 | SkDELETE(boundStr); |
michael@0 | 180 | } |
michael@0 | 181 | |
michael@0 | 182 | return mPath; |
michael@0 | 183 | } |
michael@0 | 184 | |
michael@0 | 185 | SkString* SkObjectParser::PointsToString(const SkPoint pts[], size_t count) { |
michael@0 | 186 | SkString* mPoints = new SkString("SkPoints pts[]: "); |
michael@0 | 187 | for (unsigned int i = 0; i < count; i++) { |
michael@0 | 188 | mPoints->append("("); |
michael@0 | 189 | mPoints->appendScalar(pts[i].fX); |
michael@0 | 190 | mPoints->append(","); |
michael@0 | 191 | mPoints->appendScalar(pts[i].fY); |
michael@0 | 192 | mPoints->append(")"); |
michael@0 | 193 | } |
michael@0 | 194 | return mPoints; |
michael@0 | 195 | } |
michael@0 | 196 | |
michael@0 | 197 | SkString* SkObjectParser::PointModeToString(SkCanvas::PointMode mode) { |
michael@0 | 198 | SkString* mMode = new SkString("SkCanvas::PointMode: "); |
michael@0 | 199 | if (mode == SkCanvas::kPoints_PointMode) { |
michael@0 | 200 | mMode->append("kPoints_PointMode"); |
michael@0 | 201 | } else if (mode == SkCanvas::kLines_PointMode) { |
michael@0 | 202 | mMode->append("kLines_Mode"); |
michael@0 | 203 | } else if (mode == SkCanvas::kPolygon_PointMode) { |
michael@0 | 204 | mMode->append("kPolygon_PointMode"); |
michael@0 | 205 | } |
michael@0 | 206 | return mMode; |
michael@0 | 207 | } |
michael@0 | 208 | |
michael@0 | 209 | SkString* SkObjectParser::RectToString(const SkRect& rect, const char* title) { |
michael@0 | 210 | |
michael@0 | 211 | SkString* mRect = new SkString; |
michael@0 | 212 | |
michael@0 | 213 | if (NULL == title) { |
michael@0 | 214 | mRect->append("SkRect: "); |
michael@0 | 215 | } else { |
michael@0 | 216 | mRect->append(title); |
michael@0 | 217 | } |
michael@0 | 218 | mRect->append("("); |
michael@0 | 219 | mRect->appendScalar(rect.left()); |
michael@0 | 220 | mRect->append(", "); |
michael@0 | 221 | mRect->appendScalar(rect.top()); |
michael@0 | 222 | mRect->append(", "); |
michael@0 | 223 | mRect->appendScalar(rect.right()); |
michael@0 | 224 | mRect->append(", "); |
michael@0 | 225 | mRect->appendScalar(rect.bottom()); |
michael@0 | 226 | mRect->append(")"); |
michael@0 | 227 | return mRect; |
michael@0 | 228 | } |
michael@0 | 229 | |
michael@0 | 230 | SkString* SkObjectParser::RRectToString(const SkRRect& rrect, const char* title) { |
michael@0 | 231 | |
michael@0 | 232 | SkString* mRRect = new SkString; |
michael@0 | 233 | |
michael@0 | 234 | if (NULL == title) { |
michael@0 | 235 | mRRect->append("SkRRect ("); |
michael@0 | 236 | if (rrect.isEmpty()) { |
michael@0 | 237 | mRRect->append("empty"); |
michael@0 | 238 | } else if (rrect.isRect()) { |
michael@0 | 239 | mRRect->append("rect"); |
michael@0 | 240 | } else if (rrect.isOval()) { |
michael@0 | 241 | mRRect->append("oval"); |
michael@0 | 242 | } else if (rrect.isSimple()) { |
michael@0 | 243 | mRRect->append("simple"); |
michael@0 | 244 | } else { |
michael@0 | 245 | SkASSERT(rrect.isComplex()); |
michael@0 | 246 | mRRect->append("complex"); |
michael@0 | 247 | } |
michael@0 | 248 | mRRect->append("): "); |
michael@0 | 249 | } else { |
michael@0 | 250 | mRRect->append(title); |
michael@0 | 251 | } |
michael@0 | 252 | mRRect->append("("); |
michael@0 | 253 | mRRect->appendScalar(rrect.rect().left()); |
michael@0 | 254 | mRRect->append(", "); |
michael@0 | 255 | mRRect->appendScalar(rrect.rect().top()); |
michael@0 | 256 | mRRect->append(", "); |
michael@0 | 257 | mRRect->appendScalar(rrect.rect().right()); |
michael@0 | 258 | mRRect->append(", "); |
michael@0 | 259 | mRRect->appendScalar(rrect.rect().bottom()); |
michael@0 | 260 | mRRect->append(") radii: ("); |
michael@0 | 261 | for (int i = 0; i < 4; ++i) { |
michael@0 | 262 | const SkVector& radii = rrect.radii((SkRRect::Corner) i); |
michael@0 | 263 | mRRect->appendScalar(radii.fX); |
michael@0 | 264 | mRRect->append(", "); |
michael@0 | 265 | mRRect->appendScalar(radii.fY); |
michael@0 | 266 | if (i < 3) { |
michael@0 | 267 | mRRect->append(", "); |
michael@0 | 268 | } |
michael@0 | 269 | } |
michael@0 | 270 | mRRect->append(")"); |
michael@0 | 271 | return mRRect; |
michael@0 | 272 | } |
michael@0 | 273 | |
michael@0 | 274 | SkString* SkObjectParser::RegionOpToString(SkRegion::Op op) { |
michael@0 | 275 | SkString* mOp = new SkString("SkRegion::Op: "); |
michael@0 | 276 | if (op == SkRegion::kDifference_Op) { |
michael@0 | 277 | mOp->append("kDifference_Op"); |
michael@0 | 278 | } else if (op == SkRegion::kIntersect_Op) { |
michael@0 | 279 | mOp->append("kIntersect_Op"); |
michael@0 | 280 | } else if (op == SkRegion::kUnion_Op) { |
michael@0 | 281 | mOp->append("kUnion_Op"); |
michael@0 | 282 | } else if (op == SkRegion::kXOR_Op) { |
michael@0 | 283 | mOp->append("kXOR_Op"); |
michael@0 | 284 | } else if (op == SkRegion::kReverseDifference_Op) { |
michael@0 | 285 | mOp->append("kReverseDifference_Op"); |
michael@0 | 286 | } else if (op == SkRegion::kReplace_Op) { |
michael@0 | 287 | mOp->append("kReplace_Op"); |
michael@0 | 288 | } else { |
michael@0 | 289 | mOp->append("Unknown Type"); |
michael@0 | 290 | } |
michael@0 | 291 | return mOp; |
michael@0 | 292 | } |
michael@0 | 293 | |
michael@0 | 294 | SkString* SkObjectParser::RegionToString(const SkRegion& region) { |
michael@0 | 295 | SkString* mRegion = new SkString("SkRegion: Data unavailable."); |
michael@0 | 296 | return mRegion; |
michael@0 | 297 | } |
michael@0 | 298 | |
michael@0 | 299 | SkString* SkObjectParser::SaveFlagsToString(SkCanvas::SaveFlags flags) { |
michael@0 | 300 | SkString* mFlags = new SkString("SkCanvas::SaveFlags: "); |
michael@0 | 301 | if (flags & SkCanvas::kMatrix_SaveFlag) { |
michael@0 | 302 | mFlags->append("kMatrix_SaveFlag "); |
michael@0 | 303 | } |
michael@0 | 304 | if (flags & SkCanvas::kClip_SaveFlag) { |
michael@0 | 305 | mFlags->append("kClip_SaveFlag "); |
michael@0 | 306 | } |
michael@0 | 307 | if (flags & SkCanvas::kHasAlphaLayer_SaveFlag) { |
michael@0 | 308 | mFlags->append("kHasAlphaLayer_SaveFlag "); |
michael@0 | 309 | } |
michael@0 | 310 | if (flags & SkCanvas::kFullColorLayer_SaveFlag) { |
michael@0 | 311 | mFlags->append("kFullColorLayer_SaveFlag "); |
michael@0 | 312 | } |
michael@0 | 313 | if (flags & SkCanvas::kClipToLayer_SaveFlag) { |
michael@0 | 314 | mFlags->append("kClipToLayer_SaveFlag "); |
michael@0 | 315 | } |
michael@0 | 316 | return mFlags; |
michael@0 | 317 | } |
michael@0 | 318 | |
michael@0 | 319 | SkString* SkObjectParser::ScalarToString(SkScalar x, const char* text) { |
michael@0 | 320 | SkString* mScalar = new SkString(text); |
michael@0 | 321 | mScalar->append(" "); |
michael@0 | 322 | mScalar->appendScalar(x); |
michael@0 | 323 | return mScalar; |
michael@0 | 324 | } |
michael@0 | 325 | |
michael@0 | 326 | SkString* SkObjectParser::TextToString(const void* text, size_t byteLength, |
michael@0 | 327 | SkPaint::TextEncoding encoding) { |
michael@0 | 328 | |
michael@0 | 329 | SkString* decodedText = new SkString(); |
michael@0 | 330 | switch (encoding) { |
michael@0 | 331 | case SkPaint::kUTF8_TextEncoding: { |
michael@0 | 332 | decodedText->append("UTF-8: "); |
michael@0 | 333 | decodedText->append((const char*)text, byteLength); |
michael@0 | 334 | break; |
michael@0 | 335 | } |
michael@0 | 336 | case SkPaint::kUTF16_TextEncoding: { |
michael@0 | 337 | decodedText->append("UTF-16: "); |
michael@0 | 338 | size_t sizeNeeded = SkUTF16_ToUTF8((uint16_t*)text, |
michael@0 | 339 | SkToS32(byteLength / 2), |
michael@0 | 340 | NULL); |
michael@0 | 341 | SkAutoSTMalloc<0x100, char> utf8(sizeNeeded); |
michael@0 | 342 | SkUTF16_ToUTF8((uint16_t*)text, SkToS32(byteLength / 2), utf8); |
michael@0 | 343 | decodedText->append(utf8, sizeNeeded); |
michael@0 | 344 | break; |
michael@0 | 345 | } |
michael@0 | 346 | case SkPaint::kUTF32_TextEncoding: { |
michael@0 | 347 | decodedText->append("UTF-32: "); |
michael@0 | 348 | const SkUnichar* begin = (const SkUnichar*)text; |
michael@0 | 349 | const SkUnichar* end = (const SkUnichar*)((const char*)text + byteLength); |
michael@0 | 350 | for (const SkUnichar* unichar = begin; unichar < end; ++unichar) { |
michael@0 | 351 | decodedText->appendUnichar(*unichar); |
michael@0 | 352 | } |
michael@0 | 353 | break; |
michael@0 | 354 | } |
michael@0 | 355 | case SkPaint::kGlyphID_TextEncoding: { |
michael@0 | 356 | decodedText->append("GlyphID: "); |
michael@0 | 357 | const uint16_t* begin = (const uint16_t*)text; |
michael@0 | 358 | const uint16_t* end = (const uint16_t*)((const char*)text + byteLength); |
michael@0 | 359 | for (const uint16_t* glyph = begin; glyph < end; ++glyph) { |
michael@0 | 360 | decodedText->append("0x"); |
michael@0 | 361 | decodedText->appendHex(*glyph); |
michael@0 | 362 | decodedText->append(" "); |
michael@0 | 363 | } |
michael@0 | 364 | break; |
michael@0 | 365 | } |
michael@0 | 366 | default: |
michael@0 | 367 | decodedText->append("Unknown text encoding."); |
michael@0 | 368 | break; |
michael@0 | 369 | } |
michael@0 | 370 | |
michael@0 | 371 | return decodedText; |
michael@0 | 372 | } |