| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/extensions/chrome_url_request_util.h" | 5 #include "chrome/browser/extensions/chrome_url_request_util.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 weak_factory_(this) { | 54 weak_factory_(this) { |
| 55 // Leave cache headers out of resource bundle requests. | 55 // Leave cache headers out of resource bundle requests. |
| 56 response_info_.headers = extensions::BuildHttpHeaders( | 56 response_info_.headers = extensions::BuildHttpHeaders( |
| 57 content_security_policy, send_cors_header, base::Time()); | 57 content_security_policy, send_cors_header, base::Time()); |
| 58 } | 58 } |
| 59 | 59 |
| 60 // Overridden from URLRequestSimpleJob: | 60 // Overridden from URLRequestSimpleJob: |
| 61 virtual int GetData(std::string* mime_type, | 61 virtual int GetData(std::string* mime_type, |
| 62 std::string* charset, | 62 std::string* charset, |
| 63 std::string* data, | 63 std::string* data, |
| 64 const net::CompletionCallback& callback) const OVERRIDE { | 64 const net::CompletionCallback& callback) const override { |
| 65 const ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 65 const ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 66 *data = rb.GetRawDataResource(resource_id_).as_string(); | 66 *data = rb.GetRawDataResource(resource_id_).as_string(); |
| 67 | 67 |
| 68 // Add the Content-Length header now that we know the resource length. | 68 // Add the Content-Length header now that we know the resource length. |
| 69 response_info_.headers->AddHeader( | 69 response_info_.headers->AddHeader( |
| 70 base::StringPrintf("%s: %s", | 70 base::StringPrintf("%s: %s", |
| 71 net::HttpRequestHeaders::kContentLength, | 71 net::HttpRequestHeaders::kContentLength, |
| 72 base::UintToString(data->size()).c_str())); | 72 base::UintToString(data->size()).c_str())); |
| 73 | 73 |
| 74 std::string* read_mime_type = new std::string; | 74 std::string* read_mime_type = new std::string; |
| 75 bool posted = base::PostTaskAndReplyWithResult( | 75 bool posted = base::PostTaskAndReplyWithResult( |
| 76 BrowserThread::GetBlockingPool(), | 76 BrowserThread::GetBlockingPool(), |
| 77 FROM_HERE, | 77 FROM_HERE, |
| 78 base::Bind(&net::GetMimeTypeFromFile, | 78 base::Bind(&net::GetMimeTypeFromFile, |
| 79 filename_, | 79 filename_, |
| 80 base::Unretained(read_mime_type)), | 80 base::Unretained(read_mime_type)), |
| 81 base::Bind(&URLRequestResourceBundleJob::OnMimeTypeRead, | 81 base::Bind(&URLRequestResourceBundleJob::OnMimeTypeRead, |
| 82 weak_factory_.GetWeakPtr(), | 82 weak_factory_.GetWeakPtr(), |
| 83 mime_type, | 83 mime_type, |
| 84 charset, | 84 charset, |
| 85 data, | 85 data, |
| 86 base::Owned(read_mime_type), | 86 base::Owned(read_mime_type), |
| 87 callback)); | 87 callback)); |
| 88 DCHECK(posted); | 88 DCHECK(posted); |
| 89 | 89 |
| 90 return net::ERR_IO_PENDING; | 90 return net::ERR_IO_PENDING; |
| 91 } | 91 } |
| 92 | 92 |
| 93 virtual void GetResponseInfo(net::HttpResponseInfo* info) OVERRIDE { | 93 virtual void GetResponseInfo(net::HttpResponseInfo* info) override { |
| 94 *info = response_info_; | 94 *info = response_info_; |
| 95 } | 95 } |
| 96 | 96 |
| 97 private: | 97 private: |
| 98 virtual ~URLRequestResourceBundleJob() {} | 98 virtual ~URLRequestResourceBundleJob() {} |
| 99 | 99 |
| 100 void OnMimeTypeRead(std::string* out_mime_type, | 100 void OnMimeTypeRead(std::string* out_mime_type, |
| 101 std::string* charset, | 101 std::string* charset, |
| 102 std::string* data, | 102 std::string* data, |
| 103 std::string* read_mime_type, | 103 std::string* read_mime_type, |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 resource_id, | 183 resource_id, |
| 184 content_security_policy, | 184 content_security_policy, |
| 185 send_cors_header); | 185 send_cors_header); |
| 186 } | 186 } |
| 187 } | 187 } |
| 188 return NULL; | 188 return NULL; |
| 189 } | 189 } |
| 190 | 190 |
| 191 } // namespace chrome_url_request_util | 191 } // namespace chrome_url_request_util |
| 192 } // namespace extensions | 192 } // namespace extensions |
| OLD | NEW |