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 "SkCornerPathEffect.h" |
michael@0 | 11 | #include "SkPath.h" |
michael@0 | 12 | #include "SkPoint.h" |
michael@0 | 13 | #include "SkReadBuffer.h" |
michael@0 | 14 | #include "SkWriteBuffer.h" |
michael@0 | 15 | |
michael@0 | 16 | SkCornerPathEffect::SkCornerPathEffect(SkScalar radius) : fRadius(radius) {} |
michael@0 | 17 | SkCornerPathEffect::~SkCornerPathEffect() {} |
michael@0 | 18 | |
michael@0 | 19 | static bool ComputeStep(const SkPoint& a, const SkPoint& b, SkScalar radius, |
michael@0 | 20 | SkPoint* step) { |
michael@0 | 21 | SkScalar dist = SkPoint::Distance(a, b); |
michael@0 | 22 | |
michael@0 | 23 | step->set(b.fX - a.fX, b.fY - a.fY); |
michael@0 | 24 | |
michael@0 | 25 | if (dist <= radius * 2) { |
michael@0 | 26 | step->scale(SK_ScalarHalf); |
michael@0 | 27 | return false; |
michael@0 | 28 | } else { |
michael@0 | 29 | step->scale(SkScalarDiv(radius, dist)); |
michael@0 | 30 | return true; |
michael@0 | 31 | } |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | bool SkCornerPathEffect::filterPath(SkPath* dst, const SkPath& src, |
michael@0 | 35 | SkStrokeRec*, const SkRect*) const { |
michael@0 | 36 | if (0 == fRadius) { |
michael@0 | 37 | return false; |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | SkPath::Iter iter(src, false); |
michael@0 | 41 | SkPath::Verb verb, prevVerb = (SkPath::Verb)-1; |
michael@0 | 42 | SkPoint pts[4]; |
michael@0 | 43 | |
michael@0 | 44 | bool closed; |
michael@0 | 45 | SkPoint moveTo, lastCorner; |
michael@0 | 46 | SkVector firstStep, step; |
michael@0 | 47 | bool prevIsValid = true; |
michael@0 | 48 | |
michael@0 | 49 | // to avoid warnings |
michael@0 | 50 | moveTo.set(0, 0); |
michael@0 | 51 | firstStep.set(0, 0); |
michael@0 | 52 | lastCorner.set(0, 0); |
michael@0 | 53 | |
michael@0 | 54 | for (;;) { |
michael@0 | 55 | switch (verb = iter.next(pts, false)) { |
michael@0 | 56 | case SkPath::kMove_Verb: |
michael@0 | 57 | // close out the previous (open) contour |
michael@0 | 58 | if (SkPath::kLine_Verb == prevVerb) { |
michael@0 | 59 | dst->lineTo(lastCorner); |
michael@0 | 60 | } |
michael@0 | 61 | closed = iter.isClosedContour(); |
michael@0 | 62 | if (closed) { |
michael@0 | 63 | moveTo = pts[0]; |
michael@0 | 64 | prevIsValid = false; |
michael@0 | 65 | } else { |
michael@0 | 66 | dst->moveTo(pts[0]); |
michael@0 | 67 | prevIsValid = true; |
michael@0 | 68 | } |
michael@0 | 69 | break; |
michael@0 | 70 | case SkPath::kLine_Verb: { |
michael@0 | 71 | bool drawSegment = ComputeStep(pts[0], pts[1], fRadius, &step); |
michael@0 | 72 | // prev corner |
michael@0 | 73 | if (!prevIsValid) { |
michael@0 | 74 | dst->moveTo(moveTo + step); |
michael@0 | 75 | prevIsValid = true; |
michael@0 | 76 | } else { |
michael@0 | 77 | dst->quadTo(pts[0].fX, pts[0].fY, pts[0].fX + step.fX, |
michael@0 | 78 | pts[0].fY + step.fY); |
michael@0 | 79 | } |
michael@0 | 80 | if (drawSegment) { |
michael@0 | 81 | dst->lineTo(pts[1].fX - step.fX, pts[1].fY - step.fY); |
michael@0 | 82 | } |
michael@0 | 83 | lastCorner = pts[1]; |
michael@0 | 84 | prevIsValid = true; |
michael@0 | 85 | break; |
michael@0 | 86 | } |
michael@0 | 87 | case SkPath::kQuad_Verb: |
michael@0 | 88 | // TBD - just replicate the curve for now |
michael@0 | 89 | if (!prevIsValid) { |
michael@0 | 90 | dst->moveTo(pts[0]); |
michael@0 | 91 | prevIsValid = true; |
michael@0 | 92 | } |
michael@0 | 93 | dst->quadTo(pts[1], pts[2]); |
michael@0 | 94 | lastCorner = pts[2]; |
michael@0 | 95 | firstStep.set(0, 0); |
michael@0 | 96 | break; |
michael@0 | 97 | case SkPath::kCubic_Verb: |
michael@0 | 98 | if (!prevIsValid) { |
michael@0 | 99 | dst->moveTo(pts[0]); |
michael@0 | 100 | prevIsValid = true; |
michael@0 | 101 | } |
michael@0 | 102 | // TBD - just replicate the curve for now |
michael@0 | 103 | dst->cubicTo(pts[1], pts[2], pts[3]); |
michael@0 | 104 | lastCorner = pts[3]; |
michael@0 | 105 | firstStep.set(0, 0); |
michael@0 | 106 | break; |
michael@0 | 107 | case SkPath::kClose_Verb: |
michael@0 | 108 | if (firstStep.fX || firstStep.fY) { |
michael@0 | 109 | dst->quadTo(lastCorner.fX, lastCorner.fY, |
michael@0 | 110 | lastCorner.fX + firstStep.fX, |
michael@0 | 111 | lastCorner.fY + firstStep.fY); |
michael@0 | 112 | } |
michael@0 | 113 | dst->close(); |
michael@0 | 114 | break; |
michael@0 | 115 | case SkPath::kConic_Verb: |
michael@0 | 116 | SkASSERT(0); |
michael@0 | 117 | break; |
michael@0 | 118 | case SkPath::kDone_Verb: |
michael@0 | 119 | goto DONE; |
michael@0 | 120 | } |
michael@0 | 121 | |
michael@0 | 122 | if (SkPath::kMove_Verb == prevVerb) { |
michael@0 | 123 | firstStep = step; |
michael@0 | 124 | } |
michael@0 | 125 | prevVerb = verb; |
michael@0 | 126 | } |
michael@0 | 127 | DONE: |
michael@0 | 128 | return true; |
michael@0 | 129 | } |
michael@0 | 130 | |
michael@0 | 131 | void SkCornerPathEffect::flatten(SkWriteBuffer& buffer) const { |
michael@0 | 132 | this->INHERITED::flatten(buffer); |
michael@0 | 133 | buffer.writeScalar(fRadius); |
michael@0 | 134 | } |
michael@0 | 135 | |
michael@0 | 136 | SkCornerPathEffect::SkCornerPathEffect(SkReadBuffer& buffer) { |
michael@0 | 137 | fRadius = buffer.readScalar(); |
michael@0 | 138 | } |