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 "SkBlurDrawLooper.h" |
michael@0 | 9 | #include "SkBlurMask.h" // just for SkBlurMask::ConvertRadiusToSigma |
michael@0 | 10 | #include "SkBlurMaskFilter.h" |
michael@0 | 11 | #include "SkCanvas.h" |
michael@0 | 12 | #include "SkColorFilter.h" |
michael@0 | 13 | #include "SkReadBuffer.h" |
michael@0 | 14 | #include "SkWriteBuffer.h" |
michael@0 | 15 | #include "SkMaskFilter.h" |
michael@0 | 16 | #include "SkPaint.h" |
michael@0 | 17 | #include "SkString.h" |
michael@0 | 18 | #include "SkStringUtils.h" |
michael@0 | 19 | |
michael@0 | 20 | SkBlurDrawLooper::SkBlurDrawLooper(SkScalar radius, SkScalar dx, SkScalar dy, |
michael@0 | 21 | SkColor color, uint32_t flags) { |
michael@0 | 22 | this->init(SkBlurMask::ConvertRadiusToSigma(radius), dx, dy, color, flags); |
michael@0 | 23 | } |
michael@0 | 24 | |
michael@0 | 25 | SkBlurDrawLooper::SkBlurDrawLooper(SkColor color, SkScalar sigma, |
michael@0 | 26 | SkScalar dx, SkScalar dy, uint32_t flags) { |
michael@0 | 27 | this->init(sigma, dx, dy, color, flags); |
michael@0 | 28 | } |
michael@0 | 29 | |
michael@0 | 30 | void SkBlurDrawLooper::init(SkScalar sigma, SkScalar dx, SkScalar dy, |
michael@0 | 31 | SkColor color, uint32_t flags) { |
michael@0 | 32 | fDx = dx; |
michael@0 | 33 | fDy = dy; |
michael@0 | 34 | fBlurColor = color; |
michael@0 | 35 | fBlurFlags = flags; |
michael@0 | 36 | |
michael@0 | 37 | SkASSERT(flags <= kAll_BlurFlag); |
michael@0 | 38 | if (sigma > 0) { |
michael@0 | 39 | uint32_t blurFlags = flags & kIgnoreTransform_BlurFlag ? |
michael@0 | 40 | SkBlurMaskFilter::kIgnoreTransform_BlurFlag : |
michael@0 | 41 | SkBlurMaskFilter::kNone_BlurFlag; |
michael@0 | 42 | |
michael@0 | 43 | blurFlags |= flags & kHighQuality_BlurFlag ? |
michael@0 | 44 | SkBlurMaskFilter::kHighQuality_BlurFlag : |
michael@0 | 45 | SkBlurMaskFilter::kNone_BlurFlag; |
michael@0 | 46 | |
michael@0 | 47 | fBlur = SkBlurMaskFilter::Create(SkBlurMaskFilter::kNormal_BlurStyle, |
michael@0 | 48 | sigma, |
michael@0 | 49 | blurFlags); |
michael@0 | 50 | } else { |
michael@0 | 51 | fBlur = NULL; |
michael@0 | 52 | } |
michael@0 | 53 | |
michael@0 | 54 | if (flags & kOverrideColor_BlurFlag) { |
michael@0 | 55 | // Set alpha to 1 for the override since transparency will already |
michael@0 | 56 | // be baked into the blurred mask. |
michael@0 | 57 | SkColor opaqueColor = SkColorSetA(color, 255); |
michael@0 | 58 | //The SrcIn xfer mode will multiply 'color' by the incoming alpha |
michael@0 | 59 | fColorFilter = SkColorFilter::CreateModeFilter(opaqueColor, |
michael@0 | 60 | SkXfermode::kSrcIn_Mode); |
michael@0 | 61 | } else { |
michael@0 | 62 | fColorFilter = NULL; |
michael@0 | 63 | } |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | SkBlurDrawLooper::SkBlurDrawLooper(SkReadBuffer& buffer) |
michael@0 | 67 | : INHERITED(buffer) { |
michael@0 | 68 | |
michael@0 | 69 | fDx = buffer.readScalar(); |
michael@0 | 70 | fDy = buffer.readScalar(); |
michael@0 | 71 | fBlurColor = buffer.readColor(); |
michael@0 | 72 | fBlur = buffer.readMaskFilter(); |
michael@0 | 73 | fColorFilter = buffer.readColorFilter(); |
michael@0 | 74 | fBlurFlags = buffer.readUInt() & kAll_BlurFlag; |
michael@0 | 75 | } |
michael@0 | 76 | |
michael@0 | 77 | SkBlurDrawLooper::~SkBlurDrawLooper() { |
michael@0 | 78 | SkSafeUnref(fBlur); |
michael@0 | 79 | SkSafeUnref(fColorFilter); |
michael@0 | 80 | } |
michael@0 | 81 | |
michael@0 | 82 | void SkBlurDrawLooper::flatten(SkWriteBuffer& buffer) const { |
michael@0 | 83 | this->INHERITED::flatten(buffer); |
michael@0 | 84 | buffer.writeScalar(fDx); |
michael@0 | 85 | buffer.writeScalar(fDy); |
michael@0 | 86 | buffer.writeColor(fBlurColor); |
michael@0 | 87 | buffer.writeFlattenable(fBlur); |
michael@0 | 88 | buffer.writeFlattenable(fColorFilter); |
michael@0 | 89 | buffer.writeUInt(fBlurFlags); |
michael@0 | 90 | } |
michael@0 | 91 | |
michael@0 | 92 | SkDrawLooper::Context* SkBlurDrawLooper::createContext(SkCanvas*, void* storage) const { |
michael@0 | 93 | return SkNEW_PLACEMENT_ARGS(storage, BlurDrawLooperContext, (this)); |
michael@0 | 94 | } |
michael@0 | 95 | |
michael@0 | 96 | SkBlurDrawLooper::BlurDrawLooperContext::BlurDrawLooperContext( |
michael@0 | 97 | const SkBlurDrawLooper* looper) |
michael@0 | 98 | : fLooper(looper), fState(SkBlurDrawLooper::kBeforeEdge) {} |
michael@0 | 99 | |
michael@0 | 100 | bool SkBlurDrawLooper::BlurDrawLooperContext::next(SkCanvas* canvas, |
michael@0 | 101 | SkPaint* paint) { |
michael@0 | 102 | switch (fState) { |
michael@0 | 103 | case kBeforeEdge: |
michael@0 | 104 | // we do nothing if a maskfilter is already installed |
michael@0 | 105 | if (paint->getMaskFilter()) { |
michael@0 | 106 | fState = kDone; |
michael@0 | 107 | return false; |
michael@0 | 108 | } |
michael@0 | 109 | #ifdef SK_BUILD_FOR_ANDROID |
michael@0 | 110 | SkColor blurColor; |
michael@0 | 111 | blurColor = fLooper->fBlurColor; |
michael@0 | 112 | if (SkColorGetA(blurColor) == 255) { |
michael@0 | 113 | blurColor = SkColorSetA(blurColor, paint->getAlpha()); |
michael@0 | 114 | } |
michael@0 | 115 | paint->setColor(blurColor); |
michael@0 | 116 | #else |
michael@0 | 117 | paint->setColor(fLooper->fBlurColor); |
michael@0 | 118 | #endif |
michael@0 | 119 | paint->setMaskFilter(fLooper->fBlur); |
michael@0 | 120 | paint->setColorFilter(fLooper->fColorFilter); |
michael@0 | 121 | canvas->save(SkCanvas::kMatrix_SaveFlag); |
michael@0 | 122 | if (fLooper->fBlurFlags & kIgnoreTransform_BlurFlag) { |
michael@0 | 123 | SkMatrix transform(canvas->getTotalMatrix()); |
michael@0 | 124 | transform.postTranslate(fLooper->fDx, fLooper->fDy); |
michael@0 | 125 | canvas->setMatrix(transform); |
michael@0 | 126 | } else { |
michael@0 | 127 | canvas->translate(fLooper->fDx, fLooper->fDy); |
michael@0 | 128 | } |
michael@0 | 129 | fState = kAfterEdge; |
michael@0 | 130 | return true; |
michael@0 | 131 | case kAfterEdge: |
michael@0 | 132 | canvas->restore(); |
michael@0 | 133 | fState = kDone; |
michael@0 | 134 | return true; |
michael@0 | 135 | default: |
michael@0 | 136 | SkASSERT(kDone == fState); |
michael@0 | 137 | return false; |
michael@0 | 138 | } |
michael@0 | 139 | } |
michael@0 | 140 | |
michael@0 | 141 | #ifndef SK_IGNORE_TO_STRING |
michael@0 | 142 | void SkBlurDrawLooper::toString(SkString* str) const { |
michael@0 | 143 | str->append("SkBlurDrawLooper: "); |
michael@0 | 144 | |
michael@0 | 145 | str->append("dx: "); |
michael@0 | 146 | str->appendScalar(fDx); |
michael@0 | 147 | |
michael@0 | 148 | str->append(" dy: "); |
michael@0 | 149 | str->appendScalar(fDy); |
michael@0 | 150 | |
michael@0 | 151 | str->append(" color: "); |
michael@0 | 152 | str->appendHex(fBlurColor); |
michael@0 | 153 | |
michael@0 | 154 | str->append(" flags: ("); |
michael@0 | 155 | if (kNone_BlurFlag == fBlurFlags) { |
michael@0 | 156 | str->append("None"); |
michael@0 | 157 | } else { |
michael@0 | 158 | bool needsSeparator = false; |
michael@0 | 159 | SkAddFlagToString(str, SkToBool(kIgnoreTransform_BlurFlag & fBlurFlags), "IgnoreTransform", |
michael@0 | 160 | &needsSeparator); |
michael@0 | 161 | SkAddFlagToString(str, SkToBool(kOverrideColor_BlurFlag & fBlurFlags), "OverrideColor", |
michael@0 | 162 | &needsSeparator); |
michael@0 | 163 | SkAddFlagToString(str, SkToBool(kHighQuality_BlurFlag & fBlurFlags), "HighQuality", |
michael@0 | 164 | &needsSeparator); |
michael@0 | 165 | } |
michael@0 | 166 | str->append(")"); |
michael@0 | 167 | |
michael@0 | 168 | // TODO: add optional "fBlurFilter->toString(str);" when SkMaskFilter::toString is added |
michael@0 | 169 | // alternatively we could cache the radius in SkBlurDrawLooper and just add it here |
michael@0 | 170 | } |
michael@0 | 171 | #endif |