OLD | NEW |
---|---|
1 # High-level overview of Save-Page-As code | 1 # High-level overview of Save-Page-As code |
2 | 2 |
3 This document describes code under `//content/browser/downloads` | 3 This document describes code under `//content/browser/downloads` |
4 restricting the scope only to code handling Save-Page-As functionality | 4 restricting the scope only to code handling Save-Page-As functionality |
5 (i.e. leaving out other downloads-related code). | 5 (i.e. leaving out other downloads-related code). |
6 This document focuses on high-level overview and aspects of the code that | 6 This document focuses on high-level overview and aspects of the code that |
7 span multiple compilation units (hoping that individual compilation units | 7 span multiple compilation units (hoping that individual compilation units |
8 are described by their code comments or by their code structure). | 8 are described by their code comments or by their code structure). |
9 | 9 |
10 ## Classes overview | 10 ## Classes overview |
11 | 11 |
12 * SavePackage class | 12 * SavePackage class |
13 * coordinates overall save-page-as request | 13 * coordinates overall save-page-as request |
14 * created and owned by `WebContents` | 14 * created and owned by `WebContents` |
15 (ref-counted today, but it is unnecessary - see https://crbug.com/596953) | 15 (ref-counted today, but it is unnecessary - see https://crbug.com/596953) |
16 * UI-thread object | 16 * UI-thread object |
17 | 17 |
18 * SaveFileCreateInfo::SaveFileSource enum | 18 * SaveFileCreateInfo::SaveFileSource enum |
19 * classifies `SaveItem` and `SaveFile` processing into 3 flavours: | 19 * classifies `SaveItem` and `SaveFile` processing into 2 flavours: |
20 * `SAVE_FILE_FROM_NET` (see `SaveFileResourceHandler`) | 20 * `SAVE_FILE_FROM_NET` (see `SaveFileResourceHandler`) |
21 * `SAVE_FILE_FROM_DOM` (see "Complete HTML" section below) | 21 * `SAVE_FILE_FROM_DOM` (see "Complete HTML" section below) |
22 * `SAVE_FILE_FROM_FILE` (see `SaveFileManager::SaveLocalFile`) | |
23 | 22 |
24 * SaveItem class | 23 * SaveItem class |
25 * tracks saving a single file | 24 * tracks saving a single file |
26 * created and owned by `SavePackage` | 25 * created and owned by `SavePackage` |
27 * UI-thread object | 26 * UI-thread object |
28 | 27 |
29 * SaveFileManager class | 28 * SaveFileManager class |
30 * coordinates between FILE and UI threads | 29 * coordinates between FILE and UI threads |
31 * Gets requests from `SavePackage` and communicates results back to | 30 * Gets requests from `SavePackage` and communicates results back to |
32 `SavePackage` on the UI thread. | 31 `SavePackage` on the UI thread. |
(...skipping 28 matching lines...) Expand all Loading... | |
61 The flow is different depending on the save format chosen by the user | 60 The flow is different depending on the save format chosen by the user |
62 (each flow is described in a separate section below). | 61 (each flow is described in a separate section below). |
63 | 62 |
64 ### Complete HTML | 63 ### Complete HTML |
65 | 64 |
66 Very high-level flow of saving a page as "Complete HTML": | 65 Very high-level flow of saving a page as "Complete HTML": |
67 | 66 |
68 * Step 1: `SavePackage` asks all frames for "savable resources" | 67 * Step 1: `SavePackage` asks all frames for "savable resources" |
69 and creates `SaveItem` for each of files that need to be saved | 68 and creates `SaveItem` for each of files that need to be saved |
70 | 69 |
71 * Step 2: `SavePackage` first processes `SAVE_FILE_FROM_NET` and | 70 * Step 2: `SavePackage` first processes `SAVE_FILE_FROM_NET` |
Randy Smith (Not in Mondays)
2016/07/21 19:29:54
Worth changing the enum name now that it's no-long
Łukasz Anforowicz
2016/07/21 23:44:30
Maybe. I cannot think of a better name. The gist
| |
72 `SAVE_FILE_FROM_FILE` `SaveItem`s and asks `SaveFileManager` to save | 71 `SaveItem`s and asks `SaveFileManager` to save |
73 them. | 72 them. |
74 | 73 |
75 * Step 3: `SavePackage` handles remaining `SAVE_FILE_FROM_DOM` `SaveItem`s and | 74 * Step 3: `SavePackage` handles remaining `SAVE_FILE_FROM_DOM` `SaveItem`s and |
76 asks each frame to serialize its DOM/HTML (each frame gets from | 75 asks each frame to serialize its DOM/HTML (each frame gets from |
77 `SavePackage` a map covering local paths that need to be referenced by | 76 `SavePackage` a map covering local paths that need to be referenced by |
78 the frame). Responses from frames get forwarded to `SaveFileManager` | 77 the frame). Responses from frames get forwarded to `SaveFileManager` |
79 to be written to disk. | 78 to be written to disk. |
80 | 79 |
81 | 80 |
82 ### MHTML | 81 ### MHTML |
(...skipping 16 matching lines...) Expand all Loading... | |
99 | 98 |
100 Note: MHTML format is by default disabled in Save-Page-As UI on Windows, MacOS | 99 Note: MHTML format is by default disabled in Save-Page-As UI on Windows, MacOS |
101 and Linux (it is the default on ChromeOS), but for testing this can be easily | 100 and Linux (it is the default on ChromeOS), but for testing this can be easily |
102 changed using `--save-page-as-mhtml` command line switch. | 101 changed using `--save-page-as-mhtml` command line switch. |
103 | 102 |
104 | 103 |
105 ### HTML Only | 104 ### HTML Only |
106 | 105 |
107 Very high-level flow of saving a page as "HTML Only": | 106 Very high-level flow of saving a page as "HTML Only": |
108 | 107 |
109 * `SavePackage` creates only a single `SaveItem` (either `SAVE_FILE_FROM_NET` or | 108 * `SavePackage` creates only a single `SaveItem` (always `SAVE_FILE_FROM_NET`) |
110 `SAVE_FILE_FROM_FILE`) and asks `SaveFileManager` to process it | 109 and asks `SaveFileManager` to process it |
111 (as in the Complete HTML individual SaveItem handling above.). | 110 (as in the Complete HTML individual SaveItem handling above.). |
112 | 111 |
113 | 112 |
114 ## Other relevant code | 113 ## Other relevant code |
115 | 114 |
116 Pointers to related code outside of `//content/browser/download`: | 115 Pointers to related code outside of `//content/browser/download`: |
117 | 116 |
118 * End-to-end tests: | 117 * End-to-end tests: |
119 * `//chrome/browser/downloads/save_page_browsertest.cc` | 118 * `//chrome/browser/downloads/save_page_browsertest.cc` |
120 * `//chrome/test/data/save_page/...` | 119 * `//chrome/test/data/save_page/...` |
121 | 120 |
122 * Other tests: | 121 * Other tests: |
123 * `//content/browser/downloads/*test*.cc` | 122 * `//content/browser/downloads/*test*.cc` |
124 * `//content/renderer/dom_serializer_browsertest.cc` - single process... :-/ | 123 * `//content/renderer/dom_serializer_browsertest.cc` - single process... :-/ |
125 | 124 |
126 * Elsewhere in `//content`: | 125 * Elsewhere in `//content`: |
127 * `//content/renderer/savable_resources...` | 126 * `//content/renderer/savable_resources...` |
128 | 127 |
129 * Blink: | 128 * Blink: |
130 * `//third_party/WebKit/public/web/WebFrameSerializer...` | 129 * `//third_party/WebKit/public/web/WebFrameSerializer...` |
131 * `//third_party/WebKit/Source/web/WebFrameSerializerImpl...` | 130 * `//third_party/WebKit/Source/web/WebFrameSerializerImpl...` |
132 (used for Complete HTML today; should use `FrameSerializer` instead in | 131 (used for Complete HTML today; should use `FrameSerializer` instead in |
133 the long-term - see https://crbug.com/328354). | 132 the long-term - see https://crbug.com/328354). |
134 * `//third_party/WebKit/Source/core/frame/FrameSerializer...` | 133 * `//third_party/WebKit/Source/core/frame/FrameSerializer...` |
135 (used for MHTML today) | 134 (used for MHTML today) |
136 * `//third_party/WebKit/Source/platform/mhtml/MHTMLArchive...` | 135 * `//third_party/WebKit/Source/platform/mhtml/MHTMLArchive...` |
137 | 136 |
OLD | NEW |