简体   繁体   English

java如何在浏览器中运行其applet?

[英]How does java run its applets in the browser?

好吧,我们已经很长时间没有在Internet Explorer中运行ActiveX控件了,所以我的问题是Java如何操纵浏览器在网页上显示小程序?

how does java manipulate the browser into displaying the applet on the web page? Java如何操纵浏览器在网页上显示小程序?

It doesn't. 没有。 The user installs an NPAPI (Netscape Plugin API) plugin which tells the browser it can run Java applets. 用户安装一个NPAPI(Netscape插件API) 插件 ,该插件告诉浏览器它可以运行Java小程序。 Then, when the browser sees a Java applet, it fires up the plugin. 然后,当浏览器看到Java小程序时,它将启动该插件。

It's worth noting that Chrome no longer supports the NPAPI on Linux, and they're scheduled to stop supporting it on Windows in September . 值得注意的是,Chrome不再支持Linux上的NPAPI,并且计划于9月停止在Windows上支持它 As far as I know, officially Mozilla calls NPAPI plugins a "legacy" feature and recommends using other options, but is continuing to support them via click-to-play (at least for now).. 据我所知,Mozilla 正式将NPAPI插件称为“旧版”功能,并建议使用其他选项,但仍继续通过点击播放来支持它们(至少目前如此)。

Java Applets consists of compiled byte-code, which is executed under the control of a JVM. Java Applets由编译后的字节码组成,该字节码在JVM的控制下执行。 Applets may either be untrusted which limits their capabilities or may be trusted which increases their access permissions and allows them to access user data or hardware. 小程序可能是不受信任的,这限制了它们的功能,或者可能是受信任的,这增加了它们的访问权限,并允许它们访问用户数据或硬件。

Java applet runs in browser using Java Plug-in technology (hereafter the "Java Plug-in"), which is included in the Java Runtime Environment (JRE), enables Java applets to run in web browsers on the desktop. Java小程序在Java运行时环境(JRE)中包含的Java插件技术(以下称为“ Java插件”)在浏览器中运行,使Java小程序能够在桌面上的Web浏览器中运行。 The Java Plug-in provides powerful capabilities to applets in the web browser. Java插件为Web浏览器中的小程序提供了强大的功能。 With the Java Plug-in, applets are not run in the JVM inside the browser. 使用Java插件时,小程序不会在浏览器内部的JVM中运行。 Instead, they are executed in a separate process. 相反,它们在单独的过程中执行。 The same JVM process can be shared between multiple applets, or applets can be placed into different processes depending on whether the existing JVMs match the applet requirements and have enough resources to execute the applet. 可以在多个applet之间共享同一JVM进程,也可以将applet放入不同的进程中,具体取决于现有的JVM是否符合applet的要求并具有足够的资源来执行applet。

A web browser's JavaScript interpreter engine is single thread. Web浏览器的JavaScript解释器引擎是单线程。 The Java Plug-in is capable of managing multiple threads. Java插件能够管理多个线程。 The Java Plug-in creates a separate worker thread for every applet. Java插件为每个小程序创建一个单独的工作线程。 Applets themselves may be multi-threaded. Applet本身可能是多线程的。

The following figure shows the thread interactions between the JavaScript Interpreter, Java Plug-in, and an applet. 下图显示了JavaScript解释器,Java插件和小程序之间的线程交互。

线程互动

When the JavaScript interpreter is idle, the Java Plug-in executes a JavaScript to Java call on the per applet worker thread (JavaScript Interpreter Not Busy scenario). 当JavaScript解释器空闲时,Java插件在每个applet工作者线程上执行JavaScript到Java的调用(JavaScript Interpreter Not Busy场景)。

When a Java to JavaScript call is in progress and a JavaScript to Java call is made, the latter is executed on the same thread that made the Java to JavaScript call (Round Trip scenario). 当正在进行Java到JavaScript的调用并且进行JavaScript到Java的调用时,后者将在执行Java到JavaScript的同一线程上执行(往返方案)。

