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 2010 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 | #ifndef SkPDFGraphicState_DEFINED |
michael@0 | 11 | #define SkPDFGraphicState_DEFINED |
michael@0 | 12 | |
michael@0 | 13 | #include "SkPaint.h" |
michael@0 | 14 | #include "SkPDFTypes.h" |
michael@0 | 15 | #include "SkTemplates.h" |
michael@0 | 16 | #include "SkThread.h" |
michael@0 | 17 | |
michael@0 | 18 | class SkPDFFormXObject; |
michael@0 | 19 | |
michael@0 | 20 | /** \class SkPDFGraphicState |
michael@0 | 21 | SkPaint objects roughly correspond to graphic state dictionaries that can |
michael@0 | 22 | be installed. So that a given dictionary is only output to the pdf file |
michael@0 | 23 | once, we want to canonicalize them. Static methods in this class manage |
michael@0 | 24 | a weakly referenced set of SkPDFGraphicState objects: when the last |
michael@0 | 25 | reference to a SkPDFGraphicState is removed, it removes itself from the |
michael@0 | 26 | static set of objects. |
michael@0 | 27 | |
michael@0 | 28 | */ |
michael@0 | 29 | class SkPDFGraphicState : public SkPDFDict { |
michael@0 | 30 | SK_DECLARE_INST_COUNT(SkPDFGraphicState) |
michael@0 | 31 | public: |
michael@0 | 32 | enum SkPDFSMaskMode { |
michael@0 | 33 | kAlpha_SMaskMode, |
michael@0 | 34 | kLuminosity_SMaskMode |
michael@0 | 35 | }; |
michael@0 | 36 | |
michael@0 | 37 | virtual ~SkPDFGraphicState(); |
michael@0 | 38 | |
michael@0 | 39 | virtual void getResources(const SkTSet<SkPDFObject*>& knownResourceObjects, |
michael@0 | 40 | SkTSet<SkPDFObject*>* newResourceObjects); |
michael@0 | 41 | |
michael@0 | 42 | // Override emitObject and getOutputSize so that we can populate |
michael@0 | 43 | // the dictionary on demand. |
michael@0 | 44 | virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog, |
michael@0 | 45 | bool indirect); |
michael@0 | 46 | virtual size_t getOutputSize(SkPDFCatalog* catalog, bool indirect); |
michael@0 | 47 | |
michael@0 | 48 | /** Get the graphic state for the passed SkPaint. The reference count of |
michael@0 | 49 | * the object is incremented and it is the caller's responsibility to |
michael@0 | 50 | * unreference it when done. This is needed to accommodate the weak |
michael@0 | 51 | * reference pattern used when the returned object is new and has no |
michael@0 | 52 | * other references. |
michael@0 | 53 | * @param paint The SkPaint to emulate. |
michael@0 | 54 | */ |
michael@0 | 55 | static SkPDFGraphicState* GetGraphicStateForPaint(const SkPaint& paint); |
michael@0 | 56 | |
michael@0 | 57 | /** Make a graphic state that only sets the passed soft mask. The |
michael@0 | 58 | * reference count of the object is incremented and it is the caller's |
michael@0 | 59 | * responsibility to unreference it when done. |
michael@0 | 60 | * @param sMask The form xobject to use as a soft mask. |
michael@0 | 61 | * @param invert Indicates if the alpha of the sMask should be inverted. |
michael@0 | 62 | * @param sMaskMode Whether to use alpha or luminosity for the sMask. |
michael@0 | 63 | */ |
michael@0 | 64 | static SkPDFGraphicState* GetSMaskGraphicState(SkPDFFormXObject* sMask, |
michael@0 | 65 | bool invert, |
michael@0 | 66 | SkPDFSMaskMode sMaskMode); |
michael@0 | 67 | |
michael@0 | 68 | /** Get a graphic state that only unsets the soft mask. The reference |
michael@0 | 69 | * count of the object is incremented and it is the caller's responsibility |
michael@0 | 70 | * to unreference it when done. This is needed to accommodate the weak |
michael@0 | 71 | * reference pattern used when the returned object is new and has no |
michael@0 | 72 | * other references. |
michael@0 | 73 | */ |
michael@0 | 74 | static SkPDFGraphicState* GetNoSMaskGraphicState(); |
michael@0 | 75 | |
michael@0 | 76 | private: |
michael@0 | 77 | const SkPaint fPaint; |
michael@0 | 78 | SkTDArray<SkPDFObject*> fResources; |
michael@0 | 79 | bool fPopulated; |
michael@0 | 80 | bool fSMask; |
michael@0 | 81 | |
michael@0 | 82 | class GSCanonicalEntry { |
michael@0 | 83 | public: |
michael@0 | 84 | SkPDFGraphicState* fGraphicState; |
michael@0 | 85 | const SkPaint* fPaint; |
michael@0 | 86 | |
michael@0 | 87 | bool operator==(const GSCanonicalEntry& b) const; |
michael@0 | 88 | explicit GSCanonicalEntry(SkPDFGraphicState* gs) |
michael@0 | 89 | : fGraphicState(gs), |
michael@0 | 90 | fPaint(&gs->fPaint) {} |
michael@0 | 91 | explicit GSCanonicalEntry(const SkPaint* paint) |
michael@0 | 92 | : fGraphicState(NULL), |
michael@0 | 93 | fPaint(paint) {} |
michael@0 | 94 | }; |
michael@0 | 95 | |
michael@0 | 96 | // This should be made a hash table if performance is a problem. |
michael@0 | 97 | static SkTDArray<GSCanonicalEntry>& CanonicalPaints(); |
michael@0 | 98 | static SkBaseMutex& CanonicalPaintsMutex(); |
michael@0 | 99 | |
michael@0 | 100 | SkPDFGraphicState(); |
michael@0 | 101 | explicit SkPDFGraphicState(const SkPaint& paint); |
michael@0 | 102 | |
michael@0 | 103 | void populateDict(); |
michael@0 | 104 | |
michael@0 | 105 | static SkPDFObject* GetInvertFunction(); |
michael@0 | 106 | |
michael@0 | 107 | static int Find(const SkPaint& paint); |
michael@0 | 108 | typedef SkPDFDict INHERITED; |
michael@0 | 109 | }; |
michael@0 | 110 | |
michael@0 | 111 | #endif |