Skip to content

Commit 3c907c5

Browse files
document should not be null after navigation with site isolation enabled
https://bugs.webkit.org/show_bug.cgi?id=294228 rdar://152872994 Reviewed by Charlie Wolfe. https://commits.webkit.org/292437@main introduced a case where we take the WindowProxy from one page to another when navigating the main frame from one domain to another. If the WindowProxy that we are taking had its JSWindowProxy initialized by an iframe on the previous page accessing its parent's properties, then JSDOMWindowBase::initStaticGlobals has already been called to initialize document to null, but ScriptController::initScriptForWindowProxy won't call JSDOMWindowBase::updateDocument to set document to the document instead of null because WindowProxy::jsWindowProxy will find an already existing JSWindowProxy initialized where WindowProxy::createJSWindowProxyWithInitializedScript has skipped the call to initScriptForWindowProxy because the Frame was a RemoteFrame when it was initialized. To fix this issue, we add another call to didBecomeCurrentDocumentInFrame after swapping from a RemoteFrame to a LocalFrame. That will call updateDocument as well as do possibly other initialization needed. I also restore an assertion that was removed in 292437@main, but I added a condition to make it pass when taking a WindowProxy from one page to another. This fixes one of the issues I found in rdar://152460976 but not the initial one, so that still needs more investigation. * LayoutTests/http/tests/site-isolation/document-access-expected.txt: Added. * LayoutTests/http/tests/site-isolation/document-access.html: Added. * LayoutTests/http/tests/site-isolation/resources/access-document.html: Added. * LayoutTests/http/tests/site-isolation/resources/access-parent.html: Added. * Source/WebCore/dom/Document.h: * Source/WebCore/page/Frame.cpp: (WebCore::Frame::takeWindowProxyAndOpenerFrom): * Source/WebKit/WebProcess/WebPage/WebFrame.cpp: (WebKit::WebFrame::commitProvisionalFrame): Canonical link: https://commits.webkit.org/296022@main
1 parent 3b698e6 commit 3c907c5

7 files changed

Lines changed: 21 additions & 1 deletion

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALERT: document is null? false
2+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<!-- webkit-test-runner [ SiteIsolationEnabled=true ] -->
2+
<body>
3+
<script>
4+
if (window.testRunner) { testRunner.dumpAsText(); testRunner.waitUntilDone() }
5+
onload = ()=>{ window.location = 'http://localhost:8000/site-isolation/resources/access-document.html' }
6+
</script>
7+
<iframe src="http://localhost:8000/site-isolation/resources/access-parent.html" frameborder=0></iframe>
8+
</body>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<script>
2+
alert('document is null? ' + (document == null))
3+
if (window.testRunner) { testRunner.notifyDone() }
4+
</script>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<script>
2+
window.parent.frames
3+
</script>

Source/WebCore/dom/Document.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ class Document
754754
inline CachedResourceLoader& cachedResourceLoader();
755755
inline Ref<CachedResourceLoader> protectedCachedResourceLoader() const;
756756

757-
void didBecomeCurrentDocumentInFrame();
757+
WEBCORE_EXPORT void didBecomeCurrentDocumentInFrame();
758758
void destroyRenderTree();
759759
WEBCORE_EXPORT void willBeRemovedFromFrame();
760760

Source/WebCore/page/Frame.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ void Frame::disconnectOwnerElement()
173173

174174
void Frame::takeWindowProxyAndOpenerFrom(Frame& frame)
175175
{
176+
ASSERT(is<LocalDOMWindow>(window()) != is<LocalDOMWindow>(frame.window()) || page() != frame.page());
176177
ASSERT(m_windowProxy->frame() == this);
177178
m_windowProxy->detachFromFrame();
178179
m_windowProxy = frame.windowProxy();

Source/WebKit/WebProcess/WebPage/WebFrame.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,8 @@ void WebFrame::commitProvisionalFrame()
518518
if (remoteFrame->isMainFrame())
519519
corePage->setMainFrame(*localFrame);
520520
localFrame->takeWindowProxyAndOpenerFrom(*remoteFrame);
521+
if (RefPtr document = localFrame->document())
522+
document->didBecomeCurrentDocumentInFrame();
521523

522524
if (corePage->focusController().focusedFrame() == remoteFrame.get())
523525
corePage->focusController().setFocusedFrame(localFrame.get(), FocusController::BroadcastFocusedFrame::No);

0 commit comments

Comments
 (0)