source: webkit/trunk/Source/WebCore/fileapi/BlobBuilder.cpp

Last change on this file was 286772, checked in by [email protected], 3 years ago

Move TextCodec files from WebCore/platform/text to WebCore/PAL/text
https://bugs.webkit.org/show_bug.cgi?id=233683

Reviewed by Yusuke Suzuki.

Source/WebCore:

This is a purely mechanical move. The TextCodec files don't have any dependencies
except for ICU, so they're good candidates to move.

They do have a thread-local cache, so I split ThreadGlobalData into a PAL part and
a WebCore part.

No new tests because there is no behavior change.

  • Headers.cmake:
  • Modules/encryptedmedia/legacy/LegacyCDMSessionClearKey.cpp:

(WebCore::CDMSessionClearKey::generateKeyRequest):

  • Modules/fetch/FetchBody.cpp:

(WebCore::FetchBody::consumeAsStream):
(WebCore::FetchBody::consumeText):
(WebCore::FetchBody::bodyAsFormData const):
(WebCore::FetchBody::take):

  • Modules/fetch/FetchBodyConsumer.cpp:

(WebCore::FetchBodyConsumer::packageFormData):

  • Sources.txt:
  • SourcesCocoa.txt:
  • WebCore.xcodeproj/project.pbxproj:
  • accessibility/atk/WebKitAccessibleInterfaceText.cpp:
  • bindings/js/ScriptController.cpp:

(WebCore::ScriptController::executeJavaScriptURL):

  • css/parser/CSSParserContext.cpp:

(WebCore::CSSParserContext::completeURL const):

  • css/parser/CSSParserContext.h:
  • dom/Document.cpp:

(WebCore::Document::characterSetWithUTF8Fallback const):
(WebCore::Document::defaultCharsetForLegacyBindings const):

  • dom/Document.h:
  • dom/DocumentInlines.h:

(WebCore::Document::textEncoding const):

  • dom/TextDecoder.cpp:
  • dom/TextDecoder.h:
  • fileapi/BlobBuilder.cpp:

(WebCore::BlobBuilder::append):

  • fileapi/FileReaderLoader.cpp:

(WebCore::FileReaderLoader::convertToText):
(WebCore::FileReaderLoader::setEncoding):

  • fileapi/FileReaderLoader.h:
  • html/DOMFormData.cpp:

(WebCore::DOMFormData::DOMFormData):
(WebCore::DOMFormData::create):

  • html/DOMFormData.h:

(WebCore::DOMFormData::encoding const):

  • html/HTMLLinkElement.cpp:

(WebCore::HTMLLinkElement::process):

  • html/ImageDocument.cpp:

(WebCore::ImageDocument::finishedParsing):

  • html/MediaFragmentURIParser.cpp:

(WebCore::MediaFragmentURIParser::parseFragments):

  • html/parser/HTMLMetaCharsetParser.cpp:

(WebCore::HTMLMetaCharsetParser::HTMLMetaCharsetParser):
(WebCore::HTMLMetaCharsetParser::encodingFromMetaAttributes):

  • html/parser/HTMLMetaCharsetParser.h:

(WebCore::HTMLMetaCharsetParser::encoding):

  • html/track/WebVTTParser.cpp:

(WebCore::WebVTTParser::WebVTTParser):

  • inspector/agents/InspectorDOMAgent.cpp:

(WebCore::computeContentSecurityPolicySHA256Hash):

  • inspector/agents/InspectorNetworkAgent.cpp:
  • inspector/agents/InspectorPageAgent.cpp:

(WebCore::decodeBuffer):

  • loader/FormSubmission.cpp:

(WebCore::appendMailtoPostFormDataToURL):
(WebCore::encodingFromAcceptCharset):
(WebCore::FormSubmission::create):

  • loader/TextResourceDecoder.cpp:

