diff options
author | Lars Knoll <lars.knoll@nokia.com> | 2009-03-23 09:18:55 (GMT) |
---|---|---|
committer | Simon Hausmann <simon.hausmann@nokia.com> | 2009-03-23 09:18:55 (GMT) |
commit | e5fcad302d86d316390c6b0f62759a067313e8a9 (patch) | |
tree | c2afbf6f1066b6ce261f14341cf6d310e5595bc1 /src/3rdparty/webkit/WebCore/platform/network | |
download | Qt-e5fcad302d86d316390c6b0f62759a067313e8a9.zip Qt-e5fcad302d86d316390c6b0f62759a067313e8a9.tar.gz Qt-e5fcad302d86d316390c6b0f62759a067313e8a9.tar.bz2 |
Long live Qt 4.5!
Diffstat (limited to 'src/3rdparty/webkit/WebCore/platform/network')
35 files changed, 4490 insertions, 0 deletions
diff --git a/src/3rdparty/webkit/WebCore/platform/network/AuthenticationChallengeBase.cpp b/src/3rdparty/webkit/WebCore/platform/network/AuthenticationChallengeBase.cpp new file mode 100644 index 0000000..df80441 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/platform/network/AuthenticationChallengeBase.cpp @@ -0,0 +1,113 @@ +/* + * Copyright (C) 2007 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "config.h" +#include "AuthenticationChallenge.h" + +#include "ResourceHandle.h" + +namespace WebCore { + +AuthenticationChallengeBase::AuthenticationChallengeBase() + : m_isNull(true) + , m_previousFailureCount(0) +{ +} + +AuthenticationChallengeBase::AuthenticationChallengeBase(const ProtectionSpace& protectionSpace, + const Credential& proposedCredential, + unsigned previousFailureCount, + const ResourceResponse& response, + const ResourceError& error) + : m_isNull(false) + , m_protectionSpace(protectionSpace) + , m_proposedCredential(proposedCredential) + , m_previousFailureCount(previousFailureCount) + , m_failureResponse(response) + , m_error(error) +{ +} + +unsigned AuthenticationChallengeBase::previousFailureCount() const +{ + return m_previousFailureCount; +} + +const Credential& AuthenticationChallengeBase::proposedCredential() const +{ + return m_proposedCredential; +} + +const ProtectionSpace& AuthenticationChallengeBase::protectionSpace() const +{ + return m_protectionSpace; +} + +const ResourceResponse& AuthenticationChallengeBase::failureResponse() const +{ + return m_failureResponse; +} + +const ResourceError& AuthenticationChallengeBase::error() const +{ + return m_error; +} + +bool AuthenticationChallengeBase::isNull() const +{ + return m_isNull; +} + +void AuthenticationChallengeBase::nullify() +{ + m_isNull = true; +} + +bool AuthenticationChallengeBase::compare(const AuthenticationChallenge& a, const AuthenticationChallenge& b) +{ + if (a.isNull() && b.isNull()) + return true; + + if (a.isNull() || b.isNull()) + return false; + + if (a.protectionSpace() != b.protectionSpace()) + return false; + + if (a.proposedCredential() != b.proposedCredential()) + return false; + + if (a.previousFailureCount() != b.previousFailureCount()) + return false; + + if (a.failureResponse() != b.failureResponse()) + return false; + + if (a.error() != b.error()) + return false; + + return AuthenticationChallenge::platformCompare(a, b); +} + +} diff --git a/src/3rdparty/webkit/WebCore/platform/network/AuthenticationChallengeBase.h b/src/3rdparty/webkit/WebCore/platform/network/AuthenticationChallengeBase.h new file mode 100644 index 0000000..9d85866 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/platform/network/AuthenticationChallengeBase.h @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2007 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef AuthenticationChallengeBase_h +#define AuthenticationChallengeBase_h + +#include "Credential.h" +#include "ProtectionSpace.h" +#include "ResourceResponse.h" +#include "ResourceError.h" + +namespace WebCore { + +class AuthenticationChallenge; + +class AuthenticationChallengeBase { +public: + AuthenticationChallengeBase(); + AuthenticationChallengeBase(const ProtectionSpace& protectionSpace, const Credential& proposedCredential, unsigned previousFailureCount, const ResourceResponse& response, const ResourceError& error); + + unsigned previousFailureCount() const; + const Credential& proposedCredential() const; + const ProtectionSpace& protectionSpace() const; + const ResourceResponse& failureResponse() const; + const ResourceError& error() const; + + bool isNull() const; + void nullify(); + + static bool compare(const AuthenticationChallenge& a, const AuthenticationChallenge& b); + +protected: + // The AuthenticationChallenge subclass may "shadow" this method to compare platform specific fields + static bool platformCompare(const AuthenticationChallengeBase&, const AuthenticationChallengeBase&) { return true; } + + bool m_isNull; + ProtectionSpace m_protectionSpace; + Credential m_proposedCredential; + unsigned m_previousFailureCount; + ResourceResponse m_failureResponse; + ResourceError m_error; +}; + +inline bool operator==(const AuthenticationChallenge& a, const AuthenticationChallenge& b) { return AuthenticationChallengeBase::compare(a, b); } +inline bool operator!=(const AuthenticationChallenge& a, const AuthenticationChallenge& b) { return !(a == b); } + +} + +#endif diff --git a/src/3rdparty/webkit/WebCore/platform/network/Credential.cpp b/src/3rdparty/webkit/WebCore/platform/network/Credential.cpp new file mode 100644 index 0000000..4743959 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/platform/network/Credential.cpp @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2007 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "config.h" +#include "Credential.h" + +namespace WebCore { + +// Need to enforce empty, non-null strings due to the pickiness of the String == String operator +// combined with the semantics of the String(NSString*) constructor +Credential::Credential() + : m_user("") + , m_password("") +{ +} + +// Need to enforce empty, non-null strings due to the pickiness of the String == String operator +// combined with the semantics of the String(NSString*) constructor +Credential::Credential(const String& user, const String& password, CredentialPersistence persistence) + : m_user(user.length() ? user : "") + , m_password(password.length() ? password : "") + , m_persistence(persistence) +{ +} + +const String& Credential::user() const +{ + return m_user; +} + +const String& Credential::password() const +{ + return m_password; +} + +bool Credential::hasPassword() const +{ + return !m_password.isEmpty(); +} + +CredentialPersistence Credential::persistence() const +{ + return m_persistence; +} + +bool operator==(const Credential& a, const Credential& b) +{ + if (a.user() != b.user()) + return false; + if (a.password() != b.password()) + return false; + if (a.persistence() != b.persistence()) + return false; + + return true; +} + +} + diff --git a/src/3rdparty/webkit/WebCore/platform/network/Credential.h b/src/3rdparty/webkit/WebCore/platform/network/Credential.h new file mode 100644 index 0000000..4d80490 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/platform/network/Credential.h @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2007 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef Credential_h +#define Credential_h + +#include "PlatformString.h" + +namespace WebCore { + +enum CredentialPersistence { + CredentialPersistenceNone, + CredentialPersistenceForSession, + CredentialPersistencePermanent +}; + +class Credential { + +public: + Credential(); + Credential(const String& user, const String& password, CredentialPersistence); + + const String& user() const; + const String& password() const; + bool hasPassword() const; + CredentialPersistence persistence() const; + +private: + String m_user; + String m_password; + CredentialPersistence m_persistence; +}; + +bool operator==(const Credential& a, const Credential& b); +inline bool operator!=(const Credential& a, const Credential& b) { return !(a == b); } + +}; +#endif diff --git a/src/3rdparty/webkit/WebCore/platform/network/DNS.h b/src/3rdparty/webkit/WebCore/platform/network/DNS.h new file mode 100644 index 0000000..c232272 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/platform/network/DNS.h @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2008 Collin Jackson <collinj@webkit.org> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef DNS_h +#define DNS_h + +namespace WebCore { + + class String; + + void prefetchDNS(const String& hostname); +} + +#endif diff --git a/src/3rdparty/webkit/WebCore/platform/network/FormData.cpp b/src/3rdparty/webkit/WebCore/platform/network/FormData.cpp new file mode 100644 index 0000000..0d31856 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/platform/network/FormData.cpp @@ -0,0 +1,167 @@ +/* + * Copyright (C) 2004, 2006, 2008 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "FormData.h" + +#include "CString.h" +#include "ChromeClient.h" +#include "FileSystem.h" +#include "TextEncoding.h" + +namespace WebCore { + +inline FormData::FormData() + : m_hasGeneratedFiles(false) + , m_alwaysStream(false) +{ +} + +inline FormData::FormData(const FormData& data) + : RefCounted<FormData>() + , m_elements(data.m_elements) + , m_hasGeneratedFiles(false) + , m_alwaysStream(false) +{ + // We shouldn't be copying FormData that hasn't already removed its generated files + // but just in case, make sure the new FormData is ready to generate its own files. + if (data.m_hasGeneratedFiles) { + size_t n = m_elements.size(); + for (size_t i = 0; i < n; ++i) { + FormDataElement& e = m_elements[i]; + if (e.m_type == FormDataElement::encodedFile) + e.m_generatedFilename = String(); + } + } +} + +FormData::~FormData() +{ + // This cleanup should've happened when the form submission finished. + // Just in case, let's assert, and do the cleanup anyway in release builds. + ASSERT(!m_hasGeneratedFiles); + removeGeneratedFilesIfNeeded(); +} + +PassRefPtr<FormData> FormData::create() +{ + return adoptRef(new FormData); +} + +PassRefPtr<FormData> FormData::create(const void* data, size_t size) +{ + RefPtr<FormData> result = create(); + result->appendData(data, size); + return result.release(); +} + +PassRefPtr<FormData> FormData::create(const CString& string) +{ + RefPtr<FormData> result = create(); + result->appendData(string.data(), string.length()); + return result.release(); +} + +PassRefPtr<FormData> FormData::create(const Vector<char>& vector) +{ + RefPtr<FormData> result = create(); + result->appendData(vector.data(), vector.size()); + return result.release(); +} + +PassRefPtr<FormData> FormData::copy() const +{ + return adoptRef(new FormData(*this)); +} + +void FormData::appendData(const void* data, size_t size) +{ + if (m_elements.isEmpty() || m_elements.last().m_type != FormDataElement::data) + m_elements.append(FormDataElement()); + FormDataElement& e = m_elements.last(); + size_t oldSize = e.m_data.size(); + e.m_data.grow(oldSize + size); + memcpy(e.m_data.data() + oldSize, data, size); +} + +void FormData::appendFile(const String& filename, bool shouldGenerateFile) +{ + m_elements.append(FormDataElement(filename, shouldGenerateFile)); +} + +void FormData::flatten(Vector<char>& data) const +{ + // Concatenate all the byte arrays, but omit any files. + data.clear(); + size_t n = m_elements.size(); + for (size_t i = 0; i < n; ++i) { + const FormDataElement& e = m_elements[i]; + if (e.m_type == FormDataElement::data) { + size_t oldSize = data.size(); + size_t delta = e.m_data.size(); + data.grow(oldSize + delta); + memcpy(data.data() + oldSize, e.m_data.data(), delta); + } + } +} + +String FormData::flattenToString() const +{ + Vector<char> bytes; + flatten(bytes); + return Latin1Encoding().decode(bytes.data(), bytes.size()); +} + +void FormData::generateFiles(ChromeClient* client) +{ + ASSERT(!m_hasGeneratedFiles); + + if (m_hasGeneratedFiles) + return; + + size_t n = m_elements.size(); + for (size_t i = 0; i < n; ++i) { + FormDataElement& e = m_elements[i]; + if (e.m_type == FormDataElement::encodedFile && e.m_shouldGenerateFile) { + e.m_generatedFilename = client->generateReplacementFile(e.m_filename); + m_hasGeneratedFiles = true; + } + } +} + +void FormData::removeGeneratedFilesIfNeeded() +{ + if (!m_hasGeneratedFiles) + return; + + size_t n = m_elements.size(); + for (size_t i = 0; i < n; ++i) { + FormDataElement& e = m_elements[i]; + if (e.m_type == FormDataElement::encodedFile && !e.m_generatedFilename.isEmpty()) { + ASSERT(e.m_shouldGenerateFile); + String directory = directoryName(e.m_generatedFilename); + deleteFile(e.m_generatedFilename); + deleteEmptyDirectory(directory); + e.m_generatedFilename = String(); + } + } + m_hasGeneratedFiles = false; +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/platform/network/FormData.h b/src/3rdparty/webkit/WebCore/platform/network/FormData.h new file mode 100644 index 0000000..cb91fab --- /dev/null +++ b/src/3rdparty/webkit/WebCore/platform/network/FormData.h @@ -0,0 +1,109 @@ +/* + * Copyright (C) 2004, 2006, 2008 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef FormData_h +#define FormData_h + +#include "PlatformString.h" +#include <wtf/RefCounted.h> +#include <wtf/Vector.h> + +namespace WebCore { + +class ChromeClient; + +class FormDataElement { +public: + FormDataElement() : m_type(data) { } + FormDataElement(const Vector<char>& array) : m_type(data), m_data(array) { } + FormDataElement(const String& filename, bool shouldGenerateFile) : m_type(encodedFile), m_filename(filename), m_shouldGenerateFile(shouldGenerateFile) { } + + enum { data, encodedFile } m_type; + Vector<char> m_data; + String m_filename; + String m_generatedFilename; + bool m_shouldGenerateFile; +}; + +inline bool operator==(const FormDataElement& a, const FormDataElement& b) +{ + if (&a == &b) + return true; + + if (a.m_type != b.m_type) + return false; + if (a.m_data != b.m_data) + return false; + if (a.m_filename != b.m_filename) + return false; + + return true; +} + +inline bool operator!=(const FormDataElement& a, const FormDataElement& b) +{ + return !(a == b); +} + +class FormData : public RefCounted<FormData> { +public: + static PassRefPtr<FormData> create(); + static PassRefPtr<FormData> create(const void*, size_t); + static PassRefPtr<FormData> create(const CString&); + static PassRefPtr<FormData> create(const Vector<char>&); + PassRefPtr<FormData> copy() const; + ~FormData(); + + void appendData(const void* data, size_t); + void appendFile(const String& filename, bool shouldGenerateFile = false); + + void flatten(Vector<char>&) const; // omits files + String flattenToString() const; // omits files + + bool isEmpty() const { return m_elements.isEmpty(); } + const Vector<FormDataElement>& elements() const { return m_elements; } + + void generateFiles(ChromeClient*); + void removeGeneratedFilesIfNeeded(); + + bool alwaysStream() const { return m_alwaysStream; } + void setAlwaysStream(bool alwaysStream) { m_alwaysStream = alwaysStream; } + +private: + FormData(); + FormData(const FormData&); + + Vector<FormDataElement> m_elements; + bool m_hasGeneratedFiles; + bool m_alwaysStream; +}; + +inline bool operator==(const FormData& a, const FormData& b) +{ + return a.elements() == b.elements(); +} + +inline bool operator!=(const FormData& a, const FormData& b) +{ + return a.elements() != b.elements(); +} + +} // namespace WebCore + +#endif diff --git a/src/3rdparty/webkit/WebCore/platform/network/FormDataBuilder.cpp b/src/3rdparty/webkit/WebCore/platform/network/FormDataBuilder.cpp new file mode 100644 index 0000000..27bdee3 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/platform/network/FormDataBuilder.cpp @@ -0,0 +1,238 @@ +/* + * Copyright (C) 1999 Lars Knoll (knoll@kde.org) + * (C) 1999 Antti Koivisto (koivisto@kde.org) + * (C) 2001 Dirk Mueller (mueller@kde.org) + * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. + * (C) 2006 Alexey Proskuryakov (ap@nypop.com) + * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "FormDataBuilder.h" + +#include "CString.h" +#include "Document.h" +#include "Frame.h" +#include "FrameLoader.h" +#include "TextEncoding.h" + +#include <limits> +#include <wtf/Assertions.h> +#include <wtf/RandomNumber.h> + +namespace WebCore { + +FormDataBuilder::FormDataBuilder() + : m_isPostMethod(false) + , m_isMultiPartForm(false) + , m_encodingType("application/x-www-form-urlencoded") +{ +} + +FormDataBuilder::~FormDataBuilder() +{ +} + +void FormDataBuilder::parseEncodingType(const String& type) +{ + if (type.contains("multipart", false) || type.contains("form-data", false)) { + m_encodingType = "multipart/form-data"; + m_isMultiPartForm = true; + } else if (type.contains("text", false) || type.contains("plain", false)) { + m_encodingType = "text/plain"; + m_isMultiPartForm = false; + } else { + m_encodingType = "application/x-www-form-urlencoded"; + m_isMultiPartForm = false; + } +} + +void FormDataBuilder::parseMethodType(const String& type) +{ + if (equalIgnoringCase(type, "post")) + m_isPostMethod = true; + else if (equalIgnoringCase(type, "get")) + m_isPostMethod = false; +} + +TextEncoding FormDataBuilder::dataEncoding(Document* document) const +{ + String acceptCharset = m_acceptCharset; + acceptCharset.replace(',', ' '); + + Vector<String> charsets; + acceptCharset.split(' ', charsets); + + TextEncoding encoding; + + Vector<String>::const_iterator end = charsets.end(); + for (Vector<String>::const_iterator it = charsets.begin(); it != end; ++it) { + if ((encoding = TextEncoding(*it)).isValid()) + return encoding; + } + + if (Frame* frame = document->frame()) + return frame->loader()->encoding(); + + return Latin1Encoding(); +} + +// Helper functions +static inline void append(Vector<char>& buffer, char string) +{ + buffer.append(string); +} + +static inline void append(Vector<char>& buffer, const char* string) +{ + buffer.append(string, strlen(string)); +} + +static inline void append(Vector<char>& buffer, const CString& string) +{ + buffer.append(string.data(), string.length()); +} + +Vector<char> FormDataBuilder::generateUniqueBoundaryString() +{ + Vector<char> boundary; + + // The RFC 2046 spec says the alphanumeric characters plus the + // following characters are legal for boundaries: '()+_,-./:=? + // However the following characters, though legal, cause some sites + // to fail: (),./:= (http://bugs.webkit.org/show_bug.cgi?id=13352) + static const char alphaNumericEncodingMap[64] = { + 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, + 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, + 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, + 0x59, 0x5A, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, + 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, + 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, + 0x77, 0x78, 0x79, 0x7A, 0x30, 0x31, 0x32, 0x33, + 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x2B, 0x41 + // FIXME <rdar://problem/5252577> gmail does not accept legal characters in the form boundary + // As stated above, some legal characters cause, sites to fail. Specifically + // the / character which was the last character in the above array. I have + // replaced the last character with another character already in the array + // (notice the first and last values are both 0x41, A). Instead of picking + // another unique legal character for boundary strings that, because it has + // never been tested, may or may not break other sites, I simply + // replaced / with A. This means A is twice as likely to occur in our boundary + // strings than any other character but I think this is fine for the time being. + // The FIXME here is about restoring the / character once the aforementioned + // radar has been resolved. + }; + + // Start with an informative prefix. + append(boundary, "----WebKitFormBoundary"); + + // Append 16 random 7bit ascii AlphaNumeric characters. + Vector<char> randomBytes; + + for (unsigned i = 0; i < 4; ++i) { + unsigned randomness = static_cast<unsigned>(WTF::randomNumber() * (std::numeric_limits<unsigned>::max() + 1.0)); + randomBytes.append(alphaNumericEncodingMap[(randomness >> 24) & 0x3F]); + randomBytes.append(alphaNumericEncodingMap[(randomness >> 16) & 0x3F]); + randomBytes.append(alphaNumericEncodingMap[(randomness >> 8) & 0x3F]); + randomBytes.append(alphaNumericEncodingMap[randomness & 0x3F]); + } + + boundary.append(randomBytes); + boundary.append(0); // Add a 0 at the end so we can use this as a C-style string. + return boundary; +} + +void FormDataBuilder::beginMultiPartHeader(Vector<char>& buffer, const CString& boundary, const CString& name) +{ + addBoundaryToMultiPartHeader(buffer, boundary); + + append(buffer, "Content-Disposition: form-data; name=\""); + append(buffer, name); + append(buffer, '"'); +} + +void FormDataBuilder::addBoundaryToMultiPartHeader(Vector<char>& buffer, const CString& boundary, bool isLastBoundary) +{ + append(buffer, "--"); + append(buffer, boundary); + + if (isLastBoundary) + append(buffer, "--"); + + append(buffer, "\r\n"); +} + +void FormDataBuilder::addFilenameToMultiPartHeader(Vector<char>& buffer, const TextEncoding& encoding, const String& filename) +{ + // FIXME: This won't work if the filename includes a " mark, + // or control characters like CR or LF. This also does strange + // things if the filename includes characters you can't encode + // in the website's character set. + append(buffer, "; filename=\""); + append(buffer, encoding.encode(filename.characters(), filename.length(), QuestionMarksForUnencodables)); + append(buffer, '"'); +} + +void FormDataBuilder::addContentTypeToMultiPartHeader(Vector<char>& buffer, const CString& mimeType) +{ + append(buffer, "\r\nContent-Type: "); + append(buffer, mimeType); +} + +void FormDataBuilder::finishMultiPartHeader(Vector<char>& buffer) +{ + append(buffer, "\r\n\r\n"); +} + +void FormDataBuilder::addKeyValuePairAsFormData(Vector<char>& buffer, const CString& key, const CString& value) +{ + if (!buffer.isEmpty()) + append(buffer, '&'); + + encodeStringAsFormData(buffer, key); + append(buffer, '='); + encodeStringAsFormData(buffer, value); +} + +void FormDataBuilder::encodeStringAsFormData(Vector<char>& buffer, const CString& string) +{ + static const char hexDigits[17] = "0123456789ABCDEF"; + + // Same safe characters as Netscape for compatibility. + static const char safeCharacters[] = "-._*"; + + // http://www.w3.org/TR/html4/interact/forms.html#h-17.13.4.1 + unsigned length = string.length(); + for (unsigned i = 0; i < length; ++i) { + unsigned char c = string.data()[i]; + + if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || strchr(safeCharacters, c)) + append(buffer, c); + else if (c == ' ') + append(buffer, '+'); + else if (c == '\n' || (c == '\r' && (i + 1 >= length || string.data()[i + 1] != '\n'))) + append(buffer, "%0D%0A"); + else if (c != '\r') { + append(buffer, '%'); + append(buffer, hexDigits[c >> 4]); + append(buffer, hexDigits[c & 0xF]); + } + } +} + +} diff --git a/src/3rdparty/webkit/WebCore/platform/network/FormDataBuilder.h b/src/3rdparty/webkit/WebCore/platform/network/FormDataBuilder.h new file mode 100644 index 0000000..666f0c1 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/platform/network/FormDataBuilder.h @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef FormDataBuilder_h +#define FormDataBuilder_h + +#include "PlatformString.h" +#include <wtf/Noncopyable.h> + +namespace WebCore { + +class CString; +class Document; +class TextEncoding; + +class FormDataBuilder : Noncopyable { +public: + FormDataBuilder(); + ~FormDataBuilder(); + + bool isPostMethod() const { return m_isPostMethod; } + void setIsPostMethod(bool value) { m_isPostMethod = value; } + + bool isMultiPartForm() const { return m_isMultiPartForm; } + void setIsMultiPartForm(bool value) { m_isMultiPartForm = value; } + + String encodingType() const { return m_encodingType; } + void setEncodingType(const String& value) { m_encodingType = value; } + + String acceptCharset() const { return m_acceptCharset; } + void setAcceptCharset(const String& value) { m_acceptCharset = value; } + + void parseEncodingType(const String&); + void parseMethodType(const String&); + + TextEncoding dataEncoding(Document*) const; + + // Helper functions used by HTMLFormElement/WMLGoElement for multi-part form data + static Vector<char> generateUniqueBoundaryString(); + static void beginMultiPartHeader(Vector<char>&, const CString& boundary, const CString& name); + static void addBoundaryToMultiPartHeader(Vector<char>&, const CString& boundary, bool isLastBoundary = false); + static void addFilenameToMultiPartHeader(Vector<char>&, const TextEncoding&, const String& filename); + static void addContentTypeToMultiPartHeader(Vector<char>&, const CString& mimeType); + static void finishMultiPartHeader(Vector<char>&); + + // Helper functions used by HTMLFormElement/WMLGoElement for non multi-part form data + static void addKeyValuePairAsFormData(Vector<char>&, const CString& key, const CString& value); + static void encodeStringAsFormData(Vector<char>&, const CString&); + +private: + bool m_isPostMethod; + bool m_isMultiPartForm; + + String m_encodingType; + String m_acceptCharset; +}; + +} + +#endif diff --git a/src/3rdparty/webkit/WebCore/platform/network/HTTPHeaderMap.h b/src/3rdparty/webkit/WebCore/platform/network/HTTPHeaderMap.h new file mode 100644 index 0000000..37ba39a --- /dev/null +++ b/src/3rdparty/webkit/WebCore/platform/network/HTTPHeaderMap.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef HTTPHeaderMap_h +#define HTTPHeaderMap_h + +#include "AtomicString.h" +#include "AtomicStringHash.h" +#include "StringHash.h" +#include <wtf/HashMap.h> + +namespace WebCore { + + typedef HashMap<AtomicString, String, CaseFoldingHash> HTTPHeaderMap; + +} // namespace WebCore + +#endif // HTTPHeaderMap_h diff --git a/src/3rdparty/webkit/WebCore/platform/network/HTTPParsers.cpp b/src/3rdparty/webkit/WebCore/platform/network/HTTPParsers.cpp new file mode 100644 index 0000000..0858fc9 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/platform/network/HTTPParsers.cpp @@ -0,0 +1,186 @@ +/* + * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org) + * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "HTTPParsers.h" + +#include "PlatformString.h" + +namespace WebCore { + +// true if there is more to parse +static inline bool skipWhiteSpace(const String& str, int& pos, bool fromHttpEquivMeta) +{ + int len = str.length(); + + if (fromHttpEquivMeta) + while (pos != len && str[pos] <= ' ') + ++pos; + else + while (pos != len && (str[pos] == '\t' || str[pos] == ' ')) + ++pos; + + return pos != len; +} + +bool parseHTTPRefresh(const String& refresh, bool fromHttpEquivMeta, double& delay, String& url) +{ + int len = refresh.length(); + int pos = 0; + + if (!skipWhiteSpace(refresh, pos, fromHttpEquivMeta)) + return false; + + while (pos != len && refresh[pos] != ',' && refresh[pos] != ';') + ++pos; + + if (pos == len) { // no URL + url = String(); + bool ok; + delay = refresh.stripWhiteSpace().toDouble(&ok); + return ok; + } else { + bool ok; + delay = refresh.left(pos).stripWhiteSpace().toDouble(&ok); + if (!ok) + return false; + + ++pos; + skipWhiteSpace(refresh, pos, fromHttpEquivMeta); + int urlStartPos = pos; + if (refresh.find("url", urlStartPos, false) == urlStartPos) { + urlStartPos += 3; + skipWhiteSpace(refresh, urlStartPos, fromHttpEquivMeta); + if (refresh[urlStartPos] == '=') { + ++urlStartPos; + skipWhiteSpace(refresh, urlStartPos, fromHttpEquivMeta); + } else + urlStartPos = pos; // e.g. "Refresh: 0; url.html" + } + + int urlEndPos = len; + + if (refresh[urlStartPos] == '"' || refresh[urlStartPos] == '\'') { + UChar quotationMark = refresh[urlStartPos]; + urlStartPos++; + while (urlEndPos > urlStartPos) { + urlEndPos--; + if (refresh[urlEndPos] == quotationMark) + break; + } + } + + url = refresh.substring(urlStartPos, urlEndPos - urlStartPos).stripWhiteSpace(); + return true; + } +} + +String filenameFromHTTPContentDisposition(const String& value) +{ + Vector<String> keyValuePairs; + value.split(';', keyValuePairs); + + unsigned length = keyValuePairs.size(); + for (unsigned i = 0; i < length; i++) { + int valueStartPos = keyValuePairs[i].find('='); + if (valueStartPos < 0) + continue; + + String key = keyValuePairs[i].left(valueStartPos).stripWhiteSpace(); + + if (key.isEmpty() || key != "filename") + continue; + + String value = keyValuePairs[i].substring(valueStartPos + 1).stripWhiteSpace(); + + // Remove quotes if there are any + if (value[0] == '\"') + value = value.substring(1, value.length() - 2); + + return value; + } + + return String(); +} + +String extractMIMETypeFromMediaType(const String& mediaType) +{ + String mimeType; + unsigned length = mediaType.length(); + for (unsigned offset = 0; offset < length; offset++) { + UChar c = mediaType[offset]; + if (c == ';') + break; + else if (isSpaceOrNewline(c)) // FIXME: This seems wrong, " " is an invalid MIME type character according to RFC 2045. bug 8644 + continue; + // FIXME: This is a very slow way to build a string, given WebCore::String's implementation. + mimeType += String(&c, 1); + } + return mimeType; +} + +String extractCharsetFromMediaType(const String& mediaType) +{ + int pos = 0; + int length = (int)mediaType.length(); + + while (pos < length) { + pos = mediaType.find("charset", pos, false); + if (pos <= 0) + return String(); + + // is what we found a beginning of a word? + if (mediaType[pos-1] > ' ' && mediaType[pos-1] != ';') { + pos += 7; + continue; + } + + pos += 7; + + // skip whitespace + while (pos != length && mediaType[pos] <= ' ') + ++pos; + + if (mediaType[pos++] != '=') // this "charset" substring wasn't a parameter name, but there may be others + continue; + + while (pos != length && (mediaType[pos] <= ' ' || mediaType[pos] == '"' || mediaType[pos] == '\'')) + ++pos; + + // we don't handle spaces within quoted parameter values, because charset names cannot have any + int endpos = pos; + while (pos != length && mediaType[endpos] > ' ' && mediaType[endpos] != '"' && mediaType[endpos] != '\'' && mediaType[endpos] != ';') + ++endpos; + + return mediaType.substring(pos, endpos-pos); + } + + return String(); +} +} diff --git a/src/3rdparty/webkit/WebCore/platform/network/HTTPParsers.h b/src/3rdparty/webkit/WebCore/platform/network/HTTPParsers.h new file mode 100644 index 0000000..28a9ce9 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/platform/network/HTTPParsers.h @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org) + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef HTTPParsers_h +#define HTTPParsers_h + +namespace WebCore { + + class String; + + bool parseHTTPRefresh(const String& refresh, bool fromHttpEquivMeta, double& delay, String& url); + String filenameFromHTTPContentDisposition(const String&); + String extractMIMETypeFromMediaType(const String&); + String extractCharsetFromMediaType(const String&); +} + +#endif diff --git a/src/3rdparty/webkit/WebCore/platform/network/NetworkStateNotifier.cpp b/src/3rdparty/webkit/WebCore/platform/network/NetworkStateNotifier.cpp new file mode 100644 index 0000000..7638478 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/platform/network/NetworkStateNotifier.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2008 Apple Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "NetworkStateNotifier.h" + +#include <wtf/Assertions.h> +#include <wtf/StdLibExtras.h> +#include <wtf/Threading.h> + +namespace WebCore { + +NetworkStateNotifier& networkStateNotifier() +{ + AtomicallyInitializedStatic(NetworkStateNotifier*, networkStateNotifier = new NetworkStateNotifier); + + return *networkStateNotifier; +} + +void NetworkStateNotifier::setNetworkStateChangedFunction(void(*function)()) +{ + ASSERT(!m_networkStateChangedFunction); + + m_networkStateChangedFunction = function; +} + +} diff --git a/src/3rdparty/webkit/WebCore/platform/network/NetworkStateNotifier.h b/src/3rdparty/webkit/WebCore/platform/network/NetworkStateNotifier.h new file mode 100644 index 0000000..0189f5f --- /dev/null +++ b/src/3rdparty/webkit/WebCore/platform/network/NetworkStateNotifier.h @@ -0,0 +1,100 @@ +/* + * Copyright (C) 2008 Apple Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef NetworkStateNotifier_h +#define NetworkStateNotifier_h + +#if PLATFORM(MAC) + +#include <wtf/RetainPtr.h> +#include "Timer.h" + +typedef const struct __CFArray * CFArrayRef; +typedef const struct __SCDynamicStore * SCDynamicStoreRef; + +#elif PLATFORM(CHROMIUM) + +#include "NetworkStateNotifierPrivate.h" + +#elif PLATFORM(WIN) + +#include <windows.h> + +#endif + +namespace WebCore { + +class NetworkStateNotifier { +public: + NetworkStateNotifier(); + void setNetworkStateChangedFunction(void (*)()); + + bool onLine() const { return m_isOnLine; } + +private: + bool m_isOnLine; + void (*m_networkStateChangedFunction)(); + + void updateState(); + +#if PLATFORM(MAC) + void networkStateChangeTimerFired(Timer<NetworkStateNotifier>*); + + static void dynamicStoreCallback(SCDynamicStoreRef, CFArrayRef changedKeys, void *info); + + RetainPtr<SCDynamicStoreRef> m_store; + Timer<NetworkStateNotifier> m_networkStateChangeTimer; + +#elif PLATFORM(WIN) + static void CALLBACK addrChangeCallback(void*, BOOLEAN timedOut); + static void callAddressChanged(void*); + void addressChanged(); + + void registerForAddressChange(); + HANDLE m_waitHandle; + OVERLAPPED m_overlapped; + +#elif PLATFORM(CHROMIUM) + NetworkStateNotifierPrivate p; +#endif +}; + +#if !PLATFORM(MAC) && !PLATFORM(WIN) && !PLATFORM(CHROMIUM) + +inline NetworkStateNotifier::NetworkStateNotifier() + : m_isOnLine(true) + , m_networkStateChangedFunction(0) +{ +} + +inline void NetworkStateNotifier::updateState() { } + +#endif + +NetworkStateNotifier& networkStateNotifier(); + +}; + +#endif // NetworkStateNotifier_h diff --git a/src/3rdparty/webkit/WebCore/platform/network/ProtectionSpace.cpp b/src/3rdparty/webkit/WebCore/platform/network/ProtectionSpace.cpp new file mode 100644 index 0000000..bd73558 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/platform/network/ProtectionSpace.cpp @@ -0,0 +1,119 @@ +/* + * Copyright (C) 2007 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "config.h" +#include "ProtectionSpace.h" + +#if USE(CFNETWORK) && !PLATFORM(MAC) +#include "AuthenticationCF.h" +#include <CFNetwork/CFURLProtectionSpacePriv.h> +#include <wtf/RetainPtr.h> +#endif + +namespace WebCore { + +// Need to enforce empty, non-null strings due to the pickiness of the String == String operator +// combined with the semantics of the String(NSString*) constructor +ProtectionSpace::ProtectionSpace() + : m_host("") + , m_realm("") +{ +} + +// Need to enforce empty, non-null strings due to the pickiness of the String == String operator +// combined with the semantics of the String(NSString*) constructor +ProtectionSpace::ProtectionSpace(const String& host, int port, ProtectionSpaceServerType serverType, const String& realm, ProtectionSpaceAuthenticationScheme authenticationScheme) + : m_host(host.length() ? host : "") + , m_port(port) + , m_serverType(serverType) + , m_realm(realm.length() ? realm : "") + , m_authenticationScheme(authenticationScheme) +{ +} + +const String& ProtectionSpace::host() const +{ + return m_host; +} + +int ProtectionSpace::port() const +{ + return m_port; +} + +ProtectionSpaceServerType ProtectionSpace::serverType() const +{ + return m_serverType; +} + +bool ProtectionSpace::isProxy() const +{ + return (m_serverType == ProtectionSpaceProxyHTTP || + m_serverType == ProtectionSpaceProxyHTTPS || + m_serverType == ProtectionSpaceProxyFTP || + m_serverType == ProtectionSpaceProxySOCKS); +} + +const String& ProtectionSpace::realm() const +{ + return m_realm; +} + +ProtectionSpaceAuthenticationScheme ProtectionSpace::authenticationScheme() const +{ + return m_authenticationScheme; +} + +bool ProtectionSpace::receivesCredentialSecurely() const +{ +#if USE(CFNETWORK) && !PLATFORM(MAC) + RetainPtr<CFURLProtectionSpaceRef> cfSpace(AdoptCF, createCF(*this)); + return cfSpace && CFURLProtectionSpaceReceivesCredentialSecurely(cfSpace.get()); +#else + return (m_serverType == ProtectionSpaceServerHTTPS || + m_serverType == ProtectionSpaceServerFTPS || + m_serverType == ProtectionSpaceProxyHTTPS || + m_authenticationScheme == ProtectionSpaceAuthenticationSchemeHTTPDigest); +#endif +} + +bool operator==(const ProtectionSpace& a, const ProtectionSpace& b) +{ + if (a.host() != b.host()) + return false; + if (a.port() != b.port()) + return false; + if (a.serverType() != b.serverType()) + return false; + if (a.realm() != b.realm()) + return false; + if (a.authenticationScheme() != b.authenticationScheme()) + return false; + + return true; +} + +} + + diff --git a/src/3rdparty/webkit/WebCore/platform/network/ProtectionSpace.h b/src/3rdparty/webkit/WebCore/platform/network/ProtectionSpace.h new file mode 100644 index 0000000..9a73cff --- /dev/null +++ b/src/3rdparty/webkit/WebCore/platform/network/ProtectionSpace.h @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2007 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef ProtectionSpace_h +#define ProtectionSpace_h + +#include "PlatformString.h" + +namespace WebCore { + +enum ProtectionSpaceServerType { + ProtectionSpaceServerHTTP = 1, + ProtectionSpaceServerHTTPS = 2, + ProtectionSpaceServerFTP = 3, + ProtectionSpaceServerFTPS = 4, + ProtectionSpaceProxyHTTP = 5, + ProtectionSpaceProxyHTTPS = 6, + ProtectionSpaceProxyFTP = 7, + ProtectionSpaceProxySOCKS = 8 +}; + +enum ProtectionSpaceAuthenticationScheme { + ProtectionSpaceAuthenticationSchemeDefault = 1, + ProtectionSpaceAuthenticationSchemeHTTPBasic = 2, + ProtectionSpaceAuthenticationSchemeHTTPDigest = 3, + ProtectionSpaceAuthenticationSchemeHTMLForm = 4, + ProtectionSpaceAuthenticationSchemeNTLM = 5, + ProtectionSpaceAuthenticationSchemeNegotiate = 6, +}; + +class ProtectionSpace { + +public: + ProtectionSpace(); + ProtectionSpace(const String& host, int port, ProtectionSpaceServerType, const String& realm, ProtectionSpaceAuthenticationScheme); + + const String& host() const; + int port() const; + ProtectionSpaceServerType serverType() const; + bool isProxy() const; + const String& realm() const; + ProtectionSpaceAuthenticationScheme authenticationScheme() const; + + bool receivesCredentialSecurely() const; + +private: + String m_host; + int m_port; + ProtectionSpaceServerType m_serverType; + String m_realm; + ProtectionSpaceAuthenticationScheme m_authenticationScheme; +}; + +bool operator==(const ProtectionSpace& a, const ProtectionSpace& b); +inline bool operator!=(const ProtectionSpace& a, const ProtectionSpace& b) { return !(a == b); } + +} +#endif diff --git a/src/3rdparty/webkit/WebCore/platform/network/ResourceErrorBase.cpp b/src/3rdparty/webkit/WebCore/platform/network/ResourceErrorBase.cpp new file mode 100644 index 0000000..1ea35b0 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/platform/network/ResourceErrorBase.cpp @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "ResourceError.h" + +namespace WebCore { + +void ResourceErrorBase::lazyInit() const +{ + const_cast<ResourceError*>(static_cast<const ResourceError*>(this))->platformLazyInit(); +} + +bool ResourceErrorBase::compare(const ResourceError& a, const ResourceError& b) +{ + if (a.isNull() && b.isNull()) + return true; + + if (a.isNull() || b.isNull()) + return false; + + if (a.domain() != b.domain()) + return false; + + if (a.errorCode() != b.errorCode()) + return false; + + if (a.failingURL() != b.failingURL()) + return false; + + if (a.localizedDescription() != b.localizedDescription()) + return false; + + if (a.isCancellation() != b.isCancellation()) + return false; + + return platformCompare(a, b); +} + +} diff --git a/src/3rdparty/webkit/WebCore/platform/network/ResourceErrorBase.h b/src/3rdparty/webkit/WebCore/platform/network/ResourceErrorBase.h new file mode 100644 index 0000000..4631324 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/platform/network/ResourceErrorBase.h @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ResourceErrorBase_h +#define ResourceErrorBase_h + +#include "PlatformString.h" + +namespace WebCore { + +class ResourceError; + +class ResourceErrorBase { +public: + bool isNull() const { return m_isNull; } + + const String& domain() const { lazyInit(); return m_domain; } + int errorCode() const { lazyInit(); return m_errorCode; } + const String& failingURL() const { lazyInit(); return m_failingURL; } + const String& localizedDescription() const { lazyInit(); return m_localizedDescription; } + + void setIsCancellation(bool isCancellation) { m_isCancellation = isCancellation; } + bool isCancellation() const { return m_isCancellation; } + + static bool compare(const ResourceError& a, const ResourceError& b); + +protected: + ResourceErrorBase() + : m_errorCode(0) + , m_isNull(true) + , m_isCancellation(false) + { + } + + ResourceErrorBase(const String& domain, int errorCode, const String& failingURL, const String& localizedDescription) + : m_domain(domain) + , m_errorCode(errorCode) + , m_failingURL(failingURL) + , m_localizedDescription(localizedDescription) + , m_isNull(false) + , m_isCancellation(false) + { + } + + void lazyInit() const; + + // The ResourceError subclass may "shadow" this method to lazily initialize platform specific fields + void platformLazyInit() {} + + // The ResourceError subclass may "shadow" this method to compare platform specific fields + static bool platformCompare(const ResourceError&, const ResourceError&) { return true; } + + String m_domain; + int m_errorCode; + String m_failingURL; + String m_localizedDescription; + bool m_isNull; + bool m_isCancellation; +}; + +inline bool operator==(const ResourceError& a, const ResourceError& b) { return ResourceErrorBase::compare(a, b); } +inline bool operator!=(const ResourceError& a, const ResourceError& b) { return !(a == b); } + +} // namespace WebCore + +#endif // ResourceErrorBase_h_ diff --git a/src/3rdparty/webkit/WebCore/platform/network/ResourceHandle.cpp b/src/3rdparty/webkit/WebCore/platform/network/ResourceHandle.cpp new file mode 100644 index 0000000..149411e --- /dev/null +++ b/src/3rdparty/webkit/WebCore/platform/network/ResourceHandle.cpp @@ -0,0 +1,202 @@ +/* + * Copyright (C) 2004, 2006, 2007, 2008 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "ResourceHandle.h" +#include "ResourceHandleInternal.h" + +#include "Logging.h" +#include "ResourceHandleClient.h" +#include "Timer.h" +#include <algorithm> + +namespace WebCore { + +static bool portAllowed(const ResourceRequest&); + +ResourceHandle::ResourceHandle(const ResourceRequest& request, ResourceHandleClient* client, bool defersLoading, + bool shouldContentSniff, bool mightDownloadFromHandle) + : d(new ResourceHandleInternal(this, request, client, defersLoading, shouldContentSniff, mightDownloadFromHandle)) +{ +} + +PassRefPtr<ResourceHandle> ResourceHandle::create(const ResourceRequest& request, ResourceHandleClient* client, + Frame* frame, bool defersLoading, bool shouldContentSniff, bool mightDownloadFromHandle) +{ + RefPtr<ResourceHandle> newHandle(adoptRef(new ResourceHandle(request, client, defersLoading, shouldContentSniff, mightDownloadFromHandle))); + + if (!request.url().isValid()) { + newHandle->scheduleFailure(InvalidURLFailure); + return newHandle.release(); + } + + if (!portAllowed(request)) { + newHandle->scheduleFailure(BlockedFailure); + return newHandle.release(); + } + + if (newHandle->start(frame)) + return newHandle.release(); + + return 0; +} + +void ResourceHandle::scheduleFailure(FailureType type) +{ + d->m_failureType = type; + d->m_failureTimer.startOneShot(0); +} + +void ResourceHandle::fireFailure(Timer<ResourceHandle>*) +{ + if (!client()) + return; + + switch (d->m_failureType) { + case BlockedFailure: + client()->wasBlocked(this); + return; + case InvalidURLFailure: + client()->cannotShowURL(this); + return; + } + + ASSERT_NOT_REACHED(); +} + +ResourceHandleClient* ResourceHandle::client() const +{ + return d->m_client; +} + +void ResourceHandle::setClient(ResourceHandleClient* client) +{ + d->m_client = client; +} + +const ResourceRequest& ResourceHandle::request() const +{ + return d->m_request; +} + +void ResourceHandle::clearAuthentication() +{ +#if PLATFORM(MAC) + d->m_currentMacChallenge = nil; +#elif USE(CFNETWORK) + d->m_currentCFChallenge = 0; +#endif + d->m_currentWebChallenge.nullify(); +} + +static bool portAllowed(const ResourceRequest& request) +{ + unsigned short port = request.url().port(); + + // Since most URLs don't have a port, return early for the "no port" case. + if (!port) + return true; + + // This blocked port list matches the port blocking that Mozilla implements. + // See http://www.mozilla.org/projects/netlib/PortBanning.html for more information. + static const unsigned short blockedPortList[] = { + 1, // tcpmux + 7, // echo + 9, // discard + 11, // systat + 13, // daytime + 15, // netstat + 17, // qotd + 19, // chargen + 20, // FTP-data + 21, // FTP-control + 22, // SSH + 23, // telnet + 25, // SMTP + 37, // time + 42, // name + 43, // nicname + 53, // domain + 77, // priv-rjs + 79, // finger + 87, // ttylink + 95, // supdup + 101, // hostriame + 102, // iso-tsap + 103, // gppitnp + 104, // acr-nema + 109, // POP2 + 110, // POP3 + 111, // sunrpc + 113, // auth + 115, // SFTP + 117, // uucp-path + 119, // nntp + 123, // NTP + 135, // loc-srv / epmap + 139, // netbios + 143, // IMAP2 + 179, // BGP + 389, // LDAP + 465, // SMTP+SSL + 512, // print / exec + 513, // login + 514, // shell + 515, // printer + 526, // tempo + 530, // courier + 531, // Chat + 532, // netnews + 540, // UUCP + 556, // remotefs + 563, // NNTP+SSL + 587, // ESMTP + 601, // syslog-conn + 636, // LDAP+SSL + 993, // IMAP+SSL + 995, // POP3+SSL + 2049, // NFS + 4045, // lockd + 6000, // X11 + }; + const unsigned short* const blockedPortListEnd = blockedPortList + + sizeof(blockedPortList) / sizeof(blockedPortList[0]); + + // If the port is not in the blocked port list, allow it. + if (!std::binary_search(blockedPortList, blockedPortListEnd, port)) + return true; + + // Allow ports 21 and 22 for FTP URLs, as Mozilla does. + if ((port == 21 || port == 22) && request.url().protocolIs("ftp")) + return true; + + // Allow any port number in a file URL, since the port number is ignored. + if (request.url().protocolIs("file")) + return true; + + return false; +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/platform/network/ResourceHandle.h b/src/3rdparty/webkit/WebCore/platform/network/ResourceHandle.h new file mode 100644 index 0000000..c93af21 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/platform/network/ResourceHandle.h @@ -0,0 +1,195 @@ +/* + * Copyright (C) 2004, 2006 Apple Computer, Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ResourceHandle_h +#define ResourceHandle_h + +#include "AuthenticationChallenge.h" +#include "HTTPHeaderMap.h" +#include <wtf/OwnPtr.h> + +#if PLATFORM(CF) +typedef const struct __CFData * CFDataRef; +#endif + +#if PLATFORM(WIN) +typedef unsigned long DWORD; +typedef unsigned long DWORD_PTR; +typedef void* LPVOID; +typedef LPVOID HINTERNET; +typedef unsigned WPARAM; +typedef long LPARAM; +typedef struct HWND__* HWND; +typedef _W64 long LONG_PTR; +typedef LONG_PTR LRESULT; +#endif + + +#if PLATFORM(MAC) +#include <wtf/RetainPtr.h> +#ifdef __OBJC__ +@class NSData; +@class NSError; +@class NSURLConnection; +@class WebCoreResourceHandleAsDelegate; +#else +class NSData; +class NSError; +class NSURLConnection; +class WebCoreResourceHandleAsDelegate; +typedef struct objc_object *id; +#endif +#endif + +#if USE(CFNETWORK) +typedef struct _CFURLConnection* CFURLConnectionRef; +typedef int CFHTTPCookieStorageAcceptPolicy; +typedef struct OpaqueCFHTTPCookieStorage* CFHTTPCookieStorageRef; +#endif + +namespace WebCore { + +class AuthenticationChallenge; +class Credential; +class FormData; +class Frame; +class KURL; +class ResourceError; +class ResourceHandleClient; +class ResourceHandleInternal; +class ResourceRequest; +class ResourceResponse; +class SchedulePair; +class SharedBuffer; + +template <typename T> class Timer; + +class ResourceHandle : public RefCounted<ResourceHandle> { +private: + ResourceHandle(const ResourceRequest&, ResourceHandleClient*, bool defersLoading, bool shouldContentSniff, bool mightDownloadFromHandle); + + enum FailureType { + BlockedFailure, + InvalidURLFailure + }; + +public: + // FIXME: should not need the Frame + static PassRefPtr<ResourceHandle> create(const ResourceRequest&, ResourceHandleClient*, Frame*, bool defersLoading, bool shouldContentSniff, bool mightDownloadFromHandle = false); + + static void loadResourceSynchronously(const ResourceRequest&, ResourceError&, ResourceResponse&, Vector<char>& data, Frame* frame); + static bool willLoadFromCache(ResourceRequest&); +#if PLATFORM(MAC) + static bool didSendBodyDataDelegateExists(); +#endif + + ~ResourceHandle(); + +#if PLATFORM(MAC) || USE(CFNETWORK) + bool shouldUseCredentialStorage(); +#endif +#if PLATFORM(MAC) || USE(CFNETWORK) || USE(CURL) + void didReceiveAuthenticationChallenge(const AuthenticationChallenge&); + void receivedCredential(const AuthenticationChallenge&, const Credential&); + void receivedRequestToContinueWithoutCredential(const AuthenticationChallenge&); + void receivedCancellation(const AuthenticationChallenge&); +#endif + +#if PLATFORM(MAC) + void didCancelAuthenticationChallenge(const AuthenticationChallenge&); + NSURLConnection *connection() const; + WebCoreResourceHandleAsDelegate *delegate(); + void releaseDelegate(); + id releaseProxy(); + + void schedule(SchedulePair*); + void unschedule(SchedulePair*); +#elif USE(CFNETWORK) + static CFRunLoopRef loaderRunLoop(); + CFURLConnectionRef connection() const; + CFURLConnectionRef releaseConnectionForDownload(); + static void setHostAllowsAnyHTTPSCertificate(const String&); + static void setClientCertificate(const String& host, CFDataRef); +#endif + +#if PLATFORM(WIN) && USE(CURL) + static void setHostAllowsAnyHTTPSCertificate(const String&); +#endif +#if PLATFORM(WIN) && USE(CURL) && PLATFORM(CF) + static void setClientCertificate(const String& host, CFDataRef); +#endif + + PassRefPtr<SharedBuffer> bufferedData(); + static bool supportsBufferedData(); + +#if USE(WININET) + void setHasReceivedResponse(bool = true); + bool hasReceivedResponse() const; + void fileLoadTimer(Timer<ResourceHandle>*); + void onHandleCreated(LPARAM); + void onRequestRedirected(LPARAM); + void onRequestComplete(LPARAM); + friend void __stdcall transferJobStatusCallback(HINTERNET, DWORD_PTR, DWORD, LPVOID, DWORD); + friend LRESULT __stdcall ResourceHandleWndProc(HWND, unsigned message, WPARAM, LPARAM); +#endif + +#if PLATFORM(QT) || USE(CURL) || USE(SOUP) + ResourceHandleInternal* getInternal() { return d.get(); } +#endif + + // Used to work around the fact that you don't get any more NSURLConnection callbacks until you return from the one you're in. + static bool loadsBlocked(); + + void clearAuthentication(); + void cancel(); + + // The client may be 0, in which case no callbacks will be made. + ResourceHandleClient* client() const; + void setClient(ResourceHandleClient*); + + void setDefersLoading(bool); + + const ResourceRequest& request() const; + + void fireFailure(Timer<ResourceHandle>*); + +private: +#if USE(SOUP) + bool startData(String urlString); + bool startHttp(String urlString); + bool startGio(String urlString); +#endif + + void scheduleFailure(FailureType); + + bool start(Frame*); + + friend class ResourceHandleInternal; + OwnPtr<ResourceHandleInternal> d; +}; + +} + +#endif // ResourceHandle_h diff --git a/src/3rdparty/webkit/WebCore/platform/network/ResourceHandleClient.h b/src/3rdparty/webkit/WebCore/platform/network/ResourceHandleClient.h new file mode 100644 index 0000000..3668d88 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/platform/network/ResourceHandleClient.h @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ResourceHandleClient_h +#define ResourceHandleClient_h + +#include <wtf/RefCounted.h> +#include <wtf/Platform.h> +#include <wtf/RefPtr.h> + +#if USE(CFNETWORK) +#include <ConditionalMacros.h> +#include <CFNetwork/CFURLResponsePriv.h> +#endif + +#if PLATFORM(MAC) +#ifdef __OBJC__ +@class NSCachedURLResponse; +#else +class NSCachedURLResponse; +#endif +#endif + +namespace WebCore { + class AuthenticationChallenge; + class Credential; + class KURL; + class ResourceHandle; + class ResourceError; + class ResourceRequest; + class ResourceResponse; + + enum CacheStoragePolicy { + StorageAllowed, + StorageAllowedInMemoryOnly, + StorageNotAllowed, + }; + + class ResourceHandleClient { + public: + virtual ~ResourceHandleClient() { } + + // request may be modified + virtual void willSendRequest(ResourceHandle*, ResourceRequest&, const ResourceResponse& /*redirectResponse*/) { } + virtual void didSendData(ResourceHandle*, unsigned long long /*bytesSent*/, unsigned long long /*totalBytesToBeSent*/) { } + + virtual void didReceiveResponse(ResourceHandle*, const ResourceResponse&) { } + virtual void didReceiveData(ResourceHandle*, const char*, int, int /*lengthReceived*/) { } + virtual void didFinishLoading(ResourceHandle*) { } + virtual void didFail(ResourceHandle*, const ResourceError&) { } + virtual void wasBlocked(ResourceHandle*) { } + virtual void cannotShowURL(ResourceHandle*) { } + + virtual void willCacheResponse(ResourceHandle*, CacheStoragePolicy&) { } + + virtual bool shouldUseCredentialStorage(ResourceHandle*) { return false; } + virtual void didReceiveAuthenticationChallenge(ResourceHandle*, const AuthenticationChallenge&) { } + virtual void didCancelAuthenticationChallenge(ResourceHandle*, const AuthenticationChallenge&) { } + virtual void receivedCredential(ResourceHandle*, const AuthenticationChallenge&, const Credential&) { } + virtual void receivedRequestToContinueWithoutCredential(ResourceHandle*, const AuthenticationChallenge&) { } + virtual void receivedCancellation(ResourceHandle*, const AuthenticationChallenge&) { } + +#if PLATFORM(MAC) + virtual NSCachedURLResponse* willCacheResponse(ResourceHandle*, NSCachedURLResponse* response) { return response; } + virtual void willStopBufferingData(ResourceHandle*, const char*, int) { } +#endif + }; + +} + +#endif diff --git a/src/3rdparty/webkit/WebCore/platform/network/ResourceHandleInternal.h b/src/3rdparty/webkit/WebCore/platform/network/ResourceHandleInternal.h new file mode 100644 index 0000000..66aa4c1 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/platform/network/ResourceHandleInternal.h @@ -0,0 +1,213 @@ +/* + * Copyright (C) 2004, 2006 Apple Computer, Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ResourceHandleInternal_h +#define ResourceHandleInternal_h + +#include "ResourceHandle.h" +#include "ResourceRequest.h" +#include "AuthenticationChallenge.h" +#include "Timer.h" + +#if USE(CFNETWORK) +#include <CFNetwork/CFURLConnectionPriv.h> +#endif + +#if USE(WININET) +#include <winsock2.h> +#include <windows.h> +#endif + +#if USE(CURL) +#include <curl/curl.h> +#include "FormDataStreamCurl.h" +#endif + +#if USE(SOUP) +#include <libsoup/soup.h> +#endif + +#if PLATFORM(QT) +class QWebFrame; +class QWebNetworkJob; +namespace WebCore { +class QNetworkReplyHandler; +} +#endif + +#if PLATFORM(MAC) +#ifdef __OBJC__ +@class NSURLAuthenticationChallenge; +@class NSURLConnection; +#else +class NSURLAuthenticationChallenge; +class NSURLConnection; +#endif +#endif + +// The allocations and releases in ResourceHandleInternal are +// Cocoa-exception-free (either simple Foundation classes or +// WebCoreResourceLoaderImp which avoids doing work in dealloc). + +namespace WebCore { + class ResourceHandleClient; + + class ResourceHandleInternal : Noncopyable { + public: + ResourceHandleInternal(ResourceHandle* loader, const ResourceRequest& request, ResourceHandleClient* c, bool defersLoading, bool shouldContentSniff, bool mightDownloadFromHandle) + : m_client(c) + , m_request(request) + , status(0) + , m_defersLoading(defersLoading) + , m_shouldContentSniff(shouldContentSniff) + , m_mightDownloadFromHandle(mightDownloadFromHandle) +#if USE(CFNETWORK) + , m_connection(0) +#endif +#if USE(WININET) + , m_fileHandle(INVALID_HANDLE_VALUE) + , m_fileLoadTimer(loader, &ResourceHandle::fileLoadTimer) + , m_resourceHandle(0) + , m_secondaryHandle(0) + , m_jobId(0) + , m_threadId(0) + , m_writing(false) + , m_formDataString(0) + , m_formDataLength(0) + , m_bytesRemainingToWrite(0) + , m_hasReceivedResponse(false) + , m_resend(false) +#endif +#if USE(CURL) + , m_handle(0) + , m_url(0) + , m_customHeaders(0) + , m_cancelled(false) + , m_formDataStream(loader) +#endif +#if USE(SOUP) + , m_msg(0) + , m_cancelled(false) + , m_gfile(0) + , m_input_stream(0) + , m_cancellable(0) + , m_buffer(0) + , m_bufsize(0) + , m_total(0) + , m_idleHandler(0) +#endif +#if PLATFORM(QT) + , m_job(0) + , m_frame(0) +#endif +#if PLATFORM(MAC) + , m_startWhenScheduled(false) + , m_currentMacChallenge(nil) +#elif USE(CFNETWORK) + , m_currentCFChallenge(0) +#endif + , m_failureTimer(loader, &ResourceHandle::fireFailure) + { + } + + ~ResourceHandleInternal(); + + ResourceHandleClient* client() { return m_client; } + ResourceHandleClient* m_client; + + ResourceRequest m_request; + + int status; + + bool m_defersLoading; + bool m_shouldContentSniff; + bool m_mightDownloadFromHandle; +#if USE(CFNETWORK) + RetainPtr<CFURLConnectionRef> m_connection; +#elif PLATFORM(MAC) + RetainPtr<NSURLConnection> m_connection; + RetainPtr<WebCoreResourceHandleAsDelegate> m_delegate; + RetainPtr<id> m_proxy; + bool m_startWhenScheduled; +#endif +#if USE(WININET) + HANDLE m_fileHandle; + Timer<ResourceHandle> m_fileLoadTimer; + HINTERNET m_resourceHandle; + HINTERNET m_secondaryHandle; + unsigned m_jobId; + DWORD m_threadId; + bool m_writing; + char* m_formDataString; + int m_formDataLength; + int m_bytesRemainingToWrite; + String m_postReferrer; + bool m_hasReceivedResponse; + bool m_resend; +#endif +#if USE(CURL) + CURL* m_handle; + char* m_url; + struct curl_slist* m_customHeaders; + ResourceResponse m_response; + bool m_cancelled; + + FormDataStream m_formDataStream; + Vector<char> m_postBytes; +#endif +#if USE(SOUP) + SoupMessage* m_msg; + ResourceResponse m_response; + bool m_cancelled; + GFile* m_gfile; + GInputStream* m_input_stream; + GCancellable* m_cancellable; + char* m_buffer; + gsize m_bufsize, m_total; + guint m_idleHandler; +#endif +#if PLATFORM(QT) +#if QT_VERSION < 0x040400 + QWebNetworkJob* m_job; +#else + QNetworkReplyHandler* m_job; +#endif + QWebFrame* m_frame; +#endif +#if PLATFORM(MAC) + NSURLAuthenticationChallenge *m_currentMacChallenge; +#endif +#if USE(CFNETWORK) + CFURLAuthChallengeRef m_currentCFChallenge; +#endif + AuthenticationChallenge m_currentWebChallenge; + + ResourceHandle::FailureType m_failureType; + Timer<ResourceHandle> m_failureTimer; + }; + +} // namespace WebCore + +#endif // ResourceHandleInternal_h diff --git a/src/3rdparty/webkit/WebCore/platform/network/ResourceRequestBase.cpp b/src/3rdparty/webkit/WebCore/platform/network/ResourceRequestBase.cpp new file mode 100644 index 0000000..3984d8e --- /dev/null +++ b/src/3rdparty/webkit/WebCore/platform/network/ResourceRequestBase.cpp @@ -0,0 +1,287 @@ +/* + * Copyright (C) 2003, 2006 Apple Computer, Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "config.h" +#include "ResourceRequestBase.h" +#include "ResourceRequest.h" + +namespace WebCore { + +inline const ResourceRequest& ResourceRequestBase::asResourceRequest() const +{ + return *static_cast<const ResourceRequest*>(this); +} + +bool ResourceRequestBase::isEmpty() const +{ + updateResourceRequest(); + + return m_url.isEmpty(); +} + +bool ResourceRequestBase::isNull() const +{ + updateResourceRequest(); + + return m_url.isNull(); +} + +const KURL& ResourceRequestBase::url() const +{ + updateResourceRequest(); + + return m_url; +} + +void ResourceRequestBase::setURL(const KURL& url) +{ + updateResourceRequest(); + + m_url = url; + + m_platformRequestUpdated = false; +} + +ResourceRequestCachePolicy ResourceRequestBase::cachePolicy() const +{ + updateResourceRequest(); + + return m_cachePolicy; +} + +void ResourceRequestBase::setCachePolicy(ResourceRequestCachePolicy cachePolicy) +{ + updateResourceRequest(); + + m_cachePolicy = cachePolicy; + + m_platformRequestUpdated = false; +} + +double ResourceRequestBase::timeoutInterval() const +{ + updateResourceRequest(); + + return m_timeoutInterval; +} + +void ResourceRequestBase::setTimeoutInterval(double timeoutInterval) +{ + updateResourceRequest(); + + m_timeoutInterval = timeoutInterval; + + m_platformRequestUpdated = false; +} + +const KURL& ResourceRequestBase::mainDocumentURL() const +{ + updateResourceRequest(); + + return m_mainDocumentURL; +} + +void ResourceRequestBase::setMainDocumentURL(const KURL& mainDocumentURL) +{ + updateResourceRequest(); + + m_mainDocumentURL = mainDocumentURL; + + m_platformRequestUpdated = false; +} + +const String& ResourceRequestBase::httpMethod() const +{ + updateResourceRequest(); + + return m_httpMethod; +} + +void ResourceRequestBase::setHTTPMethod(const String& httpMethod) +{ + updateResourceRequest(); + + m_httpMethod = httpMethod; + + m_platformRequestUpdated = false; +} + +const HTTPHeaderMap& ResourceRequestBase::httpHeaderFields() const +{ + updateResourceRequest(); + + return m_httpHeaderFields; +} + +String ResourceRequestBase::httpHeaderField(const AtomicString& name) const +{ + updateResourceRequest(); + + return m_httpHeaderFields.get(name); +} + +void ResourceRequestBase::setHTTPHeaderField(const AtomicString& name, const String& value) +{ + updateResourceRequest(); + + m_httpHeaderFields.set(name, value); + + m_platformRequestUpdated = false; +} + +void ResourceRequestBase::setResponseContentDispositionEncodingFallbackArray(const String& encoding1, const String& encoding2, const String& encoding3) +{ + updateResourceRequest(); + + m_responseContentDispositionEncodingFallbackArray.clear(); + if (!encoding1.isNull()) + m_responseContentDispositionEncodingFallbackArray.append(encoding1); + if (!encoding2.isNull()) + m_responseContentDispositionEncodingFallbackArray.append(encoding2); + if (!encoding3.isNull()) + m_responseContentDispositionEncodingFallbackArray.append(encoding3); + + m_platformRequestUpdated = false; +} + +FormData* ResourceRequestBase::httpBody() const +{ + updateResourceRequest(); + + return m_httpBody.get(); +} + +void ResourceRequestBase::setHTTPBody(PassRefPtr<FormData> httpBody) +{ + updateResourceRequest(); + + m_httpBody = httpBody; + + m_platformRequestUpdated = false; +} + +bool ResourceRequestBase::allowHTTPCookies() const +{ + updateResourceRequest(); + + return m_allowHTTPCookies; +} + +void ResourceRequestBase::setAllowHTTPCookies(bool allowHTTPCookies) +{ + updateResourceRequest(); + + m_allowHTTPCookies = allowHTTPCookies; + + m_platformRequestUpdated = false; +} + +void ResourceRequestBase::addHTTPHeaderField(const AtomicString& name, const String& value) +{ + updateResourceRequest(); + pair<HTTPHeaderMap::iterator, bool> result = m_httpHeaderFields.add(name, value); + if (!result.second) + result.first->second += "," + value; +} + +void ResourceRequestBase::addHTTPHeaderFields(const HTTPHeaderMap& headerFields) +{ + HTTPHeaderMap::const_iterator end = headerFields.end(); + for (HTTPHeaderMap::const_iterator it = headerFields.begin(); it != end; ++it) + addHTTPHeaderField(it->first, it->second); +} + +bool equalIgnoringHeaderFields(const ResourceRequestBase& a, const ResourceRequestBase& b) +{ + if (a.url() != b.url()) + return false; + + if (a.cachePolicy() != b.cachePolicy()) + return false; + + if (a.timeoutInterval() != b.timeoutInterval()) + return false; + + if (a.mainDocumentURL() != b.mainDocumentURL()) + return false; + + if (a.httpMethod() != b.httpMethod()) + return false; + + if (a.allowHTTPCookies() != b.allowHTTPCookies()) + return false; + + FormData* formDataA = a.httpBody(); + FormData* formDataB = b.httpBody(); + + if (!formDataA) + return !formDataB; + if (!formDataB) + return !formDataA; + + if (*formDataA != *formDataB) + return false; + + return true; +} + +bool operator==(const ResourceRequestBase& a, const ResourceRequestBase& b) +{ + if (!equalIgnoringHeaderFields(a, b)) + return false; + + if (a.httpHeaderFields() != b.httpHeaderFields()) + return false; + + return true; +} + +bool ResourceRequestBase::isConditional() const +{ + return (m_httpHeaderFields.contains("If-Match") || + m_httpHeaderFields.contains("If-Modified-Since") || + m_httpHeaderFields.contains("If-None-Match") || + m_httpHeaderFields.contains("If-Range") || + m_httpHeaderFields.contains("If-Unmodified-Since")); +} + +void ResourceRequestBase::updatePlatformRequest() const +{ + if (m_platformRequestUpdated) + return; + + const_cast<ResourceRequest&>(asResourceRequest()).doUpdatePlatformRequest(); + m_platformRequestUpdated = true; +} + +void ResourceRequestBase::updateResourceRequest() const +{ + if (m_resourceRequestUpdated) + return; + + const_cast<ResourceRequest&>(asResourceRequest()).doUpdateResourceRequest(); + m_resourceRequestUpdated = true; +} + +} diff --git a/src/3rdparty/webkit/WebCore/platform/network/ResourceRequestBase.h b/src/3rdparty/webkit/WebCore/platform/network/ResourceRequestBase.h new file mode 100644 index 0000000..1cbf21e --- /dev/null +++ b/src/3rdparty/webkit/WebCore/platform/network/ResourceRequestBase.h @@ -0,0 +1,147 @@ +/* + * Copyright (C) 2003, 2006 Apple Computer, Inc. All rights reserved. + * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ResourceRequestBase_h +#define ResourceRequestBase_h + +#include "FormData.h" +#include "KURL.h" +#include "HTTPHeaderMap.h" + +namespace WebCore { + + enum ResourceRequestCachePolicy { + UseProtocolCachePolicy, // normal load + ReloadIgnoringCacheData, // reload + ReturnCacheDataElseLoad, // back/forward or encoding change - allow stale data + ReturnCacheDataDontLoad, // results of a post - allow stale data and only use cache + }; + + const int unspecifiedTimeoutInterval = INT_MAX; + + class ResourceRequest; + + // Do not use this type directly. Use ResourceRequest instead. + class ResourceRequestBase { + public: + bool isNull() const; + bool isEmpty() const; + + const KURL& url() const; + void setURL(const KURL& url); + + ResourceRequestCachePolicy cachePolicy() const; + void setCachePolicy(ResourceRequestCachePolicy cachePolicy); + + double timeoutInterval() const; + void setTimeoutInterval(double timeoutInterval); + + const KURL& mainDocumentURL() const; + void setMainDocumentURL(const KURL& mainDocumentURL); + + const String& httpMethod() const; + void setHTTPMethod(const String& httpMethod); + + const HTTPHeaderMap& httpHeaderFields() const; + String httpHeaderField(const AtomicString& name) const; + void setHTTPHeaderField(const AtomicString& name, const String& value); + void addHTTPHeaderField(const AtomicString& name, const String& value); + void addHTTPHeaderFields(const HTTPHeaderMap& headerFields); + + String httpContentType() const { return httpHeaderField("Content-Type"); } + void setHTTPContentType(const String& httpContentType) { setHTTPHeaderField("Content-Type", httpContentType); } + + String httpReferrer() const { return httpHeaderField("Referer"); } + void setHTTPReferrer(const String& httpReferrer) { setHTTPHeaderField("Referer", httpReferrer); } + void clearHTTPReferrer() { m_httpHeaderFields.remove("Referer"); } + + String httpOrigin() const { return httpHeaderField("Origin"); } + void setHTTPOrigin(const String& httpOrigin) { setHTTPHeaderField("Origin", httpOrigin); } + void clearHTTPOrigin() { m_httpHeaderFields.remove("Origin"); } + + String httpUserAgent() const { return httpHeaderField("User-Agent"); } + void setHTTPUserAgent(const String& httpUserAgent) { setHTTPHeaderField("User-Agent", httpUserAgent); } + + String httpAccept() const { return httpHeaderField("Accept"); } + void setHTTPAccept(const String& httpAccept) { setHTTPHeaderField("Accept", httpAccept); } + + void setResponseContentDispositionEncodingFallbackArray(const String& encoding1, const String& encoding2 = String(), const String& encoding3 = String()); + + FormData* httpBody() const; + void setHTTPBody(PassRefPtr<FormData> httpBody); + + bool allowHTTPCookies() const; + void setAllowHTTPCookies(bool allowHTTPCookies); + + bool isConditional() const; + + protected: + // Used when ResourceRequest is initialized from a platform representation of the request + ResourceRequestBase() + : m_resourceRequestUpdated(false) + , m_platformRequestUpdated(true) + { + } + + ResourceRequestBase(const KURL& url, ResourceRequestCachePolicy policy) + : m_url(url) + , m_cachePolicy(policy) + , m_timeoutInterval(unspecifiedTimeoutInterval) + , m_httpMethod("GET") + , m_allowHTTPCookies(true) + , m_resourceRequestUpdated(true) + , m_platformRequestUpdated(false) + { + } + + void updatePlatformRequest() const; + void updateResourceRequest() const; + + KURL m_url; + + ResourceRequestCachePolicy m_cachePolicy; + double m_timeoutInterval; + KURL m_mainDocumentURL; + String m_httpMethod; + HTTPHeaderMap m_httpHeaderFields; + Vector<String> m_responseContentDispositionEncodingFallbackArray; + RefPtr<FormData> m_httpBody; + bool m_allowHTTPCookies; + mutable bool m_resourceRequestUpdated; + mutable bool m_platformRequestUpdated; + + private: + const ResourceRequest& asResourceRequest() const; + }; + + bool equalIgnoringHeaderFields(const ResourceRequestBase&, const ResourceRequestBase&); + + bool operator==(const ResourceRequestBase&, const ResourceRequestBase&); + inline bool operator!=(ResourceRequestBase& a, const ResourceRequestBase& b) { return !(a == b); } + +} // namespace WebCore + +#endif // ResourceRequestBase_h diff --git a/src/3rdparty/webkit/WebCore/platform/network/ResourceResponseBase.cpp b/src/3rdparty/webkit/WebCore/platform/network/ResourceResponseBase.cpp new file mode 100644 index 0000000..fb7f5c7 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/platform/network/ResourceResponseBase.cpp @@ -0,0 +1,380 @@ +/* + * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "ResourceResponseBase.h" + +#include "ResourceResponse.h" + +namespace WebCore { + +static void parseCacheHeader(const String& header, Vector<pair<String, String> >& result); +static void parseCacheControlDirectiveValues(const String& directives, Vector<String>& result); + +bool ResourceResponseBase::isHTTP() const +{ + lazyInit(); + + String protocol = m_url.protocol(); + + return equalIgnoringCase(protocol, "http") || equalIgnoringCase(protocol, "https"); +} + +const KURL& ResourceResponseBase::url() const +{ + lazyInit(); + + return m_url; +} + +void ResourceResponseBase::setUrl(const KURL& url) +{ + lazyInit(); + m_isNull = false; + + m_url = url; +} + +const String& ResourceResponseBase::mimeType() const +{ + lazyInit(); + + return m_mimeType; +} + +void ResourceResponseBase::setMimeType(const String& mimeType) +{ + lazyInit(); + m_isNull = false; + + m_mimeType = mimeType; +} + +long long ResourceResponseBase::expectedContentLength() const +{ + lazyInit(); + + return m_expectedContentLength; +} + +void ResourceResponseBase::setExpectedContentLength(long long expectedContentLength) +{ + lazyInit(); + m_isNull = false; + + m_expectedContentLength = expectedContentLength; +} + +const String& ResourceResponseBase::textEncodingName() const +{ + lazyInit(); + + return m_textEncodingName; +} + +void ResourceResponseBase::setTextEncodingName(const String& encodingName) +{ + lazyInit(); + m_isNull = false; + + m_textEncodingName = encodingName; +} + +// FIXME should compute this on the fly +const String& ResourceResponseBase::suggestedFilename() const +{ + lazyInit(); + + return m_suggestedFilename; +} + +void ResourceResponseBase::setSuggestedFilename(const String& suggestedName) +{ + lazyInit(); + m_isNull = false; + + m_suggestedFilename = suggestedName; +} + +int ResourceResponseBase::httpStatusCode() const +{ + lazyInit(); + + return m_httpStatusCode; +} + +void ResourceResponseBase::setHTTPStatusCode(int statusCode) +{ + lazyInit(); + + m_httpStatusCode = statusCode; +} + +const String& ResourceResponseBase::httpStatusText() const +{ + lazyInit(); + + return m_httpStatusText; +} + +void ResourceResponseBase::setHTTPStatusText(const String& statusText) +{ + lazyInit(); + + m_httpStatusText = statusText; +} + +String ResourceResponseBase::httpHeaderField(const AtomicString& name) const +{ + lazyInit(); + + return m_httpHeaderFields.get(name); +} + +void ResourceResponseBase::setHTTPHeaderField(const AtomicString& name, const String& value) +{ + lazyInit(); + + if (equalIgnoringCase(name, "cache-control")) + m_haveParsedCacheControl = false; + m_httpHeaderFields.set(name, value); +} + +const HTTPHeaderMap& ResourceResponseBase::httpHeaderFields() const +{ + lazyInit(); + + return m_httpHeaderFields; +} + +void ResourceResponseBase::parseCacheControlDirectives() const +{ + ASSERT(!m_haveParsedCacheControl); + + lazyInit(); + + m_haveParsedCacheControl = true; + m_cacheControlContainsMustRevalidate = false; + m_cacheControlContainsNoCache = false; + + String cacheControlValue = httpHeaderField("cache-control"); + if (cacheControlValue.isEmpty()) + return; + + // FIXME: It would probably be much more efficient to parse this without creating all these data structures. + + Vector<pair<String, String> > directives; + parseCacheHeader(cacheControlValue, directives); + + size_t directivesSize = directives.size(); + for (size_t i = 0; i < directivesSize; ++i) { + Vector<String> directiveValues; + if ((equalIgnoringCase(directives[i].first, "private") || equalIgnoringCase(directives[i].first, "no-cache")) && !directives[i].second.isEmpty()) + parseCacheControlDirectiveValues(directives[i].second, directiveValues); + else + directiveValues.append(directives[i].second); + for (size_t i = 0; i < directiveValues.size(); ++i) { + if (equalIgnoringCase(directiveValues[i], "no-cache")) + m_cacheControlContainsNoCache = true; + else if (equalIgnoringCase(directiveValues[i], "must-revalidate")) + m_cacheControlContainsMustRevalidate = true; + } + } +} + +bool ResourceResponseBase::isAttachment() const +{ + lazyInit(); + + String value = m_httpHeaderFields.get("Content-Disposition"); + int loc = value.find(';'); + if (loc != -1) + value = value.left(loc); + value = value.stripWhiteSpace(); + return equalIgnoringCase(value, "attachment"); +} + +void ResourceResponseBase::setExpirationDate(time_t expirationDate) +{ + lazyInit(); + + m_expirationDate = expirationDate; +} + +time_t ResourceResponseBase::expirationDate() const +{ + lazyInit(); + + return m_expirationDate; +} + +void ResourceResponseBase::setLastModifiedDate(time_t lastModifiedDate) +{ + lazyInit(); + + m_lastModifiedDate = lastModifiedDate; +} + +time_t ResourceResponseBase::lastModifiedDate() const +{ + lazyInit(); + + return m_lastModifiedDate; +} + +void ResourceResponseBase::lazyInit() const +{ + const_cast<ResourceResponse*>(static_cast<const ResourceResponse*>(this))->platformLazyInit(); +} + +bool ResourceResponseBase::compare(const ResourceResponse& a, const ResourceResponse& b) +{ + if (a.isNull() != b.isNull()) + return false; + if (a.url() != b.url()) + return false; + if (a.mimeType() != b.mimeType()) + return false; + if (a.expectedContentLength() != b.expectedContentLength()) + return false; + if (a.textEncodingName() != b.textEncodingName()) + return false; + if (a.suggestedFilename() != b.suggestedFilename()) + return false; + if (a.httpStatusCode() != b.httpStatusCode()) + return false; + if (a.httpStatusText() != b.httpStatusText()) + return false; + if (a.httpHeaderFields() != b.httpHeaderFields()) + return false; + if (a.expirationDate() != b.expirationDate()) + return false; + return ResourceResponse::platformCompare(a, b); +} + +static bool isCacheHeaderSeparator(UChar c) +{ + // See RFC 2616, Section 2.2 + switch (c) { + case '(': + case ')': + case '<': + case '>': + case '@': + case ',': + case ';': + case ':': + case '\\': + case '"': + case '/': + case '[': + case ']': + case '?': + case '=': + case '{': + case '}': + case ' ': + case '\t': + return true; + default: + return false; + } +} + +static bool isControlCharacter(UChar c) +{ + return c < ' ' || c == 127; +} + +static inline String trimToNextSeparator(const String& str) +{ + return str.substring(0, str.find(isCacheHeaderSeparator, 0)); +} + +static void parseCacheHeader(const String& header, Vector<pair<String, String> >& result) +{ + const String safeHeader = header.removeCharacters(isControlCharacter); + unsigned max = safeHeader.length(); + for (unsigned pos = 0; pos < max; /* pos incremented in loop */) { + int nextCommaPosition = safeHeader.find(',', pos); + int nextEqualSignPosition = safeHeader.find('=', pos); + if (nextEqualSignPosition >= 0 && (nextEqualSignPosition < nextCommaPosition || nextCommaPosition < 0)) { + // Get directive name, parse right hand side of equal sign, then add to map + String directive = trimToNextSeparator(safeHeader.substring(pos, nextEqualSignPosition - pos).stripWhiteSpace()); + pos += nextEqualSignPosition - pos + 1; + + String value = safeHeader.substring(pos, max - pos).stripWhiteSpace(); + if (value[0] == '"') { + // The value is a quoted string + int nextDoubleQuotePosition = value.find('"', 1); + if (nextDoubleQuotePosition >= 0) { + // Store the value as a quoted string without quotes + result.append(pair<String, String>(directive, value.substring(1, nextDoubleQuotePosition - 1).stripWhiteSpace())); + pos += (safeHeader.find('"', pos) - pos) + nextDoubleQuotePosition + 1; + // Move past next comma, if there is one + int nextCommaPosition2 = safeHeader.find(',', pos); + if (nextCommaPosition2 >= 0) + pos += nextCommaPosition2 - pos + 1; + else + return; // Parse error if there is anything left with no comma + } else { + // Parse error; just use the rest as the value + result.append(pair<String, String>(directive, trimToNextSeparator(value.substring(1, value.length() - 1).stripWhiteSpace()))); + return; + } + } else { + // The value is a token until the next comma + int nextCommaPosition2 = value.find(',', 0); + if (nextCommaPosition2 >= 0) { + // The value is delimited by the next comma + result.append(pair<String, String>(directive, trimToNextSeparator(value.substring(0, nextCommaPosition2).stripWhiteSpace()))); + pos += (safeHeader.find(',', pos) - pos) + 1; + } else { + // The rest is the value; no change to value needed + result.append(pair<String, String>(directive, trimToNextSeparator(value))); + return; + } + } + } else if (nextCommaPosition >= 0 && (nextCommaPosition < nextEqualSignPosition || nextEqualSignPosition < 0)) { + // Add directive to map with empty string as value + result.append(pair<String, String>(trimToNextSeparator(safeHeader.substring(pos, nextCommaPosition - pos).stripWhiteSpace()), "")); + pos += nextCommaPosition - pos + 1; + } else { + // Add last directive to map with empty string as value + result.append(pair<String, String>(trimToNextSeparator(safeHeader.substring(pos, max - pos).stripWhiteSpace()), "")); + return; + } + } +} + +static void parseCacheControlDirectiveValues(const String& directives, Vector<String>& result) +{ + directives.split(',', false, result); + unsigned max = result.size(); + for (unsigned i = 0; i < max; ++i) + result[i] = result[i].stripWhiteSpace(); +} + +} diff --git a/src/3rdparty/webkit/WebCore/platform/network/ResourceResponseBase.h b/src/3rdparty/webkit/WebCore/platform/network/ResourceResponseBase.h new file mode 100644 index 0000000..20df8af --- /dev/null +++ b/src/3rdparty/webkit/WebCore/platform/network/ResourceResponseBase.h @@ -0,0 +1,151 @@ +/* + * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ResourceResponseBase_h +#define ResourceResponseBase_h + +#include "HTTPHeaderMap.h" +#include "KURL.h" + +namespace WebCore { + +class ResourceResponse; + +// Do not use this class directly, use the class ResponseResponse instead +class ResourceResponseBase { +public: + bool isNull() const { return m_isNull; } + bool isHTTP() const; + + const KURL& url() const; + void setUrl(const KURL& url); + + const String& mimeType() const; + void setMimeType(const String& mimeType); + + long long expectedContentLength() const; + void setExpectedContentLength(long long expectedContentLength); + + const String& textEncodingName() const; + void setTextEncodingName(const String& name); + + // FIXME should compute this on the fly + const String& suggestedFilename() const; + void setSuggestedFilename(const String&); + + int httpStatusCode() const; + void setHTTPStatusCode(int); + + const String& httpStatusText() const; + void setHTTPStatusText(const String&); + + String httpHeaderField(const AtomicString& name) const; + void setHTTPHeaderField(const AtomicString& name, const String& value); + const HTTPHeaderMap& httpHeaderFields() const; + + bool isMultipart() const { return mimeType() == "multipart/x-mixed-replace"; } + + bool isAttachment() const; + + void setExpirationDate(time_t); + time_t expirationDate() const; + + void setLastModifiedDate(time_t); + time_t lastModifiedDate() const; + + bool cacheControlContainsNoCache() const + { + if (!m_haveParsedCacheControl) + parseCacheControlDirectives(); + return m_cacheControlContainsMustRevalidate; + } + bool cacheControlContainsMustRevalidate() const + { + if (!m_haveParsedCacheControl) + parseCacheControlDirectives(); + return m_cacheControlContainsMustRevalidate; + } + + static bool compare(const ResourceResponse& a, const ResourceResponse& b); + +protected: + ResourceResponseBase() + : m_expectedContentLength(0) + , m_httpStatusCode(0) + , m_expirationDate(0) + , m_lastModifiedDate(0) + , m_isNull(true) + , m_haveParsedCacheControl(false) + { + } + + ResourceResponseBase(const KURL& url, const String& mimeType, long long expectedLength, const String& textEncodingName, const String& filename) + : m_url(url) + , m_mimeType(mimeType) + , m_expectedContentLength(expectedLength) + , m_textEncodingName(textEncodingName) + , m_suggestedFilename(filename) + , m_httpStatusCode(0) + , m_expirationDate(0) + , m_lastModifiedDate(0) + , m_isNull(false) + , m_haveParsedCacheControl(false) + { + } + + void lazyInit() const; + + // The ResourceResponse subclass may "shadow" this method to lazily initialize platform specific fields + void platformLazyInit() { } + + // The ResourceResponse subclass may "shadow" this method to compare platform specific fields + static bool platformCompare(const ResourceResponse&, const ResourceResponse&) { return true; } + + KURL m_url; + String m_mimeType; + long long m_expectedContentLength; + String m_textEncodingName; + String m_suggestedFilename; + int m_httpStatusCode; + String m_httpStatusText; + HTTPHeaderMap m_httpHeaderFields; + time_t m_expirationDate; + time_t m_lastModifiedDate; + bool m_isNull : 1; + +private: + void parseCacheControlDirectives() const; + + mutable bool m_haveParsedCacheControl : 1; + mutable bool m_cacheControlContainsMustRevalidate : 1; + mutable bool m_cacheControlContainsNoCache : 1; +}; + +inline bool operator==(const ResourceResponse& a, const ResourceResponse& b) { return ResourceResponseBase::compare(a, b); } +inline bool operator!=(const ResourceResponse& a, const ResourceResponse& b) { return !(a == b); } + +} // namespace WebCore + +#endif // ResourceResponseBase_h diff --git a/src/3rdparty/webkit/WebCore/platform/network/chromium/ResourceResponse.h b/src/3rdparty/webkit/WebCore/platform/network/chromium/ResourceResponse.h new file mode 100644 index 0000000..d018402 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/platform/network/chromium/ResourceResponse.h @@ -0,0 +1,83 @@ + /* + * Copyright (C) 2008 Google Inc. All rights reserved. + * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ResourceResponse_h +#define ResourceResponse_h + +#include "CString.h" +#include "ResourceResponseBase.h" + +#include "NotImplemented.h" + +namespace WebCore { + +class ResourceResponse : public ResourceResponseBase { +public: + ResourceResponse() + : ResourceResponseBase(), + m_isContentFiltered(false) + { + } + + ResourceResponse(const KURL& url, const String& mimeType, long long expectedLength, const String& textEncodingName, const String& filename) + : ResourceResponseBase(url, mimeType, expectedLength, textEncodingName, filename), + m_isContentFiltered(false) + { + } + + const CString& getSecurityInfo() const { return m_securityInfo; } + void setSecurityInfo(const CString& securityInfo) + { + m_securityInfo = securityInfo; + } + + bool isContentFiltered() const { return m_isContentFiltered; } + void setIsContentFiltered(bool isContentFiltered) + { + m_isContentFiltered = isContentFiltered; + } + +private: + friend class ResourceResponseBase; + + // An opaque value that contains some information regarding the security of + // the connection for this request, such as SSL connection info (empty + // string if not over HTTPS). + CString m_securityInfo; + + void doUpdateResourceResponse() + { + notImplemented(); + } + + // Whether the contents for this response has been altered/blocked (usually + // for security reasons. + bool m_isContentFiltered; +}; + +} // namespace WebCore + +#endif // ResourceResponse_h diff --git a/src/3rdparty/webkit/WebCore/platform/network/qt/AuthenticationChallenge.h b/src/3rdparty/webkit/WebCore/platform/network/qt/AuthenticationChallenge.h new file mode 100644 index 0000000..753ac6f --- /dev/null +++ b/src/3rdparty/webkit/WebCore/platform/network/qt/AuthenticationChallenge.h @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2007 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef AuthenticationChallenge_h +#define AuthenticationChallenge_h + +#include "AuthenticationChallengeBase.h" + +namespace WebCore { + +class AuthenticationChallenge : public AuthenticationChallengeBase { +public: + AuthenticationChallenge() + { + } + + AuthenticationChallenge(const ProtectionSpace& protectionSpace, const Credential& proposedCredential, unsigned previousFailureCount, const ResourceResponse& response, const ResourceError& error) + : AuthenticationChallengeBase(protectionSpace, proposedCredential, previousFailureCount, response, error) + { + } +}; + +} + +#endif diff --git a/src/3rdparty/webkit/WebCore/platform/network/qt/QNetworkReplyHandler.cpp b/src/3rdparty/webkit/WebCore/platform/network/qt/QNetworkReplyHandler.cpp new file mode 100644 index 0000000..2de2125 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/platform/network/qt/QNetworkReplyHandler.cpp @@ -0,0 +1,435 @@ +/* + Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) + Copyright (C) 2007 Staikos Computing Services Inc. <info@staikos.net> + Copyright (C) 2008 Holger Hans Peter Freyther + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ +#include "config.h" +#include "QNetworkReplyHandler.h" + +#if QT_VERSION >= 0x040400 + +#include "HTTPParsers.h" +#include "MIMETypeRegistry.h" +#include "ResourceHandle.h" +#include "ResourceHandleClient.h" +#include "ResourceHandleInternal.h" +#include "ResourceResponse.h" +#include "ResourceRequest.h" +#include <QDateTime> +#include <QFile> +#include <QNetworkReply> +#include <QNetworkCookie> +#include <qwebframe.h> +#include <qwebpage.h> + +#include <QDebug> +#include <QCoreApplication> + +namespace WebCore { + +// Take a deep copy of the FormDataElement +FormDataIODevice::FormDataIODevice(FormData* data) + : m_formElements(data ? data->elements() : Vector<FormDataElement>()) + , m_currentFile(0) + , m_currentDelta(0) +{ + setOpenMode(FormDataIODevice::ReadOnly); +} + +FormDataIODevice::~FormDataIODevice() +{ + delete m_currentFile; +} + +void FormDataIODevice::moveToNextElement() +{ + if (m_currentFile) + m_currentFile->close(); + m_currentDelta = 0; + + m_formElements.remove(0); + + if (m_formElements.isEmpty() || m_formElements[0].m_type == FormDataElement::data) + return; + + if (!m_currentFile) + m_currentFile = new QFile; + + m_currentFile->setFileName(m_formElements[0].m_filename); + m_currentFile->open(QFile::ReadOnly); +} + +// m_formElements[0] is the current item. If the destination buffer is +// big enough we are going to read from more than one FormDataElement +qint64 FormDataIODevice::readData(char* destination, qint64 size) +{ + if (m_formElements.isEmpty()) + return -1; + + qint64 copied = 0; + while (copied < size && !m_formElements.isEmpty()) { + const FormDataElement& element = m_formElements[0]; + const qint64 available = size-copied; + + if (element.m_type == FormDataElement::data) { + const qint64 toCopy = qMin<qint64>(available, element.m_data.size() - m_currentDelta); + memcpy(destination+copied, element.m_data.data()+m_currentDelta, toCopy); + m_currentDelta += toCopy; + copied += toCopy; + + if (m_currentDelta == element.m_data.size()) + moveToNextElement(); + } else { + const QByteArray data = m_currentFile->read(available); + memcpy(destination+copied, data.constData(), data.size()); + copied += data.size(); + + if (m_currentFile->atEnd() || !m_currentFile->isOpen()) + moveToNextElement(); + } + } + + return copied; +} + +qint64 FormDataIODevice::writeData(const char*, qint64) +{ + return -1; +} + +void FormDataIODevice::setParent(QNetworkReply* reply) +{ + QIODevice::setParent(reply); + + connect(reply, SIGNAL(finished()), SLOT(slotFinished()), Qt::QueuedConnection); +} + +bool FormDataIODevice::isSequential() const +{ + return true; +} + +void FormDataIODevice::slotFinished() +{ + deleteLater(); +} + +QNetworkReplyHandler::QNetworkReplyHandler(ResourceHandle* handle, LoadMode loadMode) + : QObject(0) + , m_resourceHandle(handle) + , m_reply(0) + , m_redirected(false) + , m_responseSent(false) + , m_loadMode(loadMode) + , m_startTime(0) + , m_shouldStart(true) + , m_shouldFinish(false) + , m_shouldSendResponse(false) + , m_shouldForwardData(false) +{ + const ResourceRequest &r = m_resourceHandle->request(); + + if (r.httpMethod() == "GET") + m_method = QNetworkAccessManager::GetOperation; + else if (r.httpMethod() == "HEAD") + m_method = QNetworkAccessManager::HeadOperation; + else if (r.httpMethod() == "POST") + m_method = QNetworkAccessManager::PostOperation; + else if (r.httpMethod() == "PUT") + m_method = QNetworkAccessManager::PutOperation; + else + m_method = QNetworkAccessManager::UnknownOperation; + + m_request = r.toNetworkRequest(); + + if (m_loadMode == LoadNormal) + start(); +} + +void QNetworkReplyHandler::setLoadMode(LoadMode mode) +{ + m_loadMode = mode; + if (m_loadMode == LoadNormal) + sendQueuedItems(); +} + +void QNetworkReplyHandler::abort() +{ + m_resourceHandle = 0; + if (m_reply) { + QNetworkReply* reply = release(); + reply->abort(); + deleteLater(); + } +} + +QNetworkReply* QNetworkReplyHandler::release() +{ + QNetworkReply* reply = m_reply; + if (m_reply) { + disconnect(m_reply, 0, this, 0); + // We have queued connections to the QNetworkReply. Make sure any + // posted meta call events that were the result of a signal emission + // don't reach the slots in our instance. + QCoreApplication::removePostedEvents(this, QEvent::MetaCall); + m_reply = 0; + } + return reply; +} + +void QNetworkReplyHandler::finish() +{ + m_shouldFinish = (m_loadMode == LoadDeferred); + if (m_loadMode == LoadDeferred) + return; + + sendResponseIfNeeded(); + + if (!m_resourceHandle) + return; + ResourceHandleClient* client = m_resourceHandle->client(); + if (!client) { + m_reply->deleteLater(); + m_reply = 0; + return; + } + QNetworkReply* oldReply = m_reply; + if (m_redirected) { + resetState(); + start(); + } else if (m_reply->error() != QNetworkReply::NoError + // a web page that returns 403/404 can still have content + && m_reply->error() != QNetworkReply::ContentOperationNotPermittedError + && m_reply->error() != QNetworkReply::ContentNotFoundError) { + QUrl url = m_reply->url(); + ResourceError error(url.host(), m_reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(), + url.toString(), m_reply->errorString()); + client->didFail(m_resourceHandle, error); + } else { + client->didFinishLoading(m_resourceHandle); + } + oldReply->deleteLater(); + if (oldReply == m_reply) + m_reply = 0; +} + +void QNetworkReplyHandler::sendResponseIfNeeded() +{ + m_shouldSendResponse = (m_loadMode == LoadDeferred); + if (m_loadMode == LoadDeferred) + return; + + if (m_responseSent || !m_resourceHandle) + return; + m_responseSent = true; + + ResourceHandleClient* client = m_resourceHandle->client(); + if (!client) + return; + + WebCore::String contentType = m_reply->header(QNetworkRequest::ContentTypeHeader).toString(); + WebCore::String encoding = extractCharsetFromMediaType(contentType); + WebCore::String mimeType = extractMIMETypeFromMediaType(contentType); + + if (mimeType.isEmpty()) { + // let's try to guess from the extension + QString extension = m_reply->url().path(); + int index = extension.lastIndexOf(QLatin1Char('.')); + if (index > 0) { + extension = extension.mid(index + 1); + mimeType = MIMETypeRegistry::getMIMETypeForExtension(extension); + } + } + + KURL url(m_reply->url()); + String suggestedFilename = filenameFromHTTPContentDisposition(QString::fromAscii(m_reply->rawHeader("Content-Disposition"))); + + if (suggestedFilename.isEmpty()) + suggestedFilename = url.lastPathComponent(); + + ResourceResponse response(url, mimeType, + m_reply->header(QNetworkRequest::ContentLengthHeader).toLongLong(), + encoding, + suggestedFilename); + + const bool isLocalFileReply = (m_reply->url().scheme() == QLatin1String("file")); + int statusCode = m_reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); + if (!isLocalFileReply) + response.setHTTPStatusCode(statusCode); + else if (m_reply->error() == QNetworkReply::ContentNotFoundError) + response.setHTTPStatusCode(404); + + + /* Fill in the other fields + * For local file requests remove the content length and the last-modified + * headers as required by fast/dom/xmlhttprequest-get.xhtml + */ + foreach (QByteArray headerName, m_reply->rawHeaderList()) { + + if (isLocalFileReply + && (headerName == "Content-Length" || headerName == "Last-Modified")) + continue; + + response.setHTTPHeaderField(QString::fromAscii(headerName), QString::fromAscii(m_reply->rawHeader(headerName))); + } + + if (isLocalFileReply) + response.setExpirationDate(m_startTime); + + QUrl redirection = m_reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl(); + if (redirection.isValid()) { + QUrl newUrl = m_reply->url().resolved(redirection); + ResourceRequest newRequest = m_resourceHandle->request(); + newRequest.setURL(newUrl); + + if (((statusCode >= 301 && statusCode <= 303) || statusCode == 307) && m_method == QNetworkAccessManager::PostOperation) { + m_method = QNetworkAccessManager::GetOperation; + newRequest.setHTTPMethod("GET"); + } + + client->willSendRequest(m_resourceHandle, newRequest, response); + m_redirected = true; + m_request = newRequest.toNetworkRequest(); + } else { + client->didReceiveResponse(m_resourceHandle, response); + } +} + +void QNetworkReplyHandler::forwardData() +{ + m_shouldForwardData = (m_loadMode == LoadDeferred); + if (m_loadMode == LoadDeferred) + return; + + sendResponseIfNeeded(); + + // don't emit the "Document has moved here" type of HTML + if (m_redirected) + return; + + if (!m_resourceHandle) + return; + + QByteArray data = m_reply->read(m_reply->bytesAvailable()); + + ResourceHandleClient* client = m_resourceHandle->client(); + if (!client) + return; + + if (!data.isEmpty()) + client->didReceiveData(m_resourceHandle, data.constData(), data.length(), data.length() /*FixMe*/); +} + +void QNetworkReplyHandler::start() +{ + m_shouldStart = false; + + ResourceHandleInternal* d = m_resourceHandle->getInternal(); + + QNetworkAccessManager* manager = d->m_frame->page()->networkAccessManager(); + + const QUrl url = m_request.url(); + const QString scheme = url.scheme(); + // Post requests on files and data don't really make sense, but for + // fast/forms/form-post-urlencoded.html and for fast/forms/button-state-restore.html + // we still need to retrieve the file/data, which means we map it to a Get instead. + if (m_method == QNetworkAccessManager::PostOperation + && (!url.toLocalFile().isEmpty() || url.scheme() == QLatin1String("data"))) + m_method = QNetworkAccessManager::GetOperation; + + m_startTime = QDateTime::currentDateTime().toTime_t(); + + switch (m_method) { + case QNetworkAccessManager::GetOperation: + m_reply = manager->get(m_request); + break; + case QNetworkAccessManager::PostOperation: { + FormDataIODevice* postDevice = new FormDataIODevice(d->m_request.httpBody()); + m_reply = manager->post(m_request, postDevice); + postDevice->setParent(m_reply); + break; + } + case QNetworkAccessManager::HeadOperation: + m_reply = manager->head(m_request); + break; + case QNetworkAccessManager::PutOperation: { + FormDataIODevice* putDevice = new FormDataIODevice(d->m_request.httpBody()); + m_reply = manager->put(m_request, putDevice); + putDevice->setParent(m_reply); + break; + } + case QNetworkAccessManager::UnknownOperation: { + m_reply = 0; + ResourceHandleClient* client = m_resourceHandle->client(); + if (client) { + ResourceError error(url.host(), 400 /*bad request*/, + url.toString(), + QCoreApplication::translate("QWebPage", "Bad HTTP request")); + client->didFail(m_resourceHandle, error); + } + return; + } + } + + m_reply->setParent(this); + + connect(m_reply, SIGNAL(finished()), + this, SLOT(finish()), Qt::QueuedConnection); + + // For http(s) we know that the headers are complete upon metaDataChanged() emission, so we + // can send the response as early as possible + if (scheme == QLatin1String("http") || scheme == QLatin1String("https")) + connect(m_reply, SIGNAL(metaDataChanged()), + this, SLOT(sendResponseIfNeeded()), Qt::QueuedConnection); + + connect(m_reply, SIGNAL(readyRead()), + this, SLOT(forwardData()), Qt::QueuedConnection); +} + +void QNetworkReplyHandler::resetState() +{ + m_redirected = false; + m_responseSent = false; + m_shouldStart = true; + m_shouldFinish = false; + m_shouldSendResponse = false; + m_shouldForwardData = false; +} + +void QNetworkReplyHandler::sendQueuedItems() +{ + Q_ASSERT(m_loadMode == LoadNormal); + + if (m_shouldStart) + start(); + + if (m_shouldSendResponse) + sendResponseIfNeeded(); + + if (m_shouldForwardData) + forwardData(); + + if (m_shouldFinish) + finish(); +} + +} + +#include "moc_QNetworkReplyHandler.cpp" + +#endif diff --git a/src/3rdparty/webkit/WebCore/platform/network/qt/QNetworkReplyHandler.h b/src/3rdparty/webkit/WebCore/platform/network/qt/QNetworkReplyHandler.h new file mode 100644 index 0000000..98be28d --- /dev/null +++ b/src/3rdparty/webkit/WebCore/platform/network/qt/QNetworkReplyHandler.h @@ -0,0 +1,118 @@ +/* + Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ +#ifndef QNETWORKREPLYHANDLER_H +#define QNETWORKREPLYHANDLER_H + +#include <QObject> + +#if QT_VERSION >= 0x040400 + +#include <QNetworkRequest> +#include <QNetworkAccessManager> + +#include "FormData.h" + +QT_BEGIN_NAMESPACE +class QFile; +class QNetworkReply; +QT_END_NAMESPACE + +namespace WebCore { + +class ResourceHandle; + +class QNetworkReplyHandler : public QObject +{ + Q_OBJECT +public: + enum LoadMode { + LoadNormal, + LoadDeferred + }; + + QNetworkReplyHandler(ResourceHandle *handle, LoadMode); + void setLoadMode(LoadMode); + + QNetworkReply* reply() const { return m_reply; } + + void abort(); + + QNetworkReply* release(); + +private slots: + void finish(); + void sendResponseIfNeeded(); + void forwardData(); + +private: + void start(); + void resetState(); + void sendQueuedItems(); + + QNetworkReply* m_reply; + ResourceHandle* m_resourceHandle; + bool m_redirected; + bool m_responseSent; + LoadMode m_loadMode; + QNetworkAccessManager::Operation m_method; + QNetworkRequest m_request; + uint m_startTime; + + // defer state holding + bool m_shouldStart; + bool m_shouldFinish; + bool m_shouldSendResponse; + bool m_shouldForwardData; +}; + +// Self destructing QIODevice for FormData +// For QNetworkAccessManager::put we will have to gurantee that the +// QIODevice is valid as long finished() of the QNetworkReply has not +// been emitted. With the presence of QNetworkReplyHandler::release I do +// not want to gurantee this. +class FormDataIODevice : public QIODevice { + Q_OBJECT +public: + FormDataIODevice(FormData*); + ~FormDataIODevice(); + + void setParent(QNetworkReply*); + bool isSequential() const; + +protected: + qint64 readData(char*, qint64); + qint64 writeData(const char*, qint64); + +private Q_SLOTS: + void slotFinished(); + +private: + void moveToNextElement(); + +private: + Vector<FormDataElement> m_formElements; + QFile* m_currentFile; + qint64 m_currentDelta; +}; + +} + +#endif + +#endif // QNETWORKREPLYHANDLER_H diff --git a/src/3rdparty/webkit/WebCore/platform/network/qt/ResourceError.h b/src/3rdparty/webkit/WebCore/platform/network/qt/ResourceError.h new file mode 100644 index 0000000..ca8d36b --- /dev/null +++ b/src/3rdparty/webkit/WebCore/platform/network/qt/ResourceError.h @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ResourceError_h +#define ResourceError_h + +#include "ResourceErrorBase.h" + +namespace WebCore { + +class ResourceError : public ResourceErrorBase +{ +public: + ResourceError() + { + } + + ResourceError(const String& domain, int errorCode, const String& failingURL, const String& localizedDescription) + : ResourceErrorBase(domain, errorCode, failingURL, localizedDescription) + { + } +}; + +} + +#endif // ResourceError_h_ diff --git a/src/3rdparty/webkit/WebCore/platform/network/qt/ResourceHandleQt.cpp b/src/3rdparty/webkit/WebCore/platform/network/qt/ResourceHandleQt.cpp new file mode 100644 index 0000000..7af5895 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/platform/network/qt/ResourceHandleQt.cpp @@ -0,0 +1,208 @@ +/* + * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) + * Copyright (C) 2008 Holger Hans Peter Freyther + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#include "Frame.h" +#include "DocLoader.h" +#include "ResourceHandle.h" +#include "ResourceHandleClient.h" +#include "ResourceHandleInternal.h" +#include "qwebpage_p.h" +#include "ChromeClientQt.h" +#include "FrameLoaderClientQt.h" +#include "Page.h" +#include "QNetworkReplyHandler.h" + +#include "NotImplemented.h" + +#include <QCoreApplication> +#include <QUrl> +#if QT_VERSION >= 0x040400 +#include <QNetworkAccessManager> +#include <QNetworkRequest> +#include <QNetworkReply> +#else +#include "qwebnetworkinterface_p.h" +#endif + +namespace WebCore { + +class WebCoreSynchronousLoader : public ResourceHandleClient { +public: + WebCoreSynchronousLoader(); + + void waitForCompletion(); + + virtual void didReceiveResponse(ResourceHandle*, const ResourceResponse&); + virtual void didReceiveData(ResourceHandle*, const char*, int, int lengthReceived); + virtual void didFinishLoading(ResourceHandle*); + virtual void didFail(ResourceHandle*, const ResourceError&); + + ResourceResponse resourceResponse() const { return m_response; } + ResourceError resourceError() const { return m_error; } + Vector<char> data() const { return m_data; } + +private: + ResourceResponse m_response; + ResourceError m_error; + Vector<char> m_data; + bool m_finished; +}; + +WebCoreSynchronousLoader::WebCoreSynchronousLoader() + : m_finished(false) +{ +} + +void WebCoreSynchronousLoader::didReceiveResponse(ResourceHandle*, const ResourceResponse& response) +{ + m_response = response; +} + +void WebCoreSynchronousLoader::didReceiveData(ResourceHandle*, const char* data, int length, int) +{ + m_data.append(data, length); +} + +void WebCoreSynchronousLoader::didFinishLoading(ResourceHandle*) +{ + m_finished = true; +} + +void WebCoreSynchronousLoader::didFail(ResourceHandle*, const ResourceError& error) +{ + m_error = error; + m_finished = true; +} + +void WebCoreSynchronousLoader::waitForCompletion() +{ + while (!m_finished) + QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents); +} + +ResourceHandleInternal::~ResourceHandleInternal() +{ +} + +ResourceHandle::~ResourceHandle() +{ + if (d->m_job) + cancel(); +} + +bool ResourceHandle::start(Frame* frame) +{ + if (!frame) + return false; + + Page *page = frame->page(); + // If we are no longer attached to a Page, this must be an attempted load from an + // onUnload handler, so let's just block it. + if (!page) + return false; + + getInternal()->m_frame = static_cast<FrameLoaderClientQt*>(frame->loader()->client())->webFrame(); +#if QT_VERSION < 0x040400 + return QWebNetworkManager::self()->add(this, getInternal()->m_frame->page()->d->networkInterface); +#else + ResourceHandleInternal *d = getInternal(); + d->m_job = new QNetworkReplyHandler(this, QNetworkReplyHandler::LoadMode(d->m_defersLoading)); + return true; +#endif +} + +void ResourceHandle::cancel() +{ +#if QT_VERSION < 0x040400 + QWebNetworkManager::self()->cancel(this); +#else + if (d->m_job) + d->m_job->abort(); +#endif +} + +bool ResourceHandle::loadsBlocked() +{ + return false; +} + +bool ResourceHandle::willLoadFromCache(ResourceRequest& request) +{ + notImplemented(); + return false; +} + +bool ResourceHandle::supportsBufferedData() +{ + return false; +} + +PassRefPtr<SharedBuffer> ResourceHandle::bufferedData() +{ + ASSERT_NOT_REACHED(); + return 0; +} + +void ResourceHandle::loadResourceSynchronously(const ResourceRequest& request, ResourceError& error, ResourceResponse& response, Vector<char>& data, Frame* frame) +{ + WebCoreSynchronousLoader syncLoader; + ResourceHandle handle(request, &syncLoader, true, false, true); + +#if QT_VERSION < 0x040400 + if (!QWebNetworkManager::self()->add(&handle, QWebNetworkInterface::defaultInterface(), QWebNetworkManager::SynchronousJob)) { + // FIXME Create a sane ResourceError + error = ResourceError(String(), -1, String(), String()); + return; + } +#else + ResourceHandleInternal *d = handle.getInternal(); + d->m_frame = static_cast<FrameLoaderClientQt*>(frame->loader()->client())->webFrame(); + d->m_job = new QNetworkReplyHandler(&handle, QNetworkReplyHandler::LoadNormal); +#endif + + syncLoader.waitForCompletion(); + error = syncLoader.resourceError(); + data = syncLoader.data(); + response = syncLoader.resourceResponse(); +} + + +void ResourceHandle::setDefersLoading(bool defers) +{ + d->m_defersLoading = defers; + +#if QT_VERSION >= 0x040400 + if (d->m_job) + d->m_job->setLoadMode(QNetworkReplyHandler::LoadMode(defers)); +#endif +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/platform/network/qt/ResourceRequest.h b/src/3rdparty/webkit/WebCore/platform/network/qt/ResourceRequest.h new file mode 100644 index 0000000..af76f61 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/platform/network/qt/ResourceRequest.h @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2003, 2006 Apple Computer, Inc. All rights reserved. + * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ResourceRequest_h +#define ResourceRequest_h + +#include "ResourceRequestBase.h" + +QT_BEGIN_NAMESPACE +class QNetworkRequest; +QT_END_NAMESPACE + +namespace WebCore { + + struct ResourceRequest : ResourceRequestBase { + + ResourceRequest(const String& url) + : ResourceRequestBase(KURL(url), UseProtocolCachePolicy) + { + } + + ResourceRequest(const KURL& url) + : ResourceRequestBase(url, UseProtocolCachePolicy) + { + } + + ResourceRequest(const KURL& url, const String& referrer, ResourceRequestCachePolicy policy = UseProtocolCachePolicy) + : ResourceRequestBase(url, policy) + { + setHTTPReferrer(referrer); + } + + ResourceRequest() + : ResourceRequestBase(KURL(), UseProtocolCachePolicy) + { + } + +#if QT_VERSION >= 0x040400 + QNetworkRequest toNetworkRequest() const; +#endif + + private: + friend class ResourceRequestBase; + + void doUpdatePlatformRequest() {} + void doUpdateResourceRequest() {} + }; + +} // namespace WebCore + +#endif // ResourceRequest_h diff --git a/src/3rdparty/webkit/WebCore/platform/network/qt/ResourceRequestQt.cpp b/src/3rdparty/webkit/WebCore/platform/network/qt/ResourceRequestQt.cpp new file mode 100644 index 0000000..9308878 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/platform/network/qt/ResourceRequestQt.cpp @@ -0,0 +1,49 @@ +/* + Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "config.h" +#include "ResourceRequest.h" + +#include <qglobal.h> +#if QT_VERSION >= 0x040400 + +#include <QNetworkRequest> +#include <QUrl> + +namespace WebCore { + +QNetworkRequest ResourceRequest::toNetworkRequest() const +{ + QNetworkRequest request; + request.setUrl(url()); + + const HTTPHeaderMap &headers = httpHeaderFields(); + for (HTTPHeaderMap::const_iterator it = headers.begin(), end = headers.end(); + it != end; ++it) { + QByteArray name = QString(it->first).toAscii(); + QByteArray value = QString(it->second).toAscii(); + request.setRawHeader(name, value); + } + + return request; +} + +} + +#endif diff --git a/src/3rdparty/webkit/WebCore/platform/network/qt/ResourceResponse.h b/src/3rdparty/webkit/WebCore/platform/network/qt/ResourceResponse.h new file mode 100644 index 0000000..345ef25 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/platform/network/qt/ResourceResponse.h @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ResourceResponse_h +#define ResourceResponse_h + +#include "ResourceResponseBase.h" + +namespace WebCore { + +class ResourceResponse : public ResourceResponseBase { +public: + ResourceResponse() + { + } + + ResourceResponse(const KURL& url, const String& mimeType, long long expectedLength, const String& textEncodingName, const String& filename) + : ResourceResponseBase(url, mimeType, expectedLength, textEncodingName, filename) + { + } +}; + +} // namespace WebCore + +#endif // ResourceResponse_h |