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

Unified Diff: ios/chrome/browser/reading_list/reading_list_distiller_page.mm

Issue 2680313004: [Reading List] Navigate to the amphtml link in Google SRP AMP pages. (Closed)
Patch Set: Created 3 years, 10 months 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/chrome/browser/reading_list/reading_list_distiller_page.mm
diff --git a/ios/chrome/browser/reading_list/reading_list_distiller_page.mm b/ios/chrome/browser/reading_list/reading_list_distiller_page.mm
index c1510de82786246025b4b0dead06eb7a13db8835..b456e9023ace45fc1f2090de465c9857b6027584 100644
--- a/ios/chrome/browser/reading_list/reading_list_distiller_page.mm
+++ b/ios/chrome/browser/reading_list/reading_list_distiller_page.mm
@@ -24,8 +24,21 @@ namespace {
// The delay given to the web page to render after the PageLoaded callback.
const int64_t kPageLoadDelayInSeconds = 2;
+// This script retrieve the href parameter of the <link rel="amphtml"> element
+// of the page if it exists. If it does not exist, it returns the src of the
+// first iframe of the page.
const char* kGetIframeURLJavaScript =
- "document.getElementsByTagName('iframe')[0].src;";
+ "(() => {"
+ " var link = document.evaluate('//link[@rel=\"amphtml\"]',"
+ " document,"
+ " null,"
+ " XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,"
+ " null ).snapshotItem(0);"
+ " if (link !== null) {"
+ " return link.getAttribute('href');"
+ " }"
+ " return document.getElementsByTagName('iframe')[0].src;"
+ "})()";
} // namespace
namespace reading_list {
@@ -209,14 +222,7 @@ bool ReadingListDistillerPage::HandleGoogleCachedAMPPageJavaScriptResult(
if (!new_url) {
return false;
}
- bool is_cdn_ampproject =
- [[new_url host] isEqualToString:@"cdn.ampproject.org"];
- bool is_cdn_ampproject_subdomain =
- [[new_url host] hasSuffix:@".cdn.ampproject.org"];
- if (!is_cdn_ampproject && !is_cdn_ampproject_subdomain) {
- return false;
- }
GURL new_gurl = net::GURLWithNSURL(new_url);
if (!new_gurl.is_valid()) {
return false;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698