(WebCore::findTextEncoding):
(WebCore::TextResourceDecoder::defaultEncoding):
(WebCore::TextResourceDecoder::TextResourceDecoder):
(WebCore::TextResourceDecoder::create):
(WebCore::TextResourceDecoder::setEncoding):
(WebCore::TextResourceDecoder::checkForBOM):
(WebCore::TextResourceDecoder::checkForHeadCharset):
(WebCore::TextResourceDecoder::decode):
(WebCore::TextResourceDecoder::flush):
(WebCore::TextResourceDecoder::encodingForURLParsing):

  • loader/TextResourceDecoder.h:

(WebCore::TextResourceDecoder::create):
(WebCore::TextResourceDecoder::encoding const):

  • loader/cache/CachedApplicationManifest.cpp:

(WebCore::CachedApplicationManifest::CachedApplicationManifest):

  • loader/cache/CachedScript.cpp:

(WebCore::CachedScript::script):

  • page/FrameView.cpp:

(WebCore::FrameView::scrollToFragment):

  • page/Page.cpp:

(WebCore::Page::userStyleSheetLocationChanged):

  • page/PageSerializer.cpp:

(WebCore::PageSerializer::serializeFrame):
(WebCore::PageSerializer::serializeCSSStyleSheet):

  • page/SecurityOrigin.cpp:

(WebCore::SecurityOrigin::extractInnerURL):
(WebCore::SecurityOrigin::create):

  • page/csp/ContentSecurityPolicy.cpp:

(WebCore::ContentSecurityPolicy::findHashOfContentInPolicies const):

  • page/csp/ContentSecurityPolicy.h:
  • page/csp/ContentSecurityPolicySource.cpp:

(WebCore::ContentSecurityPolicySource::pathMatches const):

  • page/csp/ContentSecurityPolicySourceList.cpp:

(WebCore::ContentSecurityPolicySourceList::parsePath):

  • platform/ThreadGlobalData.cpp:

(WebCore::ThreadGlobalData::ThreadGlobalData):
(WebCore::ThreadGlobalData::destroy):
(PAL::threadGlobalData):

  • platform/ThreadGlobalData.h:

(WebCore::ThreadGlobalData::threadTimers):
(WebCore::ThreadGlobalData::ThreadGlobalData::cachedResourceRequestInitiators): Deleted.
(WebCore::ThreadGlobalData::ThreadGlobalData::eventNames): Deleted.
(WebCore::ThreadGlobalData::ThreadGlobalData::qualifiedNameCache): Deleted.
(WebCore::ThreadGlobalData::ThreadGlobalData::mimeTypeRegistryThreadGlobalData): Deleted.
(WebCore::ThreadGlobalData::ThreadGlobalData::threadTimers): Deleted.
(WebCore::ThreadGlobalData::ThreadGlobalData::cachedConverterICU): Deleted.
(WebCore::ThreadGlobalData::ThreadGlobalData::currentState const): Deleted.
(WebCore::ThreadGlobalData::ThreadGlobalData::setCurrentState): Deleted.
(WebCore::ThreadGlobalData::ThreadGlobalData::isInRemoveAllEventListeners const): Deleted.
(WebCore::ThreadGlobalData::ThreadGlobalData::setIsInRemoveAllEventListeners): Deleted.
(WebCore::ThreadGlobalData::ThreadGlobalData::fontCache): Deleted.
(WebCore::ThreadGlobalData::ThreadGlobalData::fontCacheIfNotDestroyed): Deleted.

  • platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:

(WebCore::MediaPlayerPrivateAVFoundationObjC::shouldWaitForLoadingOfResource):

  • platform/gtk/PlatformKeyboardEventGtk.cpp:
  • platform/network/DataURLDecoder.cpp:

(WebCore::DataURLDecoder::decodeBase64):
(WebCore::DataURLDecoder::decodeEscaped):

  • platform/network/FormData.cpp:

(WebCore::normalizeStringData):
(WebCore::FormData::appendMultiPartFileValue):
(WebCore::FormData::appendMultiPartStringValue):
(WebCore::FormData::flattenToString const):

  • platform/network/FormData.h:
  • platform/network/FormDataBuilder.cpp:

