Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(107)

Side by Side Diff: content/browser/download/mhtml_generation_manager.h

Issue 2683493002: Get signals working in the EXTRA_DATA section of MHTML (Closed)
Patch Set: Add Arbitrary extra data sections to MHTML. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #ifndef CONTENT_BROWSER_DOWNLOAD_MHTML_GENERATION_MANAGER_H_ 4 #ifndef CONTENT_BROWSER_DOWNLOAD_MHTML_GENERATION_MANAGER_H_
5 #define CONTENT_BROWSER_DOWNLOAD_MHTML_GENERATION_MANAGER_H_ 5 #define CONTENT_BROWSER_DOWNLOAD_MHTML_GENERATION_MANAGER_H_
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <map> 9 #include <map>
10 #include <memory> 10 #include <memory>
11 #include <set> 11 #include <set>
12 #include <string> 12 #include <string>
13 13
14 #include "base/files/file.h" 14 #include "base/files/file.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/memory/singleton.h" 16 #include "base/memory/singleton.h"
17 #include "base/process/process.h" 17 #include "base/process/process.h"
18 #include "base/supports_user_data.h"
18 #include "content/common/download/mhtml_save_status.h" 19 #include "content/common/download/mhtml_save_status.h"
20 #include "content/public/browser/web_contents.h"
19 #include "content/public/common/mhtml_generation_params.h" 21 #include "content/public/common/mhtml_generation_params.h"
20 #include "ipc/ipc_platform_file.h" 22 #include "ipc/ipc_platform_file.h"
21 23
22 namespace base { 24 namespace base {
23 class FilePath; 25 class FilePath;
24 } 26 }
25 27
26 namespace content { 28 namespace content {
27 29
28 class RenderFrameHostImpl; 30 class RenderFrameHostImpl;
29 class WebContents; 31 class WebContents;
30 32
31 // The class and all of its members live on the UI thread. Only static methods 33 // The class and all of its members live on the UI thread. Only static methods
32 // are executed on other threads. 34 // are executed on other threads.
33 // 35 //
34 // MHTMLGenerationManager is a singleton. Each call to SaveMHTML method creates 36 // MHTMLGenerationManager is a singleton. Each call to SaveMHTML method creates
35 // a new instance of MHTMLGenerationManager::Job that tracks generation of a 37 // a new instance of MHTMLGenerationManager::Job that tracks generation of a
36 // single MHTML file. 38 // single MHTML file.
37 class MHTMLGenerationManager { 39 class CONTENT_EXPORT MHTMLGenerationManager {
38 public: 40 public:
39 static MHTMLGenerationManager* GetInstance(); 41 static MHTMLGenerationManager* GetInstance();
40 42
41 // GenerateMHTMLCallback is called to report completion and status of MHTML 43 // GenerateMHTMLCallback is called to report completion and status of MHTML
42 // generation. On success |file_size| indicates the size of the 44 // generation. On success |file_size| indicates the size of the
43 // generated file. On failure |file_size| is -1. 45 // generated file. On failure |file_size| is -1.
44 typedef base::Callback<void(int64_t file_size)> GenerateMHTMLCallback; 46 typedef base::Callback<void(int64_t file_size)> GenerateMHTMLCallback;
45 47
46 // Instructs the RenderFrames in |web_contents| to generate a MHTML 48 // Instructs the RenderFrames in |web_contents| to generate a MHTML
47 // representation of the current page. 49 // representation of the current page.
48 void SaveMHTML(WebContents* web_contents, 50 void SaveMHTML(WebContents* web_contents,
49 const MHTMLGenerationParams& params, 51 const MHTMLGenerationParams& params,
50 const GenerateMHTMLCallback& callback); 52 const GenerateMHTMLCallback& callback);
51 53
52 // Handler for FrameHostMsg_SerializeAsMHTMLResponse (a notification from the 54 // Handler for FrameHostMsg_SerializeAsMHTMLResponse (a notification from the
53 // renderer that the MHTML generation finished for a single frame). 55 // renderer that the MHTML generation finished for a single frame).
54 void OnSerializeAsMHTMLResponse( 56 void OnSerializeAsMHTMLResponse(
55 RenderFrameHostImpl* sender, 57 RenderFrameHostImpl* sender,
56 int job_id, 58 int job_id,
57 MhtmlSaveStatus save_status, 59 MhtmlSaveStatus save_status,
58 const std::set<std::string>& digests_of_uris_of_serialized_resources, 60 const std::set<std::string>& digests_of_uris_of_serialized_resources,
59 base::TimeDelta renderer_main_thread_time); 61 base::TimeDelta renderer_main_thread_time);
60 62
63 // Contained class that represents an extra data section.
Dmitry Titov 2017/03/18 00:58:34 This mechanism needs a great deal of comment, to e
Pete Williamson 2017/03/20 18:26:53 Added comments, LMK if I need more.
64 struct MHTMLExtraSection {
Dmitry Titov 2017/03/18 00:58:34 Naming suggestion: MHTMLExtraSection -> ExtraPart.
Pete Williamson 2017/03/20 18:26:53 Done.
65 std::string content_type;
66 std::string content_location;
67 std::string body;
68 };
69
70 // Helper class to put extra sections into the WebContents user data, and take
71 // them back out again.
72 class MHTMLExtraData : public base::SupportsUserData::Data {
73 public:
74 MHTMLExtraData();
75
Dmitry Titov 2017/03/18 00:58:34 extra empty line
Pete Williamson 2017/03/20 18:26:53 Done.
76 ~MHTMLExtraData() override;
77
78 std::vector<MHTMLExtraSection>* sections() { return &sections_; }
Dmitry Titov 2017/03/18 00:58:34 It feels that the access to the vector is not need
Pete Williamson 2017/03/20 18:26:53 Turns out I didn't really need this after all, I w
79
80 // Get the data string out of the web contents.
81 // The web contents retains ownership of the vector
82 static std::vector<MHTMLExtraSection>* FromWebContents(
83 content::WebContents* contents);
84
85 // Stash the data string in the web contents user data.
86 static void AddToWebContents(content::WebContents* contents,
Dmitry Titov 2017/03/18 00:58:34 Not sure why this method is needed.
Pete Williamson 2017/03/20 18:26:53 This method is for adding a part to the vector sto
87 MHTMLExtraSection& section);
88
89 private:
90 std::vector<MHTMLExtraSection> sections_;
91 };
92
61 private: 93 private:
62 friend struct base::DefaultSingletonTraits<MHTMLGenerationManager>; 94 friend struct base::DefaultSingletonTraits<MHTMLGenerationManager>;
63 class Job; 95 class Job;
64 96
65 MHTMLGenerationManager(); 97 MHTMLGenerationManager();
66 virtual ~MHTMLGenerationManager(); 98 virtual ~MHTMLGenerationManager();
67 99
68 // Called on the file thread to create |file|. 100 // Called on the file thread to create |file|.
69 static base::File CreateFile(const base::FilePath& file_path); 101 static base::File CreateFile(const base::FilePath& file_path);
70 102
(...skipping 23 matching lines...) Expand all
94 std::map<int, std::unique_ptr<Job>> id_to_job_; 126 std::map<int, std::unique_ptr<Job>> id_to_job_;
95 127
96 int next_job_id_; 128 int next_job_id_;
97 129
98 DISALLOW_COPY_AND_ASSIGN(MHTMLGenerationManager); 130 DISALLOW_COPY_AND_ASSIGN(MHTMLGenerationManager);
99 }; 131 };
100 132
101 } // namespace content 133 } // namespace content
102 134
103 #endif // CONTENT_BROWSER_DOWNLOAD_MHTML_GENERATION_MANAGER_H_ 135 #endif // CONTENT_BROWSER_DOWNLOAD_MHTML_GENERATION_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698