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 |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a0d3ba7f07dfa44192400786ad5a054c1c4c0c48 |
| --- /dev/null |
| +++ b/ios/chrome/browser/reading_list/reading_list_distiller_page.mm |
| @@ -0,0 +1,61 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
|
gambard
2016/12/27 09:35:59
Update year?
Olivier
2016/12/27 10:08:37
Done.
|
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "ios/chrome/browser/reading_list/reading_list_distiller_page.h" |
| + |
| +#include "base/bind.h" |
| +#include "base/threading/thread_task_runner_handle.h" |
| +#import "ios/web/public/web_state/web_state.h" |
| + |
| +namespace reading_list { |
| + |
| +ReadingListDistillerPage::ReadingListDistillerPage( |
| + FaviconWebStateDispatcher* web_state_dispatcher) |
| + : dom_distiller::DistillerPageIOS(std::unique_ptr<web::WebState>()), |
| + web_state_dispatcher_(web_state_dispatcher), |
| + weak_ptr_factory_(this) {} |
| + |
| +ReadingListDistillerPage::~ReadingListDistillerPage() {} |
| + |
| +void ReadingListDistillerPage::DistillPageImpl(const GURL& url, |
| + const std::string& script) { |
| + std::unique_ptr<web::WebState> new_web_state = |
| + web_state_dispatcher_->RequestWebState(); |
| + std::unique_ptr<web::WebState> old_web_state = |
| + ReplaceWebState(std::move(new_web_state)); |
| + if (old_web_state) { |
| + web_state_dispatcher_->ReturnWebState(std::move(old_web_state)); |
| + } |
| + DistillerPageIOS::DistillPageImpl(url, script); |
| +} |
| + |
| +void ReadingListDistillerPage::OnDistillationDone(const GURL& page_url, |
| + const base::Value* value) { |
| + std::unique_ptr<web::WebState> old_web_state = |
| + ReplaceWebState(std::unique_ptr<web::WebState>()); |
| + if (old_web_state) { |
| + web_state_dispatcher_->ReturnWebState(std::move(old_web_state)); |
| + } |
| + DistillerPageIOS::OnDistillationDone(page_url, value); |
| +} |
| + |
| +void ReadingListDistillerPage::OnLoadURLDone( |
| + web::PageLoadCompletionStatus load_completion_status) { |
| + if (load_completion_status == web::PageLoadCompletionStatus::FAILURE) { |
| + DistillerPageIOS::OnLoadURLDone(load_completion_status); |
| + return; |
| + } |
| + base::WeakPtr<ReadingListDistillerPage> weak_this = |
| + weak_ptr_factory_.GetWeakPtr(); |
| + base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| + FROM_HERE, base::Bind(&ReadingListDistillerPage::DelayedOnLoadURLDone, |
|
gambard
2016/12/27 09:35:59
Is this really necessary? ReadingListDistillerPage
Olivier
2016/12/27 10:08:37
You cannot bind directly DistillerPageIOS::OnLoadU
|
| + weak_this, load_completion_status), |
| + base::TimeDelta::FromSeconds(2)); |
| +} |
| + |
| +void ReadingListDistillerPage::DelayedOnLoadURLDone( |
| + web::PageLoadCompletionStatus load_completion_status) { |
| + DistillerPageIOS::OnLoadURLDone(load_completion_status); |
| +} |
| +} |
|
gambard
2016/12/27 09:35:59
// namespace reading_list
Olivier
2016/12/27 10:08:37
Done.
|