OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/browser/webui/url_data_manager_backend.h" | 5 #include "content/browser/webui/url_data_manager_backend.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 public: | 112 public: |
113 // |is_incognito| set when job is generated from an incognito profile. | 113 // |is_incognito| set when job is generated from an incognito profile. |
114 URLRequestChromeJob(net::URLRequest* request, | 114 URLRequestChromeJob(net::URLRequest* request, |
115 net::NetworkDelegate* network_delegate, | 115 net::NetworkDelegate* network_delegate, |
116 URLDataManagerBackend* backend, | 116 URLDataManagerBackend* backend, |
117 bool is_incognito); | 117 bool is_incognito); |
118 | 118 |
119 // net::URLRequestJob implementation. | 119 // net::URLRequestJob implementation. |
120 void Start() override; | 120 void Start() override; |
121 void Kill() override; | 121 void Kill() override; |
122 int ReadRawData(net::IOBuffer* buf, int buf_size) override; | 122 bool ReadRawData(net::IOBuffer* buf, int buf_size, int* bytes_read) override; |
123 bool GetMimeType(std::string* mime_type) const override; | 123 bool GetMimeType(std::string* mime_type) const override; |
124 int GetResponseCode() const override; | 124 int GetResponseCode() const override; |
125 void GetResponseInfo(net::HttpResponseInfo* info) override; | 125 void GetResponseInfo(net::HttpResponseInfo* info) override; |
126 | 126 |
127 // Used to notify that the requested data's |mime_type| is ready. | 127 // Used to notify that the requested data's |mime_type| is ready. |
128 void MimeTypeAvailable(const std::string& mime_type); | 128 void MimeTypeAvailable(const std::string& mime_type); |
129 | 129 |
130 // Called by ChromeURLDataManager to notify us that the data blob is ready | 130 // Called by ChromeURLDataManager to notify us that the data blob is ready |
131 // for us. | 131 // for us. |
132 void DataAvailable(base::RefCountedMemory* bytes); | 132 void DataAvailable(base::RefCountedMemory* bytes); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 // Called on the UI thread to check if this request is allowed. | 183 // Called on the UI thread to check if this request is allowed. |
184 static void CheckStoragePartitionMatches( | 184 static void CheckStoragePartitionMatches( |
185 int render_process_id, | 185 int render_process_id, |
186 const GURL& url, | 186 const GURL& url, |
187 const base::WeakPtr<URLRequestChromeJob>& job); | 187 const base::WeakPtr<URLRequestChromeJob>& job); |
188 | 188 |
189 // Specific resources require unsafe-eval in the Content Security Policy. | 189 // Specific resources require unsafe-eval in the Content Security Policy. |
190 bool RequiresUnsafeEval() const; | 190 bool RequiresUnsafeEval() const; |
191 | 191 |
192 // Do the actual copy from data_ (the data we're serving) into |buf|. | 192 // Do the actual copy from data_ (the data we're serving) into |buf|. |
193 // Separate from ReadRawData so we can handle async I/O. Returns the number of | 193 // Separate from ReadRawData so we can handle async I/O. |
194 // bytes read. | 194 void CompleteRead(net::IOBuffer* buf, int buf_size, int* bytes_read); |
195 int CompleteRead(net::IOBuffer* buf, int buf_size); | |
196 | 195 |
197 // The actual data we're serving. NULL until it's been fetched. | 196 // The actual data we're serving. NULL until it's been fetched. |
198 scoped_refptr<base::RefCountedMemory> data_; | 197 scoped_refptr<base::RefCountedMemory> data_; |
199 // The current offset into the data that we're handing off to our | 198 // The current offset into the data that we're handing off to our |
200 // callers via the Read interfaces. | 199 // callers via the Read interfaces. |
201 int data_offset_; | 200 int data_offset_; |
202 | 201 |
203 // For async reads, we keep around a pointer to the buffer that | 202 // For async reads, we keep around a pointer to the buffer that |
204 // we're reading into. | 203 // we're reading into. |
205 scoped_refptr<net::IOBuffer> pending_buf_; | 204 scoped_refptr<net::IOBuffer> pending_buf_; |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 } | 329 } |
331 | 330 |
332 void URLRequestChromeJob::MimeTypeAvailable(const std::string& mime_type) { | 331 void URLRequestChromeJob::MimeTypeAvailable(const std::string& mime_type) { |
333 set_mime_type(mime_type); | 332 set_mime_type(mime_type); |
334 NotifyHeadersComplete(); | 333 NotifyHeadersComplete(); |
335 } | 334 } |
336 | 335 |
337 void URLRequestChromeJob::DataAvailable(base::RefCountedMemory* bytes) { | 336 void URLRequestChromeJob::DataAvailable(base::RefCountedMemory* bytes) { |
338 TRACE_EVENT_ASYNC_END0("browser", "DataManager:Request", this); | 337 TRACE_EVENT_ASYNC_END0("browser", "DataManager:Request", this); |
339 if (bytes) { | 338 if (bytes) { |
| 339 // The request completed, and we have all the data. |
| 340 // Clear any IO pending status. |
| 341 SetStatus(net::URLRequestStatus()); |
| 342 |
340 data_ = bytes; | 343 data_ = bytes; |
| 344 int bytes_read; |
341 if (pending_buf_.get()) { | 345 if (pending_buf_.get()) { |
342 CHECK(pending_buf_->data()); | 346 CHECK(pending_buf_->data()); |
343 int result = CompleteRead(pending_buf_.get(), pending_buf_size_); | 347 CompleteRead(pending_buf_.get(), pending_buf_size_, &bytes_read); |
344 pending_buf_ = NULL; | 348 pending_buf_ = NULL; |
345 ReadRawDataComplete(result); | 349 NotifyReadComplete(bytes_read); |
346 } | 350 } |
347 } else { | 351 } else { |
348 // The request failed. | 352 // The request failed. |
349 ReadRawDataComplete(net::ERR_FAILED); | 353 NotifyDone( |
| 354 net::URLRequestStatus(net::URLRequestStatus::FAILED, net::ERR_FAILED)); |
350 } | 355 } |
351 } | 356 } |
352 | 357 |
353 base::WeakPtr<URLRequestChromeJob> URLRequestChromeJob::AsWeakPtr() { | 358 base::WeakPtr<URLRequestChromeJob> URLRequestChromeJob::AsWeakPtr() { |
354 return weak_factory_.GetWeakPtr(); | 359 return weak_factory_.GetWeakPtr(); |
355 } | 360 } |
356 | 361 |
357 int URLRequestChromeJob::ReadRawData(net::IOBuffer* buf, int buf_size) { | 362 bool URLRequestChromeJob::ReadRawData(net::IOBuffer* buf, |
| 363 int buf_size, |
| 364 int* bytes_read) { |
358 if (!data_.get()) { | 365 if (!data_.get()) { |
| 366 SetStatus(net::URLRequestStatus(net::URLRequestStatus::IO_PENDING, 0)); |
359 DCHECK(!pending_buf_.get()); | 367 DCHECK(!pending_buf_.get()); |
360 CHECK(buf->data()); | 368 CHECK(buf->data()); |
361 pending_buf_ = buf; | 369 pending_buf_ = buf; |
362 pending_buf_size_ = buf_size; | 370 pending_buf_size_ = buf_size; |
363 return net::ERR_IO_PENDING; | 371 return false; // Tell the caller we're still waiting for data. |
364 } | 372 } |
365 | 373 |
366 // Otherwise, the data is available. | 374 // Otherwise, the data is available. |
367 return CompleteRead(buf, buf_size); | 375 CompleteRead(buf, buf_size, bytes_read); |
| 376 return true; |
368 } | 377 } |
369 | 378 |
370 int URLRequestChromeJob::CompleteRead(net::IOBuffer* buf, int buf_size) { | 379 void URLRequestChromeJob::CompleteRead(net::IOBuffer* buf, |
371 int remaining = data_->size() - data_offset_; | 380 int buf_size, |
| 381 int* bytes_read) { |
| 382 int remaining = static_cast<int>(data_->size()) - data_offset_; |
372 if (buf_size > remaining) | 383 if (buf_size > remaining) |
373 buf_size = remaining; | 384 buf_size = remaining; |
374 if (buf_size > 0) { | 385 if (buf_size > 0) { |
375 // TODO(pkasting): Remove ScopedTracker below once crbug.com/455423 is | 386 // TODO(pkasting): Remove ScopedTracker below once crbug.com/455423 is |
376 // fixed. | 387 // fixed. |
377 tracked_objects::ScopedTracker tracking_profile( | 388 tracked_objects::ScopedTracker tracking_profile( |
378 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 389 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
379 "455423 URLRequestChromeJob::CompleteRead memcpy")); | 390 "455423 URLRequestChromeJob::CompleteRead memcpy")); |
380 memcpy(buf->data(), data_->front() + data_offset_, buf_size); | 391 memcpy(buf->data(), data_->front() + data_offset_, buf_size); |
381 data_offset_ += buf_size; | 392 data_offset_ += buf_size; |
382 } | 393 } |
383 return buf_size; | 394 *bytes_read = buf_size; |
384 } | 395 } |
385 | 396 |
386 void URLRequestChromeJob::CheckStoragePartitionMatches( | 397 void URLRequestChromeJob::CheckStoragePartitionMatches( |
387 int render_process_id, | 398 int render_process_id, |
388 const GURL& url, | 399 const GURL& url, |
389 const base::WeakPtr<URLRequestChromeJob>& job) { | 400 const base::WeakPtr<URLRequestChromeJob>& job) { |
390 // The embedder could put some webui pages in separate storage partition. | 401 // The embedder could put some webui pages in separate storage partition. |
391 // RenderProcessHostImpl::IsSuitableHost would guard against top level pages | 402 // RenderProcessHostImpl::IsSuitableHost would guard against top level pages |
392 // being in the same process. We do an extra check to guard against an | 403 // being in the same process. We do an extra check to guard against an |
393 // exploited renderer pretending to add them as a subframe. We skip this check | 404 // exploited renderer pretending to add them as a subframe. We skip this check |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
764 | 775 |
765 } // namespace | 776 } // namespace |
766 | 777 |
767 net::URLRequestJobFactory::ProtocolHandler* | 778 net::URLRequestJobFactory::ProtocolHandler* |
768 CreateDevToolsProtocolHandler(content::ResourceContext* resource_context, | 779 CreateDevToolsProtocolHandler(content::ResourceContext* resource_context, |
769 bool is_incognito) { | 780 bool is_incognito) { |
770 return new DevToolsJobFactory(resource_context, is_incognito); | 781 return new DevToolsJobFactory(resource_context, is_incognito); |
771 } | 782 } |
772 | 783 |
773 } // namespace content | 784 } // namespace content |
OLD | NEW |