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

Side by Side Diff: chrome/browser/autocomplete/keyword_provider.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: kalman's requests 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/autocomplete/keyword_provider.h" 5 #include "chrome/browser/autocomplete/keyword_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/string16.h" 10 #include "base/string16.h"
11 #include "base/string_util.h" 11 #include "base/string_util.h"
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 #include "chrome/browser/autocomplete/autocomplete_match.h" 13 #include "chrome/browser/autocomplete/autocomplete_match.h"
14 #include "chrome/browser/autocomplete/autocomplete_provider_listener.h" 14 #include "chrome/browser/autocomplete/autocomplete_provider_listener.h"
15 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h" 15 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h"
16 #include "chrome/browser/extensions/extension_service.h" 16 #include "chrome/browser/extensions/extension_service.h"
17 #include "chrome/browser/extensions/extension_system.h" 17 #include "chrome/browser/extensions/extension_system.h"
18 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/search_engines/template_url.h" 19 #include "chrome/browser/search_engines/template_url.h"
20 #include "chrome/browser/search_engines/template_url_service.h" 20 #include "chrome/browser/search_engines/template_url_service.h"
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 "content/public/browser/notification_details.h" 23 #include "content/public/browser/notification_details.h"
24 #include "content/public/browser/notification_source.h" 24 #include "content/public/browser/notification_source.h"
25 #include "grit/generated_resources.h" 25 #include "grit/generated_resources.h"
26 #include "net/base/escape.h" 26 #include "net/base/escape.h"
27 #include "net/base/net_util.h" 27 #include "net/base/net_util.h"
28 #include "ui/base/l10n/l10n_util.h" 28 #include "ui/base/l10n/l10n_util.h"
29 29
30 namespace omnibox = extensions::api::omnibox;
31
30 // Helper functor for Start(), for ending keyword mode unless explicitly told 32 // Helper functor for Start(), for ending keyword mode unless explicitly told
31 // otherwise. 33 // otherwise.
32 class KeywordProvider::ScopedEndExtensionKeywordMode { 34 class KeywordProvider::ScopedEndExtensionKeywordMode {
33 public: 35 public:
34 explicit ScopedEndExtensionKeywordMode(KeywordProvider* provider) 36 explicit ScopedEndExtensionKeywordMode(KeywordProvider* provider)
35 : provider_(provider) { } 37 : provider_(provider) { }
36 ~ScopedEndExtensionKeywordMode() { 38 ~ScopedEndExtensionKeywordMode() {
37 if (provider_) 39 if (provider_)
38 provider_->MaybeEndExtensionKeywordMode(); 40 provider_->MaybeEndExtensionKeywordMode();
39 } 41 }
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 model->GetTemplateURLForKeyword(keyword)); 553 model->GetTemplateURLForKeyword(keyword));
552 extensions::ApplyDefaultSuggestionForExtensionKeyword( 554 extensions::ApplyDefaultSuggestionForExtensionKeyword(
553 profile_, template_url, 555 profile_, template_url,
554 remaining_input, 556 remaining_input,
555 &matches_[0]); 557 &matches_[0]);
556 listener_->OnProviderUpdate(true); 558 listener_->OnProviderUpdate(true);
557 return; 559 return;
558 } 560 }
559 561
560 case chrome::NOTIFICATION_EXTENSION_OMNIBOX_SUGGESTIONS_READY: { 562 case chrome::NOTIFICATION_EXTENSION_OMNIBOX_SUGGESTIONS_READY: {
561 const extensions::ExtensionOmniboxSuggestions& suggestions = 563 const omnibox::SendSuggestions::Params& suggestions =
not at google - send to devlin 2013/03/16 00:04:25 I think this should be omnibox_api:: rather than o
Aaron Jacobs 2013/03/21 21:59:55 Done.
562 *content::Details< 564 *content::Details<
563 extensions::ExtensionOmniboxSuggestions>(details).ptr(); 565 omnibox::SendSuggestions::Params>(details).ptr();
564 if (suggestions.request_id != current_input_id_) 566 if (suggestions.request_id != current_input_id_)
565 return; // This is an old result. Just ignore. 567 return; // This is an old result. Just ignore.
566 568
567 string16 keyword, remaining_input; 569 string16 keyword, remaining_input;
568 if (!ExtractKeywordFromInput(input, &keyword, &remaining_input)) { 570 if (!ExtractKeywordFromInput(input, &keyword, &remaining_input)) {
569 NOTREACHED(); 571 NOTREACHED();
570 return; 572 return;
571 } 573 }
572 574
573 // TODO(mpcomplete): consider clamping the number of suggestions to 575 // TODO(mpcomplete): consider clamping the number of suggestions to
574 // AutocompleteProvider::kMaxMatches. 576 // AutocompleteProvider::kMaxMatches.
575 for (size_t i = 0; i < suggestions.suggestions.size(); ++i) { 577 for (size_t i = 0; i < suggestions.suggest_results.size(); ++i) {
576 const extensions::ExtensionOmniboxSuggestion& suggestion = 578 const omnibox::SuggestResult& suggestion =
577 suggestions.suggestions[i]; 579 *suggestions.suggest_results[i];
578 // We want to order these suggestions in descending order, so start with 580 // We want to order these suggestions in descending order, so start with
579 // the relevance of the first result (added synchronously in Start()), 581 // the relevance of the first result (added synchronously in Start()),
580 // and subtract 1 for each subsequent suggestion from the extension. 582 // and subtract 1 for each subsequent suggestion from the extension.
581 // We know that |complete| is true, because we wouldn't get results from 583 // We know that |complete| is true, because we wouldn't get results from
582 // the extension unless the full keyword had been typed. 584 // the extension unless the full keyword had been typed.
583 int first_relevance = CalculateRelevance(input.type(), true, true, 585 int first_relevance = CalculateRelevance(input.type(), true, true,
584 input.prefer_keyword(), input.allow_exact_keyword_match()); 586 input.prefer_keyword(), input.allow_exact_keyword_match());
585 extension_suggest_matches_.push_back(CreateAutocompleteMatch( 587 extension_suggest_matches_.push_back(CreateAutocompleteMatch(
586 model, keyword, input, keyword.length(), 588 model, keyword, input, keyword.length(),
587 suggestion.content, first_relevance - (i + 1))); 589 UTF8ToUTF16(suggestion.content), first_relevance - (i + 1)));
588 590
589 AutocompleteMatch* match = &extension_suggest_matches_.back(); 591 AutocompleteMatch* match = &extension_suggest_matches_.back();
590 match->contents.assign(suggestion.description); 592 match->contents.assign(UTF8ToUTF16(suggestion.description));
591 match->contents_class = suggestion.description_styles; 593 match->contents_class = extensions::StyleTypesToACMatchClassifications(
594 suggestion);
not at google - send to devlin 2013/03/16 00:04:25 prefer line break after the =
Aaron Jacobs 2013/03/21 21:59:55 Done.
592 match->description.clear(); 595 match->description.clear();
593 match->description_class.clear(); 596 match->description_class.clear();
594 } 597 }
595 598
596 done_ = true; 599 done_ = true;
597 matches_.insert(matches_.end(), extension_suggest_matches_.begin(), 600 matches_.insert(matches_.end(), extension_suggest_matches_.begin(),
598 extension_suggest_matches_.end()); 601 extension_suggest_matches_.end());
599 listener_->OnProviderUpdate(!extension_suggest_matches_.empty()); 602 listener_->OnProviderUpdate(!extension_suggest_matches_.empty());
600 return; 603 return;
601 } 604 }
(...skipping 24 matching lines...) Expand all
626 } 629 }
627 630
628 void KeywordProvider::MaybeEndExtensionKeywordMode() { 631 void KeywordProvider::MaybeEndExtensionKeywordMode() {
629 if (!current_keyword_extension_id_.empty()) { 632 if (!current_keyword_extension_id_.empty()) {
630 extensions::ExtensionOmniboxEventRouter::OnInputCancelled( 633 extensions::ExtensionOmniboxEventRouter::OnInputCancelled(
631 profile_, current_keyword_extension_id_); 634 profile_, current_keyword_extension_id_);
632 635
633 current_keyword_extension_id_.clear(); 636 current_keyword_extension_id_.clear();
634 } 637 }
635 } 638 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698