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

Unified Diff: Source/core/dom/DOMURLUtils.cpp

Issue 143313002: Implement URLSearchParams. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebased Created 6 years, 4 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/dom/DOMURLUtils.h ('k') | Source/core/dom/URLSearchParams.idl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/dom/DOMURLUtils.cpp
diff --git a/Source/core/dom/DOMURLUtils.cpp b/Source/core/dom/DOMURLUtils.cpp
index a3940bb17a5eedd78cfd3d168fbf4fccb1bab973..7b983e388fa4b1772ae075c481332e8760b69203 100644
--- a/Source/core/dom/DOMURLUtils.cpp
+++ b/Source/core/dom/DOMURLUtils.cpp
@@ -27,10 +27,24 @@
#include "config.h"
#include "core/dom/DOMURLUtils.h"
+#include "bindings/core/v8/ExceptionState.h"
+#if !URLUTILS_SUPPORTS_SEARCHPARAMS
+#include "core/dom/ExceptionCode.h"
+#endif
#include "platform/weborigin/KnownPorts.h"
+#include "wtf/PassOwnPtr.h"
namespace blink {
+DOMURLUtils::~DOMURLUtils()
+{
+}
+
+void DOMURLUtils::update()
+{
+ updateSearchParams(url().query());
+}
+
void DOMURLUtils::setHref(const String& value)
{
setInput(value);
@@ -118,6 +132,16 @@ void DOMURLUtils::setPathname(const String& value)
void DOMURLUtils::setSearch(const String& value)
{
+ setQuery(value);
+
+ if (!value.isEmpty() && value[0] == '?')
+ updateSearchParams(value.substring(1));
+ else
+ updateSearchParams(value);
+}
+
+void DOMURLUtils::setQuery(const String& value)
+{
KURL kurl = url();
if (!kurl.isValid())
return;
@@ -139,4 +163,67 @@ void DOMURLUtils::setHash(const String& value)
setURL(kurl);
}
+DOMURLSearchParams* DOMURLUtils::searchParams()
+{
+#if URLUTILS_SUPPORTS_SEARCHPARAMS
+ if (!m_searchParams)
+ createSearchParams(url().query());
+ return m_searchParams.get();
+#else
+ // To make testing a bit more regular, return an object.
+ return DOMURLSearchParams::create(url().query());
+#endif
+}
+
+void DOMURLUtils::createSearchParams(const String& queryString)
+{
+#if URLUTILS_SUPPORTS_SEARCHPARAMS
+ if (!m_searchParams)
+ m_searchParams = DOMURLSearchParams::create(queryString, this);
+ else
+ updateSearchParams(queryString);
+#endif
+}
+
+void DOMURLUtils::updateSearchParams(const String& queryString)
+{
+#if URLUTILS_SUPPORTS_SEARCHPARAMS
+ if (!m_searchParams)
+ return;
+
+ ASSERT(m_searchParams->hasURLObject(this));
+ m_searchParams->setInput(queryString);
+#endif
+}
+
+void DOMURLUtils::setSearchParams(DOMURLSearchParams* searchParams, ExceptionState& exceptionState)
+{
+#if URLUTILS_SUPPORTS_SEARCHPARAMS
+ if (!searchParams) {
+ exceptionState.throwTypeError("Value is not an URLSearchParams object.");
+ return;
+ }
+ // Remove ourselves from current query object's list of URL objects.
+ if (m_searchParams)
+ m_searchParams->dropURLObject(this);
+
+ searchParams->addURLObject(this);
+ m_searchParams = searchParams;
+
+ const String& query = searchParams->toString();
+ setQuery(query);
+ // NOTE: the spec currently has an idempotent 'update step' after setting
+ // the query. Left out here.
+#else
+ exceptionState.throwDOMException(NotSupportedError, "Updating searchParams is not supported.");
+#endif
+}
+
+void DOMURLUtils::trace(Visitor* visitor)
+{
+#if URLUTILS_SUPPORTS_SEARCHPARAMS
+ visitor->trace(m_searchParams);
+#endif
+}
+
} // namespace blink
« no previous file with comments | « Source/core/dom/DOMURLUtils.h ('k') | Source/core/dom/URLSearchParams.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698