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/chrome_autocomplete_scheme_classifier.h" | 9 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" |
10 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 10 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
11 #include "chrome/browser/search_engines/template_url_service_factory.h" | 11 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 12 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" |
12 #include "chrome/browser/ui/app_list/search/search_util.h" | 13 #include "chrome/browser/ui/app_list/search/search_util.h" |
13 #include "chrome/browser/ui/browser_navigator.h" | |
14 #include "components/bookmarks/browser/bookmark_model.h" | 14 #include "components/bookmarks/browser/bookmark_model.h" |
15 #include "components/metrics/proto/omnibox_event.pb.h" | 15 #include "components/metrics/proto/omnibox_event.pb.h" |
16 #include "components/omnibox/autocomplete_input.h" | 16 #include "components/omnibox/autocomplete_input.h" |
17 #include "components/omnibox/autocomplete_match.h" | 17 #include "components/omnibox/autocomplete_match.h" |
18 #include "grit/theme_resources.h" | 18 #include "grit/theme_resources.h" |
19 #include "ui/app_list/search_result.h" | 19 #include "ui/app_list/search_result.h" |
20 #include "ui/base/resource/resource_bundle.h" | 20 #include "ui/base/resource/resource_bundle.h" |
21 | 21 |
22 namespace app_list { | 22 namespace app_list { |
23 | 23 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 | 62 |
63 if (tag_styles != SearchResult::Tag::NONE) { | 63 if (tag_styles != SearchResult::Tag::NONE) { |
64 tags->push_back(SearchResult::Tag( | 64 tags->push_back(SearchResult::Tag( |
65 tag_styles, tag_start, text.length())); | 65 tag_styles, tag_start, text.length())); |
66 } | 66 } |
67 } | 67 } |
68 | 68 |
69 class OmniboxResult : public SearchResult { | 69 class OmniboxResult : public SearchResult { |
70 public: | 70 public: |
71 OmniboxResult(Profile* profile, | 71 OmniboxResult(Profile* profile, |
| 72 AppListControllerDelegate* list_controller, |
72 AutocompleteController* autocomplete_controller, | 73 AutocompleteController* autocomplete_controller, |
73 const AutocompleteMatch& match) | 74 const AutocompleteMatch& match) |
74 : profile_(profile), | 75 : profile_(profile), |
| 76 list_controller_(list_controller), |
75 autocomplete_controller_(autocomplete_controller), | 77 autocomplete_controller_(autocomplete_controller), |
76 match_(match) { | 78 match_(match) { |
77 if (match_.search_terms_args) { | 79 if (match_.search_terms_args) { |
78 match_.search_terms_args->from_app_list = true; | 80 match_.search_terms_args->from_app_list = true; |
79 autocomplete_controller_->UpdateMatchDestinationURL( | 81 autocomplete_controller_->UpdateMatchDestinationURL( |
80 *match_.search_terms_args, &match_); | 82 *match_.search_terms_args, &match_); |
81 } | 83 } |
82 set_id(match_.destination_url.spec()); | 84 set_id(match_.destination_url.spec()); |
83 | 85 |
84 // Derive relevance from omnibox relevance and normalize it to [0, 1]. | 86 // Derive relevance from omnibox relevance and normalize it to [0, 1]. |
85 // The magic number 1500 is the highest score of an omnibox result. | 87 // The magic number 1500 is the highest score of an omnibox result. |
86 // See comments in autocomplete_provider.h. | 88 // See comments in autocomplete_provider.h. |
87 set_relevance(match_.relevance / 1500.0); | 89 set_relevance(match_.relevance / 1500.0); |
88 | 90 |
89 UpdateIcon(); | 91 UpdateIcon(); |
90 UpdateTitleAndDetails(); | 92 UpdateTitleAndDetails(); |
91 } | 93 } |
92 virtual ~OmniboxResult() {} | 94 virtual ~OmniboxResult() {} |
93 | 95 |
94 // SearchResult overrides: | 96 // SearchResult overrides: |
95 virtual void Open(int event_flags) override { | 97 virtual void Open(int event_flags) override { |
96 RecordHistogram(OMNIBOX_SEARCH_RESULT); | 98 RecordHistogram(OMNIBOX_SEARCH_RESULT); |
97 chrome::NavigateParams params(profile_, | 99 list_controller_->OpenURL(profile_, |
98 match_.destination_url, | 100 match_.destination_url, |
99 match_.transition); | 101 match_.transition, |
100 params.disposition = ui::DispositionFromEventFlags(event_flags); | 102 ui::DispositionFromEventFlags(event_flags)); |
101 chrome::Navigate(¶ms); | |
102 } | 103 } |
103 | 104 |
104 virtual scoped_ptr<SearchResult> Duplicate() override { | 105 virtual scoped_ptr<SearchResult> Duplicate() override { |
105 return scoped_ptr<SearchResult>( | 106 return scoped_ptr<SearchResult>(new OmniboxResult( |
106 new OmniboxResult(profile_, autocomplete_controller_, match_)); | 107 profile_, list_controller_, autocomplete_controller_, match_)); |
107 } | 108 } |
108 | 109 |
109 private: | 110 private: |
110 void UpdateIcon() { | 111 void UpdateIcon() { |
111 BookmarkModel* bookmark_model = | 112 BookmarkModel* bookmark_model = |
112 BookmarkModelFactory::GetForProfile(profile_); | 113 BookmarkModelFactory::GetForProfile(profile_); |
113 bool is_bookmarked = | 114 bool is_bookmarked = |
114 bookmark_model && bookmark_model->IsBookmarked(match_.destination_url); | 115 bookmark_model && bookmark_model->IsBookmarked(match_.destination_url); |
115 int resource_id = is_bookmarked ? | 116 int resource_id = is_bookmarked ? |
116 IDR_OMNIBOX_STAR : AutocompleteMatch::TypeToIcon(match_.type); | 117 IDR_OMNIBOX_STAR : AutocompleteMatch::TypeToIcon(match_.type); |
(...skipping 11 matching lines...) Expand all Loading... |
128 | 129 |
129 set_details(match_.description); | 130 set_details(match_.description); |
130 SearchResult::Tags details_tags; | 131 SearchResult::Tags details_tags; |
131 ACMatchClassificationsToTags(match_.description, | 132 ACMatchClassificationsToTags(match_.description, |
132 match_.description_class, | 133 match_.description_class, |
133 &details_tags); | 134 &details_tags); |
134 set_details_tags(details_tags); | 135 set_details_tags(details_tags); |
135 } | 136 } |
136 | 137 |
137 Profile* profile_; | 138 Profile* profile_; |
| 139 AppListControllerDelegate* list_controller_; |
138 AutocompleteController* autocomplete_controller_; | 140 AutocompleteController* autocomplete_controller_; |
139 AutocompleteMatch match_; | 141 AutocompleteMatch match_; |
140 | 142 |
141 DISALLOW_COPY_AND_ASSIGN(OmniboxResult); | 143 DISALLOW_COPY_AND_ASSIGN(OmniboxResult); |
142 }; | 144 }; |
143 | 145 |
144 } // namespace | 146 } // namespace |
145 | 147 |
146 OmniboxProvider::OmniboxProvider(Profile* profile) | 148 OmniboxProvider::OmniboxProvider(Profile* profile, |
| 149 AppListControllerDelegate* list_controller) |
147 : profile_(profile), | 150 : profile_(profile), |
| 151 list_controller_(list_controller), |
148 controller_(new AutocompleteController( | 152 controller_(new AutocompleteController( |
149 profile, | 153 profile, |
150 TemplateURLServiceFactory::GetForProfile(profile), | 154 TemplateURLServiceFactory::GetForProfile(profile), |
151 this, | 155 this, |
152 AutocompleteClassifier::kDefaultOmniboxProviders & | 156 AutocompleteClassifier::kDefaultOmniboxProviders & |
153 ~AutocompleteProvider::TYPE_ZERO_SUGGEST)) { | 157 ~AutocompleteProvider::TYPE_ZERO_SUGGEST)) { |
154 } | 158 } |
155 | 159 |
156 OmniboxProvider::~OmniboxProvider() {} | 160 OmniboxProvider::~OmniboxProvider() {} |
157 | 161 |
(...skipping 10 matching lines...) Expand all Loading... |
168 | 172 |
169 void OmniboxProvider::PopulateFromACResult(const AutocompleteResult& result) { | 173 void OmniboxProvider::PopulateFromACResult(const AutocompleteResult& result) { |
170 ClearResults(); | 174 ClearResults(); |
171 for (ACMatches::const_iterator it = result.begin(); | 175 for (ACMatches::const_iterator it = result.begin(); |
172 it != result.end(); | 176 it != result.end(); |
173 ++it) { | 177 ++it) { |
174 if (!it->destination_url.is_valid()) | 178 if (!it->destination_url.is_valid()) |
175 continue; | 179 continue; |
176 | 180 |
177 Add(scoped_ptr<SearchResult>( | 181 Add(scoped_ptr<SearchResult>( |
178 new OmniboxResult(profile_, controller_.get(), *it))); | 182 new OmniboxResult(profile_, list_controller_, controller_.get(), *it))); |
179 } | 183 } |
180 } | 184 } |
181 | 185 |
182 void OmniboxProvider::OnResultChanged(bool default_match_changed) { | 186 void OmniboxProvider::OnResultChanged(bool default_match_changed) { |
183 const AutocompleteResult& result = controller_->result(); | 187 const AutocompleteResult& result = controller_->result(); |
184 PopulateFromACResult(result); | 188 PopulateFromACResult(result); |
185 } | 189 } |
186 | 190 |
187 } // namespace app_list | 191 } // namespace app_list |
OLD | NEW |