diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-15 18:31:22 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-15 18:31:22 +0000 |
commit | 7b9f36791bc6caec093a18d790bba7bff03b54d0 (patch) | |
tree | 82f4631e118157c872185e830a7afe869b24e713 /chrome | |
parent | 94f9a0f686619656ca4ff2b6511179dc2132cc5d (diff) | |
download | chromium_src-7b9f36791bc6caec093a18d790bba7bff03b54d0.zip chromium_src-7b9f36791bc6caec093a18d790bba7bff03b54d0.tar.gz chromium_src-7b9f36791bc6caec093a18d790bba7bff03b54d0.tar.bz2 |
Fixes bug where keyword editor would end up prefixing all keyword urls
with "http://" if they didn't have one. This proves problematic as for
the google search url we don't have http:// and don't want it. The fix
is to only add http:// if the url field is editable. If the url field
isn't editable, we know the user hasn't editted it and don't need to
try and fix it up.
BUG=13282
TEST=see bug, but also make sure you don't run into any other problems
with the keyword editor.
Review URL: http://codereview.chromium.org/126052
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18410 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/autocomplete/keyword_provider.cc | 4 | ||||
-rw-r--r-- | chrome/browser/autocomplete/search_provider.cc | 12 | ||||
-rw-r--r-- | chrome/browser/autocomplete/search_provider_unittest.cc | 16 | ||||
-rw-r--r-- | chrome/browser/browser_init.cc | 6 | ||||
-rw-r--r-- | chrome/browser/dom_ui/new_tab_ui.cc | 4 | ||||
-rw-r--r-- | chrome/browser/importer/importer.cc | 4 | ||||
-rw-r--r-- | chrome/browser/search_engines/template_url.cc | 8 | ||||
-rw-r--r-- | chrome/browser/search_engines/template_url.h | 2 | ||||
-rw-r--r-- | chrome/browser/search_engines/template_url_model.cc | 7 | ||||
-rw-r--r-- | chrome/browser/search_engines/template_url_model_unittest.cc | 7 | ||||
-rw-r--r-- | chrome/browser/search_engines/template_url_prepopulate_data.cc | 2 | ||||
-rw-r--r-- | chrome/browser/search_engines/template_url_unittest.cc | 49 | ||||
-rw-r--r-- | chrome/browser/tab_contents/render_view_context_menu.cc | 4 | ||||
-rw-r--r-- | chrome/browser/views/edit_keyword_controller.cc | 23 |
14 files changed, 77 insertions, 71 deletions
diff --git a/chrome/browser/autocomplete/keyword_provider.cc b/chrome/browser/autocomplete/keyword_provider.cc index 1ff05ad..1185390 100644 --- a/chrome/browser/autocomplete/keyword_provider.cc +++ b/chrome/browser/autocomplete/keyword_provider.cc @@ -211,9 +211,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 = element->url()->ReplaceSearchTerms( + match->destination_url = GURL(WideToUTF8(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/search_provider.cc b/chrome/browser/autocomplete/search_provider.cc index 8a6d305..d08b5b6 100644 --- a/chrome/browser/autocomplete/search_provider.cc +++ b/chrome/browser/autocomplete/search_provider.cc @@ -365,9 +365,9 @@ URLFetcher* SearchProvider::CreateSuggestFetcher(int id, const TemplateURLRef* const suggestions_url = provider.suggestions_url(); DCHECK(suggestions_url->SupportsReplacement()); URLFetcher* fetcher = URLFetcher::Create(id, - suggestions_url->ReplaceSearchTerms( + GURL(WideToUTF8(suggestions_url->ReplaceSearchTerms( provider, text, TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, - std::wstring()), + std::wstring()))), URLFetcher::GET, this); fetcher->set_request_context(profile_->GetRequestContext()); fetcher->Start(); @@ -763,10 +763,10 @@ void SearchProvider::AddMatchToMap(const std::wstring& query_string, const TemplateURLRef* const search_url = provider.url(); DCHECK(search_url->SupportsReplacement()); - match.destination_url = search_url->ReplaceSearchTerms(provider, - query_string, - accepted_suggestion, - input_text); + match.destination_url = + GURL(WideToUTF8(search_url->ReplaceSearchTerms(provider, query_string, + accepted_suggestion, + input_text))); // Search results don't look like URLs. match.transition = diff --git a/chrome/browser/autocomplete/search_provider_unittest.cc b/chrome/browser/autocomplete/search_provider_unittest.cc index 6211734..6e1c196 100644 --- a/chrome/browser/autocomplete/search_provider_unittest.cc +++ b/chrome/browser/autocomplete/search_provider_unittest.cc @@ -99,8 +99,8 @@ void SearchProviderTest::SetUp() { // Add url1, with search term term1_. HistoryService* history = profile_.GetHistoryService(Profile::EXPLICIT_ACCESS); - term1_url_ = default_t_url_->url()->ReplaceSearchTerms( - *default_t_url_, term1_, 0, std::wstring()); + term1_url_ = GURL(WideToUTF8(default_t_url_->url()->ReplaceSearchTerms( + *default_t_url_, term1_, 0, std::wstring()))); history->AddPageWithDetails(term1_url_, std::wstring(), 1, 1, base::Time::Now(), false); history->SetKeywordSearchTermsForURL(term1_url_, default_t_url_->id(), @@ -116,8 +116,8 @@ void SearchProviderTest::SetUp() { ASSERT_NE(0, keyword_t_url_->id()); // Add a page and search term for keyword_t_url_. - keyword_url_ = keyword_t_url_->url()->ReplaceSearchTerms( - *keyword_t_url_, keyword_term_, 0, std::wstring()); + keyword_url_ = GURL(WideToUTF8(keyword_t_url_->url()->ReplaceSearchTerms( + *keyword_t_url_, keyword_term_, 0, std::wstring()))); history->AddPageWithDetails(keyword_url_, std::wstring(), 1, 1, base::Time::Now(), false); history->SetKeywordSearchTermsForURL(keyword_url_, keyword_t_url_->id(), @@ -190,8 +190,8 @@ TEST_F(SearchProviderTest, QueryDefaultProvider) { ASSERT_TRUE(fetcher); // And the URL matches what we expected. - GURL expected_url = default_t_url_->suggestions_url()->ReplaceSearchTerms( - *default_t_url_, term, 0, std::wstring()); + GURL expected_url = GURL(WideToUTF8(default_t_url_->suggestions_url()-> + ReplaceSearchTerms(*default_t_url_, term, 0, std::wstring()))); ASSERT_TRUE(fetcher->original_url() == expected_url); // Tell the SearchProvider the suggest query is done. @@ -232,8 +232,8 @@ TEST_F(SearchProviderTest, QueryKeywordProvider) { ASSERT_TRUE(keyword_fetcher); // And the URL matches what we expected. - GURL expected_url = keyword_t_url_->suggestions_url()->ReplaceSearchTerms( - *keyword_t_url_, term, 0, std::wstring()); + GURL expected_url = GURL(WideToUTF8(keyword_t_url_->suggestions_url()-> + ReplaceSearchTerms(*keyword_t_url_, term, 0, std::wstring()))); ASSERT_TRUE(keyword_fetcher->original_url() == expected_url); // Tell the SearchProvider the keyword suggest query is done. diff --git a/chrome/browser/browser_init.cc b/chrome/browser/browser_init.cc index f2b6d95..5833a13 100644 --- a/chrome/browser/browser_init.cc +++ b/chrome/browser/browser_init.cc @@ -567,9 +567,9 @@ std::vector<GURL> BrowserInit::LaunchWithProfile::GetURLsFromCommandLine( } const TemplateURLRef* search_url = default_provider->url(); DCHECK(search_url->SupportsReplacement()); - urls.push_back(GURL(search_url->ReplaceSearchTerms(*default_provider, - value.substr(2), TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, - std::wstring()))); + urls.push_back(GURL(WideToUTF8(search_url->ReplaceSearchTerms( + *default_provider, value.substr(2), + TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring())))); } else { // This will create a file URL or a regular URL. urls.push_back(GURL(WideToUTF8( diff --git a/chrome/browser/dom_ui/new_tab_ui.cc b/chrome/browser/dom_ui/new_tab_ui.cc index 2e60110..52b0297 100644 --- a/chrome/browser/dom_ui/new_tab_ui.cc +++ b/chrome/browser/dom_ui/new_tab_ui.cc @@ -879,8 +879,8 @@ void TemplateURLHandler::HandleDoSearch(const Value* content) { NOTREACHED(); return; } - GURL url = url_ref->ReplaceSearchTerms(*template_url, search, - TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring()); + GURL url = GURL(WideToUTF8(url_ref->ReplaceSearchTerms(*template_url, search, + TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring()))); if (url.is_valid()) { // Record the user action diff --git a/chrome/browser/importer/importer.cc b/chrome/browser/importer/importer.cc index e3b1782..b3a36a3 100644 --- a/chrome/browser/importer/importer.cc +++ b/chrome/browser/importer/importer.cc @@ -191,9 +191,9 @@ static std::string BuildHostPathKey(const TemplateURL* t_url, if (t_url->url()->SupportsReplacement()) { return HostPathKeyForURL( - t_url->url()->ReplaceSearchTerms( + GURL(WideToUTF8(t_url->url()->ReplaceSearchTerms( *t_url, L"random string", - TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring())); + TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring())))); } } return std::string(); diff --git a/chrome/browser/search_engines/template_url.cc b/chrome/browser/search_engines/template_url.cc index 9e9a5c9..e749e89 100644 --- a/chrome/browser/search_engines/template_url.cc +++ b/chrome/browser/search_engines/template_url.cc @@ -230,17 +230,17 @@ void TemplateURLRef::ParseHostAndSearchTermKey() const { } } -GURL TemplateURLRef::ReplaceSearchTerms( +std::wstring TemplateURLRef::ReplaceSearchTerms( const TemplateURL& host, const std::wstring& terms, int accepted_suggestion, const std::wstring& original_query_for_suggestion) const { ParseIfNecessary(); if (!valid_) - return GURL(); + return std::wstring(); if (replacements_.empty()) - return GURL(WideToUTF8(parsed_url_)); + return parsed_url_; // Encode the search terms so that we know the encoding. const std::vector<std::string>& encodings = host.input_encodings(); @@ -330,7 +330,7 @@ GURL TemplateURLRef::ReplaceSearchTerms( } } - return GURL(WideToUTF8(url)); + return url; } bool TemplateURLRef::SupportsReplacement() const { diff --git a/chrome/browser/search_engines/template_url.h b/chrome/browser/search_engines/template_url.h index d59a420..5abcb14 100644 --- a/chrome/browser/search_engines/template_url.h +++ b/chrome/browser/search_engines/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. - GURL ReplaceSearchTerms( + std::wstring ReplaceSearchTerms( const TemplateURL& host, const std::wstring& terms, int accepted_suggestion, diff --git a/chrome/browser/search_engines/template_url_model.cc b/chrome/browser/search_engines/template_url_model.cc index 5a36b0e..8953673 100644 --- a/chrome/browser/search_engines/template_url_model.cc +++ b/chrome/browser/search_engines/template_url_model.cc @@ -196,10 +196,9 @@ GURL TemplateURLModel::GenerateSearchURL(const TemplateURL* t_url) { if (!search_ref->SupportsReplacement()) return GURL(WideToUTF8(search_ref->url())); - return search_ref->ReplaceSearchTerms( - *t_url, - kReplacementTerm, - TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring()); + return GURL(WideToUTF8(search_ref->ReplaceSearchTerms( + *t_url, kReplacementTerm, TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, + std::wstring()))); } bool TemplateURLModel::CanReplaceKeyword( diff --git a/chrome/browser/search_engines/template_url_model_unittest.cc b/chrome/browser/search_engines/template_url_model_unittest.cc index 4a4bace..1889262 100644 --- a/chrome/browser/search_engines/template_url_model_unittest.cc +++ b/chrome/browser/search_engines/template_url_model_unittest.cc @@ -632,8 +632,8 @@ 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("http://foo.com/?q=x", t_url->url()->ReplaceSearchTerms(*t_url, - L"x", TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring()).spec()); + EXPECT_EQ(L"http://foo.com/?q=x", t_url->url()->ReplaceSearchTerms(*t_url, + L"x", TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring())); } struct QueryHistoryCallbackImpl { @@ -669,7 +669,8 @@ TEST_F(TemplateURLModelTest, GenerateVisitOnKeyword) { HistoryService* history = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); history->AddPage( - t_url->url()->ReplaceSearchTerms(*t_url, L"blah", 0, std::wstring()), + GURL(WideToUTF8(t_url->url()->ReplaceSearchTerms(*t_url, L"blah", 0, + std::wstring()))), NULL, 0, GURL(), PageTransition::KEYWORD, HistoryService::RedirectList()); // Wait for history to finish processing the request. diff --git a/chrome/browser/search_engines/template_url_prepopulate_data.cc b/chrome/browser/search_engines/template_url_prepopulate_data.cc index 414eb0e..1c97eec 100644 --- a/chrome/browser/search_engines/template_url_prepopulate_data.cc +++ b/chrome/browser/search_engines/template_url_prepopulate_data.cc @@ -3185,7 +3185,7 @@ void RegisterUserPrefs(PrefService* prefs) { } int GetDataVersion() { - return 21; // Increment this if you change the above data in ways that mean + return 22; // Increment this if you change the above data in ways that mean // users with existing data should get a new version. } diff --git a/chrome/browser/search_engines/template_url_unittest.cc b/chrome/browser/search_engines/template_url_unittest.cc index 7a44b6c..5aa9ce5b 100644 --- a/chrome/browser/search_engines/template_url_unittest.cc +++ b/chrome/browser/search_engines/template_url_unittest.cc @@ -43,8 +43,8 @@ TEST_F(TemplateURLTest, URLRefTestSearchTerms) { ASSERT_TRUE(ref.IsValid()); ASSERT_TRUE(ref.SupportsReplacement()); - GURL result = ref.ReplaceSearchTerms(t_url, L"search", - TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring()); + GURL result = GURL(WideToUTF8(ref.ReplaceSearchTerms(t_url, L"search", + TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring()))); ASSERT_TRUE(result.is_valid()); ASSERT_EQ("http://foosearch/", result.spec()); } @@ -54,8 +54,8 @@ TEST_F(TemplateURLTest, URLRefTestCount) { TemplateURLRef ref(L"http://foo{searchTerms}{count?}", 0, 0); ASSERT_TRUE(ref.IsValid()); ASSERT_TRUE(ref.SupportsReplacement()); - GURL result = ref.ReplaceSearchTerms(t_url, L"X", - TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring()); + GURL result = GURL(WideToUTF8(ref.ReplaceSearchTerms(t_url, L"X", + TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring()))); ASSERT_TRUE(result.is_valid()); ASSERT_EQ("http://foox/", result.spec()); } @@ -65,8 +65,8 @@ TEST_F(TemplateURLTest, URLRefTestCount2) { TemplateURLRef ref(L"http://foo{searchTerms}{count}", 0, 0); ASSERT_TRUE(ref.IsValid()); ASSERT_TRUE(ref.SupportsReplacement()); - GURL result = ref.ReplaceSearchTerms(t_url, L"X", - TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring()); + GURL result = GURL(WideToUTF8(ref.ReplaceSearchTerms(t_url, L"X", + TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring()))); ASSERT_TRUE(result.is_valid()); ASSERT_EQ("http://foox10/", result.spec()); } @@ -77,8 +77,8 @@ TEST_F(TemplateURLTest, URLRefTestIndices) { 1, 2); ASSERT_TRUE(ref.IsValid()); ASSERT_TRUE(ref.SupportsReplacement()); - GURL result = ref.ReplaceSearchTerms(t_url, L"X", - TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring()); + GURL result = GURL(WideToUTF8(ref.ReplaceSearchTerms(t_url, L"X", + TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring()))); ASSERT_TRUE(result.is_valid()); ASSERT_EQ("http://fooxxy/", result.spec()); } @@ -88,8 +88,8 @@ TEST_F(TemplateURLTest, URLRefTestIndices2) { TemplateURLRef ref(L"http://foo{searchTerms}x{startIndex}y{startPage}", 1, 2); ASSERT_TRUE(ref.IsValid()); ASSERT_TRUE(ref.SupportsReplacement()); - GURL result = ref.ReplaceSearchTerms(t_url, L"X", - TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring()); + GURL result = GURL(WideToUTF8(ref.ReplaceSearchTerms(t_url, L"X", + TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring()))); ASSERT_TRUE(result.is_valid()); ASSERT_EQ("http://fooxx1y2/", result.spec()); } @@ -100,8 +100,8 @@ TEST_F(TemplateURLTest, URLRefTestEncoding) { L"http://foo{searchTerms}x{inputEncoding?}y{outputEncoding?}a", 1, 2); ASSERT_TRUE(ref.IsValid()); ASSERT_TRUE(ref.SupportsReplacement()); - GURL result = ref.ReplaceSearchTerms(t_url, L"X", - TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring()); + GURL result = GURL(WideToUTF8(ref.ReplaceSearchTerms(t_url, L"X", + TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring()))); ASSERT_TRUE(result.is_valid()); ASSERT_EQ("http://fooxxutf-8ya/", result.spec()); } @@ -112,8 +112,8 @@ TEST_F(TemplateURLTest, InputEncodingBeforeSearchTerm) { L"http://foox{inputEncoding?}a{searchTerms}y{outputEncoding?}b", 1, 2); ASSERT_TRUE(ref.IsValid()); ASSERT_TRUE(ref.SupportsReplacement()); - GURL result = ref.ReplaceSearchTerms(t_url, L"X", - TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring()); + GURL result = GURL(WideToUTF8(ref.ReplaceSearchTerms(t_url, L"X", + TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring()))); ASSERT_TRUE(result.is_valid()); ASSERT_EQ("http://fooxutf-8axyb/", result.spec()); } @@ -124,8 +124,8 @@ TEST_F(TemplateURLTest, URLRefTestEncoding2) { L"http://foo{searchTerms}x{inputEncoding}y{outputEncoding}a", 1, 2); ASSERT_TRUE(ref.IsValid()); ASSERT_TRUE(ref.SupportsReplacement()); - GURL result = ref.ReplaceSearchTerms(t_url, L"X", - TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring()); + GURL result = GURL(WideToUTF8(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()); } @@ -239,8 +239,8 @@ TEST_F(TemplateURLTest, ReplaceSearchTerms) { 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()); + GURL result = GURL(WideToUTF8(ref.ReplaceSearchTerms(turl, L"X", + TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring()))); EXPECT_TRUE(result.is_valid()); EXPECT_EQ(expected_result, result.spec()); } @@ -265,8 +265,9 @@ TEST_F(TemplateURLTest, ReplaceArbitrarySearchTerms) { TemplateURL turl; turl.add_input_encoding(data[i].encoding); TemplateURLRef ref(data[i].url, 1, 2); - GURL result = ref.ReplaceSearchTerms(turl, data[i].search_term, - TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring()); + GURL result = GURL(WideToUTF8(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()); } @@ -296,8 +297,8 @@ TEST_F(TemplateURLTest, Suggestions) { ASSERT_TRUE(ref.IsValid()); ASSERT_TRUE(ref.SupportsReplacement()); for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { - GURL result = ref.ReplaceSearchTerms(turl, L"foobar", - data[i].accepted_suggestion, data[i].original_query_for_suggestion); + GURL result = GURL(WideToUTF8(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()); } @@ -314,8 +315,8 @@ TEST_F(TemplateURLTest, RLZ) { TemplateURLRef ref(L"http://bar/?{google:RLZ}{searchTerms}", 1, 2); ASSERT_TRUE(ref.IsValid()); ASSERT_TRUE(ref.SupportsReplacement()); - GURL result = ref.ReplaceSearchTerms(t_url, L"x", - TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring()); + GURL result = GURL(WideToUTF8(ref.ReplaceSearchTerms(t_url, L"x", + TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring()))); ASSERT_TRUE(result.is_valid()); std::string expected_url = "http://bar/?"; if (!rlz_string.empty()) { diff --git a/chrome/browser/tab_contents/render_view_context_menu.cc b/chrome/browser/tab_contents/render_view_context_menu.cc index bb33e78..581598d 100644 --- a/chrome/browser/tab_contents/render_view_context_menu.cc +++ b/chrome/browser/tab_contents/render_view_context_menu.cc @@ -533,9 +533,9 @@ void RenderViewContextMenu::ExecuteItemCommand(int id) { // item when there is no provider. const TemplateURLRef* const search_url = default_provider->url(); DCHECK(search_url->SupportsReplacement()); - OpenURL(GURL(search_url->ReplaceSearchTerms(*default_provider, + OpenURL(GURL(WideToUTF8(search_url->ReplaceSearchTerms(*default_provider, params_.selection_text, TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, - std::wstring())), NEW_FOREGROUND_TAB, PageTransition::GENERATED); + std::wstring()))), NEW_FOREGROUND_TAB, PageTransition::GENERATED); break; } diff --git a/chrome/browser/views/edit_keyword_controller.cc b/chrome/browser/views/edit_keyword_controller.cc index debc5947..d8167f1 100644 --- a/chrome/browser/views/edit_keyword_controller.cc +++ b/chrome/browser/views/edit_keyword_controller.cc @@ -298,8 +298,8 @@ bool EditKeywordController::IsURLValid() const { // 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(); + return GURL(WideToUTF8(template_ref.ReplaceSearchTerms(TemplateURL(), L"a", + TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring()))).is_valid(); } std::wstring EditKeywordController::GetURL() const { @@ -309,14 +309,19 @@ std::wstring EditKeywordController::GetURL() const { if (url.empty()) return url; - // Parse the string as a URL to determine the scheme. If a scheme hasn't been - // specified, we add it. + // Parse the string as a URL to determine the scheme. If we need to, add the + // scheme. As the scheme may be expanded (as happens with {google:baseURL}) + // we need to replace the search terms before testing for the scheme. + TemplateURL t_url; + t_url.SetURL(url, 0, 0); + std::wstring expanded_url = + t_url.url()->ReplaceSearchTerms(t_url, L"x", 0, std::wstring()); url_parse::Parsed parts; - std::wstring scheme(URLFixerUpper::SegmentURL(url, &parts)); - if (!parts.scheme.is_valid()) { - std::wstring fixed_scheme(scheme); - fixed_scheme.append(L"://"); - url.insert(0, fixed_scheme); + std::string scheme( + URLFixerUpper::SegmentURL(WideToUTF8(expanded_url), &parts)); + if(!parts.scheme.is_valid()) { + scheme.append("://"); + url.insert(0, UTF8ToWide(scheme)); } return url; |