haikuwebkit/Source/WebCore/page/Base64Utilities.cpp

57 lines
2.1 KiB
C++
Raw Permalink Normal View History

/*
* Copyright (C) 2016 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "Base64Utilities.h"
#include <wtf/text/Base64.h>
namespace WebCore {
Move some more assorted classes from ExceptionCode to Exception https://bugs.webkit.org/show_bug.cgi?id=163775 Reviewed by Chris Dumez. * Modules/fetch/WorkerGlobalScopeFetch.cpp: (WebCore::WorkerGlobalScopeFetch::fetch): Remove unnecessary calls to WorkerGlobalScope::scriptExcutionObject, which just returns the scope itself. * Modules/notifications/Notification.cpp: Added now-needed include. * Modules/webdatabase/DOMWindowWebDatabase.cpp: Ditto. * WebCore.xcodeproj/project.pbxproj: Added WindowOrWorkerGlobalScope.idl. * bindings/js/JSDedicatedWorkerGlobalScopeCustom.cpp: (WebCore::JSDedicatedWorkerGlobalScope::postMessage): Pass a reference instead of a pointer to handlePostMessage. * bindings/js/JSMessagePortCustom.cpp: (WebCore::JSMessagePort::postMessage): Ditto. * bindings/js/JSMessagePortCustom.h: Use pragma once. Change handlePostMessage to take a reference to the object instead of a pointer, and also to use propagateException since postMessage now uses ExceptionOr. * bindings/js/JSWorkerCustom.cpp: (WebCore::JSWorker::postMessage): Pass a reference instead of a pointer to handlePostMessage. (WebCore::constructJSWorker): Use the version of toJSNewlyCreated that handles propagating an exception from ExceptionOr. * bindings/js/JSWorkerGlobalScopeCustom.cpp: (WebCore::JSWorkerGlobalScope::visitAdditionalChildren): Use auto. Remove unnecessary round trip through the scriptExecutionContext function. (WebCore::JSWorkerGlobalScope::importScripts): Use reserveInitialCapacity and uncheckedAppend to build up the vector of strings. Use propagateException to deal with ExceptionOr result. * dom/MessagePort.cpp: (WebCore::MessagePort::MessagePort): Initialize boolean data members in the class definition instead of here. (WebCore::MessagePort::postMessage): Use ExceptionOr. (WebCore::MessagePort::entangle): Use an rvalue reference. (WebCore::MessagePort::dispatchMessages): Use ExceptionOr. (WebCore::MessagePort::disentanglePorts): Ditto. Also use a more efficient idiom that does half as much hashing as the old algorithm, and got rid an unneeded local variable. (WebCore::MessagePort::entanglePorts): Use an rvalue reference. * dom/MessagePort.h: Updated for above changes. * fileapi/FileReader.cpp: (WebCore::FileReader::create): Use auto. (WebCore::FileReader::FileReader): Initialize scalars in the class definition. (WebCore::FileReader::~FileReader): Call cancel on the loader directly instead of sharing code with the stop function. (WebCore::FileReader::stop): Moved the body of the terminate function here. (WebCore::FileReader::readAsArrayBuffer): Use ExceptionOr. (WebCore::FileReader::readAsBinaryString): Ditto. (WebCore::FileReader::readAsText): Ditto. (WebCore::FileReader::readAsDataURL): Ditto. (WebCore::FileReader::readInternal): Ditto. Also add a cast now that we derive privately from FileReaderLoaderClient. (WebCore::FileReader::abort): Call stop instead of terminate. (WebCore::FileReader::terminate): Deleted. Moved code into stop. (WebCore::FileReader::didReceiveData): Moved comment to where the constant is. * fileapi/FileReader.h: Updated for above changes. Made more functions private and used final instead of override. * fileapi/FileReader.idl: Use non-legacy exceptions. * fileapi/FileReaderSync.cpp: (WebCore::FileReaderSync::readAsArrayBuffer): Use ExceptionOr. (WebCore::FileReaderSync::readAsBinaryString): Ditto. (WebCore::FileReaderSync::readAsText): Ditto. (WebCore::FileReaderSync::readAsDataURL): Ditto. (WebCore::FileReaderSync::startLoading): Ditto. (WebCore::FileReaderSync::startLoadingString): Added. Helper to cut down on repeated code in functions above. * fileapi/FileReaderSync.h: Updated for above changes. * fileapi/FileReaderSync.idl: Use non-legacy exceptions. * page/Base64Utilities.cpp: (WebCore::Base64Utilities::btoa): Use ExceptionOr. (WebCore::Base64Utilities::atob): Ditto. * page/Base64Utilities.h: Updated for above changes. * page/DOMWindow.cpp: (WebCore::DOMWindow::navigator): Pass a reference to the frame. (WebCore::DOMWindow::postMessage): Use ExceptionOr when calling MessagePort::disentanglePorts. Also udpated for changes to the PostMessageTimer. * page/Navigator.cpp: (WebCore::Navigator::Navigator): Take a reference. (WebCore::shouldHideFourDot): Ditto (WebCore::Navigator::appVersion): Pass a reference. (WebCore::Navigator::plugins): Return a reference. (WebCore::Navigator::mimeTypes): Ditto. * page/Navigator.h: Updated for above changes. Also marked the class final and moved derivation from RefCounted to NavigatorBase. * page/NavigatorBase.h: Addded derivation from RefCounted since both derived classes want that, and the destructor is already virtual. * page/WindowOrWorkerGlobalScope.idl: Use non-legacy exceptions. * page/WorkerNavigator.cpp: (WebCore::WorkerNavigator::~WorkerNavigator): Deleted. * page/WorkerNavigator.h: Moved derivation from RefCounted to NavigatorBase. Also marked class final. * workers/AbstractWorker.cpp: (WebCore::AbstractWorker::resolveURL): Use ExceptionOr. * workers/AbstractWorker.h: Updated for above changes. * workers/DedicatedWorkerGlobalScope.cpp: (WebCore::DedicatedWorkerGlobalScope::create): Use RefPtr&& instead of PassRefPtr. (WebCore::DedicatedWorkerGlobalScope::DedicatedWorkerGlobalScope): Ditto. (WebCore::DedicatedWorkerGlobalScope::postMessage): Use ExceptionOr. (WebCore::DedicatedWorkerGlobalScope::importScripts): Ditto. * workers/DedicatedWorkerGlobalScope.h: Updated for above changes. * workers/DedicatedWorkerGlobalScope.idl: Use non-legacy exceptions. * workers/Worker.cpp: (WebCore::Worker::create): Use ExceptionOr. (WebCore::Worker::postMessage): Ditto. * workers/Worker.h: Updated for above changes. * workers/Worker.idl: Use non-legacy exception. * workers/WorkerGlobalScope.cpp: (WebCore::WorkerGlobalScope::WorkerGlobalScope): Moved initialization of m_closing to class definition. (WebCore::WorkerGlobalScope::~WorkerGlobalScope): Removed call to deleted notifyObserversOfStop function. (WebCore::WorkerGlobalScope::importScripts): Use ExceptionOr. Also use reserveInitialCapacity and uncheckedAppend to build a vector. (WebCore::WorkerGlobalScope::addConsoleMessage): Use an rvalue reference. Also moved the body of one of the addMessageToWorkerConsole overloads into one of the overloads of this function, and changed the other to call addMessage. (WebCore::WorkerGlobalScope::addMessage): Moved the body of the other addMessageToWorkerConsole here. (WebCore::WorkerGlobalScope::addMessageToWorkerConsole): Deleted. (WebCore::WorkerGlobalScope::Observer::Observer): Deleted. (WebCore::WorkerGlobalScope::Observer::~Observer): Deleted. (WebCore::WorkerGlobalScope::Observer::stopObserving): Deleted. (WebCore::WorkerGlobalScope::registerObserver): Deleted. (WebCore::WorkerGlobalScope::unregisterObserver): Deleted. (WebCore::WorkerGlobalScope::notifyObserversOfStop): Deleted. * workers/WorkerGlobalScope.h: Removed unneeded includes. Moved many virtual function overrides into the private section. Marked many functions final instead of just override. Removed unused Observer class and m_workerObservers set. * workers/WorkerThread.cpp: (WebCore::WorkerThread::stop): Removed call to deleted WorkerGlobalScope::notifyObserversOfStop function. Canonical link: https://commits.webkit.org/181566@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@207687 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-10-21 18:32:04 +00:00
ExceptionOr<String> Base64Utilities::btoa(const String& stringToEncode)
{
if (stringToEncode.isNull())
return String();
Reduce WTF::String operations that do unnecessary Unicode operations instead of ASCII https://bugs.webkit.org/show_bug.cgi?id=179907 Reviewed by Sam Weinig. Source/JavaScriptCore: * inspector/agents/InspectorDebuggerAgent.cpp: (Inspector::matches): Removed explicit TextCaseSensitive because RegularExpression now defaults to that. * runtime/StringPrototype.cpp: (JSC::stringIncludesImpl): Use String::find since there is no overload of String::contains that takes a start offset now that we removed the one that took a caseSensitive boolean. We can add one later if we like, but this should do for now. * yarr/RegularExpression.h: Moved the TextCaseSensitivity enumeration here from the StringImpl.h header because it is only used here. Source/WebCore: * Modules/plugins/YouTubePluginReplacement.cpp: (WebCore::hasCaseInsensitivePrefix): Deleted. (WebCore::processAndCreateYouTubeURL): Use startsWithLettersIgnoringASCIICase. * Modules/websockets/WebSocketHandshake.cpp: (WebCore::WebSocketHandshake::readHTTPHeaders): Use isAllASCII. * accessibility/atk/AccessibilityObjectAtk.cpp: (WebCore::AccessibilityObject::getLengthForTextRange const): Use text().length(). * accessibility/AXObjectCache.cpp: (WebCore::AXObjectCache::traverseToOffsetInRange): Use isHTMLSpace instead of isSpaceOrNewline since the code is trying to skip collapsible HTML spaces, not arbitrary Unicode whitespace. * accessibility/AccessibilityList.cpp: (WebCore::AccessibilityList::childHasPseudoVisibleListItemMarkers): Use isAllSpecialCharacters<isHTMLSpace> for the same reason as above. * accessibility/AccessibilityNodeObject.cpp: (WebCore::AccessibilityNodeObject::isSearchField const): Use containsIgnoringASCIICase. * accessibility/AccessibilityObject.cpp: (WebCore::AccessibilityObject::accessibilityObjectContainsText const): Use new findPlainText function exported from TextIterator so this can share the same search matching logic used to find text in webpages. (WebCore::AccessibilityObject::selectText): Use capitalize and its return value rather than makeCapitalize modifying a string in place. * accessibility/AccessibilityRenderObject.cpp: (WebCore::objectInclusionFromAltText): Use isAllSpecialCharacters<isHTMLSpace> for the same reason as above. (WebCore::AccessibilityRenderObject::computeAccessibilityIsIgnored const): Ditto. * bindings/js/JSDOMConvertStrings.cpp: (WebCore::stringToByteString): Use isAllLatin1. * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::containsOnlyASCIIWithNoUppercase): Use StringView::codeUnits instead of String::at. * contentextensions/ContentExtensionsBackend.cpp: (WebCore::ContentExtensions::ContentExtensionsBackend::actionsForResourceLoad const): Use isAllASCII. * contentextensions/URLFilterParser.cpp: (WebCore::ContentExtensions::URLFilterParser::addPattern): Ditto. * css/CSSFontFaceSrcValue.cpp: (WebCore::CSSFontFaceSrcValue::isSupportedFormat const): Use protocolIs and endsWithIgnoringASCIICase. * css/DOMCSSNamespace.cpp: (WebCore::valueWithoutImportant): Use endsWithIgnoringASCIICase. * css/parser/CSSPropertyParser.cpp: (WebCore::parseGridTemplateAreasRow): Use isAllSpecialCharacters<isCSSSpace>, for the preflight, which matches what the actual parsing code uses. * dom/CharacterData.cpp: (WebCore::CharacterData::containsOnlyWhitespace const): Deleted. Callers can efficiently get at the data and do this kind of check on the data directly. * dom/CharacterData.h: Updated for the above. * dom/DataTransfer.cpp: (WebCore::normalizeType): Use startsWith since the string is already converted to ASCII lowercase. * dom/Position.cpp: (WebCore::Position::leadingWhitespacePosition const): Use isHTMLSpace since since the code is trying to check for collapsible HTML spaces, not general Unicode spaces. Other call sites of isSpaceOrNewline need to be checked for this, but I did not fix them all at this time. (WebCore::Position::trailingWhitespacePosition const): Ditto. * editing/Editor.cpp: (WebCore::Editor::editorUIUpdateTimerFired): Use noBreakSpace. * editing/FrameSelection.cpp: (WebCore::FrameSelection::debugRenderer const): Use text().length() instead of textLength. (WebCore::FrameSelection::selectionAtWordStart const): Use noBreakSpace. (WebCore::FrameSelection::wordSelectionContainingCaretSelection): Ditto. (WebCore::FrameSelection::actualSelectionAtSentenceStart const): Ditto. * editing/TextIterator.cpp: (WebCore::textNodeOffsetInFlow): Use text().length(). (WebCore::TextIterator::handleTextNode): Ditto. (WebCore::collapsedSpaceLength): Updated since RenderText::text now returns a reference rather than a pointer. (WebCore::findPlainText): Added. Uses SearchBuffer to search for one string within another. Exported so accessibility code can do this operation. * editing/TextIterator.h: Updated for the above. * editing/TypingCommand.cpp: (WebCore::TypingCommand::markMisspellingsAfterTyping): Use noBreakSpace. * editing/VisibleUnits.cpp: (WebCore::findStartOfParagraph): Updated since RenderText::text now returns a reference. (WebCore::findEndOfParagraph): Ditto. * editing/cocoa/HTMLConverter.mm: (HTMLConverter::_processText): Use String::characterAt instead of String::at. Use capitalize instead of makeCapitalized. * editing/cocoa/WebContentReaderCocoa.mm: (WebCore::stripMicrosoftPrefix): Use findIgnoringASCIICase. * html/Autofill.cpp: (WebCore::AutofillData::createFromHTMLFormControlElement): Use startsWithLettersIgnoringASCIICase. * html/BaseTextInputType.cpp: (WebCore::BaseTextInputType::patternMismatch const): Removed explicit TextCaseSensitive since it now is the default, and needed to touch this anyway because the enumeration is now in a different namespace. * html/EmailInputType.cpp: (WebCore::isValidEmailAddress): Updated to use JSC::Yarr::TextCaseInsensitive. * html/HTMLObjectElement.cpp: (WebCore::HTMLObjectElement::hasFallbackContent const): Use isAllSpecialCharacters<isHTMLSpace>. (WebCore::HTMLObjectElement::shouldAllowQuickTimeClassIdQuirk): Use startsWithLettersIgnoringASCIICase. (WebCore::HTMLObjectElement::hasValidClassId): Use protocolIs. (WebCore::preventsParentObjectFromExposure): Use isAllSpecialCharacters<isHTMLSpace>. * html/parser/HTMLConstructionSite.cpp: (WebCore::HTMLConstructionSite::setCompatibilityModeFromDoctype): Use startsWithLettersIgnoringASCIICase. * html/parser/HTMLMetaCharsetParser.cpp: (WebCore::extractCharset): Use findIgnoringASCIICase. * html/parser/XSSAuditor.cpp: (WebCore::XSSAuditor::isContainedInRequest): Use containsIgnoringASCIICase. * html/track/WebVTTParser.cpp: (WebCore::WebVTTParser::hasRequiredFileIdentifier): Don't pass the length to the String::startsWith function. There has never been a version of that function that takes the length, there is no need to pass the length since the function handles null-terminated strings like the one here, and in the past the length has been getting converted to a boolean making the comparison be case sensitive. Removing the argument entirely leaves it case sensitive. * inspector/InspectorNodeFinder.cpp: (WebCore::InspectorNodeFinder::matchesElement): Use startsWithIgnoringASCIICase and endsWithIgnoringASCIICase. * inspector/InspectorStyleSheet.cpp: (WebCore::selectorsFromSource): Use JSC::Yarr::TextCaseSensitive. * inspector/agents/InspectorDOMAgent.cpp: (WebCore::containsOnlyHTMLWhitespace): Made this a non-member function and reimplemented using isAllSpecialCharacters<isHTMLSpace>(). (WebCore::InspectorDOMAgent::innerFirstChild): Use containsOnlyHTMLWhitespace. (WebCore::InspectorDOMAgent::innerNextSibling): Ditto. (WebCore::InspectorDOMAgent::innerPreviousSibling): Ditto. (WebCore::InspectorDOMAgent::innerChildNodeCount): Ditto. (WebCore::InspectorDOMAgent::didInsertDOMNode): Ditto. (WebCore::InspectorDOMAgent::didRemoveDOMNode): Ditto. * inspector/agents/InspectorDOMAgent.h: Updated for above change. * loader/appcache/ApplicationCacheStorage.cpp: (WebCore::ApplicationCacheStorage::shouldStoreResourceAsFlatFile): Use startsWithLettersIgnoringASCIICase. * page/Base64Utilities.cpp: (WebCore::Base64Utilities::btoa): Use isAllLatin1. * page/Frame.cpp: (WebCore::createRegExpForLabels): Removed TextCaseSensitive argument since that is now the default and also used JSC::Yarr::TextCaseInsensitive. (WebCore::matchLabelsAgainstString): More of the same. * page/FrameView.cpp: (WebCore::countRenderedCharactersInRenderObjectWithThreshold): Use text().length(). * page/SecurityOrigin.cpp: (WebCore::isFeedWithNestedProtocolInHTTPFamily): Use startsWithLettersIgnoringASCIICase. * page/UserContentURLPattern.cpp: (WebCore::UserContentURLPattern::matchesHost const): Use endsWithIgnoringASCIICase. * page/csp/ContentSecurityPolicySource.cpp: (WebCore::ContentSecurityPolicySource::hostMatches const): Ditto. * page/csp/ContentSecurityPolicySourceList.cpp: (WebCore::ContentSecurityPolicySourceList::parseNonceSource): Use startsWithIgnoringASCIICase. * page/ios/FrameIOS.mm: (WebCore::Frame::wordsInCurrentParagraph const): Use noBreakSpace. * platform/ContentType.cpp: (WebCore::ContentType::parameter const): Use findIgnoringASCIICase. * platform/MIMETypeRegistry.cpp: (WebCore::MIMETypeRegistry::isSupportedFontMIMEType): Use startsWithLettersIgnoringASCIICase. (WebCore::MIMETypeRegistry::isSupportedJSONMIMEType): Use mimeType.endsWithIgnoringASCIICase. (WebCore::MIMETypeRegistry::isTextMIMEType): Use startsWithLettersIgnoringASCIICase. (WebCore::MIMETypeRegistry::isXMLMIMEType): Use endsWithIgnoringASCIICase. (WebCore::MIMETypeRegistry::isJavaAppletMIMEType): Use startsWithLettersIgnoringASCIICase. (WebCore::MIMETypeRegistry::canShowMIMEType): Ditto. * platform/URL.cpp: (WebCore::isAllASCII): Renamed from containsOnlyASCII. (WebCore::appendEncodedHostname): Use isAllASCII. * platform/URLParser.cpp: (WebCore::containsOnlyASCII): Deleted. (WebCore::URLParser::domainToASCII): Use StringImpl::isAllASCII. Changed to take StringImpl& to guarantee we won't keep doing null checks since the caller already checks for null. (WebCore::URLParser::parseHostAndPort): Pass StringImpl&. * platform/URLParser.h: Updated for above. * platform/graphics/MediaPlayer.cpp: (WebCore::MediaPlayer::supportsType): Use endsWithIgnoringASCIICase and startsWithLettersIgnoringASCIICase. * platform/graphics/avfoundation/CDMPrivateMediaSourceAVFObjC.mm: (WebCore::validKeySystemRE): Use JSC::Yarr::TextCaseInsensitive. * platform/graphics/cocoa/FontCacheCoreText.cpp: (WebCore::FontCache::similarFont): Use containsIgnoringASCIICase for the Geeza font special cases. * platform/graphics/mac/MediaPlayerPrivateQTKit.mm: (WebCore::shouldRejectMIMEType): Use startsWithLettersIgnoringASCIICase. * platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp: (WebCore::GraphicsContext3D::getUnmangledInfoLog): Removed TextCaseSensitive since it now is the default. * platform/mac/PublicSuffixMac.mm: (WebCore::topPrivatelyControlledDomain): Use isAllASCII. * platform/mac/SSLKeyGeneratorMac.mm: (WebCore::signedPublicKeyAndChallengeString): Use isAllASCII. * platform/mac/StringUtilities.mm: (WebCore::stringMatchesWildcardString): Use JSC::Yarr::TextCaseInsensitive. * platform/mediastream/RealtimeMediaSourceCenter.cpp: (WebCore::addStringToSHA1): Use isAllASCII. * platform/network/CacheValidation.cpp: (WebCore::parseCacheControlDirectives): Use containsIgnoringASCIICase. * platform/network/HTTPParsers.cpp: (WebCore::parseHTTPRefresh): Use findIgnoringASCIICase. (WebCore::findCharsetInMediaType): Ditto. (WebCore::parseRange): Use startsWithLettersIgnoringASCIICase. * platform/network/curl/AuthenticationChallengeCurl.cpp: (WebCore::AuthenticationChallenge::protectionSpaceFromHandle): Use findIgnoringASCIICase. * platform/network/curl/MultipartHandle.cpp: (WebCore::MultipartHandle::extractBoundary): Ditto. * platform/network/curl/ResourceHandleCurlDelegate.cpp: (WebCore::ResourceHandleCurlDelegate::handleDataURL): Use endsWithIgnoringASCIICase. * platform/network/curl/ResourceResponseCurl.cpp: (WebCore::ResourceResponse::isAppendableHeader): Use startsWithLettersIgnoringASCIICase. (WebCore::ResourceResponse::appendHTTPHeaderField): Ditto. * platform/win/ClipboardUtilitiesWin.cpp: (WebCore::extractMarkupFromCFHTML): Use findIgnoringASCIICase. (WebCore::fragmentFromCFHTML): Ditto. * rendering/BidiRun.cpp: (WebCore::BidiRun::BidiRun): Use text().length(). * rendering/HitTestResult.cpp: (WebCore::HitTestResult::absolutePDFURL const): Use endsWithIgnoringASCIICase. * rendering/InlineFlowBox.cpp: (WebCore::InlineFlowBox::placeBoxRangeInInlineDirection): Use text().length(). * rendering/InlineIterator.h: (WebCore::InlineIterator::fastIncrementInTextNode): Ditto. (WebCore::InlineIterator::increment): Dtto. * rendering/InlineTextBox.cpp: (WebCore::InlineTextBox::isLineBreak const): Updated since RenderText::text now returns a StringImpl&. (WebCore::InlineTextBox::selectionStartEnd const): Use text().length(). (WebCore::InlineTextBox::text const): Updated since RenderText::text now returns a StringImpl&. * rendering/RenderBlock.cpp: (WebCore::RenderBlock::constructTextRun): Use text().length(). * rendering/RenderBlockFlow.cpp: (WebCore::isVisibleRenderText): Use isAllSpecialCharacters<isHTMLSpace>(). (WebCore::RenderBlockFlow::computeInlinePreferredLogicalWidths const): Use the new trimmedPreferredWidths that returns a structure instead of the old one with lots of arguments. Also use text().length(). * rendering/RenderBlockLineLayout.cpp: (WebCore::endsWithHTMLSpaces): Renamed and changed to use isHTMLSpace instead of isASCIISpace. (WebCore::reachedEndOfTextRenderer): Use endsWithHTMLSpaces. (WebCore::RenderBlockFlow::computeInlineDirectionPositionsForSegment): Updated for hcanges to RenderText. (WebCore::RenderBlockFlow::handleTrailingSpaces): Ditto. (WebCore::RenderBlockFlow::determineStartPosition): Ditto. * rendering/RenderCombineText.cpp: (WebCore::RenderCombineText::combineTextIfNeeded): Use isAllSpecialCharacters<isHTMLSpace>. * rendering/RenderLayer.cpp: (WebCore::RenderLayer::calculateClipRects const): Ditto. * rendering/RenderListBox.cpp: (WebCore::bolder): Added. Helper function. (WebCore::RenderListBox::updateFromElement): Rewrote to only compute the bolder font once rather than for every item. (WebCore::RenderListBox::paintItemForeground): Updated for change to applyTextTransform. * rendering/RenderMenuList.cpp: (WebCore::RenderMenuList::adjustInnerStyle): Updated for change to RenderText::text. (RenderMenuList::updateOptionsWidth): Updated for change to applyTextTransform. (RenderMenuList::itemText const): Ditto. * rendering/RenderText.cpp: (WebCore::capitalize): Renamed from makeCapitalized. Changed to take and return a String instead of taking a String*. (WebCore::RenderText::RenderText): Use isAllASCII. Also moved initialization of most non-bitfield members to the class definition. (WebCore::RenderText::positionForPoint): Use text(). (WebCore::RenderText::widthFromCache const): Ditto. (WebCore::RenderText::hangablePunctuationStartWidth const): Ditto. (WebCore::RenderText::hangablePunctuationEndWidth const): Ditto. (WebCore::RenderText::isHangableStopOrComma): Ditto. (WebCore::RenderText::firstCharacterIndexStrippingSpaces const): Ditto. (WebCore::RenderText::lastCharacterIndexStrippingSpaces const): Ditto. (WebCore::RenderText::trimmedPreferredWidths): Changed to return values in a structure instead of taking lots of arguments. (WebCore::RenderText::computePreferredLogicalWidths): Updated to use the text() function. (WebCore::isAllCollapsibleWhitespace): Added. (WebCore::RenderText::isAllCollapsibleWhitespace const): Updated to use a tighter loop. (WebCore::isAllPossiblyCollapsibleWhitespace): Added. (WebCore::RenderText::containsOnlyHTMLWhitespace const): Updated to use a tighter loop. Renamed from containsOnlyWhitespace. (WebCore::RenderText::setTextWithOffset): Updated to use text(). (WebCore::isInlineFlowOrEmptyText): Rewrote to be easier to read. (WebCore::RenderText::previousCharacter const): Got rid of unneeded null check and simplified. (WebCore::applyTextTransform): Changed to return a String rather than modifying one that is passed in. (WebCore::RenderText::setRenderedText): Updated use of applyTextTransform. (WebCore::RenderText::secureText): More of the same. (WebCore::RenderText::computeCanUseSimplifiedTextMeasuring const): Ditto. (WebCore::RenderText::textWithoutConvertingBackslashToYenSymbol const): Ditto. (WebCore::RenderText::width const): Ditto. (WebCore::RenderText::collectSelectionRectsForLineBoxes): Ditto. (WebCore::RenderText::previousOffset const): Ditto. (WebCore::RenderText::previousOffsetForBackwardDeletion const): Ditto. (WebCore::RenderText::nextOffset const): Ditto. (WebCore::RenderText::computeCanUseSimpleFontCodePath const): Ditto. (WebCore::RenderText::stringView const): Ditto. * rendering/RenderText.h: Made some more members private and final. Updated for above, including adding the Widths structure. Got rid of the textLength function, which existed as a workaround before we could mark a function like length final. Made the text function return a StringImpl&, which is good since the m_text string is never null, and so callers end up using StringImpl directly and saving null checks. Removed functions that are not needed, including is8Bit, characters8, characters16, uncheckedCharacterAt, operator[], and isAllASCII. * rendering/RenderTextFragment.cpp: (WebCore::RenderTextFragment::setText): Use text().length(). * rendering/RenderTextLineBoxes.cpp: (WebCore::RenderTextLineBoxes::caretMaxOffset const): Ditto. (WebCore::RenderTextLineBoxes::positionForPoint const): Ditto. (WebCore::RenderTextLineBoxes::setSelectionState): Ditto. (WebCore::RenderTextLineBoxes::absoluteQuads const): Ditto. * rendering/SimpleLineLayout.cpp: (WebCore::SimpleLineLayout::canUseForFontAndText): Ditto. * rendering/SimpleLineLayoutCoverage.cpp: (WebCore::SimpleLineLayout::textLengthForSubtree): Ditto. (WebCore::SimpleLineLayout::collectNonEmptyLeafRenderBlockFlows): Ditto. * rendering/SimpleLineLayoutFlowContents.cpp: (WebCore::SimpleLineLayout::initializeSegments): Ditto. * rendering/SimpleLineLayoutFunctions.cpp: (WebCore::SimpleLineLayout::textOffsetForPoint): Ditto. * rendering/SimpleLineLayoutFunctions.h: (WebCore::SimpleLineLayout::findCaretMaximumOffset): Ditto. * rendering/line/BreakingContext.h: (WebCore::shouldAddBorderPaddingMargin): Ditto. (WebCore::shouldSkipWhitespaceAfterStartObject): Ditto. (WebCore::iteratorIsBeyondEndOfRenderCombineText): Ditto. (WebCore::textWidth): Ditto. (WebCore::BreakingContext::handleText): Ditto. (WebCore::BreakingContext::optimalLineBreakLocationForTrailingWord): Ditto. * rendering/line/TrailingObjects.cpp: (WebCore::TrailingObjects::updateWhitespaceCollapsingTransitionsForTrailingBoxes): Ditto. * rendering/mathml/RenderMathMLFenced.cpp: (WebCore::RenderMathMLFenced::updateFromElement): Removed stray use of "unsigned int". * rendering/svg/RenderSVGInlineText.cpp: (WebCore::RenderSVGInlineText::characterStartsNewTextChunk const): Use text().length(). (WebCore::RenderSVGInlineText::positionForPoint): Ditto. * rendering/svg/SVGTextLayoutAttributesBuilder.cpp: (WebCore::processRenderSVGInlineText): Ditto. * rendering/svg/SVGTextLayoutEngine.cpp: (WebCore::SVGTextLayoutEngine::currentLogicalCharacterAttributes): Ditto. * rendering/svg/SVGTextQuery.cpp: (WebCore::SVGTextQuery::modifyStartEndPositionsRespectingLigatures const): Ditto. * style/RenderTreeUpdater.cpp: (WebCore::RenderTreeUpdater::updateRenderTree): Use isAllSpecialCharacters<isHTMLSpace>. (WebCore::RenderTreeUpdater::textRendererIsNeeded): Ditto. * svg/SVGTests.cpp: (WebCore::SVGTests::hasFeatureForLegacyBindings): Use startsWithLettersIgnoringASCIICase. * xml/parser/XMLDocumentParserLibxml2.cpp: (WebCore::shouldAllowExternalLoad): Ditto. Source/WebKit: * NetworkProcess/cache/NetworkCache.cpp: (WebKit::NetworkCache::isMediaMIMEType): Use startsWithLettersIgnoringASCIICase. * NetworkProcess/cache/NetworkCacheKey.cpp: (WebKit::NetworkCache::hashString): Use isAllASCII.. * UIProcess/API/C/WKWebsitePolicies.cpp: (WKWebsitePoliciesSetCustomHeaderFields): Use startsWithLettersIgnoringASCIICase.. * UIProcess/API/Cocoa/_WKWebsitePolicies.mm: (-[_WKWebsitePolicies setCustomHeaderFields:]): Ditto. * UIProcess/WebPageProxy.cpp: (WebKit::WebPageProxy::savePDFToFileInDownloadsFolder): Use endsWithIgnoringASCIICase. * UIProcess/WebPreferences.cpp: (WebKit::WebPreferences::WebPreferences): Initialize m_identifier explicitly. Somehow changing the String default constructor to be "= default" led to a warning that we otherwise did not get about not initializing m_identifier. Arguably a compiler bug, but legitimately strange that the copy constructor does not copy m_identifier and so nice to be explicit about it, I guess. * UIProcess/mac/WebPageProxyMac.mm: (WebKit::WebPageProxy::savePDFToTemporaryFolderAndOpenWithNativeApplicationRaw): Use endsWithIgnoringASCIICase. (WebKit::WebPageProxy::openPDFFromTemporaryFolderWithNativeApplication): Ditto. * WebProcess/WebPage/WebPage.cpp: (WebKit::WebPage::createPlugin): Ditto. * WebProcess/WebPage/ios/WebPageIOS.mm: (WebKit::WebPage::platformEditorState const): Use isAllSpecialCharacters<isHTMLSpace>. Source/WebKitLegacy/mac: * History/BinaryPropertyList.cpp: (BinaryPropertyListPlan::writeStringObject): Use isAllASCII. (BinaryPropertyListSerializer::appendStringObject): Ditto. * WebView/WebHTMLRepresentation.mm: (regExpForLabels): Removed TextCaseSensitive since it is now the default. (matchLabelsAgainstString): Use JSC::Yarr::TextCaseInsensitive. Source/WebKitLegacy/win: * Plugins/PluginDatabaseWin.cpp: (WebCore::PluginDatabase::getPluginPathsInDirectories const): Use startsWithLettersIgnoringASCIICase and endsWithIgnoringASCIICase. * WebDownloadCFNet.cpp: (WebDownload::initToResumeWithBundle): Use endsWithIgnoringASCIICase. * WebView.cpp: (WebView::markAllMatchesForText): Fix old code that was passing TextCaseSensitivity to a function that actually takes FindOptions. By luck, TextCaseSensitive happens to be 0, which is correct FindOptions for case sensitive matching, and TextCaseInsensitive happens to be 1, which is correct FindOptions for case insensitive matching, so fixing the code does not cause any change in behavior. Source/WTF: * wtf/text/ASCIIFastPath.h: Moved the using for charactersAreAllASCII here since the function is defined here. * wtf/text/AtomicString.h: Removed overloads of contains, find, startsWith, and endsWith that take a boolean indicating whether they should be "case sensitive". When false, this was doing Unicode case folding, and no callers needed that. Also tweaked formatting and argument names. * wtf/text/IntegerToStringConversion.h: Added an include of LChar.h since this file uses that. Also tweaked formatting a bit. * wtf/text/StringImpl.cpp: (WTF::StringImpl::containsOnlyWhitespace): Deleted. Despite its name sounding like it used the full Unicode whitespace definition, this actually checked isASCIISpace. Callers now all use isAllSpecialCharacters instead with the whitespace definition that is appropriate to each call site. (WTF::latin1CaseFoldTable): Deleted. (WTF::equalCompatibilityCaseless): Deleted. (WTF::StringImpl::findIgnoringCase): Deleted. (WTF::findIgnoringCaseInner): Deleted. (WTF::reverseFindIgnoringCaseInner): Deleted. (WTF::StringImpl::reverseFindIgnoringCase): Deleted. (WTF::equalInner): Removed boolean caseSensitive argument. (WTF::StringImpl::startsWith): Ditto. (WTF::StringImpl::endsWith): Ditto. * wtf/text/StringImpl.h: Moved TextCaseSensitivity out into a different header. Moved ASCIIFastPath.h include here from WTFString.h. Moved isAllSpecialCharacters free function here from WTFString.h. Moved lots of function bodies out of class definitions to make the class definitions easier to read. Sorted things a bit. Tweaked formatting. Marked constructor that takes one argument explicit. Added an isEmpty function like the one in String. Renamed copyChars to copyCharacters. Added isAllASCII, isAllLatin1 and isAllSpecialCharacters functions. Removed boolean caseSensitive arguments from various functions. Removed findIgnoringCase and reverseFindIgnoringCase. Added a FIXME to codePointCompare about the way it treats null and empty strings as equal. Changed length argument in remove to unsigned to match other lengths. * wtf/text/WTFString.cpp: (WTF::String::removeInternal): Changed length argument to be unsigned. (WTF::createWithFormatAndArguments): Use emptyString. (WTF::String::isSafeToSendToAnotherThread const): Rewrote to be easier to read. * wtf/text/WTFString.h: Moved ASCIIFastPath.h to StringImpl.h. Moved lots of function bodies out of class definitions to make the class definitions easier to read, made others one-liners. Removed the String::at function but kept the String::characterAt function; the two were identical. Removed boolean caseSensitive arguments from various functions. Removed findIgnoringCase and reverseFindIgnoringCase. Renamed containsOnlyASCII to isAllASCII and containsOnlyLatin1 to isAllLatin1 to match the naming of isAllSpecialCharacters. Moved the inline implementations of functions that are defined above further down, after things like the ASCIILiteral class and various functions. * wtf/text/icu/UTextProviderLatin1.cpp: Updated name of copyChars. Tools: * DumpRenderTree/mac/DumpRenderTree.mm: (changeWindowScaleIfNeeded): Use containsIgnoringASCIICase. * WebKitTestRunner/TestInvocation.cpp: (WTR::TestInvocation::urlContains const): Ditto. Canonical link: https://commits.webkit.org/195985@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225117 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-11-23 17:32:42 +00:00
if (!stringToEncode.isAllLatin1())
return Exception { InvalidCharacterError };
Update Base64 encoding/decoding to match more modern WebKit conventions https://bugs.webkit.org/show_bug.cgi?id=225920 Reviewed by Chris Dumez. Source/WebCore: - Updates to use new signatures for base64 encoding/decoding including utilizing the string type adaptor and makeString. - Replace out parameter based getDefaultWebCryptoMasterKey() with Optional<Vector<uint8_t>> defaultWebCryptoMasterKey(). - Update synchronous loading code path to use uint8_t* consistently for data buffer representation. - Replace out parameters in quotedPrintableEncode/quotedPrintableDecode with Optional. * Modules/encryptedmedia/InitDataRegistry.cpp: (WebCore::extractKeyIDsKeyids): Update to use new base64URLDecode. (WebCore::sanitizeKeyids): Update to use new base64URLEncodeToString() * Modules/encryptedmedia/legacy/LegacyCDMSessionClearKey.cpp: (WebCore::CDMSessionClearKey::update): Update to use new base64Decode(). * Modules/plugins/QuickTimePluginReplacement.mm: (WebCore::jsValueWithDataInContext): (WebCore::jsValueWithAVMetadataItemInContext): Update to use new base64EncodeToString(). Replace string concatentation using operator+ with makeString(). * Modules/webauthn/AuthenticatorCoordinator.cpp: (WebCore::AuthenticatorCoordinatorInternal::produceClientDataJson): Update to use new base64URLEncodeToString(). * Modules/webauthn/PublicKeyCredential.cpp: (WebCore::PublicKeyCredential::PublicKeyCredential): Update to use new base64URLEncodeToString(). * Modules/websockets/WebSocketHandshake.cpp: (WebCore::generateSecWebSocketKey): (WebCore::WebSocketHandshake::getExpectedWebSocketAccept): Update to use new base64URLEncodeToString(). * crypto/SerializedCryptoKeyWrap.h: Change from outparameter based getDefaultWebCryptoMasterKey() to new Optional<Vector<uint8_t>> defaultWebCryptoMasterKey(). * crypto/gcrypt/CryptoKeyECGCrypt.cpp: (WebCore::CryptoKeyEC::platformAddFieldElements const): Update to use new base64URLEncodeToString(). * crypto/gcrypt/SerializedCryptoKeyWrapGCrypt.cpp: (WebCore::defaultWebCryptoMasterKey): (WebCore::getDefaultWebCryptoMasterKey): Deleted. Update for new defaultWebCryptoMasterKey() signature. * crypto/keys/CryptoKeyAES.cpp: (WebCore::CryptoKeyAES::importJwk): (WebCore::CryptoKeyAES::exportJwk const): Update to use new base64URLDecode / base64URLEncodeToString(). * crypto/keys/CryptoKeyEC.cpp: (WebCore::CryptoKeyEC::importJwk): Update to use new base64URLDecode. * crypto/keys/CryptoKeyHMAC.cpp: (WebCore::CryptoKeyHMAC::importJwk): (WebCore::CryptoKeyHMAC::exportJwk const): Update to use new base64URLDecode / base64URLEncodeToString(). * crypto/keys/CryptoKeyRSA.cpp: (WebCore::CryptoKeyRSA::importJwk): (WebCore::CryptoKeyRSA::exportJwk const): Update to use new base64URLDecode / base64URLEncodeToString(). * crypto/mac/CryptoKeyECMac.cpp: (WebCore::CryptoKeyEC::platformAddFieldElements const): Update to use new base64URLEncodeToString(). * crypto/mac/SerializedCryptoKeyWrapMac.mm: (WebCore::createAndStoreMasterKey): (WebCore::findMasterKey): (WebCore::defaultWebCryptoMasterKey): (WebCore::getDefaultWebCryptoMasterKey): Deleted. Update for new defaultWebCryptoMasterKey() signature. * crypto/openssl/SerializedCryptoKeyWrapOpenSSL.cpp: (WebCore::defaultWebCryptoMasterKey): (WebCore::getDefaultWebCryptoMasterKey): Deleted. Update for new defaultWebCryptoMasterKey() signature. * fileapi/FileReaderLoader.cpp: (WebCore::FileReaderLoader::convertToDataURL): Update to use new base64EncodeToString(). * inspector/DOMPatchSupport.cpp: (WebCore::DOMPatchSupport::createDigest): Update to use new base64EncodeToString(). * inspector/InspectorFrontendHost.cpp: (WebCore::InspectorFrontendHost::showCertificate): Update to use new base64URLDecode / base64URLEncodeToString(). * inspector/NetworkResourcesData.cpp: (WebCore::NetworkResourcesData::ResourceData::decodeDataToContent): Update to use new base64EncodeToString(). * inspector/agents/InspectorDOMAgent.cpp: (WebCore::computeContentSecurityPolicySHA256Hash): Update to use new base64Decode / base64EncodeToString(). * inspector/agents/InspectorNetworkAgent.cpp: (WebCore::Inspector::buildWebSocketMessage): (WebCore::InspectorNetworkAgent::didReceiveData): (WebCore::InspectorNetworkAgent::getSerializedCertificate): (WebCore::InspectorNetworkAgent::interceptWithRequest): (WebCore::InspectorNetworkAgent::interceptWithResponse): (WebCore::InspectorNetworkAgent::interceptRequestWithResponse): (WebCore::InspectorNetworkAgent::cachedResourceContent): Update to use new base64Decode / base64EncodeToString(). * inspector/agents/InspectorPageAgent.cpp: (WebCore::InspectorPageAgent::dataContent): (WebCore::InspectorPageAgent::archive): Update to use new base64EncodeToString(). * loader/FrameLoader.cpp: (WebCore::FrameLoader::loadResourceSynchronously): Switch to using Vector<uint8_t> buffer to match new loadResourceSynchronously signature. * loader/LoaderStrategy.h: Switch to using Vector<uint8_t> for the data buffer. * loader/PrivateClickMeasurement.cpp: (WebCore::PrivateClickMeasurement::EphemeralSourceNonce::isValid const): Update to use new base64URLDecode. * loader/ResourceCryptographicDigest.cpp: (WebCore::parseCryptographicDigestImpl): (WebCore::decodeEncodedResourceCryptographicDigest): Update to use new base64Decode. * loader/archive/mhtml/MHTMLArchive.cpp: (WebCore::MHTMLArchive::generateMHTMLData): Switch to using new base64Encode and new quotedPrintableEncode. * loader/archive/mhtml/MHTMLParser.cpp: (WebCore::MHTMLParser::parseNextPart): Switch to using new base64Decode and new quotedPrintableDecode. * loader/cocoa/PrivateClickMeasurementCocoa.mm: (WebCore::PrivateClickMeasurement::calculateAndUpdateSourceUnlinkableToken): (WebCore::PrivateClickMeasurement::calculateAndUpdateSourceSecretToken): Update to use new base64URLDecode / base64URLEncodeToString(). * page/Base64Utilities.cpp: (WebCore::Base64Utilities::btoa): (WebCore::Base64Utilities::atob): Update to use new base64Decode / base64EncodeToString(). * page/Page.cpp: (WebCore::Page::userStyleSheetLocationChanged): Update to use new base64Decode. * platform/SharedBuffer.cpp: (WebCore::SharedBuffer::append): * platform/SharedBuffer.h: Add overload for append which allows passing in a uint8_t*. * platform/encryptedmedia/clearkey/CDMClearKey.cpp: (WebCore::parseLicenseFormat): (WebCore::extractKeyidsFromCencInitData): (WebCore::extractKeyIdFromWebMInitData): (WebCore::CDMInstanceSessionClearKey::removeSessionData): Update to use new base64URLDecode / base64URLEncodeToString(). * platform/graphics/avfoundation/CDMFairPlayStreaming.cpp: (WebCore::extractSinfData): Update to use new base64Decode. * platform/graphics/avfoundation/objc/CDMInstanceFairPlayStreamingAVFObjC.mm: (WebCore::CDMInstanceSessionFairPlayStreamingAVFObjC::requestLicense): (WebCore::CDMInstanceSessionFairPlayStreamingAVFObjC::updateLicense): (WebCore::CDMInstanceSessionFairPlayStreamingAVFObjC::didProvideRequests): Update to use new base64Decode / base64EncodeToString(). * platform/graphics/cairo/ImageBufferCairoBackend.cpp: (WebCore::ImageBufferCairoBackend::toDataURL const): Update to use new base64EncodeToString(). * platform/graphics/cg/ImageBufferUtilitiesCG.cpp: (WebCore::dataURL): Update to use new base64EncodeToString(). * platform/graphics/win/FontCustomPlatformData.cpp: (WebCore::createUniqueFontName): Update to use new base64EncodeToString(). * platform/graphics/win/FontCustomPlatformDataCairo.cpp: (WebCore::createUniqueFontName): Update to use new base64EncodeToString(). * platform/mac/SSLKeyGeneratorMac.mm: (WebCore::signedPublicKeyAndChallengeString): Update to use new base64EncodeToString(). * platform/network/BlobRegistryImpl.cpp: (WebCore::loadBlobResourceSynchronously): Switch to using Vector<uint8_t> buffer to match new loadResourceSynchronously signature. * platform/network/BlobResourceHandle.cpp: * platform/network/BlobResourceHandle.h: (WebCore::BlobResourceHandle::loadResourceSynchronously): Switch to using Vector<uint8_t> buffer to match new loadResourceSynchronously signature. * platform/network/CredentialBase.cpp: * platform/network/CredentialBase.h: (WebCore::CredentialBase::serializationForBasicAuthorizationHeader const): Add helper to construct Basic auth header to replace duplicated logic in call sites. * platform/network/DataURLDecoder.cpp: (WebCore::DataURLDecoder::decodeBase64): (WebCore::DataURLDecoder::decodeEscaped): (WebCore::DataURLDecoder::decodeSynchronously): * platform/network/DataURLDecoder.h: Update to use new base64Decode. * platform/network/ResourceHandle.cpp: * platform/network/ResourceHandle.h: Switch to using Vector<uint8_t> for the data buffer in the synchronous load. * platform/network/SynchronousLoaderClient.cpp: (WebCore::SynchronousLoaderClient::didReceiveData): * platform/network/SynchronousLoaderClient.h: Switch to using Vector<uint8_t> buffer to match new loadResourceSynchronously signature. * platform/network/cf/ResourceHandleCFNet.cpp: (WebCore::applyBasicAuthorizationHeader): Use new serializationForBasicAuthorizationHeader() helper. (WebCore::ResourceHandle::platformLoadResourceSynchronously): Switch to using Vector<uint8_t> for the data buffer in the synchronous load. * platform/network/curl/ResourceHandleCurl.cpp: (WebCore::ResourceHandle::platformLoadResourceSynchronously): (WebCore::ResourceHandle::handleDataURL): Switch to using Vector<uint8_t> for the data buffer in the synchronous load. * platform/network/mac/ResourceHandleMac.mm: (WebCore::applyBasicAuthorizationHeader): Use new serializationForBasicAuthorizationHeader() helper. (WebCore::ResourceHandle::platformLoadResourceSynchronously): Switch to using Vector<uint8_t> for the data buffer in the synchronous load. * platform/network/soup/ResourceHandleSoup.cpp: (WebCore::ResourceHandle::platformLoadResourceSynchronously): Switch to using Vector<uint8_t> for the data buffer in the synchronous load. * platform/network/soup/SoupNetworkSession.cpp: (WebCore::HostTLSCertificateSet::computeCertificateHash): Update to use new base64EncodeToString(). * platform/text/DecodeEscapeSequences.h: (WebCore::decodeURLEscapeSequencesAsData): Switch to returning Vector<uint8_t>. * platform/text/QuotedPrintable.cpp: * platform/text/QuotedPrintable.h: (WebCore::lengthOfLineEndingAtIndex): (WebCore::quotedPrintableEncode): (WebCore::quotedPrintableDecode): Replace uses of Vector<char> with Vector<uint8_t> and the out parameters with Optional return values. * platform/win/SSLKeyGeneratorWin.cpp: (WebCore::signedPublicKeyAndChallengeString): Update to use new base64EncodeToString(). * workers/service/server/SWScriptStorage.cpp: (WebCore::SWScriptStorage::sha2Hash const): Update to use new base64URLEncodeToString(). Source/WebKit: * NetworkProcess/NetworkConnectionToWebProcess.messages.in: * UIProcess/API/C/WKPage.cpp: (WKPageSetPageNavigationClient): * UIProcess/WebPageProxy.messages.in: * UIProcess/WebURLSchemeHandler.h: * UIProcess/WebURLSchemeTask.cpp: (WebKit::WebURLSchemeTask::didComplete): * UIProcess/WebURLSchemeTask.h: * WebProcess/Network/WebLoaderStrategy.cpp: (WebKit::WebLoaderStrategy::loadResourceSynchronously): * WebProcess/Network/WebLoaderStrategy.h: * WebProcess/WebPage/WebURLSchemeHandlerProxy.cpp: (WebKit::WebURLSchemeHandlerProxy::loadSynchronously): * WebProcess/WebPage/WebURLSchemeHandlerProxy.h: Update to use uint8_t* data buffers more consistently for synchronous loads. * NetworkProcess/NetworkResourceLoader.cpp: (WebKit::sendReplyToSynchronousRequest): Update to use uint8_t* data buffers more consistently for synchronous loads. * NetworkProcess/PrivateClickMeasurementManager.cpp: (WebKit::PrivateClickMeasurementManager::fireConversionRequest): Update to use new base64URLDecode / base64URLEncodeToString(). * NetworkProcess/cocoa/NetworkDataTaskCocoa.mm: (WebKit::applyBasicAuthorizationHeader): Use new serializationForBasicAuthorizationHeader() helper. * Shared/API/APIData.h: (API::Data::create): (API::Data::fastFreeBytes): Deleted. Add new create function that takes ownership of a Vector's buffer rather than copying it. Replace use of static functions with inline lambdas for free-functions. * Shared/mac/AuxiliaryProcessMac.mm: (WebKit::sandboxFilePath): Use makeString and new base64URLEncoded(). * UIProcess/API/Cocoa/_WKWebAuthenticationPanel.mm: (produceClientDataJson): Use new base64URLEncodeToString(). * UIProcess/Automation/cairo/WebAutomationSessionCairo.cpp: (WebKit::base64EncodedPNGData): Use new base64EncodeToString(). * UIProcess/Cocoa/NavigationState.mm: (WebKit::NavigationState::NavigationClient::webCryptoMasterKey): Use new defaultWebCryptoMasterKey() and new adopting API::Data::create function. * UIProcess/Inspector/glib/RemoteInspectorClient.cpp: (WebKit::RemoteInspectorClient::setBackendCommands): Use new base64EncodeToString(). * UIProcess/Inspector/gtk/RemoteWebInspectorUIProxyGtk.cpp: (WebKit::RemoteWebInspectorUIProxy::platformSave): Use new base64Decode(). * UIProcess/Inspector/gtk/WebInspectorUIProxyGtk.cpp: (WebKit::WebInspectorUIProxy::platformSave): Use new base64Decode(). * UIProcess/Inspector/mac/RemoteWebInspectorUIProxyMac.mm: (WebKit::RemoteWebInspectorUIProxy::platformSave): Use new base64Decode(). * UIProcess/Inspector/mac/WebInspectorUIProxyMac.mm: (WebKit::WebInspectorUIProxy::platformSave): Use new base64Decode(). * UIProcess/Inspector/socket/RemoteInspectorClient.cpp: (WebKit::RemoteInspectorClient::setBackendCommands): Use new base64EncodeToString(). * UIProcess/WebAuthentication/Cocoa/LocalAuthenticator.mm: (WebKit::LocalAuthenticatorInternal::produceHashSet): (WebKit::LocalAuthenticator::makeCredential): (WebKit::LocalAuthenticator::getAssertion): Use new base64EncodeToString(). * UIProcess/WebAuthentication/Mock/MockHidConnection.cpp: (WebKit::MockHidConnection::feedReports): Use new base64Decode(). * UIProcess/WebAuthentication/Mock/MockLocalConnection.mm: (WebKit::MockLocalConnection::filterResponses const): Use new base64EncodeToString(). Source/WebKitLegacy: * WebCoreSupport/WebResourceLoadScheduler.cpp: (WebResourceLoadScheduler::loadResourceSynchronously): * WebCoreSupport/WebResourceLoadScheduler.h: Update to match new signature. char -> uint8_t. Source/WebKitLegacy/mac: * WebCoreSupport/WebChromeClient.mm: (WebChromeClient::wrapCryptoKey const): (WebChromeClient::unwrapCryptoKey const): Update to use new Optional returning defaultWebCryptoMasterKey(). * WebCoreSupport/WebInspectorClient.mm: (WebInspectorFrontendClient::save): Update to use new Optional returning base64Decode(). Source/WTF: Bring base64 encoding/decoding up to more modern WebKit conventions by: - Replace use of "out parameter + bool" with Optional return values. - Using enum class for enumerations. - Replacing SignedOrUnsignedCharVectorAdapter/ConstSignedOrUnsignedCharVectorAdapter with appropriate function overloads. Also adds a new StringTypeAdapter for inline base64 encoding data in either makeString() or StringBuilder. To make this work, a few modifications were need to the base64Encode() functions to support the fixed size writeTo() function. First, the length of the encoded data is now computed up front depending on the policy. This has been extracted into a new calculateBase64EncodedSize() function used by both the adaptor and by base64Encode when passed a Vector. Previously, when encoding using some policies, the size was an overestimate and the resulting Vector would be resized down after encoding. Second, base64EncodeInternal was made into a template function to allow for two new base64Encode functions, one of which has a UChar* destination. These are used by the adaptor to write the encoded data. One additional small change is that now a optional map type parameter has been added to all the encoders to allow using either the default map or the URL one as defined in RFC 4648. This simplifies the implementation of the StringTypeAdapter and makes the base64URLEncode/base64URLDecode functions into simple convenience functions that use the right defaults for the generic encode/decode functions. * wtf/text/Base64.cpp: (WTF::base64EncodeInternal): (WTF::base64Encode): (WTF::base64DecodeInternal): (WTF::base64Decode): (WTF::base64URLDecode): (WTF::base64URLEncode): Deleted. * wtf/text/Base64.h: (WTF::base64Decode): (WTF::base64Encode): (WTF::base64URLEncode): (WTF::isBase64OrBase64URLCharacter): (WTF::calculateBase64EncodedSize): (WTF::base64Encoded): (WTF::base64URLEncoded): (WTF::StringTypeAdapter<Base64Specification>::StringTypeAdapter): (WTF::StringTypeAdapter<Base64Specification>::length const): (WTF::StringTypeAdapter<Base64Specification>::is8Bit const): (WTF::StringTypeAdapter<Base64Specification>::writeTo const): Tools: Update to use updated base64 and defaultWebCryptoMasterKey() related functions. * TestWebKitAPI/TCPServer.cpp: (TestWebKitAPI::TCPServer::startSecureConnection): (TestWebKitAPI::TCPServer::testCertificate): (TestWebKitAPI::TCPServer::testPrivateKey): * TestWebKitAPI/Tests/WebCore/ISOBox.cpp: (TestWebKitAPI::TEST): * TestWebKitAPI/Tests/WebCore/cocoa/PrivateClickMeasurementCocoa.mm: (TestWebKitAPI::TEST): * TestWebKitAPI/Tests/WebCore/cocoa/SerializedCryptoKeyWrap.mm: (TestWebKitAPI::TEST_F): * TestWebKitAPI/Tests/WebKitCocoa/Challenge.mm: (testIdentity2): * TestWebKitAPI/Tests/WebKitCocoa/EventAttribution.mm: (TestWebKitAPI::TEST): * TestWebKitAPI/Tests/mac/SSLKeyGenerator.mm: (TestWebKitAPI::TEST_F): * TestWebKitAPI/cocoa/HTTPServer.mm: (TestWebKitAPI::Connection::webSocketHandshake): Canonical link: https://commits.webkit.org/237912@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@277740 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-05-19 18:43:29 +00:00
return base64EncodeToString(stringToEncode.latin1());
}
Move some more assorted classes from ExceptionCode to Exception https://bugs.webkit.org/show_bug.cgi?id=163775 Reviewed by Chris Dumez. * Modules/fetch/WorkerGlobalScopeFetch.cpp: (WebCore::WorkerGlobalScopeFetch::fetch): Remove unnecessary calls to WorkerGlobalScope::scriptExcutionObject, which just returns the scope itself. * Modules/notifications/Notification.cpp: Added now-needed include. * Modules/webdatabase/DOMWindowWebDatabase.cpp: Ditto. * WebCore.xcodeproj/project.pbxproj: Added WindowOrWorkerGlobalScope.idl. * bindings/js/JSDedicatedWorkerGlobalScopeCustom.cpp: (WebCore::JSDedicatedWorkerGlobalScope::postMessage): Pass a reference instead of a pointer to handlePostMessage. * bindings/js/JSMessagePortCustom.cpp: (WebCore::JSMessagePort::postMessage): Ditto. * bindings/js/JSMessagePortCustom.h: Use pragma once. Change handlePostMessage to take a reference to the object instead of a pointer, and also to use propagateException since postMessage now uses ExceptionOr. * bindings/js/JSWorkerCustom.cpp: (WebCore::JSWorker::postMessage): Pass a reference instead of a pointer to handlePostMessage. (WebCore::constructJSWorker): Use the version of toJSNewlyCreated that handles propagating an exception from ExceptionOr. * bindings/js/JSWorkerGlobalScopeCustom.cpp: (WebCore::JSWorkerGlobalScope::visitAdditionalChildren): Use auto. Remove unnecessary round trip through the scriptExecutionContext function. (WebCore::JSWorkerGlobalScope::importScripts): Use reserveInitialCapacity and uncheckedAppend to build up the vector of strings. Use propagateException to deal with ExceptionOr result. * dom/MessagePort.cpp: (WebCore::MessagePort::MessagePort): Initialize boolean data members in the class definition instead of here. (WebCore::MessagePort::postMessage): Use ExceptionOr. (WebCore::MessagePort::entangle): Use an rvalue reference. (WebCore::MessagePort::dispatchMessages): Use ExceptionOr. (WebCore::MessagePort::disentanglePorts): Ditto. Also use a more efficient idiom that does half as much hashing as the old algorithm, and got rid an unneeded local variable. (WebCore::MessagePort::entanglePorts): Use an rvalue reference. * dom/MessagePort.h: Updated for above changes. * fileapi/FileReader.cpp: (WebCore::FileReader::create): Use auto. (WebCore::FileReader::FileReader): Initialize scalars in the class definition. (WebCore::FileReader::~FileReader): Call cancel on the loader directly instead of sharing code with the stop function. (WebCore::FileReader::stop): Moved the body of the terminate function here. (WebCore::FileReader::readAsArrayBuffer): Use ExceptionOr. (WebCore::FileReader::readAsBinaryString): Ditto. (WebCore::FileReader::readAsText): Ditto. (WebCore::FileReader::readAsDataURL): Ditto. (WebCore::FileReader::readInternal): Ditto. Also add a cast now that we derive privately from FileReaderLoaderClient. (WebCore::FileReader::abort): Call stop instead of terminate. (WebCore::FileReader::terminate): Deleted. Moved code into stop. (WebCore::FileReader::didReceiveData): Moved comment to where the constant is. * fileapi/FileReader.h: Updated for above changes. Made more functions private and used final instead of override. * fileapi/FileReader.idl: Use non-legacy exceptions. * fileapi/FileReaderSync.cpp: (WebCore::FileReaderSync::readAsArrayBuffer): Use ExceptionOr. (WebCore::FileReaderSync::readAsBinaryString): Ditto. (WebCore::FileReaderSync::readAsText): Ditto. (WebCore::FileReaderSync::readAsDataURL): Ditto. (WebCore::FileReaderSync::startLoading): Ditto. (WebCore::FileReaderSync::startLoadingString): Added. Helper to cut down on repeated code in functions above. * fileapi/FileReaderSync.h: Updated for above changes. * fileapi/FileReaderSync.idl: Use non-legacy exceptions. * page/Base64Utilities.cpp: (WebCore::Base64Utilities::btoa): Use ExceptionOr. (WebCore::Base64Utilities::atob): Ditto. * page/Base64Utilities.h: Updated for above changes. * page/DOMWindow.cpp: (WebCore::DOMWindow::navigator): Pass a reference to the frame. (WebCore::DOMWindow::postMessage): Use ExceptionOr when calling MessagePort::disentanglePorts. Also udpated for changes to the PostMessageTimer. * page/Navigator.cpp: (WebCore::Navigator::Navigator): Take a reference. (WebCore::shouldHideFourDot): Ditto (WebCore::Navigator::appVersion): Pass a reference. (WebCore::Navigator::plugins): Return a reference. (WebCore::Navigator::mimeTypes): Ditto. * page/Navigator.h: Updated for above changes. Also marked the class final and moved derivation from RefCounted to NavigatorBase. * page/NavigatorBase.h: Addded derivation from RefCounted since both derived classes want that, and the destructor is already virtual. * page/WindowOrWorkerGlobalScope.idl: Use non-legacy exceptions. * page/WorkerNavigator.cpp: (WebCore::WorkerNavigator::~WorkerNavigator): Deleted. * page/WorkerNavigator.h: Moved derivation from RefCounted to NavigatorBase. Also marked class final. * workers/AbstractWorker.cpp: (WebCore::AbstractWorker::resolveURL): Use ExceptionOr. * workers/AbstractWorker.h: Updated for above changes. * workers/DedicatedWorkerGlobalScope.cpp: (WebCore::DedicatedWorkerGlobalScope::create): Use RefPtr&& instead of PassRefPtr. (WebCore::DedicatedWorkerGlobalScope::DedicatedWorkerGlobalScope): Ditto. (WebCore::DedicatedWorkerGlobalScope::postMessage): Use ExceptionOr. (WebCore::DedicatedWorkerGlobalScope::importScripts): Ditto. * workers/DedicatedWorkerGlobalScope.h: Updated for above changes. * workers/DedicatedWorkerGlobalScope.idl: Use non-legacy exceptions. * workers/Worker.cpp: (WebCore::Worker::create): Use ExceptionOr. (WebCore::Worker::postMessage): Ditto. * workers/Worker.h: Updated for above changes. * workers/Worker.idl: Use non-legacy exception. * workers/WorkerGlobalScope.cpp: (WebCore::WorkerGlobalScope::WorkerGlobalScope): Moved initialization of m_closing to class definition. (WebCore::WorkerGlobalScope::~WorkerGlobalScope): Removed call to deleted notifyObserversOfStop function. (WebCore::WorkerGlobalScope::importScripts): Use ExceptionOr. Also use reserveInitialCapacity and uncheckedAppend to build a vector. (WebCore::WorkerGlobalScope::addConsoleMessage): Use an rvalue reference. Also moved the body of one of the addMessageToWorkerConsole overloads into one of the overloads of this function, and changed the other to call addMessage. (WebCore::WorkerGlobalScope::addMessage): Moved the body of the other addMessageToWorkerConsole here. (WebCore::WorkerGlobalScope::addMessageToWorkerConsole): Deleted. (WebCore::WorkerGlobalScope::Observer::Observer): Deleted. (WebCore::WorkerGlobalScope::Observer::~Observer): Deleted. (WebCore::WorkerGlobalScope::Observer::stopObserving): Deleted. (WebCore::WorkerGlobalScope::registerObserver): Deleted. (WebCore::WorkerGlobalScope::unregisterObserver): Deleted. (WebCore::WorkerGlobalScope::notifyObserversOfStop): Deleted. * workers/WorkerGlobalScope.h: Removed unneeded includes. Moved many virtual function overrides into the private section. Marked many functions final instead of just override. Removed unused Observer class and m_workerObservers set. * workers/WorkerThread.cpp: (WebCore::WorkerThread::stop): Removed call to deleted WorkerGlobalScope::notifyObserversOfStop function. Canonical link: https://commits.webkit.org/181566@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@207687 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-10-21 18:32:04 +00:00
ExceptionOr<String> Base64Utilities::atob(const String& encodedString)
{
if (encodedString.isNull())
return String();
Update Base64 encoding/decoding to match more modern WebKit conventions https://bugs.webkit.org/show_bug.cgi?id=225920 Reviewed by Chris Dumez. Source/WebCore: - Updates to use new signatures for base64 encoding/decoding including utilizing the string type adaptor and makeString. - Replace out parameter based getDefaultWebCryptoMasterKey() with Optional<Vector<uint8_t>> defaultWebCryptoMasterKey(). - Update synchronous loading code path to use uint8_t* consistently for data buffer representation. - Replace out parameters in quotedPrintableEncode/quotedPrintableDecode with Optional. * Modules/encryptedmedia/InitDataRegistry.cpp: (WebCore::extractKeyIDsKeyids): Update to use new base64URLDecode. (WebCore::sanitizeKeyids): Update to use new base64URLEncodeToString() * Modules/encryptedmedia/legacy/LegacyCDMSessionClearKey.cpp: (WebCore::CDMSessionClearKey::update): Update to use new base64Decode(). * Modules/plugins/QuickTimePluginReplacement.mm: (WebCore::jsValueWithDataInContext): (WebCore::jsValueWithAVMetadataItemInContext): Update to use new base64EncodeToString(). Replace string concatentation using operator+ with makeString(). * Modules/webauthn/AuthenticatorCoordinator.cpp: (WebCore::AuthenticatorCoordinatorInternal::produceClientDataJson): Update to use new base64URLEncodeToString(). * Modules/webauthn/PublicKeyCredential.cpp: (WebCore::PublicKeyCredential::PublicKeyCredential): Update to use new base64URLEncodeToString(). * Modules/websockets/WebSocketHandshake.cpp: (WebCore::generateSecWebSocketKey): (WebCore::WebSocketHandshake::getExpectedWebSocketAccept): Update to use new base64URLEncodeToString(). * crypto/SerializedCryptoKeyWrap.h: Change from outparameter based getDefaultWebCryptoMasterKey() to new Optional<Vector<uint8_t>> defaultWebCryptoMasterKey(). * crypto/gcrypt/CryptoKeyECGCrypt.cpp: (WebCore::CryptoKeyEC::platformAddFieldElements const): Update to use new base64URLEncodeToString(). * crypto/gcrypt/SerializedCryptoKeyWrapGCrypt.cpp: (WebCore::defaultWebCryptoMasterKey): (WebCore::getDefaultWebCryptoMasterKey): Deleted. Update for new defaultWebCryptoMasterKey() signature. * crypto/keys/CryptoKeyAES.cpp: (WebCore::CryptoKeyAES::importJwk): (WebCore::CryptoKeyAES::exportJwk const): Update to use new base64URLDecode / base64URLEncodeToString(). * crypto/keys/CryptoKeyEC.cpp: (WebCore::CryptoKeyEC::importJwk): Update to use new base64URLDecode. * crypto/keys/CryptoKeyHMAC.cpp: (WebCore::CryptoKeyHMAC::importJwk): (WebCore::CryptoKeyHMAC::exportJwk const): Update to use new base64URLDecode / base64URLEncodeToString(). * crypto/keys/CryptoKeyRSA.cpp: (WebCore::CryptoKeyRSA::importJwk): (WebCore::CryptoKeyRSA::exportJwk const): Update to use new base64URLDecode / base64URLEncodeToString(). * crypto/mac/CryptoKeyECMac.cpp: (WebCore::CryptoKeyEC::platformAddFieldElements const): Update to use new base64URLEncodeToString(). * crypto/mac/SerializedCryptoKeyWrapMac.mm: (WebCore::createAndStoreMasterKey): (WebCore::findMasterKey): (WebCore::defaultWebCryptoMasterKey): (WebCore::getDefaultWebCryptoMasterKey): Deleted. Update for new defaultWebCryptoMasterKey() signature. * crypto/openssl/SerializedCryptoKeyWrapOpenSSL.cpp: (WebCore::defaultWebCryptoMasterKey): (WebCore::getDefaultWebCryptoMasterKey): Deleted. Update for new defaultWebCryptoMasterKey() signature. * fileapi/FileReaderLoader.cpp: (WebCore::FileReaderLoader::convertToDataURL): Update to use new base64EncodeToString(). * inspector/DOMPatchSupport.cpp: (WebCore::DOMPatchSupport::createDigest): Update to use new base64EncodeToString(). * inspector/InspectorFrontendHost.cpp: (WebCore::InspectorFrontendHost::showCertificate): Update to use new base64URLDecode / base64URLEncodeToString(). * inspector/NetworkResourcesData.cpp: (WebCore::NetworkResourcesData::ResourceData::decodeDataToContent): Update to use new base64EncodeToString(). * inspector/agents/InspectorDOMAgent.cpp: (WebCore::computeContentSecurityPolicySHA256Hash): Update to use new base64Decode / base64EncodeToString(). * inspector/agents/InspectorNetworkAgent.cpp: (WebCore::Inspector::buildWebSocketMessage): (WebCore::InspectorNetworkAgent::didReceiveData): (WebCore::InspectorNetworkAgent::getSerializedCertificate): (WebCore::InspectorNetworkAgent::interceptWithRequest): (WebCore::InspectorNetworkAgent::interceptWithResponse): (WebCore::InspectorNetworkAgent::interceptRequestWithResponse): (WebCore::InspectorNetworkAgent::cachedResourceContent): Update to use new base64Decode / base64EncodeToString(). * inspector/agents/InspectorPageAgent.cpp: (WebCore::InspectorPageAgent::dataContent): (WebCore::InspectorPageAgent::archive): Update to use new base64EncodeToString(). * loader/FrameLoader.cpp: (WebCore::FrameLoader::loadResourceSynchronously): Switch to using Vector<uint8_t> buffer to match new loadResourceSynchronously signature. * loader/LoaderStrategy.h: Switch to using Vector<uint8_t> for the data buffer. * loader/PrivateClickMeasurement.cpp: (WebCore::PrivateClickMeasurement::EphemeralSourceNonce::isValid const): Update to use new base64URLDecode. * loader/ResourceCryptographicDigest.cpp: (WebCore::parseCryptographicDigestImpl): (WebCore::decodeEncodedResourceCryptographicDigest): Update to use new base64Decode. * loader/archive/mhtml/MHTMLArchive.cpp: (WebCore::MHTMLArchive::generateMHTMLData): Switch to using new base64Encode and new quotedPrintableEncode. * loader/archive/mhtml/MHTMLParser.cpp: (WebCore::MHTMLParser::parseNextPart): Switch to using new base64Decode and new quotedPrintableDecode. * loader/cocoa/PrivateClickMeasurementCocoa.mm: (WebCore::PrivateClickMeasurement::calculateAndUpdateSourceUnlinkableToken): (WebCore::PrivateClickMeasurement::calculateAndUpdateSourceSecretToken): Update to use new base64URLDecode / base64URLEncodeToString(). * page/Base64Utilities.cpp: (WebCore::Base64Utilities::btoa): (WebCore::Base64Utilities::atob): Update to use new base64Decode / base64EncodeToString(). * page/Page.cpp: (WebCore::Page::userStyleSheetLocationChanged): Update to use new base64Decode. * platform/SharedBuffer.cpp: (WebCore::SharedBuffer::append): * platform/SharedBuffer.h: Add overload for append which allows passing in a uint8_t*. * platform/encryptedmedia/clearkey/CDMClearKey.cpp: (WebCore::parseLicenseFormat): (WebCore::extractKeyidsFromCencInitData): (WebCore::extractKeyIdFromWebMInitData): (WebCore::CDMInstanceSessionClearKey::removeSessionData): Update to use new base64URLDecode / base64URLEncodeToString(). * platform/graphics/avfoundation/CDMFairPlayStreaming.cpp: (WebCore::extractSinfData): Update to use new base64Decode. * platform/graphics/avfoundation/objc/CDMInstanceFairPlayStreamingAVFObjC.mm: (WebCore::CDMInstanceSessionFairPlayStreamingAVFObjC::requestLicense): (WebCore::CDMInstanceSessionFairPlayStreamingAVFObjC::updateLicense): (WebCore::CDMInstanceSessionFairPlayStreamingAVFObjC::didProvideRequests): Update to use new base64Decode / base64EncodeToString(). * platform/graphics/cairo/ImageBufferCairoBackend.cpp: (WebCore::ImageBufferCairoBackend::toDataURL const): Update to use new base64EncodeToString(). * platform/graphics/cg/ImageBufferUtilitiesCG.cpp: (WebCore::dataURL): Update to use new base64EncodeToString(). * platform/graphics/win/FontCustomPlatformData.cpp: (WebCore::createUniqueFontName): Update to use new base64EncodeToString(). * platform/graphics/win/FontCustomPlatformDataCairo.cpp: (WebCore::createUniqueFontName): Update to use new base64EncodeToString(). * platform/mac/SSLKeyGeneratorMac.mm: (WebCore::signedPublicKeyAndChallengeString): Update to use new base64EncodeToString(). * platform/network/BlobRegistryImpl.cpp: (WebCore::loadBlobResourceSynchronously): Switch to using Vector<uint8_t> buffer to match new loadResourceSynchronously signature. * platform/network/BlobResourceHandle.cpp: * platform/network/BlobResourceHandle.h: (WebCore::BlobResourceHandle::loadResourceSynchronously): Switch to using Vector<uint8_t> buffer to match new loadResourceSynchronously signature. * platform/network/CredentialBase.cpp: * platform/network/CredentialBase.h: (WebCore::CredentialBase::serializationForBasicAuthorizationHeader const): Add helper to construct Basic auth header to replace duplicated logic in call sites. * platform/network/DataURLDecoder.cpp: (WebCore::DataURLDecoder::decodeBase64): (WebCore::DataURLDecoder::decodeEscaped): (WebCore::DataURLDecoder::decodeSynchronously): * platform/network/DataURLDecoder.h: Update to use new base64Decode. * platform/network/ResourceHandle.cpp: * platform/network/ResourceHandle.h: Switch to using Vector<uint8_t> for the data buffer in the synchronous load. * platform/network/SynchronousLoaderClient.cpp: (WebCore::SynchronousLoaderClient::didReceiveData): * platform/network/SynchronousLoaderClient.h: Switch to using Vector<uint8_t> buffer to match new loadResourceSynchronously signature. * platform/network/cf/ResourceHandleCFNet.cpp: (WebCore::applyBasicAuthorizationHeader): Use new serializationForBasicAuthorizationHeader() helper. (WebCore::ResourceHandle::platformLoadResourceSynchronously): Switch to using Vector<uint8_t> for the data buffer in the synchronous load. * platform/network/curl/ResourceHandleCurl.cpp: (WebCore::ResourceHandle::platformLoadResourceSynchronously): (WebCore::ResourceHandle::handleDataURL): Switch to using Vector<uint8_t> for the data buffer in the synchronous load. * platform/network/mac/ResourceHandleMac.mm: (WebCore::applyBasicAuthorizationHeader): Use new serializationForBasicAuthorizationHeader() helper. (WebCore::ResourceHandle::platformLoadResourceSynchronously): Switch to using Vector<uint8_t> for the data buffer in the synchronous load. * platform/network/soup/ResourceHandleSoup.cpp: (WebCore::ResourceHandle::platformLoadResourceSynchronously): Switch to using Vector<uint8_t> for the data buffer in the synchronous load. * platform/network/soup/SoupNetworkSession.cpp: (WebCore::HostTLSCertificateSet::computeCertificateHash): Update to use new base64EncodeToString(). * platform/text/DecodeEscapeSequences.h: (WebCore::decodeURLEscapeSequencesAsData): Switch to returning Vector<uint8_t>. * platform/text/QuotedPrintable.cpp: * platform/text/QuotedPrintable.h: (WebCore::lengthOfLineEndingAtIndex): (WebCore::quotedPrintableEncode): (WebCore::quotedPrintableDecode): Replace uses of Vector<char> with Vector<uint8_t> and the out parameters with Optional return values. * platform/win/SSLKeyGeneratorWin.cpp: (WebCore::signedPublicKeyAndChallengeString): Update to use new base64EncodeToString(). * workers/service/server/SWScriptStorage.cpp: (WebCore::SWScriptStorage::sha2Hash const): Update to use new base64URLEncodeToString(). Source/WebKit: * NetworkProcess/NetworkConnectionToWebProcess.messages.in: * UIProcess/API/C/WKPage.cpp: (WKPageSetPageNavigationClient): * UIProcess/WebPageProxy.messages.in: * UIProcess/WebURLSchemeHandler.h: * UIProcess/WebURLSchemeTask.cpp: (WebKit::WebURLSchemeTask::didComplete): * UIProcess/WebURLSchemeTask.h: * WebProcess/Network/WebLoaderStrategy.cpp: (WebKit::WebLoaderStrategy::loadResourceSynchronously): * WebProcess/Network/WebLoaderStrategy.h: * WebProcess/WebPage/WebURLSchemeHandlerProxy.cpp: (WebKit::WebURLSchemeHandlerProxy::loadSynchronously): * WebProcess/WebPage/WebURLSchemeHandlerProxy.h: Update to use uint8_t* data buffers more consistently for synchronous loads. * NetworkProcess/NetworkResourceLoader.cpp: (WebKit::sendReplyToSynchronousRequest): Update to use uint8_t* data buffers more consistently for synchronous loads. * NetworkProcess/PrivateClickMeasurementManager.cpp: (WebKit::PrivateClickMeasurementManager::fireConversionRequest): Update to use new base64URLDecode / base64URLEncodeToString(). * NetworkProcess/cocoa/NetworkDataTaskCocoa.mm: (WebKit::applyBasicAuthorizationHeader): Use new serializationForBasicAuthorizationHeader() helper. * Shared/API/APIData.h: (API::Data::create): (API::Data::fastFreeBytes): Deleted. Add new create function that takes ownership of a Vector's buffer rather than copying it. Replace use of static functions with inline lambdas for free-functions. * Shared/mac/AuxiliaryProcessMac.mm: (WebKit::sandboxFilePath): Use makeString and new base64URLEncoded(). * UIProcess/API/Cocoa/_WKWebAuthenticationPanel.mm: (produceClientDataJson): Use new base64URLEncodeToString(). * UIProcess/Automation/cairo/WebAutomationSessionCairo.cpp: (WebKit::base64EncodedPNGData): Use new base64EncodeToString(). * UIProcess/Cocoa/NavigationState.mm: (WebKit::NavigationState::NavigationClient::webCryptoMasterKey): Use new defaultWebCryptoMasterKey() and new adopting API::Data::create function. * UIProcess/Inspector/glib/RemoteInspectorClient.cpp: (WebKit::RemoteInspectorClient::setBackendCommands): Use new base64EncodeToString(). * UIProcess/Inspector/gtk/RemoteWebInspectorUIProxyGtk.cpp: (WebKit::RemoteWebInspectorUIProxy::platformSave): Use new base64Decode(). * UIProcess/Inspector/gtk/WebInspectorUIProxyGtk.cpp: (WebKit::WebInspectorUIProxy::platformSave): Use new base64Decode(). * UIProcess/Inspector/mac/RemoteWebInspectorUIProxyMac.mm: (WebKit::RemoteWebInspectorUIProxy::platformSave): Use new base64Decode(). * UIProcess/Inspector/mac/WebInspectorUIProxyMac.mm: (WebKit::WebInspectorUIProxy::platformSave): Use new base64Decode(). * UIProcess/Inspector/socket/RemoteInspectorClient.cpp: (WebKit::RemoteInspectorClient::setBackendCommands): Use new base64EncodeToString(). * UIProcess/WebAuthentication/Cocoa/LocalAuthenticator.mm: (WebKit::LocalAuthenticatorInternal::produceHashSet): (WebKit::LocalAuthenticator::makeCredential): (WebKit::LocalAuthenticator::getAssertion): Use new base64EncodeToString(). * UIProcess/WebAuthentication/Mock/MockHidConnection.cpp: (WebKit::MockHidConnection::feedReports): Use new base64Decode(). * UIProcess/WebAuthentication/Mock/MockLocalConnection.mm: (WebKit::MockLocalConnection::filterResponses const): Use new base64EncodeToString(). Source/WebKitLegacy: * WebCoreSupport/WebResourceLoadScheduler.cpp: (WebResourceLoadScheduler::loadResourceSynchronously): * WebCoreSupport/WebResourceLoadScheduler.h: Update to match new signature. char -> uint8_t. Source/WebKitLegacy/mac: * WebCoreSupport/WebChromeClient.mm: (WebChromeClient::wrapCryptoKey const): (WebChromeClient::unwrapCryptoKey const): Update to use new Optional returning defaultWebCryptoMasterKey(). * WebCoreSupport/WebInspectorClient.mm: (WebInspectorFrontendClient::save): Update to use new Optional returning base64Decode(). Source/WTF: Bring base64 encoding/decoding up to more modern WebKit conventions by: - Replace use of "out parameter + bool" with Optional return values. - Using enum class for enumerations. - Replacing SignedOrUnsignedCharVectorAdapter/ConstSignedOrUnsignedCharVectorAdapter with appropriate function overloads. Also adds a new StringTypeAdapter for inline base64 encoding data in either makeString() or StringBuilder. To make this work, a few modifications were need to the base64Encode() functions to support the fixed size writeTo() function. First, the length of the encoded data is now computed up front depending on the policy. This has been extracted into a new calculateBase64EncodedSize() function used by both the adaptor and by base64Encode when passed a Vector. Previously, when encoding using some policies, the size was an overestimate and the resulting Vector would be resized down after encoding. Second, base64EncodeInternal was made into a template function to allow for two new base64Encode functions, one of which has a UChar* destination. These are used by the adaptor to write the encoded data. One additional small change is that now a optional map type parameter has been added to all the encoders to allow using either the default map or the URL one as defined in RFC 4648. This simplifies the implementation of the StringTypeAdapter and makes the base64URLEncode/base64URLDecode functions into simple convenience functions that use the right defaults for the generic encode/decode functions. * wtf/text/Base64.cpp: (WTF::base64EncodeInternal): (WTF::base64Encode): (WTF::base64DecodeInternal): (WTF::base64Decode): (WTF::base64URLDecode): (WTF::base64URLEncode): Deleted. * wtf/text/Base64.h: (WTF::base64Decode): (WTF::base64Encode): (WTF::base64URLEncode): (WTF::isBase64OrBase64URLCharacter): (WTF::calculateBase64EncodedSize): (WTF::base64Encoded): (WTF::base64URLEncoded): (WTF::StringTypeAdapter<Base64Specification>::StringTypeAdapter): (WTF::StringTypeAdapter<Base64Specification>::length const): (WTF::StringTypeAdapter<Base64Specification>::is8Bit const): (WTF::StringTypeAdapter<Base64Specification>::writeTo const): Tools: Update to use updated base64 and defaultWebCryptoMasterKey() related functions. * TestWebKitAPI/TCPServer.cpp: (TestWebKitAPI::TCPServer::startSecureConnection): (TestWebKitAPI::TCPServer::testCertificate): (TestWebKitAPI::TCPServer::testPrivateKey): * TestWebKitAPI/Tests/WebCore/ISOBox.cpp: (TestWebKitAPI::TEST): * TestWebKitAPI/Tests/WebCore/cocoa/PrivateClickMeasurementCocoa.mm: (TestWebKitAPI::TEST): * TestWebKitAPI/Tests/WebCore/cocoa/SerializedCryptoKeyWrap.mm: (TestWebKitAPI::TEST_F): * TestWebKitAPI/Tests/WebKitCocoa/Challenge.mm: (testIdentity2): * TestWebKitAPI/Tests/WebKitCocoa/EventAttribution.mm: (TestWebKitAPI::TEST): * TestWebKitAPI/Tests/mac/SSLKeyGenerator.mm: (TestWebKitAPI::TEST_F): * TestWebKitAPI/cocoa/HTTPServer.mm: (TestWebKitAPI::Connection::webSocketHandshake): Canonical link: https://commits.webkit.org/237912@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@277740 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-05-19 18:43:29 +00:00
auto decodedData = base64Decode(encodedString, { Base64DecodeOptions::ValidatePadding, Base64DecodeOptions::IgnoreSpacesAndNewLines, Base64DecodeOptions::DiscardVerticalTab });
if (!decodedData)
return Exception { InvalidCharacterError };
Update Base64 encoding/decoding to match more modern WebKit conventions https://bugs.webkit.org/show_bug.cgi?id=225920 Reviewed by Chris Dumez. Source/WebCore: - Updates to use new signatures for base64 encoding/decoding including utilizing the string type adaptor and makeString. - Replace out parameter based getDefaultWebCryptoMasterKey() with Optional<Vector<uint8_t>> defaultWebCryptoMasterKey(). - Update synchronous loading code path to use uint8_t* consistently for data buffer representation. - Replace out parameters in quotedPrintableEncode/quotedPrintableDecode with Optional. * Modules/encryptedmedia/InitDataRegistry.cpp: (WebCore::extractKeyIDsKeyids): Update to use new base64URLDecode. (WebCore::sanitizeKeyids): Update to use new base64URLEncodeToString() * Modules/encryptedmedia/legacy/LegacyCDMSessionClearKey.cpp: (WebCore::CDMSessionClearKey::update): Update to use new base64Decode(). * Modules/plugins/QuickTimePluginReplacement.mm: (WebCore::jsValueWithDataInContext): (WebCore::jsValueWithAVMetadataItemInContext): Update to use new base64EncodeToString(). Replace string concatentation using operator+ with makeString(). * Modules/webauthn/AuthenticatorCoordinator.cpp: (WebCore::AuthenticatorCoordinatorInternal::produceClientDataJson): Update to use new base64URLEncodeToString(). * Modules/webauthn/PublicKeyCredential.cpp: (WebCore::PublicKeyCredential::PublicKeyCredential): Update to use new base64URLEncodeToString(). * Modules/websockets/WebSocketHandshake.cpp: (WebCore::generateSecWebSocketKey): (WebCore::WebSocketHandshake::getExpectedWebSocketAccept): Update to use new base64URLEncodeToString(). * crypto/SerializedCryptoKeyWrap.h: Change from outparameter based getDefaultWebCryptoMasterKey() to new Optional<Vector<uint8_t>> defaultWebCryptoMasterKey(). * crypto/gcrypt/CryptoKeyECGCrypt.cpp: (WebCore::CryptoKeyEC::platformAddFieldElements const): Update to use new base64URLEncodeToString(). * crypto/gcrypt/SerializedCryptoKeyWrapGCrypt.cpp: (WebCore::defaultWebCryptoMasterKey): (WebCore::getDefaultWebCryptoMasterKey): Deleted. Update for new defaultWebCryptoMasterKey() signature. * crypto/keys/CryptoKeyAES.cpp: (WebCore::CryptoKeyAES::importJwk): (WebCore::CryptoKeyAES::exportJwk const): Update to use new base64URLDecode / base64URLEncodeToString(). * crypto/keys/CryptoKeyEC.cpp: (WebCore::CryptoKeyEC::importJwk): Update to use new base64URLDecode. * crypto/keys/CryptoKeyHMAC.cpp: (WebCore::CryptoKeyHMAC::importJwk): (WebCore::CryptoKeyHMAC::exportJwk const): Update to use new base64URLDecode / base64URLEncodeToString(). * crypto/keys/CryptoKeyRSA.cpp: (WebCore::CryptoKeyRSA::importJwk): (WebCore::CryptoKeyRSA::exportJwk const): Update to use new base64URLDecode / base64URLEncodeToString(). * crypto/mac/CryptoKeyECMac.cpp: (WebCore::CryptoKeyEC::platformAddFieldElements const): Update to use new base64URLEncodeToString(). * crypto/mac/SerializedCryptoKeyWrapMac.mm: (WebCore::createAndStoreMasterKey): (WebCore::findMasterKey): (WebCore::defaultWebCryptoMasterKey): (WebCore::getDefaultWebCryptoMasterKey): Deleted. Update for new defaultWebCryptoMasterKey() signature. * crypto/openssl/SerializedCryptoKeyWrapOpenSSL.cpp: (WebCore::defaultWebCryptoMasterKey): (WebCore::getDefaultWebCryptoMasterKey): Deleted. Update for new defaultWebCryptoMasterKey() signature. * fileapi/FileReaderLoader.cpp: (WebCore::FileReaderLoader::convertToDataURL): Update to use new base64EncodeToString(). * inspector/DOMPatchSupport.cpp: (WebCore::DOMPatchSupport::createDigest): Update to use new base64EncodeToString(). * inspector/InspectorFrontendHost.cpp: (WebCore::InspectorFrontendHost::showCertificate): Update to use new base64URLDecode / base64URLEncodeToString(). * inspector/NetworkResourcesData.cpp: (WebCore::NetworkResourcesData::ResourceData::decodeDataToContent): Update to use new base64EncodeToString(). * inspector/agents/InspectorDOMAgent.cpp: (WebCore::computeContentSecurityPolicySHA256Hash): Update to use new base64Decode / base64EncodeToString(). * inspector/agents/InspectorNetworkAgent.cpp: (WebCore::Inspector::buildWebSocketMessage): (WebCore::InspectorNetworkAgent::didReceiveData): (WebCore::InspectorNetworkAgent::getSerializedCertificate): (WebCore::InspectorNetworkAgent::interceptWithRequest): (WebCore::InspectorNetworkAgent::interceptWithResponse): (WebCore::InspectorNetworkAgent::interceptRequestWithResponse): (WebCore::InspectorNetworkAgent::cachedResourceContent): Update to use new base64Decode / base64EncodeToString(). * inspector/agents/InspectorPageAgent.cpp: (WebCore::InspectorPageAgent::dataContent): (WebCore::InspectorPageAgent::archive): Update to use new base64EncodeToString(). * loader/FrameLoader.cpp: (WebCore::FrameLoader::loadResourceSynchronously): Switch to using Vector<uint8_t> buffer to match new loadResourceSynchronously signature. * loader/LoaderStrategy.h: Switch to using Vector<uint8_t> for the data buffer. * loader/PrivateClickMeasurement.cpp: (WebCore::PrivateClickMeasurement::EphemeralSourceNonce::isValid const): Update to use new base64URLDecode. * loader/ResourceCryptographicDigest.cpp: (WebCore::parseCryptographicDigestImpl): (WebCore::decodeEncodedResourceCryptographicDigest): Update to use new base64Decode. * loader/archive/mhtml/MHTMLArchive.cpp: (WebCore::MHTMLArchive::generateMHTMLData): Switch to using new base64Encode and new quotedPrintableEncode. * loader/archive/mhtml/MHTMLParser.cpp: (WebCore::MHTMLParser::parseNextPart): Switch to using new base64Decode and new quotedPrintableDecode. * loader/cocoa/PrivateClickMeasurementCocoa.mm: (WebCore::PrivateClickMeasurement::calculateAndUpdateSourceUnlinkableToken): (WebCore::PrivateClickMeasurement::calculateAndUpdateSourceSecretToken): Update to use new base64URLDecode / base64URLEncodeToString(). * page/Base64Utilities.cpp: (WebCore::Base64Utilities::btoa): (WebCore::Base64Utilities::atob): Update to use new base64Decode / base64EncodeToString(). * page/Page.cpp: (WebCore::Page::userStyleSheetLocationChanged): Update to use new base64Decode. * platform/SharedBuffer.cpp: (WebCore::SharedBuffer::append): * platform/SharedBuffer.h: Add overload for append which allows passing in a uint8_t*. * platform/encryptedmedia/clearkey/CDMClearKey.cpp: (WebCore::parseLicenseFormat): (WebCore::extractKeyidsFromCencInitData): (WebCore::extractKeyIdFromWebMInitData): (WebCore::CDMInstanceSessionClearKey::removeSessionData): Update to use new base64URLDecode / base64URLEncodeToString(). * platform/graphics/avfoundation/CDMFairPlayStreaming.cpp: (WebCore::extractSinfData): Update to use new base64Decode. * platform/graphics/avfoundation/objc/CDMInstanceFairPlayStreamingAVFObjC.mm: (WebCore::CDMInstanceSessionFairPlayStreamingAVFObjC::requestLicense): (WebCore::CDMInstanceSessionFairPlayStreamingAVFObjC::updateLicense): (WebCore::CDMInstanceSessionFairPlayStreamingAVFObjC::didProvideRequests): Update to use new base64Decode / base64EncodeToString(). * platform/graphics/cairo/ImageBufferCairoBackend.cpp: (WebCore::ImageBufferCairoBackend::toDataURL const): Update to use new base64EncodeToString(). * platform/graphics/cg/ImageBufferUtilitiesCG.cpp: (WebCore::dataURL): Update to use new base64EncodeToString(). * platform/graphics/win/FontCustomPlatformData.cpp: (WebCore::createUniqueFontName): Update to use new base64EncodeToString(). * platform/graphics/win/FontCustomPlatformDataCairo.cpp: (WebCore::createUniqueFontName): Update to use new base64EncodeToString(). * platform/mac/SSLKeyGeneratorMac.mm: (WebCore::signedPublicKeyAndChallengeString): Update to use new base64EncodeToString(). * platform/network/BlobRegistryImpl.cpp: (WebCore::loadBlobResourceSynchronously): Switch to using Vector<uint8_t> buffer to match new loadResourceSynchronously signature. * platform/network/BlobResourceHandle.cpp: * platform/network/BlobResourceHandle.h: (WebCore::BlobResourceHandle::loadResourceSynchronously): Switch to using Vector<uint8_t> buffer to match new loadResourceSynchronously signature. * platform/network/CredentialBase.cpp: * platform/network/CredentialBase.h: (WebCore::CredentialBase::serializationForBasicAuthorizationHeader const): Add helper to construct Basic auth header to replace duplicated logic in call sites. * platform/network/DataURLDecoder.cpp: (WebCore::DataURLDecoder::decodeBase64): (WebCore::DataURLDecoder::decodeEscaped): (WebCore::DataURLDecoder::decodeSynchronously): * platform/network/DataURLDecoder.h: Update to use new base64Decode. * platform/network/ResourceHandle.cpp: * platform/network/ResourceHandle.h: Switch to using Vector<uint8_t> for the data buffer in the synchronous load. * platform/network/SynchronousLoaderClient.cpp: (WebCore::SynchronousLoaderClient::didReceiveData): * platform/network/SynchronousLoaderClient.h: Switch to using Vector<uint8_t> buffer to match new loadResourceSynchronously signature. * platform/network/cf/ResourceHandleCFNet.cpp: (WebCore::applyBasicAuthorizationHeader): Use new serializationForBasicAuthorizationHeader() helper. (WebCore::ResourceHandle::platformLoadResourceSynchronously): Switch to using Vector<uint8_t> for the data buffer in the synchronous load. * platform/network/curl/ResourceHandleCurl.cpp: (WebCore::ResourceHandle::platformLoadResourceSynchronously): (WebCore::ResourceHandle::handleDataURL): Switch to using Vector<uint8_t> for the data buffer in the synchronous load. * platform/network/mac/ResourceHandleMac.mm: (WebCore::applyBasicAuthorizationHeader): Use new serializationForBasicAuthorizationHeader() helper. (WebCore::ResourceHandle::platformLoadResourceSynchronously): Switch to using Vector<uint8_t> for the data buffer in the synchronous load. * platform/network/soup/ResourceHandleSoup.cpp: (WebCore::ResourceHandle::platformLoadResourceSynchronously): Switch to using Vector<uint8_t> for the data buffer in the synchronous load. * platform/network/soup/SoupNetworkSession.cpp: (WebCore::HostTLSCertificateSet::computeCertificateHash): Update to use new base64EncodeToString(). * platform/text/DecodeEscapeSequences.h: (WebCore::decodeURLEscapeSequencesAsData): Switch to returning Vector<uint8_t>. * platform/text/QuotedPrintable.cpp: * platform/text/QuotedPrintable.h: (WebCore::lengthOfLineEndingAtIndex): (WebCore::quotedPrintableEncode): (WebCore::quotedPrintableDecode): Replace uses of Vector<char> with Vector<uint8_t> and the out parameters with Optional return values. * platform/win/SSLKeyGeneratorWin.cpp: (WebCore::signedPublicKeyAndChallengeString): Update to use new base64EncodeToString(). * workers/service/server/SWScriptStorage.cpp: (WebCore::SWScriptStorage::sha2Hash const): Update to use new base64URLEncodeToString(). Source/WebKit: * NetworkProcess/NetworkConnectionToWebProcess.messages.in: * UIProcess/API/C/WKPage.cpp: (WKPageSetPageNavigationClient): * UIProcess/WebPageProxy.messages.in: * UIProcess/WebURLSchemeHandler.h: * UIProcess/WebURLSchemeTask.cpp: (WebKit::WebURLSchemeTask::didComplete): * UIProcess/WebURLSchemeTask.h: * WebProcess/Network/WebLoaderStrategy.cpp: (WebKit::WebLoaderStrategy::loadResourceSynchronously): * WebProcess/Network/WebLoaderStrategy.h: * WebProcess/WebPage/WebURLSchemeHandlerProxy.cpp: (WebKit::WebURLSchemeHandlerProxy::loadSynchronously): * WebProcess/WebPage/WebURLSchemeHandlerProxy.h: Update to use uint8_t* data buffers more consistently for synchronous loads. * NetworkProcess/NetworkResourceLoader.cpp: (WebKit::sendReplyToSynchronousRequest): Update to use uint8_t* data buffers more consistently for synchronous loads. * NetworkProcess/PrivateClickMeasurementManager.cpp: (WebKit::PrivateClickMeasurementManager::fireConversionRequest): Update to use new base64URLDecode / base64URLEncodeToString(). * NetworkProcess/cocoa/NetworkDataTaskCocoa.mm: (WebKit::applyBasicAuthorizationHeader): Use new serializationForBasicAuthorizationHeader() helper. * Shared/API/APIData.h: (API::Data::create): (API::Data::fastFreeBytes): Deleted. Add new create function that takes ownership of a Vector's buffer rather than copying it. Replace use of static functions with inline lambdas for free-functions. * Shared/mac/AuxiliaryProcessMac.mm: (WebKit::sandboxFilePath): Use makeString and new base64URLEncoded(). * UIProcess/API/Cocoa/_WKWebAuthenticationPanel.mm: (produceClientDataJson): Use new base64URLEncodeToString(). * UIProcess/Automation/cairo/WebAutomationSessionCairo.cpp: (WebKit::base64EncodedPNGData): Use new base64EncodeToString(). * UIProcess/Cocoa/NavigationState.mm: (WebKit::NavigationState::NavigationClient::webCryptoMasterKey): Use new defaultWebCryptoMasterKey() and new adopting API::Data::create function. * UIProcess/Inspector/glib/RemoteInspectorClient.cpp: (WebKit::RemoteInspectorClient::setBackendCommands): Use new base64EncodeToString(). * UIProcess/Inspector/gtk/RemoteWebInspectorUIProxyGtk.cpp: (WebKit::RemoteWebInspectorUIProxy::platformSave): Use new base64Decode(). * UIProcess/Inspector/gtk/WebInspectorUIProxyGtk.cpp: (WebKit::WebInspectorUIProxy::platformSave): Use new base64Decode(). * UIProcess/Inspector/mac/RemoteWebInspectorUIProxyMac.mm: (WebKit::RemoteWebInspectorUIProxy::platformSave): Use new base64Decode(). * UIProcess/Inspector/mac/WebInspectorUIProxyMac.mm: (WebKit::WebInspectorUIProxy::platformSave): Use new base64Decode(). * UIProcess/Inspector/socket/RemoteInspectorClient.cpp: (WebKit::RemoteInspectorClient::setBackendCommands): Use new base64EncodeToString(). * UIProcess/WebAuthentication/Cocoa/LocalAuthenticator.mm: (WebKit::LocalAuthenticatorInternal::produceHashSet): (WebKit::LocalAuthenticator::makeCredential): (WebKit::LocalAuthenticator::getAssertion): Use new base64EncodeToString(). * UIProcess/WebAuthentication/Mock/MockHidConnection.cpp: (WebKit::MockHidConnection::feedReports): Use new base64Decode(). * UIProcess/WebAuthentication/Mock/MockLocalConnection.mm: (WebKit::MockLocalConnection::filterResponses const): Use new base64EncodeToString(). Source/WebKitLegacy: * WebCoreSupport/WebResourceLoadScheduler.cpp: (WebResourceLoadScheduler::loadResourceSynchronously): * WebCoreSupport/WebResourceLoadScheduler.h: Update to match new signature. char -> uint8_t. Source/WebKitLegacy/mac: * WebCoreSupport/WebChromeClient.mm: (WebChromeClient::wrapCryptoKey const): (WebChromeClient::unwrapCryptoKey const): Update to use new Optional returning defaultWebCryptoMasterKey(). * WebCoreSupport/WebInspectorClient.mm: (WebInspectorFrontendClient::save): Update to use new Optional returning base64Decode(). Source/WTF: Bring base64 encoding/decoding up to more modern WebKit conventions by: - Replace use of "out parameter + bool" with Optional return values. - Using enum class for enumerations. - Replacing SignedOrUnsignedCharVectorAdapter/ConstSignedOrUnsignedCharVectorAdapter with appropriate function overloads. Also adds a new StringTypeAdapter for inline base64 encoding data in either makeString() or StringBuilder. To make this work, a few modifications were need to the base64Encode() functions to support the fixed size writeTo() function. First, the length of the encoded data is now computed up front depending on the policy. This has been extracted into a new calculateBase64EncodedSize() function used by both the adaptor and by base64Encode when passed a Vector. Previously, when encoding using some policies, the size was an overestimate and the resulting Vector would be resized down after encoding. Second, base64EncodeInternal was made into a template function to allow for two new base64Encode functions, one of which has a UChar* destination. These are used by the adaptor to write the encoded data. One additional small change is that now a optional map type parameter has been added to all the encoders to allow using either the default map or the URL one as defined in RFC 4648. This simplifies the implementation of the StringTypeAdapter and makes the base64URLEncode/base64URLDecode functions into simple convenience functions that use the right defaults for the generic encode/decode functions. * wtf/text/Base64.cpp: (WTF::base64EncodeInternal): (WTF::base64Encode): (WTF::base64DecodeInternal): (WTF::base64Decode): (WTF::base64URLDecode): (WTF::base64URLEncode): Deleted. * wtf/text/Base64.h: (WTF::base64Decode): (WTF::base64Encode): (WTF::base64URLEncode): (WTF::isBase64OrBase64URLCharacter): (WTF::calculateBase64EncodedSize): (WTF::base64Encoded): (WTF::base64URLEncoded): (WTF::StringTypeAdapter<Base64Specification>::StringTypeAdapter): (WTF::StringTypeAdapter<Base64Specification>::length const): (WTF::StringTypeAdapter<Base64Specification>::is8Bit const): (WTF::StringTypeAdapter<Base64Specification>::writeTo const): Tools: Update to use updated base64 and defaultWebCryptoMasterKey() related functions. * TestWebKitAPI/TCPServer.cpp: (TestWebKitAPI::TCPServer::startSecureConnection): (TestWebKitAPI::TCPServer::testCertificate): (TestWebKitAPI::TCPServer::testPrivateKey): * TestWebKitAPI/Tests/WebCore/ISOBox.cpp: (TestWebKitAPI::TEST): * TestWebKitAPI/Tests/WebCore/cocoa/PrivateClickMeasurementCocoa.mm: (TestWebKitAPI::TEST): * TestWebKitAPI/Tests/WebCore/cocoa/SerializedCryptoKeyWrap.mm: (TestWebKitAPI::TEST_F): * TestWebKitAPI/Tests/WebKitCocoa/Challenge.mm: (testIdentity2): * TestWebKitAPI/Tests/WebKitCocoa/EventAttribution.mm: (TestWebKitAPI::TEST): * TestWebKitAPI/Tests/mac/SSLKeyGenerator.mm: (TestWebKitAPI::TEST_F): * TestWebKitAPI/cocoa/HTTPServer.mm: (TestWebKitAPI::Connection::webSocketHandshake): Canonical link: https://commits.webkit.org/237912@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@277740 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-05-19 18:43:29 +00:00
return String(decodedData->data(), decodedData->size());
}
}