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 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
michael@0 | 2 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "BasicLayersImpl.h" |
michael@0 | 7 | #include <new> // for operator new |
michael@0 | 8 | #include "Layers.h" // for Layer, etc |
michael@0 | 9 | #include "basic/BasicImplData.h" // for BasicImplData |
michael@0 | 10 | #include "mozilla/Assertions.h" // for MOZ_ASSERT, etc |
michael@0 | 11 | #include "mozilla/DebugOnly.h" // for DebugOnly |
michael@0 | 12 | #include "mozilla/layers/CompositorTypes.h" |
michael@0 | 13 | #include "mozilla/layers/ISurfaceAllocator.h" |
michael@0 | 14 | #include "AutoMaskData.h" |
michael@0 | 15 | |
michael@0 | 16 | using namespace mozilla::gfx; |
michael@0 | 17 | |
michael@0 | 18 | namespace mozilla { |
michael@0 | 19 | namespace layers { |
michael@0 | 20 | |
michael@0 | 21 | bool |
michael@0 | 22 | GetMaskData(Layer* aMaskLayer, |
michael@0 | 23 | const Point& aDeviceOffset, |
michael@0 | 24 | AutoMoz2DMaskData* aMaskData) |
michael@0 | 25 | { |
michael@0 | 26 | if (aMaskLayer) { |
michael@0 | 27 | RefPtr<SourceSurface> surface = |
michael@0 | 28 | static_cast<BasicImplData*>(aMaskLayer->ImplData())->GetAsSourceSurface(); |
michael@0 | 29 | if (surface) { |
michael@0 | 30 | Matrix transform; |
michael@0 | 31 | Matrix4x4 effectiveTransform = aMaskLayer->GetEffectiveTransform(); |
michael@0 | 32 | DebugOnly<bool> maskIs2D = effectiveTransform.CanDraw2D(&transform); |
michael@0 | 33 | NS_ASSERTION(maskIs2D, "How did we end up with a 3D transform here?!"); |
michael@0 | 34 | transform.Translate(-aDeviceOffset.x, -aDeviceOffset.y); |
michael@0 | 35 | aMaskData->Construct(transform, surface); |
michael@0 | 36 | return true; |
michael@0 | 37 | } |
michael@0 | 38 | } |
michael@0 | 39 | return false; |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | void |
michael@0 | 43 | PaintWithMask(gfxContext* aContext, float aOpacity, Layer* aMaskLayer) |
michael@0 | 44 | { |
michael@0 | 45 | AutoMoz2DMaskData mask; |
michael@0 | 46 | if (GetMaskData(aMaskLayer, Point(), &mask)) { |
michael@0 | 47 | if (aOpacity < 1.0) { |
michael@0 | 48 | aContext->PushGroup(gfxContentType::COLOR_ALPHA); |
michael@0 | 49 | aContext->Paint(aOpacity); |
michael@0 | 50 | aContext->PopGroupToSource(); |
michael@0 | 51 | } |
michael@0 | 52 | aContext->SetMatrix(ThebesMatrix(mask.GetTransform())); |
michael@0 | 53 | aContext->Mask(mask.GetSurface()); |
michael@0 | 54 | return; |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | // if there is no mask, just paint normally |
michael@0 | 58 | aContext->Paint(aOpacity); |
michael@0 | 59 | } |
michael@0 | 60 | |
michael@0 | 61 | void |
michael@0 | 62 | FillRectWithMask(DrawTarget* aDT, |
michael@0 | 63 | const Rect& aRect, |
michael@0 | 64 | const Color& aColor, |
michael@0 | 65 | const DrawOptions& aOptions, |
michael@0 | 66 | SourceSurface* aMaskSource, |
michael@0 | 67 | const Matrix* aMaskTransform) |
michael@0 | 68 | { |
michael@0 | 69 | if (aMaskSource && aMaskTransform) { |
michael@0 | 70 | aDT->PushClipRect(aRect); |
michael@0 | 71 | Matrix oldTransform = aDT->GetTransform(); |
michael@0 | 72 | |
michael@0 | 73 | aDT->SetTransform(*aMaskTransform); |
michael@0 | 74 | aDT->MaskSurface(ColorPattern(aColor), aMaskSource, Point(), aOptions); |
michael@0 | 75 | aDT->SetTransform(oldTransform); |
michael@0 | 76 | aDT->PopClip(); |
michael@0 | 77 | return; |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | aDT->FillRect(aRect, ColorPattern(aColor), aOptions); |
michael@0 | 81 | } |
michael@0 | 82 | void |
michael@0 | 83 | FillRectWithMask(DrawTarget* aDT, |
michael@0 | 84 | const gfx::Point& aDeviceOffset, |
michael@0 | 85 | const Rect& aRect, |
michael@0 | 86 | const Color& aColor, |
michael@0 | 87 | const DrawOptions& aOptions, |
michael@0 | 88 | Layer* aMaskLayer) |
michael@0 | 89 | { |
michael@0 | 90 | AutoMoz2DMaskData mask; |
michael@0 | 91 | if (GetMaskData(aMaskLayer, aDeviceOffset, &mask)) { |
michael@0 | 92 | const Matrix& maskTransform = mask.GetTransform(); |
michael@0 | 93 | FillRectWithMask(aDT, aRect, aColor, aOptions, mask.GetSurface(), &maskTransform); |
michael@0 | 94 | return; |
michael@0 | 95 | } |
michael@0 | 96 | |
michael@0 | 97 | FillRectWithMask(aDT, aRect, aColor, aOptions); |
michael@0 | 98 | } |
michael@0 | 99 | |
michael@0 | 100 | void |
michael@0 | 101 | FillRectWithMask(DrawTarget* aDT, |
michael@0 | 102 | const Rect& aRect, |
michael@0 | 103 | SourceSurface* aSurface, |
michael@0 | 104 | Filter aFilter, |
michael@0 | 105 | const DrawOptions& aOptions, |
michael@0 | 106 | ExtendMode aExtendMode, |
michael@0 | 107 | SourceSurface* aMaskSource, |
michael@0 | 108 | const Matrix* aMaskTransform, |
michael@0 | 109 | const Matrix* aSurfaceTransform) |
michael@0 | 110 | { |
michael@0 | 111 | if (aMaskSource && aMaskTransform) { |
michael@0 | 112 | aDT->PushClipRect(aRect); |
michael@0 | 113 | Matrix oldTransform = aDT->GetTransform(); |
michael@0 | 114 | |
michael@0 | 115 | Matrix inverseMask = *aMaskTransform; |
michael@0 | 116 | inverseMask.Invert(); |
michael@0 | 117 | |
michael@0 | 118 | Matrix transform = oldTransform * inverseMask; |
michael@0 | 119 | if (aSurfaceTransform) { |
michael@0 | 120 | transform = (*aSurfaceTransform) * transform; |
michael@0 | 121 | } |
michael@0 | 122 | |
michael@0 | 123 | SurfacePattern source(aSurface, aExtendMode, transform, aFilter); |
michael@0 | 124 | |
michael@0 | 125 | aDT->SetTransform(*aMaskTransform); |
michael@0 | 126 | aDT->MaskSurface(source, aMaskSource, Point(0, 0), aOptions); |
michael@0 | 127 | aDT->SetTransform(oldTransform); |
michael@0 | 128 | aDT->PopClip(); |
michael@0 | 129 | return; |
michael@0 | 130 | } |
michael@0 | 131 | |
michael@0 | 132 | aDT->FillRect(aRect, |
michael@0 | 133 | SurfacePattern(aSurface, aExtendMode, |
michael@0 | 134 | aSurfaceTransform ? (*aSurfaceTransform) : Matrix(), |
michael@0 | 135 | aFilter), aOptions); |
michael@0 | 136 | } |
michael@0 | 137 | |
michael@0 | 138 | void |
michael@0 | 139 | FillRectWithMask(DrawTarget* aDT, |
michael@0 | 140 | const gfx::Point& aDeviceOffset, |
michael@0 | 141 | const Rect& aRect, |
michael@0 | 142 | SourceSurface* aSurface, |
michael@0 | 143 | Filter aFilter, |
michael@0 | 144 | const DrawOptions& aOptions, |
michael@0 | 145 | Layer* aMaskLayer) |
michael@0 | 146 | { |
michael@0 | 147 | AutoMoz2DMaskData mask; |
michael@0 | 148 | if (GetMaskData(aMaskLayer, aDeviceOffset, &mask)) { |
michael@0 | 149 | const Matrix& maskTransform = mask.GetTransform(); |
michael@0 | 150 | FillRectWithMask(aDT, aRect, aSurface, aFilter, aOptions, ExtendMode::CLAMP, |
michael@0 | 151 | mask.GetSurface(), &maskTransform); |
michael@0 | 152 | return; |
michael@0 | 153 | } |
michael@0 | 154 | |
michael@0 | 155 | FillRectWithMask(aDT, aRect, aSurface, aFilter, aOptions, ExtendMode::CLAMP); |
michael@0 | 156 | } |
michael@0 | 157 | |
michael@0 | 158 | BasicImplData* |
michael@0 | 159 | ToData(Layer* aLayer) |
michael@0 | 160 | { |
michael@0 | 161 | return static_cast<BasicImplData*>(aLayer->ImplData()); |
michael@0 | 162 | } |
michael@0 | 163 | |
michael@0 | 164 | gfx::CompositionOp |
michael@0 | 165 | GetEffectiveOperator(Layer* aLayer) |
michael@0 | 166 | { |
michael@0 | 167 | CompositionOp op = aLayer->GetEffectiveMixBlendMode(); |
michael@0 | 168 | |
michael@0 | 169 | if (op != CompositionOp::OP_OVER) { |
michael@0 | 170 | return op; |
michael@0 | 171 | } |
michael@0 | 172 | |
michael@0 | 173 | return ToData(aLayer)->GetOperator(); |
michael@0 | 174 | } |
michael@0 | 175 | |
michael@0 | 176 | ShadowableLayer* |
michael@0 | 177 | ToShadowable(Layer* aLayer) |
michael@0 | 178 | { |
michael@0 | 179 | return aLayer->AsShadowableLayer(); |
michael@0 | 180 | } |
michael@0 | 181 | |
michael@0 | 182 | bool |
michael@0 | 183 | ShouldShadow(Layer* aLayer) |
michael@0 | 184 | { |
michael@0 | 185 | if (!ToShadowable(aLayer)) { |
michael@0 | 186 | NS_ABORT_IF_FALSE(aLayer->GetType() == Layer::TYPE_READBACK, |
michael@0 | 187 | "Only expect not to shadow ReadbackLayers"); |
michael@0 | 188 | return false; |
michael@0 | 189 | } |
michael@0 | 190 | return true; |
michael@0 | 191 | } |
michael@0 | 192 | |
michael@0 | 193 | |
michael@0 | 194 | } |
michael@0 | 195 | } |