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/ui/app_list/search_builder.h" | 5 #include "chrome/browser/ui/app_list/search_builder.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
| 8 #include <vector> |
8 | 9 |
9 #include "base/command_line.h" | 10 #include "base/command_line.h" |
10 #include "chrome/browser/autocomplete/autocomplete_controller.h" | 11 #include "chrome/browser/autocomplete/autocomplete_controller.h" |
11 #include "chrome/browser/autocomplete/autocomplete_input.h" | 12 #include "chrome/browser/autocomplete/autocomplete_input.h" |
12 #include "chrome/browser/autocomplete/autocomplete_match.h" | 13 #include "chrome/browser/autocomplete/autocomplete_match.h" |
13 #include "chrome/browser/autocomplete/autocomplete_result.h" | 14 #include "chrome/browser/autocomplete/autocomplete_result.h" |
14 #include "chrome/browser/autocomplete/extension_app_provider.h" | 15 #include "chrome/browser/autocomplete/extension_app_provider.h" |
15 #include "chrome/browser/event_disposition.h" | 16 #include "chrome/browser/event_disposition.h" |
16 #include "chrome/browser/extensions/extension_service.h" | 17 #include "chrome/browser/extensions/extension_service.h" |
17 #include "chrome/browser/extensions/image_loading_tracker.h" | 18 #include "chrome/browser/extensions/image_loading_tracker.h" |
18 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
19 #include "chrome/browser/ui/app_list/app_list_controller.h" | 20 #include "chrome/browser/ui/app_list/app_list_controller.h" |
20 #include "chrome/browser/ui/browser.h" | 21 #include "chrome/browser/ui/browser.h" |
21 #include "chrome/browser/ui/browser_navigator.h" | 22 #include "chrome/browser/ui/browser_navigator.h" |
22 #include "chrome/browser/ui/browser_tabstrip.h" | 23 #include "chrome/browser/ui/browser_tabstrip.h" |
| 24 #include "chrome/common/chrome_switches.h" |
23 #include "chrome/common/extensions/extension.h" | 25 #include "chrome/common/extensions/extension.h" |
24 #include "chrome/common/extensions/extension_constants.h" | 26 #include "chrome/common/extensions/extension_constants.h" |
25 #include "chrome/common/extensions/extension_icon_set.h" | 27 #include "chrome/common/extensions/extension_icon_set.h" |
26 #include "chrome/common/url_constants.h" | 28 #include "chrome/common/url_constants.h" |
27 #include "content/public/browser/user_metrics.h" | 29 #include "content/public/browser/user_metrics.h" |
28 #include "content/public/browser/web_contents.h" | 30 #include "content/public/browser/web_contents.h" |
29 #include "grit/generated_resources.h" | 31 #include "grit/generated_resources.h" |
30 #include "grit/theme_resources.h" | 32 #include "grit/theme_resources.h" |
31 #include "ui/app_list/app_list_switches.h" | 33 #include "ui/app_list/app_list_switches.h" |
32 #include "ui/app_list/search_box_model.h" | 34 #include "ui/app_list/search_box_model.h" |
33 #include "ui/app_list/search_result.h" | 35 #include "ui/app_list/search_result.h" |
34 #include "ui/base/l10n/l10n_util.h" | 36 #include "ui/base/l10n/l10n_util.h" |
35 #include "ui/base/resource/resource_bundle.h" | 37 #include "ui/base/resource/resource_bundle.h" |
| 38 #include "ui/gfx/codec/png_codec.h" |
| 39 |
| 40 #if defined(OS_CHROMEOS) |
| 41 #include "base/memory/ref_counted.h" |
| 42 #include "chrome/browser/chromeos/contacts/contact.pb.h" |
| 43 #include "chrome/browser/chromeos/contacts/contact_manager.h" |
| 44 #include "chrome/browser/image_decoder.h" |
| 45 #endif |
36 | 46 |
37 namespace { | 47 namespace { |
38 | 48 |
39 int ACMatchStyleToTagStyle(int styles) { | 49 int ACMatchStyleToTagStyle(int styles) { |
40 int tag_styles = 0; | 50 int tag_styles = 0; |
41 if (styles & ACMatchClassification::URL) | 51 if (styles & ACMatchClassification::URL) |
42 tag_styles |= app_list::SearchResult::Tag::URL; | 52 tag_styles |= app_list::SearchResult::Tag::URL; |
43 if (styles & ACMatchClassification::MATCH) | 53 if (styles & ACMatchClassification::MATCH) |
44 tag_styles |= app_list::SearchResult::Tag::MATCH; | 54 tag_styles |= app_list::SearchResult::Tag::MATCH; |
45 if (styles & ACMatchClassification::DIM) | 55 if (styles & ACMatchClassification::DIM) |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 // not having a web extent to include new tab url, thus GetInstalledApp does | 96 // not having a web extent to include new tab url, thus GetInstalledApp does |
87 // not find it. | 97 // not find it. |
88 return url.spec() == chrome::kChromeUINewTabURL ? | 98 return url.spec() == chrome::kChromeUINewTabURL ? |
89 service->extensions()->GetByID(extension_misc::kChromeAppId) : | 99 service->extensions()->GetByID(extension_misc::kChromeAppId) : |
90 service->GetInstalledApp(url); | 100 service->GetInstalledApp(url); |
91 } | 101 } |
92 | 102 |
93 // SearchBuildResult is an app list SearchResult built from an | 103 // SearchBuildResult is an app list SearchResult built from an |
94 // AutocompleteMatch. | 104 // AutocompleteMatch. |
95 class SearchBuilderResult : public app_list::SearchResult, | 105 class SearchBuilderResult : public app_list::SearchResult, |
| 106 #if defined(OS_CHROMEOS) |
| 107 public ImageDecoder::Delegate, |
| 108 #endif |
96 public ImageLoadingTracker::Observer { | 109 public ImageLoadingTracker::Observer { |
97 public: | 110 public: |
98 SearchBuilderResult(Profile* profile, | 111 SearchBuilderResult(Profile* profile, |
99 const AutocompleteMatch& match) | 112 const AutocompleteMatch& match) |
100 : profile_(profile), | 113 : profile_(profile), |
101 match_(match) { | 114 match_(match) { |
102 UpdateIcon(); | 115 UpdateIcon(); |
103 UpdateTitleAndDetails(); | 116 UpdateTitleAndDetails(); |
| 117 #if defined(OS_CHROMEOS) |
| 118 if (match_.type == AutocompleteMatch::CONTACT) |
| 119 AddContactActionIcons(); |
| 120 #endif |
| 121 } |
| 122 |
| 123 virtual ~SearchBuilderResult() { |
| 124 #if defined(OS_CHROMEOS) |
| 125 if (contact_photo_decoder_.get()) |
| 126 contact_photo_decoder_->set_delegate(NULL); |
| 127 #endif |
104 } | 128 } |
105 | 129 |
106 const AutocompleteMatch& match() const { | 130 const AutocompleteMatch& match() const { |
107 return match_; | 131 return match_; |
108 } | 132 } |
109 | 133 |
110 private: | 134 private: |
111 void UpdateIcon() { | 135 void UpdateIcon() { |
112 if (match_.type == AutocompleteMatch::EXTENSION_APP) { | 136 if (match_.type == AutocompleteMatch::EXTENSION_APP) { |
113 const extensions::Extension* extension = | 137 const extensions::Extension* extension = |
114 GetExtensionByURL(profile_, match_.destination_url); | 138 GetExtensionByURL(profile_, match_.destination_url); |
115 if (extension) { | 139 if (extension) { |
116 LoadExtensionIcon(extension); | 140 LoadExtensionIcon(extension); |
117 return; | 141 return; |
118 } | 142 } |
119 } | 143 } |
120 | 144 |
| 145 #if defined(OS_CHROMEOS) |
| 146 if (match_.type == AutocompleteMatch::CONTACT) { |
| 147 AutocompleteMatch::AdditionalInfo::const_iterator it = |
| 148 match_.additional_info.find("contact_id"); |
| 149 DCHECK(it != match_.additional_info.end()); |
| 150 const contacts::Contact* contact = |
| 151 contacts::ContactManager::GetInstance()->GetContactById( |
| 152 profile_, it->second); |
| 153 if (contact && contact->has_raw_untrusted_photo()) { |
| 154 contact_photo_decoder_ = |
| 155 new ImageDecoder( |
| 156 this, |
| 157 contact->raw_untrusted_photo(), |
| 158 ImageDecoder::DEFAULT_CODEC); |
| 159 contact_photo_decoder_->Start(); |
| 160 return; |
| 161 } else { |
| 162 SetIcon(*ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 163 IDR_CONTACT_DEFAULT_PHOTO)); |
| 164 } |
| 165 } |
| 166 #endif |
| 167 |
121 int resource_id = match_.starred ? | 168 int resource_id = match_.starred ? |
122 IDR_OMNIBOX_STAR : AutocompleteMatch::TypeToIcon(match_.type); | 169 IDR_OMNIBOX_STAR : AutocompleteMatch::TypeToIcon(match_.type); |
123 SetIcon(*ui::ResourceBundle::GetSharedInstance().GetBitmapNamed( | 170 SetIcon(*ui::ResourceBundle::GetSharedInstance().GetBitmapNamed( |
124 resource_id)); | 171 resource_id)); |
125 } | 172 } |
126 | 173 |
127 void LoadExtensionIcon(const extensions::Extension* extension) { | 174 void LoadExtensionIcon(const extensions::Extension* extension) { |
128 tracker_.reset(new ImageLoadingTracker(this)); | 175 tracker_.reset(new ImageLoadingTracker(this)); |
129 // TODO(xiyuan): Fix this for HD. | 176 // TODO(xiyuan): Fix this for HD. |
130 tracker_->LoadImage(extension, | 177 tracker_->LoadImage(extension, |
(...skipping 14 matching lines...) Expand all Loading... |
145 set_title_tags(title_tags); | 192 set_title_tags(title_tags); |
146 | 193 |
147 set_details(match_.description); | 194 set_details(match_.description); |
148 app_list::SearchResult::Tags details_tags; | 195 app_list::SearchResult::Tags details_tags; |
149 ACMatchClassificationsToTags(match_.description, | 196 ACMatchClassificationsToTags(match_.description, |
150 match_.description_class, | 197 match_.description_class, |
151 &details_tags); | 198 &details_tags); |
152 set_details_tags(details_tags); | 199 set_details_tags(details_tags); |
153 } | 200 } |
154 | 201 |
| 202 #if defined(OS_CHROMEOS) |
| 203 // Add icons for contact-related actions. |
| 204 void AddContactActionIcons() { |
| 205 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| 206 std::vector<app_list::SearchResult::ActionIconSet> icons; |
| 207 icons.push_back( |
| 208 app_list::SearchResult::ActionIconSet( |
| 209 *bundle.GetImageSkiaNamed(IDR_CONTACT_ACTION_CHAT), |
| 210 *bundle.GetImageSkiaNamed(IDR_CONTACT_ACTION_CHAT_H), |
| 211 *bundle.GetImageSkiaNamed(IDR_CONTACT_ACTION_CHAT), |
| 212 l10n_util::GetStringUTF16(IDS_APP_LIST_CONTACT_CHAT_TOOLTIP))); |
| 213 icons.push_back( |
| 214 app_list::SearchResult::ActionIconSet( |
| 215 *bundle.GetImageSkiaNamed(IDR_CONTACT_ACTION_VIDEO), |
| 216 *bundle.GetImageSkiaNamed(IDR_CONTACT_ACTION_VIDEO_H), |
| 217 *bundle.GetImageSkiaNamed(IDR_CONTACT_ACTION_VIDEO), |
| 218 l10n_util::GetStringUTF16(IDS_APP_LIST_CONTACT_VIDEO_TOOLTIP))); |
| 219 icons.push_back( |
| 220 app_list::SearchResult::ActionIconSet( |
| 221 *bundle.GetImageSkiaNamed(IDR_CONTACT_ACTION_PHONE), |
| 222 *bundle.GetImageSkiaNamed(IDR_CONTACT_ACTION_PHONE_H), |
| 223 *bundle.GetImageSkiaNamed(IDR_CONTACT_ACTION_PHONE), |
| 224 l10n_util::GetStringUTF16(IDS_APP_LIST_CONTACT_PHONE_TOOLTIP))); |
| 225 icons.push_back( |
| 226 app_list::SearchResult::ActionIconSet( |
| 227 *bundle.GetImageSkiaNamed(IDR_CONTACT_ACTION_EMAIL), |
| 228 *bundle.GetImageSkiaNamed(IDR_CONTACT_ACTION_EMAIL_H), |
| 229 *bundle.GetImageSkiaNamed(IDR_CONTACT_ACTION_EMAIL), |
| 230 l10n_util::GetStringUTF16(IDS_APP_LIST_CONTACT_EMAIL_TOOLTIP))); |
| 231 SetActionIcons(icons); |
| 232 } |
| 233 |
| 234 // Overridden from ImageDecoder::Delegate: |
| 235 virtual void OnImageDecoded(const ImageDecoder* decoder, |
| 236 const SkBitmap& decoded_image) OVERRIDE { |
| 237 DCHECK_EQ(decoder, contact_photo_decoder_); |
| 238 SetIcon(decoded_image); |
| 239 } |
| 240 |
| 241 virtual void OnDecodeImageFailed(const ImageDecoder* decoder) OVERRIDE { |
| 242 DCHECK_EQ(decoder, contact_photo_decoder_); |
| 243 SetIcon(*ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 244 IDR_CONTACT_DEFAULT_PHOTO)); |
| 245 } |
| 246 #endif |
| 247 |
155 // Overridden from ImageLoadingTracker::Observer: | 248 // Overridden from ImageLoadingTracker::Observer: |
156 virtual void OnImageLoaded(const gfx::Image& image, | 249 virtual void OnImageLoaded(const gfx::Image& image, |
157 const std::string& extension_id, | 250 const std::string& extension_id, |
158 int tracker_index) OVERRIDE { | 251 int tracker_index) OVERRIDE { |
159 if (!image.IsEmpty()) { | 252 if (!image.IsEmpty()) { |
160 SetIcon(*image.ToSkBitmap()); | 253 SetIcon(*image.ToSkBitmap()); |
161 return; | 254 return; |
162 } | 255 } |
163 | 256 |
164 SetIcon(profile_->GetExtensionService()->GetOmniboxPopupIcon(extension_id). | 257 SetIcon(profile_->GetExtensionService()->GetOmniboxPopupIcon(extension_id). |
165 AsImageSkia()); | 258 AsImageSkia()); |
166 } | 259 } |
167 | 260 |
168 Profile* profile_; | 261 Profile* profile_; |
169 AutocompleteMatch match_; | 262 AutocompleteMatch match_; |
170 scoped_ptr<ImageLoadingTracker> tracker_; | 263 scoped_ptr<ImageLoadingTracker> tracker_; |
171 | 264 |
| 265 #if defined(OS_CHROMEOS) |
| 266 scoped_refptr<ImageDecoder> contact_photo_decoder_; |
| 267 #endif |
| 268 |
172 DISALLOW_COPY_AND_ASSIGN(SearchBuilderResult); | 269 DISALLOW_COPY_AND_ASSIGN(SearchBuilderResult); |
173 }; | 270 }; |
174 | 271 |
175 } // namespace | 272 } // namespace |
176 | 273 |
177 SearchBuilder::SearchBuilder( | 274 SearchBuilder::SearchBuilder( |
178 Profile* profile, | 275 Profile* profile, |
179 app_list::SearchBoxModel* search_box, | 276 app_list::SearchBoxModel* search_box, |
180 app_list::AppListModel::SearchResults* results, | 277 app_list::AppListModel::SearchResults* results, |
181 AppListController* list_controller) | 278 AppListController* list_controller) |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 ++it) { | 368 ++it) { |
272 results_->Add(new SearchBuilderResult(profile_, *it)); | 369 results_->Add(new SearchBuilderResult(profile_, *it)); |
273 } | 370 } |
274 } | 371 } |
275 | 372 |
276 void SearchBuilder::OnResultChanged(bool default_match_changed) { | 373 void SearchBuilder::OnResultChanged(bool default_match_changed) { |
277 // TODO(xiyuan): Handle default match properly. | 374 // TODO(xiyuan): Handle default match properly. |
278 const AutocompleteResult& ac_result = controller_->result(); | 375 const AutocompleteResult& ac_result = controller_->result(); |
279 PopulateFromACResult(ac_result); | 376 PopulateFromACResult(ac_result); |
280 } | 377 } |
OLD | NEW |