blob: 722263ebcc2cf6b3843f4b289a216d02486db563 [file] [log] [blame]
darin@chromium.orgda869c12009-01-28 08:19:22 +00001/*
commit-queue@webkit.org7763dc22011-02-11 01:01:30 +00002 * Copyright (c) 2008, 2009, 2011 Google Inc. All rights reserved.
darin@chromium.orgda869c12009-01-28 08:19:22 +00003 *
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.org5bd1cc02012-09-13 12:12:19 +000034#include <wtf/Forward.h>
ericu@chromium.org551f57f2012-01-25 22:43:19 +000035#include <wtf/OwnPtr.h>
barraclough@apple.com00b79922010-03-31 05:44:34 +000036#include <wtf/text/CString.h>
darin@chromium.orgda869c12009-01-28 08:19:22 +000037
38#include <googleurl/src/url_parse.h>
39#include <googleurl/src/url_canon.h>
40
41namespace WebCore {
42
43 class KURL;
44 class TextEncoding;
45
commit-queue@webkit.orgcfd41322011-02-11 08:14:07 +000046 // Wraps the internals related to using Google-URL as the backend for KURL.
darin@chromium.orgda869c12009-01-28 08:19:22 +000047 // 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.com0245dfc2012-07-26 08:55:13 +000053 explicit KURLGooglePrivate(WTF::HashTableDeletedValueType);
54 explicit KURLGooglePrivate(const KURLGooglePrivate&);
ericu@chromium.org551f57f2012-01-25 22:43:19 +000055 KURLGooglePrivate& operator=(const KURLGooglePrivate&);
darin@chromium.orgda869c12009-01-28 08:19:22 +000056
commit-queue@webkit.orgcfd41322011-02-11 08:14:07 +000057 // Initializes the object. This will call through the backend initializer
58 // below.
darin@chromium.orgda869c12009-01-28 08:19:22 +000059 void init(const KURL& base, const String& relative,
60 const TextEncoding* queryEncoding);
61
commit-queue@webkit.orgcfd41322011-02-11 08:14:07 +000062 // 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.org7763dc22011-02-11 01:01:30 +000064 // has just been created and the strings are null. Do not call on an
darin@chromium.orgda869c12009-01-28 08:19:22 +000065 // already-constructed object.
commit-queue@webkit.orgcfd41322011-02-11 08:14:07 +000066 template <typename CHAR>
67 void init(const KURL& base, const CHAR* rel, int relLength,
darin@chromium.orgda869c12009-01-28 08:19:22 +000068 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.orgc28bccf2009-02-13 19:01:12 +000084 void setUtf8(const CString&);
85 void setAscii(const CString&);
darin@chromium.orgda869c12009-01-28 08:19:22 +000086
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.com6eed1c12011-04-27 16:22:48 +000098 bool m_protocolIsInHTTPFamily;
darin@chromium.orgda869c12009-01-28 08:19:22 +000099 url_parse::Parsed m_parsed; // Indexes into the UTF-8 version of the string.
100
ericu@chromium.org551f57f2012-01-25 22:43:19 +0000101 KURL* innerURL() const { return m_innerURL.get(); }
102
loislo@chromium.org5bd1cc02012-09-13 12:12:19 +0000103 void reportMemoryUsage(MemoryObjectInfo*) const;
104
darin@chromium.orgda869c12009-01-28 08:19:22 +0000105 private:
ericu@chromium.org551f57f2012-01-25 22:43:19 +0000106 void initInnerURL();
darin@apple.com6eed1c12011-04-27 16:22:48 +0000107 void initProtocolIsInHTTPFamily();
eric@webkit.org8e388832009-02-06 23:25:18 +0000108
darin@chromium.orgda869c12009-01-28 08:19:22 +0000109 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.org551f57f2012-01-25 22:43:19 +0000119
120 OwnPtr<KURL> m_innerURL;
darin@chromium.orgda869c12009-01-28 08:19:22 +0000121 };
122
123} // namespace WebCore
124
125#endif