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