| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "chrome/browser/android/offline_pages/offline_page_mhtml_archiver.h" | 5 #include "chrome/browser/android/offline_pages/offline_page_mhtml_archiver.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| 11 #include "base/guid.h" | 11 #include "base/guid.h" |
| 12 #include "base/location.h" | 12 #include "base/location.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
| 15 #include "base/threading/thread_task_runner_handle.h" | 15 #include "base/threading/thread_task_runner_handle.h" |
| 16 #include "chrome/browser/ssl/security_state_tab_helper.h" | 16 #include "chrome/browser/ssl/security_state_tab_helper.h" |
| 17 #include "components/security_state/core/security_state.h" | 17 #include "components/security_state/core/security_state.h" |
| 18 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 19 #include "content/public/browser/navigation_entry.h" |
| 19 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
| 20 #include "content/public/common/mhtml_generation_params.h" | 21 #include "content/public/common/mhtml_generation_params.h" |
| 21 #include "net/base/filename_util.h" | 22 #include "net/base/filename_util.h" |
| 22 | 23 |
| 23 namespace offline_pages { | 24 namespace offline_pages { |
| 24 namespace { | 25 namespace { |
| 25 const base::FilePath::CharType kMHTMLExtension[] = FILE_PATH_LITERAL("mhtml"); | 26 const base::FilePath::CharType kMHTMLExtension[] = FILE_PATH_LITERAL("mhtml"); |
| 26 | 27 |
| 27 void DeleteFileOnFileThread(const base::FilePath& file_path, | 28 void DeleteFileOnFileThread(const base::FilePath& file_path, |
| 28 const base::Closure& callback) { | 29 const base::Closure& callback) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 51 } | 52 } |
| 52 | 53 |
| 53 void OfflinePageMHTMLArchiver::CreateArchive( | 54 void OfflinePageMHTMLArchiver::CreateArchive( |
| 54 const base::FilePath& archives_dir, | 55 const base::FilePath& archives_dir, |
| 55 const CreateArchiveParams& create_archive_params, | 56 const CreateArchiveParams& create_archive_params, |
| 56 const CreateArchiveCallback& callback) { | 57 const CreateArchiveCallback& callback) { |
| 57 DCHECK(callback_.is_null()); | 58 DCHECK(callback_.is_null()); |
| 58 DCHECK(!callback.is_null()); | 59 DCHECK(!callback.is_null()); |
| 59 callback_ = callback; | 60 callback_ = callback; |
| 60 | 61 |
| 62 // TODO(chili): crbug/710248 These checks should probably be done inside |
| 63 // the offliner. |
| 61 if (HasConnectionSecurityError()) { | 64 if (HasConnectionSecurityError()) { |
| 62 ReportFailure(ArchiverResult::ERROR_SECURITY_CERTIFICATE); | 65 ReportFailure(ArchiverResult::ERROR_SECURITY_CERTIFICATE); |
| 63 return; | 66 return; |
| 64 } | 67 } |
| 65 | 68 |
| 69 // Don't save chrome error pages. |
| 70 if (GetPageType() == content::PageType::PAGE_TYPE_ERROR) { |
| 71 ReportFailure(ArchiverResult::ERROR_ERROR_PAGE); |
| 72 return; |
| 73 } |
| 74 |
| 75 // Don't save chrome-injected interstitial info pages |
| 76 // i.e. "This site may be dangerous. Are you sure you want to continue?" |
| 77 if (GetPageType() == content::PageType::PAGE_TYPE_INTERSTITIAL) { |
| 78 ReportFailure(ArchiverResult::ERROR_INTERSTITIAL_PAGE); |
| 79 return; |
| 80 } |
| 81 |
| 66 GenerateMHTML(archives_dir, create_archive_params); | 82 GenerateMHTML(archives_dir, create_archive_params); |
| 67 } | 83 } |
| 68 | 84 |
| 69 void OfflinePageMHTMLArchiver::GenerateMHTML( | 85 void OfflinePageMHTMLArchiver::GenerateMHTML( |
| 70 const base::FilePath& archives_dir, | 86 const base::FilePath& archives_dir, |
| 71 const CreateArchiveParams& create_archive_params) { | 87 const CreateArchiveParams& create_archive_params) { |
| 72 if (archives_dir.empty()) { | 88 if (archives_dir.empty()) { |
| 73 DVLOG(1) << "Archive path was empty. Can't create archive."; | 89 DVLOG(1) << "Archive path was empty. Can't create archive."; |
| 74 ReportFailure(ArchiverResult::ERROR_ARCHIVE_CREATION_FAILED); | 90 ReportFailure(ArchiverResult::ERROR_ARCHIVE_CREATION_FAILED); |
| 75 return; | 91 return; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 SecurityStateTabHelper::CreateForWebContents(web_contents_); | 139 SecurityStateTabHelper::CreateForWebContents(web_contents_); |
| 124 SecurityStateTabHelper* helper = | 140 SecurityStateTabHelper* helper = |
| 125 SecurityStateTabHelper::FromWebContents(web_contents_); | 141 SecurityStateTabHelper::FromWebContents(web_contents_); |
| 126 DCHECK(helper); | 142 DCHECK(helper); |
| 127 security_state::SecurityInfo security_info; | 143 security_state::SecurityInfo security_info; |
| 128 helper->GetSecurityInfo(&security_info); | 144 helper->GetSecurityInfo(&security_info); |
| 129 return security_state::SecurityLevel::DANGEROUS == | 145 return security_state::SecurityLevel::DANGEROUS == |
| 130 security_info.security_level; | 146 security_info.security_level; |
| 131 } | 147 } |
| 132 | 148 |
| 149 content::PageType OfflinePageMHTMLArchiver::GetPageType() { |
| 150 return web_contents_->GetController().GetVisibleEntry()->GetPageType(); |
| 151 } |
| 152 |
| 133 void OfflinePageMHTMLArchiver::ReportFailure(ArchiverResult result) { | 153 void OfflinePageMHTMLArchiver::ReportFailure(ArchiverResult result) { |
| 134 DCHECK(result != ArchiverResult::SUCCESSFULLY_CREATED); | 154 DCHECK(result != ArchiverResult::SUCCESSFULLY_CREATED); |
| 135 base::ThreadTaskRunnerHandle::Get()->PostTask( | 155 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 136 FROM_HERE, base::Bind(callback_, this, result, GURL(), base::FilePath(), | 156 FROM_HERE, base::Bind(callback_, this, result, GURL(), base::FilePath(), |
| 137 base::string16(), 0)); | 157 base::string16(), 0)); |
| 138 } | 158 } |
| 139 | 159 |
| 140 } // namespace offline_pages | 160 } // namespace offline_pages |
| OLD | NEW |