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/views/ash/app_list/search_builder.h" | 5 #include "chrome/browser/ui/views/ash/app_list/search_builder.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "chrome/browser/autocomplete/autocomplete_controller.h" | 10 #include "chrome/browser/autocomplete/autocomplete_controller.h" |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 const GURL& url) { | 81 const GURL& url) { |
82 ExtensionService* service = profile->GetExtensionService(); | 82 ExtensionService* service = profile->GetExtensionService(); |
83 // Need to explicitly get chrome app because it does not override new tab and | 83 // Need to explicitly get chrome app because it does not override new tab and |
84 // not having a web extent to include new tab url, thus GetInstalledApp does | 84 // not having a web extent to include new tab url, thus GetInstalledApp does |
85 // not find it. | 85 // not find it. |
86 return url.spec() == chrome::kChromeUINewTabURL ? | 86 return url.spec() == chrome::kChromeUINewTabURL ? |
87 service->extensions()->GetByID(extension_misc::kChromeAppId) : | 87 service->extensions()->GetByID(extension_misc::kChromeAppId) : |
88 service->GetInstalledApp(url); | 88 service->GetInstalledApp(url); |
89 } | 89 } |
90 | 90 |
| 91 #if defined(OS_CHROMEOS) |
| 92 const contacts::Contact* GetContactByURL(const GURL& url) { |
| 93 return contacts::ContactManager::GetInstance()->GetContactByProviderId( |
| 94 url.spec()); |
| 95 } |
| 96 #endif |
| 97 |
91 // SearchBuildResult is an app list SearchResult built from an | 98 // SearchBuildResult is an app list SearchResult built from an |
92 // AutocompleteMatch. | 99 // AutocompleteMatch. |
93 class SearchBuilderResult : public app_list::SearchResult, | 100 class SearchBuilderResult : public app_list::SearchResult, |
94 public ImageLoadingTracker::Observer { | 101 public ImageLoadingTracker::Observer { |
95 public: | 102 public: |
96 SearchBuilderResult(Profile* profile, | 103 SearchBuilderResult(Profile* profile, |
97 const AutocompleteMatch& match) | 104 const AutocompleteMatch& match) |
98 : profile_(profile), | 105 : profile_(profile), |
99 match_(match) { | 106 match_(match) { |
100 UpdateIcon(); | 107 UpdateIcon(); |
101 UpdateTitleAndDetails(); | 108 UpdateTitleAndDetails(); |
102 } | 109 } |
103 | 110 |
104 const AutocompleteMatch& match() const { | 111 const AutocompleteMatch& match() const { |
105 return match_; | 112 return match_; |
106 } | 113 } |
107 | 114 |
108 private: | 115 private: |
109 void UpdateIcon() { | 116 void UpdateIcon() { |
110 if (match_.type == AutocompleteMatch::EXTENSION_APP) { | 117 if (match_.type == AutocompleteMatch::EXTENSION_APP) { |
111 const extensions::Extension* extension = | 118 const extensions::Extension* extension = |
112 GetExtensionByURL(profile_, match_.destination_url); | 119 GetExtensionByURL(profile_, match_.destination_url); |
113 if (extension) { | 120 if (extension) { |
114 LoadExtensionIcon(extension); | 121 LoadExtensionIcon(extension); |
115 return; | 122 return; |
116 } | 123 } |
117 } | 124 } |
118 | 125 |
| 126 #if defined(OS_CHROMEOS) |
| 127 if (match_.type == AutocompleteMatch::CONTACT) { |
| 128 const contacts::Contact* contact = |
| 129 GetContactByURL(match_.destination_url); |
| 130 if (contact && !contact->photo.empty() && !contact->photo.isNull()) { |
| 131 SetIcon(contact->photo); |
| 132 return; |
| 133 } |
| 134 } |
| 135 #endif |
| 136 |
119 int resource_id = match_.starred ? | 137 int resource_id = match_.starred ? |
120 IDR_OMNIBOX_STAR : AutocompleteMatch::TypeToIcon(match_.type); | 138 IDR_OMNIBOX_STAR : AutocompleteMatch::TypeToIcon(match_.type); |
121 SetIcon(*ui::ResourceBundle::GetSharedInstance().GetBitmapNamed( | 139 SetIcon(*ui::ResourceBundle::GetSharedInstance().GetBitmapNamed( |
122 resource_id)); | 140 resource_id)); |
123 } | 141 } |
124 | 142 |
125 void LoadExtensionIcon(const extensions::Extension* extension) { | 143 void LoadExtensionIcon(const extensions::Extension* extension) { |
126 tracker_.reset(new ImageLoadingTracker(this)); | 144 tracker_.reset(new ImageLoadingTracker(this)); |
127 // TODO(xiyuan): Fix this for HD. | 145 // TODO(xiyuan): Fix this for HD. |
128 tracker_->LoadImage(extension, | 146 tracker_->LoadImage(extension, |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 ++it) { | 287 ++it) { |
270 results_->Add(new SearchBuilderResult(profile_, *it)); | 288 results_->Add(new SearchBuilderResult(profile_, *it)); |
271 } | 289 } |
272 } | 290 } |
273 | 291 |
274 void SearchBuilder::OnResultChanged(bool default_match_changed) { | 292 void SearchBuilder::OnResultChanged(bool default_match_changed) { |
275 // TODO(xiyuan): Handle default match properly. | 293 // TODO(xiyuan): Handle default match properly. |
276 const AutocompleteResult& ac_result = controller_->result(); | 294 const AutocompleteResult& ac_result = controller_->result(); |
277 PopulateFromACResult(ac_result); | 295 PopulateFromACResult(ac_result); |
278 } | 296 } |
OLD | NEW |