Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "nsISupports.idl" |
michael@0 | 7 | |
michael@0 | 8 | interface nsIURI; |
michael@0 | 9 | interface nsIPrefBranch; |
michael@0 | 10 | |
michael@0 | 11 | /** |
michael@0 | 12 | * nsINetUtil provides various network-related utility methods. |
michael@0 | 13 | */ |
michael@0 | 14 | [scriptable, uuid(ca68c485-9db3-4c12-82a6-4fab7948e2d5)] |
michael@0 | 15 | interface nsINetUtil : nsISupports |
michael@0 | 16 | { |
michael@0 | 17 | /** |
michael@0 | 18 | * Parse a content-type header and return the content type and |
michael@0 | 19 | * charset (if any). |
michael@0 | 20 | * |
michael@0 | 21 | * @param aTypeHeader the header string to parse |
michael@0 | 22 | * @param [out] aCharset the charset parameter specified in the |
michael@0 | 23 | * header, if any. |
michael@0 | 24 | * @param [out] aHadCharset whether a charset was explicitly specified. |
michael@0 | 25 | * @return the MIME type specified in the header, in lower-case. |
michael@0 | 26 | */ |
michael@0 | 27 | AUTF8String parseContentType(in AUTF8String aTypeHeader, |
michael@0 | 28 | out AUTF8String aCharset, |
michael@0 | 29 | out boolean aHadCharset); |
michael@0 | 30 | |
michael@0 | 31 | /** |
michael@0 | 32 | * Test whether the given URI's handler has the given protocol flags. |
michael@0 | 33 | * |
michael@0 | 34 | * @param aURI the URI in question |
michael@0 | 35 | * @param aFlags the flags we're testing for. |
michael@0 | 36 | * |
michael@0 | 37 | * @return whether the protocol handler for aURI has all the flags |
michael@0 | 38 | * in aFlags. |
michael@0 | 39 | */ |
michael@0 | 40 | boolean protocolHasFlags(in nsIURI aURI, in unsigned long aFlag); |
michael@0 | 41 | |
michael@0 | 42 | /** |
michael@0 | 43 | * Test whether the protocol handler for this URI or that for any of |
michael@0 | 44 | * its inner URIs has the given protocol flags. This will QI aURI to |
michael@0 | 45 | * nsINestedURI and walk the nested URI chain. |
michael@0 | 46 | * |
michael@0 | 47 | * @param aURI the URI in question |
michael@0 | 48 | * @param aFlags the flags we're testing for. |
michael@0 | 49 | * |
michael@0 | 50 | * @return whether any of the protocol handlers involved have all the flags |
michael@0 | 51 | * in aFlags. |
michael@0 | 52 | */ |
michael@0 | 53 | boolean URIChainHasFlags(in nsIURI aURI, in unsigned long aFlags); |
michael@0 | 54 | |
michael@0 | 55 | /** |
michael@0 | 56 | * Take aURI and produce an immutable version of it for the caller. If aURI |
michael@0 | 57 | * is immutable this will be aURI itself; otherwise this will be a clone, |
michael@0 | 58 | * marked immutable if possible. Passing null to this method is allowed; in |
michael@0 | 59 | * that case it will return null. |
michael@0 | 60 | */ |
michael@0 | 61 | nsIURI toImmutableURI(in nsIURI aURI); |
michael@0 | 62 | |
michael@0 | 63 | /** |
michael@0 | 64 | * Create a simple nested URI using the result of |
michael@0 | 65 | * toImmutableURI on the passed-in aURI which may not be null. |
michael@0 | 66 | * Note: The return URI will not have had its spec set yet. |
michael@0 | 67 | */ |
michael@0 | 68 | nsIURI newSimpleNestedURI(in nsIURI aURI); |
michael@0 | 69 | |
michael@0 | 70 | /** Escape every character with its %XX-escaped equivalent */ |
michael@0 | 71 | const unsigned long ESCAPE_ALL = 0; |
michael@0 | 72 | |
michael@0 | 73 | /** Leave alphanumeric characters intact and %XX-escape all others */ |
michael@0 | 74 | const unsigned long ESCAPE_XALPHAS = 1; |
michael@0 | 75 | |
michael@0 | 76 | /** Leave alphanumeric characters intact, convert spaces to '+', |
michael@0 | 77 | %XX-escape all others */ |
michael@0 | 78 | const unsigned long ESCAPE_XPALPHAS = 2; |
michael@0 | 79 | |
michael@0 | 80 | /** Leave alphanumeric characters and forward slashes intact, |
michael@0 | 81 | %XX-escape all others */ |
michael@0 | 82 | const unsigned long ESCAPE_URL_PATH = 4; |
michael@0 | 83 | |
michael@0 | 84 | /** |
michael@0 | 85 | * escape a string with %00-style escaping |
michael@0 | 86 | */ |
michael@0 | 87 | ACString escapeString(in ACString aString, in unsigned long aEscapeType); |
michael@0 | 88 | |
michael@0 | 89 | /** %XX-escape URL scheme */ |
michael@0 | 90 | const unsigned long ESCAPE_URL_SCHEME = 1; |
michael@0 | 91 | |
michael@0 | 92 | /** %XX-escape username in the URL */ |
michael@0 | 93 | const unsigned long ESCAPE_URL_USERNAME = 1 << 1; |
michael@0 | 94 | |
michael@0 | 95 | /** %XX-escape password in the URL */ |
michael@0 | 96 | const unsigned long ESCAPE_URL_PASSWORD = 1 << 2; |
michael@0 | 97 | |
michael@0 | 98 | /** %XX-escape URL host */ |
michael@0 | 99 | const unsigned long ESCAPE_URL_HOST = 1 << 3; |
michael@0 | 100 | |
michael@0 | 101 | /** %XX-escape URL directory */ |
michael@0 | 102 | const unsigned long ESCAPE_URL_DIRECTORY = 1 << 4; |
michael@0 | 103 | |
michael@0 | 104 | /** %XX-escape file basename in the URL */ |
michael@0 | 105 | const unsigned long ESCAPE_URL_FILE_BASENAME = 1 << 5; |
michael@0 | 106 | |
michael@0 | 107 | /** %XX-escape file extension in the URL */ |
michael@0 | 108 | const unsigned long ESCAPE_URL_FILE_EXTENSION = 1 << 6; |
michael@0 | 109 | |
michael@0 | 110 | /** %XX-escape URL parameters */ |
michael@0 | 111 | const unsigned long ESCAPE_URL_PARAM = 1 << 7; |
michael@0 | 112 | |
michael@0 | 113 | /** %XX-escape URL query */ |
michael@0 | 114 | const unsigned long ESCAPE_URL_QUERY = 1 << 8; |
michael@0 | 115 | |
michael@0 | 116 | /** %XX-escape URL ref */ |
michael@0 | 117 | const unsigned long ESCAPE_URL_REF = 1 << 9; |
michael@0 | 118 | |
michael@0 | 119 | /** %XX-escape URL path - same as escaping directory, basename and extension */ |
michael@0 | 120 | const unsigned long ESCAPE_URL_FILEPATH = |
michael@0 | 121 | ESCAPE_URL_DIRECTORY | ESCAPE_URL_FILE_BASENAME | ESCAPE_URL_FILE_EXTENSION; |
michael@0 | 122 | |
michael@0 | 123 | /** %XX-escape scheme, username, password, host, path, params, query and ref */ |
michael@0 | 124 | const unsigned long ESCAPE_URL_MINIMAL = |
michael@0 | 125 | ESCAPE_URL_SCHEME | ESCAPE_URL_USERNAME | ESCAPE_URL_PASSWORD | |
michael@0 | 126 | ESCAPE_URL_HOST | ESCAPE_URL_FILEPATH | ESCAPE_URL_PARAM | |
michael@0 | 127 | ESCAPE_URL_QUERY | ESCAPE_URL_REF; |
michael@0 | 128 | |
michael@0 | 129 | /** Force %XX-escaping of already escaped sequences */ |
michael@0 | 130 | const unsigned long ESCAPE_URL_FORCED = 1 << 10; |
michael@0 | 131 | |
michael@0 | 132 | /** Skip non-ascii octets, %XX-escape all others */ |
michael@0 | 133 | const unsigned long ESCAPE_URL_ONLY_ASCII = 1 << 11; |
michael@0 | 134 | |
michael@0 | 135 | /** |
michael@0 | 136 | * Skip graphic octets (0x20-0x7E) when escaping |
michael@0 | 137 | * Skips all ASCII octets (0x00-0x7F) when unescaping |
michael@0 | 138 | */ |
michael@0 | 139 | const unsigned long ESCAPE_URL_ONLY_NONASCII = 1 << 12; |
michael@0 | 140 | |
michael@0 | 141 | /** Force %XX-escape of colon */ |
michael@0 | 142 | const unsigned long ESCAPE_URL_COLON = 1 << 14; |
michael@0 | 143 | |
michael@0 | 144 | /** Skip C0 and DEL from unescaping */ |
michael@0 | 145 | const unsigned long ESCAPE_URL_SKIP_CONTROL = 1 << 15; |
michael@0 | 146 | |
michael@0 | 147 | /** |
michael@0 | 148 | * %XX-Escape invalid chars in a URL segment. |
michael@0 | 149 | * |
michael@0 | 150 | * @param aStr the URL to be escaped |
michael@0 | 151 | * @param aFlags the URL segment type flags |
michael@0 | 152 | * |
michael@0 | 153 | * @return the escaped string (the string itself if escaping did not happen) |
michael@0 | 154 | * |
michael@0 | 155 | */ |
michael@0 | 156 | ACString escapeURL(in ACString aStr, in unsigned long aFlags); |
michael@0 | 157 | |
michael@0 | 158 | /** |
michael@0 | 159 | * Expands URL escape sequences |
michael@0 | 160 | * |
michael@0 | 161 | * @param aStr the URL to be unescaped |
michael@0 | 162 | * @param aFlags only ESCAPE_URL_ONLY_NONASCII and ESCAPE_URL_SKIP_CONTROL |
michael@0 | 163 | * are recognized. If |aFlags| is 0 all escape sequences are |
michael@0 | 164 | * unescaped |
michael@0 | 165 | * @return unescaped string |
michael@0 | 166 | */ |
michael@0 | 167 | ACString unescapeString(in AUTF8String aStr, in unsigned long aFlags); |
michael@0 | 168 | |
michael@0 | 169 | /** |
michael@0 | 170 | * Extract the charset parameter location and value from a content-type |
michael@0 | 171 | * header. |
michael@0 | 172 | * |
michael@0 | 173 | * @param aTypeHeader the header string to parse |
michael@0 | 174 | * @param [out] aCharset the charset parameter specified in the |
michael@0 | 175 | * header, if any. |
michael@0 | 176 | * @param [out] aCharsetStart index of the start of the charset parameter |
michael@0 | 177 | * (the ';' separating it from what came before) in aTypeHeader. |
michael@0 | 178 | * If this function returns false, this argument will still be |
michael@0 | 179 | * set, to the index of the location where a new charset should |
michael@0 | 180 | * be inserted. |
michael@0 | 181 | * @param [out] aCharsetEnd index of the end of the charset parameter (the |
michael@0 | 182 | * ';' separating it from what comes after, or the end |
michael@0 | 183 | * of the string) in aTypeHeader. If this function returns |
michael@0 | 184 | * false, this argument will still be set, to the index of the |
michael@0 | 185 | * location where a new charset should be inserted. |
michael@0 | 186 | * |
michael@0 | 187 | * @return whether a charset parameter was found. This can be false even in |
michael@0 | 188 | * cases when parseContentType would claim to have a charset, if the type |
michael@0 | 189 | * that won out does not have a charset parameter specified. |
michael@0 | 190 | */ |
michael@0 | 191 | boolean extractCharsetFromContentType(in AUTF8String aTypeHeader, |
michael@0 | 192 | out AUTF8String aCharset, |
michael@0 | 193 | out long aCharsetStart, |
michael@0 | 194 | out long aCharsetEnd); |
michael@0 | 195 | }; |