darin@chromium.org | da869c1 | 2009-01-28 08:19:22 +0000 | [diff] [blame] | 1 | /* |
commit-queue@webkit.org | 7763dc2 | 2011-02-11 01:01:30 +0000 | [diff] [blame] | 2 | * Copyright (c) 2008, 2009, 2011 Google Inc. All rights reserved. |
darin@chromium.org | da869c1 | 2009-01-28 08:19:22 +0000 | [diff] [blame] | 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 | |
loislo@chromium.org | 5bd1cc0 | 2012-09-13 12:12:19 +0000 | [diff] [blame] | 34 | #include <wtf/Forward.h> |
ericu@chromium.org | 551f57f | 2012-01-25 22:43:19 +0000 | [diff] [blame] | 35 | #include <wtf/OwnPtr.h> |
barraclough@apple.com | 00b7992 | 2010-03-31 05:44:34 +0000 | [diff] [blame] | 36 | #include <wtf/text/CString.h> |
darin@chromium.org | da869c1 | 2009-01-28 08:19:22 +0000 | [diff] [blame] | 37 | |
| 38 | #include <googleurl/src/url_parse.h> |
| 39 | #include <googleurl/src/url_canon.h> |
| 40 | |
| 41 | namespace WebCore { |
| 42 | |
| 43 | class KURL; |
| 44 | class TextEncoding; |
| 45 | |
commit-queue@webkit.org | cfd4132 | 2011-02-11 08:14:07 +0000 | [diff] [blame] | 46 | // Wraps the internals related to using Google-URL as the backend for KURL. |
darin@chromium.org | da869c1 | 2009-01-28 08:19:22 +0000 | [diff] [blame] | 47 | // This maintains the state and has auxiliary functions so that we don't need |
| 48 | // to uglify KURL.h while allowing Google-URL to be evaluated. |
| 49 | class KURLGooglePrivate { |
| 50 | public: |
| 51 | KURLGooglePrivate(); |
| 52 | KURLGooglePrivate(const url_parse::Parsed&, bool isValid); |
gyuyoung.kim@samsung.com | 0245dfc | 2012-07-26 08:55:13 +0000 | [diff] [blame] | 53 | explicit KURLGooglePrivate(WTF::HashTableDeletedValueType); |
| 54 | explicit KURLGooglePrivate(const KURLGooglePrivate&); |
ericu@chromium.org | 551f57f | 2012-01-25 22:43:19 +0000 | [diff] [blame] | 55 | KURLGooglePrivate& operator=(const KURLGooglePrivate&); |
darin@chromium.org | da869c1 | 2009-01-28 08:19:22 +0000 | [diff] [blame] | 56 | |
commit-queue@webkit.org | cfd4132 | 2011-02-11 08:14:07 +0000 | [diff] [blame] | 57 | // Initializes the object. This will call through the backend initializer |
| 58 | // below. |
darin@chromium.org | da869c1 | 2009-01-28 08:19:22 +0000 | [diff] [blame] | 59 | void init(const KURL& base, const String& relative, |
| 60 | const TextEncoding* queryEncoding); |
| 61 | |
commit-queue@webkit.org | cfd4132 | 2011-02-11 08:14:07 +0000 | [diff] [blame] | 62 | // Backend initializer. The query encoding parameters are optional and can |
| 63 | // be 0 (this implies UTF-8). This initializer requires that the object |
commit-queue@webkit.org | 7763dc2 | 2011-02-11 01:01:30 +0000 | [diff] [blame] | 64 | // has just been created and the strings are null. Do not call on an |
darin@chromium.org | da869c1 | 2009-01-28 08:19:22 +0000 | [diff] [blame] | 65 | // already-constructed object. |
commit-queue@webkit.org | cfd4132 | 2011-02-11 08:14:07 +0000 | [diff] [blame] | 66 | template <typename CHAR> |
| 67 | void init(const KURL& base, const CHAR* rel, int relLength, |
darin@chromium.org | da869c1 | 2009-01-28 08:19:22 +0000 | [diff] [blame] | 68 | const TextEncoding* queryEncoding); |
| 69 | |
| 70 | // Does a deep copy to the given output object. |
| 71 | void copyTo(KURLGooglePrivate* dest) const; |
| 72 | |
| 73 | // Returns the substring of the input identified by the given component. |
| 74 | String componentString(const url_parse::Component&) const; |
| 75 | |
| 76 | // Replaces the given components, modifying the current URL. The current |
| 77 | // URL must be valid. |
| 78 | typedef url_canon::Replacements<url_parse::UTF16Char> Replacements; |
| 79 | void replaceComponents(const Replacements&); |
| 80 | |
| 81 | // Setters for the data. Using the ASCII version when you know the |
| 82 | // data is ASCII will be slightly more efficient. The UTF-8 version |
| 83 | // will always be correct if the caller is unsure. |
darin@chromium.org | c28bccf | 2009-02-13 19:01:12 +0000 | [diff] [blame] | 84 | void setUtf8(const CString&); |
| 85 | void setAscii(const CString&); |
darin@chromium.org | da869c1 | 2009-01-28 08:19:22 +0000 | [diff] [blame] | 86 | |
| 87 | // TODO(brettw) we can support an additional optimization. Make this |
| 88 | // buffer support both optinal Strings and UTF-8 data. This way, we can use |
| 89 | // the optimization from the original KURL which uses = with the original |
| 90 | // string when canonicalization did not change it. This allows the strings |
| 91 | // to share a buffer internally, and saves a malloc. |
| 92 | |
| 93 | // Getters for the data. |
| 94 | const CString& utf8String() const { return m_utf8; } |
| 95 | const String& string() const; |
| 96 | |
| 97 | bool m_isValid; |
darin@apple.com | 6eed1c1 | 2011-04-27 16:22:48 +0000 | [diff] [blame] | 98 | bool m_protocolIsInHTTPFamily; |
darin@chromium.org | da869c1 | 2009-01-28 08:19:22 +0000 | [diff] [blame] | 99 | url_parse::Parsed m_parsed; // Indexes into the UTF-8 version of the string. |
| 100 | |
ericu@chromium.org | 551f57f | 2012-01-25 22:43:19 +0000 | [diff] [blame] | 101 | KURL* innerURL() const { return m_innerURL.get(); } |
| 102 | |
loislo@chromium.org | 5bd1cc0 | 2012-09-13 12:12:19 +0000 | [diff] [blame] | 103 | void reportMemoryUsage(MemoryObjectInfo*) const; |
| 104 | |
darin@chromium.org | da869c1 | 2009-01-28 08:19:22 +0000 | [diff] [blame] | 105 | private: |
ericu@chromium.org | 551f57f | 2012-01-25 22:43:19 +0000 | [diff] [blame] | 106 | void initInnerURL(); |
darin@apple.com | 6eed1c1 | 2011-04-27 16:22:48 +0000 | [diff] [blame] | 107 | void initProtocolIsInHTTPFamily(); |
eric@webkit.org | 8e38883 | 2009-02-06 23:25:18 +0000 | [diff] [blame] | 108 | |
darin@chromium.org | da869c1 | 2009-01-28 08:19:22 +0000 | [diff] [blame] | 109 | CString m_utf8; |
| 110 | |
| 111 | // Set to true when the caller set us using the ASCII setter. We can |
| 112 | // be more efficient when we know there is no UTF-8 to worry about. |
| 113 | // This flag is currently always correct, but should be changed to be a |
| 114 | // hint (see setUtf8). |
| 115 | bool m_utf8IsASCII; |
| 116 | |
| 117 | mutable bool m_stringIsValid; |
| 118 | mutable String m_string; |
ericu@chromium.org | 551f57f | 2012-01-25 22:43:19 +0000 | [diff] [blame] | 119 | |
| 120 | OwnPtr<KURL> m_innerURL; |
darin@chromium.org | da869c1 | 2009-01-28 08:19:22 +0000 | [diff] [blame] | 121 | }; |
| 122 | |
| 123 | } // namespace WebCore |
| 124 | |
| 125 | #endif |