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 2011 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 | #include "SkParsePaint.h" |
michael@0 | 9 | #include "SkTSearch.h" |
michael@0 | 10 | #include "SkParse.h" |
michael@0 | 11 | #include "SkImageDecoder.h" |
michael@0 | 12 | #include "SkGradientShader.h" |
michael@0 | 13 | |
michael@0 | 14 | static SkShader* inflate_shader(const SkDOM& dom, const SkDOM::Node* node) |
michael@0 | 15 | { |
michael@0 | 16 | if ((node = dom.getFirstChild(node, "shader")) == NULL) |
michael@0 | 17 | return NULL; |
michael@0 | 18 | |
michael@0 | 19 | const char* str; |
michael@0 | 20 | |
michael@0 | 21 | if (dom.hasAttr(node, "type", "linear-gradient")) |
michael@0 | 22 | { |
michael@0 | 23 | SkColor colors[2]; |
michael@0 | 24 | SkPoint pts[2]; |
michael@0 | 25 | |
michael@0 | 26 | colors[0] = colors[1] = SK_ColorBLACK; // need to initialized the alpha to opaque, since FindColor doesn't set it |
michael@0 | 27 | if ((str = dom.findAttr(node, "c0")) != NULL && |
michael@0 | 28 | SkParse::FindColor(str, &colors[0]) && |
michael@0 | 29 | (str = dom.findAttr(node, "c1")) != NULL && |
michael@0 | 30 | SkParse::FindColor(str, &colors[1]) && |
michael@0 | 31 | dom.findScalars(node, "p0", &pts[0].fX, 2) && |
michael@0 | 32 | dom.findScalars(node, "p1", &pts[1].fX, 2)) |
michael@0 | 33 | { |
michael@0 | 34 | SkShader::TileMode mode = SkShader::kClamp_TileMode; |
michael@0 | 35 | int index; |
michael@0 | 36 | |
michael@0 | 37 | if ((index = dom.findList(node, "tile-mode", "clamp,repeat,mirror")) >= 0) |
michael@0 | 38 | mode = (SkShader::TileMode)index; |
michael@0 | 39 | return SkGradientShader::CreateLinear(pts, colors, NULL, 2, mode); |
michael@0 | 40 | } |
michael@0 | 41 | } |
michael@0 | 42 | else if (dom.hasAttr(node, "type", "bitmap")) |
michael@0 | 43 | { |
michael@0 | 44 | if ((str = dom.findAttr(node, "src")) == NULL) |
michael@0 | 45 | return NULL; |
michael@0 | 46 | |
michael@0 | 47 | SkBitmap bm; |
michael@0 | 48 | |
michael@0 | 49 | if (SkImageDecoder::DecodeFile(str, &bm)) |
michael@0 | 50 | { |
michael@0 | 51 | SkShader::TileMode mode = SkShader::kRepeat_TileMode; |
michael@0 | 52 | int index; |
michael@0 | 53 | |
michael@0 | 54 | if ((index = dom.findList(node, "tile-mode", "clamp,repeat,mirror")) >= 0) |
michael@0 | 55 | mode = (SkShader::TileMode)index; |
michael@0 | 56 | |
michael@0 | 57 | return SkShader::CreateBitmapShader(bm, mode, mode); |
michael@0 | 58 | } |
michael@0 | 59 | } |
michael@0 | 60 | return NULL; |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | void SkPaint_Inflate(SkPaint* paint, const SkDOM& dom, const SkDOM::Node* node) |
michael@0 | 64 | { |
michael@0 | 65 | SkASSERT(paint); |
michael@0 | 66 | SkASSERT(&dom); |
michael@0 | 67 | SkASSERT(node); |
michael@0 | 68 | |
michael@0 | 69 | SkScalar x; |
michael@0 | 70 | |
michael@0 | 71 | if (dom.findScalar(node, "stroke-width", &x)) |
michael@0 | 72 | paint->setStrokeWidth(x); |
michael@0 | 73 | if (dom.findScalar(node, "text-size", &x)) |
michael@0 | 74 | paint->setTextSize(x); |
michael@0 | 75 | |
michael@0 | 76 | bool b; |
michael@0 | 77 | |
michael@0 | 78 | SkASSERT("legacy: use is-stroke" && !dom.findBool(node, "is-frame", &b)); |
michael@0 | 79 | |
michael@0 | 80 | if (dom.findBool(node, "is-stroke", &b)) |
michael@0 | 81 | paint->setStyle(b ? SkPaint::kStroke_Style : SkPaint::kFill_Style); |
michael@0 | 82 | if (dom.findBool(node, "is-antialias", &b)) |
michael@0 | 83 | paint->setAntiAlias(b); |
michael@0 | 84 | if (dom.findBool(node, "is-lineartext", &b)) |
michael@0 | 85 | paint->setLinearText(b); |
michael@0 | 86 | |
michael@0 | 87 | const char* str = dom.findAttr(node, "color"); |
michael@0 | 88 | if (str) |
michael@0 | 89 | { |
michael@0 | 90 | SkColor c = paint->getColor(); |
michael@0 | 91 | if (SkParse::FindColor(str, &c)) |
michael@0 | 92 | paint->setColor(c); |
michael@0 | 93 | } |
michael@0 | 94 | |
michael@0 | 95 | // do this AFTER parsing for the color |
michael@0 | 96 | if (dom.findScalar(node, "opacity", &x)) |
michael@0 | 97 | { |
michael@0 | 98 | x = SkMaxScalar(0, SkMinScalar(x, SK_Scalar1)); |
michael@0 | 99 | paint->setAlpha(SkScalarRoundToInt(x * 255)); |
michael@0 | 100 | } |
michael@0 | 101 | |
michael@0 | 102 | int index = dom.findList(node, "text-anchor", "left,center,right"); |
michael@0 | 103 | if (index >= 0) |
michael@0 | 104 | paint->setTextAlign((SkPaint::Align)index); |
michael@0 | 105 | |
michael@0 | 106 | SkShader* shader = inflate_shader(dom, node); |
michael@0 | 107 | if (shader) |
michael@0 | 108 | paint->setShader(shader)->unref(); |
michael@0 | 109 | } |