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

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

Issue 143313002: Implement URLSearchParams. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: More tests + ref count unattached URLSearchParams objects Created 6 years, 11 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: Source/core/dom/DOMURLUtils.cpp
diff --git a/Source/core/dom/DOMURLUtils.cpp b/Source/core/dom/DOMURLUtils.cpp
index 7e1fa195c5af5d86fe00115f540654c8e164e65c..697f8525f1cdaee11be493ffd55d879e8b88f1bf 100644
--- a/Source/core/dom/DOMURLUtils.cpp
+++ b/Source/core/dom/DOMURLUtils.cpp
@@ -27,10 +27,18 @@
#include "config.h"
#include "core/dom/DOMURLUtils.h"
+#include "bindings/v8/ExceptionState.h"
#include "platform/weborigin/KnownPorts.h"
+#include "wtf/PassOwnPtr.h"
namespace WebCore {
+void DOMURLUtils::update(DOMURLUtils* impl)
+{
+ KURL url = impl->url();
+ updateSearchParams(impl, url.query());
+}
+
void DOMURLUtils::setHref(DOMURLUtils* impl, const String& value)
{
impl->setInput(value);
@@ -122,6 +130,12 @@ void DOMURLUtils::setSearch(DOMURLUtils* impl, const String& value)
if (!url.isValid())
return;
url.setQuery(value);
+
+ if (!value.isEmpty() && value[0] == '?')
+ updateSearchParams(impl, value.substring(1));
+ else
+ updateSearchParams(impl, value);
+
impl->setURL(url);
}
@@ -139,4 +153,53 @@ void DOMURLUtils::setHash(DOMURLUtils* impl, const String& value)
impl->setURL(url);
}
+DOMURLSearchParams* DOMURLUtils::searchParams(DOMURLUtils* impl)
+{
+ if (!impl->m_searchParams)
+ createSearchParams(impl, impl->url().query());
+ return impl->m_searchParams.get();
+}
+
+void DOMURLUtils::createSearchParams(DOMURLUtils* impl, const String& queryString)
+{
+ if (!impl->m_searchParams) {
+ RefPtr<DOMURLSearchParams> searchParams = DOMURLSearchParams::create(queryString, impl);
+ impl->m_searchParams = adoptPtr(searchParams.get());
+ } else {
+ updateSearchParams(impl, queryString);
+ }
+}
+
+void DOMURLUtils::updateSearchParams(DOMURLUtils* impl, const String& queryString)
+{
+ if (!impl->m_searchParams)
+ return;
+
+ ASSERT(impl->m_searchParams->urlObject() == impl);
+ impl->m_searchParams->setInput(queryString);
+}
+
+void DOMURLUtils::setSearchParams(DOMURLUtils* impl, DOMURLSearchParams* searchParams, ExceptionState& exceptionState)
+{
+ if (!searchParams) {
+ exceptionState.throwTypeError("Value is not an URLSearchParams object.");
+ return;
+ }
+ if (searchParams == impl->m_searchParams)
+ return;
+
+ // Let go of previous; GC reclaims eventually.
+ if (impl->m_searchParams) {
+ impl->m_searchParams->setURLObject(0);
+ DOMURLSearchParams* ALLOW_UNUSED oldParams = impl->m_searchParams.leakPtr();
+ }
+ if (searchParams->urlObject()) {
arv (Not doing code reviews) 2014/01/22 16:12:05 Is there a test covering this?
sof 2014/01/22 19:27:09 Yes, url-searchparam-constructor.html ("URLSearchP
+ RefPtr<DOMURLSearchParams> copiedParams = DOMURLSearchParams::create(searchParams, impl);
+ impl->m_searchParams = adoptPtr(copiedParams.get());
+ } else {
+ searchParams->setURLObject(impl);
+ impl->m_searchParams = adoptPtr(searchParams);
+ }
+}
+
} // namespace WebCore

Powered by Google App Engine
This is Rietveld 408576698