Chromium Code Reviews| 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" |
| 10 #include "content/public/browser/web_ui.h" | 13 #include "content/public/browser/web_ui.h" |
| 14 #include "content/public/common/manifest_util.h" | |
| 15 #include "ui/gfx/color_utils.h" | |
| 16 | |
| 17 namespace { | |
| 18 // Converts a color from the format documented in content::Manifest to a | |
| 19 // rgba() CSS string. | |
| 20 std::string ColorToString(int64_t color) { | |
| 21 if (color == content::Manifest::kInvalidOrMissingColor) { | |
|
Dan Beam
2017/02/28 17:40:52
no curlies
gonzalon
2017/02/28 17:56:50
Done.
| |
| 22 return ""; | |
|
Dan Beam
2017/02/28 17:40:52
return std::string();
gonzalon
2017/02/28 17:56:50
Done.
| |
| 23 } | |
| 24 return color_utils::SkColorToRGBAString(reinterpret_cast<uint32_t&>(color)); | |
| 25 } | |
| 26 } // namespace | |
| 11 | 27 |
| 12 WebApksHandler::WebApksHandler() : weak_ptr_factory_(this) {} | 28 WebApksHandler::WebApksHandler() : weak_ptr_factory_(this) {} |
| 13 | 29 |
| 14 WebApksHandler::~WebApksHandler() {} | 30 WebApksHandler::~WebApksHandler() {} |
| 15 | 31 |
| 16 void WebApksHandler::RegisterMessages() { | 32 void WebApksHandler::RegisterMessages() { |
| 17 web_ui()->RegisterMessageCallback( | 33 web_ui()->RegisterMessageCallback( |
| 18 "requestWebApksInfo", | 34 "requestWebApksInfo", |
| 19 base::Bind(&WebApksHandler::HandleRequestWebApksInfo, | 35 base::Bind(&WebApksHandler::HandleRequestWebApksInfo, |
| 20 base::Unretained(this))); | 36 base::Unretained(this))); |
| 21 } | 37 } |
| 22 | 38 |
| 23 void WebApksHandler::HandleRequestWebApksInfo(const base::ListValue* args) { | 39 void WebApksHandler::HandleRequestWebApksInfo(const base::ListValue* args) { |
| 24 AllowJavascript(); | 40 AllowJavascript(); |
| 25 ShortcutHelper::RetrieveWebApks(base::Bind( | 41 ShortcutHelper::RetrieveWebApks(base::Bind( |
| 26 &WebApksHandler::OnWebApkInfoRetrieved, weak_ptr_factory_.GetWeakPtr())); | 42 &WebApksHandler::OnWebApkInfoRetrieved, weak_ptr_factory_.GetWeakPtr())); |
| 27 } | 43 } |
| 28 | 44 |
| 29 void WebApksHandler::OnWebApkInfoRetrieved( | 45 void WebApksHandler::OnWebApkInfoRetrieved( |
| 30 const std::vector<WebApkInfo>& webapks_list) { | 46 const std::vector<WebApkInfo>& webapks_list) { |
| 31 if (!IsJavascriptAllowed()) | 47 if (!IsJavascriptAllowed()) |
| 32 return; | 48 return; |
| 33 base::ListValue list; | 49 base::ListValue list; |
| 34 for (const auto& webapk_info : webapks_list) { | 50 for (const auto& webapk_info : webapks_list) { |
| 35 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue()); | 51 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue()); |
| 52 result->SetString("name", webapk_info.name); | |
| 36 result->SetString("shortName", webapk_info.short_name); | 53 result->SetString("shortName", webapk_info.short_name); |
| 37 result->SetString("packageName", webapk_info.package_name); | 54 result->SetString("packageName", webapk_info.package_name); |
| 38 result->SetInteger("shellApkVersion", webapk_info.shell_apk_version); | 55 result->SetInteger("shellApkVersion", webapk_info.shell_apk_version); |
| 39 result->SetInteger("versionCode", webapk_info.version_code); | 56 result->SetInteger("versionCode", webapk_info.version_code); |
| 57 result->SetString("uri", webapk_info.uri); | |
| 58 result->SetString("scope", webapk_info.scope); | |
| 59 result->SetString("manifestUrl", webapk_info.manifest_url); | |
| 60 result->SetString("manifestStartUrl", webapk_info.manifest_start_url); | |
| 61 result->SetString("displayMode", | |
| 62 content::WebDisplayModeToString(webapk_info.display)); | |
| 63 result->SetString( | |
| 64 "orientation", | |
| 65 content::WebScreenOrientationLockTypeToString(webapk_info.orientation)); | |
| 66 result->SetString("themeColor", ColorToString(webapk_info.theme_color)); | |
| 67 result->SetString("backgroundColor", | |
| 68 ColorToString(webapk_info.background_color)); | |
| 40 list.Append(std::move(result)); | 69 list.Append(std::move(result)); |
| 41 } | 70 } |
| 42 | 71 |
| 43 CallJavascriptFunction("returnWebApksInfo", list); | 72 CallJavascriptFunction("returnWebApksInfo", list); |
| 44 } | 73 } |
| OLD | NEW |