OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
11 #include "base/i18n/file_util_icu.h" | 11 #include "base/i18n/file_util_icu.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
14 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
15 #include "base/string_piece.h" | 15 #include "base/string_piece.h" |
16 #include "base/string_split.h" | 16 #include "base/string_split.h" |
17 #include "base/sys_string_conversions.h" | 17 #include "base/sys_string_conversions.h" |
18 #include "base/task.h" | 18 #include "base/task.h" |
19 #include "base/threading/thread.h" | 19 #include "base/threading/thread.h" |
20 #include "base/utf_string_conversions.h" | 20 #include "base/utf_string_conversions.h" |
| 21 #include "chrome/browser/download/download_history.h" |
21 #include "chrome/browser/download/download_item.h" | 22 #include "chrome/browser/download/download_item.h" |
22 #include "chrome/browser/download/download_item_model.h" | 23 #include "chrome/browser/download/download_item_model.h" |
23 #include "chrome/browser/download/download_manager.h" | 24 #include "chrome/browser/download/download_manager.h" |
24 #include "chrome/browser/download/download_util.h" | 25 #include "chrome/browser/download/download_util.h" |
25 #include "chrome/browser/prefs/pref_member.h" | 26 #include "chrome/browser/prefs/pref_member.h" |
26 #include "chrome/browser/prefs/pref_service.h" | 27 #include "chrome/browser/prefs/pref_service.h" |
27 #include "chrome/browser/profiles/profile.h" | 28 #include "chrome/browser/profiles/profile.h" |
28 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.h" |
29 #include "content/browser/browser_thread.h" | 30 #include "content/browser/browser_thread.h" |
30 #include "content/browser/content_browser_client.h" | 31 #include "content/browser/content_browser_client.h" |
31 #include "content/browser/download/save_file.h" | 32 #include "content/browser/download/save_file.h" |
32 #include "content/browser/download/save_file_manager.h" | 33 #include "content/browser/download/save_file_manager.h" |
33 #include "content/browser/download/save_item.h" | 34 #include "content/browser/download/save_item.h" |
34 #include "content/browser/renderer_host/render_process_host.h" | 35 #include "content/browser/renderer_host/render_process_host.h" |
35 #include "content/browser/renderer_host/render_view_host.h" | 36 #include "content/browser/renderer_host/render_view_host.h" |
36 #include "content/browser/renderer_host/render_view_host_delegate.h" | 37 #include "content/browser/renderer_host/render_view_host_delegate.h" |
37 #include "content/browser/renderer_host/resource_dispatcher_host.h" | 38 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
38 #include "content/browser/tab_contents/tab_contents.h" | 39 #include "content/browser/tab_contents/tab_contents.h" |
39 #include "content/common/content_notification_types.h" | |
40 #include "content/common/notification_service.h" | |
41 #include "content/common/url_constants.h" | 40 #include "content/common/url_constants.h" |
42 #include "content/common/view_messages.h" | 41 #include "content/common/view_messages.h" |
43 #include "net/base/io_buffer.h" | 42 #include "net/base/io_buffer.h" |
44 #include "net/base/mime_util.h" | 43 #include "net/base/mime_util.h" |
45 #include "net/base/net_util.h" | 44 #include "net/base/net_util.h" |
46 #include "net/url_request/url_request_context.h" | 45 #include "net/url_request/url_request_context.h" |
47 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPageSerializerClie
nt.h" | 46 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPageSerializerClie
nt.h" |
48 | 47 |
49 using base::Time; | 48 using base::Time; |
50 using WebKit::WebPageSerializerClient; | 49 using WebKit::WebPageSerializerClient; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 #else | 112 #else |
114 FILE_PATH_LITERAL("html"); | 113 FILE_PATH_LITERAL("html"); |
115 #endif | 114 #endif |
116 | 115 |
117 SavePackage::SavePackage(TabContents* tab_contents, | 116 SavePackage::SavePackage(TabContents* tab_contents, |
118 SavePackageType save_type, | 117 SavePackageType save_type, |
119 const FilePath& file_full_path, | 118 const FilePath& file_full_path, |
120 const FilePath& directory_full_path) | 119 const FilePath& directory_full_path) |
121 : TabContentsObserver(tab_contents), | 120 : TabContentsObserver(tab_contents), |
122 file_manager_(NULL), | 121 file_manager_(NULL), |
| 122 download_manager_(NULL), |
123 download_(NULL), | 123 download_(NULL), |
124 page_url_(GetUrlToBeSaved()), | 124 page_url_(GetUrlToBeSaved()), |
125 saved_main_file_path_(file_full_path), | 125 saved_main_file_path_(file_full_path), |
126 saved_main_directory_path_(directory_full_path), | 126 saved_main_directory_path_(directory_full_path), |
127 title_(tab_contents->GetTitle()), | 127 title_(tab_contents->GetTitle()), |
128 finished_(false), | 128 finished_(false), |
129 user_canceled_(false), | 129 user_canceled_(false), |
130 disk_error_occurred_(false), | 130 disk_error_occurred_(false), |
131 save_type_(save_type), | 131 save_type_(save_type), |
132 all_save_items_count_(0), | 132 all_save_items_count_(0), |
133 wait_state_(INITIALIZE), | 133 wait_state_(INITIALIZE), |
134 tab_id_(tab_contents->GetRenderProcessHost()->id()), | 134 tab_id_(tab_contents->GetRenderProcessHost()->id()), |
135 unique_id_(g_save_package_id++), | 135 unique_id_(g_save_package_id++), |
136 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { | 136 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { |
137 DCHECK(page_url_.is_valid()); | 137 DCHECK(page_url_.is_valid()); |
138 DCHECK(save_type_ == SAVE_AS_ONLY_HTML || | 138 DCHECK(save_type_ == SAVE_AS_ONLY_HTML || |
139 save_type_ == SAVE_AS_COMPLETE_HTML); | 139 save_type_ == SAVE_AS_COMPLETE_HTML); |
140 DCHECK(!saved_main_file_path_.empty() && | 140 DCHECK(!saved_main_file_path_.empty() && |
141 saved_main_file_path_.value().length() <= kMaxFilePathLength); | 141 saved_main_file_path_.value().length() <= kMaxFilePathLength); |
142 DCHECK(!saved_main_directory_path_.empty() && | 142 DCHECK(!saved_main_directory_path_.empty() && |
143 saved_main_directory_path_.value().length() < kMaxFilePathLength); | 143 saved_main_directory_path_.value().length() < kMaxFilePathLength); |
144 InternalInit(); | 144 InternalInit(); |
145 } | 145 } |
146 | 146 |
147 SavePackage::SavePackage(TabContents* tab_contents) | 147 SavePackage::SavePackage(TabContents* tab_contents) |
148 : TabContentsObserver(tab_contents), | 148 : TabContentsObserver(tab_contents), |
149 file_manager_(NULL), | 149 file_manager_(NULL), |
| 150 download_manager_(NULL), |
150 download_(NULL), | 151 download_(NULL), |
151 page_url_(GetUrlToBeSaved()), | 152 page_url_(GetUrlToBeSaved()), |
152 title_(tab_contents->GetTitle()), | 153 title_(tab_contents->GetTitle()), |
153 finished_(false), | 154 finished_(false), |
154 user_canceled_(false), | 155 user_canceled_(false), |
155 disk_error_occurred_(false), | 156 disk_error_occurred_(false), |
156 save_type_(SAVE_TYPE_UNKNOWN), | 157 save_type_(SAVE_TYPE_UNKNOWN), |
157 all_save_items_count_(0), | 158 all_save_items_count_(0), |
158 wait_state_(INITIALIZE), | 159 wait_state_(INITIALIZE), |
159 tab_id_(tab_contents->GetRenderProcessHost()->id()), | 160 tab_id_(tab_contents->GetRenderProcessHost()->id()), |
160 unique_id_(g_save_package_id++), | 161 unique_id_(g_save_package_id++), |
161 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { | 162 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { |
162 DCHECK(page_url_.is_valid()); | 163 DCHECK(page_url_.is_valid()); |
163 InternalInit(); | 164 InternalInit(); |
164 } | 165 } |
165 | 166 |
166 // This is for testing use. Set |finished_| as true because we don't want | 167 // This is for testing use. Set |finished_| as true because we don't want |
167 // method Cancel to be be called in destructor in test mode. | 168 // method Cancel to be be called in destructor in test mode. |
168 // We also don't call InternalInit(). | 169 // We also don't call InternalInit(). |
169 SavePackage::SavePackage(TabContents* tab_contents, | 170 SavePackage::SavePackage(TabContents* tab_contents, |
170 const FilePath& file_full_path, | 171 const FilePath& file_full_path, |
171 const FilePath& directory_full_path) | 172 const FilePath& directory_full_path) |
172 : TabContentsObserver(tab_contents), | 173 : TabContentsObserver(tab_contents), |
173 file_manager_(NULL), | 174 file_manager_(NULL), |
| 175 download_manager_(NULL), |
174 download_(NULL), | 176 download_(NULL), |
175 saved_main_file_path_(file_full_path), | 177 saved_main_file_path_(file_full_path), |
176 saved_main_directory_path_(directory_full_path), | 178 saved_main_directory_path_(directory_full_path), |
177 finished_(true), | 179 finished_(true), |
178 user_canceled_(false), | 180 user_canceled_(false), |
179 disk_error_occurred_(false), | 181 disk_error_occurred_(false), |
180 save_type_(SAVE_TYPE_UNKNOWN), | 182 save_type_(SAVE_TYPE_UNKNOWN), |
181 all_save_items_count_(0), | 183 all_save_items_count_(0), |
182 wait_state_(INITIALIZE), | 184 wait_state_(INITIALIZE), |
183 tab_id_(0), | 185 tab_id_(0), |
184 unique_id_(g_save_package_id++), | 186 unique_id_(g_save_package_id++), |
185 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { | 187 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { |
186 } | 188 } |
187 | 189 |
188 SavePackage::~SavePackage() { | 190 SavePackage::~SavePackage() { |
189 // Stop receiving saving job's updates | 191 // Stop receiving saving job's updates |
190 if (!finished_ && !canceled()) { | 192 if (!finished_ && !canceled()) { |
191 // Unexpected quit. | 193 // Unexpected quit. |
192 Cancel(true); | 194 Cancel(true); |
193 } | 195 } |
194 | 196 |
| 197 // We should no longer be observing the DownloadManager at this point. |
| 198 CHECK(!download_manager_); |
| 199 CHECK(!download_); |
| 200 |
195 DCHECK(all_save_items_count_ == (waiting_item_queue_.size() + | 201 DCHECK(all_save_items_count_ == (waiting_item_queue_.size() + |
196 completed_count() + | 202 completed_count() + |
197 in_process_count())); | 203 in_process_count())); |
198 // Free all SaveItems. | 204 // Free all SaveItems. |
199 while (!waiting_item_queue_.empty()) { | 205 while (!waiting_item_queue_.empty()) { |
200 // We still have some items which are waiting for start to save. | 206 // We still have some items which are waiting for start to save. |
201 SaveItem* save_item = waiting_item_queue_.front(); | 207 SaveItem* save_item = waiting_item_queue_.front(); |
202 waiting_item_queue_.pop(); | 208 waiting_item_queue_.pop(); |
203 delete save_item; | 209 delete save_item; |
204 } | 210 } |
205 | 211 |
206 STLDeleteValues(&saved_success_items_); | 212 STLDeleteValues(&saved_success_items_); |
207 STLDeleteValues(&in_progress_items_); | 213 STLDeleteValues(&in_progress_items_); |
208 STLDeleteValues(&saved_failed_items_); | 214 STLDeleteValues(&saved_failed_items_); |
209 | 215 |
210 // The DownloadItem is owned by DownloadManager. | |
211 download_ = NULL; | |
212 | |
213 file_manager_ = NULL; | 216 file_manager_ = NULL; |
214 } | 217 } |
215 | 218 |
216 GURL SavePackage::GetUrlToBeSaved() { | 219 GURL SavePackage::GetUrlToBeSaved() { |
217 // Instead of using tab_contents_.GetURL here, we use url() | 220 // Instead of using tab_contents_.GetURL here, we use url() |
218 // (which is the "real" url of the page) | 221 // (which is the "real" url of the page) |
219 // from the NavigationEntry because it reflects its' origin | 222 // from the NavigationEntry because it reflects its' origin |
220 // rather than the displayed one (returned by GetURL) which may be | 223 // rather than the displayed one (returned by GetURL) which may be |
221 // different (like having "view-source:" on the front). | 224 // different (like having "view-source:" on the front). |
222 NavigationEntry* active_entry = | 225 NavigationEntry* active_entry = |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 | 261 |
259 wait_state_ = START_PROCESS; | 262 wait_state_ = START_PROCESS; |
260 | 263 |
261 // Initialize the request context and resource dispatcher. | 264 // Initialize the request context and resource dispatcher. |
262 Profile* profile = tab_contents()->profile(); | 265 Profile* profile = tab_contents()->profile(); |
263 if (!profile) { | 266 if (!profile) { |
264 NOTREACHED(); | 267 NOTREACHED(); |
265 return false; | 268 return false; |
266 } | 269 } |
267 | 270 |
268 // Create the fake DownloadItem and display the view. | 271 // Get the download manager and add ourselves as an observer. |
269 DownloadManager* download_manager = | 272 download_manager_ = tab_contents()->profile()->GetDownloadManager(); |
270 tab_contents()->profile()->GetDownloadManager(); | 273 if (!download_manager_) { |
271 download_ = new DownloadItem(download_manager, | 274 NOTREACHED(); |
| 275 return false; |
| 276 } |
| 277 |
| 278 // Create the download item. |
| 279 download_ = new DownloadItem(download_manager_, |
272 saved_main_file_path_, | 280 saved_main_file_path_, |
273 page_url_, | 281 page_url_, |
274 profile->IsOffTheRecord()); | 282 profile->IsOffTheRecord()); |
| 283 download_->AddObserver(this); |
275 | 284 |
276 // Transfer the ownership to the download manager. We need the DownloadItem | 285 // Transfer ownership to the download manager. |
277 // to be alive as long as the Profile is alive. | 286 download_manager_->SavePageDownloadStarted(download_); |
278 download_manager->SavePageAsDownloadStarted(download_); | |
279 | |
280 tab_contents()->OnStartDownload(download_); | |
281 | 287 |
282 // Check save type and process the save page job. | 288 // Check save type and process the save page job. |
283 if (save_type_ == SAVE_AS_COMPLETE_HTML) { | 289 if (save_type_ == SAVE_AS_COMPLETE_HTML) { |
284 // Get directory | 290 // Get directory |
285 DCHECK(!saved_main_directory_path_.empty()); | 291 DCHECK(!saved_main_directory_path_.empty()); |
286 GetAllSavableResourceLinksForCurrentPage(); | 292 GetAllSavableResourceLinksForCurrentPage(); |
287 } else { | 293 } else { |
288 wait_state_ = NET_FILES; | 294 wait_state_ = NET_FILES; |
289 SaveFileCreateInfo::SaveFileSource save_source = page_url_.SchemeIsFile() ? | 295 SaveFileCreateInfo::SaveFileSource save_source = page_url_.SchemeIsFile() ? |
290 SaveFileCreateInfo::SAVE_FILE_FROM_FILE : | 296 SaveFileCreateInfo::SAVE_FILE_FROM_FILE : |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
632 BrowserThread::PostTask( | 638 BrowserThread::PostTask( |
633 BrowserThread::FILE, FROM_HERE, | 639 BrowserThread::FILE, FROM_HERE, |
634 NewRunnableMethod(file_manager_, | 640 NewRunnableMethod(file_manager_, |
635 &SaveFileManager::RemoveSavedFileFromFileMap, | 641 &SaveFileManager::RemoveSavedFileFromFileMap, |
636 save_ids)); | 642 save_ids)); |
637 | 643 |
638 finished_ = true; | 644 finished_ = true; |
639 wait_state_ = FAILED; | 645 wait_state_ = FAILED; |
640 | 646 |
641 // Inform the DownloadItem we have canceled whole save page job. | 647 // Inform the DownloadItem we have canceled whole save page job. |
642 download_->Cancel(false); | 648 if (download_) { |
| 649 download_->Cancel(false); |
| 650 FinalizeDownloadEntry(); |
| 651 } |
643 } | 652 } |
644 | 653 |
645 void SavePackage::CheckFinish() { | 654 void SavePackage::CheckFinish() { |
646 if (in_process_count() || finished_) | 655 if (in_process_count() || finished_) |
647 return; | 656 return; |
648 | 657 |
649 FilePath dir = (save_type_ == SAVE_AS_COMPLETE_HTML && | 658 FilePath dir = (save_type_ == SAVE_AS_COMPLETE_HTML && |
650 saved_success_items_.size() > 1) ? | 659 saved_success_items_.size() > 1) ? |
651 saved_main_directory_path_ : FilePath(); | 660 saved_main_directory_path_ : FilePath(); |
652 | 661 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
685 for (SaveUrlItemMap::iterator it = saved_failed_items_.begin(); | 694 for (SaveUrlItemMap::iterator it = saved_failed_items_.begin(); |
686 it != saved_failed_items_.end(); ++it) | 695 it != saved_failed_items_.end(); ++it) |
687 save_ids.push_back(it->second->save_id()); | 696 save_ids.push_back(it->second->save_id()); |
688 | 697 |
689 BrowserThread::PostTask( | 698 BrowserThread::PostTask( |
690 BrowserThread::FILE, FROM_HERE, | 699 BrowserThread::FILE, FROM_HERE, |
691 NewRunnableMethod(file_manager_, | 700 NewRunnableMethod(file_manager_, |
692 &SaveFileManager::RemoveSavedFileFromFileMap, | 701 &SaveFileManager::RemoveSavedFileFromFileMap, |
693 save_ids)); | 702 save_ids)); |
694 | 703 |
695 download_->OnAllDataSaved(all_save_items_count_); | 704 if (download_) { |
696 download_->MarkAsComplete(); | 705 download_->OnAllDataSaved(all_save_items_count_); |
697 | 706 download_->MarkAsComplete(); |
698 NotificationService::current()->Notify( | 707 FinalizeDownloadEntry(); |
699 content::NOTIFICATION_SAVE_PACKAGE_SUCCESSFULLY_FINISHED, | 708 } |
700 Source<SavePackage>(this), | |
701 Details<GURL>(&page_url_)); | |
702 } | 709 } |
703 | 710 |
704 // Called for updating end state. | 711 // Called for updating end state. |
705 void SavePackage::SaveFinished(int32 save_id, int64 size, bool is_success) { | 712 void SavePackage::SaveFinished(int32 save_id, int64 size, bool is_success) { |
706 // Because we might have canceled this saving job before, | 713 // Because we might have canceled this saving job before, |
707 // so we might not find corresponding SaveItem. Just ignore it. | 714 // so we might not find corresponding SaveItem. Just ignore it. |
708 SaveItem* save_item = LookupItemInProcessBySaveId(save_id); | 715 SaveItem* save_item = LookupItemInProcessBySaveId(save_id); |
709 if (!save_item) | 716 if (!save_item) |
710 return; | 717 return; |
711 | 718 |
712 // Let SaveItem set end state. | 719 // Let SaveItem set end state. |
713 save_item->Finish(size, is_success); | 720 save_item->Finish(size, is_success); |
714 // Remove the associated save id and SavePackage. | 721 // Remove the associated save id and SavePackage. |
715 file_manager_->RemoveSaveFile(save_id, save_item->url(), this); | 722 file_manager_->RemoveSaveFile(save_id, save_item->url(), this); |
716 | 723 |
717 PutInProgressItemToSavedMap(save_item); | 724 PutInProgressItemToSavedMap(save_item); |
718 | 725 |
719 // Inform the DownloadItem to update UI. | 726 // Inform the DownloadItem to update UI. |
720 // We use the received bytes as number of saved files. | 727 // We use the received bytes as number of saved files. |
721 download_->Update(completed_count()); | 728 if (download_) |
| 729 download_->Update(completed_count()); |
722 | 730 |
723 if (save_item->save_source() == SaveFileCreateInfo::SAVE_FILE_FROM_DOM && | 731 if (save_item->save_source() == SaveFileCreateInfo::SAVE_FILE_FROM_DOM && |
724 save_item->url() == page_url_ && !save_item->received_bytes()) { | 732 save_item->url() == page_url_ && !save_item->received_bytes()) { |
725 // If size of main HTML page is 0, treat it as disk error. | 733 // If size of main HTML page is 0, treat it as disk error. |
726 Cancel(false); | 734 Cancel(false); |
727 return; | 735 return; |
728 } | 736 } |
729 | 737 |
730 if (canceled()) { | 738 if (canceled()) { |
731 DCHECK(finished_); | 739 DCHECK(finished_); |
(...skipping 20 matching lines...) Expand all Loading... |
752 return; | 760 return; |
753 } | 761 } |
754 SaveItem* save_item = it->second; | 762 SaveItem* save_item = it->second; |
755 | 763 |
756 save_item->Finish(0, false); | 764 save_item->Finish(0, false); |
757 | 765 |
758 PutInProgressItemToSavedMap(save_item); | 766 PutInProgressItemToSavedMap(save_item); |
759 | 767 |
760 // Inform the DownloadItem to update UI. | 768 // Inform the DownloadItem to update UI. |
761 // We use the received bytes as number of saved files. | 769 // We use the received bytes as number of saved files. |
762 download_->Update(completed_count()); | 770 if (download_) |
| 771 download_->Update(completed_count()); |
763 | 772 |
764 if (save_type_ == SAVE_AS_ONLY_HTML || | 773 if (save_type_ == SAVE_AS_ONLY_HTML || |
765 save_item->save_source() == SaveFileCreateInfo::SAVE_FILE_FROM_DOM) { | 774 save_item->save_source() == SaveFileCreateInfo::SAVE_FILE_FROM_DOM) { |
766 // We got error when saving page. Treat it as disk error. | 775 // We got error when saving page. Treat it as disk error. |
767 Cancel(true); | 776 Cancel(true); |
768 } | 777 } |
769 | 778 |
770 if (canceled()) { | 779 if (canceled()) { |
771 DCHECK(finished_); | 780 DCHECK(finished_); |
772 return; | 781 return; |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1016 const std::vector<GURL>& referrers_list, | 1025 const std::vector<GURL>& referrers_list, |
1017 const std::vector<GURL>& frames_list) { | 1026 const std::vector<GURL>& frames_list) { |
1018 if (wait_state_ != RESOURCES_LIST) | 1027 if (wait_state_ != RESOURCES_LIST) |
1019 return; | 1028 return; |
1020 | 1029 |
1021 DCHECK(resources_list.size() == referrers_list.size()); | 1030 DCHECK(resources_list.size() == referrers_list.size()); |
1022 all_save_items_count_ = static_cast<int>(resources_list.size()) + | 1031 all_save_items_count_ = static_cast<int>(resources_list.size()) + |
1023 static_cast<int>(frames_list.size()); | 1032 static_cast<int>(frames_list.size()); |
1024 | 1033 |
1025 // We use total bytes as the total number of files we want to save. | 1034 // We use total bytes as the total number of files we want to save. |
1026 download_->set_total_bytes(all_save_items_count_); | 1035 if (download_) |
| 1036 download_->set_total_bytes(all_save_items_count_); |
1027 | 1037 |
1028 if (all_save_items_count_) { | 1038 if (all_save_items_count_) { |
1029 // Put all sub-resources to wait list. | 1039 // Put all sub-resources to wait list. |
1030 for (int i = 0; i < static_cast<int>(resources_list.size()); ++i) { | 1040 for (int i = 0; i < static_cast<int>(resources_list.size()); ++i) { |
1031 const GURL& u = resources_list[i]; | 1041 const GURL& u = resources_list[i]; |
1032 DCHECK(u.is_valid()); | 1042 DCHECK(u.is_valid()); |
1033 SaveFileCreateInfo::SaveFileSource save_source = u.SchemeIsFile() ? | 1043 SaveFileCreateInfo::SaveFileSource save_source = u.SchemeIsFile() ? |
1034 SaveFileCreateInfo::SAVE_FILE_FROM_FILE : | 1044 SaveFileCreateInfo::SAVE_FILE_FROM_FILE : |
1035 SaveFileCreateInfo::SAVE_FILE_FROM_NET; | 1045 SaveFileCreateInfo::SAVE_FILE_FROM_NET; |
1036 SaveItem* save_item = new SaveItem(u, referrers_list[i], | 1046 SaveItem* save_item = new SaveItem(u, referrers_list[i], |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1304 bool SavePackage::IsSavableContents(const std::string& contents_mime_type) { | 1314 bool SavePackage::IsSavableContents(const std::string& contents_mime_type) { |
1305 // WebKit creates Document object when MIME type is application/xhtml+xml, | 1315 // WebKit creates Document object when MIME type is application/xhtml+xml, |
1306 // so we also support this MIME type. | 1316 // so we also support this MIME type. |
1307 return contents_mime_type == "text/html" || | 1317 return contents_mime_type == "text/html" || |
1308 contents_mime_type == "text/xml" || | 1318 contents_mime_type == "text/xml" || |
1309 contents_mime_type == "application/xhtml+xml" || | 1319 contents_mime_type == "application/xhtml+xml" || |
1310 contents_mime_type == "text/plain" || | 1320 contents_mime_type == "text/plain" || |
1311 contents_mime_type == "text/css" || | 1321 contents_mime_type == "text/css" || |
1312 net::IsSupportedJavascriptMimeType(contents_mime_type.c_str()); | 1322 net::IsSupportedJavascriptMimeType(contents_mime_type.c_str()); |
1313 } | 1323 } |
| 1324 |
| 1325 void SavePackage::StopObservation() { |
| 1326 DCHECK(download_); |
| 1327 DCHECK(download_manager_); |
| 1328 |
| 1329 download_->RemoveObserver(this); |
| 1330 download_ = NULL; |
| 1331 download_manager_ = NULL; |
| 1332 } |
| 1333 |
| 1334 void SavePackage::OnDownloadUpdated(DownloadItem* download) { |
| 1335 DCHECK(download_); |
| 1336 DCHECK(download_ == download); |
| 1337 DCHECK(download_manager_); |
| 1338 |
| 1339 // Check for removal. |
| 1340 if (download->state() == DownloadItem::REMOVING) |
| 1341 StopObservation(); |
| 1342 } |
| 1343 |
| 1344 void SavePackage::FinalizeDownloadEntry() { |
| 1345 DCHECK(download_); |
| 1346 DCHECK(download_manager_); |
| 1347 |
| 1348 download_manager_->SavePageDownloadFinished(download_); |
| 1349 StopObservation(); |
| 1350 } |
OLD | NEW |