summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-09 22:20:40 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-09 22:20:40 +0000
commit1685f9b0efb3f65bc084e8b012357e2986d073d1 (patch)
treedafcc9e7d2bf8cddff882638432bd492c983fd77
parent6d1b928bc85521046fa7713abadc762beba11881 (diff)
downloadchromium_src-1685f9b0efb3f65bc084e8b012357e2986d073d1.zip
chromium_src-1685f9b0efb3f65bc084e8b012357e2986d073d1.tar.gz
chromium_src-1685f9b0efb3f65bc084e8b012357e2986d073d1.tar.bz2
Strips http from the omnibox
BUG=none TEST=type in urls and make sure once loaded we don't show http. Make sure we do show https (and other schemes) though. Review URL: http://codereview.chromium.org/1513023 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@44140 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--app/text_elider.cc9
-rw-r--r--app/text_elider_unittest.cc20
-rw-r--r--chrome/browser/autocomplete/autocomplete.cc8
-rw-r--r--chrome/browser/autocomplete/autocomplete.h3
-rw-r--r--chrome/browser/autocomplete/history_contents_provider.cc6
-rw-r--r--chrome/browser/autocomplete/history_url_provider.cc35
-rw-r--r--chrome/browser/autocomplete/search_provider.cc7
-rw-r--r--chrome/browser/bookmarks/bookmark_table_model.cc6
-rw-r--r--chrome/browser/bookmarks/bookmark_utils.cc3
-rw-r--r--chrome/browser/cocoa/status_bubble_mac_unittest.mm8
-rw-r--r--chrome/browser/gtk/options/passwords_exceptions_page_gtk.cc2
-rw-r--r--chrome/browser/gtk/options/passwords_page_gtk.cc4
-rw-r--r--chrome/browser/gtk/options/url_picker_dialog_gtk.cc3
-rw-r--r--chrome/browser/net/browser_url_util.cc6
-rw-r--r--chrome/browser/net/url_fixer_upper.cc8
-rw-r--r--chrome/browser/toolbar_model.cc4
-rw-r--r--chrome/browser/views/bookmark_editor_view.cc5
-rw-r--r--chrome/browser/views/url_picker.cc6
-rw-r--r--net/base/net_util.cc80
-rw-r--r--net/base/net_util.h42
-rw-r--r--net/base/net_util_unittest.cc160
21 files changed, 270 insertions, 155 deletions
diff --git a/app/text_elider.cc b/app/text_elider.cc
index 1098f82..ccdb3e33 100644
--- a/app/text_elider.cc
+++ b/app/text_elider.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -37,8 +37,8 @@ std::wstring ElideUrl(const GURL& url,
const std::wstring& languages) {
// Get a formatted string and corresponding parsing of the url.
url_parse::Parsed parsed;
- std::wstring url_string = net::FormatUrl(url, languages, true,
- UnescapeRule::SPACES, &parsed, NULL, NULL);
+ std::wstring url_string = net::FormatUrl(url, languages,
+ net::kFormatUrlOmitAll, UnescapeRule::SPACES, &parsed, NULL, NULL);
if (available_pixel_width <= 0)
return url_string;
@@ -363,7 +363,8 @@ SortedDisplayURL::SortedDisplayURL(const GURL& url,
string16 host_minus_www = WideToUTF16Hack(net::StripWWW(host));
url_parse::Parsed parsed;
display_url_ = WideToUTF16Hack(net::FormatUrl(url, languages,
- true, UnescapeRule::SPACES, &parsed, &prefix_end_, NULL));
+ net::kFormatUrlOmitAll, UnescapeRule::SPACES, &parsed, &prefix_end_,
+ NULL));
if (sort_host_.length() > host_minus_www.length()) {
prefix_end_ += sort_host_.length() - host_minus_www.length();
sort_host_.swap(host_minus_www);
diff --git a/app/text_elider_unittest.cc b/app/text_elider_unittest.cc
index d976333..caf619d 100644
--- a/app/text_elider_unittest.cc
+++ b/app/text_elider_unittest.cc
@@ -55,7 +55,7 @@ TEST(TextEliderTest, TestGeneralEliding) {
const std::wstring kEllipsisStr(kEllipsis);
Testcase testcases[] = {
{"http://www.google.com/intl/en/ads/",
- L"http://www.google.com/intl/en/ads/"},
+ L"www.google.com/intl/en/ads/"},
{"http://www.google.com/intl/en/ads/", L"www.google.com/intl/en/ads/"},
// TODO(port): make this test case work on mac.
#if !defined(OS_MACOSX)
@@ -73,7 +73,7 @@ TEST(TextEliderTest, TestGeneralEliding) {
{"http://subdomain.foo.com/bar/filename.html",
kEllipsisStr + L"foo.com/" + kEllipsisStr + L"/filename.html"},
{"http://www.google.com/intl/en/ads/?aLongQueryWhichIsNotRequired",
- L"http://www.google.com/intl/en/ads/?aLongQ" + kEllipsisStr},
+ L"www.google.com/intl/en/ads/?aLongQ" + kEllipsisStr},
};
RunTest(testcases, arraysize(testcases));
@@ -83,7 +83,7 @@ TEST(TextEliderTest, TestGeneralEliding) {
TEST(TextEliderTest, TestMoreEliding) {
const std::wstring kEllipsisStr(kEllipsis);
Testcase testcases[] = {
- {"http://www.google.com/foo?bar", L"http://www.google.com/foo?bar"},
+ {"http://www.google.com/foo?bar", L"www.google.com/foo?bar"},
{"http://xyz.google.com/foo?bar", L"xyz.google.com/foo?" + kEllipsisStr},
{"http://xyz.google.com/foo?bar", L"xyz.google.com/foo" + kEllipsisStr},
{"http://xyz.google.com/foo?bar", L"xyz.google.com/fo" + kEllipsisStr},
@@ -91,11 +91,11 @@ TEST(TextEliderTest, TestMoreEliding) {
{"", L""},
{"http://foo.bar..example.com...hello/test/filename.html",
L"foo.bar..example.com...hello/" + kEllipsisStr + L"/filename.html"},
- {"http://foo.bar../", L"http://foo.bar../"},
- {"http://xn--1lq90i.cn/foo", L"http://\x5317\x4eac.cn/foo"},
+ {"http://foo.bar../", L"foo.bar../"},
+ {"http://xn--1lq90i.cn/foo", L"\x5317\x4eac.cn/foo"},
{"http://me:mypass@secrethost.com:99/foo?bar#baz",
- L"http://secrethost.com:99/foo?bar#baz"},
- {"http://me:mypass@ss%xxfdsf.com/foo", L"http://ss%25xxfdsf.com/foo"},
+ L"secrethost.com:99/foo?bar#baz"},
+ {"http://me:mypass@ss%xxfdsf.com/foo", L"ss%25xxfdsf.com/foo"},
{"mailto:elgoato@elgoato.com", L"mailto:elgoato@elgoato.com"},
{"javascript:click(0)", L"javascript:click(0)"},
{"https://chess.eecs.berkeley.edu:4430/login/arbitfilename",
@@ -105,13 +105,13 @@ TEST(TextEliderTest, TestMoreEliding) {
// Unescaping.
{"http://www/%E4%BD%A0%E5%A5%BD?q=%E4%BD%A0%E5%A5%BD#\xe4\xbd\xa0",
- L"http://www/\x4f60\x597d?q=\x4f60\x597d#\x4f60"},
+ L"www/\x4f60\x597d?q=\x4f60\x597d#\x4f60"},
// Invalid unescaping for path. The ref will always be valid UTF-8. We don't
// bother to do too many edge cases, since these are handled by the escaper
// unittest.
{"http://www/%E4%A0%E5%A5%BD?q=%E4%BD%A0%E5%A5%BD#\xe4\xbd\xa0",
- L"http://www/%E4%A0%E5%A5%BD?q=\x4f60\x597d#\x4f60"},
+ L"www/%E4%A0%E5%A5%BD?q=\x4f60\x597d#\x4f60"},
};
RunTest(testcases, arraysize(testcases));
@@ -229,7 +229,7 @@ TEST(TextEliderTest, ElideTextLongStrings) {
// Verifies display_url is set correctly.
TEST(TextEliderTest, SortedDisplayURL) {
gfx::SortedDisplayURL d_url(GURL("http://www.google.com/"), std::wstring());
- EXPECT_EQ("http://www.google.com/", UTF16ToASCII(d_url.display_url()));
+ EXPECT_EQ("www.google.com/", UTF16ToASCII(d_url.display_url()));
}
// Verifies DisplayURL::Compare works correctly.
diff --git a/chrome/browser/autocomplete/autocomplete.cc b/chrome/browser/autocomplete/autocomplete.cc
index b6d7764..1278a9b 100644
--- a/chrome/browser/autocomplete/autocomplete.cc
+++ b/chrome/browser/autocomplete/autocomplete.cc
@@ -595,10 +595,14 @@ void AutocompleteProvider::UpdateStarredStateOfMatches() {
std::wstring AutocompleteProvider::StringForURLDisplay(
const GURL& url,
- bool check_accept_lang) const {
+ bool check_accept_lang,
+ bool trim_http) const {
std::wstring languages = (check_accept_lang && profile_) ?
profile_->GetPrefs()->GetString(prefs::kAcceptLanguages) : std::wstring();
- return net::FormatUrl(url, languages);
+ const net::FormatUrlTypes format_types = trim_http ?
+ net::kFormatUrlOmitAll : net::kFormatUrlOmitUsernamePassword;
+ return net::FormatUrl(url, languages, format_types, UnescapeRule::SPACES,
+ NULL, NULL, NULL);
}
// AutocompleteResult ---------------------------------------------------------
diff --git a/chrome/browser/autocomplete/autocomplete.h b/chrome/browser/autocomplete/autocomplete.h
index 124783f1..54bd9ff 100644
--- a/chrome/browser/autocomplete/autocomplete.h
+++ b/chrome/browser/autocomplete/autocomplete.h
@@ -561,7 +561,8 @@ class AutocompleteProvider
// "Accept Languages" when check_accept_lang is true. Otherwise, it's called
// with an empty list.
std::wstring StringForURLDisplay(const GURL& url,
- bool check_accept_lang) const;
+ bool check_accept_lang,
+ bool trim_http) const;
// The profile associated with the AutocompleteProvider. Reference is not
// owned by us.
diff --git a/chrome/browser/autocomplete/history_contents_provider.cc b/chrome/browser/autocomplete/history_contents_provider.cc
index ac81c31..1e72ceb 100644
--- a/chrome/browser/autocomplete/history_contents_provider.cc
+++ b/chrome/browser/autocomplete/history_contents_provider.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -207,11 +207,9 @@ AutocompleteMatch HistoryContentsProvider::ResultToMatch(
// Also show star in popup.
AutocompleteMatch match(this, score, false, MatchInTitle(result) ?
AutocompleteMatch::HISTORY_TITLE : AutocompleteMatch::HISTORY_BODY);
- match.fill_into_edit = StringForURLDisplay(result.url(), true);
+ match.fill_into_edit = StringForURLDisplay(result.url(), true, trim_http_);
match.destination_url = result.url();
match.contents = match.fill_into_edit;
- if (trim_http_)
- TrimHttpPrefix(&match.contents);
match.contents_class.push_back(
ACMatchClassification(0, ACMatchClassification::URL));
match.description = result.title();
diff --git a/chrome/browser/autocomplete/history_url_provider.cc b/chrome/browser/autocomplete/history_url_provider.cc
index 2708d47..8462925 100644
--- a/chrome/browser/autocomplete/history_url_provider.cc
+++ b/chrome/browser/autocomplete/history_url_provider.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -256,11 +256,9 @@ AutocompleteMatch HistoryURLProvider::SuggestExactInput(
const GURL& url = input.canonicalized_url();
if (url.is_valid()) {
match.destination_url = url;
- match.fill_into_edit = StringForURLDisplay(url, false);
+ match.fill_into_edit = StringForURLDisplay(url, false, trim_http);
// NOTE: Don't set match.input_location (to allow inline autocompletion)
// here, it's surprising and annoying.
- // Trim off "http://" if the user didn't type it.
- const size_t offset = trim_http ? TrimHttpPrefix(&match.fill_into_edit) : 0;
// Try to highlight "innermost" match location. If we fix up "w" into
// "www.w.com", we want to highlight the fifth character, not the first.
@@ -272,7 +270,7 @@ AutocompleteMatch HistoryURLProvider::SuggestExactInput(
// to not contain the user's input at all. In this case don't mark anything
// as a match.
const size_t match_location = (best_prefix == NULL) ?
- std::wstring::npos : best_prefix->prefix.length() - offset;
+ std::wstring::npos : best_prefix->prefix.length();
AutocompleteMatch::ClassifyLocationInString(match_location,
input.text().length(),
match.contents.length(),
@@ -828,17 +826,13 @@ AutocompleteMatch HistoryURLProvider::HistoryMatchToACMatch(
DCHECK(match.destination_url.is_valid());
size_t inline_autocomplete_offset =
history_match.input_location + params->input.text().length();
+ const net::FormatUrlTypes format_types =
+ (params->trim_http && !history_match.match_in_scheme) ?
+ net::kFormatUrlOmitAll : net::kFormatUrlOmitUsernamePassword;
match.fill_into_edit = net::FormatUrl(info.url(),
- match_type == WHAT_YOU_TYPED ? std::wstring() : params->languages, true,
- UnescapeRule::SPACES, NULL, NULL, &inline_autocomplete_offset);
- size_t offset = 0;
- if (params->trim_http && !history_match.match_in_scheme) {
- offset = TrimHttpPrefix(&match.fill_into_edit);
- if (inline_autocomplete_offset != std::wstring::npos) {
- DCHECK(inline_autocomplete_offset >= offset);
- inline_autocomplete_offset -= offset;
- }
- }
+ match_type == WHAT_YOU_TYPED ? std::wstring() : params->languages,
+ format_types, UnescapeRule::SPACES, NULL, NULL,
+ &inline_autocomplete_offset);
if (!params->input.prevent_inline_autocomplete())
match.inline_autocomplete_offset = inline_autocomplete_offset;
DCHECK((match.inline_autocomplete_offset == std::wstring::npos) ||
@@ -846,15 +840,8 @@ AutocompleteMatch HistoryURLProvider::HistoryMatchToACMatch(
size_t match_start = history_match.input_location;
match.contents = net::FormatUrl(info.url(),
- match_type == WHAT_YOU_TYPED ? std::wstring() : params->languages, true,
- UnescapeRule::SPACES, NULL, NULL, &match_start);
- if (offset) {
- TrimHttpPrefix(&match.contents);
- if (match_start != std::wstring::npos) {
- DCHECK(match_start >= offset);
- match_start -= offset;
- }
- }
+ match_type == WHAT_YOU_TYPED ? std::wstring() : params->languages,
+ format_types, UnescapeRule::SPACES, NULL, NULL, &match_start);
if ((match_start != std::wstring::npos) &&
(inline_autocomplete_offset != std::wstring::npos) &&
(inline_autocomplete_offset != match_start)) {
diff --git a/chrome/browser/autocomplete/search_provider.cc b/chrome/browser/autocomplete/search_provider.cc
index 9a01fef..acba81e 100644
--- a/chrome/browser/autocomplete/search_provider.cc
+++ b/chrome/browser/autocomplete/search_provider.cc
@@ -737,10 +737,9 @@ AutocompleteMatch SearchProvider::NavigationToMatch(
AutocompleteMatch match(this, relevance, false,
AutocompleteMatch::NAVSUGGEST);
match.destination_url = navigation.url;
- match.contents = StringForURLDisplay(navigation.url, true);
- if (!url_util::FindAndCompareScheme(WideToUTF8(input_text),
- chrome::kHttpScheme, NULL))
- TrimHttpPrefix(&match.contents);
+ const bool trim_http = !url_util::FindAndCompareScheme(
+ WideToUTF8(input_text), chrome::kHttpScheme, NULL);
+ match.contents = StringForURLDisplay(navigation.url, true, trim_http);
AutocompleteMatch::ClassifyMatchInString(input_text, match.contents,
ACMatchClassification::URL,
&match.contents_class);
diff --git a/chrome/browser/bookmarks/bookmark_table_model.cc b/chrome/browser/bookmarks/bookmark_table_model.cc
index f7848e4..0ac5416 100644
--- a/chrome/browser/bookmarks/bookmark_table_model.cc
+++ b/chrome/browser/bookmarks/bookmark_table_model.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -325,8 +325,8 @@ std::wstring BookmarkTableModel::GetText(int row, int column_id) {
std::wstring languages = model_ && model_->profile()
? model_->profile()->GetPrefs()->GetString(prefs::kAcceptLanguages)
: std::wstring();
- std::wstring url_text = net::FormatUrl(node->GetURL(), languages, false,
- UnescapeRule::SPACES, NULL, NULL, NULL);
+ std::wstring url_text = net::FormatUrl(node->GetURL(), languages,
+ net::kFormatUrlOmitAll, UnescapeRule::SPACES, NULL, NULL, NULL);
if (base::i18n::IsRTL())
base::i18n::WrapStringWithLTRFormatting(&url_text);
return url_text;
diff --git a/chrome/browser/bookmarks/bookmark_utils.cc b/chrome/browser/bookmarks/bookmark_utils.cc
index 2214e4c..4ffeeb2 100644
--- a/chrome/browser/bookmarks/bookmark_utils.cc
+++ b/chrome/browser/bookmarks/bookmark_utils.cc
@@ -224,7 +224,8 @@ bool DoesBookmarkContainWords(const BookmarkNode* node,
DoesBookmarkTextContainWords(
l10n_util::ToLower(UTF8ToWide(node->GetURL().spec())), words) ||
DoesBookmarkTextContainWords(l10n_util::ToLower(net::FormatUrl(
- node->GetURL(), languages, false, true, NULL, NULL, NULL)), words);
+ node->GetURL(), languages, net::kFormatUrlOmitNothing,
+ UnescapeRule::NORMAL, NULL, NULL, NULL)), words);
}
} // namespace
diff --git a/chrome/browser/cocoa/status_bubble_mac_unittest.mm b/chrome/browser/cocoa/status_bubble_mac_unittest.mm
index 3dd628e..6f4dab4 100644
--- a/chrome/browser/cocoa/status_bubble_mac_unittest.mm
+++ b/chrome/browser/cocoa/status_bubble_mac_unittest.mm
@@ -141,7 +141,7 @@ TEST_F(StatusBubbleMacTest, SetURL) {
EXPECT_TRUE([GetURLText() isEqualToString:@"foopy://"]);
bubble_->SetURL(GURL("http://www.cnn.com"), L"");
EXPECT_TRUE(IsVisible());
- EXPECT_TRUE([GetURLText() isEqualToString:@"http://www.cnn.com/"]);
+ EXPECT_TRUE([GetURLText() isEqualToString:@"www.cnn.com/"]);
}
// Test hiding bubble that's already hidden.
@@ -162,7 +162,7 @@ TEST_F(StatusBubbleMacTest, SetStatusAndURL) {
EXPECT_TRUE([GetBubbleViewText() isEqualToString:@"Status"]);
bubble_->SetURL(GURL("http://www.nytimes.com/"), L"");
EXPECT_TRUE(IsVisible());
- EXPECT_TRUE([GetBubbleViewText() isEqualToString:@"http://www.nytimes.com/"]);
+ EXPECT_TRUE([GetBubbleViewText() isEqualToString:@"www.nytimes.com/"]);
bubble_->SetURL(GURL(), L"");
EXPECT_TRUE(IsVisible());
EXPECT_TRUE([GetBubbleViewText() isEqualToString:@"Status"]);
@@ -170,13 +170,13 @@ TEST_F(StatusBubbleMacTest, SetStatusAndURL) {
EXPECT_FALSE(IsVisible());
bubble_->SetURL(GURL("http://www.nytimes.com/"), L"");
EXPECT_TRUE(IsVisible());
- EXPECT_TRUE([GetBubbleViewText() isEqualToString:@"http://www.nytimes.com/"]);
+ EXPECT_TRUE([GetBubbleViewText() isEqualToString:@"www.nytimes.com/"]);
bubble_->SetStatus(L"Status");
EXPECT_TRUE(IsVisible());
EXPECT_TRUE([GetBubbleViewText() isEqualToString:@"Status"]);
bubble_->SetStatus(L"");
EXPECT_TRUE(IsVisible());
- EXPECT_TRUE([GetBubbleViewText() isEqualToString:@"http://www.nytimes.com/"]);
+ EXPECT_TRUE([GetBubbleViewText() isEqualToString:@"www.nytimes.com/"]);
bubble_->SetURL(GURL(), L"");
EXPECT_FALSE(IsVisible());
}
diff --git a/chrome/browser/gtk/options/passwords_exceptions_page_gtk.cc b/chrome/browser/gtk/options/passwords_exceptions_page_gtk.cc
index 5488e4f..8162610 100644
--- a/chrome/browser/gtk/options/passwords_exceptions_page_gtk.cc
+++ b/chrome/browser/gtk/options/passwords_exceptions_page_gtk.cc
@@ -116,7 +116,7 @@ void PasswordsExceptionsPageGtk::SetExceptionList(
for (size_t i = 0; i < result.size(); ++i) {
exception_list_[i] = *result[i];
std::wstring formatted = net::FormatUrl(result[i]->origin, languages,
- false, UnescapeRule::NONE, NULL, NULL, NULL);
+ net::kFormatUrlOmitAll, UnescapeRule::NONE, NULL, NULL, NULL);
std::string site = WideToUTF8(formatted);
GtkTreeIter iter;
gtk_list_store_insert_with_values(exception_list_store_, &iter, (gint) i,
diff --git a/chrome/browser/gtk/options/passwords_page_gtk.cc b/chrome/browser/gtk/options/passwords_page_gtk.cc
index 0de0403..9ecf89f 100644
--- a/chrome/browser/gtk/options/passwords_page_gtk.cc
+++ b/chrome/browser/gtk/options/passwords_page_gtk.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -160,7 +160,7 @@ void PasswordsPageGtk::SetPasswordList(
for (size_t i = 0; i < result.size(); ++i) {
password_list_[i] = *result[i];
std::wstring formatted = net::FormatUrl(result[i]->origin, languages,
- false, UnescapeRule::NONE, NULL, NULL, NULL);
+ net::kFormatUrlOmitAll, UnescapeRule::NONE, NULL, NULL, NULL);
std::string site = WideToUTF8(formatted);
std::string user = UTF16ToUTF8(result[i]->username_value);
GtkTreeIter iter;
diff --git a/chrome/browser/gtk/options/url_picker_dialog_gtk.cc b/chrome/browser/gtk/options/url_picker_dialog_gtk.cc
index df45b14..b5e5a5b 100644
--- a/chrome/browser/gtk/options/url_picker_dialog_gtk.cc
+++ b/chrome/browser/gtk/options/url_picker_dialog_gtk.cc
@@ -198,7 +198,8 @@ std::string UrlPickerDialogGtk::GetURLForPath(GtkTreePath* path) const {
// Because the url_field_ is user-editable, we set the URL with
// username:password and escaped path and query.
std::wstring formatted = net::FormatUrl(url_table_model_->GetURL(row),
- languages, false, UnescapeRule::NONE, NULL, NULL, NULL);
+ languages, net::kFormatUrlOmitNothing, UnescapeRule::NONE, NULL, NULL,
+ NULL);
return WideToUTF8(formatted);
}
diff --git a/chrome/browser/net/browser_url_util.cc b/chrome/browser/net/browser_url_util.cc
index 9c8ab48..24747b2 100644
--- a/chrome/browser/net/browser_url_util.cc
+++ b/chrome/browser/net/browser_url_util.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -23,8 +23,8 @@ void WriteURLToClipboard(const GURL& url,
// may not encode non-ASCII characters in UTF-8. See crbug.com/2820.
string16 text = url.SchemeIs(chrome::kMailToScheme) ?
ASCIIToUTF16(url.path()) :
- WideToUTF16(net::FormatUrl(url, languages, false, UnescapeRule::NONE,
- NULL, NULL, NULL));
+ WideToUTF16(net::FormatUrl(url, languages, net::kFormatUrlOmitNothing,
+ UnescapeRule::NONE, NULL, NULL, NULL));
ScopedClipboardWriter scw(clipboard);
scw.WriteURL(text);
diff --git a/chrome/browser/net/url_fixer_upper.cc b/chrome/browser/net/url_fixer_upper.cc
index edacefd..9d974db 100644
--- a/chrome/browser/net/url_fixer_upper.cc
+++ b/chrome/browser/net/url_fixer_upper.cc
@@ -170,8 +170,9 @@ static std::string FixupPath(const std::string& text) {
// Here, we know the input looks like a file.
GURL file_url = net::FilePathToFileURL(FilePath(filename));
if (file_url.is_valid()) {
- return WideToUTF8(net::FormatUrl(file_url, std::wstring(), true,
- UnescapeRule::NORMAL, NULL, NULL, NULL));
+ return WideToUTF8(net::FormatUrl(file_url, std::wstring(),
+ net::kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL, NULL,
+ NULL, NULL));
}
// Invalid file URL, just return the input.
@@ -557,7 +558,8 @@ std::string URLFixerUpper::FixupRelativeFile(const FilePath& base_dir,
GURL file_url = net::FilePathToFileURL(full_path);
if (file_url.is_valid())
return WideToUTF8(net::FormatUrl(file_url, std::wstring(),
- true, UnescapeRule::NORMAL, NULL, NULL, NULL));
+ net::kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL, NULL,
+ NULL, NULL));
// Invalid files fall through to regular processing.
}
diff --git a/chrome/browser/toolbar_model.cc b/chrome/browser/toolbar_model.cc
index add91d8..eeae184 100644
--- a/chrome/browser/toolbar_model.cc
+++ b/chrome/browser/toolbar_model.cc
@@ -53,8 +53,8 @@ std::wstring ToolbarModel::GetText() const {
url = GURL(url.scheme() + ":");
}
}
- return net::FormatUrl(url, languages, true, UnescapeRule::NORMAL, NULL, NULL,
- NULL);
+ return net::FormatUrl(url, languages, net::kFormatUrlOmitAll,
+ UnescapeRule::NORMAL, NULL, NULL, NULL);
}
ToolbarModel::SecurityLevel ToolbarModel::GetSecurityLevel() const {
diff --git a/chrome/browser/views/bookmark_editor_view.cc b/chrome/browser/views/bookmark_editor_view.cc
index 34f8e91..bd61ab3 100644
--- a/chrome/browser/views/bookmark_editor_view.cc
+++ b/chrome/browser/views/bookmark_editor_view.cc
@@ -282,10 +282,9 @@ void BookmarkEditorView::Init() {
std::wstring languages = profile_
? profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)
: std::wstring();
- // The following URL is user-editable. We specify omit_username_password=
- // false and unescape=false to show the original URL except IDN.
+ // The following URL is user-editable, so we don't strip anything from it.
url_text = net::FormatUrl(details_.existing_node->GetURL(), languages,
- false, UnescapeRule::NONE, NULL, NULL, NULL);
+ net::kFormatUrlOmitNothing, UnescapeRule::NONE, NULL, NULL, NULL);
}
url_tf_.SetText(url_text);
url_tf_.SetController(this);
diff --git a/chrome/browser/views/url_picker.cc b/chrome/browser/views/url_picker.cc
index 5f82832..3d275d4 100644
--- a/chrome/browser/views/url_picker.cc
+++ b/chrome/browser/views/url_picker.cc
@@ -221,10 +221,10 @@ void UrlPicker::OnSelectionChanged() {
if (selection >= 0 && selection < url_table_model_->RowCount()) {
std::wstring languages =
profile_->GetPrefs()->GetString(prefs::kAcceptLanguages);
- // Because the url_field_ is user-editable, we set the URL with
- // username:password and escaped path and query.
+ // Because the url_field_ is user-editable, we don't strip anything.
std::wstring formatted = net::FormatUrl(url_table_model_->GetURL(selection),
- languages, false, UnescapeRule::NONE, NULL, NULL, NULL);
+ languages, net::kFormatUrlOmitNothing, UnescapeRule::NONE, NULL, NULL,
+ NULL);
url_field_->SetText(formatted);
GetDialogClientView()->UpdateDialogButtons();
}
diff --git a/net/base/net_util.cc b/net/base/net_util.cc
index a66d27a..099746b 100644
--- a/net/base/net_util.cc
+++ b/net/base/net_util.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -707,10 +707,30 @@ bool IDNToUnicodeOneComponent(const char16* comp,
return false;
}
+// If |component| is valid, its begin is incremented by |delta|.
+void AdjustComponent(int delta, url_parse::Component* component) {
+ if (!component->is_valid())
+ return;
+
+ DCHECK(delta >= 0 || component->begin >= -delta);
+ component->begin += delta;
+}
+
+// Adjusts all the components of |parsed| by |delta|, except for the scheme.
+void AdjustComponents(int delta, url_parse::Parsed* parsed) {
+ AdjustComponent(delta, &(parsed->username));
+ AdjustComponent(delta, &(parsed->password));
+ AdjustComponent(delta, &(parsed->host));
+ AdjustComponent(delta, &(parsed->port));
+ AdjustComponent(delta, &(parsed->path));
+ AdjustComponent(delta, &(parsed->query));
+ AdjustComponent(delta, &(parsed->ref));
+}
+
// Helper for FormatUrl().
std::wstring FormatViewSourceUrl(const GURL& url,
const std::wstring& languages,
- bool omit_username_password,
+ net::FormatUrlTypes format_types,
UnescapeRule::Type unescape_rules,
url_parse::Parsed* new_parsed,
size_t* prefix_end,
@@ -725,8 +745,7 @@ std::wstring FormatViewSourceUrl(const GURL& url,
size_t* temp_offset_ptr = (*offset_for_adjustment < kViewSourceLengthPlus1) ?
NULL : &temp_offset;
std::wstring result = net::FormatUrl(real_url, languages,
- omit_username_password, unescape_rules, new_parsed, prefix_end,
- temp_offset_ptr);
+ format_types, unescape_rules, new_parsed, prefix_end, temp_offset_ptr);
result.insert(0, kWideViewSource);
// Adjust position values.
@@ -737,20 +756,7 @@ std::wstring FormatViewSourceUrl(const GURL& url,
new_parsed->scheme.begin = 0;
new_parsed->scheme.len = kViewSourceLengthPlus1 - 1;
}
- if (new_parsed->username.is_nonempty())
- new_parsed->username.begin += kViewSourceLengthPlus1;
- if (new_parsed->password.is_nonempty())
- new_parsed->password.begin += kViewSourceLengthPlus1;
- if (new_parsed->host.is_nonempty())
- new_parsed->host.begin += kViewSourceLengthPlus1;
- if (new_parsed->port.is_nonempty())
- new_parsed->port.begin += kViewSourceLengthPlus1;
- if (new_parsed->path.is_nonempty())
- new_parsed->path.begin += kViewSourceLengthPlus1;
- if (new_parsed->query.is_nonempty())
- new_parsed->query.begin += kViewSourceLengthPlus1;
- if (new_parsed->ref.is_nonempty())
- new_parsed->ref.begin += kViewSourceLengthPlus1;
+ AdjustComponents(kViewSourceLengthPlus1, new_parsed);
if (prefix_end)
*prefix_end += kViewSourceLengthPlus1;
if (temp_offset_ptr) {
@@ -764,6 +770,12 @@ std::wstring FormatViewSourceUrl(const GURL& url,
namespace net {
+const FormatUrlType kFormatUrlOmitNothing = 0;
+const FormatUrlType kFormatUrlOmitUsernamePassword = 1 << 0;
+const FormatUrlType kFormatUrlOmitHTTP = 1 << 1;
+const FormatUrlType kFormatUrlOmitAll = kFormatUrlOmitUsernamePassword |
+ kFormatUrlOmitHTTP;
+
std::set<int> explicitly_allowed_ports;
// Appends the substring |in_component| inside of the URL |spec| to |output|,
@@ -1372,7 +1384,7 @@ void AppendFormattedComponent(const std::string& spec,
std::wstring FormatUrl(const GURL& url,
const std::wstring& languages,
- bool omit_username_password,
+ FormatUrlTypes format_types,
UnescapeRule::Type unescape_rules,
url_parse::Parsed* new_parsed,
size_t* prefix_end,
@@ -1401,7 +1413,7 @@ std::wstring FormatUrl(const GURL& url,
// Rejects view-source:view-source:... to avoid deep recursive call.
if (url.SchemeIs(kViewSource) &&
!StartsWithASCII(url.possibly_invalid_spec(), kViewSourceTwice, false)) {
- return FormatViewSourceUrl(url, languages, omit_username_password,
+ return FormatViewSourceUrl(url, languages, format_types,
unescape_rules, new_parsed, prefix_end, offset_for_adjustment);
}
@@ -1418,9 +1430,15 @@ std::wstring FormatUrl(const GURL& url,
spec.begin() + parsed.CountCharactersBefore(url_parse::Parsed::USERNAME,
true),
std::back_inserter(url_string));
+
+ const wchar_t* const kHTTP = L"http://";
+ const size_t kHTTPSize = std::wstring(kHTTP).size();
+ bool omit_http = ((format_types & kFormatUrlOmitHTTP) != 0 &&
+ url_string == kHTTP);
+
new_parsed->scheme = parsed.scheme;
- if (omit_username_password) {
+ if ((format_types & kFormatUrlOmitUsernamePassword) != 0) {
// Remove the username and password fields. We don't want to display those
// to the user since they can be used for attacks,
// e.g. "http://google.com:search@evil.ru/"
@@ -1520,6 +1538,26 @@ std::wstring FormatUrl(const GURL& url,
}
}
+ // If we need to strip out http do it after the fact. This way we don't need
+ // to worry about how offset_for_adjustment is interpreted.
+ if (omit_http && !url_string.compare(0, kHTTPSize, kHTTP)) {
+ url_string = url_string.substr(kHTTPSize);
+ if (*offset_for_adjustment != std::wstring::npos) {
+ if (*offset_for_adjustment < kHTTPSize)
+ *offset_for_adjustment = std::wstring::npos;
+ else
+ *offset_for_adjustment -= kHTTPSize;
+ }
+ if (prefix_end)
+ *prefix_end -= kHTTPSize;
+
+ // Adjust new_parsed.
+ DCHECK(new_parsed->scheme.is_valid());
+ int delta = -(new_parsed->scheme.len + 3); // +3 for ://.
+ new_parsed->scheme.reset();
+ AdjustComponents(delta, new_parsed);
+ }
+
return url_string;
}
diff --git a/net/base/net_util.h b/net/base/net_util.h
index f614eb6..53314bf 100644
--- a/net/base/net_util.h
+++ b/net/base/net_util.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -36,6 +36,22 @@ struct Parsed;
namespace net {
+// Used by FormatUrl to specify handling of certain parts of the url.
+typedef uint32 FormatUrlType;
+typedef uint32 FormatUrlTypes;
+
+// Nothing is ommitted.
+extern const FormatUrlType kFormatUrlOmitNothing;
+
+// If set, any username and password are removed.
+extern const FormatUrlType kFormatUrlOmitUsernamePassword;
+
+// If the scheme is 'http://', it's removed.
+extern const FormatUrlType kFormatUrlOmitHTTP;
+
+// Convenience for omitting all unecessary types.
+extern const FormatUrlType kFormatUrlOmitAll;
+
// Holds a list of ports that should be accepted despite bans.
extern std::set<int> explicitly_allowed_ports;
@@ -245,13 +261,12 @@ void AppendFormattedHost(const GURL& url,
size_t* offset_for_adjustment);
// Creates a string representation of |url|. The IDN host name may be in Unicode
-// if |languages| accepts the Unicode representation. If
-// |omit_username_password| is true, any username and password are removed.
-// |unescape_rules| defines how to clean the URL for human readability.
-// You will generally want |UnescapeRule::SPACES| for display to the user if you
-// can handle spaces, or |UnescapeRule::NORMAL| if not. If the path part and the
-// query part seem to be encoded in %-encoded UTF-8, decodes %-encoding and
-// UTF-8.
+// if |languages| accepts the Unicode representation. |format_type| is a bitmask
+// of FormatUrlTypes, see it for details. |unescape_rules| defines how to clean
+// the URL for human readability. You will generally want |UnescapeRule::SPACES|
+// for display to the user if you can handle spaces, or |UnescapeRule::NORMAL|
+// if not. If the path part and the query part seem to be encoded in %-encoded
+// UTF-8, decodes %-encoding and UTF-8.
//
// The last three parameters may be NULL.
// |new_parsed| will be set to the parsing parameters of the resultant URL.
@@ -267,18 +282,17 @@ void AppendFormattedHost(const GURL& url,
// std::wstring::npos.
std::wstring FormatUrl(const GURL& url,
const std::wstring& languages,
- bool omit_username_password,
+ FormatUrlTypes format_types,
UnescapeRule::Type unescape_rules,
url_parse::Parsed* new_parsed,
size_t* prefix_end,
size_t* offset_for_adjustment);
-// Creates a string representation of |url| for display to the user.
-// This is a shorthand of the above function with omit_username_password=true,
-// unescape=SPACES, new_parsed=NULL, and prefix_end=NULL.
+// This is a convenience for FormatUrl with
+// format_types=kFormatUrlOmitUsernamePassword and unescape=SPACES.
inline std::wstring FormatUrl(const GURL& url, const std::wstring& languages) {
- return FormatUrl(url, languages, true, UnescapeRule::SPACES, NULL, NULL,
- NULL);
+ return FormatUrl(url, languages, kFormatUrlOmitUsernamePassword,
+ UnescapeRule::SPACES, NULL, NULL, NULL);
}
// Strip the portions of |url| that aren't core to the network request.
diff --git a/net/base/net_util_unittest.cc b/net/base/net_util_unittest.cc
index 833375c..4c1ae52 100644
--- a/net/base/net_util_unittest.cc
+++ b/net/base/net_util_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -364,7 +364,7 @@ struct UrlTestData {
const char* description;
const char* input;
const std::wstring languages;
- bool omit;
+ net::FormatUrlTypes format_types;
UnescapeRule::Type escape_rules;
const std::wstring output;
size_t prefix_len;
@@ -1267,74 +1267,78 @@ TEST(NetUtilTest, GetHostName) {
}
TEST(NetUtilTest, FormatUrl) {
+ net::FormatUrlTypes default_format_type = net::kFormatUrlOmitUsernamePassword;
const UrlTestData tests[] = {
- {"Empty URL", "", L"", true, UnescapeRule::NORMAL, L"", 0},
+ {"Empty URL", "", L"", default_format_type, UnescapeRule::NORMAL, L"", 0},
{"Simple URL",
- "http://www.google.com/", L"", true, UnescapeRule::NORMAL,
+ "http://www.google.com/", L"", default_format_type, UnescapeRule::NORMAL,
L"http://www.google.com/", 7},
{"With a port number and a reference",
- "http://www.google.com:8080/#\xE3\x82\xB0", L"", true,
+ "http://www.google.com:8080/#\xE3\x82\xB0", L"", default_format_type,
UnescapeRule::NORMAL,
L"http://www.google.com:8080/#\x30B0", 7},
// -------- IDN tests --------
{"Japanese IDN with ja",
- "http://xn--l8jvb1ey91xtjb.jp", L"ja", true, UnescapeRule::NORMAL,
- L"http://\x671d\x65e5\x3042\x3055\x3072.jp/", 7},
+ "http://xn--l8jvb1ey91xtjb.jp", L"ja", default_format_type,
+ UnescapeRule::NORMAL, L"http://\x671d\x65e5\x3042\x3055\x3072.jp/", 7},
{"Japanese IDN with en",
- "http://xn--l8jvb1ey91xtjb.jp", L"en", true, UnescapeRule::NORMAL,
- L"http://xn--l8jvb1ey91xtjb.jp/", 7},
+ "http://xn--l8jvb1ey91xtjb.jp", L"en", default_format_type,
+ UnescapeRule::NORMAL, L"http://xn--l8jvb1ey91xtjb.jp/", 7},
{"Japanese IDN without any languages",
- "http://xn--l8jvb1ey91xtjb.jp", L"", true, UnescapeRule::NORMAL,
+ "http://xn--l8jvb1ey91xtjb.jp", L"", default_format_type,
+ UnescapeRule::NORMAL,
// Single script is safe for empty languages.
L"http://\x671d\x65e5\x3042\x3055\x3072.jp/", 7},
{"mailto: with Japanese IDN",
- "mailto:foo@xn--l8jvb1ey91xtjb.jp", L"ja", true, UnescapeRule::NORMAL,
+ "mailto:foo@xn--l8jvb1ey91xtjb.jp", L"ja", default_format_type,
+ UnescapeRule::NORMAL,
// GURL doesn't assume an email address's domain part as a host name.
L"mailto:foo@xn--l8jvb1ey91xtjb.jp", 7},
{"file: with Japanese IDN",
- "file://xn--l8jvb1ey91xtjb.jp/config.sys", L"ja", true,
+ "file://xn--l8jvb1ey91xtjb.jp/config.sys", L"ja", default_format_type,
UnescapeRule::NORMAL,
L"file://\x671d\x65e5\x3042\x3055\x3072.jp/config.sys", 7},
{"ftp: with Japanese IDN",
- "ftp://xn--l8jvb1ey91xtjb.jp/config.sys", L"ja", true,
+ "ftp://xn--l8jvb1ey91xtjb.jp/config.sys", L"ja", default_format_type,
UnescapeRule::NORMAL,
L"ftp://\x671d\x65e5\x3042\x3055\x3072.jp/config.sys", 6},
// -------- omit_username_password flag tests --------
{"With username and password, omit_username_password=false",
- "http://user:passwd@example.com/foo", L"", false, UnescapeRule::NORMAL,
+ "http://user:passwd@example.com/foo", L"",
+ net::kFormatUrlOmitNothing, UnescapeRule::NORMAL,
L"http://user:passwd@example.com/foo", 19},
{"With username and password, omit_username_password=true",
- "http://user:passwd@example.com/foo", L"", true, UnescapeRule::NORMAL,
- L"http://example.com/foo", 7},
+ "http://user:passwd@example.com/foo", L"", default_format_type,
+ UnescapeRule::NORMAL, L"http://example.com/foo", 7},
{"With username and no password",
- "http://user@example.com/foo", L"", true, UnescapeRule::NORMAL,
- L"http://example.com/foo", 7},
+ "http://user@example.com/foo", L"", default_format_type,
+ UnescapeRule::NORMAL, L"http://example.com/foo", 7},
{"Just '@' without username and password",
- "http://@example.com/foo", L"", true, UnescapeRule::NORMAL,
+ "http://@example.com/foo", L"", default_format_type, UnescapeRule::NORMAL,
L"http://example.com/foo", 7},
// GURL doesn't think local-part of an email address is username for URL.
{"mailto:, omit_username_password=true",
- "mailto:foo@example.com", L"", true, UnescapeRule::NORMAL,
+ "mailto:foo@example.com", L"", default_format_type, UnescapeRule::NORMAL,
L"mailto:foo@example.com", 7},
// -------- unescape flag tests --------
{"Do not unescape",
"http://%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB.jp/"
"%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB"
- "?q=%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB", L"en", true,
+ "?q=%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB", L"en", default_format_type,
UnescapeRule::NONE,
// GURL parses %-encoded hostnames into Punycode.
L"http://xn--qcka1pmc.jp/%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB"
@@ -1343,38 +1347,54 @@ TEST(NetUtilTest, FormatUrl) {
{"Unescape normally",
"http://%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB.jp/"
"%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB"
- "?q=%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB", L"en", true,
+ "?q=%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB", L"en", default_format_type,
UnescapeRule::NORMAL,
L"http://xn--qcka1pmc.jp/\x30B0\x30FC\x30B0\x30EB"
L"?q=\x30B0\x30FC\x30B0\x30EB", 7},
{"Unescape normally including unescape spaces",
- "http://www.google.com/search?q=Hello%20World", L"en", true,
- UnescapeRule::SPACES,
- L"http://www.google.com/search?q=Hello World", 7},
+ "http://www.google.com/search?q=Hello%20World", L"en", default_format_type,
+ UnescapeRule::SPACES, L"http://www.google.com/search?q=Hello World", 7},
/*
{"unescape=true with some special characters",
- "http://user%3A:%40passwd@example.com/foo%3Fbar?q=b%26z", L"", false, true,
+ "http://user%3A:%40passwd@example.com/foo%3Fbar?q=b%26z", L"",
+ net::kFormatUrlOmitNothing, UnescapeRule::NORMAL,
L"http://user%3A:%40passwd@example.com/foo%3Fbar?q=b%26z", 25},
*/
// Disabled: the resultant URL becomes "...user%253A:%2540passwd...".
// -------- view-source: --------
{"view-source",
- "view-source:http://xn--qcka1pmc.jp/", L"ja", true, UnescapeRule::NORMAL,
- L"view-source:http://\x30B0\x30FC\x30B0\x30EB.jp/", 12 + 7},
+ "view-source:http://xn--qcka1pmc.jp/", L"ja", default_format_type,
+ UnescapeRule::NORMAL, L"view-source:http://\x30B0\x30FC\x30B0\x30EB.jp/",
+ 12 + 7},
{"view-source of view-source",
- "view-source:view-source:http://xn--qcka1pmc.jp/", L"ja", true,
- UnescapeRule::NORMAL,
+ "view-source:view-source:http://xn--qcka1pmc.jp/", L"ja",
+ default_format_type, UnescapeRule::NORMAL,
L"view-source:view-source:http://xn--qcka1pmc.jp/", 12},
+
+ // -------- omit http: --------
+ {"omit http with user name",
+ "http://user@example.com/foo", L"", net::kFormatUrlOmitAll,
+ UnescapeRule::NORMAL, L"example.com/foo", 0},
+
+ {"omit http",
+ "http://www.google.com/", L"en", net::kFormatUrlOmitHTTP,
+ UnescapeRule::NORMAL, L"www.google.com/",
+ 0},
+
+ {"omit http with https",
+ "https://www.google.com/", L"en", net::kFormatUrlOmitHTTP,
+ UnescapeRule::NORMAL, L"https://www.google.com/",
+ 8},
};
for (size_t i = 0; i < arraysize(tests); ++i) {
size_t prefix_len;
std::wstring formatted = net::FormatUrl(
- GURL(tests[i].input), tests[i].languages, tests[i].omit,
+ GURL(tests[i].input), tests[i].languages, tests[i].format_types,
tests[i].escape_rules, NULL, &prefix_len, NULL);
EXPECT_EQ(tests[i].output, formatted) << tests[i].description;
EXPECT_EQ(tests[i].prefix_len, prefix_len) << tests[i].description;
@@ -1387,7 +1407,8 @@ TEST(NetUtilTest, FormatUrlParsed) {
std::wstring formatted = net::FormatUrl(
GURL("http://\xE3\x82\xB0:\xE3\x83\xBC@xn--qcka1pmc.jp:8080/"
"%E3%82%B0/?q=%E3%82%B0#\xE3\x82\xB0"),
- L"ja", false, UnescapeRule::NONE, &parsed, NULL, NULL);
+ L"ja", net::kFormatUrlOmitNothing, UnescapeRule::NONE, &parsed, NULL,
+ NULL);
EXPECT_EQ(L"http://%E3%82%B0:%E3%83%BC@\x30B0\x30FC\x30B0\x30EB.jp:8080"
L"/%E3%82%B0/?q=%E3%82%B0#\x30B0", formatted);
EXPECT_EQ(L"%E3%82%B0",
@@ -1407,7 +1428,8 @@ TEST(NetUtilTest, FormatUrlParsed) {
formatted = net::FormatUrl(
GURL("http://\xE3\x82\xB0:\xE3\x83\xBC@xn--qcka1pmc.jp:8080/"
"%E3%82%B0/?q=%E3%82%B0#\xE3\x82\xB0"),
- L"ja", false, UnescapeRule::NORMAL, &parsed, NULL, NULL);
+ L"ja", net::kFormatUrlOmitNothing, UnescapeRule::NORMAL, &parsed, NULL,
+ NULL);
EXPECT_EQ(L"http://\x30B0:\x30FC@\x30B0\x30FC\x30B0\x30EB.jp:8080"
L"/\x30B0/?q=\x30B0#\x30B0", formatted);
EXPECT_EQ(L"\x30B0",
@@ -1426,7 +1448,8 @@ TEST(NetUtilTest, FormatUrlParsed) {
formatted = net::FormatUrl(
GURL("http://\xE3\x82\xB0:\xE3\x83\xBC@xn--qcka1pmc.jp:8080/"
"%E3%82%B0/?q=%E3%82%B0#\xE3\x82\xB0"),
- L"ja", true, UnescapeRule::NORMAL, &parsed, NULL, NULL);
+ L"ja", net::kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL,
+ &parsed, NULL, NULL);
EXPECT_EQ(L"http://\x30B0\x30FC\x30B0\x30EB.jp:8080"
L"/\x30B0/?q=\x30B0#\x30B0", formatted);
EXPECT_FALSE(parsed.username.is_valid());
@@ -1442,7 +1465,8 @@ TEST(NetUtilTest, FormatUrlParsed) {
// View-source case.
formatted = net::FormatUrl(
GURL("view-source:http://user:passwd@host:81/path?query#ref"),
- L"", true, UnescapeRule::NORMAL, &parsed, NULL, NULL);
+ L"", net::kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL, &parsed,
+ NULL, NULL);
EXPECT_EQ(L"view-source:http://host:81/path?query#ref", formatted);
EXPECT_EQ(L"view-source:http",
formatted.substr(parsed.scheme.begin, parsed.scheme.len));
@@ -1453,6 +1477,20 @@ TEST(NetUtilTest, FormatUrlParsed) {
EXPECT_EQ(L"/path", formatted.substr(parsed.path.begin, parsed.path.len));
EXPECT_EQ(L"query", formatted.substr(parsed.query.begin, parsed.query.len));
EXPECT_EQ(L"ref", formatted.substr(parsed.ref.begin, parsed.ref.len));
+
+ // omit http case.
+ formatted = net::FormatUrl(
+ GURL("http://host:8000/a?b=c#d"),
+ L"", net::kFormatUrlOmitHTTP, UnescapeRule::NORMAL, &parsed, NULL, NULL);
+ EXPECT_EQ(L"host:8000/a?b=c#d", formatted);
+ EXPECT_FALSE(parsed.scheme.is_valid());
+ EXPECT_FALSE(parsed.username.is_valid());
+ EXPECT_FALSE(parsed.password.is_valid());
+ EXPECT_EQ(L"host", formatted.substr(parsed.host.begin, parsed.host.len));
+ EXPECT_EQ(L"8000", formatted.substr(parsed.port.begin, parsed.port.len));
+ EXPECT_EQ(L"/a", formatted.substr(parsed.path.begin, parsed.path.len));
+ EXPECT_EQ(L"b=c", formatted.substr(parsed.query.begin, parsed.query.len));
+ EXPECT_EQ(L"d", formatted.substr(parsed.ref.begin, parsed.ref.len));
}
TEST(NetUtilTest, FormatUrlAdjustOffset) {
@@ -1472,8 +1510,9 @@ TEST(NetUtilTest, FormatUrlAdjustOffset) {
};
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(basic_cases); ++i) {
size_t offset = basic_cases[i].input_offset;
- net::FormatUrl(GURL("http://www.google.com/foo/"), L"en", true,
- UnescapeRule::NORMAL, NULL, NULL, &offset);
+ net::FormatUrl(GURL("http://www.google.com/foo/"), L"en",
+ net::kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL,
+ NULL, NULL, &offset);
EXPECT_EQ(basic_cases[i].output_offset, offset);
}
@@ -1495,8 +1534,9 @@ TEST(NetUtilTest, FormatUrlAdjustOffset) {
};
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(omit_auth_cases); ++i) {
size_t offset = omit_auth_cases[i].input_offset;
- net::FormatUrl(GURL(omit_auth_cases[i].input_url), L"en", true,
- UnescapeRule::NORMAL, NULL, NULL, &offset);
+ net::FormatUrl(GURL(omit_auth_cases[i].input_url), L"en",
+ net::kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL,
+ NULL, NULL, &offset);
EXPECT_EQ(omit_auth_cases[i].output_offset, offset);
}
@@ -1514,8 +1554,9 @@ TEST(NetUtilTest, FormatUrlAdjustOffset) {
};
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(view_source_cases); ++i) {
size_t offset = view_source_cases[i].input_offset;
- net::FormatUrl(GURL("view-source:http://foo@www.google.com/"), L"en", true,
- UnescapeRule::NORMAL, NULL, NULL, &offset);
+ net::FormatUrl(GURL("view-source:http://foo@www.google.com/"), L"en",
+ net::kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL,
+ NULL, NULL, &offset);
EXPECT_EQ(view_source_cases[i].output_offset, offset);
}
@@ -1529,8 +1570,9 @@ TEST(NetUtilTest, FormatUrlAdjustOffset) {
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(idn_hostname_cases); ++i) {
size_t offset = idn_hostname_cases[i].input_offset;
// "http://\x671d\x65e5\x3042\x3055\x3072.jp/foo/"
- net::FormatUrl(GURL("http://xn--l8jvb1ey91xtjb.jp/foo/"), L"ja", true,
- UnescapeRule::NORMAL, NULL, NULL, &offset);
+ net::FormatUrl(GURL("http://xn--l8jvb1ey91xtjb.jp/foo/"), L"ja",
+ net::kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL,
+ NULL, NULL, &offset);
EXPECT_EQ(idn_hostname_cases[i].output_offset, offset);
}
@@ -1551,7 +1593,8 @@ TEST(NetUtilTest, FormatUrlAdjustOffset) {
// "http://www.google.com/foo bar/\x30B0\x30FC\x30B0\x30EB"
net::FormatUrl(GURL(
"http://www.google.com/foo%20bar/%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB"),
- L"en", true, UnescapeRule::SPACES, NULL, NULL, &offset);
+ L"en", net::kFormatUrlOmitUsernamePassword, UnescapeRule::SPACES, NULL,
+ NULL, &offset);
EXPECT_EQ(unescape_cases[i].output_offset, offset);
}
@@ -1568,9 +1611,36 @@ TEST(NetUtilTest, FormatUrlAdjustOffset) {
// "http://www.google.com/foo.html#\x30B0\x30B0z"
net::FormatUrl(GURL(
"http://www.google.com/foo.html#\xE3\x82\xB0\xE3\x82\xB0z"), L"en",
- true, UnescapeRule::NORMAL, NULL, NULL, &offset);
+ net::kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL, NULL, NULL,
+ &offset);
EXPECT_EQ(ref_cases[i].output_offset, offset);
}
+
+ const AdjustOffsetCase omit_http_cases[] = {
+ {0, std::wstring::npos},
+ {3, std::wstring::npos},
+ {7, 0},
+ {8, 1},
+ };
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(omit_http_cases); ++i) {
+ size_t offset = omit_http_cases[i].input_offset;
+ net::FormatUrl(GURL("http://www.google.com"), L"en",
+ net::kFormatUrlOmitHTTP, UnescapeRule::NORMAL, NULL, NULL, &offset);
+ EXPECT_EQ(omit_http_cases[i].output_offset, offset);
+ }
+
+ const AdjustOffsetCase omit_all_cases[] = {
+ {12, 0},
+ {13, 1},
+ {0, std::wstring::npos},
+ {3, std::wstring::npos},
+ };
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(omit_all_cases); ++i) {
+ size_t offset = omit_all_cases[i].input_offset;
+ net::FormatUrl(GURL("http://user@foo.com/"), L"en", net::kFormatUrlOmitAll,
+ UnescapeRule::NORMAL, NULL, NULL, &offset);
+ EXPECT_EQ(omit_all_cases[i].output_offset, offset);
+ }
}
TEST(NetUtilTest, SimplifyUrlForRequest) {