diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-15 19:25:53 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-15 19:25:53 +0000 |
commit | a88dbdd5cf8de46acb59d2eb9b39188612b23da0 (patch) | |
tree | 9dd0bb97b5f4405db4cbd621b7bd2bb0b9dc5a3e /chrome/browser | |
parent | 3e3c120b805368bbbd1a6a49cfca92f830254fbf (diff) | |
download | chromium_src-a88dbdd5cf8de46acb59d2eb9b39188612b23da0.zip chromium_src-a88dbdd5cf8de46acb59d2eb9b39188612b23da0.tar.gz chromium_src-a88dbdd5cf8de46acb59d2eb9b39188612b23da0.tar.bz2 |
Lands http://codereview.chromium.org/545058 for Dmitry:
Preserve short_name for search engine from OSDD file and generate
keyword from URL in OSDD for JS added search engines.
BUG=7851
TEST=Try adding search engine via JS and autodetected search engines.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@36384 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/search_engines/template_url_fetcher.cc | 21 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents.cc | 5 |
2 files changed, 20 insertions, 6 deletions
diff --git a/chrome/browser/search_engines/template_url_fetcher.cc b/chrome/browser/search_engines/template_url_fetcher.cc index d881d92..1d1edea 100644 --- a/chrome/browser/search_engines/template_url_fetcher.cc +++ b/chrome/browser/search_engines/template_url_fetcher.cc @@ -70,7 +70,7 @@ class TemplateURLFetcher::RequestDelegate : public URLFetcher::Delegate, private: URLFetcher url_fetcher_; TemplateURLFetcher* fetcher_; - const std::wstring keyword_; + std::wstring keyword_; const GURL osdd_url_; const GURL favicon_url_; bool autodetected_; @@ -107,9 +107,21 @@ void TemplateURLFetcher::RequestDelegate::OnURLFetchComplete( NULL, template_url.get()) && template_url->url() && template_url->url()->SupportsReplacement()) { + if (!autodetected_ || keyword_.empty()) { + // Generate new keyword from URL in OSDD for none autodetected case. + // Previous keyword was generated from URL where OSDD was placed and + // it gives wrong result when OSDD is located on third party site that + // has nothing in common with search engine in OSDD. + GURL keyword_url(WideToUTF16Hack(template_url->url()->url())); + std::wstring new_keyword = TemplateURLModel::GenerateKeyword( + keyword_url, false); + if (!new_keyword.empty()) + keyword_ = new_keyword; + } TemplateURLModel* model = fetcher_->profile()->GetTemplateURLModel(); const TemplateURL* existing_url; - if (!model || !model->loaded() || + if (keyword_.empty() || + !model || !model->loaded() || !model->CanReplaceKeyword(keyword_, template_url->url()->url(), &existing_url)) { // TODO(pamg): If we're coming from JS (not autodetected) and this URL @@ -125,9 +137,8 @@ void TemplateURLFetcher::RequestDelegate::OnURLFetchComplete( if (existing_url) model->Remove(existing_url); - // The short name is what is shown to the user. We reset it to make sure - // we don't display random text from the web. - template_url->set_short_name(keyword_); + // The short name is what is shown to the user. We preserve original names + // since it is better when generated keyword in many cases. template_url->set_keyword(keyword_); template_url->set_originating_url(osdd_url_); diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc index 10efa22..6b8ef7d 100644 --- a/chrome/browser/tab_contents/tab_contents.cc +++ b/chrome/browser/tab_contents/tab_contents.cc @@ -2355,7 +2355,10 @@ void TabContents::PageHasOSDD(RenderViewHost* render_view_host, return; std::wstring keyword = TemplateURLModel::GenerateKeyword(keyword_url, autodetected); - if (keyword.empty()) + + // For JS added OSDD empty keyword is OK because we will generate keyword + // later from OSDD content. + if (autodetected && keyword.empty()) return; const TemplateURL* template_url = url_model->GetTemplateURLForKeyword(keyword); |