| 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 // Simple implementation of a data: protocol handler. | 5 // Simple implementation of a data: protocol handler. |
| 6 | 6 |
| 7 #include "net/url_request/url_request_data_job.h" | 7 #include "net/url_request/url_request_data_job.h" |
| 8 | 8 |
| 9 #include "net/base/data_url.h" | 9 #include "net/base/data_url.h" |
| 10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
| 11 | 11 |
| 12 namespace net { | 12 namespace net { |
| 13 | 13 |
| 14 URLRequestDataJob::URLRequestDataJob( | 14 URLRequestDataJob::URLRequestDataJob( |
| 15 URLRequest* request, NetworkDelegate* network_delegate) | 15 URLRequest* request, NetworkDelegate* network_delegate) |
| 16 : URLRequestSimpleJob(request, network_delegate) { | 16 : URLRequestSimpleJob(request, network_delegate) { |
| 17 } | 17 } |
| 18 | 18 |
| 19 // static | |
| 20 URLRequestJob* URLRequestDataJob::Factory(URLRequest* request, | |
| 21 NetworkDelegate* network_delegate, | |
| 22 const std::string& scheme) { | |
| 23 return new URLRequestDataJob(request, network_delegate); | |
| 24 } | |
| 25 | |
| 26 int URLRequestDataJob::GetData(std::string* mime_type, | 19 int URLRequestDataJob::GetData(std::string* mime_type, |
| 27 std::string* charset, | 20 std::string* charset, |
| 28 std::string* data, | 21 std::string* data, |
| 29 const CompletionCallback& callback) const { | 22 const CompletionCallback& callback) const { |
| 30 // Check if data URL is valid. If not, don't bother to try to extract data. | 23 // Check if data URL is valid. If not, don't bother to try to extract data. |
| 31 // Otherwise, parse the data from the data URL. | 24 // Otherwise, parse the data from the data URL. |
| 32 const GURL& url = request_->url(); | 25 const GURL& url = request_->url(); |
| 33 if (!url.is_valid()) | 26 if (!url.is_valid()) |
| 34 return ERR_INVALID_URL; | 27 return ERR_INVALID_URL; |
| 35 return DataURL::Parse(url, mime_type, charset, data)? OK: ERR_INVALID_URL; | 28 return DataURL::Parse(url, mime_type, charset, data)? OK: ERR_INVALID_URL; |
| 36 } | 29 } |
| 37 | 30 |
| 38 URLRequestDataJob::~URLRequestDataJob() { | 31 URLRequestDataJob::~URLRequestDataJob() { |
| 39 } | 32 } |
| 40 | 33 |
| 41 } // namespace net | 34 } // namespace net |
| OLD | NEW |