OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/autocomplete/builtin_provider.h" | 5 #include "chrome/browser/autocomplete/builtin_provider.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
11 #include "chrome/browser/autocomplete/autocomplete_input.h" | 11 #include "chrome/browser/autocomplete/autocomplete_input.h" |
12 #include "chrome/browser/autocomplete/history_provider.h" | 12 #include "chrome/browser/autocomplete/history_provider.h" |
13 #include "chrome/common/net/url_fixer_upper.h" | 13 #include "chrome/common/net/url_fixer_upper.h" |
14 #include "chrome/common/url_constants.h" | 14 #include "chrome/common/url_constants.h" |
15 | 15 |
16 namespace { | 16 namespace { |
17 | 17 |
| 18 #if !defined(OS_ANDROID) |
18 // This list should be kept in sync with chrome/common/url_constants.h. | 19 // This list should be kept in sync with chrome/common/url_constants.h. |
19 // Only include useful sub-pages, confirmation alerts are not useful. | 20 // Only include useful sub-pages, confirmation alerts are not useful. |
20 const char* const kChromeSettingsSubPages[] = { | 21 const char* const kChromeSettingsSubPages[] = { |
21 chrome::kAutofillSubPage, | 22 chrome::kAutofillSubPage, |
22 chrome::kClearBrowserDataSubPage, | 23 chrome::kClearBrowserDataSubPage, |
23 chrome::kContentSettingsSubPage, | 24 chrome::kContentSettingsSubPage, |
24 chrome::kContentSettingsExceptionsSubPage, | 25 chrome::kContentSettingsExceptionsSubPage, |
25 chrome::kImportDataSubPage, | 26 chrome::kImportDataSubPage, |
26 chrome::kLanguageOptionsSubPage, | 27 chrome::kLanguageOptionsSubPage, |
27 chrome::kPasswordManagerSubPage, | 28 chrome::kPasswordManagerSubPage, |
28 chrome::kResetProfileSettingsSubPage, | 29 chrome::kResetProfileSettingsSubPage, |
29 chrome::kSearchEnginesSubPage, | 30 chrome::kSearchEnginesSubPage, |
30 chrome::kSyncSetupSubPage, | 31 chrome::kSyncSetupSubPage, |
31 #if defined(OS_CHROMEOS) | 32 #if defined(OS_CHROMEOS) |
32 chrome::kInternetOptionsSubPage, | 33 chrome::kInternetOptionsSubPage, |
33 #endif | 34 #endif |
34 }; | 35 }; |
| 36 #endif // !defined(OS_ANDROID) |
35 | 37 |
36 } // namespace | 38 } // namespace |
37 | 39 |
38 const int BuiltinProvider::kRelevance = 860; | 40 const int BuiltinProvider::kRelevance = 860; |
39 | 41 |
40 BuiltinProvider::BuiltinProvider(AutocompleteProviderListener* listener, | 42 BuiltinProvider::BuiltinProvider(AutocompleteProviderListener* listener, |
41 Profile* profile) | 43 Profile* profile) |
42 : AutocompleteProvider(listener, profile, | 44 : AutocompleteProvider(listener, profile, |
43 AutocompleteProvider::TYPE_BUILTIN) { | 45 AutocompleteProvider::TYPE_BUILTIN) { |
44 std::vector<std::string> builtins( | 46 std::vector<std::string> builtins( |
45 chrome::kChromeHostURLs, | 47 chrome::kChromeHostURLs, |
46 chrome::kChromeHostURLs + chrome::kNumberOfChromeHostURLs); | 48 chrome::kChromeHostURLs + chrome::kNumberOfChromeHostURLs); |
47 std::sort(builtins.begin(), builtins.end()); | 49 std::sort(builtins.begin(), builtins.end()); |
48 for (std::vector<std::string>::iterator i(builtins.begin()); | 50 for (std::vector<std::string>::iterator i(builtins.begin()); |
49 i != builtins.end(); ++i) | 51 i != builtins.end(); ++i) |
50 builtins_.push_back(base::ASCIIToUTF16(*i)); | 52 builtins_.push_back(base::ASCIIToUTF16(*i)); |
| 53 |
| 54 #if !defined(OS_ANDROID) |
51 base::string16 settings(base::ASCIIToUTF16(chrome::kChromeUISettingsHost) + | 55 base::string16 settings(base::ASCIIToUTF16(chrome::kChromeUISettingsHost) + |
52 base::ASCIIToUTF16("/")); | 56 base::ASCIIToUTF16("/")); |
53 for (size_t i = 0; i < arraysize(kChromeSettingsSubPages); i++) { | 57 for (size_t i = 0; i < arraysize(kChromeSettingsSubPages); i++) { |
54 builtins_.push_back( | 58 builtins_.push_back( |
55 settings + base::ASCIIToUTF16(kChromeSettingsSubPages[i])); | 59 settings + base::ASCIIToUTF16(kChromeSettingsSubPages[i])); |
56 } | 60 } |
| 61 #endif |
57 } | 62 } |
58 | 63 |
59 void BuiltinProvider::Start(const AutocompleteInput& input, | 64 void BuiltinProvider::Start(const AutocompleteInput& input, |
60 bool minimal_changes) { | 65 bool minimal_changes) { |
61 matches_.clear(); | 66 matches_.clear(); |
62 if ((input.type() == AutocompleteInput::INVALID) || | 67 if ((input.type() == AutocompleteInput::INVALID) || |
63 (input.type() == AutocompleteInput::FORCED_QUERY) || | 68 (input.type() == AutocompleteInput::FORCED_QUERY) || |
64 (input.type() == AutocompleteInput::QUERY)) | 69 (input.type() == AutocompleteInput::QUERY)) |
65 return; | 70 return; |
66 | 71 |
(...skipping 13 matching lines...) Expand all Loading... |
80 // input "about:" (with optional slashes), highlight the whole "chrome://". | 85 // input "about:" (with optional slashes), highlight the whole "chrome://". |
81 const size_t kAboutSchemeLength = strlen(content::kAboutScheme); | 86 const size_t kAboutSchemeLength = strlen(content::kAboutScheme); |
82 bool highlight = starting_chrome || text.length() > kAboutSchemeLength; | 87 bool highlight = starting_chrome || text.length() > kAboutSchemeLength; |
83 styles.push_back(ACMatchClassification(0, highlight ? kMatch : kUrl)); | 88 styles.push_back(ACMatchClassification(0, highlight ? kMatch : kUrl)); |
84 size_t offset = starting_chrome ? text.length() : kChrome.length(); | 89 size_t offset = starting_chrome ? text.length() : kChrome.length(); |
85 if (highlight) | 90 if (highlight) |
86 styles.push_back(ACMatchClassification(offset, kUrl)); | 91 styles.push_back(ACMatchClassification(offset, kUrl)); |
87 // Include some common builtin chrome URLs as the user types the scheme. | 92 // Include some common builtin chrome URLs as the user types the scheme. |
88 AddMatch(base::ASCIIToUTF16(chrome::kChromeUIChromeURLsURL), | 93 AddMatch(base::ASCIIToUTF16(chrome::kChromeUIChromeURLsURL), |
89 base::string16(), styles); | 94 base::string16(), styles); |
| 95 #if !defined(OS_ANDROID) |
90 AddMatch(base::ASCIIToUTF16(chrome::kChromeUISettingsURL), | 96 AddMatch(base::ASCIIToUTF16(chrome::kChromeUISettingsURL), |
91 base::string16(), styles); | 97 base::string16(), styles); |
| 98 #endif |
92 AddMatch(base::ASCIIToUTF16(chrome::kChromeUIVersionURL), | 99 AddMatch(base::ASCIIToUTF16(chrome::kChromeUIVersionURL), |
93 base::string16(), styles); | 100 base::string16(), styles); |
94 } else { | 101 } else { |
95 // Match input about: or chrome: URL input against builtin chrome URLs. | 102 // Match input about: or chrome: URL input against builtin chrome URLs. |
96 GURL url = URLFixerUpper::FixupURL(base::UTF16ToUTF8(text), std::string()); | 103 GURL url = URLFixerUpper::FixupURL(base::UTF16ToUTF8(text), std::string()); |
97 // BuiltinProvider doesn't know how to suggest valid ?query or #fragment | 104 // BuiltinProvider doesn't know how to suggest valid ?query or #fragment |
98 // extensions to chrome: URLs. | 105 // extensions to chrome: URLs. |
99 if (url.SchemeIs(content::kChromeUIScheme) && url.has_host() && | 106 if (url.SchemeIs(content::kChromeUIScheme) && url.has_host() && |
100 !url.has_query() && !url.has_ref()) { | 107 !url.has_query() && !url.has_ref()) { |
101 // Include the path for sub-pages (e.g. "chrome://settings/browser"). | 108 // Include the path for sub-pages (e.g. "chrome://settings/browser"). |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 const ACMatchClassifications& styles) { | 144 const ACMatchClassifications& styles) { |
138 AutocompleteMatch match(this, kRelevance, false, | 145 AutocompleteMatch match(this, kRelevance, false, |
139 AutocompleteMatchType::NAVSUGGEST); | 146 AutocompleteMatchType::NAVSUGGEST); |
140 match.fill_into_edit = match_string; | 147 match.fill_into_edit = match_string; |
141 match.inline_autocompletion = inline_completion; | 148 match.inline_autocompletion = inline_completion; |
142 match.destination_url = GURL(match_string); | 149 match.destination_url = GURL(match_string); |
143 match.contents = match_string; | 150 match.contents = match_string; |
144 match.contents_class = styles; | 151 match.contents_class = styles; |
145 matches_.push_back(match); | 152 matches_.push_back(match); |
146 } | 153 } |
OLD | NEW |