Chromium Code Reviews| 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 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/command_line.h" | |
| 11 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 12 #include "base/files/file_util.h" | 13 #include "base/files/file_util.h" |
| 13 #include "base/i18n/file_util_icu.h" | 14 #include "base/i18n/file_util_icu.h" |
| 14 #include "base/logging.h" | 15 #include "base/logging.h" |
| 15 #include "base/macros.h" | 16 #include "base/macros.h" |
| 16 #include "base/message_loop/message_loop.h" | 17 #include "base/message_loop/message_loop.h" |
| 17 #include "base/stl_util.h" | 18 #include "base/stl_util.h" |
| 18 #include "base/strings/string_piece.h" | 19 #include "base/strings/string_piece.h" |
| 19 #include "base/strings/string_split.h" | 20 #include "base/strings/string_split.h" |
| 20 #include "base/strings/sys_string_conversions.h" | 21 #include "base/strings/sys_string_conversions.h" |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 41 #include "content/public/browser/browser_context.h" | 42 #include "content/public/browser/browser_context.h" |
| 42 #include "content/public/browser/browser_thread.h" | 43 #include "content/public/browser/browser_thread.h" |
| 43 #include "content/public/browser/content_browser_client.h" | 44 #include "content/public/browser/content_browser_client.h" |
| 44 #include "content/public/browser/download_manager_delegate.h" | 45 #include "content/public/browser/download_manager_delegate.h" |
| 45 #include "content/public/browser/navigation_entry.h" | 46 #include "content/public/browser/navigation_entry.h" |
| 46 #include "content/public/browser/notification_service.h" | 47 #include "content/public/browser/notification_service.h" |
| 47 #include "content/public/browser/notification_types.h" | 48 #include "content/public/browser/notification_types.h" |
| 48 #include "content/public/browser/render_frame_host.h" | 49 #include "content/public/browser/render_frame_host.h" |
| 49 #include "content/public/browser/resource_context.h" | 50 #include "content/public/browser/resource_context.h" |
| 50 #include "content/public/browser/web_contents.h" | 51 #include "content/public/browser/web_contents.h" |
| 52 #include "content/public/common/content_switches.h" | |
| 51 #include "content/public/common/mhtml_generation_params.h" | 53 #include "content/public/common/mhtml_generation_params.h" |
| 52 #include "net/base/filename_util.h" | 54 #include "net/base/filename_util.h" |
| 53 #include "net/base/io_buffer.h" | 55 #include "net/base/io_buffer.h" |
| 54 #include "net/base/mime_util.h" | 56 #include "net/base/mime_util.h" |
| 55 #include "net/url_request/url_request_context.h" | 57 #include "net/url_request/url_request_context.h" |
| 56 #include "url/url_constants.h" | 58 #include "url/url_constants.h" |
| 57 | 59 |
| 58 namespace content { | 60 namespace content { |
| 59 namespace { | 61 namespace { |
| 60 | 62 |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 333 if (!download_created_callback.is_null()) | 335 if (!download_created_callback.is_null()) |
| 334 download_created_callback.Run(download_); | 336 download_created_callback.Run(download_); |
| 335 | 337 |
| 336 // Check save type and process the save page job. | 338 // Check save type and process the save page job. |
| 337 if (save_type_ == SAVE_PAGE_TYPE_AS_COMPLETE_HTML) { | 339 if (save_type_ == SAVE_PAGE_TYPE_AS_COMPLETE_HTML) { |
| 338 // Get directory | 340 // Get directory |
| 339 DCHECK(!saved_main_directory_path_.empty()); | 341 DCHECK(!saved_main_directory_path_.empty()); |
| 340 GetSavableResourceLinks(); | 342 GetSavableResourceLinks(); |
| 341 } else if (save_type_ == SAVE_PAGE_TYPE_AS_MHTML) { | 343 } else if (save_type_ == SAVE_PAGE_TYPE_AS_MHTML) { |
| 342 MHTMLGenerationParams mhtml_generation_params(saved_main_file_path_); | 344 MHTMLGenerationParams mhtml_generation_params(saved_main_file_path_); |
| 345 | |
| 346 // Check which variant of MHTML generation is required. | |
| 347 std::string MHTMLGeneratorOptionFlag = | |
|
dewittj
2016/05/24 23:03:20
Another option would be to override the default in
| |
| 348 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | |
| 349 switches::kMHTMLGeneratorOption); | |
| 350 | |
| 351 if (MHTMLGeneratorOptionFlag == "skip_nostore_main") { | |
|
dewittj
2016/05/24 23:03:20
hm, wish this could be a constant that's shared in
| |
| 352 mhtml_generation_params.cache_control_policy = | |
| 353 blink::WebFrameSerializerCacheControlPolicy:: | |
| 354 FailForNoStoreMainFrame; | |
| 355 } else if (MHTMLGeneratorOptionFlag == "skip_nostore_all") { | |
| 356 mhtml_generation_params.cache_control_policy = | |
| 357 blink::WebFrameSerializerCacheControlPolicy:: | |
| 358 SkipAnyFrameOrResourceMarkedNoStore; | |
| 359 } | |
| 360 | |
| 343 web_contents()->GenerateMHTML( | 361 web_contents()->GenerateMHTML( |
| 344 mhtml_generation_params, | 362 mhtml_generation_params, |
| 345 base::Bind(&SavePackage::OnMHTMLGenerated, this)); | 363 base::Bind(&SavePackage::OnMHTMLGenerated, this)); |
| 346 } else { | 364 } else { |
| 347 DCHECK_EQ(SAVE_PAGE_TYPE_AS_ONLY_HTML, save_type_); | 365 DCHECK_EQ(SAVE_PAGE_TYPE_AS_ONLY_HTML, save_type_); |
| 348 wait_state_ = NET_FILES; | 366 wait_state_ = NET_FILES; |
| 349 SaveFileCreateInfo::SaveFileSource save_source = page_url_.SchemeIsFile() ? | 367 SaveFileCreateInfo::SaveFileSource save_source = page_url_.SchemeIsFile() ? |
| 350 SaveFileCreateInfo::SAVE_FILE_FROM_FILE : | 368 SaveFileCreateInfo::SAVE_FILE_FROM_FILE : |
| 351 SaveFileCreateInfo::SAVE_FILE_FROM_NET; | 369 SaveFileCreateInfo::SAVE_FILE_FROM_NET; |
| 352 // Add this item to waiting list. | 370 // Add this item to waiting list. |
| (...skipping 1143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1496 } | 1514 } |
| 1497 | 1515 |
| 1498 void SavePackage::FinalizeDownloadEntry() { | 1516 void SavePackage::FinalizeDownloadEntry() { |
| 1499 DCHECK(download_); | 1517 DCHECK(download_); |
| 1500 | 1518 |
| 1501 download_manager_->OnSavePackageSuccessfullyFinished(download_); | 1519 download_manager_->OnSavePackageSuccessfullyFinished(download_); |
| 1502 StopObservation(); | 1520 StopObservation(); |
| 1503 } | 1521 } |
| 1504 | 1522 |
| 1505 } // namespace content | 1523 } // namespace content |
| OLD | NEW |