| 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 7c2f278321dc8eb4887b0322a8fb6847a315f6e0..83a53aae260e41c678ae50cd390f64a1059ece82 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"
|
| @@ -31,6 +32,7 @@
|
| #include "chrome/browser/profiles/profile_manager.h"
|
| #include "chrome/browser/renderer_host/chrome_render_message_filter.h"
|
| #include "chrome/browser/renderer_host/web_cache_manager.h"
|
| +#include "chrome/common/chrome_version_info.h"
|
| #include "chrome/common/extensions/event_filtering_info.h"
|
| #include "chrome/common/extensions/extension.h"
|
| #include "chrome/common/extensions/extension_constants.h"
|
| @@ -157,6 +159,32 @@ 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) {
|
| + post_data->SetString(keys::kPostDataErrorKey, "chunked_encoding");
|
| + 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")
|
| + *extra_info_spec |= (IsPostDataEnabled()) ? POST_DATA : 0;
|
| else
|
| return false;
|
|
|
| @@ -498,6 +528,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 |=
|
| @@ -1827,3 +1859,16 @@ void SendExtensionWebRequestStatusToHost(content::RenderProcessHost* host) {
|
|
|
| host->Send(new ExtensionMsg_UsingWebRequestAPI(adblock, adblock_plus, other));
|
| }
|
| +
|
| +bool IsPostDataEnabled() {
|
| + static bool cached = false;
|
| + static bool enabled = false;
|
| + if (!cached) {
|
| + chrome::VersionInfo::Channel channel = chrome::VersionInfo::CHANNEL_UNKNOWN;
|
| + enabled = channel == chrome::VersionInfo::CHANNEL_UNKNOWN ||
|
| + channel == chrome::VersionInfo::CHANNEL_CANARY ||
|
| + channel == chrome::VersionInfo::CHANNEL_DEV;
|
| + cached = true;
|
| + }
|
| + return enabled;
|
| +}
|
|
|