diff options
27 files changed, 234 insertions, 132 deletions
diff --git a/chrome/common/extensions/extension_localization_peer.cc b/chrome/common/extensions/extension_localization_peer.cc index 8323d9f..4bfb0d6 100644 --- a/chrome/common/extensions/extension_localization_peer.cc +++ b/chrome/common/extensions/extension_localization_peer.cc @@ -59,8 +59,10 @@ void ExtensionLocalizationPeer::OnReceivedResponse( response_info_ = info; } -void ExtensionLocalizationPeer::OnReceivedData(const char* data, int len) { - data_.append(data, len); +void ExtensionLocalizationPeer::OnReceivedData(const char* data, + int data_length, + int raw_data_length) { + data_.append(data, data_length); } void ExtensionLocalizationPeer::OnCompletedRequest( @@ -85,7 +87,8 @@ void ExtensionLocalizationPeer::OnCompletedRequest( original_peer_->OnReceivedResponse(response_info_); if (!data_.empty()) original_peer_->OnReceivedData(data_.data(), - static_cast<int>(data_.size())); + static_cast<int>(data_.size()), + -1); original_peer_->OnCompletedRequest(status, security_info, completion_time); } diff --git a/chrome/common/extensions/extension_localization_peer.h b/chrome/common/extensions/extension_localization_peer.h index f370e3a..ad168fd 100644 --- a/chrome/common/extensions/extension_localization_peer.h +++ b/chrome/common/extensions/extension_localization_peer.h @@ -39,7 +39,9 @@ class ExtensionLocalizationPeer virtual void OnReceivedResponse( const webkit_glue::ResourceResponseInfo& info); virtual void OnDownloadedData(int len) {} - virtual void OnReceivedData(const char* data, int len); + virtual void OnReceivedData(const char* data, + int data_length, + int raw_data_length); virtual void OnCompletedRequest(const net::URLRequestStatus& status, const std::string& security_info, const base::Time& completion_time); diff --git a/chrome/common/extensions/extension_localization_peer_unittest.cc b/chrome/common/extensions/extension_localization_peer_unittest.cc index 2b1b69d..15aec31 100644 --- a/chrome/common/extensions/extension_localization_peer_unittest.cc +++ b/chrome/common/extensions/extension_localization_peer_unittest.cc @@ -66,7 +66,8 @@ class MockResourceLoaderBridgePeer MOCK_METHOD1(OnReceivedResponse, void( const webkit_glue::ResourceResponseInfo& info)); MOCK_METHOD1(OnDownloadedData, void(int len)); - MOCK_METHOD2(OnReceivedData, void(const char* data, int len)); + MOCK_METHOD3(OnReceivedData, + void(const char* data, int data_length, int raw_data_length)); MOCK_METHOD3(OnCompletedRequest, void( const net::URLRequestStatus& status, const std::string& security_info, @@ -124,11 +125,11 @@ TEST_F(ExtensionLocalizationPeerTest, OnReceivedData) { EXPECT_TRUE(GetData(filter_peer_.get()).empty()); const std::string data_chunk("12345"); - filter_peer_->OnReceivedData(data_chunk.c_str(), data_chunk.length()); + filter_peer_->OnReceivedData(data_chunk.c_str(), data_chunk.length(), -1); EXPECT_EQ(data_chunk, GetData(filter_peer_.get())); - filter_peer_->OnReceivedData(data_chunk.c_str(), data_chunk.length()); + filter_peer_->OnReceivedData(data_chunk.c_str(), data_chunk.length(), -1); EXPECT_EQ(data_chunk + data_chunk, GetData(filter_peer_.get())); } @@ -151,7 +152,7 @@ TEST_F(ExtensionLocalizationPeerTest, OnCompletedRequestEmptyData) { // It will self-delete once it exits OnCompletedRequest. ExtensionLocalizationPeer* filter_peer = filter_peer_.release(); - EXPECT_CALL(*original_peer_, OnReceivedData(_, _)).Times(0); + EXPECT_CALL(*original_peer_, OnReceivedData(_, _, _)).Times(0); EXPECT_CALL(*sender_, Send(_)).Times(0); EXPECT_CALL(*original_peer_, OnReceivedResponse(_)); @@ -173,7 +174,7 @@ TEST_F(ExtensionLocalizationPeerTest, OnCompletedRequestNoCatalogs) { std::string data = GetData(filter_peer); EXPECT_CALL(*original_peer_, - OnReceivedData(StrEq(data.data()), data.length())).Times(2); + OnReceivedData(StrEq(data.data()), data.length(), -1)).Times(2); EXPECT_CALL(*original_peer_, OnReceivedResponse(_)).Times(2); EXPECT_CALL(*original_peer_, OnCompletedRequest( @@ -211,7 +212,7 @@ TEST_F(ExtensionLocalizationPeerTest, OnCompletedRequestWithCatalogs) { // __MSG_text__ gets replaced with "new text". std::string data("some new text"); EXPECT_CALL(*original_peer_, - OnReceivedData(StrEq(data.data()), data.length())); + OnReceivedData(StrEq(data.data()), data.length(), -1)); EXPECT_CALL(*original_peer_, OnReceivedResponse(_)); EXPECT_CALL(*original_peer_, OnCompletedRequest( @@ -241,7 +242,7 @@ TEST_F(ExtensionLocalizationPeerTest, OnCompletedRequestReplaceMessagesFails) { // __MSG_missing_message__ is missing, so message stays the same. EXPECT_CALL(*original_peer_, - OnReceivedData(StrEq(message.data()), message.length())); + OnReceivedData(StrEq(message.data()), message.length(), -1)); EXPECT_CALL(*original_peer_, OnReceivedResponse(_)); EXPECT_CALL(*original_peer_, OnCompletedRequest( diff --git a/chrome/renderer/safe_browsing/render_view_fake_resources_test.cc b/chrome/renderer/safe_browsing/render_view_fake_resources_test.cc index 097f2e4..2abaa59 100644 --- a/chrome/renderer/safe_browsing/render_view_fake_resources_test.cc +++ b/chrome/renderer/safe_browsing/render_view_fake_resources_test.cc @@ -166,7 +166,11 @@ void RenderViewFakeResourcesTest::OnRequestResource( ASSERT_TRUE(shared_memory.GiveToProcess(base::Process::Current().handle(), &handle)); ASSERT_TRUE(channel_->Send(new ResourceMsg_DataReceived( - message.routing_id(), request_id, handle, body.size()))); + message.routing_id(), + request_id, + handle, + body.size(), + body.size()))); ASSERT_TRUE(channel_->Send(new ResourceMsg_RequestComplete( message.routing_id(), diff --git a/chrome/renderer/security_filter_peer.cc b/chrome/renderer/security_filter_peer.cc index d1d6a5a..fd857a1 100644 --- a/chrome/renderer/security_filter_peer.cc +++ b/chrome/renderer/security_filter_peer.cc @@ -79,7 +79,9 @@ void SecurityFilterPeer::OnReceivedResponse( NOTREACHED(); } -void SecurityFilterPeer::OnReceivedData(const char* data, int len) { +void SecurityFilterPeer::OnReceivedData(const char* data, + int data_length, + int raw_data_length) { NOTREACHED(); } @@ -137,8 +139,10 @@ void BufferedPeer::OnReceivedResponse( ProcessResponseInfo(info, &response_info_, mime_type_); } -void BufferedPeer::OnReceivedData(const char* data, int len) { - data_.append(data, len); +void BufferedPeer::OnReceivedData(const char* data, + int data_length, + int raw_data_length) { + data_.append(data, data_length); } void BufferedPeer::OnCompletedRequest(const net::URLRequestStatus& status, @@ -160,7 +164,8 @@ void BufferedPeer::OnCompletedRequest(const net::URLRequestStatus& status, original_peer_->OnReceivedResponse(response_info_); if (!data_.empty()) original_peer_->OnReceivedData(data_.data(), - static_cast<int>(data_.size())); + static_cast<int>(data_.size()), + -1); original_peer_->OnCompletedRequest(status, security_info, completion_time); } @@ -185,7 +190,9 @@ void ReplaceContentPeer::OnReceivedResponse( // Ignore this, we'll serve some alternate content in OnCompletedRequest. } -void ReplaceContentPeer::OnReceivedData(const char* data, int len) { +void ReplaceContentPeer::OnReceivedData(const char* data, + int data_length, + int raw_data_length) { // Ignore this, we'll serve some alternate content in OnCompletedRequest. } @@ -200,7 +207,8 @@ void ReplaceContentPeer::OnCompletedRequest( original_peer_->OnReceivedResponse(info); if (!data_.empty()) original_peer_->OnReceivedData(data_.data(), - static_cast<int>(data_.size())); + static_cast<int>(data_.size()), + -1); original_peer_->OnCompletedRequest(net::URLRequestStatus(), security_info, completion_time); diff --git a/chrome/renderer/security_filter_peer.h b/chrome/renderer/security_filter_peer.h index 464a593..e1764b7 100644 --- a/chrome/renderer/security_filter_peer.h +++ b/chrome/renderer/security_filter_peer.h @@ -38,7 +38,9 @@ class SecurityFilterPeer : public webkit_glue::ResourceLoaderBridge::Peer { virtual void OnReceivedResponse( const webkit_glue::ResourceResponseInfo& info); virtual void OnDownloadedData(int len) {} - virtual void OnReceivedData(const char* data, int len); + virtual void OnReceivedData(const char* data, + int data_length, + int raw_data_length); virtual void OnCompletedRequest(const net::URLRequestStatus& status, const std::string& security_info, const base::Time& completion_time); @@ -66,7 +68,9 @@ class BufferedPeer : public SecurityFilterPeer { // ResourceLoaderBridge::Peer Implementation. virtual void OnReceivedResponse( const webkit_glue::ResourceResponseInfo& info); - virtual void OnReceivedData(const char* data, int len); + virtual void OnReceivedData(const char* data, + int data_length, + int raw_data_length); virtual void OnCompletedRequest(const net::URLRequestStatus& status, const std::string& security_info, const base::Time& completion_time); @@ -106,7 +110,9 @@ class ReplaceContentPeer : public SecurityFilterPeer { // ResourceLoaderBridge::Peer Implementation. virtual void OnReceivedResponse( const webkit_glue::ResourceResponseInfo& info); - virtual void OnReceivedData(const char* data, int len); + virtual void OnReceivedData(const char* data, + int data_length, + int raw_data_length); virtual void OnCompletedRequest(const net::URLRequestStatus& status, const std::string& security_info, const base::Time& completion_time); diff --git a/content/browser/renderer_host/async_resource_handler.cc b/content/browser/renderer_host/async_resource_handler.cc index 4e80081..d8ac365 100644 --- a/content/browser/renderer_host/async_resource_handler.cc +++ b/content/browser/renderer_host/async_resource_handler.cc @@ -216,8 +216,12 @@ bool AsyncResourceHandler::OnReadCompleted(int request_id, int* bytes_read) { // We just unmapped the memory. read_buffer_ = NULL; + net::URLRequest* request = rdh_->GetURLRequest( + GlobalRequestID(filter_->child_id(), request_id)); + int raw_data_length = + DevToolsNetLogObserver::GetAndResetRawDataLength(request); filter_->Send(new ResourceMsg_DataReceived( - routing_id_, request_id, handle, *bytes_read)); + routing_id_, request_id, handle, *bytes_read, raw_data_length)); return true; } diff --git a/content/browser/renderer_host/sync_resource_handler.cc b/content/browser/renderer_host/sync_resource_handler.cc index 7b19a08..b474cf6 100644 --- a/content/browser/renderer_host/sync_resource_handler.cc +++ b/content/browser/renderer_host/sync_resource_handler.cc @@ -103,6 +103,11 @@ bool SyncResourceHandler::OnResponseCompleted( const std::string& security_info) { result_.status = status; + net::URLRequest* request = rdh_->GetURLRequest( + GlobalRequestID(filter_->child_id(), request_id)); + result_.raw_data_length = + DevToolsNetLogObserver::GetAndResetRawDataLength(request); + ResourceHostMsg_SyncLoad::WriteReplyParams(result_message_, result_); filter_->Send(result_message_); result_message_ = NULL; diff --git a/content/common/resource_dispatcher.cc b/content/common/resource_dispatcher.cc index 7542551..9ed50bd 100644 --- a/content/common/resource_dispatcher.cc +++ b/content/common/resource_dispatcher.cc @@ -212,6 +212,7 @@ void IPCResourceLoaderBridge::SyncLoad(SyncLoadResponse* response) { response->charset = result.charset; response->request_time = result.request_time; response->response_time = result.response_time; + response->raw_data_length = result.raw_data_length; response->connection_id = result.connection_id; response->connection_reused = result.connection_reused; response->load_timing = result.load_timing; @@ -336,7 +337,8 @@ void ResourceDispatcher::OnReceivedCachedMetadata( void ResourceDispatcher::OnReceivedData(const IPC::Message& message, int request_id, base::SharedMemoryHandle shm_handle, - int data_len) { + int data_len, + int raw_data_length) { // Acknowledge the reception of this data. message_sender()->Send( new ResourceHostMsg_DataReceived_ACK(message.routing_id(), request_id)); @@ -351,7 +353,7 @@ void ResourceDispatcher::OnReceivedData(const IPC::Message& message, if (data_len > 0 && shared_mem.Map(data_len)) { const char* data = static_cast<char*>(shared_mem.memory()); - request_info->peer->OnReceivedData(data, data_len); + request_info->peer->OnReceivedData(data, data_len, raw_data_length); } } diff --git a/content/common/resource_dispatcher.h b/content/common/resource_dispatcher.h index 83fa4511..efe4514 100644 --- a/content/common/resource_dispatcher.h +++ b/content/common/resource_dispatcher.h @@ -126,7 +126,8 @@ class ResourceDispatcher : public IPC::Channel::Listener { const IPC::Message& message, int request_id, base::SharedMemoryHandle data, - int data_len); + int data_len, + int raw_data_length); void OnDownloadedData( const IPC::Message& message, int request_id, diff --git a/content/common/resource_dispatcher_unittest.cc b/content/common/resource_dispatcher_unittest.cc index c92ab5e..0236262 100644 --- a/content/common/resource_dispatcher_unittest.cc +++ b/content/common/resource_dispatcher_unittest.cc @@ -56,9 +56,12 @@ class TestRequestCallback : public ResourceLoaderBridge::Peer { virtual void OnDownloadedData(int len) { } - virtual void OnReceivedData(const char* data, int len) { + virtual void OnReceivedData(const char* data, + int data_length, + int raw_data_length) { EXPECT_FALSE(complete_); - data_.append(data, len); + data_.append(data, data_length); + total_raw_data_length_ += raw_data_length; } virtual void OnCompletedRequest(const net::URLRequestStatus& status, @@ -68,16 +71,20 @@ class TestRequestCallback : public ResourceLoaderBridge::Peer { complete_ = true; } + bool complete() const { + return complete_; + } const std::string& data() const { return data_; } - bool complete() const { - return complete_; + int total_raw_data_length() const { + return total_raw_data_length_; } private: bool complete_; std::string data_; + int total_raw_data_length_; }; @@ -123,7 +130,11 @@ class ResourceDispatcherTest : public testing::Test, EXPECT_TRUE(shared_mem.GiveToProcess( base::Process::Current().handle(), &dup_handle)); dispatcher_->OnReceivedData( - message_queue_[0], request_id, dup_handle, test_page_contents_len); + message_queue_[0], + request_id, + dup_handle, + test_page_contents_len, + test_page_contents_len); message_queue_.erase(message_queue_.begin()); @@ -183,6 +194,7 @@ TEST_F(ResourceDispatcherTest, RoundTrip) { // and dispatched, uncomment this. //EXPECT_TRUE(callback.complete()); //EXPECT_STREQ(test_page_contents, callback.data().c_str()); + //EXPECT_EQ(test_page_contents_len, callback.total_raw_data_length()); delete bridge; } @@ -242,7 +254,7 @@ class DeferredResourceLoadingTest : public ResourceDispatcherTest, &duplicated_handle)); response_message = - new ResourceMsg_DataReceived(0, 0, duplicated_handle, 100); + new ResourceMsg_DataReceived(0, 0, duplicated_handle, 100, 100); dispatcher_->OnMessageReceived(*response_message); @@ -272,7 +284,9 @@ class DeferredResourceLoadingTest : public ResourceDispatcherTest, virtual void OnDownloadedData(int len) { } - virtual void OnReceivedData(const char* data, int len) { + virtual void OnReceivedData(const char* data, + int data_length, + int raw_data_length) { EXPECT_EQ(defer_loading_, false); set_defer_loading(false); } diff --git a/content/common/resource_messages.h b/content/common/resource_messages.h index cb40e1f..5e6874a 100644 --- a/content/common/resource_messages.h +++ b/content/common/resource_messages.h @@ -20,6 +20,7 @@ IPC_STRUCT_TRAITS_BEGIN(webkit_glue::ResourceResponseInfo) IPC_STRUCT_TRAITS_MEMBER(charset) IPC_STRUCT_TRAITS_MEMBER(security_info) IPC_STRUCT_TRAITS_MEMBER(content_length) + IPC_STRUCT_TRAITS_MEMBER(raw_data_length) IPC_STRUCT_TRAITS_MEMBER(appcache_id) IPC_STRUCT_TRAITS_MEMBER(appcache_manifest_url) IPC_STRUCT_TRAITS_MEMBER(connection_id) @@ -121,10 +122,11 @@ IPC_MESSAGE_ROUTED3(ResourceMsg_ReceivedRedirect, // Sent when some data from a resource request is ready. The handle should // already be mapped into the process that receives this message. -IPC_MESSAGE_ROUTED3(ResourceMsg_DataReceived, +IPC_MESSAGE_ROUTED4(ResourceMsg_DataReceived, int /* request_id */, base::SharedMemoryHandle /* data */, - int /* data_len */) + int /* data_len */, + int /* raw_data_length */) // Sent when some data from a resource request has been downloaded to // file. This is only called in the 'download_to_file' case and replaces diff --git a/webkit/glue/media/buffered_resource_loader.cc b/webkit/glue/media/buffered_resource_loader.cc index 8cca6f8..4eefe16 100644 --- a/webkit/glue/media/buffered_resource_loader.cc +++ b/webkit/glue/media/buffered_resource_loader.cc @@ -322,7 +322,7 @@ void BufferedResourceLoader::didReceiveData( WebURLLoader* loader, const char* data, int data_length, - int length_received) { + int raw_data_length) { DCHECK(!completed_); DCHECK_GT(data_length, 0); diff --git a/webkit/glue/media/buffered_resource_loader.h b/webkit/glue/media/buffered_resource_loader.h index 06b0590..52513e8 100644 --- a/webkit/glue/media/buffered_resource_loader.h +++ b/webkit/glue/media/buffered_resource_loader.h @@ -135,7 +135,7 @@ class BufferedResourceLoader : WebKit::WebURLLoader* loader, const char* data, int data_length, - int length_received); + int raw_data_length); virtual void didReceiveCachedMetadata( WebKit::WebURLLoader* loader, const char* data, int dataLength); diff --git a/webkit/glue/multipart_response_delegate.cc b/webkit/glue/multipart_response_delegate.cc index 53cdc3f..f45ec0f 100644 --- a/webkit/glue/multipart_response_delegate.cc +++ b/webkit/glue/multipart_response_delegate.cc @@ -62,6 +62,7 @@ MultipartResponseDelegate::MultipartResponseDelegate( : client_(client), loader_(loader), original_response_(response), + raw_data_length_(0), boundary_("--"), first_received_data_(true), processing_headers_(false), @@ -76,7 +77,8 @@ MultipartResponseDelegate::MultipartResponseDelegate( } void MultipartResponseDelegate::OnReceivedData(const char* data, - int data_len) { + int data_len, + int raw_data_length) { // stop_sending_ means that we've already received the final boundary token. // The server should stop sending us data at this point, but if it does, we // just throw it away. @@ -84,6 +86,7 @@ void MultipartResponseDelegate::OnReceivedData(const char* data, return; data_.append(data, data_len); + raw_data_length_ += raw_data_length; if (first_received_data_) { // Some servers don't send a boundary token before the first chunk of // data. We handle this case anyway (Gecko does too). @@ -141,7 +144,8 @@ void MultipartResponseDelegate::OnReceivedData(const char* data, client_->didReceiveData(loader_, data_.data(), static_cast<int>(data_length), - -1); + raw_data_length_); + raw_data_length_ = 0; } } size_t boundary_end_pos = boundary_pos + boundary_.length(); @@ -172,8 +176,12 @@ void MultipartResponseDelegate::OnReceivedData(const char* data, if (data_[data_.length() - 1] == '\n') send_length = data_.length(); if (client_) - client_->didReceiveData(loader_, data_.data(), send_length, -1); + client_->didReceiveData(loader_, + data_.data(), + send_length, + raw_data_length_); data_ = data_.substr(send_length); + raw_data_length_ = 0; } } @@ -183,7 +191,9 @@ void MultipartResponseDelegate::OnCompletedRequest() { if (!processing_headers_ && !data_.empty() && !stop_sending_ && client_) { client_->didReceiveData(loader_, data_.data(), - static_cast<int>(data_.length()), -1); + static_cast<int>(data_.length()), + raw_data_length_); + raw_data_length_ = 0; } } diff --git a/webkit/glue/multipart_response_delegate.h b/webkit/glue/multipart_response_delegate.h index d4583bb..7c82958 100644 --- a/webkit/glue/multipart_response_delegate.h +++ b/webkit/glue/multipart_response_delegate.h @@ -72,7 +72,7 @@ class MultipartResponseDelegate { const std::string& boundary); // Passed through from ResourceHandleInternal - void OnReceivedData(const char* data, int data_len); + void OnReceivedData(const char* data, int data_len, int raw_data_length); void OnCompletedRequest(); // The request has been canceled, so stop making calls to the client. @@ -120,6 +120,9 @@ class MultipartResponseDelegate { // full token. size_t FindBoundary(); + // Transferred data size accumulated between client callbacks. + int raw_data_length_; + // A temporary buffer to hold data between reads for multipart data that // gets split in the middle of a header. std::string data_; diff --git a/webkit/glue/multipart_response_delegate_unittest.cc b/webkit/glue/multipart_response_delegate_unittest.cc index b0fb6e6..0aba6e9 100644 --- a/webkit/glue/multipart_response_delegate_unittest.cc +++ b/webkit/glue/multipart_response_delegate_unittest.cc @@ -70,15 +70,16 @@ class MockWebURLLoaderClient : public WebURLLoaderClient { WebKit::WebURLLoader* loader, const char* data, int data_length, - int length_received) { + int raw_data_length) { ++received_data_; data_.append(data, data_length); + total_raw_data_length_ += raw_data_length; } virtual void didFinishLoading(WebURLLoader*, double finishTime) {} virtual void didFail(WebURLLoader*, const WebURLError&) {} void Reset() { - received_response_ = received_data_ = 0; + received_response_ = received_data_ = total_raw_data_length_ = 0; data_.clear(); response_.reset(); } @@ -87,7 +88,7 @@ class MockWebURLLoaderClient : public WebURLLoaderClient { return string(response_.httpHeaderField(WebString::fromUTF8(name)).utf8()); } - int received_response_, received_data_; + int received_response_, received_data_, total_raw_data_length_; string data_; WebURLResponse response_; }; @@ -216,11 +217,13 @@ TEST(MultipartResponseTest, MissingBoundaries) { "--bound--" "ignore junk after end token --bound\n\nTest2\n"); delegate.OnReceivedData(no_start_boundary.c_str(), + static_cast<int>(no_start_boundary.length()), static_cast<int>(no_start_boundary.length())); EXPECT_EQ(1, client.received_response_); EXPECT_EQ(1, client.received_data_); - EXPECT_EQ(string("This is a sample response"), - client.data_); + EXPECT_EQ(string("This is a sample response"), client.data_); + EXPECT_EQ(static_cast<int>(no_start_boundary.length()), + client.total_raw_data_length_); delegate.OnCompletedRequest(); EXPECT_EQ(1, client.received_response_); @@ -233,16 +236,20 @@ TEST(MultipartResponseTest, MissingBoundaries) { "bound\nContent-type: text/plain\n\n" "This is a sample response\n"); delegate2.OnReceivedData(no_end_boundary.c_str(), + static_cast<int>(no_end_boundary.length()), static_cast<int>(no_end_boundary.length())); EXPECT_EQ(1, client.received_response_); EXPECT_EQ(1, client.received_data_); EXPECT_EQ("This is a sample response\n", client.data_); + EXPECT_EQ(static_cast<int>(no_end_boundary.length()), + client.total_raw_data_length_); delegate2.OnCompletedRequest(); EXPECT_EQ(1, client.received_response_); EXPECT_EQ(1, client.received_data_); - EXPECT_EQ(string("This is a sample response\n"), - client.data_); + EXPECT_EQ(string("This is a sample response\n"), client.data_); + EXPECT_EQ(static_cast<int>(no_end_boundary.length()), + client.total_raw_data_length_); // Neither boundary client.Reset(); @@ -251,16 +258,20 @@ TEST(MultipartResponseTest, MissingBoundaries) { "Content-type: text/plain\n\n" "This is a sample response\n"); delegate3.OnReceivedData(no_boundaries.c_str(), + static_cast<int>(no_boundaries.length()), static_cast<int>(no_boundaries.length())); EXPECT_EQ(1, client.received_response_); EXPECT_EQ(1, client.received_data_); EXPECT_EQ("This is a sample response\n", client.data_); + EXPECT_EQ(static_cast<int>(no_boundaries.length()), + client.total_raw_data_length_); delegate3.OnCompletedRequest(); EXPECT_EQ(1, client.received_response_); EXPECT_EQ(1, client.received_data_); - EXPECT_EQ(string("This is a sample response\n"), - client.data_); + EXPECT_EQ(string("This is a sample response\n"), client.data_); + EXPECT_EQ(static_cast<int>(no_boundaries.length()), + client.total_raw_data_length_); } TEST(MultipartResponseTest, MalformedBoundary) { @@ -280,10 +291,13 @@ TEST(MultipartResponseTest, MalformedBoundary) { "This is a sample response\n" "--bound--" "ignore junk after end token --bound\n\nTest2\n"); - delegate.OnReceivedData(data.c_str(), static_cast<int>(data.length())); + delegate.OnReceivedData(data.c_str(), + static_cast<int>(data.length()), + static_cast<int>(data.length())); EXPECT_EQ(1, client.received_response_); EXPECT_EQ(1, client.received_data_); EXPECT_EQ(string("This is a sample response"), client.data_); + EXPECT_EQ(static_cast<int>(data.length()), client.total_raw_data_length_); delegate.OnCompletedRequest(); EXPECT_EQ(1, client.received_response_); @@ -298,11 +312,13 @@ struct TestChunk { const int expected_responses; const int expected_received_data; const char* expected_data; + const int expected_raw_data_length; }; void VariousChunkSizesTest(const TestChunk chunks[], int chunks_size, int responses, int received_data, - const char* completed_data) { + const char* completed_data, + int completed_raw_data_length) { const string data( "--bound\n" // 0-7 "Content-type: image/png\n\n" // 8-32 @@ -322,106 +338,107 @@ void VariousChunkSizesTest(const TestChunk chunks[], int chunks_size, ASSERT_TRUE(chunks[i].start_pos < chunks[i].end_pos); string chunk = data.substr(chunks[i].start_pos, chunks[i].end_pos - chunks[i].start_pos); - delegate.OnReceivedData(chunk.c_str(), static_cast<int>(chunk.length())); - EXPECT_EQ(chunks[i].expected_responses, - client.received_response_); - EXPECT_EQ(chunks[i].expected_received_data, - client.received_data_); - EXPECT_EQ(string(chunks[i].expected_data), - client.data_); + delegate.OnReceivedData( + chunk.c_str(), + static_cast<int>(chunk.length()), + static_cast<int>(chunk.length())); + EXPECT_EQ(chunks[i].expected_responses, client.received_response_); + EXPECT_EQ(chunks[i].expected_received_data, client.received_data_); + EXPECT_EQ(string(chunks[i].expected_data), client.data_); + EXPECT_EQ(chunks[i].expected_raw_data_length, + client.total_raw_data_length_); } // Check final state delegate.OnCompletedRequest(); - EXPECT_EQ(responses, - client.received_response_); - EXPECT_EQ(received_data, - client.received_data_); - EXPECT_EQ(string(completed_data), - client.data_); + EXPECT_EQ(responses, client.received_response_); + EXPECT_EQ(received_data, client.received_data_); + string completed_data_string(completed_data); + EXPECT_EQ(completed_data_string, client.data_); + EXPECT_EQ(completed_raw_data_length, client.total_raw_data_length_); } TEST(MultipartResponseTest, BreakInBoundary) { // Break in the first boundary const TestChunk bound1[] = { - { 0, 4, 0, 0, ""}, - { 4, 110, 2, 2, "foofoofoofoofoo" }, + { 0, 4, 0, 0, "", 0 }, + { 4, 110, 2, 2, "foofoofoofoofoo", 110 }, }; VariousChunkSizesTest(bound1, arraysize(bound1), - 2, 2, "foofoofoofoofoo"); + 2, 2, "foofoofoofoofoo", 110); // Break in first and second const TestChunk bound2[] = { - { 0, 4, 0, 0, ""}, - { 4, 55, 1, 1, "datadatadatadat" }, - { 55, 65, 1, 2, "datadatadatadatadata" }, - { 65, 110, 2, 3, "foofoofoofoofoo" }, + { 0, 4, 0, 0, "", 0 }, + { 4, 55, 1, 1, "datadatadatadat", 55 }, + { 55, 65, 1, 2, "datadatadatadatadata", 65 }, + { 65, 110, 2, 3, "foofoofoofoofoo", 110 }, }; VariousChunkSizesTest(bound2, arraysize(bound2), - 2, 3, "foofoofoofoofoo"); + 2, 3, "foofoofoofoofoo", 110); // Break in second only const TestChunk bound3[] = { - { 0, 55, 1, 1, "datadatadatadat" }, - { 55, 110, 2, 3, "foofoofoofoofoo" }, + { 0, 55, 1, 1, "datadatadatadat", 55 }, + { 55, 110, 2, 3, "foofoofoofoofoo", 110 }, }; VariousChunkSizesTest(bound3, arraysize(bound3), - 2, 3, "foofoofoofoofoo"); + 2, 3, "foofoofoofoofoo", 110); } TEST(MultipartResponseTest, BreakInHeaders) { // Break in first header const TestChunk header1[] = { - { 0, 10, 0, 0, "" }, - { 10, 35, 1, 0, "" }, - { 35, 110, 2, 2, "foofoofoofoofoo" }, + { 0, 10, 0, 0, "", 0 }, + { 10, 35, 1, 0, "", 0 }, + { 35, 110, 2, 2, "foofoofoofoofoo", 110 }, }; VariousChunkSizesTest(header1, arraysize(header1), - 2, 2, "foofoofoofoofoo"); + 2, 2, "foofoofoofoofoo", 110); // Break in both headers const TestChunk header2[] = { - { 0, 10, 0, 0, "" }, - { 10, 65, 1, 1, "datadatadatadatadata" }, - { 65, 110, 2, 2, "foofoofoofoofoo" }, + { 0, 10, 0, 0, "", 0 }, + { 10, 65, 1, 1, "datadatadatadatadata", 65 }, + { 65, 110, 2, 2, "foofoofoofoofoo", 110 }, }; VariousChunkSizesTest(header2, arraysize(header2), - 2, 2, "foofoofoofoofoo"); + 2, 2, "foofoofoofoofoo", 110); // Break at end of a header const TestChunk header3[] = { - { 0, 33, 1, 0, "" }, - { 33, 65, 1, 1, "datadatadatadatadata" }, - { 65, 110, 2, 2, "foofoofoofoofoo" }, + { 0, 33, 1, 0, "", 0 }, + { 33, 65, 1, 1, "datadatadatadatadata", 65 }, + { 65, 110, 2, 2, "foofoofoofoofoo", 110 }, }; VariousChunkSizesTest(header3, arraysize(header3), - 2, 2, "foofoofoofoofoo"); + 2, 2, "foofoofoofoofoo", 110); } TEST(MultipartResponseTest, BreakInData) { // All data as one chunk const TestChunk data1[] = { - { 0, 110, 2, 2, "foofoofoofoofoo" }, + { 0, 110, 2, 2, "foofoofoofoofoo", 110 }, }; VariousChunkSizesTest(data1, arraysize(data1), - 2, 2, "foofoofoofoofoo"); + 2, 2, "foofoofoofoofoo", 110); // breaks in data segment const TestChunk data2[] = { - { 0, 35, 1, 0, "" }, - { 35, 65, 1, 1, "datadatadatadatadata" }, - { 65, 90, 2, 1, "" }, - { 90, 110, 2, 2, "foofoofoofoofoo" }, + { 0, 35, 1, 0, "", 0 }, + { 35, 65, 1, 1, "datadatadatadatadata", 65 }, + { 65, 90, 2, 1, "", 65 }, + { 90, 110, 2, 2, "foofoofoofoofoo", 110 }, }; VariousChunkSizesTest(data2, arraysize(data2), - 2, 2, "foofoofoofoofoo"); + 2, 2, "foofoofoofoofoo", 110); // Incomplete send const TestChunk data3[] = { - { 0, 35, 1, 0, "" }, - { 35, 90, 2, 1, "" }, + { 0, 35, 1, 0, "", 0 }, + { 35, 90, 2, 1, "", 90 }, }; VariousChunkSizesTest(data3, arraysize(data3), - 2, 2, "foof"); + 2, 2, "foof", 90); } TEST(MultipartResponseTest, SmallChunk) { @@ -440,10 +457,12 @@ TEST(MultipartResponseTest, SmallChunk) { "--boundContent-type: text/plain\n\n" "end--bound--"); delegate.OnReceivedData(data.c_str(), + static_cast<int>(data.length()), static_cast<int>(data.length())); EXPECT_EQ(4, client.received_response_); EXPECT_EQ(2, client.received_data_); EXPECT_EQ(string("end"), client.data_); + EXPECT_EQ(static_cast<int>(data.length()), client.total_raw_data_length_); delegate.OnCompletedRequest(); EXPECT_EQ(4, client.received_response_); @@ -459,13 +478,13 @@ TEST(MultipartResponseTest, MultipleBoundaries) { MultipartResponseDelegate delegate(&client, NULL, response, "bound"); string data("--bound\r\n\r\n--bound\r\n\r\nfoofoo--bound--"); - delegate.OnReceivedData(data.c_str(), static_cast<int>(data.length())); - EXPECT_EQ(2, - client.received_response_); - EXPECT_EQ(1, - client.received_data_); - EXPECT_EQ(string("foofoo"), - client.data_); + delegate.OnReceivedData(data.c_str(), + static_cast<int>(data.length()), + static_cast<int>(data.length())); + EXPECT_EQ(2, client.received_response_); + EXPECT_EQ(1, client.received_data_); + EXPECT_EQ(string("foofoo"), client.data_); + EXPECT_EQ(static_cast<int>(data.length()), client.total_raw_data_length_); } TEST(MultipartResponseTest, MultipartByteRangeParsingTest) { @@ -628,22 +647,25 @@ TEST(MultipartResponseTest, MultipartPayloadSet) { "Content-type: text/plain\n\n" "response data\n" "--bound\n"); - delegate.OnReceivedData(data.c_str(), static_cast<int>(data.length())); - EXPECT_EQ(1, - client.received_response_); - EXPECT_EQ(string("response data"), - client.data_); + delegate.OnReceivedData(data.c_str(), + static_cast<int>(data.length()), + static_cast<int>(data.length())); + EXPECT_EQ(1, client.received_response_); + EXPECT_EQ(string("response data"), client.data_); + EXPECT_EQ(static_cast<int>(data.length()), client.total_raw_data_length_); EXPECT_FALSE(client.response_.isMultipartPayload()); string data2( "Content-type: text/plain\n\n" "response data2\n" "--bound\n"); - delegate.OnReceivedData(data2.c_str(), static_cast<int>(data2.length())); - EXPECT_EQ(2, - client.received_response_); - EXPECT_EQ(string("response data2"), - client.data_); + delegate.OnReceivedData(data2.c_str(), + static_cast<int>(data2.length()), + static_cast<int>(data2.length())); + EXPECT_EQ(2, client.received_response_); + EXPECT_EQ(string("response data2"), client.data_); + EXPECT_EQ(static_cast<int>(data.length()) + static_cast<int>(data2.length()), + client.total_raw_data_length_); EXPECT_TRUE(client.response_.isMultipartPayload()); } diff --git a/webkit/glue/resource_fetcher.cc b/webkit/glue/resource_fetcher.cc index f7907fb..2e2fc74 100644 --- a/webkit/glue/resource_fetcher.cc +++ b/webkit/glue/resource_fetcher.cc @@ -86,7 +86,7 @@ void ResourceFetcher::didReceiveResponse( void ResourceFetcher::didReceiveData( WebURLLoader* loader, const char* data, int data_length, - int length_received) { + int raw_data_length) { DCHECK(!completed_); DCHECK(data_length > 0); diff --git a/webkit/glue/resource_fetcher.h b/webkit/glue/resource_fetcher.h index d9b3460..908658e 100644 --- a/webkit/glue/resource_fetcher.h +++ b/webkit/glue/resource_fetcher.h @@ -66,7 +66,7 @@ class ResourceFetcher : public WebKit::WebURLLoaderClient { virtual void didReceiveData( WebKit::WebURLLoader* loader, const char* data, int data_length, - int length_received); + int raw_data_length); virtual void didFinishLoading( WebKit::WebURLLoader* loader, double finishTime); virtual void didFail( diff --git a/webkit/glue/resource_loader_bridge.cc b/webkit/glue/resource_loader_bridge.cc index b757921..ab757df 100644 --- a/webkit/glue/resource_loader_bridge.cc +++ b/webkit/glue/resource_loader_bridge.cc @@ -35,6 +35,7 @@ ResourceDevToolsInfo::~ResourceDevToolsInfo() {} ResourceResponseInfo::ResourceResponseInfo() : content_length(-1), + raw_data_length(-1), appcache_id(appcache::kNoCacheId), connection_id(0), connection_reused(false), diff --git a/webkit/glue/resource_loader_bridge.h b/webkit/glue/resource_loader_bridge.h index e5f7d2e..df55897 100644 --- a/webkit/glue/resource_loader_bridge.h +++ b/webkit/glue/resource_loader_bridge.h @@ -141,6 +141,10 @@ struct ResourceResponseInfo { // Content length if available. -1 if not available int64 content_length; + // Length of the raw data transferred over the network. In case there is no + // data, contains -1. + int64 raw_data_length; + // The appcache this response was loaded from, or kNoCacheId. int64 appcache_id; @@ -301,7 +305,12 @@ class ResourceLoaderBridge { // Called when a chunk of response data is available. This method may // be called multiple times or not at all if an error occurs. - virtual void OnReceivedData(const char* data, int len) = 0; + // The raw_data_length is the length of the raw data transferred over the + // network, which could be different from data length (e.g. for gzipped + // content), or -1 if if unknown. + virtual void OnReceivedData(const char* data, + int data_length, + int raw_data_length) = 0; // Called when metadata generated by the renderer is retrieved from the // cache. This method may be called zero or one times. diff --git a/webkit/glue/weburlloader_impl.cc b/webkit/glue/weburlloader_impl.cc index 2c0659a..c3d79be 100644 --- a/webkit/glue/weburlloader_impl.cc +++ b/webkit/glue/weburlloader_impl.cc @@ -157,6 +157,7 @@ bool GetInfoFromDataURL(const GURL& url, info->charset.swap(charset); info->security_info.clear(); info->content_length = -1; + info->raw_data_length = 0; info->load_timing.base_time = Time::Now(); return true; @@ -295,7 +296,9 @@ class WebURLLoaderImpl::Context : public base::RefCounted<Context>, GURL* new_first_party_for_cookies); virtual void OnReceivedResponse(const ResourceResponseInfo& info); virtual void OnDownloadedData(int len); - virtual void OnReceivedData(const char* data, int len); + virtual void OnReceivedData(const char* data, + int data_length, + int raw_data_length); virtual void OnReceivedCachedMetadata(const char* data, int len); virtual void OnCompletedRequest(const net::URLRequestStatus& status, const std::string& security_info, @@ -591,23 +594,25 @@ void WebURLLoaderImpl::Context::OnDownloadedData(int len) { client_->didDownloadData(loader_, len); } -void WebURLLoaderImpl::Context::OnReceivedData(const char* data, int len) { +void WebURLLoaderImpl::Context::OnReceivedData(const char* data, + int data_length, + int raw_data_length) { if (!client_) return; // Temporary logging, see site_isolation_metrics.h/cc. - SiteIsolationMetrics::SniffCrossOriginHTML(response_url_, data, len); + SiteIsolationMetrics::SniffCrossOriginHTML(response_url_, data, data_length); if (ftp_listing_delegate_.get()) { // The FTP listing delegate will make the appropriate calls to // client_->didReceiveData and client_->didReceiveResponse. - ftp_listing_delegate_->OnReceivedData(data, len); + ftp_listing_delegate_->OnReceivedData(data, data_length); } else if (multipart_delegate_.get()) { // The multipart delegate will make the appropriate calls to // client_->didReceiveData and client_->didReceiveResponse. - multipart_delegate_->OnReceivedData(data, len); + multipart_delegate_->OnReceivedData(data, data_length, raw_data_length); } else { - client_->didReceiveData(loader_, data, len, -1); + client_->didReceiveData(loader_, data, data_length, raw_data_length); } } @@ -694,7 +699,7 @@ void WebURLLoaderImpl::Context::HandleDataURL() { if (GetInfoFromDataURL(request_.url(), &info, &data, &status)) { OnReceivedResponse(info); if (!data.empty()) - OnReceivedData(data.data(), data.size()); + OnReceivedData(data.data(), data.size(), 0); } OnCompletedRequest(status, info.security_info, base::Time::Now()); diff --git a/webkit/plugins/npapi/webplugin_impl.cc b/webkit/plugins/npapi/webplugin_impl.cc index 80943a9..aafcc76 100644 --- a/webkit/plugins/npapi/webplugin_impl.cc +++ b/webkit/plugins/npapi/webplugin_impl.cc @@ -111,7 +111,7 @@ class MultiPartResponseClient : public WebURLLoaderClient { // Receives individual part data from a multipart response. virtual void didReceiveData( - WebURLLoader*, const char* data, int data_length, int length_received) { + WebURLLoader*, const char* data, int data_length, int raw_data_length) { // TODO(ananta) // We should defer further loads on multipart resources on the same lines // as regular resources requested by plugins to prevent reentrancy. @@ -952,7 +952,7 @@ void WebPluginImpl::didReceiveResponse(WebURLLoader* loader, void WebPluginImpl::didReceiveData(WebURLLoader* loader, const char *buffer, int data_length, - int length_received) { + int raw_data_length) { WebPluginResourceClient* client = GetClientFromLoader(loader); if (!client) return; @@ -962,7 +962,7 @@ void WebPluginImpl::didReceiveData(WebURLLoader* loader, if (index != multi_part_response_map_.end()) { MultipartResponseDelegate* multi_part_handler = (*index).second; DCHECK(multi_part_handler != NULL); - multi_part_handler->OnReceivedData(buffer, data_length); + multi_part_handler->OnReceivedData(buffer, data_length, raw_data_length); } else { loader->setDefersLoading(true); client->DidReceiveData(buffer, data_length, 0); diff --git a/webkit/plugins/npapi/webplugin_impl.h b/webkit/plugins/npapi/webplugin_impl.h index 85aef63..966dc0e 100644 --- a/webkit/plugins/npapi/webplugin_impl.h +++ b/webkit/plugins/npapi/webplugin_impl.h @@ -205,7 +205,7 @@ class WebPluginImpl : public WebPlugin, const WebKit::WebURLResponse& response); virtual void didReceiveData(WebKit::WebURLLoader* loader, const char *buffer, - int data_length, int length_received); + int data_length, int raw_data_length); virtual void didFinishLoading(WebKit::WebURLLoader* loader, double finishTime); virtual void didFail(WebKit::WebURLLoader* loader, diff --git a/webkit/plugins/ppapi/ppb_url_loader_impl.cc b/webkit/plugins/ppapi/ppb_url_loader_impl.cc index 7d0faed..31518d1 100644 --- a/webkit/plugins/ppapi/ppb_url_loader_impl.cc +++ b/webkit/plugins/ppapi/ppb_url_loader_impl.cc @@ -423,7 +423,7 @@ void PPB_URLLoader_Impl::didDownloadData(WebURLLoader* loader, void PPB_URLLoader_Impl::didReceiveData(WebURLLoader* loader, const char* data, int data_length, - int length_received) { + int raw_data_length) { bytes_received_ += data_length; buffer_.insert(buffer_.end(), data, data + data_length); diff --git a/webkit/plugins/ppapi/ppb_url_loader_impl.h b/webkit/plugins/ppapi/ppb_url_loader_impl.h index 4367114..cd21285 100644 --- a/webkit/plugins/ppapi/ppb_url_loader_impl.h +++ b/webkit/plugins/ppapi/ppb_url_loader_impl.h @@ -80,7 +80,7 @@ class PPB_URLLoader_Impl : public Resource, public WebKit::WebURLLoaderClient { virtual void didReceiveData(WebKit::WebURLLoader* loader, const char* data, int data_length, - int length_received); + int raw_data_length); virtual void didFinishLoading(WebKit::WebURLLoader* loader, double finish_time); virtual void didFail(WebKit::WebURLLoader* loader, diff --git a/webkit/tools/test_shell/simple_resource_loader_bridge.cc b/webkit/tools/test_shell/simple_resource_loader_bridge.cc index 81ebab4..7f278bd 100644 --- a/webkit/tools/test_shell/simple_resource_loader_bridge.cc +++ b/webkit/tools/test_shell/simple_resource_loader_bridge.cc @@ -305,7 +305,7 @@ class RequestProxy : public net::URLRequest::Delegate, g_io_thread->message_loop()->PostTask(FROM_HERE, NewRunnableMethod( this, &RequestProxy::AsyncReadData)); - peer_->OnReceivedData(buf_copy.get(), bytes_read); + peer_->OnReceivedData(buf_copy.get(), bytes_read, -1); } void NotifyDownloadedData(int bytes_read) { |