(WebCore::FormDataBuilder::addFilenameToMultiPartHeader):

  • platform/network/FormDataBuilder.h:
  • platform/network/curl/ResourceHandleCurl.cpp:

(WebCore::ResourceHandle::handleDataURL):

  • platform/network/soup/ResourceHandleSoup.cpp:
  • platform/win/ClipboardUtilitiesWin.cpp:

(WebCore::getFullCFHTML):
(WebCore::getUtf8Data):

  • platform/win/DragDataWin.cpp:
  • platform/win/PasteboardWin.cpp:

(WebCore::Pasteboard::documentFragment):
(WebCore::createGlobalHDropContent):

  • rendering/RenderText.cpp:

(WebCore::RenderText::computeUseBackslashAsYenSymbol const):

  • xml/XMLHttpRequest.cpp:

(WebCore::XMLHttpRequest::send):
(WebCore::XMLHttpRequest::finalResponseCharset const):
(WebCore::XMLHttpRequest::createDecoder const):

  • xml/XMLHttpRequest.h:
  • xml/XSLTProcessor.cpp:

(WebCore::XSLTProcessor::createDocumentFromSource):

Source/WebCore/PAL:

This is a purely mechanical move. The TextCodec files don't have any dependencies
except for ICU, so they're good candidates to move.

  • PAL.xcodeproj/project.pbxproj:
  • pal/CMakeLists.txt:
  • pal/PlatformMac.cmake:
  • pal/ThreadGlobalData.cpp: Copied from Source/WebCore/PAL/pal/text/UnencodableHandling.h.

(PAL::ThreadGlobalData::ThreadGlobalData):
(PAL::ThreadGlobalData::destroy):

  • pal/ThreadGlobalData.h: Copied from Source/WebCore/html/parser/HTMLMetaCharsetParser.h.

(PAL::ThreadGlobalData::ThreadGlobalData::cachedConverterICU):

  • pal/text/DecodeEscapeSequences.h: Renamed from Source/WebCore/platform/text/DecodeEscapeSequences.h.

(PAL::Unicode16BitEscapeSequence::findEndOfRun):
(PAL::Unicode16BitEscapeSequence::decodeRun):
(PAL::URLEscapeSequence::findEndOfRun):
(PAL::URLEscapeSequence::decodeRun):
(PAL::decodeURLEscapeSequencesAsData):

  • pal/text/EncodingTables.cpp: Renamed from Source/WebCore/platform/text/EncodingTables.cpp.

(PAL::big5):
(PAL::eucKR):

  • pal/text/EncodingTables.h: Renamed from Source/WebCore/platform/text/EncodingTables.h.

(PAL::findInSortedPairs):

  • pal/text/TextCodec.cpp: Renamed from Source/WebCore/platform/text/TextCodec.cpp.
  • pal/text/TextCodec.h: Renamed from Source/WebCore/platform/text/TextCodec.h.
  • pal/text/TextCodecASCIIFastPath.h: Renamed from Source/WebCore/platform/text/TextCodecASCIIFastPath.h.
  • pal/text/TextCodecCJK.cpp: Renamed from Source/WebCore/platform/text/TextCodecCJK.cpp.

(PAL::gb18030Ranges):

  • pal/text/TextCodecCJK.h: Renamed from Source/WebCore/platform/text/TextCodecCJK.h.
  • pal/text/TextCodecICU.cpp: Renamed from Source/WebCore/platform/text/TextCodecICU.cpp.

(PAL::TextCodecICU::decode):

  • pal/text/TextCodecICU.h: Renamed from Source/WebCore/platform/text/TextCodecICU.h.
  • pal/text/TextCodecLatin1.cpp: Renamed from Source/WebCore/platform/text/TextCodecLatin1.cpp.
  • pal/text/TextCodecLatin1.h: Renamed from Source/WebCore/platform/text/TextCodecLatin1.h.
  • pal/text/TextCodecReplacement.cpp: Renamed from Source/WebCore/platform/text/TextCodecReplacement.cpp.
  • pal/text/TextCodecReplacement.h: Renamed from Source/WebCore/platform/text/TextCodecReplacement.h.
  • pal/text/TextCodecSingleByte.cpp: Renamed from Source/WebCore/platform/text/TextCodecSingleByte.cpp.

