OLD | NEW |
---|---|
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. |
(...skipping 13 matching lines...) Expand all Loading... | |
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 "platform/weborigin/KnownPorts.h" | 30 #include "platform/weborigin/KnownPorts.h" |
31 | 31 |
32 namespace WebCore { | 32 namespace WebCore { |
33 | 33 |
34 DOMURLUtils::~DOMURLUtils() | |
35 { | |
36 // Safe, but not ideal. See setSearchParams() FIXME. | |
37 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.
| |
38 m_searchParams->setURLObject(0); | |
39 } | |
40 | |
41 void DOMURLUtils::update(DOMURLUtils* impl) | |
42 { | |
43 KURL url = impl->url(); | |
44 setSearchParams(impl, url.query()); | |
45 } | |
46 | |
34 void DOMURLUtils::setHref(DOMURLUtils* impl, const String& value) | 47 void DOMURLUtils::setHref(DOMURLUtils* impl, const String& value) |
35 { | 48 { |
36 impl->setInput(value); | 49 impl->setInput(value); |
37 } | 50 } |
38 | 51 |
39 void DOMURLUtils::setProtocol(DOMURLUtils* impl, const String& value) | 52 void DOMURLUtils::setProtocol(DOMURLUtils* impl, const String& value) |
40 { | 53 { |
41 KURL url = impl->url(); | 54 KURL url = impl->url(); |
42 if (url.isNull()) | 55 if (url.isNull()) |
43 return; | 56 return; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
115 url.setPath(value); | 128 url.setPath(value); |
116 impl->setURL(url); | 129 impl->setURL(url); |
117 } | 130 } |
118 | 131 |
119 void DOMURLUtils::setSearch(DOMURLUtils* impl, const String& value) | 132 void DOMURLUtils::setSearch(DOMURLUtils* impl, const String& value) |
120 { | 133 { |
121 KURL url = impl->url(); | 134 KURL url = impl->url(); |
122 if (!url.isValid()) | 135 if (!url.isValid()) |
123 return; | 136 return; |
124 url.setQuery(value); | 137 url.setQuery(value); |
138 | |
139 if (!value.isEmpty() && value[0] == '?') | |
140 setSearchParams(impl, value.substring(1)); | |
141 else | |
142 setSearchParams(impl, value); | |
143 | |
125 impl->setURL(url); | 144 impl->setURL(url); |
126 } | 145 } |
127 | 146 |
128 void DOMURLUtils::setHash(DOMURLUtils* impl, const String& value) | 147 void DOMURLUtils::setHash(DOMURLUtils* impl, const String& value) |
129 { | 148 { |
130 KURL url = impl->url(); | 149 KURL url = impl->url(); |
131 if (url.isNull()) | 150 if (url.isNull()) |
132 return; | 151 return; |
133 | 152 |
134 if (value[0] == '#') | 153 if (value[0] == '#') |
135 url.setFragmentIdentifier(value.substring(1)); | 154 url.setFragmentIdentifier(value.substring(1)); |
136 else | 155 else |
137 url.setFragmentIdentifier(value); | 156 url.setFragmentIdentifier(value); |
138 | 157 |
139 impl->setURL(url); | 158 impl->setURL(url); |
140 } | 159 } |
141 | 160 |
161 PassRefPtr<DOMURLSearchParams> DOMURLUtils::searchParams(DOMURLUtils* impl, bool & isNull) | |
162 { | |
163 if (!impl->m_searchParams.get()) | |
164 setSearchParams(impl, impl->url().query()); | |
165 isNull = false; | |
166 return impl->m_searchParams.get(); | |
167 } | |
168 | |
169 void DOMURLUtils::setSearchParams(DOMURLUtils* impl, const String& queryString) | |
170 { | |
171 if (!impl->m_searchParams.get()) { | |
172 impl->m_searchParams = DOMURLSearchParams::create(queryString); | |
173 // See FIXME below. | |
174 impl->m_searchParams->setURLObject(impl); | |
175 } else { | |
176 ASSERT(impl->m_searchParams->getURLObject() == impl); | |
177 impl->m_searchParams->setInput(queryString); | |
178 } | |
179 } | |
180 | |
181 void DOMURLUtils::setSearchParams(DOMURLUtils* impl, PassRefPtr<DOMURLSearchPara ms> searchParams) | |
182 { | |
183 // The spec tells us to ignore the setting if it is null.. | |
184 if (searchParams.get()) { | |
185 if (searchParams->getURLObject()) | |
186 impl->m_searchParams = DOMURLSearchParams::create(searchParams.get() ); | |
187 else | |
188 impl->m_searchParams = searchParams; | |
189 | |
190 // FIXME: setting the URL object on the searchParams object | |
191 // really should create a strong reference back to the | |
192 // URLUtils object. | |
193 // | |
194 // This is needed when the URLUtils object is no longer | |
195 // otherwise referenced, but the searchParams object is. In | |
196 // that case, the updating of the searchParams should still | |
197 // have an effect on the URLUtils' underlying URL. | |
198 // | |
199 // A ref-count cycle is introduced if we do this, however. | |
200 // | |
201 // Notice that this will only happen if the searchParams | |
202 // object doesn't have a pre-existing 'url object.' i.e., the | |
203 // complexity here is due to the fact that URLSearchParams | |
204 // object can be separately constructed, and then assigned a | |
205 // URLUtils via its searchParams setter. | |
206 // | |
207 // How to appropriately handle the mutual dependency? Do not | |
208 // have a solution yet, so the URLUtils object simply removes | |
209 // itself as the 'url object' of its searchParams object when | |
210 // it goes away. | |
211 ASSERT(!impl->m_searchParams->getURLObject()); | |
212 impl->m_searchParams->setURLObject(impl); | |
213 } | |
214 } | |
215 | |
142 } // namespace WebCore | 216 } // namespace WebCore |
OLD | NEW |