Chromium Code Reviews| 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..256060e8971b860c1b8699e0bda8ab1bf665b996 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() { |
| @@ -188,7 +203,12 @@ void ReadingListDistillerPage::ContinuePageDistillation() { |
| if (redirected_url != original_url_ && delegate_) { |
| delegate_->DistilledPageRedirectedToURL(original_url_, redirected_url); |
| } |
| - DistillerPageIOS::OnLoadURLDone(web::PageLoadCompletionStatus::SUCCESS); |
| + |
| + [CurrentWebState()->GetJSInjectionReceiver() |
| + executeJavaScript:@(kWikipediaWorkaround) |
| + completionHandler:^(id response, id error) { |
| + DistillerPageIOS::OnLoadURLDone(web::PageLoadCompletionStatus::SUCCESS); |
| + }]; |
|
noyau (Ping after 24h)
2017/03/03 21:52:52
This is leftover from the initial hack you forgot
Olivier
2017/03/04 09:26:23
Done.
|
| } |
| bool ReadingListDistillerPage::IsGoogleCachedAMPPage() { |
| @@ -257,4 +277,26 @@ bool ReadingListDistillerPage::HandleGoogleCachedAMPPageJavaScriptResult( |
| return true; |
| } |
| +bool ReadingListDistillerPage::IsWikipediaPage() { |
| + // All wikipedia pages are in the form "https://xxx.wikipedia.org/..." |
|
noyau (Ping after 24h)
2017/03/03 21:52:52
In the cases that interest us [countrycode].m.wiki
Olivier
2017/03/04 09:26:23
Done.
|
| + const GURL& url = CurrentWebState()->GetLastCommittedURL(); |
| + if (!url.is_valid() || !url.SchemeIs(url::kHttpsScheme)) { |
| + return false; |
| + } |
| + return (base::EndsWith(url.host(), ".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 |