Chromium Code Reviews| 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/extensions/api/omnibox/omnibox_api.h" | 5 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h" |
| 6 | 6 |
| 7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/string16.h" | 10 #include "base/string16.h" |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 #include "chrome/browser/search_engines/template_url_service_factory.h" | 21 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 22 #include "chrome/common/chrome_notification_types.h" | 22 #include "chrome/common/chrome_notification_types.h" |
| 23 #include "chrome/common/extensions/api/omnibox/omnibox_handler.h" | 23 #include "chrome/common/extensions/api/omnibox/omnibox_handler.h" |
| 24 #include "chrome/common/extensions/extension.h" | 24 #include "chrome/common/extensions/extension.h" |
| 25 #include "chrome/common/extensions/extension_manifest_constants.h" | 25 #include "chrome/common/extensions/extension_manifest_constants.h" |
| 26 #include "chrome/common/extensions/manifest_handler.h" | 26 #include "chrome/common/extensions/manifest_handler.h" |
| 27 #include "content/public/browser/notification_details.h" | 27 #include "content/public/browser/notification_details.h" |
| 28 #include "content/public/browser/notification_service.h" | 28 #include "content/public/browser/notification_service.h" |
| 29 #include "ui/gfx/image/image.h" | 29 #include "ui/gfx/image/image.h" |
| 30 | 30 |
| 31 namespace SendSuggestions = extensions::api::omnibox::SendSuggestions; | |
| 32 namespace SetDefaultSuggestion = extensions::api::omnibox::SetDefaultSuggestion; | |
| 33 | |
| 31 namespace events { | 34 namespace events { |
| 32 const char kOnInputStarted[] = "omnibox.onInputStarted"; | 35 const char kOnInputStarted[] = "omnibox.onInputStarted"; |
| 33 const char kOnInputChanged[] = "omnibox.onInputChanged"; | 36 const char kOnInputChanged[] = "omnibox.onInputChanged"; |
| 34 const char kOnInputEntered[] = "omnibox.onInputEntered"; | 37 const char kOnInputEntered[] = "omnibox.onInputEntered"; |
| 35 const char kOnInputCancelled[] = "omnibox.onInputCancelled"; | 38 const char kOnInputCancelled[] = "omnibox.onInputCancelled"; |
| 36 } // namespace events | 39 } // namespace events |
| 37 | 40 |
| 38 namespace extensions { | 41 namespace extensions { |
| 39 | 42 |
| 40 namespace { | 43 namespace { |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 217 omnibox_icon_manager_.GetIcon(extension_id)); | 220 omnibox_icon_manager_.GetIcon(extension_id)); |
| 218 } | 221 } |
| 219 | 222 |
| 220 gfx::Image OmniboxAPI::GetOmniboxPopupIcon(const std::string& extension_id) { | 223 gfx::Image OmniboxAPI::GetOmniboxPopupIcon(const std::string& extension_id) { |
| 221 return gfx::Image::CreateFrom1xBitmap( | 224 return gfx::Image::CreateFrom1xBitmap( |
| 222 omnibox_popup_icon_manager_.GetIcon(extension_id)); | 225 omnibox_popup_icon_manager_.GetIcon(extension_id)); |
| 223 } | 226 } |
| 224 | 227 |
| 225 bool OmniboxSendSuggestionsFunction::RunImpl() { | 228 bool OmniboxSendSuggestionsFunction::RunImpl() { |
| 226 ExtensionOmniboxSuggestions suggestions; | 229 ExtensionOmniboxSuggestions suggestions; |
| 227 ListValue* suggestions_value; | 230 scoped_ptr<SendSuggestions::Params> params( |
| 228 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &suggestions.request_id)); | 231 SendSuggestions::Params::Create(*args_)); |
| 229 EXTENSION_FUNCTION_VALIDATE(args_->GetList(1, &suggestions_value)); | 232 EXTENSION_FUNCTION_VALIDATE(params.get()); |
|
not at google - send to devlin
2013/03/11 16:32:40
just params not params.get().
Aaron Jacobs
2013/03/14 22:00:51
Done.
| |
| 230 | 233 |
| 231 suggestions.suggestions.resize(suggestions_value->GetSize()); | 234 suggestions.request_id = params->request_id; |
| 232 for (size_t i = 0; i < suggestions_value->GetSize(); ++i) { | 235 std::vector<linked_ptr<SendSuggestions::Params::SuggestResultsType> > |
| 236 suggest_results = params->suggest_results; | |
| 237 | |
| 238 suggestions.suggestions.resize(suggest_results.size()); | |
| 239 for (size_t i = 0; i < suggest_results.size(); ++i) { | |
| 233 ExtensionOmniboxSuggestion& suggestion = suggestions.suggestions[i]; | 240 ExtensionOmniboxSuggestion& suggestion = suggestions.suggestions[i]; |
|
not at google - send to devlin
2013/03/11 16:32:40
inline this
Aaron Jacobs
2013/03/14 22:00:51
Done.
| |
| 234 DictionaryValue* suggestion_value; | 241 |
| 235 EXTENSION_FUNCTION_VALIDATE(suggestions_value->GetDictionary( | 242 EXTENSION_FUNCTION_VALIDATE(suggestion.Populate( |
| 236 i, &suggestion_value)); | 243 suggest_results[i]->additional_properties, true)); |
| 237 EXTENSION_FUNCTION_VALIDATE(suggestion.Populate(*suggestion_value, true)); | |
| 238 } | 244 } |
| 239 | 245 |
| 240 content::NotificationService::current()->Notify( | 246 content::NotificationService::current()->Notify( |
| 241 chrome::NOTIFICATION_EXTENSION_OMNIBOX_SUGGESTIONS_READY, | 247 chrome::NOTIFICATION_EXTENSION_OMNIBOX_SUGGESTIONS_READY, |
| 242 content::Source<Profile>(profile_->GetOriginalProfile()), | 248 content::Source<Profile>(profile_->GetOriginalProfile()), |
| 243 content::Details<ExtensionOmniboxSuggestions>(&suggestions)); | 249 content::Details<ExtensionOmniboxSuggestions>(&suggestions)); |
| 244 | 250 |
| 245 return true; | 251 return true; |
| 246 } | 252 } |
| 247 | 253 |
| 248 bool OmniboxSetDefaultSuggestionFunction::RunImpl() { | 254 bool OmniboxSetDefaultSuggestionFunction::RunImpl() { |
| 249 ExtensionOmniboxSuggestion suggestion; | 255 ExtensionOmniboxSuggestion suggestion; |
| 250 DictionaryValue* suggestion_value; | 256 scoped_ptr<SetDefaultSuggestion::Params> params( |
| 251 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &suggestion_value)); | 257 SetDefaultSuggestion::Params::Create(*args_)); |
| 252 EXTENSION_FUNCTION_VALIDATE(suggestion.Populate(*suggestion_value, false)); | 258 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 259 | |
|
not at google - send to devlin
2013/03/11 16:32:40
blank line unnecessary
Aaron Jacobs
2013/03/14 22:00:51
Done.
| |
| 260 EXTENSION_FUNCTION_VALIDATE( | |
| 261 suggestion.PopulateFromDefaultSuggestion(params->suggestion)); | |
| 253 | 262 |
| 254 ExtensionPrefs* prefs = | 263 ExtensionPrefs* prefs = |
| 255 ExtensionSystem::Get(profile())->extension_service()->extension_prefs(); | 264 ExtensionSystem::Get(profile())->extension_service()->extension_prefs(); |
| 256 if (prefs) | 265 if (prefs) |
| 257 prefs->SetOmniboxDefaultSuggestion(extension_id(), suggestion); | 266 prefs->SetOmniboxDefaultSuggestion(extension_id(), suggestion); |
| 258 | 267 |
| 259 content::NotificationService::current()->Notify( | 268 content::NotificationService::current()->Notify( |
| 260 chrome::NOTIFICATION_EXTENSION_OMNIBOX_DEFAULT_SUGGESTION_CHANGED, | 269 chrome::NOTIFICATION_EXTENSION_OMNIBOX_DEFAULT_SUGGESTION_CHANGED, |
| 261 content::Source<Profile>(profile_->GetOriginalProfile()), | 270 content::Source<Profile>(profile_->GetOriginalProfile()), |
| 262 content::NotificationService::NoDetails()); | 271 content::NotificationService::NoDetails()); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 303 description_styles.push_back(ACMatchClassification(offset, type)); | 312 description_styles.push_back(ACMatchClassification(offset, type)); |
| 304 } | 313 } |
| 305 } else { | 314 } else { |
| 306 description_styles.push_back( | 315 description_styles.push_back( |
| 307 ACMatchClassification(0, ACMatchClassification::NONE)); | 316 ACMatchClassification(0, ACMatchClassification::NONE)); |
| 308 } | 317 } |
| 309 | 318 |
| 310 return true; | 319 return true; |
| 311 } | 320 } |
| 312 | 321 |
| 322 bool ExtensionOmniboxSuggestion::PopulateFromDefaultSuggestion( | |
| 323 const SetDefaultSuggestion::Params::Suggestion& suggestion) { | |
| 324 description_styles.clear(); | |
| 325 description_styles.push_back( | |
| 326 ACMatchClassification(0, ACMatchClassification::NONE)); | |
| 327 | |
| 328 description = UTF8ToUTF16(suggestion.description); | |
| 329 | |
|
not at google - send to devlin
2013/03/11 16:32:40
blank lines unecessary
Aaron Jacobs
2013/03/14 22:00:51
Done.
| |
| 330 return true; | |
| 331 } | |
| 332 | |
| 313 bool ExtensionOmniboxSuggestion::ReadStylesFromValue( | 333 bool ExtensionOmniboxSuggestion::ReadStylesFromValue( |
| 314 const ListValue& styles_value) { | 334 const ListValue& styles_value) { |
| 315 description_styles.clear(); | 335 description_styles.clear(); |
| 316 | 336 |
| 317 // Step 1: Build a vector of styles, 1 per character of description text. | 337 // Step 1: Build a vector of styles, 1 per character of description text. |
| 318 std::vector<int> styles; | 338 std::vector<int> styles; |
| 319 styles.resize(description.length()); // sets all styles to 0 | 339 styles.resize(description.length()); // sets all styles to 0 |
| 320 | 340 |
| 321 for (size_t i = 0; i < styles_value.GetSize(); ++i) { | 341 for (size_t i = 0; i < styles_value.GetSize(); ++i) { |
| 322 const DictionaryValue* style; | 342 const DictionaryValue* style; |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 416 for (size_t i = 0; i < description_styles.size(); ++i) { | 436 for (size_t i = 0; i < description_styles.size(); ++i) { |
| 417 if (description_styles[i].offset > placeholder) | 437 if (description_styles[i].offset > placeholder) |
| 418 description_styles[i].offset += replacement.length() - 2; | 438 description_styles[i].offset += replacement.length() - 2; |
| 419 } | 439 } |
| 420 } | 440 } |
| 421 | 441 |
| 422 match->contents.assign(description); | 442 match->contents.assign(description); |
| 423 } | 443 } |
| 424 | 444 |
| 425 } // namespace extensions | 445 } // namespace extensions |
| OLD | NEW |