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 (c) 2002-2010 The ANGLE Project Authors. All rights reserved. |
michael@0 | 3 | // Use of this source code is governed by a BSD-style license that can be |
michael@0 | 4 | // found in the LICENSE file. |
michael@0 | 5 | // |
michael@0 | 6 | |
michael@0 | 7 | #ifndef _INFOSINK_INCLUDED_ |
michael@0 | 8 | #define _INFOSINK_INCLUDED_ |
michael@0 | 9 | |
michael@0 | 10 | #include <math.h> |
michael@0 | 11 | #include "compiler/Common.h" |
michael@0 | 12 | |
michael@0 | 13 | // Returns the fractional part of the given floating-point number. |
michael@0 | 14 | inline float fractionalPart(float f) { |
michael@0 | 15 | float intPart = 0.0f; |
michael@0 | 16 | return modff(f, &intPart); |
michael@0 | 17 | } |
michael@0 | 18 | |
michael@0 | 19 | // |
michael@0 | 20 | // TPrefixType is used to centralize how info log messages start. |
michael@0 | 21 | // See below. |
michael@0 | 22 | // |
michael@0 | 23 | enum TPrefixType { |
michael@0 | 24 | EPrefixNone, |
michael@0 | 25 | EPrefixWarning, |
michael@0 | 26 | EPrefixError, |
michael@0 | 27 | EPrefixInternalError, |
michael@0 | 28 | EPrefixUnimplemented, |
michael@0 | 29 | EPrefixNote |
michael@0 | 30 | }; |
michael@0 | 31 | |
michael@0 | 32 | // |
michael@0 | 33 | // Encapsulate info logs for all objects that have them. |
michael@0 | 34 | // |
michael@0 | 35 | // The methods are a general set of tools for getting a variety of |
michael@0 | 36 | // messages and types inserted into the log. |
michael@0 | 37 | // |
michael@0 | 38 | class TInfoSinkBase { |
michael@0 | 39 | public: |
michael@0 | 40 | TInfoSinkBase() {} |
michael@0 | 41 | |
michael@0 | 42 | template <typename T> |
michael@0 | 43 | TInfoSinkBase& operator<<(const T& t) { |
michael@0 | 44 | TPersistStringStream stream; |
michael@0 | 45 | stream << t; |
michael@0 | 46 | sink.append(stream.str()); |
michael@0 | 47 | return *this; |
michael@0 | 48 | } |
michael@0 | 49 | // Override << operator for specific types. It is faster to append strings |
michael@0 | 50 | // and characters directly to the sink. |
michael@0 | 51 | TInfoSinkBase& operator<<(char c) { |
michael@0 | 52 | sink.append(1, c); |
michael@0 | 53 | return *this; |
michael@0 | 54 | } |
michael@0 | 55 | TInfoSinkBase& operator<<(const char* str) { |
michael@0 | 56 | sink.append(str); |
michael@0 | 57 | return *this; |
michael@0 | 58 | } |
michael@0 | 59 | TInfoSinkBase& operator<<(const TPersistString& str) { |
michael@0 | 60 | sink.append(str); |
michael@0 | 61 | return *this; |
michael@0 | 62 | } |
michael@0 | 63 | TInfoSinkBase& operator<<(const TString& str) { |
michael@0 | 64 | sink.append(str.c_str()); |
michael@0 | 65 | return *this; |
michael@0 | 66 | } |
michael@0 | 67 | // Make sure floats are written with correct precision. |
michael@0 | 68 | TInfoSinkBase& operator<<(float f) { |
michael@0 | 69 | // Make sure that at least one decimal point is written. If a number |
michael@0 | 70 | // does not have a fractional part, the default precision format does |
michael@0 | 71 | // not write the decimal portion which gets interpreted as integer by |
michael@0 | 72 | // the compiler. |
michael@0 | 73 | TPersistStringStream stream; |
michael@0 | 74 | if (fractionalPart(f) == 0.0f) { |
michael@0 | 75 | stream.precision(1); |
michael@0 | 76 | stream << std::showpoint << std::fixed << f; |
michael@0 | 77 | } else { |
michael@0 | 78 | stream.unsetf(std::ios::fixed); |
michael@0 | 79 | stream.unsetf(std::ios::scientific); |
michael@0 | 80 | stream.precision(8); |
michael@0 | 81 | stream << f; |
michael@0 | 82 | } |
michael@0 | 83 | sink.append(stream.str()); |
michael@0 | 84 | return *this; |
michael@0 | 85 | } |
michael@0 | 86 | // Write boolean values as their names instead of integral value. |
michael@0 | 87 | TInfoSinkBase& operator<<(bool b) { |
michael@0 | 88 | const char* str = b ? "true" : "false"; |
michael@0 | 89 | sink.append(str); |
michael@0 | 90 | return *this; |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | void erase() { sink.clear(); } |
michael@0 | 94 | int size() { return static_cast<int>(sink.size()); } |
michael@0 | 95 | |
michael@0 | 96 | const TPersistString& str() const { return sink; } |
michael@0 | 97 | const char* c_str() const { return sink.c_str(); } |
michael@0 | 98 | |
michael@0 | 99 | void prefix(TPrefixType p); |
michael@0 | 100 | void location(int file, int line); |
michael@0 | 101 | void location(const TSourceLoc& loc); |
michael@0 | 102 | void message(TPrefixType p, const TSourceLoc& loc, const char* m); |
michael@0 | 103 | |
michael@0 | 104 | private: |
michael@0 | 105 | TPersistString sink; |
michael@0 | 106 | }; |
michael@0 | 107 | |
michael@0 | 108 | class TInfoSink { |
michael@0 | 109 | public: |
michael@0 | 110 | TInfoSinkBase info; |
michael@0 | 111 | TInfoSinkBase debug; |
michael@0 | 112 | TInfoSinkBase obj; |
michael@0 | 113 | }; |
michael@0 | 114 | |
michael@0 | 115 | #endif // _INFOSINK_INCLUDED_ |