Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(170)

Unified Diff: third_party/WebKit/Source/core/svg/SVGURIReference.cpp

Issue 2174833002: Make fragment-only URLs always be document-local references (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove isExternal...; add additional test Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/svg/SVGURIReference.cpp
diff --git a/third_party/WebKit/Source/core/svg/SVGURIReference.cpp b/third_party/WebKit/Source/core/svg/SVGURIReference.cpp
index 64fd240732119346f16d22c97426f888d9ad5cff..8ed6a8491170637a1fa62bff61283ce66ac2ff90 100644
--- a/third_party/WebKit/Source/core/svg/SVGURIReference.cpp
+++ b/third_party/WebKit/Source/core/svg/SVGURIReference.cpp
@@ -56,24 +56,47 @@ KURL SVGURIReference::legacyHrefURL(const Document& document) const
return document.completeURL(stripLeadingAndTrailingHTMLSpaces(hrefString()));
}
-AtomicString SVGURIReference::fragmentIdentifierFromIRIString(const String& urlString, const TreeScope& treeScope)
+SVGURLReferenceResolver::SVGURLReferenceResolver(const String& urlString, const Document& document)
+ : m_relativeUrl(urlString)
+ , m_document(&document)
+ , m_isLocal(urlString.startsWith('#'))
+{
+}
+
+KURL SVGURLReferenceResolver::absoluteUrl() const
+{
+ if (m_absoluteUrl.isNull())
+ m_absoluteUrl = m_document->completeURL(m_relativeUrl);
+ return m_absoluteUrl;
+}
+
+bool SVGURLReferenceResolver::isLocal() const
{
- const Document& document = treeScope.document();
+ return m_isLocal || equalIgnoringFragmentIdentifier(absoluteUrl(), m_document->url());
+}
+
+AtomicString SVGURLReferenceResolver::fragmentIdentifier() const
+{
+ // If this is a "fragment-only" URL, then the reference is always local, so
+ // just return what's after the '#' as the fragment.
+ if (m_isLocal)
+ return AtomicString(m_relativeUrl.substring(1));
+ return AtomicString(absoluteUrl().fragmentIdentifier());
+}
- KURL url = document.completeURL(urlString);
- if (!url.hasFragmentIdentifier() || !equalIgnoringFragmentIdentifier(url, document.url()))
+AtomicString SVGURIReference::fragmentIdentifierFromIRIString(const String& urlString, const TreeScope& treeScope)
+{
+ SVGURLReferenceResolver resolver(urlString, treeScope.document());
+ if (!resolver.isLocal())
return emptyAtom;
- return AtomicString(url.fragmentIdentifier());
+ return resolver.fragmentIdentifier();
}
Element* SVGURIReference::targetElementFromIRIString(const String& urlString, const TreeScope& treeScope, AtomicString* fragmentIdentifier)
{
- const Document& document = treeScope.document();
-
- KURL url = document.completeURL(urlString);
- if (!url.hasFragmentIdentifier() || !equalIgnoringFragmentIdentifier(url, document.url()))
+ AtomicString id = fragmentIdentifierFromIRIString(urlString, treeScope);
+ if (id.isEmpty())
return nullptr;
- AtomicString id(url.fragmentIdentifier());
if (fragmentIdentifier)
*fragmentIdentifier = id;
return treeScope.getElementById(id);
« no previous file with comments | « third_party/WebKit/Source/core/svg/SVGURIReference.h ('k') | third_party/WebKit/Source/core/svg/SVGUseElement.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698