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

Side by Side Diff: sky/engine/platform/network/FormData.cpp

Issue 1239633002: Remove //sky/engine/platform/network (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: rebase Created 5 years, 5 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 | « sky/engine/platform/network/FormData.h ('k') | sky/engine/platform/network/FormDataBuilder.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2004, 2006, 2008, 2011 Apple Inc. All rights reserved.
3 * Copyright (C) 2009 Google Inc. All rights reserved.
4 * Copyright (C) 2012 Digia Plc. and/or its subsidiary(-ies)
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 */
21
22 #include "sky/engine/platform/network/FormData.h"
23
24 #include "sky/engine/platform/network/FormDataBuilder.h"
25 #include "sky/engine/wtf/text/CString.h"
26 #include "sky/engine/wtf/text/TextEncoding.h"
27
28 namespace blink {
29
30 inline FormData::FormData()
31 : m_identifier(0)
32 , m_alwaysStream(false)
33 , m_containsPasswordData(false)
34 {
35 }
36
37 inline FormData::FormData(const FormData& data)
38 : RefCounted<FormData>()
39 , m_elements(data.m_elements)
40 , m_identifier(data.m_identifier)
41 , m_alwaysStream(false)
42 , m_containsPasswordData(data.m_containsPasswordData)
43 {
44 }
45
46 FormData::~FormData()
47 {
48 }
49
50 PassRefPtr<FormData> FormData::create()
51 {
52 return adoptRef(new FormData);
53 }
54
55 PassRefPtr<FormData> FormData::create(const void* data, size_t size)
56 {
57 RefPtr<FormData> result = create();
58 result->appendData(data, size);
59 return result.release();
60 }
61
62 PassRefPtr<FormData> FormData::create(const CString& string)
63 {
64 RefPtr<FormData> result = create();
65 result->appendData(string.data(), string.length());
66 return result.release();
67 }
68
69 PassRefPtr<FormData> FormData::create(const Vector<char>& vector)
70 {
71 RefPtr<FormData> result = create();
72 result->appendData(vector.data(), vector.size());
73 return result.release();
74 }
75
76 PassRefPtr<FormData> FormData::copy() const
77 {
78 return adoptRef(new FormData(*this));
79 }
80
81 PassRefPtr<FormData> FormData::deepCopy() const
82 {
83 RefPtr<FormData> formData(create());
84
85 formData->m_alwaysStream = m_alwaysStream;
86
87 size_t n = m_elements.size();
88 formData->m_elements.reserveInitialCapacity(n);
89 for (size_t i = 0; i < n; ++i) {
90 const FormDataElement& e = m_elements[i];
91 switch (e.m_type) {
92 case FormDataElement::data:
93 formData->m_elements.uncheckedAppend(FormDataElement(e.m_data));
94 break;
95 }
96 }
97 return formData.release();
98 }
99
100 void FormData::appendData(const void* data, size_t size)
101 {
102 if (m_elements.isEmpty() || m_elements.last().m_type != FormDataElement::dat a)
103 m_elements.append(FormDataElement());
104 FormDataElement& e = m_elements.last();
105 size_t oldSize = e.m_data.size();
106 e.m_data.grow(oldSize + size);
107 memcpy(e.m_data.data() + oldSize, data, size);
108 }
109
110 void FormData::flatten(Vector<char>& data) const
111 {
112 // Concatenate all the byte arrays, but omit any files.
113 data.clear();
114 size_t n = m_elements.size();
115 for (size_t i = 0; i < n; ++i) {
116 const FormDataElement& e = m_elements[i];
117 if (e.m_type == FormDataElement::data)
118 data.append(e.m_data.data(), static_cast<size_t>(e.m_data.size()));
119 }
120 }
121
122 String FormData::flattenToString() const
123 {
124 Vector<char> bytes;
125 flatten(bytes);
126 return Latin1Encoding().decode(reinterpret_cast<const char*>(bytes.data()), bytes.size());
127 }
128
129 unsigned long long FormData::sizeInBytes() const
130 {
131 unsigned size = 0;
132 size_t n = m_elements.size();
133 for (size_t i = 0; i < n; ++i) {
134 const FormDataElement& e = m_elements[i];
135 switch (e.m_type) {
136 case FormDataElement::data:
137 size += e.m_data.size();
138 break;
139 }
140 }
141 return size;
142 }
143
144 } // namespace blink
OLDNEW
« no previous file with comments | « sky/engine/platform/network/FormData.h ('k') | sky/engine/platform/network/FormDataBuilder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698