Commit b322a223 authored by Eero Häkkinen's avatar Eero Häkkinen Committed by Commit Bot

Rename named UTF-8 decode constructors in TextResourceDecoderOptions

This CL renames CreateAlwaysUseUTF8ForText to CreateUTF8Decode and
CreateAlwaysUseUTF8WithoutBOMForText to CreateUTF8DecodeWithoutBOM in
TextResourceDecoderOptions. This is to make it easier to distinguish
these two named constructors, to match with the spec names and to
shorten the names.

Bug: 796192
Change-Id: Ib3ee204b1e0c81a95ab0ca58f47def892525984e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1893260
Commit-Queue: Eero Häkkinen <eero.hakkinen@intel.com>
Reviewed-by: default avatarHiroshige Hayashizaki <hiroshige@chromium.org>
Reviewed-by: default avatarBen Kelly <wanderview@chromium.org>
Cr-Commit-Position: refs/heads/master@{#711659}
parent 2a641e8a
......@@ -259,8 +259,7 @@ ScriptPromise Body::formData(ScriptState* script_state,
// which does not decode BOM.
BodyBuffer()->StartLoading(
FetchDataLoader::CreateLoaderAsString(
TextResourceDecoderOptions::
CreateAlwaysUseUTF8WithoutBOMForText()),
TextResourceDecoderOptions::CreateUTF8DecodeWithoutBOM()),
MakeGarbageCollected<BodyFormDataConsumer>(resolver),
exception_state);
if (exception_state.HadException()) {
......@@ -307,7 +306,7 @@ ScriptPromise Body::json(ScriptState* script_state,
if (BodyBuffer()) {
BodyBuffer()->StartLoading(
FetchDataLoader::CreateLoaderAsString(
TextResourceDecoderOptions::CreateAlwaysUseUTF8ForText()),
TextResourceDecoderOptions::CreateUTF8Decode()),
MakeGarbageCollected<BodyJsonConsumer>(resolver), exception_state);
if (exception_state.HadException()) {
// Need to resolve the ScriptPromiseResolver to avoid a DCHECK().
......@@ -336,7 +335,7 @@ ScriptPromise Body::text(ScriptState* script_state,
if (BodyBuffer()) {
BodyBuffer()->StartLoading(
FetchDataLoader::CreateLoaderAsString(
TextResourceDecoderOptions::CreateAlwaysUseUTF8ForText()),
TextResourceDecoderOptions::CreateUTF8Decode()),
MakeGarbageCollected<BodyTextConsumer>(resolver), exception_state);
if (exception_state.HadException()) {
// Need to resolve the ScriptPromiseResolver to avoid a DCHECK().
......
......@@ -126,18 +126,16 @@ TEST_F(BodyStreamBufferTest, Tee) {
EXPECT_FALSE(buffer->HasPendingActivity());
checkpoint.Call(0);
new1->StartLoading(
FetchDataLoader::CreateLoaderAsString(
TextResourceDecoderOptions::CreateAlwaysUseUTF8ForText()),
client1, exception_state);
new1->StartLoading(FetchDataLoader::CreateLoaderAsString(
TextResourceDecoderOptions::CreateUTF8Decode()),
client1, exception_state);
checkpoint.Call(1);
test::RunPendingTasks();
checkpoint.Call(2);
new2->StartLoading(
FetchDataLoader::CreateLoaderAsString(
TextResourceDecoderOptions::CreateAlwaysUseUTF8ForText()),
client2, exception_state);
new2->StartLoading(FetchDataLoader::CreateLoaderAsString(
TextResourceDecoderOptions::CreateUTF8Decode()),
client2, exception_state);
checkpoint.Call(3);
test::RunPendingTasks();
checkpoint.Call(4);
......@@ -199,18 +197,16 @@ TEST_F(BodyStreamBufferTest, TeeFromHandleMadeFromStream) {
EXPECT_TRUE(buffer->IsStreamDisturbed(exception_state).value_or(false));
EXPECT_FALSE(buffer->HasPendingActivity());
new1->StartLoading(
FetchDataLoader::CreateLoaderAsString(
TextResourceDecoderOptions::CreateAlwaysUseUTF8ForText()),
client1, exception_state);
new1->StartLoading(FetchDataLoader::CreateLoaderAsString(
TextResourceDecoderOptions::CreateUTF8Decode()),
client1, exception_state);
checkpoint.Call(1);
test::RunPendingTasks();
checkpoint.Call(2);
new2->StartLoading(
FetchDataLoader::CreateLoaderAsString(
TextResourceDecoderOptions::CreateAlwaysUseUTF8ForText()),
client2, exception_state);
new2->StartLoading(FetchDataLoader::CreateLoaderAsString(
TextResourceDecoderOptions::CreateUTF8Decode()),
client2, exception_state);
checkpoint.Call(3);
test::RunPendingTasks();
checkpoint.Call(4);
......@@ -448,10 +444,9 @@ TEST_F(BodyStreamBufferTest, LoadBodyStreamBufferAsString) {
src->Add(Command(Command::kDone));
BodyStreamBuffer* buffer = MakeGarbageCollected<BodyStreamBuffer>(
scope.GetScriptState(), src, nullptr);
buffer->StartLoading(
FetchDataLoader::CreateLoaderAsString(
TextResourceDecoderOptions::CreateAlwaysUseUTF8ForText()),
client, ASSERT_NO_EXCEPTION);
buffer->StartLoading(FetchDataLoader::CreateLoaderAsString(
TextResourceDecoderOptions::CreateUTF8Decode()),
client, ASSERT_NO_EXCEPTION);
EXPECT_TRUE(buffer->IsStreamLocked(ASSERT_NO_EXCEPTION).value_or(false));
EXPECT_TRUE(buffer->IsStreamDisturbed(ASSERT_NO_EXCEPTION).value_or(false));
......@@ -486,10 +481,9 @@ TEST_F(BodyStreamBufferTest, LoadClosedHandle) {
EXPECT_FALSE(buffer->HasPendingActivity());
checkpoint.Call(1);
buffer->StartLoading(
FetchDataLoader::CreateLoaderAsString(
TextResourceDecoderOptions::CreateAlwaysUseUTF8ForText()),
client, ASSERT_NO_EXCEPTION);
buffer->StartLoading(FetchDataLoader::CreateLoaderAsString(
TextResourceDecoderOptions::CreateUTF8Decode()),
client, ASSERT_NO_EXCEPTION);
checkpoint.Call(2);
EXPECT_TRUE(buffer->IsStreamLocked(ASSERT_NO_EXCEPTION).value_or(false));
......@@ -518,10 +512,9 @@ TEST_F(BodyStreamBufferTest, LoadErroredHandle) {
EXPECT_FALSE(buffer->HasPendingActivity());
checkpoint.Call(1);
buffer->StartLoading(
FetchDataLoader::CreateLoaderAsString(
TextResourceDecoderOptions::CreateAlwaysUseUTF8ForText()),
client, ASSERT_NO_EXCEPTION);
buffer->StartLoading(FetchDataLoader::CreateLoaderAsString(
TextResourceDecoderOptions::CreateUTF8Decode()),
client, ASSERT_NO_EXCEPTION);
checkpoint.Call(2);
EXPECT_TRUE(buffer->IsStreamLocked(ASSERT_NO_EXCEPTION).value_or(false));
......@@ -546,10 +539,9 @@ TEST_F(BodyStreamBufferTest, LoaderShouldBeKeptAliveByBodyStreamBuffer) {
src->Add(Command(Command::kDone));
Persistent<BodyStreamBuffer> buffer = MakeGarbageCollected<BodyStreamBuffer>(
scope.GetScriptState(), src, nullptr);
buffer->StartLoading(
FetchDataLoader::CreateLoaderAsString(
TextResourceDecoderOptions::CreateAlwaysUseUTF8ForText()),
client, ASSERT_NO_EXCEPTION);
buffer->StartLoading(FetchDataLoader::CreateLoaderAsString(
TextResourceDecoderOptions::CreateUTF8Decode()),
client, ASSERT_NO_EXCEPTION);
ThreadState::Current()->CollectAllGarbageForTesting();
checkpoint.Call(1);
......
......@@ -399,7 +399,7 @@ class FetchDataLoaderAsFormData final : public FetchDataLoader,
} else {
if (!string_decoder_) {
string_decoder_ = std::make_unique<TextResourceDecoder>(
TextResourceDecoderOptions::CreateAlwaysUseUTF8ForText());
TextResourceDecoderOptions::CreateUTF8Decode());
}
string_builder_.reset(new StringBuilder);
}
......
......@@ -75,8 +75,8 @@ class CORE_EXPORT FetchDataLoader : public GarbageCollected<FetchDataLoader> {
static FetchDataLoader* CreateLoaderAsFormData(
const String& multipart_boundary);
// The text resource decoder options should be created either by
// TextResourceDecoderOptions::CreateAlwaysUseUTF8ForText() or
// TextResourceDecoderOptions::CreateAlwaysUseUTF8WithoutBOMForText().
// TextResourceDecoderOptions::CreateUTF8Decode() or
// TextResourceDecoderOptions::CreateUTF8DecodeWithoutBOM().
static FetchDataLoader* CreateLoaderAsString(
const TextResourceDecoderOptions&);
// The mojo::DataPipe consumer handle is provided via the
......
......@@ -606,7 +606,7 @@ TEST_F(FetchDataLoaderTest, LoadAsString) {
auto* consumer = MakeGarbageCollected<MockBytesConsumer>();
FetchDataLoader* fetch_data_loader = FetchDataLoader::CreateLoaderAsString(
TextResourceDecoderOptions::CreateAlwaysUseUTF8ForText());
TextResourceDecoderOptions::CreateUTF8Decode());
auto* fetch_data_loader_client =
MakeGarbageCollected<MockFetchDataLoaderClient>();
......@@ -646,7 +646,7 @@ TEST_F(FetchDataLoaderTest, LoadAsStringWithNullBytes) {
auto* consumer = MakeGarbageCollected<MockBytesConsumer>();
FetchDataLoader* fetch_data_loader = FetchDataLoader::CreateLoaderAsString(
TextResourceDecoderOptions::CreateAlwaysUseUTF8ForText());
TextResourceDecoderOptions::CreateUTF8Decode());
auto* fetch_data_loader_client =
MakeGarbageCollected<MockFetchDataLoaderClient>();
......@@ -687,7 +687,7 @@ TEST_F(FetchDataLoaderTest, LoadAsStringError) {
auto* consumer = MakeGarbageCollected<MockBytesConsumer>();
FetchDataLoader* fetch_data_loader = FetchDataLoader::CreateLoaderAsString(
TextResourceDecoderOptions::CreateAlwaysUseUTF8ForText());
TextResourceDecoderOptions::CreateUTF8Decode());
auto* fetch_data_loader_client =
MakeGarbageCollected<MockFetchDataLoaderClient>();
......@@ -726,7 +726,7 @@ TEST_F(FetchDataLoaderTest, LoadAsStringCancel) {
auto* consumer = MakeGarbageCollected<MockBytesConsumer>();
FetchDataLoader* fetch_data_loader = FetchDataLoader::CreateLoaderAsString(
TextResourceDecoderOptions::CreateAlwaysUseUTF8ForText());
TextResourceDecoderOptions::CreateUTF8Decode());
auto* fetch_data_loader_client =
MakeGarbageCollected<MockFetchDataLoaderClient>();
......
......@@ -83,11 +83,11 @@ void CheckResponseStream(ScriptState* script_state,
response->InternalBodyBuffer()->StartLoading(
FetchDataLoader::CreateLoaderAsString(
TextResourceDecoderOptions::CreateAlwaysUseUTF8ForText()),
TextResourceDecoderOptions::CreateUTF8Decode()),
client1, ASSERT_NO_EXCEPTION);
cloned_response->InternalBodyBuffer()->StartLoading(
FetchDataLoader::CreateLoaderAsString(
TextResourceDecoderOptions::CreateAlwaysUseUTF8ForText()),
TextResourceDecoderOptions::CreateUTF8Decode()),
client2, ASSERT_NO_EXCEPTION);
blink::test::RunPendingTasks();
}
......@@ -188,11 +188,11 @@ TEST(ServiceWorkerResponseTest, BodyStreamBufferCloneError) {
response->InternalBodyBuffer()->StartLoading(
FetchDataLoader::CreateLoaderAsString(
TextResourceDecoderOptions::CreateAlwaysUseUTF8ForText()),
TextResourceDecoderOptions::CreateUTF8Decode()),
client1, ASSERT_NO_EXCEPTION);
cloned_response->InternalBodyBuffer()->StartLoading(
FetchDataLoader::CreateLoaderAsString(
TextResourceDecoderOptions::CreateAlwaysUseUTF8ForText()),
TextResourceDecoderOptions::CreateUTF8Decode()),
client2, ASSERT_NO_EXCEPTION);
blink::test::RunPendingTasks();
}
......
......@@ -90,8 +90,7 @@ Resource* PreloadRequest::Start(Document* document) {
if (script_type_ == mojom::ScriptType::kModule) {
DCHECK_EQ(resource_type_, ResourceType::kScript);
params.SetDecoderOptions(
TextResourceDecoderOptions::CreateAlwaysUseUTF8ForText());
params.SetDecoderOptions(TextResourceDecoderOptions::CreateUTF8Decode());
} else if (resource_type_ == ResourceType::kScript ||
resource_type_ == ResourceType::kCSSStyleSheet ||
resource_type_ == ResourceType::kImportResource) {
......
......@@ -35,7 +35,7 @@ class TextResourceDecoderForFuzzing : public TextResourceDecoder {
FuzzedEncoding(fuzzed_data));
case TextResourceDecoderOptions::kAlwaysUseUTF8ForText:
return TextResourceDecoderOptions::CreateAlwaysUseUTF8ForText();
return TextResourceDecoderOptions::CreateUTF8Decode();
}
}
......
......@@ -8,10 +8,10 @@
namespace blink {
TEST(TextResourceDecoderTest, AlwaysUseUTF8) {
TEST(TextResourceDecoderTest, UTF8Decode) {
std::unique_ptr<TextResourceDecoder> decoder =
std::make_unique<TextResourceDecoder>(
TextResourceDecoderOptions::CreateAlwaysUseUTF8ForText());
TextResourceDecoderOptions::CreateUTF8Decode());
const unsigned char kFooUTF8WithBOM[] = {0xef, 0xbb, 0xbf, 0x66, 0x6f, 0x6f};
WTF::String decoded = decoder->Decode(
reinterpret_cast<const char*>(kFooUTF8WithBOM), sizeof(kFooUTF8WithBOM));
......@@ -20,10 +20,10 @@ TEST(TextResourceDecoderTest, AlwaysUseUTF8) {
EXPECT_EQ("foo", decoded);
}
TEST(TextResourceDecoderTest, AlwaysUseUTF8WithoutBOM) {
TEST(TextResourceDecoderTest, UTF8DecodeWithoutBOM) {
std::unique_ptr<TextResourceDecoder> decoder =
std::make_unique<TextResourceDecoder>(
TextResourceDecoderOptions::CreateAlwaysUseUTF8WithoutBOMForText());
TextResourceDecoderOptions::CreateUTF8DecodeWithoutBOM());
const unsigned char kFooUTF8WithBOM[] = {0xef, 0xbb, 0xbf, 0x66, 0x6f, 0x6f};
WTF::String decoded = decoder->Decode(
reinterpret_cast<const char*>(kFooUTF8WithBOM), sizeof(kFooUTF8WithBOM));
......
......@@ -204,7 +204,7 @@ void ModuleScriptLoader::FetchInternal(
// <spec step="12.1">Let source text be the result of UTF-8 decoding
// response's body.</spec>
fetch_params.SetDecoderOptions(
TextResourceDecoderOptions::CreateAlwaysUseUTF8ForText());
TextResourceDecoderOptions::CreateUTF8Decode());
// <spec step="8">If the caller specified custom steps to perform the fetch,
// perform them on request, setting the is top-level flag if the top-level
......
......@@ -477,7 +477,7 @@ class Cache::CodeCacheHandleCallbackForPut final
// See crbug.com/743311.
std::unique_ptr<TextResourceDecoder> text_decoder =
std::make_unique<TextResourceDecoder>(
TextResourceDecoderOptions::CreateAlwaysUseUTF8ForText());
TextResourceDecoderOptions::CreateUTF8Decode());
return V8CodeCache::GenerateFullCodeCache(
script_state_,
......
......@@ -16,15 +16,14 @@ TextResourceDecoderOptions::TextResourceDecoderOptions(
nullptr,
KURL()) {}
TextResourceDecoderOptions
TextResourceDecoderOptions::CreateAlwaysUseUTF8ForText() {
TextResourceDecoderOptions TextResourceDecoderOptions::CreateUTF8Decode() {
return TextResourceDecoderOptions(kAlwaysUseUTF8ForText, kPlainTextContent,
UTF8Encoding(), nullptr, NullURL());
}
TextResourceDecoderOptions
TextResourceDecoderOptions::CreateAlwaysUseUTF8WithoutBOMForText() {
TextResourceDecoderOptions options = CreateAlwaysUseUTF8ForText();
TextResourceDecoderOptions::CreateUTF8DecodeWithoutBOM() {
TextResourceDecoderOptions options = CreateUTF8Decode();
options.no_bom_decoding_ = true;
return options;
}
......
......@@ -38,11 +38,11 @@ class PLATFORM_EXPORT TextResourceDecoderOptions final {
// Corresponds to utf-8 decode in Encoding spec:
// https://encoding.spec.whatwg.org/#utf-8-decode.
static TextResourceDecoderOptions CreateAlwaysUseUTF8ForText();
static TextResourceDecoderOptions CreateUTF8Decode();
// Corresponds to utf-8 decode without BOM in Encoding spec:
// https://encoding.spec.whatwg.org/#utf-8-decode-without-bom.
static TextResourceDecoderOptions CreateAlwaysUseUTF8WithoutBOMForText();
static TextResourceDecoderOptions CreateUTF8DecodeWithoutBOM();
static TextResourceDecoderOptions CreateWithAutoDetection(
ContentType,
......
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