nsIChannelEventSink.idl (5115B)
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 /* vim:set ts=4 sw=4 sts=4 cin: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #include "nsISupports.idl" 8 9 interface nsIChannel; 10 interface nsIAsyncVerifyRedirectCallback; 11 12 /** 13 * Implement this interface to receive control over various channel events. 14 * Channels will try to get this interface from a channel's 15 * notificationCallbacks or, if not available there, from the loadGroup's 16 * notificationCallbacks. 17 * 18 * These methods are called before onStartRequest. 19 */ 20 [scriptable, uuid(0197720d-37ed-4e75-8956-d0d296e4d8a6)] 21 interface nsIChannelEventSink : nsISupports 22 { 23 /** 24 * This is a temporary redirect. New requests for this resource should 25 * continue to use the URI of the old channel. 26 * 27 * The new URI may be identical to the old one. 28 */ 29 const unsigned long REDIRECT_TEMPORARY = 1 << 0; 30 31 /** 32 * This is a permanent redirect. New requests for this resource should use 33 * the URI of the new channel (This might be an HTTP 301 reponse). 34 * If this flag is not set, this is a temporary redirect. 35 * 36 * The new URI may be identical to the old one. 37 */ 38 const unsigned long REDIRECT_PERMANENT = 1 << 1; 39 40 /** 41 * This is an internal redirect, i.e. it was not initiated by the remote 42 * server, but is specific to the channel implementation. 43 * 44 * The new URI may be identical to the old one. 45 */ 46 const unsigned long REDIRECT_INTERNAL = 1 << 2; 47 48 /** 49 * This is a special-cased redirect coming from hitting HSTS upgrade 50 * redirect from http to https only. In some cases this type of redirect 51 * may be considered as safe despite not being the-same-origin redirect. 52 */ 53 const unsigned long REDIRECT_STS_UPGRADE = 1 << 3; 54 55 /** 56 * This is a internal redirect used to handle http authentication retries. 57 * Upon receiving a 401 or 407 the channel gets redirected to a new channel 58 * (same URL) that performs the request with the appropriate credentials. 59 * Auth retry to the server must be made after redirecting to a new channel 60 */ 61 const unsigned long REDIRECT_AUTH_RETRY = 1 << 4; 62 63 /** 64 * This is a special-case internal redirect triggered by 65 * transparentRedirectTo. The URL bar and window.location.href 66 * must remain unchanged, preserving the original request URI, 67 * while the content is served from the redirected URI. 68 */ 69 const unsigned long REDIRECT_TRANSPARENT = 1 << 5; 70 71 /** 72 * Called when a redirect occurs. This may happen due to an HTTP 3xx status 73 * code. The purpose of this method is to notify the sink that a redirect 74 * is about to happen, but also to give the sink the right to veto the 75 * redirect by throwing or passing a failure-code in the callback. 76 * 77 * Note that vetoing the redirect simply means that |newChannel| will not 78 * be opened. It is important to understand that |oldChannel| will continue 79 * loading as if it received a HTTP 200, which includes notifying observers 80 * and possibly display or process content attached to the HTTP response. 81 * If the sink wants to prevent this loading it must explicitly deal with 82 * it, e.g. by calling |oldChannel->Cancel()| 83 * 84 * There is a certain freedom in implementing this method: 85 * 86 * If the return-value indicates success, a callback on |callback| is 87 * required. This callback can be done from within asyncOnChannelRedirect 88 * (effectively making the call synchronous) or at some point later 89 * (making the call asynchronous). Repeat: A callback must be done 90 * if this method returns successfully. 91 * 92 * If the return value indicates error (method throws an exception) 93 * the redirect is vetoed and no callback must be done. Repeat: No 94 * callback must be done if this method throws! 95 * 96 * NOTE: originalURI isn't yet set on the new channel when 97 * asyncOnChannelRedirect is called. 98 * 99 * @see nsIAsyncVerifyRedirectCallback::onRedirectVerifyCallback() 100 * 101 * @param oldChannel 102 * The channel that's being redirected. 103 * @param newChannel 104 * The new channel. This channel is not opened yet. 105 * @param flags 106 * Flags indicating the type of redirect. A bitmask consisting 107 * of flags from above. 108 * One of REDIRECT_TEMPORARY and REDIRECT_PERMANENT will always be 109 * set. 110 * @param callback 111 * Object to inform about the async result of this method 112 * 113 * @throw <any> Throwing an exception will cause the redirect to be 114 * cancelled 115 */ 116 void asyncOnChannelRedirect(in nsIChannel oldChannel, 117 in nsIChannel newChannel, 118 in unsigned long flags, 119 in nsIAsyncVerifyRedirectCallback callback); 120 };