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

Side by Side Diff: chrome/browser/ui/app_list/search/webstore_result.cc

Issue 15342003: app_list: Add web store search. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase and address nits in #3 Created 7 years, 7 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/app_list/search/webstore_result.h"
6
7 #include <vector>
8
9 #include "base/bind.h"
10 #include "base/utf_string_conversions.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/ui/app_list/search/webstore_result_icon_source.h"
13 #include "chrome/browser/ui/browser_navigator.h"
14 #include "chrome/common/extensions/extension.h"
15 #include "grit/generated_resources.h"
16 #include "ui/base/l10n/l10n_util.h"
17
18 namespace app_list {
19
20 WebstoreResult::WebstoreResult(Profile* profile,
21 const std::string& app_id,
22 const std::string& localized_name,
23 const GURL& icon_url)
24 : profile_(profile),
25 app_id_(app_id),
26 localized_name_(localized_name),
27 icon_url_(icon_url),
28 weak_factory_(this) {
29 set_id(extensions::Extension::GetBaseURLFromExtensionId(app_id_).spec());
30 set_relevance(0.0); // What is the right value to use?
31
32 set_title(UTF8ToUTF16(localized_name_));
33 SetDefaultDetails();
34
35 const int kIconSize = 32;
36 icon_ = gfx::ImageSkia(
37 new WebstoreResultIconSource(
38 base::Bind(&WebstoreResult::OnIconLoaded,
39 weak_factory_.GetWeakPtr()),
40 profile_->GetRequestContext(),
41 icon_url_,
42 kIconSize),
43 gfx::Size(kIconSize, kIconSize));
44 SetIcon(icon_);
45 }
46
47 WebstoreResult::~WebstoreResult() {}
48
49 void WebstoreResult::Open(int event_flags) {
50 const GURL store_url(extension_urls::GetWebstoreItemDetailURLPrefix() +
51 app_id_);
52 chrome::NavigateParams params(profile_,
53 store_url,
54 content::PAGE_TRANSITION_LINK);
55 params.disposition = ui::DispositionFromEventFlags(event_flags);
56 chrome::Navigate(&params);
57 }
58
59 void WebstoreResult::InvokeAction(int action_index, int event_flags) {}
60
61 scoped_ptr<ChromeSearchResult> WebstoreResult::Duplicate() {
62 return scoped_ptr<ChromeSearchResult>(
63 new WebstoreResult(profile_, app_id_, localized_name_, icon_url_)).Pass();
64 }
65
66 void WebstoreResult::SetDefaultDetails() {
67 const base::string16 details =
68 l10n_util::GetStringUTF16(IDS_EXTENSION_WEB_STORE_TITLE);
69 Tags details_tags;
70 details_tags.push_back(Tag(SearchResult::Tag::DIM, 0, details.length()));
71
72 set_details(details);
73 set_details_tags(details_tags);
74 }
75
76 void WebstoreResult::OnIconLoaded() {
77 // Remove the existing image reps since the icon data is loaded and they
78 // need to be re-created.
79 const std::vector<gfx::ImageSkiaRep>& image_reps = icon_.image_reps();
80 for (size_t i = 0; i < image_reps.size(); ++i)
81 icon_.RemoveRepresentation(image_reps[i].scale_factor());
82
83 SetIcon(icon_);
84 }
85
86 } // namespace app_list
OLDNEW
« no previous file with comments | « chrome/browser/ui/app_list/search/webstore_result.h ('k') | chrome/browser/ui/app_list/search/webstore_result_icon_source.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698