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

Unified Diff: ios/chrome/browser/dom_distiller/distiller_viewer.cc

Issue 972683002: Upstream dom_distiller iOS factories (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@browser_state
Patch Set: Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: ios/chrome/browser/dom_distiller/distiller_viewer.cc
diff --git a/ios/chrome/browser/dom_distiller/distiller_viewer.cc b/ios/chrome/browser/dom_distiller/distiller_viewer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..bf30950290303c6a3d4115fdb5eac1a290cf37f5
--- /dev/null
+++ b/ios/chrome/browser/dom_distiller/distiller_viewer.cc
@@ -0,0 +1,51 @@
+// Copyright 2015 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/dom_distiller/distiller_viewer.h"
+
+#include <string>
+
+#include "components/dom_distiller/core/distilled_page_prefs.h"
+#include "components/dom_distiller/core/dom_distiller_service.h"
+#include "components/dom_distiller/core/proto/distilled_article.pb.h"
+#include "components/dom_distiller/core/task_tracker.h"
+#include "components/dom_distiller/core/viewer.h"
+#include "ios/chrome/browser/dom_distiller/dom_distiller_service_factory.h"
+#include "ios/public/provider/chrome/browser/browser_state/chrome_browser_state.h"
+#include "ui/gfx/geometry/size.h"
+
+namespace dom_distiller {
+
+DistillerViewer::DistillerViewer(ios::ChromeBrowserState* browser_state,
+ const GURL& url,
+ const DistillationFinishedCallback& callback)
+ : url_(url),
+ callback_(callback),
+ distilled_page_prefs_(new DistilledPagePrefs(browser_state->GetPrefs())) {
+ DCHECK(browser_state);
+ DCHECK(url.is_valid());
+ dom_distiller::DomDistillerService* distillerService =
+ dom_distiller::DomDistillerServiceFactory::GetForBrowserState(
+ browser_state);
+
+ viewer_handle_ = distillerService->ViewUrl(
+ this, distillerService->CreateDefaultDistillerPage(gfx::Size()), url);
+}
+
+DistillerViewer::~DistillerViewer() {
+}
+
+void DistillerViewer::OnArticleReady(
+ const DistilledArticleProto* article_proto) {
+ const std::string html = viewer::GetUnsafeArticleHtml(
+ article_proto, distilled_page_prefs_->GetTheme(),
+ distilled_page_prefs_->GetFontFamily());
+
+ callback_.Run(url_, html);
+
+ // No need to hold on to the ViewerHandle now that distillation is complete.
+ viewer_handle_.reset();
+}
+
+} // namespace dom_distiller
« no previous file with comments | « ios/chrome/browser/dom_distiller/distiller_viewer.h ('k') | ios/chrome/browser/dom_distiller/dom_distiller_service_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698