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 "content/public/browser/web_ui.h" | |
10 | |
11 WebApksHandler::WebApksHandler() : weak_ptr_factory_(this) {} | |
12 | |
13 WebApksHandler::~WebApksHandler() {} | |
14 | |
15 void WebApksHandler::RegisterMessages() { | |
16 web_ui()->RegisterMessageCallback("requestWebApksInfo", | |
17 base::Bind(&WebApksHandler::HandleRequestWebApksInfo, | |
18 base::Unretained(this))); | |
19 } | |
20 | |
21 void WebApksHandler::HandleRequestWebApksInfo(const base::ListValue* args) { | |
22 // The WebApkInfoCallback will delete itself after it is done. | |
pkotwicz
2017/01/20 16:57:17
Nit: Delete the comment.
I think that commenting
gonzalon
2017/01/20 19:27:01
Done.
| |
23 ShortcutHelper::ListWebApks(base::Bind( | |
24 &WebApksHandler::OnWebApkInfoReceived, weak_ptr_factory_.GetWeakPtr())); | |
25 } | |
26 | |
27 void WebApksHandler::OnWebApkInfoReceived( | |
28 std::vector<const WebApkInfo> webapks_list) { | |
29 base::ListValue list; | |
30 for (size_t i = 0; i < webapks_list.size(); ++i) { | |
31 const WebApkInfo webapk_info = webapks_list[i]; | |
32 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue()); | |
33 result->SetString("shortName", webapk_info.short_name); | |
34 result->SetString("packageName", webapk_info.package_name); | |
35 result->SetInteger("shellApkVersion", webapk_info.shell_apk_version); | |
36 result->SetInteger("versionCode", webapk_info.version_code); | |
37 list.Append(std::move(result)); | |
38 } | |
39 | |
40 web_ui()->CallJavascriptFunctionUnsafe("returnWebApksInfo", list); | |
41 } | |
OLD | NEW |