diff options
44 files changed, 263 insertions, 251 deletions
diff --git a/chrome/browser/DEPS b/chrome/browser/DEPS index 3a0f040..139f20d 100644 --- a/chrome/browser/DEPS +++ b/chrome/browser/DEPS @@ -61,7 +61,6 @@ include_rules = [ "+content/browser/download/mock_download_file.h", "+content/browser/download/mock_download_item.h", "+content/browser/download/mock_download_manager.h", - "+content/browser/download/save_package.h", "+content/browser/file_system/browser_file_system_helper.h", "+content/browser/find_pasteboard.h", "+content/browser/font_list_async.h", diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc index 06d1ec5..be09899 100644 --- a/chrome/browser/automation/automation_provider.cc +++ b/chrome/browser/automation/automation_provider.cc @@ -78,7 +78,6 @@ #include "chrome/common/pref_names.h" #include "chrome/common/render_messages.h" #include "chrome/common/url_constants.h" -#include "content/browser/download/save_package.h" #include "content/browser/renderer_host/render_view_host.h" #include "content/browser/ssl/ssl_manager.h" #include "content/public/browser/browser_thread.h" diff --git a/chrome/browser/automation/automation_provider_observers.cc b/chrome/browser/automation/automation_provider_observers.cc index 223014d..7325a5e 100644 --- a/chrome/browser/automation/automation_provider_observers.cc +++ b/chrome/browser/automation/automation_provider_observers.cc @@ -74,7 +74,6 @@ #include "chrome/common/chrome_view_type.h" #include "chrome/common/content_settings_types.h" #include "chrome/common/extensions/extension.h" -#include "content/browser/download/save_package.h" #include "content/browser/renderer_host/render_view_host.h" #include "content/public/browser/navigation_controller.h" #include "content/public/browser/notification_service.h" diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc index e10c260..a417f6c 100644 --- a/chrome/browser/automation/testing_automation_provider.cc +++ b/chrome/browser/automation/testing_automation_provider.cc @@ -1733,10 +1733,10 @@ void TestingAutomationProvider::SavePage(int tab_handle, const FilePath& dir_path, int type, bool* success) { - SavePackage::SavePackageType save_type = - static_cast<SavePackage::SavePackageType>(type); - if (save_type < SavePackage::SAVE_AS_ONLY_HTML || - save_type > SavePackage::SAVE_AS_COMPLETE_HTML) { + content::SavePageType save_type = + static_cast<content::SavePageType>(type); + if (save_type < content::SAVE_PAGE_TYPE_AS_ONLY_HTML || + save_type > content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML) { *success = false; return; } @@ -3753,7 +3753,7 @@ void TestingAutomationProvider::SaveTabContents( if (!web_contents->SavePage( FilePath(filename), FilePath(parent_directory), - SavePackage::SAVE_AS_ONLY_HTML)) { + content::SAVE_PAGE_TYPE_AS_ONLY_HTML)) { AutomationJSONReply(this, reply_message).SendError( "Could not initiate SavePage"); return; diff --git a/chrome/browser/browser_encoding_uitest.cc b/chrome/browser/browser_encoding_uitest.cc index 93bb37e..fd9e362 100644 --- a/chrome/browser/browser_encoding_uitest.cc +++ b/chrome/browser/browser_encoding_uitest.cc @@ -11,7 +11,6 @@ #include "chrome/test/automation/tab_proxy.h" #include "chrome/test/base/ui_test_utils.h" #include "chrome/test/ui/ui_test.h" -#include "content/browser/download/save_package.h" #include "content/browser/net/url_request_mock_http_job.h" static const FilePath::CharType* kTestDir = FILE_PATH_LITERAL("encoding_tests"); @@ -152,7 +151,7 @@ TEST_F(BrowserEncodingTest, FLAKY_TestOverrideEncoding) { // name to save sub resources in it. Although this test file does not have // sub resources, but the directory name is still required. EXPECT_TRUE(tab_proxy->SavePage(full_file_name, temp_sub_resource_dir_, - SavePackage::SAVE_AS_COMPLETE_HTML)); + content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML)); scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); ASSERT_TRUE(browser.get()); EXPECT_TRUE(WaitForDownloadShelfVisible(browser.get())); @@ -297,7 +296,7 @@ TEST_F(BrowserEncodingTest, MAYBE_TestEncodingAutoDetect) { expected_result_file_name = expected_result_file_name.AppendASCII( kTestDatas[i].expected_result); EXPECT_TRUE(tab->SavePage(full_saved_file_name, temp_sub_resource_dir_, - SavePackage::SAVE_AS_COMPLETE_HTML)); + content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML)); EXPECT_TRUE(WaitForDownloadShelfVisible(browser.get())); CheckFile(full_saved_file_name, expected_result_file_name, true); } diff --git a/chrome/browser/custom_handlers/protocol_handler_registry_browsertest.cc b/chrome/browser/custom_handlers/protocol_handler_registry_browsertest.cc index 74dfe8d..f882957 100644 --- a/chrome/browser/custom_handlers/protocol_handler_registry_browsertest.cc +++ b/chrome/browser/custom_handlers/protocol_handler_registry_browsertest.cc @@ -12,6 +12,7 @@ #include "chrome/browser/ui/browser.h" #include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/ui_test_utils.h" +#include "content/public/browser/navigation_controller.h" #include "content/public/browser/navigation_entry.h" #include "content/public/browser/web_contents.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebContextMenuData.h" diff --git a/chrome/browser/download/chrome_download_manager_delegate.cc b/chrome/browser/download/chrome_download_manager_delegate.cc index 695aeaf..e430200 100644 --- a/chrome/browser/download/chrome_download_manager_delegate.cc +++ b/chrome/browser/download/chrome_download_manager_delegate.cc @@ -303,13 +303,15 @@ void ChromeDownloadManagerDelegate::GetSaveDir(WebContents* web_contents, } void ChromeDownloadManagerDelegate::ChooseSavePath( - const base::WeakPtr<SavePackage>& save_package, + WebContents* web_contents, const FilePath& suggested_path, - bool can_save_as_complete) { + const FilePath::StringType& default_extension, + bool can_save_as_complete, + content::SaveFilePathPickedCallback callback) { // Deletes itself. new SavePackageFilePicker( - save_package, suggested_path, can_save_as_complete, - download_prefs_.get()); + web_contents, suggested_path, default_extension, can_save_as_complete, + download_prefs_.get(), callback); } void ChromeDownloadManagerDelegate::DownloadProgressUpdated() { diff --git a/chrome/browser/download/chrome_download_manager_delegate.h b/chrome/browser/download/chrome_download_manager_delegate.h index b8f0ff10..b04282e 100644 --- a/chrome/browser/download/chrome_download_manager_delegate.h +++ b/chrome/browser/download/chrome_download_manager_delegate.h @@ -81,9 +81,12 @@ class ChromeDownloadManagerDelegate virtual void GetSaveDir(content::WebContents* web_contents, FilePath* website_save_dir, FilePath* download_save_dir) OVERRIDE; - virtual void ChooseSavePath(const base::WeakPtr<SavePackage>& save_package, - const FilePath& suggested_path, - bool can_save_as_complete) OVERRIDE; + virtual void ChooseSavePath( + content::WebContents* web_contents, + const FilePath& suggested_path, + const FilePath::StringType& default_extension, + bool can_save_as_complete, + content::SaveFilePathPickedCallback callback) OVERRIDE; virtual void DownloadProgressUpdated() OVERRIDE; DownloadPrefs* download_prefs() { return download_prefs_.get(); } diff --git a/chrome/browser/download/download_file_picker.cc b/chrome/browser/download/download_file_picker.cc index 22d6365..2451ce6 100644 --- a/chrome/browser/download/download_file_picker.cc +++ b/chrome/browser/download/download_file_picker.cc @@ -7,7 +7,6 @@ #include "chrome/browser/download/download_prefs.h" #include "chrome/browser/platform_util.h" #include "chrome/browser/profiles/profile.h" -#include "content/browser/download/save_package.h" #include "content/public/browser/web_contents.h" #include "grit/generated_resources.h" #include "ui/base/l10n/l10n_util.h" diff --git a/chrome/browser/download/download_item_model.cc b/chrome/browser/download/download_item_model.cc index c9e2a0f..feb0c0b 100644 --- a/chrome/browser/download/download_item_model.cc +++ b/chrome/browser/download/download_item_model.cc @@ -10,7 +10,6 @@ #include "base/utf_string_conversions.h" #include "chrome/browser/download/chrome_download_manager_delegate.h" #include "chrome/common/time_format.h" -#include "content/browser/download/save_package.h" #include "content/public/browser/download_item.h" #include "grit/chromium_strings.h" #include "grit/generated_resources.h" @@ -110,48 +109,3 @@ string16 DownloadItemModel::GetStatusText() { return status_text; } - -// ----------------------------------------------------------------------------- -// SavePageModel - -SavePageModel::SavePageModel(SavePackage* save, DownloadItem* download) - : BaseDownloadItemModel(download), - save_(save) { -} - -void SavePageModel::CancelTask() { - save_->Cancel(true); -} - -string16 SavePageModel::GetStatusText() { - int64 size = download_->GetReceivedBytes(); - int64 total_size = download_->GetTotalBytes(); - - string16 status_text; - switch (download_->GetState()) { - case DownloadItem::IN_PROGRESS: - status_text = l10n_util::GetStringFUTF16( - IDS_SAVE_PAGE_PROGRESS, - base::FormatNumber(size), - base::FormatNumber(total_size)); - break; - case DownloadItem::COMPLETE: - status_text = l10n_util::GetStringUTF16(IDS_SAVE_PAGE_STATUS_COMPLETED); - break; - case DownloadItem::CANCELLED: - status_text = l10n_util::GetStringUTF16(IDS_SAVE_PAGE_STATUS_CANCELED); - break; - case DownloadItem::REMOVING: - break; - case DownloadItem::INTERRUPTED: - status_text = l10n_util::GetStringFUTF16( - IDS_SAVE_PAGE_STATUS_INTERRUPTED, - base::FormatNumber(size), - base::FormatNumber(total_size)); - break; - default: - NOTREACHED(); - } - - return status_text; -} diff --git a/chrome/browser/download/download_item_model.h b/chrome/browser/download/download_item_model.h index a658636..db81467 100644 --- a/chrome/browser/download/download_item_model.h +++ b/chrome/browser/download/download_item_model.h @@ -56,25 +56,4 @@ class DownloadItemModel : public BaseDownloadItemModel { DISALLOW_COPY_AND_ASSIGN(DownloadItemModel); }; -// This class is a model class for DownloadItemView. It provides cancel -// functionality for saving page, and also the text for displaying saving -// status. -class SavePageModel : public BaseDownloadItemModel { - public: - SavePageModel(SavePackage* save, content::DownloadItem* download); - virtual ~SavePageModel() { } - - // Cancel the page saving. - virtual void CancelTask() OVERRIDE; - - // Get page saving status text. - virtual string16 GetStatusText() OVERRIDE; - - private: - // Saving page management. - SavePackage* save_; - - DISALLOW_COPY_AND_ASSIGN(SavePageModel); -}; - #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_MODEL_H_ diff --git a/chrome/browser/download/download_prefs.cc b/chrome/browser/download/download_prefs.cc index 0c0a613..728cf16 100644 --- a/chrome/browser/download/download_prefs.cc +++ b/chrome/browser/download/download_prefs.cc @@ -20,9 +20,9 @@ #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/common/pref_names.h" -#include "content/browser/download/save_package.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/download_manager.h" +#include "content/public/browser/save_page_type.h" using content::BrowserThread; using content::DownloadManager; @@ -67,7 +67,7 @@ void DownloadPrefs::RegisterUserPrefs(PrefService* prefs) { false, PrefService::UNSYNCABLE_PREF); prefs->RegisterIntegerPref(prefs::kSaveFileType, - SavePackage::SAVE_AS_COMPLETE_HTML, + content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML, PrefService::UNSYNCABLE_PREF); // The default download path is userprofile\download. diff --git a/chrome/browser/download/download_util.cc b/chrome/browser/download/download_util.cc index 737f30a..857c3a4 100644 --- a/chrome/browser/download/download_util.cc +++ b/chrome/browser/download/download_util.cc @@ -40,6 +40,7 @@ #include "content/public/browser/download_file.h" #include "content/public/browser/download_item.h" #include "content/public/browser/download_manager.h" +#include "content/public/common/url_constants.h" #include "grit/generated_resources.h" #include "grit/locale_settings.h" #include "grit/theme_resources.h" @@ -599,4 +600,13 @@ FilePath GetCrDownloadPath(const FilePath& suggested_path) { suggested_path, FILE_PATH_LITERAL(".crdownload")); } +bool IsSavableURL(const GURL& url) { + for (int i = 0; chrome::GetSavableSchemes()[i] != NULL; ++i) { + if (url.SchemeIs(chrome::GetSavableSchemes()[i])) { + return true; + } + } + return false; +} + } // namespace download_util diff --git a/chrome/browser/download/download_util.h b/chrome/browser/download/download_util.h index c459ce6..fcfa401 100644 --- a/chrome/browser/download/download_util.h +++ b/chrome/browser/download/download_util.h @@ -20,6 +20,8 @@ #include "ui/views/view.h" #endif +class GURL; + namespace base { class DictionaryValue; } @@ -161,6 +163,9 @@ int GetUniquePathNumberWithCrDownload(const FilePath& path); // Returns a .crdownload intermediate path for the |suggested_path|. FilePath GetCrDownloadPath(const FilePath& suggested_path); +// Check whether we can do the saving page operation for the specified URL. +bool IsSavableURL(const GURL& url); + } // namespace download_util #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_UTIL_H_ diff --git a/chrome/browser/download/save_package_file_picker.cc b/chrome/browser/download/save_package_file_picker.cc index 8cec092..1249273 100644 --- a/chrome/browser/download/save_package_file_picker.cc +++ b/chrome/browser/download/save_package_file_picker.cc @@ -11,12 +11,15 @@ #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/common/pref_names.h" -#include "content/browser/download/save_package.h" #include "content/public/browser/download_manager.h" +#include "content/public/browser/render_process_host.h" +#include "content/public/browser/save_page_type.h" #include "content/public/browser/web_contents.h" #include "grit/generated_resources.h" #include "ui/base/l10n/l10n_util.h" +using content::RenderProcessHost; +using content::SavePageType; using content::WebContents; namespace { @@ -25,14 +28,14 @@ namespace { // exists only for testing. bool g_should_prompt_for_filename = true; -// Used for mapping between SavePackageType constants and the indexes above. -const SavePackage::SavePackageType kIndexToSaveType[] = { - SavePackage::SAVE_TYPE_UNKNOWN, - SavePackage::SAVE_AS_ONLY_HTML, - SavePackage::SAVE_AS_COMPLETE_HTML, +// Used for mapping between SavePageType constants and the indexes above. +const SavePageType kIndexToSaveType[] = { + content::SAVE_PAGE_TYPE_UNKNOWN, + content::SAVE_PAGE_TYPE_AS_ONLY_HTML, + content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML, }; -int SavePackageTypeToIndex(SavePackage::SavePackageType type) { +int SavePackageTypeToIndex(SavePageType type) { for (size_t i = 0; i < arraysize(kIndexToSaveType); ++i) { if (kIndexToSaveType[i] == type) return i; @@ -54,18 +57,18 @@ const int kIndexToIDS[] = { } SavePackageFilePicker::SavePackageFilePicker( - const base::WeakPtr<SavePackage>& save_package, + content::WebContents* web_contents, const FilePath& suggested_path, + const FilePath::StringType& default_extension, bool can_save_as_complete, - DownloadPrefs* download_prefs) - : save_package_(save_package) { + DownloadPrefs* download_prefs, + content::SaveFilePathPickedCallback callback) + : render_process_id_(web_contents->GetRenderProcessHost()->GetID()) { int file_type_index = SavePackageTypeToIndex( - static_cast<SavePackage::SavePackageType>( - download_prefs->save_file_type())); + static_cast<SavePageType>(download_prefs->save_file_type())); DCHECK_NE(-1, file_type_index); SelectFileDialog::FileTypeInfo file_type_info; - FilePath::StringType default_extension; // If the contents can not be saved as complete-HTML, do not show the // file filters. @@ -105,7 +108,6 @@ SavePackageFilePicker::SavePackageFilePicker( file_type_info.extension_description_overrides.push_back( l10n_util::GetStringUTF16(kIndexToIDS[kSelectFileCompleteIndex])); file_type_info.include_all_files = false; - default_extension = SavePackage::kDefaultHtmlExtension; } else { file_type_info.extensions.resize(1); file_type_info.extensions[kSelectFileHtmlOnlyIndex - 1].push_back( @@ -122,7 +124,6 @@ SavePackageFilePicker::SavePackageFilePicker( if (g_should_prompt_for_filename) { select_file_dialog_ = SelectFileDialog::Create(this); - WebContents* web_contents = save_package_->web_contents(); select_file_dialog_->SelectFile(SelectFileDialog::SELECT_SAVEAS_FILE, string16(), suggested_path, @@ -135,8 +136,7 @@ SavePackageFilePicker::SavePackageFilePicker( NULL); } else { // Just use 'suggested_path' instead of opening the dialog prompt. - save_package_->OnPathPicked( - suggested_path, kIndexToSaveType[file_type_index]); + callback.Run(suggested_path, kIndexToSaveType[file_type_index]); } } @@ -154,11 +154,11 @@ void SavePackageFilePicker::FileSelected(const FilePath& path, DCHECK(index >= kSelectFileHtmlOnlyIndex && index <= kSelectFileCompleteIndex); - if (save_package_) { - WebContents* web_contents = save_package_->web_contents(); - SavePackage::SavePackageType save_type = kIndexToSaveType[index]; + RenderProcessHost* process = RenderProcessHost::FromID(render_process_id_); + if (process) { + SavePageType save_type = kIndexToSaveType[index]; Profile* profile = - Profile::FromBrowserContext(web_contents->GetBrowserContext()); + Profile::FromBrowserContext(process->GetBrowserContext()); PrefService* prefs = profile->GetPrefs(); if (select_file_dialog_ && select_file_dialog_->HasMultipleFileTypeChoices()) @@ -173,12 +173,12 @@ void SavePackageFilePicker::FileSelected(const FilePath& path, #endif // If user change the default saving directory, we will remember it just // like IE and FireFox. - if (!web_contents->GetBrowserContext()->IsOffTheRecord() && + if (!process->GetBrowserContext()->IsOffTheRecord() && save_file_path.GetValue() != path_string) { save_file_path.SetValue(path_string); } - save_package_->OnPathPicked(path, save_type); + callback_.Run(path, save_type); } delete this; diff --git a/chrome/browser/download/save_package_file_picker.h b/chrome/browser/download/save_package_file_picker.h index 86b74a6..c3b622c 100644 --- a/chrome/browser/download/save_package_file_picker.h +++ b/chrome/browser/download/save_package_file_picker.h @@ -6,21 +6,22 @@ #define CHROME_BROWSER_DOWNLOAD_SAVE_PACKAGE_FILE_PICKER_H_ #pragma once +#include "base/callback.h" #include "base/memory/ref_counted.h" -#include "base/memory/weak_ptr.h" #include "chrome/browser/ui/select_file_dialog.h" +#include "content/public/browser/download_manager_delegate.h" class DownloadPrefs; -class FilePath; -class SavePackage; // Handles showing a dialog to the user to ask for the filename to save a page. class SavePackageFilePicker : public SelectFileDialog::Listener { public: - SavePackageFilePicker(const base::WeakPtr<SavePackage>& save_package, + SavePackageFilePicker(content::WebContents* web_contents, const FilePath& suggested_path, + const FilePath::StringType& default_extension, bool can_save_as_complete, - DownloadPrefs* download_prefs); + DownloadPrefs* download_prefs, + content::SaveFilePathPickedCallback callback); virtual ~SavePackageFilePicker(); // Used to disable prompting the user for a directory/filename of the saved @@ -34,7 +35,10 @@ class SavePackageFilePicker : public SelectFileDialog::Listener { void* params) OVERRIDE; virtual void FileSelectionCanceled(void* params) OVERRIDE; - base::WeakPtr<SavePackage> save_package_; + // Used to look up the renderer process for this request to get the context. + int render_process_id_; + + content::SaveFilePathPickedCallback callback_; // For managing select file dialogs. scoped_refptr<SelectFileDialog> select_file_dialog_; diff --git a/chrome/browser/download/save_page_browsertest.cc b/chrome/browser/download/save_page_browsertest.cc index 4985d02..835b2b1 100644 --- a/chrome/browser/download/save_page_browsertest.cc +++ b/chrome/browser/download/save_page_browsertest.cc @@ -201,7 +201,7 @@ IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveHTMLOnly) { FilePath full_file_name, dir; GetDestinationPaths("a", &full_file_name, &dir); ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir, - SavePackage::SAVE_AS_ONLY_HTML)); + content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); EXPECT_EQ(url, WaitForSavePackageToFinish()); @@ -226,7 +226,7 @@ IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveViewSourceHTMLOnly) { FilePath full_file_name, dir; GetDestinationPaths("a", &full_file_name, &dir); ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir, - SavePackage::SAVE_AS_ONLY_HTML)); + content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); EXPECT_EQ(actual_page_url, WaitForSavePackageToFinish()); @@ -245,8 +245,8 @@ IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveCompleteHTML) { FilePath full_file_name, dir; GetDestinationPaths("b", &full_file_name, &dir); - ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir, - SavePackage::SAVE_AS_COMPLETE_HTML)); + ASSERT_TRUE(GetCurrentTab()->SavePage( + full_file_name, dir, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML)); EXPECT_EQ(url, WaitForSavePackageToFinish()); @@ -279,8 +279,8 @@ IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, FileNameFromPageTitle) { std::string("Test page for saving page feature") + kAppendedExtension); FilePath dir = save_dir_.path().AppendASCII( "Test page for saving page feature_files"); - ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir, - SavePackage::SAVE_AS_COMPLETE_HTML)); + ASSERT_TRUE(GetCurrentTab()->SavePage( + full_file_name, dir, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML)); EXPECT_EQ(url, WaitForSavePackageToFinish()); @@ -306,7 +306,7 @@ IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, RemoveFromList) { FilePath full_file_name, dir; GetDestinationPaths("a", &full_file_name, &dir); ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir, - SavePackage::SAVE_AS_ONLY_HTML)); + content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); EXPECT_EQ(url, WaitForSavePackageToFinish()); @@ -332,25 +332,4 @@ IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, RemoveFromList) { full_file_name)); } -// Create a SavePackage and delete it without calling Init. -// SavePackage dtor has various asserts/checks that should not fire. -IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, ImplicitCancel) { - GURL url = NavigateToMockURL("a"); - FilePath full_file_name, dir; - GetDestinationPaths("a", &full_file_name, &dir); - scoped_refptr<SavePackage> save_package(new SavePackage(GetCurrentTab(), - SavePackage::SAVE_AS_ONLY_HTML, full_file_name, dir)); -} - -// Create a SavePackage, call Cancel, then delete it. -// SavePackage dtor has various asserts/checks that should not fire. -IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, ExplicitCancel) { - GURL url = NavigateToMockURL("a"); - FilePath full_file_name, dir; - GetDestinationPaths("a", &full_file_name, &dir); - scoped_refptr<SavePackage> save_package(new SavePackage(GetCurrentTab(), - SavePackage::SAVE_AS_ONLY_HTML, full_file_name, dir)); - save_package->Cancel(true); -} - } // namespace diff --git a/chrome/browser/download/save_page_uitest.cc b/chrome/browser/download/save_page_uitest.cc index eff6ed55..b3885b1 100644 --- a/chrome/browser/download/save_page_uitest.cc +++ b/chrome/browser/download/save_page_uitest.cc @@ -13,7 +13,6 @@ #include "chrome/test/automation/tab_proxy.h" #include "chrome/test/base/ui_test_utils.h" #include "chrome/test/ui/ui_test.h" -#include "content/browser/download/save_package.h" #include "content/browser/net/url_request_mock_http_job.h" #include "net/url_request/url_request_test_util.h" diff --git a/chrome/browser/feedback/feedback_util.cc b/chrome/browser/feedback/feedback_util.cc index 065cc80..1c22d47 100644 --- a/chrome/browser/feedback/feedback_util.cc +++ b/chrome/browser/feedback/feedback_util.cc @@ -23,6 +23,7 @@ #include "chrome/browser/ui/browser_list.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_version_info.h" +#include "content/public/browser/navigation_controller.h" #include "content/public/browser/web_contents.h" #include "content/public/common/url_fetcher.h" #include "content/public/common/url_fetcher_delegate.h" diff --git a/chrome/browser/memory_details.cc b/chrome/browser/memory_details.cc index df2d39c..727bb99 100644 --- a/chrome/browser/memory_details.cc +++ b/chrome/browser/memory_details.cc @@ -20,6 +20,7 @@ #include "content/browser/renderer_host/backing_store_manager.h" #include "content/browser/renderer_host/render_view_host.h" #include "content/public/browser/browser_thread.h" +#include "content/public/browser/navigation_controller.h" #include "content/public/browser/navigation_entry.h" #include "content/public/browser/render_process_host.h" #include "content/public/browser/render_view_host_delegate.h" diff --git a/chrome/browser/tab_contents/render_view_context_menu.cc b/chrome/browser/tab_contents/render_view_context_menu.cc index f6f1fc2..2fd71bb 100644 --- a/chrome/browser/tab_contents/render_view_context_menu.cc +++ b/chrome/browser/tab_contents/render_view_context_menu.cc @@ -23,6 +23,7 @@ #include "chrome/browser/debugger/devtools_window.h" #include "chrome/browser/download/download_service.h" #include "chrome/browser/download/download_service_factory.h" +#include "chrome/browser/download/download_util.h" #include "chrome/browser/extensions/extension_event_router.h" #include "chrome/browser/extensions/extension_host.h" #include "chrome/browser/extensions/extension_service.h" @@ -61,7 +62,6 @@ #include "chrome/common/url_constants.h" #include "content/browser/child_process_security_policy.h" #include "content/browser/download/download_stats.h" -#include "content/browser/download/save_package.h" #include "content/browser/renderer_host/render_view_host.h" #include "content/browser/renderer_host/render_widget_host_view.h" #include "content/browser/speech/speech_input_preferences.h" @@ -1237,7 +1237,7 @@ bool RenderViewContextMenu::IsCommandIdEnabled(int id) const { // different (like having "view-source:" on the front). NavigationEntry* active_entry = source_web_contents_->GetController().GetActiveEntry(); - return SavePackage::IsSavableURL( + return download_util::IsSavableURL( (active_entry) ? active_entry->GetURL() : GURL()); } diff --git a/chrome/browser/tab_contents/render_view_context_menu_browsertest.cc b/chrome/browser/tab_contents/render_view_context_menu_browsertest.cc index 6dae82f..9bc2b9f 100644 --- a/chrome/browser/tab_contents/render_view_context_menu_browsertest.cc +++ b/chrome/browser/tab_contents/render_view_context_menu_browsertest.cc @@ -12,6 +12,7 @@ #include "chrome/browser/ui/browser.h" #include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/ui_test_utils.h" +#include "content/public/browser/navigation_controller.h" #include "content/public/browser/navigation_entry.h" #include "content/public/browser/web_contents.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebContextMenuData.h" diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc index 3080871..1011ffb 100644 --- a/chrome/browser/ui/browser.cc +++ b/chrome/browser/ui/browser.cc @@ -46,6 +46,7 @@ #include "chrome/browser/download/download_service.h" #include "chrome/browser/download/download_service_factory.h" #include "chrome/browser/download/download_started_animation.h" +#include "chrome/browser/download/download_util.h" #include "chrome/browser/extensions/crx_installer.h" #include "chrome/browser/extensions/default_apps_trial.h" #include "chrome/browser/extensions/extension_browser_event_router.h" @@ -145,7 +146,6 @@ #include "chrome/common/web_apps.h" #include "content/browser/browser_url_handler.h" #include "content/browser/child_process_security_policy.h" -#include "content/browser/download/save_package.h" #include "content/browser/host_zoom_map.h" #include "content/browser/renderer_host/render_view_host.h" #include "content/browser/site_instance.h" @@ -4732,8 +4732,7 @@ void Browser::UpdateCommandsForTabState() { bool is_chrome_internal = HasInternalURL(nc.GetActiveEntry()) || current_tab->ShowingInterstitialPage(); command_updater_.UpdateCommandEnabled(IDC_ENCODING_MENU, - !is_chrome_internal && SavePackage::IsSavableContents( - current_tab->GetContentsMimeType())); + !is_chrome_internal && current_tab->IsSavable()); // Show various bits of UI // TODO(pinkerton): Disable app-mode in the model until we implement it @@ -5405,7 +5404,7 @@ int Browser::GetContentRestrictionsForSelectedTab() { NavigationEntry* active_entry = current_tab->GetController().GetActiveEntry(); // See comment in UpdateCommandsForTabState about why we call url(). - if (!SavePackage::IsSavableURL( + if (!download_util::IsSavableURL( active_entry ? active_entry->GetURL() : GURL()) || current_tab->ShowingInterstitialPage()) content_restrictions |= content::CONTENT_RESTRICTION_SAVE; diff --git a/chrome/browser/ui/cocoa/applescript/tab_applescript.mm b/chrome/browser/ui/cocoa/applescript/tab_applescript.mm index 9b64abc..8aef217 100644 --- a/chrome/browser/ui/cocoa/applescript/tab_applescript.mm +++ b/chrome/browser/ui/cocoa/applescript/tab_applescript.mm @@ -18,10 +18,10 @@ #include "chrome/browser/ui/cocoa/applescript/error_applescript.h" #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "chrome/common/url_constants.h" -#include "content/browser/download/save_package.h" #include "content/browser/renderer_host/render_view_host.h" #include "content/public/browser/navigation_controller.h" #include "content/public/browser/navigation_entry.h" +#include "content/public/browser/save_page_type.h" #include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents_delegate.h" #include "googleurl/src/gurl.h" @@ -369,22 +369,19 @@ static NSAppleEventDescriptor* valueToDescriptor(Value* value) { NSString* saveType = [dictionary objectForKey:@"FileType"]; - SavePackage::SavePackageType savePackageType = - SavePackage::SAVE_AS_COMPLETE_HTML; + content::SavePageType savePageType = content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML; if (saveType) { if ([saveType isEqualToString:@"only html"]) { - savePackageType = SavePackage::SAVE_AS_ONLY_HTML; + savePageType = content::SAVE_PAGE_TYPE_AS_ONLY_HTML; } else if ([saveType isEqualToString:@"complete html"]) { - savePackageType = SavePackage::SAVE_AS_COMPLETE_HTML; + savePageType = content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML; } else { AppleScript::SetError(AppleScript::errInvalidSaveType); return; } } - tabContents_->web_contents()->SavePage(mainFile, - directoryPath, - savePackageType); + tabContents_->web_contents()->SavePage(mainFile, directoryPath, savePageType); } - (void)handlesCloseScriptCommand:(NSScriptCommand*)command { diff --git a/chrome/browser/ui/cocoa/location_bar/location_icon_decoration.mm b/chrome/browser/ui/cocoa/location_bar/location_icon_decoration.mm index 2e08505..7ccbab6 100644 --- a/chrome/browser/ui/cocoa/location_bar/location_icon_decoration.mm +++ b/chrome/browser/ui/cocoa/location_bar/location_icon_decoration.mm @@ -7,6 +7,7 @@ #include "base/sys_string_conversions.h" #import "chrome/browser/bookmarks/bookmark_pasteboard_helper_mac.h" #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" +#include "content/public/browser/navigation_controller.h" #include "content/public/browser/navigation_entry.h" #include "content/public/browser/web_contents.h" #include "grit/generated_resources.h" diff --git a/chrome/browser/ui/views/tab_contents/tab_contents_drag_win.cc b/chrome/browser/ui/views/tab_contents/tab_contents_drag_win.cc index f6497f5..5850023 100644 --- a/chrome/browser/ui/views/tab_contents/tab_contents_drag_win.cc +++ b/chrome/browser/ui/views/tab_contents/tab_contents_drag_win.cc @@ -11,6 +11,7 @@ #include "base/bind.h" #include "base/file_path.h" #include "base/message_loop.h" +#include "base/pickle.h" #include "base/threading/platform_thread.h" #include "base/threading/thread.h" #include "base/utf_string_conversions.h" diff --git a/chrome/browser/ui/webui/options/certificate_manager_handler.cc b/chrome/browser/ui/webui/options/certificate_manager_handler.cc index ac58c40..e69d279 100644 --- a/chrome/browser/ui/webui/options/certificate_manager_handler.cc +++ b/chrome/browser/ui/webui/options/certificate_manager_handler.cc @@ -20,6 +20,7 @@ #include "content/public/browser/web_contents_view.h" #include "grit/generated_resources.h" #include "net/base/crypto_module.h" +#include "net/base/net_errors.h" #include "net/base/x509_certificate.h" #include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util_collator.h" diff --git a/chrome/browser/ui/webui/options2/certificate_manager_handler2.cc b/chrome/browser/ui/webui/options2/certificate_manager_handler2.cc index 5e6e836..9e95d9d 100644 --- a/chrome/browser/ui/webui/options2/certificate_manager_handler2.cc +++ b/chrome/browser/ui/webui/options2/certificate_manager_handler2.cc @@ -20,6 +20,7 @@ #include "content/public/browser/web_contents_view.h" #include "grit/generated_resources.h" #include "net/base/crypto_module.h" +#include "net/base/net_errors.h" #include "net/base/x509_certificate.h" #include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util_collator.h" diff --git a/chrome/test/automation/tab_proxy.cc b/chrome/test/automation/tab_proxy.cc index d15825f..b3a35ba 100644 --- a/chrome/test/automation/tab_proxy.cc +++ b/chrome/test/automation/tab_proxy.cc @@ -630,7 +630,7 @@ bool TabProxy::PrintAsync() { bool TabProxy::SavePage(const FilePath& file_name, const FilePath& dir_path, - SavePackage::SavePackageType type) { + content::SavePageType type) { if (!is_valid()) return false; diff --git a/chrome/test/automation/tab_proxy.h b/chrome/test/automation/tab_proxy.h index d86f76d..336d6d8 100644 --- a/chrome/test/automation/tab_proxy.h +++ b/chrome/test/automation/tab_proxy.h @@ -22,13 +22,14 @@ #include "chrome/test/automation/automation_handle_tracker.h" #include "chrome/test/automation/dom_element_proxy.h" #include "chrome/test/automation/javascript_execution_controller.h" -#include "content/browser/download/save_package.h" +#include "content/public/browser/save_page_type.h" #include "content/public/common/page_type.h" #include "content/public/common/security_style.h" #include "net/base/cert_status_flags.h" #include "webkit/glue/window_open_disposition.h" class BrowserProxy; +class FilePath; class GURL; namespace IPC { class Message; @@ -305,7 +306,7 @@ class TabProxy : public AutomationResourceProxy, // |dir_path| is the directory for saving resource files. |type| indicates // which type we're saving as: HTML only or the complete web page. bool SavePage(const FilePath& file_name, const FilePath& dir_path, - SavePackage::SavePackageType type) WARN_UNUSED_RESULT; + content::SavePageType type) WARN_UNUSED_RESULT; // Retrieves the number of info-bars currently showing in |count|. bool GetInfoBarCount(size_t* count) WARN_UNUSED_RESULT; diff --git a/content/browser/download/mock_download_manager_delegate.h b/content/browser/download/mock_download_manager_delegate.h index 607df77..1fb62cb 100644 --- a/content/browser/download/mock_download_manager_delegate.h +++ b/content/browser/download/mock_download_manager_delegate.h @@ -51,10 +51,12 @@ class MockDownloadManagerDelegate : public content::DownloadManagerDelegate { MOCK_METHOD3(GetSaveDir, void(content::WebContents* web_contents, FilePath* website_save_dir, FilePath* download_save_dir)); - MOCK_METHOD3(ChooseSavePath, void( - const base::WeakPtr<SavePackage>& save_package, + MOCK_METHOD5(ChooseSavePath, void( + content::WebContents* web_contents, const FilePath& suggested_path, - bool can_save_as_complete)); + const FilePath::StringType& default_extension, + bool can_save_as_complete, + content::SaveFilePathPickedCallback callback)); MOCK_METHOD0(DownloadProgressUpdated, void()); }; diff --git a/content/browser/download/save_package.cc b/content/browser/download/save_package.cc index f59df0a..c5372b8 100644 --- a/content/browser/download/save_package.cc +++ b/content/browser/download/save_package.cc @@ -116,7 +116,7 @@ const FilePath::CharType SavePackage::kDefaultHtmlExtension[] = #endif SavePackage::SavePackage(WebContents* web_contents, - SavePackageType save_type, + content::SavePageType save_type, const FilePath& file_full_path, const FilePath& directory_full_path) : content::WebContentsObserver(web_contents), @@ -137,8 +137,8 @@ SavePackage::SavePackage(WebContents* web_contents, tab_id_(web_contents->GetRenderProcessHost()->GetID()), unique_id_(g_save_package_id++) { DCHECK(page_url_.is_valid()); - DCHECK(save_type_ == SAVE_AS_ONLY_HTML || - save_type_ == SAVE_AS_COMPLETE_HTML); + DCHECK(save_type_ == content::SAVE_PAGE_TYPE_AS_ONLY_HTML || + save_type_ == content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML); DCHECK(!saved_main_file_path_.empty() && saved_main_file_path_.value().length() <= kMaxFilePathLength); DCHECK(!saved_main_directory_path_.empty() && @@ -157,7 +157,7 @@ SavePackage::SavePackage(TabContents* tab_contents) finished_(false), user_canceled_(false), disk_error_occurred_(false), - save_type_(SAVE_TYPE_UNKNOWN), + save_type_(content::SAVE_PAGE_TYPE_UNKNOWN), all_save_items_count_(0), wait_state_(INITIALIZE), tab_id_(tab_contents->GetRenderProcessHost()->GetID()), @@ -182,7 +182,7 @@ SavePackage::SavePackage(TabContents* tab_contents, finished_(true), user_canceled_(false), disk_error_occurred_(false), - save_type_(SAVE_TYPE_UNKNOWN), + save_type_(content::SAVE_PAGE_TYPE_UNKNOWN), all_save_items_count_(0), wait_state_(INITIALIZE), tab_id_(0), @@ -275,7 +275,7 @@ bool SavePackage::Init() { browser_context->IsOffTheRecord(), this); // Check save type and process the save page job. - if (save_type_ == SAVE_AS_COMPLETE_HTML) { + if (save_type_ == content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML) { // Get directory DCHECK(!saved_main_directory_path_.empty()); GetAllSavableResourceLinksForCurrentPage(); @@ -492,7 +492,7 @@ void SavePackage::StartSave(const SaveFileCreateInfo* info) { // When saving page as only-HTML, we only have a SaveItem whose url // must be page_url_. - DCHECK(save_type_ == SAVE_AS_COMPLETE_HTML); + DCHECK(save_type_ == content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML); DCHECK(!saved_main_directory_path_.empty()); // Now we get final name retrieved from GenerateFileName, we will use it @@ -518,7 +518,8 @@ void SavePackage::StartSave(const SaveFileCreateInfo* info) { } // Check whether we begin to require serialized HTML data. - if (save_type_ == SAVE_AS_COMPLETE_HTML && wait_state_ == HTML_DATA) { + if (save_type_ == content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML && + wait_state_ == HTML_DATA) { // Inform backend to serialize the all frames' DOM and send serialized // HTML data back. GetSerializedHtmlDataForCurrentPageWithLocalLinks(); @@ -632,7 +633,7 @@ void SavePackage::CheckFinish() { if (in_process_count() || finished_) return; - FilePath dir = (save_type_ == SAVE_AS_COMPLETE_HTML && + FilePath dir = (save_type_ == content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML && saved_success_items_.size() > 1) ? saved_main_directory_path_ : FilePath(); @@ -748,7 +749,7 @@ void SavePackage::SaveFailed(const GURL& save_url) { if (download_) download_->UpdateProgress(completed_count(), CurrentSpeed(), ""); - if (save_type_ == SAVE_AS_ONLY_HTML || + if (save_type_ == content::SAVE_PAGE_TYPE_AS_ONLY_HTML || save_item->save_source() == SaveFileCreateInfo::SAVE_FILE_FROM_DOM) { // We got error when saving page. Treat it as disk error. Cancel(true); @@ -828,7 +829,7 @@ int64 SavePackage::CurrentSpeed() const { // Continue processing the save page job after one SaveItem has been // finished. void SavePackage::DoSavingProcess() { - if (save_type_ == SAVE_AS_COMPLETE_HTML) { + if (save_type_ == content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML) { // We guarantee that images and JavaScripts must be downloaded first. // So when finishing all those sub-resources, we will know which // sub-resource's link can be replaced with local file path, which @@ -857,7 +858,7 @@ void SavePackage::DoSavingProcess() { } else { // Save as HTML only. DCHECK(wait_state_ == NET_FILES); - DCHECK(save_type_ == SAVE_AS_ONLY_HTML); + DCHECK(save_type_ == content::SAVE_PAGE_TYPE_AS_ONLY_HTML); if (waiting_item_queue_.size()) { DCHECK(all_save_items_count_ == waiting_item_queue_.size()); SaveNextFile(false); @@ -1116,8 +1117,7 @@ FilePath SavePackage::EnsureMimeExtension(const FilePath& name, ExtensionForMimeType(contents_mime_type); std::string mime_type; if (!suggested_extension.empty() && - (!net::GetMimeTypeFromExtension(ext, &mime_type) || - !IsSavableContents(mime_type))) { + !net::GetMimeTypeFromExtension(ext, &mime_type)) { // Extension is absent or needs to be updated. return FilePath(name.value() + FILE_PATH_LITERAL(".") + suggested_extension); @@ -1229,13 +1229,17 @@ void SavePackage::ContinueGetSaveInfo(const FilePath& suggested_path, if (!web_contents()) return; + FilePath::StringType default_extension; + if (can_save_as_complete) + default_extension = kDefaultHtmlExtension; + download_manager_->delegate()->ChooseSavePath( - AsWeakPtr(), suggested_path, can_save_as_complete); + web_contents(), suggested_path, default_extension, can_save_as_complete, + base::Bind(&SavePackage::OnPathPicked, AsWeakPtr())); } -// Called after the save file dialog box returns. void SavePackage::OnPathPicked(const FilePath& final_name, - SavePackageType type) { + content::SavePageType type) { // Ensure the filename is safe. saved_main_file_path_ = final_name; // TODO(asanka): This call may block on IO and shouldn't be made @@ -1245,7 +1249,7 @@ void SavePackage::OnPathPicked(const FilePath& final_name, saved_main_directory_path_ = saved_main_file_path_.DirName(); save_type_ = type; - if (save_type_ == SavePackage::SAVE_AS_COMPLETE_HTML) { + if (save_type_ == content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML) { // Make new directory for saving complete file. saved_main_directory_path_ = saved_main_directory_path_.Append( saved_main_file_path_.RemoveExtension().BaseName().value() + @@ -1255,28 +1259,6 @@ void SavePackage::OnPathPicked(const FilePath& final_name, Init(); } -// Static -bool SavePackage::IsSavableURL(const GURL& url) { - for (int i = 0; chrome::GetSavableSchemes()[i] != NULL; ++i) { - if (url.SchemeIs(chrome::GetSavableSchemes()[i])) { - return true; - } - } - return false; -} - -// Static -bool SavePackage::IsSavableContents(const std::string& contents_mime_type) { - // WebKit creates Document object when MIME type is application/xhtml+xml, - // so we also support this MIME type. - return contents_mime_type == "text/html" || - contents_mime_type == "text/xml" || - contents_mime_type == "application/xhtml+xml" || - contents_mime_type == "text/plain" || - contents_mime_type == "text/css" || - net::IsSupportedJavascriptMimeType(contents_mime_type.c_str()); -} - void SavePackage::StopObservation() { DCHECK(download_); DCHECK(download_manager_); diff --git a/content/browser/download/save_package.h b/content/browser/download/save_package.h index 3b7b495..3c1c514 100644 --- a/content/browser/download/save_package.h +++ b/content/browser/download/save_package.h @@ -19,6 +19,7 @@ #include "base/time.h" #include "content/common/content_export.h" #include "content/public/browser/download_item.h" +#include "content/public/browser/save_page_type.h" #include "content/public/browser/web_contents_observer.h" #include "googleurl/src/gurl.h" @@ -51,15 +52,6 @@ class CONTENT_EXPORT SavePackage public content::DownloadItem::Observer, public base::SupportsWeakPtr<SavePackage> { public: - enum SavePackageType { - // The value of the save type before its set by the user. - SAVE_TYPE_UNKNOWN = -1, - // User chose to save only the HTML of the page. - SAVE_AS_ONLY_HTML = 0, - // User chose to save complete-html page. - SAVE_AS_COMPLETE_HTML = 1 - }; - enum WaitState { // State when created but not initialized. INITIALIZE = 0, @@ -88,7 +80,7 @@ class CONTENT_EXPORT SavePackage // directory name generation / sanitization by providing well known paths // better suited for tests. SavePackage(content::WebContents* web_contents, - SavePackageType save_type, + content::SavePageType save_type, const FilePath& file_full_path, const FilePath& directory_full_path); @@ -114,12 +106,9 @@ class CONTENT_EXPORT SavePackage // total size). int PercentComplete(); - // Called by the embedder once a path is chosen by the user. - void OnPathPicked(const FilePath& final_name, SavePackageType type); - bool canceled() const { return user_canceled_ || disk_error_occurred_; } bool finished() const { return finished_; } - SavePackageType save_type() const { return save_type_; } + content::SavePageType save_type() const { return save_type_; } int tab_id() const { return tab_id_; } int id() const { return unique_id_; } TabContents* tab_contents() const; @@ -127,15 +116,6 @@ class CONTENT_EXPORT SavePackage void GetSaveInfo(); - // Statics ------------------------------------------------------------------- - - // Check whether we can do the saving page operation for the specified URL. - static bool IsSavableURL(const GURL& url); - - // Check whether we can do the saving page operation for the contents which - // have the specified MIME type. - static bool IsSavableContents(const std::string& contents_mime_type); - private: friend class base::RefCountedThreadSafe<SavePackage>; @@ -206,7 +186,7 @@ class CONTENT_EXPORT SavePackage const std::string& accept_langs); void ContinueGetSaveInfo(const FilePath& suggested_path, bool can_save_as_complete); - + void OnPathPicked(const FilePath& final_name, content::SavePageType type); void OnReceivedSavableResourceLinksForCurrentPage( const std::vector<GURL>& resources_list, const std::vector<GURL>& referrers_list, @@ -298,7 +278,7 @@ class CONTENT_EXPORT SavePackage bool disk_error_occurred_; // Type about saving page as only-html or complete-html. - SavePackageType save_type_; + content::SavePageType save_type_; // Number of all need to be saved resources. size_t all_save_items_count_; diff --git a/content/browser/download/save_package_browsertest.cc b/content/browser/download/save_package_browsertest.cc new file mode 100644 index 0000000..c46afc6 --- /dev/null +++ b/content/browser/download/save_package_browsertest.cc @@ -0,0 +1,63 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/scoped_temp_dir.h" +#include "chrome/browser/ui/browser.h" +#include "chrome/test/base/in_process_browser_test.h" +#include "chrome/test/base/ui_test_utils.h" +#include "content/browser/download/save_package.h" + +namespace { + +const char kTestFile[] = "files/save_page/a.htm"; + +class SavePackageBrowserTest : public InProcessBrowserTest { + protected: + void SetUp() OVERRIDE { + ASSERT_TRUE(save_dir_.CreateUniqueTempDir()); + InProcessBrowserTest::SetUp(); + } + + // Returns full paths of destination file and directory. + void GetDestinationPaths(const std::string& prefix, + FilePath* full_file_name, + FilePath* dir) { + *full_file_name = save_dir_.path().AppendASCII(prefix + ".htm"); + *dir = save_dir_.path().AppendASCII(prefix + "_files"); + } + + // Temporary directory we will save pages to. + ScopedTempDir save_dir_; +}; + +// Create a SavePackage and delete it without calling Init. +// SavePackage dtor has various asserts/checks that should not fire. +IN_PROC_BROWSER_TEST_F(SavePackageBrowserTest, ImplicitCancel) { + ASSERT_TRUE(test_server()->Start()); + GURL url = test_server()->GetURL(kTestFile); + ui_test_utils::NavigateToURL(browser(), url); + FilePath full_file_name, dir; + GetDestinationPaths("a", &full_file_name, &dir); + scoped_refptr<SavePackage> save_package(new SavePackage( + browser()->GetSelectedWebContents(), + content::SAVE_PAGE_TYPE_AS_ONLY_HTML, full_file_name, dir)); + ASSERT_TRUE(test_server()->Stop()); +} + +// Create a SavePackage, call Cancel, then delete it. +// SavePackage dtor has various asserts/checks that should not fire. +IN_PROC_BROWSER_TEST_F(SavePackageBrowserTest, ExplicitCancel) { + ASSERT_TRUE(test_server()->Start()); + GURL url = test_server()->GetURL(kTestFile); + ui_test_utils::NavigateToURL(browser(), url); + FilePath full_file_name, dir; + GetDestinationPaths("a", &full_file_name, &dir); + scoped_refptr<SavePackage> save_package(new SavePackage( + browser()->GetSelectedWebContents(), + content::SAVE_PAGE_TYPE_AS_ONLY_HTML, full_file_name, dir)); + save_package->Cancel(true); + ASSERT_TRUE(test_server()->Stop()); +} + +} // namespace diff --git a/content/browser/tab_contents/tab_contents.cc b/content/browser/tab_contents/tab_contents.cc index 1b6fe89..6ba5327 100644 --- a/content/browser/tab_contents/tab_contents.cc +++ b/content/browser/tab_contents/tab_contents.cc @@ -16,6 +16,7 @@ #include "content/browser/child_process_security_policy.h" #include "content/browser/debugger/devtools_manager_impl.h" #include "content/browser/download/download_stats.h" +#include "content/browser/download/save_package.h" #include "content/browser/host_zoom_map.h" #include "content/browser/in_process_webkit/session_storage_namespace.h" #include "content/browser/intents/web_intents_dispatcher_impl.h" @@ -50,6 +51,7 @@ #include "content/public/common/content_constants.h" #include "content/public/common/content_restriction.h" #include "content/public/common/url_constants.h" +#include "net/base/mime_util.h" #include "net/base/net_util.h" #include "net/url_request/url_request_context_getter.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" @@ -915,9 +917,20 @@ InterstitialPage* TabContents::GetInterstitialPage() const { return render_manager_.interstitial_page(); } +bool TabContents::IsSavable() { + // WebKit creates Document object when MIME type is application/xhtml+xml, + // so we also support this MIME type. + return contents_mime_type_ == "text/html" || + contents_mime_type_ == "text/xml" || + contents_mime_type_ == "application/xhtml+xml" || + contents_mime_type_ == "text/plain" || + contents_mime_type_ == "text/css" || + net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str()); +} + void TabContents::OnSavePage() { // If we can not save the page, try to download it. - if (!SavePackage::IsSavableContents(GetContentsMimeType())) { + if (!IsSavable()) { DownloadManager* dlm = GetBrowserContext()->GetDownloadManager(); const GURL& current_page_url = GetURL(); if (dlm && current_page_url.is_valid()) { @@ -941,7 +954,7 @@ void TabContents::OnSavePage() { // Instead, the names and paths are hard coded rather than running them through // file name sanitation and extension / mime checking. bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path, - SavePackage::SavePackageType save_type) { + content::SavePageType save_type) { // Stop the page from navigating. Stop(); diff --git a/content/browser/tab_contents/tab_contents.h b/content/browser/tab_contents/tab_contents.h index 058e650..6d9e277 100644 --- a/content/browser/tab_contents/tab_contents.h +++ b/content/browser/tab_contents/tab_contents.h @@ -33,6 +33,7 @@ class LoadNotificationDetails; class RenderViewHost; +class SavePackage; class SessionStorageNamespace; class SiteInstance; struct ViewHostMsg_DidFailProvisionalLoadWithError_Params; @@ -179,10 +180,11 @@ class CONTENT_EXPORT TabContents virtual void FocusThroughTabTraversal(bool reverse) OVERRIDE; virtual bool ShowingInterstitialPage() const OVERRIDE; virtual InterstitialPage* GetInterstitialPage() const OVERRIDE; + virtual bool IsSavable() OVERRIDE; virtual void OnSavePage() OVERRIDE; virtual bool SavePage(const FilePath& main_file, const FilePath& dir_path, - SavePackage::SavePackageType save_type) OVERRIDE; + content::SavePageType save_type) OVERRIDE; virtual bool IsActiveEntry(int32 page_id) OVERRIDE; virtual const std::string& GetContentsMimeType() const OVERRIDE; diff --git a/content/content_browser.gypi b/content/content_browser.gypi index f60b942..1c9bd79 100644 --- a/content/content_browser.gypi +++ b/content/content_browser.gypi @@ -79,6 +79,7 @@ 'public/browser/resource_dispatcher_host_delegate.cc', 'public/browser/resource_dispatcher_host_delegate.h', 'public/browser/resource_dispatcher_host_login_delegate.h', + 'public/browser/save_page_type.h', 'public/browser/sensors.h', 'public/browser/sensors_listener.h', 'public/browser/ssl_status.cc', diff --git a/content/public/browser/DEPS b/content/public/browser/DEPS index 85dabc6..6013335 100644 --- a/content/public/browser/DEPS +++ b/content/public/browser/DEPS @@ -5,7 +5,6 @@ include_rules = [ # TODO(jam): remove "+content/browser/download/download_id.h", "+content/browser/download/download_state_info.h", - "+content/browser/download/save_package.h", "+content/browser/download/interrupt_reasons.h", "+content/browser/javascript_dialogs.h", "+content/browser/tab_contents/navigation_controller.h", diff --git a/content/public/browser/download_manager_delegate.h b/content/public/browser/download_manager_delegate.h index a92301e..722aac7 100644 --- a/content/public/browser/download_manager_delegate.h +++ b/content/public/browser/download_manager_delegate.h @@ -7,17 +7,19 @@ #pragma once #include "base/basictypes.h" -#include "base/memory/weak_ptr.h" +#include "base/callback.h" +#include "base/file_path.h" #include "base/time.h" - -class FilePath; -class SavePackage; +#include "content/public/browser/save_page_type.h" namespace content { class DownloadItem; class WebContents; +typedef base::Callback<void(const FilePath&, content::SavePageType)> + SaveFilePathPickedCallback; + // Browser's download manager: manages all downloads and destination view. class DownloadManagerDelegate { public: @@ -106,11 +108,13 @@ class DownloadManagerDelegate { FilePath* website_save_dir, FilePath* download_save_dir) = 0; - // Asks the user for the path to save a page. The delegate calls - // SavePackage::OnPathPicked to give the answer. - virtual void ChooseSavePath(const base::WeakPtr<SavePackage>& save_package, + // Asks the user for the path to save a page. The delegate calls the callback + // to give the answer. + virtual void ChooseSavePath(WebContents* web_contents, const FilePath& suggested_path, - bool can_save_as_complete) = 0; + const FilePath::StringType& default_extension, + bool can_save_as_complete, + SaveFilePathPickedCallback callback) = 0; // Informs the delegate that the progress of downloads has changed. virtual void DownloadProgressUpdated() = 0; diff --git a/content/public/browser/save_page_type.h b/content/public/browser/save_page_type.h new file mode 100644 index 0000000..81c7803 --- /dev/null +++ b/content/public/browser/save_page_type.h @@ -0,0 +1,22 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CONTENT_PUBLIC_BROWSER_SAVE_PAGE_TYPE_H_ +#define CONTENT_PUBLIC_BROWSER_SAVE_PAGE_TYPE_H_ +#pragma once + +namespace content { + +enum SavePageType { + // The value of the save type before its set by the user. + SAVE_PAGE_TYPE_UNKNOWN = -1, + // User chose to save only the HTML of the page. + SAVE_PAGE_TYPE_AS_ONLY_HTML = 0, + // User chose to save complete-html page. + SAVE_PAGE_TYPE_AS_COMPLETE_HTML = 1 +}; + +} + +#endif // CONTENT_PUBLIC_BROWSER_SAVE_PAGE_TYPE_H_ diff --git a/content/public/browser/web_contents.h b/content/public/browser/web_contents.h index acb2623..393f984 100644 --- a/content/public/browser/web_contents.h +++ b/content/public/browser/web_contents.h @@ -9,9 +9,9 @@ #include "base/basictypes.h" #include "base/process_util.h" #include "base/string16.h" -#include "content/browser/download/save_package.h" #include "content/common/content_export.h" #include "content/public/browser/page_navigator.h" +#include "content/public/browser/save_page_type.h" #include "content/public/browser/web_ui.h" #include "content/public/common/view_type.h" #include "ui/gfx/native_widget_types.h" @@ -262,6 +262,10 @@ class WebContents : public PageNavigator { // Misc state & callbacks ---------------------------------------------------- + // Check whether we can do the saving page operation this page given its MIME + // type. + virtual bool IsSavable() = 0; + // Prepare for saving the current web page to disk. virtual void OnSavePage() = 0; @@ -270,7 +274,7 @@ class WebContents : public PageNavigator { // saving process has been initiated successfully. virtual bool SavePage(const FilePath& main_file, const FilePath& dir_path, - SavePackage::SavePackageType save_type) = 0; + SavePageType save_type) = 0; // Returns true if the active NavigationEntry's page_id equals page_id. virtual bool IsActiveEntry(int32 page_id) = 0; diff --git a/content/public/common/url_constants.h b/content/public/common/url_constants.h index d0824bc..2c02972 100644 --- a/content/public/common/url_constants.h +++ b/content/public/common/url_constants.h @@ -14,7 +14,7 @@ namespace chrome { // Null terminated list of schemes that are savable. This function can be // invoked on any thread. -const char** GetSavableSchemes(); +CONTENT_EXPORT const char** GetSavableSchemes(); // Canonical schemes you can use as input to GURL.SchemeIs(). // TODO(jam): some of these don't below in the content layer, but are accessed diff --git a/content/shell/shell_download_manager_delegate.cc b/content/shell/shell_download_manager_delegate.cc index 2ee3a7d..67ff59a 100644 --- a/content/shell/shell_download_manager_delegate.cc +++ b/content/shell/shell_download_manager_delegate.cc @@ -196,9 +196,11 @@ void ShellDownloadManagerDelegate::GetSaveDir( } void ShellDownloadManagerDelegate::ChooseSavePath( - const base::WeakPtr<SavePackage>& save_package, + WebContents* web_contents, const FilePath& suggested_path, - bool can_save_as_complete) { + const FilePath::StringType& default_extension, + bool can_save_as_complete, + SaveFilePathPickedCallback callback) { } void ShellDownloadManagerDelegate::DownloadProgressUpdated() { diff --git a/content/shell/shell_download_manager_delegate.h b/content/shell/shell_download_manager_delegate.h index 1eaea2f..d46ac43 100644 --- a/content/shell/shell_download_manager_delegate.h +++ b/content/shell/shell_download_manager_delegate.h @@ -49,9 +49,12 @@ class ShellDownloadManagerDelegate virtual void GetSaveDir(WebContents* web_contents, FilePath* website_save_dir, FilePath* download_save_dir) OVERRIDE; - virtual void ChooseSavePath(const base::WeakPtr<SavePackage>& save_package, - const FilePath& suggested_path, - bool can_save_as_complete) OVERRIDE; + virtual void ChooseSavePath( + content::WebContents* web_contents, + const FilePath& suggested_path, + const FilePath::StringType& default_extension, + bool can_save_as_complete, + content::SaveFilePathPickedCallback callback) OVERRIDE; virtual void DownloadProgressUpdated() OVERRIDE; private: |