NPAPI:HTTPRedirectHandling: Difference between revisions

From MozillaWiki
Jump to navigation Jump to search
No edit summary
 
(13 intermediate revisions by the same user not shown)
Line 1: Line 1:
= Status =
= Status =


Under consideration.
Accepted, ready for implementation.


= Contributors =
= Contributors =


* Last modified: October 28, 2010
* Last modified: November 5, 2010
* Authors: Josh Aas (Mozilla), Johnny Stenback (Mozilla)
* Authors: Josh Aas (Mozilla), Johnny Stenback (Mozilla)
* Contributors: Rudi Sherry (Adobe), Darin Fisher (Google), Dimcho Balev (Adobe), Deneb Meketa (Adobe), Stuart Morgan (Google), Jimson Xu (Adobe)
* Contributors: Rudi Sherry (Adobe), Darin Fisher (Google), Dimcho Balev (Adobe), Deneb Meketa (Adobe), Stuart Morgan (Google), Jimson Xu (Adobe), Julian Reschke


= Overview =
= Overview =


Plugins need the opportunity to participate in HTTP redirect handling for requests
Plugins need the opportunity to participate in HTTP redirect handling for requests
started with 'NPN_PostURLNotify' and 'NPN_GetURLNotify'.
started with 'NPN_PostURLNotify' and 'NPN_GetURLNotify' with null window targets.


= Specification =
= Specification =
Line 20: Line 20:
The following function can be implemented by plugins to allow for URL redirect handling:
The following function can be implemented by plugins to allow for URL redirect handling:


   void NPP_URLRedirectNotify(NPP instance, const char* uri,
   void NPP_URLRedirectNotify(NPP instance, const char* url,
                             int32 status, void* notifyData);
                             int32_t status, void* notifyData);


* instance: The plug-in instance that made the request.
* instance: The plug-in instance that made the request.
* uri: The raw 'Location' header field value for the redirect.
* url: The resolved strictly-ASCII URI for the redirect.
* status: The HTTP status code returned from the server (will be 3xx).
* status: The HTTP status code returned from the server (will be 3xx).
* notifyData: The plugin's private request data.
* notifyData: The plugin's private request data.
Line 42: Line 42:
In 'NPN_URLRedirectResponse', the applicable query getting the redirect is identified by the combination of 'instance' and 'notifyData'.  If there are extant calls to NPN_GetURLNotify() or NPN_PostURLNotify() with particular values for 'instance' and 'notifyData' that have not finished, any subsequent calls to those with the same values of 'instance' and 'notifyData' will result in undefined behavior.
In 'NPN_URLRedirectResponse', the applicable query getting the redirect is identified by the combination of 'instance' and 'notifyData'.  If there are extant calls to NPN_GetURLNotify() or NPN_PostURLNotify() with particular values for 'instance' and 'notifyData' that have not finished, any subsequent calls to those with the same values of 'instance' and 'notifyData' will result in undefined behavior.


Network requests may time out if a response is not received in a reasonable amount of time. 'NPN_URLRedirectResponse' can be called during the call to 'NPP_URLRedirectNotify'.
Plugins can respond from within 'NPP_URLRedirectNotify' but the API is asynchronous so this is not necessary. It is recommended that plugins always respond to redirect notifications as soon as possible because browsers will have to track outstanding requests. If a response is not received before the relevant plugin instance is destroyed then the outstanding request will be canceled upon destruction.


There may be further redirect notifications when a redirect is allowed. When a redirect is disallowed or a response is not received within a reasonable amount of time the browser will subsequently issue an 'NPP_URLNotify' call with reason 'NPRES_USER_BREAK' and the last allowed or original url.
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 allowed or original url.


== Threading ==
== Threading ==
Line 56: Line 56:
   NPVERS_HAS_URL_REDIRECT_HANDLER = 26
   NPVERS_HAS_URL_REDIRECT_HANDLER = 26


The slot for this handler in the plugin function structure can be 'NULL'. If this handler 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 handler is not provided then redirect behavior is up to the browser.


Plugins can query the browser for support for this specification by examining the browser's function table. If the version number is equal to or higher than 'NPVERS_HAS_URL_REDIRECT_HANDLER' and the slot for 'NPN_URLRedirectResponse' is non-NULL then the browser will call 'NPP_URLRedirectNotify' when appropriate.
Plugins can query the browser for support for this specification by examining the browser's function table. If the version number is equal to or higher than 'NPVERS_HAS_URL_REDIRECT_HANDLER' and the slot for 'NPN_URLRedirectResponse' is non-NULL then the browser will call 'NPP_URLRedirectNotify' when appropriate.

Latest revision as of 02:03, 19 November 2010

Status

Accepted, ready for implementation.

Contributors

  • Last modified: November 5, 2010
  • Authors: Josh Aas (Mozilla), Johnny Stenback (Mozilla)
  • Contributors: Rudi Sherry (Adobe), Darin Fisher (Google), Dimcho Balev (Adobe), Deneb Meketa (Adobe), Stuart Morgan (Google), Jimson Xu (Adobe), Julian Reschke

Overview

Plugins need the opportunity to participate in HTTP redirect handling for requests started with 'NPN_PostURLNotify' and 'NPN_GetURLNotify' with null window targets.

Specification

Notification

The following function can be implemented by plugins to allow for URL redirect handling:

 void NPP_URLRedirectNotify(NPP instance, const char* url,
                            int32_t status, void* notifyData);
  • instance: The plug-in instance that made the request.
  • url: The resolved strictly-ASCII URI for the redirect.
  • status: The HTTP status code returned from the server (will be 3xx).
  • notifyData: The plugin's private request data.

Response

Plugins must respond to URL redirect requests by calling the following function in the browser's function table:

 void NPN_URLRedirectResponse(NPP instance, void* notifyData, NPBool allow);
  • instance: The plug-in instance that made the request.
  • notifyData: The plugin's private request data.
  • allow: The plugin's response to the last URL redirect request.

This function must be available if the browser has called 'NPP_URLRedirectNotify' on the plugin.

In 'NPN_URLRedirectResponse', the applicable query getting the redirect is identified by the combination of 'instance' and 'notifyData'. If there are extant calls to NPN_GetURLNotify() or NPN_PostURLNotify() with particular values for 'instance' and 'notifyData' that have not finished, any subsequent calls to those with the same values of 'instance' and 'notifyData' will result in undefined behavior.

Plugins can respond from within 'NPP_URLRedirectNotify' but the API is asynchronous so this is not necessary. It is recommended that plugins always respond to redirect notifications as soon as possible because browsers will have to track outstanding requests. If a response is not received before the relevant plugin instance is destroyed then the outstanding request will be canceled upon destruction.

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 allowed or original url.

Threading

With respect to threading, this specification conforms to standard NPAPI thread rules. Unless otherwise explicitly noted, all NPAPI functions must be called on the main thread.

Querying for Support

The browser will look for 'NPP_URLRedirectNotify' only if the plugin function structure's version field is set to the following value or higher:

 NPVERS_HAS_URL_REDIRECT_HANDLER = 26

The slot for this handler in the plugin function structure can be 'NULL'. If this handler is not provided then redirect behavior is up to the browser.

Plugins can query the browser for support for this specification by examining the browser's function table. If the version number is equal to or higher than 'NPVERS_HAS_URL_REDIRECT_HANDLER' and the slot for 'NPN_URLRedirectResponse' is non-NULL then the browser will call 'NPP_URLRedirectNotify' when appropriate.