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 "SkDiscretePathEffect.h" |
michael@0 | 11 | #include "SkReadBuffer.h" |
michael@0 | 12 | #include "SkWriteBuffer.h" |
michael@0 | 13 | #include "SkPathMeasure.h" |
michael@0 | 14 | #include "SkRandom.h" |
michael@0 | 15 | |
michael@0 | 16 | static void Perterb(SkPoint* p, const SkVector& tangent, SkScalar scale) { |
michael@0 | 17 | SkVector normal = tangent; |
michael@0 | 18 | normal.rotateCCW(); |
michael@0 | 19 | normal.setLength(scale); |
michael@0 | 20 | *p += normal; |
michael@0 | 21 | } |
michael@0 | 22 | |
michael@0 | 23 | |
michael@0 | 24 | SkDiscretePathEffect::SkDiscretePathEffect(SkScalar segLength, SkScalar deviation) |
michael@0 | 25 | : fSegLength(segLength), fPerterb(deviation) |
michael@0 | 26 | { |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | bool SkDiscretePathEffect::filterPath(SkPath* dst, const SkPath& src, |
michael@0 | 30 | SkStrokeRec* rec, const SkRect*) const { |
michael@0 | 31 | bool doFill = rec->isFillStyle(); |
michael@0 | 32 | |
michael@0 | 33 | SkPathMeasure meas(src, doFill); |
michael@0 | 34 | uint32_t seed = SkScalarRoundToInt(meas.getLength()); |
michael@0 | 35 | SkLCGRandom rand(seed ^ ((seed << 16) | (seed >> 16))); |
michael@0 | 36 | SkScalar scale = fPerterb; |
michael@0 | 37 | SkPoint p; |
michael@0 | 38 | SkVector v; |
michael@0 | 39 | |
michael@0 | 40 | do { |
michael@0 | 41 | SkScalar length = meas.getLength(); |
michael@0 | 42 | |
michael@0 | 43 | if (fSegLength * (2 + doFill) > length) { |
michael@0 | 44 | meas.getSegment(0, length, dst, true); // to short for us to mangle |
michael@0 | 45 | } else { |
michael@0 | 46 | int n = SkScalarRoundToInt(length / fSegLength); |
michael@0 | 47 | SkScalar delta = length / n; |
michael@0 | 48 | SkScalar distance = 0; |
michael@0 | 49 | |
michael@0 | 50 | if (meas.isClosed()) { |
michael@0 | 51 | n -= 1; |
michael@0 | 52 | distance += delta/2; |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | if (meas.getPosTan(distance, &p, &v)) { |
michael@0 | 56 | Perterb(&p, v, SkScalarMul(rand.nextSScalar1(), scale)); |
michael@0 | 57 | dst->moveTo(p); |
michael@0 | 58 | } |
michael@0 | 59 | while (--n >= 0) { |
michael@0 | 60 | distance += delta; |
michael@0 | 61 | if (meas.getPosTan(distance, &p, &v)) { |
michael@0 | 62 | Perterb(&p, v, SkScalarMul(rand.nextSScalar1(), scale)); |
michael@0 | 63 | dst->lineTo(p); |
michael@0 | 64 | } |
michael@0 | 65 | } |
michael@0 | 66 | if (meas.isClosed()) { |
michael@0 | 67 | dst->close(); |
michael@0 | 68 | } |
michael@0 | 69 | } |
michael@0 | 70 | } while (meas.nextContour()); |
michael@0 | 71 | return true; |
michael@0 | 72 | } |
michael@0 | 73 | |
michael@0 | 74 | void SkDiscretePathEffect::flatten(SkWriteBuffer& buffer) const { |
michael@0 | 75 | this->INHERITED::flatten(buffer); |
michael@0 | 76 | buffer.writeScalar(fSegLength); |
michael@0 | 77 | buffer.writeScalar(fPerterb); |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | SkDiscretePathEffect::SkDiscretePathEffect(SkReadBuffer& buffer) { |
michael@0 | 81 | fSegLength = buffer.readScalar(); |
michael@0 | 82 | fPerterb = buffer.readScalar(); |
michael@0 | 83 | } |