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 "gl/GrGLExtensions.h" |
michael@0 | 9 | #include "gl/GrGLDefines.h" |
michael@0 | 10 | #include "gl/GrGLUtil.h" |
michael@0 | 11 | |
michael@0 | 12 | #include "SkTSearch.h" |
michael@0 | 13 | #include "SkTSort.h" |
michael@0 | 14 | |
michael@0 | 15 | namespace { // This cannot be static because it is used as a template parameter. |
michael@0 | 16 | inline bool extension_compare(const SkString& a, const SkString& b) { |
michael@0 | 17 | return strcmp(a.c_str(), b.c_str()) < 0; |
michael@0 | 18 | } |
michael@0 | 19 | } |
michael@0 | 20 | |
michael@0 | 21 | // finds the index of ext in strings or a negative result if ext is not found. |
michael@0 | 22 | static int find_string(const SkTArray<SkString>& strings, const char ext[]) { |
michael@0 | 23 | if (strings.empty()) { |
michael@0 | 24 | return -1; |
michael@0 | 25 | } |
michael@0 | 26 | SkString extensionStr(ext); |
michael@0 | 27 | int idx = SkTSearch<SkString, extension_compare>(&strings.front(), |
michael@0 | 28 | strings.count(), |
michael@0 | 29 | extensionStr, |
michael@0 | 30 | sizeof(SkString)); |
michael@0 | 31 | return idx; |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | GrGLExtensions::GrGLExtensions(const GrGLExtensions& that) : fStrings(SkNEW(SkTArray<SkString>)) { |
michael@0 | 35 | *this = that; |
michael@0 | 36 | } |
michael@0 | 37 | |
michael@0 | 38 | GrGLExtensions& GrGLExtensions::operator=(const GrGLExtensions& that) { |
michael@0 | 39 | *fStrings = *that.fStrings; |
michael@0 | 40 | fInitialized = that.fInitialized; |
michael@0 | 41 | return *this; |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | bool GrGLExtensions::init(GrGLStandard standard, |
michael@0 | 45 | GrGLGetStringProc getString, |
michael@0 | 46 | GrGLGetStringiProc getStringi, |
michael@0 | 47 | GrGLGetIntegervProc getIntegerv) { |
michael@0 | 48 | fInitialized = false; |
michael@0 | 49 | fStrings->reset(); |
michael@0 | 50 | |
michael@0 | 51 | if (NULL == getString) { |
michael@0 | 52 | return false; |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | // glGetStringi and indexed extensions were added in version 3.0 of desktop GL and ES. |
michael@0 | 56 | const GrGLubyte* verString = getString(GR_GL_VERSION); |
michael@0 | 57 | if (NULL == verString) { |
michael@0 | 58 | return false; |
michael@0 | 59 | } |
michael@0 | 60 | GrGLVersion version = GrGLGetVersionFromString((const char*) verString); |
michael@0 | 61 | bool indexed = version >= GR_GL_VER(3, 0); |
michael@0 | 62 | |
michael@0 | 63 | if (indexed) { |
michael@0 | 64 | if (NULL == getStringi || NULL == getIntegerv) { |
michael@0 | 65 | return false; |
michael@0 | 66 | } |
michael@0 | 67 | GrGLint extensionCnt = 0; |
michael@0 | 68 | getIntegerv(GR_GL_NUM_EXTENSIONS, &extensionCnt); |
michael@0 | 69 | fStrings->push_back_n(extensionCnt); |
michael@0 | 70 | for (int i = 0; i < extensionCnt; ++i) { |
michael@0 | 71 | const char* ext = (const char*) getStringi(GR_GL_EXTENSIONS, i); |
michael@0 | 72 | (*fStrings)[i] = ext; |
michael@0 | 73 | } |
michael@0 | 74 | } else { |
michael@0 | 75 | const char* extensions = (const char*) getString(GR_GL_EXTENSIONS); |
michael@0 | 76 | if (NULL == extensions) { |
michael@0 | 77 | return false; |
michael@0 | 78 | } |
michael@0 | 79 | while (true) { |
michael@0 | 80 | // skip over multiple spaces between extensions |
michael@0 | 81 | while (' ' == *extensions) { |
michael@0 | 82 | ++extensions; |
michael@0 | 83 | } |
michael@0 | 84 | // quit once we reach the end of the string. |
michael@0 | 85 | if ('\0' == *extensions) { |
michael@0 | 86 | break; |
michael@0 | 87 | } |
michael@0 | 88 | // we found an extension |
michael@0 | 89 | size_t length = strcspn(extensions, " "); |
michael@0 | 90 | fStrings->push_back().set(extensions, length); |
michael@0 | 91 | extensions += length; |
michael@0 | 92 | } |
michael@0 | 93 | } |
michael@0 | 94 | if (!fStrings->empty()) { |
michael@0 | 95 | SkTLessFunctionToFunctorAdaptor<SkString, extension_compare> cmp; |
michael@0 | 96 | SkTQSort(&fStrings->front(), &fStrings->back(), cmp); |
michael@0 | 97 | } |
michael@0 | 98 | fInitialized = true; |
michael@0 | 99 | return true; |
michael@0 | 100 | } |
michael@0 | 101 | |
michael@0 | 102 | bool GrGLExtensions::has(const char ext[]) const { |
michael@0 | 103 | SkASSERT(fInitialized); |
michael@0 | 104 | return find_string(*fStrings, ext) >= 0; |
michael@0 | 105 | } |
michael@0 | 106 | |
michael@0 | 107 | bool GrGLExtensions::remove(const char ext[]) { |
michael@0 | 108 | SkASSERT(fInitialized); |
michael@0 | 109 | int idx = find_string(*fStrings, ext); |
michael@0 | 110 | if (idx >= 0) { |
michael@0 | 111 | // This is not terribly effecient but we really only expect this function to be called at |
michael@0 | 112 | // most a handful of times when our test programs start. |
michael@0 | 113 | SkAutoTDelete< SkTArray<SkString> > oldStrings(fStrings.detach()); |
michael@0 | 114 | fStrings.reset(SkNEW(SkTArray<SkString>(oldStrings->count() - 1))); |
michael@0 | 115 | fStrings->push_back_n(idx, &oldStrings->front()); |
michael@0 | 116 | fStrings->push_back_n(oldStrings->count() - idx - 1, &(*oldStrings)[idx] + 1); |
michael@0 | 117 | return true; |
michael@0 | 118 | } else { |
michael@0 | 119 | return false; |
michael@0 | 120 | } |
michael@0 | 121 | } |
michael@0 | 122 | |
michael@0 | 123 | void GrGLExtensions::add(const char ext[]) { |
michael@0 | 124 | int idx = find_string(*fStrings, ext); |
michael@0 | 125 | if (idx < 0) { |
michael@0 | 126 | // This is not the most effecient approach since we end up doing a full sort of the |
michael@0 | 127 | // extensions after the add |
michael@0 | 128 | fStrings->push_back().set(ext); |
michael@0 | 129 | SkTLessFunctionToFunctorAdaptor<SkString, extension_compare> cmp; |
michael@0 | 130 | SkTQSort(&fStrings->front(), &fStrings->back(), cmp); |
michael@0 | 131 | } |
michael@0 | 132 | } |
michael@0 | 133 | |
michael@0 | 134 | void GrGLExtensions::print(const char* sep) const { |
michael@0 | 135 | if (NULL == sep) { |
michael@0 | 136 | sep = " "; |
michael@0 | 137 | } |
michael@0 | 138 | int cnt = fStrings->count(); |
michael@0 | 139 | for (int i = 0; i < cnt; ++i) { |
michael@0 | 140 | GrPrintf("%s%s", (*fStrings)[i].c_str(), (i < cnt - 1) ? sep : ""); |
michael@0 | 141 | } |
michael@0 | 142 | } |