Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / app_list / search / search_webstore_result.cc
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/search_webstore_result.h"
6
7 #include "base/strings/string16.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/ui/browser_navigator.h"
10 #include "chrome/common/extensions/extension_constants.h"
11 #include "chrome/grit/generated_resources.h"
12 #include "extensions/common/extension_urls.h"
13 #include "grit/theme_resources.h"
14 #include "net/base/url_util.h"
15 #include "ui/base/l10n/l10n_util.h"
16 #include "ui/base/resource/resource_bundle.h"
17
18 namespace app_list {
19
20 SearchWebstoreResult::SearchWebstoreResult(Profile* profile,
21                                            const std::string& query)
22     : profile_(profile),
23       query_(query),
24       launch_url_(extension_urls::GetWebstoreSearchPageUrl(query)) {
25   set_id(launch_url_.spec());
26   set_relevance(0.0);
27
28   set_title(base::UTF8ToUTF16(query));
29
30   const base::string16 details =
31       l10n_util::GetStringUTF16(IDS_EXTENSION_WEB_STORE_TITLE);
32   Tags details_tags;
33   details_tags.push_back(Tag(SearchResult::Tag::DIM, 0, details.length()));
34
35   set_details(details);
36   set_details_tags(details_tags);
37
38   SetIcon(*ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
39       IDR_WEBSTORE_ICON_32));
40 }
41
42 SearchWebstoreResult::~SearchWebstoreResult() {}
43
44 void SearchWebstoreResult::Open(int event_flags) {
45   const GURL store_url = net::AppendQueryParameter(
46       launch_url_,
47       extension_urls::kWebstoreSourceField,
48       extension_urls::kLaunchSourceAppListSearch);
49
50   chrome::NavigateParams params(profile_,
51                                 store_url,
52                                 ui::PAGE_TRANSITION_LINK);
53   params.disposition = ui::DispositionFromEventFlags(event_flags);
54   chrome::Navigate(&params);
55 }
56
57 void SearchWebstoreResult::InvokeAction(int action_index, int event_flags) {
58 }
59
60 scoped_ptr<ChromeSearchResult> SearchWebstoreResult::Duplicate() {
61   return scoped_ptr<ChromeSearchResult>(
62       new SearchWebstoreResult(profile_, query_)).Pass();
63 }
64
65 ChromeSearchResultType SearchWebstoreResult::GetType() {
66   return WEBSTORE_SEARCH_RESULT;
67 }
68
69 }  // namespace app_list