Skip to content

Commit 88c0f97

Browse files
committed
8252381: Cherry pick GTK WebKit 2.28.4 changes
Reviewed-by: kcr, bchoudhary
1 parent c86bd35 commit 88c0f97

21 files changed

+158
-51
lines changed

modules/javafx.web/src/main/native/Source/WebCore/Modules/streams/ReadableStream.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ function initializeReadableStream(underlyingSource, strategy)
4848
// Initialized with null value to enable distinction with undefined case.
4949
@putByIdDirectPrivate(this, "readableStreamController", null);
5050

51+
// FIXME: We should introduce https://streams.spec.whatwg.org/#create-readable-stream.
52+
// For now, we emulate this with underlyingSource with private properties.
53+
if (@getByIdDirectPrivate(underlyingSource, "pull") !== @undefined) {
54+
@setupReadableStreamDefaultController(this, underlyingSource, @undefined, 1, @getByIdDirectPrivate(underlyingSource, "start"), @getByIdDirectPrivate(underlyingSource, "pull"), @getByIdDirectPrivate(underlyingSource, "cancel"));
55+
return this;
56+
}
57+
5158
const type = underlyingSource.type;
5259
const typeString = @toString(type);
5360

@@ -65,7 +72,8 @@ function initializeReadableStream(underlyingSource, strategy)
6572
} else if (type === @undefined) {
6673
if (strategy.highWaterMark === @undefined)
6774
strategy.highWaterMark = 1;
68-
@putByIdDirectPrivate(this, "readableStreamController", new @ReadableStreamDefaultController(this, underlyingSource, strategy.size, strategy.highWaterMark, @isReadableStream));
75+
76+
@setupReadableStreamDefaultController(this, underlyingSource, strategy.size, strategy.highWaterMark, underlyingSource.start, underlyingSource.pull, underlyingSource.cancel);
6977
} else
7078
@throwRangeError("Invalid type for underlying source");
7179

