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

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

Issue 2730863002: Expand all Wikipedia sections on distillation. (Closed)
Patch Set: feedback 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 | « ios/chrome/browser/reading_list/reading_list_distiller_page.h ('k') | 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 6ac1c4ad5b4047feaddfec0173351a24c6b493b1..feb04ff68a3039c35627f729ebad3bbe0546f0f0 100644
--- a/ios/chrome/browser/reading_list/reading_list_distiller_page.mm
+++ b/ios/chrome/browser/reading_list/reading_list_distiller_page.mm
@@ -6,6 +6,7 @@
#include "base/bind.h"
#include "base/mac/foundation_util.h"
+#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/thread_task_runner_handle.h"
#include "components/favicon/ios/web_favicon_driver.h"
@@ -39,6 +40,13 @@ const char* kGetIframeURLJavaScript =
" }"
" return document.getElementsByTagName('iframe')[0].src;"
"})()";
+
+const char* kWikipediaWorkaround =
+ "(() => {"
+ " var s = document.createElement('style');"
+ " s.innerHTML='.client-js .collapsible-block { display: block }';"
+ " document.head.appendChild(s);"
+ "})()";
} // namespace
namespace reading_list {
@@ -175,9 +183,16 @@ void ReadingListDistillerPage::DelayedOnLoadURLDone(int delayed_task_id) {
if (IsGoogleCachedAMPPage()) {
// Workaround for Google AMP pages.
HandleGoogleCachedAMPPage();
- } else {
- ContinuePageDistillation();
+ return;
+ }
+ if (IsWikipediaPage()) {
+ // Workaround for Wikipedia pages.
+ // TODO(crbug.com/647667): remove workaround once DOM distiller handle this
+ // case.
+ HandleWikipediaPage();
+ return;
}
+ ContinuePageDistillation();
}
void ReadingListDistillerPage::ContinuePageDistillation() {
@@ -257,4 +272,26 @@ bool ReadingListDistillerPage::HandleGoogleCachedAMPPageJavaScriptResult(
return true;
}
+bool ReadingListDistillerPage::IsWikipediaPage() {
+ // All wikipedia pages are in the form "https://xxx.m.wikipedia.org/..."
+ const GURL& url = CurrentWebState()->GetLastCommittedURL();
+ if (!url.is_valid() || !url.SchemeIs(url::kHttpsScheme)) {
+ return false;
+ }
+ return (base::EndsWith(url.host(), ".m.wikipedia.org",
+ base::CompareCase::SENSITIVE));
+}
+
+void ReadingListDistillerPage::HandleWikipediaPage() {
+ base::WeakPtr<ReadingListDistillerPage> weak_this =
+ weak_ptr_factory_.GetWeakPtr();
+ [CurrentWebState()->GetJSInjectionReceiver()
+ executeJavaScript:@(kWikipediaWorkaround)
+ completionHandler:^(id result, NSError* error) {
+ if (weak_this) {
+ weak_this->ContinuePageDistillation();
+ }
+ }];
+}
+
} // namespace reading_list
« 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