OSDN Git Service

am 6032fa42: Merge "Implement dual textures for layers to handle zooming correctly...
[android-x86/external-webkit.git] / Source / WebCore / platform / KURLGooglePrivate.h
1 /*
2  * Copyright (c) 2008, 2009, 2011 Google Inc. All rights reserved.
3  * 
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  * 
8  *     * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *     * Redistributions in binary form must reproduce the above
11  * copyright notice, this list of conditions and the following disclaimer
12  * in the documentation and/or other materials provided with the
13  * distribution.
14  *     * Neither the name of Google Inc. nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  * 
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30
31 #ifndef KURLGooglePrivate_h
32 #define KURLGooglePrivate_h
33
34 #include <wtf/text/CString.h>
35
36 #include <googleurl/src/url_parse.h>
37 #include <googleurl/src/url_canon.h>
38
39 namespace WebCore {
40
41     class KURL;
42     class TextEncoding;
43
44     // Wraps the internals related to using Google-URL as the backend for KURL.
45     // This maintains the state and has auxiliary functions so that we don't need
46     // to uglify KURL.h while allowing Google-URL to be evaluated.
47     class KURLGooglePrivate {
48     public:
49         KURLGooglePrivate();
50         KURLGooglePrivate(const url_parse::Parsed&, bool isValid);
51         KURLGooglePrivate(WTF::HashTableDeletedValueType);
52
53         // Initializes the object. This will call through the backend initializer
54         // below.
55         void init(const KURL& base, const String& relative,
56                   const TextEncoding* queryEncoding);
57
58         // Backend initializer. The query encoding parameters are optional and can
59         // be 0 (this implies UTF-8). This initializer requires that the object
60         // has just been created and the strings are null. Do not call on an
61         // already-constructed object.
62         template <typename CHAR>
63         void init(const KURL& base, const CHAR* rel, int relLength,
64                   const TextEncoding* queryEncoding);
65
66         // Does a deep copy to the given output object.
67         void copyTo(KURLGooglePrivate* dest) const;
68
69         // Returns the substring of the input identified by the given component.
70         String componentString(const url_parse::Component&) const;
71
72         // Replaces the given components, modifying the current URL. The current
73         // URL must be valid.
74         typedef url_canon::Replacements<url_parse::UTF16Char> Replacements;
75         void replaceComponents(const Replacements&);
76
77         // Setters for the data. Using the ASCII version when you know the
78         // data is ASCII will be slightly more efficient. The UTF-8 version
79         // will always be correct if the caller is unsure.
80         void setUtf8(const CString&);
81         void setAscii(const CString&);
82
83         // TODO(brettw) we can support an additional optimization.  Make this
84         // buffer support both optinal Strings and UTF-8 data. This way, we can use
85         // the optimization from the original KURL which uses = with the original
86         // string when canonicalization did not change it. This allows the strings
87         // to share a buffer internally, and saves a malloc.
88
89         // Getters for the data.
90         const CString& utf8String() const { return m_utf8; }
91         const String& string() const;
92
93         bool m_isValid;
94         bool m_protocolInHTTPFamily;
95         url_parse::Parsed m_parsed; // Indexes into the UTF-8 version of the string.
96
97     private:
98         void initProtocolInHTTPFamily();
99
100         CString m_utf8;
101
102         // Set to true when the caller set us using the ASCII setter. We can
103         // be more efficient when we know there is no UTF-8 to worry about.
104         // This flag is currently always correct, but should be changed to be a
105         // hint (see setUtf8).
106         bool m_utf8IsASCII;
107
108         mutable bool m_stringIsValid;
109         mutable String m_string;
110     };
111
112 } // namespace WebCore
113
114 #endif