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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ios/chrome/browser/reading_list/reading_list_distiller_page.h" 5 #include "ios/chrome/browser/reading_list/reading_list_distiller_page.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/mac/foundation_util.h" 8 #include "base/mac/foundation_util.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "base/threading/thread_task_runner_handle.h" 10 #include "base/threading/thread_task_runner_handle.h"
11 #include "components/favicon/ios/web_favicon_driver.h" 11 #include "components/favicon/ios/web_favicon_driver.h"
12 #include "components/google/core/browser/google_util.h" 12 #include "components/google/core/browser/google_util.h"
13 #include "ios/chrome/browser/reading_list/favicon_web_state_dispatcher_impl.h" 13 #include "ios/chrome/browser/reading_list/favicon_web_state_dispatcher_impl.h"
14 #import "ios/web/public/navigation_item.h" 14 #import "ios/web/public/navigation_item.h"
15 #import "ios/web/public/navigation_manager.h" 15 #import "ios/web/public/navigation_manager.h"
16 #include "ios/web/public/ssl_status.h" 16 #include "ios/web/public/ssl_status.h"
17 #import "ios/web/public/web_state/js/crw_js_injection_receiver.h" 17 #import "ios/web/public/web_state/js/crw_js_injection_receiver.h"
18 #import "ios/web/public/web_state/web_state.h" 18 #import "ios/web/public/web_state/web_state.h"
19 #import "net/base/mac/url_conversions.h" 19 #import "net/base/mac/url_conversions.h"
20 #include "net/cert/cert_status_flags.h" 20 #include "net/cert/cert_status_flags.h"
21 #include "url/url_constants.h" 21 #include "url/url_constants.h"
22 22
23 namespace { 23 namespace {
24 // The delay given to the web page to render after the PageLoaded callback. 24 // The delay given to the web page to render after the PageLoaded callback.
25 const int64_t kPageLoadDelayInSeconds = 2; 25 const int64_t kPageLoadDelayInSeconds = 2;
26 26
27 // This script retrieve the href parameter of the <link rel="amphtml"> element
28 // of the page if it exists. If it does not exist, it returns the src of the
29 // first iframe of the page.
27 const char* kGetIframeURLJavaScript = 30 const char* kGetIframeURLJavaScript =
28 "document.getElementsByTagName('iframe')[0].src;"; 31 "(() => {"
32 " var link = document.evaluate('//link[@rel=\"amphtml\"]',"
33 " document,"
34 " null,"
35 " XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,"
36 " null ).snapshotItem(0);"
37 " if (link !== null) {"
38 " return link.getAttribute('href');"
39 " }"
40 " return document.getElementsByTagName('iframe')[0].src;"
41 "})()";
29 } // namespace 42 } // namespace
30 43
31 namespace reading_list { 44 namespace reading_list {
32 45
33 ReadingListDistillerPageDelegate::ReadingListDistillerPageDelegate() {} 46 ReadingListDistillerPageDelegate::ReadingListDistillerPageDelegate() {}
34 ReadingListDistillerPageDelegate::~ReadingListDistillerPageDelegate() {} 47 ReadingListDistillerPageDelegate::~ReadingListDistillerPageDelegate() {}
35 48
36 ReadingListDistillerPage::ReadingListDistillerPage( 49 ReadingListDistillerPage::ReadingListDistillerPage(
37 web::BrowserState* browser_state, 50 web::BrowserState* browser_state,
38 FaviconWebStateDispatcher* web_state_dispatcher, 51 FaviconWebStateDispatcher* web_state_dispatcher,
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 id result, 215 id result,
203 id error) { 216 id error) {
204 if (error) { 217 if (error) {
205 return false; 218 return false;
206 } 219 }
207 NSString* result_string = base::mac::ObjCCast<NSString>(result); 220 NSString* result_string = base::mac::ObjCCast<NSString>(result);
208 NSURL* new_url = [NSURL URLWithString:result_string]; 221 NSURL* new_url = [NSURL URLWithString:result_string];
209 if (!new_url) { 222 if (!new_url) {
210 return false; 223 return false;
211 } 224 }
212 bool is_cdn_ampproject =
213 [[new_url host] isEqualToString:@"cdn.ampproject.org"];
214 bool is_cdn_ampproject_subdomain =
215 [[new_url host] hasSuffix:@".cdn.ampproject.org"];
216 225
217 if (!is_cdn_ampproject && !is_cdn_ampproject_subdomain) {
218 return false;
219 }
220 GURL new_gurl = net::GURLWithNSURL(new_url); 226 GURL new_gurl = net::GURLWithNSURL(new_url);
221 if (!new_gurl.is_valid()) { 227 if (!new_gurl.is_valid()) {
222 return false; 228 return false;
223 } 229 }
224 FetchFavicon(new_gurl); 230 FetchFavicon(new_gurl);
225 web::NavigationManager::WebLoadParams params(new_gurl); 231 web::NavigationManager::WebLoadParams params(new_gurl);
226 CurrentWebState()->GetNavigationManager()->LoadURLWithParams(params); 232 CurrentWebState()->GetNavigationManager()->LoadURLWithParams(params);
227 return true; 233 return true;
228 } 234 }
229 235
230 } // namespace reading_list 236 } // namespace reading_list
OLDNEW
« 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