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

Unified Diff: third_party/WebKit/Source/platform/text/TextEncodingDetector.cpp

Issue 2784483003: Respect UTF-8 detection result for local file resources (Closed)
Patch Set: Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/platform/text/TextEncodingDetectorTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/platform/text/TextEncodingDetector.cpp
diff --git a/third_party/WebKit/Source/platform/text/TextEncodingDetector.cpp b/third_party/WebKit/Source/platform/text/TextEncodingDetector.cpp
index e31947b91d2ec5e769434ce48e6cc643c9601836..0df2c620e0fe2dd69f41e41fe1c65baf678adc55 100644
--- a/third_party/WebKit/Source/platform/text/TextEncodingDetector.cpp
+++ b/third_party/WebKit/Source/platform/text/TextEncodingDetector.cpp
@@ -30,6 +30,7 @@
#include "platform/text/TextEncodingDetector.h"
+#include "platform/weborigin/KURL.h"
#include "third_party/ced/src/compact_enc_det/compact_enc_det.h"
#include "wtf/text/TextEncoding.h"
@@ -56,10 +57,12 @@ bool detectTextEncoding(const char* data,
// Should return false if the detected encoding is UTF8. This helps prevent
// modern web sites from neglecting proper encoding labelling and simply
// relying on browser-side encoding detection. Encoding detection is supposed
- // to work for web sites with legacy encoding only. Detection failure leads
- // |TextResourceDecoder| to use its default encoding determined from system
- // locale or TLD.
- if (encoding == UNKNOWN_ENCODING || encoding == UTF8)
+ // to work for web sites with legacy encoding only (so this doesn't have to
+ // be applied to local file resources).
+ // Detection failure leads |TextResourceDecoder| to use its default encoding
+ // determined from system locale or TLD.
+ String protocol = hintUrl ? KURL(ParsedURLString, hintUrl).protocol() : "";
+ if (encoding == UNKNOWN_ENCODING || (protocol != "file" && encoding == UTF8))
return false;
*detectedEncoding = WTF::TextEncoding(MimeEncodingName(encoding));
« no previous file with comments | « no previous file | third_party/WebKit/Source/platform/text/TextEncodingDetectorTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698