summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-29 00:10:17 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-29 00:10:17 +0000
commit45b2e16d81eb606ecbd102ca36dc51d87298f966 (patch)
tree1b1359211be9aede274ab6f824e88402fd433960 /chrome
parent1c0be54a98e2f801e8fa22c01aac83e36485eee4 (diff)
downloadchromium_src-45b2e16d81eb606ecbd102ca36dc51d87298f966.zip
chromium_src-45b2e16d81eb606ecbd102ca36dc51d87298f966.tar.gz
chromium_src-45b2e16d81eb606ecbd102ca36dc51d87298f966.tar.bz2
Hoist TrimHttpPrefix() so we only have one copy, not one per provider.
Make use of this in HistoryContentsProvider so results from it get their schemes trimmed appropriately. BUG=10558 Review URL: http://codereview.chromium.org/115885 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17145 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/autocomplete/autocomplete.cc21
-rw-r--r--chrome/browser/autocomplete/autocomplete.h4
-rw-r--r--chrome/browser/autocomplete/history_contents_provider.cc6
-rw-r--r--chrome/browser/autocomplete/history_contents_provider.h3
-rw-r--r--chrome/browser/autocomplete/history_url_provider.cc23
-rw-r--r--chrome/browser/autocomplete/history_url_provider.h4
-rw-r--r--chrome/browser/autocomplete/search_provider.cc26
-rw-r--r--chrome/browser/autocomplete/search_provider.h5
8 files changed, 37 insertions, 55 deletions
diff --git a/chrome/browser/autocomplete/autocomplete.cc b/chrome/browser/autocomplete/autocomplete.cc
index 9720e73..ca78d7b 100644
--- a/chrome/browser/autocomplete/autocomplete.cc
+++ b/chrome/browser/autocomplete/autocomplete.cc
@@ -24,6 +24,7 @@
#include "chrome/common/url_constants.h"
#include "googleurl/src/gurl.h"
#include "googleurl/src/url_canon_ip.h"
+#include "googleurl/src/url_util.h"
#include "grit/generated_resources.h"
#include "net/base/net_util.h"
#include "net/base/registry_controlled_domain.h"
@@ -474,6 +475,26 @@ void AutocompleteProvider::SetProfile(Profile* profile) {
profile_ = profile;
}
+// static
+size_t AutocompleteProvider::TrimHttpPrefix(std::wstring* url) {
+ url_parse::Component scheme;
+ if (!url_util::FindAndCompareScheme(WideToUTF8(*url), chrome::kHttpScheme,
+ &scheme))
+ return 0; // Not "http".
+
+ // Erase scheme plus up to two slashes.
+ size_t prefix_len = scheme.end() + 1; // "http:"
+ const size_t after_slashes = std::min(url->length(),
+ static_cast<size_t>(scheme.end() + 3));
+ while ((prefix_len < after_slashes) && ((*url)[prefix_len] == L'/'))
+ ++prefix_len;
+ if (prefix_len == url->length())
+ url->clear();
+ else
+ url->erase(url->begin(), url->begin() + prefix_len);
+ return prefix_len;
+}
+
void AutocompleteProvider::UpdateStarredStateOfMatches() {
if (matches_.empty())
return;
diff --git a/chrome/browser/autocomplete/autocomplete.h b/chrome/browser/autocomplete/autocomplete.h
index cf40c1c..c2b8edd 100644
--- a/chrome/browser/autocomplete/autocomplete.h
+++ b/chrome/browser/autocomplete/autocomplete.h
@@ -532,6 +532,10 @@ class AutocompleteProvider
static size_t max_matches() { return max_matches_; }
protected:
+ // Trims "http:" and up to two subsequent slashes from |url|. Returns the
+ // number of characters that were trimmed.
+ static size_t TrimHttpPrefix(std::wstring* url);
+
// Updates the starred state of each of the matches in matches_ from the
// profile's bookmark bar model.
void UpdateStarredStateOfMatches();
diff --git a/chrome/browser/autocomplete/history_contents_provider.cc b/chrome/browser/autocomplete/history_contents_provider.cc
index f194559..c81ccd8 100644
--- a/chrome/browser/autocomplete/history_contents_provider.cc
+++ b/chrome/browser/autocomplete/history_contents_provider.cc
@@ -9,6 +9,8 @@
#include "chrome/browser/bookmarks/bookmark_model.h"
#include "chrome/browser/history/query_parser.h"
#include "chrome/browser/profile.h"
+#include "chrome/common/url_constants.h"
+#include "googleurl/src/url_util.h"
#include "net/base/net_util.h"
using base::TimeTicks;
@@ -72,6 +74,8 @@ void HistoryContentsProvider::Start(const AutocompleteInput& input,
// Change input type and reset relevance counters, so matches will be marked
// up properly.
input_type_ = input.type();
+ trim_http_ = !url_util::FindAndCompareScheme(WideToUTF8(input.text()),
+ chrome::kHttpScheme, NULL);
star_title_count_ = star_contents_count_ = title_count_ = contents_count_ = 0;
// Decide what to do about any previous query/results.
@@ -198,6 +202,8 @@ AutocompleteMatch HistoryContentsProvider::ResultToMatch(
match.fill_into_edit = StringForURLDisplay(result.url(), true);
match.destination_url = result.url();
match.contents = match.fill_into_edit;
+ if (trim_http_)
+ TrimHttpPrefix(&match.contents);
match.contents_class.push_back(
ACMatchClassification(0, ACMatchClassification::URL));
match.description = result.title();
diff --git a/chrome/browser/autocomplete/history_contents_provider.h b/chrome/browser/autocomplete/history_contents_provider.h
index 7cb72dd..b99b21e 100644
--- a/chrome/browser/autocomplete/history_contents_provider.h
+++ b/chrome/browser/autocomplete/history_contents_provider.h
@@ -80,6 +80,9 @@ class HistoryContentsProvider : public AutocompleteProvider {
// Current autocomplete input type.
AutocompleteInput::Type input_type_;
+ // Whether we should trim "http://" from results.
+ bool trim_http_;
+
// Results from most recent query. These are cached so we don't have to
// re-issue queries for "minor changes" (which don't affect this provider).
history::QueryResults results_;
diff --git a/chrome/browser/autocomplete/history_url_provider.cc b/chrome/browser/autocomplete/history_url_provider.cc
index faae195..18c1269 100644
--- a/chrome/browser/autocomplete/history_url_provider.cc
+++ b/chrome/browser/autocomplete/history_url_provider.cc
@@ -372,10 +372,9 @@ std::wstring HistoryURLProvider::FixupUserInput(
std::wstring output(UTF8ToWide(canonical_gurl_str));
// Don't prepend a scheme when the user didn't have one. Since the fixer
// upper only prepends the "http" scheme, that's all we need to check for.
- url_parse::Component scheme;
if (canonical_gurl.SchemeIs(chrome::kHttpScheme) &&
!url_util::FindAndCompareScheme(WideToUTF8(input_text),
- chrome::kHttpScheme, &scheme))
+ chrome::kHttpScheme, NULL))
TrimHttpPrefix(&output);
// Make the number of trailing slashes on the output exactly match the input.
@@ -408,26 +407,6 @@ std::wstring HistoryURLProvider::FixupUserInput(
}
// static
-size_t HistoryURLProvider::TrimHttpPrefix(std::wstring* url) {
- url_parse::Component scheme;
- if (!url_util::FindAndCompareScheme(WideToUTF8(*url), chrome::kHttpScheme,
- &scheme))
- return 0; // Not "http".
-
- // Erase scheme plus up to two slashes.
- size_t prefix_len = scheme.end() + 1; // "http:"
- const size_t after_slashes = std::min(url->length(),
- static_cast<size_t>(scheme.end() + 3));
- while ((prefix_len < after_slashes) && ((*url)[prefix_len] == L'/'))
- ++prefix_len;
- if (prefix_len == url->length())
- url->clear();
- else
- url->erase(url->begin(), url->begin() + prefix_len);
- return prefix_len;
-}
-
-// static
bool HistoryURLProvider::IsHostOnly(const GURL& url) {
DCHECK(url.is_valid());
return (!url.has_path() || (url.path() == "/")) && !url.has_query() &&
diff --git a/chrome/browser/autocomplete/history_url_provider.h b/chrome/browser/autocomplete/history_url_provider.h
index bdea469..2f95594 100644
--- a/chrome/browser/autocomplete/history_url_provider.h
+++ b/chrome/browser/autocomplete/history_url_provider.h
@@ -255,10 +255,6 @@ class HistoryURLProvider : public AutocompleteProvider {
// output that surprises the user ("Search Google for xn--6ca.com").
static std::wstring FixupUserInput(const AutocompleteInput& input);
- // Trims "http:" and up to two subsequent slashes from |url|. Returns the
- // number of characters that were trimmed.
- static size_t TrimHttpPrefix(std::wstring* url);
-
// Returns true if |url| is just a host (e.g. "http://www.google.com/") and
// not some other subpage (e.g. "http://www.google.com/foo.html").
static bool IsHostOnly(const GURL& url);
diff --git a/chrome/browser/autocomplete/search_provider.cc b/chrome/browser/autocomplete/search_provider.cc
index a4c3134..9d2dce4 100644
--- a/chrome/browser/autocomplete/search_provider.cc
+++ b/chrome/browser/autocomplete/search_provider.cc
@@ -748,9 +748,8 @@ AutocompleteMatch SearchProvider::NavigationToMatch(
AutocompleteMatch::NAVSUGGEST);
match.destination_url = navigation.url;
match.contents = StringForURLDisplay(navigation.url, true);
- // TODO(kochi): Consider moving HistoryURLProvider::TrimHttpPrefix() to some
- // public utility function.
- if (!url_util::FindAndCompareScheme(WideToUTF8(input_text), "http", NULL))
+ if (!url_util::FindAndCompareScheme(WideToUTF8(input_text),
+ chrome::kHttpScheme, NULL))
TrimHttpPrefix(&match.contents);
AutocompleteMatch::ClassifyMatchInString(input_text, match.contents,
ACMatchClassification::URL,
@@ -772,24 +771,3 @@ AutocompleteMatch SearchProvider::NavigationToMatch(
return match;
}
-
-// TODO(kochi): This is duplicate from HistoryURLProvider.
-// static
-size_t SearchProvider::TrimHttpPrefix(std::wstring* url) {
- url_parse::Component scheme;
- if (!url_util::FindAndCompareScheme(WideToUTF8(*url), chrome::kHttpScheme,
- &scheme))
- return 0; // Not "http".
-
- // Erase scheme plus up to two slashes.
- size_t prefix_len = scheme.end() + 1; // "http:"
- const size_t after_slashes = std::min(url->length(),
- static_cast<size_t>(scheme.end() + 3));
- while ((prefix_len < after_slashes) && ((*url)[prefix_len] == L'/'))
- ++prefix_len;
- if (prefix_len == url->length())
- url->clear();
- else
- url->erase(url->begin(), url->begin() + prefix_len);
- return prefix_len;
-}
diff --git a/chrome/browser/autocomplete/search_provider.h b/chrome/browser/autocomplete/search_provider.h
index 6515bc7..e36a2ef 100644
--- a/chrome/browser/autocomplete/search_provider.h
+++ b/chrome/browser/autocomplete/search_provider.h
@@ -260,11 +260,6 @@ class SearchProvider : public AutocompleteProvider,
int relevance,
bool is_keyword);
- // Trims "http:" and up to two subsequent slashes from |url|. Returns the
- // number of characters that were trimmed.
- // TODO(kochi): this is duplicate from history_autocomplete
- static size_t TrimHttpPrefix(std::wstring* url);
-
// Should we query for suggest results immediately? This is normally false,
// but may be set to true during testing.
static bool query_suggest_immediately_;