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

Unified Diff: Source/core/html/HTMLAnchorElement.cpp

Issue 24066010: Implement URLUtils and URL interface (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: updates based on code review comments Created 7 years, 2 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
« no previous file with comments | « Source/core/html/HTMLAnchorElement.h ('k') | Source/core/html/HTMLAnchorElement.idl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/html/HTMLAnchorElement.cpp
diff --git a/Source/core/html/HTMLAnchorElement.cpp b/Source/core/html/HTMLAnchorElement.cpp
index 472c402190583e67ef9721ea2010461926fa8202..b08d41aa9cf129e04b04d93fd8c05393d33f4504 100644
--- a/Source/core/html/HTMLAnchorElement.cpp
+++ b/Source/core/html/HTMLAnchorElement.cpp
@@ -343,6 +343,26 @@ void HTMLAnchorElement::setHref(const AtomicString& value)
setAttribute(hrefAttr, value);
}
+KURL HTMLAnchorElement::url() const
+{
+ return href();
+}
+
+void HTMLAnchorElement::setURL(const KURL& url)
+{
+ setHref(url.string());
+}
+
+String HTMLAnchorElement::input() const
+{
+ return getAttribute(hrefAttr);
+}
+
+void HTMLAnchorElement::setInput(const String& value)
+{
+ setHref(value);
+}
+
bool HTMLAnchorElement::hasRel(uint32_t relation) const
{
return m_linkRelations & relation;
@@ -373,180 +393,12 @@ String HTMLAnchorElement::target() const
return getAttribute(targetAttr);
}
-String HTMLAnchorElement::hash() const
-{
- String fragmentIdentifier = href().fragmentIdentifier();
- if (fragmentIdentifier.isEmpty())
- return emptyString();
- return AtomicString(String("#" + fragmentIdentifier));
-}
-
-void HTMLAnchorElement::setHash(const String& value)
-{
- KURL url = href();
- if (value[0] == '#')
- url.setFragmentIdentifier(value.substring(1));
- else
- url.setFragmentIdentifier(value);
- setHref(url.string());
-}
-
-String HTMLAnchorElement::host() const
-{
- const KURL& url = href();
- if (url.hostEnd() == url.pathStart())
- return url.host();
- if (isDefaultPortForProtocol(url.port(), url.protocol()))
- return url.host();
- return url.host() + ":" + String::number(url.port());
-}
-
-void HTMLAnchorElement::setHost(const String& value)
-{
- if (value.isEmpty())
- return;
- KURL url = href();
- if (!url.canSetHostOrPort())
- return;
-
- size_t separator = value.find(':');
- if (!separator)
- return;
-
- if (separator == kNotFound) {
- url.setHost(value);
- } else {
- unsigned portEnd;
- unsigned port = parsePortFromStringPosition(value, separator + 1, portEnd);
- if (!port) {
- // http://dev.w3.org/html5/spec/infrastructure.html#url-decomposition-idl-attributes
- // specifically goes against RFC 3986 (p3.2) and
- // requires setting the port to "0" if it is set to empty string.
- url.setHostAndPort(value.substring(0, separator + 1) + "0");
- } else {
- if (isDefaultPortForProtocol(port, url.protocol()))
- url.setHostAndPort(value.substring(0, separator));
- else
- url.setHostAndPort(value.substring(0, portEnd));
- }
- }
- setHref(url.string());
-}
-
-String HTMLAnchorElement::hostname() const
-{
- return href().host();
-}
-
-void HTMLAnchorElement::setHostname(const String& value)
-{
- // Before setting new value:
- // Remove all leading U+002F SOLIDUS ("/") characters.
- unsigned i = 0;
- unsigned hostLength = value.length();
- while (value[i] == '/')
- i++;
-
- if (i == hostLength)
- return;
-
- KURL url = href();
- if (!url.canSetHostOrPort())
- return;
-
- url.setHost(value.substring(i));
- setHref(url.string());
-}
-
-String HTMLAnchorElement::pathname() const
-{
- return href().path();
-}
-
-void HTMLAnchorElement::setPathname(const String& value)
-{
- KURL url = href();
- if (!url.canSetPathname())
- return;
-
- if (value[0] == '/')
- url.setPath(value);
- else
- url.setPath("/" + value);
-
- setHref(url.string());
-}
-
-String HTMLAnchorElement::port() const
-{
- if (href().hasPort())
- return String::number(href().port());
-
- return emptyString();
-}
-
-void HTMLAnchorElement::setPort(const String& value)
-{
- KURL url = href();
- if (!url.canSetHostOrPort())
- return;
-
- // http://dev.w3.org/html5/spec/infrastructure.html#url-decomposition-idl-attributes
- // specifically goes against RFC 3986 (p3.2) and
- // requires setting the port to "0" if it is set to empty string.
- unsigned port = value.toUInt();
- if (isDefaultPortForProtocol(port, url.protocol()))
- url.removePort();
- else
- url.setPort(port);
-
- setHref(url.string());
-}
-
-String HTMLAnchorElement::protocol() const
-{
- return href().protocol() + ":";
-}
-
-void HTMLAnchorElement::setProtocol(const String& value)
-{
- KURL url = href();
- url.setProtocol(value);
- setHref(url.string());
-}
-
-String HTMLAnchorElement::search() const
-{
- String query = href().query();
- return query.isEmpty() ? emptyString() : "?" + query;
-}
-
-String HTMLAnchorElement::origin() const
-{
- RefPtr<SecurityOrigin> origin = SecurityOrigin::create(href());
- return origin->toString();
-}
-
-void HTMLAnchorElement::setSearch(const String& value)
-{
- KURL url = href();
- String newSearch = (value[0] == '?') ? value.substring(1) : value;
- // Make sure that '#' in the query does not leak to the hash.
- url.setQuery(newSearch.replaceWithLiteral('#', "%23"));
-
- setHref(url.string());
-}
String HTMLAnchorElement::text()
{
return innerText();
}
-String HTMLAnchorElement::toString() const
-{
- return href().string();
-}
-
bool HTMLAnchorElement::isLiveLink() const
{
return isLink() && treatLinkAsLiveForEventType(m_wasShiftKeyDownOnMouseDown ? MouseEventWithShiftKey : MouseEventWithoutShiftKey);
« no previous file with comments | « Source/core/html/HTMLAnchorElement.h ('k') | Source/core/html/HTMLAnchorElement.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698