| 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; | |
| 252 std::string local_image_name; | 251 std::string local_image_name; |
| 253 if (!SaveImage(url, images[i].url, images[i].data, &local_image_name)) { | 252 // Mixed content is HTTP images on HTTPS pages. |
| 254 return std::string(); | 253 bool image_is_mixed_content = distilled_url_.SchemeIsCryptographic() && |
| 254 !images[i].url.SchemeIsCryptographic(); |
| 255 // Only save images if it is not mixed content. |
| 256 if (!image_is_mixed_content) { |
| 257 if (!SaveImage(url, images[i].url, images[i].data, &local_image_name)) { |
| 258 return std::string(); |
| 259 } |
| 255 } | 260 } |
| 256 std::string image_url = net::EscapeForHTML(images[i].url.spec()); | 261 std::string image_url = net::EscapeForHTML(images[i].url.spec()); |
| 257 size_t image_url_size = image_url.size(); | 262 size_t image_url_size = image_url.size(); |
| 258 size_t pos = mutable_html.find(image_url, 0); | 263 size_t pos = mutable_html.find(image_url, 0); |
| 259 while (pos != std::string::npos) { | 264 while (pos != std::string::npos) { |
| 260 local_images_found = true; | 265 local_images_found = true; |
| 261 mutable_html.replace(pos, image_url_size, local_image_name); | 266 mutable_html.replace(pos, image_url_size, local_image_name); |
| 262 pos = mutable_html.find(image_url, pos + local_image_name.size()); | 267 pos = mutable_html.find(image_url, pos + local_image_name.size()); |
| 263 } | 268 } |
| 264 } | 269 } |
| 265 if (local_images_found) { | 270 if (local_images_found) { |
| 266 mutable_html += kDisableImageContextMenuScript; | 271 mutable_html += kDisableImageContextMenuScript; |
| 267 } | 272 } |
| 268 | 273 |
| 269 return mutable_html; | 274 return mutable_html; |
| 270 } | 275 } |
| 271 | 276 |
| 272 bool URLDownloader::SaveHTMLForURL(std::string html, const GURL& url) { | 277 bool URLDownloader::SaveHTMLForURL(std::string html, const GURL& url) { |
| 273 if (html.empty()) { | 278 if (html.empty()) { |
| 274 return false; | 279 return false; |
| 275 } | 280 } |
| 276 base::FilePath path = | 281 base::FilePath path = |
| 277 reading_list::OfflinePageAbsolutePath(base_directory_, url); | 282 reading_list::OfflinePageAbsolutePath(base_directory_, url); |
| 278 return base::WriteFile(path, html.c_str(), html.length()) > 0; | 283 return base::WriteFile(path, html.c_str(), html.length()) > 0; |
| 279 } | 284 } |
| OLD | NEW |