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

Side by Side Diff: ios/chrome/browser/reading_list/reading_list_distiller_page.mm

Issue 2737743003: [Reading List] Expand all Wikipedia sections on distillation. (Closed)
Patch Set: Created 3 years, 9 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 | « ios/chrome/browser/reading_list/reading_list_distiller_page.h ('k') | 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/string_util.h"
9 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
10 #include "base/threading/thread_task_runner_handle.h" 11 #include "base/threading/thread_task_runner_handle.h"
11 #include "components/favicon/ios/web_favicon_driver.h" 12 #include "components/favicon/ios/web_favicon_driver.h"
12 #include "components/google/core/browser/google_util.h" 13 #include "components/google/core/browser/google_util.h"
13 #include "ios/chrome/browser/reading_list/favicon_web_state_dispatcher_impl.h" 14 #include "ios/chrome/browser/reading_list/favicon_web_state_dispatcher_impl.h"
14 #import "ios/web/public/navigation_item.h" 15 #import "ios/web/public/navigation_item.h"
15 #import "ios/web/public/navigation_manager.h" 16 #import "ios/web/public/navigation_manager.h"
16 #include "ios/web/public/ssl_status.h" 17 #include "ios/web/public/ssl_status.h"
17 #import "ios/web/public/web_state/js/crw_js_injection_receiver.h" 18 #import "ios/web/public/web_state/js/crw_js_injection_receiver.h"
18 #import "ios/web/public/web_state/web_state.h" 19 #import "ios/web/public/web_state/web_state.h"
(...skipping 13 matching lines...) Expand all
32 " var link = document.evaluate('//link[@rel=\"amphtml\"]'," 33 " var link = document.evaluate('//link[@rel=\"amphtml\"]',"
33 " document," 34 " document,"
34 " null," 35 " null,"
35 " XPathResult.ORDERED_NODE_SNAPSHOT_TYPE," 36 " XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,"
36 " null ).snapshotItem(0);" 37 " null ).snapshotItem(0);"
37 " if (link !== null) {" 38 " if (link !== null) {"
38 " return link.getAttribute('href');" 39 " return link.getAttribute('href');"
39 " }" 40 " }"
40 " return document.getElementsByTagName('iframe')[0].src;" 41 " return document.getElementsByTagName('iframe')[0].src;"
41 "})()"; 42 "})()";
43
44 const char* kWikipediaWorkaround =
45 "(() => {"
46 " var s = document.createElement('style');"
47 " s.innerHTML='.client-js .collapsible-block { display: block }';"
48 " document.head.appendChild(s);"
49 "})()";
42 } // namespace 50 } // namespace
43 51
44 namespace reading_list { 52 namespace reading_list {
45 53
46 ReadingListDistillerPageDelegate::ReadingListDistillerPageDelegate() {} 54 ReadingListDistillerPageDelegate::ReadingListDistillerPageDelegate() {}
47 ReadingListDistillerPageDelegate::~ReadingListDistillerPageDelegate() {} 55 ReadingListDistillerPageDelegate::~ReadingListDistillerPageDelegate() {}
48 56
49 ReadingListDistillerPage::ReadingListDistillerPage( 57 ReadingListDistillerPage::ReadingListDistillerPage(
50 web::BrowserState* browser_state, 58 web::BrowserState* browser_state,
51 FaviconWebStateDispatcher* web_state_dispatcher, 59 FaviconWebStateDispatcher* web_state_dispatcher,
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 176
169 void ReadingListDistillerPage::DelayedOnLoadURLDone(int delayed_task_id) { 177 void ReadingListDistillerPage::DelayedOnLoadURLDone(int delayed_task_id) {
170 if (!CurrentWebState() || delayed_task_id != delayed_task_id_) { 178 if (!CurrentWebState() || delayed_task_id != delayed_task_id_) {
171 // Something interrupted the distillation. 179 // Something interrupted the distillation.
172 // Abort here. 180 // Abort here.
173 return; 181 return;
174 } 182 }
175 if (IsGoogleCachedAMPPage()) { 183 if (IsGoogleCachedAMPPage()) {
176 // Workaround for Google AMP pages. 184 // Workaround for Google AMP pages.
177 HandleGoogleCachedAMPPage(); 185 HandleGoogleCachedAMPPage();
178 } else { 186 return;
179 ContinuePageDistillation();
180 } 187 }
188 if (IsWikipediaPage()) {
189 // Workaround for Wikipedia pages.
190 // TODO(crbug.com/647667): remove workaround once DOM distiller handle this
191 // case.
192 HandleWikipediaPage();
193 return;
194 }
195 ContinuePageDistillation();
181 } 196 }
182 197
183 void ReadingListDistillerPage::ContinuePageDistillation() { 198 void ReadingListDistillerPage::ContinuePageDistillation() {
184 // The page is ready to be distilled. 199 // The page is ready to be distilled.
185 // If the visible URL is not the original URL, notify the caller that URL 200 // If the visible URL is not the original URL, notify the caller that URL
186 // changed. 201 // changed.
187 GURL redirected_url = CurrentWebState()->GetVisibleURL(); 202 GURL redirected_url = CurrentWebState()->GetVisibleURL();
188 if (redirected_url != original_url_ && delegate_) { 203 if (redirected_url != original_url_ && delegate_) {
189 delegate_->DistilledPageRedirectedToURL(original_url_, redirected_url); 204 delegate_->DistilledPageRedirectedToURL(original_url_, redirected_url);
190 } 205 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 GURL new_gurl = net::GURLWithNSURL(new_url); 265 GURL new_gurl = net::GURLWithNSURL(new_url);
251 if (!new_gurl.is_valid()) { 266 if (!new_gurl.is_valid()) {
252 return false; 267 return false;
253 } 268 }
254 FetchFavicon(new_gurl); 269 FetchFavicon(new_gurl);
255 web::NavigationManager::WebLoadParams params(new_gurl); 270 web::NavigationManager::WebLoadParams params(new_gurl);
256 CurrentWebState()->GetNavigationManager()->LoadURLWithParams(params); 271 CurrentWebState()->GetNavigationManager()->LoadURLWithParams(params);
257 return true; 272 return true;
258 } 273 }
259 274
275 bool ReadingListDistillerPage::IsWikipediaPage() {
276 // All wikipedia pages are in the form "https://xxx.m.wikipedia.org/..."
277 const GURL& url = CurrentWebState()->GetLastCommittedURL();
278 if (!url.is_valid() || !url.SchemeIs(url::kHttpsScheme)) {
279 return false;
280 }
281 return (base::EndsWith(url.host(), ".m.wikipedia.org",
282 base::CompareCase::SENSITIVE));
283 }
284
285 void ReadingListDistillerPage::HandleWikipediaPage() {
286 base::WeakPtr<ReadingListDistillerPage> weak_this =
287 weak_ptr_factory_.GetWeakPtr();
288 [CurrentWebState()->GetJSInjectionReceiver()
289 executeJavaScript:@(kWikipediaWorkaround)
290 completionHandler:^(id result, NSError* error) {
291 if (weak_this) {
292 weak_this->ContinuePageDistillation();
293 }
294 }];
295 }
296
260 } // namespace reading_list 297 } // namespace reading_list
OLDNEW
« no previous file with comments | « ios/chrome/browser/reading_list/reading_list_distiller_page.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698