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 2013 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 | #include "SkPDFResourceDict.h" |
michael@0 | 9 | #include "SkPostConfig.h" |
michael@0 | 10 | |
michael@0 | 11 | // Sanity check that the values of enum SkPDFResourceType correspond to the |
michael@0 | 12 | // expected values as defined in the arrays below. |
michael@0 | 13 | // If these are failing, you may need to update the resource_type_prefixes |
michael@0 | 14 | // and resource_type_names arrays below. |
michael@0 | 15 | SK_COMPILE_ASSERT(SkPDFResourceDict::kExtGState_ResourceType == 0, |
michael@0 | 16 | resource_type_mismatch); |
michael@0 | 17 | SK_COMPILE_ASSERT(SkPDFResourceDict::kPattern_ResourceType == 1, |
michael@0 | 18 | resource_type_mismatch); |
michael@0 | 19 | SK_COMPILE_ASSERT(SkPDFResourceDict::kXObject_ResourceType == 2, |
michael@0 | 20 | resource_type_mismatch); |
michael@0 | 21 | SK_COMPILE_ASSERT(SkPDFResourceDict::kFont_ResourceType == 3, |
michael@0 | 22 | resource_type_mismatch); |
michael@0 | 23 | |
michael@0 | 24 | static const char resource_type_prefixes[] = { |
michael@0 | 25 | 'G', |
michael@0 | 26 | 'P', |
michael@0 | 27 | 'X', |
michael@0 | 28 | 'F' |
michael@0 | 29 | }; |
michael@0 | 30 | |
michael@0 | 31 | static const char* resource_type_names[] = { |
michael@0 | 32 | "ExtGState", |
michael@0 | 33 | "Pattern", |
michael@0 | 34 | "XObject", |
michael@0 | 35 | "Font" |
michael@0 | 36 | }; |
michael@0 | 37 | |
michael@0 | 38 | static char get_resource_type_prefix( |
michael@0 | 39 | SkPDFResourceDict::SkPDFResourceType type) { |
michael@0 | 40 | SkASSERT(type >= 0); |
michael@0 | 41 | SkASSERT(type < SkPDFResourceDict::kResourceTypeCount); |
michael@0 | 42 | |
michael@0 | 43 | return resource_type_prefixes[type]; |
michael@0 | 44 | } |
michael@0 | 45 | |
michael@0 | 46 | static const char* get_resource_type_name( |
michael@0 | 47 | SkPDFResourceDict::SkPDFResourceType type) { |
michael@0 | 48 | SkASSERT(type >= 0); |
michael@0 | 49 | SkASSERT(type < SkPDFResourceDict::kResourceTypeCount); |
michael@0 | 50 | |
michael@0 | 51 | return resource_type_names[type]; |
michael@0 | 52 | } |
michael@0 | 53 | |
michael@0 | 54 | SkPDFResourceDict::SkPDFResourceDict() : SkPDFDict() { |
michael@0 | 55 | const char procs[][7] = {"PDF", "Text", "ImageB", "ImageC", "ImageI"}; |
michael@0 | 56 | SkPDFArray* procSets = SkNEW(SkPDFArray()); |
michael@0 | 57 | |
michael@0 | 58 | procSets->reserve(SK_ARRAY_COUNT(procs)); |
michael@0 | 59 | for (size_t i = 0; i < SK_ARRAY_COUNT(procs); i++) { |
michael@0 | 60 | procSets->appendName(procs[i]); |
michael@0 | 61 | } |
michael@0 | 62 | insert("ProcSets", procSets)->unref(); |
michael@0 | 63 | |
michael@0 | 64 | // Actual sub-dicts will be lazily added later |
michael@0 | 65 | fTypes.setCount(kResourceTypeCount); |
michael@0 | 66 | for (int i=0; i < kResourceTypeCount; i++) { |
michael@0 | 67 | fTypes[i] = NULL; |
michael@0 | 68 | } |
michael@0 | 69 | } |
michael@0 | 70 | |
michael@0 | 71 | SkPDFObject* SkPDFResourceDict::insertResourceAsReference( |
michael@0 | 72 | SkPDFResourceType type, int key, SkPDFObject* value) { |
michael@0 | 73 | SkAutoTUnref<SkPDFObjRef> ref(SkNEW_ARGS(SkPDFObjRef, (value))); |
michael@0 | 74 | insertResource(type, key, ref); |
michael@0 | 75 | fResources.add(value); |
michael@0 | 76 | |
michael@0 | 77 | return value; |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | void SkPDFResourceDict::getReferencedResources( |
michael@0 | 81 | const SkTSet<SkPDFObject*>& knownResourceObjects, |
michael@0 | 82 | SkTSet<SkPDFObject*>* newResourceObjects, |
michael@0 | 83 | bool recursive) const { |
michael@0 | 84 | // TODO: reserve not correct if we need to recursively explore. |
michael@0 | 85 | newResourceObjects->setReserve(newResourceObjects->count() + |
michael@0 | 86 | fResources.count()); |
michael@0 | 87 | |
michael@0 | 88 | for (int i = 0; i < fResources.count(); i++) { |
michael@0 | 89 | if (!knownResourceObjects.contains(fResources[i]) && |
michael@0 | 90 | !newResourceObjects->contains(fResources[i])) { |
michael@0 | 91 | newResourceObjects->add(fResources[i]); |
michael@0 | 92 | fResources[i]->ref(); |
michael@0 | 93 | if (recursive) { |
michael@0 | 94 | fResources[i]->getResources(knownResourceObjects, |
michael@0 | 95 | newResourceObjects); |
michael@0 | 96 | } |
michael@0 | 97 | } |
michael@0 | 98 | } |
michael@0 | 99 | } |
michael@0 | 100 | |
michael@0 | 101 | SkString SkPDFResourceDict::getResourceName( |
michael@0 | 102 | SkPDFResourceType type, int key) { |
michael@0 | 103 | SkString keyString; |
michael@0 | 104 | keyString.printf("%c%d", get_resource_type_prefix(type), key); |
michael@0 | 105 | return keyString; |
michael@0 | 106 | } |
michael@0 | 107 | |
michael@0 | 108 | SkPDFObject* SkPDFResourceDict::insertResource( |
michael@0 | 109 | SkPDFResourceType type, int key, SkPDFObject* value) { |
michael@0 | 110 | SkPDFDict* typeDict = fTypes[type]; |
michael@0 | 111 | if (NULL == typeDict) { |
michael@0 | 112 | SkAutoTUnref<SkPDFDict> newDict(SkNEW(SkPDFDict())); |
michael@0 | 113 | SkAutoTUnref<SkPDFName> typeName( |
michael@0 | 114 | SkNEW_ARGS(SkPDFName, (get_resource_type_name(type)))); |
michael@0 | 115 | insert(typeName, newDict); // ref counting handled here |
michael@0 | 116 | fTypes[type] = newDict; |
michael@0 | 117 | typeDict = newDict.get(); |
michael@0 | 118 | } |
michael@0 | 119 | |
michael@0 | 120 | SkAutoTUnref<SkPDFName> keyName( |
michael@0 | 121 | SkNEW_ARGS(SkPDFName, (getResourceName(type, key)))); |
michael@0 | 122 | typeDict->insert(keyName, value); |
michael@0 | 123 | return value; |
michael@0 | 124 | } |