Commit 69246eaa authored by Jan Wilken Dörrie's avatar Jan Wilken Dörrie Committed by Commit Bot

[WebUI] Add PluralStringHandler and PluralStringProxy

This change registers the PluralStringHandler as a MessageHandler for
the SettingsUI and adds PluralStringProxy as a thin JavaScript wrapper
around it.

Bug: 1047726
Change-Id: I4c53eed726711635adb29e63435dd9da697d0635
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2090425Reviewed-by: default avatarEsmael Elmoslimany <aee@chromium.org>
Commit-Queue: Jan Wilken Dörrie <jdoerrie@chromium.org>
Cr-Commit-Position: refs/heads/master@{#747854}
parent ac7a6b27
......@@ -137,6 +137,7 @@ js_type_check("settings_resources") {
":metrics_browser_proxy",
":open_window_proxy",
":page_visibility",
":plural_string_proxy",
":route",
":router",
":search_settings",
......@@ -173,6 +174,10 @@ js_library("open_window_proxy") {
deps = [ "//ui/webui/resources/js:cr" ]
}
js_library("plural_string_proxy") {
deps = [ "//ui/webui/resources/js:cr" ]
}
js_library("route") {
deps = [
":page_visibility",
......@@ -474,6 +479,7 @@ js_modulizer("modulize") {
"lifetime_browser_proxy.js",
"metrics_browser_proxy.js",
"open_window_proxy.js",
"plural_string_proxy.js",
"page_visibility.js",
"route.js",
"router.js",
......
<link rel="import" href="chrome://resources/html/cr.html">
<script src="plural_string_proxy.js"></script>
// Copyright 2020 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.
/**
* @fileoverview A helper object used to get a pluralized string.
*/
cr.define('settings', function() {
/** @interface */
class PluralStringProxy {
/**
* Obtains a pluralized string for |messageName| with |itemCount| items.
* @param {!string} messageName The name of the message.
* @param {!number} itemCount The number of items.
* @return {!Promise<string>} Promise resolved with the appropriate plural
* string for |messageName| with |itemCount| items.
*/
getPluralString(messageName, itemCount) {}
}
/** @implements {settings.PluralStringProxy} */
class PluralStringProxyImpl {
/** @override */
getPluralString(messageName, itemCount) {
return cr.sendWithPromise('getPluralString', messageName, itemCount);
}
}
cr.addSingletonGetter(PluralStringProxyImpl);
// #cr_define_end
return {PluralStringProxy, PluralStringProxyImpl};
});
......@@ -808,6 +808,12 @@
<structure name="IDR_SETTINGS_OPEN_WINDOW_PROXY_JS"
file="open_window_proxy.js"
type="chrome_html" />
<structure name="IDR_SETTINGS_PLURAL_STRING_PROXY_HTML"
file="plural_string_proxy.html"
type="chrome_html" />
<structure name="IDR_SETTINGS_PLURAL_STRING_PROXY_JS"
file="plural_string_proxy.js"
type="chrome_html" />
<structure name="IDR_SETTINGS_PAGE_VISIBILITY_HTML"
file="page_visibility.html"
type="chrome_html" />
......
......@@ -26,6 +26,7 @@
#include "chrome/browser/ui/webui/favicon_source.h"
#include "chrome/browser/ui/webui/managed_ui_handler.h"
#include "chrome/browser/ui/webui/metrics_handler.h"
#include "chrome/browser/ui/webui/plural_string_handler.h"
#include "chrome/browser/ui/webui/settings/about_handler.h"
#include "chrome/browser/ui/webui/settings/accessibility_main_handler.h"
#include "chrome/browser/ui/webui/settings/appearance_handler.h"
......@@ -303,6 +304,9 @@ SettingsUI::SettingsUI(content::WebUI* web_ui)
AddSettingsPageUIHandler(
base::WrapUnique(ResetSettingsHandler::Create(html_source, profile)));
// Add a handler to provide pluralized strings.
web_ui->AddMessageHandler(std::make_unique<PluralStringHandler>());
// Add the metrics handler to write uma stats.
web_ui->AddMessageHandler(std::make_unique<MetricsHandler>());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment