Thu, 15 Jan 2015 15:59:08 +0100
Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #pragma once |
michael@0 | 7 | |
michael@0 | 8 | /* this file is included by exe stubs, don't pull xpcom into it. */ |
michael@0 | 9 | |
michael@0 | 10 | #include <d3d10_1.h> |
michael@0 | 11 | #include <dxgi.h> |
michael@0 | 12 | #include <d3d10misc.h> |
michael@0 | 13 | |
michael@0 | 14 | /* |
michael@0 | 15 | * Checks to see if the d3d implementation supports feature level 9.3 or |
michael@0 | 16 | * above. Metrofx can't run on systems that fail this check. |
michael@0 | 17 | * |
michael@0 | 18 | * Note, this can hit perf, don't call this unless you absolutely have to. |
michael@0 | 19 | * Both the ceh and winrt widget code save a cached result in the registry. |
michael@0 | 20 | */ |
michael@0 | 21 | static bool D3DFeatureLevelCheck() |
michael@0 | 22 | { |
michael@0 | 23 | HMODULE dxgiModule = LoadLibraryA("dxgi.dll"); |
michael@0 | 24 | if (!dxgiModule) { |
michael@0 | 25 | return false; |
michael@0 | 26 | } |
michael@0 | 27 | decltype(CreateDXGIFactory1)* createDXGIFactory1 = |
michael@0 | 28 | (decltype(CreateDXGIFactory1)*) GetProcAddress(dxgiModule, "CreateDXGIFactory1"); |
michael@0 | 29 | if (!createDXGIFactory1) { |
michael@0 | 30 | FreeLibrary(dxgiModule); |
michael@0 | 31 | return false; |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | HMODULE d3d10module = LoadLibraryA("d3d10_1.dll"); |
michael@0 | 35 | if (!d3d10module) { |
michael@0 | 36 | FreeLibrary(dxgiModule); |
michael@0 | 37 | return false; |
michael@0 | 38 | } |
michael@0 | 39 | decltype(D3D10CreateDevice1)* createD3DDevice = |
michael@0 | 40 | (decltype(D3D10CreateDevice1)*) GetProcAddress(d3d10module, |
michael@0 | 41 | "D3D10CreateDevice1"); |
michael@0 | 42 | if (!createD3DDevice) { |
michael@0 | 43 | FreeLibrary(d3d10module); |
michael@0 | 44 | FreeLibrary(dxgiModule); |
michael@0 | 45 | return false; |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | IDXGIFactory1* factory1; |
michael@0 | 49 | if (FAILED(createDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&factory1))) { |
michael@0 | 50 | FreeLibrary(d3d10module); |
michael@0 | 51 | FreeLibrary(dxgiModule); |
michael@0 | 52 | return false; |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | IDXGIAdapter1* adapter1; |
michael@0 | 56 | if (FAILED(factory1->EnumAdapters1(0, &adapter1))) { |
michael@0 | 57 | factory1->Release(); |
michael@0 | 58 | FreeLibrary(d3d10module); |
michael@0 | 59 | FreeLibrary(dxgiModule); |
michael@0 | 60 | return false; |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | // Try for DX10.1 |
michael@0 | 64 | ID3D10Device1* device; |
michael@0 | 65 | if (FAILED(createD3DDevice(adapter1, D3D10_DRIVER_TYPE_HARDWARE, nullptr, |
michael@0 | 66 | D3D10_CREATE_DEVICE_BGRA_SUPPORT | |
michael@0 | 67 | D3D10_CREATE_DEVICE_PREVENT_INTERNAL_THREADING_OPTIMIZATIONS, |
michael@0 | 68 | D3D10_FEATURE_LEVEL_10_1, |
michael@0 | 69 | D3D10_1_SDK_VERSION, &device))) { |
michael@0 | 70 | // Try for DX10 |
michael@0 | 71 | if (FAILED(createD3DDevice(adapter1, D3D10_DRIVER_TYPE_HARDWARE, nullptr, |
michael@0 | 72 | D3D10_CREATE_DEVICE_BGRA_SUPPORT | |
michael@0 | 73 | D3D10_CREATE_DEVICE_PREVENT_INTERNAL_THREADING_OPTIMIZATIONS, |
michael@0 | 74 | D3D10_FEATURE_LEVEL_10_0, |
michael@0 | 75 | D3D10_1_SDK_VERSION, &device))) { |
michael@0 | 76 | // Try for DX9.3 (we fall back to cairo and cairo has support for D3D 9.3) |
michael@0 | 77 | if (FAILED(createD3DDevice(adapter1, D3D10_DRIVER_TYPE_HARDWARE, nullptr, |
michael@0 | 78 | D3D10_CREATE_DEVICE_BGRA_SUPPORT | |
michael@0 | 79 | D3D10_CREATE_DEVICE_PREVENT_INTERNAL_THREADING_OPTIMIZATIONS, |
michael@0 | 80 | D3D10_FEATURE_LEVEL_9_3, |
michael@0 | 81 | D3D10_1_SDK_VERSION, &device))) { |
michael@0 | 82 | adapter1->Release(); |
michael@0 | 83 | factory1->Release(); |
michael@0 | 84 | FreeLibrary(d3d10module); |
michael@0 | 85 | FreeLibrary(dxgiModule); |
michael@0 | 86 | return false; |
michael@0 | 87 | } |
michael@0 | 88 | } |
michael@0 | 89 | } |
michael@0 | 90 | device->Release(); |
michael@0 | 91 | adapter1->Release(); |
michael@0 | 92 | factory1->Release(); |
michael@0 | 93 | FreeLibrary(d3d10module); |
michael@0 | 94 | FreeLibrary(dxgiModule); |
michael@0 | 95 | return true; |
michael@0 | 96 | } |