gfx/skia/trunk/src/ports/SkOSFile_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.

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 "SkOSFile.h"
michael@0 9
michael@0 10 #include "SkTFitsIn.h"
michael@0 11
michael@0 12 #include <io.h>
michael@0 13 #include <stdio.h>
michael@0 14 #include <sys/stat.h>
michael@0 15
michael@0 16 typedef struct {
michael@0 17 ULONGLONG fVolume;
michael@0 18 ULONGLONG fLsbSize;
michael@0 19 ULONGLONG fMsbSize;
michael@0 20 } SkFILEID;
michael@0 21
michael@0 22 static bool sk_ino(SkFILE* f, SkFILEID* id) {
michael@0 23 int fileno = _fileno((FILE*)f);
michael@0 24 if (fileno < 0) {
michael@0 25 return false;
michael@0 26 }
michael@0 27
michael@0 28 HANDLE file = (HANDLE)_get_osfhandle(fileno);
michael@0 29 if (INVALID_HANDLE_VALUE == file) {
michael@0 30 return false;
michael@0 31 }
michael@0 32
michael@0 33 //TODO: call GetFileInformationByHandleEx on Vista and later with FileIdInfo.
michael@0 34 BY_HANDLE_FILE_INFORMATION info;
michael@0 35 if (0 == GetFileInformationByHandle(file, &info)) {
michael@0 36 return false;
michael@0 37 }
michael@0 38 id->fVolume = info.dwVolumeSerialNumber;
michael@0 39 id->fLsbSize = info.nFileIndexLow + (((ULONGLONG)info.nFileIndexHigh) << 32);
michael@0 40 id->fMsbSize = 0;
michael@0 41
michael@0 42 return true;
michael@0 43 }
michael@0 44
michael@0 45 bool sk_fidentical(SkFILE* a, SkFILE* b) {
michael@0 46 SkFILEID aID, bID;
michael@0 47 return sk_ino(a, &aID) && sk_ino(b, &bID)
michael@0 48 && aID.fLsbSize == bID.fLsbSize
michael@0 49 && aID.fMsbSize == bID.fMsbSize
michael@0 50 && aID.fVolume == bID.fVolume;
michael@0 51 }
michael@0 52
michael@0 53 class SkAutoNullKernelHandle : SkNoncopyable {
michael@0 54 public:
michael@0 55 SkAutoNullKernelHandle(const HANDLE handle) : fHandle(handle) { }
michael@0 56 ~SkAutoNullKernelHandle() { CloseHandle(fHandle); }
michael@0 57 operator HANDLE() const { return fHandle; }
michael@0 58 bool isValid() const { return NULL != fHandle; }
michael@0 59 private:
michael@0 60 HANDLE fHandle;
michael@0 61 };
michael@0 62 typedef SkAutoNullKernelHandle SkAutoWinMMap;
michael@0 63
michael@0 64 void sk_fmunmap(const void* addr, size_t) {
michael@0 65 UnmapViewOfFile(addr);
michael@0 66 }
michael@0 67
michael@0 68 void* sk_fdmmap(int fileno, size_t* length) {
michael@0 69 HANDLE file = (HANDLE)_get_osfhandle(fileno);
michael@0 70 if (INVALID_HANDLE_VALUE == file) {
michael@0 71 return NULL;
michael@0 72 }
michael@0 73
michael@0 74 LARGE_INTEGER fileSize;
michael@0 75 if (0 == GetFileSizeEx(file, &fileSize)) {
michael@0 76 //TODO: use SK_TRACEHR(GetLastError(), "Could not get file size.") to report.
michael@0 77 return NULL;
michael@0 78 }
michael@0 79 if (!SkTFitsIn<size_t>(fileSize.QuadPart)) {
michael@0 80 return NULL;
michael@0 81 }
michael@0 82
michael@0 83 SkAutoWinMMap mmap(CreateFileMapping(file, NULL, PAGE_READONLY, 0, 0, NULL));
michael@0 84 if (!mmap.isValid()) {
michael@0 85 //TODO: use SK_TRACEHR(GetLastError(), "Could not create file mapping.") to report.
michael@0 86 return NULL;
michael@0 87 }
michael@0 88
michael@0 89 // Eventually call UnmapViewOfFile
michael@0 90 void* addr = MapViewOfFile(mmap, FILE_MAP_READ, 0, 0, 0);
michael@0 91 if (NULL == addr) {
michael@0 92 //TODO: use SK_TRACEHR(GetLastError(), "Could not map view of file.") to report.
michael@0 93 return NULL;
michael@0 94 }
michael@0 95
michael@0 96 *length = static_cast<size_t>(fileSize.QuadPart);
michael@0 97 return addr;
michael@0 98 }
michael@0 99
michael@0 100 int sk_fileno(SkFILE* f) {
michael@0 101 return _fileno((FILE*)f);
michael@0 102 }
michael@0 103
michael@0 104 void* sk_fmmap(SkFILE* f, size_t* length) {
michael@0 105 int fileno = sk_fileno(f);
michael@0 106 if (fileno < 0) {
michael@0 107 return NULL;
michael@0 108 }
michael@0 109
michael@0 110 return sk_fdmmap(fileno, length);
michael@0 111 }

mercurial