NPAPI:HTTPRedirectHandling: Difference between revisions

Jump to navigation Jump to search
Line 18: Line 18:
The following function can be implemented by plugins to allow for HTTP redirect handling:
The following function can be implemented by plugins to allow for HTTP redirect handling:


   int32 NPP_URLNotifyRedirect(NPP instance, const char* url,
   /* Callback function type used by NPP_URLRedirectNotify */
                              int32 status, void* notifyData);
  typedef NPError (*NPN_HTTPRedirectResponseFunc)(NPNetscapeFuncs*,
                                                  NPPluginFuncs*);
 
  NPError NPP_URLRedirectNotify(NPP instance, const char* url,
                                int32 status, void* notifyData,
                                NPN_HTTPRedirectResponseFunc callback);


* instance: the plug-in instance that made the request
* instance: the plug-in instance that made the request
Line 25: Line 30:
* status: the status code returned from the server (will be 3xx)
* status: the status code returned from the server (will be 3xx)
* notifyData: the data passed into NPN_PostURLNotify() or NPN_GetURLNotify()
* notifyData: the data passed into NPN_PostURLNotify() or NPN_GetURLNotify()
* callback: the address of a callback function for asynchronous responses


The browser will look for this handler only if the plugin function structure's version field is set to the following value or higher:
The browser will look for this handler only if the plugin function structure's version field is set to the following value or higher:
Line 32: Line 38:
The slot for this handler in the plugin function structure can be NULL. If this function is not provided then redirect behavior is up to the browser. The recommended default behavior is to allow all same-origin redirects and disallow all cross-origin redirects.
The slot for this handler in the plugin function structure can be NULL. If this function is not provided then redirect behavior is up to the browser. The recommended default behavior is to allow all same-origin redirects and disallow all cross-origin redirects.


Plugins should return "NPERR_NO_ERR" when the redirect is to be allowed. There may be further redirect notifications when a redirect is allowed. Any return value other than "NPERR_NO_ERR" will disallow the redirect and the browser will subsequently issue an "NPP_URLNotify" call with reason "NPRES_USER_BREAK" and the last redirected url (the same one passed to the NPP_URLNotifyRedirect the last time)
Plugins have the option of synchronously or asynchronously responding to the redirect notification.
 
Returning "NPERR_NO_ERR" will synchronously allow the redirect, returning "NPERR_INVALID_URL" will synchronously disallow the redirect. To respond asynchronously via the provided callback function plugins can return a newly defined error:
 
  #define NPERR_ASYNC_RESPONSE (NPERR_BASE + 14)
 
Network requests may time out if an asynchronous response is not received in a reasonable amount of time. If this happens, the browser will subsequently issue an "NPP_URLNotify" call with reason "NPRES_USER_BREAK" and the last redirected url (the same one passed to the NPP_URLNotifyRedirect the last time).
 
There may be further redirect notifications when a redirect is allowed. When a redirect is disallowed the browser will subsequently issue an "NPP_URLNotify" call with reason "NPRES_USER_BREAK" and the last redirected url (the same one passed to the NPP_URLNotifyRedirect the last time).


Plugins can query the browser for support for this specification using the following variable:
Plugins can query the browser for support for this specification using the following variable:
Confirmed users, Bureaucrats and Sysops emeriti
1,680

edits

Navigation menu