gfx/skia/trunk/src/utils/ios/SkOSFile_iOS.mm

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
-rwxr-xr-x

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.

     1 /*
     2  * Copyright 2010 Google Inc.
     3  *
     4  * Use of this source code is governed by a BSD-style license that can be
     5  * found in the LICENSE file.
     6  */
     8 #include <Foundation/Foundation.h>
     9 #include "SkOSFile.h"
    10 #include "SkString.h"
    12 struct SkFILE {
    13     NSData* fData;
    14     size_t  fOffset;
    15     size_t  fLength;
    16 };
    18 SkFILE* sk_fopen(const char cpath[], SkFILE_Flags flags) {
    19     if (flags & kWrite_SkFILE_Flag) {
    20         return NULL;
    21     }
    23     SkString cname, csuffix;
    25     const char* start = strrchr(cpath, '/');
    26     if (NULL == start) {
    27         start = cpath;
    28     } else {
    29         start += 1;
    30     }
    31     const char* stop = strrchr(cpath, '.');
    32     if (NULL == stop) {
    33         return NULL;
    34     } else {
    35         stop += 1;
    36     }
    38     cname.set(start, stop - start - 1);
    39     csuffix.set(stop);
    41     NSBundle* bundle = [NSBundle mainBundle];
    42     NSString* name = [NSString stringWithUTF8String:cname.c_str()];
    43     NSString* suffix = [NSString stringWithUTF8String:csuffix.c_str()];
    44     NSString* path = [bundle pathForResource:name ofType:suffix];
    45     NSData* data = [NSData dataWithContentsOfMappedFile:path];
    47     if (data) {
    48         [data retain];
    49         SkFILE* rec = new SkFILE;
    50         rec->fData = data;
    51         rec->fOffset = 0;
    52         rec->fLength = [data length];
    53         return reinterpret_cast<SkFILE*>(rec);
    54     }
    55     return NULL;
    56 }
    58 size_t sk_fgetsize(SkFILE* rec) {
    59     SkASSERT(rec);
    60     return rec->fLength;
    61 }
    63 bool sk_frewind(SkFILE* rec) {
    64     SkASSERT(rec);
    65     rec->fOffset = 0;
    66     return true;
    67 }
    69 size_t sk_fread(void* buffer, size_t byteCount, SkFILE* rec) {
    70     if (NULL == buffer) {
    71         return rec->fLength;
    72     } else {
    73         size_t remaining = rec->fLength - rec->fOffset;
    74         if (byteCount > remaining) {
    75             byteCount = remaining;
    76         }
    77         memcpy(buffer, (char*)[rec->fData bytes] + rec->fOffset, byteCount);
    78         rec->fOffset += byteCount;
    79         SkASSERT(rec->fOffset <= rec->fLength);
    80         return byteCount;
    81     }
    82 }
    84 size_t sk_fwrite(const void* buffer, size_t byteCount, SkFILE* f) {
    85     SkDEBUGFAIL("Not supported yet");
    86     return 0;
    87 }
    89 void sk_fflush(SkFILE* f) {
    90     SkDEBUGFAIL("Not supported yet");
    91 }
    93 void sk_fclose(SkFILE* rec) {
    94     SkASSERT(rec);
    95     [rec->fData release];
    96     delete rec;
    97 }

mercurial