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

Side by Side Diff: third_party/WebKit/Source/core/svg/SVGURIReference.h

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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2005, 2008, 2009 Nikolas Zimmermann <zimmermann@kde.org> 2 * Copyright (C) 2004, 2005, 2008, 2009 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> 3 * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org>
4 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public 6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either 7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version. 8 * version 2 of the License, or (at your option) any later version.
9 * 9 *
10 * This library is distributed in the hope that it will be useful, 10 * This library is distributed in the hope that it will be useful,
(...skipping 30 matching lines...) Expand all
41 // SVGURIReference. 41 // SVGURIReference.
42 static const AtomicString& legacyHrefString(const SVGElement&); 42 static const AtomicString& legacyHrefString(const SVGElement&);
43 43
44 // Like above, but for elements that inherit from SVGURIReference. Resolves 44 // Like above, but for elements that inherit from SVGURIReference. Resolves
45 // against the base URL of the passed Document. 45 // against the base URL of the passed Document.
46 KURL legacyHrefURL(const Document&) const; 46 KURL legacyHrefURL(const Document&) const;
47 47
48 static AtomicString fragmentIdentifierFromIRIString(const String&, const Tre eScope&); 48 static AtomicString fragmentIdentifierFromIRIString(const String&, const Tre eScope&);
49 static Element* targetElementFromIRIString(const String&, const TreeScope&, AtomicString* = nullptr); 49 static Element* targetElementFromIRIString(const String&, const TreeScope&, AtomicString* = nullptr);
50 50
51 static inline bool isExternalURIReference(const String& uri, const Document& document)
52 {
53 // Fragment-only URIs are always internal if the baseURL is same as the document URL.
54 // This is common case, so check that first to avoid resolving URL (whic h is relatively expensive). See crbug.com/557979
55 if (document.baseURL() == document.url() && uri.startsWith('#'))
56 return false;
57
58 // If the URI matches our documents URL, we're dealing with a local refe rence.
59 KURL url = document.completeURL(uri);
60 return !equalIgnoringFragmentIdentifier(url, document.url());
61 }
62
63 const String& hrefString() const { return m_href->currentValue()->value(); } 51 const String& hrefString() const { return m_href->currentValue()->value(); }
64 52
65 // JS API 53 // JS API
66 SVGAnimatedHref* href() const { return m_href.get(); } 54 SVGAnimatedHref* href() const { return m_href.get(); }
67 55
68 DECLARE_VIRTUAL_TRACE(); 56 DECLARE_VIRTUAL_TRACE();
69 57
70 protected: 58 protected:
71 explicit SVGURIReference(SVGElement*); 59 explicit SVGURIReference(SVGElement*);
72 60
73 private: 61 private:
74 Member<SVGAnimatedHref> m_href; 62 Member<SVGAnimatedHref> m_href;
75 }; 63 };
76 64
65 // Helper class used to resolve fragment references. Handles the 'local url
66 // flag' per https://drafts.csswg.org/css-values/#local-urls .
67 class SVGURLReferenceResolver {
68 STACK_ALLOCATED();
69 public:
70 SVGURLReferenceResolver(const String& urlString, const Document&);
71
72 bool isLocal() const;
73 KURL absoluteUrl() const;
74 AtomicString fragmentIdentifier() const;
75
76 private:
77 const String& m_relativeUrl;
78 Member<const Document> m_document;
79 mutable KURL m_absoluteUrl;
80 bool m_isLocal;
81 };
82
77 } // namespace blink 83 } // namespace blink
78 84
79 #endif // SVGURIReference_h 85 #endif // SVGURIReference_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698