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

Side by Side Diff: chrome/browser/ui/views/ash/app_list/search_builder.cc

Issue 10652003: chromeos: Make Chrome app a real app. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 5 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 | Annotate | Revision Log
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/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 "ash/ash_switches.h" 9 #include "ash/ash_switches.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 tag_start = text_class.offset; 67 tag_start = text_class.offset;
68 tag_styles = ACMatchStyleToTagStyle(text_class.style); 68 tag_styles = ACMatchStyleToTagStyle(text_class.style);
69 } 69 }
70 70
71 if (tag_styles != app_list::SearchResult::Tag::NONE) { 71 if (tag_styles != app_list::SearchResult::Tag::NONE) {
72 tags->push_back(app_list::SearchResult::Tag( 72 tags->push_back(app_list::SearchResult::Tag(
73 tag_styles, tag_start, text.length())); 73 tag_styles, tag_start, text.length()));
74 } 74 }
75 } 75 }
76 76
77 const extensions::Extension* GetExtensionByURL(Profile* profile,
78 const GURL& url) {
79 ExtensionService* service = profile->GetExtensionService();
80 // Need to explicitly get chrome app because it does not override new tab and
81 // not having a web extent to include new tab url, thus GetInstalledApp does
82 // not find it.
83 return url.spec() == chrome::kChromeUINewTabURL ?
84 service->extensions()->GetByID(extension_misc::kChromeAppId) :
85 service->GetInstalledApp(url);
86 }
87
77 // SearchBuildResult is an app list SearchResult built from an 88 // SearchBuildResult is an app list SearchResult built from an
78 // AutocompleteMatch. 89 // AutocompleteMatch.
79 class SearchBuilderResult : public app_list::SearchResult, 90 class SearchBuilderResult : public app_list::SearchResult,
80 public ImageLoadingTracker::Observer { 91 public ImageLoadingTracker::Observer {
81 public: 92 public:
82 SearchBuilderResult(Profile* profile, 93 SearchBuilderResult(Profile* profile,
83 const AutocompleteMatch& match) 94 const AutocompleteMatch& match)
84 : profile_(profile), 95 : profile_(profile),
85 match_(match) { 96 match_(match) {
86 UpdateIcon(); 97 UpdateIcon();
87 UpdateTitleAndDetails(); 98 UpdateTitleAndDetails();
88 } 99 }
89 100
90 const AutocompleteMatch& match() const { 101 const AutocompleteMatch& match() const {
91 return match_; 102 return match_;
92 } 103 }
93 104
94 private: 105 private:
95 void UpdateIcon() { 106 void UpdateIcon() {
96 if (match_.type == AutocompleteMatch::EXTENSION_APP) { 107 if (match_.type == AutocompleteMatch::EXTENSION_APP) {
97 ExtensionService* service = profile_->GetExtensionService();
98 const extensions::Extension* extension = 108 const extensions::Extension* extension =
99 service->GetInstalledApp(match_.destination_url); 109 GetExtensionByURL(profile_, match_.destination_url);
100 if (extension) { 110 if (extension) {
101 LoadExtensionIcon(extension); 111 LoadExtensionIcon(extension);
102 return; 112 return;
103 } 113 }
104 } 114 }
105 115
106 int resource_id = match_.starred ? 116 int resource_id = match_.starred ?
107 IDR_OMNIBOX_STAR : AutocompleteMatch::TypeToIcon(match_.type); 117 IDR_OMNIBOX_STAR : AutocompleteMatch::TypeToIcon(match_.type);
108 SetIcon(*ui::ResourceBundle::GetSharedInstance().GetBitmapNamed( 118 SetIcon(*ui::ResourceBundle::GetSharedInstance().GetBitmapNamed(
109 resource_id)); 119 resource_id));
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 apps_provider_->Stop(); 223 apps_provider_->Stop();
214 } 224 }
215 225
216 void SearchBuilder::OpenResult(const app_list::SearchResult& result, 226 void SearchBuilder::OpenResult(const app_list::SearchResult& result,
217 int event_flags) { 227 int event_flags) {
218 const SearchBuilderResult* builder_result = 228 const SearchBuilderResult* builder_result =
219 static_cast<const SearchBuilderResult*>(&result); 229 static_cast<const SearchBuilderResult*>(&result);
220 const AutocompleteMatch& match = builder_result->match(); 230 const AutocompleteMatch& match = builder_result->match();
221 231
222 if (match.type == AutocompleteMatch::EXTENSION_APP) { 232 if (match.type == AutocompleteMatch::EXTENSION_APP) {
223 ExtensionService* service = profile_->GetExtensionService();
224 const extensions::Extension* extension = 233 const extensions::Extension* extension =
225 service->GetInstalledApp(match.destination_url); 234 GetExtensionByURL(profile_, match.destination_url);
226 if (extension) 235 if (extension)
227 extension_utils::OpenExtension(profile_, extension, event_flags); 236 extension_utils::OpenExtension(profile_, extension, event_flags);
228 } else { 237 } else {
229 WindowOpenDisposition disposition = 238 WindowOpenDisposition disposition =
230 browser::DispositionFromEventFlags(event_flags); 239 browser::DispositionFromEventFlags(event_flags);
231 Browser* browser = browser::FindOrCreateTabbedBrowser(profile_); 240 Browser* browser = browser::FindOrCreateTabbedBrowser(profile_);
232 241
233 if (disposition == CURRENT_TAB) { 242 if (disposition == CURRENT_TAB) {
234 // If current tab is not NTP, change disposition to NEW_FOREGROUND_TAB. 243 // If current tab is not NTP, change disposition to NEW_FOREGROUND_TAB.
235 const GURL& url = browser->GetActiveWebContents() ? 244 const GURL& url = browser->GetActiveWebContents() ?
(...skipping 21 matching lines...) Expand all
257 ++it) { 266 ++it) {
258 results_->Add(new SearchBuilderResult(profile_, *it)); 267 results_->Add(new SearchBuilderResult(profile_, *it));
259 } 268 }
260 } 269 }
261 270
262 void SearchBuilder::OnResultChanged(bool default_match_changed) { 271 void SearchBuilder::OnResultChanged(bool default_match_changed) {
263 // TODO(xiyuan): Handle default match properly. 272 // TODO(xiyuan): Handle default match properly.
264 const AutocompleteResult& ac_result = controller_->result(); 273 const AutocompleteResult& ac_result = controller_->result();
265 PopulateFromACResult(ac_result); 274 PopulateFromACResult(ac_result);
266 } 275 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/ash/app_list/extension_app_item.cc ('k') | chrome/common/extensions/extension.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698