(PAL::TextCodecSingleByte::encode const):
(PAL::TextCodecSingleByte::decode):

  • pal/text/TextCodecSingleByte.h: Renamed from Source/WebCore/platform/text/TextCodecSingleByte.h.
  • pal/text/TextCodecUTF16.cpp: Renamed from Source/WebCore/platform/text/TextCodecUTF16.cpp.
  • pal/text/TextCodecUTF16.h: Renamed from Source/WebCore/platform/text/TextCodecUTF16.h.
  • pal/text/TextCodecUTF8.cpp: Renamed from Source/WebCore/platform/text/TextCodecUTF8.cpp.

(PAL::TextCodecUTF8::decode):

  • pal/text/TextCodecUTF8.h: Renamed from Source/WebCore/platform/text/TextCodecUTF8.h.
  • pal/text/TextCodecUserDefined.cpp: Renamed from Source/WebCore/platform/text/TextCodecUserDefined.cpp.
  • pal/text/TextCodecUserDefined.h: Renamed from Source/WebCore/platform/text/TextCodecUserDefined.h.
  • pal/text/TextEncoding.cpp: Renamed from Source/WebCore/platform/text/TextEncoding.cpp.

(PAL::TextEncoding::encode const):

  • pal/text/TextEncoding.h: Renamed from Source/WebCore/platform/text/TextEncoding.h.
  • pal/text/TextEncodingDetector.h: Renamed from Source/WebCore/platform/text/TextEncodingDetector.h.
  • pal/text/TextEncodingDetectorICU.cpp: Renamed from Source/WebCore/platform/text/TextEncodingDetectorICU.cpp.

(PAL::detectTextEncoding):

  • pal/text/TextEncodingRegistry.cpp: Renamed from Source/WebCore/platform/text/TextEncodingRegistry.cpp.

(PAL::isUndesiredAlias):

  • pal/text/TextEncodingRegistry.h: Renamed from Source/WebCore/platform/text/TextEncodingRegistry.h.
  • pal/text/UnencodableHandling.h:
  • pal/text/ios/TextEncodingRegistryIOS.mm: Renamed from Source/WebCore/platform/text/ios/TextEncodingRegistryIOS.mm.

(PAL::webDefaultCFStringEncoding):

  • pal/text/mac/TextEncodingRegistryMac.mm: Renamed from Source/WebCore/platform/text/mac/TextEncodingRegistryMac.mm.
  • pal/text/win/TextCodecWin.cpp: Renamed from Source/WebCore/platform/text/win/TextCodecWin.cpp.

(PAL::getCodePageFlags):

  • pal/text/win/TextCodecWin.h: Renamed from Source/WebCore/platform/text/win/TextCodecWin.h.

Source/WebKit:

Update to use the new PAL files.

  • NetworkProcess/CustomProtocols/Cocoa/LegacyCustomProtocolManagerCocoa.mm:
  • NetworkProcess/WebStorage/LocalStorageDatabaseTracker.cpp:
  • NetworkProcess/WebStorage/StorageManager.cpp:
  • NetworkProcess/WebStorage/StorageManagerSet.cpp:

(WebKit::StorageManagerSet::StorageManagerSet):

  • NetworkProcess/curl/NetworkDataTaskCurl.cpp:

(WebKit::NetworkDataTaskCurl::suggestedFilename const):

  • NetworkProcess/soup/NetworkDataTaskSoup.cpp:

(WebKit::NetworkDataTaskSoup::suggestedFilename const):

  • Scripts/PreferencesTemplates/WebPreferencesStoreDefaultsMap.cpp.erb:
  • UIProcess/API/glib/WebKitFileChooserRequest.cpp:

(webkit_file_chooser_request_select_files):

  • UIProcess/API/glib/WebKitSettings.cpp:
  • UIProcess/Inspector/WebInspectorUIProxy.cpp:

