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 "SkSVGGradient.h" |
michael@0 | 11 | #include "SkSVGParser.h" |
michael@0 | 12 | #include "SkSVGStop.h" |
michael@0 | 13 | |
michael@0 | 14 | SkSVGGradient::SkSVGGradient() { |
michael@0 | 15 | } |
michael@0 | 16 | |
michael@0 | 17 | SkSVGElement* SkSVGGradient::getGradient() { |
michael@0 | 18 | return this; |
michael@0 | 19 | } |
michael@0 | 20 | |
michael@0 | 21 | bool SkSVGGradient::isDef() { |
michael@0 | 22 | return true; |
michael@0 | 23 | } |
michael@0 | 24 | |
michael@0 | 25 | bool SkSVGGradient::isNotDef() { |
michael@0 | 26 | return false; |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | void SkSVGGradient::translate(SkSVGParser& parser, bool defState) { |
michael@0 | 30 | INHERITED::translate(parser, defState); |
michael@0 | 31 | // !!! no support for 'objectBoundingBox' yet |
michael@0 | 32 | bool first = true; |
michael@0 | 33 | bool addedFirst = false; |
michael@0 | 34 | bool addedLast = false; |
michael@0 | 35 | SkString offsets("["); |
michael@0 | 36 | SkString* lastOffset = NULL; |
michael@0 | 37 | for (SkSVGElement** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) { |
michael@0 | 38 | SkASSERT((*ptr)->getType() == SkSVGType_Stop); |
michael@0 | 39 | SkSVGStop* stop = (SkSVGStop*) *ptr; |
michael@0 | 40 | if (first && stop->f_offset.equals("0") == false) { |
michael@0 | 41 | addedFirst = true; |
michael@0 | 42 | offsets.append("0,"); |
michael@0 | 43 | } |
michael@0 | 44 | SkString* thisOffset = &stop->f_offset; |
michael@0 | 45 | if (lastOffset && thisOffset->equals(*lastOffset)) { |
michael@0 | 46 | if (thisOffset->equals("1")) { |
michael@0 | 47 | offsets.remove(offsets.size() - 2, 2); |
michael@0 | 48 | offsets.append(".999,"); |
michael@0 | 49 | } else { |
michael@0 | 50 | SkASSERT(0); // !!! need to write this case |
michael@0 | 51 | } |
michael@0 | 52 | } |
michael@0 | 53 | offsets.append(*thisOffset); |
michael@0 | 54 | if (ptr == fChildren.end() - 1) { // last |
michael@0 | 55 | if (stop->f_offset.equals("1") == false) { |
michael@0 | 56 | offsets.append(",1"); |
michael@0 | 57 | addedLast = true; |
michael@0 | 58 | } |
michael@0 | 59 | } else |
michael@0 | 60 | offsets.appendUnichar(','); |
michael@0 | 61 | first = false; |
michael@0 | 62 | lastOffset = thisOffset; |
michael@0 | 63 | } |
michael@0 | 64 | offsets.appendUnichar(']'); |
michael@0 | 65 | parser._addAttribute("offsets", offsets); |
michael@0 | 66 | if (addedFirst) |
michael@0 | 67 | parser.translate(*fChildren.begin(), defState); |
michael@0 | 68 | for (SkSVGElement** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) |
michael@0 | 69 | parser.translate(*ptr, defState); |
michael@0 | 70 | if (addedLast) |
michael@0 | 71 | parser.translate(*(fChildren.end() - 1), defState); |
michael@0 | 72 | } |
michael@0 | 73 | |
michael@0 | 74 | void SkSVGGradient::translateGradientUnits(SkString& units) { |
michael@0 | 75 | // !!! no support for 'objectBoundingBox' yet |
michael@0 | 76 | SkASSERT(strcmp(units.c_str(), "userSpaceOnUse") == 0); |
michael@0 | 77 | } |
michael@0 | 78 | |
michael@0 | 79 | void SkSVGGradient::write(SkSVGParser& parser, SkString& baseColor) { |
michael@0 | 80 | if (baseColor.c_str()[0] != '#') |
michael@0 | 81 | return; |
michael@0 | 82 | SkSVGPaint* saveHead = parser.fHead; |
michael@0 | 83 | parser.fHead = &fPaintState; |
michael@0 | 84 | parser.fSuppressPaint = true; |
michael@0 | 85 | SkString originalID(f_id); |
michael@0 | 86 | f_id.set("mask"); // write out gradient named given name + color (less initial #) |
michael@0 | 87 | f_id.append(baseColor.c_str() + 1); |
michael@0 | 88 | SkString originalColors; |
michael@0 | 89 | for (SkSVGElement** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) { |
michael@0 | 90 | SkSVGStop* colorElement = (SkSVGStop*) *ptr; |
michael@0 | 91 | SkString& color = colorElement->fPaintState.f_stopColor; |
michael@0 | 92 | originalColors.append(color); |
michael@0 | 93 | originalColors.appendUnichar(','); |
michael@0 | 94 | SkASSERT(color.c_str()[0] == '#'); |
michael@0 | 95 | SkString replacement; |
michael@0 | 96 | replacement.set("0x"); |
michael@0 | 97 | replacement.append(color.c_str() + 1, 2); // add stop colors using given color, turning existing stop color into alpha |
michael@0 | 98 | SkASSERT(baseColor.c_str()[0] == '#'); |
michael@0 | 99 | SkASSERT(baseColor.size() == 7); |
michael@0 | 100 | replacement.append(baseColor.c_str() + 1); |
michael@0 | 101 | color.set(replacement); |
michael@0 | 102 | } |
michael@0 | 103 | translate(parser, true); |
michael@0 | 104 | const char* originalPtr = originalColors.c_str(); // restore original gradient values |
michael@0 | 105 | for (SkSVGElement** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) { |
michael@0 | 106 | SkSVGStop* color = (SkSVGStop*) *ptr; |
michael@0 | 107 | const char* originalEnd = strchr(originalPtr, ','); |
michael@0 | 108 | color->fPaintState.f_stopColor.set(originalPtr, originalEnd - originalPtr); |
michael@0 | 109 | originalPtr = originalEnd + 1; |
michael@0 | 110 | } |
michael@0 | 111 | f_id.set(originalID); |
michael@0 | 112 | parser.fSuppressPaint = false; |
michael@0 | 113 | parser.fHead = saveHead; |
michael@0 | 114 | } |