Index: Source/core/dom/DOMURLUtils.cpp |
diff --git a/Source/core/dom/DOMURLUtils.cpp b/Source/core/dom/DOMURLUtils.cpp |
index 7e1fa195c5af5d86fe00115f540654c8e164e65c..5ffd943d6df25365c50c5f6abecab0bee7605b1d 100644 |
--- a/Source/core/dom/DOMURLUtils.cpp |
+++ b/Source/core/dom/DOMURLUtils.cpp |
@@ -31,6 +31,19 @@ |
namespace WebCore { |
+DOMURLUtils::~DOMURLUtils() |
+{ |
+ // Safe, but not ideal. See setSearchParams() FIXME. |
+ if (m_searchParams.get()) |
Inactive
2014/01/20 22:06:12
FYI, you don't need this '.get()' in your conditio
sof
2014/01/21 13:20:11
Yes, thanks - tidied now.
|
+ m_searchParams->setURLObject(0); |
+} |
+ |
+void DOMURLUtils::update(DOMURLUtils* impl) |
+{ |
+ KURL url = impl->url(); |
+ setSearchParams(impl, url.query()); |
+} |
+ |
void DOMURLUtils::setHref(DOMURLUtils* impl, const String& value) |
{ |
impl->setInput(value); |
@@ -122,6 +135,12 @@ void DOMURLUtils::setSearch(DOMURLUtils* impl, const String& value) |
if (!url.isValid()) |
return; |
url.setQuery(value); |
+ |
+ if (!value.isEmpty() && value[0] == '?') |
+ setSearchParams(impl, value.substring(1)); |
+ else |
+ setSearchParams(impl, value); |
+ |
impl->setURL(url); |
} |
@@ -139,4 +158,59 @@ void DOMURLUtils::setHash(DOMURLUtils* impl, const String& value) |
impl->setURL(url); |
} |
+PassRefPtr<DOMURLSearchParams> DOMURLUtils::searchParams(DOMURLUtils* impl, bool& isNull) |
+{ |
+ if (!impl->m_searchParams.get()) |
+ setSearchParams(impl, impl->url().query()); |
+ isNull = false; |
+ return impl->m_searchParams.get(); |
+} |
+ |
+void DOMURLUtils::setSearchParams(DOMURLUtils* impl, const String& queryString) |
+{ |
+ if (!impl->m_searchParams.get()) { |
+ impl->m_searchParams = DOMURLSearchParams::create(queryString); |
+ // See FIXME below. |
+ impl->m_searchParams->setURLObject(impl); |
+ } else { |
+ ASSERT(impl->m_searchParams->getURLObject() == impl); |
+ impl->m_searchParams->setInput(queryString); |
+ } |
+} |
+ |
+void DOMURLUtils::setSearchParams(DOMURLUtils* impl, PassRefPtr<DOMURLSearchParams> searchParams) |
+{ |
+ // The spec tells us to ignore the setting if it is null.. |
+ if (searchParams.get()) { |
+ if (searchParams->getURLObject()) |
+ impl->m_searchParams = DOMURLSearchParams::create(searchParams.get()); |
+ else |
+ impl->m_searchParams = searchParams; |
+ |
+ // FIXME: setting the URL object on the searchParams object |
+ // really should create a strong reference back to the |
+ // URLUtils object. |
+ // |
+ // This is needed when the URLUtils object is no longer |
+ // otherwise referenced, but the searchParams object is. In |
+ // that case, the updating of the searchParams should still |
+ // have an effect on the URLUtils' underlying URL. |
+ // |
+ // A ref-count cycle is introduced if we do this, however. |
+ // |
+ // Notice that this will only happen if the searchParams |
+ // object doesn't have a pre-existing 'url object.' i.e., the |
+ // complexity here is due to the fact that URLSearchParams |
+ // object can be separately constructed, and then assigned a |
+ // URLUtils via its searchParams setter. |
+ // |
+ // How to appropriately handle the mutual dependency? Do not |
+ // have a solution yet, so the URLUtils object simply removes |
+ // itself as the 'url object' of its searchParams object when |
+ // it goes away. |
+ ASSERT(!impl->m_searchParams->getURLObject()); |
+ impl->m_searchParams->setURLObject(impl); |
+ } |
+} |
+ |
} // namespace WebCore |