Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/dom/URLSearchParams.h" | 5 #include "core/dom/URLSearchParams.h" |
| 6 | 6 |
| 7 #include "core/dom/DOMURL.h" | 7 #include "core/dom/DOMURL.h" |
| 8 #include "platform/network/FormDataEncoder.h" | 8 #include "platform/network/FormDataEncoder.h" |
| 9 #include "platform/weborigin/KURL.h" | 9 #include "platform/weborigin/KURL.h" |
| 10 #include "wtf/text/TextEncoding.h" | 10 #include "wtf/text/TextEncoding.h" |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 32 return true; | 32 return true; |
| 33 } | 33 } |
| 34 | 34 |
| 35 private: | 35 private: |
| 36 Vector<std::pair<String, String>> m_params; | 36 Vector<std::pair<String, String>> m_params; |
| 37 size_t m_current; | 37 size_t m_current; |
| 38 }; | 38 }; |
| 39 | 39 |
| 40 } // namespace | 40 } // namespace |
| 41 | 41 |
| 42 URLSearchParams* URLSearchParams::create(const URLSearchParamsInit& init) { | 42 URLSearchParams* URLSearchParams::create(const URLSearchParamsInit& init, |
| 43 ExceptionState& exceptionState) { | |
| 43 if (init.isUSVString()) { | 44 if (init.isUSVString()) { |
| 44 const String& queryString = init.getAsUSVString(); | 45 const String& queryString = init.getAsUSVString(); |
| 45 if (queryString.startsWith('?')) | 46 if (queryString.startsWith('?')) |
| 46 return new URLSearchParams(queryString.substring(1)); | 47 return new URLSearchParams(queryString.substring(1)); |
| 47 return new URLSearchParams(queryString); | 48 return new URLSearchParams(queryString); |
| 48 } | 49 } |
| 50 // TODO(sof): copy constructor no longer in the spec, | |
| 51 // consider removing. | |
| 49 if (init.isURLSearchParams()) | 52 if (init.isURLSearchParams()) |
| 50 return new URLSearchParams(init.getAsURLSearchParams()); | 53 return new URLSearchParams(init.getAsURLSearchParams()); |
| 51 | 54 |
| 55 if (init.isUSVStringSequenceSequence()) { | |
| 56 return URLSearchParams::create(init.getAsUSVStringSequenceSequence(), | |
| 57 exceptionState); | |
| 58 } | |
| 59 | |
| 52 DCHECK(init.isNull()); | 60 DCHECK(init.isNull()); |
| 53 return new URLSearchParams(String()); | 61 return new URLSearchParams(String()); |
| 54 } | 62 } |
| 55 | 63 |
| 64 URLSearchParams* URLSearchParams::create(const Vector<Vector<String>>& init, | |
| 65 ExceptionState& exceptionState) { | |
| 66 URLSearchParams* instance = new URLSearchParams(String()); | |
| 67 for (unsigned i = 0; i < init.size(); ++i) { | |
| 68 const Vector<String>& pair = init[i]; | |
| 69 if (pair.size() != 2) { | |
| 70 exceptionState.throwTypeError(ExceptionMessages::failedToConstruct( | |
| 71 "URLSearchParams", | |
| 72 "Sequence initializer must only contain pair elements")); | |
| 73 return nullptr; | |
| 74 } | |
| 75 instance->append(pair[0], pair[1]); | |
|
tyoshino (SeeGerritForStatus)
2017/03/01 08:07:26
can we populate m_params first and then runUpdateS
sof
2017/03/01 08:40:59
Done, runUpdateSteps() would be near no-op in this
| |
| 76 } | |
| 77 return instance; | |
| 78 } | |
| 79 | |
| 56 URLSearchParams::URLSearchParams(const String& queryString, DOMURL* urlObject) | 80 URLSearchParams::URLSearchParams(const String& queryString, DOMURL* urlObject) |
| 57 : m_urlObject(urlObject) { | 81 : m_urlObject(urlObject) { |
| 58 if (!queryString.isEmpty()) | 82 if (!queryString.isEmpty()) |
| 59 setInput(queryString); | 83 setInput(queryString); |
| 60 } | 84 } |
| 61 | 85 |
| 62 URLSearchParams::URLSearchParams(URLSearchParams* searchParams) { | 86 URLSearchParams::URLSearchParams(URLSearchParams* searchParams) { |
| 63 DCHECK(searchParams); | 87 DCHECK(searchParams); |
| 64 m_params = searchParams->m_params; | 88 m_params = searchParams->m_params; |
| 65 } | 89 } |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 202 return EncodedFormData::create(encodedData.data(), encodedData.size()); | 226 return EncodedFormData::create(encodedData.data(), encodedData.size()); |
| 203 } | 227 } |
| 204 | 228 |
| 205 PairIterable<String, String>::IterationSource* URLSearchParams::startIteration( | 229 PairIterable<String, String>::IterationSource* URLSearchParams::startIteration( |
| 206 ScriptState*, | 230 ScriptState*, |
| 207 ExceptionState&) { | 231 ExceptionState&) { |
| 208 return new URLSearchParamsIterationSource(m_params); | 232 return new URLSearchParamsIterationSource(m_params); |
| 209 } | 233 } |
| 210 | 234 |
| 211 } // namespace blink | 235 } // namespace blink |
| OLD | NEW |