| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/ui/app_list/search/omnibox_provider.h" | 5 #include "chrome/browser/ui/app_list/search/omnibox_provider.h" |
| 6 | 6 |
| 7 #include "chrome/browser/autocomplete/autocomplete_classifier.h" | 7 #include "chrome/browser/autocomplete/autocomplete_classifier.h" |
| 8 #include "chrome/browser/autocomplete/autocomplete_controller.h" | 8 #include "chrome/browser/autocomplete/autocomplete_controller.h" |
| 9 #include "chrome/browser/autocomplete/autocomplete_match.h" | 9 #include "chrome/browser/autocomplete/autocomplete_match.h" |
| 10 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" | 10 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" |
| 11 #include "chrome/browser/autocomplete/search_provider.h" | |
| 12 #include "chrome/browser/search_engines/template_url_service_factory.h" | 11 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 13 #include "chrome/browser/ui/app_list/search/chrome_search_result.h" | 12 #include "chrome/browser/ui/app_list/search/chrome_search_result.h" |
| 14 #include "chrome/browser/ui/browser_navigator.h" | 13 #include "chrome/browser/ui/browser_navigator.h" |
| 15 #include "components/autocomplete/autocomplete_input.h" | 14 #include "components/autocomplete/autocomplete_input.h" |
| 16 #include "components/metrics/proto/omnibox_event.pb.h" | 15 #include "components/metrics/proto/omnibox_event.pb.h" |
| 17 #include "grit/theme_resources.h" | 16 #include "grit/theme_resources.h" |
| 18 #include "ui/base/resource/resource_bundle.h" | 17 #include "ui/base/resource/resource_bundle.h" |
| 19 | 18 |
| 20 namespace app_list { | 19 namespace app_list { |
| 21 | 20 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 } | 58 } |
| 60 | 59 |
| 61 if (tag_styles != SearchResult::Tag::NONE) { | 60 if (tag_styles != SearchResult::Tag::NONE) { |
| 62 tags->push_back(SearchResult::Tag( | 61 tags->push_back(SearchResult::Tag( |
| 63 tag_styles, tag_start, text.length())); | 62 tag_styles, tag_start, text.length())); |
| 64 } | 63 } |
| 65 } | 64 } |
| 66 | 65 |
| 67 class OmniboxResult : public ChromeSearchResult { | 66 class OmniboxResult : public ChromeSearchResult { |
| 68 public: | 67 public: |
| 69 OmniboxResult(Profile* profile, const AutocompleteMatch& match) | 68 OmniboxResult(Profile* profile, |
| 69 AutocompleteController* autocomplete_controller, |
| 70 const AutocompleteMatch& match) |
| 70 : profile_(profile), | 71 : profile_(profile), |
| 72 autocomplete_controller_(autocomplete_controller), |
| 71 match_(match) { | 73 match_(match) { |
| 72 set_id(match.destination_url.spec()); | 74 if (match_.search_terms_args) { |
| 75 match_.search_terms_args->from_app_list = true; |
| 76 autocomplete_controller_->UpdateMatchDestinationURL( |
| 77 *match_.search_terms_args, &match_); |
| 78 } |
| 79 set_id(match_.destination_url.spec()); |
| 73 | 80 |
| 74 // Derive relevance from omnibox relevance and normalize it to [0, 1]. | 81 // Derive relevance from omnibox relevance and normalize it to [0, 1]. |
| 75 // The magic number 1500 is the highest score of an omnibox result. | 82 // The magic number 1500 is the highest score of an omnibox result. |
| 76 // See comments in autocomplete_provider.h. | 83 // See comments in autocomplete_provider.h. |
| 77 set_relevance(match.relevance / 1500.0); | 84 set_relevance(match_.relevance / 1500.0); |
| 78 | 85 |
| 79 UpdateIcon(); | 86 UpdateIcon(); |
| 80 UpdateTitleAndDetails(); | 87 UpdateTitleAndDetails(); |
| 81 } | 88 } |
| 82 virtual ~OmniboxResult() {} | 89 virtual ~OmniboxResult() {} |
| 83 | 90 |
| 84 // ChromeSearchResult overides: | 91 // ChromeSearchResult overides: |
| 85 virtual void Open(int event_flags) OVERRIDE { | 92 virtual void Open(int event_flags) OVERRIDE { |
| 86 chrome::NavigateParams params(profile_, | 93 chrome::NavigateParams params(profile_, |
| 87 match_.destination_url, | 94 match_.destination_url, |
| 88 match_.transition); | 95 match_.transition); |
| 89 params.disposition = ui::DispositionFromEventFlags(event_flags); | 96 params.disposition = ui::DispositionFromEventFlags(event_flags); |
| 90 chrome::Navigate(¶ms); | 97 chrome::Navigate(¶ms); |
| 91 } | 98 } |
| 92 | 99 |
| 93 virtual void InvokeAction(int action_index, int event_flags) OVERRIDE {} | 100 virtual void InvokeAction(int action_index, int event_flags) OVERRIDE {} |
| 94 | 101 |
| 95 virtual scoped_ptr<ChromeSearchResult> Duplicate() OVERRIDE { | 102 virtual scoped_ptr<ChromeSearchResult> Duplicate() OVERRIDE { |
| 96 return scoped_ptr<ChromeSearchResult>( | 103 return scoped_ptr<ChromeSearchResult>( |
| 97 new OmniboxResult(profile_, match_)).Pass(); | 104 new OmniboxResult(profile_, autocomplete_controller_, match_)).Pass(); |
| 98 } | 105 } |
| 99 | 106 |
| 100 virtual ChromeSearchResultType GetType() OVERRIDE { | 107 virtual ChromeSearchResultType GetType() OVERRIDE { |
| 101 return OMNIBOX_SEARCH_RESULT; | 108 return OMNIBOX_SEARCH_RESULT; |
| 102 } | 109 } |
| 103 | 110 |
| 104 private: | 111 private: |
| 105 void UpdateIcon() { | 112 void UpdateIcon() { |
| 106 int resource_id = match_.starred ? | 113 int resource_id = match_.starred ? |
| 107 IDR_OMNIBOX_STAR : AutocompleteMatch::TypeToIcon(match_.type); | 114 IDR_OMNIBOX_STAR : AutocompleteMatch::TypeToIcon(match_.type); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 119 | 126 |
| 120 set_details(match_.description); | 127 set_details(match_.description); |
| 121 SearchResult::Tags details_tags; | 128 SearchResult::Tags details_tags; |
| 122 ACMatchClassificationsToTags(match_.description, | 129 ACMatchClassificationsToTags(match_.description, |
| 123 match_.description_class, | 130 match_.description_class, |
| 124 &details_tags); | 131 &details_tags); |
| 125 set_details_tags(details_tags); | 132 set_details_tags(details_tags); |
| 126 } | 133 } |
| 127 | 134 |
| 128 Profile* profile_; | 135 Profile* profile_; |
| 136 AutocompleteController* autocomplete_controller_; |
| 129 AutocompleteMatch match_; | 137 AutocompleteMatch match_; |
| 130 | 138 |
| 131 DISALLOW_COPY_AND_ASSIGN(OmniboxResult); | 139 DISALLOW_COPY_AND_ASSIGN(OmniboxResult); |
| 132 }; | 140 }; |
| 133 | 141 |
| 134 } // namespace | 142 } // namespace |
| 135 | 143 |
| 136 OmniboxProvider::OmniboxProvider(Profile* profile) | 144 OmniboxProvider::OmniboxProvider(Profile* profile) |
| 137 : profile_(profile), | 145 : profile_(profile), |
| 138 controller_(new AutocompleteController( | 146 controller_(new AutocompleteController( |
| 139 profile, | 147 profile, |
| 140 TemplateURLServiceFactory::GetForProfile(profile), | 148 TemplateURLServiceFactory::GetForProfile(profile), |
| 141 this, | 149 this, |
| 142 AutocompleteClassifier::kDefaultOmniboxProviders & | 150 AutocompleteClassifier::kDefaultOmniboxProviders & |
| 143 ~AutocompleteProvider::TYPE_ZERO_SUGGEST)) { | 151 ~AutocompleteProvider::TYPE_ZERO_SUGGEST)) { |
| 144 controller_->search_provider()->set_in_app_list(); | |
| 145 } | 152 } |
| 146 | 153 |
| 147 OmniboxProvider::~OmniboxProvider() {} | 154 OmniboxProvider::~OmniboxProvider() {} |
| 148 | 155 |
| 149 void OmniboxProvider::Start(const base::string16& query) { | 156 void OmniboxProvider::Start(const base::string16& query) { |
| 150 controller_->Start(AutocompleteInput( | 157 controller_->Start(AutocompleteInput( |
| 151 query, base::string16::npos, base::string16(), GURL(), | 158 query, base::string16::npos, base::string16(), GURL(), |
| 152 metrics::OmniboxEventProto::INVALID_SPEC, false, false, true, true, | 159 metrics::OmniboxEventProto::INVALID_SPEC, false, false, true, true, |
| 153 ChromeAutocompleteSchemeClassifier(profile_))); | 160 ChromeAutocompleteSchemeClassifier(profile_))); |
| 154 } | 161 } |
| 155 | 162 |
| 156 void OmniboxProvider::Stop() { | 163 void OmniboxProvider::Stop() { |
| 157 controller_->Stop(false); | 164 controller_->Stop(false); |
| 158 } | 165 } |
| 159 | 166 |
| 160 void OmniboxProvider::PopulateFromACResult(const AutocompleteResult& result) { | 167 void OmniboxProvider::PopulateFromACResult(const AutocompleteResult& result) { |
| 161 ClearResults(); | 168 ClearResults(); |
| 162 for (ACMatches::const_iterator it = result.begin(); | 169 for (ACMatches::const_iterator it = result.begin(); |
| 163 it != result.end(); | 170 it != result.end(); |
| 164 ++it) { | 171 ++it) { |
| 165 if (!it->destination_url.is_valid()) | 172 if (!it->destination_url.is_valid()) |
| 166 continue; | 173 continue; |
| 167 | 174 |
| 168 Add(scoped_ptr<SearchResult>(new OmniboxResult(profile_, *it))); | 175 Add(scoped_ptr<SearchResult>( |
| 176 new OmniboxResult(profile_, controller_.get(), *it))); |
| 169 } | 177 } |
| 170 } | 178 } |
| 171 | 179 |
| 172 void OmniboxProvider::OnResultChanged(bool default_match_changed) { | 180 void OmniboxProvider::OnResultChanged(bool default_match_changed) { |
| 173 const AutocompleteResult& result = controller_->result(); | 181 const AutocompleteResult& result = controller_->result(); |
| 174 PopulateFromACResult(result); | 182 PopulateFromACResult(result); |
| 175 } | 183 } |
| 176 | 184 |
| 177 } // namespace app_list | 185 } // namespace app_list |
| OLD | NEW |