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 "SkOSFile.h" |
michael@0 | 9 | |
michael@0 | 10 | #include "SkTFitsIn.h" |
michael@0 | 11 | |
michael@0 | 12 | #include <stdio.h> |
michael@0 | 13 | #include <sys/mman.h> |
michael@0 | 14 | #include <sys/stat.h> |
michael@0 | 15 | #include <sys/types.h> |
michael@0 | 16 | |
michael@0 | 17 | typedef struct { |
michael@0 | 18 | dev_t dev; |
michael@0 | 19 | ino_t ino; |
michael@0 | 20 | } SkFILEID; |
michael@0 | 21 | |
michael@0 | 22 | static bool sk_ino(SkFILE* a, SkFILEID* id) { |
michael@0 | 23 | int fd = fileno((FILE*)a); |
michael@0 | 24 | if (fd < 0) { |
michael@0 | 25 | return 0; |
michael@0 | 26 | } |
michael@0 | 27 | struct stat status; |
michael@0 | 28 | if (0 != fstat(fd, &status)) { |
michael@0 | 29 | return 0; |
michael@0 | 30 | } |
michael@0 | 31 | id->dev = status.st_dev; |
michael@0 | 32 | id->ino = status.st_ino; |
michael@0 | 33 | return true; |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | bool sk_fidentical(SkFILE* a, SkFILE* b) { |
michael@0 | 37 | SkFILEID aID, bID; |
michael@0 | 38 | return sk_ino(a, &aID) && sk_ino(b, &bID) |
michael@0 | 39 | && aID.ino == bID.ino |
michael@0 | 40 | && aID.dev == bID.dev; |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | void sk_fmunmap(const void* addr, size_t length) { |
michael@0 | 44 | munmap(const_cast<void*>(addr), length); |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | void* sk_fdmmap(int fd, size_t* size) { |
michael@0 | 48 | struct stat status; |
michael@0 | 49 | if (0 != fstat(fd, &status)) { |
michael@0 | 50 | return NULL; |
michael@0 | 51 | } |
michael@0 | 52 | if (!S_ISREG(status.st_mode)) { |
michael@0 | 53 | return NULL; |
michael@0 | 54 | } |
michael@0 | 55 | if (!SkTFitsIn<size_t>(status.st_size)) { |
michael@0 | 56 | return NULL; |
michael@0 | 57 | } |
michael@0 | 58 | size_t fileSize = static_cast<size_t>(status.st_size); |
michael@0 | 59 | |
michael@0 | 60 | void* addr = mmap(NULL, fileSize, PROT_READ, MAP_PRIVATE, fd, 0); |
michael@0 | 61 | if (MAP_FAILED == addr) { |
michael@0 | 62 | return NULL; |
michael@0 | 63 | } |
michael@0 | 64 | |
michael@0 | 65 | *size = fileSize; |
michael@0 | 66 | return addr; |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | int sk_fileno(SkFILE* f) { |
michael@0 | 70 | return fileno((FILE*)f); |
michael@0 | 71 | } |
michael@0 | 72 | |
michael@0 | 73 | void* sk_fmmap(SkFILE* f, size_t* size) { |
michael@0 | 74 | int fd = sk_fileno(f); |
michael@0 | 75 | if (fd < 0) { |
michael@0 | 76 | return NULL; |
michael@0 | 77 | } |
michael@0 | 78 | |
michael@0 | 79 | return sk_fdmmap(fd, size); |
michael@0 | 80 | } |