gfx/skia/trunk/src/core/SkError.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 /*
michael@0 3 * Copyright 2013 Google Inc.
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 #include "SkTLS.h"
michael@0 10 #include "SkTypes.h"
michael@0 11 #include "SkError.h"
michael@0 12 #include "SkErrorInternals.h"
michael@0 13
michael@0 14 #include <stdio.h>
michael@0 15 #include <stdarg.h>
michael@0 16
michael@0 17 namespace {
michael@0 18 void *CreateThreadError() {
michael@0 19 return SkNEW_ARGS(SkError, (kNoError_SkError));
michael@0 20 }
michael@0 21 void DeleteThreadError(void* v) {
michael@0 22 SkDELETE(reinterpret_cast<SkError*>(v));
michael@0 23 }
michael@0 24 #define THREAD_ERROR \
michael@0 25 (*reinterpret_cast<SkError*>(SkTLS::Get(CreateThreadError, DeleteThreadError)))
michael@0 26
michael@0 27 void *CreateThreadErrorCallback() {
michael@0 28 return SkNEW_ARGS(SkErrorCallbackFunction, (SkErrorInternals::DefaultErrorCallback));
michael@0 29 }
michael@0 30 void DeleteThreadErrorCallback(void* v) {
michael@0 31 SkDELETE(reinterpret_cast<SkErrorCallbackFunction *>(v));
michael@0 32 }
michael@0 33
michael@0 34 #define THREAD_ERROR_CALLBACK \
michael@0 35 *(reinterpret_cast<SkErrorCallbackFunction *>(SkTLS::Get(CreateThreadErrorCallback, \
michael@0 36 DeleteThreadErrorCallback)))
michael@0 37
michael@0 38 void *CreateThreadErrorContext() {
michael@0 39 return SkNEW_ARGS(void **, (NULL));
michael@0 40 }
michael@0 41 void DeleteThreadErrorContext(void* v) {
michael@0 42 SkDELETE(reinterpret_cast<void **>(v));
michael@0 43 }
michael@0 44 #define THREAD_ERROR_CONTEXT \
michael@0 45 (*reinterpret_cast<void **>(SkTLS::Get(CreateThreadErrorContext, DeleteThreadErrorContext)))
michael@0 46
michael@0 47 #define ERROR_STRING_LENGTH 2048
michael@0 48
michael@0 49 void *CreateThreadErrorString() {
michael@0 50 return SkNEW_ARRAY(char, (ERROR_STRING_LENGTH));
michael@0 51 }
michael@0 52 void DeleteThreadErrorString(void* v) {
michael@0 53 SkDELETE_ARRAY(reinterpret_cast<char *>(v));
michael@0 54 }
michael@0 55 #define THREAD_ERROR_STRING \
michael@0 56 (reinterpret_cast<char *>(SkTLS::Get(CreateThreadErrorString, DeleteThreadErrorString)))
michael@0 57 }
michael@0 58
michael@0 59 SkError SkGetLastError() {
michael@0 60 return SkErrorInternals::GetLastError();
michael@0 61 }
michael@0 62 void SkClearLastError() {
michael@0 63 SkErrorInternals::ClearError();
michael@0 64 }
michael@0 65 void SkSetErrorCallback(SkErrorCallbackFunction cb, void *context) {
michael@0 66 SkErrorInternals::SetErrorCallback(cb, context);
michael@0 67 }
michael@0 68 const char *SkGetLastErrorString() {
michael@0 69 return SkErrorInternals::GetLastErrorString();
michael@0 70 }
michael@0 71
michael@0 72 // ------------ Private Error functions ---------
michael@0 73
michael@0 74 void SkErrorInternals::SetErrorCallback(SkErrorCallbackFunction cb, void *context) {
michael@0 75 if (cb == NULL) {
michael@0 76 THREAD_ERROR_CALLBACK = SkErrorInternals::DefaultErrorCallback;
michael@0 77 } else {
michael@0 78 THREAD_ERROR_CALLBACK = cb;
michael@0 79 }
michael@0 80 THREAD_ERROR_CONTEXT = context;
michael@0 81 }
michael@0 82
michael@0 83 void SkErrorInternals::DefaultErrorCallback(SkError code, void *context) {
michael@0 84 SkDebugf("Skia Error: %s\n", SkGetLastErrorString());
michael@0 85 }
michael@0 86
michael@0 87 void SkErrorInternals::ClearError() {
michael@0 88 SkErrorInternals::SetError( kNoError_SkError, "All is well" );
michael@0 89 }
michael@0 90
michael@0 91 SkError SkErrorInternals::GetLastError() {
michael@0 92 return THREAD_ERROR;
michael@0 93 }
michael@0 94
michael@0 95 const char *SkErrorInternals::GetLastErrorString() {
michael@0 96 return THREAD_ERROR_STRING;
michael@0 97 }
michael@0 98
michael@0 99 void SkErrorInternals::SetError(SkError code, const char *fmt, ...) {
michael@0 100 THREAD_ERROR = code;
michael@0 101 va_list args;
michael@0 102
michael@0 103 char *str = THREAD_ERROR_STRING;
michael@0 104 const char *error_name = NULL;
michael@0 105 switch( code ) {
michael@0 106 case kNoError_SkError:
michael@0 107 error_name = "No Error";
michael@0 108 break;
michael@0 109 case kInvalidArgument_SkError:
michael@0 110 error_name = "Invalid Argument";
michael@0 111 break;
michael@0 112 case kInvalidOperation_SkError:
michael@0 113 error_name = "Invalid Operation";
michael@0 114 break;
michael@0 115 case kInvalidHandle_SkError:
michael@0 116 error_name = "Invalid Handle";
michael@0 117 break;
michael@0 118 case kInvalidPaint_SkError:
michael@0 119 error_name = "Invalid Paint";
michael@0 120 break;
michael@0 121 case kOutOfMemory_SkError:
michael@0 122 error_name = "Out Of Memory";
michael@0 123 break;
michael@0 124 case kParseError_SkError:
michael@0 125 error_name = "Parse Error";
michael@0 126 break;
michael@0 127 default:
michael@0 128 error_name = "Unknown error";
michael@0 129 break;
michael@0 130 }
michael@0 131
michael@0 132 sprintf( str, "%s: ", error_name );
michael@0 133 int string_left = SkToInt(ERROR_STRING_LENGTH - strlen(str));
michael@0 134 str += strlen(str);
michael@0 135
michael@0 136 va_start( args, fmt );
michael@0 137 vsnprintf( str, string_left, fmt, args );
michael@0 138 va_end( args );
michael@0 139 SkErrorCallbackFunction fn = THREAD_ERROR_CALLBACK;
michael@0 140 if (fn && code != kNoError_SkError) {
michael@0 141 fn(code, THREAD_ERROR_CONTEXT);
michael@0 142 }
michael@0 143 }

mercurial