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

Side by Side 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 unified diff | Download patch
OLDNEW
(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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698