| 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 #ifndef EXTENSIONS_BROWSER_API_WEB_REQUEST_UPLOAD_DATA_PRESENTER_H_ | 5 #ifndef EXTENSIONS_BROWSER_API_WEB_REQUEST_UPLOAD_DATA_PRESENTER_H_ |
| 6 #define EXTENSIONS_BROWSER_API_WEB_REQUEST_UPLOAD_DATA_PRESENTER_H_ | 6 #define EXTENSIONS_BROWSER_API_WEB_REQUEST_UPLOAD_DATA_PRESENTER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 | 65 |
| 66 // This class passes all the bytes from bytes elements as a BinaryValue for each | 66 // This class passes all the bytes from bytes elements as a BinaryValue for each |
| 67 // such element. File elements are presented as StringValue containing the path | 67 // such element. File elements are presented as StringValue containing the path |
| 68 // for that file. | 68 // for that file. |
| 69 class RawDataPresenter : public UploadDataPresenter { | 69 class RawDataPresenter : public UploadDataPresenter { |
| 70 public: | 70 public: |
| 71 RawDataPresenter(); | 71 RawDataPresenter(); |
| 72 virtual ~RawDataPresenter(); | 72 virtual ~RawDataPresenter(); |
| 73 | 73 |
| 74 // Implementation of UploadDataPresenter. | 74 // Implementation of UploadDataPresenter. |
| 75 virtual void FeedNext(const net::UploadElementReader& reader) OVERRIDE; | 75 virtual void FeedNext(const net::UploadElementReader& reader) override; |
| 76 virtual bool Succeeded() OVERRIDE; | 76 virtual bool Succeeded() override; |
| 77 virtual scoped_ptr<base::Value> Result() OVERRIDE; | 77 virtual scoped_ptr<base::Value> Result() override; |
| 78 | 78 |
| 79 private: | 79 private: |
| 80 void FeedNextBytes(const char* bytes, size_t size); | 80 void FeedNextBytes(const char* bytes, size_t size); |
| 81 void FeedNextFile(const std::string& filename); | 81 void FeedNextFile(const std::string& filename); |
| 82 FRIEND_TEST_ALL_PREFIXES(WebRequestUploadDataPresenterTest, RawData); | 82 FRIEND_TEST_ALL_PREFIXES(WebRequestUploadDataPresenterTest, RawData); |
| 83 | 83 |
| 84 bool success_; | 84 bool success_; |
| 85 scoped_ptr<base::ListValue> list_; | 85 scoped_ptr<base::ListValue> list_; |
| 86 | 86 |
| 87 DISALLOW_COPY_AND_ASSIGN(RawDataPresenter); | 87 DISALLOW_COPY_AND_ASSIGN(RawDataPresenter); |
| 88 }; | 88 }; |
| 89 | 89 |
| 90 // This class inspects the contents of bytes elements. It uses the | 90 // This class inspects the contents of bytes elements. It uses the |
| 91 // parser classes inheriting from FormDataParser to parse the concatenated | 91 // parser classes inheriting from FormDataParser to parse the concatenated |
| 92 // content of such elements. If the parsing is successful, the parsed form is | 92 // content of such elements. If the parsing is successful, the parsed form is |
| 93 // returned as a DictionaryValue. For example, a form consisting of | 93 // returned as a DictionaryValue. For example, a form consisting of |
| 94 // <input name="check" type="checkbox" value="A" checked /> | 94 // <input name="check" type="checkbox" value="A" checked /> |
| 95 // <input name="check" type="checkbox" value="B" checked /> | 95 // <input name="check" type="checkbox" value="B" checked /> |
| 96 // <input name="text" type="text" value="abc" /> | 96 // <input name="text" type="text" value="abc" /> |
| 97 // would be represented as {"check": ["A", "B"], "text": ["abc"]} (although as a | 97 // would be represented as {"check": ["A", "B"], "text": ["abc"]} (although as a |
| 98 // DictionaryValue, not as a JSON string). | 98 // DictionaryValue, not as a JSON string). |
| 99 class ParsedDataPresenter : public UploadDataPresenter { | 99 class ParsedDataPresenter : public UploadDataPresenter { |
| 100 public: | 100 public: |
| 101 explicit ParsedDataPresenter(const net::URLRequest& request); | 101 explicit ParsedDataPresenter(const net::URLRequest& request); |
| 102 virtual ~ParsedDataPresenter(); | 102 virtual ~ParsedDataPresenter(); |
| 103 | 103 |
| 104 // Implementation of UploadDataPresenter. | 104 // Implementation of UploadDataPresenter. |
| 105 virtual void FeedNext(const net::UploadElementReader& reader) OVERRIDE; | 105 virtual void FeedNext(const net::UploadElementReader& reader) override; |
| 106 virtual bool Succeeded() OVERRIDE; | 106 virtual bool Succeeded() override; |
| 107 virtual scoped_ptr<base::Value> Result() OVERRIDE; | 107 virtual scoped_ptr<base::Value> Result() override; |
| 108 | 108 |
| 109 // Allows to create ParsedDataPresenter without the URLRequest. Uses the | 109 // Allows to create ParsedDataPresenter without the URLRequest. Uses the |
| 110 // parser for "application/x-www-form-urlencoded" form encoding. Only use this | 110 // parser for "application/x-www-form-urlencoded" form encoding. Only use this |
| 111 // in tests. | 111 // in tests. |
| 112 static scoped_ptr<ParsedDataPresenter> CreateForTests(); | 112 static scoped_ptr<ParsedDataPresenter> CreateForTests(); |
| 113 | 113 |
| 114 private: | 114 private: |
| 115 // This constructor is used in CreateForTests. | 115 // This constructor is used in CreateForTests. |
| 116 explicit ParsedDataPresenter(const std::string& form_type); | 116 explicit ParsedDataPresenter(const std::string& form_type); |
| 117 | 117 |
| 118 // Clears resources and the success flag. | 118 // Clears resources and the success flag. |
| 119 void Abort(); | 119 void Abort(); |
| 120 scoped_ptr<FormDataParser> parser_; | 120 scoped_ptr<FormDataParser> parser_; |
| 121 bool success_; | 121 bool success_; |
| 122 scoped_ptr<base::DictionaryValue> dictionary_; | 122 scoped_ptr<base::DictionaryValue> dictionary_; |
| 123 | 123 |
| 124 DISALLOW_COPY_AND_ASSIGN(ParsedDataPresenter); | 124 DISALLOW_COPY_AND_ASSIGN(ParsedDataPresenter); |
| 125 }; | 125 }; |
| 126 | 126 |
| 127 } // namespace extensions | 127 } // namespace extensions |
| 128 | 128 |
| 129 #endif // EXTENSIONS_BROWSER_API_WEB_REQUEST_UPLOAD_DATA_PRESENTER_H_ | 129 #endif // EXTENSIONS_BROWSER_API_WEB_REQUEST_UPLOAD_DATA_PRESENTER_H_ |
| OLD | NEW |