summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/alternate_nav_url_fetcher.cc6
-rw-r--r--chrome/browser/alternate_nav_url_fetcher.h4
-rw-r--r--chrome/browser/autocomplete/autocomplete.cc14
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit.cc33
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit.h20
-rw-r--r--chrome/browser/autocomplete/autocomplete_popup.h14
-rw-r--r--chrome/browser/autocomplete/autocomplete_unittest.cc12
-rw-r--r--chrome/browser/autocomplete/history_contents_provider.cc2
-rw-r--r--chrome/browser/autocomplete/history_contents_provider_unittest.cc26
-rw-r--r--chrome/browser/autocomplete/history_url_provider.cc15
-rw-r--r--chrome/browser/autocomplete/history_url_provider.h2
-rw-r--r--chrome/browser/autocomplete/history_url_provider_unittest.cc119
-rw-r--r--chrome/browser/autocomplete/keyword_provider.cc6
-rw-r--r--chrome/browser/autocomplete/keyword_provider_unittest.cc54
-rw-r--r--chrome/browser/autocomplete/search_provider.cc8
-rw-r--r--chrome/browser/autocomplete/search_provider.h4
-rw-r--r--chrome/browser/dom_ui/new_tab_ui.cc9
-rw-r--r--chrome/browser/importer/importer.cc5
-rw-r--r--chrome/browser/net/dns_global.cc10
-rw-r--r--chrome/browser/net/dns_global.h2
-rw-r--r--chrome/browser/template_url.cc8
-rw-r--r--chrome/browser/template_url.h2
-rw-r--r--chrome/browser/template_url_model_unittest.cc4
-rw-r--r--chrome/browser/template_url_unittest.cc160
-rw-r--r--chrome/browser/views/edit_keyword_controller.cc16
-rw-r--r--chrome/browser/views/location_bar_view.cc10
-rw-r--r--chrome/browser/views/location_bar_view.h4
27 files changed, 296 insertions, 273 deletions
diff --git a/chrome/browser/alternate_nav_url_fetcher.cc b/chrome/browser/alternate_nav_url_fetcher.cc
index 6533dba..3f058c1 100644
--- a/chrome/browser/alternate_nav_url_fetcher.cc
+++ b/chrome/browser/alternate_nav_url_fetcher.cc
@@ -13,7 +13,7 @@
#include "generated_resources.h"
AlternateNavURLFetcher::AlternateNavURLFetcher(
- const std::wstring& alternate_nav_url)
+ const GURL& alternate_nav_url)
: LinkInfoBarDelegate(NULL),
alternate_nav_url_(alternate_nav_url),
controller_(NULL),
@@ -97,7 +97,7 @@ std::wstring AlternateNavURLFetcher::GetMessageTextWithOffset(
}
std::wstring AlternateNavURLFetcher::GetLinkText() const {
- return alternate_nav_url_;
+ return UTF8ToWide(alternate_nav_url_.spec());
}
SkBitmap* AlternateNavURLFetcher::GetIcon() const {
@@ -107,7 +107,7 @@ SkBitmap* AlternateNavURLFetcher::GetIcon() const {
bool AlternateNavURLFetcher::LinkClicked(WindowOpenDisposition disposition) {
infobar_contents_->OpenURL(
- GURL(alternate_nav_url_), GURL(), disposition,
+ alternate_nav_url_, GURL(), disposition,
// Pretend the user typed this URL, so that navigating to
// it will be the default action when it's typed again in
// the future.
diff --git a/chrome/browser/alternate_nav_url_fetcher.h b/chrome/browser/alternate_nav_url_fetcher.h
index 501bed4..7e55af7 100644
--- a/chrome/browser/alternate_nav_url_fetcher.h
+++ b/chrome/browser/alternate_nav_url_fetcher.h
@@ -37,7 +37,7 @@ class AlternateNavURLFetcher : public NotificationObserver,
FAILED,
};
- explicit AlternateNavURLFetcher(const std::wstring& alternate_nav_url);
+ explicit AlternateNavURLFetcher(const GURL& alternate_nav_url);
State state() const { return state_; }
@@ -66,7 +66,7 @@ class AlternateNavURLFetcher : public NotificationObserver,
// the fetch of the alternate URL succeeded).
void ShowInfobarIfPossible();
- std::wstring alternate_nav_url_;
+ GURL alternate_nav_url_;
scoped_ptr<URLFetcher> fetcher_;
NavigationController* controller_;
State state_;
diff --git a/chrome/browser/autocomplete/autocomplete.cc b/chrome/browser/autocomplete/autocomplete.cc
index 5d2fb87..f0e16e3 100644
--- a/chrome/browser/autocomplete/autocomplete.cc
+++ b/chrome/browser/autocomplete/autocomplete.cc
@@ -20,6 +20,7 @@
#include "chrome/common/l10n_util.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/pref_service.h"
+#include "googleurl/src/gurl.h"
#include "googleurl/src/url_canon_ip.h"
#include "net/base/net_util.h"
#include "net/base/registry_controlled_domain.h"
@@ -442,7 +443,7 @@ void AutocompleteProvider::UpdateStarredStateOfMatches() {
size_t AutocompleteResult::max_matches_ = 6;
void AutocompleteResult::Selection::Clear() {
- destination_url.clear();
+ destination_url = GURL();
provider_affinity = NULL;
is_history_what_you_typed_match = false;
}
@@ -516,7 +517,7 @@ void AutocompleteResult::SortAndCull() {
default_match_ = begin();
}
-std::wstring AutocompleteResult::GetAlternateNavURL(
+GURL AutocompleteResult::GetAlternateNavURL(
const AutocompleteInput& input,
const_iterator match) const {
if (((input.type() == AutocompleteInput::UNKNOWN) ||
@@ -525,11 +526,11 @@ std::wstring AutocompleteResult::GetAlternateNavURL(
for (const_iterator i(begin()); i != end(); ++i) {
if (i->is_history_what_you_typed_match) {
return (i->destination_url == match->destination_url) ?
- std::wstring() : i->destination_url;
+ GURL() : i->destination_url;
}
}
}
- return std::wstring();
+ return GURL();
}
#ifndef NDEBUG
@@ -727,7 +728,7 @@ ACMatches AutocompleteController::GetMatchesNotInLatestResult(
DCHECK(provider);
// Determine the set of destination URLs.
- std::set<std::wstring> destination_urls;
+ std::set<GURL> destination_urls;
for (AutocompleteResult::const_iterator i(latest_result_.begin());
i != latest_result_.end(); ++i)
destination_urls.insert(i->destination_url);
@@ -814,8 +815,7 @@ void AutocompleteController::AddHistoryContentsShortcut() {
ACMatchClassification::NONE));
}
match.destination_url =
- UTF8ToWide(HistoryTabUI::GetHistoryURLWithSearchText(
- input_.text()).spec());
+ HistoryTabUI::GetHistoryURLWithSearchText(input_.text());
match.transition = PageTransition::AUTO_BOOKMARK;
match.provider = history_contents_provider_;
latest_result_.AddMatch(match);
diff --git a/chrome/browser/autocomplete/autocomplete_edit.cc b/chrome/browser/autocomplete/autocomplete_edit.cc
index 357fbd9..03267af 100644
--- a/chrome/browser/autocomplete/autocomplete_edit.cc
+++ b/chrome/browser/autocomplete/autocomplete_edit.cc
@@ -137,9 +137,8 @@ void AutocompleteEditModel::SetUserText(const std::wstring& text) {
void AutocompleteEditModel::GetDataForURLExport(GURL* url,
std::wstring* title,
SkBitmap* favicon) {
- const std::wstring url_str(GetURLForCurrentText(NULL, NULL, NULL));
- *url = GURL(url_str);
- if (url_str == permanent_text_) {
+ *url = GetURLForCurrentText(NULL, NULL, NULL);
+ if (UTF8ToWide(url->possibly_invalid_spec()) == permanent_text_) {
*title = controller_->GetTitle();
*favicon = controller_->GetFavIcon();
}
@@ -205,9 +204,9 @@ void AutocompleteEditModel::StartAutocomplete(
bool AutocompleteEditModel::CanPasteAndGo(const std::wstring& text) const {
// Reset local state.
- paste_and_go_url_.clear();
+ paste_and_go_url_ = GURL();
paste_and_go_transition_ = PageTransition::TYPED;
- paste_and_go_alternate_nav_url_.clear();
+ paste_and_go_alternate_nav_url_ = GURL();
// Ask the controller what do do with this input.
paste_and_go_controller->SetProfile(profile_);
@@ -229,7 +228,7 @@ bool AutocompleteEditModel::CanPasteAndGo(const std::wstring& text) const {
paste_and_go_alternate_nav_url_ =
result.GetAlternateNavURL(paste_and_go_controller->input(), match);
- return !paste_and_go_url_.empty();
+ return paste_and_go_url_.is_valid();
}
void AutocompleteEditModel::PasteAndGo() {
@@ -247,14 +246,14 @@ void AutocompleteEditModel::AcceptInput(WindowOpenDisposition disposition,
// Get the URL and transition type for the selected entry.
PageTransition::Type transition;
bool is_history_what_you_typed_match;
- std::wstring alternate_nav_url;
- const std::wstring url(GetURLForCurrentText(&transition,
- &is_history_what_you_typed_match,
- &alternate_nav_url));
- if (url.empty())
+ GURL alternate_nav_url;
+ const GURL url(GetURLForCurrentText(&transition,
+ &is_history_what_you_typed_match,
+ &alternate_nav_url));
+ if (!url.is_valid())
return;
- if (url == permanent_text_) {
+ if (UTF8ToWide(url.spec()) == permanent_text_) {
// When the user hit enter on the existing permanent URL, treat it like a
// reload for scoring purposes. We could detect this by just checking
// user_input_in_progress_, but it seems better to treat "edits" that end
@@ -565,10 +564,10 @@ std::wstring AutocompleteEditModel::UserTextFromDisplayText(
text : (keyword_ + L" " + text);
}
-std::wstring AutocompleteEditModel::GetURLForCurrentText(
+GURL AutocompleteEditModel::GetURLForCurrentText(
PageTransition::Type* transition,
bool* is_history_what_you_typed_match,
- std::wstring* alternate_nav_url) {
+ GURL* alternate_nav_url) {
return (popup_->is_open() || !popup_->autocomplete_controller()->done()) ?
popup_->URLsForCurrentSelection(transition,
is_history_what_you_typed_match,
@@ -868,13 +867,13 @@ void AutocompleteEditView::Update(const TabContents* tab_for_state_restoring) {
}
}
-void AutocompleteEditView::OpenURL(const std::wstring& url,
+void AutocompleteEditView::OpenURL(const GURL& url,
WindowOpenDisposition disposition,
PageTransition::Type transition,
- const std::wstring& alternate_nav_url,
+ const GURL& alternate_nav_url,
size_t selected_line,
const std::wstring& keyword) {
- if (url.empty())
+ if (!url.is_valid())
return;
model_->SendOpenNotification(selected_line, keyword);
diff --git a/chrome/browser/autocomplete/autocomplete_edit.h b/chrome/browser/autocomplete/autocomplete_edit.h
index fc6398d..dc7d0a5 100644
--- a/chrome/browser/autocomplete/autocomplete_edit.h
+++ b/chrome/browser/autocomplete/autocomplete_edit.h
@@ -46,10 +46,10 @@ class AutocompleteEditController {
// |alternate_nav_url|, if non-empty, contains the alternate navigation URL
// for |url|, which the controller can check for existence. See comments on
// AutocompleteResult::GetAlternateNavURL().
- virtual void OnAutocompleteAccept(const std::wstring& url,
+ virtual void OnAutocompleteAccept(const GURL& url,
WindowOpenDisposition disposition,
PageTransition::Type transition,
- const std::wstring& alternate_nav_url) = 0;
+ const GURL& alternate_nav_url) = 0;
// Called when anything has changed that might affect the layout or contents
// of the views around the edit, including the text of the edit and the
@@ -325,9 +325,9 @@ class AutocompleteEditModel {
//
// See AutocompleteEdit for a description of the args (they may be null if
// not needed).
- std::wstring GetURLForCurrentText(PageTransition::Type* transition,
- bool* is_history_what_you_typed_match,
- std::wstring* alternate_nav_url);
+ GURL GetURLForCurrentText(PageTransition::Type* transition,
+ bool* is_history_what_you_typed_match,
+ GURL* alternate_nav_url);
AutocompleteEditView* view_;
@@ -394,7 +394,7 @@ class AutocompleteEditModel {
// arrows to a different item with the same text, we can still distinguish
// them and not revert all the way to the permanent_text_.
bool has_temporary_text_;
- std::wstring original_url_;
+ GURL original_url_;
KeywordUIState original_keyword_ui_state_;
// When the user's last action was to paste and replace all the text, we
@@ -427,9 +427,9 @@ class AutocompleteEditModel {
bool show_search_hint_;
// Paste And Go-related state. See CanPasteAndGo().
- mutable std::wstring paste_and_go_url_;
+ mutable GURL paste_and_go_url_;
mutable PageTransition::Type paste_and_go_transition_;
- mutable std::wstring paste_and_go_alternate_nav_url_;
+ mutable GURL paste_and_go_alternate_nav_url_;
Profile* profile_;
@@ -494,10 +494,10 @@ class AutocompleteEditView
// If the URL was expanded from a keyword, |keyword| is that keyword.
//
// This may close the popup.
- void OpenURL(const std::wstring& url,
+ void OpenURL(const GURL& url,
WindowOpenDisposition disposition,
PageTransition::Type transition,
- const std::wstring& alternate_nav_url,
+ const GURL& alternate_nav_url,
size_t selected_line,
const std::wstring& keyword);
diff --git a/chrome/browser/autocomplete/autocomplete_popup.h b/chrome/browser/autocomplete/autocomplete_popup.h
index 593f169..6f7808a 100644
--- a/chrome/browser/autocomplete/autocomplete_popup.h
+++ b/chrome/browser/autocomplete/autocomplete_popup.h
@@ -274,10 +274,10 @@ class AutocompletePopupModel : public NotificationObserver {
// If |alternate_nav_url| is non-NULL, it will be set to the alternate
// navigation URL for |url| if one exists, or left unchanged otherwise. See
// comments on AutocompleteResult::GetAlternateNavURL().
- std::wstring URLsForCurrentSelection(
+ GURL URLsForCurrentSelection(
PageTransition::Type* transition,
bool* is_history_what_you_typed_match,
- std::wstring* alternate_nav_url) const;
+ GURL* alternate_nav_url) const;
// This is sort of a hybrid between StartAutocomplete() and
// URLForCurrentSelection(). When the popup isn't open and the user hits
@@ -292,11 +292,11 @@ class AutocompletePopupModel : public NotificationObserver {
//
// If there are no matches for |text|, leaves the outparams unset and returns
// the empty string.
- std::wstring URLsForDefaultMatch(const std::wstring& text,
- const std::wstring& desired_tld,
- PageTransition::Type* transition,
- bool* is_history_what_you_typed_match,
- std::wstring* alternate_nav_url);
+ GURL URLsForDefaultMatch(const std::wstring& text,
+ const std::wstring& desired_tld,
+ PageTransition::Type* transition,
+ bool* is_history_what_you_typed_match,
+ GURL* alternate_nav_url);
// Gets the selected keyword or keyword hint for the given match. Returns
// true if |keyword| represents a keyword hint, or false if |keyword|
diff --git a/chrome/browser/autocomplete/autocomplete_unittest.cc b/chrome/browser/autocomplete/autocomplete_unittest.cc
index a945a5b..9127659 100644
--- a/chrome/browser/autocomplete/autocomplete_unittest.cc
+++ b/chrome/browser/autocomplete/autocomplete_unittest.cc
@@ -4,6 +4,7 @@
#include "base/message_loop.h"
#include "base/ref_counted.h"
+#include "base/string_util.h"
#include "chrome/browser/autocomplete/autocomplete.h"
#include "chrome/common/notification_registrar.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -75,12 +76,12 @@ void TestProvider::AddResults(int start_at, int num) {
wchar_t str[16];
swprintf_s(str, L"%d", i);
match.fill_into_edit = prefix_ + str;
- match.destination_url = match.fill_into_edit;
+ match.destination_url = GURL(WideToUTF8(match.fill_into_edit));
- match.contents = match.destination_url;
+ match.contents = match.fill_into_edit;
match.contents_class.push_back(
ACMatchClassification(0, ACMatchClassification::NONE));
- match.description = match.destination_url;
+ match.description = match.fill_into_edit;
match.description_class.push_back(
ACMatchClassification(0, ACMatchClassification::NONE));
@@ -131,12 +132,13 @@ void AutocompleteProviderTest::ResetController(bool same_destinations) {
providers_.clear();
// Construct two new providers, with either the same or different prefixes.
- TestProvider* providerA = new TestProvider(num_results_per_provider, L"a");
+ TestProvider* providerA = new TestProvider(num_results_per_provider,
+ L"http://a");
providerA->AddRef();
providers_.push_back(providerA);
TestProvider* providerB = new TestProvider(num_results_per_provider * 2,
- same_destinations ? L"a" : L"b");
+ same_destinations ? L"http://a" : L"http://b");
providerB->AddRef();
providers_.push_back(providerB);
diff --git a/chrome/browser/autocomplete/history_contents_provider.cc b/chrome/browser/autocomplete/history_contents_provider.cc
index cc1598f..a2397af 100644
--- a/chrome/browser/autocomplete/history_contents_provider.cc
+++ b/chrome/browser/autocomplete/history_contents_provider.cc
@@ -196,7 +196,7 @@ AutocompleteMatch HistoryContentsProvider::ResultToMatch(
AutocompleteMatch match(this, score, false, MatchInTitle(result) ?
AutocompleteMatch::HISTORY_TITLE : AutocompleteMatch::HISTORY_BODY);
match.fill_into_edit = StringForURLDisplay(result.url(), true);
- match.destination_url = UTF8ToWide(result.url().spec());
+ match.destination_url = result.url();
match.contents = match.fill_into_edit;
match.contents_class.push_back(
ACMatchClassification(0, ACMatchClassification::URL));
diff --git a/chrome/browser/autocomplete/history_contents_provider_unittest.cc b/chrome/browser/autocomplete/history_contents_provider_unittest.cc
index 0ab3d76..4c3009e 100644
--- a/chrome/browser/autocomplete/history_contents_provider_unittest.cc
+++ b/chrome/browser/autocomplete/history_contents_provider_unittest.cc
@@ -26,12 +26,6 @@ struct TestEntry {
{"http://www.google.com/3", L"PAGETHREE 3", L"BAR some hello world for you"},
};
-// For comparing TestEntry.url with wide strings generated by the autocomplete
-// code
-bool UrlIs(const char* url, const std::wstring& str) {
- return WideToUTF8(str) == std::string(url);
-}
-
class HistoryContentsProviderTest : public testing::Test,
public ACProviderListener {
public:
@@ -109,9 +103,9 @@ TEST_F(HistoryContentsProviderTest, Body) {
// The results should be the first two pages, in decreasing order.
const ACMatches& m = matches();
ASSERT_EQ(2, m.size());
- EXPECT_TRUE(UrlIs(test_entries[1].url, m[0].destination_url));
+ EXPECT_EQ(test_entries[1].url, m[0].destination_url.spec());
EXPECT_STREQ(test_entries[1].title, m[0].description.c_str());
- EXPECT_TRUE(UrlIs(test_entries[0].url, m[1].destination_url));
+ EXPECT_EQ(test_entries[0].url, m[1].destination_url.spec());
EXPECT_STREQ(test_entries[0].title, m[1].description.c_str());
}
@@ -122,9 +116,9 @@ TEST_F(HistoryContentsProviderTest, Title) {
// The results should be the first two pages.
const ACMatches& m = matches();
ASSERT_EQ(2, m.size());
- EXPECT_TRUE(UrlIs(test_entries[1].url, m[0].destination_url));
+ EXPECT_EQ(test_entries[1].url, m[0].destination_url.spec());
EXPECT_STREQ(test_entries[1].title, m[0].description.c_str());
- EXPECT_TRUE(UrlIs(test_entries[0].url, m[1].destination_url));
+ EXPECT_EQ(test_entries[0].url, m[1].destination_url.spec());
EXPECT_STREQ(test_entries[0].title, m[1].description.c_str());
}
@@ -164,7 +158,7 @@ TEST_F(HistoryContentsProviderTest, Bookmarks) {
RunQuery(sync_input, false);
const ACMatches& m1 = matches();
ASSERT_EQ(1, m1.size());
- EXPECT_EQ(bookmark_url.spec(), WideToUTF8(m1[0].destination_url));
+ EXPECT_EQ(bookmark_url, m1[0].destination_url);
EXPECT_EQ(L"bar", m1[0].description);
EXPECT_TRUE(m1[0].starred);
@@ -173,7 +167,7 @@ TEST_F(HistoryContentsProviderTest, Bookmarks) {
provider()->Start(async_input, false);
const ACMatches& m2 = matches();
ASSERT_EQ(1, m2.size());
- EXPECT_EQ(bookmark_url.spec(), WideToUTF8(m2[0].destination_url));
+ EXPECT_EQ(bookmark_url, m2[0].destination_url);
// Run the message loop (needed for async history results).
MessageLoop::current()->Run();
@@ -181,10 +175,10 @@ TEST_F(HistoryContentsProviderTest, Bookmarks) {
// We should two urls now, bookmark_url and http://www.google.com/3.
const ACMatches& m3 = matches();
ASSERT_EQ(2, m3.size());
- if (bookmark_url.spec() == WideToUTF8(m3[0].destination_url)) {
- EXPECT_EQ(L"http://www.google.com/3", m3[1].destination_url);
+ if (bookmark_url == m3[0].destination_url) {
+ EXPECT_EQ("http://www.google.com/3", m3[1].destination_url.spec());
} else {
- EXPECT_EQ(bookmark_url.spec(), WideToUTF8(m3[1].destination_url));
- EXPECT_EQ(L"http://www.google.com/3", m3[0].destination_url);
+ EXPECT_EQ(bookmark_url, m3[1].destination_url);
+ EXPECT_EQ("http://www.google.com/3", m3[0].destination_url.spec());
}
}
diff --git a/chrome/browser/autocomplete/history_url_provider.cc b/chrome/browser/autocomplete/history_url_provider.cc
index 175fca4..0737036 100644
--- a/chrome/browser/autocomplete/history_url_provider.cc
+++ b/chrome/browser/autocomplete/history_url_provider.cc
@@ -149,8 +149,7 @@ void HistoryURLProvider::DoAutocomplete(history::HistoryBackend* backend,
max_matches() * 2, &url_matches);
for (URLRowVector::const_iterator j(url_matches.begin());
j != url_matches.end(); ++j) {
- const Prefix* best_prefix = BestPrefix(UTF8ToWide(j->url().spec()),
- std::wstring());
+ const Prefix* best_prefix = BestPrefix(j->url(), std::wstring());
DCHECK(best_prefix != NULL);
history_matches.push_back(HistoryMatch(*j, i->prefix.length(),
!i->num_components,
@@ -232,7 +231,7 @@ void HistoryURLProvider::SuggestExactInput(const AutocompleteInput& input,
(canonicalized_url.IsStandard() &&
!canonicalized_url.SchemeIsFile() && canonicalized_url.host().empty()))
return;
- match.destination_url = UTF8ToWide(canonicalized_url.spec());
+ match.destination_url = canonicalized_url;
match.fill_into_edit = StringForURLDisplay(canonicalized_url, false);
// NOTE: Don't set match.input_location (to allow inline autocompletion)
// here, it's surprising and annoying.
@@ -283,7 +282,7 @@ bool HistoryURLProvider::FixupExactSuggestion(history::URLDatabase* db,
// * and the input _without_ the TLD _is_ in the history DB,
// * ...then just before pressing "ctrl" the best match we supplied was the
// what-you-typed match, so stick with it by promoting this.
- if (!db->GetRowForURL(GURL(match.destination_url), &info)) {
+ if (!db->GetRowForURL(match.destination_url, &info)) {
if (params->input.desired_tld().empty())
return false;
// This code should match what SuggestExactInput() would do with no
@@ -517,9 +516,8 @@ void HistoryURLProvider::PromoteOrCreateShorterSuggestion(
search_base = GURL(new_match);
} else if (!can_add_search_base_to_matches) {
- // TODO(brettw) this extra GURL conversion should be unnecessary.
can_add_search_base_to_matches =
- (search_base != GURL(params.matches.front().destination_url));
+ (search_base != params.matches.front().destination_url);
}
if (search_base == match.url_info.url())
return; // Couldn't shorten |match|, so no range of URLs to search over.
@@ -662,9 +660,10 @@ void HistoryURLProvider::RunAutocompletePasses(const AutocompleteInput& input,
}
const HistoryURLProvider::Prefix* HistoryURLProvider::BestPrefix(
- const std::wstring& text,
+ const GURL& url,
const std::wstring& prefix_suffix) const {
const Prefix* best_prefix = NULL;
+ const std::wstring text(UTF8ToWide(url.spec()));
for (Prefixes::const_iterator i(prefixes_.begin()); i != prefixes_.end();
++i) {
if ((best_prefix == NULL) ||
@@ -798,7 +797,7 @@ AutocompleteMatch HistoryURLProvider::HistoryMatchToACMatch(
AutocompleteMatch match(this,
CalculateRelevance(params->input.type(), match_type, match_number),
!!info.visit_count(), AutocompleteMatch::HISTORY_URL);
- match.destination_url = UTF8ToWide(info.url().possibly_invalid_spec());
+ match.destination_url = info.url();
match.fill_into_edit = gfx::ElideUrl(info.url(), ChromeFont(), 0,
match_type == WHAT_YOU_TYPED ? std::wstring() : params->languages);
if (!params->input.prevent_inline_autocomplete()) {
diff --git a/chrome/browser/autocomplete/history_url_provider.h b/chrome/browser/autocomplete/history_url_provider.h
index e8d1838..dfb462d 100644
--- a/chrome/browser/autocomplete/history_url_provider.h
+++ b/chrome/browser/autocomplete/history_url_provider.h
@@ -321,7 +321,7 @@ class HistoryURLProvider : public AutocompleteProvider {
// |prefix_suffix| (which may be empty) is appended to every attempted
// prefix. This is useful when you need to figure out the innermost match
// for some user input in a URL.
- const Prefix* BestPrefix(const std::wstring& text,
+ const Prefix* BestPrefix(const GURL& text,
const std::wstring& prefix_suffix) const;
// Adds the exact input for what the user has typed as input. This is
diff --git a/chrome/browser/autocomplete/history_url_provider_unittest.cc b/chrome/browser/autocomplete/history_url_provider_unittest.cc
index 610191f..70602ee 100644
--- a/chrome/browser/autocomplete/history_url_provider_unittest.cc
+++ b/chrome/browser/autocomplete/history_url_provider_unittest.cc
@@ -5,6 +5,7 @@
#include "base/file_util.h"
#include "base/message_loop.h"
#include "base/path_service.h"
+#include "base/string_util.h"
#include "chrome/browser/autocomplete/history_url_provider.h"
#include "chrome/browser/bookmarks/bookmark_model.h"
#include "chrome/browser/history/history.h"
@@ -98,7 +99,7 @@ class HistoryURLProviderTest : public testing::Test,
void RunTest(const std::wstring text,
const std::wstring& desired_tld,
bool prevent_inline_autocomplete,
- const std::wstring* expected_urls,
+ const std::string* expected_urls,
int num_results);
MessageLoopForUI message_loop_;
@@ -156,7 +157,7 @@ void HistoryURLProviderTest::FillData() {
void HistoryURLProviderTest::RunTest(const std::wstring text,
const std::wstring& desired_tld,
bool prevent_inline_autocomplete,
- const std::wstring* expected_urls,
+ const std::string* expected_urls,
int num_results) {
AutocompleteInput input(text, desired_tld, prevent_inline_autocomplete,
false, false);
@@ -167,41 +168,41 @@ void HistoryURLProviderTest::RunTest(const std::wstring text,
matches_ = autocomplete_->matches();
ASSERT_EQ(num_results, matches_.size());
for (int i = 0; i < num_results; ++i)
- EXPECT_EQ(expected_urls[i], matches_[i].destination_url);
+ EXPECT_EQ(expected_urls[i], matches_[i].destination_url.spec());
}
TEST_F(HistoryURLProviderTest, PromoteShorterURLs) {
// Test that hosts get synthesized below popular pages.
- const std::wstring expected_nonsynth[] = {
- L"http://slash/",
- L"http://slashdot.org/favorite_page.html",
- L"http://slashdot.org/",
+ const std::string expected_nonsynth[] = {
+ "http://slash/",
+ "http://slashdot.org/favorite_page.html",
+ "http://slashdot.org/",
};
RunTest(L"slash", std::wstring(), true, expected_nonsynth,
arraysize(expected_nonsynth));
// Test that hosts get synthesized above less popular pages.
- const std::wstring expected_synth[] = {
- L"http://kernel/",
- L"http://kerneltrap.org/",
- L"http://kerneltrap.org/not_very_popular.html",
+ const std::string expected_synth[] = {
+ "http://kernel/",
+ "http://kerneltrap.org/",
+ "http://kerneltrap.org/not_very_popular.html",
};
RunTest(L"kernel", std::wstring(), true, expected_synth,
arraysize(expected_synth));
// Test that unpopular pages are ignored completely.
- const std::wstring expected_what_you_typed_only[] = {
- L"http://fresh/",
+ const std::string expected_what_you_typed_only[] = {
+ "http://fresh/",
};
RunTest(L"fresh", std::wstring(), true, expected_what_you_typed_only,
arraysize(expected_what_you_typed_only));
// Test that if we have a synthesized host that matches a suggestion, they
// get combined into one.
- const std::wstring expected_combine[] = {
- L"http://news/",
- L"http://news.google.com/",
- L"http://news.google.com/?ned=us&topic=n",
+ const std::string expected_combine[] = {
+ "http://news/",
+ "http://news.google.com/",
+ "http://news.google.com/?ned=us&topic=n",
};
RunTest(L"news", std::wstring(), true, expected_combine,
arraysize(expected_combine));
@@ -212,21 +213,21 @@ TEST_F(HistoryURLProviderTest, PromoteShorterURLs) {
// Test that short URL matching works correctly as the user types more
// (several tests):
// The entry for foo.com is the best of all five foo.com* entries.
- const std::wstring short_1[] = {
- L"http://foo/",
- L"http://foo.com/",
- L"http://foo.com/dir/another/again/myfile.html",
- L"http://foo.com/dir/",
+ const std::string short_1[] = {
+ "http://foo/",
+ "http://foo.com/",
+ "http://foo.com/dir/another/again/myfile.html",
+ "http://foo.com/dir/",
};
RunTest(L"foo", std::wstring(), true, short_1, arraysize(short_1));
// When the user types the whole host, make sure we don't get two results for
// it.
- const std::wstring short_2[] = {
- L"http://foo.com/",
- L"http://foo.com/dir/another/again/myfile.html",
- L"http://foo.com/dir/",
- L"http://foo.com/dir/another/",
+ const std::string short_2[] = {
+ "http://foo.com/",
+ "http://foo.com/dir/another/again/myfile.html",
+ "http://foo.com/dir/",
+ "http://foo.com/dir/another/",
};
RunTest(L"foo.com", std::wstring(), true, short_2, arraysize(short_2));
RunTest(L"foo.com/", std::wstring(), true, short_2, arraysize(short_2));
@@ -234,20 +235,20 @@ TEST_F(HistoryURLProviderTest, PromoteShorterURLs) {
// The filename is the second best of the foo.com* entries, but there is a
// shorter URL that's "good enough". The host doesn't match the user input
// and so should not appear.
- const std::wstring short_3[] = {
- L"http://foo.com/d",
- L"http://foo.com/dir/another/",
- L"http://foo.com/dir/another/again/myfile.html",
- L"http://foo.com/dir/",
+ const std::string short_3[] = {
+ "http://foo.com/d",
+ "http://foo.com/dir/another/",
+ "http://foo.com/dir/another/again/myfile.html",
+ "http://foo.com/dir/",
};
RunTest(L"foo.com/d", std::wstring(), true, short_3, arraysize(short_3));
// We shouldn't promote shorter URLs than the best if they're not good
// enough.
- const std::wstring short_4[] = {
- L"http://foo.com/dir/another/a",
- L"http://foo.com/dir/another/again/myfile.html",
- L"http://foo.com/dir/another/again/",
+ const std::string short_4[] = {
+ "http://foo.com/dir/another/a",
+ "http://foo.com/dir/another/again/myfile.html",
+ "http://foo.com/dir/another/again/",
};
RunTest(L"foo.com/dir/another/a", std::wstring(), true, short_4,
arraysize(short_4));
@@ -257,18 +258,18 @@ TEST_F(HistoryURLProviderTest, PromoteShorterURLs) {
// working. See TODO in URLDatabase::AutocompleteForPrefix.
TEST_F(HistoryURLProviderTest, DISABLED_Starred) {
// Test that starred pages sort properly.
- const std::wstring star_1[] = {
- L"http://startest/",
- L"http://startest.com/x/d",
- L"http://startest.com/x/c",
- L"http://startest.com/y/a",
+ const std::string star_1[] = {
+ "http://startest/",
+ "http://startest.com/x/d",
+ "http://startest.com/x/c",
+ "http://startest.com/y/a",
};
RunTest(L"startest", std::wstring(), true, star_1, arraysize(star_1));
- const std::wstring star_2[] = {
- L"http://startest.com/y",
- L"http://startest.com/y/a",
- L"http://startest.com/y/b",
- L"http://startest.com/y/e",
+ const std::string star_2[] = {
+ "http://startest.com/y",
+ "http://startest.com/y/a",
+ "http://startest.com/y/b",
+ "http://startest.com/y/e",
};
RunTest(L"startest.com/y", std::wstring(), true, star_2, arraysize(star_2));
}
@@ -279,13 +280,13 @@ TEST_F(HistoryURLProviderTest, CullRedirects) {
// the results to be in A,B,C order. Note also that our visit counts are
// all high enough so that domain synthesizing won't get triggered.
struct RedirectCase {
- const wchar_t* url;
+ const char* url;
int count;
};
static const RedirectCase redirect[] = {
- {L"http://redirects/A", 30},
- {L"http://redirects/B", 20},
- {L"http://redirects/C", 10}
+ {"http://redirects/A", 30},
+ {"http://redirects/B", 20},
+ {"http://redirects/C", 10}
};
for (int i = 0; i < arraysize(redirect); i++) {
history_service_->AddPageWithDetails(GURL(redirect[i].url), L"Title",
@@ -308,8 +309,8 @@ TEST_F(HistoryURLProviderTest, CullRedirects) {
// all but the first one (A) should be culled. We should get the default
// "what you typed" result, plus this one.
const std::wstring typing(L"http://redirects/");
- const std::wstring expected_results[] = {
- typing,
+ const std::string expected_results[] = {
+ WideToUTF8(typing),
redirect[0].url};
RunTest(typing, std::wstring(), true, expected_results,
arraysize(expected_results));
@@ -321,29 +322,29 @@ TEST_F(HistoryURLProviderTest, Fixup) {
RunTest(L"#", std::wstring(), false, NULL, 0);
- const std::wstring crash_1[] = {L"http://%20/"};
+ const std::string crash_1[] = {"http://%20/"};
RunTest(L"%20", std::wstring(), false, crash_1, arraysize(crash_1));
// Fixing up "file:" should result in an inline autocomplete offset of just
// after "file:", not just after "file://".
const std::wstring input_1(L"file:");
- const std::wstring fixup_1[] = {L"file:///", L"file:///C:/foo.txt"};
+ const std::string fixup_1[] = {"file:///", "file:///C:/foo.txt"};
RunTest(input_1, std::wstring(), false, fixup_1, arraysize(fixup_1));
EXPECT_EQ(input_1.length(), matches_[1].inline_autocomplete_offset);
// Fixing up "http:/" should result in an inline autocomplete offset of just
// after "http:/", not just after "http:".
const std::wstring input_2(L"http:/");
- const std::wstring fixup_2[] = {
- L"http://bogussite.com/a",
- L"http://bogussite.com/b",
- L"http://bogussite.com/c",
+ const std::string fixup_2[] = {
+ "http://bogussite.com/a",
+ "http://bogussite.com/b",
+ "http://bogussite.com/c",
};
RunTest(input_2, std::wstring(), false, fixup_2, arraysize(fixup_2));
EXPECT_EQ(input_2.length(), matches_[0].inline_autocomplete_offset);
// Adding a TLD to a small number like "56" should result in "www.56.com"
// rather than "0.0.0.56.com".
- std::wstring fixup_3[] = {L"http://www.56.com/"};
+ std::string fixup_3[] = {"http://www.56.com/"};
RunTest(L"56", L"com", true, fixup_3, arraysize(fixup_3));
}
diff --git a/chrome/browser/autocomplete/keyword_provider.cc b/chrome/browser/autocomplete/keyword_provider.cc
index badc300..9f0eb3e 100644
--- a/chrome/browser/autocomplete/keyword_provider.cc
+++ b/chrome/browser/autocomplete/keyword_provider.cc
@@ -168,7 +168,7 @@ void KeywordProvider::FillInURLAndContents(
ACMatchClassification(0, ACMatchClassification::DIM));
} else {
// Keyword that has no replacement text (aka a shorthand for a URL).
- match->destination_url.assign(element->url()->url());
+ match->destination_url = GURL(WideToUTF8(element->url()->url()));
match->contents.assign(element->short_name());
AutocompleteMatch::ClassifyLocationInString(0, match->contents.length(),
match->contents.length(), ACMatchClassification::NONE,
@@ -180,9 +180,9 @@ void KeywordProvider::FillInURLAndContents(
// input, but we rely on later canonicalization functions to do more
// fixup to make the URL valid if necessary.
DCHECK(element->url()->SupportsReplacement());
- match->destination_url.assign(element->url()->ReplaceSearchTerms(
+ match->destination_url = element->url()->ReplaceSearchTerms(
*element, remaining_input, TemplateURLRef::NO_SUGGESTIONS_AVAILABLE,
- std::wstring()));
+ std::wstring());
std::vector<size_t> content_param_offsets;
match->contents.assign(l10n_util::GetStringF(IDS_KEYWORD_SEARCH,
element->short_name(),
diff --git a/chrome/browser/autocomplete/keyword_provider_unittest.cc b/chrome/browser/autocomplete/keyword_provider_unittest.cc
index c51e1fa..e82e8d6 100644
--- a/chrome/browser/autocomplete/keyword_provider_unittest.cc
+++ b/chrome/browser/autocomplete/keyword_provider_unittest.cc
@@ -11,10 +11,11 @@
class KeywordProviderTest : public testing::Test {
protected:
+ template<class ResultType>
struct test_data {
const std::wstring input;
const size_t num_results;
- const std::wstring output[3];
+ const ResultType output[3];
};
KeywordProviderTest() : kw_provider_(NULL) { }
@@ -23,9 +24,10 @@ class KeywordProviderTest : public testing::Test {
virtual void SetUp();
virtual void TearDown();
- void RunTest(test_data* keyword_cases,
+ template<class ResultType>
+ void RunTest(test_data<ResultType>* keyword_cases,
int num_cases,
- std::wstring AutocompleteMatch::* member);
+ ResultType AutocompleteMatch::* member);
protected:
scoped_refptr<KeywordProvider> kw_provider_;
@@ -52,10 +54,11 @@ void KeywordProviderTest::TearDown() {
kw_provider_ = NULL;
}
+template<class ResultType>
void KeywordProviderTest::RunTest(
- test_data* keyword_cases,
+ test_data<ResultType>* keyword_cases,
int num_cases,
- std::wstring AutocompleteMatch::* member) {
+ ResultType AutocompleteMatch::* member) {
ACMatches matches;
for (int i = 0; i < num_cases; ++i) {
AutocompleteInput input(keyword_cases[i].input, std::wstring(), true,
@@ -74,7 +77,7 @@ void KeywordProviderTest::RunTest(
}
TEST_F(KeywordProviderTest, Edit) {
- test_data edit_cases[] = {
+ test_data<std::wstring> edit_cases[] = {
// Searching for a nonexistent prefix should give nothing.
{L"Not Found", 0, {}},
{L"aaaaaNot Found", 0, {}},
@@ -105,34 +108,35 @@ TEST_F(KeywordProviderTest, Edit) {
{L"mailto:z", 1, {L"z "}},
};
- RunTest(edit_cases, arraysize(edit_cases),
- &AutocompleteMatch::fill_into_edit);
+ RunTest<std::wstring>(edit_cases, arraysize(edit_cases),
+ &AutocompleteMatch::fill_into_edit);
}
TEST_F(KeywordProviderTest, URL) {
- test_data url_cases[] = {
+ test_data<GURL> url_cases[] = {
// No query input -> empty destination URL.
- {L"z", 1, {L""}},
- {L"z \t", 1, {L""}},
+ {L"z", 1, {GURL("")}},
+ {L"z \t", 1, {GURL("")}},
// Check that tokenization only collapses whitespace between first tokens
// and query input, but not rest of URL, is escaped.
- {L"z a b c++", 1, {L"a+++b+++c%2B%2B=z"}},
- {L"www.www www", 1, {L" +%2B?=wwwfoo "}},
+ {L"z a b c++", 1, {GURL("a+++b+++c%2B%2B=z")}},
+ {L"www.www www", 1, {GURL(" +%2B?=wwwfoo ")}},
// Substitution should work with various locations of the "%s".
- {L"aaa 1a2b", 2, {L"http://aaaa/?aaaa=1&b=1a2b&c", L"1a2b"}},
- {L"a 1 2 3", 3, {L"aa.com?foo=1+2+3", L"bogus URL 1+2+3",
- L"http://aaaa/?aaaa=1&b=1+2+3&c"}},
- {L"www.w w", 2, {L" +%2B?=wfoo ", L"weaselwweasel"}},
+ {L"aaa 1a2b", 2, {GURL("http://aaaa/?aaaa=1&b=1a2b&c"),
+ GURL("1a2b")}},
+ {L"a 1 2 3", 3, {GURL("aa.com?foo=1+2+3"), GURL("bogus URL 1+2+3"),
+ GURL("http://aaaa/?aaaa=1&b=1+2+3&c")}},
+ {L"www.w w", 2, {GURL(" +%2B?=wfoo "), GURL("weaselwweasel")}},
};
- RunTest(url_cases, arraysize(url_cases),
- &AutocompleteMatch::destination_url);
+ RunTest<GURL>(url_cases, arraysize(url_cases),
+ &AutocompleteMatch::destination_url);
}
TEST_F(KeywordProviderTest, Contents) {
- test_data contents_cases[] = {
+ test_data<std::wstring> contents_cases[] = {
// No query input -> substitute "<enter query>" into contents.
{L"z", 1, {L"Search z for <enter query>"}},
{L"z \t", 1, {L"Search z for <enter query>"}},
@@ -150,12 +154,12 @@ TEST_F(KeywordProviderTest, Contents) {
{L"www.w w", 2, {L"Search www for w", L"Search weasel for w"}},
};
- RunTest(contents_cases, arraysize(contents_cases),
- &AutocompleteMatch::contents);
+ RunTest<std::wstring>(contents_cases, arraysize(contents_cases),
+ &AutocompleteMatch::contents);
}
TEST_F(KeywordProviderTest, Description) {
- test_data description_cases[] = {
+ test_data<std::wstring> description_cases[] = {
// Whole keyword should be returned for both exact and inexact matches.
{L"z foo", 1, {L"(Keyword: z)"}},
{L"a foo", 3, {L"(Keyword: aa)", L"(Keyword: ab)",
@@ -168,8 +172,8 @@ TEST_F(KeywordProviderTest, Description) {
{L"z a b c++", 1, {L"(Keyword: z)"}},
};
- RunTest(description_cases, arraysize(description_cases),
- &AutocompleteMatch::description);
+ RunTest<std::wstring>(description_cases, arraysize(description_cases),
+ &AutocompleteMatch::description);
}
TEST_F(KeywordProviderTest, AddKeyword) {
diff --git a/chrome/browser/autocomplete/search_provider.cc b/chrome/browser/autocomplete/search_provider.cc
index 0bad51c..32c2fb2 100644
--- a/chrome/browser/autocomplete/search_provider.cc
+++ b/chrome/browser/autocomplete/search_provider.cc
@@ -88,9 +88,9 @@ void SearchProvider::Run() {
const TemplateURLRef* const suggestions_url =
default_provider_.suggestions_url();
DCHECK(suggestions_url->SupportsReplacement());
- fetcher_.reset(new URLFetcher(GURL(suggestions_url->ReplaceSearchTerms(
+ fetcher_.reset(new URLFetcher(suggestions_url->ReplaceSearchTerms(
default_provider_, input_.text(),
- TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring())),
+ TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring()),
URLFetcher::GET, this));
fetcher_->set_request_context(profile_->GetRequestContext());
fetcher_->Start();
@@ -320,7 +320,7 @@ bool SearchProvider::ParseSuggestResults(Value* root_val) {
description_list && description_list->Get(i, &site_val) &&
site_val->IsType(Value::TYPE_STRING) &&
site_val->GetAsString(&site_name)) {
- navigation_results_.push_back(NavigationResult(suggestion_str,
+ navigation_results_.push_back(NavigationResult(GURL(suggestion_str),
site_name));
}
} else {
@@ -566,7 +566,7 @@ AutocompleteMatch SearchProvider::NavigationToMatch(
AutocompleteMatch match(this, relevance, false,
AutocompleteMatch::NAVSUGGEST);
match.destination_url = navigation.url;
- match.contents = StringForURLDisplay(GURL(navigation.url), true);
+ match.contents = StringForURLDisplay(navigation.url, true);
// TODO(kochi): Consider moving HistoryURLProvider::TrimHttpPrefix() to some
// public utility function.
if (!url_util::FindAndCompareScheme(input_.text(), "http", NULL))
diff --git a/chrome/browser/autocomplete/search_provider.h b/chrome/browser/autocomplete/search_provider.h
index 2ff00ad..8fe402f 100644
--- a/chrome/browser/autocomplete/search_provider.h
+++ b/chrome/browser/autocomplete/search_provider.h
@@ -61,13 +61,13 @@ class SearchProvider : public AutocompleteProvider,
private:
struct NavigationResult {
- NavigationResult(const std::wstring& url, const std::wstring& site_name)
+ NavigationResult(const GURL& url, const std::wstring& site_name)
: url(url),
site_name(site_name) {
}
// The URL.
- std::wstring url;
+ GURL url;
// Name for the site.
std::wstring site_name;
diff --git a/chrome/browser/dom_ui/new_tab_ui.cc b/chrome/browser/dom_ui/new_tab_ui.cc
index f242e38..440bdd1 100644
--- a/chrome/browser/dom_ui/new_tab_ui.cc
+++ b/chrome/browser/dom_ui/new_tab_ui.cc
@@ -401,13 +401,12 @@ void TemplateURLHandler::HandleDoSearch(const Value* content) {
NOTREACHED();
return;
}
- std::wstring url = url_ref->ReplaceSearchTerms(*template_url, search,
+ GURL url = url_ref->ReplaceSearchTerms(*template_url, search,
TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring());
- if (!url.empty()) {
- // Load the URL.
- dom_ui_host_->OpenURL(GURL(WideToUTF8(url)), GURL(), CURRENT_TAB,
- PageTransition::LINK);
+ if (url.is_valid()) {
+ // Load the URL.
+ dom_ui_host_->OpenURL(url, GURL(), CURRENT_TAB, PageTransition::LINK);
// Record the user action
std::vector<const TemplateURL*> urls =
diff --git a/chrome/browser/importer/importer.cc b/chrome/browser/importer/importer.cc
index 77711ac..d4c353d 100644
--- a/chrome/browser/importer/importer.cc
+++ b/chrome/browser/importer/importer.cc
@@ -165,8 +165,7 @@ typedef std::map<std::string, const TemplateURL*> HostPathMap;
// Returns the key for the map built by BuildHostPathMap. If url_string is not
// a valid URL, an empty string is returned, otherwise host+path is returned.
-static std::string HostPathKeyForURL(const std::wstring& url_string) {
- GURL url(url_string);
+static std::string HostPathKeyForURL(const GURL& url) {
return url.is_valid() ? url.host() + url.path() : std::string();
}
@@ -187,7 +186,7 @@ static std::string BuildHostPathKey(const TemplateURL* t_url,
bool try_url_if_invalid) {
if (t_url->url()) {
if (try_url_if_invalid && !t_url->url()->IsValid())
- return HostPathKeyForURL(t_url->url()->url());
+ return HostPathKeyForURL(GURL(WideToUTF8(t_url->url()->url())));
if (t_url->url()->SupportsReplacement()) {
return HostPathKeyForURL(
diff --git a/chrome/browser/net/dns_global.cc b/chrome/browser/net/dns_global.cc
index 727af82..eb8d79f 100644
--- a/chrome/browser/net/dns_global.cc
+++ b/chrome/browser/net/dns_global.cc
@@ -88,14 +88,12 @@ static void DnsPrefetchMotivatedList(
dns_master->ResolveList(hostnames, motivation);
}
-// This API is used by the autocomplete popup box (wher URLs are typed).
-void DnsPrefetchUrlString(const url_canon::UTF16String& url_string) {
+// This API is used by the autocomplete popup box (where URLs are typed).
+void DnsPrefetchUrl(const GURL& url) {
if (!dns_prefetch_enabled || NULL == dns_master)
return;
- GURL gurl(url_string);
- if (gurl.is_valid()) {
- DnsMotivatedPrefetch(gurl.host(), DnsHostInfo::OMNIBOX_MOTIVATED);
- }
+ if (url.is_valid())
+ DnsMotivatedPrefetch(url.host(), DnsHostInfo::OMNIBOX_MOTIVATED);
}
static void DnsMotivatedPrefetch(const std::string& hostname,
diff --git a/chrome/browser/net/dns_global.h b/chrome/browser/net/dns_global.h
index 3b76f45..7bf441d 100644
--- a/chrome/browser/net/dns_global.h
+++ b/chrome/browser/net/dns_global.h
@@ -31,7 +31,7 @@ void RegisterUserPrefs(PrefService* user_prefs);
// Renderer bundles up list and sends to this browser API via IPC.
void DnsPrefetchList(const NameList& hostnames);
// This API is used by the autocomplete popup box (as user types).
-void DnsPrefetchUrlString(const url_canon::UTF16String& url_string);
+void DnsPrefetchUrl(const GURL& url);
void DnsPrefetchGetHtmlInfo(std::string* output);
//------------------------------------------------------------------------------
diff --git a/chrome/browser/template_url.cc b/chrome/browser/template_url.cc
index c214db8..ef5fe47 100644
--- a/chrome/browser/template_url.cc
+++ b/chrome/browser/template_url.cc
@@ -235,17 +235,17 @@ void TemplateURLRef::ParseHostAndSearchTermKey() const {
}
}
-std::wstring TemplateURLRef::ReplaceSearchTerms(
+GURL TemplateURLRef::ReplaceSearchTerms(
const TemplateURL& host,
const std::wstring& terms,
int accepted_suggestion,
const std::wstring& original_query_for_suggestion) const {
ParseIfNecessary();
if (!valid_)
- return std::wstring();
+ return GURL();
if (replacements_.empty())
- return parsed_url_;
+ return GURL(WideToUTF8(parsed_url_));
// Encode the search terms so that we know the encoding.
const std::vector<std::string>& encodings = host.input_encodings();
@@ -335,7 +335,7 @@ std::wstring TemplateURLRef::ReplaceSearchTerms(
}
}
- return url;
+ return GURL(WideToUTF8(url));
}
bool TemplateURLRef::SupportsReplacement() const {
diff --git a/chrome/browser/template_url.h b/chrome/browser/template_url.h
index 7be7d0b..a675eec 100644
--- a/chrome/browser/template_url.h
+++ b/chrome/browser/template_url.h
@@ -63,7 +63,7 @@ class TemplateURLRef {
// returns false), an empty string is returned.
//
// The TemplateURL is used to determine the input encoding for the term.
- std::wstring ReplaceSearchTerms(
+ GURL ReplaceSearchTerms(
const TemplateURL& host,
const std::wstring& terms,
int accepted_suggestion,
diff --git a/chrome/browser/template_url_model_unittest.cc b/chrome/browser/template_url_model_unittest.cc
index 3c17ff2..ebc00f2 100644
--- a/chrome/browser/template_url_model_unittest.cc
+++ b/chrome/browser/template_url_model_unittest.cc
@@ -630,6 +630,6 @@ TEST_F(TemplateURLModelTest, ChangeGoogleBaseValue) {
EXPECT_TRUE(model_->GetTemplateURLForHost("google.com") == NULL);
EXPECT_EQ("foo.com", t_url->url()->GetHost());
EXPECT_EQ(L"foo.com", t_url->keyword());
- EXPECT_EQ(L"http://foo.com/?q=x", t_url->url()->ReplaceSearchTerms(*t_url,
- L"x", TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring()));
+ EXPECT_EQ("http://foo.com/?q=x", t_url->url()->ReplaceSearchTerms(*t_url,
+ L"x", TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring()).spec());
}
diff --git a/chrome/browser/template_url_unittest.cc b/chrome/browser/template_url_unittest.cc
index 12c07b6..e602ec5 100644
--- a/chrome/browser/template_url_unittest.cc
+++ b/chrome/browser/template_url_unittest.cc
@@ -42,8 +42,10 @@ TEST_F(TemplateURLTest, URLRefTestSearchTerms) {
ASSERT_TRUE(ref.IsValid());
ASSERT_TRUE(ref.SupportsReplacement());
- ASSERT_EQ(L"http://foosearch", ref.ReplaceSearchTerms(t_url, L"search",
- TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring()));
+ GURL result = ref.ReplaceSearchTerms(t_url, L"search",
+ TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring());
+ ASSERT_TRUE(result.is_valid());
+ ASSERT_EQ("http://foosearch/", result.spec());
}
TEST_F(TemplateURLTest, URLRefTestCount) {
@@ -51,8 +53,10 @@ TEST_F(TemplateURLTest, URLRefTestCount) {
TemplateURLRef ref(L"http://foo{searchTerms}{count?}", 0, 0);
ASSERT_TRUE(ref.IsValid());
ASSERT_TRUE(ref.SupportsReplacement());
- ASSERT_EQ(L"http://fooX", ref.ReplaceSearchTerms(t_url, L"X",
- TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring()));
+ GURL result = ref.ReplaceSearchTerms(t_url, L"X",
+ TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring());
+ ASSERT_TRUE(result.is_valid());
+ ASSERT_EQ("http://foox/", result.spec());
}
TEST_F(TemplateURLTest, URLRefTestCount2) {
@@ -60,8 +64,10 @@ TEST_F(TemplateURLTest, URLRefTestCount2) {
TemplateURLRef ref(L"http://foo{searchTerms}{count}", 0, 0);
ASSERT_TRUE(ref.IsValid());
ASSERT_TRUE(ref.SupportsReplacement());
- ASSERT_EQ(L"http://fooX10", ref.ReplaceSearchTerms(t_url, L"X",
- TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring()));
+ GURL result = ref.ReplaceSearchTerms(t_url, L"X",
+ TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring());
+ ASSERT_TRUE(result.is_valid());
+ ASSERT_EQ("http://foox10/", result.spec());
}
TEST_F(TemplateURLTest, URLRefTestIndices) {
@@ -70,8 +76,10 @@ TEST_F(TemplateURLTest, URLRefTestIndices) {
1, 2);
ASSERT_TRUE(ref.IsValid());
ASSERT_TRUE(ref.SupportsReplacement());
- ASSERT_EQ(L"http://fooXxy", ref.ReplaceSearchTerms(t_url, L"X",
- TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring()));
+ GURL result = ref.ReplaceSearchTerms(t_url, L"X",
+ TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring());
+ ASSERT_TRUE(result.is_valid());
+ ASSERT_EQ("http://fooxxy/", result.spec());
}
TEST_F(TemplateURLTest, URLRefTestIndices2) {
@@ -79,8 +87,10 @@ TEST_F(TemplateURLTest, URLRefTestIndices2) {
TemplateURLRef ref(L"http://foo{searchTerms}x{startIndex}y{startPage}", 1, 2);
ASSERT_TRUE(ref.IsValid());
ASSERT_TRUE(ref.SupportsReplacement());
- ASSERT_EQ(L"http://fooXx1y2", ref.ReplaceSearchTerms(t_url, L"X",
- TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring()));
+ GURL result = ref.ReplaceSearchTerms(t_url, L"X",
+ TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring());
+ ASSERT_TRUE(result.is_valid());
+ ASSERT_EQ("http://fooxx1y2/", result.spec());
}
TEST_F(TemplateURLTest, URLRefTestEncoding) {
@@ -89,8 +99,10 @@ TEST_F(TemplateURLTest, URLRefTestEncoding) {
L"http://foo{searchTerms}x{inputEncoding?}y{outputEncoding?}a", 1, 2);
ASSERT_TRUE(ref.IsValid());
ASSERT_TRUE(ref.SupportsReplacement());
- ASSERT_EQ(L"http://fooXxUTF-8ya", ref.ReplaceSearchTerms(t_url, L"X",
- TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring()));
+ GURL result = ref.ReplaceSearchTerms(t_url, L"X",
+ TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring());
+ ASSERT_TRUE(result.is_valid());
+ ASSERT_EQ("http://fooxxutf-8ya/", result.spec());
}
TEST_F(TemplateURLTest, InputEncodingBeforeSearchTerm) {
@@ -99,8 +111,10 @@ TEST_F(TemplateURLTest, InputEncodingBeforeSearchTerm) {
L"http://foox{inputEncoding?}a{searchTerms}y{outputEncoding?}b", 1, 2);
ASSERT_TRUE(ref.IsValid());
ASSERT_TRUE(ref.SupportsReplacement());
- ASSERT_EQ(L"http://fooxUTF-8aXyb", ref.ReplaceSearchTerms(t_url, L"X",
- TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring()));
+ GURL result = ref.ReplaceSearchTerms(t_url, L"X",
+ TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring());
+ ASSERT_TRUE(result.is_valid());
+ ASSERT_EQ("http://fooxutf-8axyb/", result.spec());
}
TEST_F(TemplateURLTest, URLRefTestEncoding2) {
@@ -109,8 +123,10 @@ TEST_F(TemplateURLTest, URLRefTestEncoding2) {
L"http://foo{searchTerms}x{inputEncoding}y{outputEncoding}a", 1, 2);
ASSERT_TRUE(ref.IsValid());
ASSERT_TRUE(ref.SupportsReplacement());
- ASSERT_EQ(L"http://fooXxUTF-8yUTF-8a", ref.ReplaceSearchTerms(t_url, L"X",
- TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring()));
+ GURL result = ref.ReplaceSearchTerms(t_url, L"X",
+ TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring());
+ ASSERT_TRUE(result.is_valid());
+ ASSERT_EQ("http://fooxxutf-8yutf-8a/", result.spec());
}
TEST_F(TemplateURLTest, URLRefTermToWide) {
@@ -186,42 +202,46 @@ TEST_F(TemplateURLTest, DisplayURLToURLRef) {
TEST_F(TemplateURLTest, ReplaceSearchTerms) {
struct TestData {
const std::wstring url;
- const std::wstring expected_result;
+ const std::string expected_result;
} data[] = {
- { L"{language}{searchTerms}{inputEncoding}",
- L"{language}XUTF-8" },
- { L"{language}{inputEncoding}{searchTerms}",
- L"{language}UTF-8X" },
- { L"{searchTerms}{language}{inputEncoding}",
- L"X{language}UTF-8" },
- { L"{searchTerms}{inputEncoding}{language}",
- L"XUTF-8{language}" },
- { L"{inputEncoding}{searchTerms}{language}",
- L"UTF-8X{language}" },
- { L"{inputEncoding}{language}{searchTerms}",
- L"UTF-8{language}X" },
- { L"{language}a{searchTerms}a{inputEncoding}a",
- L"{language}aXaUTF-8a" },
- { L"{language}a{inputEncoding}a{searchTerms}a",
- L"{language}aUTF-8aXa" },
- { L"{searchTerms}a{language}a{inputEncoding}a",
- L"Xa{language}aUTF-8a" },
- { L"{searchTerms}a{inputEncoding}a{language}a",
- L"XaUTF-8a{language}a" },
- { L"{inputEncoding}a{searchTerms}a{language}a",
- L"UTF-8aXa{language}a" },
- { L"{inputEncoding}a{language}a{searchTerms}a",
- L"UTF-8a{language}aXa" },
+ { L"http://foo/{language}{searchTerms}{inputEncoding}",
+ "http://foo/{language}XUTF-8" },
+ { L"http://foo/{language}{inputEncoding}{searchTerms}",
+ "http://foo/{language}UTF-8X" },
+ { L"http://foo/{searchTerms}{language}{inputEncoding}",
+ "http://foo/X{language}UTF-8" },
+ { L"http://foo/{searchTerms}{inputEncoding}{language}",
+ "http://foo/XUTF-8{language}" },
+ { L"http://foo/{inputEncoding}{searchTerms}{language}",
+ "http://foo/UTF-8X{language}" },
+ { L"http://foo/{inputEncoding}{language}{searchTerms}",
+ "http://foo/UTF-8{language}X" },
+ { L"http://foo/{language}a{searchTerms}a{inputEncoding}a",
+ "http://foo/{language}aXaUTF-8a" },
+ { L"http://foo/{language}a{inputEncoding}a{searchTerms}a",
+ "http://foo/{language}aUTF-8aXa" },
+ { L"http://foo/{searchTerms}a{language}a{inputEncoding}a",
+ "http://foo/Xa{language}aUTF-8a" },
+ { L"http://foo/{searchTerms}a{inputEncoding}a{language}a",
+ "http://foo/XaUTF-8a{language}a" },
+ { L"http://foo/{inputEncoding}a{searchTerms}a{language}a",
+ "http://foo/UTF-8aXa{language}a" },
+ { L"http://foo/{inputEncoding}a{language}a{searchTerms}a",
+ "http://foo/UTF-8a{language}aXa" },
};
TemplateURL turl;
turl.add_input_encoding("UTF-8");
for (int i = 0; i < arraysize(data); ++i) {
TemplateURLRef ref(data[i].url, 1, 2);
- std::wstring expected_result = data[i].expected_result;
- ReplaceSubstringsAfterOffset(&expected_result, 0, L"{language}",
- g_browser_process->GetApplicationLocale());
- EXPECT_EQ(expected_result, ref.ReplaceSearchTerms(turl, L"X",
- TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring()));
+ EXPECT_TRUE(ref.IsValid());
+ EXPECT_TRUE(ref.SupportsReplacement());
+ std::string expected_result = data[i].expected_result;
+ ReplaceSubstringsAfterOffset(&expected_result, 0, "{language}",
+ WideToASCII(g_browser_process->GetApplicationLocale()));
+ GURL result = ref.ReplaceSearchTerms(turl, L"X",
+ TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring());
+ EXPECT_TRUE(result.is_valid());
+ EXPECT_EQ(expected_result, result.spec());
}
}
@@ -233,19 +253,21 @@ TEST_F(TemplateURLTest, ReplaceArbitrarySearchTerms) {
const std::string encoding;
const std::wstring search_term;
const std::wstring url;
- const std::wstring expected_result;
+ const std::string expected_result;
} data[] = {
- { "BIG5", L"\x60BD", L"{searchTerms}{inputEncoding}", L"%B1~BIG5" },
- { "UTF-8", L"blah", L"{searchTerms}{inputEncoding}", L"blahUTF-8" },
+ { "BIG5", L"\x60BD", L"http://foo/{searchTerms}{inputEncoding}",
+ "http://foo/%B1~BIG5" },
+ { "UTF-8", L"blah", L"http://foo/{searchTerms}{inputEncoding}",
+ "http://foo/blahUTF-8" },
};
for (int i = 0; i < arraysize(data); ++i) {
TemplateURL turl;
turl.add_input_encoding(data[i].encoding);
TemplateURLRef ref(data[i].url, 1, 2);
- std::wstring expected_result = data[i].expected_result;
- EXPECT_EQ(data[i].expected_result, ref.ReplaceSearchTerms(
- turl, data[i].search_term, TemplateURLRef::NO_SUGGESTIONS_AVAILABLE,
- std::wstring()));
+ GURL result = ref.ReplaceSearchTerms(turl, data[i].search_term,
+ TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring());
+ EXPECT_TRUE(result.is_valid());
+ EXPECT_EQ(data[i].expected_result, result.spec());
}
}
@@ -253,26 +275,30 @@ TEST_F(TemplateURLTest, Suggestions) {
struct TestData {
const int accepted_suggestion;
const std::wstring original_query_for_suggestion;
- const std::wstring expected_result;
+ const std::string expected_result;
} data[] = {
{ TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring(),
- L"foo?q=foobar" },
- { TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, L"foo", L"foo?q=foobar" },
+ "http://bar/foo?q=foobar" },
+ { TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, L"foo",
+ "http://bar/foo?q=foobar" },
{ TemplateURLRef::NO_SUGGESTION_CHOSEN, std::wstring(),
- L"foo?aq=f&q=foobar" },
- { TemplateURLRef::NO_SUGGESTION_CHOSEN, L"foo", L"foo?aq=f&q=foobar" },
- { 0, std::wstring(), L"foo?aq=0&oq=&q=foobar" },
- { 1, L"foo", L"foo?aq=1&oq=foo&q=foobar" },
+ "http://bar/foo?aq=f&q=foobar" },
+ { TemplateURLRef::NO_SUGGESTION_CHOSEN, L"foo",
+ "http://bar/foo?aq=f&q=foobar" },
+ { 0, std::wstring(), "http://bar/foo?aq=0&oq=&q=foobar" },
+ { 1, L"foo", "http://bar/foo?aq=1&oq=foo&q=foobar" },
};
TemplateURL turl;
turl.add_input_encoding("UTF-8");
- TemplateURLRef ref(L"foo?{google:acceptedSuggestion}"
+ TemplateURLRef ref(L"http://bar/foo?{google:acceptedSuggestion}"
L"{google:originalQueryForSuggestion}q={searchTerms}", 1, 2);
ASSERT_TRUE(ref.IsValid());
ASSERT_TRUE(ref.SupportsReplacement());
for (int i = 0; i < arraysize(data); ++i) {
- EXPECT_EQ(data[i].expected_result, ref.ReplaceSearchTerms(turl, L"foobar",
- data[i].accepted_suggestion, data[i].original_query_for_suggestion));
+ GURL result = ref.ReplaceSearchTerms(turl, L"foobar",
+ data[i].accepted_suggestion, data[i].original_query_for_suggestion);
+ EXPECT_TRUE(result.is_valid());
+ EXPECT_EQ(data[i].expected_result, result.spec());
}
}
@@ -281,11 +307,13 @@ TEST_F(TemplateURLTest, RLZ) {
RLZTracker::GetAccessPointRlz(RLZTracker::CHROME_OMNIBOX, &rlz_string);
TemplateURL t_url;
- TemplateURLRef ref(L"{google:RLZ}{searchTerms}", 1, 2);
+ TemplateURLRef ref(L"http://bar/{google:RLZ}{searchTerms}", 1, 2);
ASSERT_TRUE(ref.IsValid());
ASSERT_TRUE(ref.SupportsReplacement());
- ASSERT_EQ(rlz_string + L"x", ref.ReplaceSearchTerms(t_url, L"x",
- TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring()));
+ GURL result = ref.ReplaceSearchTerms(t_url, L"x",
+ TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring());
+ ASSERT_TRUE(result.is_valid());
+ ASSERT_EQ("http://bar/" + WideToUTF8(rlz_string) + "x", result.spec());
}
TEST_F(TemplateURLTest, HostAndSearchTermKey) {
diff --git a/chrome/browser/views/edit_keyword_controller.cc b/chrome/browser/views/edit_keyword_controller.cc
index efbb43e..4eb913f 100644
--- a/chrome/browser/views/edit_keyword_controller.cc
+++ b/chrome/browser/views/edit_keyword_controller.cc
@@ -296,14 +296,14 @@ bool EditKeywordController::IsURLValid() const {
if (!template_ref.IsValid())
return false;
- if (template_ref.SupportsReplacement()) {
- // If the url has a search term, replace it with a random string and make
- // sure the resulting URL is valid. We don't check the validity of the url
- // with the search term as that is not necessarily valid.
- url = template_ref.ReplaceSearchTerms(TemplateURL(), L"a",
- TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring());
- }
- return GURL(url).is_valid();
+ if (!template_ref.SupportsReplacement())
+ return GURL(url).is_valid();
+
+ // If the url has a search term, replace it with a random string and make
+ // sure the resulting URL is valid. We don't check the validity of the url
+ // with the search term as that is not necessarily valid.
+ return template_ref.ReplaceSearchTerms(TemplateURL(), L"a",
+ TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring()).is_valid();
}
std::wstring EditKeywordController::GetURL() const {
diff --git a/chrome/browser/views/location_bar_view.cc b/chrome/browser/views/location_bar_view.cc
index 30a8a8c..eb0a7cc 100644
--- a/chrome/browser/views/location_bar_view.cc
+++ b/chrome/browser/views/location_bar_view.cc
@@ -308,19 +308,19 @@ void LocationBarView::OnMouseReleased(const views::MouseEvent& event,
}
void LocationBarView::OnAutocompleteAccept(
- const std::wstring& url,
+ const GURL& url,
WindowOpenDisposition disposition,
PageTransition::Type transition,
- const std::wstring& alternate_nav_url) {
- if (url.empty())
+ const GURL& alternate_nav_url) {
+ if (!url.is_valid())
return;
- location_input_ = url;
+ location_input_ = UTF8ToWide(url.spec());
disposition_ = disposition;
transition_ = transition;
if (controller_) {
- if (alternate_nav_url.empty()) {
+ if (!alternate_nav_url.is_valid()) {
controller_->ExecuteCommand(IDC_OPEN_CURRENT_URL);
return;
}
diff --git a/chrome/browser/views/location_bar_view.h b/chrome/browser/views/location_bar_view.h
index 089b3c1..c594d54 100644
--- a/chrome/browser/views/location_bar_view.h
+++ b/chrome/browser/views/location_bar_view.h
@@ -89,10 +89,10 @@ class LocationBarView : public views::View,
virtual void OnMouseReleased(const views::MouseEvent& event, bool canceled);
// AutocompleteEditController
- virtual void OnAutocompleteAccept(const std::wstring& url,
+ virtual void OnAutocompleteAccept(const GURL& url,
WindowOpenDisposition disposition,
PageTransition::Type transition,
- const std::wstring& alternate_nav_url);
+ const GURL& alternate_nav_url);
virtual void OnChanged();
virtual void OnInputInProgress(bool in_progress) {
delegate_->OnInputInProgress(in_progress);