Index: chrome/browser/extensions/api/web_request/web_request_api.cc |
diff --git a/chrome/browser/extensions/api/web_request/web_request_api.cc b/chrome/browser/extensions/api/web_request/web_request_api.cc |
index 10f1d581887ab328fd3bc0dbb4124f670d89b67c..b3294d20f1e087e1300f21a1d14b60e3a1b4a2a4 100644 |
--- a/chrome/browser/extensions/api/web_request/web_request_api.cc |
+++ b/chrome/browser/extensions/api/web_request/web_request_api.cc |
@@ -19,6 +19,7 @@ |
#include "chrome/browser/extensions/api/declarative_webrequest/webrequest_rule.h" |
#include "chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_registry.h" |
#include "chrome/browser/extensions/api/web_navigation/web_navigation_api_helpers.h" |
+#include "chrome/browser/extensions/api/web_request/post_data_parser.h" |
#include "chrome/browser/extensions/api/web_request/web_request_api_constants.h" |
#include "chrome/browser/extensions/api/web_request/web_request_api_helpers.h" |
#include "chrome/browser/extensions/api/web_request/web_request_time_tracker.h" |
@@ -157,6 +158,33 @@ void ExtractRequestInfo(net::URLRequest* request, DictionaryValue* out) { |
out->SetDouble(keys::kTimeStampKey, base::Time::Now().ToDoubleT() * 1000); |
} |
+// Extracts the POST data from |request| and writes the data into |out|. |
+// This can be expensive, so it's separated from ExtractRequestInfo(). |
+void ExtractRequestInfoPost(const net::URLRequest* request, |
+ DictionaryValue* out) { |
+ if (request->method() != "POST") |
+ return; // Need to exit without "out->Set(keys::kPostDataKey, ...);" . |
+ |
+ DictionaryValue* post_data = new DictionaryValue(); |
+ out->Set(keys::kPostDataKey, post_data); |
+ |
+ // Chunked encoding (defined in RFC 2616) is currently not supported. |
+ std::string transfer_encoding; |
+ if (request->extra_request_headers().GetHeader( |
+ net::HttpRequestHeaders::kTransferEncoding, &transfer_encoding)) { |
+ if (base::strcasecmp(transfer_encoding.c_str(), "chunked") == 0) { |
+ StringValue* error = new StringValue("chunked_encoding"); |
+ post_data->Set(keys::kPostDataErrorKey, error); |
battre
2012/07/30 17:54:25
nit: post_data->SetString(keys::kPostDataErrorKey,
vabr (Chromium)
2012/07/31 09:03:18
Done.
|
+ return; |
+ } |
+ } |
+ |
+ scoped_ptr<DictionaryValue> form_data = |
+ extensions::PostDataParser::ParseURLRequestData(request); |
+ if (form_data.get() != NULL) |
+ post_data->Set(keys::kFormDataKey, form_data.release()); |
+} |
+ |
// Converts a HttpHeaders dictionary to a |name|, |value| pair. Returns |
// true if successful. |
bool FromHeaderDictionary(const DictionaryValue* header_value, |
@@ -409,6 +437,8 @@ bool ExtensionWebRequestEventRouter::ExtraInfoSpec::InitFromValue( |
*extra_info_spec |= BLOCKING; |
else if (str == "asyncBlocking") |
*extra_info_spec |= ASYNC_BLOCKING; |
+ else if (str == "postData") |
battre
2012/07/30 17:54:25
I think at this place we need to check whether we
Matt Perry
2012/07/31 09:14:12
Good catch. I was thinking we could do it through
|
+ *extra_info_spec |= POST_DATA; |
else |
return false; |
@@ -494,6 +524,8 @@ int ExtensionWebRequestEventRouter::OnBeforeRequest( |
ListValue args; |
DictionaryValue* dict = new DictionaryValue(); |
ExtractRequestInfo(request, dict); |
+ if (extra_info_spec & ExtraInfoSpec::POST_DATA) |
+ ExtractRequestInfoPost(request, dict); |
args.Append(dict); |
initialize_blocked_requests |= |