Chromium Code Reviews| 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 20 matching lines...) Expand all Loading... | |
| 31 std::unique_ptr<ViewerHandle> viewer_handle = distillerService->ViewUrl( | 31 std::unique_ptr<ViewerHandle> viewer_handle = distillerService->ViewUrl( |
| 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); |
|
wychen
2016/12/22 07:58:19
In DomDistillerRequestViewBase::OnArticleReady(),
Olivier
2016/12/22 10:54:59
But IIUC, not the protobuf, correct?
Should I do m
wychen
2016/12/22 11:05:12
The protobuf should be intact, so no need to chang
| |
| 42 if (article_proto->pages_size() > 0) { | 42 bool is_empty = true; |
| 43 for (int i = 0; i < article_proto->pages_size(); i++) { | |
|
wychen
2016/12/22 10:19:33
When the first distilled page is empty, even if th
Olivier
2016/12/22 10:54:59
Done. This makes code simpler
| |
| 44 if (article_proto->pages(i).html() != "") { | |
|
wychen
2016/12/22 10:19:33
Using .empty() might be slightly better.
Olivier
2016/12/22 10:54:59
Done.
| |
| 45 is_empty = false; | |
| 46 break; | |
| 47 } | |
| 48 } | |
| 49 if (article_proto->pages_size() > 0 && !is_empty) { | |
| 43 std::vector<ImageInfo> images; | 50 std::vector<ImageInfo> images; |
| 44 for (int i = 0; i < article_proto->pages(0).image_size(); i++) { | 51 for (int i = 0; i < article_proto->pages(0).image_size(); i++) { |
| 45 auto image = article_proto->pages(0).image(i); | 52 auto image = article_proto->pages(0).image(i); |
| 46 images.push_back(ImageInfo{GURL(image.url()), image.data()}); | 53 images.push_back(ImageInfo{GURL(image.url()), image.data()}); |
| 47 } | 54 } |
| 48 | |
| 49 const std::string html = viewer::GetUnsafeArticleTemplateHtml( | 55 const std::string html = viewer::GetUnsafeArticleTemplateHtml( |
| 50 url_.spec(), distilled_page_prefs_->GetTheme(), | 56 url_.spec(), distilled_page_prefs_->GetTheme(), |
| 51 distilled_page_prefs_->GetFontFamily()); | 57 distilled_page_prefs_->GetFontFamily()); |
| 52 | 58 |
| 53 std::string html_and_script(html); | 59 std::string html_and_script(html); |
| 54 html_and_script += | 60 html_and_script += |
| 55 "<script> distiller_on_ios = true; " + js_buffer_ + "</script>"; | 61 "<script> distiller_on_ios = true; " + js_buffer_ + "</script>"; |
| 56 callback_.Run(url_, html_and_script, images, article_proto->title()); | 62 callback_.Run(url_, html_and_script, images, article_proto->title()); |
| 57 } else { | 63 } else { |
| 58 callback_.Run(url_, std::string(), {}, std::string()); | 64 callback_.Run(url_, std::string(), {}, std::string()); |
| 59 } | 65 } |
| 60 } | 66 } |
| 61 | 67 |
| 62 void DistillerViewer::SendJavaScript(const std::string& buffer) { | 68 void DistillerViewer::SendJavaScript(const std::string& buffer) { |
| 63 js_buffer_ += buffer; | 69 js_buffer_ += buffer; |
| 64 } | 70 } |
| 65 | 71 |
| 66 } // namespace dom_distiller | 72 } // namespace dom_distiller |
| OLD | NEW |