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: 20; 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 <stdint.h> // for uint8_t, uint32_t |
michael@0 | 7 | #include "BasicLayers.h" // for BasicLayerManager |
michael@0 | 8 | #include "ImageContainer.h" // for PlanarYCbCrImage, etc |
michael@0 | 9 | #include "ImageTypes.h" // for ImageFormat, etc |
michael@0 | 10 | #include "cairo.h" // for cairo_user_data_key_t |
michael@0 | 11 | #include "gfxASurface.h" // for gfxASurface, etc |
michael@0 | 12 | #include "gfxPlatform.h" // for gfxPlatform, gfxImageFormat |
michael@0 | 13 | #include "gfxUtils.h" // for gfxUtils |
michael@0 | 14 | #include "mozilla/mozalloc.h" // for operator delete[], etc |
michael@0 | 15 | #include "nsAutoPtr.h" // for nsRefPtr, nsAutoArrayPtr |
michael@0 | 16 | #include "nsAutoRef.h" // for nsCountedRef |
michael@0 | 17 | #include "nsCOMPtr.h" // for already_AddRefed |
michael@0 | 18 | #include "nsDebug.h" // for NS_ERROR, NS_ASSERTION |
michael@0 | 19 | #include "nsISupportsImpl.h" // for Image::Release, etc |
michael@0 | 20 | #include "nsThreadUtils.h" // for NS_IsMainThread |
michael@0 | 21 | #include "mozilla/gfx/Point.h" // for IntSize |
michael@0 | 22 | #include "gfx2DGlue.h" |
michael@0 | 23 | #include "YCbCrUtils.h" // for YCbCr conversions |
michael@0 | 24 | #ifdef XP_MACOSX |
michael@0 | 25 | #include "gfxQuartzImageSurface.h" |
michael@0 | 26 | #endif |
michael@0 | 27 | |
michael@0 | 28 | namespace mozilla { |
michael@0 | 29 | namespace layers { |
michael@0 | 30 | |
michael@0 | 31 | class BasicPlanarYCbCrImage : public PlanarYCbCrImage |
michael@0 | 32 | { |
michael@0 | 33 | public: |
michael@0 | 34 | BasicPlanarYCbCrImage(const gfx::IntSize& aScaleHint, gfxImageFormat aOffscreenFormat, BufferRecycleBin *aRecycleBin) |
michael@0 | 35 | : PlanarYCbCrImage(aRecycleBin) |
michael@0 | 36 | , mScaleHint(aScaleHint) |
michael@0 | 37 | , mDelayedConversion(false) |
michael@0 | 38 | { |
michael@0 | 39 | SetOffscreenFormat(aOffscreenFormat); |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | ~BasicPlanarYCbCrImage() |
michael@0 | 43 | { |
michael@0 | 44 | if (mDecodedBuffer) { |
michael@0 | 45 | // Right now this only happens if the Image was never drawn, otherwise |
michael@0 | 46 | // this will have been tossed away at surface destruction. |
michael@0 | 47 | mRecycleBin->RecycleBuffer(mDecodedBuffer.forget(), mSize.height * mStride); |
michael@0 | 48 | } |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | virtual void SetData(const Data& aData); |
michael@0 | 52 | virtual void SetDelayedConversion(bool aDelayed) { mDelayedConversion = aDelayed; } |
michael@0 | 53 | |
michael@0 | 54 | TemporaryRef<gfx::SourceSurface> GetAsSourceSurface(); |
michael@0 | 55 | |
michael@0 | 56 | virtual size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const MOZ_OVERRIDE |
michael@0 | 57 | { |
michael@0 | 58 | return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf); |
michael@0 | 59 | } |
michael@0 | 60 | |
michael@0 | 61 | virtual size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const MOZ_OVERRIDE |
michael@0 | 62 | { |
michael@0 | 63 | size_t size = PlanarYCbCrImage::SizeOfExcludingThis(aMallocSizeOf); |
michael@0 | 64 | size += mDecodedBuffer.SizeOfExcludingThis(aMallocSizeOf); |
michael@0 | 65 | return size; |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | private: |
michael@0 | 69 | nsAutoArrayPtr<uint8_t> mDecodedBuffer; |
michael@0 | 70 | gfx::IntSize mScaleHint; |
michael@0 | 71 | int mStride; |
michael@0 | 72 | bool mDelayedConversion; |
michael@0 | 73 | }; |
michael@0 | 74 | |
michael@0 | 75 | class BasicImageFactory : public ImageFactory |
michael@0 | 76 | { |
michael@0 | 77 | public: |
michael@0 | 78 | BasicImageFactory() {} |
michael@0 | 79 | |
michael@0 | 80 | virtual already_AddRefed<Image> CreateImage(ImageFormat aFormat, |
michael@0 | 81 | const gfx::IntSize &aScaleHint, |
michael@0 | 82 | BufferRecycleBin *aRecycleBin) |
michael@0 | 83 | { |
michael@0 | 84 | nsRefPtr<Image> image; |
michael@0 | 85 | if (aFormat == ImageFormat::PLANAR_YCBCR) { |
michael@0 | 86 | image = new BasicPlanarYCbCrImage(aScaleHint, gfxPlatform::GetPlatform()->GetOffscreenFormat(), aRecycleBin); |
michael@0 | 87 | return image.forget(); |
michael@0 | 88 | } |
michael@0 | 89 | |
michael@0 | 90 | return ImageFactory::CreateImage(aFormat, aScaleHint, aRecycleBin); |
michael@0 | 91 | } |
michael@0 | 92 | }; |
michael@0 | 93 | |
michael@0 | 94 | void |
michael@0 | 95 | BasicPlanarYCbCrImage::SetData(const Data& aData) |
michael@0 | 96 | { |
michael@0 | 97 | PlanarYCbCrImage::SetData(aData); |
michael@0 | 98 | |
michael@0 | 99 | if (mDelayedConversion) { |
michael@0 | 100 | return; |
michael@0 | 101 | } |
michael@0 | 102 | |
michael@0 | 103 | // Do some sanity checks to prevent integer overflow |
michael@0 | 104 | if (aData.mYSize.width > PlanarYCbCrImage::MAX_DIMENSION || |
michael@0 | 105 | aData.mYSize.height > PlanarYCbCrImage::MAX_DIMENSION) { |
michael@0 | 106 | NS_ERROR("Illegal image source width or height"); |
michael@0 | 107 | return; |
michael@0 | 108 | } |
michael@0 | 109 | |
michael@0 | 110 | gfx::SurfaceFormat format = gfx::ImageFormatToSurfaceFormat(GetOffscreenFormat()); |
michael@0 | 111 | |
michael@0 | 112 | gfx::IntSize size(mScaleHint); |
michael@0 | 113 | gfx::GetYCbCrToRGBDestFormatAndSize(aData, format, size); |
michael@0 | 114 | if (size.width > PlanarYCbCrImage::MAX_DIMENSION || |
michael@0 | 115 | size.height > PlanarYCbCrImage::MAX_DIMENSION) { |
michael@0 | 116 | NS_ERROR("Illegal image dest width or height"); |
michael@0 | 117 | return; |
michael@0 | 118 | } |
michael@0 | 119 | |
michael@0 | 120 | gfxImageFormat iFormat = gfx::SurfaceFormatToImageFormat(format); |
michael@0 | 121 | mStride = gfxASurface::FormatStrideForWidth(iFormat, size.width); |
michael@0 | 122 | mDecodedBuffer = AllocateBuffer(size.height * mStride); |
michael@0 | 123 | if (!mDecodedBuffer) { |
michael@0 | 124 | // out of memory |
michael@0 | 125 | return; |
michael@0 | 126 | } |
michael@0 | 127 | |
michael@0 | 128 | gfx::ConvertYCbCrToRGB(aData, format, size, mDecodedBuffer, mStride); |
michael@0 | 129 | SetOffscreenFormat(iFormat); |
michael@0 | 130 | mSize = size; |
michael@0 | 131 | } |
michael@0 | 132 | |
michael@0 | 133 | TemporaryRef<gfx::SourceSurface> |
michael@0 | 134 | BasicPlanarYCbCrImage::GetAsSourceSurface() |
michael@0 | 135 | { |
michael@0 | 136 | NS_ASSERTION(NS_IsMainThread(), "Must be main thread"); |
michael@0 | 137 | |
michael@0 | 138 | if (mSourceSurface) { |
michael@0 | 139 | return mSourceSurface.get(); |
michael@0 | 140 | } |
michael@0 | 141 | |
michael@0 | 142 | if (!mDecodedBuffer) { |
michael@0 | 143 | return PlanarYCbCrImage::GetAsSourceSurface(); |
michael@0 | 144 | } |
michael@0 | 145 | |
michael@0 | 146 | gfxImageFormat format = GetOffscreenFormat(); |
michael@0 | 147 | |
michael@0 | 148 | RefPtr<gfx::SourceSurface> surface; |
michael@0 | 149 | { |
michael@0 | 150 | // Create a DrawTarget so that we can own the data inside mDecodeBuffer. |
michael@0 | 151 | // We create the target out of mDecodedBuffer, and get a snapshot from it. |
michael@0 | 152 | // The draw target is destroyed on scope exit and the surface owns the data. |
michael@0 | 153 | RefPtr<gfx::DrawTarget> drawTarget |
michael@0 | 154 | = gfxPlatform::GetPlatform()->CreateDrawTargetForData(mDecodedBuffer, |
michael@0 | 155 | mSize, |
michael@0 | 156 | mStride, |
michael@0 | 157 | gfx::ImageFormatToSurfaceFormat(format)); |
michael@0 | 158 | if (!drawTarget) { |
michael@0 | 159 | return nullptr; |
michael@0 | 160 | } |
michael@0 | 161 | |
michael@0 | 162 | surface = drawTarget->Snapshot(); |
michael@0 | 163 | } |
michael@0 | 164 | |
michael@0 | 165 | mRecycleBin->RecycleBuffer(mDecodedBuffer.forget(), mSize.height * mStride); |
michael@0 | 166 | |
michael@0 | 167 | mSourceSurface = surface; |
michael@0 | 168 | return mSourceSurface.get(); |
michael@0 | 169 | } |
michael@0 | 170 | |
michael@0 | 171 | |
michael@0 | 172 | ImageFactory* |
michael@0 | 173 | BasicLayerManager::GetImageFactory() |
michael@0 | 174 | { |
michael@0 | 175 | if (!mFactory) { |
michael@0 | 176 | mFactory = new BasicImageFactory(); |
michael@0 | 177 | } |
michael@0 | 178 | |
michael@0 | 179 | return mFactory.get(); |
michael@0 | 180 | } |
michael@0 | 181 | |
michael@0 | 182 | } |
michael@0 | 183 | } |