Chromium Code Reviews| 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 "chrome/browser/ui/download/download_tab_helper.h" | 5 #include "chrome/browser/ui/download/download_tab_helper.h" |
| 6 | 6 |
| 7 #include "chrome/browser/download/download_manager.h" | 7 #include "chrome/browser/download/download_manager.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/common/render_messages.h" | |
| 9 #include "content/browser/tab_contents/tab_contents.h" | 10 #include "content/browser/tab_contents/tab_contents.h" |
| 11 #include "content/common/view_messages.h" | |
|
jam
2011/04/15 18:53:23
you only need one of these message headers
| |
| 10 | 12 |
| 11 DownloadTabHelper::DownloadTabHelper(TabContents* tab_contents) | 13 DownloadTabHelper::DownloadTabHelper(TabContents* tab_contents) |
| 12 : tab_contents_(tab_contents) { | 14 : TabContentsObserver(tab_contents) { |
| 13 DCHECK(tab_contents_); | 15 DCHECK(tab_contents); |
| 14 } | 16 } |
| 15 | 17 |
| 16 DownloadTabHelper::~DownloadTabHelper() { | 18 DownloadTabHelper::~DownloadTabHelper() { |
| 17 } | 19 } |
| 18 | 20 |
| 19 void DownloadTabHelper::OnSavePage() { | 21 void DownloadTabHelper::OnSavePage() { |
| 20 // If we can not save the page, try to download it. | 22 // If we can not save the page, try to download it. |
| 21 if (!SavePackage::IsSavableContents(tab_contents_->contents_mime_type())) { | 23 if (!SavePackage::IsSavableContents(tab_contents()->contents_mime_type())) { |
| 22 DownloadManager* dlm = tab_contents_->profile()->GetDownloadManager(); | 24 DownloadManager* dlm = tab_contents()->profile()->GetDownloadManager(); |
| 23 const GURL& current_page_url = tab_contents_->GetURL(); | 25 const GURL& current_page_url = tab_contents()->GetURL(); |
| 24 if (dlm && current_page_url.is_valid()) | 26 if (dlm && current_page_url.is_valid()) |
| 25 dlm->DownloadUrl(current_page_url, GURL(), "", tab_contents_); | 27 dlm->DownloadUrl(current_page_url, GURL(), "", tab_contents()); |
| 26 return; | 28 return; |
| 27 } | 29 } |
| 28 | 30 |
| 29 tab_contents_->Stop(); | 31 tab_contents()->Stop(); |
| 30 | 32 |
| 31 // Create the save package and possibly prompt the user for the name to save | 33 // Create the save package and possibly prompt the user for the name to save |
| 32 // the page as. The user prompt is an asynchronous operation that runs on | 34 // the page as. The user prompt is an asynchronous operation that runs on |
| 33 // another thread. | 35 // another thread. |
| 34 save_package_ = new SavePackage(tab_contents_); | 36 save_package_ = new SavePackage(tab_contents()); |
| 35 save_package_->GetSaveInfo(); | 37 save_package_->GetSaveInfo(); |
| 36 } | 38 } |
| 37 | 39 |
| 38 // Used in automated testing to bypass prompting the user for file names. | 40 // Used in automated testing to bypass prompting the user for file names. |
| 39 // Instead, the names and paths are hard coded rather than running them through | 41 // Instead, the names and paths are hard coded rather than running them through |
| 40 // file name sanitation and extension / mime checking. | 42 // file name sanitation and extension / mime checking. |
| 41 bool DownloadTabHelper::SavePage(const FilePath& main_file, | 43 bool DownloadTabHelper::SavePage(const FilePath& main_file, |
| 42 const FilePath& dir_path, | 44 const FilePath& dir_path, |
| 43 SavePackage::SavePackageType save_type) { | 45 SavePackage::SavePackageType save_type) { |
| 44 // Stop the page from navigating. | 46 // Stop the page from navigating. |
| 45 tab_contents_->Stop(); | 47 tab_contents()->Stop(); |
| 46 | 48 |
| 47 save_package_ = | 49 save_package_ = |
| 48 new SavePackage(tab_contents_, save_type, main_file, dir_path); | 50 new SavePackage(tab_contents(), save_type, main_file, dir_path); |
| 49 return save_package_->Init(); | 51 return save_package_->Init(); |
| 50 } | 52 } |
| 51 | 53 |
| 54 bool DownloadTabHelper::OnMessageReceived(const IPC::Message& message) { | |
| 55 bool handled = true; | |
| 56 IPC_BEGIN_MESSAGE_MAP(DownloadTabHelper, message) | |
| 57 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveAs, OnSavePage) | |
| 58 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 59 IPC_END_MESSAGE_MAP() | |
| 60 | |
| 61 return handled; | |
| 62 } | |
| 63 | |
| OLD | NEW |