OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "content/browser/download/mhtml_extra_parts_impl.h" | 5 #include "content/browser/download/mhtml_extra_parts_impl.h" |
6 | 6 |
7 namespace { | 7 namespace { |
8 // Only the address of this variable is used. It is used as a key to UserData. | 8 // Only the address of this variable is used. It is used as a key to UserData. |
9 const int kMHTMLExtraPartsKey = 0; | 9 const int kMHTMLExtraPartsKey = 0; |
10 } | 10 } |
11 | 11 |
12 namespace content { | 12 namespace content { |
13 | 13 |
| 14 MHTMLExtraDataPart::MHTMLExtraDataPart() = default; |
| 15 |
| 16 MHTMLExtraDataPart::~MHTMLExtraDataPart() = default; |
| 17 |
| 18 MHTMLExtraDataPart::MHTMLExtraDataPart(const MHTMLExtraDataPart& other) = |
| 19 default; |
| 20 |
14 MHTMLExtraPartsImpl::MHTMLExtraPartsImpl() = default; | 21 MHTMLExtraPartsImpl::MHTMLExtraPartsImpl() = default; |
15 | 22 |
16 MHTMLExtraPartsImpl::~MHTMLExtraPartsImpl() = default; | 23 MHTMLExtraPartsImpl::~MHTMLExtraPartsImpl() = default; |
17 | 24 |
18 MHTMLExtraParts* MHTMLExtraParts::FromWebContents(WebContents* contents) { | 25 MHTMLExtraParts* MHTMLExtraParts::FromWebContents(WebContents* contents) { |
19 // Get the MHTMLExtraPartsImpl from the web contents. | 26 // Get the MHTMLExtraPartsImpl from the web contents. |
20 MHTMLExtraPartsImpl* extra_data_impl = static_cast<MHTMLExtraPartsImpl*>( | 27 MHTMLExtraPartsImpl* extra_data_impl = static_cast<MHTMLExtraPartsImpl*>( |
21 contents->GetUserData(&kMHTMLExtraPartsKey)); | 28 contents->GetUserData(&kMHTMLExtraPartsKey)); |
22 | 29 |
23 // If we did not have one on the web contents already, make one and put it on | 30 // If we did not have one on the web contents already, make one and put it on |
24 // the web contents. | 31 // the web contents. |
25 if (extra_data_impl == nullptr) { | 32 if (extra_data_impl == nullptr) { |
26 extra_data_impl = new MHTMLExtraPartsImpl(); | 33 extra_data_impl = new MHTMLExtraPartsImpl(); |
27 contents->SetUserData(&kMHTMLExtraPartsKey, | 34 contents->SetUserData(&kMHTMLExtraPartsKey, |
28 std::unique_ptr<MHTMLExtraParts>( | 35 std::unique_ptr<MHTMLExtraParts>( |
29 static_cast<MHTMLExtraParts*>(extra_data_impl))); | 36 static_cast<MHTMLExtraParts*>(extra_data_impl))); |
30 } | 37 } |
31 return static_cast<MHTMLExtraParts*>(extra_data_impl); | 38 return static_cast<MHTMLExtraParts*>(extra_data_impl); |
32 } | 39 } |
33 | 40 |
34 int64_t MHTMLExtraPartsImpl::size() { | 41 int64_t MHTMLExtraPartsImpl::size() { |
35 return parts_.size(); | 42 return parts_.size(); |
36 } | 43 } |
37 | 44 |
38 void MHTMLExtraPartsImpl::AddExtraMHTMLPart(const std::string& content_type, | 45 void MHTMLExtraPartsImpl::AddExtraMHTMLPart(const std::string& content_type, |
39 const std::string& content_location, | 46 const std::string& content_location, |
| 47 const std::string& extra_headers, |
40 const std::string& body) { | 48 const std::string& body) { |
41 MHTMLExtraDataPart part; | 49 MHTMLExtraDataPart part; |
42 part.content_type = content_type; | 50 part.content_type = content_type; |
43 part.content_location = content_location; | 51 part.content_location = content_location; |
| 52 part.extra_headers = extra_headers; |
44 part.body = body; | 53 part.body = body; |
45 | 54 |
46 // Add this part to the list of parts to be saved out when the file is | 55 // Add this part to the list of parts to be saved out when the file is |
47 // written. | 56 // written. |
48 parts_.push_back(part); | 57 parts_.push_back(part); |
49 } | 58 } |
50 | 59 |
51 } // namespace content | 60 } // namespace content |
OLD | NEW |