Add SearchProvider nav result inline autocompletion.
SearchProvider::NavigationToMatch authored by PKasting.
Consolidate URLPrefix code; add many unit test cases.
Trim |contents| and |fill_into_edit|'s http scheme if:
-the input does not contain "http:"
-and the input is not a leading substring of "http:".
TODO: Add file and chrome schemes as inlineable prefixes?
TBR=sky (chrome/browser/history OWNERS)
BUG=125871
TEST=Automated; manual with upcoming suggest experiments.
Review URL: https://chromiumcodereview.appspot.com/10396002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@139964 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/autocomplete/url_prefix.cc b/chrome/browser/autocomplete/url_prefix.cc
new file mode 100644
index 0000000..e04d139e
--- /dev/null
+++ b/chrome/browser/autocomplete/url_prefix.cc
@@ -0,0 +1,54 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/autocomplete/url_prefix.h"
+
+#include "base/basictypes.h"
+#include "base/utf_string_conversions.h"
+
+URLPrefix::URLPrefix(const string16& prefix, size_t num_components)
+ : prefix(prefix),
+ num_components(num_components) {
+}
+
+// static
+const URLPrefixes& URLPrefix::GetURLPrefixes() {
+ CR_DEFINE_STATIC_LOCAL(URLPrefixes, prefixes, ());
+ if (prefixes.empty()) {
+ prefixes.push_back(URLPrefix(ASCIIToUTF16("https://www."), 2));
+ prefixes.push_back(URLPrefix(ASCIIToUTF16("http://www."), 2));
+ prefixes.push_back(URLPrefix(ASCIIToUTF16("ftp://ftp."), 2));
+ prefixes.push_back(URLPrefix(ASCIIToUTF16("ftp://www."), 2));
+ prefixes.push_back(URLPrefix(ASCIIToUTF16("https://"), 1));
+ prefixes.push_back(URLPrefix(ASCIIToUTF16("http://"), 1));
+ prefixes.push_back(URLPrefix(ASCIIToUTF16("ftp://"), 1));
+ prefixes.push_back(URLPrefix(string16(), 0));
+ }
+ return prefixes;
+}
+
+// static
+bool URLPrefix::IsURLPrefix(const string16& prefix) {
+ const URLPrefixes& list = GetURLPrefixes();
+ for (URLPrefixes::const_iterator i = list.begin(); i != list.end(); ++i)
+ if (i->prefix == prefix)
+ return true;
+ return false;
+}
+
+// static
+const URLPrefix* URLPrefix::BestURLPrefix(const string16& text,
+ const string16& prefix_suffix) {
+ const URLPrefix* best_prefix = NULL;
+ const URLPrefixes& list = GetURLPrefixes();
+ for (URLPrefixes::const_iterator i = list.begin(); i != list.end(); ++i) {
+ if (!best_prefix || (i->num_components > best_prefix->num_components)) {
+ string16 prefix_with_suffix(i->prefix + prefix_suffix);
+ if ((text.length() >= prefix_with_suffix.length()) &&
+ !text.compare(0, prefix_with_suffix.length(), prefix_with_suffix))
+ best_prefix = &(*i);
+ }
+ }
+ return best_prefix;
+}