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 (c) 2002-2012 The ANGLE Project Authors. All rights reserved. |
michael@0 | 3 | // Use of this source code is governed by a BSD-style license that can be |
michael@0 | 4 | // found in the LICENSE file. |
michael@0 | 5 | // |
michael@0 | 6 | |
michael@0 | 7 | #include "compiler/MapLongVariableNames.h" |
michael@0 | 8 | |
michael@0 | 9 | #include "third_party/murmurhash/MurmurHash3.h" |
michael@0 | 10 | |
michael@0 | 11 | namespace { |
michael@0 | 12 | |
michael@0 | 13 | TString mapLongName(size_t id, const TString& name, bool isGlobal) |
michael@0 | 14 | { |
michael@0 | 15 | ASSERT(name.size() > MAX_SHORTENED_IDENTIFIER_SIZE); |
michael@0 | 16 | TStringStream stream; |
michael@0 | 17 | |
michael@0 | 18 | uint64_t hash[2] = {0, 0}; |
michael@0 | 19 | MurmurHash3_x64_128(name.data(), name.length(), 0, hash); |
michael@0 | 20 | |
michael@0 | 21 | // We want to avoid producing a string with a double underscore, |
michael@0 | 22 | // which would be an illegal GLSL identifier. We can assume that the |
michael@0 | 23 | // original identifier doesn't have a double underscore, otherwise |
michael@0 | 24 | // it's illegal anyway. |
michael@0 | 25 | stream << (name[0] == '_' ? "webgl" : "webgl_") |
michael@0 | 26 | << name.substr(0, 9) |
michael@0 | 27 | << (name[8] == '_' ? "" : "_") |
michael@0 | 28 | << std::hex |
michael@0 | 29 | << hash[0]; |
michael@0 | 30 | ASSERT(stream.str().length() <= MAX_SHORTENED_IDENTIFIER_SIZE); |
michael@0 | 31 | ASSERT(stream.str().length() >= MAX_SHORTENED_IDENTIFIER_SIZE - 2); |
michael@0 | 32 | return stream.str(); |
michael@0 | 33 | } |
michael@0 | 34 | |
michael@0 | 35 | LongNameMap* gLongNameMapInstance = NULL; |
michael@0 | 36 | |
michael@0 | 37 | } // anonymous namespace |
michael@0 | 38 | |
michael@0 | 39 | LongNameMap::LongNameMap() |
michael@0 | 40 | : refCount(0) |
michael@0 | 41 | { |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | LongNameMap::~LongNameMap() |
michael@0 | 45 | { |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | // static |
michael@0 | 49 | LongNameMap* LongNameMap::GetInstance() |
michael@0 | 50 | { |
michael@0 | 51 | if (gLongNameMapInstance == NULL) |
michael@0 | 52 | gLongNameMapInstance = new LongNameMap; |
michael@0 | 53 | gLongNameMapInstance->refCount++; |
michael@0 | 54 | return gLongNameMapInstance; |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | void LongNameMap::Release() |
michael@0 | 58 | { |
michael@0 | 59 | ASSERT(gLongNameMapInstance == this); |
michael@0 | 60 | ASSERT(refCount > 0); |
michael@0 | 61 | refCount--; |
michael@0 | 62 | if (refCount == 0) { |
michael@0 | 63 | delete gLongNameMapInstance; |
michael@0 | 64 | gLongNameMapInstance = NULL; |
michael@0 | 65 | } |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | const char* LongNameMap::Find(const char* originalName) const |
michael@0 | 69 | { |
michael@0 | 70 | std::map<std::string, std::string>::const_iterator it = mLongNameMap.find( |
michael@0 | 71 | originalName); |
michael@0 | 72 | if (it != mLongNameMap.end()) |
michael@0 | 73 | return (*it).second.c_str(); |
michael@0 | 74 | return NULL; |
michael@0 | 75 | } |
michael@0 | 76 | |
michael@0 | 77 | void LongNameMap::Insert(const char* originalName, const char* mappedName) |
michael@0 | 78 | { |
michael@0 | 79 | mLongNameMap.insert(std::map<std::string, std::string>::value_type( |
michael@0 | 80 | originalName, mappedName)); |
michael@0 | 81 | } |
michael@0 | 82 | |
michael@0 | 83 | size_t LongNameMap::Size() const |
michael@0 | 84 | { |
michael@0 | 85 | return mLongNameMap.size(); |
michael@0 | 86 | } |
michael@0 | 87 | |
michael@0 | 88 | MapLongVariableNames::MapLongVariableNames(LongNameMap* globalMap) |
michael@0 | 89 | { |
michael@0 | 90 | ASSERT(globalMap); |
michael@0 | 91 | mGlobalMap = globalMap; |
michael@0 | 92 | } |
michael@0 | 93 | |
michael@0 | 94 | void MapLongVariableNames::visitSymbol(TIntermSymbol* symbol) |
michael@0 | 95 | { |
michael@0 | 96 | ASSERT(symbol != NULL); |
michael@0 | 97 | if (symbol->getSymbol().size() > MAX_SHORTENED_IDENTIFIER_SIZE) { |
michael@0 | 98 | switch (symbol->getQualifier()) { |
michael@0 | 99 | case EvqVaryingIn: |
michael@0 | 100 | case EvqVaryingOut: |
michael@0 | 101 | case EvqInvariantVaryingIn: |
michael@0 | 102 | case EvqInvariantVaryingOut: |
michael@0 | 103 | case EvqUniform: |
michael@0 | 104 | symbol->setSymbol( |
michael@0 | 105 | mapGlobalLongName(symbol->getSymbol())); |
michael@0 | 106 | break; |
michael@0 | 107 | default: |
michael@0 | 108 | symbol->setSymbol( |
michael@0 | 109 | mapLongName(symbol->getId(), symbol->getSymbol(), false)); |
michael@0 | 110 | break; |
michael@0 | 111 | }; |
michael@0 | 112 | } |
michael@0 | 113 | } |
michael@0 | 114 | |
michael@0 | 115 | bool MapLongVariableNames::visitLoop(Visit, TIntermLoop* node) |
michael@0 | 116 | { |
michael@0 | 117 | if (node->getInit()) |
michael@0 | 118 | node->getInit()->traverse(this); |
michael@0 | 119 | return true; |
michael@0 | 120 | } |
michael@0 | 121 | |
michael@0 | 122 | TString MapLongVariableNames::mapGlobalLongName(const TString& name) |
michael@0 | 123 | { |
michael@0 | 124 | ASSERT(mGlobalMap); |
michael@0 | 125 | const char* mappedName = mGlobalMap->Find(name.c_str()); |
michael@0 | 126 | if (mappedName != NULL) |
michael@0 | 127 | return mappedName; |
michael@0 | 128 | size_t id = mGlobalMap->Size(); |
michael@0 | 129 | TString rt = mapLongName(id, name, true); |
michael@0 | 130 | mGlobalMap->Insert(name.c_str(), rt.c_str()); |
michael@0 | 131 | return rt; |
michael@0 | 132 | } |