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

Side by Side Diff: chrome/browser/extensions/api/omnibox/omnibox_api.cc

Issue 12314164: Modified Omnibox extension api to use JSON Schema Compiler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 9 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
OLDNEW
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
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
31 namespace events { 33 namespace events {
32 const char kOnInputStarted[] = "omnibox.onInputStarted"; 34 const char kOnInputStarted[] = "omnibox.onInputStarted";
33 const char kOnInputChanged[] = "omnibox.onInputChanged"; 35 const char kOnInputChanged[] = "omnibox.onInputChanged";
34 const char kOnInputEntered[] = "omnibox.onInputEntered"; 36 const char kOnInputEntered[] = "omnibox.onInputEntered";
35 const char kOnInputCancelled[] = "omnibox.onInputCancelled"; 37 const char kOnInputCancelled[] = "omnibox.onInputCancelled";
36 } // namespace events 38 } // namespace events
37 39
38 namespace extensions { 40 namespace extensions {
39 41
40 namespace { 42 namespace {
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 omnibox_icon_manager_.GetIcon(extension_id)); 219 omnibox_icon_manager_.GetIcon(extension_id));
218 } 220 }
219 221
220 gfx::Image OmniboxAPI::GetOmniboxPopupIcon(const std::string& extension_id) { 222 gfx::Image OmniboxAPI::GetOmniboxPopupIcon(const std::string& extension_id) {
221 return gfx::Image::CreateFrom1xBitmap( 223 return gfx::Image::CreateFrom1xBitmap(
222 omnibox_popup_icon_manager_.GetIcon(extension_id)); 224 omnibox_popup_icon_manager_.GetIcon(extension_id));
223 } 225 }
224 226
225 bool OmniboxSendSuggestionsFunction::RunImpl() { 227 bool OmniboxSendSuggestionsFunction::RunImpl() {
226 ExtensionOmniboxSuggestions suggestions; 228 ExtensionOmniboxSuggestions suggestions;
227 ListValue* suggestions_value; 229 scoped_ptr<SendSuggestions::Params> params(
228 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &suggestions.request_id)); 230 SendSuggestions::Params::Create(*args_));
Devlin 2013/02/27 22:14:17 Line continuation has 4-space indentation.
Aaron Jacobs 2013/02/27 23:01:58 Done.
229 EXTENSION_FUNCTION_VALIDATE(args_->GetList(1, &suggestions_value)); 231 EXTENSION_FUNCTION_VALIDATE(params.get());
230 232
231 suggestions.suggestions.resize(suggestions_value->GetSize()); 233 suggestions.request_id = params->request_id;
232 for (size_t i = 0; i < suggestions_value->GetSize(); ++i) { 234 std::vector<linked_ptr<
Devlin 2013/02/27 22:14:17 yeah, this is another ugly line. But I think it m
Aaron Jacobs 2013/02/27 23:01:58 Done.
235 SendSuggestions::Params::SuggestResultsType> > suggest_results =
236 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];
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.at(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
260 EXTENSION_FUNCTION_VALIDATE(
261 suggestion.PopulateFromSuggestion(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
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::PopulateFromSuggestion(
Devlin 2013/02/27 22:14:17 Perhaps better as PopulateFromDefaultSuggestion, s
Aaron Jacobs 2013/02/27 23:01:58 Done.
323 const SetDefaultSuggestion::Params::Suggestion& suggestion) {
324 description_styles.clear();
325 description_styles.push_back(
326 ACMatchClassification(0, ACMatchClassification::NONE));
327
328 EXTENSION_FUNCTION_VALIDATE(UTF8ToUTF16(suggestion.description.c_str(),
Devlin 2013/02/27 22:14:17 Change to description = UTF8ToUTF16(suggestion.des
Aaron Jacobs 2013/02/27 23:01:58 Done.
329 suggestion.description.length(),
330 &description));
331
332 return true;
333 }
334
313 bool ExtensionOmniboxSuggestion::ReadStylesFromValue( 335 bool ExtensionOmniboxSuggestion::ReadStylesFromValue(
314 const ListValue& styles_value) { 336 const ListValue& styles_value) {
315 description_styles.clear(); 337 description_styles.clear();
316 338
317 // Step 1: Build a vector of styles, 1 per character of description text. 339 // Step 1: Build a vector of styles, 1 per character of description text.
318 std::vector<int> styles; 340 std::vector<int> styles;
319 styles.resize(description.length()); // sets all styles to 0 341 styles.resize(description.length()); // sets all styles to 0
320 342
321 for (size_t i = 0; i < styles_value.GetSize(); ++i) { 343 for (size_t i = 0; i < styles_value.GetSize(); ++i) {
322 const DictionaryValue* style; 344 const DictionaryValue* style;
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 for (size_t i = 0; i < description_styles.size(); ++i) { 438 for (size_t i = 0; i < description_styles.size(); ++i) {
417 if (description_styles[i].offset > placeholder) 439 if (description_styles[i].offset > placeholder)
418 description_styles[i].offset += replacement.length() - 2; 440 description_styles[i].offset += replacement.length() - 2;
419 } 441 }
420 } 442 }
421 443
422 match->contents.assign(description); 444 match->contents.assign(description);
423 } 445 }
424 446
425 } // namespace extensions 447 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698