Chromium Code Reviews| Index: content/renderer/pepper/url_request_info_util.cc |
| diff --git a/content/renderer/pepper/url_request_info_util.cc b/content/renderer/pepper/url_request_info_util.cc |
| index 0a58bba1f363de27b49bc0870f6c33eed9dea5c5..fca20237b40c63b241dcc10c77ddc10578ba1adb 100644 |
| --- a/content/renderer/pepper/url_request_info_util.cc |
| +++ b/content/renderer/pepper/url_request_info_util.cc |
| @@ -103,6 +103,42 @@ bool ValidateURLRequestData(const URLRequestInfoData& data) { |
| return true; |
| } |
| +std::string FilterStringForXRequestedWithValue(const std::string& s) { |
| + std::string rv; |
| + rv.reserve(s.length()); |
| + for (size_t i = 0; i < s.length(); i++) { |
| + char c = s[i]; |
| + // Allow ASCII digits, letters, periods, commas, and underscores. (Ignore |
| + // all other characters.) |
| + if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || |
| + (c >= 'a' && c <= 'z') || (c == '.') || (c == ',') || (c == '_')) |
| + rv.push_back(c); |
| + } |
| + return rv; |
| +} |
| + |
| +// Returns an appropriate value for the X-Requested-With header for plugins that |
| +// present an X-Requested-With header. Returns a blank string for other plugins. |
| +// We produce a user-agent-like string (eating spaces and other undesired |
| +// characters) like "ShockwaveFlash/11.5.31.135" from the plugin name and |
| +// version. |
| +std::string MakeXRequestedWithValue(const std::string& name, |
| + const std::string& version) { |
| + std::string rv = FilterStringForXRequestedWithValue(name); |
| + if (rv.empty()) |
| + return ""; |
|
brettw
2014/08/18 21:22:48
When returning an empty string, can you do
retur
Tom Sepez
2014/08/18 22:15:23
Done.
|
| + |
| + // Apply to a narrow list of plugins only. |
| + if (rv != "ShockwaveFlash" && rv != "PPAPITests") |
| + return ""; |
| + |
| + std::string filtered_version = FilterStringForXRequestedWithValue(version); |
| + if (!filtered_version.empty()) |
| + rv += "/" + filtered_version; |
| + |
| + return rv; |
| +} |
| + |
| } // namespace |
| bool CreateWebURLRequest(PP_Instance instance, |
| @@ -115,6 +151,21 @@ bool CreateWebURLRequest(PP_Instance instance, |
| if (!ValidateURLRequestData(*data)) |
| return false; |
| + std::string name_version; |
| + |
| + // Allow null instances for testing purposes. |
| + if (instance) { |
| + PepperPluginInstanceImpl* instance_impl = |
| + HostGlobals::Get()->GetInstance(instance); |
| + if (instance_impl) { |
| + name_version = MakeXRequestedWithValue( |
| + instance_impl->module()->name(), |
| + instance_impl->module()->version()); |
| + } |
| + } else { |
| + name_version = "internal_testing_only"; |
| + } |
| + |
| dest->initialize(); |
| dest->setURL(frame->document().completeURL(WebString::fromUTF8(data->url))); |
| dest->setDownloadToFile(data->stream_to_file); |
| @@ -171,10 +222,16 @@ bool CreateWebURLRequest(PP_Instance instance, |
| WebString::fromUTF8(data->custom_content_transfer_encoding)); |
| } |
| - if (data->has_custom_user_agent) { |
| + if (data->has_custom_user_agent || !name_version.empty()) { |
| RequestExtraData* extra_data = new RequestExtraData(); |
| - extra_data->set_custom_user_agent( |
| - WebString::fromUTF8(data->custom_user_agent)); |
| + if (data->has_custom_user_agent) { |
| + extra_data->set_custom_user_agent( |
| + WebString::fromUTF8(data->custom_user_agent)); |
| + } |
| + if (!name_version.empty()) { |
| + extra_data->set_x_requested_with( |
| + WebString::fromUTF8(name_version)); |
| + } |
| dest->setExtraData(extra_data); |
| } |