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/autocomplete_provider.h" | 5 #include "chrome/browser/autocomplete/autocomplete_provider.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/browser/autocomplete/autocomplete_match.h" | 10 #include "chrome/browser/autocomplete/autocomplete_match.h" |
11 #include "chrome/browser/autocomplete/autocomplete_provider_listener.h" | 11 #include "chrome/browser/autocomplete/autocomplete_provider_listener.h" |
12 #include "chrome/browser/bookmarks/bookmark_model.h" | 12 #include "chrome/browser/bookmarks/bookmark_model.h" |
13 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 13 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
16 #include "content/public/common/url_constants.h" | 16 #include "content/public/common/url_constants.h" |
17 #include "net/base/net_util.h" | 17 #include "net/base/net_util.h" |
18 #include "url/gurl.h" | 18 #include "url/gurl.h" |
19 #include "url/url_util.h" | |
20 | 19 |
21 // static | 20 // static |
22 const size_t AutocompleteProvider::kMaxMatches = 3; | 21 const size_t AutocompleteProvider::kMaxMatches = 3; |
23 | 22 |
24 AutocompleteProvider::AutocompleteProvider( | 23 AutocompleteProvider::AutocompleteProvider( |
25 AutocompleteProviderListener* listener, | 24 AutocompleteProviderListener* listener, |
26 Profile* profile, | 25 Profile* profile, |
27 Type type) | 26 Type type) |
28 : profile_(profile), | 27 : profile_(profile), |
29 listener_(listener), | 28 listener_(listener), |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages) : std::string(); | 114 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages) : std::string(); |
116 return net::FormatUrl(url, languages, | 115 return net::FormatUrl(url, languages, |
117 net::kFormatUrlOmitAll & ~(trim_http ? 0 : net::kFormatUrlOmitHTTP), | 116 net::kFormatUrlOmitAll & ~(trim_http ? 0 : net::kFormatUrlOmitHTTP), |
118 net::UnescapeRule::SPACES, NULL, NULL, NULL); | 117 net::UnescapeRule::SPACES, NULL, NULL, NULL); |
119 } | 118 } |
120 | 119 |
121 AutocompleteProvider::~AutocompleteProvider() { | 120 AutocompleteProvider::~AutocompleteProvider() { |
122 Stop(false); | 121 Stop(false); |
123 } | 122 } |
124 | 123 |
125 // static | |
126 bool AutocompleteProvider::HasHTTPScheme(const string16& input) { | |
127 std::string utf8_input(UTF16ToUTF8(input)); | |
128 url_parse::Component scheme; | |
129 if (url_util::FindAndCompareScheme(utf8_input, content::kViewSourceScheme, | |
130 &scheme)) | |
131 utf8_input.erase(0, scheme.end() + 1); | |
132 return url_util::FindAndCompareScheme(utf8_input, content::kHttpScheme, NULL); | |
133 } | |
134 | |
135 void AutocompleteProvider::UpdateStarredStateOfMatches() { | 124 void AutocompleteProvider::UpdateStarredStateOfMatches() { |
136 if (matches_.empty()) | 125 if (matches_.empty()) |
137 return; | 126 return; |
138 | 127 |
139 if (!profile_) | 128 if (!profile_) |
140 return; | 129 return; |
141 | 130 |
142 BookmarkModel* bookmark_model = BookmarkModelFactory::GetForProfile(profile_); | 131 BookmarkModel* bookmark_model = BookmarkModelFactory::GetForProfile(profile_); |
143 if (!bookmark_model || !bookmark_model->loaded()) | 132 if (!bookmark_model || !bookmark_model->loaded()) |
144 return; | 133 return; |
145 | 134 |
146 for (ACMatches::iterator i(matches_.begin()); i != matches_.end(); ++i) | 135 for (ACMatches::iterator i(matches_.begin()); i != matches_.end(); ++i) |
147 i->starred = bookmark_model->IsBookmarked(i->destination_url); | 136 i->starred = bookmark_model->IsBookmarked(i->destination_url); |
148 } | 137 } |
OLD | NEW |