OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/ui/webui/plural_string_handler.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "base/bind_helpers.h" | |
9 #include "base/values.h" | |
10 #include "content/public/browser/web_ui.h" | |
11 #include "ui/base/l10n/l10n_util.h" | |
12 | |
13 PluralStringHandler::PluralStringHandler() {} | |
14 | |
15 PluralStringHandler::~PluralStringHandler() {} | |
16 | |
17 void PluralStringHandler::RegisterMessages() { | |
18 web_ui()->RegisterMessageCallback( | |
19 "getPluralString", base::Bind(&PluralStringHandler::HandleGetPluralString, | |
20 base::Unretained(this))); | |
21 } | |
22 | |
23 void PluralStringHandler::AddLocalizedString(const std::string& name, int id) { | |
24 name_to_id_[name] = id; | |
25 } | |
26 | |
27 void PluralStringHandler::HandleGetPluralString(const base::ListValue* args) { | |
28 AllowJavascript(); | |
29 CHECK_EQ(3U, args->GetSize()); | |
30 const base::Value* callback_id; | |
31 CHECK(args->Get(0, &callback_id)); | |
32 | |
33 std::string message_name; | |
34 CHECK(args->GetString(1, &message_name)); | |
35 | |
36 int count; | |
37 CHECK(args->GetInteger(2, &count)); | |
38 | |
39 auto message_id_it = name_to_id_.find(message_name); | |
40 DCHECK(name_to_id_.end() != message_id_it); | |
tsergeant
2017/06/01 08:25:00
Should this be a CHECK instead of a DCHECK? What g
calamity
2017/06/02 05:34:22
Done.
| |
41 | |
42 ResolveJavascriptCallback(*callback_id, | |
43 base::Value(l10n_util::GetPluralStringFUTF8( | |
44 message_id_it->second, count))); | |
45 } | |
OLD | NEW |