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 | /* |
michael@0 | 3 | * Copyright 2006 The Android Open Source Project |
michael@0 | 4 | * |
michael@0 | 5 | * Use of this source code is governed by a BSD-style license that can be |
michael@0 | 6 | * found in the LICENSE file. |
michael@0 | 7 | */ |
michael@0 | 8 | |
michael@0 | 9 | |
michael@0 | 10 | // TODO: add unittests for all these operations |
michael@0 | 11 | |
michael@0 | 12 | #ifndef SkOSFile_DEFINED |
michael@0 | 13 | #define SkOSFile_DEFINED |
michael@0 | 14 | |
michael@0 | 15 | #include "SkString.h" |
michael@0 | 16 | |
michael@0 | 17 | #if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_ANDROID) || defined(SK_BUILD_FOR_IOS) |
michael@0 | 18 | #include <dirent.h> |
michael@0 | 19 | #endif |
michael@0 | 20 | |
michael@0 | 21 | #include <stddef.h> // ptrdiff_t |
michael@0 | 22 | |
michael@0 | 23 | struct SkFILE; |
michael@0 | 24 | |
michael@0 | 25 | enum SkFILE_Flags { |
michael@0 | 26 | kRead_SkFILE_Flag = 0x01, |
michael@0 | 27 | kWrite_SkFILE_Flag = 0x02 |
michael@0 | 28 | }; |
michael@0 | 29 | |
michael@0 | 30 | #ifdef _WIN32 |
michael@0 | 31 | const static char SkPATH_SEPARATOR = '\\'; |
michael@0 | 32 | #else |
michael@0 | 33 | const static char SkPATH_SEPARATOR = '/'; |
michael@0 | 34 | #endif |
michael@0 | 35 | |
michael@0 | 36 | SkFILE* sk_fopen(const char path[], SkFILE_Flags); |
michael@0 | 37 | void sk_fclose(SkFILE*); |
michael@0 | 38 | |
michael@0 | 39 | size_t sk_fgetsize(SkFILE*); |
michael@0 | 40 | /** Return true if the file could seek back to the beginning |
michael@0 | 41 | */ |
michael@0 | 42 | bool sk_frewind(SkFILE*); |
michael@0 | 43 | |
michael@0 | 44 | size_t sk_fread(void* buffer, size_t byteCount, SkFILE*); |
michael@0 | 45 | size_t sk_fwrite(const void* buffer, size_t byteCount, SkFILE*); |
michael@0 | 46 | |
michael@0 | 47 | char* sk_fgets(char* str, int size, SkFILE* f); |
michael@0 | 48 | |
michael@0 | 49 | void sk_fflush(SkFILE*); |
michael@0 | 50 | |
michael@0 | 51 | bool sk_fseek(SkFILE*, size_t); |
michael@0 | 52 | bool sk_fmove(SkFILE*, long); |
michael@0 | 53 | size_t sk_ftell(SkFILE*); |
michael@0 | 54 | |
michael@0 | 55 | /** Maps a file into memory. Returns the address and length on success, NULL otherwise. |
michael@0 | 56 | * The mapping is read only. |
michael@0 | 57 | * When finished with the mapping, free the returned pointer with sk_fmunmap. |
michael@0 | 58 | */ |
michael@0 | 59 | void* sk_fmmap(SkFILE* f, size_t* length); |
michael@0 | 60 | |
michael@0 | 61 | /** Maps a file descriptor into memory. Returns the address and length on success, NULL otherwise. |
michael@0 | 62 | * The mapping is read only. |
michael@0 | 63 | * When finished with the mapping, free the returned pointer with sk_fmunmap. |
michael@0 | 64 | */ |
michael@0 | 65 | void* sk_fdmmap(int fd, size_t* length); |
michael@0 | 66 | |
michael@0 | 67 | /** Unmaps a file previously mapped by sk_fmmap or sk_fdmmap. |
michael@0 | 68 | * The length parameter must be the same as returned from sk_fmmap. |
michael@0 | 69 | */ |
michael@0 | 70 | void sk_fmunmap(const void* addr, size_t length); |
michael@0 | 71 | |
michael@0 | 72 | /** Returns true if the two point at the exact same filesystem object. */ |
michael@0 | 73 | bool sk_fidentical(SkFILE* a, SkFILE* b); |
michael@0 | 74 | |
michael@0 | 75 | /** Returns the underlying file descriptor for the given file. |
michael@0 | 76 | * The return value will be < 0 on failure. |
michael@0 | 77 | */ |
michael@0 | 78 | int sk_fileno(SkFILE* f); |
michael@0 | 79 | |
michael@0 | 80 | // Returns true if something (file, directory, ???) exists at this path. |
michael@0 | 81 | bool sk_exists(const char *path); |
michael@0 | 82 | |
michael@0 | 83 | // Returns true if a directory exists at this path. |
michael@0 | 84 | bool sk_isdir(const char *path); |
michael@0 | 85 | |
michael@0 | 86 | // Have we reached the end of the file? |
michael@0 | 87 | int sk_feof(SkFILE *); |
michael@0 | 88 | |
michael@0 | 89 | |
michael@0 | 90 | // Create a new directory at this path; returns true if successful. |
michael@0 | 91 | // If the directory already existed, this will return true. |
michael@0 | 92 | // Description of the error, if any, will be written to stderr. |
michael@0 | 93 | bool sk_mkdir(const char* path); |
michael@0 | 94 | |
michael@0 | 95 | class SkOSFile { |
michael@0 | 96 | public: |
michael@0 | 97 | class Iter { |
michael@0 | 98 | public: |
michael@0 | 99 | Iter(); |
michael@0 | 100 | Iter(const char path[], const char suffix[] = NULL); |
michael@0 | 101 | ~Iter(); |
michael@0 | 102 | |
michael@0 | 103 | void reset(const char path[], const char suffix[] = NULL); |
michael@0 | 104 | /** If getDir is true, only returns directories. |
michael@0 | 105 | Results are undefined if true and false calls are |
michael@0 | 106 | interleaved on a single iterator. |
michael@0 | 107 | */ |
michael@0 | 108 | bool next(SkString* name, bool getDir = false); |
michael@0 | 109 | |
michael@0 | 110 | private: |
michael@0 | 111 | #ifdef SK_BUILD_FOR_WIN |
michael@0 | 112 | HANDLE fHandle; |
michael@0 | 113 | uint16_t* fPath16; |
michael@0 | 114 | #elif defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_ANDROID) || defined(SK_BUILD_FOR_IOS) |
michael@0 | 115 | DIR* fDIR; |
michael@0 | 116 | SkString fPath, fSuffix; |
michael@0 | 117 | #endif |
michael@0 | 118 | }; |
michael@0 | 119 | }; |
michael@0 | 120 | |
michael@0 | 121 | class SkUTF16_Str { |
michael@0 | 122 | public: |
michael@0 | 123 | SkUTF16_Str(const char src[]); |
michael@0 | 124 | ~SkUTF16_Str() |
michael@0 | 125 | { |
michael@0 | 126 | sk_free(fStr); |
michael@0 | 127 | } |
michael@0 | 128 | const uint16_t* get() const { return fStr; } |
michael@0 | 129 | |
michael@0 | 130 | private: |
michael@0 | 131 | uint16_t* fStr; |
michael@0 | 132 | }; |
michael@0 | 133 | |
michael@0 | 134 | /** |
michael@0 | 135 | * Functions for modifying SkStrings which represent paths on the filesystem. |
michael@0 | 136 | */ |
michael@0 | 137 | class SkOSPath { |
michael@0 | 138 | public: |
michael@0 | 139 | /** |
michael@0 | 140 | * Assembles rootPath and relativePath into a single path, like this: |
michael@0 | 141 | * rootPath/relativePath. |
michael@0 | 142 | * It is okay to call with a NULL rootPath and/or relativePath. A path |
michael@0 | 143 | * separator will still be inserted. |
michael@0 | 144 | * |
michael@0 | 145 | * Uses SkPATH_SEPARATOR, to work on all platforms. |
michael@0 | 146 | */ |
michael@0 | 147 | static SkString SkPathJoin(const char *rootPath, const char *relativePath); |
michael@0 | 148 | |
michael@0 | 149 | /** |
michael@0 | 150 | * Return the name of the file, ignoring the directory structure. |
michael@0 | 151 | * Behaves like python's os.path.basename. If the fullPath is |
michael@0 | 152 | * /dir/subdir/, an empty string is returned. |
michael@0 | 153 | * @param fullPath Full path to the file. |
michael@0 | 154 | * @return SkString The basename of the file - anything beyond the |
michael@0 | 155 | * final slash, or the full name if there is no slash. |
michael@0 | 156 | */ |
michael@0 | 157 | static SkString SkBasename(const char* fullPath); |
michael@0 | 158 | }; |
michael@0 | 159 | #endif |