OLD | NEW |
---|---|
(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 icon_changed_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 icon_changed_factory_.GetWeakPtr()), | |
koz (OOO until 15th September)
2013/05/20 01:14:16
nit: I think it's more common to just name this va
xiyuan
2013/05/20 16:56:31
Done.
| |
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(¶ms); | |
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 | |
OLD | NEW |