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/form_data_parser.h" | 5 #include "extensions/browser/api/web_request/form_data_parser.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 } // namespace | 75 } // namespace |
76 | 76 |
77 // Parses URLencoded forms, see | 77 // Parses URLencoded forms, see |
78 // http://www.w3.org/TR/REC-html40-971218/interact/forms.html#h-17.13.4.1 . | 78 // http://www.w3.org/TR/REC-html40-971218/interact/forms.html#h-17.13.4.1 . |
79 class FormDataParserUrlEncoded : public FormDataParser { | 79 class FormDataParserUrlEncoded : public FormDataParser { |
80 public: | 80 public: |
81 FormDataParserUrlEncoded(); | 81 FormDataParserUrlEncoded(); |
82 virtual ~FormDataParserUrlEncoded(); | 82 virtual ~FormDataParserUrlEncoded(); |
83 | 83 |
84 // Implementation of FormDataParser. | 84 // Implementation of FormDataParser. |
85 virtual bool AllDataReadOK() OVERRIDE; | 85 virtual bool AllDataReadOK() override; |
86 virtual bool GetNextNameValue(Result* result) OVERRIDE; | 86 virtual bool GetNextNameValue(Result* result) override; |
87 virtual bool SetSource(base::StringPiece source) OVERRIDE; | 87 virtual bool SetSource(base::StringPiece source) override; |
88 | 88 |
89 private: | 89 private: |
90 // Returns the pattern to match a single name-value pair. This could be even | 90 // Returns the pattern to match a single name-value pair. This could be even |
91 // static, but then we would have to spend more code on initializing the | 91 // static, but then we would have to spend more code on initializing the |
92 // cached pointer to g_patterns.Get(). | 92 // cached pointer to g_patterns.Get(). |
93 const RE2& pattern() const { | 93 const RE2& pattern() const { |
94 return patterns_->url_encoded_pattern; | 94 return patterns_->url_encoded_pattern; |
95 } | 95 } |
96 | 96 |
97 // Auxiliary constant for using RE2. Number of arguments for parsing | 97 // Auxiliary constant for using RE2. Number of arguments for parsing |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 // This parser supports sources split into multiple chunks. Therefore SetSource | 186 // This parser supports sources split into multiple chunks. Therefore SetSource |
187 // can be called multiple times if the source is spread over several chunks. | 187 // can be called multiple times if the source is spread over several chunks. |
188 // However, the split may only occur inside a body part, right after the | 188 // However, the split may only occur inside a body part, right after the |
189 // trailing CRLF of headers. | 189 // trailing CRLF of headers. |
190 class FormDataParserMultipart : public FormDataParser { | 190 class FormDataParserMultipart : public FormDataParser { |
191 public: | 191 public: |
192 explicit FormDataParserMultipart(const std::string& boundary_separator); | 192 explicit FormDataParserMultipart(const std::string& boundary_separator); |
193 virtual ~FormDataParserMultipart(); | 193 virtual ~FormDataParserMultipart(); |
194 | 194 |
195 // Implementation of FormDataParser. | 195 // Implementation of FormDataParser. |
196 virtual bool AllDataReadOK() OVERRIDE; | 196 virtual bool AllDataReadOK() override; |
197 virtual bool GetNextNameValue(Result* result) OVERRIDE; | 197 virtual bool GetNextNameValue(Result* result) override; |
198 virtual bool SetSource(base::StringPiece source) OVERRIDE; | 198 virtual bool SetSource(base::StringPiece source) override; |
199 | 199 |
200 private: | 200 private: |
201 enum State { | 201 enum State { |
202 STATE_INIT, // No input read yet. | 202 STATE_INIT, // No input read yet. |
203 STATE_READY, // Ready to call GetNextNameValue. | 203 STATE_READY, // Ready to call GetNextNameValue. |
204 STATE_FINISHED, // Read the input until the end. | 204 STATE_FINISHED, // Read the input until the end. |
205 STATE_SUSPEND, // Waiting until a new |source_| is set. | 205 STATE_SUSPEND, // Waiting until a new |source_| is set. |
206 STATE_ERROR | 206 STATE_ERROR |
207 }; | 207 }; |
208 | 208 |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
586 if (value_pattern().Match(header, | 586 if (value_pattern().Match(header, |
587 kContentDispositionLength, header.size(), | 587 kContentDispositionLength, header.size(), |
588 RE2::UNANCHORED, groups, 2)) { | 588 RE2::UNANCHORED, groups, 2)) { |
589 value->set(groups[1].data(), groups[1].size()); | 589 value->set(groups[1].data(), groups[1].size()); |
590 *value_assigned = true; | 590 *value_assigned = true; |
591 } | 591 } |
592 return true; | 592 return true; |
593 } | 593 } |
594 | 594 |
595 } // namespace extensions | 595 } // namespace extensions |
OLD | NEW |