Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "content/child/url_response_body_consumer.h" | 5 #include "content/child/url_response_body_consumer.h" |
| 6 | 6 |
| 7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "content/child/resource_dispatcher.h" | 11 #include "content/child/resource_dispatcher.h" |
| 12 #include "content/child/site_isolation_stats_gatherer.h" | |
| 12 #include "content/common/resource_messages.h" | 13 #include "content/common/resource_messages.h" |
| 13 #include "content/common/resource_request_completion_status.h" | 14 #include "content/common/resource_request_completion_status.h" |
| 14 #include "content/public/child/request_peer.h" | 15 #include "content/public/child/request_peer.h" |
| 15 | 16 |
| 16 namespace content { | 17 namespace content { |
| 17 | 18 |
| 18 class URLResponseBodyConsumer::ReceivedData final | 19 class URLResponseBodyConsumer::ReceivedData final |
| 19 : public RequestPeer::ReceivedData { | 20 : public RequestPeer::ReceivedData { |
| 20 public: | 21 public: |
| 21 ReceivedData(const char* payload, | 22 ReceivedData(const char* payload, |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 136 DCHECK_EQ(result, MOJO_RESULT_OK); | 137 DCHECK_EQ(result, MOJO_RESULT_OK); |
| 137 task_runner_->PostTask(FROM_HERE, | 138 task_runner_->PostTask(FROM_HERE, |
| 138 base::Bind(&URLResponseBodyConsumer::OnReadable, | 139 base::Bind(&URLResponseBodyConsumer::OnReadable, |
| 139 AsWeakPtr(), MOJO_RESULT_OK)); | 140 AsWeakPtr(), MOJO_RESULT_OK)); |
| 140 return; | 141 return; |
| 141 } | 142 } |
| 142 num_bytes_consumed += available; | 143 num_bytes_consumed += available; |
| 143 ResourceDispatcher::PendingRequestInfo* request_info = | 144 ResourceDispatcher::PendingRequestInfo* request_info = |
| 144 resource_dispatcher_->GetPendingRequestInfo(request_id_); | 145 resource_dispatcher_->GetPendingRequestInfo(request_id_); |
| 145 DCHECK(request_info); | 146 DCHECK(request_info); |
| 147 | |
| 148 // Check whether this response data is compliant with our cross-site | |
|
yhirano
2017/01/19 10:35:55
This code is copied from ResourceDispatcher::OnRec
| |
| 149 // document blocking policy. We only do this for the first chunk of data. | |
| 150 if (request_info->site_isolation_metadata.get()) { | |
| 151 SiteIsolationStatsGatherer::OnReceivedFirstChunk( | |
| 152 request_info->site_isolation_metadata, | |
| 153 static_cast<const char*>(buffer), available); | |
| 154 request_info->site_isolation_metadata.reset(); | |
| 155 } | |
| 156 | |
| 146 request_info->peer->OnReceivedData(base::MakeUnique<ReceivedData>( | 157 request_info->peer->OnReceivedData(base::MakeUnique<ReceivedData>( |
| 147 static_cast<const char*>(buffer), available, this)); | 158 static_cast<const char*>(buffer), available, this)); |
| 148 } | 159 } |
| 149 } | 160 } |
| 150 | 161 |
| 151 void URLResponseBodyConsumer::NotifyCompletionIfAppropriate() { | 162 void URLResponseBodyConsumer::NotifyCompletionIfAppropriate() { |
| 152 if (has_been_cancelled_) | 163 if (has_been_cancelled_) |
| 153 return; | 164 return; |
| 154 if (!has_received_completion_ || !has_seen_end_of_data_) | 165 if (!has_received_completion_ || !has_seen_end_of_data_) |
| 155 return; | 166 return; |
| 156 // Cancel this instance in order not to notify twice. | 167 // Cancel this instance in order not to notify twice. |
| 157 Cancel(); | 168 Cancel(); |
| 158 | 169 |
| 159 resource_dispatcher_->DispatchMessage( | 170 resource_dispatcher_->DispatchMessage( |
| 160 ResourceMsg_RequestComplete(request_id_, completion_status_)); | 171 ResourceMsg_RequestComplete(request_id_, completion_status_)); |
| 161 // |this| may be deleted. | 172 // |this| may be deleted. |
| 162 } | 173 } |
| 163 | 174 |
| 164 } // namespace content | 175 } // namespace content |
| OLD | NEW |