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 "extensions/browser/extension_protocols.h" | 5 #include "extensions/browser/extension_protocols.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 // Leave cache headers out of generated background page jobs. | 79 // Leave cache headers out of generated background page jobs. |
80 response_info_.headers = BuildHttpHeaders(content_security_policy, | 80 response_info_.headers = BuildHttpHeaders(content_security_policy, |
81 send_cors_headers, | 81 send_cors_headers, |
82 base::Time()); | 82 base::Time()); |
83 } | 83 } |
84 | 84 |
85 // Overridden from URLRequestSimpleJob: | 85 // Overridden from URLRequestSimpleJob: |
86 virtual int GetData(std::string* mime_type, | 86 virtual int GetData(std::string* mime_type, |
87 std::string* charset, | 87 std::string* charset, |
88 std::string* data, | 88 std::string* data, |
89 const net::CompletionCallback& callback) const OVERRIDE { | 89 const net::CompletionCallback& callback) const override { |
90 *mime_type = "text/html"; | 90 *mime_type = "text/html"; |
91 *charset = "utf-8"; | 91 *charset = "utf-8"; |
92 | 92 |
93 *data = "<!DOCTYPE html>\n<body>\n"; | 93 *data = "<!DOCTYPE html>\n<body>\n"; |
94 const std::vector<std::string>& background_scripts = | 94 const std::vector<std::string>& background_scripts = |
95 extensions::BackgroundInfo::GetBackgroundScripts(extension_.get()); | 95 extensions::BackgroundInfo::GetBackgroundScripts(extension_.get()); |
96 for (size_t i = 0; i < background_scripts.size(); ++i) { | 96 for (size_t i = 0; i < background_scripts.size(); ++i) { |
97 *data += "<script src=\""; | 97 *data += "<script src=\""; |
98 *data += background_scripts[i]; | 98 *data += background_scripts[i]; |
99 *data += "\"></script>\n"; | 99 *data += "\"></script>\n"; |
100 } | 100 } |
101 | 101 |
102 return net::OK; | 102 return net::OK; |
103 } | 103 } |
104 | 104 |
105 virtual void GetResponseInfo(net::HttpResponseInfo* info) OVERRIDE { | 105 virtual void GetResponseInfo(net::HttpResponseInfo* info) override { |
106 *info = response_info_; | 106 *info = response_info_; |
107 } | 107 } |
108 | 108 |
109 private: | 109 private: |
110 virtual ~GeneratedBackgroundPageJob() {} | 110 virtual ~GeneratedBackgroundPageJob() {} |
111 | 111 |
112 scoped_refptr<const Extension> extension_; | 112 scoped_refptr<const Extension> extension_; |
113 net::HttpResponseInfo response_info_; | 113 net::HttpResponseInfo response_info_; |
114 }; | 114 }; |
115 | 115 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 // break when updating on Linux. | 185 // break when updating on Linux. |
186 resource_(extension_id, directory_path, relative_path), | 186 resource_(extension_id, directory_path, relative_path), |
187 content_security_policy_(content_security_policy), | 187 content_security_policy_(content_security_policy), |
188 send_cors_header_(send_cors_header), | 188 send_cors_header_(send_cors_header), |
189 weak_factory_(this) { | 189 weak_factory_(this) { |
190 if (follow_symlinks_anywhere) { | 190 if (follow_symlinks_anywhere) { |
191 resource_.set_follow_symlinks_anywhere(); | 191 resource_.set_follow_symlinks_anywhere(); |
192 } | 192 } |
193 } | 193 } |
194 | 194 |
195 virtual void GetResponseInfo(net::HttpResponseInfo* info) OVERRIDE { | 195 virtual void GetResponseInfo(net::HttpResponseInfo* info) override { |
196 *info = response_info_; | 196 *info = response_info_; |
197 } | 197 } |
198 | 198 |
199 virtual void Start() OVERRIDE { | 199 virtual void Start() override { |
200 request_timer_.reset(new base::ElapsedTimer()); | 200 request_timer_.reset(new base::ElapsedTimer()); |
201 base::FilePath* read_file_path = new base::FilePath; | 201 base::FilePath* read_file_path = new base::FilePath; |
202 base::Time* last_modified_time = new base::Time(); | 202 base::Time* last_modified_time = new base::Time(); |
203 bool posted = BrowserThread::PostBlockingPoolTaskAndReply( | 203 bool posted = BrowserThread::PostBlockingPoolTaskAndReply( |
204 FROM_HERE, | 204 FROM_HERE, |
205 base::Bind(&ReadResourceFilePathAndLastModifiedTime, | 205 base::Bind(&ReadResourceFilePathAndLastModifiedTime, |
206 resource_, | 206 resource_, |
207 directory_path_, | 207 directory_path_, |
208 base::Unretained(read_file_path), | 208 base::Unretained(read_file_path), |
209 base::Unretained(last_modified_time)), | 209 base::Unretained(last_modified_time)), |
210 base::Bind(&URLRequestExtensionJob::OnFilePathAndLastModifiedTimeRead, | 210 base::Bind(&URLRequestExtensionJob::OnFilePathAndLastModifiedTimeRead, |
211 weak_factory_.GetWeakPtr(), | 211 weak_factory_.GetWeakPtr(), |
212 base::Owned(read_file_path), | 212 base::Owned(read_file_path), |
213 base::Owned(last_modified_time))); | 213 base::Owned(last_modified_time))); |
214 DCHECK(posted); | 214 DCHECK(posted); |
215 } | 215 } |
216 | 216 |
217 virtual void SetExtraRequestHeaders( | 217 virtual void SetExtraRequestHeaders( |
218 const net::HttpRequestHeaders& headers) OVERRIDE { | 218 const net::HttpRequestHeaders& headers) override { |
219 // TODO(asargent) - we'll need to add proper support for range headers. | 219 // TODO(asargent) - we'll need to add proper support for range headers. |
220 // crbug.com/369895. | 220 // crbug.com/369895. |
221 std::string range_header; | 221 std::string range_header; |
222 if (headers.GetHeader(net::HttpRequestHeaders::kRange, &range_header)) { | 222 if (headers.GetHeader(net::HttpRequestHeaders::kRange, &range_header)) { |
223 if (verify_job_.get()) | 223 if (verify_job_.get()) |
224 verify_job_ = NULL; | 224 verify_job_ = NULL; |
225 } | 225 } |
226 URLRequestFileJob::SetExtraRequestHeaders(headers); | 226 URLRequestFileJob::SetExtraRequestHeaders(headers); |
227 } | 227 } |
228 | 228 |
229 virtual void OnSeekComplete(int64 result) OVERRIDE { | 229 virtual void OnSeekComplete(int64 result) override { |
230 DCHECK_EQ(seek_position_, 0); | 230 DCHECK_EQ(seek_position_, 0); |
231 seek_position_ = result; | 231 seek_position_ = result; |
232 // TODO(asargent) - we'll need to add proper support for range headers. | 232 // TODO(asargent) - we'll need to add proper support for range headers. |
233 // crbug.com/369895. | 233 // crbug.com/369895. |
234 if (result > 0 && verify_job_.get()) | 234 if (result > 0 && verify_job_.get()) |
235 verify_job_ = NULL; | 235 verify_job_ = NULL; |
236 } | 236 } |
237 | 237 |
238 virtual void OnReadComplete(net::IOBuffer* buffer, int result) OVERRIDE { | 238 virtual void OnReadComplete(net::IOBuffer* buffer, int result) override { |
239 if (result >= 0) | 239 if (result >= 0) |
240 UMA_HISTOGRAM_COUNTS("ExtensionUrlRequest.OnReadCompleteResult", result); | 240 UMA_HISTOGRAM_COUNTS("ExtensionUrlRequest.OnReadCompleteResult", result); |
241 else | 241 else |
242 UMA_HISTOGRAM_SPARSE_SLOWLY("ExtensionUrlRequest.OnReadCompleteError", | 242 UMA_HISTOGRAM_SPARSE_SLOWLY("ExtensionUrlRequest.OnReadCompleteError", |
243 -result); | 243 -result); |
244 if (result > 0) { | 244 if (result > 0) { |
245 bytes_read_ += result; | 245 bytes_read_ += result; |
246 if (verify_job_.get()) { | 246 if (verify_job_.get()) { |
247 verify_job_->BytesRead(result, buffer->data()); | 247 verify_job_->BytesRead(result, buffer->data()); |
248 if (!remaining_bytes()) | 248 if (!remaining_bytes()) |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 : public net::URLRequestJobFactory::ProtocolHandler { | 376 : public net::URLRequestJobFactory::ProtocolHandler { |
377 public: | 377 public: |
378 ExtensionProtocolHandler(bool is_incognito, | 378 ExtensionProtocolHandler(bool is_incognito, |
379 extensions::InfoMap* extension_info_map) | 379 extensions::InfoMap* extension_info_map) |
380 : is_incognito_(is_incognito), extension_info_map_(extension_info_map) {} | 380 : is_incognito_(is_incognito), extension_info_map_(extension_info_map) {} |
381 | 381 |
382 virtual ~ExtensionProtocolHandler() {} | 382 virtual ~ExtensionProtocolHandler() {} |
383 | 383 |
384 virtual net::URLRequestJob* MaybeCreateJob( | 384 virtual net::URLRequestJob* MaybeCreateJob( |
385 net::URLRequest* request, | 385 net::URLRequest* request, |
386 net::NetworkDelegate* network_delegate) const OVERRIDE; | 386 net::NetworkDelegate* network_delegate) const override; |
387 | 387 |
388 private: | 388 private: |
389 const bool is_incognito_; | 389 const bool is_incognito_; |
390 extensions::InfoMap* const extension_info_map_; | 390 extensions::InfoMap* const extension_info_map_; |
391 DISALLOW_COPY_AND_ASSIGN(ExtensionProtocolHandler); | 391 DISALLOW_COPY_AND_ASSIGN(ExtensionProtocolHandler); |
392 }; | 392 }; |
393 | 393 |
394 // Creates URLRequestJobs for extension:// URLs. | 394 // Creates URLRequestJobs for extension:// URLs. |
395 net::URLRequestJob* | 395 net::URLRequestJob* |
396 ExtensionProtocolHandler::MaybeCreateJob( | 396 ExtensionProtocolHandler::MaybeCreateJob( |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
569 return new net::HttpResponseHeaders(raw_headers); | 569 return new net::HttpResponseHeaders(raw_headers); |
570 } | 570 } |
571 | 571 |
572 net::URLRequestJobFactory::ProtocolHandler* CreateExtensionProtocolHandler( | 572 net::URLRequestJobFactory::ProtocolHandler* CreateExtensionProtocolHandler( |
573 bool is_incognito, | 573 bool is_incognito, |
574 extensions::InfoMap* extension_info_map) { | 574 extensions::InfoMap* extension_info_map) { |
575 return new ExtensionProtocolHandler(is_incognito, extension_info_map); | 575 return new ExtensionProtocolHandler(is_incognito, extension_info_map); |
576 } | 576 } |
577 | 577 |
578 } // namespace extensions | 578 } // namespace extensions |
OLD | NEW |