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" |
7 #include "chrome/browser/download/download_manager.h" | 8 #include "chrome/browser/download/download_manager.h" |
| 9 #include "chrome/browser/download/download_request_limiter.h" |
8 #include "chrome/browser/download/download_util.h" | 10 #include "chrome/browser/download/download_util.h" |
9 #include "chrome/browser/profiles/profile.h" | 11 #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" |
10 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 15 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
11 #include "chrome/common/render_messages.h" | 16 #include "chrome/common/render_messages.h" |
12 #include "content/browser/tab_contents/tab_contents.h" | 17 #include "content/browser/tab_contents/tab_contents.h" |
13 #include "content/common/view_messages.h" | 18 #include "content/common/view_messages.h" |
14 | 19 |
15 DownloadTabHelper::DownloadTabHelper(TabContentsWrapper* tab_contents) | 20 DownloadTabHelper::DownloadTabHelper(TabContentsWrapper* tab_contents) |
16 : TabContentsObserver(tab_contents->tab_contents()), | 21 : TabContentsObserver(tab_contents->tab_contents()), |
17 tab_contents_wrapper_(tab_contents) { | 22 tab_contents_wrapper_(tab_contents), |
| 23 delegate_(NULL) { |
18 DCHECK(tab_contents); | 24 DCHECK(tab_contents); |
19 } | 25 } |
20 | 26 |
21 DownloadTabHelper::~DownloadTabHelper() { | 27 DownloadTabHelper::~DownloadTabHelper() { |
22 } | 28 } |
23 | 29 |
24 void DownloadTabHelper::OnSavePage() { | 30 void DownloadTabHelper::OnSavePage() { |
25 // If we can not save the page, try to download it. | 31 // If we can not save the page, try to download it. |
26 if (!SavePackage::IsSavableContents(tab_contents()->contents_mime_type())) { | 32 if (!SavePackage::IsSavableContents(tab_contents()->contents_mime_type())) { |
27 DownloadManager* dlm = tab_contents()->profile()->GetDownloadManager(); | 33 DownloadManager* dlm = tab_contents()->profile()->GetDownloadManager(); |
(...skipping 27 matching lines...) Expand all Loading... |
55 const FilePath& dir_path, | 61 const FilePath& dir_path, |
56 SavePackage::SavePackageType save_type) { | 62 SavePackage::SavePackageType save_type) { |
57 // Stop the page from navigating. | 63 // Stop the page from navigating. |
58 tab_contents()->Stop(); | 64 tab_contents()->Stop(); |
59 | 65 |
60 save_package_ = | 66 save_package_ = |
61 new SavePackage(tab_contents_wrapper_, save_type, main_file, dir_path); | 67 new SavePackage(tab_contents_wrapper_, save_type, main_file, dir_path); |
62 return save_package_->Init(); | 68 return save_package_->Init(); |
63 } | 69 } |
64 | 70 |
| 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 |
65 bool DownloadTabHelper::OnMessageReceived(const IPC::Message& message) { | 96 bool DownloadTabHelper::OnMessageReceived(const IPC::Message& message) { |
66 bool handled = true; | 97 bool handled = true; |
67 IPC_BEGIN_MESSAGE_MAP(DownloadTabHelper, message) | 98 IPC_BEGIN_MESSAGE_MAP(DownloadTabHelper, message) |
68 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL) | 99 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL) |
69 IPC_MESSAGE_UNHANDLED(handled = false) | 100 IPC_MESSAGE_UNHANDLED(handled = false) |
70 IPC_END_MESSAGE_MAP() | 101 IPC_END_MESSAGE_MAP() |
71 | 102 |
72 return handled; | 103 return handled; |
73 } | 104 } |
74 | 105 |
| 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 |