OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2017 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/webui/webapks_handler.h" | |
6 | |
7 #include "base/callback_forward.h" | |
8 #include "chrome/browser/android/shortcut_helper.h" | |
9 #include "chrome/browser/profiles/profile.h" | |
pkotwicz
2017/01/19 19:37:17
I don't think that this include is needed
gonzalon
2017/01/19 23:50:16
Done.
| |
10 #include "chrome/grit/generated_resources.h" | |
pkotwicz
2017/01/19 19:37:17
I don't think that this include is needed
gonzalon
2017/01/19 23:50:16
Done.
| |
11 #include "components/strings/grit/components_strings.h" | |
pkotwicz
2017/01/19 19:37:17
I don't think that this include is needed
gonzalon
2017/01/19 23:50:16
Done.
| |
12 #include "components/webapks_ui/webapks_ui_constants.h" | |
13 #include "content/public/browser/web_ui.h" | |
14 | |
15 WebApksHandler::WebApksHandler() : weak_ptr_factory_(this) {} | |
16 | |
17 WebApksHandler::~WebApksHandler() {} | |
18 | |
19 void WebApksHandler::RegisterMessages() { | |
20 web_ui()->RegisterMessageCallback(webapks_ui::kRequestWebApksInfo, | |
21 base::Bind(&WebApksHandler::HandleRequestWebApksInfo, | |
22 base::Unretained(this))); | |
23 } | |
24 | |
25 void WebApksHandler::HandleRequestWebApksInfo(const base::ListValue* args) { | |
26 // The WebApkInfoCallback will delete itself after it is done. | |
27 ShortcutHelper::WebApkInfoCallback callback = base::Bind( | |
28 &WebApksHandler::OnWebApkInfoReceived, weak_ptr_factory_.GetWeakPtr()); | |
29 ShortcutHelper::ListWebApks(callback); | |
pkotwicz
2017/01/19 19:37:17
Nit: Inline |callback|. I think that it is cleaner
gonzalon
2017/01/19 23:50:16
Done.
| |
30 } | |
31 | |
32 void WebApksHandler::OnWebApkInfoReceived( | |
33 std::vector<WebApkInfo> webapks_list) { | |
34 base::ListValue list; | |
35 for (size_t i = 0; i < webapks_list.size(); ++i) { | |
36 const WebApkInfo webapk_info = webapks_list[i]; | |
37 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue()); | |
38 result->SetString("shortName", webapk_info.short_name); | |
39 result->SetString("packageName", webapk_info.package_name); | |
40 result->SetInteger("shellApkVersion", webapk_info.shell_apk_version); | |
41 result->SetInteger("versionCode", webapk_info.version_code); | |
42 list.Append(std::move(result)); | |
43 } | |
44 | |
45 web_ui()->CallJavascriptFunctionUnsafe(webapks_ui::kReturnWebApksInfo, list); | |
46 } | |
OLD | NEW |