| 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 a95d1ab24c25c8a5666b58505c3730a7442cbea2..8a3d58c758c149579c4ba4da95537d184b00668a 100644
|
| --- a/ios/chrome/browser/reading_list/reading_list_distiller_page.mm
|
| +++ b/ios/chrome/browser/reading_list/reading_list_distiller_page.mm
|
| @@ -21,8 +21,9 @@
|
| #include "url/url_constants.h"
|
|
|
| namespace {
|
| -// The delay between the page load and the distillation in seconds.
|
| -const int64_t kDistillationDelayInSeconds = 2;
|
| +// The delay given to the web page to render after the PageLoaded callback.
|
| +const int64_t kPageLoadDelayInSeconds = 2;
|
| +
|
| const char* kGetIframeURLJavaScript =
|
| "document.getElementsByTagName('iframe')[0].src;";
|
| } // namespace
|
| @@ -105,24 +106,25 @@ void ReadingListDistillerPage::OnLoadURLDone(
|
| DistillerPageIOS::OnLoadURLDone(load_completion_status);
|
| return;
|
| }
|
| - if (IsGoogleCachedAMPPage()) {
|
| - // Workaround for Google AMP pages.
|
| - HandleGoogleCachedAMPPage();
|
| - } else {
|
| - WaitForPageLoadCompletion();
|
| - }
|
| -}
|
| -
|
| -void ReadingListDistillerPage::WaitForPageLoadCompletion() {
|
| + // Page is loaded but rendering may not be done yet. Give a delay to the page.
|
| base::WeakPtr<ReadingListDistillerPage> weak_this =
|
| weak_ptr_factory_.GetWeakPtr();
|
| base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
|
| FROM_HERE,
|
| base::Bind(&ReadingListDistillerPage::DelayedOnLoadURLDone, weak_this),
|
| - base::TimeDelta::FromSeconds(kDistillationDelayInSeconds));
|
| + base::TimeDelta::FromSeconds(kPageLoadDelayInSeconds));
|
| }
|
|
|
| void ReadingListDistillerPage::DelayedOnLoadURLDone() {
|
| + if (IsGoogleCachedAMPPage()) {
|
| + // Workaround for Google AMP pages.
|
| + HandleGoogleCachedAMPPage();
|
| + } else {
|
| + ContinuePageDistillation();
|
| + }
|
| +}
|
| +
|
| +void ReadingListDistillerPage::ContinuePageDistillation() {
|
| // The page is ready to be distilled.
|
| // If the visible URL is not the original URL, notify the caller that URL
|
| // changed.
|
| @@ -170,7 +172,7 @@ void ReadingListDistillerPage::HandleGoogleCachedAMPPage() {
|
| !weak_this->HandleGoogleCachedAMPPageJavaScriptResult(result,
|
| error)) {
|
| // If there is an error on navigation, continue normal distillation.
|
| - weak_this->WaitForPageLoadCompletion();
|
| + weak_this->ContinuePageDistillation();
|
| }
|
| // If there is no error, the navigation completion will trigger a new
|
| // |OnLoadURLDone| call that will resume the distillation.
|
|
|