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 "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "content/child/request_extra_data.h" | 9 #include "content/child/request_extra_data.h" |
10 #include "content/common/fileapi/file_system_messages.h" | 10 #include "content/common/fileapi/file_system_messages.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 using blink::WebFrame; | 38 using blink::WebFrame; |
39 using blink::WebURL; | 39 using blink::WebURL; |
40 using blink::WebURLRequest; | 40 using blink::WebURLRequest; |
41 | 41 |
42 namespace content { | 42 namespace content { |
43 | 43 |
44 namespace { | 44 namespace { |
45 | 45 |
46 // Appends the file ref given the Resource pointer associated with it to the | 46 // Appends the file ref given the Resource pointer associated with it to the |
47 // given HTTP body, returning true on success. | 47 // given HTTP body, returning true on success. |
48 bool AppendFileRefToBody( | 48 bool AppendFileRefToBody(PP_Instance instance, |
49 PP_Instance instance, | 49 PP_Resource resource, |
50 PP_Resource resource, | 50 int64_t start_offset, |
51 int64_t start_offset, | 51 int64_t number_of_bytes, |
52 int64_t number_of_bytes, | 52 PP_Time expected_last_modified_time, |
53 PP_Time expected_last_modified_time, | 53 WebHTTPBody* http_body) { |
54 WebHTTPBody *http_body) { | |
55 base::FilePath platform_path; | 54 base::FilePath platform_path; |
56 PepperPluginInstanceImpl* instance_impl = | 55 PepperPluginInstanceImpl* instance_impl = |
57 HostGlobals::Get()->GetInstance(instance); | 56 HostGlobals::Get()->GetInstance(instance); |
58 if (!instance_impl) | 57 if (!instance_impl) |
59 return false; | 58 return false; |
60 | 59 |
61 RendererPpapiHost* renderer_ppapi_host = | 60 RendererPpapiHost* renderer_ppapi_host = |
62 instance_impl->module()->renderer_ppapi_host(); | 61 instance_impl->module()->renderer_ppapi_host(); |
63 if (!renderer_ppapi_host) | 62 if (!renderer_ppapi_host) |
64 return false; | 63 return false; |
(...skipping 11 matching lines...) Expand all Loading... |
76 RenderThreadImpl::current()->Send( | 75 RenderThreadImpl::current()->Send( |
77 new FileSystemHostMsg_SyncGetPlatformPath( | 76 new FileSystemHostMsg_SyncGetPlatformPath( |
78 file_ref_host->GetFileSystemURL(), &platform_path)); | 77 file_ref_host->GetFileSystemURL(), &platform_path)); |
79 break; | 78 break; |
80 case PP_FILESYSTEMTYPE_EXTERNAL: | 79 case PP_FILESYSTEMTYPE_EXTERNAL: |
81 platform_path = file_ref_host->GetExternalFilePath(); | 80 platform_path = file_ref_host->GetExternalFilePath(); |
82 break; | 81 break; |
83 default: | 82 default: |
84 NOTREACHED(); | 83 NOTREACHED(); |
85 } | 84 } |
86 http_body->appendFileRange( | 85 http_body->appendFileRange(platform_path.AsUTF16Unsafe(), |
87 platform_path.AsUTF16Unsafe(), | 86 start_offset, |
88 start_offset, | 87 number_of_bytes, |
89 number_of_bytes, | 88 expected_last_modified_time); |
90 expected_last_modified_time); | |
91 return true; | 89 return true; |
92 } | 90 } |
93 | 91 |
94 // Checks that the request data is valid. Returns false on failure. Note that | 92 // Checks that the request data is valid. Returns false on failure. Note that |
95 // method and header validation is done by the URL loader when the request is | 93 // method and header validation is done by the URL loader when the request is |
96 // opened, and any access errors are returned asynchronously. | 94 // opened, and any access errors are returned asynchronously. |
97 bool ValidateURLRequestData(const URLRequestInfoData& data) { | 95 bool ValidateURLRequestData(const URLRequestInfoData& data) { |
98 if (data.prefetch_buffer_lower_threshold < 0 || | 96 if (data.prefetch_buffer_lower_threshold < 0 || |
99 data.prefetch_buffer_upper_threshold < 0 || | 97 data.prefetch_buffer_upper_threshold < 0 || |
100 data.prefetch_buffer_upper_threshold <= | 98 data.prefetch_buffer_upper_threshold <= |
101 data.prefetch_buffer_lower_threshold) { | 99 data.prefetch_buffer_lower_threshold) { |
102 return false; | 100 return false; |
103 } | 101 } |
104 return true; | 102 return true; |
105 } | 103 } |
106 | 104 |
107 } // namespace | 105 } // namespace |
108 | 106 |
109 bool CreateWebURLRequest(PP_Instance instance, | 107 bool CreateWebURLRequest(PP_Instance instance, |
110 URLRequestInfoData* data, | 108 URLRequestInfoData* data, |
111 WebFrame* frame, | 109 WebFrame* frame, |
112 WebURLRequest* dest) { | 110 WebURLRequest* dest) { |
113 // In the out-of-process case, we've received the URLRequestInfoData | 111 // In the out-of-process case, we've received the URLRequestInfoData |
114 // from the untrusted plugin and done no validation on it. We need to be | 112 // from the untrusted plugin and done no validation on it. We need to be |
115 // sure it's not being malicious by checking everything for consistency. | 113 // sure it's not being malicious by checking everything for consistency. |
116 if (!ValidateURLRequestData(*data)) | 114 if (!ValidateURLRequestData(*data)) |
117 return false; | 115 return false; |
118 | 116 |
119 dest->initialize(); | 117 dest->initialize(); |
120 dest->setURL(frame->document().completeURL(WebString::fromUTF8( | 118 dest->setURL(frame->document().completeURL(WebString::fromUTF8(data->url))); |
121 data->url))); | |
122 dest->setDownloadToFile(data->stream_to_file); | 119 dest->setDownloadToFile(data->stream_to_file); |
123 dest->setReportUploadProgress(data->record_upload_progress); | 120 dest->setReportUploadProgress(data->record_upload_progress); |
124 | 121 |
125 if (!data->method.empty()) | 122 if (!data->method.empty()) |
126 dest->setHTTPMethod(WebString::fromUTF8(data->method)); | 123 dest->setHTTPMethod(WebString::fromUTF8(data->method)); |
127 | 124 |
128 dest->setFirstPartyForCookies(frame->document().firstPartyForCookies()); | 125 dest->setFirstPartyForCookies(frame->document().firstPartyForCookies()); |
129 | 126 |
130 const std::string& headers = data->headers; | 127 const std::string& headers = data->headers; |
131 if (!headers.empty()) { | 128 if (!headers.empty()) { |
132 net::HttpUtil::HeadersIterator it(headers.begin(), headers.end(), "\n\r"); | 129 net::HttpUtil::HeadersIterator it(headers.begin(), headers.end(), "\n\r"); |
133 while (it.GetNext()) { | 130 while (it.GetNext()) { |
134 dest->addHTTPHeaderField( | 131 dest->addHTTPHeaderField(WebString::fromUTF8(it.name()), |
135 WebString::fromUTF8(it.name()), | 132 WebString::fromUTF8(it.values())); |
136 WebString::fromUTF8(it.values())); | |
137 } | 133 } |
138 } | 134 } |
139 | 135 |
140 // Append the upload data. | 136 // Append the upload data. |
141 if (!data->body.empty()) { | 137 if (!data->body.empty()) { |
142 WebHTTPBody http_body; | 138 WebHTTPBody http_body; |
143 http_body.initialize(); | 139 http_body.initialize(); |
144 int file_index = 0; | 140 int file_index = 0; |
145 for (size_t i = 0; i < data->body.size(); ++i) { | 141 for (size_t i = 0; i < data->body.size(); ++i) { |
146 const URLRequestInfoData::BodyItem& item = data->body[i]; | 142 const URLRequestInfoData::BodyItem& item = data->body[i]; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 extra_data->set_custom_user_agent( | 176 extra_data->set_custom_user_agent( |
181 WebString::fromUTF8(data->custom_user_agent)); | 177 WebString::fromUTF8(data->custom_user_agent)); |
182 extra_data->set_was_after_preconnect_request(was_after_preconnect_request); | 178 extra_data->set_was_after_preconnect_request(was_after_preconnect_request); |
183 dest->setExtraData(extra_data); | 179 dest->setExtraData(extra_data); |
184 } | 180 } |
185 | 181 |
186 return true; | 182 return true; |
187 } | 183 } |
188 | 184 |
189 bool URLRequestRequiresUniversalAccess(const URLRequestInfoData& data) { | 185 bool URLRequestRequiresUniversalAccess(const URLRequestInfoData& data) { |
190 return | 186 return data.has_custom_referrer_url || |
191 data.has_custom_referrer_url || | 187 data.has_custom_content_transfer_encoding || |
192 data.has_custom_content_transfer_encoding || | 188 data.has_custom_user_agent || |
193 data.has_custom_user_agent || | 189 url_util::FindAndCompareScheme(data.url, "javascript", NULL); |
194 url_util::FindAndCompareScheme(data.url, "javascript", NULL); | |
195 } | 190 } |
196 | 191 |
197 } // namespace content | 192 } // namespace content |
OLD | NEW |