KURLGooglePrivate.h revision 8f72e70a9fd78eec56623b3a62e68f16b7b27e28
1/* 2 * Copyright (c) 2008, 2009, 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 "CString.h" 35 36#include <googleurl/src/url_parse.h> 37#include <googleurl/src/url_canon.h> 38 39namespace WebCore { 40 41 class KURL; 42 class TextEncoding; 43 44 // Wraps the internals related to using Google-URL as the bnackend 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 52 // Initializes the object. This will call through to one of the backend 53 // initializers below depending on whether the string's internal 54 // representation is 8 or 16 bit. 55 void init(const KURL& base, const String& relative, 56 const TextEncoding* queryEncoding); 57 58 // Backend initializers. The query encoding parameters are optional and can 59 // be NULL (this implies UTF-8). These initializers require that the object 60 // has just been created and the strings are NULL. Do not call on an 61 // already-constructed object. 62 void init(const KURL& base, const char* rel, int relLength, 63 const TextEncoding* queryEncoding); 64 void init(const KURL& base, const UChar* rel, int relLength, 65 const TextEncoding* queryEncoding); 66 67 // Does a deep copy to the given output object. 68 void copyTo(KURLGooglePrivate* dest) const; 69 70 // Returns the substring of the input identified by the given component. 71 String componentString(const url_parse::Component&) const; 72 73 // Replaces the given components, modifying the current URL. The current 74 // URL must be valid. 75 typedef url_canon::Replacements<url_parse::UTF16Char> Replacements; 76 void replaceComponents(const Replacements&); 77 78 // Setters for the data. Using the ASCII version when you know the 79 // data is ASCII will be slightly more efficient. The UTF-8 version 80 // will always be correct if the caller is unsure. 81 void setUtf8(const CString&); 82 void setAscii(const CString&); 83 84 // TODO(brettw) we can support an additional optimization. Make this 85 // buffer support both optinal Strings and UTF-8 data. This way, we can use 86 // the optimization from the original KURL which uses = with the original 87 // string when canonicalization did not change it. This allows the strings 88 // to share a buffer internally, and saves a malloc. 89 90 // Getters for the data. 91 const CString& utf8String() const { return m_utf8; } 92 const String& string() const; 93 94 bool m_isValid; 95 bool m_protocolInHTTPFamily; 96 url_parse::Parsed m_parsed; // Indexes into the UTF-8 version of the string. 97 98 private: 99 void initProtocolInHTTPFamily(); 100 101 CString m_utf8; 102 103 // Set to true when the caller set us using the ASCII setter. We can 104 // be more efficient when we know there is no UTF-8 to worry about. 105 // This flag is currently always correct, but should be changed to be a 106 // hint (see setUtf8). 107 bool m_utf8IsASCII; 108 109 mutable bool m_stringIsValid; 110 mutable String m_string; 111 }; 112 113} // namespace WebCore 114 115#endif 116