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_file_ref_renderer_host.h" | |
13 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" | |
11 #include "content/renderer/pepper/plugin_module.h" | 14 #include "content/renderer/pepper/plugin_module.h" |
12 #include "content/renderer/pepper/ppb_file_ref_impl.h" | 15 #include "content/renderer/pepper/renderer_ppapi_host_impl.h" |
13 #include "content/renderer/render_thread_impl.h" | 16 #include "content/renderer/render_thread_impl.h" |
14 #include "net/http/http_util.h" | 17 #include "net/http/http_util.h" |
18 #include "ppapi/proxy/ppapi_messages.h" | |
15 #include "ppapi/shared_impl/url_request_info_data.h" | 19 #include "ppapi/shared_impl/url_request_info_data.h" |
16 #include "ppapi/shared_impl/var.h" | 20 #include "ppapi/shared_impl/var.h" |
17 #include "ppapi/thunk/enter.h" | 21 #include "ppapi/thunk/enter.h" |
18 #include "third_party/WebKit/public/platform/WebData.h" | 22 #include "third_party/WebKit/public/platform/WebData.h" |
19 #include "third_party/WebKit/public/platform/WebHTTPBody.h" | 23 #include "third_party/WebKit/public/platform/WebHTTPBody.h" |
20 #include "third_party/WebKit/public/platform/WebURL.h" | 24 #include "third_party/WebKit/public/platform/WebURL.h" |
21 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 25 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
22 #include "third_party/WebKit/public/web/WebDocument.h" | 26 #include "third_party/WebKit/public/web/WebDocument.h" |
23 #include "third_party/WebKit/public/web/WebFrame.h" | 27 #include "third_party/WebKit/public/web/WebFrame.h" |
24 #include "url/gurl.h" | 28 #include "url/gurl.h" |
25 #include "url/url_util.h" | 29 #include "url/url_util.h" |
26 #include "webkit/child/weburlrequest_extradata_impl.h" | 30 #include "webkit/child/weburlrequest_extradata_impl.h" |
27 | 31 |
32 using ppapi::Resource; | |
28 using ppapi::URLRequestInfoData; | 33 using ppapi::URLRequestInfoData; |
29 using ppapi::Resource; | |
30 using ppapi::thunk::EnterResourceNoLock; | 34 using ppapi::thunk::EnterResourceNoLock; |
31 using ppapi::thunk::PPB_FileRef_API; | |
32 using WebKit::WebData; | 35 using WebKit::WebData; |
33 using WebKit::WebHTTPBody; | 36 using WebKit::WebHTTPBody; |
34 using WebKit::WebString; | 37 using WebKit::WebString; |
35 using WebKit::WebFrame; | 38 using WebKit::WebFrame; |
36 using WebKit::WebURL; | 39 using WebKit::WebURL; |
37 using WebKit::WebURLRequest; | 40 using WebKit::WebURLRequest; |
38 | 41 |
39 namespace content { | 42 namespace content { |
40 | 43 |
41 namespace { | 44 namespace { |
42 | 45 |
43 // 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 |
44 // given HTTP body, returning true on success. | 47 // given HTTP body, returning true on success. |
45 bool AppendFileRefToBody( | 48 bool AppendFileRefToBody( |
46 Resource* file_ref_resource, | 49 PP_Instance instance, |
50 PP_Resource resource, | |
47 int64_t start_offset, | 51 int64_t start_offset, |
48 int64_t number_of_bytes, | 52 int64_t number_of_bytes, |
49 PP_Time expected_last_modified_time, | 53 PP_Time expected_last_modified_time, |
50 WebHTTPBody *http_body) { | 54 WebHTTPBody *http_body) { |
51 // Get the underlying file ref impl. | 55 base::FilePath platform_path; |
52 if (!file_ref_resource) | 56 ppapi::host::ResourceHost* resource_host = |
57 HostGlobals::Get()->GetInstance(instance)->module()-> | |
58 renderer_ppapi_host()->GetPpapiHost()->GetResourceHost(resource); | |
59 if (!resource_host->IsFileRefHost()) | |
53 return false; | 60 return false; |
54 PPB_FileRef_API* file_ref_api = file_ref_resource->AsPPB_FileRef_API(); | 61 PepperFileRefRendererHost* file_ref_host = |
55 if (!file_ref_api) | 62 static_cast<PepperFileRefRendererHost*>(resource_host); |
56 return false; | |
57 const PPB_FileRef_Impl* file_ref = | |
58 static_cast<PPB_FileRef_Impl*>(file_ref_api); | |
59 | 63 |
60 base::FilePath platform_path; | 64 fprintf(stderr, "AppendFileRefToBody, type: %d\n", |
61 switch (file_ref->GetFileSystemType()) { | 65 file_ref_host->GetFileSystemType()); |
dmichael (off chromium)
2013/09/04 17:23:54
^^^ Leftover debugging? Please remove.
| |
66 switch (file_ref_host->GetFileSystemType()) { | |
62 case PP_FILESYSTEMTYPE_LOCALTEMPORARY: | 67 case PP_FILESYSTEMTYPE_LOCALTEMPORARY: |
63 case PP_FILESYSTEMTYPE_LOCALPERSISTENT: | 68 case PP_FILESYSTEMTYPE_LOCALPERSISTENT: |
64 // TODO(kinuko): remove this sync IPC when we fully support | 69 // TODO(kinuko): remove this sync IPC when we fully support |
65 // AppendURLRange for FileSystem URL. | 70 // AppendURLRange for FileSystem URL. |
71 // FIXME | |
dmichael (off chromium)
2013/09/04 17:23:54
^^ Another FIXME
| |
66 RenderThreadImpl::current()->Send( | 72 RenderThreadImpl::current()->Send( |
67 new FileSystemHostMsg_SyncGetPlatformPath( | 73 new FileSystemHostMsg_SyncGetPlatformPath( |
68 file_ref->GetFileSystemURL(), &platform_path)); | 74 file_ref_host->GetFileSystemURL(), &platform_path)); |
69 break; | 75 break; |
70 case PP_FILESYSTEMTYPE_EXTERNAL: | 76 case PP_FILESYSTEMTYPE_EXTERNAL: |
71 platform_path = file_ref->GetSystemPath(); | 77 platform_path = file_ref_host->GetExternalFilePath(); |
72 break; | 78 break; |
73 default: | 79 default: |
74 NOTREACHED(); | 80 NOTREACHED(); |
75 } | 81 } |
76 http_body->appendFileRange( | 82 http_body->appendFileRange( |
77 platform_path.AsUTF16Unsafe(), | 83 platform_path.AsUTF16Unsafe(), |
78 start_offset, | 84 start_offset, |
79 number_of_bytes, | 85 number_of_bytes, |
80 expected_last_modified_time); | 86 expected_last_modified_time); |
81 return true; | 87 return true; |
82 } | 88 } |
83 | 89 |
84 // Checks that the request data is valid. Returns false on failure. Note that | 90 // 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 | 91 // method and header validation is done by the URL loader when the request is |
86 // opened, and any access errors are returned asynchronously. | 92 // opened, and any access errors are returned asynchronously. |
87 bool ValidateURLRequestData(const ppapi::URLRequestInfoData& data) { | 93 bool ValidateURLRequestData(const URLRequestInfoData& data) { |
88 if (data.prefetch_buffer_lower_threshold < 0 || | 94 if (data.prefetch_buffer_lower_threshold < 0 || |
89 data.prefetch_buffer_upper_threshold < 0 || | 95 data.prefetch_buffer_upper_threshold < 0 || |
90 data.prefetch_buffer_upper_threshold <= | 96 data.prefetch_buffer_upper_threshold <= |
91 data.prefetch_buffer_lower_threshold) { | 97 data.prefetch_buffer_lower_threshold) { |
92 return false; | 98 return false; |
93 } | 99 } |
94 return true; | 100 return true; |
95 } | 101 } |
96 | 102 |
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 | 103 } // namespace |
116 | 104 |
117 bool CreateWebURLRequest(ppapi::URLRequestInfoData* data, | 105 bool CreateWebURLRequest(PP_Instance instance, |
106 URLRequestInfoData* data, | |
118 WebFrame* frame, | 107 WebFrame* frame, |
119 WebURLRequest* dest) { | 108 WebURLRequest* dest) { |
120 // In the out-of-process case, we've received the URLRequestInfoData | 109 // 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 | 110 // 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. | 111 // sure it's not being malicious by checking everything for consistency. |
123 if (!ValidateURLRequestData(*data) || !EnsureFileRefObjectsPopulated(data)) | 112 if (!ValidateURLRequestData(*data)) |
124 return false; | 113 return false; |
125 | 114 |
126 dest->initialize(); | 115 dest->initialize(); |
127 dest->setTargetType(WebURLRequest::TargetIsObject); | 116 dest->setTargetType(WebURLRequest::TargetIsObject); |
128 dest->setURL(frame->document().completeURL(WebString::fromUTF8( | 117 dest->setURL(frame->document().completeURL(WebString::fromUTF8( |
129 data->url))); | 118 data->url))); |
130 dest->setDownloadToFile(data->stream_to_file); | 119 dest->setDownloadToFile(data->stream_to_file); |
131 dest->setReportUploadProgress(data->record_upload_progress); | 120 dest->setReportUploadProgress(data->record_upload_progress); |
132 | 121 |
133 if (!data->method.empty()) | 122 if (!data->method.empty()) |
134 dest->setHTTPMethod(WebString::fromUTF8(data->method)); | 123 dest->setHTTPMethod(WebString::fromUTF8(data->method)); |
135 | 124 |
136 dest->setFirstPartyForCookies(frame->document().firstPartyForCookies()); | 125 dest->setFirstPartyForCookies(frame->document().firstPartyForCookies()); |
137 | 126 |
138 const std::string& headers = data->headers; | 127 const std::string& headers = data->headers; |
139 if (!headers.empty()) { | 128 if (!headers.empty()) { |
140 net::HttpUtil::HeadersIterator it(headers.begin(), headers.end(), "\n\r"); | 129 net::HttpUtil::HeadersIterator it(headers.begin(), headers.end(), "\n\r"); |
141 while (it.GetNext()) { | 130 while (it.GetNext()) { |
142 dest->addHTTPHeaderField( | 131 dest->addHTTPHeaderField( |
143 WebString::fromUTF8(it.name()), | 132 WebString::fromUTF8(it.name()), |
144 WebString::fromUTF8(it.values())); | 133 WebString::fromUTF8(it.values())); |
145 } | 134 } |
146 } | 135 } |
147 | 136 |
148 // Append the upload data. | 137 // Append the upload data. |
149 if (!data->body.empty()) { | 138 if (!data->body.empty()) { |
150 WebHTTPBody http_body; | 139 WebHTTPBody http_body; |
151 http_body.initialize(); | 140 http_body.initialize(); |
141 int file_index = 0; | |
152 for (size_t i = 0; i < data->body.size(); ++i) { | 142 for (size_t i = 0; i < data->body.size(); ++i) { |
153 const URLRequestInfoData::BodyItem& item = data->body[i]; | 143 const URLRequestInfoData::BodyItem& item = data->body[i]; |
154 if (item.is_file) { | 144 if (item.is_file) { |
155 if (!AppendFileRefToBody(item.file_ref.get(), | 145 if (!AppendFileRefToBody(instance, |
146 item.file_ref_pp_resource, | |
156 item.start_offset, | 147 item.start_offset, |
157 item.number_of_bytes, | 148 item.number_of_bytes, |
158 item.expected_last_modified_time, | 149 item.expected_last_modified_time, |
159 &http_body)) | 150 &http_body)) |
160 return false; | 151 return false; |
152 file_index++; | |
161 } else { | 153 } else { |
162 DCHECK(!item.data.empty()); | 154 DCHECK(!item.data.empty()); |
163 http_body.appendData(WebData(item.data)); | 155 http_body.appendData(WebData(item.data)); |
164 } | 156 } |
165 } | 157 } |
166 dest->setHTTPBody(http_body); | 158 dest->setHTTPBody(http_body); |
167 } | 159 } |
168 | 160 |
169 // Add the "Referer" header if there is a custom referrer. Such requests | 161 // Add the "Referer" header if there is a custom referrer. Such requests |
170 // require universal access. For all other requests, "Referer" will be set | 162 // require universal access. For all other requests, "Referer" will be set |
(...skipping 12 matching lines...) Expand all Loading... | |
183 bool was_after_preconnect_request = false; | 175 bool was_after_preconnect_request = false; |
184 dest->setExtraData(new webkit_glue::WebURLRequestExtraDataImpl( | 176 dest->setExtraData(new webkit_glue::WebURLRequestExtraDataImpl( |
185 WebKit::WebReferrerPolicyDefault, // Ignored. | 177 WebKit::WebReferrerPolicyDefault, // Ignored. |
186 WebString::fromUTF8(data->custom_user_agent), | 178 WebString::fromUTF8(data->custom_user_agent), |
187 was_after_preconnect_request)); | 179 was_after_preconnect_request)); |
188 } | 180 } |
189 | 181 |
190 return true; | 182 return true; |
191 } | 183 } |
192 | 184 |
193 bool URLRequestRequiresUniversalAccess(const ppapi::URLRequestInfoData& data) { | 185 bool URLRequestRequiresUniversalAccess(const URLRequestInfoData& data) { |
194 return | 186 return |
195 data.has_custom_referrer_url || | 187 data.has_custom_referrer_url || |
196 data.has_custom_content_transfer_encoding || | 188 data.has_custom_content_transfer_encoding || |
197 data.has_custom_user_agent || | 189 data.has_custom_user_agent || |
198 url_util::FindAndCompareScheme(data.url, "javascript", NULL); | 190 url_util::FindAndCompareScheme(data.url, "javascript", NULL); |
199 } | 191 } |
200 | 192 |
201 } // namespace content | 193 } // namespace content |
OLD | NEW |