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