| 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 NET_HTTP_HTTP_CONTENT_DISPOSITION_H_ | 5 #ifndef NET_HTTP_HTTP_CONTENT_DISPOSITION_H_ |
| 6 #define NET_HTTP_HTTP_CONTENT_DISPOSITION_H_ | 6 #define NET_HTTP_HTTP_CONTENT_DISPOSITION_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "net/base/net_export.h" | 11 #include "net/base/net_export.h" |
| 12 | 12 |
| 13 namespace net { | 13 namespace net { |
| 14 | 14 |
| 15 class NET_EXPORT HttpContentDisposition { | 15 class NET_EXPORT HttpContentDisposition { |
| 16 public: | 16 public: |
| 17 enum Type { | 17 enum Type { |
| 18 INLINE, | 18 INLINE, |
| 19 ATTACHMENT, | 19 ATTACHMENT, |
| 20 }; | 20 }; |
| 21 | 21 |
| 22 // Properties of the Content-Disposition header. Used for UMA. | 22 // Properties of the Content-Disposition header. These flags are used to |
| 23 // report download metrics in UMA. This enum isn't directly used in UMA but |
| 24 // mapped to another one for binary compatiblity; ie. changes are OK. |
| 23 enum ParseResultFlags { | 25 enum ParseResultFlags { |
| 24 INVALID = 0, | 26 INVALID = 0, |
| 25 | 27 |
| 26 // A valid disposition-type is present. | 28 // A valid disposition-type is present. |
| 27 HAS_DISPOSITION_TYPE = 1 << 0, | 29 HAS_DISPOSITION_TYPE = 1 << 0, |
| 28 | 30 |
| 29 // The disposition-type is not 'inline' or 'attachment'. | 31 // The disposition-type is not 'inline' or 'attachment'. |
| 30 HAS_UNKNOWN_DISPOSITION_TYPE = 1 << 1, | 32 HAS_UNKNOWN_DISPOSITION_TYPE = 1 << 1, |
| 31 | 33 |
| 32 // Has a valid non-empty 'name' attribute. | |
| 33 HAS_NAME = 1 << 2, | |
| 34 | |
| 35 // Has a valid non-empty 'filename' attribute. | 34 // Has a valid non-empty 'filename' attribute. |
| 36 HAS_FILENAME = 1 << 3, | 35 HAS_FILENAME = 1 << 2, |
| 37 | 36 |
| 38 // Has a valid non-empty 'filename*' attribute. | 37 // Has a valid non-empty 'filename*' attribute. |
| 39 HAS_EXT_FILENAME = 1 << 4, | 38 HAS_EXT_FILENAME = 1 << 3, |
| 40 | 39 |
| 41 // The following fields are properties of the 'filename' attribute: | 40 // The following fields are properties of the 'filename' attribute: |
| 42 | 41 |
| 43 // Quoted-string contains non-ASCII characters. | 42 // Quoted-string contains non-ASCII characters. |
| 44 HAS_NON_ASCII_STRINGS = 1 << 5, | 43 HAS_NON_ASCII_STRINGS = 1 << 4, |
| 45 | 44 |
| 46 // Quoted-string contains percent-encoding. | 45 // Quoted-string contains percent-encoding. |
| 47 HAS_PERCENT_ENCODED_STRINGS = 1 << 6, | 46 HAS_PERCENT_ENCODED_STRINGS = 1 << 5, |
| 48 | 47 |
| 49 // Quoted-string contains RFC 2047 encoded words. | 48 // Quoted-string contains RFC 2047 encoded words. |
| 50 HAS_RFC2047_ENCODED_STRINGS = 1 << 7 | 49 HAS_RFC2047_ENCODED_STRINGS = 1 << 6 |
| 51 }; | 50 }; |
| 52 | 51 |
| 53 HttpContentDisposition(const std::string& header, | 52 HttpContentDisposition(const std::string& header, |
| 54 const std::string& referrer_charset); | 53 const std::string& referrer_charset); |
| 55 ~HttpContentDisposition(); | 54 ~HttpContentDisposition(); |
| 56 | 55 |
| 57 bool is_attachment() const { return type() == ATTACHMENT; } | 56 bool is_attachment() const { return type() == ATTACHMENT; } |
| 58 | 57 |
| 59 Type type() const { return type_; } | 58 Type type() const { return type_; } |
| 60 const std::string& filename() const { return filename_; } | 59 const std::string& filename() const { return filename_; } |
| 61 | 60 |
| 62 // A combination of ParseResultFlags values. | 61 // A combination of ParseResultFlags values. |
| 63 int parse_result_flags() const { return parse_result_flags_; } | 62 int parse_result_flags() const { return parse_result_flags_; } |
| 64 | 63 |
| 65 private: | 64 private: |
| 66 void Parse(const std::string& header, const std::string& referrer_charset); | 65 void Parse(const std::string& header, const std::string& referrer_charset); |
| 67 std::string::const_iterator ConsumeDispositionType( | 66 std::string::const_iterator ConsumeDispositionType( |
| 68 std::string::const_iterator begin, std::string::const_iterator end); | 67 std::string::const_iterator begin, std::string::const_iterator end); |
| 69 | 68 |
| 70 Type type_; | 69 Type type_; |
| 71 std::string filename_; | 70 std::string filename_; |
| 72 int parse_result_flags_; | 71 int parse_result_flags_; |
| 73 | 72 |
| 74 DISALLOW_COPY_AND_ASSIGN(HttpContentDisposition); | 73 DISALLOW_COPY_AND_ASSIGN(HttpContentDisposition); |
| 75 }; | 74 }; |
| 76 | 75 |
| 77 } // namespace net | 76 } // namespace net |
| 78 | 77 |
| 79 #endif // NET_HTTP_HTTP_CONTENT_DISPOSITION_H_ | 78 #endif // NET_HTTP_HTTP_CONTENT_DISPOSITION_H_ |
| OLD | NEW |