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 "SkPathHeap.h" |
michael@0 | 9 | #include "SkPath.h" |
michael@0 | 10 | #include "SkStream.h" |
michael@0 | 11 | #include "SkReadBuffer.h" |
michael@0 | 12 | #include "SkTSearch.h" |
michael@0 | 13 | #include "SkWriteBuffer.h" |
michael@0 | 14 | #include <new> |
michael@0 | 15 | |
michael@0 | 16 | #define kPathCount 64 |
michael@0 | 17 | |
michael@0 | 18 | SkPathHeap::SkPathHeap() : fHeap(kPathCount * sizeof(SkPath)) { |
michael@0 | 19 | } |
michael@0 | 20 | |
michael@0 | 21 | SkPathHeap::SkPathHeap(SkReadBuffer& buffer) |
michael@0 | 22 | : fHeap(kPathCount * sizeof(SkPath)) { |
michael@0 | 23 | const int count = buffer.readInt(); |
michael@0 | 24 | |
michael@0 | 25 | fPaths.setCount(count); |
michael@0 | 26 | SkPath** ptr = fPaths.begin(); |
michael@0 | 27 | SkPath* p = (SkPath*)fHeap.allocThrow(count * sizeof(SkPath)); |
michael@0 | 28 | |
michael@0 | 29 | for (int i = 0; i < count; i++) { |
michael@0 | 30 | new (p) SkPath; |
michael@0 | 31 | buffer.readPath(p); |
michael@0 | 32 | *ptr++ = p; // record the pointer |
michael@0 | 33 | p++; // move to the next storage location |
michael@0 | 34 | } |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | SkPathHeap::~SkPathHeap() { |
michael@0 | 38 | SkPath** iter = fPaths.begin(); |
michael@0 | 39 | SkPath** stop = fPaths.end(); |
michael@0 | 40 | while (iter < stop) { |
michael@0 | 41 | (*iter)->~SkPath(); |
michael@0 | 42 | iter++; |
michael@0 | 43 | } |
michael@0 | 44 | } |
michael@0 | 45 | |
michael@0 | 46 | int SkPathHeap::append(const SkPath& path) { |
michael@0 | 47 | SkPath* p = (SkPath*)fHeap.allocThrow(sizeof(SkPath)); |
michael@0 | 48 | new (p) SkPath(path); |
michael@0 | 49 | *fPaths.append() = p; |
michael@0 | 50 | return fPaths.count(); |
michael@0 | 51 | } |
michael@0 | 52 | |
michael@0 | 53 | SkPathHeap::LookupEntry::LookupEntry(const SkPath& path) |
michael@0 | 54 | : fGenerationID(path.getGenerationID()), fStorageSlot(0) { |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | SkPathHeap::LookupEntry* SkPathHeap::addIfNotPresent(const SkPath& path) { |
michael@0 | 58 | LookupEntry searchKey(path); |
michael@0 | 59 | int index = SkTSearch<const LookupEntry, LookupEntry::Less>( |
michael@0 | 60 | fLookupTable.begin(), |
michael@0 | 61 | fLookupTable.count(), |
michael@0 | 62 | searchKey, |
michael@0 | 63 | sizeof(LookupEntry)); |
michael@0 | 64 | if (index < 0) { |
michael@0 | 65 | index = ~index; |
michael@0 | 66 | *fLookupTable.insert(index) = LookupEntry(path); |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | return &fLookupTable[index];; |
michael@0 | 70 | } |
michael@0 | 71 | |
michael@0 | 72 | int SkPathHeap::insert(const SkPath& path) { |
michael@0 | 73 | SkPathHeap::LookupEntry* entry = this->addIfNotPresent(path); |
michael@0 | 74 | |
michael@0 | 75 | if (entry->storageSlot() > 0) { |
michael@0 | 76 | return entry->storageSlot(); |
michael@0 | 77 | } |
michael@0 | 78 | |
michael@0 | 79 | int newSlot = this->append(path); |
michael@0 | 80 | SkASSERT(newSlot > 0); |
michael@0 | 81 | entry->setStorageSlot(newSlot); |
michael@0 | 82 | return newSlot; |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | void SkPathHeap::flatten(SkWriteBuffer& buffer) const { |
michael@0 | 86 | int count = fPaths.count(); |
michael@0 | 87 | |
michael@0 | 88 | buffer.writeInt(count); |
michael@0 | 89 | SkPath* const* iter = fPaths.begin(); |
michael@0 | 90 | SkPath* const* stop = fPaths.end(); |
michael@0 | 91 | while (iter < stop) { |
michael@0 | 92 | buffer.writePath(**iter); |
michael@0 | 93 | iter++; |
michael@0 | 94 | } |
michael@0 | 95 | } |