mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 19:35:51 +00:00
Added Swing webclient test code and windows makefile mods.
Author=Ann Sunhachawee r=edburns@acm.org Approver=edburns@acm.org Bug=http://bugzilla.mozilla.org/show_bug.cgi?id=16842
This commit is contained in:
parent
1178f50d75
commit
e681c419cb
@ -40,7 +40,7 @@ include <$(DEPTH)\config\config.mak>
|
||||
include <$(DEPTH)\java\config\localdefs.mak>
|
||||
|
||||
JAR_WEBCLIENT_CLASSES = org\mozilla\webclient \
|
||||
org\mozilla\webclient\test org\mozilla\webclient\win32
|
||||
org\mozilla\webclient\test org\mozilla\webclient\win32 org\mozilla\webclient\test\swing
|
||||
|
||||
!ifdef JAVA_OR_NSJVM
|
||||
JDIRS = $(JAR_WEBCLIENT_CLASSES)
|
||||
|
@ -26,7 +26,7 @@ package org.mozilla.webclient;
|
||||
* interfaces.
|
||||
|
||||
*
|
||||
* @version $Id: BrowserControl.java,v 1.1 1999/07/30 01:03:03 edburns%acm.org Exp $
|
||||
* @version $Id: BrowserControl.java,v 1.2 1999/10/20 00:49:18 edburns%acm.org Exp $
|
||||
*
|
||||
* @see org.mozilla.webclient.BrowserControlCore
|
||||
* @see org.mozilla.webclient.BrowserControlExtended
|
||||
@ -36,4 +36,6 @@ package org.mozilla.webclient;
|
||||
public interface BrowserControl extends BrowserControlCore, BrowserControlExtended
|
||||
{
|
||||
|
||||
public EventRegistration getEventRegistration();
|
||||
|
||||
} // end of interface BrowserControl
|
||||
|
@ -31,13 +31,13 @@ import java.awt.Rectangle;
|
||||
*
|
||||
* <B>Lifetime And Scope</B> <P>
|
||||
*
|
||||
* @version $Id: BrowserControlImpl.java,v 1.3 1999/10/08 00:48:01 edburns%acm.org Exp $
|
||||
* @version $Id: BrowserControlImpl.java,v 1.4 1999/10/20 00:49:18 edburns%acm.org Exp $
|
||||
*
|
||||
* @see org.mozilla.webclient.BrowserControl
|
||||
*
|
||||
*/
|
||||
|
||||
public class BrowserControlImpl extends Object implements BrowserControl
|
||||
public class BrowserControlImpl extends Object implements BrowserControl, EventRegistration
|
||||
{
|
||||
//
|
||||
// Protected Constants
|
||||
@ -69,8 +69,7 @@ public class BrowserControlImpl extends Object implements BrowserControl
|
||||
|
||||
public BrowserControlImpl(int windowPtr, Rectangle bounds) throws Exception
|
||||
{
|
||||
nativeWebShell = BrowserControlMozillaShim.webShellCreate(windowPtr,
|
||||
bounds);
|
||||
nativeWebShell = BrowserControlMozillaShim.webShellCreate(windowPtr, bounds);
|
||||
}
|
||||
|
||||
//
|
||||
@ -211,6 +210,21 @@ public boolean refresh() throws Exception
|
||||
return BrowserControlMozillaShim.webShellRefresh(nativeWebShell);
|
||||
}
|
||||
|
||||
/**
|
||||
* get EventRegistration object
|
||||
*/
|
||||
|
||||
public EventRegistration getEventRegistration() {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* add document load event listener
|
||||
*/
|
||||
public boolean addDocumentLoadListener(DocumentLoadListener dll) throws Exception {
|
||||
return BrowserControlMozillaShim.webShellAddDocListener(nativeWebShell, dll);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@ -245,7 +259,7 @@ public static void main(String [] args)
|
||||
// BrowserControlImpl me = new BrowserControlImpl();
|
||||
Log.setApplicationName("BrowserControlImpl");
|
||||
Log.setApplicationVersion("0.0");
|
||||
Log.setApplicationVersionDate("$Id: BrowserControlImpl.java,v 1.3 1999/10/08 00:48:01 edburns%acm.org Exp $");
|
||||
Log.setApplicationVersionDate("$Id: BrowserControlImpl.java,v 1.4 1999/10/20 00:49:18 edburns%acm.org Exp $");
|
||||
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,7 @@ import java.awt.*;
|
||||
* There is one instance of this class and all of the exposed methods
|
||||
* are static.
|
||||
|
||||
* @version $Id: BrowserControlMozillaShim.java,v 1.4 1999/10/08 00:48:02 edburns%acm.org Exp $
|
||||
* @version $Id: BrowserControlMozillaShim.java,v 1.5 1999/10/20 00:49:19 edburns%acm.org Exp $
|
||||
*
|
||||
* @see org.mozilla.webclient.BrowserControlImpl
|
||||
|
||||
@ -299,6 +299,17 @@ public static void webShellDelete (int webShellPtr) throws Exception
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean webShellAddDocListener(int webShellPtr, DocumentLoadListener dl) throws Exception
|
||||
{
|
||||
synchronized(lock) {
|
||||
if (initialized) {
|
||||
return instance.nativeWebShellAddDocListener(webShellPtr, dl);
|
||||
} else {
|
||||
throw new Exception ("instance is not initialized");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void webShellLoadURL (int webShellPtr,
|
||||
String urlString) throws Exception
|
||||
{
|
||||
@ -527,6 +538,7 @@ private native void nativeUpdateEvent (int windowPtr, int eventTime);
|
||||
|
||||
private native int nativeWidgetCreate (int windowPtr, int x, int y, int width, int height) throws Exception;
|
||||
private native void nativeWidgetDelete (int widgetPtr) throws Exception;
|
||||
private native boolean nativeWebShellAddDocListener(int windowPtr, DocumentLoadListener dl);
|
||||
private native void nativeWidgetResize (int widgetPtr, int x, int y, int width, int height, boolean repaint);
|
||||
|
||||
/*
|
||||
@ -588,7 +600,7 @@ public static void main(String [] args)
|
||||
BrowserControlMozillaShim me = new BrowserControlMozillaShim();
|
||||
Log.setApplicationName("BrowserControlMozillaShim");
|
||||
Log.setApplicationVersion("0.0");
|
||||
Log.setApplicationVersionDate("$Id: BrowserControlMozillaShim.java,v 1.4 1999/10/08 00:48:02 edburns%acm.org Exp $");
|
||||
Log.setApplicationVersionDate("$Id: BrowserControlMozillaShim.java,v 1.5 1999/10/20 00:49:19 edburns%acm.org Exp $");
|
||||
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,7 @@
|
||||
package org.mozilla.webclient;
|
||||
|
||||
public interface DocListener {
|
||||
|
||||
public void handleDocLoaderEvent();
|
||||
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package org.mozilla.webclient;
|
||||
|
||||
public interface DocumentLoadListener {
|
||||
public void docEventPerformed(String event);
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package org.mozilla.webclient;
|
||||
|
||||
public interface EventRegistration {
|
||||
|
||||
public boolean addDocumentLoadListener(DocumentLoadListener dll) throws Exception;
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
|
||||
package org.mozilla.webclient.test.swing;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import javax.swing.*;
|
||||
|
||||
import org.mozilla.webclient.*;
|
||||
|
||||
class BackAction extends AbstractAction {
|
||||
private SwingEmbeddedMozilla em;
|
||||
|
||||
public BackAction(SwingEmbeddedMozilla em) {
|
||||
super ("Back");
|
||||
this.em = em;
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent evt) {
|
||||
System.out.println("Back was pressed!!");
|
||||
em.back();
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,93 @@
|
||||
package org.mozilla.webclient.test.swing;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import javax.swing.*;
|
||||
|
||||
import org.mozilla.webclient.*;
|
||||
|
||||
public class CommandPanel extends JPanel implements ActionListener {
|
||||
private JToolBar urltool;
|
||||
private JToolBar navtool;
|
||||
private JTextField urlfield;
|
||||
private JComboBox cb;
|
||||
private SwingEmbeddedMozilla em;
|
||||
|
||||
public CommandPanel(SwingEmbeddedMozilla em) {
|
||||
super();
|
||||
GridBagLayout gbl = new GridBagLayout();
|
||||
GridBagConstraints gbc = new GridBagConstraints();
|
||||
setLayout(gbl);
|
||||
this.em = em;
|
||||
|
||||
navtool = createNavToolBar();
|
||||
urltool = createURLToolBar();
|
||||
|
||||
// Layout of the toolbars.
|
||||
gbc.anchor = GridBagConstraints.NORTHWEST;
|
||||
add(navtool, gbc);
|
||||
|
||||
gbc.gridwidth = GridBagConstraints.REMAINDER;
|
||||
gbc.weightx = 1.0;
|
||||
add(Box.createHorizontalGlue(), gbc);
|
||||
|
||||
gbc.gridwidth = 1;
|
||||
add(urltool, gbc);
|
||||
}
|
||||
|
||||
private JButton makeButton(String arg) {
|
||||
JButton button = new JButton(arg);
|
||||
return button;
|
||||
}
|
||||
|
||||
private JToolBar createURLToolBar() {
|
||||
JToolBar tb = new JToolBar();
|
||||
// Ann - commented out the combobox for demo purposes. 9/20/99
|
||||
// String temp[] = {"Fee", "Fi", "Fo", "Fum"};
|
||||
//cb = new JComboBox(temp);
|
||||
//cb.setEditable(true);
|
||||
//cb.setLightWeightPopupEnabled(false);
|
||||
urlfield = new JTextField(25);
|
||||
|
||||
tb.add(urlfield);
|
||||
//tb.add(cb);
|
||||
//cb.addActionListener(this);
|
||||
urlfield.addActionListener(this);
|
||||
return tb;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private JToolBar createNavToolBar() {
|
||||
JToolBar tb = new JToolBar();
|
||||
|
||||
tb.add(new BackAction(em));
|
||||
tb.add(new ForwardAction(em));
|
||||
tb.add(new StopAction(em));
|
||||
tb.add(new RefreshAction(em));
|
||||
tb.putClientProperty("JToolBar.isRollover", Boolean.TRUE);
|
||||
return tb;
|
||||
}
|
||||
|
||||
|
||||
public JTextField getURLField() {
|
||||
return urlfield;
|
||||
}
|
||||
|
||||
public JToolBar getNavToolBar() {
|
||||
return navtool;
|
||||
}
|
||||
|
||||
public void actionPerformed (ActionEvent evt) {
|
||||
String command = evt.getActionCommand();
|
||||
String url = null;
|
||||
System.out.println( "ActionComand is "+ command);
|
||||
if ("comboBoxChanged".equals(command)) {
|
||||
url = (String) cb.getSelectedItem();
|
||||
} else {
|
||||
url = urlfield.getText();
|
||||
}
|
||||
em.loadURL(url);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
|
||||
package org.mozilla.webclient.test.swing;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import javax.swing.*;
|
||||
|
||||
import org.mozilla.webclient.*;
|
||||
|
||||
class ForwardAction extends AbstractAction {
|
||||
private SwingEmbeddedMozilla em;
|
||||
|
||||
public ForwardAction(SwingEmbeddedMozilla em) {
|
||||
super ("Forward");
|
||||
this.em = em;
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent evt) {
|
||||
System.out.println("Forwardwas pressed!!");
|
||||
em.forward();
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
|
||||
package org.mozilla.webclient.test.swing;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import javax.swing.*;
|
||||
|
||||
import org.mozilla.webclient.*;
|
||||
|
||||
class RefreshAction extends AbstractAction {
|
||||
private SwingEmbeddedMozilla em;
|
||||
|
||||
public RefreshAction(SwingEmbeddedMozilla em) {
|
||||
super ("Refresh");
|
||||
this.em = em;
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent evt) {
|
||||
System.out.println("Refresh was pressed!!");
|
||||
em.refresh();
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package org.mozilla.webclient.test.swing;
|
||||
/*
|
||||
* StatusPanel.java
|
||||
*/
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import javax.swing.*;
|
||||
import org.mozilla.webclient.*;
|
||||
|
||||
public class StatusTextField extends JTextField implements DocumentLoadListener {
|
||||
|
||||
public StatusTextField(BrowserControl bc) {
|
||||
super();
|
||||
setEditable(false);
|
||||
try {
|
||||
bc.getEventRegistration().addDocumentLoadListener(this);
|
||||
} catch (Exception ex) {
|
||||
System.out.println(ex.toString());
|
||||
}
|
||||
|
||||
}
|
||||
public void docEventPerformed(String event) {
|
||||
if (event.equals("startdocumentload")) {
|
||||
this.setText("Loading document...");
|
||||
} else if (event.equals("enddocumentload")) {
|
||||
this.setText("Finished loading document.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
|
||||
package org.mozilla.webclient.test.swing;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import javax.swing.*;
|
||||
|
||||
import org.mozilla.webclient.*;
|
||||
|
||||
class StopAction extends AbstractAction {
|
||||
private SwingEmbeddedMozilla em;
|
||||
|
||||
public StopAction(SwingEmbeddedMozilla em) {
|
||||
super ("Stop");
|
||||
this.em = em;
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent evt) {
|
||||
System.out.println("Stop was pressed!!");
|
||||
em.stop();
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,244 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
||||
* the License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The original code is RaptorCanvas
|
||||
*
|
||||
* The Initial Developer of the Original Code is Kirk Baker <kbaker@eb.com> and * Ian Wilkinson <iw@ennoble.com
|
||||
*/
|
||||
|
||||
package org.mozilla.webclient.test.swing;
|
||||
|
||||
/*
|
||||
* SwingEmbeddedMozilla.java
|
||||
*/
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import javax.swing.*;
|
||||
|
||||
import org.mozilla.webclient.*;
|
||||
|
||||
/**
|
||||
*
|
||||
|
||||
* This is a test application for using the BrowserControl.
|
||||
|
||||
*
|
||||
* @version $Id: SwingEmbeddedMozilla.java,v 1.1 1999/10/20 00:49:24 edburns%acm.org Exp $
|
||||
*
|
||||
* @see org.mozilla.webclient.BrowserControlCanvasFactory
|
||||
|
||||
*/
|
||||
|
||||
public class SwingEmbeddedMozilla extends JFrame
|
||||
{
|
||||
static final int defaultWidth = 640;
|
||||
static final int defaultHeight = 480;
|
||||
static String binDir = null;
|
||||
|
||||
private TextField urlField;
|
||||
private BrowserControl browserControl;
|
||||
private CommandPanel controlPanel;
|
||||
|
||||
public static void printUsage()
|
||||
{
|
||||
System.out.println("usage: java org.mozilla.webclient.test.SwingEmbeddedMozilla <path> [url]");
|
||||
System.out.println(" <path> is the absolute path to the native browser bin directory, ");
|
||||
System.out.println(" including the bin.");
|
||||
}
|
||||
|
||||
|
||||
public static void main (String[] arg) {
|
||||
if (1 > arg.length) {
|
||||
printUsage();
|
||||
System.exit(-1);
|
||||
}
|
||||
String urlArg =(2 == arg.length) ? arg[1] : "http://www.mozilla.org/";
|
||||
|
||||
SwingEmbeddedMozilla.binDir = arg[0];
|
||||
|
||||
SwingEmbeddedMozilla gecko =
|
||||
new SwingEmbeddedMozilla("Embedded Mozilla", arg[0], urlArg);
|
||||
} // main()
|
||||
|
||||
public SwingEmbeddedMozilla (String title, String binDir, String url)
|
||||
{
|
||||
super(title);
|
||||
|
||||
Container contentPane = getContentPane();
|
||||
JMenuBar menubar = createMenuBar();
|
||||
|
||||
System.out.println("constructed with " + url);
|
||||
|
||||
addWindowListener(new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent e) {
|
||||
dispose();
|
||||
// should close the BrowserControlCanvas
|
||||
}
|
||||
|
||||
public void windowClosed(WindowEvent e) {
|
||||
System.exit(0);
|
||||
}
|
||||
});
|
||||
|
||||
setSize(defaultWidth, defaultHeight);
|
||||
|
||||
// Create the browser
|
||||
BrowserControlCanvas browser = null;
|
||||
|
||||
try {
|
||||
BrowserControlCanvasFactory.setAppData(binDir);
|
||||
browser = BrowserControlCanvasFactory.newBrowserControlCanvas();
|
||||
}
|
||||
catch(Exception e) {
|
||||
System.out.println("Can't create BrowserControlCanvas: " +
|
||||
e.getMessage());
|
||||
}
|
||||
|
||||
browser.setSize(defaultWidth, defaultHeight);
|
||||
|
||||
// Add the control panel and the browser
|
||||
contentPane.add(browser, BorderLayout.CENTER);
|
||||
|
||||
|
||||
controlPanel = new CommandPanel(this);
|
||||
contentPane.add(controlPanel, BorderLayout.NORTH);
|
||||
|
||||
|
||||
getRootPane().setMenuBar(menubar);
|
||||
|
||||
pack();
|
||||
show();
|
||||
toFront();
|
||||
|
||||
browserControl = browser.getWebShell();
|
||||
|
||||
// DocumentLoadListener dll;
|
||||
try {
|
||||
// dll = new DocumentLoadListener();
|
||||
// browserControl.getEventRegistration().addDocumentLoadListener(dll);
|
||||
contentPane.add(new StatusTextField(browserControl), BorderLayout.SOUTH);
|
||||
|
||||
} catch (Exception ex) {
|
||||
System.out.println(ex.toString());
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
browserControl.loadURL(url);
|
||||
controlPanel.getURLField().setText(url);
|
||||
}
|
||||
catch (Exception e) {
|
||||
System.out.println(e.toString());
|
||||
}
|
||||
} // SwingEmbeddedMozilla() ctor
|
||||
|
||||
private JMenuBar createMenuBar()
|
||||
{
|
||||
JMenuBar menubar = new JMenuBar();
|
||||
JMenu menu = new JMenu("File");
|
||||
JMenuItem exitItem = new JMenuItem("Exit");
|
||||
JMenuItem newItem = new JMenuItem("New Window");
|
||||
|
||||
KeyStroke ks = KeyStroke.getKeyStroke(KeyEvent.VK_Q, Event.CTRL_MASK);
|
||||
KeyStroke ks_new = KeyStroke.getKeyStroke(KeyEvent.VK_N, Event.CTRL_MASK);
|
||||
|
||||
menu.getPopupMenu().setLightWeightPopupEnabled(false);
|
||||
newItem.setAccelerator(ks_new);
|
||||
newItem.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
new SwingEmbeddedMozilla("New Window", SwingEmbeddedMozilla.binDir,
|
||||
controlPanel.getURLField().getText());
|
||||
}
|
||||
});
|
||||
|
||||
exitItem.setAccelerator(ks);
|
||||
exitItem.addActionListener( new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
System.exit(0);
|
||||
}
|
||||
});
|
||||
menu.setMnemonic('F');
|
||||
exitItem.setMnemonic(KeyEvent.VK_X);
|
||||
newItem.setMnemonic(KeyEvent.VK_N);
|
||||
menu.add(newItem);
|
||||
menu.add(exitItem);
|
||||
|
||||
menubar.add(menu);
|
||||
return menubar;
|
||||
}
|
||||
|
||||
public void back()
|
||||
{
|
||||
try {
|
||||
if (browserControl.canBack()) {
|
||||
browserControl.back();
|
||||
int index = browserControl.getHistoryIndex();
|
||||
String newURL = browserControl.getURL(index);
|
||||
|
||||
System.out.println(newURL);
|
||||
|
||||
controlPanel.getURLField().setText(newURL);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println( "anns: exception in back "+ e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public void forward()
|
||||
{
|
||||
try {
|
||||
if (browserControl.canForward()) {
|
||||
browserControl.forward();
|
||||
int index = browserControl.getHistoryIndex();
|
||||
String newURL = browserControl.getURL(index);
|
||||
|
||||
System.out.println(newURL);
|
||||
|
||||
controlPanel.getURLField().setText(newURL);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println( "anns: exception in forward "+ e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public void stop()
|
||||
{
|
||||
try {
|
||||
browserControl.stop();
|
||||
} catch (Exception e) {
|
||||
System.out.println("anns: exception in stop "+ e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public void refresh()
|
||||
{
|
||||
try {
|
||||
browserControl.refresh();
|
||||
} catch (Exception e) {
|
||||
System.out.println("anns: exception in refresh" + e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public void loadURL(String url)
|
||||
{
|
||||
try {
|
||||
browserControl.loadURL(url);
|
||||
} catch (Exception e) {
|
||||
System.out.println("anns: exception in load "+ e.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// EOF
|
@ -62,6 +62,8 @@ nsMacMessageSink gMessageSink;
|
||||
#include "nsIRegistry.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIPref.h"
|
||||
#include "DocumentObserver.h"
|
||||
#include "nsIDocumentLoader.h"
|
||||
|
||||
#define DEBUG_RAPTOR_CANVAS 1
|
||||
|
||||
@ -1616,6 +1618,35 @@ Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeWebShellBack (
|
||||
return JNI_FALSE;
|
||||
} // Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeWebShellBack()
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeWebShellAddDocListener
|
||||
(JNIEnv *env,
|
||||
jobject obj,
|
||||
jint webShellPtr,
|
||||
jobject doclistener)
|
||||
{
|
||||
|
||||
// need to pass in the environment to the addition of c doclistener, so
|
||||
// that it can call into the java stuff again
|
||||
DocumentObserver * documentObserver = new DocumentObserver(env, obj, webShellPtr, doclistener);
|
||||
|
||||
WebShellInitContext* initContext = (WebShellInitContext *) webShellPtr;
|
||||
|
||||
if (initContext == nsnull) {
|
||||
::ThrowExceptionToJava(env, "Exception: null webShellPtr passed to raptorWebShellAddDocListener");
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
if (initContext->initComplete) {
|
||||
nsIDocumentLoader *docloader;
|
||||
initContext->webShell->GetDocumentLoader(docloader );
|
||||
if (docloader != nsnull) {
|
||||
docloader->AddObserver((nsIDocumentLoaderObserver *) documentObserver);
|
||||
}
|
||||
|
||||
}
|
||||
return JNI_TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: BrowserControlMozillaShim
|
||||
|
156
java/webclient/src/DocumentObserver.cpp
Normal file
156
java/webclient/src/DocumentObserver.cpp
Normal file
@ -0,0 +1,156 @@
|
||||
#include "nsString.h"
|
||||
#include "DocumentObserver.h"
|
||||
#include "nsIDocumentLoaderObserver.h"
|
||||
#include "nsISupportsUtils.h"
|
||||
#include<stdio.h>
|
||||
#include "jni_util.h"
|
||||
#include <jni.h>
|
||||
|
||||
void fireDocumentLoadEvent(char *);
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kIDocumentLoaderObserverIID, NS_IDOCUMENT_LOADER_OBSERVER_IID);
|
||||
|
||||
|
||||
NS_IMPL_ADDREF(DocumentObserver);
|
||||
NS_IMPL_RELEASE(DocumentObserver);
|
||||
|
||||
jobject peer;
|
||||
JavaVM *vm = NULL;
|
||||
|
||||
DocumentObserver::DocumentObserver(){
|
||||
}
|
||||
|
||||
DocumentObserver::DocumentObserver(JNIEnv *env, jobject obj,
|
||||
jint webShellPtr,
|
||||
jobject doclistener) {
|
||||
env->GetJavaVM(&vm); // save this vm reference away for the callback!
|
||||
peer = env->NewGlobalRef(doclistener);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP DocumentObserver::QueryInterface(REFNSIID aIID, void** aInstance)
|
||||
{
|
||||
if (NULL == aInstance)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*aInstance = NULL;
|
||||
|
||||
|
||||
if (aIID.Equals(kIDocumentLoaderObserverIID)) {
|
||||
*aInstance = (void*) ((nsIDocumentLoaderObserver*)this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
/* nsIDocumentLoaderObserver methods */
|
||||
NS_IMETHODIMP DocumentObserver::OnStartDocumentLoad(nsIDocumentLoader* loader,
|
||||
nsIURI* aURL,
|
||||
const char* aCommand)
|
||||
{
|
||||
printf("DocumentObserver.cpp: OnStartDocumentLoad\n");
|
||||
fireDocumentLoadEvent("startdocumentload");
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP DocumentObserver::OnEndDocumentLoad(nsIDocumentLoader* loader,
|
||||
#ifdef NECKO
|
||||
nsIChannel* channel,
|
||||
nsresult aStatus,
|
||||
#else
|
||||
nsIURI* aURL,
|
||||
PRInt32 aStatus,
|
||||
#endif
|
||||
nsIDocumentLoaderObserver* aObserver) {
|
||||
printf("!!DocumentObserver.cpp: OnEndDocumentLoad\n");
|
||||
fireDocumentLoadEvent("enddocumentload");
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void fireDocumentLoadEvent(char *eventname) {
|
||||
JNIEnv *env = (JNIEnv *) JNU_GetEnv(vm, JNI_VERSION_1_2);
|
||||
|
||||
if (env == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
jclass clazz = env->GetObjectClass(peer);
|
||||
jmethodID mid = env->GetMethodID(clazz, "docEventPerformed", "(Ljava/lang/String;)V");
|
||||
jstring testmsg = env->NewStringUTF(eventname);
|
||||
if ( mid != NULL) {
|
||||
env->CallVoidMethod(peer, mid, testmsg);
|
||||
} else {
|
||||
printf("cannot call the Java Method!\n");
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP DocumentObserver::OnStartURLLoad(nsIDocumentLoader* loader,
|
||||
#ifdef NECKO
|
||||
nsIChannel* channel,
|
||||
#else
|
||||
nsIURI* aURL,
|
||||
const char* aContentType,
|
||||
#endif
|
||||
nsIContentViewer* aViewer) {
|
||||
printf("!DocumentObserver: OnStartURLLoad\n");
|
||||
fireDocumentLoadEvent("startURLload");
|
||||
|
||||
return NS_OK;}
|
||||
|
||||
NS_IMETHODIMP DocumentObserver::OnProgressURLLoad(nsIDocumentLoader* loader,
|
||||
#ifdef NECKO
|
||||
nsIChannel* channel,
|
||||
#else
|
||||
nsIURI* aURL,
|
||||
#endif
|
||||
PRUint32 aProgress,
|
||||
PRUint32 aProgressMax) {
|
||||
printf("!DocumentObserver: OnProgressURLLoad\n");
|
||||
fireDocumentLoadEvent("progressURLload");
|
||||
|
||||
return NS_OK;}
|
||||
|
||||
NS_IMETHODIMP DocumentObserver::OnStatusURLLoad(nsIDocumentLoader* loader,
|
||||
#ifdef NECKO
|
||||
nsIChannel* channel,
|
||||
#else
|
||||
nsIURI* aURL,
|
||||
#endif
|
||||
nsString& aMsg) {
|
||||
printf("!DocumentObserver: OnStatusURLLoad\n");
|
||||
fireDocumentLoadEvent("statusURLload");
|
||||
|
||||
return NS_OK;}
|
||||
NS_IMETHODIMP DocumentObserver::OnEndURLLoad(nsIDocumentLoader* loader,
|
||||
#ifdef NECKO
|
||||
nsIChannel* channel,
|
||||
nsresult aStatus) {
|
||||
printf("!DocumentObserver: OnEndURLLoad\n");
|
||||
fireDocumentLoadEvent("onendURLload");
|
||||
|
||||
return NS_OK;}
|
||||
#else
|
||||
nsIURI* aURL,
|
||||
PRInt32 aStatus) {return NS_OK;}
|
||||
#endif
|
||||
|
||||
NS_IMETHODIMP DocumentObserver::HandleUnknownContentType(nsIDocumentLoader* loader,
|
||||
#ifdef NECKO
|
||||
nsIChannel* channel,
|
||||
#else
|
||||
nsIURI* aURL,
|
||||
#endif
|
||||
const char *aContentType,
|
||||
const char *aCommand) {
|
||||
printf("!DocumentObserver: HandleUnknownContentType\n");
|
||||
fireDocumentLoadEvent("handleunknown content");
|
||||
|
||||
return NS_OK;}
|
||||
|
||||
|
||||
|
99
java/webclient/src/DocumentObserver.h
Normal file
99
java/webclient/src/DocumentObserver.h
Normal file
@ -0,0 +1,99 @@
|
||||
/*
|
||||
The contents of this file are subject to the Mozilla Public License
|
||||
Version 1.0 (the "License"); you may not use this file except in
|
||||
compliance with the License. You may obtain a copy of the License at
|
||||
http://www.mozilla.org/MPL/
|
||||
|
||||
Software distributed under the License is distributed on an "AS IS"
|
||||
basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
||||
the License for the specific language governing rights and limitations
|
||||
under the License.
|
||||
|
||||
The Initial Developer of the Original Code is Sun Microsystems,
|
||||
Inc. Portions created by Sun are Copyright (C) 1999 Sun Microsystems,
|
||||
Inc. All Rights Reserved.
|
||||
*/
|
||||
|
||||
|
||||
#include "nsISupports.h"
|
||||
#include "nsISupportsUtils.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIDocumentLoaderObserver.h"
|
||||
#include "jni.h"
|
||||
|
||||
class nsIURI;
|
||||
|
||||
|
||||
class DocumentObserver : public nsIDocumentLoaderObserver {
|
||||
NS_DECL_ISUPPORTS
|
||||
public:
|
||||
|
||||
DocumentObserver::DocumentObserver(JNIEnv *env, jobject obj,
|
||||
jint webShellPtr,
|
||||
jobject doclistener);
|
||||
|
||||
DocumentObserver::DocumentObserver();
|
||||
|
||||
/* nsIDocumentLoaderObserver methods */
|
||||
NS_IMETHOD OnStartDocumentLoad(nsIDocumentLoader* loader,
|
||||
nsIURI* aURL,
|
||||
const char* aCommand);
|
||||
|
||||
NS_IMETHOD OnEndDocumentLoad(nsIDocumentLoader* loader,
|
||||
#ifdef NECKO
|
||||
nsIChannel* channel,
|
||||
nsresult aStatus,
|
||||
#else
|
||||
nsIURI* aURL,
|
||||
PRInt32 aStatus,
|
||||
#endif
|
||||
nsIDocumentLoaderObserver* aObserver);
|
||||
|
||||
NS_IMETHOD OnStartURLLoad(nsIDocumentLoader* loader,
|
||||
#ifdef NECKO
|
||||
nsIChannel* channel,
|
||||
#else
|
||||
nsIURI* aURL,
|
||||
const char* aContentType,
|
||||
#endif
|
||||
nsIContentViewer* aViewer);
|
||||
|
||||
NS_IMETHOD OnProgressURLLoad(nsIDocumentLoader* loader,
|
||||
#ifdef NECKO
|
||||
nsIChannel* channel,
|
||||
#else
|
||||
nsIURI* aURL,
|
||||
#endif
|
||||
PRUint32 aProgress,
|
||||
PRUint32 aProgressMax);
|
||||
|
||||
NS_IMETHOD OnStatusURLLoad(nsIDocumentLoader* loader,
|
||||
#ifdef NECKO
|
||||
nsIChannel* channel,
|
||||
#else
|
||||
nsIURI* aURL,
|
||||
#endif
|
||||
nsString& aMsg);
|
||||
|
||||
NS_IMETHOD OnEndURLLoad(nsIDocumentLoader* loader,
|
||||
#ifdef NECKO
|
||||
nsIChannel* channel,
|
||||
nsresult aStatus);
|
||||
#else
|
||||
nsIURI* aURL,
|
||||
PRInt32 aStatus);
|
||||
#endif
|
||||
|
||||
NS_IMETHOD HandleUnknownContentType(nsIDocumentLoader* loader,
|
||||
#ifdef NECKO
|
||||
nsIChannel* channel,
|
||||
#else
|
||||
nsIURI* aURL,
|
||||
#endif
|
||||
const char *aContentType,
|
||||
const char *aCommand);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
@ -26,9 +26,13 @@ MODULE=webclient
|
||||
OBJS = \
|
||||
.\$(OBJDIR)\nsActions.obj \
|
||||
.\$(OBJDIR)\BrowserControlMozillaShim.obj \
|
||||
.\$(OBJDIR)\DocumentObserver.obj \
|
||||
.\$(OBJDIR)\jni_util.obj \
|
||||
$(NULL)
|
||||
|
||||
LINCS = \
|
||||
-I$(JDKHOME)\include \
|
||||
-I$(JDKHOME)\include\win32 \
|
||||
$(NULL)
|
||||
|
||||
|
||||
@ -68,6 +72,9 @@ install:: $(DLL)
|
||||
@echo +++ Creating $(MOZ_SRC)\mozilla\java\webclient\src\$(OBJDIR)\runem.bat. Use this to run the test browser.
|
||||
@echo set PATH=$(MOZ_SRC)\mozilla\dist\$(OBJDIR)\bin;$(PATH) > .\$(OBJDIR)\runem.bat
|
||||
@echo $(JAVA) -Djava.library.path=$(MOZ_SRC)\mozilla\dist\$(OBJDIR)\bin -classpath $(JAVAC_CLASSPATH) org.mozilla.webclient.test.EmbeddedMozilla $(MOZ_SRC)\mozilla\dist\$(OBJDIR)\bin %1% >> .\$(OBJDIR)\runem.bat
|
||||
@echo +++ Creating $(MOZ_SRC)\mozilla\java\webclient\src\$(OBJDIR)\swingem.bat. Use this to run the swing based test browser.
|
||||
@echo set PATH=$(MOZ_SRC)\mozilla\dist\$(OBJDIR)\bin;$(PATH) > .\$(OBJDIR)\swingem.bat
|
||||
@echo $(JAVA) -Djava.library.path=$(MOZ_SRC)\mozilla\dist\$(OBJDIR)\bin -classpath $(JAVAC_CLASSPATH) org.mozilla.webclient.test.swing.SwingEmbeddedMozilla $(MOZ_SRC)\mozilla\dist\$(OBJDIR)\bin %1% >> .\$(OBJDIR)\swingem.bat
|
||||
|
||||
clobber_all:: clobber
|
||||
|
||||
@ -75,3 +82,4 @@ clobber::
|
||||
rm -f $(DIST)\bin\$(DLLNAME).dll
|
||||
rm -f BrowserControlMozillaShim.h
|
||||
rm -f .\$(OBJDIR)\runem.bat
|
||||
rm -f .\$(OBJDIR)\swingem.bat
|
||||
|
107
java/webclient/src/jni_util.c
Normal file
107
java/webclient/src/jni_util.c
Normal file
@ -0,0 +1,107 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "jni.h"
|
||||
#include "jni_util.h"
|
||||
|
||||
|
||||
JNIEXPORT jvalue JNICALL
|
||||
JNU_CallMethodByName(JNIEnv *env,
|
||||
jboolean *hasException,
|
||||
jobject obj,
|
||||
const char *name,
|
||||
const char *signature,
|
||||
...)
|
||||
{
|
||||
jvalue result;
|
||||
va_list args;
|
||||
|
||||
va_start(args, signature);
|
||||
result = JNU_CallMethodByNameV(env, hasException, obj, name, signature,
|
||||
args);
|
||||
va_end(args);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
JNIEXPORT jvalue JNICALL
|
||||
JNU_CallMethodByNameV(JNIEnv *env,
|
||||
jboolean *hasException,
|
||||
jobject obj,
|
||||
const char *name,
|
||||
const char *signature,
|
||||
va_list args)
|
||||
{
|
||||
jclass clazz;
|
||||
jmethodID mid;
|
||||
jvalue result;
|
||||
const char *p = signature;
|
||||
printf("jni_util: call method by name if 0");
|
||||
/* find out the return type */
|
||||
while (*p && *p != ')')
|
||||
p++;
|
||||
p++;
|
||||
|
||||
result.i = 0;
|
||||
|
||||
if ((*env)->EnsureLocalCapacity(env, 3) < 0)
|
||||
goto done2;
|
||||
printf("jni_util: call method by name if 1");
|
||||
clazz = (*env)->GetObjectClass(env, obj);
|
||||
printf("jni_util: call method by name 2");
|
||||
mid = (*env)->GetMethodID(env, clazz, name, signature);
|
||||
printf("jni_util: call method by name 3");
|
||||
if (mid == 0)
|
||||
goto done1;
|
||||
printf("jni_util: call method by name if 4");
|
||||
switch (*p) {
|
||||
case 'V':
|
||||
(*env)->CallVoidMethodV(env, obj, mid, args);
|
||||
break;
|
||||
case '[':
|
||||
case 'L':
|
||||
result.l = (*env)->CallObjectMethodV(env, obj, mid, args);
|
||||
break;
|
||||
case 'Z':
|
||||
result.z = (*env)->CallBooleanMethodV(env, obj, mid, args);
|
||||
break;
|
||||
case 'B':
|
||||
result.b = (*env)->CallByteMethodV(env, obj, mid, args);
|
||||
break;
|
||||
case 'C':
|
||||
result.c = (*env)->CallCharMethodV(env, obj, mid, args);
|
||||
break;
|
||||
case 'S':
|
||||
result.s = (*env)->CallShortMethodV(env, obj, mid, args);
|
||||
break;
|
||||
case 'I':
|
||||
result.i = (*env)->CallIntMethodV(env, obj, mid, args);
|
||||
break;
|
||||
case 'J':
|
||||
result.j = (*env)->CallLongMethodV(env, obj, mid, args);
|
||||
break;
|
||||
case 'F':
|
||||
result.f = (*env)->CallFloatMethodV(env, obj, mid, args);
|
||||
break;
|
||||
case 'D':
|
||||
result.d = (*env)->CallDoubleMethodV(env, obj, mid, args);
|
||||
break;
|
||||
default:
|
||||
(*env)->FatalError(env, "JNU_CallMethodByNameV: illegal signature");
|
||||
}
|
||||
done1:
|
||||
(*env)->DeleteLocalRef(env, clazz);
|
||||
done2:
|
||||
if (hasException) {
|
||||
*hasException = (*env)->ExceptionCheck(env);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
JNIEXPORT void * JNICALL
|
||||
JNU_GetEnv(JavaVM *vm, jint version)
|
||||
{
|
||||
void *env;
|
||||
(*vm)->GetEnv(vm, &env, version);
|
||||
return env;
|
||||
}
|
48
java/webclient/src/jni_util.h
Normal file
48
java/webclient/src/jni_util.h
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* @(#)jni_util.h 1.24 98/09/02
|
||||
*
|
||||
* Copyright 1997, 1998 by Sun Microsystems, Inc.,
|
||||
* 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is the confidential and proprietary information
|
||||
* of Sun Microsystems, Inc. ("Confidential Information"). You
|
||||
* shall not disclose such Confidential Information and shall use
|
||||
* it only in accordance with the terms of the license agreement
|
||||
* you entered into with Sun.
|
||||
*/
|
||||
|
||||
#ifndef JNI_UTIL_H
|
||||
#define JNI_UTIL_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/* Invoke an instance method by name.
|
||||
*/
|
||||
JNIEXPORT jvalue JNICALL
|
||||
JNU_CallMethodByName(JNIEnv *env,
|
||||
jboolean *hasException,
|
||||
jobject obj,
|
||||
const char *name,
|
||||
const char *signature,
|
||||
...);
|
||||
|
||||
JNIEXPORT jvalue JNICALL
|
||||
JNU_CallMethodByNameV(JNIEnv *env,
|
||||
jboolean *hasException,
|
||||
jobject obj,
|
||||
const char *name,
|
||||
const char *signature,
|
||||
va_list args);
|
||||
|
||||
JNIEXPORT void * JNICALL
|
||||
JNU_GetEnv(JavaVM *vm, jint version);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* JNI_UTIL_H */
|
@ -73,6 +73,7 @@ jint (* nativeWebShellGetHistoryIndex) (JNIEnv *, jobject, jint);
|
||||
jstring (* nativeWebShellGetURL) (JNIEnv *, jobject, jint, jint);
|
||||
// added by Mark Goddard OTMP 9/2/1999
|
||||
jboolean (* nativeWebShellRefresh)(JNIEnv *, jobject, jint);
|
||||
jboolean (* nativeWebShellAddDocListener) (JNIEnv *, jobject, jint, jobject);
|
||||
void (* processNativeEventQueue) (JNIEnv *, jobject, jint);
|
||||
|
||||
|
||||
@ -220,6 +221,12 @@ void locateBrowserControlStubFunctions(void * dll) {
|
||||
printf("got dlsym error %s\n", dlerror());
|
||||
}
|
||||
|
||||
nativeWebShellAddDocListener = (jboolean (*) (JNIEnv *, jobject, jint, jobject)) dlsym(dll, "Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeWebShellAddDocListener");
|
||||
if (!nativeWebShellAddDocListener) {
|
||||
printf("got dlsym error %s\n", dlerror());
|
||||
}
|
||||
|
||||
|
||||
processNativeEventQueue = (void (*) (JNIEnv *, jobject, jint)) dlsym(dll, "Java_org_mozilla_webclient_motif_MozillaEventThread_processNativeEventQueue");
|
||||
if (!processNativeEventQueue) {
|
||||
printf("got dlsym error %s\n", dlerror());
|
||||
@ -818,4 +825,20 @@ Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeWebShellRefresh (
|
||||
} // Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeWebShellRefresh()
|
||||
|
||||
|
||||
/*
|
||||
* Class: BrowserControlMozillaShimStub
|
||||
* Method: nativeWebShellAddDocListener
|
||||
* Signature: (I)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeWebShellAddDocListener (
|
||||
JNIEnv * env,
|
||||
jobject obj,
|
||||
jint webShellPtr,
|
||||
jobject listener)
|
||||
{
|
||||
return (* nativeWebShellAddDocListener) (env, obj, webShellPtr, listener);
|
||||
} // Java_org_mozilla_webclient_BrowserControlMozillaShim_nativeWebShellAddDocListener()
|
||||
|
||||
|
||||
// EOF
|
||||
|
Loading…
Reference in New Issue
Block a user