(WebKit::WebInspectorUIProxy::isMainOrTestInspectorPage):

  • WebProcess/Plugins/PluginView.cpp:

(WebKit::PluginView::performJavaScriptURLRequest):

Source/WebKitLegacy:

Update to use the new PAL files.

  • Storage/StorageTracker.cpp:

(WebKit::StorageTracker::internalInitialize):

Source/WebKitLegacy/mac:

Update to use the new PAL files.

  • Misc/WebNSURLExtras.mm:

(-[NSString _webkit_stringByReplacingValidPercentEscapes]):

  • WebView/WebFrame.mm:

(+[WebFrame stringWithData:textEncodingName:]):

  • WebView/WebPreferences.mm:

(+[WebPreferences _systemCFStringEncoding]):
(+[WebPreferences _setInitialDefaultTextEncodingToSystemEncoding]):

  • WebView/WebResource.mm:

(-[WebResource _stringValue]):

Source/WebKitLegacy/win:

Update to use the new PAL files.

  • WebDownloadCurl.cpp:

(WebDownload::didReceiveResponse):

Source/WTF:

Update to use the new PAL files.

  • Scripts/Preferences/WebPreferences.yaml:

Tools:

Update to use the new PAL files.

  • Scripts/webkitpy/style/checkers/cpp.py:

(check_identifier_name_in_declaration):

  • TestWebKitAPI/Tests/WebCore/TextCodec.cpp:

(TestWebKitAPI::testDecode):

  • TestWebKitAPI/Tests/WebCore/URLParserTextEncoding.cpp:

(TestWebKitAPI::checkURL):
(TestWebKitAPI::TEST_F):

  • Property svn:eol-style set to native
File size: 3.2 KB
Line 
1/*
2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#include "config.h"
32#include "BlobBuilder.h"
33#include "EndingType.h"
34
35#include "Blob.h"
36#include <JavaScriptCore/ArrayBuffer.h>
37#include <JavaScriptCore/ArrayBufferView.h>
38#include <pal/text/TextEncoding.h>
39#include <wtf/text/CString.h>
40#include <wtf/text/LineEnding.h>
41
42namespace WebCore {
43
44BlobBuilder::BlobBuilder(EndingType endings)
45 : m_endings(endings)
46{
47}
48
49void BlobBuilder::append(RefPtr<ArrayBuffer>&& arrayBuffer)
50{
51 if (!arrayBuffer)
52 return;
53 m_appendableData.append(static_cast<const uint8_t*>(arrayBuffer->data()), arrayBuffer->byteLength());
54}
55
56void BlobBuilder::append(RefPtr<ArrayBufferView>&& arrayBufferView)
57{
58 if (!arrayBufferView)
59 return;
60 m_appendableData.append(static_cast<const uint8_t*>(arrayBufferView->baseAddress()), arrayBufferView->byteLength());
61}
62
63void BlobBuilder::append(RefPtr<Blob>&& blob)
64{
65 if (!blob)
66 return;
67 if (!m_appendableData.isEmpty())
68 m_items.append(BlobPart(WTFMove(m_appendableData)));
69 m_items.append(BlobPart(blob->url()));
70}
71
72void BlobBuilder::append(const String& text)
73{
74 auto bytes = PAL::UTF8Encoding().encode(text, PAL::UnencodableHandling::Entities, PAL::NFCNormalize::No);
75
76 if (m_endings == EndingType::Native)
77 bytes = normalizeLineEndingsToNative(WTFMove(bytes));
78
79 if (m_appendableData.isEmpty())
80 m_appendableData = WTFMove(bytes);
81 else {
82 // FIXME: Would it be better to move multiple vectors into m_items instead of merging them into one?
83 m_appendableData.appendVector(bytes);
84 }
85}
86
87Vector<BlobPart> BlobBuilder::finalize()
88{
89 if (!m_appendableData.isEmpty())
90 m_items.append(BlobPart(WTFMove(m_appendableData)));
91 return WTFMove(m_items);
92}
93
94} // namespace WebCore
Note: See TracBrowser for help on using the repository browser.