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

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

Issue 1130703003: Show template before distiller finishes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ios-superclass
Patch Set: Fix flaky test Created 5 years, 7 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
« no previous file with comments | « ios/chrome/browser/dom_distiller/distiller_viewer.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
index d078046038845bc7e05211f6dfefecfb0705b1ba..1e1aab96e3ee60b9346051a581a0cc9271de93eb 100644
--- a/ios/chrome/browser/dom_distiller/distiller_viewer.cc
+++ b/ios/chrome/browser/dom_distiller/distiller_viewer.cc
@@ -18,72 +18,45 @@
namespace dom_distiller {
-namespace {
-
-class IOSContentDataCallback : public DistillerDataCallback {
- public:
- IOSContentDataCallback(
- const GURL& url,
- const DistillerViewer::DistillationFinishedCallback& callback,
- DistillerViewer* distiller_viewer_handle);
- ~IOSContentDataCallback() override{};
- void RunCallback(std::string& data) override;
-
- private:
- // Extra param needed by the callback specified below.
- GURL url_;
- // The callback to be run.
- const DistillerViewer::DistillationFinishedCallback callback_;
- // A handle to the DistillerViewer object.
- DistillerViewer* distiller_viewer_handle_;
-};
-
-IOSContentDataCallback::IOSContentDataCallback(
- const GURL& url,
- const DistillerViewer::DistillationFinishedCallback& callback,
- DistillerViewer* distiller_viewer_handle)
- : url_(url),
- callback_(callback),
- distiller_viewer_handle_(distiller_viewer_handle) {
-}
-
-void IOSContentDataCallback::RunCallback(std::string& data) {
- std::string htmlAndScript(data);
- htmlAndScript += "<script>" +
- distiller_viewer_handle_->GetJavaScriptBuffer() +
- "</script>";
-
- callback_.Run(url_, htmlAndScript);
-}
-
-} // namespace
-
DistillerViewer::DistillerViewer(ios::ChromeBrowserState* browser_state,
const GURL& url,
const DistillationFinishedCallback& callback)
: DomDistillerRequestViewBase(
- scoped_ptr<DistillerDataCallback>(
- new IOSContentDataCallback(url, callback, this)).Pass(),
- new DistilledPagePrefs(browser_state->GetPrefs())) {
+ new DistilledPagePrefs(browser_state->GetPrefs())),
+ url_(url),
+ callback_(callback) {
DCHECK(browser_state);
DCHECK(url.is_valid());
dom_distiller::DomDistillerService* distillerService =
dom_distiller::DomDistillerServiceFactory::GetForBrowserState(
browser_state);
- viewer_handle_ = distillerService->ViewUrl(
+ scoped_ptr<ViewerHandle> viewer_handle = distillerService->ViewUrl(
this, distillerService->CreateDefaultDistillerPage(gfx::Size()), url);
+
+ TakeViewerHandle(viewer_handle.Pass());
}
DistillerViewer::~DistillerViewer() {
}
-void DistillerViewer::SendJavaScript(const std::string& buffer) {
- js_buffer_ += buffer;
+void DistillerViewer::OnArticleReady(
+ const dom_distiller::DistilledArticleProto* article_proto) {
+ DomDistillerRequestViewBase::OnArticleReady(article_proto);
+
+ const std::string html = viewer::GetUnsafeArticleTemplateHtml(
+ url_.spec(), distilled_page_prefs_->GetTheme(),
+ distilled_page_prefs_->GetFontFamily());
+
+ std::string html_and_script(html);
+ std::string hide_feedback =
+ "document.getElementById('feedbackContainer').style.display = 'none';";
+ html_and_script += "<script>" + js_buffer_ + hide_feedback + "</script>";
+ callback_.Run(url_, html_and_script);
}
-std::string DistillerViewer::GetJavaScriptBuffer() {
- return js_buffer_;
+void DistillerViewer::SendJavaScript(const std::string& buffer) {
+ js_buffer_ += buffer;
}
} // namespace dom_distiller
« no previous file with comments | « ios/chrome/browser/dom_distiller/distiller_viewer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698