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 "base/values.h" | |
9 #include "chrome/browser/android/shortcut_helper.h" | |
10 #include "content/public/browser/web_ui.h" | |
11 | |
12 WebApksHandler::WebApksHandler() : weak_ptr_factory_(this) {} | |
13 | |
14 WebApksHandler::~WebApksHandler() {} | |
15 | |
16 void WebApksHandler::RegisterMessages() { | |
17 web_ui()->RegisterMessageCallback( | |
18 "requestWebApksInfo", | |
19 base::Bind(&WebApksHandler::HandleRequestWebApksInfo, | |
20 base::Unretained(this))); | |
21 } | |
22 | |
23 void WebApksHandler::HandleRequestWebApksInfo(const base::ListValue* args) { | |
24 ShortcutHelper::RetrieveWebApks(base::Bind( | |
25 &WebApksHandler::OnWebApkInfoRetrieved, weak_ptr_factory_.GetWeakPtr())); | |
26 } | |
27 | |
28 void WebApksHandler::OnWebApkInfoRetrieved( | |
29 const std::vector<const WebApkInfo>& webapks_list) { | |
30 base::ListValue list; | |
31 for (size_t i = 0; i < webapks_list.size(); ++i) { | |
32 const WebApkInfo webapk_info = webapks_list[i]; | |
dominickn
2017/01/24 02:55:22
This copies the object. Use const WebApkInfo& weba
| |
33 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue()); | |
34 result->SetString("shortName", webapk_info.short_name); | |
35 result->SetString("packageName", webapk_info.package_name); | |
36 result->SetInteger("shellApkVersion", webapk_info.shell_apk_version); | |
37 result->SetInteger("versionCode", webapk_info.version_code); | |
38 list.Append(std::move(result)); | |
39 } | |
40 | |
41 web_ui()->CallJavascriptFunctionUnsafe("returnWebApksInfo", list); | |
42 } | |
OLD | NEW |