| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/webui/webapks_handler.h" | 5 #include "chrome/browser/ui/webui/webapks_handler.h" |
| 6 | 6 |
| 7 #include <string> |
| 8 |
| 7 #include "base/callback_forward.h" | 9 #include "base/callback_forward.h" |
| 10 #include "base/strings/stringprintf.h" |
| 8 #include "base/values.h" | 11 #include "base/values.h" |
| 9 #include "chrome/browser/android/shortcut_helper.h" | 12 #include "chrome/browser/android/shortcut_helper.h" |
| 13 #include "chrome/browser/ui/webui/color_utils.h" |
| 10 #include "content/public/browser/web_ui.h" | 14 #include "content/public/browser/web_ui.h" |
| 15 #include "content/public/common/manifest_util.h" |
| 11 | 16 |
| 12 WebApksHandler::WebApksHandler() : weak_ptr_factory_(this) {} | 17 WebApksHandler::WebApksHandler() : weak_ptr_factory_(this) {} |
| 13 | 18 |
| 14 WebApksHandler::~WebApksHandler() {} | 19 WebApksHandler::~WebApksHandler() {} |
| 15 | 20 |
| 16 void WebApksHandler::RegisterMessages() { | 21 void WebApksHandler::RegisterMessages() { |
| 17 web_ui()->RegisterMessageCallback( | 22 web_ui()->RegisterMessageCallback( |
| 18 "requestWebApksInfo", | 23 "requestWebApksInfo", |
| 19 base::Bind(&WebApksHandler::HandleRequestWebApksInfo, | 24 base::Bind(&WebApksHandler::HandleRequestWebApksInfo, |
| 20 base::Unretained(this))); | 25 base::Unretained(this))); |
| 21 } | 26 } |
| 22 | 27 |
| 23 void WebApksHandler::HandleRequestWebApksInfo(const base::ListValue* args) { | 28 void WebApksHandler::HandleRequestWebApksInfo(const base::ListValue* args) { |
| 24 AllowJavascript(); | 29 AllowJavascript(); |
| 25 ShortcutHelper::RetrieveWebApks(base::Bind( | 30 ShortcutHelper::RetrieveWebApks(base::Bind( |
| 26 &WebApksHandler::OnWebApkInfoRetrieved, weak_ptr_factory_.GetWeakPtr())); | 31 &WebApksHandler::OnWebApkInfoRetrieved, weak_ptr_factory_.GetWeakPtr())); |
| 27 } | 32 } |
| 28 | 33 |
| 29 void WebApksHandler::OnWebApkInfoRetrieved( | 34 void WebApksHandler::OnWebApkInfoRetrieved( |
| 30 const std::vector<WebApkInfo>& webapks_list) { | 35 const std::vector<WebApkInfo>& webapks_list) { |
| 31 if (!IsJavascriptAllowed()) | 36 if (!IsJavascriptAllowed()) |
| 32 return; | 37 return; |
| 33 base::ListValue list; | 38 base::ListValue list; |
| 34 for (const auto& webapk_info : webapks_list) { | 39 for (const auto& webapk_info : webapks_list) { |
| 35 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue()); | 40 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue()); |
| 41 result->SetString("name", webapk_info.name); |
| 36 result->SetString("shortName", webapk_info.short_name); | 42 result->SetString("shortName", webapk_info.short_name); |
| 37 result->SetString("packageName", webapk_info.package_name); | 43 result->SetString("packageName", webapk_info.package_name); |
| 38 result->SetInteger("shellApkVersion", webapk_info.shell_apk_version); | 44 result->SetInteger("shellApkVersion", webapk_info.shell_apk_version); |
| 39 result->SetInteger("versionCode", webapk_info.version_code); | 45 result->SetInteger("versionCode", webapk_info.version_code); |
| 46 result->SetString("uri", webapk_info.uri); |
| 47 result->SetString("scope", webapk_info.scope); |
| 48 result->SetString("manifestUrl", webapk_info.manifest_url); |
| 49 result->SetString("manifestStartUrl", webapk_info.manifest_start_url); |
| 50 result->SetString("displayMode", |
| 51 content::WebDisplayModeToString(webapk_info.display)); |
| 52 result->SetString( |
| 53 "orientation", |
| 54 content::WebScreenOrientationLockTypeToString(webapk_info.orientation)); |
| 55 result->SetString("themeColor", |
| 56 ColorUtils::ColorToString(webapk_info.theme_color)); |
| 57 result->SetString("backgroundColor", |
| 58 ColorUtils::ColorToString(webapk_info.background_color)); |
| 40 list.Append(std::move(result)); | 59 list.Append(std::move(result)); |
| 41 } | 60 } |
| 42 | 61 |
| 43 CallJavascriptFunction("returnWebApksInfo", list); | 62 CallJavascriptFunction("returnWebApksInfo", list); |
| 44 } | 63 } |
| OLD | NEW |