Skip to content

Commit

Permalink
Merge r265630 - Add RenderTreeMutationDisallowedScope to track intrus…
Browse files Browse the repository at this point in the history
…ive render tree mutations

https://bugs.webkit.org/show_bug.cgi?id=215463
<rdar://problem/67012831>

Reviewed by Simon Fraser.

RenderLayer::enclosingScrollableLayer should not mutate the render tree accidentally.
This is related to <rdar://problem/64739768>.

* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* rendering/RenderTreeMutationDisallowedScope.cpp: Added.
* rendering/RenderTreeMutationDisallowedScope.h: Added.
(WebCore::RenderTreeMutationDisallowedScope::RenderTreeMutationDisallowedScope):
(WebCore::RenderTreeMutationDisallowedScope::~RenderTreeMutationDisallowedScope):
(WebCore::RenderTreeMutationDisallowedScope::isMutationAllowed):
* rendering/updating/RenderTreeBuilder.cpp:
(WebCore::RenderTreeBuilder::destroy):
  • Loading branch information
alanbaradlay authored and carlosgcampos committed Aug 14, 2020
1 parent bfd7ec1 commit 14115c6
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Source/WebCore/ChangeLog
@@ -1,3 +1,24 @@
2020-08-13 Zalan Bujtas <zalan@apple.com>

Add RenderTreeMutationDisallowedScope to track intrusive render tree mutations
https://bugs.webkit.org/show_bug.cgi?id=215463
<rdar://problem/67012831>

Reviewed by Simon Fraser.

RenderLayer::enclosingScrollableLayer should not mutate the render tree accidentally.
This is related to <rdar://problem/64739768>.

* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* rendering/RenderTreeMutationDisallowedScope.cpp: Added.
* rendering/RenderTreeMutationDisallowedScope.h: Added.
(WebCore::RenderTreeMutationDisallowedScope::RenderTreeMutationDisallowedScope):
(WebCore::RenderTreeMutationDisallowedScope::~RenderTreeMutationDisallowedScope):
(WebCore::RenderTreeMutationDisallowedScope::isMutationAllowed):
* rendering/updating/RenderTreeBuilder.cpp:
(WebCore::RenderTreeBuilder::destroy):

2020-08-12 Myles C. Maxfield <mmaxfield@apple.com>

