| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 OnArticleReady(distilled_article.get()); | 61 OnArticleReady(distilled_article.get()); |
| 62 } | 62 } |
| 63 | 63 |
| 64 void DistillerViewer::OnArticleReady( | 64 void DistillerViewer::OnArticleReady( |
| 65 const dom_distiller::DistilledArticleProto* article_proto) { | 65 const dom_distiller::DistilledArticleProto* article_proto) { |
| 66 DomDistillerRequestViewBase::OnArticleReady(article_proto); | 66 DomDistillerRequestViewBase::OnArticleReady(article_proto); |
| 67 bool is_empty = article_proto->pages_size() == 0 || | 67 bool is_empty = article_proto->pages_size() == 0 || |
| 68 article_proto->pages(0).html().empty(); | 68 article_proto->pages(0).html().empty(); |
| 69 if (!is_empty) { | 69 if (!is_empty) { |
| 70 std::vector<ImageInfo> images; | 70 std::vector<ImageInfo> images; |
| 71 for (int i = 0; i < article_proto->pages(0).image_size(); i++) { | 71 for (int p = 0; p < article_proto->pages_size(); p++) { |
| 72 auto image = article_proto->pages(0).image(i); | 72 for (int i = 0; i < article_proto->pages(p).image_size(); i++) { |
| 73 images.push_back(ImageInfo{GURL(image.url()), image.data()}); | 73 auto image = article_proto->pages(p).image(i); |
| 74 images.push_back(ImageInfo{GURL(image.url()), image.data()}); |
| 75 } |
| 74 } | 76 } |
| 75 const std::string html = viewer::GetUnsafeArticleTemplateHtml( | 77 const std::string html = viewer::GetUnsafeArticleTemplateHtml( |
| 76 url_.spec(), distilled_page_prefs_->GetTheme(), | 78 url_.spec(), distilled_page_prefs_->GetTheme(), |
| 77 distilled_page_prefs_->GetFontFamily()); | 79 distilled_page_prefs_->GetFontFamily()); |
| 78 | 80 |
| 79 std::string html_and_script(html); | 81 std::string html_and_script(html); |
| 80 html_and_script += | 82 html_and_script += |
| 81 "<script> distiller_on_ios = true; " + js_buffer_ + "</script>"; | 83 "<script> distiller_on_ios = true; " + js_buffer_ + "</script>"; |
| 82 callback_.Run(url_, html_and_script, images, article_proto->title()); | 84 callback_.Run(url_, html_and_script, images, article_proto->title()); |
| 83 } else { | 85 } else { |
| 84 callback_.Run(url_, std::string(), {}, std::string()); | 86 callback_.Run(url_, std::string(), {}, std::string()); |
| 85 } | 87 } |
| 86 } | 88 } |
| 87 | 89 |
| 88 void DistillerViewer::SendJavaScript(const std::string& buffer) { | 90 void DistillerViewer::SendJavaScript(const std::string& buffer) { |
| 89 js_buffer_ += buffer; | 91 js_buffer_ += buffer; |
| 90 } | 92 } |
| 91 | 93 |
| 92 } // namespace dom_distiller | 94 } // namespace dom_distiller |
| OLD | NEW |