• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2010, The Android Open Source Project
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *  * Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  *  * Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 
26 #ifndef WebResponse_h
27 #define WebResponse_h
28 
29 #include "ChromiumIncludes.h"
30 #include "KURL.h"
31 #include "WebViewClientError.h"
32 
33 #include <map>
34 #include <string>
35 
36 namespace WebCore {
37 class ResourceResponse;
38 class ResourceError;
39 }
40 
41 namespace android {
42 
43 class WebResponse {
44 
45 public:
WebResponse()46     WebResponse() {}
47     WebResponse(net::URLRequest*);
48     WebResponse(const std::string &url, const std::string &mimeType, long long expectedSize, const std::string &encoding, int httpStatusCode);
49 
50     const std::string& getUrl() const;
51     void setUrl(const std::string&);
52 
53     const std::string& getMimeType(); // Use only on WebCore thread.
54     bool getHeader(const std::string& header, std::string* result) const;
55     long long getExpectedSize() const;
56 
getSslInfo()57     const net::SSLInfo& getSslInfo() const { return m_sslInfo; }
58 
59     // The create() methods create WebCore objects. They must only be called on the WebKit thread.
60     WebCore::KURL createKurl();
61     WebCore::ResourceResponse createResourceResponse();
62     WebCore::ResourceError createResourceError();
63 
64     static const std::string resolveMimeType(const std::string& url, const std::string& old_mime);
65 
66 private:
67     net::Error m_error;
68     std::string m_encoding;
69     int m_httpStatusCode;
70     std::string m_host;
71     std::string m_httpStatusText;
72     long long m_expectedSize;
73     std::string m_mime;
74     std::string m_url;
75     net::SSLInfo m_sslInfo;
76 
77     struct CaseInsensitiveLessThan {
operatorCaseInsensitiveLessThan78         bool operator()(const std::string& lhs, const std::string& rhs) const {
79             return strcasecmp(lhs.c_str(), rhs.c_str()) < 0;
80         }
81     };
82 
83     // Header fields are case insensitive, so we use a case-insensitive map.
84     // See RFC 822, 3.4.7, "CASE INDEPENDENCE".
85     std::map<std::string, std::string, CaseInsensitiveLessThan> m_headerFields;
86 
87 };
88 
89 } // namespace android
90 
91 #endif
92