gfx/skia/trunk/src/ports/SkTLS_win.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

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.

     1 /*
     2  * Copyright 2013 Google Inc.
     3  *
     4  * Use of this source code is governed by a BSD-style license that can be
     5  * found in the LICENSE file.
     6  */
     8 #include "SkTLS.h"
     9 #include "SkThread.h"
    11 static bool gOnce = false;
    12 static DWORD gTlsIndex;
    13 SK_DECLARE_STATIC_MUTEX(gMutex);
    15 void* SkTLS::PlatformGetSpecific(bool forceCreateTheSlot) {
    16     if (!forceCreateTheSlot && !gOnce) {
    17         return NULL;
    18     }
    20     if (!gOnce) {
    21         SkAutoMutexAcquire tmp(gMutex);
    22         if (!gOnce) {
    23             gTlsIndex = TlsAlloc();
    24             gOnce = true;
    25         }
    26     }
    27     return TlsGetValue(gTlsIndex);
    28 }
    30 void SkTLS::PlatformSetSpecific(void* ptr) {
    31     SkASSERT(gOnce);
    32     (void)TlsSetValue(gTlsIndex, ptr);
    33 }
    35 // Call TLS destructors on thread exit. Code based on Chromium's
    36 // base/threading/thread_local_storage_win.cc
    37 #ifdef _WIN64
    39 #pragma comment(linker, "/INCLUDE:_tls_used")
    40 #pragma comment(linker, "/INCLUDE:skia_tls_callback")
    42 #else
    44 #pragma comment(linker, "/INCLUDE:__tls_used")
    45 #pragma comment(linker, "/INCLUDE:_skia_tls_callback")
    47 #endif
    49 void NTAPI onTLSCallback(PVOID unused, DWORD reason, PVOID unused2) {
    50     if ((DLL_THREAD_DETACH == reason || DLL_PROCESS_DETACH == reason) && gOnce) {
    51         void* ptr = TlsGetValue(gTlsIndex);
    52         if (ptr != NULL) {
    53             SkTLS::Destructor(ptr);
    54             TlsSetValue(gTlsIndex, NULL);
    55         }
    56     }
    57 }
    59 extern "C" {
    61 #ifdef _WIN64
    63 #pragma const_seg(".CRT$XLB")
    64 extern const PIMAGE_TLS_CALLBACK skia_tls_callback;
    65 const PIMAGE_TLS_CALLBACK skia_tls_callback = onTLSCallback;
    66 #pragma const_seg()
    68 #else
    70 #pragma data_seg(".CRT$XLB")
    71 PIMAGE_TLS_CALLBACK skia_tls_callback = onTLSCallback;
    72 #pragma data_seg()
    74 #endif
    75 }

mercurial