Chromium Code Reviews| 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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 162 class URLRequestExtensionJob : public net::URLRequestFileJob { | 162 class URLRequestExtensionJob : public net::URLRequestFileJob { |
| 163 public: | 163 public: |
| 164 URLRequestExtensionJob(net::URLRequest* request, | 164 URLRequestExtensionJob(net::URLRequest* request, |
| 165 net::NetworkDelegate* network_delegate, | 165 net::NetworkDelegate* network_delegate, |
| 166 const std::string& extension_id, | 166 const std::string& extension_id, |
| 167 const base::FilePath& directory_path, | 167 const base::FilePath& directory_path, |
| 168 const base::FilePath& relative_path, | 168 const base::FilePath& relative_path, |
| 169 const std::string& content_security_policy, | 169 const std::string& content_security_policy, |
| 170 bool send_cors_header, | 170 bool send_cors_header, |
| 171 bool follow_symlinks_anywhere, | 171 bool follow_symlinks_anywhere, |
| 172 ContentVerifyJob* verify_job) | 172 ContentVerifier* verifier) |
| 173 : net::URLRequestFileJob( | 173 : net::URLRequestFileJob( |
| 174 request, | 174 request, |
| 175 network_delegate, | 175 network_delegate, |
| 176 base::FilePath(), | 176 base::FilePath(), |
| 177 BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior( | 177 BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior( |
| 178 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)), | 178 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)), |
| 179 verify_job_(verify_job), | 179 verifier_(verifier), |
| 180 seek_position_(0), | 180 seek_position_(0), |
| 181 bytes_read_(0), | 181 bytes_read_(0), |
| 182 directory_path_(directory_path), | 182 directory_path_(directory_path), |
| 183 // TODO(tc): Move all of these files into resources.pak so we don't | 183 // TODO(tc): Move all of these files into resources.pak so we don't |
| 184 // break when updating on Linux. | 184 // break when updating on Linux. |
| 185 resource_(extension_id, directory_path, relative_path), | 185 resource_(extension_id, directory_path, relative_path), |
| 186 content_security_policy_(content_security_policy), | 186 content_security_policy_(content_security_policy), |
| 187 send_cors_header_(send_cors_header), | 187 send_cors_header_(send_cors_header), |
| 188 weak_factory_(this) { | 188 weak_factory_(this) { |
| 189 if (follow_symlinks_anywhere) { | 189 if (follow_symlinks_anywhere) { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 255 UMA_HISTOGRAM_COUNTS("ExtensionUrlRequest.TotalKbRead", bytes_read_ / 1024); | 255 UMA_HISTOGRAM_COUNTS("ExtensionUrlRequest.TotalKbRead", bytes_read_ / 1024); |
| 256 UMA_HISTOGRAM_COUNTS("ExtensionUrlRequest.SeekPosition", seek_position_); | 256 UMA_HISTOGRAM_COUNTS("ExtensionUrlRequest.SeekPosition", seek_position_); |
| 257 if (request_timer_.get()) | 257 if (request_timer_.get()) |
| 258 UMA_HISTOGRAM_TIMES("ExtensionUrlRequest.Latency", | 258 UMA_HISTOGRAM_TIMES("ExtensionUrlRequest.Latency", |
| 259 request_timer_->Elapsed()); | 259 request_timer_->Elapsed()); |
| 260 } | 260 } |
| 261 | 261 |
| 262 void OnFilePathAndLastModifiedTimeRead(base::FilePath* read_file_path, | 262 void OnFilePathAndLastModifiedTimeRead(base::FilePath* read_file_path, |
| 263 base::Time* last_modified_time) { | 263 base::Time* last_modified_time) { |
| 264 file_path_ = *read_file_path; | 264 file_path_ = *read_file_path; |
| 265 if (verifier_.get()) { | |
| 266 // On case-insentivie filesystems, the relative path we got passed in at | |
| 267 // construction time might differ in case from the actual filename on | |
| 268 // disk, but we want to use the actual filename for content verification | |
| 269 // purposes. | |
| 270 base::FilePath actual_relative_path; | |
| 271 directory_path_.AppendRelativePath(file_path_, &actual_relative_path); | |
|
Ken Rockot(use gerrit already)
2014/09/19 18:03:05
It looks like this may not actually work on Window
| |
| 272 verify_job_ = verifier_->CreateJobFor( | |
| 273 resource_.extension_id(), directory_path_, actual_relative_path); | |
| 274 if (verify_job_.get()) | |
| 275 verify_job_->Start(); | |
| 276 verifier_ = NULL; | |
| 277 } | |
| 265 response_info_.headers = BuildHttpHeaders( | 278 response_info_.headers = BuildHttpHeaders( |
| 266 content_security_policy_, | 279 content_security_policy_, |
| 267 send_cors_header_, | 280 send_cors_header_, |
| 268 *last_modified_time); | 281 *last_modified_time); |
| 269 URLRequestFileJob::Start(); | 282 URLRequestFileJob::Start(); |
| 270 } | 283 } |
| 271 | 284 |
| 285 scoped_refptr<ContentVerifier> verifier_; | |
| 272 scoped_refptr<ContentVerifyJob> verify_job_; | 286 scoped_refptr<ContentVerifyJob> verify_job_; |
| 273 | 287 |
| 274 scoped_ptr<base::ElapsedTimer> request_timer_; | 288 scoped_ptr<base::ElapsedTimer> request_timer_; |
| 275 | 289 |
| 276 // The position we seeked to in the file. | 290 // The position we seeked to in the file. |
| 277 int64 seek_position_; | 291 int64 seek_position_; |
| 278 | 292 |
| 279 // The number of bytes of content we read from the file. | 293 // The number of bytes of content we read from the file. |
| 280 int bytes_read_; | 294 int bytes_read_; |
| 281 | 295 |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 501 new_extension && | 515 new_extension && |
| 502 (first_party_in_import || | 516 (first_party_in_import || |
| 503 SharedModuleInfo::IsExportAllowed(new_extension, new_relative_path))) { | 517 SharedModuleInfo::IsExportAllowed(new_extension, new_relative_path))) { |
| 504 directory_path = new_extension->path(); | 518 directory_path = new_extension->path(); |
| 505 extension_id = new_extension_id; | 519 extension_id = new_extension_id; |
| 506 relative_path = base::FilePath::FromUTF8Unsafe(new_relative_path); | 520 relative_path = base::FilePath::FromUTF8Unsafe(new_relative_path); |
| 507 } else { | 521 } else { |
| 508 return NULL; | 522 return NULL; |
| 509 } | 523 } |
| 510 } | 524 } |
| 511 ContentVerifyJob* verify_job = NULL; | |
| 512 ContentVerifier* verifier = extension_info_map_->content_verifier(); | 525 ContentVerifier* verifier = extension_info_map_->content_verifier(); |
| 513 if (verifier) { | |
| 514 verify_job = | |
| 515 verifier->CreateJobFor(extension_id, directory_path, relative_path); | |
| 516 if (verify_job) | |
| 517 verify_job->Start(); | |
| 518 } | |
| 519 | |
| 520 return new URLRequestExtensionJob(request, | 526 return new URLRequestExtensionJob(request, |
| 521 network_delegate, | 527 network_delegate, |
| 522 extension_id, | 528 extension_id, |
| 523 directory_path, | 529 directory_path, |
| 524 relative_path, | 530 relative_path, |
| 525 content_security_policy, | 531 content_security_policy, |
| 526 send_cors_header, | 532 send_cors_header, |
| 527 follow_symlinks_anywhere, | 533 follow_symlinks_anywhere, |
| 528 verify_job); | 534 verifier); |
| 529 } | 535 } |
| 530 | 536 |
| 531 } // namespace | 537 } // namespace |
| 532 | 538 |
| 533 net::HttpResponseHeaders* BuildHttpHeaders( | 539 net::HttpResponseHeaders* BuildHttpHeaders( |
| 534 const std::string& content_security_policy, | 540 const std::string& content_security_policy, |
| 535 bool send_cors_header, | 541 bool send_cors_header, |
| 536 const base::Time& last_modified_time) { | 542 const base::Time& last_modified_time) { |
| 537 std::string raw_headers; | 543 std::string raw_headers; |
| 538 raw_headers.append("HTTP/1.1 200 OK"); | 544 raw_headers.append("HTTP/1.1 200 OK"); |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 568 return new net::HttpResponseHeaders(raw_headers); | 574 return new net::HttpResponseHeaders(raw_headers); |
| 569 } | 575 } |
| 570 | 576 |
| 571 net::URLRequestJobFactory::ProtocolHandler* CreateExtensionProtocolHandler( | 577 net::URLRequestJobFactory::ProtocolHandler* CreateExtensionProtocolHandler( |
| 572 bool is_incognito, | 578 bool is_incognito, |
| 573 extensions::InfoMap* extension_info_map) { | 579 extensions::InfoMap* extension_info_map) { |
| 574 return new ExtensionProtocolHandler(is_incognito, extension_info_map); | 580 return new ExtensionProtocolHandler(is_incognito, extension_info_map); |
| 575 } | 581 } |
| 576 | 582 |
| 577 } // namespace extensions | 583 } // namespace extensions |
| OLD | NEW |