OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // Detecting mime types is a tricky business because we need to balance | 5 // Detecting mime types is a tricky business because we need to balance |
6 // compatibility concerns with security issues. Here is a survey of how other | 6 // compatibility concerns with security issues. Here is a survey of how other |
7 // browsers behave and then a description of how we intend to behave. | 7 // browsers behave and then a description of how we intend to behave. |
8 // | 8 // |
9 // HTML payload, no Content-Type header: | 9 // HTML payload, no Content-Type header: |
10 // * IE 7: Render as HTML | 10 // * IE 7: Render as HTML |
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
565 bool ShouldSniffMimeType(const GURL& url, const std::string& mime_type) { | 565 bool ShouldSniffMimeType(const GURL& url, const std::string& mime_type) { |
566 static base::Histogram* should_sniff_counter(NULL); | 566 static base::Histogram* should_sniff_counter(NULL); |
567 if (!should_sniff_counter) | 567 if (!should_sniff_counter) |
568 should_sniff_counter = | 568 should_sniff_counter = |
569 UMASnifferHistogramGet("mime_sniffer.ShouldSniffMimeType2", 3); | 569 UMASnifferHistogramGet("mime_sniffer.ShouldSniffMimeType2", 3); |
570 // We are willing to sniff the mime type for HTTP, HTTPS, and FTP | 570 // We are willing to sniff the mime type for HTTP, HTTPS, and FTP |
571 bool sniffable_scheme = url.is_empty() || | 571 bool sniffable_scheme = url.is_empty() || |
572 url.SchemeIs("http") || | 572 url.SchemeIs("http") || |
573 url.SchemeIs("https") || | 573 url.SchemeIs("https") || |
574 url.SchemeIs("ftp") || | 574 url.SchemeIs("ftp") || |
575 url.SchemeIsFile(); | 575 url.SchemeIsFile() || |
| 576 url.SchemeIsFileSystem(); |
576 if (!sniffable_scheme) { | 577 if (!sniffable_scheme) { |
577 should_sniff_counter->Add(1); | 578 should_sniff_counter->Add(1); |
578 return false; | 579 return false; |
579 } | 580 } |
580 | 581 |
581 static const char* kSniffableTypes[] = { | 582 static const char* kSniffableTypes[] = { |
582 // Many web servers are misconfigured to send text/plain for many | 583 // Many web servers are misconfigured to send text/plain for many |
583 // different types of content. | 584 // different types of content. |
584 "text/plain", | 585 "text/plain", |
585 // We want to sniff application/octet-stream for | 586 // We want to sniff application/octet-stream for |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
680 // Now we look in our large table of magic numbers to see if we can find | 681 // Now we look in our large table of magic numbers to see if we can find |
681 // anything that matches the content. | 682 // anything that matches the content. |
682 if (SniffForMagicNumbers(content, content_size, | 683 if (SniffForMagicNumbers(content, content_size, |
683 &have_enough_content, result)) | 684 &have_enough_content, result)) |
684 return true; // We've matched a magic number. No more content needed. | 685 return true; // We've matched a magic number. No more content needed. |
685 | 686 |
686 return have_enough_content; | 687 return have_enough_content; |
687 } | 688 } |
688 | 689 |
689 } // namespace net | 690 } // namespace net |
OLD | NEW |