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 "SkFlattenable.h" |
michael@0 | 9 | #include "SkPtrRecorder.h" |
michael@0 | 10 | |
michael@0 | 11 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 12 | |
michael@0 | 13 | void SkFlattenable::flatten(SkWriteBuffer&) const |
michael@0 | 14 | { |
michael@0 | 15 | /* we don't write anything at the moment, but this allows our subclasses |
michael@0 | 16 | to not know that, since we want them to always call INHERITED::flatten() |
michael@0 | 17 | in their code. |
michael@0 | 18 | */ |
michael@0 | 19 | } |
michael@0 | 20 | |
michael@0 | 21 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 22 | |
michael@0 | 23 | SkNamedFactorySet::SkNamedFactorySet() : fNextAddedFactory(0) {} |
michael@0 | 24 | |
michael@0 | 25 | uint32_t SkNamedFactorySet::find(SkFlattenable::Factory factory) { |
michael@0 | 26 | uint32_t index = fFactorySet.find(factory); |
michael@0 | 27 | if (index > 0) { |
michael@0 | 28 | return index; |
michael@0 | 29 | } |
michael@0 | 30 | const char* name = SkFlattenable::FactoryToName(factory); |
michael@0 | 31 | if (NULL == name) { |
michael@0 | 32 | return 0; |
michael@0 | 33 | } |
michael@0 | 34 | *fNames.append() = name; |
michael@0 | 35 | return fFactorySet.add(factory); |
michael@0 | 36 | } |
michael@0 | 37 | |
michael@0 | 38 | const char* SkNamedFactorySet::getNextAddedFactoryName() { |
michael@0 | 39 | if (fNextAddedFactory < fNames.count()) { |
michael@0 | 40 | return fNames[fNextAddedFactory++]; |
michael@0 | 41 | } |
michael@0 | 42 | return NULL; |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 46 | |
michael@0 | 47 | SkRefCntSet::~SkRefCntSet() { |
michael@0 | 48 | // call this now, while our decPtr() is sill in scope |
michael@0 | 49 | this->reset(); |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | void SkRefCntSet::incPtr(void* ptr) { |
michael@0 | 53 | ((SkRefCnt*)ptr)->ref(); |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | void SkRefCntSet::decPtr(void* ptr) { |
michael@0 | 57 | ((SkRefCnt*)ptr)->unref(); |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 61 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 62 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 63 | |
michael@0 | 64 | #define MAX_ENTRY_COUNT 1024 |
michael@0 | 65 | |
michael@0 | 66 | struct Entry { |
michael@0 | 67 | const char* fName; |
michael@0 | 68 | SkFlattenable::Factory fFactory; |
michael@0 | 69 | SkFlattenable::Type fType; |
michael@0 | 70 | }; |
michael@0 | 71 | |
michael@0 | 72 | static int gCount; |
michael@0 | 73 | static Entry gEntries[MAX_ENTRY_COUNT]; |
michael@0 | 74 | |
michael@0 | 75 | void SkFlattenable::Register(const char name[], Factory factory, SkFlattenable::Type type) { |
michael@0 | 76 | SkASSERT(name); |
michael@0 | 77 | SkASSERT(factory); |
michael@0 | 78 | |
michael@0 | 79 | static bool gOnce = false; |
michael@0 | 80 | if (!gOnce) { |
michael@0 | 81 | gCount = 0; |
michael@0 | 82 | gOnce = true; |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | SkASSERT(gCount < MAX_ENTRY_COUNT); |
michael@0 | 86 | |
michael@0 | 87 | gEntries[gCount].fName = name; |
michael@0 | 88 | gEntries[gCount].fFactory = factory; |
michael@0 | 89 | gEntries[gCount].fType = type; |
michael@0 | 90 | gCount += 1; |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | #ifdef SK_DEBUG |
michael@0 | 94 | static void report_no_entries(const char* functionName) { |
michael@0 | 95 | if (!gCount) { |
michael@0 | 96 | SkDebugf("%s has no registered name/factory/type entries." |
michael@0 | 97 | " Call SkFlattenable::InitializeFlattenablesIfNeeded() before using gEntries", |
michael@0 | 98 | functionName); |
michael@0 | 99 | } |
michael@0 | 100 | } |
michael@0 | 101 | #endif |
michael@0 | 102 | |
michael@0 | 103 | SkFlattenable::Factory SkFlattenable::NameToFactory(const char name[]) { |
michael@0 | 104 | InitializeFlattenablesIfNeeded(); |
michael@0 | 105 | #ifdef SK_DEBUG |
michael@0 | 106 | report_no_entries(__FUNCTION__); |
michael@0 | 107 | #endif |
michael@0 | 108 | const Entry* entries = gEntries; |
michael@0 | 109 | for (int i = gCount - 1; i >= 0; --i) { |
michael@0 | 110 | if (strcmp(entries[i].fName, name) == 0) { |
michael@0 | 111 | return entries[i].fFactory; |
michael@0 | 112 | } |
michael@0 | 113 | } |
michael@0 | 114 | return NULL; |
michael@0 | 115 | } |
michael@0 | 116 | |
michael@0 | 117 | bool SkFlattenable::NameToType(const char name[], SkFlattenable::Type* type) { |
michael@0 | 118 | SkASSERT(NULL != type); |
michael@0 | 119 | InitializeFlattenablesIfNeeded(); |
michael@0 | 120 | #ifdef SK_DEBUG |
michael@0 | 121 | report_no_entries(__FUNCTION__); |
michael@0 | 122 | #endif |
michael@0 | 123 | const Entry* entries = gEntries; |
michael@0 | 124 | for (int i = gCount - 1; i >= 0; --i) { |
michael@0 | 125 | if (strcmp(entries[i].fName, name) == 0) { |
michael@0 | 126 | *type = entries[i].fType; |
michael@0 | 127 | return true; |
michael@0 | 128 | } |
michael@0 | 129 | } |
michael@0 | 130 | return false; |
michael@0 | 131 | } |
michael@0 | 132 | |
michael@0 | 133 | const char* SkFlattenable::FactoryToName(Factory fact) { |
michael@0 | 134 | InitializeFlattenablesIfNeeded(); |
michael@0 | 135 | #ifdef SK_DEBUG |
michael@0 | 136 | report_no_entries(__FUNCTION__); |
michael@0 | 137 | #endif |
michael@0 | 138 | const Entry* entries = gEntries; |
michael@0 | 139 | for (int i = gCount - 1; i >= 0; --i) { |
michael@0 | 140 | if (entries[i].fFactory == fact) { |
michael@0 | 141 | return entries[i].fName; |
michael@0 | 142 | } |
michael@0 | 143 | } |
michael@0 | 144 | return NULL; |
michael@0 | 145 | } |