1 // Copyright 2015 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.
5 #include "ios/chrome/browser/dom_distiller/distiller_viewer.h"
9 #include "components/dom_distiller/core/distilled_page_prefs.h"
10 #include "components/dom_distiller/core/dom_distiller_service.h"
11 #include "components/dom_distiller/core/proto/distilled_article.pb.h"
12 #include "components/dom_distiller/core/task_tracker.h"
13 #include "components/dom_distiller/core/viewer.h"
14 #include "ios/chrome/browser/dom_distiller/dom_distiller_service_factory.h"
15 #include "ios/public/provider/chrome/browser/browser_state/chrome_browser_state.h"
16 #include "ui/gfx/geometry/size.h"
18 namespace dom_distiller
{
20 DistillerViewer::DistillerViewer(ios::ChromeBrowserState
* browser_state
,
22 const DistillationFinishedCallback
& callback
)
25 distilled_page_prefs_(new DistilledPagePrefs(browser_state
->GetPrefs())) {
26 DCHECK(browser_state
);
27 DCHECK(url
.is_valid());
28 dom_distiller::DomDistillerService
* distillerService
=
29 dom_distiller::DomDistillerServiceFactory::GetForBrowserState(
32 viewer_handle_
= distillerService
->ViewUrl(
33 this, distillerService
->CreateDefaultDistillerPage(gfx::Size()), url
);
36 DistillerViewer::~DistillerViewer() {
39 void DistillerViewer::OnArticleReady(
40 const DistilledArticleProto
* article_proto
) {
41 const std::string html
= viewer::GetUnsafeArticleHtml(
42 article_proto
, distilled_page_prefs_
->GetTheme(),
43 distilled_page_prefs_
->GetFontFamily());
45 callback_
.Run(url_
, html
);
47 // No need to hold on to the ViewerHandle now that distillation is complete.
48 viewer_handle_
.reset();
51 } // namespace dom_distiller