Commit 48d788fb authored by Lei Zhang's avatar Lei Zhang Committed by Commit Bot

Avoid UTF8 to UTF16 to UTF8 conversions with base::Value.

There are a couple places that starts with UTF8 data and converts them
to UTF16 before passing them to base::Value. base::Value turns around
and converts it back to UTF8.

Fix some nits along the way.

Change-Id: I10ad741de22aecc04b37fa633ab0033a26acc688
Reviewed-on: https://chromium-review.googlesource.com/1188033Reviewed-by: default avatarJonathan Ross <jonross@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#585848}
parent 2b9f6363
......@@ -22,7 +22,6 @@
#include "base/single_thread_task_runner.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/thread_task_runner_handle.h"
#include "build/build_config.h"
#include "components/grit/components_resources.h"
......@@ -634,9 +633,8 @@ void PrintRenderFrameHelper::PrintHeaderAndFooter(
blink::WebWidgetClient web_widget_client;
blink::WebFrameWidget::Create(&web_widget_client, frame);
base::Value html(base::UTF8ToUTF16(
ui::ResourceBundle::GetSharedInstance().GetRawDataResource(
IDR_PRINT_HEADER_FOOTER_TEMPLATE_PAGE)));
base::Value html(ui::ResourceBundle::GetSharedInstance().GetRawDataResource(
IDR_PRINT_HEADER_FOOTER_TEMPLATE_PAGE));
// Load page with script to avoid async operations.
ExecuteScript(frame, kPageLoadScriptFormat, html);
......@@ -1850,7 +1848,6 @@ bool PrintRenderFrameHelper::UpdatePrintSettings(
}
bool source_is_html = !PrintingNodeOrPdfFrame(frame, node);
if (!source_is_html) {
modified_job_settings.MergeDictionary(job_settings);
modified_job_settings.SetBoolean(kSettingHeaderFooterEnabled, false);
......@@ -2408,7 +2405,7 @@ void PrintRenderFrameHelper::SetPrintPagesParams(
settings.params.document_cookie));
}
PrintRenderFrameHelper::ScriptingThrottler::ScriptingThrottler() : count_(0) {}
PrintRenderFrameHelper::ScriptingThrottler::ScriptingThrottler() = default;
bool PrintRenderFrameHelper::ScriptingThrottler::IsAllowed(
blink::WebLocalFrame* frame) {
......@@ -2442,7 +2439,7 @@ bool PrintRenderFrameHelper::ScriptingThrottler::IsAllowed(
}
blink::WebString message(
blink::WebString::FromUTF8("Ignoring too frequent calls to print()."));
blink::WebString::FromASCII("Ignoring too frequent calls to print()."));
frame->AddMessageToConsole(blink::WebConsoleMessage(
blink::WebConsoleMessage::kLevelWarning, message));
return false;
......
......@@ -60,8 +60,8 @@ class ServiceTestClient : public service_manager::test::ServiceTestClient,
const std::string& name,
service_manager::mojom::PIDReceiverPtr pid_receiver) override {
if (name == prefs::mojom::kServiceName) {
pref_service_context_.reset(new service_manager::ServiceContext(
service_factory_.Run(), std::move(request)));
pref_service_context_ = std::make_unique<service_manager::ServiceContext>(
service_factory_.Run(), std::move(request));
} else if (name == "prefs_unittest_helper") {
test_helper_service_context_ =
std::make_unique<service_manager::ServiceContext>(
......@@ -95,8 +95,8 @@ class PrefServiceFactoryTest : public service_manager::test::ServiceTest {
protected:
void SetUp() override {
above_user_prefs_pref_store_ = new ValueMapPrefStore();
below_user_prefs_pref_store_ = new ValueMapPrefStore();
above_user_prefs_pref_store_ = base::MakeRefCounted<ValueMapPrefStore>();
below_user_prefs_pref_store_ = base::MakeRefCounted<ValueMapPrefStore>();
auto user_prefs = base::MakeRefCounted<InMemoryPrefStore>();
PrefServiceFactory factory;
service_factory_ = std::make_unique<InProcessPrefServiceFactory>();
......@@ -442,8 +442,7 @@ TEST_F(PrefServiceFactoryTest, MultipleClients_SubPrefUpdates_Basic) {
EXPECT_EQ(base::ASCIIToUTF16("hello"), out);
},
[](ScopedDictionaryPrefUpdate* update) {
(*update)->SetKey("key.for.string16",
base::Value(base::ASCIIToUTF16("prefs!")));
(*update)->SetKey("key.for.string16", base::Value("prefs!"));
base::string16 out;
ASSERT_TRUE(
(*update)->GetStringWithoutPathExpansion("key.for.string16", &out));
......
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