Commit 31004dd3 authored by Yuheng Huang's avatar Yuheng Huang Committed by Commit Bot

WebUI: Add AddDouble() to WebUIDataSource

We need to pass in some floating point feature flags
to WebUI. Adding this method to make it possible.

Bug: 1099917
Change-Id: I1d9cd115c2234d66239fe555ed89aee3314df779
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2426608Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Reviewed-by: default avatardpapad <dpapad@chromium.org>
Commit-Queue: Yuheng Huang <yuhengh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#809918}
parent 7e74bc72
...@@ -164,6 +164,10 @@ void WebUIDataSourceImpl::AddInteger(base::StringPiece name, int32_t value) { ...@@ -164,6 +164,10 @@ void WebUIDataSourceImpl::AddInteger(base::StringPiece name, int32_t value) {
localized_strings_.SetInteger(name, value); localized_strings_.SetInteger(name, value);
} }
void WebUIDataSourceImpl::AddDouble(base::StringPiece name, double value) {
localized_strings_.SetDouble(name, value);
}
void WebUIDataSourceImpl::UseStringsJs() { void WebUIDataSourceImpl::UseStringsJs() {
use_strings_js_ = true; use_strings_js_ = true;
} }
......
...@@ -37,6 +37,7 @@ class CONTENT_EXPORT WebUIDataSourceImpl : public URLDataSourceImpl, ...@@ -37,6 +37,7 @@ class CONTENT_EXPORT WebUIDataSourceImpl : public URLDataSourceImpl,
const base::DictionaryValue& localized_strings) override; const base::DictionaryValue& localized_strings) override;
void AddBoolean(base::StringPiece name, bool value) override; void AddBoolean(base::StringPiece name, bool value) override;
void AddInteger(base::StringPiece name, int32_t value) override; void AddInteger(base::StringPiece name, int32_t value) override;
void AddDouble(base::StringPiece name, double value) override;
void UseStringsJs() override; void UseStringsJs() override;
void AddResourcePath(base::StringPiece path, int resource_id) override; void AddResourcePath(base::StringPiece path, int resource_id) override;
void SetDefaultResource(int resource_id) override; void SetDefaultResource(int resource_id) override;
......
...@@ -119,6 +119,7 @@ void SomeValuesCallback(scoped_refptr<base::RefCountedMemory> data) { ...@@ -119,6 +119,7 @@ void SomeValuesCallback(scoped_refptr<base::RefCountedMemory> data) {
EXPECT_NE(result.find("\"flag\":true"), std::string::npos); EXPECT_NE(result.find("\"flag\":true"), std::string::npos);
EXPECT_NE(result.find("\"counter\":10"), std::string::npos); EXPECT_NE(result.find("\"counter\":10"), std::string::npos);
EXPECT_NE(result.find("\"debt\":-456"), std::string::npos); EXPECT_NE(result.find("\"debt\":-456"), std::string::npos);
EXPECT_NE(result.find("\"threshold\":0.55"), std::string::npos);
EXPECT_NE(result.find("\"planet\":\"pluto\""), std::string::npos); EXPECT_NE(result.find("\"planet\":\"pluto\""), std::string::npos);
EXPECT_NE(result.find("\"button\":\"foo\""), std::string::npos); EXPECT_NE(result.find("\"button\":\"foo\""), std::string::npos);
} }
...@@ -128,6 +129,7 @@ TEST_F(WebUIDataSourceTest, SomeValues) { ...@@ -128,6 +129,7 @@ TEST_F(WebUIDataSourceTest, SomeValues) {
source()->AddBoolean("flag", true); source()->AddBoolean("flag", true);
source()->AddInteger("counter", 10); source()->AddInteger("counter", 10);
source()->AddInteger("debt", -456); source()->AddInteger("debt", -456);
source()->AddDouble("threshold", 0.55);
source()->AddString("planet", base::ASCIIToUTF16("pluto")); source()->AddString("planet", base::ASCIIToUTF16("pluto"));
source()->AddLocalizedString("button", kDummyStringId); source()->AddLocalizedString("button", kDummyStringId);
StartDataRequest("strings.js", base::BindOnce(&SomeValuesCallback)); StartDataRequest("strings.js", base::BindOnce(&SomeValuesCallback));
......
...@@ -69,6 +69,9 @@ class WebUIDataSource { ...@@ -69,6 +69,9 @@ class WebUIDataSource {
// MAX_SAFE_INTEGER in /v8/src/globals.h. // MAX_SAFE_INTEGER in /v8/src/globals.h.
virtual void AddInteger(base::StringPiece name, int32_t value) = 0; virtual void AddInteger(base::StringPiece name, int32_t value) = 0;
// Adds a double keyed to its name to our dictionary.
virtual void AddDouble(base::StringPiece name, double value) = 0;
// Call this to enable a virtual "strings.js" (or "strings.m.js" for modules) // Call this to enable a virtual "strings.js" (or "strings.m.js" for modules)
// URL that provides translations and dynamic data when requested. // URL that provides translations and dynamic data when requested.
virtual void UseStringsJs() = 0; virtual void UseStringsJs() = 0;
......
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