Font loads quickly followed by navigations may fail indefinitely
Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/Sources.txt
Expand Up @@ -2171,6 +2171,7 @@ rendering/RenderTextFragment.cpp
rendering/RenderTextLineBoxes.cpp
rendering/RenderTheme.cpp
rendering/RenderTreeAsText.cpp
rendering/RenderTreeMutationDisallowedScope.cpp
rendering/RenderVTTCue.cpp
rendering/RenderVideo.cpp
rendering/RenderView.cpp
Expand Down
6 changes: 6 additions & 0 deletions Source/WebCore/WebCore.xcodeproj/project.pbxproj
Expand Up @@ -385,6 +385,7 @@
115CFA82208B8EDA001E6991 /* FloatingState.h in Headers */ = {isa = PBXBuildFile; fileRef = 115CFA80208B8EDA001E6991 /* FloatingState.h */; settings = {ATTRIBUTES = (Private, ); }; };
115CFA86208B9066001E6991 /* FloatingContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 115CFA84208B9066001E6991 /* FloatingContext.h */; settings = {ATTRIBUTES = (Private, ); }; };
115CFA97208B952B001E6991 /* LayoutBox.h in Headers */ = {isa = PBXBuildFile; fileRef = 115CFA95208B952B001E6991 /* LayoutBox.h */; settings = {ATTRIBUTES = (Private, ); }; };
1163F82424E5D5AE000AB960 /* RenderTreeMutationDisallowedScope.h in Headers */ = {isa = PBXBuildFile; fileRef = 1163F82124E5D59B000AB960 /* RenderTreeMutationDisallowedScope.h */; settings = {ATTRIBUTES = (Private, ); }; };
119340791FE8B92300935F1E /* RenderTreeBuilderTable.h in Headers */ = {isa = PBXBuildFile; fileRef = 119340771FE8B92300935F1E /* RenderTreeBuilderTable.h */; };
1193408A1FEB355D00935F1E /* RenderTreeBuilderRuby.h in Headers */ = {isa = PBXBuildFile; fileRef = 119340881FEB355D00935F1E /* RenderTreeBuilderRuby.h */; };
119340971FED715500935F1E /* RenderTreeBuilderFormControls.h in Headers */ = {isa = PBXBuildFile; fileRef = 119340951FED715500935F1E /* RenderTreeBuilderFormControls.h */; };
Expand Down Expand Up @@ -6091,6 +6092,8 @@
115CFA89208B921A001E6991 /* BlockMarginCollapse.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = BlockMarginCollapse.cpp; sourceTree = "<group>"; };
115CFA95208B952B001E6991 /* LayoutBox.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LayoutBox.h; sourceTree = "<group>"; };
115CFA96208B952B001E6991 /* LayoutBox.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = LayoutBox.cpp; sourceTree = "<group>"; };
1163F82124E5D59B000AB960 /* RenderTreeMutationDisallowedScope.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RenderTreeMutationDisallowedScope.h; sourceTree = "<group>"; };
1163F82324E5D59B000AB960 /* RenderTreeMutationDisallowedScope.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = RenderTreeMutationDisallowedScope.cpp; sourceTree = "<group>"; };
119340761FE8B92300935F1E /* RenderTreeBuilderTable.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = RenderTreeBuilderTable.cpp; sourceTree = "<group>"; };
119340771FE8B92300935F1E /* RenderTreeBuilderTable.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RenderTreeBuilderTable.h; sourceTree = "<group>"; };
119340871FEB355D00935F1E /* RenderTreeBuilderRuby.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = RenderTreeBuilderRuby.cpp; sourceTree = "<group>"; };
Expand Down Expand Up @@ -28855,6 +28858,8 @@
BCEA4849097D93020094C9E4 /* RenderThemeMac.mm */,
93955A4203D72932008635CE /* RenderTreeAsText.cpp */,
93955A4103D72932008635CE /* RenderTreeAsText.h */,
1163F82324E5D59B000AB960 /* RenderTreeMutationDisallowedScope.cpp */,
1163F82124E5D59B000AB960 /* RenderTreeMutationDisallowedScope.h */,
E4B41E330CBFB60900AF2ECE /* RenderVideo.cpp */,
E4B41E340CBFB60900AF2ECE /* RenderVideo.h */,
BCEA4828097D93020094C9E4 /* RenderView.cpp */,
Expand Down Expand Up @@ -33214,6 +33219,7 @@
E47C39331FE6E10800BBBC6B /* RenderTreeBuilderMultiColumn.h in Headers */,
1193408A1FEB355D00935F1E /* RenderTreeBuilderRuby.h in Headers */,
119340791FE8B92300935F1E /* RenderTreeBuilderTable.h in Headers */,
1163F82424E5D5AE000AB960 /* RenderTreeMutationDisallowedScope.h in Headers */,
E47C392E1FE6E0F700BBBC6B /* RenderTreePosition.h in Headers */,
E47C392F1FE6E0F900BBBC6B /* RenderTreeUpdater.h in Headers */,
E47C39311FE6E10200BBBC6B /* RenderTreeUpdaterGeneratedContent.h in Headers */,
Expand Down
3 changes: 3 additions & 0 deletions Source/WebCore/rendering/RenderLayer.cpp
Expand Up @@ -111,6 +111,7 @@
#include "RenderText.h"
#include "RenderTheme.h"
#include "RenderTreeAsText.h"
#include "RenderTreeMutationDisallowedScope.h"
#include "RenderView.h"
#include "RuntimeEnabledFeatures.h"
#include "SVGNames.h"
Expand Down Expand Up @@ -1865,6 +1866,8 @@ static RenderLayer* enclosingContainingBlockLayer(const RenderLayer& layer, Cros

RenderLayer* RenderLayer::enclosingScrollableLayer(IncludeSelfOrNot includeSelf, CrossFrameBoundaries crossFrameBoundaries) const
{
RenderTreeMutationDisallowedScope renderTreeMutationDisallowedScope;

auto isConsideredScrollable = [](const RenderLayer& layer) {
return is<RenderBox>(layer.renderer()) && downcast<RenderBox>(layer.renderer()).canBeScrolledAndHasScrollableArea();
};
Expand Down
33 changes: 33 additions & 0 deletions Source/WebCore/rendering/RenderTreeMutationDisallowedScope.cpp
@@ -0,0 +1,33 @@
/*
* Copyright (C) 2020 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 "RenderTreeMutationDisallowedScope.h"

namespace WebCore {

RenderTreeMutationDisallowedScope* RenderTreeMutationDisallowedScope::s_currentMutationAssertion = nullptr;

}
50 changes: 50 additions & 0 deletions Source/WebCore/rendering/RenderTreeMutationDisallowedScope.h
@@ -0,0 +1,50 @@
/*
* Copyright (C) 2020 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

namespace WebCore {

class RenderTreeMutationDisallowedScope {
public:
RenderTreeMutationDisallowedScope()
: m_previousMutationAssertion(s_currentMutationAssertion)
{
s_currentMutationAssertion = this;
}

~RenderTreeMutationDisallowedScope()
{
s_currentMutationAssertion = m_previousMutationAssertion;
}

static bool isMutationAllowed() { return !s_currentMutationAssertion; }

private:
RenderTreeMutationDisallowedScope* m_previousMutationAssertion { nullptr };
static RenderTreeMutationDisallowedScope* s_currentMutationAssertion;
};

}
2 changes: 2 additions & 0 deletions Source/WebCore/rendering/updating/RenderTreeBuilder.cpp
Expand Up @@ -67,6 +67,7 @@
#include "RenderTreeBuilderRuby.h"
#include "RenderTreeBuilderSVG.h"
#include "RenderTreeBuilderTable.h"
#include "RenderTreeMutationDisallowedScope.h"
#include "RenderView.h"

#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
Expand Down Expand Up @@ -163,6 +164,7 @@ RenderTreeBuilder::~RenderTreeBuilder()

void RenderTreeBuilder::destroy(RenderObject& renderer)
{
RELEASE_ASSERT(RenderTreeMutationDisallowedScope::isMutationAllowed());
ASSERT(renderer.parent());
auto toDestroy = detach(*renderer.parent(), renderer);

Expand Down

0 comments on commit 14115c6

Please sign in to comment.