Index: chrome/browser/ui/webui/webapks_handler.cc |
diff --git a/chrome/browser/ui/webui/webapks_handler.cc b/chrome/browser/ui/webui/webapks_handler.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..fb5bbed262f4f44204f7fdfeed89cf95d6f56e20 |
--- /dev/null |
+++ b/chrome/browser/ui/webui/webapks_handler.cc |
@@ -0,0 +1,41 @@ |
+// Copyright (c) 2017 The Chromium Authors. All rights reserved. |
Dan Beam
2017/01/24 18:35:32
no (c)
gonzalon
2017/01/24 20:43:29
Done.
|
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/ui/webui/webapks_handler.h" |
+ |
+#include "base/callback_forward.h" |
+#include "base/values.h" |
+#include "chrome/browser/android/shortcut_helper.h" |
+#include "content/public/browser/web_ui.h" |
+ |
+WebApksHandler::WebApksHandler() : weak_ptr_factory_(this) {} |
+ |
+WebApksHandler::~WebApksHandler() {} |
+ |
+void WebApksHandler::RegisterMessages() { |
+ web_ui()->RegisterMessageCallback( |
+ "requestWebApksInfo", |
+ base::Bind(&WebApksHandler::HandleRequestWebApksInfo, |
+ base::Unretained(this))); |
+} |
+ |
+void WebApksHandler::HandleRequestWebApksInfo(const base::ListValue* args) { |
Dan Beam
2017/01/24 18:35:32
AllowJavascript();
gonzalon
2017/01/24 20:43:29
Done.
|
+ ShortcutHelper::RetrieveWebApks(base::Bind( |
+ &WebApksHandler::OnWebApkInfoRetrieved, weak_ptr_factory_.GetWeakPtr())); |
+} |
+ |
+void WebApksHandler::OnWebApkInfoRetrieved( |
+ const std::vector<WebApkInfo>& webapks_list) { |
Dan Beam
2017/01/24 18:35:32
if (!IsJavascriptAllowed())
return;
gonzalon
2017/01/24 20:43:29
Done.
|
+ base::ListValue list; |
+ for (const auto& webapk_info : webapks_list) { |
+ std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue()); |
+ result->SetString("shortName", webapk_info.short_name); |
+ result->SetString("packageName", webapk_info.package_name); |
+ result->SetInteger("shellApkVersion", webapk_info.shell_apk_version); |
+ result->SetInteger("versionCode", webapk_info.version_code); |
+ list.Append(std::move(result)); |
+ } |
+ |
+ web_ui()->CallJavascriptFunctionUnsafe("returnWebApksInfo", list); |
Dan Beam
2017/01/24 18:35:32
CallJavascriptFunction("returnWebApksInfo", list);
gonzalon
2017/01/24 20:43:29
Done.
|
+} |