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 2010 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 <Foundation/Foundation.h> |
michael@0 | 9 | #include "SkOSFile.h" |
michael@0 | 10 | #include "SkString.h" |
michael@0 | 11 | |
michael@0 | 12 | struct SkFILE { |
michael@0 | 13 | NSData* fData; |
michael@0 | 14 | size_t fOffset; |
michael@0 | 15 | size_t fLength; |
michael@0 | 16 | }; |
michael@0 | 17 | |
michael@0 | 18 | SkFILE* sk_fopen(const char cpath[], SkFILE_Flags flags) { |
michael@0 | 19 | if (flags & kWrite_SkFILE_Flag) { |
michael@0 | 20 | return NULL; |
michael@0 | 21 | } |
michael@0 | 22 | |
michael@0 | 23 | SkString cname, csuffix; |
michael@0 | 24 | |
michael@0 | 25 | const char* start = strrchr(cpath, '/'); |
michael@0 | 26 | if (NULL == start) { |
michael@0 | 27 | start = cpath; |
michael@0 | 28 | } else { |
michael@0 | 29 | start += 1; |
michael@0 | 30 | } |
michael@0 | 31 | const char* stop = strrchr(cpath, '.'); |
michael@0 | 32 | if (NULL == stop) { |
michael@0 | 33 | return NULL; |
michael@0 | 34 | } else { |
michael@0 | 35 | stop += 1; |
michael@0 | 36 | } |
michael@0 | 37 | |
michael@0 | 38 | cname.set(start, stop - start - 1); |
michael@0 | 39 | csuffix.set(stop); |
michael@0 | 40 | |
michael@0 | 41 | NSBundle* bundle = [NSBundle mainBundle]; |
michael@0 | 42 | NSString* name = [NSString stringWithUTF8String:cname.c_str()]; |
michael@0 | 43 | NSString* suffix = [NSString stringWithUTF8String:csuffix.c_str()]; |
michael@0 | 44 | NSString* path = [bundle pathForResource:name ofType:suffix]; |
michael@0 | 45 | NSData* data = [NSData dataWithContentsOfMappedFile:path]; |
michael@0 | 46 | |
michael@0 | 47 | if (data) { |
michael@0 | 48 | [data retain]; |
michael@0 | 49 | SkFILE* rec = new SkFILE; |
michael@0 | 50 | rec->fData = data; |
michael@0 | 51 | rec->fOffset = 0; |
michael@0 | 52 | rec->fLength = [data length]; |
michael@0 | 53 | return reinterpret_cast<SkFILE*>(rec); |
michael@0 | 54 | } |
michael@0 | 55 | return NULL; |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | size_t sk_fgetsize(SkFILE* rec) { |
michael@0 | 59 | SkASSERT(rec); |
michael@0 | 60 | return rec->fLength; |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | bool sk_frewind(SkFILE* rec) { |
michael@0 | 64 | SkASSERT(rec); |
michael@0 | 65 | rec->fOffset = 0; |
michael@0 | 66 | return true; |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | size_t sk_fread(void* buffer, size_t byteCount, SkFILE* rec) { |
michael@0 | 70 | if (NULL == buffer) { |
michael@0 | 71 | return rec->fLength; |
michael@0 | 72 | } else { |
michael@0 | 73 | size_t remaining = rec->fLength - rec->fOffset; |
michael@0 | 74 | if (byteCount > remaining) { |
michael@0 | 75 | byteCount = remaining; |
michael@0 | 76 | } |
michael@0 | 77 | memcpy(buffer, (char*)[rec->fData bytes] + rec->fOffset, byteCount); |
michael@0 | 78 | rec->fOffset += byteCount; |
michael@0 | 79 | SkASSERT(rec->fOffset <= rec->fLength); |
michael@0 | 80 | return byteCount; |
michael@0 | 81 | } |
michael@0 | 82 | } |
michael@0 | 83 | |
michael@0 | 84 | size_t sk_fwrite(const void* buffer, size_t byteCount, SkFILE* f) { |
michael@0 | 85 | SkDEBUGFAIL("Not supported yet"); |
michael@0 | 86 | return 0; |
michael@0 | 87 | } |
michael@0 | 88 | |
michael@0 | 89 | void sk_fflush(SkFILE* f) { |
michael@0 | 90 | SkDEBUGFAIL("Not supported yet"); |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | void sk_fclose(SkFILE* rec) { |
michael@0 | 94 | SkASSERT(rec); |
michael@0 | 95 | [rec->fData release]; |
michael@0 | 96 | delete rec; |
michael@0 | 97 | } |
michael@0 | 98 |