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

Unified Diff: chrome/browser/ui/webui/plural_string_handler.cc

Issue 2898303004: [MD Bookmarks] Add toasts. (Closed)
Patch Set: fix nits Created 3 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/plural_string_handler.cc
diff --git a/chrome/browser/ui/webui/plural_string_handler.cc b/chrome/browser/ui/webui/plural_string_handler.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4693d198562ebfba36344b4dfd828c09f7220147
--- /dev/null
+++ b/chrome/browser/ui/webui/plural_string_handler.cc
@@ -0,0 +1,45 @@
+// Copyright 2017 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.
+
+#include "chrome/browser/ui/webui/plural_string_handler.h"
+
+#include "base/bind.h"
+#include "base/bind_helpers.h"
+#include "base/values.h"
+#include "content/public/browser/web_ui.h"
+#include "ui/base/l10n/l10n_util.h"
+
+PluralStringHandler::PluralStringHandler() {}
+
+PluralStringHandler::~PluralStringHandler() {}
+
+void PluralStringHandler::RegisterMessages() {
+ web_ui()->RegisterMessageCallback(
+ "getPluralString", base::Bind(&PluralStringHandler::HandleGetPluralString,
+ base::Unretained(this)));
+}
+
+void PluralStringHandler::AddLocalizedString(const std::string& name, int id) {
+ name_to_id_[name] = id;
+}
+
+void PluralStringHandler::HandleGetPluralString(const base::ListValue* args) {
+ AllowJavascript();
+ CHECK_EQ(3U, args->GetSize());
+ const base::Value* callback_id;
+ CHECK(args->Get(0, &callback_id));
+
+ std::string message_name;
+ CHECK(args->GetString(1, &message_name));
+
+ int count;
+ CHECK(args->GetInteger(2, &count));
+
+ auto message_id_it = name_to_id_.find(message_name);
+ CHECK(name_to_id_.end() != message_id_it);
+
+ ResolveJavascriptCallback(*callback_id,
+ base::Value(l10n_util::GetPluralStringFUTF8(
+ message_id_it->second, count)));
+}
« no previous file with comments | « chrome/browser/ui/webui/plural_string_handler.h ('k') | chrome/test/data/webui/md_bookmarks/command_manager_test.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698