java 小程序不响应 webkit 浏览器中的重绘请求

发布于 2024-09-26 09:32:33 字数 2042 浏览 2 评论 0原文

我目前正在编写一个小型 Java 小程序,以与浏览器无关的方式解决我们公司内部网中的特定问题。这过去是通过 ActiveX 来完成的,但我们希望让人们远离 IE。该代码对于公众使用显然不安全,但在受控情况下很有用。本质上,我希望用户能够单击其中的链接,并根据 AJAX 调用返回的数据打开安装在本地计算机上的应用程序。这是一个已签名的 Java 小程序,并且证书已在本地计算机上被接受。

目前,这在 IE 和 Opera 中完美运行,但在 Chrome 和 Safari 中失败。看来 repaint() 方法实际上并没有导致重新绘制,这是我正在努力解决的问题。这是小程序代码:

import java.applet.Applet;
import java.awt.Graphics;
import java.util.*;

public class OdehAppLauncher extends Applet {

    private ArrayList<String> toRun = null;

    public void paint(Graphics g) {
        System.out.println("-----painting");
        try {
            if (toRun != null) {
                new ProcessBuilder(toRun).start();
                toRun = null;
            }

        } catch (Exception e) {
            System.out.println("-----Exception e = " + e);
            e.printStackTrace();
        }
    }

    public void runApp(String appName, String args) {
        System.out.println("-----running app: " + appName);
        toRun = new ArrayList<String>(2);
        toRun.add(appName);
        toRun.add(args);
        System.out.println("-----triggering a repaint...");
        repaint();
    }
}

以下是调用 runApp 方法时四个测试浏览器中每个浏览器的 Java 控制台的最后几行:

IE 9(测试版)- 有效:

基本:小程序已启动
基本:告诉客户小程序已启动
-----绘画
-----运行应用程序:notepad.exe
-----触发重绘...
-----绘画

Safari 5.0.2 (7533.18.5) - 失败

liveconnect:JavaScript:默认安全策略=
-----运行应用程序:notepad.exe
-----触发重绘...

Opera 10.62 - 有效

基本:小程序已启动
基本:告诉客户小程序已启动
-----绘画
-----绘画
-----绘画
-----运行应用程序:notepad.exe
-----触发重绘...
-----绘画

Chrome 6.0.472.63 - 失败

基本:小程序已启动
基本:告诉客户小程序已启动
-----运行应用程序:notepad.exe
-----触发重绘...

如果您能想到导致行为不一致的任何原因(或者一般情况下更好的方法),请告诉我。我还应该指出,我尝试直接从 runApp 调用启动进程,但普遍失败。

I currently have a tiny Java applet I'm writing to solve a specific problem in our company intranet in a browser neutral way. This used to be accomplished with ActiveX but we'd like to let people move away from IE. The code is obviously unsafe for public consumption, but it's useful under controlled circumstances. Essentially I want the user to be able to click a link in their and open an application installed on the local machine based on data returned from an AJAX call. This is a signed Java applet and the certificate has been accepted on the local machine.

Currently this works perfectly in IE and Opera, but it fails in Chrome and Safari. It appears that the repaint() method doesn't actually cause a repaint, which I am struggling with. Here's the applet code:

import java.applet.Applet;
import java.awt.Graphics;
import java.util.*;

public class OdehAppLauncher extends Applet {

    private ArrayList<String> toRun = null;

    public void paint(Graphics g) {
        System.out.println("-----painting");
        try {
            if (toRun != null) {
                new ProcessBuilder(toRun).start();
                toRun = null;
            }

        } catch (Exception e) {
            System.out.println("-----Exception e = " + e);
            e.printStackTrace();
        }
    }

    public void runApp(String appName, String args) {
        System.out.println("-----running app: " + appName);
        toRun = new ArrayList<String>(2);
        toRun.add(appName);
        toRun.add(args);
        System.out.println("-----triggering a repaint...");
        repaint();
    }
}

Here are the last few lines of the Java Console for each of the four tested browsers when the runApp method is called:

IE 9 (beta) - works:

basic: Applet started
basic: Told clients applet is started
-----painting
-----running app: notepad.exe
-----triggering a repaint...
-----painting

Safari 5.0.2 (7533.18.5) - fails

liveconnect: JavaScript: default security policy =
-----running app: notepad.exe
-----triggering a repaint...

Opera 10.62 - works

basic: Applet started
basic: Told clients applet is started
-----painting
-----painting
-----painting
-----running app: notepad.exe
-----triggering a repaint...
-----painting

Chrome 6.0.472.63 - fails

basic: Applet started
basic: Told clients applet is started
-----running app: notepad.exe
-----triggering a repaint...

Please let me know if you can think of any reason why this isn't behaving consistently (or a better way to do this in general). I should also point out that I've tried just launching the process directly from the runApp call, but that fails universally.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吃不饱 2024-10-03 09:32:33

也许这个链接给出了一些提示。例如:

注意:如果在处理初始重绘请求之前组件上发生了对 repaint() 的多次调用,则多个请求可能会合并为对 update() 的单个调用。确定何时应折叠多个请求的算法取决于实现。如果折叠多个请求,则生成的更新矩形将等于折叠请求中包含的矩形的并集。

您可能想检查小程序是否可见,最近是否有绘画,以及是否调用了 update(Graphics)...

Maybe this link gives a few hints. For instance:

NOTE: If multiple calls to repaint() occur on a component before the initial repaint request is processed, the multiple requests may be collapsed into a single call to update(). The algorithm for determining when multiple requests should be collapsed is implementation-dependent. If multiple requests are collapsed, the resulting update rectangle will be equal to the union of the rectangles contained in the collapsed requests.

You might want to check if the applet is visible, if there has been a paint recently, and if update(Graphics) is called...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文