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 bool ReadRawData(net::IOBuffer* buf, int buf_size, int* bytes_read) override; | 122 int ReadRawData(net::IOBuffer* buf, int buf_size) 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. | 193 // Separate from ReadRawData so we can handle async I/O. Returns the number of |
194 void CompleteRead(net::IOBuffer* buf, int buf_size, int* bytes_read); | 194 // bytes read. |
| 195 int CompleteRead(net::IOBuffer* buf, int buf_size); |
195 | 196 |
196 // The actual data we're serving. NULL until it's been fetched. | 197 // The actual data we're serving. NULL until it's been fetched. |
197 scoped_refptr<base::RefCountedMemory> data_; | 198 scoped_refptr<base::RefCountedMemory> data_; |
198 // The current offset into the data that we're handing off to our | 199 // The current offset into the data that we're handing off to our |
199 // callers via the Read interfaces. | 200 // callers via the Read interfaces. |
200 int data_offset_; | 201 int data_offset_; |
201 | 202 |
202 // For async reads, we keep around a pointer to the buffer that | 203 // For async reads, we keep around a pointer to the buffer that |
203 // we're reading into. | 204 // we're reading into. |
204 scoped_refptr<net::IOBuffer> pending_buf_; | 205 scoped_refptr<net::IOBuffer> pending_buf_; |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 } | 330 } |
330 | 331 |
331 void URLRequestChromeJob::MimeTypeAvailable(const std::string& mime_type) { | 332 void URLRequestChromeJob::MimeTypeAvailable(const std::string& mime_type) { |
332 set_mime_type(mime_type); | 333 set_mime_type(mime_type); |
333 NotifyHeadersComplete(); | 334 NotifyHeadersComplete(); |
334 } | 335 } |
335 | 336 |
336 void URLRequestChromeJob::DataAvailable(base::RefCountedMemory* bytes) { | 337 void URLRequestChromeJob::DataAvailable(base::RefCountedMemory* bytes) { |
337 TRACE_EVENT_ASYNC_END0("browser", "DataManager:Request", this); | 338 TRACE_EVENT_ASYNC_END0("browser", "DataManager:Request", this); |
338 if (bytes) { | 339 if (bytes) { |
339 // The request completed, and we have all the data. | |
340 // Clear any IO pending status. | |
341 SetStatus(net::URLRequestStatus()); | |
342 | |
343 data_ = bytes; | 340 data_ = bytes; |
344 int bytes_read; | |
345 if (pending_buf_.get()) { | 341 if (pending_buf_.get()) { |
346 CHECK(pending_buf_->data()); | 342 CHECK(pending_buf_->data()); |
347 CompleteRead(pending_buf_.get(), pending_buf_size_, &bytes_read); | 343 int result = CompleteRead(pending_buf_.get(), pending_buf_size_); |
348 pending_buf_ = NULL; | 344 pending_buf_ = NULL; |
349 NotifyReadComplete(bytes_read); | 345 ReadRawDataComplete(result); |
350 } | 346 } |
351 } else { | 347 } else { |
352 // The request failed. | 348 // The request failed. |
353 NotifyDone( | 349 ReadRawDataComplete(net::ERR_FAILED); |
354 net::URLRequestStatus(net::URLRequestStatus::FAILED, net::ERR_FAILED)); | |
355 } | 350 } |
356 } | 351 } |
357 | 352 |
358 base::WeakPtr<URLRequestChromeJob> URLRequestChromeJob::AsWeakPtr() { | 353 base::WeakPtr<URLRequestChromeJob> URLRequestChromeJob::AsWeakPtr() { |
359 return weak_factory_.GetWeakPtr(); | 354 return weak_factory_.GetWeakPtr(); |
360 } | 355 } |
361 | 356 |
362 bool URLRequestChromeJob::ReadRawData(net::IOBuffer* buf, | 357 int URLRequestChromeJob::ReadRawData(net::IOBuffer* buf, int buf_size) { |
363 int buf_size, | |
364 int* bytes_read) { | |
365 if (!data_.get()) { | 358 if (!data_.get()) { |
366 SetStatus(net::URLRequestStatus(net::URLRequestStatus::IO_PENDING, 0)); | |
367 DCHECK(!pending_buf_.get()); | 359 DCHECK(!pending_buf_.get()); |
368 CHECK(buf->data()); | 360 CHECK(buf->data()); |
369 pending_buf_ = buf; | 361 pending_buf_ = buf; |
370 pending_buf_size_ = buf_size; | 362 pending_buf_size_ = buf_size; |
371 return false; // Tell the caller we're still waiting for data. | 363 return net::ERR_IO_PENDING; |
372 } | 364 } |
373 | 365 |
374 // Otherwise, the data is available. | 366 // Otherwise, the data is available. |
375 CompleteRead(buf, buf_size, bytes_read); | 367 return CompleteRead(buf, buf_size); |
376 return true; | |
377 } | 368 } |
378 | 369 |
379 void URLRequestChromeJob::CompleteRead(net::IOBuffer* buf, | 370 int URLRequestChromeJob::CompleteRead(net::IOBuffer* buf, int buf_size) { |
380 int buf_size, | 371 int remaining = data_->size() - data_offset_; |
381 int* bytes_read) { | |
382 int remaining = static_cast<int>(data_->size()) - data_offset_; | |
383 if (buf_size > remaining) | 372 if (buf_size > remaining) |
384 buf_size = remaining; | 373 buf_size = remaining; |
385 if (buf_size > 0) { | 374 if (buf_size > 0) { |
386 // TODO(pkasting): Remove ScopedTracker below once crbug.com/455423 is | 375 // TODO(pkasting): Remove ScopedTracker below once crbug.com/455423 is |
387 // fixed. | 376 // fixed. |
388 tracked_objects::ScopedTracker tracking_profile( | 377 tracked_objects::ScopedTracker tracking_profile( |
389 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 378 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
390 "455423 URLRequestChromeJob::CompleteRead memcpy")); | 379 "455423 URLRequestChromeJob::CompleteRead memcpy")); |
391 memcpy(buf->data(), data_->front() + data_offset_, buf_size); | 380 memcpy(buf->data(), data_->front() + data_offset_, buf_size); |
392 data_offset_ += buf_size; | 381 data_offset_ += buf_size; |
393 } | 382 } |
394 *bytes_read = buf_size; | 383 return buf_size; |
395 } | 384 } |
396 | 385 |
397 void URLRequestChromeJob::CheckStoragePartitionMatches( | 386 void URLRequestChromeJob::CheckStoragePartitionMatches( |
398 int render_process_id, | 387 int render_process_id, |
399 const GURL& url, | 388 const GURL& url, |
400 const base::WeakPtr<URLRequestChromeJob>& job) { | 389 const base::WeakPtr<URLRequestChromeJob>& job) { |
401 // The embedder could put some webui pages in separate storage partition. | 390 // The embedder could put some webui pages in separate storage partition. |
402 // RenderProcessHostImpl::IsSuitableHost would guard against top level pages | 391 // RenderProcessHostImpl::IsSuitableHost would guard against top level pages |
403 // being in the same process. We do an extra check to guard against an | 392 // being in the same process. We do an extra check to guard against an |
404 // exploited renderer pretending to add them as a subframe. We skip this check | 393 // 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... |
775 | 764 |
776 } // namespace | 765 } // namespace |
777 | 766 |
778 net::URLRequestJobFactory::ProtocolHandler* | 767 net::URLRequestJobFactory::ProtocolHandler* |
779 CreateDevToolsProtocolHandler(content::ResourceContext* resource_context, | 768 CreateDevToolsProtocolHandler(content::ResourceContext* resource_context, |
780 bool is_incognito) { | 769 bool is_incognito) { |
781 return new DevToolsJobFactory(resource_context, is_incognito); | 770 return new DevToolsJobFactory(resource_context, is_incognito); |
782 } | 771 } |
783 | 772 |
784 } // namespace content | 773 } // namespace content |
OLD | NEW |