summaryrefslogtreecommitdiffstats
path: root/net/base/net_util.cc
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-04 20:34:48 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-04 20:34:48 +0000
commitc11132e8c15c88716ee6b3b73729f13090a67f24 (patch)
treed9c3402e8d99d183c8e48c8e816ecef5c2179177 /net/base/net_util.cc
parent333887630a7acb82cde382820650033b18532d73 (diff)
downloadchromium_src-c11132e8c15c88716ee6b3b73729f13090a67f24.zip
chromium_src-c11132e8c15c88716ee6b3b73729f13090a67f24.tar.gz
chromium_src-c11132e8c15c88716ee6b3b73729f13090a67f24.tar.bz2
To show IDN in view-source URLs, add special handling for view-source scheme in
net::FormatUrl(). TEST=add a unit test BUG=3991 Original review: http://codereview.chromium.org/118071 Checked in for tkent@google.com git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17661 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base/net_util.cc')
-rw-r--r--net/base/net_util.cc54
1 files changed, 54 insertions, 0 deletions
diff --git a/net/base/net_util.cc b/net/base/net_util.cc
index 3139acb..0b2f243 100644
--- a/net/base/net_util.cc
+++ b/net/base/net_util.cc
@@ -651,6 +651,49 @@ void IDNToUnicodeOneComponent(const char16* comp,
(*out)[host_begin_in_output + i] = comp[i];
}
+// Helper for FormatUrl().
+std::wstring FormatViewSourceUrl(const GURL& url,
+ const std::wstring& languages,
+ bool omit_username_password,
+ UnescapeRule::Type unescape_rules,
+ url_parse::Parsed* new_parsed,
+ size_t* prefix_end) {
+ DCHECK(new_parsed);
+ const wchar_t* const kWideViewSource = L"view-source:";
+ const size_t kViewSourceLengthPlus1 = 12;
+
+ GURL real_url(url.possibly_invalid_spec().substr(kViewSourceLengthPlus1));
+ std::wstring result = net::FormatUrl(real_url, languages,
+ omit_username_password, unescape_rules, new_parsed, prefix_end);
+ result.insert(0, kWideViewSource);
+
+ // Adjust position values.
+ if (prefix_end)
+ *prefix_end += kViewSourceLengthPlus1;
+ if (new_parsed->scheme.is_nonempty()) {
+ // Assume "view-source:real-scheme" as a scheme.
+ new_parsed->scheme.len += kViewSourceLengthPlus1;
+ } else {
+ 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;
+ return result;
+}
+
} // namespace
namespace net {
@@ -1123,6 +1166,17 @@ std::wstring FormatUrl(const GURL& url,
return url_string;
}
+ // Special handling for view-source:. Don't use chrome::kViewSourceScheme
+ // because this library shouldn't depend on chrome.
+ const char* const kViewSource = "view-source";
+ const char* const kViewSourceTwice = "view-source:view-source:";
+ // 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,
+ unescape_rules, new_parsed, prefix_end);
+ }
+
// We handle both valid and invalid URLs (this will give us the spec
// regardless of validity).
const std::string& spec = url.possibly_invalid_spec();