OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "ios/chrome/browser/dom_distiller/distiller_viewer.h" |
| 6 |
| 7 #include <string> |
| 8 |
| 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" |
| 17 |
| 18 namespace dom_distiller { |
| 19 |
| 20 DistillerViewer::DistillerViewer(ios::ChromeBrowserState* browser_state, |
| 21 const GURL& url, |
| 22 const DistillationFinishedCallback& callback) |
| 23 : url_(url), |
| 24 callback_(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( |
| 30 browser_state); |
| 31 |
| 32 viewer_handle_ = distillerService->ViewUrl( |
| 33 this, distillerService->CreateDefaultDistillerPage(gfx::Size()), url); |
| 34 } |
| 35 |
| 36 DistillerViewer::~DistillerViewer() { |
| 37 } |
| 38 |
| 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()); |
| 44 |
| 45 callback_.Run(url_, html); |
| 46 |
| 47 // No need to hold on to the ViewerHandle now that distillation is complete. |
| 48 viewer_handle_.reset(); |
| 49 } |
| 50 |
| 51 } // namespace dom_distiller |
OLD | NEW |