Commit eba51657 authored by Nate Fischer's avatar Nate Fischer Committed by Commit Bot

AW: fix bug when measuring '#' in data URIs

loadDataWithBaseURL doesn't always accept encoded content. This moves
the histogram code into the branch which actually accepts encoded
content (since it's reasonable to expect an unencoded '#' in unencoded
content).

R=smcgruer@chromium.org, torne@chromium.org

Bug: 902223
Bug: 823666
Test: None
Change-Id: If5c912640ea81a4d6e333496233958f3323d9bd6
Reviewed-on: https://chromium-review.googlesource.com/c/1319347
Commit-Queue: Nate Fischer <ntfschr@chromium.org>
Reviewed-by: default avatarStephen McGruer <smcgruer@chromium.org>
Reviewed-by: default avatarRichard Coles <torne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#605887}
parent d6356d47
......@@ -1678,9 +1678,6 @@ public class AwContents implements SmartClipProvider {
String baseUrl, String data, String mimeType, String encoding, String historyUrl) {
if (TRACE) Log.i(TAG, "%s loadDataWithBaseURL=%s", this, baseUrl);
if (isDestroyedOrNoOperation(WARN)) return;
if (data != null && data.contains("#")) {
RecordHistogram.recordBooleanHistogram(DATA_URI_HISTOGRAM_NAME, true);
}
data = fixupData(data);
mimeType = fixupMimeType(mimeType);
......@@ -1697,6 +1694,10 @@ public class AwContents implements SmartClipProvider {
}
if (baseUrl.startsWith("data:")) {
// We record only for this branch, because the other branch assumes unencoded content.
if (data != null && data.contains("#")) {
RecordHistogram.recordBooleanHistogram(DATA_URI_HISTOGRAM_NAME, true);
}
// For backwards compatibility with WebViewClassic, we use the value of |encoding|
// as the charset, as long as it's not "base64".
boolean isBase64 = isBase64Encoded(encoding);
......
......@@ -844,11 +844,19 @@ public class AwContentsTest {
});
Assert.assertEquals(0, getHistogramSampleCount(AwContents.DATA_URI_HISTOGRAM_NAME));
// Check a URL with a '#' character.
// '#' is legal if the baseUrl is not data scheme, because loadDataWithBaseURL accepts
// unencoded content.
mActivityTestRule.runOnUiThread(() -> {
awContents.loadDataWithBaseURL(
"http://www.example.com", "<html>test#foo</html>", "text/html", null, null);
});
Assert.assertEquals(0, getHistogramSampleCount(AwContents.DATA_URI_HISTOGRAM_NAME));
// Check a URL with a '#' character, with data-scheme baseUrl.
mActivityTestRule.runOnUiThread(() -> {
awContents.loadDataWithBaseURL(
"data:text/html", "<html>test#foo</html>", "text/html", null, null);
});
Assert.assertEquals(1, getHistogramSampleCount(AwContents.DATA_URI_HISTOGRAM_NAME));
// An encoded '#' should not cause the histogram to increment.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment