Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: third_party/WebKit/WebCore/platform/KURLGoogle.cpp

Issue 21343: Make it possible to initialize KURLGoogle from a CString. This is so that I... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 11 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2008, 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2008, 2009 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 , m_protocolInHTTPFamily(false) 127 , m_protocolInHTTPFamily(false)
128 , m_parsed(parsed) 128 , m_parsed(parsed)
129 , m_utf8IsASCII(true) 129 , m_utf8IsASCII(true)
130 , m_stringIsValid(false) 130 , m_stringIsValid(false)
131 { 131 {
132 } 132 }
133 133
134 // Setters for the data. Using the ASCII version when you know the 134 // Setters for the data. Using the ASCII version when you know the
135 // data is ASCII will be slightly more efficient. The UTF-8 version 135 // data is ASCII will be slightly more efficient. The UTF-8 version
136 // will always be correct if the caller is unsure. 136 // will always be correct if the caller is unsure.
137 void KURLGooglePrivate::setUtf8(const char* data, int dataLength) 137 void KURLGooglePrivate::setUtf8(const CString& str)
138 { 138 {
139 const char* data = str.data();
140 unsigned dataLength = str.length();
141
139 // The m_utf8IsASCII must always be correct since the DeprecatedString 142 // The m_utf8IsASCII must always be correct since the DeprecatedString
140 // getter must create it with the proper constructor. This test can be 143 // getter must create it with the proper constructor. This test can be
141 // removed when DeprecatedString is gone, but it still might be a 144 // removed when DeprecatedString is gone, but it still might be a
142 // performance win. 145 // performance win.
143 m_utf8IsASCII = true; 146 m_utf8IsASCII = true;
144 for (int i = 0; i < dataLength; i++) { 147 for (unsigned i = 0; i < dataLength; i++) {
145 if (static_cast<unsigned char>(data[i]) >= 0x80) { 148 if (static_cast<unsigned char>(data[i]) >= 0x80) {
146 m_utf8IsASCII = false; 149 m_utf8IsASCII = false;
147 break; 150 break;
148 } 151 }
149 } 152 }
150 153
151 m_utf8 = CString(data, dataLength); 154 m_utf8 = str;
152 m_stringIsValid = false; 155 m_stringIsValid = false;
153 initProtocolInHTTPFamily(); 156 initProtocolInHTTPFamily();
154 } 157 }
155 158
156 void KURLGooglePrivate::setAscii(const char* data, int dataLength) 159 void KURLGooglePrivate::setAscii(const CString& str)
157 { 160 {
158 m_utf8 = CString(data, dataLength); 161 m_utf8 = str;
159 m_utf8IsASCII = true; 162 m_utf8IsASCII = true;
160 m_stringIsValid = false; 163 m_stringIsValid = false;
161 initProtocolInHTTPFamily(); 164 initProtocolInHTTPFamily();
162 } 165 }
163 166
164 void KURLGooglePrivate::init(const KURL& base, 167 void KURLGooglePrivate::init(const KURL& base,
165 const String& relative, 168 const String& relative,
166 const TextEncoding* queryEncoding) 169 const TextEncoding* queryEncoding)
167 { 170 {
168 init(base, relative.characters(), relative.length(), queryEncoding); 171 init(base, relative.characters(), relative.length(), queryEncoding);
(...skipping 27 matching lines...) Expand all
196 // changed the string, we can avoid an extra allocation by using assignment. 199 // changed the string, we can avoid an extra allocation by using assignment.
197 // 200 //
198 // When KURL encounters an error such that the URL is invalid and empty 201 // When KURL encounters an error such that the URL is invalid and empty
199 // (for example, resolving a relative URL on a non-hierarchical base), it 202 // (for example, resolving a relative URL on a non-hierarchical base), it
200 // will produce an isNull URL, and calling setUtf8 will produce an empty 203 // will produce an isNull URL, and calling setUtf8 will produce an empty
201 // non-null URL. This is unlikely to affect anything, but we preserve this 204 // non-null URL. This is unlikely to affect anything, but we preserve this
202 // just in case. 205 // just in case.
203 if (m_isValid || output.length()) { 206 if (m_isValid || output.length()) {
204 // Without ref, the whole url is guaranteed to be ASCII-only. 207 // Without ref, the whole url is guaranteed to be ASCII-only.
205 if (m_parsed.ref.is_nonempty()) 208 if (m_parsed.ref.is_nonempty())
206 setUtf8(output.data(), output.length()); 209 setUtf8(CString(output.data(), output.length()));
207 else 210 else
208 setAscii(output.data(), output.length()); 211 setAscii(CString(output.data(), output.length()));
209 } else { 212 } else {
210 // WebCore expects resolved URLs to be empty rather than NULL. 213 // WebCore expects resolved URLs to be empty rather than NULL.
211 setUtf8("", 0); 214 setUtf8(CString("", 0));
212 } 215 }
213 } 216 }
214 217
215 // Note: code mostly duplicated above. See FIXMEs and comments there. 218 // Note: code mostly duplicated above. See FIXMEs and comments there.
216 void KURLGooglePrivate::init(const KURL& base, const UChar* rel, int relLength, 219 void KURLGooglePrivate::init(const KURL& base, const UChar* rel, int relLength,
217 const TextEncoding* queryEncoding) 220 const TextEncoding* queryEncoding)
218 { 221 {
219 KURLCharsetConverter charsetConverterObject(queryEncoding); 222 KURLCharsetConverter charsetConverterObject(queryEncoding);
220 KURLCharsetConverter* charsetConverter = 223 KURLCharsetConverter* charsetConverter =
221 (!queryEncoding || isUnicodeEncoding(queryEncoding)) ? 0 : 224 (!queryEncoding || isUnicodeEncoding(queryEncoding)) ? 0 :
222 &charsetConverterObject; 225 &charsetConverterObject;
223 226
224 url_canon::RawCanonOutputT<char> output; 227 url_canon::RawCanonOutputT<char> output;
225 const CString& baseStr = base.m_url.utf8String(); 228 const CString& baseStr = base.m_url.utf8String();
226 m_isValid = url_util::ResolveRelative(baseStr.data(), baseStr.length(), 229 m_isValid = url_util::ResolveRelative(baseStr.data(), baseStr.length(),
227 base.m_url.m_parsed, rel, relLength, 230 base.m_url.m_parsed, rel, relLength,
228 charsetConverter, 231 charsetConverter,
229 &output, &m_parsed); 232 &output, &m_parsed);
230 233
231 234
232 if (m_isValid || output.length()) { 235 if (m_isValid || output.length()) {
233 if (m_parsed.ref.is_nonempty()) 236 if (m_parsed.ref.is_nonempty())
234 setUtf8(output.data(), output.length()); 237 setUtf8(CString(output.data(), output.length()));
235 else 238 else
236 setAscii(output.data(), output.length()); 239 setAscii(CString(output.data(), output.length()));
237 } else 240 } else
238 setUtf8("", 0); 241 setUtf8(CString("", 0));
239 } 242 }
240 243
241 void KURLGooglePrivate::initProtocolInHTTPFamily() 244 void KURLGooglePrivate::initProtocolInHTTPFamily()
242 { 245 {
243 if (!m_isValid) { 246 if (!m_isValid) {
244 m_protocolInHTTPFamily = false; 247 m_protocolInHTTPFamily = false;
245 return; 248 return;
246 } 249 }
247 250
248 const char* scheme = m_utf8.data() + m_parsed.scheme.begin; 251 const char* scheme = m_utf8.data() + m_parsed.scheme.begin;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 void KURLGooglePrivate::replaceComponents(const Replacements& replacements) 292 void KURLGooglePrivate::replaceComponents(const Replacements& replacements)
290 { 293 {
291 url_canon::RawCanonOutputT<char> output; 294 url_canon::RawCanonOutputT<char> output;
292 url_parse::Parsed newParsed; 295 url_parse::Parsed newParsed;
293 296
294 m_isValid = url_util::ReplaceComponents(utf8String().data(), 297 m_isValid = url_util::ReplaceComponents(utf8String().data(),
295 utf8String().length(), m_parsed, rep lacements, 0, &output, &newParsed); 298 utf8String().length(), m_parsed, rep lacements, 0, &output, &newParsed);
296 299
297 m_parsed = newParsed; 300 m_parsed = newParsed;
298 if (m_parsed.ref.is_nonempty()) 301 if (m_parsed.ref.is_nonempty())
299 setUtf8(output.data(), output.length()); 302 setUtf8(CString(output.data(), output.length()));
300 else 303 else
301 setAscii(output.data(), output.length()); 304 setAscii(CString(output.data(), output.length()));
302 } 305 }
303 306
304 const String& KURLGooglePrivate::string() const 307 const String& KURLGooglePrivate::string() const
305 { 308 {
306 if (!m_stringIsValid) { 309 if (!m_stringIsValid) {
307 // Must special case the NULL case, since constructing the 310 // Must special case the NULL case, since constructing the
308 // string like we do below will generate an empty rather than 311 // string like we do below will generate an empty rather than
309 // a NULL string. 312 // a NULL string.
310 if (m_utf8.isNull()) 313 if (m_utf8.isNull())
311 m_string = String(); 314 m_string = String();
(...skipping 14 matching lines...) Expand all
326 KURL::KURL(const char *url) 329 KURL::KURL(const char *url)
327 { 330 {
328 // FIXME The Mac code checks for beginning with a slash and converting to a 331 // FIXME The Mac code checks for beginning with a slash and converting to a
329 // file: URL. We will want to add this as well once we can compile on a 332 // file: URL. We will want to add this as well once we can compile on a
330 // system like that. 333 // system like that.
331 m_url.init(KURL(), url, strlen(url), 0); 334 m_url.init(KURL(), url, strlen(url), 0);
332 335
333 // The one-argument constructors should never generate a NULL string. 336 // The one-argument constructors should never generate a NULL string.
334 // This is a funny quirk of KURL.cpp (probably a bug) which we preserve. 337 // This is a funny quirk of KURL.cpp (probably a bug) which we preserve.
335 if (m_url.utf8String().isNull()) 338 if (m_url.utf8String().isNull())
336 m_url.setAscii("", 0); 339 m_url.setAscii(CString("", 0));
337 } 340 }
338 341
339 // Initializes with a string representing an absolute URL. No encoding 342 // Initializes with a string representing an absolute URL. No encoding
340 // information is specified. This generally happens when a KURL is converted 343 // information is specified. This generally happens when a KURL is converted
341 // to a string and then converted back. In this case, the URL is already 344 // to a string and then converted back. In this case, the URL is already
342 // canonical and in proper escaped form so needs no encoding. We treat it was 345 // canonical and in proper escaped form so needs no encoding. We treat it was
343 // UTF-8 just in case. 346 // UTF-8 just in case.
344 KURL::KURL(const String& url) 347 KURL::KURL(const String& url)
345 { 348 {
346 if (!url.isNull()) 349 if (!url.isNull())
(...skipping 16 matching lines...) Expand all
363 366
364 // Constructs a new URL given a base URL and a possibly relative input URL. 367 // Constructs a new URL given a base URL and a possibly relative input URL.
365 // Any query portion of the relative URL will be encoded in the given encoding. 368 // Any query portion of the relative URL will be encoded in the given encoding.
366 KURL::KURL(const KURL& base, 369 KURL::KURL(const KURL& base,
367 const String& relative, 370 const String& relative,
368 const TextEncoding& encoding) 371 const TextEncoding& encoding)
369 { 372 {
370 m_url.init(base, relative, &encoding.encodingForFormSubmission()); 373 m_url.init(base, relative, &encoding.encodingForFormSubmission());
371 } 374 }
372 375
373 KURL::KURL(const char* canonicalSpec, int canonicalSpecLen, 376 KURL::KURL(const CString& canonicalSpec,
374 const url_parse::Parsed& parsed, bool isValid) 377 const url_parse::Parsed& parsed, bool isValid)
375 : m_url(parsed, isValid) 378 : m_url(parsed, isValid)
376 { 379 {
377 // We know the reference fragment is the only part that can be UTF-8, so 380 // We know the reference fragment is the only part that can be UTF-8, so
378 // we know it's ASCII when there is no ref. 381 // we know it's ASCII when there is no ref.
379 if (parsed.ref.is_nonempty()) 382 if (parsed.ref.is_nonempty())
380 m_url.setUtf8(canonicalSpec, canonicalSpecLen); 383 m_url.setUtf8(canonicalSpec);
381 else 384 else
382 m_url.setAscii(canonicalSpec, canonicalSpecLen); 385 m_url.setAscii(canonicalSpec);
383 } 386 }
384 387
385 #if PLATFORM(CF) 388 #if PLATFORM(CF)
386 KURL::KURL(CFURLRef) 389 KURL::KURL(CFURLRef)
387 { 390 {
388 notImplemented(); 391 notImplemented();
389 invalidate(); 392 invalidate();
390 } 393 }
391 394
392 CFURLRef KURL::createCFURL() const 395 CFURLRef KURL::createCFURL() const
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after
936 } 939 }
937 940
938 inline bool KURL::protocolIs(const String& string, const char* protocol) 941 inline bool KURL::protocolIs(const String& string, const char* protocol)
939 { 942 {
940 return WebCore::protocolIs(string, protocol); 943 return WebCore::protocolIs(string, protocol);
941 } 944 }
942 945
943 } // namespace WebCore 946 } // namespace WebCore
944 947
945 #endif // USE(GOOGLEURL) 948 #endif // USE(GOOGLEURL)
OLDNEW
« no previous file with comments | « third_party/WebKit/WebCore/platform/KURL.h ('k') | third_party/WebKit/WebCore/platform/KURLGooglePrivate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698