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

Side by Side 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * Copyright (C) 2012 Motorola Mobility Inc. 3 * Copyright (C) 2012 Motorola Mobility Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the 12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution. 13 * documentation and/or other materials provided with the distribution.
14 * 14 *
15 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 15 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
16 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 18 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
19 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 21 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */ 25 */
26 26
27 #include "config.h" 27 #include "config.h"
28 #include "core/dom/DOMURLUtils.h" 28 #include "core/dom/DOMURLUtils.h"
29 29
30 #include "bindings/v8/ExceptionState.h"
30 #include "platform/weborigin/KnownPorts.h" 31 #include "platform/weborigin/KnownPorts.h"
32 #include "wtf/PassOwnPtr.h"
31 33
32 namespace WebCore { 34 namespace WebCore {
33 35
36 void DOMURLUtils::update(DOMURLUtils* impl)
37 {
38 KURL url = impl->url();
39 updateSearchParams(impl, url.query());
40 }
41
34 void DOMURLUtils::setHref(DOMURLUtils* impl, const String& value) 42 void DOMURLUtils::setHref(DOMURLUtils* impl, const String& value)
35 { 43 {
36 impl->setInput(value); 44 impl->setInput(value);
37 } 45 }
38 46
39 void DOMURLUtils::setProtocol(DOMURLUtils* impl, const String& value) 47 void DOMURLUtils::setProtocol(DOMURLUtils* impl, const String& value)
40 { 48 {
41 KURL url = impl->url(); 49 KURL url = impl->url();
42 if (url.isNull()) 50 if (url.isNull())
43 return; 51 return;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 url.setPath(value); 123 url.setPath(value);
116 impl->setURL(url); 124 impl->setURL(url);
117 } 125 }
118 126
119 void DOMURLUtils::setSearch(DOMURLUtils* impl, const String& value) 127 void DOMURLUtils::setSearch(DOMURLUtils* impl, const String& value)
120 { 128 {
121 KURL url = impl->url(); 129 KURL url = impl->url();
122 if (!url.isValid()) 130 if (!url.isValid())
123 return; 131 return;
124 url.setQuery(value); 132 url.setQuery(value);
133
134 if (!value.isEmpty() && value[0] == '?')
135 updateSearchParams(impl, value.substring(1));
136 else
137 updateSearchParams(impl, value);
138
125 impl->setURL(url); 139 impl->setURL(url);
126 } 140 }
127 141
128 void DOMURLUtils::setHash(DOMURLUtils* impl, const String& value) 142 void DOMURLUtils::setHash(DOMURLUtils* impl, const String& value)
129 { 143 {
130 KURL url = impl->url(); 144 KURL url = impl->url();
131 if (url.isNull()) 145 if (url.isNull())
132 return; 146 return;
133 147
134 if (value[0] == '#') 148 if (value[0] == '#')
135 url.setFragmentIdentifier(value.substring(1)); 149 url.setFragmentIdentifier(value.substring(1));
136 else 150 else
137 url.setFragmentIdentifier(value); 151 url.setFragmentIdentifier(value);
138 152
139 impl->setURL(url); 153 impl->setURL(url);
140 } 154 }
141 155
156 DOMURLSearchParams* DOMURLUtils::searchParams(DOMURLUtils* impl)
157 {
158 if (!impl->m_searchParams)
159 createSearchParams(impl, impl->url().query());
160 return impl->m_searchParams.get();
161 }
162
163 void DOMURLUtils::createSearchParams(DOMURLUtils* impl, const String& queryStrin g)
164 {
165 if (!impl->m_searchParams) {
166 RefPtr<DOMURLSearchParams> searchParams = DOMURLSearchParams::create(que ryString, impl);
167 impl->m_searchParams = adoptPtr(searchParams.get());
168 } else {
169 updateSearchParams(impl, queryString);
170 }
171 }
172
173 void DOMURLUtils::updateSearchParams(DOMURLUtils* impl, const String& queryStrin g)
174 {
175 if (!impl->m_searchParams)
176 return;
177
178 ASSERT(impl->m_searchParams->urlObject() == impl);
179 impl->m_searchParams->setInput(queryString);
180 }
181
182 void DOMURLUtils::setSearchParams(DOMURLUtils* impl, DOMURLSearchParams* searchP arams, ExceptionState& exceptionState)
183 {
184 if (!searchParams) {
185 exceptionState.throwTypeError("Value is not an URLSearchParams object.") ;
186 return;
187 }
188 if (searchParams == impl->m_searchParams)
189 return;
190
191 // Let go of previous; GC reclaims eventually.
192 if (impl->m_searchParams) {
193 impl->m_searchParams->setURLObject(0);
194 DOMURLSearchParams* ALLOW_UNUSED oldParams = impl->m_searchParams.leakPt r();
195 }
196 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
197 RefPtr<DOMURLSearchParams> copiedParams = DOMURLSearchParams::create(sea rchParams, impl);
198 impl->m_searchParams = adoptPtr(copiedParams.get());
199 } else {
200 searchParams->setURLObject(impl);
201 impl->m_searchParams = adoptPtr(searchParams);
202 }
203 }
204
142 } // namespace WebCore 205 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698