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

Side by Side Diff: chrome/browser/net/url_fixer_upper.cc

Issue 31008: Coalesce more hardcoded schemes to using predefined constants. (Closed) Base URL: svn://chrome-svn/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 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <algorithm> 5 #include <algorithm>
6 6
7 #include "chrome/browser/net/url_fixer_upper.h" 7 #include "chrome/browser/net/url_fixer_upper.h"
8 8
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/string_util.h" 11 #include "base/string_util.h"
12 #include "chrome/common/gfx/text_elider.h" 12 #include "chrome/common/gfx/text_elider.h"
13 #include "chrome/common/url_constants.h"
13 #include "googleurl/src/gurl.h" 14 #include "googleurl/src/gurl.h"
14 #include "googleurl/src/url_canon.h" 15 #include "googleurl/src/url_canon.h"
15 #include "googleurl/src/url_file.h" 16 #include "googleurl/src/url_file.h"
16 #include "googleurl/src/url_parse.h" 17 #include "googleurl/src/url_parse.h"
17 #include "googleurl/src/url_util.h" 18 #include "googleurl/src/url_util.h"
18 #include "net/base/escape.h" 19 #include "net/base/escape.h"
19 #include "net/base/net_util.h" 20 #include "net/base/net_util.h"
20 #include "net/base/registry_controlled_domain.h" 21 #include "net/base/registry_controlled_domain.h"
21 22
22 using namespace std; 23 using namespace std;
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 // We need to fix up the segmentation for "www:123/". For this case, we 297 // We need to fix up the segmentation for "www:123/". For this case, we
297 // will add an HTTP scheme later and make the URL parser happy. 298 // will add an HTTP scheme later and make the URL parser happy.
298 // TODO(pkasting): Maybe we should try to use GURL's parser for this? 299 // TODO(pkasting): Maybe we should try to use GURL's parser for this?
299 HasPort(text, parts->scheme))) 300 HasPort(text, parts->scheme)))
300 parts->scheme.reset(); 301 parts->scheme.reset();
301 } 302 }
302 303
303 // When we couldn't find a scheme in the input, we need to pick one. Normally 304 // When we couldn't find a scheme in the input, we need to pick one. Normally
304 // we choose http, but if the URL starts with "ftp.", we match other browsers 305 // we choose http, but if the URL starts with "ftp.", we match other browsers
305 // and choose ftp. 306 // and choose ftp.
306 if (!parts->scheme.is_valid()) 307 if (!parts->scheme.is_valid()) {
307 scheme.assign(StartsWithASCII(text, "ftp.", false) ? "ftp" : "http"); 308 scheme.assign(StartsWithASCII(text, "ftp.", false) ?
309 chrome::kFtpScheme : chrome::kHttpScheme);
310 }
308 311
309 // Cannonicalize the scheme. 312 // Cannonicalize the scheme.
310 StringToLowerASCII(&scheme); 313 StringToLowerASCII(&scheme);
311 314
312 // Not segmenting file schemes or nonstandard schemes. 315 // Not segmenting file schemes or nonstandard schemes.
313 if ((scheme == "file") || 316 if ((scheme == chrome::kFileScheme) ||
314 !url_util::IsStandard(scheme.c_str(), static_cast<int>(scheme.length()), 317 !url_util::IsStandard(scheme.c_str(), static_cast<int>(scheme.length()),
315 url_parse::Component(0, static_cast<int>(scheme.length())))) 318 url_parse::Component(0, static_cast<int>(scheme.length()))))
316 return scheme; 319 return scheme;
317 320
318 if (parts->scheme.is_valid()) { 321 if (parts->scheme.is_valid()) {
319 // Have the GURL parser do the heavy lifting for us. 322 // Have the GURL parser do the heavy lifting for us.
320 url_parse::ParseStandardURL(text.data(), static_cast<int>(text.length()), 323 url_parse::ParseStandardURL(text.data(), static_cast<int>(text.length()),
321 parts); 324 parts);
322 return scheme; 325 return scheme;
323 } 326 }
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 } 473 }
471 wstring URLFixerUpper::FixupURL(const wstring& text, 474 wstring URLFixerUpper::FixupURL(const wstring& text,
472 const wstring& desired_tld) { 475 const wstring& desired_tld) {
473 return UTF8ToWide(FixupURL(WideToUTF8(text), WideToUTF8(desired_tld))); 476 return UTF8ToWide(FixupURL(WideToUTF8(text), WideToUTF8(desired_tld)));
474 } 477 }
475 wstring URLFixerUpper::FixupRelativeFile(const wstring& base_dir, 478 wstring URLFixerUpper::FixupRelativeFile(const wstring& base_dir,
476 const wstring& text) { 479 const wstring& text) {
477 return UTF8ToWide(FixupRelativeFile(FilePath::FromWStringHack(base_dir), 480 return UTF8ToWide(FixupRelativeFile(FilePath::FromWStringHack(base_dir),
478 FilePath::FromWStringHack(text))); 481 FilePath::FromWStringHack(text)));
479 } 482 }
OLDNEW
« no previous file with comments | « chrome/browser/importer/ie_importer.cc ('k') | chrome/browser/renderer_host/buffered_resource_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698