OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 // | |
5 // The SavePackage object manages the process of saving a page as only-html or | |
6 // complete-html and providing the information for displaying saving status. | |
7 // Saving page as only-html means means that we save web page to a single HTML | |
8 // file regardless internal sub resources and sub frames. | |
9 // Saving page as complete-html page means we save not only the main html file | |
10 // the user told it to save but also a directory for the auxiliary files such | |
11 // as all sub-frame html files, image files, css files and js files. | |
12 // | |
13 // Each page saving job may include one or multiple files which need to be | |
14 // saved. Each file is represented by a SaveItem, and all SaveItems are owned | |
15 // by the SavePackage. SaveItems are created when a user initiates a page | |
16 // saving job, and exist for the duration of one tab's life time. | |
17 | 4 |
18 #ifndef CHROME_BROWSER_DOWNLOAD_SAVE_PACKAGE_H__ | 5 #ifndef CHROME_BROWSER_DOWNLOAD_SAVE_PACKAGE_H_ |
19 #define CHROME_BROWSER_DOWNLOAD_SAVE_PACKAGE_H__ | 6 #define CHROME_BROWSER_DOWNLOAD_SAVE_PACKAGE_H_ |
20 | 7 |
21 #include <string> | 8 #include <string> |
22 #include <vector> | 9 #include <vector> |
23 #include <queue> | 10 #include <queue> |
24 #include <utility> | 11 #include <utility> |
25 | 12 |
26 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
27 #include "base/hash_tables.h" | 14 #include "base/hash_tables.h" |
28 #include "base/ref_counted.h" | 15 #include "base/ref_counted.h" |
29 #include "base/time.h" | 16 #include "base/time.h" |
30 #include "chrome/common/pref_member.h" | 17 #include "chrome/common/pref_member.h" |
31 #include "chrome/browser/download/save_item.h" | 18 #include "chrome/browser/download/save_item.h" |
32 #include "chrome/browser/download/save_types.h" | 19 #include "chrome/browser/download/save_types.h" |
| 20 #include "chrome/browser/render_view_host_delegate.h" |
33 | 21 |
34 class SaveFileManager; | 22 class SaveFileManager; |
35 class SavePackage; | 23 class SavePackage; |
36 class DownloadItem; | 24 class DownloadItem; |
37 class GURL; | 25 class GURL; |
38 class MessageLoop; | 26 class MessageLoop; |
39 class PrefService; | 27 class PrefService; |
40 class Profile; | 28 class Profile; |
41 class WebContents; | 29 class WebContents; |
42 class URLRequestContext; | 30 class URLRequestContext; |
43 class WebContents; | 31 class WebContents; |
44 class Time; | 32 class Time; |
45 | 33 |
46 namespace base { | 34 namespace base { |
47 class Thread; | 35 class Thread; |
48 } | 36 } |
49 | 37 |
50 // save package: manages all save item. | 38 // The SavePackage object manages the process of saving a page as only-html or |
51 class SavePackage : public base::RefCountedThreadSafe<SavePackage> { | 39 // complete-html and providing the information for displaying saving status. |
| 40 // Saving page as only-html means means that we save web page to a single HTML |
| 41 // file regardless internal sub resources and sub frames. |
| 42 // Saving page as complete-html page means we save not only the main html file |
| 43 // the user told it to save but also a directory for the auxiliary files such |
| 44 // as all sub-frame html files, image files, css files and js files. |
| 45 // |
| 46 // Each page saving job may include one or multiple files which need to be |
| 47 // saved. Each file is represented by a SaveItem, and all SaveItems are owned |
| 48 // by the SavePackage. SaveItems are created when a user initiates a page |
| 49 // saving job, and exist for the duration of one tab's life time. |
| 50 class SavePackage : public base::RefCountedThreadSafe<SavePackage>, |
| 51 public RenderViewHostDelegate::Save { |
52 public: | 52 public: |
53 enum SavePackageType { | 53 enum SavePackageType { |
54 // User chose to save only the HTML of the page. | 54 // User chose to save only the HTML of the page. |
55 SAVE_AS_ONLY_HTML = 0, | 55 SAVE_AS_ONLY_HTML = 0, |
56 // User chose to save complete-html page. | 56 // User chose to save complete-html page. |
57 SAVE_AS_COMPLETE_HTML = 1 | 57 SAVE_AS_COMPLETE_HTML = 1 |
58 }; | 58 }; |
59 | 59 |
60 enum WaitState { | 60 enum WaitState { |
61 // State when created but not initialized. | 61 // State when created but not initialized. |
(...skipping 29 matching lines...) Expand all Loading... |
91 | 91 |
92 void Finish(); | 92 void Finish(); |
93 | 93 |
94 // Notifications sent from the file thread to the UI thread. | 94 // Notifications sent from the file thread to the UI thread. |
95 void StartSave(const SaveFileCreateInfo* info); | 95 void StartSave(const SaveFileCreateInfo* info); |
96 bool UpdateSaveProgress(int32 save_id, int64 size, bool write_success); | 96 bool UpdateSaveProgress(int32 save_id, int64 size, bool write_success); |
97 void SaveFinished(int32 save_id, int64 size, bool is_success); | 97 void SaveFinished(int32 save_id, int64 size, bool is_success); |
98 void SaveFailed(const std::wstring& save_url); | 98 void SaveFailed(const std::wstring& save_url); |
99 void SaveCanceled(SaveItem* save_item); | 99 void SaveCanceled(SaveItem* save_item); |
100 | 100 |
101 // Process current page's all savable links of sub resources, resources' | |
102 // referrer and frames(include main frame and sub frames) gotten from | |
103 // render process. | |
104 void ProcessCurrentPageAllSavableResourceLinks( | |
105 const std::vector<GURL>& resources_list, | |
106 const std::vector<GURL>& referrers_list, | |
107 const std::vector<GURL>& frames_list); | |
108 | |
109 // Process the serialized html content data of a specified web page | |
110 // gotten from render process. | |
111 void ProcessSerializedHtmlData(const GURL& frame_url, | |
112 const std::string& data, | |
113 int32 status); | |
114 | |
115 // Rough percent complete, -1 means we don't know (since we didn't receive a | 101 // Rough percent complete, -1 means we don't know (since we didn't receive a |
116 // total size). | 102 // total size). |
117 int PercentComplete(); | 103 int PercentComplete(); |
118 | 104 |
119 // Show or Open a saved page via the Windows shell. | 105 // Show or Open a saved page via the Windows shell. |
120 void ShowDownloadInShell(); | 106 void ShowDownloadInShell(); |
121 | 107 |
122 bool canceled() { return user_canceled_ || disk_error_occurred_; } | 108 bool canceled() { return user_canceled_ || disk_error_occurred_; } |
123 | 109 |
124 // Accessor | 110 // Accessor |
125 bool finished() { return finished_; } | 111 bool finished() { return finished_; } |
126 SavePackageType save_type() { return save_type_; } | 112 SavePackageType save_type() { return save_type_; } |
127 | 113 |
128 // Since for one tab, it can only have one SavePackage in same time. | 114 // Since for one tab, it can only have one SavePackage in same time. |
129 // Now we actually use render_process_id as tab's unique id. | 115 // Now we actually use render_process_id as tab's unique id. |
130 int tab_id() const { return tab_id_; } | 116 int tab_id() const { return tab_id_; } |
131 | 117 |
| 118 // RenderViewHostDelegate::Save ---------------------------------------------- |
| 119 |
| 120 // Process all of the current page's savable links of subresources, resources |
| 121 // referrers and frames (including the main frame and subframes) from the |
| 122 // render view host. |
| 123 virtual void OnReceivedSavableResourceLinksForCurrentPage( |
| 124 const std::vector<GURL>& resources_list, |
| 125 const std::vector<GURL>& referrers_list, |
| 126 const std::vector<GURL>& frames_list); |
| 127 |
| 128 // Process the serialized html content data of a specified web page |
| 129 // gotten from render process. |
| 130 virtual void OnReceivedSerializedHtmlData(const GURL& frame_url, |
| 131 const std::string& data, |
| 132 int32 status); |
| 133 |
| 134 // Statics ------------------------------------------------------------------- |
| 135 |
132 // Helper function for preparing suggested name for the SaveAs Dialog. The | 136 // Helper function for preparing suggested name for the SaveAs Dialog. The |
133 // suggested name is composed of the default save path and the web document's | 137 // suggested name is composed of the default save path and the web document's |
134 // title. | 138 // title. |
135 static std::wstring GetSuggestNameForSaveAs(PrefService* prefs, | 139 static std::wstring GetSuggestNameForSaveAs(PrefService* prefs, |
136 const std::wstring& name); | 140 const std::wstring& name); |
137 | 141 |
138 // This structure is for storing parameters which we will use to create | 142 // This structure is for storing parameters which we will use to create |
139 // a SavePackage object later. | 143 // a SavePackage object later. |
140 struct SavePackageParam { | 144 struct SavePackageParam { |
141 // MIME type of current tab contents. | 145 // MIME type of current tab contents. |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 // This map is used to track serial number for specified filename. | 303 // This map is used to track serial number for specified filename. |
300 FileNameCountMap file_name_count_map_; | 304 FileNameCountMap file_name_count_map_; |
301 | 305 |
302 // Indicates current waiting state when SavePackage try to get something | 306 // Indicates current waiting state when SavePackage try to get something |
303 // from outside. | 307 // from outside. |
304 WaitState wait_state_; | 308 WaitState wait_state_; |
305 | 309 |
306 // Unique id for this SavePackage. | 310 // Unique id for this SavePackage. |
307 const int tab_id_; | 311 const int tab_id_; |
308 | 312 |
309 DISALLOW_EVIL_CONSTRUCTORS(SavePackage); | 313 DISALLOW_COPY_AND_ASSIGN(SavePackage); |
310 }; | 314 }; |
311 | 315 |
312 #endif // CHROME_BROWSER_DOWNLOAD_SAVE_PACKAGE_H__ | 316 #endif // CHROME_BROWSER_DOWNLOAD_SAVE_PACKAGE_H_ |
OLD | NEW |