Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: 7c36bd3c403e26c44c730d77c5225a8416499648
https://github.com/WebKit/WebKit/commit/7c36bd3c403e26c44c730d77c5225a8416499648
Author: Rupin Mittal <[email protected]>
Date: 2025-09-21 (Sun, 21 Sep 2025)
Changed paths:
M Source/WebCore/page/ImageAnalysisQueue.cpp
M Source/WebCore/page/ImageAnalysisQueue.h
M Source/WebCore/page/Page.cpp
M Source/WebCore/page/PageConfiguration.h
M Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in
M Source/WebKit/Shared/WebPageCreationParameters.h
M Source/WebKit/Shared/WebPageCreationParameters.serialization.in
M Source/WebKit/UIProcess/WebPageProxy.cpp
M Source/WebKit/UIProcess/WebPageProxyInternals.h
M Source/WebKit/WebProcess/WebPage/WebPage.cpp
M Tools/TestWebKitAPI/Tests/WebKitCocoa/SiteIsolation.mm
Log Message:
-----------
[Site Isolation] Image in cross-site iframe isn't translated if frame is
added after user translates page
https://bugs.webkit.org/show_bug.cgi?id=299158
rdar://160917894
Reviewed by Wenson Hsieh.
If the user translates a page, and then a cross-site iframe is added later, the
images in this iframe should be translated automatically as well. This happens
with site isolation off, but not with site isolation on.
There are two issues:
1. When loading an image into a page, Page::didFinishLoadingImageForElement()
will add the image to the ImageAnalysisQueue to be translated. But only if
this queue already exists. This queue is only created when the user requests
translation and WKWebView::_startImageAnalysis is called.
In our case where a cross-site iframe is loaded after page translation, a
new Page will be created but will not have an ImageAnalysisQueue. And so the
images in the frame will not be translated.
To fix this, we keep a flag on WebPageProxy which indicates if translation
has been requested. If a new Page is created, it will be passed this flag.
If it's true, the Page will create an ImageAnalysisQueue so that when the
images are loaded and Page::didFinishLoadingImageForElement() is called, the
images will be translated.
2. Now the images are being added to the queue to be translated. But translation
only occurs if a source and target language are specified. These are set by
the call to WKWebView::_startImageAnalysis. This call won't occur after the
cross-site iframe is loaded. So the images are queued for translation, but
aren't actually translated.
To fix this, we store the two languages on WebPageProxy as well.
These three bits of information are stored on WebPageProxy like so:
std::optional<ImageTranslationLanguageIdentifiers>
imageTranslationLanguageIdentifiers;
Where struct ImageTranslationLanguageIdentifiers contains the two languages.
If the struct is present, it means translation was requested. This struct will
be plumbed from WebPageProxy to WebPage to PageConfiguration to Page where it's
used to create the ImageAnalysisQueue with the two languages if needed.
If a new document is loaded in the main frame, this is nulled since translation
on one page must not cause translation on the next. This is done in
WebPageProxy::didCommitLoadForFrame().
New API test:
SiteIsolation.IframeImageTranslationIfIframeIsAddedAfterTranslationCall
* Source/WebCore/page/ImageAnalysisQueue.cpp:
(WebCore::ImageAnalysisQueue::enqueueAllImagesIfNeeded):
(WebCore::ImageAnalysisQueue::resumeProcessing):
(WebCore::ImageAnalysisQueue::clear):
* Source/WebCore/page/ImageAnalysisQueue.h:
* Source/WebCore/page/Page.cpp:
If the flag is set, create the ImageAnalysisQueue and set the two languages.
(WebCore::m_mediaSessionManagerFactory):
* Source/WebCore/page/PageConfiguration.h:
* Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in:
* Source/WebKit/Shared/WebPageCreationParameters.h:
* Source/WebKit/Shared/WebPageCreationParameters.serialization.in:
* Source/WebKit/UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::didCommitLoadForFrame):
Unset the flag and the two languages if a new load was done in the main frame.
(WebKit::WebPageProxy::creationParameters):
(WebKit::WebPageProxy::startVisualTranslation):
Set the flag and the two languages.
* Source/WebKit/UIProcess/WebPageProxyInternals.h:
* Source/WebKit/WebProcess/WebPage/WebPage.cpp:
(WebKit::m_toolbarsAreVisible):
* Tools/TestWebKitAPI/Tests/WebKitCocoa/SiteIsolation.mm:
(TestWebKitAPI::(SiteIsolation, IframeImageTranslation)):
(TestWebKitAPI::(SiteIsolation,
IframeImageTranslationIfIframeIsAddedAfterTranslationCall)):
Canonical link: https://commits.webkit.org/300305@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes