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

Side by Side Diff: ios/chrome/browser/reading_list/reading_list_distiller_page.mm

Issue 2604773002: Create distiller files for Reading List. (Closed)
Patch Set: feedback Created 3 years, 11 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ios/chrome/browser/reading_list/reading_list_distiller_page.h"
6
7 #include "base/bind.h"
8 #include "base/threading/thread_task_runner_handle.h"
9 #include "components/favicon/ios/web_favicon_driver.h"
10 #import "ios/web/public/web_state/web_state.h"
11
12 namespace reading_list {
13
14 ReadingListDistillerPage::ReadingListDistillerPage(
15 FaviconWebStateDispatcher* web_state_dispatcher)
16 : dom_distiller::DistillerPageIOS(std::unique_ptr<web::WebState>()),
17 web_state_dispatcher_(web_state_dispatcher),
18 weak_ptr_factory_(this) {}
19
20 ReadingListDistillerPage::~ReadingListDistillerPage() {}
21
22 void ReadingListDistillerPage::DistillPageImpl(const GURL& url,
23 const std::string& script) {
24 std::unique_ptr<web::WebState> new_web_state =
25 web_state_dispatcher_->RequestWebState();
26 std::unique_ptr<web::WebState> old_web_state =
27 ReplaceWebState(std::move(new_web_state));
28 if (old_web_state) {
29 web_state_dispatcher_->ReturnWebState(std::move(old_web_state));
30 }
31 if (new_web_state) {
32 favicon::WebFaviconDriver* favicon_driver =
33 favicon::WebFaviconDriver::FromWebState(new_web_state.get());
34 favicon_driver->FetchFavicon(url);
35 }
36 DistillerPageIOS::DistillPageImpl(url, script);
37 }
38
39 void ReadingListDistillerPage::OnDistillationDone(const GURL& page_url,
40 const base::Value* value) {
41 std::unique_ptr<web::WebState> old_web_state =
42 ReplaceWebState(std::unique_ptr<web::WebState>());
43 if (old_web_state) {
44 web_state_dispatcher_->ReturnWebState(std::move(old_web_state));
45 }
46 DistillerPageIOS::OnDistillationDone(page_url, value);
47 }
48
49 void ReadingListDistillerPage::OnLoadURLDone(
50 web::PageLoadCompletionStatus load_completion_status) {
51 if (load_completion_status == web::PageLoadCompletionStatus::FAILURE) {
52 DistillerPageIOS::OnLoadURLDone(load_completion_status);
53 return;
54 }
55 base::WeakPtr<ReadingListDistillerPage> weak_this =
56 weak_ptr_factory_.GetWeakPtr();
57 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
58 FROM_HERE, base::Bind(&ReadingListDistillerPage::DelayedOnLoadURLDone,
59 weak_this, load_completion_status),
60 base::TimeDelta::FromSeconds(2));
61 }
62
63 void ReadingListDistillerPage::DelayedOnLoadURLDone(
64 web::PageLoadCompletionStatus load_completion_status) {
65 DistillerPageIOS::OnLoadURLDone(load_completion_status);
66 }
67 } // namespace reading_list
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698