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 | * Copyright 2013 Google Inc. |
michael@0 | 3 | * |
michael@0 | 4 | * Use of this source code is governed by a BSD-style license that can be |
michael@0 | 5 | * found in the LICENSE file. |
michael@0 | 6 | */ |
michael@0 | 7 | |
michael@0 | 8 | #include "SkPDFDeviceFlattener.h" |
michael@0 | 9 | |
michael@0 | 10 | #include "SkDraw.h" |
michael@0 | 11 | |
michael@0 | 12 | static SkISize SkSizeToISize(const SkSize& size) { |
michael@0 | 13 | return SkISize::Make(SkScalarRoundToInt(size.width()), SkScalarRoundToInt(size.height())); |
michael@0 | 14 | } |
michael@0 | 15 | |
michael@0 | 16 | SkPDFDeviceFlattener::SkPDFDeviceFlattener(const SkSize& pageSize, const SkRect* trimBox) |
michael@0 | 17 | : SkPDFDevice(SkSizeToISize(pageSize), |
michael@0 | 18 | SkSizeToISize(pageSize), |
michael@0 | 19 | SkMatrix::I()) { |
michael@0 | 20 | // TODO(edisonn): store the trimbox on emit. |
michael@0 | 21 | } |
michael@0 | 22 | |
michael@0 | 23 | SkPDFDeviceFlattener::~SkPDFDeviceFlattener() { |
michael@0 | 24 | } |
michael@0 | 25 | |
michael@0 | 26 | static void flattenPaint(const SkDraw& d, SkPaint* paint) { |
michael@0 | 27 | if (paint->getShader()) { |
michael@0 | 28 | SkMatrix local = paint->getShader()->getLocalMatrix(); |
michael@0 | 29 | local.preConcat(*d.fMatrix); |
michael@0 | 30 | paint->getShader()->setLocalMatrix(local); |
michael@0 | 31 | } |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | void SkPDFDeviceFlattener::drawPoints(const SkDraw& d, SkCanvas::PointMode mode, |
michael@0 | 35 | size_t count, const SkPoint points[], |
michael@0 | 36 | const SkPaint& paint) { |
michael@0 | 37 | if (!mustFlatten(d)) { |
michael@0 | 38 | INHERITED::drawPoints(d, mode, count, points, paint); |
michael@0 | 39 | return; |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | SkPaint paintFlatten(paint); |
michael@0 | 43 | flattenPaint(d, &paintFlatten); |
michael@0 | 44 | |
michael@0 | 45 | SkPoint* flattenedPoints = SkNEW_ARRAY(SkPoint, count); |
michael@0 | 46 | d.fMatrix->mapPoints(flattenedPoints, points, SkToS32(count)); |
michael@0 | 47 | SkDraw draw(d); |
michael@0 | 48 | SkMatrix identity = SkMatrix::I(); |
michael@0 | 49 | draw.fMatrix = &identity; |
michael@0 | 50 | INHERITED::drawPoints(draw, mode, count, flattenedPoints, paintFlatten); |
michael@0 | 51 | SkDELETE_ARRAY(flattenedPoints); |
michael@0 | 52 | } |
michael@0 | 53 | |
michael@0 | 54 | void SkPDFDeviceFlattener::drawRect(const SkDraw& d, const SkRect& r, const SkPaint& paint) { |
michael@0 | 55 | if (!mustFlatten(d)) { |
michael@0 | 56 | INHERITED::drawRect(d, r, paint); |
michael@0 | 57 | return; |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | SkPath path; |
michael@0 | 61 | path.addRect(r); |
michael@0 | 62 | path.transform(*d.fMatrix); |
michael@0 | 63 | SkDraw draw(d); |
michael@0 | 64 | SkMatrix matrix = SkMatrix::I(); |
michael@0 | 65 | draw.fMatrix = &matrix; |
michael@0 | 66 | |
michael@0 | 67 | SkPaint paintFlatten(paint); |
michael@0 | 68 | flattenPaint(d, &paintFlatten); |
michael@0 | 69 | |
michael@0 | 70 | INHERITED::drawPath(draw, path, paintFlatten, NULL, true); |
michael@0 | 71 | } |
michael@0 | 72 | |
michael@0 | 73 | void SkPDFDeviceFlattener::drawPath(const SkDraw& d, const SkPath& origPath, |
michael@0 | 74 | const SkPaint& paint, const SkMatrix* prePathMatrix, |
michael@0 | 75 | bool pathIsMutable) { |
michael@0 | 76 | if (!mustFlatten(d) && !(prePathMatrix && prePathMatrix->hasPerspective())) { |
michael@0 | 77 | INHERITED::drawPath(d, origPath, paint, prePathMatrix, pathIsMutable); |
michael@0 | 78 | return; |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | SkPath* pathPtr = (SkPath*)&origPath; |
michael@0 | 82 | SkPath tmpPath; |
michael@0 | 83 | |
michael@0 | 84 | if (!pathIsMutable) { |
michael@0 | 85 | tmpPath = origPath; |
michael@0 | 86 | pathPtr = &tmpPath; |
michael@0 | 87 | } |
michael@0 | 88 | |
michael@0 | 89 | if (prePathMatrix) { |
michael@0 | 90 | pathPtr->transform(*prePathMatrix); |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | SkPaint paintFlatten(paint); |
michael@0 | 94 | flattenPaint(d, &paintFlatten); |
michael@0 | 95 | |
michael@0 | 96 | bool fill = paintFlatten.getFillPath(*pathPtr, &tmpPath); |
michael@0 | 97 | SkDEBUGCODE(pathPtr = (SkPath*)0x12345678); // Don't use pathPtr after this point. |
michael@0 | 98 | |
michael@0 | 99 | paintFlatten.setPathEffect(NULL); |
michael@0 | 100 | if (fill) { |
michael@0 | 101 | paintFlatten.setStyle(SkPaint::kFill_Style); |
michael@0 | 102 | } else { |
michael@0 | 103 | paintFlatten.setStyle(SkPaint::kStroke_Style); |
michael@0 | 104 | paintFlatten.setStrokeWidth(0); |
michael@0 | 105 | } |
michael@0 | 106 | |
michael@0 | 107 | tmpPath.transform(*d.fMatrix); |
michael@0 | 108 | |
michael@0 | 109 | SkDraw draw(d); |
michael@0 | 110 | SkMatrix matrix = SkMatrix::I(); |
michael@0 | 111 | draw.fMatrix = &matrix; |
michael@0 | 112 | |
michael@0 | 113 | INHERITED::drawPath(draw, tmpPath, paintFlatten, NULL, true); |
michael@0 | 114 | } |
michael@0 | 115 | |
michael@0 | 116 | void SkPDFDeviceFlattener::drawText(const SkDraw& d, const void* text, size_t len, |
michael@0 | 117 | SkScalar x, SkScalar y, const SkPaint& paint) { |
michael@0 | 118 | if (mustPathText(d, paint)) { |
michael@0 | 119 | d.drawText_asPaths((const char*)text, len, x, y, paint); |
michael@0 | 120 | return; |
michael@0 | 121 | } |
michael@0 | 122 | |
michael@0 | 123 | INHERITED::drawText(d, text, len, x, y, paint); |
michael@0 | 124 | } |
michael@0 | 125 | |
michael@0 | 126 | void SkPDFDeviceFlattener::drawPosText(const SkDraw& d, const void* text, size_t len, |
michael@0 | 127 | const SkScalar pos[], SkScalar constY, |
michael@0 | 128 | int scalarsPerPos, const SkPaint& paint) { |
michael@0 | 129 | if (mustPathText(d, paint)) { |
michael@0 | 130 | d.drawPosText_asPaths((const char*)text, len, pos, constY, scalarsPerPos, paint); |
michael@0 | 131 | return; |
michael@0 | 132 | } |
michael@0 | 133 | INHERITED::drawPosText(d, text, len, pos, constY,scalarsPerPos, paint); |
michael@0 | 134 | } |
michael@0 | 135 | |
michael@0 | 136 | void SkPDFDeviceFlattener::drawTextOnPath(const SkDraw& d, const void* text, size_t len, |
michael@0 | 137 | const SkPath& path, const SkMatrix* matrix, |
michael@0 | 138 | const SkPaint& paint) { |
michael@0 | 139 | if (mustPathText(d, paint) || (matrix && matrix->hasPerspective())) { |
michael@0 | 140 | d.drawTextOnPath((const char*)text, len, path, matrix, paint); |
michael@0 | 141 | return; |
michael@0 | 142 | } |
michael@0 | 143 | INHERITED::drawTextOnPath(d, text, len, path, matrix, paint); |
michael@0 | 144 | } |
michael@0 | 145 | |
michael@0 | 146 | bool SkPDFDeviceFlattener::mustFlatten(const SkDraw& d) const { |
michael@0 | 147 | // TODO(edisonn): testability, add flag to force return true. |
michael@0 | 148 | return d.fMatrix->hasPerspective(); |
michael@0 | 149 | } |
michael@0 | 150 | |
michael@0 | 151 | bool SkPDFDeviceFlattener::mustPathText(const SkDraw& d, const SkPaint&) { |
michael@0 | 152 | // TODO(edisonn): testability, add flag to force return true. |
michael@0 | 153 | // TODO(edisonn): TBD: How to flatten MaskFilter. |
michael@0 | 154 | return d.fMatrix->hasPerspective(); |
michael@0 | 155 | } |