| 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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 headers.GetHeader(net::HttpRequestHeaders::kOrigin, &result); | 104 headers.GetHeader(net::HttpRequestHeaders::kOrigin, &result); |
| 105 return result; | 105 return result; |
| 106 } | 106 } |
| 107 | 107 |
| 108 } // namespace | 108 } // namespace |
| 109 | 109 |
| 110 // URLRequestChromeJob is a net::URLRequestJob that manages running | 110 // URLRequestChromeJob is a net::URLRequestJob that manages running |
| 111 // chrome-internal resource requests asynchronously. | 111 // chrome-internal resource requests asynchronously. |
| 112 // It hands off URL requests to ChromeURLDataManager, which asynchronously | 112 // It hands off URL requests to ChromeURLDataManager, which asynchronously |
| 113 // calls back once the data is available. | 113 // calls back once the data is available. |
| 114 class URLRequestChromeJob : public net::URLRequestJob { | 114 class URLRequestChromeJob : public net::URLRequestJob, |
| 115 public base::SupportsWeakPtr<URLRequestChromeJob> { |
| 115 public: | 116 public: |
| 116 // |is_incognito| set when job is generated from an incognito profile. | 117 // |is_incognito| set when job is generated from an incognito profile. |
| 117 URLRequestChromeJob(net::URLRequest* request, | 118 URLRequestChromeJob(net::URLRequest* request, |
| 118 net::NetworkDelegate* network_delegate, | 119 net::NetworkDelegate* network_delegate, |
| 119 URLDataManagerBackend* backend, | 120 URLDataManagerBackend* backend, |
| 120 bool is_incognito); | 121 bool is_incognito); |
| 121 | 122 |
| 122 // net::URLRequestJob implementation. | 123 // net::URLRequestJob implementation. |
| 123 void Start() override; | 124 void Start() override; |
| 124 void Kill() override; | 125 void Kill() override; |
| 125 bool ReadRawData(net::IOBuffer* buf, int buf_size, int* bytes_read) override; | 126 bool ReadRawData(net::IOBuffer* buf, int buf_size, int* bytes_read) override; |
| 126 bool GetMimeType(std::string* mime_type) const override; | 127 bool GetMimeType(std::string* mime_type) const override; |
| 127 int GetResponseCode() const override; | 128 int GetResponseCode() const override; |
| 128 void GetResponseInfo(net::HttpResponseInfo* info) override; | 129 void GetResponseInfo(net::HttpResponseInfo* info) override; |
| 129 | 130 |
| 130 // Used to notify that the requested data's |mime_type| is ready. | 131 // Used to notify that the requested data's |mime_type| is ready. |
| 131 void MimeTypeAvailable(const std::string& mime_type); | 132 void MimeTypeAvailable(const std::string& mime_type); |
| 132 | 133 |
| 133 // Called by ChromeURLDataManager to notify us that the data blob is ready | 134 // Called by ChromeURLDataManager to notify us that the data blob is ready |
| 134 // for us. | 135 // for us. |
| 135 void DataAvailable(base::RefCountedMemory* bytes); | 136 void DataAvailable(base::RefCountedMemory* bytes); |
| 136 | 137 |
| 137 // Returns a weak pointer to the job. | |
| 138 base::WeakPtr<URLRequestChromeJob> AsWeakPtr(); | |
| 139 | |
| 140 void set_mime_type(const std::string& mime_type) { | 138 void set_mime_type(const std::string& mime_type) { |
| 141 mime_type_ = mime_type; | 139 mime_type_ = mime_type; |
| 142 } | 140 } |
| 143 | 141 |
| 144 void set_allow_caching(bool allow_caching) { | 142 void set_allow_caching(bool allow_caching) { |
| 145 allow_caching_ = allow_caching; | 143 allow_caching_ = allow_caching; |
| 146 } | 144 } |
| 147 | 145 |
| 148 void set_add_content_security_policy(bool add_content_security_policy) { | 146 void set_add_content_security_policy(bool add_content_security_policy) { |
| 149 add_content_security_policy_ = add_content_security_policy; | 147 add_content_security_policy_ = add_content_security_policy; |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 void URLRequestChromeJob::Start() { | 260 void URLRequestChromeJob::Start() { |
| 263 int render_process_id, unused; | 261 int render_process_id, unused; |
| 264 bool is_renderer_request = ResourceRequestInfo::GetRenderFrameForRequest( | 262 bool is_renderer_request = ResourceRequestInfo::GetRenderFrameForRequest( |
| 265 request_, &render_process_id, &unused); | 263 request_, &render_process_id, &unused); |
| 266 if (!is_renderer_request) | 264 if (!is_renderer_request) |
| 267 render_process_id = kNoRenderProcessId; | 265 render_process_id = kNoRenderProcessId; |
| 268 BrowserThread::PostTask( | 266 BrowserThread::PostTask( |
| 269 BrowserThread::UI, | 267 BrowserThread::UI, |
| 270 FROM_HERE, | 268 FROM_HERE, |
| 271 base::Bind(&URLRequestChromeJob::CheckStoragePartitionMatches, | 269 base::Bind(&URLRequestChromeJob::CheckStoragePartitionMatches, |
| 272 render_process_id, request_->url(), | 270 render_process_id, request_->url(), AsWeakPtr())); |
| 273 weak_factory_.GetWeakPtr())); | |
| 274 TRACE_EVENT_ASYNC_BEGIN1("browser", "DataManager:Request", this, "URL", | 271 TRACE_EVENT_ASYNC_BEGIN1("browser", "DataManager:Request", this, "URL", |
| 275 request_->url().possibly_invalid_spec()); | 272 request_->url().possibly_invalid_spec()); |
| 276 } | 273 } |
| 277 | 274 |
| 278 void URLRequestChromeJob::Kill() { | 275 void URLRequestChromeJob::Kill() { |
| 279 weak_factory_.InvalidateWeakPtrs(); | |
| 280 backend_->RemoveRequest(this); | 276 backend_->RemoveRequest(this); |
| 281 URLRequestJob::Kill(); | |
| 282 } | 277 } |
| 283 | 278 |
| 284 bool URLRequestChromeJob::GetMimeType(std::string* mime_type) const { | 279 bool URLRequestChromeJob::GetMimeType(std::string* mime_type) const { |
| 285 *mime_type = mime_type_; | 280 *mime_type = mime_type_; |
| 286 return !mime_type_.empty(); | 281 return !mime_type_.empty(); |
| 287 } | 282 } |
| 288 | 283 |
| 289 int URLRequestChromeJob::GetResponseCode() const { | 284 int URLRequestChromeJob::GetResponseCode() const { |
| 290 return net::HTTP_OK; | 285 return net::HTTP_OK; |
| 291 } | 286 } |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 pending_buf_ = NULL; | 342 pending_buf_ = NULL; |
| 348 NotifyReadComplete(bytes_read); | 343 NotifyReadComplete(bytes_read); |
| 349 } | 344 } |
| 350 } else { | 345 } else { |
| 351 // The request failed. | 346 // The request failed. |
| 352 NotifyDone(net::URLRequestStatus(net::URLRequestStatus::FAILED, | 347 NotifyDone(net::URLRequestStatus(net::URLRequestStatus::FAILED, |
| 353 net::ERR_FAILED)); | 348 net::ERR_FAILED)); |
| 354 } | 349 } |
| 355 } | 350 } |
| 356 | 351 |
| 357 base::WeakPtr<URLRequestChromeJob> URLRequestChromeJob::AsWeakPtr() { | |
| 358 return weak_factory_.GetWeakPtr(); | |
| 359 } | |
| 360 | |
| 361 bool URLRequestChromeJob::ReadRawData(net::IOBuffer* buf, int buf_size, | 352 bool URLRequestChromeJob::ReadRawData(net::IOBuffer* buf, int buf_size, |
| 362 int* bytes_read) { | 353 int* bytes_read) { |
| 363 if (!data_.get()) { | 354 if (!data_.get()) { |
| 364 SetStatus(net::URLRequestStatus(net::URLRequestStatus::IO_PENDING, 0)); | 355 SetStatus(net::URLRequestStatus(net::URLRequestStatus::IO_PENDING, 0)); |
| 365 DCHECK(!pending_buf_.get()); | 356 DCHECK(!pending_buf_.get()); |
| 366 CHECK(buf->data()); | 357 CHECK(buf->data()); |
| 367 pending_buf_ = buf; | 358 pending_buf_ = buf; |
| 368 pending_buf_size_ = buf_size; | 359 pending_buf_size_ = buf_size; |
| 369 return false; // Tell the caller we're still waiting for data. | 360 return false; // Tell the caller we're still waiting for data. |
| 370 } | 361 } |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 773 | 764 |
| 774 } // namespace | 765 } // namespace |
| 775 | 766 |
| 776 net::URLRequestJobFactory::ProtocolHandler* | 767 net::URLRequestJobFactory::ProtocolHandler* |
| 777 CreateDevToolsProtocolHandler(content::ResourceContext* resource_context, | 768 CreateDevToolsProtocolHandler(content::ResourceContext* resource_context, |
| 778 bool is_incognito) { | 769 bool is_incognito) { |
| 779 return new DevToolsJobFactory(resource_context, is_incognito); | 770 return new DevToolsJobFactory(resource_context, is_incognito); |
| 780 } | 771 } |
| 781 | 772 |
| 782 } // namespace content | 773 } // namespace content |
| OLD | NEW |