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

Side by Side Diff: ios/chrome/browser/reading_list/url_downloader.cc

Issue 2683393002: [iOS Reading List] Skip invalid images in distillation. (Closed)
Patch Set: Created 3 years, 10 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 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 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 bool local_images_found = false; 326 bool local_images_found = false;
327 for (size_t i = 0; i < images.size(); i++) { 327 for (size_t i = 0; i < images.size(); i++) {
328 if (images[i].url.SchemeIs(url::kDataScheme)) { 328 if (images[i].url.SchemeIs(url::kDataScheme)) {
329 // Data URI, the data part of the image is empty, no need to store it. 329 // Data URI, the data part of the image is empty, no need to store it.
330 continue; 330 continue;
331 } 331 }
332 std::string local_image_name; 332 std::string local_image_name;
333 // Mixed content is HTTP images on HTTPS pages. 333 // Mixed content is HTTP images on HTTPS pages.
334 bool image_is_mixed_content = distilled_url_.SchemeIsCryptographic() && 334 bool image_is_mixed_content = distilled_url_.SchemeIsCryptographic() &&
335 !images[i].url.SchemeIsCryptographic(); 335 !images[i].url.SchemeIsCryptographic();
336 // Only save images if it is not mixed content. 336 // Only save images if it is not mixed content and image data is valid.
337 if (!image_is_mixed_content) { 337 if (!image_is_mixed_content && images[i].url.is_valid() &&
338 !images[i].data.empty()) {
338 if (!SaveImage(url, images[i].url, images[i].data, &local_image_name)) { 339 if (!SaveImage(url, images[i].url, images[i].data, &local_image_name)) {
339 return std::string(); 340 return std::string();
340 } 341 }
341 } 342 }
342 std::string image_url = net::EscapeForHTML(images[i].url.spec()); 343 std::string image_url = net::EscapeForHTML(images[i].url.spec());
343 size_t image_url_size = image_url.size(); 344 size_t image_url_size = image_url.size();
344 size_t pos = mutable_html.find(image_url, 0); 345 size_t pos = mutable_html.find(image_url, 0);
345 while (pos != std::string::npos) { 346 while (pos != std::string::npos) {
346 local_images_found = true; 347 local_images_found = true;
347 mutable_html.replace(pos, image_url_size, local_image_name); 348 mutable_html.replace(pos, image_url_size, local_image_name);
348 pos = mutable_html.find(image_url, pos + local_image_name.size()); 349 pos = mutable_html.find(image_url, pos + local_image_name.size());
349 } 350 }
350 } 351 }
351 if (local_images_found) { 352 if (local_images_found) {
352 mutable_html += kDisableImageContextMenuScript; 353 mutable_html += kDisableImageContextMenuScript;
353 } 354 }
354 355
355 return mutable_html; 356 return mutable_html;
356 } 357 }
357 358
358 bool URLDownloader::SaveHTMLForURL(std::string html, const GURL& url) { 359 bool URLDownloader::SaveHTMLForURL(std::string html, const GURL& url) {
359 if (html.empty()) { 360 if (html.empty()) {
360 return false; 361 return false;
361 } 362 }
362 base::FilePath path = reading_list::OfflineURLAbsolutePathFromRelativePath( 363 base::FilePath path = reading_list::OfflineURLAbsolutePathFromRelativePath(
363 base_directory_, 364 base_directory_,
364 reading_list::OfflinePagePath(url, reading_list::OFFLINE_TYPE_HTML)); 365 reading_list::OfflinePagePath(url, reading_list::OFFLINE_TYPE_HTML));
365 return base::WriteFile(path, html.c_str(), html.length()) > 0; 366 return base::WriteFile(path, html.c_str(), html.length()) > 0;
366 } 367 }
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