Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(175)

Unified Diff: chrome/browser/search_engines/template_url.cc

Issue 343823002: Move GenerateSearchURL() and GenerateKeyword() from TemplateURLService to TemplateURL (Closed) Base URL: http://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/search_engines/template_url.cc
diff --git a/chrome/browser/search_engines/template_url.cc b/chrome/browser/search_engines/template_url.cc
index 903451375fda030095e8dc227efb29c55f0b22c9..c43b8b16940d71bd268a6d2cee095f2e93a0ddad 100644
--- a/chrome/browser/search_engines/template_url.cc
+++ b/chrome/browser/search_engines/template_url.cc
@@ -22,7 +22,6 @@
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/google/google_util.h"
#include "chrome/browser/search/search.h"
-#include "chrome/browser/search_engines/template_url_service.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/chrome_version_info.h"
#include "components/metrics/proto/omnibox_input_type.pb.h"
@@ -31,6 +30,7 @@
#include "google_apis/google_api_keys.h"
#include "net/base/escape.h"
#include "net/base/mime_util.h"
+#include "net/base/net_util.h"
#include "ui/base/l10n/l10n_util.h"
namespace {
@@ -1354,6 +1354,37 @@ void TemplateURL::EncodeSearchTerms(
NOTREACHED();
}
+// static
+base::string16 TemplateURL::GenerateKeyword(const GURL& url) {
+ DCHECK(url.is_valid());
+ // Strip "www." off the front of the keyword; otherwise the keyword won't work
+ // properly. See http://code.google.com/p/chromium/issues/detail?id=6984 .
+ // Special case: if the host was exactly "www." (not sure this can happen but
+ // perhaps with some weird intranet and custom DNS server?), ensure we at
+ // least don't return the empty string.
+ base::string16 keyword(net::StripWWWFromHost(url));
+ return keyword.empty() ? base::ASCIIToUTF16("www") : keyword;
+}
+
+GURL TemplateURL::GenerateSearchURL(
+ const SearchTermsData& search_terms_data) const {
+ if (!url_ref_.IsValid(search_terms_data))
+ return GURL();
+
+ if (!url_ref_.SupportsReplacement(search_terms_data))
+ return GURL(url());
+
+ // Use something obscure for the search terms argument so that in the rare
+ // case the term replaces the URL it's unlikely another keyword would have the
+ // same url.
+ // TODO(jnd): Add additional parameters to get post data when the search URL
+ // has post parameters.
+ return GURL(url_ref_.ReplaceSearchTerms(
+ TemplateURLRef::SearchTermsArgs(
+ base::ASCIIToUTF16("blah.blah.blah.blah.blah")),
+ search_terms_data, NULL));
+}
+
void TemplateURL::CopyFrom(const TemplateURL& other) {
if (this == &other)
return;
@@ -1383,9 +1414,9 @@ void TemplateURL::ResetKeywordIfNecessary(
bool force) {
if (IsGoogleSearchURLWithReplaceableKeyword(search_terms_data) || force) {
DCHECK(GetType() != OMNIBOX_API_EXTENSION);
- GURL url(TemplateURLService::GenerateSearchURL(this, search_terms_data));
+ GURL url(GenerateSearchURL(search_terms_data));
if (url.is_valid())
- data_.SetKeyword(TemplateURLService::GenerateKeyword(url));
+ data_.SetKeyword(GenerateKeyword(url));
}
}

Powered by Google App Engine
This is Rietveld 408576698