| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/renderer/pepper/url_request_info_util.h" | 5 #include "content/renderer/pepper/url_request_info_util.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 #include "ppapi/proxy/ppapi_messages.h" | 23 #include "ppapi/proxy/ppapi_messages.h" |
| 24 #include "ppapi/shared_impl/url_request_info_data.h" | 24 #include "ppapi/shared_impl/url_request_info_data.h" |
| 25 #include "ppapi/shared_impl/var.h" | 25 #include "ppapi/shared_impl/var.h" |
| 26 #include "ppapi/thunk/enter.h" | 26 #include "ppapi/thunk/enter.h" |
| 27 #include "third_party/WebKit/public/platform/FilePathConversion.h" | 27 #include "third_party/WebKit/public/platform/FilePathConversion.h" |
| 28 #include "third_party/WebKit/public/platform/WebData.h" | 28 #include "third_party/WebKit/public/platform/WebData.h" |
| 29 #include "third_party/WebKit/public/platform/WebHTTPBody.h" | 29 #include "third_party/WebKit/public/platform/WebHTTPBody.h" |
| 30 #include "third_party/WebKit/public/platform/WebURL.h" | 30 #include "third_party/WebKit/public/platform/WebURL.h" |
| 31 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 31 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
| 32 #include "third_party/WebKit/public/web/WebDocument.h" | 32 #include "third_party/WebKit/public/web/WebDocument.h" |
| 33 #include "third_party/WebKit/public/web/WebFrame.h" | 33 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 34 #include "url/gurl.h" | 34 #include "url/gurl.h" |
| 35 #include "url/url_util.h" | 35 #include "url/url_util.h" |
| 36 | 36 |
| 37 using ppapi::Resource; | 37 using ppapi::Resource; |
| 38 using ppapi::URLRequestInfoData; | 38 using ppapi::URLRequestInfoData; |
| 39 using ppapi::thunk::EnterResourceNoLock; | 39 using ppapi::thunk::EnterResourceNoLock; |
| 40 using blink::WebData; | 40 using blink::WebData; |
| 41 using blink::WebHTTPBody; | 41 using blink::WebHTTPBody; |
| 42 using blink::WebString; | 42 using blink::WebString; |
| 43 using blink::WebFrame; | 43 using blink::WebLocalFrame; |
| 44 using blink::WebURL; | 44 using blink::WebURL; |
| 45 using blink::WebURLRequest; | 45 using blink::WebURLRequest; |
| 46 | 46 |
| 47 namespace content { | 47 namespace content { |
| 48 | 48 |
| 49 namespace { | 49 namespace { |
| 50 | 50 |
| 51 // Appends the file ref given the Resource pointer associated with it to the | 51 // Appends the file ref given the Resource pointer associated with it to the |
| 52 // given HTTP body, returning true on success. | 52 // given HTTP body, returning true on success. |
| 53 bool AppendFileRefToBody(PP_Instance instance, | 53 bool AppendFileRefToBody(PP_Instance instance, |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 if (!filtered_version.empty()) | 139 if (!filtered_version.empty()) |
| 140 rv += "/" + filtered_version; | 140 rv += "/" + filtered_version; |
| 141 | 141 |
| 142 return rv; | 142 return rv; |
| 143 } | 143 } |
| 144 | 144 |
| 145 } // namespace | 145 } // namespace |
| 146 | 146 |
| 147 bool CreateWebURLRequest(PP_Instance instance, | 147 bool CreateWebURLRequest(PP_Instance instance, |
| 148 URLRequestInfoData* data, | 148 URLRequestInfoData* data, |
| 149 WebFrame* frame, | 149 WebLocalFrame* frame, |
| 150 WebURLRequest* dest) { | 150 WebURLRequest* dest) { |
| 151 // In the out-of-process case, we've received the URLRequestInfoData | 151 // In the out-of-process case, we've received the URLRequestInfoData |
| 152 // from the untrusted plugin and done no validation on it. We need to be | 152 // from the untrusted plugin and done no validation on it. We need to be |
| 153 // sure it's not being malicious by checking everything for consistency. | 153 // sure it's not being malicious by checking everything for consistency. |
| 154 if (!ValidateURLRequestData(*data)) | 154 if (!ValidateURLRequestData(*data)) |
| 155 return false; | 155 return false; |
| 156 | 156 |
| 157 std::string name_version; | 157 std::string name_version; |
| 158 | 158 |
| 159 // Allow instance to be 0 or -1 for testing purposes. | 159 // Allow instance to be 0 or -1 for testing purposes. |
| 160 if (instance && instance != -1) { | 160 if (instance && instance != -1) { |
| 161 PepperPluginInstanceImpl* instance_impl = | 161 PepperPluginInstanceImpl* instance_impl = |
| 162 HostGlobals::Get()->GetInstance(instance); | 162 HostGlobals::Get()->GetInstance(instance); |
| 163 if (instance_impl) { | 163 if (instance_impl) { |
| 164 name_version = MakeXRequestedWithValue( | 164 name_version = MakeXRequestedWithValue( |
| 165 instance_impl->module()->name(), | 165 instance_impl->module()->name(), instance_impl->module()->version()); |
| 166 instance_impl->module()->version()); | 166 } |
| 167 } | 167 } else { |
| 168 } else { | 168 name_version = "internal_testing_only"; |
| 169 name_version = "internal_testing_only"; | 169 } |
| 170 } | |
| 171 | 170 |
| 172 dest->SetURL( | 171 dest->SetURL( |
| 173 frame->GetDocument().CompleteURL(WebString::FromUTF8(data->url))); | 172 frame->GetDocument().CompleteURL(WebString::FromUTF8(data->url))); |
| 174 dest->SetDownloadToFile(data->stream_to_file); | 173 dest->SetDownloadToFile(data->stream_to_file); |
| 175 dest->SetReportUploadProgress(data->record_upload_progress); | 174 dest->SetReportUploadProgress(data->record_upload_progress); |
| 176 | 175 |
| 177 if (!data->method.empty()) | 176 if (!data->method.empty()) |
| 178 dest->SetHTTPMethod(WebString::FromUTF8(data->method)); | 177 dest->SetHTTPMethod(WebString::FromUTF8(data->method)); |
| 179 | 178 |
| 180 dest->SetFirstPartyForCookies(frame->GetDocument().FirstPartyForCookies()); | 179 dest->SetFirstPartyForCookies(frame->GetDocument().FirstPartyForCookies()); |
| 181 | 180 |
| 182 const std::string& headers = data->headers; | 181 const std::string& headers = data->headers; |
| 183 if (!headers.empty()) { | 182 if (!headers.empty()) { |
| 184 net::HttpUtil::HeadersIterator it(headers.begin(), headers.end(), "\n\r"); | 183 net::HttpUtil::HeadersIterator it(headers.begin(), headers.end(), "\n\r"); |
| 185 while (it.GetNext()) { | 184 while (it.GetNext()) { |
| 186 dest->AddHTTPHeaderField(WebString::FromUTF8(it.name()), | 185 dest->AddHTTPHeaderField(WebString::FromUTF8(it.name()), |
| 187 WebString::FromUTF8(it.values())); | 186 WebString::FromUTF8(it.values())); |
| 188 } | 187 } |
| 189 } | 188 } |
| 190 | 189 |
| 191 // Append the upload data. | 190 // Append the upload data. |
| 192 if (!data->body.empty()) { | 191 if (!data->body.empty()) { |
| 193 WebHTTPBody http_body; | 192 WebHTTPBody http_body; |
| 194 http_body.Initialize(); | 193 http_body.Initialize(); |
| 195 int file_index = 0; | 194 int file_index = 0; |
| 196 for (size_t i = 0; i < data->body.size(); ++i) { | 195 for (size_t i = 0; i < data->body.size(); ++i) { |
| 197 const URLRequestInfoData::BodyItem& item = data->body[i]; | 196 const URLRequestInfoData::BodyItem& item = data->body[i]; |
| 198 if (item.is_file) { | 197 if (item.is_file) { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 } | 240 } |
| 242 | 241 |
| 243 bool URLRequestRequiresUniversalAccess(const URLRequestInfoData& data) { | 242 bool URLRequestRequiresUniversalAccess(const URLRequestInfoData& data) { |
| 244 return data.has_custom_referrer_url || | 243 return data.has_custom_referrer_url || |
| 245 data.has_custom_content_transfer_encoding || | 244 data.has_custom_content_transfer_encoding || |
| 246 data.has_custom_user_agent || | 245 data.has_custom_user_agent || |
| 247 url::FindAndCompareScheme(data.url, url::kJavaScriptScheme, NULL); | 246 url::FindAndCompareScheme(data.url, url::kJavaScriptScheme, NULL); |
| 248 } | 247 } |
| 249 | 248 |
| 250 } // namespace content | 249 } // namespace content |
| OLD | NEW |