| OLD | NEW |
| 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 | 4 |
| 5 #include "extensions/browser/api/web_request/upload_data_presenter.h" | 5 #include "extensions/browser/api/web_request/upload_data_presenter.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "extensions/browser/api/web_request/form_data_parser.h" | 13 #include "extensions/browser/api/web_request/form_data_parser.h" |
| 14 #include "extensions/browser/api/web_request/web_request_api_constants.h" | 14 #include "extensions/browser/api/web_request/web_request_api_constants.h" |
| 15 #include "net/base/upload_bytes_element_reader.h" | 15 #include "net/base/upload_bytes_element_reader.h" |
| 16 #include "net/base/upload_file_element_reader.h" | 16 #include "net/base/upload_file_element_reader.h" |
| 17 #include "net/url_request/url_request.h" | 17 #include "net/url_request/url_request.h" |
| 18 | 18 |
| 19 using base::BinaryValue; | 19 using base::BinaryValue; |
| 20 using base::DictionaryValue; | 20 using base::DictionaryValue; |
| 21 using base::ListValue; | 21 using base::ListValue; |
| 22 using base::StringValue; | |
| 23 using base::Value; | 22 using base::Value; |
| 24 | 23 |
| 25 namespace keys = extension_web_request_api_constants; | 24 namespace keys = extension_web_request_api_constants; |
| 26 | 25 |
| 27 namespace { | 26 namespace { |
| 28 | 27 |
| 29 // Takes |dictionary| of <string, list of strings> pairs, and gets the list | 28 // Takes |dictionary| of <string, list of strings> pairs, and gets the list |
| 30 // for |key|, creating it if necessary. | 29 // for |key|, creating it if necessary. |
| 31 base::ListValue* GetOrCreateList(base::DictionaryValue* dictionary, | 30 base::ListValue* GetOrCreateList(base::DictionaryValue* dictionary, |
| 32 const std::string& key) { | 31 const std::string& key) { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 | 90 |
| 92 void RawDataPresenter::FeedNextBytes(const char* bytes, size_t size) { | 91 void RawDataPresenter::FeedNextBytes(const char* bytes, size_t size) { |
| 93 subtle::AppendKeyValuePair(keys::kRequestBodyRawBytesKey, | 92 subtle::AppendKeyValuePair(keys::kRequestBodyRawBytesKey, |
| 94 BinaryValue::CreateWithCopiedBuffer(bytes, size), | 93 BinaryValue::CreateWithCopiedBuffer(bytes, size), |
| 95 list_.get()); | 94 list_.get()); |
| 96 } | 95 } |
| 97 | 96 |
| 98 void RawDataPresenter::FeedNextFile(const std::string& filename) { | 97 void RawDataPresenter::FeedNextFile(const std::string& filename) { |
| 99 // Insert the file path instead of the contents, which may be too large. | 98 // Insert the file path instead of the contents, which may be too large. |
| 100 subtle::AppendKeyValuePair(keys::kRequestBodyRawFileKey, | 99 subtle::AppendKeyValuePair(keys::kRequestBodyRawFileKey, |
| 101 base::MakeUnique<base::StringValue>(filename), | 100 base::MakeUnique<base::Value>(filename), |
| 102 list_.get()); | 101 list_.get()); |
| 103 } | 102 } |
| 104 | 103 |
| 105 ParsedDataPresenter::ParsedDataPresenter(const net::URLRequest& request) | 104 ParsedDataPresenter::ParsedDataPresenter(const net::URLRequest& request) |
| 106 : parser_(FormDataParser::Create(request)), | 105 : parser_(FormDataParser::Create(request)), |
| 107 success_(parser_.get() != NULL), | 106 success_(parser_.get() != NULL), |
| 108 dictionary_(success_ ? new base::DictionaryValue() : NULL) { | 107 dictionary_(success_ ? new base::DictionaryValue() : NULL) { |
| 109 } | 108 } |
| 110 | 109 |
| 111 ParsedDataPresenter::~ParsedDataPresenter() {} | 110 ParsedDataPresenter::~ParsedDataPresenter() {} |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 dictionary_(success_ ? new base::DictionaryValue() : NULL) { | 156 dictionary_(success_ ? new base::DictionaryValue() : NULL) { |
| 158 } | 157 } |
| 159 | 158 |
| 160 void ParsedDataPresenter::Abort() { | 159 void ParsedDataPresenter::Abort() { |
| 161 success_ = false; | 160 success_ = false; |
| 162 dictionary_.reset(); | 161 dictionary_.reset(); |
| 163 parser_.reset(); | 162 parser_.reset(); |
| 164 } | 163 } |
| 165 | 164 |
| 166 } // namespace extensions | 165 } // namespace extensions |
| OLD | NEW |