modules/javafx.web/src/main/native/Source/WebCore/Modules/streams/ReadableStreamInternals.js

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -63,21 +63,33 @@ function privateInitializeReadableStreamDefaultController(stream, underlyingSour
6363
@putByIdDirectPrivate(this, "pulling", false);
6464
@putByIdDirectPrivate(this, "strategy", @validateAndNormalizeQueuingStrategy(size, highWaterMark));
6565

66-
const controller = this;
67-
@promiseInvokeOrNoopNoCatch(underlyingSource, "start", [this]).@then(() => {
66+
return this;
67+
}
68+
69+
// https://streams.spec.whatwg.org/#set-up-readable-stream-default-controller, starting from step 6.
70+
// The other part is implemented in privateInitializeReadableStreamDefaultController.
71+
function setupReadableStreamDefaultController(stream, underlyingSource, size, highWaterMark, startMethod, pullMethod, cancelMethod)
72+
{
73+
"use strict";
74+
const controller = new @ReadableStreamDefaultController(stream, underlyingSource, size, highWaterMark, @isReadableStream);
75+
const startAlgorithm = () => @promiseInvokeOrNoopMethodNoCatch(underlyingSource, startMethod, [controller]);
76+
const pullAlgorithm = () => @promiseInvokeOrNoopMethod(underlyingSource, pullMethod, [controller]);
77+
const cancelAlgorithm = (reason) => @promiseInvokeOrNoopMethod(underlyingSource, cancelMethod, [reason]);
78+
79+
@putByIdDirectPrivate(controller, "pullAlgorithm", pullAlgorithm);
80+
@putByIdDirectPrivate(controller, "cancelAlgorithm", cancelAlgorithm);
81+
@putByIdDirectPrivate(controller, "pull", @readableStreamDefaultControllerPull);
82+
@putByIdDirectPrivate(controller, "cancel", @readableStreamDefaultControllerCancel);
83+
@putByIdDirectPrivate(stream, "readableStreamController", controller);
84+
85+
startAlgorithm().@then(() => {
6886
@putByIdDirectPrivate(controller, "started", true);
6987
@assert(!@getByIdDirectPrivate(controller, "pulling"));
7088
@assert(!@getByIdDirectPrivate(controller, "pullAgain"));
7189
@readableStreamDefaultControllerCallPullIfNeeded(controller);
7290
}, (error) => {
7391
@readableStreamDefaultControllerError(controller, error);
7492
});
75-
76-
@putByIdDirectPrivate(this, "cancel", @readableStreamDefaultControllerCancel);
77-
78-
@putByIdDirectPrivate(this, "pull", @readableStreamDefaultControllerPull);
79-
80-
return this;
8193
}
8294

8395
function readableStreamDefaultControllerError(controller, error)
@@ -137,18 +149,20 @@ function readableStreamTee(stream, shouldClone)
137149
reason2: @undefined,
138150
};
139151

140-
teeState.cancelPromiseCapability = @newPromiseCapability(@InternalPromise);
152+
teeState.cancelPromiseCapability = @newPromiseCapability(@Promise);
141153

142154
const pullFunction = @readableStreamTeePullFunction(teeState, reader, shouldClone);
143155

144-
const branch1 = new @ReadableStream({
145-
"pull": pullFunction,
146-
"cancel": @readableStreamTeeBranch1CancelFunction(teeState, stream)
147-
});
148-
const branch2 = new @ReadableStream({
149-
"pull": pullFunction,
150-
"cancel": @readableStreamTeeBranch2CancelFunction(teeState, stream)
151-
});
156+
const branch1Source = { };
157+
@putByIdDirectPrivate(branch1Source, "pull", pullFunction);
158+
@putByIdDirectPrivate(branch1Source, "cancel", @readableStreamTeeBranch1CancelFunction(teeState, stream));
159+
160+
const branch2Source = { };
161+
@putByIdDirectPrivate(branch2Source, "pull", pullFunction);
162+
@putByIdDirectPrivate(branch2Source, "cancel", @readableStreamTeeBranch2CancelFunction(teeState, stream));
163+
164+
const branch1 = new @ReadableStream(branch1Source);
165+
const branch2 = new @ReadableStream(branch2Source);
152166

153167
@getByIdDirectPrivate(reader, "closedPromiseCapability").@promise.@then(@undefined, function(e) {
154168
if (teeState.closedOrErrored)
@@ -322,7 +336,7 @@ function readableStreamDefaultControllerCallPullIfNeeded(controller)
322336
@assert(!@getByIdDirectPrivate(controller, "pullAgain"));
323337
@putByIdDirectPrivate(controller, "pulling", true);
324338

325-
@promiseInvokeOrNoop(@getByIdDirectPrivate(controller, "underlyingSource"), "pull", [controller]).@then(function() {
339+
@getByIdDirectPrivate(controller, "pullAlgorithm").@call(@undefined).@then(function() {
326340
@putByIdDirectPrivate(controller, "pulling", false);
327341
if (@getByIdDirectPrivate(controller, "pullAgain")) {
328342
@putByIdDirectPrivate(controller, "pullAgain", false);
@@ -385,7 +399,7 @@ function readableStreamDefaultControllerCancel(controller, reason)
385399
"use strict";
386400

387401
@putByIdDirectPrivate(controller, "queue", @newQueue());
388-
return @promiseInvokeOrNoop(@getByIdDirectPrivate(controller, "underlyingSource"), "cancel", [reason]);
402+
return @getByIdDirectPrivate(controller, "cancelAlgorithm").@call(@undefined, reason);
389403
}
390404

391405
function readableStreamDefaultControllerPull(controller)

modules/javafx.web/src/main/native/Source/WebCore/Modules/streams/StreamInternals.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,34 @@ function shieldingPromiseResolve(result)
3636
return promise;
3737
}
3838

39-
function promiseInvokeOrNoopNoCatch(object, key, args)
39+
function promiseInvokeOrNoopMethodNoCatch(object, method, args)
4040
{
4141
"use strict";
4242

43-
const method = object[key];
4443
if (method === @undefined)
4544
return @Promise.@resolve();
4645
return @shieldingPromiseResolve(method.@apply(object, args));
4746
}
4847

48+
function promiseInvokeOrNoopNoCatch(object, key, args)
49+
{
50+
"use strict";
51+
52+
return @promiseInvokeOrNoopMethodNoCatch(object, object[key], args);
53+
}
54+
55+
function promiseInvokeOrNoopMethod(object, method, args)
56+
{
57+
"use strict";
58+
59+
try {
60+
return @promiseInvokeOrNoopMethodNoCatch(object, method, args);
61+
}
62+
catch(error) {
63+
return @Promise.@reject(error);
64+
}
65+
}
66+
4967
function promiseInvokeOrNoop(object, key, args)
5068
{
5169
"use strict";
@@ -56,7 +74,6 @@ function promiseInvokeOrNoop(object, key, args)
5674
catch(error) {
5775
return @Promise.@reject(error);
5876
}
59-
6077
}
6178

6279
function promiseInvokeOrFallbackOrNoop(object, key1, args1, key2, args2)

modules/javafx.web/src/main/native/Source/WebCore/animation/DocumentTimeline.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ Vector<RefPtr<WebAnimation>> DocumentTimeline::getAnimations() const
142142
Vector<RefPtr<WebAnimation>> webAnimations;
143143

144144
// First, let's get all qualifying animations in their right group.
145-
for (const auto& animation : m_allAnimations) {
145+
for (const auto& animation : m_animations) {
146146
if (!animation || !animation->isRelevant() || animation->timeline() != this || !is<KeyframeEffect>(animation->effect()))
147147
continue;
148148

@@ -151,15 +151,15 @@ Vector<RefPtr<WebAnimation>> DocumentTimeline::getAnimations() const
151151
continue;
152152

153153
if (is<CSSTransition>(animation.get()) && downcast<CSSTransition>(animation.get())->owningElement())
154-
cssTransitions.append(animation.get());
154+
cssTransitions.append(animation);
155155
else if (is<CSSAnimation>(animation.get()) && downcast<CSSAnimation>(animation.get())->owningElement())
156-
cssAnimations.append(animation.get());
156+
cssAnimations.append(animation);
157157
else
158-
webAnimations.append(animation.get());
158+
webAnimations.append(animation);
159159
}
160160

161161
// Now sort CSS Transitions by their composite order.
162-
std::sort(cssTransitions.begin(), cssTransitions.end(), [](auto& lhs, auto& rhs) {
162+
std::stable_sort(cssTransitions.begin(), cssTransitions.end(), [](auto& lhs, auto& rhs) {
163163
// https://drafts.csswg.org/css-transitions-2/#animation-composite-order
164164
auto* lhsTransition = downcast<CSSTransition>(lhs.get());
165165
auto* rhsTransition = downcast<CSSTransition>(rhs.get());
@@ -181,7 +181,7 @@ Vector<RefPtr<WebAnimation>> DocumentTimeline::getAnimations() const
181181
});
182182

183183
// Now sort CSS Animations by their composite order.
184-
std::sort(cssAnimations.begin(), cssAnimations.end(), [](auto& lhs, auto& rhs) {
184+
std::stable_sort(cssAnimations.begin(), cssAnimations.end(), [](auto& lhs, auto& rhs) {
185185
// https://drafts.csswg.org/css-animations-2/#animation-composite-order
186186
auto* lhsOwningElement = downcast<CSSAnimation>(lhs.get())->owningElement();
187187
auto* rhsOwningElement = downcast<CSSAnimation>(rhs.get())->owningElement();
@@ -194,7 +194,7 @@ Vector<RefPtr<WebAnimation>> DocumentTimeline::getAnimations() const
194194
return compareAnimationsByCompositeOrder(*lhs, *rhs, lhsOwningElement->ensureKeyframeEffectStack().cssAnimationList());
195195
});
196196

197-
std::sort(webAnimations.begin(), webAnimations.end(), [](auto& lhs, auto& rhs) {
197+
std::stable_sort(webAnimations.begin(), webAnimations.end(), [](auto& lhs, auto& rhs) {
198198
return lhs->globalPosition() < rhs->globalPosition();
199199
});
200200

modules/javafx.web/src/main/native/Source/WebCore/animation/KeyframeEffectStack.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ void KeyframeEffectStack::ensureEffectsAreSorted()
8080
if (m_isSorted || m_effects.size() < 2)
8181
return;
8282

83-
std::sort(m_effects.begin(), m_effects.end(), [&](auto& lhs, auto& rhs) {
83+
std::stable_sort(m_effects.begin(), m_effects.end(), [&](auto& lhs, auto& rhs) {
8484
auto* lhsAnimation = lhs->animation();
8585
auto* rhsAnimation = rhs->animation();
8686

modules/javafx.web/src/main/native/Source/WebCore/animation/WebAnimationUtilities.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ namespace WebCore {
3737

3838
bool compareAnimationsByCompositeOrder(WebAnimation& lhsAnimation, WebAnimation& rhsAnimation, const AnimationList* cssAnimationList)
3939
{
40+
// We should not ever be calling this function with two WebAnimation objects that are the same. If that were the case,
41+
// then comparing objects of this kind would yield inconsistent results when comparing A == B and B == A. As such,
42+
// this function should be called with std::stable_sort().
43+
RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(&lhsAnimation != &rhsAnimation);
44+
4045
bool lhsHasOwningElement = is<DeclarativeAnimation>(lhsAnimation) && downcast<DeclarativeAnimation>(lhsAnimation).owningElement();
4146
bool rhsHasOwningElement = is<DeclarativeAnimation>(rhsAnimation) && downcast<DeclarativeAnimation>(rhsAnimation).owningElement();
4247

modules/javafx.web/src/main/native/Source/WebCore/bindings/js/WebCoreBuiltinNames.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ namespace WebCore {
245245
macro(byobRequest) \
246246
macro(caches) \
247247
macro(cancel) \
248+
macro(cancelAlgorithm) \
248249
macro(cancelIdleCallback) \
249250
macro(cloneArrayBuffer) \
250251
macro(close) \
@@ -307,6 +308,7 @@ namespace WebCore {
307308
macro(privateGetStats) \
308309
macro(pull) \
309310
macro(pullAgain) \
311+
macro(pullAlgorithm) \
310312
macro(pulling) \
311313
macro(queue) \
312314
macro(queuedAddIceCandidate) \
@@ -329,6 +331,7 @@ namespace WebCore {
329331
macro(setBodyFromInputRequest) \
330332
macro(setStatus) \
331333
macro(showModalDialog) \
334+
macro(start) \
332335
macro(startConsumingStream) \
333336
macro(started) \
334337
macro(startedPromise) \

modules/javafx.web/src/main/native/Source/WebCore/css/StyleProperties.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,10 @@ String StyleProperties::pageBreakPropertyValue(const StylePropertyShorthand& sho
751751
// FIXME: Remove this isGlobalKeyword check after we do this consistently for all shorthands in getPropertyValue.
752752
if (value->isGlobalKeyword())
753753
return value->cssText();
754+
755+
if (!is<CSSPrimitiveValue>(*value))
756+
return String();
757+
754758
CSSValueID valueId = downcast<CSSPrimitiveValue>(*value).valueID();
755759
switch (valueId) {
756760
case CSSValuePage:

modules/javafx.web/src/main/native/Source/WebCore/dom/Document.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4660,6 +4660,19 @@ void Document::nodeWillBeRemoved(Node& node)
46604660
m_markers->removeMarkers(node);
46614661
}
46624662

4663+
void Document::parentlessNodeMovedToNewDocument(Node& node)
4664+
{
4665+
Vector<Range*, 5> rangesAffected;
4666+
4667+
for (auto* range : m_ranges) {
4668+
if (range->parentlessNodeMovedToNewDocumentAffectsRange(node))
4669+
rangesAffected.append(range);
4670+
}
4671+
4672+
for (auto* range : rangesAffected)
4673+
range->updateRangeForParentlessNodeMovedToNewDocument(node);
4674+
}
4675+
46634676
static Node* fallbackFocusNavigationStartingNodeAfterRemoval(Node& node)
46644677
{
46654678
return node.previousSibling() ? node.previousSibling() : node.parentNode();

modules/javafx.web/src/main/native/Source/WebCore/dom/Document.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,7 @@ class Document
815815
void nodeChildrenWillBeRemoved(ContainerNode&);
816816
// nodeWillBeRemoved is only safe when removing one node at a time.
817817
void nodeWillBeRemoved(Node&);
818+
void parentlessNodeMovedToNewDocument(Node&);
818819

819820
enum class AcceptChildOperation { Replace, InsertOrAdd };
820821
bool canAcceptChild(const Node& newChild, const Node* refChild, AcceptChildOperation) const;

modules/javafx.web/src/main/native/Source/WebCore/dom/Node.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2050,6 +2050,9 @@ void Node::moveNodeToNewDocument(Document& oldDocument, Document& newDocument)
20502050

20512051
oldDocument.moveNodeIteratorsToNewDocument(*this, newDocument);
20522052

2053+
if (!parentNode())
2054+
oldDocument.parentlessNodeMovedToNewDocument(*this);
2055+
20532056
if (AXObjectCache::accessibilityEnabled()) {
20542057
if (auto* cache = oldDocument.existingAXObjectCache())
20552058
cache->remove(*this);

modules/javafx.web/src/main/native/Source/WebCore/dom/Range.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1659,6 +1659,18 @@ void Range::nodeWillBeRemoved(Node& node)
16591659
boundaryNodeWillBeRemoved(m_end, node);
16601660
}
16611661

1662+
bool Range::parentlessNodeMovedToNewDocumentAffectsRange(Node& node)
1663+
{
1664+
return node.containsIncludingShadowDOM(m_start.container());
1665+
}
1666+
1667+
void Range::updateRangeForParentlessNodeMovedToNewDocument(Node& node)
1668+
{
1669+
m_ownerDocument->detachRange(*this);
1670+
m_ownerDocument = node.document();
1671+
m_ownerDocument->attachRange(*this);
1672+
}
1673+
16621674
static inline void boundaryTextInserted(RangeBoundaryPoint& boundary, Node& text, unsigned offset, unsigned length)
16631675
{
16641676
if (boundary.container() != &text)

modules/javafx.web/src/main/native/Source/WebCore/dom/Range.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ class Range : public RefCounted<Range> {
138138
void nodeChildrenChanged(ContainerNode&);
139139
void nodeChildrenWillBeRemoved(ContainerNode&);
140140
void nodeWillBeRemoved(Node&);
141+
bool parentlessNodeMovedToNewDocumentAffectsRange(Node&);
142+
void updateRangeForParentlessNodeMovedToNewDocument(Node&);
141143

142144
void textInserted(Node&, unsigned offset, unsigned length);
143145
void textRemoved(Node&, unsigned offset, unsigned length);

modules/javafx.web/src/main/native/Source/WebCore/html/HTMLAppletElement.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,6 @@ void HTMLAppletElement::updateWidget(CreatePlugins createPlugins)
124124

125125
setNeedsWidgetUpdate(false);
126126

127-
RenderEmbeddedObject* renderer = renderEmbeddedObject();
128-
129-
LayoutUnit contentWidth = renderer->style().width().isFixed() ? LayoutUnit(renderer->style().width().value()) :
130-
renderer->width() - renderer->horizontalBorderAndPaddingExtent();
131-
LayoutUnit contentHeight = renderer->style().height().isFixed() ? LayoutUnit(renderer->style().height().value()) :
132-
renderer->height() - renderer->verticalBorderAndPaddingExtent();
133-
134127
Vector<String> paramNames;
135128
Vector<String> paramValues;
136129

@@ -175,7 +168,20 @@ void HTMLAppletElement::updateWidget(CreatePlugins createPlugins)
175168
RefPtr<Frame> frame = document().frame();
176169
ASSERT(frame);
177170

178-
renderer->setWidget(frame->loader().subframeLoader().createJavaAppletWidget(roundedIntSize(LayoutSize(contentWidth, contentHeight)), *this, paramNames, paramValues));
171+
auto contentSize = LayoutSize { };
172+
{
173+
auto* renderer = renderEmbeddedObject();
174+
auto& style = renderer->style();
175+
176+
contentSize = LayoutSize { style.width().isFixed() ? LayoutUnit(style.width().value()) : renderer->width() - renderer->horizontalBorderAndPaddingExtent(),
177+
style.height().isFixed() ? LayoutUnit(style.height().value()) : renderer->height() - renderer->verticalBorderAndPaddingExtent() };
178+
}
179+
180+
auto widget = frame->loader().subframeLoader().createJavaAppletWidget(roundedIntSize(contentSize), *this, paramNames, paramValues);
181+
// createJavaAppletWidget needs to check if the plugin(replacement) is obscured. Since the overlapping test requires up-to-date geometry, it initiates a top level style recalc/layout.
182+
// Let's see if this element still has a renderer after the style recalc.
183+
if (auto* renderer = renderEmbeddedObject())
184+
renderer->setWidget(WTFMove(widget));
179185
#endif // !PLATFORM(IOS_FAMILY)
180186
}
181187

modules/javafx.web/src/main/native/Source/WebCore/loader/FrameLoader.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2006-2018 Apple Inc. All rights reserved.
2+
* Copyright (C) 2006-2020 Apple Inc. All rights reserved.
33
* Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
44
* Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
55
* Copyright (C) 2008 Alp Toker <alp@atoker.com>
@@ -461,9 +461,11 @@ void FrameLoader::submitForm(Ref<FormSubmission>&& submission)
461461
return;
462462
}
463463

464-
if (WTF::protocolIsJavaScript(submission->action())) {
465-
if (!m_frame.document()->contentSecurityPolicy()->allowFormAction(URL(submission->action())))
466-
return;
464+
URL formAction = submission->action();
465+
if (!m_frame.document()->contentSecurityPolicy()->allowFormAction(formAction))
466+
return;
467+
468+
if (WTF::protocolIsJavaScript(formAction)) {
467469
m_isExecutingJavaScriptFormAction = true;
468470
Ref<Frame> protect(m_frame);
469471
m_frame.script().executeIfJavaScriptURL(submission->action(), nullptr, DoNotReplaceDocumentIfJavaScriptURL);

0 commit comments

Comments
 (0)