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

Unified Diff: third_party/WebKit/Source/web/WebViewImpl.cpp

Issue 1456843002: Finch experiment: auto-detect text encoding (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed comments Created 5 years 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
Index: third_party/WebKit/Source/web/WebViewImpl.cpp
diff --git a/third_party/WebKit/Source/web/WebViewImpl.cpp b/third_party/WebKit/Source/web/WebViewImpl.cpp
index f0b52156a097b64d3bc91f5541a8ebd9d36d913d..4139f1e6be9e451384a6056e339810459daafa64 100644
--- a/third_party/WebKit/Source/web/WebViewImpl.cpp
+++ b/third_party/WebKit/Source/web/WebViewImpl.cpp
@@ -323,6 +323,69 @@ private:
WebColor m_color;
};
+#if OS(ANDROID)
+// Array used to convert canonical encoding method name to index to be
+// uploaded to UMA for the experiment on text encoding auto detection.
+// The listed order should be in sync with the enum definition 'EncodingMethod'
+// in tools/metrics/histograms/histograms.xml.
+static const char* kEncodingNames[] = {
+ "UNKNOWN",
+ "Big5",
+ "EUC-JP",
+ "EUC-KR",
+ "GBK",
+ "IBM866",
+ "ISO-2022-JP",
+ "ISO-8859-10",
+ "ISO-8859-13",
+ "ISO-8859-14",
+ "ISO-8859-15",
+ "ISO-8859-16",
+ "ISO-8859-2",
+ "ISO-8859-3",
+ "ISO-8859-4",
+ "ISO-8859-5",
+ "ISO-8859-6",
+ "ISO-8859-7",
+ "ISO-8859-8",
+ "ISO-8859-8-I",
+ "KOI8-R",
+ "KOI8-U",
+ "Shift_JIS",
+ "UTF-16LE",
+ "UTF-8",
+ "gb18030",
+ "macintosh",
+ "windows-1250",
+ "windows-1251",
+ "windows-1252",
+ "windows-1253",
+ "windows-1254",
+ "windows-1255",
+ "windows-1256",
+ "windows-1257",
+ "windows-1258",
+ "windows-874"
+};
+
+// Returns the index of the entry in the array that matches
+// the given encoding method.
+static int encodingToUmaId(const WTF::TextEncoding& encoding)
+{
+ const char* encodingName = encoding.name();
+ for (size_t i = 0; i < WTF_ARRAY_LENGTH(kEncodingNames); ++i) {
+ if (!strcasecmp(kEncodingNames[i], encodingName))
+ return i;
+ }
+ return 0;
+}
+
+static bool isInternalURL(const KURL& url)
+{
+ const String& protocol = url.protocol();
+ return protocol == "chrome" || protocol == "chrome-native" || protocol == "swappedout";
+}
+#endif
} // namespace
// WebView ----------------------------------------------------------------
@@ -3927,6 +3990,18 @@ void WebViewImpl::didFinishDocumentLoad(WebLocalFrameImpl* webframe)
if (webframe != mainFrameImpl())
return;
resumeTreeViewCommitsIfRenderingReady();
+#if OS(ANDROID)
+ if (!isInternalURL(webframe->frame()->document()->baseURL()) && page()->settings().usesEncodingDetector()) {
+ const Document& document = *webframe->frame()->document();
+
+ // "AutodetectEncoding.Attempted" is of boolean type - either 0 or 1. Use 2 for the boundary value.
+ Platform::current()->histogramEnumeration("AutodetectEncoding.Attempted", document.attemptedToDetermineEncodingFromContentSniffing(), 2);
+ if (document.encodingWasDetectedFromContentSniffing()) {
+ int encodingId = encodingToUmaId(document.encoding());
+ Platform::current()->histogramEnumeration("AutodetectEncoding.Detected", encodingId, WTF_ARRAY_LENGTH(kEncodingNames) + 1);
+ }
+ }
+#endif
}
void WebViewImpl::didRemoveAllPendingStylesheet(WebLocalFrameImpl* webframe)

Powered by Google App Engine
This is Rietveld 408576698