Bug 840476 - Add telemetry probe for character encoding override situation. r=smaug.

This commit is contained in:
Henri Sivonen 2013-02-28 10:44:57 +02:00
parent 2af3344a27
commit cdd62eee52
4 changed files with 86 additions and 1 deletions

View File

@ -5688,6 +5688,7 @@ function SelectDetector(event, doReload)
function BrowserSetForcedCharacterSet(aCharset)
{
gBrowser.docShell.gatherCharsetMenuTelemetry();
gBrowser.docShell.charset = aCharset;
// Save the forced character-set
if (!PrivateBrowsingUtils.isWindowPrivate(window))

View File

@ -1889,6 +1889,74 @@ nsDocShell::GetCharset(char** aCharset)
return NS_OK;
}
NS_IMETHODIMP
nsDocShell::GatherCharsetMenuTelemetry()
{
nsCOMPtr<nsIContentViewer> viewer;
GetContentViewer(getter_AddRefs(viewer));
if (!viewer) {
return NS_OK;
}
nsIDocument* doc = viewer->GetDocument();
if (!doc || doc->WillIgnoreCharsetOverride()) {
return NS_OK;
}
Telemetry::Accumulate(Telemetry::CHARSET_OVERRIDE_USED, true);
bool isFileURL = false;
nsIURI* url = doc->GetOriginalURI();
if (url) {
url->SchemeIs("file", &isFileURL);
}
int32_t charsetSource = doc->GetDocumentCharacterSetSource();
switch (charsetSource) {
case kCharsetFromWeakDocTypeDefault:
case kCharsetFromUserDefault:
case kCharsetFromDocTypeDefault:
case kCharsetFromCache:
case kCharsetFromParentFrame:
case kCharsetFromHintPrevDoc:
// Changing charset on an unlabeled doc.
if (isFileURL) {
Telemetry::Accumulate(Telemetry::CHARSET_OVERRIDE_SITUATION, 0);
} else {
Telemetry::Accumulate(Telemetry::CHARSET_OVERRIDE_SITUATION, 1);
}
break;
case kCharsetFromAutoDetection:
// Changing charset on unlabeled doc where chardet fired
if (isFileURL) {
Telemetry::Accumulate(Telemetry::CHARSET_OVERRIDE_SITUATION, 2);
} else {
Telemetry::Accumulate(Telemetry::CHARSET_OVERRIDE_SITUATION, 3);
}
break;
case kCharsetFromMetaPrescan:
case kCharsetFromMetaTag:
case kCharsetFromChannel:
// Changing charset on a doc that had a charset label.
Telemetry::Accumulate(Telemetry::CHARSET_OVERRIDE_SITUATION, 4);
break;
case kCharsetFromParentForced:
case kCharsetFromUserForced:
// Changing charset on a document that already had an override.
Telemetry::Accumulate(Telemetry::CHARSET_OVERRIDE_SITUATION, 5);
break;
case kCharsetFromIrreversibleAutoDetection:
case kCharsetFromOtherComponent:
case kCharsetFromByteOrderMark:
case kCharsetUninitialized:
default:
// Bug. This isn't supposed to happen.
Telemetry::Accumulate(Telemetry::CHARSET_OVERRIDE_SITUATION, 6);
break;
}
return NS_OK;
}
NS_IMETHODIMP
nsDocShell::SetCharset(const char* aCharset)
{

View File

@ -40,7 +40,7 @@ interface nsIWebBrowserPrint;
interface nsIVariant;
interface nsIPrivacyTransitionObserver;
[scriptable, builtinclass, uuid(e8f6f3e5-8cee-4be3-8d56-5ed617305bf8)]
[scriptable, builtinclass, uuid(4277354d-5069-4278-935a-5d596ce9bfbf)]
interface nsIDocShell : nsIDocShellTreeItem
{
/**
@ -596,6 +596,13 @@ interface nsIDocShell : nsIDocShellTreeItem
*/
attribute string charset;
/**
* Called when the user chose an encoding override from the character
* encoding menu. Separate from the setter for the charset property to avoid
* extensions adding noise to the data.
*/
void gatherCharsetMenuTelemetry();
/**
* The charset forced by the user. When the charset attribute is set this
* attribute is set to the same value.

View File

@ -2418,6 +2418,15 @@
"kind": "boolean",
"description": "Deleted or to-be-reused innerwindow which has had mutation event listeners."
},
"CHARSET_OVERRIDE_SITUATION": {
"kind": "enumerated",
"n_values": 7,
"description": "Labeling status of top-level page when overriding charset (unlabeled file URL without detection, unlabeled non-file URL without detection, unlabeled file URL with detection, unlabeled non-file URL with detection, labeled, already overridden, bug)"
},
"CHARSET_OVERRIDE_USED": {
"kind": "flag",
"description": "Whether the character encoding menu was used to override an encoding in this session."
},
"XUL_FOREGROUND_REFLOW_MS": {
"kind": "exponential",
"high": "3000",