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

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: 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 unified diff | Download patch
« no previous file with comments | « Source/core/dom/DOMURLUtils.h ('k') | Source/core/dom/URLSearchParams.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/core/v8/ExceptionState.h"
31 #if !URLUTILS_SUPPORTS_SEARCHPARAMS
32 #include "core/dom/ExceptionCode.h"
33 #endif
30 #include "platform/weborigin/KnownPorts.h" 34 #include "platform/weborigin/KnownPorts.h"
35 #include "wtf/PassOwnPtr.h"
31 36
32 namespace blink { 37 namespace blink {
33 38
39 DOMURLUtils::~DOMURLUtils()
40 {
41 }
42
43 void DOMURLUtils::update()
44 {
45 updateSearchParams(url().query());
46 }
47
34 void DOMURLUtils::setHref(const String& value) 48 void DOMURLUtils::setHref(const String& value)
35 { 49 {
36 setInput(value); 50 setInput(value);
37 } 51 }
38 52
39 void DOMURLUtils::setProtocol(const String& value) 53 void DOMURLUtils::setProtocol(const String& value)
40 { 54 {
41 KURL kurl = url(); 55 KURL kurl = url();
42 if (kurl.isNull()) 56 if (kurl.isNull())
43 return; 57 return;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 { 125 {
112 KURL kurl = url(); 126 KURL kurl = url();
113 if (!kurl.canSetPathname()) 127 if (!kurl.canSetPathname())
114 return; 128 return;
115 kurl.setPath(value); 129 kurl.setPath(value);
116 setURL(kurl); 130 setURL(kurl);
117 } 131 }
118 132
119 void DOMURLUtils::setSearch(const String& value) 133 void DOMURLUtils::setSearch(const String& value)
120 { 134 {
135 setQuery(value);
136
137 if (!value.isEmpty() && value[0] == '?')
138 updateSearchParams(value.substring(1));
139 else
140 updateSearchParams(value);
141 }
142
143 void DOMURLUtils::setQuery(const String& value)
144 {
121 KURL kurl = url(); 145 KURL kurl = url();
122 if (!kurl.isValid()) 146 if (!kurl.isValid())
123 return; 147 return;
124 kurl.setQuery(value); 148 kurl.setQuery(value);
125 setURL(kurl); 149 setURL(kurl);
126 } 150 }
127 151
128 void DOMURLUtils::setHash(const String& value) 152 void DOMURLUtils::setHash(const String& value)
129 { 153 {
130 KURL kurl = url(); 154 KURL kurl = url();
131 if (kurl.isNull()) 155 if (kurl.isNull())
132 return; 156 return;
133 157
134 if (value[0] == '#') 158 if (value[0] == '#')
135 kurl.setFragmentIdentifier(value.substring(1)); 159 kurl.setFragmentIdentifier(value.substring(1));
136 else 160 else
137 kurl.setFragmentIdentifier(value); 161 kurl.setFragmentIdentifier(value);
138 162
139 setURL(kurl); 163 setURL(kurl);
140 } 164 }
141 165
166 DOMURLSearchParams* DOMURLUtils::searchParams()
167 {
168 #if URLUTILS_SUPPORTS_SEARCHPARAMS
169 if (!m_searchParams)
170 createSearchParams(url().query());
171 return m_searchParams.get();
172 #else
173 // To make testing a bit more regular, return an object.
174 return DOMURLSearchParams::create(url().query());
175 #endif
176 }
177
178 void DOMURLUtils::createSearchParams(const String& queryString)
179 {
180 #if URLUTILS_SUPPORTS_SEARCHPARAMS
181 if (!m_searchParams)
182 m_searchParams = DOMURLSearchParams::create(queryString, this);
183 else
184 updateSearchParams(queryString);
185 #endif
186 }
187
188 void DOMURLUtils::updateSearchParams(const String& queryString)
189 {
190 #if URLUTILS_SUPPORTS_SEARCHPARAMS
191 if (!m_searchParams)
192 return;
193
194 ASSERT(m_searchParams->hasURLObject(this));
195 m_searchParams->setInput(queryString);
196 #endif
197 }
198
199 void DOMURLUtils::setSearchParams(DOMURLSearchParams* searchParams, ExceptionSta te& exceptionState)
200 {
201 #if URLUTILS_SUPPORTS_SEARCHPARAMS
202 if (!searchParams) {
203 exceptionState.throwTypeError("Value is not an URLSearchParams object.") ;
204 return;
205 }
206 // Remove ourselves from current query object's list of URL objects.
207 if (m_searchParams)
208 m_searchParams->dropURLObject(this);
209
210 searchParams->addURLObject(this);
211 m_searchParams = searchParams;
212
213 const String& query = searchParams->toString();
214 setQuery(query);
215 // NOTE: the spec currently has an idempotent 'update step' after setting
216 // the query. Left out here.
217 #else
218 exceptionState.throwDOMException(NotSupportedError, "Updating searchParams i s not supported.");
219 #endif
220 }
221
222 void DOMURLUtils::trace(Visitor* visitor)
223 {
224 #if URLUTILS_SUPPORTS_SEARCHPARAMS
225 visitor->trace(m_searchParams);
226 #endif
227 }
228
142 } // namespace blink 229 } // namespace blink
OLDNEW
« 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