Wtyczki skryptowalne

UWAGA: Tłumaczenie tej strony nie zostało zakończone.
Może być ona niekompletna lub wymagać korekty.
Chcesz pomóc? | Dokończ tłumaczenie | Sprawdź ortografię | Więcej takich stron+.

XXX: Dummy p element

Wtyczki NPAPI that used to take advantage of being scriptable via LiveConnect in 4.x Netscape browsers lost this possibility in Mozilla (due to the JNI making the Netscape 4.x JRI obsolete). As an answer to this large gap in the Netscape Plugin API, an extension to the API has been developed that lets plugins be scriptable again, independent of Java. This extension will also let plugins access the script objects in the browser, and is thus a much stronger and more flexible API.

This document describes the new cross-browser NPAPI extensions that have been developed by a group of browser and plugin vendors, including the Mozilla Foundation, Adobe, Apple, Opera, and Sun Microsystems (see press release). This document also explains how to make a plugin use these new extensions to be scriptable as well as how to access objects in a browser.

Powyższe i poniższe dane dotyczą aplikacji Firefox 1.0 i Mozilla 1.7.5 lub ich nowszych wersji.

Używanie uchwytów DOM

The Mozilla DOM code now checks if a plugin supports this new scriptability API and if it exposes a scriptable object through this new mechanism. Mozilla does this by calling the old plugin API call with the new enumeration value that has been added to the enumeration.

The new NPPVariable enumeration is defined in npapi.h as:

NPPVpluginScriptableNPObject = 15

System procesowy

This API is not designed to be thread safe. The threading model for this API is such that all calls through this API are synchronous and calls from a plugin to methods in this API must come from the thread on which the plugin was initiated, and likewise all calls to methods in this API by the browser are guaranteed to come from the same thread. Future revisions to this API might provide a mechanism for proxying calls from one thread to another to aid in using this API from other threads.

System bezpieczeństwa

The security model for making calls through this API is much like the general same-origin security model enforced by the browser. That means that script from an origin other than the origin of the page that loaded the plugin is not able to access methods and properties on the plugin. The same thing applies the other way too, the plugin can reach only JavaScript objects in the same origin as the page that loaded the plugin.

In addition to this, a further extension to this API is being discussed that would give a plugin greater flexibility by letting the plugin control the origin of the calling code, so that the plugin can specify the origin of calls that come from internally loaded code from other origins. This way such code can be executed with only the privileges of the origin of the code, and not the privileges of the plugin page's origin.

Co znajduje się w kodzie pluginu?

Wtyczka, która jest skryptowalna z użyciem nowego mechanizmu, musi zwracać właściwy (który jest tworzony poprzez wzywanie ) gdy przeglądarka wymaga tego wzywając:

NPP_GetValue(npp, NPPVpluginScriptableNPObject, ...);

Uzyskiwanie dostępu do obiektów przeglądarki z poziomu pluginu

A plugin that wishes to access objects in the browser window that loaded the plugin can do this by getting the for the browsers window object, or the DOM element that loaded the plugin. This is done by using an extension to . The extensions are two additions to the enumeration, the new enumerations are NPNVWindowNPObject and NPNVPluginElementNPObject. By calling NPN_GetValue() with either of those new enumerations will return an NPObject representing the browser object, and from there, the functions in this API can be used to get and set properties, and to call methods on those browser objects.

And as always when working with reference counted NPObjects, the caller is responsible for calling on the NPObject to drop the reference.

The new NPNVariable enumerations are defined in npapi.h as:

NPNVWindowNPObject = 15,
NPNVPluginElementNPObject = 16

Sposób wzywania natywnych metod pluginu

Całą pracę wykonuje się poprzez poniższy kod HTML:

<embed type="application/plugin-mimetype">
<script>
  var embed = document.embeds[0];
  embed.nativeMethod();
  alert(embed.nativeProperty);
  embed.nativeProperty.anotherNativeMethod();
</script>

Rozszerzenia API

Rozszerzenia API bazują na czterech nowych strukturach:

Autorzy i etykiety dokumentu

Autorzy tej strony: Bedi, splewako, zarat
Ostatnia aktualizacja: splewako,