4

Do not reparse the same URL repeatedly for HTMLImageElement src attri… · WebKit/...

 1 month ago
source link: https://github.com/WebKit/WebKit/commit/88f5d6430abe12164eec7acf3a0993ef1ec67d0a
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Commit

Permalink

Do not reparse the same URL repeatedly for HTMLImageElement src attri…

Browse files Browse the repository at this point in the history

…bute setter

https://bugs.webkit.org/show_bug.cgi?id=269975
rdar://123492927

Reviewed by Ryosuke Niwa.

This patch cleans up a lot of HTMLImageElement src attribute setter path.

1. HTMLImageElement should not make m_currentSrc AtomString eagerly. This is rarely accessed. So we should defer it.
2. HTMLImageElement should have super fast path for no `sizes` attribute case since this is common. We should not invoke SizesAttributeParser.
3. ImageCandidate should carry underlying AtomString if possible. Attributes are AtomString. So by carrying it,
   we can avoid AtomString creation for `m_bestFitImageURL = candidate.string.toAtomString()`.
4. We should use HTMLImageElement::currentURL if possible in ImageLoader, avoiding repeated parsing of the same URL string.
5. FrameLoader should keep m_outgoingReferrerURL. Then subsequent code can use this URL instead of parsing it repeatedly.
   We enhance URL::strippedForUseAsReferrer to further avoid reparsing URL from stripped string.

* Source/WTF/wtf/URL.cpp:
(WTF::URL::strippedForUseAsReferrer const):
(WTF::URL::strippedForUseAsReferrerWithExplicitPort const):
* Source/WTF/wtf/URL.h:
* Source/WTF/wtf/text/StringView.h:
(WTF::StringViewWithUnderlyingString::toAtomString const):
* Source/WebCore/Modules/fetch/FetchLoader.cpp:
(WebCore::FetchLoader::start):
* Source/WebCore/Modules/reporting/ReportingScope.cpp:
(WebCore::ReportingScope::generateTestReport):
* Source/WebCore/html/HTMLImageElement.cpp:
(WebCore::HTMLImageElement::currentSrc):
(WebCore::HTMLImageElement::setBestFitURLAndDPRFromImageCandidate):
(WebCore::HTMLImageElement::selectImageSource):
* Source/WebCore/html/HTMLImageElement.h:
(WebCore::HTMLImageElement::currentSrc const): Deleted.
* Source/WebCore/html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::mediaPlayerReferrer const):
* Source/WebCore/html/parser/HTMLPreloadScanner.cpp:
(WebCore::TokenPreloadScanner::StartTagScanner::processAttributes):
* Source/WebCore/html/parser/HTMLSrcsetParser.cpp:
(WebCore::parseImageCandidatesFromSrcsetAttribute):
(WebCore::pickBestImageCandidate):
(WebCore::bestFitSourceForImageAttributes):
* Source/WebCore/html/parser/HTMLSrcsetParser.h:
(WebCore::ImageCandidate::ImageCandidate):
(WebCore::ImageCandidate::isEmpty const):
* Source/WebCore/loader/CrossOriginAccessControl.cpp:
(WebCore::updateRequestReferrer):
* Source/WebCore/loader/CrossOriginAccessControl.h:
* Source/WebCore/loader/CrossOriginPreflightChecker.cpp:
(WebCore::CrossOriginPreflightChecker::doPreflight):
* Source/WebCore/loader/FrameLoader.cpp:
(WebCore::FrameLoader::setOutgoingReferrer):
(WebCore::FrameLoader::outgoingReferrerURL):
(WebCore::FrameLoader::loadFrameRequest):
(WebCore::FrameLoader::loadResourceSynchronously):
(WebCore::createWindow):
* Source/WebCore/loader/FrameLoader.h:
* Source/WebCore/loader/ImageLoader.cpp:
(WebCore::ImageLoader::updateFromElement):
* Source/WebCore/loader/LinkLoader.cpp:
(WebCore::LinkLoader::preloadIfNeeded):
* Source/WebCore/loader/PingLoader.cpp:
(WebCore::PingLoader::loadImage):
(WebCore::PingLoader::sendViolationReport):
* Source/WebCore/loader/SubframeLoader.cpp:
(WebCore::FrameLoader::SubframeLoader::loadOrRedirectSubframe):
(WebCore::FrameLoader::SubframeLoader::loadSubframe):
* Source/WebCore/loader/SubframeLoader.h:
* Source/WebCore/loader/SubresourceLoader.cpp:
(WebCore::SubresourceLoader::checkRedirectionCrossOriginAccessControl):
* Source/WebCore/loader/WorkerThreadableLoader.cpp:
(WebCore::WorkerThreadableLoader::WorkerThreadableLoader):
* Source/WebCore/loader/cache/CachedResourceRequest.cpp:
(WebCore::CachedResourceRequest::updateReferrerAndOriginHeaders):
* Source/WebCore/page/LocalDOMWindow.cpp:
(WebCore::LocalDOMWindow::setLocation):
(WebCore::LocalDOMWindow::createWindow):
* Source/WebCore/page/SecurityPolicy.cpp:
(WebCore::SecurityPolicy::shouldHideReferrer):
(WebCore::SecurityPolicy::referrerToOriginString):
(WebCore::SecurityPolicy::generateReferrerHeader):
* Source/WebCore/page/SecurityPolicy.h:
* Source/WebCore/page/csp/ContentSecurityPolicy.cpp:
(WebCore::ContentSecurityPolicy::createURLForReporting const):
(WebCore::ContentSecurityPolicy::reportViolation const):
* Source/WebCore/platform/network/ResourceRequestBase.cpp:
(WebCore::ResourceRequestBase::setExistingHTTPReferrerToOriginString):
* Source/WebKit/WebProcess/Plugins/PluginView.cpp:
(WebKit::PluginView::loadMainResource):

Canonical link: https://commits.webkit.org/275281@main
Constellation committed Feb 24, 2024
1 parent aa1a84a commit 88f5d64

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK