Chromium Code Reviews| Index: ios/chrome/browser/reading_list/url_downloader.cc |
| diff --git a/ios/chrome/browser/reading_list/url_downloader.cc b/ios/chrome/browser/reading_list/url_downloader.cc |
| index 97e3c52d107407bd8566393e26c66b0e6f0f0bd0..f7a877edd8a7543a99213d6d4a4cf506c5ca7f88 100644 |
| --- a/ios/chrome/browser/reading_list/url_downloader.cc |
| +++ b/ios/chrome/browser/reading_list/url_downloader.cc |
| @@ -15,6 +15,7 @@ |
| #include "ios/chrome/browser/chrome_paths.h" |
| #include "ios/chrome/browser/dom_distiller/distiller_viewer.h" |
| #include "ios/web/public/web_thread.h" |
| +#include "net/base/escape.h" |
| #include "url/gurl.h" |
| namespace { |
| @@ -201,8 +202,10 @@ bool URLDownloader::CreateOfflineURLDirectory(const GURL& url) { |
| bool URLDownloader::SaveImage(const GURL& url, |
| const GURL& image_url, |
| const std::string& data, |
| - base::FilePath& path) { |
| - path = OfflineURLDirectoryPath(url).Append(base::MD5String(image_url.spec())); |
| + std::string* image_name) { |
| + std::string image_hash = base::MD5String(image_url.spec()); |
| + *image_name = image_hash; |
| + base::FilePath path = OfflineURLDirectoryPath(url).Append(image_hash); |
| if (!base::PathExists(path)) { |
| return base::WriteFile(path, data.c_str(), data.length()) > 0; |
| } |
| @@ -217,15 +220,21 @@ std::string URLDownloader::SaveAndReplaceImagesInHTML( |
| std::string mutable_html = html; |
| for (size_t i = 0; i < images.size(); i++) { |
| base::FilePath local_image_path; |
| - if (!SaveImage(url, images[i].url, images[i].data, local_image_path)) { |
| + std::string local_image_name; |
| + if (!SaveImage(url, images[i].url, images[i].data, &local_image_name)) { |
| return std::string(); |
| } |
| - const std::string& image_url = images[i].url.spec(); |
| + std::string image_url = images[i].url.spec(); |
| size_t image_url_size = image_url.size(); |
| size_t pos = mutable_html.find(image_url, 0); |
| + if (pos == std::string::npos) { |
|
jif-google
2016/11/10 15:04:51
if dom distiller will include the image at most on
Olivier
2016/11/10 16:42:11
Done.
|
| + // Try escaped URL. |
| + image_url = net::EscapeForHTML(image_url); |
| + image_url_size = image_url.size(); |
| + pos = mutable_html.find(image_url, 0); |
| + } |
| while (pos != std::string::npos) { |
| - mutable_html.replace(pos, image_url_size, |
| - local_image_path.AsUTF8Unsafe()); |
| + mutable_html.replace(pos, image_url_size, local_image_name); |
| pos = mutable_html.find(image_url, pos + image_url_size); |
| } |
| } |