Commit 0752e7df authored by Ryan Sturm's avatar Ryan Sturm Committed by Commit Bot

Adding a document URL check to match the one in the browser

This adds a document URL HTTP/HTTPS check in the renderer
(anchor_element_metrics) for OnClick. This check already happens in
OnLoad and on the browser side, and due to the browser side check being
a fast fail, this causes a crash if the user is on a data:// page with
an https:// anchor element.

Bug: 879999
Change-Id: Iec3de21649d8f4f2d81a4c9c9e23cfe02fbbc9d7
Reviewed-on: https://chromium-review.googlesource.com/1204830Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarTarun Bansal <tbansal@chromium.org>
Commit-Queue: Ryan Sturm <ryansturm@chromium.org>
Cr-Commit-Position: refs/heads/master@{#588956}
parent 00cf3e2a
...@@ -211,8 +211,10 @@ base::Optional<AnchorElementMetrics> ...@@ -211,8 +211,10 @@ base::Optional<AnchorElementMetrics>
AnchorElementMetrics::MaybeReportClickedMetricsOnClick( AnchorElementMetrics::MaybeReportClickedMetricsOnClick(
const HTMLAnchorElement* anchor_element) { const HTMLAnchorElement* anchor_element) {
if (!base::FeatureList::IsEnabled(features::kRecordAnchorMetricsClicked) || if (!base::FeatureList::IsEnabled(features::kRecordAnchorMetricsClicked) ||
!anchor_element->Href().ProtocolIsInHTTPFamily()) !anchor_element->Href().ProtocolIsInHTTPFamily() ||
!anchor_element->GetDocument().BaseURL().ProtocolIsInHTTPFamily()) {
return base::nullopt; return base::nullopt;
}
auto anchor_metrics = Create(anchor_element); auto anchor_metrics = Create(anchor_element);
if (anchor_metrics.has_value()) { if (anchor_metrics.has_value()) {
......
...@@ -101,6 +101,47 @@ TEST_F(AnchorElementMetricsTest, FinchControl) { ...@@ -101,6 +101,47 @@ TEST_F(AnchorElementMetricsTest, FinchControl) {
1); 1);
} }
// Test that non-HTTP URLs are not reported.
TEST_F(AnchorElementMetricsTest, NonHTTPOnClick) {
HistogramTester histogram_tester;
// Tests that an HTTPS page with a data anchor is not reported when the anchor
// is clicked.
SimRequest http_resource("https://example.com/", "text/html");
LoadURL("https://example.com/");
http_resource.Complete("<a id='anchor' href='data://google.com/'>google</a>");
HTMLAnchorElement* anchor_element =
ToHTMLAnchorElement(GetDocument().getElementById("anchor"));
AnchorElementMetrics::MaybeReportClickedMetricsOnClick(anchor_element);
histogram_tester.ExpectTotalCount("AnchorElementMetrics.Clicked.RatioArea",
0);
// Tests that a data page with an HTTPS anchor is not reported when the anchor
// is clicked.
SimRequest data_resource("data://example.com/", "text/html");
LoadURL("data://example.com/");
data_resource.Complete(
"<a id='anchor' href='https://google.com/'>google</a>");
anchor_element = ToHTMLAnchorElement(GetDocument().getElementById("anchor"));
AnchorElementMetrics::MaybeReportClickedMetricsOnClick(anchor_element);
histogram_tester.ExpectTotalCount("AnchorElementMetrics.Clicked.RatioArea",
0);
// Tests that an HTTPS page with an HTTPS anchor is reported when the anchor
// is clicked.
SimRequest http_resource_2("https://example.com/", "text/html");
LoadURL("https://example.com/");
http_resource_2.Complete(
"<a id='anchor' href='https://google.com/'>google</a>");
anchor_element = ToHTMLAnchorElement(GetDocument().getElementById("anchor"));
AnchorElementMetrics::MaybeReportClickedMetricsOnClick(anchor_element);
histogram_tester.ExpectTotalCount("AnchorElementMetrics.Clicked.RatioArea",
1);
}
// The main frame contains an anchor element, which contains an image element. // The main frame contains an anchor element, which contains an image element.
TEST_F(AnchorElementMetricsTest, AnchorFeatureImageLink) { TEST_F(AnchorElementMetricsTest, AnchorFeatureImageLink) {
SimRequest main_resource("https://example.com/", "text/html"); SimRequest main_resource("https://example.com/", "text/html");
......
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