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 "webkit/plugins/ppapi/url_request_info_util.h" | 5 #include "webkit/plugins/ppapi/url_request_info_util.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "googleurl/src/gurl.h" | 9 #include "googleurl/src/gurl.h" |
10 #include "googleurl/src/url_util.h" | 10 #include "googleurl/src/url_util.h" |
11 #include "net/http/http_util.h" | 11 #include "net/http/http_util.h" |
12 #include "ppapi/shared_impl/url_request_info_data.h" | 12 #include "ppapi/shared_impl/url_request_info_data.h" |
13 #include "ppapi/shared_impl/var.h" | 13 #include "ppapi/shared_impl/var.h" |
14 #include "ppapi/thunk/enter.h" | 14 #include "ppapi/thunk/enter.h" |
15 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebData.h" | 15 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebData.h" |
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
18 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebHTTPBody.
h" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebHTTPBody.
h" |
19 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" |
20 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLReques
t.h" | 20 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLReques
t.h" |
21 #include "webkit/base/file_path_string_conversions.h" | 21 #include "webkit/base/file_path_string_conversions.h" |
22 #include "webkit/glue/weburlrequest_extradata_impl.h" | 22 #include "webkit/glue/weburlrequest_extradata_impl.h" |
23 #include "webkit/plugins/ppapi/common.h" | 23 #include "webkit/plugins/ppapi/common.h" |
| 24 #include "webkit/plugins/ppapi/host_globals.h" |
24 #include "webkit/plugins/ppapi/plugin_module.h" | 25 #include "webkit/plugins/ppapi/plugin_module.h" |
| 26 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
25 #include "webkit/plugins/ppapi/ppb_file_ref_impl.h" | 27 #include "webkit/plugins/ppapi/ppb_file_ref_impl.h" |
26 #include "webkit/plugins/ppapi/ppb_file_system_impl.h" | 28 #include "webkit/plugins/ppapi/ppb_file_system_impl.h" |
27 #include "webkit/plugins/ppapi/resource_helper.h" | 29 #include "webkit/plugins/ppapi/resource_helper.h" |
28 | 30 |
29 using ppapi::URLRequestInfoData; | 31 using ppapi::URLRequestInfoData; |
30 using ppapi::Resource; | 32 using ppapi::Resource; |
31 using ppapi::thunk::EnterResourceNoLock; | 33 using ppapi::thunk::EnterResourceNoLock; |
32 using ppapi::thunk::PPB_FileRef_API; | 34 using ppapi::thunk::PPB_FileRef_API; |
33 using WebKit::WebData; | 35 using WebKit::WebData; |
34 using WebKit::WebHTTPBody; | 36 using WebKit::WebHTTPBody; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 EnterResourceNoLock<PPB_FileRef_API> enter( | 113 EnterResourceNoLock<PPB_FileRef_API> enter( |
112 item.file_ref_host_resource.host_resource(), false); | 114 item.file_ref_host_resource.host_resource(), false); |
113 if (!enter.succeeded()) | 115 if (!enter.succeeded()) |
114 return false; | 116 return false; |
115 item.file_ref = enter.resource(); | 117 item.file_ref = enter.resource(); |
116 } | 118 } |
117 } | 119 } |
118 return true; | 120 return true; |
119 } | 121 } |
120 | 122 |
| 123 std::string FilterStringForXRequestedWithValue(const std::string& s) { |
| 124 std::string rv; |
| 125 rv.reserve(s.length()); |
| 126 for (size_t i = 0; i < s.length(); i++) { |
| 127 char c = s[i]; |
| 128 // Allow ASCII digits, letters, periods, commas, and underscores. (Ignore |
| 129 // all other characters.) |
| 130 if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || |
| 131 (c >= 'a' && c <= 'z') || (c == '.') || (c == ',') || (c == '_')) |
| 132 rv.push_back(c); |
| 133 } |
| 134 return rv; |
| 135 } |
| 136 |
| 137 // Makes an appropriate value for the X-Requested-With header. We produce a |
| 138 // user-agent-like string (eating spaces and other undesired characters) like |
| 139 // "ShockwaveFlash/11.5.31.135" from the plugin name and version. |
| 140 std::string MakeXRequestedWithValue(const std::string& name, |
| 141 const std::string& version) { |
| 142 std::string rv = FilterStringForXRequestedWithValue(name); |
| 143 if (rv.empty()) |
| 144 rv = "unknown_plugin"; |
| 145 |
| 146 std::string filtered_version = FilterStringForXRequestedWithValue(version); |
| 147 if (!filtered_version.empty()) |
| 148 rv += "/" + filtered_version; |
| 149 |
| 150 return rv; |
| 151 } |
| 152 |
121 } // namespace | 153 } // namespace |
122 | 154 |
123 bool CreateWebURLRequest(::ppapi::URLRequestInfoData* data, | 155 bool CreateWebURLRequest(PP_Instance pp_instance, |
| 156 ::ppapi::URLRequestInfoData* data, |
124 WebFrame* frame, | 157 WebFrame* frame, |
125 WebURLRequest* dest) { | 158 WebURLRequest* dest) { |
| 159 std::string name_version; |
| 160 |
| 161 // Allow null instances for testing purposes. |
| 162 if (pp_instance) { |
| 163 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); |
| 164 if (!instance) |
| 165 return false; |
| 166 |
| 167 name_version = MakeXRequestedWithValue(instance->module()->name(), |
| 168 instance->module()->version()); |
| 169 } else { |
| 170 name_version = "internal_testing_only"; |
| 171 } |
| 172 |
126 // In the out-of-process case, we've received the URLRequestInfoData | 173 // In the out-of-process case, we've received the URLRequestInfoData |
127 // from the untrusted plugin and done no validation on it. We need to be | 174 // from the untrusted plugin and done no validation on it. We need to be |
128 // sure it's not being malicious by checking everything for consistency. | 175 // sure it's not being malicious by checking everything for consistency. |
129 if (!ValidateURLRequestData(*data) || !EnsureFileRefObjectsPopulated(data)) | 176 if (!ValidateURLRequestData(*data) || !EnsureFileRefObjectsPopulated(data)) |
130 return false; | 177 return false; |
131 | 178 |
132 dest->initialize(); | 179 dest->initialize(); |
133 dest->setTargetType(WebURLRequest::TargetIsObject); | 180 dest->setTargetType(WebURLRequest::TargetIsObject); |
134 dest->setURL(frame->document().completeURL(WebString::fromUTF8( | 181 dest->setURL(frame->document().completeURL(WebString::fromUTF8( |
135 data->url))); | 182 data->url))); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 if (data->has_custom_referrer_url && !data->custom_referrer_url.empty()) | 225 if (data->has_custom_referrer_url && !data->custom_referrer_url.empty()) |
179 frame->setReferrerForRequest(*dest, GURL(data->custom_referrer_url)); | 226 frame->setReferrerForRequest(*dest, GURL(data->custom_referrer_url)); |
180 | 227 |
181 if (data->has_custom_content_transfer_encoding && | 228 if (data->has_custom_content_transfer_encoding && |
182 !data->custom_content_transfer_encoding.empty()) { | 229 !data->custom_content_transfer_encoding.empty()) { |
183 dest->addHTTPHeaderField( | 230 dest->addHTTPHeaderField( |
184 WebString::fromUTF8("Content-Transfer-Encoding"), | 231 WebString::fromUTF8("Content-Transfer-Encoding"), |
185 WebString::fromUTF8(data->custom_content_transfer_encoding)); | 232 WebString::fromUTF8(data->custom_content_transfer_encoding)); |
186 } | 233 } |
187 | 234 |
188 if (data->has_custom_user_agent) { | 235 dest->setExtraData(new webkit_glue::WebURLRequestExtraDataImpl( |
189 dest->setExtraData(new webkit_glue::WebURLRequestExtraDataImpl( | 236 WebKit::WebReferrerPolicyDefault, // Ignored. |
190 WebKit::WebReferrerPolicyDefault, // Ignored. | 237 data->has_custom_user_agent ? |
191 WebString::fromUTF8(data->custom_user_agent))); | 238 WebString::fromUTF8(data->custom_user_agent) : WebString(), |
192 } | 239 WebString::fromUTF8(name_version))); |
193 | 240 |
194 return true; | 241 return true; |
195 } | 242 } |
196 | 243 |
197 bool URLRequestRequiresUniversalAccess( | 244 bool URLRequestRequiresUniversalAccess( |
198 const ::ppapi::URLRequestInfoData& data) { | 245 const ::ppapi::URLRequestInfoData& data) { |
199 return | 246 return |
200 data.has_custom_referrer_url || | 247 data.has_custom_referrer_url || |
201 data.has_custom_content_transfer_encoding || | 248 data.has_custom_content_transfer_encoding || |
202 data.has_custom_user_agent || | 249 data.has_custom_user_agent || |
203 url_util::FindAndCompareScheme(data.url, "javascript", NULL); | 250 url_util::FindAndCompareScheme(data.url, "javascript", NULL); |
204 } | 251 } |
205 | 252 |
206 } // namespace ppapi | 253 } // namespace ppapi |
207 } // namespace webkit | 254 } // namespace webkit |
OLD | NEW |