Commit 38d8c9ba authored by Gregory Chatzinoff's avatar Gregory Chatzinoff Committed by Commit Bot

Enable the sharing of non-HTTPS canonical URLs.

This CL enables the sharing of non-HTTPS canonical URLs if the
display URL is HTTPS, due to a requirements change. It also
updates the logging to treat HTTP canonical URLs as a success
case.

Bug: 794768
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: I741949980f2d6d804a673ac82d950cdf735021df
Reviewed-on: https://chromium-review.googlesource.com/826051Reviewed-by: default avatarPeter Lee <pkl@chromium.org>
Reviewed-by: default avatarSteven Holte <holte@chromium.org>
Commit-Queue: Gregory Chatzinoff <gchatz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#524433}
parent d4429890
...@@ -59,15 +59,9 @@ GURL UrlFromValue(const base::Value* value) { ...@@ -59,15 +59,9 @@ GURL UrlFromValue(const base::Value* value) {
// Log result if an invalid canonical URL is found. // Log result if an invalid canonical URL is found.
LogCanonicalUrlResultHistogram( LogCanonicalUrlResultHistogram(
activity_services::FAILED_CANONICAL_URL_INVALID); activity_services::FAILED_CANONICAL_URL_INVALID);
} else if (!canonical_url.SchemeIsCryptographic()) {
// Logs result if the found canonical URL is not HTTPS.
LogCanonicalUrlResultHistogram(
activity_services::FAILED_CANONICAL_URL_NOT_HTTPS);
} }
return canonical_url.is_valid() && canonical_url.SchemeIsCryptographic() return canonical_url.is_valid() ? canonical_url : GURL::EmptyGURL();
? canonical_url
: GURL::EmptyGURL();
} }
} // namespace } // namespace
...@@ -90,11 +84,17 @@ void RetrieveCanonicalUrl(web::WebState* web_state, ...@@ -90,11 +84,17 @@ void RetrieveCanonicalUrl(web::WebState* web_state,
// If the canonical URL is not empty, then the retrieval was successful, // If the canonical URL is not empty, then the retrieval was successful,
// and the success can be logged. // and the success can be logged.
if (!canonical_url.is_empty()) { if (!canonical_url.is_empty()) {
// Log whether the success occurred with an HTTP canonical URL, a
// canonical URL that is the same as the visible URL, or a canonical
// URL that is different from the visible URL.
LogCanonicalUrlResultHistogram( LogCanonicalUrlResultHistogram(
visible_url == canonical_url !canonical_url.SchemeIsCryptographic()
? activity_services::SUCCESS_CANONICAL_URL_SAME_AS_VISIBLE ? activity_services::SUCCESS_CANONICAL_URL_NOT_HTTPS
: activity_services:: : visible_url == canonical_url
SUCCESS_CANONICAL_URL_DIFFERENT_FROM_VISIBLE); ? activity_services::
SUCCESS_CANONICAL_URL_SAME_AS_VISIBLE
: activity_services::
SUCCESS_CANONICAL_URL_DIFFERENT_FROM_VISIBLE);
} }
completion(canonical_url); completion(canonical_url);
......
...@@ -14,9 +14,8 @@ enum CanonicalURLResult { ...@@ -14,9 +14,8 @@ enum CanonicalURLResult {
// The canonical URL retrieval failed because the visible URL is not HTTPS. // The canonical URL retrieval failed because the visible URL is not HTTPS.
FAILED_VISIBLE_URL_NOT_HTTPS = 0, FAILED_VISIBLE_URL_NOT_HTTPS = 0,
// The canonical URL retrieval failed because the canonical URL is not HTTPS // Deprecated.
// (but the visible URL is). FAILED_CANONICAL_URL_NOT_HTTPS_DEPRECATED,
FAILED_CANONICAL_URL_NOT_HTTPS,
// The canonical URL retrieval failed because the page did not define one. // The canonical URL retrieval failed because the page did not define one.
FAILED_NO_CANONICAL_URL_DEFINED, FAILED_NO_CANONICAL_URL_DEFINED,
...@@ -33,6 +32,10 @@ enum CanonicalURLResult { ...@@ -33,6 +32,10 @@ enum CanonicalURLResult {
// same as the visible URL. // same as the visible URL.
SUCCESS_CANONICAL_URL_SAME_AS_VISIBLE, SUCCESS_CANONICAL_URL_SAME_AS_VISIBLE,
// The canonical URL retrieval succeeded. The canonical URL is not HTTPS
// (but the visible URL is).
SUCCESS_CANONICAL_URL_NOT_HTTPS,
// The count of canonical URL results. This must be the last item in the enum. // The count of canonical URL results. This must be the last item in the enum.
CANONICAL_URL_RESULT_COUNT CANONICAL_URL_RESULT_COUNT
}; };
......
...@@ -165,8 +165,8 @@ TEST_F(CanonicalURLRetrieverTest, TestCanonicalURLHTTPSUpgrade) { ...@@ -165,8 +165,8 @@ TEST_F(CanonicalURLRetrieverTest, TestCanonicalURLHTTPSUpgrade) {
activity_services::FAILED_VISIBLE_URL_NOT_HTTPS, 1); activity_services::FAILED_VISIBLE_URL_NOT_HTTPS, 1);
} }
// Validates that if the visible URL is HTTPS but the canonical URL is HTTP, an // Validates that if the visible URL is HTTPS but the canonical URL is HTTP, it
// empty GURL is given to the completion block. // is found and given to the completion block.
TEST_F(CanonicalURLRetrieverTest, TestCanonicalLinkHTTPSDowngrade) { TEST_F(CanonicalURLRetrieverTest, TestCanonicalLinkHTTPSDowngrade) {
LoadHtml(@"<link rel=\"canonical\" href=\"http://chromium.test\">", LoadHtml(@"<link rel=\"canonical\" href=\"http://chromium.test\">",
GURL("https://m.chromium.test/")); GURL("https://m.chromium.test/"));
...@@ -175,8 +175,8 @@ TEST_F(CanonicalURLRetrieverTest, TestCanonicalLinkHTTPSDowngrade) { ...@@ -175,8 +175,8 @@ TEST_F(CanonicalURLRetrieverTest, TestCanonicalLinkHTTPSDowngrade) {
bool success = RetrieveCanonicalUrl(&url); bool success = RetrieveCanonicalUrl(&url);
ASSERT_TRUE(success); ASSERT_TRUE(success);
EXPECT_TRUE(url.is_empty()); EXPECT_EQ("http://chromium.test/", url);
histogram_tester_.ExpectUniqueSample( histogram_tester_.ExpectUniqueSample(
activity_services::kCanonicalURLResultHistogram, activity_services::kCanonicalURLResultHistogram,
activity_services::FAILED_CANONICAL_URL_NOT_HTTPS, 1); activity_services::SUCCESS_CANONICAL_URL_NOT_HTTPS, 1);
} }
...@@ -4271,14 +4271,17 @@ uploading your change for review. These are checked by presubmit scripts. ...@@ -4271,14 +4271,17 @@ uploading your change for review. These are checked by presubmit scripts.
<enum name="CanonicalURLResult"> <enum name="CanonicalURLResult">
<int value="0" label="Canonical URL not retrieved: Visible URL not HTTPS"/> <int value="0" label="Canonical URL not retrieved: Visible URL not HTTPS"/>
<int value="1" <int value="1"
label="Canonical URL not retrieved: Canonical URL not HTTPS (but label="(obsolete) Canonical URL not retrieved: Canonical URL not HTTPS
visible URL is)"/> (but visible URL is)"/>
<int value="2" <int value="2"
label="Canonical URL not retrieved: Page had no canonical URL defined"/> label="Canonical URL not retrieved: Page had no canonical URL defined"/>
<int value="3" <int value="3"
label="Canonical URL not retrieved: Page's canonical URL was invalid"/> label="Canonical URL not retrieved: Page's canonical URL was invalid"/>
<int value="4" label="Canonical URL retrieved: Differed from visible URL"/> <int value="4" label="Canonical URL retrieved: Differed from visible URL"/>
<int value="5" label="Canonical URL retrieved: Same as visible URL"/> <int value="5" label="Canonical URL retrieved: Same as visible URL"/>
<int value="6"
label="Canonical URL retrieved: Canonical URL not HTTPS (but visible
URL is)"/>
</enum> </enum>
<enum name="CanvasContextType"> <enum name="CanvasContextType">
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