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/common/fileapi/file_system_messages.h" | 9 #include "content/common/fileapi/file_system_messages.h" |
10 #include "content/renderer/pepper/common.h" | 10 #include "content/renderer/pepper/common.h" |
11 #include "content/renderer/pepper/host_globals.h" | |
12 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" | |
11 #include "content/renderer/pepper/plugin_module.h" | 13 #include "content/renderer/pepper/plugin_module.h" |
12 #include "content/renderer/pepper/ppb_file_ref_impl.h" | |
13 #include "content/renderer/render_thread_impl.h" | 14 #include "content/renderer/render_thread_impl.h" |
14 #include "net/http/http_util.h" | 15 #include "net/http/http_util.h" |
16 #include "ppapi/proxy/ppapi_messages.h" | |
17 #include "ppapi/shared_impl/file_ref_detailed_info.h" | |
15 #include "ppapi/shared_impl/url_request_info_data.h" | 18 #include "ppapi/shared_impl/url_request_info_data.h" |
16 #include "ppapi/shared_impl/var.h" | 19 #include "ppapi/shared_impl/var.h" |
17 #include "ppapi/thunk/enter.h" | 20 #include "ppapi/thunk/enter.h" |
18 #include "third_party/WebKit/public/platform/WebData.h" | 21 #include "third_party/WebKit/public/platform/WebData.h" |
19 #include "third_party/WebKit/public/platform/WebHTTPBody.h" | 22 #include "third_party/WebKit/public/platform/WebHTTPBody.h" |
20 #include "third_party/WebKit/public/platform/WebURL.h" | 23 #include "third_party/WebKit/public/platform/WebURL.h" |
21 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 24 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
22 #include "third_party/WebKit/public/web/WebDocument.h" | 25 #include "third_party/WebKit/public/web/WebDocument.h" |
23 #include "third_party/WebKit/public/web/WebFrame.h" | 26 #include "third_party/WebKit/public/web/WebFrame.h" |
24 #include "url/gurl.h" | 27 #include "url/gurl.h" |
25 #include "url/url_util.h" | 28 #include "url/url_util.h" |
26 #include "webkit/child/weburlrequest_extradata_impl.h" | 29 #include "webkit/child/weburlrequest_extradata_impl.h" |
27 | 30 |
28 using ppapi::URLRequestInfoData; | 31 using ppapi::URLRequestInfoData; |
29 using ppapi::Resource; | 32 using ppapi::Resource; |
30 using ppapi::thunk::EnterResourceNoLock; | 33 using ppapi::thunk::EnterResourceNoLock; |
31 using ppapi::thunk::PPB_FileRef_API; | |
32 using WebKit::WebData; | 34 using WebKit::WebData; |
33 using WebKit::WebHTTPBody; | 35 using WebKit::WebHTTPBody; |
34 using WebKit::WebString; | 36 using WebKit::WebString; |
35 using WebKit::WebFrame; | 37 using WebKit::WebFrame; |
36 using WebKit::WebURL; | 38 using WebKit::WebURL; |
37 using WebKit::WebURLRequest; | 39 using WebKit::WebURLRequest; |
38 | 40 |
39 namespace content { | 41 namespace content { |
40 | 42 |
41 namespace { | 43 namespace { |
42 | 44 |
43 // Appends the file ref given the Resource pointer associated with it to the | 45 // Appends the file ref given the Resource pointer associated with it to the |
44 // given HTTP body, returning true on success. | 46 // given HTTP body, returning true on success. |
45 bool AppendFileRefToBody( | 47 bool AppendFileRefToBody( |
46 Resource* file_ref_resource, | 48 ppapi::FileRef_DetailedInfo file_info, |
dmichael (off chromium)
2013/08/07 22:19:13
nit: The underscore looks a little weird. I think
| |
47 int64_t start_offset, | 49 int64_t start_offset, |
48 int64_t number_of_bytes, | 50 int64_t number_of_bytes, |
49 PP_Time expected_last_modified_time, | 51 PP_Time expected_last_modified_time, |
50 WebHTTPBody *http_body) { | 52 WebHTTPBody *http_body) { |
51 // Get the underlying file ref impl. | |
52 if (!file_ref_resource) | |
53 return false; | |
54 PPB_FileRef_API* file_ref_api = file_ref_resource->AsPPB_FileRef_API(); | |
55 if (!file_ref_api) | |
56 return false; | |
57 const PPB_FileRef_Impl* file_ref = | |
58 static_cast<PPB_FileRef_Impl*>(file_ref_api); | |
59 | |
60 base::FilePath platform_path; | 53 base::FilePath platform_path; |
61 switch (file_ref->GetFileSystemType()) { | 54 switch (file_info.file_system_type) { |
62 case PP_FILESYSTEMTYPE_LOCALTEMPORARY: | 55 case PP_FILESYSTEMTYPE_LOCALTEMPORARY: |
63 case PP_FILESYSTEMTYPE_LOCALPERSISTENT: | 56 case PP_FILESYSTEMTYPE_LOCALPERSISTENT: |
64 // TODO(kinuko): remove this sync IPC when we fully support | 57 // TODO(kinuko): remove this sync IPC when we fully support |
65 // AppendURLRange for FileSystem URL. | 58 // AppendURLRange for FileSystem URL. |
66 RenderThreadImpl::current()->Send( | 59 RenderThreadImpl::current()->Send( |
67 new FileSystemHostMsg_SyncGetPlatformPath( | 60 new FileSystemHostMsg_SyncGetPlatformPath( |
68 file_ref->GetFileSystemURL(), &platform_path)); | 61 GURL(file_info.file_system_url_spec), &platform_path)); |
69 break; | 62 break; |
70 case PP_FILESYSTEMTYPE_EXTERNAL: | 63 case PP_FILESYSTEMTYPE_EXTERNAL: |
71 platform_path = file_ref->GetSystemPath(); | 64 platform_path = file_info.external_path; |
72 break; | 65 break; |
73 default: | 66 default: |
74 NOTREACHED(); | 67 NOTREACHED(); |
75 } | 68 } |
76 http_body->appendFileRange( | 69 http_body->appendFileRange( |
77 platform_path.AsUTF16Unsafe(), | 70 platform_path.AsUTF16Unsafe(), |
78 start_offset, | 71 start_offset, |
79 number_of_bytes, | 72 number_of_bytes, |
80 expected_last_modified_time); | 73 expected_last_modified_time); |
81 return true; | 74 return true; |
82 } | 75 } |
83 | 76 |
84 // Checks that the request data is valid. Returns false on failure. Note that | 77 // Checks that the request data is valid. Returns false on failure. Note that |
85 // method and header validation is done by the URL loader when the request is | 78 // method and header validation is done by the URL loader when the request is |
86 // opened, and any access errors are returned asynchronously. | 79 // opened, and any access errors are returned asynchronously. |
87 bool ValidateURLRequestData(const ::ppapi::URLRequestInfoData& data) { | 80 bool ValidateURLRequestData(const ::ppapi::URLRequestInfoData& data) { |
88 if (data.prefetch_buffer_lower_threshold < 0 || | 81 if (data.prefetch_buffer_lower_threshold < 0 || |
89 data.prefetch_buffer_upper_threshold < 0 || | 82 data.prefetch_buffer_upper_threshold < 0 || |
90 data.prefetch_buffer_upper_threshold <= | 83 data.prefetch_buffer_upper_threshold <= |
91 data.prefetch_buffer_lower_threshold) { | 84 data.prefetch_buffer_lower_threshold) { |
92 return false; | 85 return false; |
93 } | 86 } |
94 return true; | 87 return true; |
95 } | 88 } |
96 | 89 |
97 // Ensures that the file_ref members of the given request info data are | |
98 // populated from the resource IDs. Returns true on success. | |
99 bool EnsureFileRefObjectsPopulated(::ppapi::URLRequestInfoData* data) { | |
100 // Get the Resource objects for any file refs with only host resource (this | |
101 // is the state of the request as it comes off IPC). | |
102 for (size_t i = 0; i < data->body.size(); ++i) { | |
103 URLRequestInfoData::BodyItem& item = data->body[i]; | |
104 if (item.is_file && !item.file_ref.get()) { | |
105 EnterResourceNoLock<PPB_FileRef_API> enter( | |
106 item.file_ref_host_resource.host_resource(), false); | |
107 if (!enter.succeeded()) | |
108 return false; | |
109 item.file_ref = enter.resource(); | |
110 } | |
111 } | |
112 return true; | |
113 } | |
114 | |
115 } // namespace | 90 } // namespace |
116 | 91 |
117 bool CreateWebURLRequest(::ppapi::URLRequestInfoData* data, | 92 bool CreateWebURLRequest(PP_Instance instance, |
93 ::ppapi::URLRequestInfoData* data, | |
118 WebFrame* frame, | 94 WebFrame* frame, |
119 WebURLRequest* dest) { | 95 WebURLRequest* dest) { |
120 // In the out-of-process case, we've received the URLRequestInfoData | 96 // In the out-of-process case, we've received the URLRequestInfoData |
121 // from the untrusted plugin and done no validation on it. We need to be | 97 // from the untrusted plugin and done no validation on it. We need to be |
122 // sure it's not being malicious by checking everything for consistency. | 98 // sure it's not being malicious by checking everything for consistency. |
123 if (!ValidateURLRequestData(*data) || !EnsureFileRefObjectsPopulated(data)) | 99 if (!ValidateURLRequestData(*data)) |
124 return false; | 100 return false; |
125 | 101 |
126 dest->initialize(); | 102 dest->initialize(); |
127 dest->setTargetType(WebURLRequest::TargetIsObject); | 103 dest->setTargetType(WebURLRequest::TargetIsObject); |
128 dest->setURL(frame->document().completeURL(WebString::fromUTF8( | 104 dest->setURL(frame->document().completeURL(WebString::fromUTF8( |
129 data->url))); | 105 data->url))); |
130 dest->setDownloadToFile(data->stream_to_file); | 106 dest->setDownloadToFile(data->stream_to_file); |
131 dest->setReportUploadProgress(data->record_upload_progress); | 107 dest->setReportUploadProgress(data->record_upload_progress); |
132 | 108 |
133 if (!data->method.empty()) | 109 if (!data->method.empty()) |
134 dest->setHTTPMethod(WebString::fromUTF8(data->method)); | 110 dest->setHTTPMethod(WebString::fromUTF8(data->method)); |
135 | 111 |
136 dest->setFirstPartyForCookies(frame->document().firstPartyForCookies()); | 112 dest->setFirstPartyForCookies(frame->document().firstPartyForCookies()); |
137 | 113 |
138 const std::string& headers = data->headers; | 114 const std::string& headers = data->headers; |
139 if (!headers.empty()) { | 115 if (!headers.empty()) { |
140 net::HttpUtil::HeadersIterator it(headers.begin(), headers.end(), "\n\r"); | 116 net::HttpUtil::HeadersIterator it(headers.begin(), headers.end(), "\n\r"); |
141 while (it.GetNext()) { | 117 while (it.GetNext()) { |
142 dest->addHTTPHeaderField( | 118 dest->addHTTPHeaderField( |
143 WebString::fromUTF8(it.name()), | 119 WebString::fromUTF8(it.name()), |
144 WebString::fromUTF8(it.values())); | 120 WebString::fromUTF8(it.values())); |
145 } | 121 } |
146 } | 122 } |
147 | 123 |
124 // Get file information for FileRefs inside BodyItems. | |
125 std::vector<PP_Resource> resources; | |
126 if (!data->body.empty()) { | |
dmichael (off chromium)
2013/08/07 22:19:13
this if seems unnecessary... the loop condition s
teravest
2013/08/08 00:50:06
Done.
| |
127 for (size_t i = 0; i < data->body.size(); ++i) { | |
128 const URLRequestInfoData::BodyItem& item = data->body[i]; | |
129 if (item.is_file) | |
130 resources.push_back(item.file_ref_pp_resource); | |
131 } | |
132 } | |
133 std::vector<ppapi::FileRef_DetailedInfo> infos; | |
134 if (!resources.empty()) { | |
135 PepperPluginInstanceImpl* instance_impl = | |
136 HostGlobals::Get()->GetInstance(instance); | |
137 int child_process_id = instance_impl->module()->GetPluginChildId(); | |
138 RenderThreadImpl::current()->Send( | |
139 new PpapiHostMsg_FileRef_SyncGetInfoForRenderer( | |
140 0, child_process_id, resources, &infos)); | |
141 } | |
142 | |
143 | |
148 // Append the upload data. | 144 // Append the upload data. |
149 if (!data->body.empty()) { | 145 if (!data->body.empty()) { |
150 WebHTTPBody http_body; | 146 WebHTTPBody http_body; |
151 http_body.initialize(); | 147 http_body.initialize(); |
148 int file_index = 0; | |
152 for (size_t i = 0; i < data->body.size(); ++i) { | 149 for (size_t i = 0; i < data->body.size(); ++i) { |
153 const URLRequestInfoData::BodyItem& item = data->body[i]; | 150 const URLRequestInfoData::BodyItem& item = data->body[i]; |
154 if (item.is_file) { | 151 if (item.is_file) { |
155 if (!AppendFileRefToBody(item.file_ref.get(), | 152 if (item.file_ref_pp_resource != infos[file_index].resource) |
153 return false; | |
154 if (!AppendFileRefToBody(infos[file_index], | |
156 item.start_offset, | 155 item.start_offset, |
157 item.number_of_bytes, | 156 item.number_of_bytes, |
158 item.expected_last_modified_time, | 157 item.expected_last_modified_time, |
159 &http_body)) | 158 &http_body)) |
160 return false; | 159 return false; |
160 file_index++; | |
161 } else { | 161 } else { |
162 DCHECK(!item.data.empty()); | 162 DCHECK(!item.data.empty()); |
163 http_body.appendData(WebData(item.data)); | 163 http_body.appendData(WebData(item.data)); |
164 } | 164 } |
165 } | 165 } |
166 dest->setHTTPBody(http_body); | 166 dest->setHTTPBody(http_body); |
167 } | 167 } |
168 | 168 |
169 // Add the "Referer" header if there is a custom referrer. Such requests | 169 // Add the "Referer" header if there is a custom referrer. Such requests |
170 // require universal access. For all other requests, "Referer" will be set | 170 // require universal access. For all other requests, "Referer" will be set |
(...skipping 22 matching lines...) Expand all Loading... | |
193 bool URLRequestRequiresUniversalAccess( | 193 bool URLRequestRequiresUniversalAccess( |
194 const ::ppapi::URLRequestInfoData& data) { | 194 const ::ppapi::URLRequestInfoData& data) { |
195 return | 195 return |
196 data.has_custom_referrer_url || | 196 data.has_custom_referrer_url || |
197 data.has_custom_content_transfer_encoding || | 197 data.has_custom_content_transfer_encoding || |
198 data.has_custom_user_agent || | 198 data.has_custom_user_agent || |
199 url_util::FindAndCompareScheme(data.url, "javascript", NULL); | 199 url_util::FindAndCompareScheme(data.url, "javascript", NULL); |
200 } | 200 } |
201 | 201 |
202 } // namespace content | 202 } // namespace content |
OLD | NEW |