Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(597)

Side by Side Diff: net/base/mime_sniffer.cc

Issue 23064011: Consolidate scheme checks into an easy GURL method (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/renderer/savable_resources.cc ('k') | net/base/network_change_notifier.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 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
(...skipping 786 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 return true; 797 return true;
798 } 798 }
799 799
800 bool ShouldSniffMimeType(const GURL& url, const std::string& mime_type) { 800 bool ShouldSniffMimeType(const GURL& url, const std::string& mime_type) {
801 static base::HistogramBase* should_sniff_counter(NULL); 801 static base::HistogramBase* should_sniff_counter(NULL);
802 if (!should_sniff_counter) { 802 if (!should_sniff_counter) {
803 should_sniff_counter = 803 should_sniff_counter =
804 UMASnifferHistogramGet("mime_sniffer.ShouldSniffMimeType2", 3); 804 UMASnifferHistogramGet("mime_sniffer.ShouldSniffMimeType2", 3);
805 } 805 }
806 bool sniffable_scheme = url.is_empty() || 806 bool sniffable_scheme = url.is_empty() ||
807 url.SchemeIs("http") || 807 url.SchemeIsHTTPOrHTTPS() ||
808 url.SchemeIs("https") ||
809 url.SchemeIs("ftp") || 808 url.SchemeIs("ftp") ||
810 #if defined(OS_ANDROID) 809 #if defined(OS_ANDROID)
811 url.SchemeIs("content") || 810 url.SchemeIs("content") ||
812 #endif 811 #endif
813 url.SchemeIsFile() || 812 url.SchemeIsFile() ||
814 url.SchemeIsFileSystem(); 813 url.SchemeIsFileSystem();
815 if (!sniffable_scheme) { 814 if (!sniffable_scheme) {
816 should_sniff_counter->Add(1); 815 should_sniff_counter->Add(1);
817 return false; 816 return false;
818 } 817 }
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
962 // First check the extra table. 961 // First check the extra table.
963 if (CheckForMagicNumbers(content, size, kExtraMagicNumbers, 962 if (CheckForMagicNumbers(content, size, kExtraMagicNumbers,
964 arraysize(kExtraMagicNumbers), NULL, result)) 963 arraysize(kExtraMagicNumbers), NULL, result))
965 return true; 964 return true;
966 // Finally check the original table. 965 // Finally check the original table.
967 return CheckForMagicNumbers(content, size, kMagicNumbers, 966 return CheckForMagicNumbers(content, size, kMagicNumbers,
968 arraysize(kMagicNumbers), NULL, result); 967 arraysize(kMagicNumbers), NULL, result);
969 } 968 }
970 969
971 } // namespace net 970 } // namespace net
OLDNEW
« no previous file with comments | « content/renderer/savable_resources.cc ('k') | net/base/network_change_notifier.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698