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

Side by Side Diff: ios/chrome/browser/dom_distiller/distiller_viewer.cc

Issue 2594663005: Report empty article as empty. (Closed)
Patch Set: Created 3 years, 12 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 = true;
43 for (int i = 0; i < article_proto->pages_size(); i++) {
44 is_empty = is_empty && article_proto->pages(i).html() == "";
jif 2016/12/21 13:36:33 Code that breaks out of the loop is easier to unde
Olivier 2016/12/21 13:46:27 Done.
45 }
46 if (article_proto->pages_size() > 0 && !is_empty) {
43 std::vector<ImageInfo> images; 47 std::vector<ImageInfo> images;
44 for (int i = 0; i < article_proto->pages(0).image_size(); i++) { 48 for (int i = 0; i < article_proto->pages(0).image_size(); i++) {
45 auto image = article_proto->pages(0).image(i); 49 auto image = article_proto->pages(0).image(i);
46 images.push_back(ImageInfo{GURL(image.url()), image.data()}); 50 images.push_back(ImageInfo{GURL(image.url()), image.data()});
47 } 51 }
48
49 const std::string html = viewer::GetUnsafeArticleTemplateHtml( 52 const std::string html = viewer::GetUnsafeArticleTemplateHtml(
50 url_.spec(), distilled_page_prefs_->GetTheme(), 53 url_.spec(), distilled_page_prefs_->GetTheme(),
51 distilled_page_prefs_->GetFontFamily()); 54 distilled_page_prefs_->GetFontFamily());
52 55
53 std::string html_and_script(html); 56 std::string html_and_script(html);
54 html_and_script += 57 html_and_script +=
55 "<script> distiller_on_ios = true; " + js_buffer_ + "</script>"; 58 "<script> distiller_on_ios = true; " + js_buffer_ + "</script>";
56 callback_.Run(url_, html_and_script, images, article_proto->title()); 59 callback_.Run(url_, html_and_script, images, article_proto->title());
57 } else { 60 } else {
58 callback_.Run(url_, std::string(), {}, std::string()); 61 callback_.Run(url_, std::string(), {}, std::string());
59 } 62 }
60 } 63 }
61 64
62 void DistillerViewer::SendJavaScript(const std::string& buffer) { 65 void DistillerViewer::SendJavaScript(const std::string& buffer) {
63 js_buffer_ += buffer; 66 js_buffer_ += buffer;
64 } 67 }
65 68
66 } // namespace dom_distiller 69 } // namespace dom_distiller
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698