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 | #ifndef SkXMLParser_DEFINED |
michael@0 | 11 | #define SkXMLParser_DEFINED |
michael@0 | 12 | |
michael@0 | 13 | #include "SkString.h" |
michael@0 | 14 | |
michael@0 | 15 | class SkStream; |
michael@0 | 16 | |
michael@0 | 17 | class SkDOM; |
michael@0 | 18 | struct SkDOMNode; |
michael@0 | 19 | |
michael@0 | 20 | class SkXMLParserError { |
michael@0 | 21 | public: |
michael@0 | 22 | enum ErrorCode { |
michael@0 | 23 | kNoError, |
michael@0 | 24 | kEmptyFile, |
michael@0 | 25 | kUnknownElement, |
michael@0 | 26 | kUnknownAttributeName, |
michael@0 | 27 | kErrorInAttributeValue, |
michael@0 | 28 | kDuplicateIDs, |
michael@0 | 29 | kUnknownError |
michael@0 | 30 | }; |
michael@0 | 31 | |
michael@0 | 32 | SkXMLParserError(); |
michael@0 | 33 | virtual ~SkXMLParserError(); |
michael@0 | 34 | ErrorCode getErrorCode() const { return fCode; } |
michael@0 | 35 | virtual void getErrorString(SkString* str) const; |
michael@0 | 36 | int getLineNumber() const { return fLineNumber; } |
michael@0 | 37 | int getNativeCode() const { return fNativeCode; } |
michael@0 | 38 | bool hasError() const { return fCode != kNoError || fNativeCode != -1; } |
michael@0 | 39 | bool hasNoun() const { return fNoun.size() > 0; } |
michael@0 | 40 | void reset(); |
michael@0 | 41 | void setCode(ErrorCode code) { fCode = code; } |
michael@0 | 42 | void setNoun(const SkString& str) { fNoun.set(str); } |
michael@0 | 43 | void setNoun(const char* ch) { fNoun.set(ch); } |
michael@0 | 44 | void setNoun(const char* ch, size_t len) { fNoun.set(ch, len); } |
michael@0 | 45 | protected: |
michael@0 | 46 | ErrorCode fCode; |
michael@0 | 47 | private: |
michael@0 | 48 | int fLineNumber; |
michael@0 | 49 | int fNativeCode; |
michael@0 | 50 | SkString fNoun; |
michael@0 | 51 | friend class SkXMLParser; |
michael@0 | 52 | }; |
michael@0 | 53 | |
michael@0 | 54 | class SkXMLParser { |
michael@0 | 55 | public: |
michael@0 | 56 | SkXMLParser(SkXMLParserError* parserError = NULL); |
michael@0 | 57 | virtual ~SkXMLParser(); |
michael@0 | 58 | |
michael@0 | 59 | /** Returns true for success |
michael@0 | 60 | */ |
michael@0 | 61 | bool parse(const char doc[], size_t len); |
michael@0 | 62 | bool parse(SkStream& docStream); |
michael@0 | 63 | bool parse(const SkDOM&, const SkDOMNode*); |
michael@0 | 64 | |
michael@0 | 65 | static void GetNativeErrorString(int nativeErrorCode, SkString* str); |
michael@0 | 66 | |
michael@0 | 67 | protected: |
michael@0 | 68 | // override in subclasses; return true to stop parsing |
michael@0 | 69 | virtual bool onStartElement(const char elem[]); |
michael@0 | 70 | virtual bool onAddAttribute(const char name[], const char value[]); |
michael@0 | 71 | virtual bool onEndElement(const char elem[]); |
michael@0 | 72 | virtual bool onText(const char text[], int len); |
michael@0 | 73 | |
michael@0 | 74 | public: |
michael@0 | 75 | // public for ported implementation, not meant for clients to call |
michael@0 | 76 | virtual bool startElement(const char elem[]); |
michael@0 | 77 | virtual bool addAttribute(const char name[], const char value[]); |
michael@0 | 78 | virtual bool endElement(const char elem[]); |
michael@0 | 79 | virtual bool text(const char text[], int len); |
michael@0 | 80 | void* fParser; |
michael@0 | 81 | protected: |
michael@0 | 82 | SkXMLParserError* fError; |
michael@0 | 83 | private: |
michael@0 | 84 | void reportError(void* parser); |
michael@0 | 85 | }; |
michael@0 | 86 | |
michael@0 | 87 | #if 0 |
michael@0 | 88 | class SkXMLPullParser { |
michael@0 | 89 | public: |
michael@0 | 90 | SkXMLPullParser(); |
michael@0 | 91 | explicit SkXMLPullParser(SkStream*); |
michael@0 | 92 | virtual ~SkXMLPullParser(); |
michael@0 | 93 | |
michael@0 | 94 | SkStream* getStream() const { return fStream; } |
michael@0 | 95 | SkStream* setStream(SkStream* stream); |
michael@0 | 96 | |
michael@0 | 97 | enum EventType { |
michael@0 | 98 | ERROR = -1, |
michael@0 | 99 | START_DOCUMENT, |
michael@0 | 100 | END_DOCUMENT, |
michael@0 | 101 | START_TAG, |
michael@0 | 102 | END_TAG, |
michael@0 | 103 | TEXT, |
michael@0 | 104 | CDSECT, |
michael@0 | 105 | ENTITY_REF, |
michael@0 | 106 | IGNORABLE_WHITESPACE, |
michael@0 | 107 | PROCESSING_INSTRUCTION, |
michael@0 | 108 | COMMENT, |
michael@0 | 109 | DOCDECL |
michael@0 | 110 | }; |
michael@0 | 111 | |
michael@0 | 112 | EventType nextToken(); |
michael@0 | 113 | EventType getEventType() const { return fCurr.fEventType; } |
michael@0 | 114 | |
michael@0 | 115 | struct AttrInfo { |
michael@0 | 116 | const char* fName; |
michael@0 | 117 | const char* fValue; |
michael@0 | 118 | }; |
michael@0 | 119 | |
michael@0 | 120 | int getDepth() const { return fDepth; } |
michael@0 | 121 | const char* getName(); |
michael@0 | 122 | int getAttributeCount(); |
michael@0 | 123 | void getAttributeInfo(int, AttrInfo*); |
michael@0 | 124 | const char* getText(); |
michael@0 | 125 | bool isWhitespace(); |
michael@0 | 126 | |
michael@0 | 127 | protected: |
michael@0 | 128 | virtual bool onEntityReplacement(const char name[], |
michael@0 | 129 | SkString* replacement); |
michael@0 | 130 | |
michael@0 | 131 | public: |
michael@0 | 132 | struct Curr { |
michael@0 | 133 | EventType fEventType; |
michael@0 | 134 | const char* fName; |
michael@0 | 135 | AttrInfo* fAttrInfos; |
michael@0 | 136 | int fAttrInfoCount; |
michael@0 | 137 | bool fIsWhitespace; |
michael@0 | 138 | }; |
michael@0 | 139 | |
michael@0 | 140 | private: |
michael@0 | 141 | // implemented in the porting layer |
michael@0 | 142 | bool onInit(); // return false on failure |
michael@0 | 143 | EventType onNextToken(); |
michael@0 | 144 | void onExit(); |
michael@0 | 145 | |
michael@0 | 146 | SkStream* fStream; |
michael@0 | 147 | Curr fCurr; |
michael@0 | 148 | int fDepth; |
michael@0 | 149 | |
michael@0 | 150 | struct Impl; |
michael@0 | 151 | Impl* fImpl; |
michael@0 | 152 | }; |
michael@0 | 153 | #endif |
michael@0 | 154 | |
michael@0 | 155 | #endif |