| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ios/chrome/browser/dom_distiller/distiller_viewer.h" | 5 #include "ios/chrome/browser/dom_distiller/distiller_viewer.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "components/dom_distiller/core/distilled_page_prefs.h" | 10 #include "components/dom_distiller/core/distilled_page_prefs.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 this, distillerService->CreateDefaultDistillerPage(gfx::Size()), url); | 32 this, distillerService->CreateDefaultDistillerPage(gfx::Size()), url); |
| 33 | 33 |
| 34 TakeViewerHandle(std::move(viewer_handle)); | 34 TakeViewerHandle(std::move(viewer_handle)); |
| 35 } | 35 } |
| 36 | 36 |
| 37 DistillerViewer::~DistillerViewer() {} | 37 DistillerViewer::~DistillerViewer() {} |
| 38 | 38 |
| 39 void DistillerViewer::OnArticleReady( | 39 void DistillerViewer::OnArticleReady( |
| 40 const dom_distiller::DistilledArticleProto* article_proto) { | 40 const dom_distiller::DistilledArticleProto* article_proto) { |
| 41 DomDistillerRequestViewBase::OnArticleReady(article_proto); | 41 DomDistillerRequestViewBase::OnArticleReady(article_proto); |
| 42 if (article_proto->pages_size() > 0) { | 42 bool is_empty = article_proto->pages_size() == 0 || |
| 43 article_proto->pages(0).html().empty(); |
| 44 if (!is_empty) { |
| 43 std::vector<ImageInfo> images; | 45 std::vector<ImageInfo> images; |
| 44 for (int i = 0; i < article_proto->pages(0).image_size(); i++) { | 46 for (int i = 0; i < article_proto->pages(0).image_size(); i++) { |
| 45 auto image = article_proto->pages(0).image(i); | 47 auto image = article_proto->pages(0).image(i); |
| 46 images.push_back(ImageInfo{GURL(image.url()), image.data()}); | 48 images.push_back(ImageInfo{GURL(image.url()), image.data()}); |
| 47 } | 49 } |
| 48 | |
| 49 const std::string html = viewer::GetUnsafeArticleTemplateHtml( | 50 const std::string html = viewer::GetUnsafeArticleTemplateHtml( |
| 50 url_.spec(), distilled_page_prefs_->GetTheme(), | 51 url_.spec(), distilled_page_prefs_->GetTheme(), |
| 51 distilled_page_prefs_->GetFontFamily()); | 52 distilled_page_prefs_->GetFontFamily()); |
| 52 | 53 |
| 53 std::string html_and_script(html); | 54 std::string html_and_script(html); |
| 54 html_and_script += | 55 html_and_script += |
| 55 "<script> distiller_on_ios = true; " + js_buffer_ + "</script>"; | 56 "<script> distiller_on_ios = true; " + js_buffer_ + "</script>"; |
| 56 callback_.Run(url_, html_and_script, images, article_proto->title()); | 57 callback_.Run(url_, html_and_script, images, article_proto->title()); |
| 57 } else { | 58 } else { |
| 58 callback_.Run(url_, std::string(), {}, std::string()); | 59 callback_.Run(url_, std::string(), {}, std::string()); |
| 59 } | 60 } |
| 60 } | 61 } |
| 61 | 62 |
| 62 void DistillerViewer::SendJavaScript(const std::string& buffer) { | 63 void DistillerViewer::SendJavaScript(const std::string& buffer) { |
| 63 js_buffer_ += buffer; | 64 js_buffer_ += buffer; |
| 64 } | 65 } |
| 65 | 66 |
| 66 } // namespace dom_distiller | 67 } // namespace dom_distiller |
| OLD | NEW |