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..dccc48bbd317c0c9c3903270e305b0ed800ef7a2 |
| --- /dev/null |
| +++ b/ios/chrome/browser/reading_list/reading_list_distiller_page.mm |
| @@ -0,0 +1,68 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// 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" |
| +#include "components/favicon/ios/web_favicon_driver.h" |
| +#import "ios/web/public/web_state/web_state.h" |
| + |
| +namespace reading_list { |
| + |
| +ReadingListDistillerPage::ReadingListDistillerPage( |
| + web::BrowserState* browser_state, |
| + FaviconWebStateDispatcher* web_state_dispatcher) |
| + : dom_distiller::DistillerPageIOS(browser_state), |
| + 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> old_web_state = DetachWebState(); |
| + if (old_web_state) { |
| + web_state_dispatcher_->ReturnWebState(std::move(old_web_state)); |
| + } |
| + std::unique_ptr<web::WebState> new_web_state = |
| + web_state_dispatcher_->RequestWebState(); |
| + if (new_web_state) { |
| + favicon::WebFaviconDriver* favicon_driver = |
| + favicon::WebFaviconDriver::FromWebState(new_web_state.get()); |
| + favicon_driver->FetchFavicon(url); |
| + } |
| + AttachWebState(std::move(new_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 = DetachWebState(); |
| + 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, |
| + weak_this, load_completion_status), |
| + base::TimeDelta::FromSeconds(2)); |
|
gambard
2016/12/27 13:56:57
Nit: Use constant instead of "2"
Olivier
2016/12/27 14:52:15
Done.
|
| +} |
| + |
| +void ReadingListDistillerPage::DelayedOnLoadURLDone( |
| + web::PageLoadCompletionStatus load_completion_status) { |
| + DistillerPageIOS::OnLoadURLDone(load_completion_status); |
| +} |
| +} // namespace reading_list |