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 #ifndef CHROME_BROWSER_UI_DOWNLOAD_DOWNLOAD_TAB_HELPER_H_ | 5 #ifndef CHROME_BROWSER_UI_DOWNLOAD_DOWNLOAD_TAB_HELPER_H_ |
6 #define CHROME_BROWSER_UI_DOWNLOAD_DOWNLOAD_TAB_HELPER_H_ | 6 #define CHROME_BROWSER_UI_DOWNLOAD_DOWNLOAD_TAB_HELPER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/gtest_prod_util.h" |
10 #include "chrome/browser/download/save_package.h" | 11 #include "chrome/browser/download/save_package.h" |
11 #include "content/browser/tab_contents/tab_contents_observer.h" | 12 #include "content/browser/tab_contents/tab_contents_observer.h" |
12 | 13 |
13 class DownloadItem; | 14 class DownloadItem; |
14 class DownloadTabHelperDelegate; | 15 class DownloadTabHelperDelegate; |
15 class TabContentsWrapper; | 16 class TabContentsWrapper; |
16 | 17 |
17 // Per-tab download controller. Handles dealing with various per-tab download | 18 // Per-tab download controller. Handles dealing with various per-tab download |
18 // duties. | 19 // duties. |
19 class DownloadTabHelper : public TabContentsObserver { | 20 class DownloadTabHelper : public TabContentsObserver { |
20 public: | 21 public: |
21 explicit DownloadTabHelper(TabContentsWrapper* tab_contents); | 22 explicit DownloadTabHelper(TabContentsWrapper* tab_contents); |
22 virtual ~DownloadTabHelper(); | 23 virtual ~DownloadTabHelper(); |
23 | 24 |
24 DownloadTabHelperDelegate* delegate() const { return delegate_; } | 25 DownloadTabHelperDelegate* delegate() const { return delegate_; } |
25 void set_delegate(DownloadTabHelperDelegate* d) { delegate_ = d; } | 26 void set_delegate(DownloadTabHelperDelegate* d) { delegate_ = d; } |
26 | 27 |
27 // Prepare for saving the current web page to disk. | 28 // Prepare for saving the current web page to disk. |
28 void OnSavePage(); | 29 void OnSavePage(); |
29 | 30 |
30 // Prepare for saving the URL to disk. | 31 // Prepare for saving the URL to disk. |
31 // URL may refer to the iframe on the page. | 32 // URL may refer to the iframe on the page. |
32 void OnSaveURL(const GURL& url); | 33 void OnSaveURL(const GURL& url); |
33 | 34 |
34 // Save page with the main HTML file path, the directory for saving resources, | 35 // Save page with the main HTML file path, the directory for saving resources, |
35 // and the save type: HTML only or complete web page. Returns true if the | 36 // and the save type: HTML only or complete web page. Returns true if the |
36 // saving process has been initiated successfully. | 37 // saving process has been initiated successfully. |
| 38 // This method is used in automated testing to bypass prompting the user for |
| 39 // file names. Instead, the names and paths are hard coded rather than |
| 40 // running them through file name sanitation and extension / mime checking. |
37 bool SavePage(const FilePath& main_file, const FilePath& dir_path, | 41 bool SavePage(const FilePath& main_file, const FilePath& dir_path, |
38 SavePackage::SavePackageType save_type); | 42 SavePackage::SavePackageType save_type); |
39 | 43 |
40 // Returns the SavePackage which manages the page saving job. May be NULL. | 44 // Returns the SavePackage which manages the page saving job. May be NULL. |
41 SavePackage* save_package() const { return save_package_.get(); } | 45 SavePackage* save_package() const { return save_package_.get(); } |
42 | 46 |
43 // Notifies the delegate that a download is about to be started. | 47 // Notifies the delegate that a download is about to be started. |
44 // This notification is fired before a local temporary file has been created. | 48 // This notification is fired before a local temporary file has been created. |
45 bool CanDownload(int request_id); | 49 bool CanDownload(int request_id); |
46 | 50 |
47 // Notifies the delegate that a download started. | 51 // Notifies the delegate that a download started. |
48 void OnStartDownload(DownloadItem* download); | 52 void OnStartDownload(DownloadItem* download); |
49 | 53 |
50 private: | 54 private: |
| 55 FRIEND_TEST_ALL_PREFIXES(SavePageBrowserTest, SaveFolder1); |
| 56 FRIEND_TEST_ALL_PREFIXES(SavePageBrowserTest, SaveFolder2); |
| 57 FRIEND_TEST_ALL_PREFIXES(SavePageBrowserTest, SaveFolder3); |
| 58 FRIEND_TEST_ALL_PREFIXES(SavePageBrowserTest, SaveFolder4); |
| 59 |
| 60 // Used in automated testing to bypass prompting the user for file names. |
| 61 // The difference between SavePageBasedOnDefaultPrefs() and SavePage() |
| 62 // is whether the default folder prefs are used. In case of SavePage(), |
| 63 // we need to give it the file path to which the file is saved. |
| 64 // On the other hand, in case of SavePageBasedOnDefaultPrefs(), |
| 65 // we need not to give the file path since the file path is determined |
| 66 // based on the default folder prefs. This method returns the title |
| 67 // of the current tab. |
| 68 string16 SavePageBasedOnDefaultPrefs(); |
| 69 |
51 // TabContentsObserver overrides. | 70 // TabContentsObserver overrides. |
52 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 71 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
53 virtual void DidGetUserGesture() OVERRIDE; | 72 virtual void DidGetUserGesture() OVERRIDE; |
54 | 73 |
55 // SavePackage, lazily created. | 74 // SavePackage, lazily created. |
56 scoped_refptr<SavePackage> save_package_; | 75 scoped_refptr<SavePackage> save_package_; |
57 | 76 |
58 // Owning TabContentsWrapper. | 77 // Owning TabContentsWrapper. |
59 TabContentsWrapper* tab_contents_wrapper_; | 78 TabContentsWrapper* tab_contents_wrapper_; |
60 | 79 |
61 // Delegate for notifying our owner (usually Browser) about stuff. Not owned | 80 // Delegate for notifying our owner (usually Browser) about stuff. Not owned |
62 // by us. | 81 // by us. |
63 DownloadTabHelperDelegate* delegate_; | 82 DownloadTabHelperDelegate* delegate_; |
64 | 83 |
65 DISALLOW_COPY_AND_ASSIGN(DownloadTabHelper); | 84 DISALLOW_COPY_AND_ASSIGN(DownloadTabHelper); |
66 }; | 85 }; |
67 | 86 |
68 #endif // CHROME_BROWSER_UI_DOWNLOAD_DOWNLOAD_TAB_HELPER_H_ | 87 #endif // CHROME_BROWSER_UI_DOWNLOAD_DOWNLOAD_TAB_HELPER_H_ |
OLD | NEW |