| OLD | NEW |
| 1 // Copyright (c) 2011 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 // 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 |
| 11 // * Firefox 2: Render as HTML | 11 // * Firefox 2: Render as HTML |
| (...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 } | 560 } |
| 561 | 561 |
| 562 return true; | 562 return true; |
| 563 } | 563 } |
| 564 | 564 |
| 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 | |
| 571 bool sniffable_scheme = url.is_empty() || | 570 bool sniffable_scheme = url.is_empty() || |
| 572 url.SchemeIs("http") || | 571 url.SchemeIs("http") || |
| 573 url.SchemeIs("https") || | 572 url.SchemeIs("https") || |
| 574 url.SchemeIs("ftp") || | 573 url.SchemeIs("ftp") || |
| 575 url.SchemeIsFile(); | 574 url.SchemeIsFile() || |
| 575 url.SchemeIsFileSystem(); |
| 576 if (!sniffable_scheme) { | 576 if (!sniffable_scheme) { |
| 577 should_sniff_counter->Add(1); | 577 should_sniff_counter->Add(1); |
| 578 return false; | 578 return false; |
| 579 } | 579 } |
| 580 | 580 |
| 581 static const char* kSniffableTypes[] = { | 581 static const char* kSniffableTypes[] = { |
| 582 // Many web servers are misconfigured to send text/plain for many | 582 // Many web servers are misconfigured to send text/plain for many |
| 583 // different types of content. | 583 // different types of content. |
| 584 "text/plain", | 584 "text/plain", |
| 585 // We want to sniff application/octet-stream for | 585 // 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 | 680 // Now we look in our large table of magic numbers to see if we can find |
| 681 // anything that matches the content. | 681 // anything that matches the content. |
| 682 if (SniffForMagicNumbers(content, content_size, | 682 if (SniffForMagicNumbers(content, content_size, |
| 683 &have_enough_content, result)) | 683 &have_enough_content, result)) |
| 684 return true; // We've matched a magic number. No more content needed. | 684 return true; // We've matched a magic number. No more content needed. |
| 685 | 685 |
| 686 return have_enough_content; | 686 return have_enough_content; |
| 687 } | 687 } |
| 688 | 688 |
| 689 } // namespace net | 689 } // namespace net |
| OLD | NEW |