Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial Stubs for Compression Streams API
https://bugs.webkit.org/show_bug.cgi?id=241964 Reviewed by Alex Christensen and Brent Fulgham. Implement initial stubs for Compression Streams API. * Source/WTF/Scripts/Preferences/WebPreferencesExperimental.yaml: * Source/WebCore/CMakeLists.txt: * Source/WebCore/DerivedSources-input.xcfilelist: * Source/WebCore/DerivedSources-output.xcfilelist: * Source/WebCore/DerivedSources.make: * Source/WebCore/Headers.cmake: * Source/WebCore/Modules/compression/CompressionStream.cpp: Added. (WebCore::CompressionStream::createStreams): (WebCore::CompressionStream::readable): (WebCore::CompressionStream::writable): * Source/WebCore/Modules/compression/CompressionStream.h: Added. (WebCore::CompressionStream::~CompressionStream): (WebCore::CompressionStream::create): (WebCore::CompressionStream::getCompressionFormat): (WebCore::CompressionStream::CompressionStream): * Source/WebCore/Modules/compression/CompressionStream.idl: Added. * Source/WebCore/Modules/compression/DecompressionStream.cpp: Added. (WebCore::DecompressionStream::createStreams): (WebCore::DecompressionStream::readable): (WebCore::DecompressionStream::writable): * Source/WebCore/Modules/compression/DecompressionStream.h: Added. (WebCore::DecompressionStream::~DecompressionStream): (WebCore::DecompressionStream::create): (WebCore::DecompressionStream::getCompressionFormat): (WebCore::DecompressionStream::DecompressionStream): * Source/WebCore/Modules/compression/DecompressionStream.idl: Added. * Source/WebCore/Modules/compression/Formats.h: Added. * Source/WebCore/Modules/streams/GenericTransformStream.idl: Added. * Source/WebCore/Modules/websockets/WebSocket.cpp: * Source/WebCore/Sources.txt: * Source/WebCore/WebCore.xcodeproj/project.pbxproj: * Source/WebCore/bindings/js/WebCoreBuiltinNames.h: * Source/WebCore/dom/EventTargetFactory.in: * Source/WebCore/features.json: Canonical link: https://commits.webkit.org/252071@main
- Loading branch information
Showing
20 changed files
with
643 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* Copyright (C) 2022 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 "CompressionStream.h" | ||
|
||
#include "ScriptExecutionContext.h" | ||
#include "WritableStreamSink.h" | ||
#include <wtf/IsoMalloc.h> | ||
#include <wtf/IsoMallocInlines.h> | ||
#include <wtf/WeakPtr.h> | ||
|
||
namespace WebCore { | ||
|
||
WTF_MAKE_ISO_ALLOCATED_IMPL(CompressionStream); | ||
|
||
ExceptionOr<void> CompressionStream::createStreams() | ||
{ | ||
// get global object | ||
auto* globalObject = scriptExecutionContext() ? scriptExecutionContext()->globalObject() : nullptr; | ||
if (!globalObject) | ||
return Exception { InvalidStateError }; | ||
|
||
// setup readable stream | ||
m_readableStreamSource = SimpleReadableStreamSource::create(); | ||
auto readable = ReadableStream::create(*globalObject, m_readableStreamSource.copyRef()); | ||
if (readable.hasException()) | ||
return readable.releaseException(); | ||
|
||
m_readable = readable.releaseReturnValue(); | ||
|
||
// setup writable stream | ||
auto simpleWritableStreamSink = SimpleWritableStreamSink::create([readableStreamSource = m_readableStreamSource, weakThis = WeakPtr { *this }](auto& context, auto value) -> ExceptionOr<void> { | ||
if (!context.globalObject()) | ||
return Exception { InvalidStateError }; | ||
|
||
UNUSED_PARAM(value); | ||
return { }; | ||
}); | ||
auto writable = WritableStream::create(*JSC::jsCast<JSDOMGlobalObject*>(globalObject), simpleWritableStreamSink); | ||
|
||
m_writable = writable.releaseReturnValue(); | ||
|
||
return { }; | ||
} | ||
|
||
ExceptionOr<RefPtr<ReadableStream>> CompressionStream::readable() | ||
{ | ||
if (!m_readable) { | ||
auto result = createStreams(); | ||
if (result.hasException()) | ||
return result.releaseException(); | ||
} | ||
|
||
return m_readable.copyRef(); | ||
} | ||
|
||
ExceptionOr<RefPtr<WritableStream>> CompressionStream::writable() | ||
{ | ||
if (!m_writable) { | ||
auto result = createStreams(); | ||
if (result.hasException()) | ||
return result.releaseException(); | ||
} | ||
|
||
return m_writable.copyRef(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/* | ||
* Copyright (C) 2022 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. | ||
*/ | ||
|
||
|
||
#pragma once | ||
|
||
#include "ActiveDOMObject.h" | ||
#include "Document.h" | ||
#include "Event.h" | ||
#include "EventTarget.h" | ||
#include "ExceptionOr.h" | ||
#include "Formats.h" | ||
#include "ReadableStream.h" | ||
#include "ReadableStreamSource.h" | ||
#include "ScriptExecutionContext.h" | ||
#include "WritableStream.h" | ||
|
||
#include <wtf/IsoMalloc.h> | ||
#include <wtf/IsoMallocInlines.h> | ||
#include <wtf/RefCounted.h> | ||
#include <wtf/text/WTFString.h> | ||
|
||
namespace JSC { | ||
class CallFrame; | ||
class JSGlobalObject; | ||
class JSValue; | ||
} | ||
|
||
namespace WebCore { | ||
|
||
class CompressionStream : public RefCounted<CompressionStream>, | ||
public ActiveDOMObject, | ||
public EventTargetWithInlineData { | ||
WTF_MAKE_ISO_ALLOCATED(CompressionStream); | ||
|
||
public: | ||
~CompressionStream() { } | ||
|
||
using RefCounted<CompressionStream>::ref; | ||
using RefCounted<CompressionStream>::deref; | ||
|
||
// Initialize readable and writable streams | ||
ExceptionOr<void> createStreams(); | ||
|
||
// Initialize Compression Streams and perform initial basic error handling | ||
static ExceptionOr<Ref<CompressionStream>> create(Document& document, String string) | ||
{ | ||
// gzip, deflate, and deflate-raw are the supported compression formats. | ||
if (string == String("gzip", 4)) | ||
return adoptRef(*new CompressionStream(document, string, Formats::Gzip)); | ||
if (string == String("deflate", 7)) | ||
return adoptRef(*new CompressionStream(document, string, Formats::Deflate)); | ||
if (string == String("deflate-raw", 11)) | ||
return adoptRef(*new CompressionStream(document, string, Formats::Deflate_raw)); | ||
|
||
// Section 5 | ||
// 1. If format is unsupported in CompressionStream, then throw a TypeError. | ||
return Exception(TypeError, "Please provide a supported compression algorithm ('gzip', 'deflate', or 'deflate-raw')."_s); | ||
} | ||
|
||
ExceptionOr<RefPtr<ReadableStream>> readable(); | ||
ExceptionOr<RefPtr<WritableStream>> writable(); | ||
|
||
Formats::CompressionFormat getCompressionFormat() { return m_format; } | ||
|
||
private: | ||
CompressionStream(Document& document, String string, Formats::CompressionFormat format) | ||
: ActiveDOMObject(document), m_string(string), m_format(format) | ||
{ | ||
createStreams(); | ||
} | ||
|
||
// Compression Format | ||
const String m_string; | ||
const Formats::CompressionFormat m_format; | ||
|
||
// Streams | ||
RefPtr<ReadableStream> m_readable; | ||
RefPtr<WritableStream> m_writable; | ||
RefPtr<SimpleReadableStreamSource> m_readableStreamSource; | ||
|
||
// ActiveDOMObject | ||
const char* activeDOMObjectName() const override { return "CompressionStream"; } | ||
void stop() override { } | ||
void suspend(ReasonForSuspension) override { } | ||
bool virtualHasPendingActivity() const final { return false; } | ||
|
||
// EventTargetWithInlineData | ||
EventTargetInterface eventTargetInterface() const override { return CompressionStreamEventTargetInterfaceType; } | ||
ScriptExecutionContext* scriptExecutionContext() const override { return ActiveDOMObject::scriptExecutionContext(); } | ||
void refEventTarget() override { ref(); } | ||
void derefEventTarget() override { deref(); } | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright (C) 2022 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. | ||
*/ | ||
|
||
// https://wicg.github.io/compression/#compression-stream | ||
|
||
[ | ||
ActiveDOMObject, | ||
EnabledBySetting=CompressionStreamEnabled, | ||
Exposed=* | ||
] interface CompressionStream : EventTarget { | ||
[CallWith=CurrentDocument] constructor(DOMString format); | ||
}; | ||
|
||
CompressionStream includes GenericTransformStream; |
Oops, something went wrong.