| 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/browser_process.h" | |
| 8 #include "chrome/browser/download/download_manager.h" | 7 #include "chrome/browser/download/download_manager.h" |
| 9 #include "chrome/browser/download/download_request_limiter.h" | |
| 10 #include "chrome/browser/download/download_util.h" | 8 #include "chrome/browser/download/download_util.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" | |
| 13 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper_delegate.
h" | |
| 14 #include "chrome/browser/ui/download/download_tab_helper_delegate.h" | |
| 15 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 10 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 16 #include "chrome/common/render_messages.h" | 11 #include "chrome/common/render_messages.h" |
| 17 #include "content/browser/tab_contents/tab_contents.h" | 12 #include "content/browser/tab_contents/tab_contents.h" |
| 18 #include "content/common/view_messages.h" | 13 #include "content/common/view_messages.h" |
| 19 | 14 |
| 20 DownloadTabHelper::DownloadTabHelper(TabContentsWrapper* tab_contents) | 15 DownloadTabHelper::DownloadTabHelper(TabContentsWrapper* tab_contents) |
| 21 : TabContentsObserver(tab_contents->tab_contents()), | 16 : TabContentsObserver(tab_contents->tab_contents()), |
| 22 tab_contents_wrapper_(tab_contents), | 17 tab_contents_wrapper_(tab_contents) { |
| 23 delegate_(NULL) { | |
| 24 DCHECK(tab_contents); | 18 DCHECK(tab_contents); |
| 25 } | 19 } |
| 26 | 20 |
| 27 DownloadTabHelper::~DownloadTabHelper() { | 21 DownloadTabHelper::~DownloadTabHelper() { |
| 28 } | 22 } |
| 29 | 23 |
| 30 void DownloadTabHelper::OnSavePage() { | 24 void DownloadTabHelper::OnSavePage() { |
| 31 // If we can not save the page, try to download it. | 25 // If we can not save the page, try to download it. |
| 32 if (!SavePackage::IsSavableContents(tab_contents()->contents_mime_type())) { | 26 if (!SavePackage::IsSavableContents(tab_contents()->contents_mime_type())) { |
| 33 DownloadManager* dlm = tab_contents()->profile()->GetDownloadManager(); | 27 DownloadManager* dlm = tab_contents()->profile()->GetDownloadManager(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 61 const FilePath& dir_path, | 55 const FilePath& dir_path, |
| 62 SavePackage::SavePackageType save_type) { | 56 SavePackage::SavePackageType save_type) { |
| 63 // Stop the page from navigating. | 57 // Stop the page from navigating. |
| 64 tab_contents()->Stop(); | 58 tab_contents()->Stop(); |
| 65 | 59 |
| 66 save_package_ = | 60 save_package_ = |
| 67 new SavePackage(tab_contents_wrapper_, save_type, main_file, dir_path); | 61 new SavePackage(tab_contents_wrapper_, save_type, main_file, dir_path); |
| 68 return save_package_->Init(); | 62 return save_package_->Init(); |
| 69 } | 63 } |
| 70 | 64 |
| 71 bool DownloadTabHelper::CanDownload(int request_id) { | |
| 72 if (delegate_) | |
| 73 return delegate_->CanDownload(request_id); | |
| 74 return true; | |
| 75 } | |
| 76 | |
| 77 void DownloadTabHelper::OnStartDownload(DownloadItem* download) { | |
| 78 DCHECK(download); | |
| 79 | |
| 80 BlockedContentTabHelperDelegate* blocked_content_delegate = | |
| 81 tab_contents_wrapper_->blocked_content_tab_helper()->delegate(); | |
| 82 if (!blocked_content_delegate) | |
| 83 return; | |
| 84 | |
| 85 // Download in a constrained popup is shown in the tab that opened it. | |
| 86 TabContentsWrapper* tab_contents = | |
| 87 blocked_content_delegate->GetConstrainingContentsWrapper( | |
| 88 tab_contents_wrapper_); | |
| 89 | |
| 90 if (tab_contents && tab_contents->download_tab_helper()->delegate()) { | |
| 91 tab_contents->download_tab_helper()->delegate()->OnStartDownload( | |
| 92 download, tab_contents_wrapper_); | |
| 93 } | |
| 94 } | |
| 95 | |
| 96 bool DownloadTabHelper::OnMessageReceived(const IPC::Message& message) { | 65 bool DownloadTabHelper::OnMessageReceived(const IPC::Message& message) { |
| 97 bool handled = true; | 66 bool handled = true; |
| 98 IPC_BEGIN_MESSAGE_MAP(DownloadTabHelper, message) | 67 IPC_BEGIN_MESSAGE_MAP(DownloadTabHelper, message) |
| 99 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL) | 68 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL) |
| 100 IPC_MESSAGE_UNHANDLED(handled = false) | 69 IPC_MESSAGE_UNHANDLED(handled = false) |
| 101 IPC_END_MESSAGE_MAP() | 70 IPC_END_MESSAGE_MAP() |
| 102 | 71 |
| 103 return handled; | 72 return handled; |
| 104 } | 73 } |
| 105 | 74 |
| 106 void DownloadTabHelper::DidGetUserGesture() { | |
| 107 DownloadRequestLimiter* limiter = | |
| 108 g_browser_process->download_request_limiter(); | |
| 109 if (limiter) | |
| 110 limiter->OnUserGesture(tab_contents()); | |
| 111 } | |
| OLD | NEW |