| 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 25 matching lines...) Expand all Loading... |
| 36 " var imgMenuDisabler = document.createElement('style');" | 36 " var imgMenuDisabler = document.createElement('style');" |
| 37 " imgMenuDisabler.innerHTML = 'img { -webkit-touch-callout: none; }';" | 37 " imgMenuDisabler.innerHTML = 'img { -webkit-touch-callout: none; }';" |
| 38 " document.head.appendChild(imgMenuDisabler);" | 38 " document.head.appendChild(imgMenuDisabler);" |
| 39 "}, false);" | 39 "}, false);" |
| 40 "</script>"; | 40 "</script>"; |
| 41 } // namespace | 41 } // namespace |
| 42 | 42 |
| 43 // URLDownloader | 43 // URLDownloader |
| 44 | 44 |
| 45 URLDownloader::URLDownloader( | 45 URLDownloader::URLDownloader( |
| 46 dom_distiller::DomDistillerService* distiller_service, | 46 dom_distiller::DistillerFactory* distiller_factory, |
| 47 reading_list::ReadingListDistillerPageFactory* distiller_page_factory, | 47 reading_list::ReadingListDistillerPageFactory* distiller_page_factory, |
| 48 PrefService* prefs, | 48 PrefService* prefs, |
| 49 base::FilePath chrome_profile_path, | 49 base::FilePath chrome_profile_path, |
| 50 net::URLRequestContextGetter* url_request_context_getter, | 50 net::URLRequestContextGetter* url_request_context_getter, |
| 51 const DownloadCompletion& download_completion, | 51 const DownloadCompletion& download_completion, |
| 52 const SuccessCompletion& delete_completion) | 52 const SuccessCompletion& delete_completion) |
| 53 : distiller_service_(distiller_service), | 53 : distiller_page_factory_(distiller_page_factory), |
| 54 distiller_page_factory_(distiller_page_factory), | 54 distiller_factory_(distiller_factory), |
| 55 pref_service_(prefs), | 55 pref_service_(prefs), |
| 56 download_completion_(download_completion), | 56 download_completion_(download_completion), |
| 57 delete_completion_(delete_completion), | 57 delete_completion_(delete_completion), |
| 58 working_(false), | 58 working_(false), |
| 59 base_directory_(chrome_profile_path), | 59 base_directory_(chrome_profile_path), |
| 60 mime_type_(), | 60 mime_type_(), |
| 61 url_request_context_getter_(url_request_context_getter), | 61 url_request_context_getter_(url_request_context_getter), |
| 62 task_tracker_() {} | 62 task_tracker_() {} |
| 63 | 63 |
| 64 URLDownloader::~URLDownloader() { | 64 URLDownloader::~URLDownloader() { |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 return; | 167 return; |
| 168 } | 168 } |
| 169 | 169 |
| 170 original_url_ = url; | 170 original_url_ = url; |
| 171 distilled_url_ = url; | 171 distilled_url_ = url; |
| 172 std::unique_ptr<reading_list::ReadingListDistillerPage> | 172 std::unique_ptr<reading_list::ReadingListDistillerPage> |
| 173 reading_list_distiller_page = | 173 reading_list_distiller_page = |
| 174 distiller_page_factory_->CreateReadingListDistillerPage(this); | 174 distiller_page_factory_->CreateReadingListDistillerPage(this); |
| 175 | 175 |
| 176 distiller_.reset(new dom_distiller::DistillerViewer( | 176 distiller_.reset(new dom_distiller::DistillerViewer( |
| 177 distiller_service_, pref_service_, url, | 177 distiller_factory_, std::move(reading_list_distiller_page), pref_service_, |
| 178 base::Bind(&URLDownloader::DistillerCallback, base::Unretained(this)), | 178 url, |
| 179 std::move(reading_list_distiller_page))); | 179 base::Bind(&URLDownloader::DistillerCallback, base::Unretained(this)))); |
| 180 } | 180 } |
| 181 | 181 |
| 182 void URLDownloader::DistilledPageRedirectedToURL(const GURL& page_url, | 182 void URLDownloader::DistilledPageRedirectedToURL(const GURL& page_url, |
| 183 const GURL& redirected_url) { | 183 const GURL& redirected_url) { |
| 184 DCHECK(original_url_ == page_url); | 184 DCHECK(original_url_ == page_url); |
| 185 distilled_url_ = redirected_url; | 185 distilled_url_ = redirected_url; |
| 186 } | 186 } |
| 187 | 187 |
| 188 void URLDownloader::DistilledPageHasMimeType(const GURL& original_url, | 188 void URLDownloader::DistilledPageHasMimeType(const GURL& original_url, |
| 189 const std::string& mime_type) { | 189 const std::string& mime_type) { |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 | 357 |
| 358 bool URLDownloader::SaveHTMLForURL(std::string html, const GURL& url) { | 358 bool URLDownloader::SaveHTMLForURL(std::string html, const GURL& url) { |
| 359 if (html.empty()) { | 359 if (html.empty()) { |
| 360 return false; | 360 return false; |
| 361 } | 361 } |
| 362 base::FilePath path = reading_list::OfflineURLAbsolutePathFromRelativePath( | 362 base::FilePath path = reading_list::OfflineURLAbsolutePathFromRelativePath( |
| 363 base_directory_, | 363 base_directory_, |
| 364 reading_list::OfflinePagePath(url, reading_list::OFFLINE_TYPE_HTML)); | 364 reading_list::OfflinePagePath(url, reading_list::OFFLINE_TYPE_HTML)); |
| 365 return base::WriteFile(path, html.c_str(), html.length()) > 0; | 365 return base::WriteFile(path, html.c_str(), html.length()) > 0; |
| 366 } | 366 } |
| OLD | NEW |