Bug 201275 [Webclient] move Prompt code from CBrowserContainer to PromptService

r=edburns
This commit is contained in:
kyle.yuan%sun.com 2003-05-06 01:50:06 +00:00
Родитель 19944bccd6
Коммит 74a6ecd06e
17 изменённых файлов: 686 добавлений и 1312 удалений

Просмотреть файл

@ -44,6 +44,7 @@ public static final String EDIT_FIELD_1_KEY = "editfield1Value";
public static final String EDIT_FIELD_2_KEY = "editfield2Value";
public static final String CHECKBOX_STATE_KEY = "checkboxState";
public static final String BUTTON_PRESSED_KEY = "buttonPressed";
public static final String FINISHED_KEY = "finished";
/**

Просмотреть файл

@ -59,7 +59,7 @@ import java.io.FileInputStream;
* This is a test application for using the BrowserControl.
*
* @version $Id: EMWindow.java,v 1.40 2003-04-24 05:55:07 kyle.yuan%sun.com Exp $
* @version $Id: EMWindow.java,v 1.41 2003-05-06 01:49:57 kyle.yuan%sun.com Exp $
*
* @see org.mozilla.webclient.BrowserControlFactory
@ -86,6 +86,7 @@ public class EMWindow extends Frame implements DialogClient, ActionListener, Doc
private Panel controlPanel;
private Panel statusPanel;
private Panel buttonsPanel;
private UniversalDialogData dlgData = null;
private FindDialog findDialog = null;
private PasswordDialog passDialog = null;
private UniversalDialog uniDialog = null;
@ -309,6 +310,9 @@ private void createMenubar()
menuBar.add(fileMenu);
Menu viewMenu = new Menu("View");
MenuItem pageSourceItem = new MenuItem("View Page Source");
viewMenu.add(pageSourceItem);
pageSourceItem.addActionListener(this);
MenuItem sourceItem = new MenuItem("View Page Source as String");
viewMenu.add(sourceItem);
sourceItem.addActionListener(this);
@ -465,6 +469,9 @@ public void actionPerformed (ActionEvent evt)
else if (command.equals("New Window2")) {
creator.CreateEMWindow("", chromeFlag);
}
else if (command.equals("Dialog")) {
execUniversalDialog();
}
else if (command.equals("Close")) {
System.out.println("Got windowClosing");
System.out.println("destroying the BrowserControl");
@ -494,6 +501,12 @@ public void actionPerformed (ActionEvent evt)
else if (command.equals("Find Next")) {
currentPage.findNextInPage();
}
else if (command.equals("View Page Source")) {
creator.CreateEMWindow("view-source:" + urlField.getText(),
NewWindowListener.CHROME_WINDOW_BORDERS |
NewWindowListener.CHROME_TITLEBAR |
NewWindowListener.CHROME_WINDOW_RESIZE);
}
else if (command.equals("View Page Source as String")) {
String sou = currentPage.getSource();
System.out.println("+++++++++++ Page Source is +++++++++++\n\n" + sou);
@ -611,9 +624,15 @@ public void actionPerformed (ActionEvent evt)
public void dialogDismissed(Dialog d) {
if (d == passDialog || d == uniDialog) {
return;
}
System.out.println("dialogDismissed");
if (d == passDialog) {
return;
}
if (d == uniDialog) {
dlgData.mProps.put(Prompt.FINISHED_KEY, "true");
uniDialog = null;
return;
}
if(findDialog.wasClosed()) {
System.out.println("Find Dialog Closed");
}
@ -650,7 +669,7 @@ public void dialogDismissed(Dialog d) {
}
public void dialogCancelled(Dialog d) {
System.out.println("Find Dialog Closed");
System.out.println("dialogCancelled");
}
@ -705,24 +724,35 @@ public void eventDispatched(WebclientEvent event)
if (event instanceof DocumentLoadEvent) {
switch ((int) event.getType()) {
case ((int) DocumentLoadEvent.START_DOCUMENT_LOAD_EVENT_MASK):
stopButton.setEnabled(true);
refreshButton.setEnabled(true);
if (null != stopButton)
stopButton.setEnabled(true);
if (null != refreshButton)
refreshButton.setEnabled(true);
currentURL = (String) event.getEventData();
System.out.println("debug: edburns: Currently Viewing: " +
currentURL);
statusLabel.setText("Starting to load " + currentURL);
urlField.setText(currentURL);
if (null != statusLabel && null != urlField) {
statusLabel.setText("Starting to load " + currentURL);
urlField.setText(currentURL);
}
currentDocument = null;
break;
case ((int) DocumentLoadEvent.END_DOCUMENT_LOAD_EVENT_MASK):
stopButton.setEnabled(false);
backButton.setEnabled(history.canBack());
backMenuItem.setEnabled(history.canBack());
forwardButton.setEnabled(history.canForward());
forwardMenuItem.setEnabled(history.canForward());
if (null != stopButton)
stopButton.setEnabled(false);
if (null != backButton)
backButton.setEnabled(history.canBack());
if (null != backMenuItem)
backMenuItem.setEnabled(history.canBack());
if (null != forwardButton)
forwardButton.setEnabled(history.canForward());
if (null != forwardMenuItem)
forwardMenuItem.setEnabled(history.canForward());
populateHistoryMenu();
statusLabel.setText("Done.");
urlStatusLabel.setText("");
if (null != statusLabel && null != urlField) {
statusLabel.setText("Done.");
urlStatusLabel.setText("");
}
currentDocument = currentPage.getDOM();
// add the new document to the domViewer
if (null != currentDocument && null != domViewer) {
@ -732,19 +762,23 @@ public void eventDispatched(WebclientEvent event)
break;
case ((int) DocumentLoadEvent.PROGRESS_URL_LOAD_EVENT_MASK):
status = "Status: " + (String) event.getEventData();
statusLabel.setText(status);
if (null != statusLabel)
statusLabel.setText(status);
break;
case ((int) DocumentLoadEvent.STATUS_URL_LOAD_EVENT_MASK):
status = "Status: " + (String) event.getEventData();
statusLabel.setText(status);
if (null != statusLabel)
statusLabel.setText(status);
break;
case ((int) DocumentLoadEvent.START_URL_LOAD_EVENT_MASK):
status = (String) event.getEventData();
urlStatusLabel.setText("startURL: " + status);
if (null != urlStatusLabel)
urlStatusLabel.setText("startURL: " + status);
break;
case ((int) DocumentLoadEvent.END_URL_LOAD_EVENT_MASK):
status = (String) event.getEventData();
urlStatusLabel.setText(" endURL: " + status);
if (null != urlStatusLabel)
urlStatusLabel.setText(" endURL: " + status);
break;
}
}
@ -924,43 +958,35 @@ public boolean universalDialog(String titleMessage,
boolean editfield1Password,
Properties fillThis)
{
System.out.println("titleMessage " + titleMessage);
System.out.println("dialogTitle " + dialogTitle);
System.out.println("text " + text);
System.out.println("checkboxMsg " + checkboxMsg);
System.out.println("button0Text " + button0Text);
System.out.println("button1Text " + button1Text);
System.out.println("button2Text " + button2Text);
System.out.println("button3Text " + button3Text);
System.out.println("editfield1Msg " + editfield1Msg);
System.out.println("editfield2Msg " + editfield2Msg);
System.out.println("numButtons " + numButtons);
System.out.println("numEditfields " + numEditfields);
System.out.println("editfield1Password " + editfield1Password);
fillThis.put("editfield1Value", "edit1");
fillThis.put("editfield2Value", "edit2");
fillThis.put("checkboxState", "true");
if (null == fillThis) {
return false;
if (dialogTitle.equals("")) {
dialogTitle = "Universal Dialog";
}
dlgData = new UniversalDialogData(titleMessage, dialogTitle, text, checkboxMsg,
button0Text, button1Text, button2Text,
editfield1Msg, editfield2Msg,
numButtons, numEditfields, editfield1Password, fillThis);
// send a "new window" event to the window
Toolkit.getDefaultToolkit().
getSystemEventQueue().
postEvent(new ActionEvent(newItem,
ActionEvent.ACTION_PERFORMED,
"Dialog"));
return true;
}
public boolean execUniversalDialog()
{
if (null == uniDialog) {
if (dialogTitle.equals("")) {
dialogTitle = "Universal Dialog";
}
uniDialog = new UniversalDialog(this, this, dialogTitle);
uniDialog = new UniversalDialog(this, this, dlgData.mDialogTitle);
if (null == uniDialog) {
return false;
}
uniDialog.setParms(titleMessage, dialogTitle, text, checkboxMsg,
button0Text, button1Text, button2Text,
editfield1Msg, editfield2Msg, numButtons,
numEditfields, editfield1Password, fillThis);
uniDialog.setParms(dlgData);
uniDialog.setModal(true);
uniDialog.setVisible(true);
}
uniDialog.setVisible(true);
return true;
}

Просмотреть файл

@ -1,6 +1,6 @@
/** Ashu -- this is the Find Dialog Class
/** Ashu -- this is the Find Dialog Class
instantiated within the EMWindow class, this
will act as the Modal dialog for calling Find/Find Next
will act as the Modal dialog for calling Find/Find Next
functions for CurrentPage
*/
@ -18,200 +18,189 @@ import java.util.Properties;
public class UniversalDialog extends WorkDialog implements ActionListener, ItemListener
{
static private int _defaultTextFieldSize = 20;
public Button [] buttons;
public TextField [] fields;
static private int _defaultTextFieldSize = 20;
public Button [] buttons;
public TextField [] fields;
public String mTitleMsg;
public String mText;
public String mCheckboxMsg;
public UniversalDialogData mData;
public Checkbox mCheckbox;
public String mField1Label;
public String mField2Label;
public boolean mField1IsPasswd;
public Properties mProps;
public UniversalDialog(Frame frame, DialogClient client, String dialogTitle)
public UniversalDialog(Frame frame, DialogClient client, String dialogTitle)
{
super(frame, client, dialogTitle, /* isModal */ true);
}
public void setParms(String titleMsg,
String dialogTitle, String text, String checkboxMsg,
String button0Text, String button1Text,
String button2Text, String editfield1Msg,
String editfield2Msg,
int numButtons, int numEditfields,
boolean editfield1Password,
Properties props)
public void setParms(UniversalDialogData data)
{
DialogPanel dialogPanel;
int i = 0;
buttons = null;
fields = null;
mTitleMsg = titleMsg;
this.setTitle(dialogTitle);
mText = text;
mCheckboxMsg = checkboxMsg;
mField1Label = editfield1Msg;
mField2Label = editfield2Msg;
mField1IsPasswd = editfield1Password;
mProps = props;
mData = data;
if (0 < numButtons) {
buttons = new Button[numButtons];
String label;
for (i = 0; i < numButtons; i++) {
// figure out which String to use;
if (0 == i) {
label = button0Text;
}
else if (1 == i) {
label = button1Text;
}
else {
label = button2Text;
}
buttons[i] = addButton(label);
buttons[i].addActionListener(this);
}
this.setTitle(mData.mDialogTitle);
if (0 < mData.mNumButtons) {
buttons = new Button[mData.mNumButtons];
String label;
for (i = 0; i < mData.mNumButtons; i++) {
// figure out which String to use;
if (0 == i) {
label = mData.mButtonText0;
}
else if (1 == i) {
label = mData.mButtonText1;
}
else {
label = mData.mButtonText2;
}
buttons[i] = addButton(label);
buttons[i].addActionListener(this);
}
}
if (0 < numEditfields) {
fields = new TextField[numEditfields];
for (i = 0; i < numEditfields; i++) {
fields[i] = new TextField("", _defaultTextFieldSize);
if (mField1IsPasswd && i == 0) {
fields[i].setEchoChar('*');
}
}
if (0 < mData.mNumEditfields) {
String defaultString;
fields = new TextField[mData.mNumEditfields];
for (i = 0; i < mData.mNumEditfields; i++) {
fields[i] = new TextField("", _defaultTextFieldSize);
if (i == 0)
defaultString = mData.mProps.getProperty(Prompt.EDIT_FIELD_1_KEY);
else
defaultString = mData.mProps.getProperty(Prompt.EDIT_FIELD_2_KEY);
fields[i].setText(defaultString);
if (mData.mField1IsPasswd && i == 0) {
fields[i].setEchoChar('*');
}
}
}
dialogPanel = new DialogPanel(this);
setWorkPanel(dialogPanel);
}
public void actionPerformed(ActionEvent ae)
public void actionPerformed(ActionEvent ae)
{
Assert.assert_it(null != buttons);
int i = 0;
for (i = 0; i < buttons.length; i++) {
if (ae.getSource() == buttons[i]) {
mProps.put(Prompt.BUTTON_PRESSED_KEY, Integer.toString(i));
// pull out the values from the TextFields
break;
}
if (ae.getSource() == buttons[i]) {
mData.mProps.put(Prompt.BUTTON_PRESSED_KEY, Integer.toString(i));
// pull out the values from the TextFields
break;
}
}
if (null != fields) {
String curString;
for (i = 0; i < fields.length; i++) {
curString = fields[i].getText();
if (0 == i) {
mProps.put(Prompt.EDIT_FIELD_1_KEY, curString);
}
else {
mProps.put(Prompt.EDIT_FIELD_2_KEY, curString);
}
}
String curString;
for (i = 0; i < fields.length; i++) {
curString = fields[i].getText();
if (0 == i) {
mData.mProps.put(Prompt.EDIT_FIELD_1_KEY, curString);
}
else {
mData.mProps.put(Prompt.EDIT_FIELD_2_KEY, curString);
}
}
}
if (null != mCheckbox) {
Boolean bool = new Boolean(mCheckbox.getState());
mProps.put(Prompt.CHECKBOX_STATE_KEY, bool.toString());
Boolean bool = new Boolean(mCheckbox.getState());
mData.mProps.put(Prompt.CHECKBOX_STATE_KEY, bool.toString());
}
dispose(true);
}
public void itemStateChanged(ItemEvent e)
public void itemStateChanged(ItemEvent e)
{
}
public void setVisible(boolean b)
public void setVisible(boolean b)
{
if (null != fields) {
fields[0].requestFocus();
fields[0].requestFocus();
}
super.setVisible(b);
}
}
class DialogPanel extends Postcard
class DialogPanel extends Postcard
{
private UniversalDialog dialog;
public DialogPanel(UniversalDialog myDialog)
public DialogPanel(UniversalDialog myDialog)
{
super(new Panel());
Panel panel = getPanel();
panel.setLayout(new BorderLayout());
this.dialog = myDialog;
int i = 0;
if (null != dialog.mTitleMsg || null != dialog.mText) {
Panel northPanel = new Panel();
northPanel.setLayout(new BorderLayout());
// set up the stuff on top of the text fields
if (null != dialog.mTitleMsg) {
Label titleLabel = new Label(dialog.mTitleMsg);
titleLabel.setBackground(Color.lightGray);
northPanel.add(titleLabel, BorderLayout.NORTH);
}
if (null != dialog.mText) {
Label textLabel = new Label(dialog.mText);
textLabel.setBackground(Color.lightGray);
northPanel.add(textLabel, BorderLayout.CENTER);
}
panel.add(northPanel, BorderLayout.NORTH);
//System.out.println(dialog.mData.mTitleMsg);
if (null != dialog.mData.mTitleMsg || null != dialog.mData.mText) {
Panel northPanel = new Panel();
northPanel.setLayout(new BorderLayout());
// set up the stuff on top of the text fields
if (null != dialog.mData.mTitleMsg) {
Label titleLabel = new Label(dialog.mData.mTitleMsg);
titleLabel.setBackground(Color.lightGray);
northPanel.add(titleLabel, BorderLayout.NORTH);
}
if (null != dialog.mData.mText) {
Label textLabel = new Label(dialog.mData.mText);
textLabel.setBackground(Color.lightGray);
northPanel.add(textLabel, BorderLayout.CENTER);
}
panel.add(northPanel, BorderLayout.NORTH);
}
Panel centerPanel = new Panel();
centerPanel.setLayout(new BorderLayout());
if (null != dialog.fields) {
Panel fieldPanel = new Panel();
fieldPanel.setLayout(new BorderLayout());
// set up the text fields
Panel curPanel;
Label curLabel;
for (i = 0; i < dialog.fields.length; i++) {
// set up the label and field
curPanel = new Panel();
curPanel.setLayout(new BorderLayout());
if (0 == i) {
curLabel = new Label(dialog.mField1Label);
}
else {
curLabel = new Label(dialog.mField2Label);
}
curLabel.setBackground(Color.lightGray);
curPanel.add(curLabel, BorderLayout.WEST);
curPanel.add(dialog.fields[i], BorderLayout.CENTER);
if (0 == i) {
fieldPanel.add(curPanel, BorderLayout.NORTH);
}
else {
fieldPanel.add(curPanel, BorderLayout.CENTER);
}
}
centerPanel.add(fieldPanel, BorderLayout.NORTH);
if (null != dialog.fields) {
Panel fieldPanel = new Panel();
fieldPanel.setLayout(new BorderLayout());
// set up the text fields
Panel curPanel;
Label curLabel;
for (i = 0; i < dialog.fields.length; i++) {
// set up the label and field
curPanel = new Panel();
curPanel.setLayout(new BorderLayout());
if (0 == i) {
curLabel = new Label(dialog.mData.mField1Label);
}
else {
curLabel = new Label(dialog.mData.mField2Label);
}
curLabel.setBackground(Color.lightGray);
curPanel.add(curLabel, BorderLayout.WEST);
curPanel.add(dialog.fields[i], BorderLayout.CENTER);
if (0 == i) {
fieldPanel.add(curPanel, BorderLayout.NORTH);
}
else {
fieldPanel.add(curPanel, BorderLayout.CENTER);
}
}
centerPanel.add(fieldPanel, BorderLayout.NORTH);
}
if (null != dialog.mCheckboxMsg) {
dialog.mCheckbox = new Checkbox(dialog.mCheckboxMsg);
dialog.mCheckbox.setBackground(Color.lightGray);
centerPanel.add(dialog.mCheckbox, BorderLayout.CENTER);
if (null != dialog.mData.mCheckboxMsg && dialog.mData.mCheckboxMsg.length() > 0) {
dialog.mCheckbox = new Checkbox(dialog.mData.mCheckboxMsg);
dialog.mCheckbox.setBackground(Color.lightGray);
centerPanel.add(dialog.mCheckbox, BorderLayout.CENTER);
}
// add the center panel to the main panel
panel.add(centerPanel, BorderLayout.CENTER);
}
}

Просмотреть файл

Просмотреть файл

Просмотреть файл

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -16,7 +16,7 @@
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
*
* Contributor(s): Ashutosh Kulkarni <ashuk@eng.sun.com>
* Ed Burns <edburns@acm.org>
*
@ -40,8 +40,7 @@
#include "nsIURIContentListener.h"
#include "nsIDocShellTreeOwner.h"
#include "nsIInterfaceRequestor.h"
#include "nsIPrompt.h"
#include "nsIAuthPrompt.h"
#include "nsIEmbeddingSiteWindow.h"
#include "nsCWebBrowser.h"
#include "nsWeakReference.h"
@ -55,16 +54,13 @@ class nsIURI;
// interfaces into the web shell and so forth.
class CBrowserContainer :
public nsIBaseWindow,
public nsIWebBrowserChrome,
public nsIWebProgressListener,
public nsIWebShellContainer,
public nsIURIContentListener,
public nsIDocShellTreeOwner,
public nsIInterfaceRequestor,
public nsIPrompt,
public nsIAuthPrompt,
public nsIDOMMouseListener,
public nsIWebBrowserChrome,
public nsIEmbeddingSiteWindow,
public nsIWebProgressListener,
public nsIWebShellContainer,
public nsIURIContentListener,
public nsIInterfaceRequestor,
public nsIDOMMouseListener,
public wcIBrowserContainer,
public nsSupportsWeakReference
{
@ -94,7 +90,7 @@ protected:
//
// The following arguments are used in the takeActionOnNode method.
//
/**
* 0 is the leaf depth. That's why we call it the inverse depth.
@ -125,39 +121,34 @@ protected:
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIBASEWINDOW
NS_DECL_NSIWEBBROWSERCHROME
NS_DECL_NSIDOCSHELLTREEOWNER
NS_DECL_NSIURICONTENTLISTENER
NS_DECL_NSIINTERFACEREQUESTOR
NS_DECL_NSIWEBPROGRESSLISTENER
NS_DECL_ISUPPORTS
NS_DECL_NSIWEBBROWSERCHROME
NS_DECL_NSIEMBEDDINGSITEWINDOW
NS_DECL_NSIURICONTENTLISTENER
NS_DECL_NSIINTERFACEREQUESTOR
NS_DECL_NSIWEBPROGRESSLISTENER
NS_DECL_WCIBROWSERCONTAINER
NS_DECL_WCIBROWSERCONTAINER
// "Services" accessed through nsIInterfaceRequestor
NS_DECL_NSIPROMPT
NS_DECL_NSIAUTHPROMPT
// nsIDOMMouseListener
// nsIDOMMouseListener
NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent);
NS_IMETHOD MouseDown(nsIDOMEvent* aMouseEvent);
NS_IMETHOD MouseUp(nsIDOMEvent* aMouseEvent);
NS_IMETHOD MouseClick(nsIDOMEvent* aMouseEvent);
NS_IMETHOD MouseDblClick(nsIDOMEvent* aMouseEvent);
NS_IMETHOD MouseOver(nsIDOMEvent* aMouseEvent);
NS_IMETHOD MouseOut(nsIDOMEvent* aMouseEvent);
NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent);
NS_IMETHOD MouseDown(nsIDOMEvent* aMouseEvent);
NS_IMETHOD MouseUp(nsIDOMEvent* aMouseEvent);
NS_IMETHOD MouseClick(nsIDOMEvent* aMouseEvent);
NS_IMETHOD MouseDblClick(nsIDOMEvent* aMouseEvent);
NS_IMETHOD MouseOver(nsIDOMEvent* aMouseEvent);
NS_IMETHOD MouseOut(nsIDOMEvent* aMouseEvent);
// nsIWebShellContainer
NS_IMETHOD WillLoadURL(nsIWebShell* aShell,
const PRUnichar* aURL,
nsLoadType aReason);
NS_IMETHOD BeginLoadURL(nsIWebShell* aShell,
const PRUnichar* aURL);
NS_IMETHOD EndLoadURL(nsIWebShell* aShell,
const PRUnichar* aURL,
nsresult aStatus);
@ -174,16 +165,17 @@ void JNICALL addMouseEventDataToProperties(nsIDOMEvent *aMouseEvent);
* Called from our nsIWebProgressListener.OnStateChanged()
*/
*/
nsresult JNICALL doStartDocumentLoad(const PRUnichar *documentName);
nsresult JNICALL doEndDocumentLoad(nsIWebProgress *aWebProgress);
nsresult JNICALL doStartURLLoad(const PRUnichar *documentName);
nsresult JNICALL doEndURLLoad(const PRUnichar *documentName);
static nsresult JNICALL takeActionOnNode(nsCOMPtr<nsIDOMNode> curNode,
static nsresult JNICALL takeActionOnNode(nsCOMPtr<nsIDOMNode> curNode,
void *yourObject);
friend class PromptService;
};
#endif

Просмотреть файл

@ -114,6 +114,8 @@ CPPSRCS = \
PreferencesActionEvents.cpp \
WrapperFactoryImpl.cpp \
WindowCreator.cpp \
PromptService.cpp \
AppComponents.cpp \
$(NULL)
ifeq ($(OS_ARCH),Linux)

Просмотреть файл

@ -1,5 +1,5 @@
/* -*- 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.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
@ -65,6 +65,7 @@
#include "nsIWindowWatcher.h"
#include "nsIComponentRegistrar.h"
#include "WindowCreator.h"
#include "AppComponents.h"
#include "prlog.h" // for PR_ASSERT
@ -74,7 +75,7 @@
#include "gtkmozarea.h"
extern "C" {
static int wc_x_error (Display *display,
static int wc_x_error (Display *display,
XErrorEvent *error);
}
@ -125,23 +126,23 @@ extern const char * gBinDir; // defined in WrapperFactoryImpl.cpp
#ifdef XP_UNIX
static int
wc_x_error (Display *display,
wc_x_error (Display *display,
XErrorEvent *error)
{
if (error->error_code)
{
char buf[64];
XGetErrorText (display, error->error_code, buf, 63);
fprintf (stderr, "Webclient-Gdk-ERROR **: %s\n serial %ld error_code %d request_code %d minor_code %d\n",
buf,
error->serial,
error->error_code,
buf,
error->serial,
error->error_code,
error->request_code,
error->minor_code);
}
return 0;
}
#endif
@ -156,7 +157,7 @@ int processEventLoop(WebShellInitContext * initContext);
/**
* Called from Java nativeInitialize to create the webshell
* Called from Java nativeInitialize to create the webshell
* and other mozilla things, then start the event loop.
*/
@ -168,18 +169,18 @@ nsresult InitMozillaStuff (WebShellInitContext * arg);
//
nsIComponentManager *gComponentManager = nsnull;
static PRBool gFirstTime = PR_TRUE;
PLEventQueue * gActionQueue = nsnull;
PRThread * gEmbeddedThread = nsnull;
static PRBool gFirstTime = PR_TRUE;
PLEventQueue * gActionQueue = nsnull;
PRThread * gEmbeddedThread = nsnull;
nsISHistory *gHistory = nsnull;
WindowCreator * gCreatorCallback = nsnull;
char * errorMessages[] = {
"No Error",
"Could not obtain the event queue service.",
"Unable to create the WebShell instance.",
"Unable to initialize the WebShell instance.",
"Unable to show the WebShell."
"No Error",
"Could not obtain the event queue service.",
"Unable to create the WebShell instance.",
"Unable to initialize the WebShell instance.",
"Unable to show the WebShell."
};
//
@ -193,7 +194,7 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_NativeEventThr
WebShellInitContext * initContext = (WebShellInitContext *) webShellPtr;
if (nsnull == initContext) {
::util_ThrowExceptionToJava(env,
::util_ThrowExceptionToJava(env,
"NULL webShellPtr passed to nativeInitialize.");
return;
}
@ -203,15 +204,15 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_NativeEventThr
rv = InitMozillaStuff(initContext);
if (NS_FAILED(rv)) {
::util_ThrowExceptionToJava(env,
::util_ThrowExceptionToJava(env,
errorMessages[initContext->initFailCode]);
return;
}
while (initContext->initComplete == FALSE) {
::PR_Sleep(PR_INTERVAL_NO_WAIT);
if (initContext->initFailCode != 0) {
::util_ThrowExceptionToJava(env, errorMessages[initContext->initFailCode]);
return;
@ -223,9 +224,9 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_NativeEventThr
(JNIEnv *env, jobject obj, jint webShellPtr)
{
WebShellInitContext * initContext = (WebShellInitContext *) webShellPtr;
if (nsnull == initContext) {
::util_ThrowExceptionToJava(env,
::util_ThrowExceptionToJava(env,
"NULL webShellPtr passed to nativeProcessEvents.");
return;
}
@ -257,11 +258,11 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_NativeEventThr
*/
JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_NativeEventThread_nativeAddListener
(JNIEnv *env, jobject obj, jint webShellPtr, jobject typedListener,
(JNIEnv *env, jobject obj, jint webShellPtr, jobject typedListener,
jstring listenerString)
{
WebShellInitContext *initContext = (WebShellInitContext *)webShellPtr;
if (initContext == nsnull) {
::util_ThrowExceptionToJava(env, "Exception: null initContext passed tonativeAddListener");
return;
@ -269,23 +270,23 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_NativeEventThr
if (nsnull == initContext->nativeEventThread) {
// store the java EventRegistrationImpl class in the initContext
initContext->nativeEventThread =
initContext->nativeEventThread =
::util_NewGlobalRef(env, obj); // VERY IMPORTANT!!
// This enables the listener to call back into java
}
jclass clazz = nsnull;
int listenerType = 0;
const char *listenerStringChars = ::util_GetStringUTFChars(env,
const char *listenerStringChars = ::util_GetStringUTFChars(env,
listenerString);
if (listenerStringChars == nsnull) {
::util_ThrowExceptionToJava(env, "Exception: nativeAddListener: Can't get className for listener.");
return;
}
while (nsnull != gSupportedListenerInterfaces[listenerType]) {
if (0 == nsCRT::strcmp(gSupportedListenerInterfaces[listenerType],
if (0 == nsCRT::strcmp(gSupportedListenerInterfaces[listenerType],
listenerStringChars)) {
// We've got a winner!
break;
@ -294,7 +295,7 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_NativeEventThr
}
::util_ReleaseStringUTFChars(env, listenerString, listenerStringChars);
listenerStringChars = nsnull;
if (LISTENER_NOT_FOUND == (LISTENER_CLASSES) listenerType) {
::util_ThrowExceptionToJava(env, "Exception: NativeEventThread.nativeAddListener(): can't find listener \n\tclass for argument");
return;
@ -311,21 +312,21 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_NativeEventThr
switch(listenerType) {
case DOCUMENT_LOAD_LISTENER:
initContext->browserContainer->AddDocumentLoadListener(globalRef);
initContext->browserContainer->AddDocumentLoadListener(globalRef);
break;
case MOUSE_LISTENER:
initContext->browserContainer->AddMouseListener(globalRef);
initContext->browserContainer->AddMouseListener(globalRef);
break;
case NEW_WINDOW_LISTENER:
if (gCreatorCallback)
gCreatorCallback->AddNewWindowListener(globalRef);
gCreatorCallback->AddNewWindowListener(globalRef);
break;
}
return;
}
JNIEXPORT void JNICALL
JNIEXPORT void JNICALL
Java_org_mozilla_webclient_wrapper_1native_NativeEventThread_nativeRemoveListener
(JNIEnv *env, jobject obj, jint webShellPtr, jobject typedListener,
jstring listenerString)
@ -336,18 +337,18 @@ Java_org_mozilla_webclient_wrapper_1native_NativeEventThread_nativeRemoveListene
::util_ThrowExceptionToJava(env, "Exception: null initContext passed to nativeRemoveListener");
return;
}
jclass clazz = nsnull;
int listenerType = 0;
const char *listenerStringChars = ::util_GetStringUTFChars(env,
const char *listenerStringChars = ::util_GetStringUTFChars(env,
listenerString);
if (listenerStringChars == nsnull) {
::util_ThrowExceptionToJava(env, "Exception: nativeRemoveListener: Can't get className for listener.");
return;
}
while (nsnull != gSupportedListenerInterfaces[listenerType]) {
if (0 == nsCRT::strcmp(gSupportedListenerInterfaces[listenerType],
if (0 == nsCRT::strcmp(gSupportedListenerInterfaces[listenerType],
listenerStringChars)) {
// We've got a winner!
break;
@ -356,25 +357,25 @@ Java_org_mozilla_webclient_wrapper_1native_NativeEventThread_nativeRemoveListene
}
::util_ReleaseStringUTFChars(env, listenerString, listenerStringChars);
listenerStringChars = nsnull;
if (LISTENER_NOT_FOUND == (LISTENER_CLASSES) listenerType) {
::util_ThrowExceptionToJava(env, "Exception: NativeEventThread.nativeRemoveListener(): can't find listener \n\tclass for argument");
return;
}
PR_ASSERT(initContext->browserContainer);
switch(listenerType) {
case DOCUMENT_LOAD_LISTENER:
initContext->browserContainer->RemoveDocumentLoadListener();
initContext->browserContainer->RemoveDocumentLoadListener();
break;
case MOUSE_LISTENER:
initContext->browserContainer->RemoveMouseListener();
initContext->browserContainer->RemoveMouseListener();
break;
}
}
JNIEXPORT void JNICALL
JNIEXPORT void JNICALL
Java_org_mozilla_webclient_wrapper_1native_NativeEventThread_nativeRemoveAllListeners(JNIEnv *env, jobject obj, jint webShellPtr)
{
WebShellInitContext *initContext = (WebShellInitContext *)webShellPtr;
@ -398,7 +399,7 @@ Java_org_mozilla_webclient_wrapper_1native_NativeEventThread_nativeRemoveAllList
*/
int processEventLoop(WebShellInitContext * initContext)
int processEventLoop(WebShellInitContext * initContext)
{
#ifdef XP_UNIX
while(gtk_events_pending()) {
@ -408,7 +409,7 @@ int processEventLoop(WebShellInitContext * initContext)
// PENDING(mark): Does this work on the Mac?
MSG msg;
PRBool wasHandled;
if (::PeekMessage(&msg, nsnull, 0, 0, PM_NOREMOVE)) {
if (::GetMessage(&msg, nsnull, 0, 0)) {
wasHandled = PR_FALSE;
@ -421,10 +422,10 @@ int processEventLoop(WebShellInitContext * initContext)
}
#endif
::PR_Sleep(PR_INTERVAL_NO_WAIT);
if ((initContext->initComplete) && (gActionQueue)) {
PLEvent * event = nsnull;
PL_ENTER_EVENT_QUEUE_MONITOR(gActionQueue);
if (::PL_EventAvailable(gActionQueue)) {
event = ::PL_GetEvent(gActionQueue);
@ -436,7 +437,7 @@ int processEventLoop(WebShellInitContext * initContext)
}
if (initContext->stopThread) {
initContext->stopThread++;
return 0;
}
@ -470,6 +471,34 @@ static void event_processor_callback(gpointer data,
//
nsresult OverrideComponents()
{
nsresult rv = NS_OK;
nsCOMPtr<nsIComponentRegistrar> cr;
NS_GetComponentRegistrar(getter_AddRefs(cr));
if (!cr)
return NS_ERROR_FAILURE;
int numComponents;
const nsModuleComponentInfo* componentInfo = GetAppModuleComponentInfo(&numComponents);
for (int i = 0; i < numComponents; ++i) {
nsCOMPtr<nsIGenericFactory> componentFactory;
rv = NS_NewGenericFactory(getter_AddRefs(componentFactory), &(componentInfo[i]));
if (NS_FAILED(rv)) {
NS_ASSERTION(PR_FALSE, "Unable to create factory for component");
continue;
}
rv = cr->RegisterFactory(componentInfo[i].mCID,
componentInfo[i].mDescription,
componentInfo[i].mContractID,
componentFactory);
NS_ASSERTION(NS_SUCCEEDED(rv), "Unable to register factory for component");
}
return rv;
}
/* InitializeWindowCreator creates and hands off an object with a callback
to a window creation function. This is how all new windows are opened,
except any created directly by the embedding app. */
@ -494,11 +523,11 @@ nsresult InitializeWindowCreator(WebShellInitContext * initContext)
}
void DoMozInitialization(WebShellInitContext * initContext)
{
{
if (gFirstTime) {
// PENDING(edburns): We need this for rdf_getChildCount
PR_SetEnv("XPCOM_CHECK_THREADSAFE=0");
nsILocalFile * pathFile = nsnull;
nsresult rv = nsnull;
JNIEnv * env = initContext->env;
@ -510,7 +539,7 @@ void DoMozInitialization(WebShellInitContext * initContext)
::util_ThrowExceptionToJava(env, "call to NS_NewLocalFile failed.");
return;
}
// It is vitally important to call NS_InitEmbedding before calling
// anything else.
NS_InitEmbedding(pathFile, nsnull);
@ -524,7 +553,9 @@ void DoMozInitialization(WebShellInitContext * initContext)
PR_SetLogFile(webclientLogFile);
// If this fails, it just goes to stdout/stderr
}
OverrideComponents();
InitializeWindowCreator(initContext);
// handle the profile manager nonsense
@ -547,7 +578,7 @@ void DoMozInitialization(WebShellInitContext * initContext)
if (NS_SUCCEEDED(rv)) {
PR_ASSERT(NamesLen >= 1);
// PENDING(edburns): fix for 70656. Really we should have a way
// for the embedding app to specify which profile to use.
// for the embedding app to specify which profile to use.
// For now we just get the name of the first profile.
char * temp = new char[100]; // de-allocated in following for loop
for (i = 0; Names[0][i] != '\0'; i++) {
@ -560,7 +591,7 @@ void DoMozInitialization(WebShellInitContext * initContext)
}
else {
argv[2] = strdup("default");
}
}
printf("debug: edburns: argv[1]: %s argv[2]: %s\n", argv[1],
argv[2]);
}
@ -588,72 +619,72 @@ void DoMozInitialization(WebShellInitContext * initContext)
return;
}
}
}
}
nsresult InitMozillaStuff (WebShellInitContext * initContext)
nsresult InitMozillaStuff (WebShellInitContext * initContext)
{
nsresult rv = nsnull;
DoMozInitialization(initContext);
PR_ASSERT(gComponentManager);
if (gFirstTime) {
printf ("\n\nCreating Event Queue \n\n");
nsCOMPtr<nsIEventQueueService>
nsCOMPtr<nsIEventQueueService>
aEventQService = do_GetService(NS_EVENTQUEUESERVICE_CONTRACTID);
// if we get here, we know that aEventQService is not null.
if (!aEventQService) {
rv = NS_ERROR_FAILURE;
return rv;
}
//TODO Add tracing from nspr.
#if DEBUG_RAPTOR_CANVAS
if (prLogModuleInfo) {
PR_LOG(prLogModuleInfo, 3, ("InitMozillaStuff(%lx): Create the Event Queue for the UI thread...\n", initContext));
}
#endif
// Create the Event Queue for the UI thread...
if (!aEventQService) {
initContext->initFailCode = kEventQueueError;
return rv;
}
// Create the event queue.
rv = aEventQService->CreateThreadEventQueue();
gEmbeddedThread = PR_GetCurrentThread();
// Create the action queue
if (gEmbeddedThread) {
if (gActionQueue == nsnull) {
printf("InitMozillaStuff(%lx): Create the action queue\n", initContext);
// We need to do something different for Unix
nsIEventQueue * EQueue = nsnull;
rv = aEventQService->GetThreadEventQueue(gEmbeddedThread,
rv = aEventQService->GetThreadEventQueue(gEmbeddedThread,
&EQueue);
if (NS_FAILED(rv)) {
initContext->initFailCode = kCreateWebShellError;
return rv;
}
#ifdef XP_UNIX
gdk_input_add(EQueue->GetEventQueueSelectFD(),
GDK_INPUT_READ,
event_processor_callback,
EQueue);
#endif
PLEventQueue * plEventQueue = nsnull;
EQueue->GetPLEventQueue(&plEventQueue);
gActionQueue = plEventQueue;
}
@ -665,7 +696,7 @@ nsresult InitMozillaStuff (WebShellInitContext * initContext)
#ifdef XP_UNIX
// The gdk_x_error function exits in some cases, we don't
// The gdk_x_error function exits in some cases, we don't
// want that.
XSetErrorHandler(wc_x_error);
#endif
@ -678,22 +709,22 @@ nsresult InitMozillaStuff (WebShellInitContext * initContext)
PRBool allowPlugins = PR_TRUE;
/*
/*
// Create the WebBrowser.
nsCOMPtr<nsIWebBrowser> webBrowser = nsnull;
webBrowser = do_CreateInstance(NS_WEBBROWSER_CONTRACTID);
initContext->webBrowser = webBrowser;
// Get the BaseWindow from the DocShell - upcast
// nsCOMPtr<nsIBaseWindow> docShellAsWin(do_QueryInterface(webBrowser));
nsCOMPtr<nsIBaseWindow> docShellAsWin;
rv = webBrowser->QueryInterface(NS_GET_IID(nsIBaseWindow), getter_AddRefs(docShellAsWin));
nsCOMPtr<nsIBaseWindow> docShellAsWin;
rv = webBrowser->QueryInterface(NS_GET_IID(nsIBaseWindow), getter_AddRefs(docShellAsWin));
initContext->baseWindow = docShellAsWin;
printf ("Init the baseWindow\n");
#ifdef XP_UNIX
GtkWidget * bin;
bin = (GtkWidget *) initContext->gtkWinPtr;
@ -704,56 +735,56 @@ nsresult InitMozillaStuff (WebShellInitContext * initContext)
if (prLogModuleInfo) {
PR_LOG(prLogModuleInfo, 3, ("Ashu Debugs - Inside InitMozillaStuff(%lx): - after Init Call...\n", initContext));
}
#else
#else
rv = initContext->baseWindow->InitWindow((nativeWindow) initContext->parentHWnd, nsnull,
initContext->x, initContext->y, initContext->w, initContext->h);
#endif
printf("Create the BaseWindow...\n");
rv = initContext->baseWindow->Create();
if (NS_FAILED(rv)) {
initContext->initFailCode = kInitWebShellError;
return rv;
}
// Create the DocShell
initContext->docShell = do_GetInterface(initContext->webBrowser);
if (!initContext->docShell) {
initContext->initFailCode = kCreateDocShellError;
return rv;
}
// create our BrowserContainer, which implements many many things.
initContext->browserContainer =
new CBrowserContainer(initContext->webBrowser, initContext->env,
initContext->browserContainer =
new CBrowserContainer(initContext->webBrowser, initContext->env,
initContext);
// set the WebShellContainer. This is a pain. It's necessary
// because nsWebShell.cpp still checks for mContainer all over the
// place.
nsCOMPtr<nsIWebShellContainer> wsContainer(do_QueryInterface(initContext->browserContainer));
nsCOMPtr<nsIWebShell> webShell(do_QueryInterface(initContext->docShell));
webShell->SetContainer(wsContainer);
// set the TreeOwner
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryInterface(initContext->docShell));
nsCOMPtr<nsIDocShellTreeOwner> treeOwner(do_QueryInterface(initContext->browserContainer));
docShellAsItem->SetTreeOwner(treeOwner);
// set the docloaderobserver
nsCOMPtr<nsIDocumentLoaderObserver> observer(do_QueryInterface(initContext->browserContainer));
initContext->docShell->SetDocLoaderObserver(observer);
printf("Creation Done.....\n");
printf("Creation Done.....\n");
// Get the WebNavigation Object from the DocShell
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(initContext->docShell));
initContext->webNavigation = webNav;
printf("Show the webBrowser\n");
// Show the webBrowser
rv = initContext->baseWindow->SetVisibility(PR_TRUE);
@ -761,19 +792,19 @@ nsresult InitMozillaStuff (WebShellInitContext * initContext)
initContext->initFailCode = kShowWebShellError;
return rv;
}
initContext->initComplete = TRUE;
*/
wsRealizeBrowserEvent * actionEvent = new wsRealizeBrowserEvent(initContext);
PLEvent * event = (PLEvent*) *actionEvent;
PLEvent * event = (PLEvent*) *actionEvent;
::util_PostSynchronousEvent(initContext, event);
#if DEBUG_RAPTOR_CANVAS
if (prLogModuleInfo) {
PR_LOG(prLogModuleInfo, 3,
PR_LOG(prLogModuleInfo, 3,
("InitMozillaStuff(%lx): enter event loop\n", initContext));
}
#endif
@ -783,7 +814,7 @@ nsresult InitMozillaStuff (WebShellInitContext * initContext)
if (threadId == (void *) gEmbeddedThread)
// Just need to loop once to clear out events before returning
processEventLoop(initContext);
return rv;
}

Просмотреть файл

@ -1,5 +1,5 @@
/* -*- 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.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
@ -21,6 +21,7 @@
* Ian Wilkinson <iw@ennoble.com>
* Ashutosh Kulkarni <ashuk@eng.sun.com>
* Ed Burns <edburns@acm.org>
* Kyle Yuan <kyle.yuan@sun.com>
*/
/*
@ -52,22 +53,29 @@ wsRealizeBrowserEvent::wsRealizeBrowserEvent(WebShellInitContext * yourInitConte
void *
wsRealizeBrowserEvent::handleEvent ()
{
nsresult rv = nsnull;
nsresult rv = nsnull;
nsCOMPtr<nsIWebBrowser> webBrowser = nsnull;
webBrowser = do_CreateInstance(NS_WEBBROWSER_CONTRACTID);
mInitContext->webBrowser = webBrowser;
// create our BrowserContainer, which implements many many things.
CBrowserContainer *browserContainer =
new CBrowserContainer(mInitContext->webBrowser, mInitContext->env,
mInitContext);
mInitContext->browserContainer = browserContainer;
webBrowser->SetContainerWindow(NS_STATIC_CAST(nsIWebBrowserChrome*, browserContainer));
// Get the BaseWindow from the DocShell - upcast
// nsCOMPtr<nsIBaseWindow> docShellAsWin(do_QueryInterface(webBrowser));
nsCOMPtr<nsIBaseWindow> docShellAsWin;
rv = webBrowser->QueryInterface(NS_GET_IID(nsIBaseWindow), getter_AddRefs(docShellAsWin));
mInitContext->baseWindow = docShellAsWin;
nsCOMPtr<nsIBaseWindow> baseWindow;
baseWindow = do_QueryInterface(webBrowser, &rv);
mInitContext->baseWindow = baseWindow;
printf ("Init the baseWindow\n");
#ifdef XP_UNIX
GtkWidget * bin;
bin = (GtkWidget *) mInitContext->gtkWinPtr;
@ -78,51 +86,33 @@ wsRealizeBrowserEvent::handleEvent ()
if (prLogModuleInfo) {
PR_LOG(prLogModuleInfo, 3, ("Ashu Debugs - Inside InitMozillaStuff(%lx): - after Init Call...\n", mInitContext));
}
#else
#else
rv = mInitContext->baseWindow->InitWindow((nativeWindow) mInitContext->parentHWnd, nsnull,
mInitContext->x, mInitContext->y, mInitContext->w, mInitContext->h);
#endif
printf("Create the BaseWindow...\n");
rv = mInitContext->baseWindow->Create();
if (NS_FAILED(rv)) {
mInitContext->initFailCode = kInitWebShellError;
return (void *) rv;
}
// Create the DocShell
mInitContext->docShell = do_GetInterface(mInitContext->webBrowser);
if (!mInitContext->docShell) {
mInitContext->initFailCode = kCreateDocShellError;
return (void *) rv;
}
// create our BrowserContainer, which implements many many things.
mInitContext->browserContainer =
new CBrowserContainer(mInitContext->webBrowser, mInitContext->env,
mInitContext);
// set the WebShellContainer. This is a pain. It's necessary
// because nsWebShell.cpp still checks for mContainer all over the
// place.
nsCOMPtr<nsIWebShellContainer> wsContainer(do_QueryInterface(mInitContext->browserContainer));
nsCOMPtr<nsIWebShell> webShell(do_QueryInterface(mInitContext->docShell));
webShell->SetContainer(wsContainer);
// set the TreeOwner
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryInterface(mInitContext->docShell));
nsCOMPtr<nsIDocShellTreeOwner> treeOwner(do_QueryInterface(mInitContext->browserContainer));
docShellAsItem->SetTreeOwner(treeOwner);
// set the docloaderobserver PENDING(edburns): how to we make our
// presence as a nsIWebProgressListener know?n
printf("Creation Done.....\n");
printf("Creation Done.....\n");
// Get the WebNavigation Object from the DocShell
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(mInitContext->docShell));
mInitContext->webNavigation = webNav;
@ -134,14 +124,14 @@ wsRealizeBrowserEvent::handleEvent ()
return (void *) rv;
}
}
// Set the History
// mInitContext->webNavigation->SetSessionHistory(gHistory);
// Save the sessionHistory in the initContext
// mInitContext->sHistory = gHistory;
printf("Show the webBrowser\n");
// Show the webBrowser
rv = mInitContext->baseWindow->SetVisibility(PR_TRUE);
@ -149,8 +139,8 @@ wsRealizeBrowserEvent::handleEvent ()
mInitContext->initFailCode = kShowWebShellError;
return (void *) rv;
}
mInitContext->initComplete = TRUE;
mInitContext->initComplete = TRUE;
// we will check this value in WindowCreator::CreateChromeWindow
gNewWindowInitContext = mInitContext;

Просмотреть файл

@ -1,5 +1,5 @@
/* -*- 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.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
@ -31,17 +31,16 @@
#include "nsString2.h" // for nsAutoString
wsPromptUsernameAndPasswordEvent::wsPromptUsernameAndPasswordEvent(WebShellInitContext *yourInitContext,
jobject yourPromptGlobalRef,
wsStringStruct *inStrings,
PRUint32 savePassword,
PRUnichar **outUser,
PRUnichar **outPwd,
jobject yourPromptGlobalRef,
wsStringStruct *inStrings,
PRUnichar **outUser,
PRUnichar **outPwd,
PRBool *_retval) :
mInitContext(yourInitContext), mPromptGlobalRef(yourPromptGlobalRef),
mInitContext(yourInitContext), mPromptGlobalRef(yourPromptGlobalRef),
mInStrings(inStrings), mOutUser(outUser),
mOutPwd(outPwd), mRetVal(_retval)
{
}
void *wsPromptUsernameAndPasswordEvent::handleEvent()
@ -66,18 +65,18 @@ void *wsPromptUsernameAndPasswordEvent::handleEvent()
if (!(promptClass = env->GetObjectClass(mPromptGlobalRef))) {
return (void *) NS_ERROR_FAILURE;
}
if (!(mid = env->GetMethodID(promptClass, "promptUsernameAndPassword",
if (!(mid = env->GetMethodID(promptClass, "promptUsernameAndPassword",
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/util/Properties;)Z"))) {
return (void *) NS_ERROR_FAILURE;
}
result = env->CallBooleanMethod(mPromptGlobalRef, mid,
mInStrings[0].jStr, mInStrings[1].jStr,
mInStrings[2].jStr, (jint) mSavePassword,
result = env->CallBooleanMethod(mPromptGlobalRef, mid,
mInStrings[0].jStr, mInStrings[1].jStr,
mInStrings[2].jStr, 0,
gPromptProperties);
#endif
// pull userName and password entries out of the properties table
user = (jstring) ::util_GetFromPropertiesObject(env, gPromptProperties,
USER_NAME_KEY, (jobject)
&(mInitContext->shareContext));
@ -87,7 +86,7 @@ void *wsPromptUsernameAndPasswordEvent::handleEvent()
*mOutUser = ToNewUnicode(autoUser);
::util_ReleaseStringChars(env, user, userJchar);
}
password = (jstring) ::util_GetFromPropertiesObject(env, gPromptProperties,
PASSWORD_KEY, (jobject)
&(mInitContext->shareContext));
@ -97,29 +96,24 @@ void *wsPromptUsernameAndPasswordEvent::handleEvent()
*mOutPwd = ToNewUnicode(autoPassword);
::util_ReleaseStringChars(env, password, passwordJchar);
}
*mRetVal = (result == JNI_TRUE) ? PR_TRUE : PR_FALSE;
return (void *) NS_OK;
}
wsPromptUniversalDialogEvent::wsPromptUniversalDialogEvent(WebShellInitContext *yourInitContext,
jobject yourPromptGlobalRef,
wsStringStruct *inStrings,
PRUnichar **fieldOne,
PRUnichar **fieldTwo,
PRBool *checkboxState,
PRInt32 numButtons,
PRInt32 numFields,
PRInt32 fieldIsPasswd,
PRInt32 *buttonPressed) :
mInitContext(yourInitContext), mPromptGlobalRef(yourPromptGlobalRef),
jobject yourPromptGlobalRef,
wsStringStruct *inStrings,
PRUnichar **fieldOne,
PRUnichar **fieldTwo,
PRInt32 numButtons,
PRInt32 numFields,
PRInt32 fieldIsPasswd) :
mInitContext(yourInitContext), mPromptGlobalRef(yourPromptGlobalRef),
mInStrings(inStrings), mFieldOne(fieldOne), mFieldTwo(fieldTwo),
mCheckboxState(checkboxState), mNumButtons(numButtons),
mNumFields(numFields), mFieldIsPasswd(fieldIsPasswd),
mButtonPressed(buttonPressed)
mNumButtons(numButtons), mNumFields(numFields), mFieldIsPasswd(fieldIsPasswd)
{
}
void *wsPromptUniversalDialogEvent::handleEvent()
@ -146,71 +140,26 @@ void *wsPromptUniversalDialogEvent::handleEvent()
if (!(promptClass = env->GetObjectClass(mPromptGlobalRef))) {
return (void *) NS_ERROR_FAILURE;
}
if (!(mid = env->GetMethodID(promptClass, "universalDialog",
if (!(mid = env->GetMethodID(promptClass, "universalDialog",
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;IIZLjava/util/Properties;)Z"))) {
return (void *) NS_ERROR_FAILURE;
}
result = env->CallBooleanMethod(mPromptGlobalRef, mid,
mInStrings[0].jStr,
mInStrings[1].jStr,
mInStrings[2].jStr,
mInStrings[3].jStr,
mInStrings[4].jStr,
mInStrings[5].jStr,
mInStrings[6].jStr,
mInStrings[7].jStr,
mInStrings[8].jStr,
mInStrings[9].jStr,
(jint) mNumButtons,
result = env->CallBooleanMethod(mPromptGlobalRef, mid,
mInStrings[0].jStr,
mInStrings[1].jStr,
mInStrings[2].jStr,
mInStrings[3].jStr,
mInStrings[4].jStr,
mInStrings[5].jStr,
mInStrings[6].jStr,
mInStrings[7].jStr,
mInStrings[8].jStr,
mInStrings[9].jStr,
(jint) mNumButtons,
(jint) mNumFields,
(jboolean) mFieldIsPasswd,
gPromptProperties);
#endif
// pull entries out of the properties table
// editfield1Value, editfield2Value, checkboxState, buttonPressed
if (mFieldOne) {
edit1 = (jstring) ::util_GetFromPropertiesObject(env,
gPromptProperties,
EDIT_FIELD_1_KEY,
(jobject)
&(mInitContext->shareContext));
edit1Jchar = ::util_GetStringChars(env, edit1);
autoEdit1 = (PRUnichar *) edit1Jchar;
*mFieldOne = ToNewUnicode(autoEdit1);
::util_ReleaseStringChars(env, edit1, edit1Jchar);
}
if (mFieldTwo) {
edit2 = (jstring) ::util_GetFromPropertiesObject(env,
gPromptProperties,
EDIT_FIELD_2_KEY,
(jobject)
&(mInitContext->shareContext));
edit2Jchar = ::util_GetStringChars(env, edit2);
autoEdit2 = (PRUnichar *) edit2Jchar;
*mFieldTwo = ToNewUnicode(autoEdit2);
::util_ReleaseStringChars(env, edit2, edit2Jchar);
}
if (mCheckboxState) {
*mCheckboxState =
(JNI_TRUE == ::util_GetBoolFromPropertiesObject(env,
gPromptProperties,
CHECKBOX_STATE_KEY,
(jobject)
&(mInitContext->shareContext)))
? PR_TRUE : PR_FALSE;
}
if (mButtonPressed) {
*mButtonPressed = (PRInt32)
::util_GetIntFromPropertiesObject(env, gPromptProperties,
BUTTON_PRESSED_KEY,
(jobject)
&(mInitContext->shareContext));
}
return (void *) NS_OK;
}

Просмотреть файл

@ -39,7 +39,6 @@ public:
wsPromptUsernameAndPasswordEvent (WebShellInitContext *yourInitContext,
jobject yourPromptGlobalRef,
wsStringStruct *inStrings,
PRUint32 savePassword,
PRUnichar **outUser,
PRUnichar **outPwd,
PRBool *_retval);
@ -49,7 +48,6 @@ protected:
WebShellInitContext *mInitContext;
jobject mPromptGlobalRef;
wsStringStruct *mInStrings;
PRUint32 mSavePassword;
PRUnichar **mOutUser;
PRUnichar **mOutPwd;
PRBool *mRetVal;
@ -62,11 +60,9 @@ public:
wsStringStruct *inStrings,
PRUnichar **fieldOne,
PRUnichar **fieldTwo,
PRBool *checkboxState,
PRInt32 numButtons,
PRInt32 numFields,
PRInt32 fieldIsPasswd,
PRInt32 *buttonPressed);
PRInt32 fieldIsPasswd);
void * handleEvent (void);
protected:
@ -75,11 +71,9 @@ protected:
wsStringStruct *mInStrings;
PRUnichar **mFieldOne;
PRUnichar **mFieldTwo;
PRBool *mCheckboxState;
PRInt32 mNumButtons;
PRInt32 mNumFields;
PRInt32 mFieldIsPasswd;
PRInt32 *mButtonPressed;
};

Просмотреть файл

Просмотреть файл

Просмотреть файл

@ -67,6 +67,7 @@ jobject EDIT_FIELD_1_KEY;
jobject EDIT_FIELD_2_KEY;
jobject CHECKBOX_STATE_KEY;
jobject BUTTON_PRESSED_KEY;
jobject FINISHED_KEY;
jobject TRUE_VALUE;
jobject FALSE_VALUE;
jobject ONE_VALUE;
@ -211,6 +212,12 @@ jboolean util_InitStringConstants()
"buttonPressed")))) {
return JNI_FALSE;
}
if (nsnull == (FINISHED_KEY =
::util_NewGlobalRef(env, (jobject)
::util_NewStringUTF(env,
"finished")))) {
return JNI_FALSE;
}
if (nsnull == (TRUE_VALUE =
::util_NewGlobalRef(env, (jobject)
::util_NewStringUTF(env, "true")))) {

Просмотреть файл

@ -82,6 +82,7 @@ extern jobject EDIT_FIELD_1_KEY;
extern jobject EDIT_FIELD_2_KEY;
extern jobject CHECKBOX_STATE_KEY;
extern jobject BUTTON_PRESSED_KEY;
extern jobject FINISHED_KEY;
extern jobject TRUE_VALUE;
extern jobject FALSE_VALUE;
extern jobject ONE_VALUE;