Chromium Code Reviews| Index: content/browser/download/save_package.cc |
| diff --git a/content/browser/download/save_package.cc b/content/browser/download/save_package.cc |
| index a64f3f29176816bc4d4899e683065af34f539aa6..1caa372fc9a63f1cffce6a9c67072b967afa5601 100644 |
| --- a/content/browser/download/save_package.cc |
| +++ b/content/browser/download/save_package.cc |
| @@ -10,6 +10,7 @@ |
| #include "base/bind.h" |
| #include "base/files/file_path.h" |
| #include "base/files/file_util.h" |
| +#include "base/guid.h" |
| #include "base/i18n/file_util_icu.h" |
| #include "base/logging.h" |
| #include "base/macros.h" |
| @@ -349,13 +350,10 @@ void SavePackage::InitWithDownloadItem( |
| } else { |
| DCHECK_EQ(SAVE_PAGE_TYPE_AS_ONLY_HTML, save_type_); |
| wait_state_ = NET_FILES; |
| - SaveFileCreateInfo::SaveFileSource save_source = page_url_.SchemeIsFile() ? |
| - SaveFileCreateInfo::SAVE_FILE_FROM_FILE : |
| - SaveFileCreateInfo::SAVE_FILE_FROM_NET; |
| // Add this item to waiting list. |
| - waiting_item_queue_.push_back( |
| - new SaveItem(page_url_, Referrer(), this, save_source, |
| - FrameTreeNode::kFrameTreeNodeInvalidId)); |
| + waiting_item_queue_.push_back(new SaveItem( |
| + page_url_, Referrer(), this, SaveFileCreateInfo::SAVE_FILE_FROM_NET, |
| + FrameTreeNode::kFrameTreeNodeInvalidId)); |
| all_save_items_count_ = 1; |
| download_->SetTotalBytes(1); |
| @@ -590,16 +588,6 @@ void SavePackage::StartSave(const SaveFileCreateInfo* info) { |
| save_item->SetTargetPath(saved_main_file_path_); |
| } |
| - // If the save source is from file system, inform SaveFileManager to copy |
| - // corresponding file to the file path which this SaveItem specifies. |
| - if (info->save_source == SaveFileCreateInfo::SAVE_FILE_FROM_FILE) { |
| - BrowserThread::PostTask( |
| - BrowserThread::FILE, FROM_HERE, |
| - base::Bind(&SaveFileManager::SaveLocalFile, file_manager_, |
| - save_item->url(), save_item->id(), id())); |
| - return; |
| - } |
| - |
| // Check whether we begin to require serialized HTML data. |
| if (save_type_ == SAVE_PAGE_TYPE_AS_COMPLETE_HTML && |
| wait_state_ == HTML_DATA) { |
| @@ -842,6 +830,11 @@ void SavePackage::SaveNextFile(bool process_all_remaining_items) { |
| DCHECK(!ContainsKey(in_progress_items_, save_item->id())); |
| in_progress_items_[save_item->id()] = save_item; |
| save_item->Start(); |
| + |
| + // TODO(lukasza): https://crbug.com/616429: Pass the correct child process |
| + // id instead of always passing main frame's process id. Correctness of |
| + // security checks in ResourceDispatcherHostImpl::BeginSave depends on it |
| + // (OTOH, this only matters if OOPIFs are present). |
|
Łukasz Anforowicz
2016/06/18 00:37:20
I need to double-check how process_id/child_id and
asanka
2016/06/20 20:24:18
Thanks for calling this out. In addition to the tw
Łukasz Anforowicz
2016/06/21 16:39:34
Ack.
|
| file_manager_->SaveURL( |
| save_item->id(), save_item->url(), save_item->referrer(), |
| web_contents()->GetRenderProcessHost()->GetID(), routing_id(), |
| @@ -993,19 +986,20 @@ void SavePackage::GetSerializedHtmlWithLocalLinksForFrame( |
| target_frame_tree_node_id); |
| if (it != frame_tree_node_id_to_contained_save_items_.end()) { |
| for (const SaveItem* save_item : it->second) { |
| - // Skip items that failed to save. |
| - if (!save_item->has_final_name()) { |
| - DCHECK_EQ(SaveItem::SaveState::COMPLETE, save_item->state()); |
| - DCHECK(!save_item->success()); |
| - continue; |
| - } |
|
Łukasz Anforowicz
2016/06/18 00:37:20
I've added these checks in https://codereview.chro
asanka
2016/06/20 20:24:18
Acknowledged.
|
| - |
| // Calculate the relative path for referring to the |save_item|. |
| base::FilePath local_path(base::FilePath::kCurrentDirectory); |
| if (target_tree_node->IsMainFrame()) { |
| local_path = local_path.Append(saved_main_directory_path_.BaseName()); |
| } |
| - local_path = local_path.Append(save_item->full_path().BaseName()); |
| + if (save_item->has_final_name()) { |
| + local_path = local_path.Append(save_item->full_path().BaseName()); |
| + } else { |
| + // Skip items that failed to save. |
| + DCHECK_EQ(SaveItem::SaveState::COMPLETE, save_item->state()); |
| + DCHECK(!save_item->success()); |
| + local_path = local_path.Append(base::FilePath::FromUTF8Unsafe( |
| + "resource-failed-to-save-" + base::GenerateGUID() + ".txt")); |
|
Łukasz Anforowicz
2016/06/18 00:37:20
This is tricky. We could analyze this with an exa
asanka
2016/06/20 20:24:18
As long as we are talking about subresources, I'm
Łukasz Anforowicz
2016/06/21 16:39:34
Yes - propagating origin-specific restrictions int
|
| + } |
| // Insert the link into |url_to_local_path| or |routing_id_to_local_path|. |
| if (save_item->save_source() != SaveFileCreateInfo::SAVE_FILE_FROM_DOM) { |
| @@ -1214,12 +1208,9 @@ void SavePackage::EnqueueSavableResource(int container_frame_tree_node_id, |
| if (!url.is_valid()) |
| return; |
| - SaveFileCreateInfo::SaveFileSource save_source = |
| - url.SchemeIsFile() ? SaveFileCreateInfo::SAVE_FILE_FROM_FILE |
| - : SaveFileCreateInfo::SAVE_FILE_FROM_NET; |
| CreatePendingSaveItemDeduplicatingByUrl( |
| container_frame_tree_node_id, FrameTreeNode::kFrameTreeNodeInvalidId, url, |
| - referrer, save_source); |
| + referrer, SaveFileCreateInfo::SAVE_FILE_FROM_NET); |
| } |
| void SavePackage::EnqueueFrame(int container_frame_tree_node_id, |