When a thread is executing a Java to JavaScript call, another thread wanting to do the same will be blocked till the first thread has received its result and is done (JavaScript Interpreter Busy scenario) 当一个线程正在执行Java到JavaScript的调用时,另一个想要执行此操作的线程将被阻塞,直到第一个线程收到其结果并完成为止(JavaScript Interpreter Busy场景)

However, Java extension plugin itself is written using NPAPI plugin, the cross-browser API for plugins. 但是,Java扩展插件本身是使用NPAPI插件(插件的跨浏览器API)编写的。 Stands for, Netscape Plugin Application Programming Interface. 代表Netscape插件应用程序编程接口。 It allowed third-party code in the form of precompiled plugins to be used by the browser to display vendor specific content seamlessly in web pages. 它允许浏览器使用预编译插件形式的第三方代码在网页中无缝显示特定于供应商的内容。 Essentially, it lets you call the native binary code from your JavaScript code. 本质上,它使您可以从JavaScript代码中调用本机二进制代码。 But running NPAPI plugin, the code has the full permissions of the current user and has unrestricted access to the local machine. 但是运行NPAPI插件后,该代码具有当前用户的全部权限,并且可以不受限制地访问本地计算机。 So all in all with NPAPI, security depends on the plugin's good behaviour and most security considerations are up to the plugin developer. 因此,总的来说,使用NPAPI时,安全性取决于插件的良好行为,并且大多数安全性注意事项取决于插件开发人员。 For example, plugin instances can load resources from different origins on request of a web page. 例如,插件实例可以根据网页的请求从不同来源加载资源。

Architectural wise, Java needs these privileges to offer the kind of power and control it brings to the table. 从架构的角度来看,Java需要这些特权来提供它带给表的那种功能和控制。 Java and some versions of Flash and Shockwave still use NPRuntime, and NPAPI needs to be enabled for Java to function correctly in a browser. Java和某些版本的Flash和Shockwave仍使用NPRuntime,并且需要启用NPAPI才能使Java在浏览器中正常运行。 At the same time many browsers like Chrome consider this (NPAPI plugin) as serious security vulnerability because if the plugin (that uses NPAPI) contains a vulnerability, an attacker might be able to exploit that vulnerability to install malicious software on the user's machine, also sine plugin (java or NPAPI) is exposed directly to web content, making it easier for a malicious web site to manipulate your plugin, which is why it has made it user permission controlled. 同时,许多浏览器(例如Chrome)都将此漏洞(NPAPI插件)视为严重的安全漏洞,因为如果该插件(使用NPAPI)包含漏洞,攻击者便可以利用该漏洞在用户计算机上安装恶意软件,正弦插件(java或NPAPI)直接暴露于Web内容,这使得恶意网站更容易操纵您的插件,这就是为什么它使用户权限受控制的原因。 Another reason why browsers are moving away from this is, NPAPI isn't supported on mobile devices. 浏览器偏离这一点的另一个原因是,移动设备不支持NPAPI。 Also there are newer problems such as jit spraying http://en.wikipedia.org/wiki/JIT_spraying 也有更新的问题,例如喷洒http://en.wikipedia.org/wiki/JIT_spraying

Though Chrome has officially stopped NPAPI support, As of Chrome Version 42, an additional configuration step is required to continue using NPAPI plugins. 尽管Chrome正式停止了对NPAPI的支持,但从Chrome版本42开始,仍需要执行其他配置步骤才能继续使用NPAPI插件。 (Could only work till Sept 2015) (只能使用到2015年9月)

In your URL bar, enter: chrome://flags/#enable-npapi Click the Enable link for the Enable NPAPI configuration option. 在您的URL栏中,输入:chrome:// flags /#enable-npapi单击“启用”链接以启用“ Enable NPAPI”配置选项。 Click the Relaunch button that now appears at the bottom of the configuration page. 单击现在显示在配置页面底部的重新启动按钮。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM