Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/reading_list/url_downloader.h" | 5 #include "ios/chrome/browser/reading_list/url_downloader.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 241 const std::string& html, | 241 const std::string& html, |
| 242 const std::vector<dom_distiller::DistillerViewerInterface::ImageInfo>& | 242 const std::vector<dom_distiller::DistillerViewerInterface::ImageInfo>& |
| 243 images) { | 243 images) { |
| 244 std::string mutable_html = html; | 244 std::string mutable_html = html; |
| 245 bool local_images_found = false; | 245 bool local_images_found = false; |
| 246 for (size_t i = 0; i < images.size(); i++) { | 246 for (size_t i = 0; i < images.size(); i++) { |
| 247 if (images[i].url.SchemeIs(url::kDataScheme)) { | 247 if (images[i].url.SchemeIs(url::kDataScheme)) { |
| 248 // Data URI, the data part of the image is empty, no need to store it. | 248 // Data URI, the data part of the image is empty, no need to store it. |
| 249 continue; | 249 continue; |
| 250 } | 250 } |
| 251 base::FilePath local_image_path; | 251 std::string local_image_name = ""; |
|
jif
2017/01/20 10:45:26
afaik you don't need to initialize local_image_nam
Olivier
2017/01/20 10:54:44
Done.
| |
| 252 std::string local_image_name; | 252 if (!(distilled_url_.SchemeIsCryptographic() && |
|
jif
2017/01/20 10:45:26
Because it confused me a bit, can you rewrite it a
Olivier
2017/01/20 10:54:44
Done.
| |
| 253 if (!SaveImage(url, images[i].url, images[i].data, &local_image_name)) { | 253 !images[i].url.SchemeIsCryptographic())) { |
| 254 return std::string(); | 254 // Only save images if it is not mixed content. |
| 255 // Mixed content is HTTP imaged on HTTPS pages. | |
|
jif
2017/01/20 10:45:26
s/imaged/images/
I appreciate the reminder of wha
Olivier
2017/01/20 10:54:44
Done.
| |
| 256 if (!SaveImage(url, images[i].url, images[i].data, &local_image_name)) { | |
| 257 return std::string(); | |
|
jif
2017/01/20 10:45:26
Optional nit (because not introduced by your CL, a
Olivier
2017/01/20 10:54:44
Returning the html empty will result in a distilla
| |
| 258 } | |
| 255 } | 259 } |
| 256 std::string image_url = net::EscapeForHTML(images[i].url.spec()); | 260 std::string image_url = net::EscapeForHTML(images[i].url.spec()); |
| 257 size_t image_url_size = image_url.size(); | 261 size_t image_url_size = image_url.size(); |
| 258 size_t pos = mutable_html.find(image_url, 0); | 262 size_t pos = mutable_html.find(image_url, 0); |
| 259 while (pos != std::string::npos) { | 263 while (pos != std::string::npos) { |
| 260 local_images_found = true; | 264 local_images_found = true; |
| 261 mutable_html.replace(pos, image_url_size, local_image_name); | 265 mutable_html.replace(pos, image_url_size, local_image_name); |
| 262 pos = mutable_html.find(image_url, pos + local_image_name.size()); | 266 pos = mutable_html.find(image_url, pos + local_image_name.size()); |
| 263 } | 267 } |
| 264 } | 268 } |
| 265 if (local_images_found) { | 269 if (local_images_found) { |
| 266 mutable_html += kDisableImageContextMenuScript; | 270 mutable_html += kDisableImageContextMenuScript; |
| 267 } | 271 } |
| 268 | 272 |
| 269 return mutable_html; | 273 return mutable_html; |
| 270 } | 274 } |
| 271 | 275 |
| 272 bool URLDownloader::SaveHTMLForURL(std::string html, const GURL& url) { | 276 bool URLDownloader::SaveHTMLForURL(std::string html, const GURL& url) { |
| 273 if (html.empty()) { | 277 if (html.empty()) { |
| 274 return false; | 278 return false; |
| 275 } | 279 } |
| 276 base::FilePath path = | 280 base::FilePath path = |
| 277 reading_list::OfflinePageAbsolutePath(base_directory_, url); | 281 reading_list::OfflinePageAbsolutePath(base_directory_, url); |
| 278 return base::WriteFile(path, html.c_str(), html.length()) > 0; | 282 return base::WriteFile(path, html.c_str(), html.length()) > 0; |
| 279 } | 283 } |
| OLD | NEW |