REGRESSION: We see authentication challenge sheets for favicon requests.
[WebKit-https.git] / Source / WebKit2 / Shared / Network / NetworkResourceLoadParameters.cpp
1 /*
2  * Copyright (C) 2012 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. 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 APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #include "config.h"
27 #include "NetworkResourceLoadParameters.h"
28
29 #include "ArgumentCoders.h"
30 #include "DataReference.h"
31 #include "DecoderAdapter.h"
32 #include "EncoderAdapter.h"
33 #include "WebCoreArgumentCoders.h"
34
35 #if ENABLE(NETWORK_PROCESS)
36
37 using namespace WebCore;
38
39 namespace WebKit {
40 NetworkResourceLoadParameters::NetworkResourceLoadParameters()
41     : identifier(0)
42     , webPageID(0)
43     , webFrameID(0)
44     , priority(ResourceLoadPriorityVeryLow)
45     , contentSniffingPolicy(SniffContent)
46     , allowStoredCredentials(DoNotAllowStoredCredentials)
47     , clientCredentialPolicy(DoNotAskClientForAnyCredentials)
48     , inPrivateBrowsingMode(false)
49     , shouldClearReferrerOnHTTPSToHTTPRedirect(true)
50     , isMainResource(false)
51 {
52 }
53
54 void NetworkResourceLoadParameters::encode(CoreIPC::ArgumentEncoder& encoder) const
55 {
56     encoder << identifier;
57     encoder << webPageID;
58     encoder << webFrameID;
59     encoder << request;
60
61     encoder << static_cast<bool>(request.httpBody());
62     if (request.httpBody()) {
63         EncoderAdapter httpBodyEncoderAdapter;
64         request.httpBody()->encode(httpBodyEncoderAdapter);
65         encoder << httpBodyEncoderAdapter.dataReference();
66
67         const Vector<FormDataElement>& elements = request.httpBody()->elements();
68         size_t fileCount = 0;
69         for (size_t i = 0, count = elements.size(); i < count; ++i) {
70             if (elements[i].m_type == FormDataElement::encodedFile)
71                 ++fileCount;
72         }
73
74         SandboxExtension::HandleArray requestBodySandboxExtensions;
75         requestBodySandboxExtensions.allocate(fileCount);
76         size_t extensionIndex = 0;
77         for (size_t i = 0, count = elements.size(); i < count; ++i) {
78             const FormDataElement& element = elements[i];
79             if (element.m_type == FormDataElement::encodedFile) {
80                 const String& path = element.m_shouldGenerateFile ? element.m_generatedFilename : element.m_filename;
81                 SandboxExtension::createHandle(path, SandboxExtension::ReadOnly, requestBodySandboxExtensions[extensionIndex++]);
82             }
83         }
84         encoder << requestBodySandboxExtensions;
85     }
86
87     if (request.url().isLocalFile()) {
88         SandboxExtension::Handle requestSandboxExtension;
89         SandboxExtension::createHandle(request.url().fileSystemPath(), SandboxExtension::ReadOnly, requestSandboxExtension);
90         encoder << requestSandboxExtension;
91     }
92
93     encoder.encodeEnum(priority);
94     encoder.encodeEnum(contentSniffingPolicy);
95     encoder.encodeEnum(allowStoredCredentials);
96     encoder.encodeEnum(clientCredentialPolicy);
97     encoder << inPrivateBrowsingMode;
98     encoder << shouldClearReferrerOnHTTPSToHTTPRedirect;
99     encoder << isMainResource;
100 }
101
102 bool NetworkResourceLoadParameters::decode(CoreIPC::ArgumentDecoder& decoder, NetworkResourceLoadParameters& result)
103 {
104     if (!decoder.decode(result.identifier))
105         return false;
106
107     if (!decoder.decode(result.webPageID))
108         return false;
109
110     if (!decoder.decode(result.webFrameID))
111         return false;
112
113     if (!decoder.decode(result.request))
114         return false;
115
116     bool hasHTTPBody;
117     if (!decoder.decode(hasHTTPBody))
118         return false;
119
120     if (hasHTTPBody) {
121         CoreIPC::DataReference formData;
122         if (!decoder.decode(formData))
123             return false;
124         DecoderAdapter httpBodyDecoderAdapter(formData.data(), formData.size());
125         result.request.setHTTPBody(FormData::decode(httpBodyDecoderAdapter));
126
127         if (!decoder.decode(result.requestBodySandboxExtensions))
128             return false;
129     }
130
131     if (result.request.url().isLocalFile()) {
132         if (!decoder.decode(result.resourceSandboxExtension))
133             return false;
134     }
135
136     if (!decoder.decodeEnum(result.priority))
137         return false;
138     if (!decoder.decodeEnum(result.contentSniffingPolicy))
139         return false;
140     if (!decoder.decodeEnum(result.allowStoredCredentials))
141         return false;
142     if (!decoder.decodeEnum(result.clientCredentialPolicy))
143         return false;
144     if (!decoder.decode(result.inPrivateBrowsingMode))
145         return false;
146     if (!decoder.decode(result.shouldClearReferrerOnHTTPSToHTTPRedirect))
147         return false;
148     if (!decoder.decode(result.isMainResource))
149         return false;
150
151     return true;
152 }
153     
154 } // namespace WebKit
155
156 #endif // ENABLE(NETWORK_PROCESS)