| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/download/save_package.h" | 5 #include "content/browser/download/save_package.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 GetAllSavableResourceLinksForCurrentPage(); | 304 GetAllSavableResourceLinksForCurrentPage(); |
| 305 } else if (save_type_ == content::SAVE_PAGE_TYPE_AS_MHTML) { | 305 } else if (save_type_ == content::SAVE_PAGE_TYPE_AS_MHTML) { |
| 306 web_contents()->GenerateMHTML(saved_main_file_path_, base::Bind( | 306 web_contents()->GenerateMHTML(saved_main_file_path_, base::Bind( |
| 307 &SavePackage::OnMHTMLGenerated, this)); | 307 &SavePackage::OnMHTMLGenerated, this)); |
| 308 } else { | 308 } else { |
| 309 wait_state_ = NET_FILES; | 309 wait_state_ = NET_FILES; |
| 310 SaveFileCreateInfo::SaveFileSource save_source = page_url_.SchemeIsFile() ? | 310 SaveFileCreateInfo::SaveFileSource save_source = page_url_.SchemeIsFile() ? |
| 311 SaveFileCreateInfo::SAVE_FILE_FROM_FILE : | 311 SaveFileCreateInfo::SAVE_FILE_FROM_FILE : |
| 312 SaveFileCreateInfo::SAVE_FILE_FROM_NET; | 312 SaveFileCreateInfo::SAVE_FILE_FROM_NET; |
| 313 SaveItem* save_item = new SaveItem(page_url_, | 313 SaveItem* save_item = new SaveItem(page_url_, |
| 314 GURL(), | 314 content::Referrer(), |
| 315 this, | 315 this, |
| 316 save_source); | 316 save_source); |
| 317 // Add this item to waiting list. | 317 // Add this item to waiting list. |
| 318 waiting_item_queue_.push(save_item); | 318 waiting_item_queue_.push(save_item); |
| 319 all_save_items_count_ = 1; | 319 all_save_items_count_ = 1; |
| 320 download_->SetTotalBytes(1); | 320 download_->SetTotalBytes(1); |
| 321 | 321 |
| 322 DoSavingProcess(); | 322 DoSavingProcess(); |
| 323 } | 323 } |
| 324 | 324 |
| (...skipping 752 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1077 wait_state_ = RESOURCES_LIST; | 1077 wait_state_ = RESOURCES_LIST; |
| 1078 Send(new ViewMsg_GetAllSavableResourceLinksForCurrentPage(routing_id(), | 1078 Send(new ViewMsg_GetAllSavableResourceLinksForCurrentPage(routing_id(), |
| 1079 page_url_)); | 1079 page_url_)); |
| 1080 } | 1080 } |
| 1081 | 1081 |
| 1082 // Give backend the lists which contain all resource links that have local | 1082 // Give backend the lists which contain all resource links that have local |
| 1083 // storage, after which, render process will serialize DOM for generating | 1083 // storage, after which, render process will serialize DOM for generating |
| 1084 // HTML data. | 1084 // HTML data. |
| 1085 void SavePackage::OnReceivedSavableResourceLinksForCurrentPage( | 1085 void SavePackage::OnReceivedSavableResourceLinksForCurrentPage( |
| 1086 const std::vector<GURL>& resources_list, | 1086 const std::vector<GURL>& resources_list, |
| 1087 const std::vector<GURL>& referrers_list, | 1087 const std::vector<content::Referrer>& referrers_list, |
| 1088 const std::vector<GURL>& frames_list) { | 1088 const std::vector<GURL>& frames_list) { |
| 1089 if (wait_state_ != RESOURCES_LIST) | 1089 if (wait_state_ != RESOURCES_LIST) |
| 1090 return; | 1090 return; |
| 1091 | 1091 |
| 1092 DCHECK(resources_list.size() == referrers_list.size()); | 1092 DCHECK(resources_list.size() == referrers_list.size()); |
| 1093 all_save_items_count_ = static_cast<int>(resources_list.size()) + | 1093 all_save_items_count_ = static_cast<int>(resources_list.size()) + |
| 1094 static_cast<int>(frames_list.size()); | 1094 static_cast<int>(frames_list.size()); |
| 1095 | 1095 |
| 1096 // We use total bytes as the total number of files we want to save. | 1096 // We use total bytes as the total number of files we want to save. |
| 1097 if (download_) | 1097 if (download_) |
| 1098 download_->SetTotalBytes(all_save_items_count_); | 1098 download_->SetTotalBytes(all_save_items_count_); |
| 1099 | 1099 |
| 1100 if (all_save_items_count_) { | 1100 if (all_save_items_count_) { |
| 1101 // Put all sub-resources to wait list. | 1101 // Put all sub-resources to wait list. |
| 1102 for (int i = 0; i < static_cast<int>(resources_list.size()); ++i) { | 1102 for (int i = 0; i < static_cast<int>(resources_list.size()); ++i) { |
| 1103 const GURL& u = resources_list[i]; | 1103 const GURL& u = resources_list[i]; |
| 1104 DCHECK(u.is_valid()); | 1104 DCHECK(u.is_valid()); |
| 1105 SaveFileCreateInfo::SaveFileSource save_source = u.SchemeIsFile() ? | 1105 SaveFileCreateInfo::SaveFileSource save_source = u.SchemeIsFile() ? |
| 1106 SaveFileCreateInfo::SAVE_FILE_FROM_FILE : | 1106 SaveFileCreateInfo::SAVE_FILE_FROM_FILE : |
| 1107 SaveFileCreateInfo::SAVE_FILE_FROM_NET; | 1107 SaveFileCreateInfo::SAVE_FILE_FROM_NET; |
| 1108 SaveItem* save_item = new SaveItem(u, referrers_list[i], | 1108 SaveItem* save_item = new SaveItem(u, referrers_list[i], |
| 1109 this, save_source); | 1109 this, save_source); |
| 1110 waiting_item_queue_.push(save_item); | 1110 waiting_item_queue_.push(save_item); |
| 1111 } | 1111 } |
| 1112 // Put all HTML resources to wait list. | 1112 // Put all HTML resources to wait list. |
| 1113 for (int i = 0; i < static_cast<int>(frames_list.size()); ++i) { | 1113 for (int i = 0; i < static_cast<int>(frames_list.size()); ++i) { |
| 1114 const GURL& u = frames_list[i]; | 1114 const GURL& u = frames_list[i]; |
| 1115 DCHECK(u.is_valid()); | 1115 DCHECK(u.is_valid()); |
| 1116 SaveItem* save_item = new SaveItem(u, GURL(), | 1116 SaveItem* save_item = new SaveItem(u, content::Referrer(), |
| 1117 this, SaveFileCreateInfo::SAVE_FILE_FROM_DOM); | 1117 this, SaveFileCreateInfo::SAVE_FILE_FROM_DOM); |
| 1118 waiting_item_queue_.push(save_item); | 1118 waiting_item_queue_.push(save_item); |
| 1119 } | 1119 } |
| 1120 wait_state_ = NET_FILES; | 1120 wait_state_ = NET_FILES; |
| 1121 DoSavingProcess(); | 1121 DoSavingProcess(); |
| 1122 } else { | 1122 } else { |
| 1123 // No resource files need to be saved, treat it as user cancel. | 1123 // No resource files need to be saved, treat it as user cancel. |
| 1124 Cancel(true); | 1124 Cancel(true); |
| 1125 } | 1125 } |
| 1126 } | 1126 } |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1374 } | 1374 } |
| 1375 } | 1375 } |
| 1376 | 1376 |
| 1377 void SavePackage::FinalizeDownloadEntry() { | 1377 void SavePackage::FinalizeDownloadEntry() { |
| 1378 DCHECK(download_); | 1378 DCHECK(download_); |
| 1379 DCHECK(download_manager_); | 1379 DCHECK(download_manager_); |
| 1380 | 1380 |
| 1381 download_manager_->SavePageDownloadFinished(download_); | 1381 download_manager_->SavePageDownloadFinished(download_); |
| 1382 StopObservation(); | 1382 StopObservation(); |
| 1383 } | 1383 } |
| OLD | NEW |