| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2009 Google Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions are | |
| 6 * met: | |
| 7 * | |
| 8 * * Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * * Redistributions in binary form must reproduce the above | |
| 11 * copyright notice, this list of conditions and the following disclaimer | |
| 12 * in the documentation and/or other materials provided with the | |
| 13 * distribution. | |
| 14 * * Neither the name of Google Inc. nor the names of its | |
| 15 * contributors may be used to endorse or promote products derived from | |
| 16 * this software without specific prior written permission. | |
| 17 * | |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 29 */ | |
| 30 | |
| 31 #include "config.h" | |
| 32 #include "WebHTTPBody.h" | |
| 33 | |
| 34 #include "FormData.h" | |
| 35 | |
| 36 using namespace WebCore; | |
| 37 | |
| 38 namespace WebKit { | |
| 39 | |
| 40 class WebHTTPBodyPrivate : public FormData { | |
| 41 }; | |
| 42 | |
| 43 void WebHTTPBody::initialize() | |
| 44 { | |
| 45 assign(static_cast<WebHTTPBodyPrivate*>(FormData::create().releaseRef())); | |
| 46 } | |
| 47 | |
| 48 void WebHTTPBody::reset() | |
| 49 { | |
| 50 assign(0); | |
| 51 } | |
| 52 | |
| 53 void WebHTTPBody::assign(const WebHTTPBody& other) | |
| 54 { | |
| 55 WebHTTPBodyPrivate* p = const_cast<WebHTTPBodyPrivate*>(other.m_private); | |
| 56 if (p) | |
| 57 p->ref(); | |
| 58 assign(p); | |
| 59 } | |
| 60 | |
| 61 size_t WebHTTPBody::elementCount() const | |
| 62 { | |
| 63 ASSERT(!isNull()); | |
| 64 return m_private->elements().size(); | |
| 65 } | |
| 66 | |
| 67 bool WebHTTPBody::elementAt(size_t index, Element& result) const | |
| 68 { | |
| 69 ASSERT(!isNull()); | |
| 70 | |
| 71 if (index >= m_private->elements().size()) | |
| 72 return false; | |
| 73 | |
| 74 const FormDataElement& element = m_private->elements()[index]; | |
| 75 | |
| 76 switch (element.m_type) { | |
| 77 case FormDataElement::data: | |
| 78 result.type = Element::TypeData; | |
| 79 result.data.assign(element.m_data.data(), element.m_data.size()); | |
| 80 result.filePath.reset(); | |
| 81 break; | |
| 82 case FormDataElement::encodedFile: | |
| 83 result.type = Element::TypeFile; | |
| 84 result.data.reset(); | |
| 85 result.filePath = element.m_filename; | |
| 86 break; | |
| 87 default: | |
| 88 ASSERT_NOT_REACHED(); | |
| 89 return false; | |
| 90 } | |
| 91 | |
| 92 return true; | |
| 93 } | |
| 94 | |
| 95 void WebHTTPBody::appendData(const WebData& data) | |
| 96 { | |
| 97 ensureMutable(); | |
| 98 // FIXME: FormDataElement::m_data should be a SharedBuffer<char>. Then we | |
| 99 // could avoid this buffer copy. | |
| 100 m_private->appendData(data.data(), data.size()); | |
| 101 } | |
| 102 | |
| 103 void WebHTTPBody::appendFile(const WebString& filePath) | |
| 104 { | |
| 105 ensureMutable(); | |
| 106 m_private->appendFile(filePath); | |
| 107 } | |
| 108 | |
| 109 long long WebHTTPBody::identifier() const | |
| 110 { | |
| 111 ASSERT(!isNull()); | |
| 112 return m_private->identifier(); | |
| 113 } | |
| 114 | |
| 115 void WebHTTPBody::setIdentifier(long long identifier) | |
| 116 { | |
| 117 ensureMutable(); | |
| 118 return m_private->setIdentifier(identifier); | |
| 119 } | |
| 120 | |
| 121 WebHTTPBody::WebHTTPBody(const PassRefPtr<FormData>& data) | |
| 122 : m_private(static_cast<WebHTTPBodyPrivate*>(data.releaseRef())) | |
| 123 { | |
| 124 } | |
| 125 | |
| 126 WebHTTPBody& WebHTTPBody::operator=(const PassRefPtr<FormData>& data) | |
| 127 { | |
| 128 assign(static_cast<WebHTTPBodyPrivate*>(data.releaseRef())); | |
| 129 return *this; | |
| 130 } | |
| 131 | |
| 132 WebHTTPBody::operator PassRefPtr<FormData>() const | |
| 133 { | |
| 134 return m_private; | |
| 135 } | |
| 136 | |
| 137 void WebHTTPBody::assign(WebHTTPBodyPrivate* p) | |
| 138 { | |
| 139 // p is already ref'd for us by the caller | |
| 140 if (m_private) | |
| 141 m_private->deref(); | |
| 142 m_private = p; | |
| 143 } | |
| 144 | |
| 145 void WebHTTPBody::ensureMutable() | |
| 146 { | |
| 147 ASSERT(!isNull()); | |
| 148 if (!m_private->hasOneRef()) | |
| 149 assign(static_cast<WebHTTPBodyPrivate*>(m_private->copy().releaseRef())); | |
| 150 } | |
| 151 | |
| 152 } // namespace WebKit | |
| OLD | NEW |