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 2014 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 | #ifndef SkOffsetTable_DEFINED |
michael@0 | 9 | #define SkOffsetTable_DEFINED |
michael@0 | 10 | |
michael@0 | 11 | #include "SkRefCnt.h" |
michael@0 | 12 | #include "SkTDArray.h" |
michael@0 | 13 | |
michael@0 | 14 | // A 2D table of skp offsets. Each row is indexed by an int. This is used |
michael@0 | 15 | // to store the command offsets that reference a particular bitmap using |
michael@0 | 16 | // the bitmap's index in the bitmap heap as the 'id' here. It has to be |
michael@0 | 17 | // ref-countable so SkPicturePlayback can take ownership of it. |
michael@0 | 18 | // Note that this class assumes that the ids are densely packed. |
michael@0 | 19 | |
michael@0 | 20 | // TODO: This needs to be sped up. We could replace the offset table with |
michael@0 | 21 | // a hash table. |
michael@0 | 22 | class SkOffsetTable : public SkRefCnt { |
michael@0 | 23 | public: |
michael@0 | 24 | SkOffsetTable() {} |
michael@0 | 25 | ~SkOffsetTable() { |
michael@0 | 26 | fOffsetArrays.deleteAll(); |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | // Record that this 'id' is used by the command starting at this 'offset'. |
michael@0 | 30 | // Offsets for a given 'id' should always be added in increasing order. |
michael@0 | 31 | void add(int id, size_t offset) { |
michael@0 | 32 | if (id >= fOffsetArrays.count()) { |
michael@0 | 33 | int oldCount = fOffsetArrays.count(); |
michael@0 | 34 | fOffsetArrays.setCount(id+1); |
michael@0 | 35 | for (int i = oldCount; i <= id; ++i) { |
michael@0 | 36 | fOffsetArrays[i] = NULL; |
michael@0 | 37 | } |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | if (NULL == fOffsetArrays[id]) { |
michael@0 | 41 | fOffsetArrays[id] = SkNEW(OffsetArray); |
michael@0 | 42 | } |
michael@0 | 43 | fOffsetArrays[id]->add(offset); |
michael@0 | 44 | } |
michael@0 | 45 | |
michael@0 | 46 | int numIDs() const { |
michael@0 | 47 | return fOffsetArrays.count(); |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | // Do the offsets of any commands referencing this ID fall in the |
michael@0 | 51 | // range [min, max] (both inclusive) |
michael@0 | 52 | bool overlap(int id, size_t min, size_t max) { |
michael@0 | 53 | SkASSERT(id < fOffsetArrays.count()); |
michael@0 | 54 | |
michael@0 | 55 | if (NULL == fOffsetArrays[id]) { |
michael@0 | 56 | return false; |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | // If this id has an offset array it should have at least one use |
michael@0 | 60 | SkASSERT(fOffsetArrays[id]->count() > 0); |
michael@0 | 61 | if (max < fOffsetArrays[id]->min() || min > fOffsetArrays[id]->max()) { |
michael@0 | 62 | return false; |
michael@0 | 63 | } |
michael@0 | 64 | |
michael@0 | 65 | return true; |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | bool includes(int id, size_t offset) { |
michael@0 | 69 | SkASSERT(id < fOffsetArrays.count()); |
michael@0 | 70 | |
michael@0 | 71 | OffsetArray* array = fOffsetArrays[id]; |
michael@0 | 72 | |
michael@0 | 73 | for (int i = 0; i < array->fOffsets.count(); ++i) { |
michael@0 | 74 | if (array->fOffsets[i] == offset) { |
michael@0 | 75 | return true; |
michael@0 | 76 | } else if (array->fOffsets[i] > offset) { |
michael@0 | 77 | return false; |
michael@0 | 78 | } |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | // Calls to 'includes' should be gaurded by an overlap() call, so we |
michael@0 | 82 | // should always find something. |
michael@0 | 83 | SkASSERT(0); |
michael@0 | 84 | return false; |
michael@0 | 85 | } |
michael@0 | 86 | |
michael@0 | 87 | protected: |
michael@0 | 88 | class OffsetArray { |
michael@0 | 89 | public: |
michael@0 | 90 | void add(size_t offset) { |
michael@0 | 91 | SkASSERT(fOffsets.count() == 0 || offset > this->max()); |
michael@0 | 92 | *fOffsets.append() = offset; |
michael@0 | 93 | } |
michael@0 | 94 | size_t min() const { |
michael@0 | 95 | SkASSERT(fOffsets.count() > 0); |
michael@0 | 96 | return fOffsets[0]; |
michael@0 | 97 | } |
michael@0 | 98 | size_t max() const { |
michael@0 | 99 | SkASSERT(fOffsets.count() > 0); |
michael@0 | 100 | return fOffsets[fOffsets.count()-1]; |
michael@0 | 101 | } |
michael@0 | 102 | int count() const { |
michael@0 | 103 | return fOffsets.count(); |
michael@0 | 104 | } |
michael@0 | 105 | |
michael@0 | 106 | SkTDArray<size_t> fOffsets; |
michael@0 | 107 | }; |
michael@0 | 108 | |
michael@0 | 109 | SkTDArray<OffsetArray*> fOffsetArrays; |
michael@0 | 110 | |
michael@0 | 111 | private: |
michael@0 | 112 | typedef SkRefCnt INHERITED; |
michael@0 | 113 | }; |
michael@0 | 114 | |
michael@0 | 115 | #endif |