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