Chromium Code Reviews| 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 "chrome/browser/profiles/profile.h" | |
| 10 #include "chrome/grit/generated_resources.h" | |
| 11 #include "components/strings/grit/components_strings.h" | |
| 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( | |
| 21 webapks_ui::kRequestWebApksInfo, | |
|
pkotwicz
2017/01/18 02:08:21
Nit: You can inline the JS method name here the wa
gonzalon
2017/01/18 15:29:32
Done.
| |
| 22 base::Bind(&WebApksHandler::HandleRequestWebApksInfo, | |
| 23 base::Unretained(this))); | |
| 24 } | |
| 25 | |
| 26 void WebApksHandler::HandleRequestWebApksInfo(const base::ListValue* args) { | |
| 27 // The WebApkInfoCallback will delete itself after it is done. | |
| 28 base::Callback<void(std::vector<WebApkInfo*>)> callback = base::Bind( | |
| 29 &WebApksHandler::OnWebApkInfoReceived, weak_ptr_factory_.GetWeakPtr()); | |
| 30 ShortcutHelper::ListWebApks(base::android::AttachCurrentThread(), callback); | |
| 31 } | |
| 32 | |
| 33 void WebApksHandler::OnWebApkInfoReceived( | |
| 34 std::vector<WebApkInfo*> webapks_list) { | |
| 35 base::ListValue* list = new base::ListValue(); | |
|
pkotwicz
2017/01/18 02:08:21
Can you create the value on the stack instead? In
gonzalon
2017/01/18 15:29:32
Yeah, not sure why I used so many pointers, it's b
| |
| 36 for (size_t i = 0; i < webapks_list.size(); ++i) { | |
| 37 const WebApkInfo* webapk_info = webapks_list[i]; | |
| 38 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue()); | |
|
pkotwicz
2017/01/18 02:08:21
Awesome! Creating base::DictionaryValue on the hea
| |
| 39 result->SetString("shortName", webapk_info->short_name); | |
| 40 result->SetString("packageName", webapk_info->package_name); | |
| 41 result->SetInteger("shellApkVersion", webapk_info->shell_apk_version); | |
| 42 result->SetInteger("versionCode", webapk_info->version_code); | |
| 43 delete webapk_info; | |
| 44 list->Append(std::move(result)); | |
| 45 } | |
| 46 | |
| 47 web_ui()->CallJavascriptFunctionUnsafe(webapks_ui::kReturnWebApksInfo, *list); | |
| 48 } | |
| OLD | NEW |