Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(282)

Unified Diff: chrome/browser/ui/webui/webapks_handler.cc

Issue 2629573004: Add a chrome://webapks page. (Closed)
Patch Set: Removes strings from i18n file Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..82a78305c1c000a338945bfa5f40ac51f44e9f0d
--- /dev/null
+++ b/chrome/browser/ui/webui/webapks_handler.cc
@@ -0,0 +1,46 @@
+// Copyright (c) 2017 The Chromium Authors. All rights reserved.
+// 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 "chrome/browser/android/shortcut_helper.h"
+#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.
+#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.
+#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.
+#include "components/webapks_ui/webapks_ui_constants.h"
+#include "content/public/browser/web_ui.h"
+
+WebApksHandler::WebApksHandler() : weak_ptr_factory_(this) {}
+
+WebApksHandler::~WebApksHandler() {}
+
+void WebApksHandler::RegisterMessages() {
+ web_ui()->RegisterMessageCallback(webapks_ui::kRequestWebApksInfo,
+ base::Bind(&WebApksHandler::HandleRequestWebApksInfo,
+ base::Unretained(this)));
+}
+
+void WebApksHandler::HandleRequestWebApksInfo(const base::ListValue* args) {
+ // The WebApkInfoCallback will delete itself after it is done.
+ ShortcutHelper::WebApkInfoCallback callback = base::Bind(
+ &WebApksHandler::OnWebApkInfoReceived, weak_ptr_factory_.GetWeakPtr());
+ 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.
+}
+
+void WebApksHandler::OnWebApkInfoReceived(
+ std::vector<WebApkInfo> webapks_list) {
+ base::ListValue list;
+ for (size_t i = 0; i < webapks_list.size(); ++i) {
+ const WebApkInfo webapk_info = webapks_list[i];
+ 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(webapks_ui::kReturnWebApksInfo, list);
+}

Powered by Google App Engine
This is Rietveld 408576698