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

Side by Side Diff: chrome/browser/autocomplete/autocomplete_popup_model.cc

Issue 6291003: Revert 71485 - Remove wstring from TemplateURL and friends.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 11 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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_popup_model.h" 5 #include "chrome/browser/autocomplete/autocomplete_popup_model.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "unicode/ubidi.h" 9 #include "unicode/ubidi.h"
10 10
11 #include "base/string_util.h" 11 #include "base/string_util.h"
12 #include "base/utf_string_conversions.h"
13 #include "chrome/browser/autocomplete/autocomplete_edit.h" 12 #include "chrome/browser/autocomplete/autocomplete_edit.h"
14 #include "chrome/browser/autocomplete/autocomplete_match.h" 13 #include "chrome/browser/autocomplete/autocomplete_match.h"
15 #include "chrome/browser/autocomplete/autocomplete_popup_view.h" 14 #include "chrome/browser/autocomplete/autocomplete_popup_view.h"
16 #include "chrome/browser/autocomplete/search_provider.h" 15 #include "chrome/browser/autocomplete/search_provider.h"
17 #include "chrome/browser/extensions/extension_service.h" 16 #include "chrome/browser/extensions/extension_service.h"
18 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/search_engines/template_url.h" 18 #include "chrome/browser/search_engines/template_url.h"
20 #include "chrome/browser/search_engines/template_url_model.h" 19 #include "chrome/browser/search_engines/template_url_model.h"
21 #include "chrome/common/notification_details.h" 20 #include "chrome/common/notification_details.h"
22 #include "chrome/common/notification_source.h" 21 #include "chrome/common/notification_source.h"
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 *alternate_nav_url = result->alternate_nav_url(); 200 *alternate_nav_url = result->alternate_nav_url();
202 } 201 }
203 202
204 bool AutocompletePopupModel::GetKeywordForMatch(const AutocompleteMatch& match, 203 bool AutocompletePopupModel::GetKeywordForMatch(const AutocompleteMatch& match,
205 std::wstring* keyword) const { 204 std::wstring* keyword) const {
206 // Assume we have no keyword until we find otherwise. 205 // Assume we have no keyword until we find otherwise.
207 keyword->clear(); 206 keyword->clear();
208 207
209 // If the current match is a keyword, return that as the selected keyword. 208 // If the current match is a keyword, return that as the selected keyword.
210 if (TemplateURL::SupportsReplacement(match.template_url)) { 209 if (TemplateURL::SupportsReplacement(match.template_url)) {
211 keyword->assign(UTF16ToWideHack(match.template_url->keyword())); 210 keyword->assign(match.template_url->keyword());
212 return false; 211 return false;
213 } 212 }
214 213
215 // See if the current match's fill_into_edit corresponds to a keyword. 214 // See if the current match's fill_into_edit corresponds to a keyword.
216 if (!profile_->GetTemplateURLModel()) 215 if (!profile_->GetTemplateURLModel())
217 return false; 216 return false;
218 profile_->GetTemplateURLModel()->Load(); 217 profile_->GetTemplateURLModel()->Load();
219 const string16 keyword_hint(TemplateURLModel::CleanUserInputKeyword( 218 const std::wstring keyword_hint(
220 WideToUTF16Hack(match.fill_into_edit))); 219 TemplateURLModel::CleanUserInputKeyword(match.fill_into_edit));
221 if (keyword_hint.empty()) 220 if (keyword_hint.empty())
222 return false; 221 return false;
223 222
224 // Don't provide a hint if this keyword doesn't support replacement. 223 // Don't provide a hint if this keyword doesn't support replacement.
225 const TemplateURL* const template_url = 224 const TemplateURL* const template_url =
226 profile_->GetTemplateURLModel()->GetTemplateURLForKeyword(keyword_hint); 225 profile_->GetTemplateURLModel()->GetTemplateURLForKeyword(keyword_hint);
227 if (!TemplateURL::SupportsReplacement(template_url)) 226 if (!TemplateURL::SupportsReplacement(template_url))
228 return false; 227 return false;
229 228
230 // Don't provide a hint for inactive/disabled extension keywords. 229 // Don't provide a hint for inactive/disabled extension keywords.
231 if (template_url->IsExtensionKeyword()) { 230 if (template_url->IsExtensionKeyword()) {
232 const Extension* extension = profile_->GetExtensionService()-> 231 const Extension* extension = profile_->GetExtensionService()->
233 GetExtensionById(template_url->GetExtensionId(), false); 232 GetExtensionById(template_url->GetExtensionId(), false);
234 if (!extension || 233 if (!extension ||
235 (profile_->IsOffTheRecord() && 234 (profile_->IsOffTheRecord() &&
236 !profile_->GetExtensionService()->IsIncognitoEnabled(extension))) 235 !profile_->GetExtensionService()->IsIncognitoEnabled(extension)))
237 return false; 236 return false;
238 } 237 }
239 238
240 keyword->assign(UTF16ToWideHack(keyword_hint)); 239 keyword->assign(keyword_hint);
241 return true; 240 return true;
242 } 241 }
243 242
244 void AutocompletePopupModel::FinalizeInstantQuery( 243 void AutocompletePopupModel::FinalizeInstantQuery(
245 const std::wstring& input_text, 244 const std::wstring& input_text,
246 const std::wstring& suggest_text) { 245 const std::wstring& suggest_text) {
247 if (IsOpen()) { 246 if (IsOpen()) {
248 SearchProvider* search_provider = controller_->search_provider(); 247 SearchProvider* search_provider = controller_->search_provider();
249 search_provider->FinalizeInstantQuery(input_text, suggest_text); 248 search_provider->FinalizeInstantQuery(input_text, suggest_text);
250 } 249 }
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 } 322 }
324 323
325 const SkBitmap* AutocompletePopupModel::GetSpecialIconForMatch( 324 const SkBitmap* AutocompletePopupModel::GetSpecialIconForMatch(
326 const AutocompleteMatch& match) const { 325 const AutocompleteMatch& match) const {
327 if (!match.template_url || !match.template_url->IsExtensionKeyword()) 326 if (!match.template_url || !match.template_url->IsExtensionKeyword())
328 return NULL; 327 return NULL;
329 328
330 return &profile_->GetExtensionService()->GetOmniboxPopupIcon( 329 return &profile_->GetExtensionService()->GetOmniboxPopupIcon(
331 match.template_url->GetExtensionId()); 330 match.template_url->GetExtensionId());
332 } 331 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698