diff --git a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/Navigation.java b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/Navigation.java index 313d4aa29d6..eb1fdb0d7fb 100644 --- a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/Navigation.java +++ b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/Navigation.java @@ -49,5 +49,15 @@ public void loadFromStream(InputStream stream, String uri, public void refresh(long loadFlags); public void stop(); +/** + + * Gives this Navigation instance the ability to call back the custom + * app when a site with basic authentication is encountered. The custom + * app can choose to put up appropriate modal UI. + + */ + +public void setPrompt(Prompt yourPrompt); + } // end of interface CurrentPage diff --git a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/Prompt.java b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/Prompt.java new file mode 100644 index 00000000000..a90be357658 --- /dev/null +++ b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/Prompt.java @@ -0,0 +1,60 @@ +/* -*- 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 + * 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 and + * Ian Wilkinson. Portions created by Kirk Baker and Ian Wilkinson are + * Copyright (C) 1999 Kirk Baker and Ian Wilkinson. All + * Rights Reserved. + * + * Contributor(s): Ed Burns + */ + +package org.mozilla.webclient; + +import java.util.Properties; + + +/** + + * The custom app must implement this interface in order to supply the + * underlying browser with basic authentication behavior. The custom + * app must tell webclient about its Prompt implementation by calling + * Navigation.setPrompt(). This must be done FOR EACH BrowserControl + * instance! + + */ + +public interface Prompt +{ + +/** + + * Puts up a username/password dialog with OK and Cancel buttons. + + * @param fillThis a pre-allocated properties object + * that the callee fills in. + + * keys: userName, password + + * @return true for OK, false for Cancel + + */ + +public boolean promptUsernameAndPassword(String dialogTitle, + String text, + String passwordRealm, + int savePassword, + Properties fillThis); + +} // end of interface History diff --git a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/test/EMWindow.java b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/test/EMWindow.java index b43188f9a85..1094d310b65 100644 --- a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/test/EMWindow.java +++ b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/test/EMWindow.java @@ -57,13 +57,13 @@ import java.io.FileInputStream; * This is a test application for using the BrowserControl. * - * @version $Id: EMWindow.java,v 1.24.2.6 2000-11-11 19:43:22 edburns%acm.org Exp $ + * @version $Id: EMWindow.java,v 1.24.2.7 2000-12-01 01:33:37 edburns%acm.org Exp $ * * @see org.mozilla.webclient.BrowserControlFactory */ -public class EMWindow extends Frame implements DialogClient, ActionListener, DocumentLoadListener, MouseListener { +public class EMWindow extends Frame implements DialogClient, ActionListener, DocumentLoadListener, MouseListener, Prompt { static final int defaultWidth = 640; static final int defaultHeight = 480; @@ -84,6 +84,7 @@ public class EMWindow extends Frame implements DialogClient, ActionListener, Doc private Panel statusPanel; private Panel buttonsPanel; private FindDialog findDialog = null; +private PasswordDialog passDialog = null; private MenuBar menuBar; private Menu historyMenu; private MenuItem backMenuItem; @@ -274,6 +275,7 @@ public class EMWindow extends Frame implements DialogClient, ActionListener, Doc try { navigation = (Navigation) browserControl.queryInterface(BrowserControl.NAVIGATION_NAME); + navigation.setPrompt(this); currentPage = (CurrentPage) browserControl.queryInterface(BrowserControl.CURRENT_PAGE_NAME); history = (History) @@ -501,6 +503,9 @@ public void actionPerformed (ActionEvent evt) public void dialogDismissed(Dialog d) { + if (d == passDialog) { + return; + } if(findDialog.wasClosed()) { System.out.println("Find Dialog Closed"); } @@ -738,6 +743,36 @@ public void mouseReleased(java.awt.event.MouseEvent e) { } +// +// Prompt methods +// + +public boolean promptUsernameAndPassword(String dialogTitle, + String text, + String passwordRealm, + int savePassword, + Properties fillThis) +{ + if (null == fillThis) { + return false; + } + if (null == passDialog) { + if (dialogTitle.equals("")) { + dialogTitle = "Basic Authentication Test"; + } + passDialog = new PasswordDialog(this, this, + dialogTitle, text, passwordRealm, + 20, true, fillThis); + if (null == passDialog) { + return false; + } + passDialog.setModal(true); + } + passDialog.setVisible(true); + + return passDialog.wasOk(); +} + class HistoryActionListener implements ActionListener { diff --git a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/test/PasswordDialog.java b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/test/PasswordDialog.java new file mode 100644 index 00000000000..3e0e769202b --- /dev/null +++ b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/test/PasswordDialog.java @@ -0,0 +1,192 @@ +/** Ashu -- this is the Find Dialog Class + instantiated within the EMWindow class, this + will act as the Modal dialog for calling Find/Find Next + functions for CurrentPage +*/ + +package org.mozilla.webclient.test; + +import java.awt.*; +import java.awt.event.*; + +import java.util.Properties; + +public class PasswordDialog extends WorkDialog implements ActionListener, ItemListener{ + static private int _defaultTextFieldSize = 20; + private Button okButton; + private Button cancelButton; + private String realm; + private TextField userField; + private TextField passField; + private boolean wasOk; + private boolean wasCanceled; + private ButtonPanel buttonPanel = new ButtonPanel(); + private Properties props; + + + public PasswordDialog(Frame frame, DialogClient client, String title, + String text, String realm, + int userFieldSize, boolean modal, + Properties passwordProperties) { + super(frame, client, title, modal); + RealmPanel realmPanel; + okButton = addButton("Ok"); + cancelButton = addButton("Cancel"); + props = passwordProperties; + + okButton.addActionListener(this); + cancelButton.addActionListener(this); + + realmPanel = new RealmPanel(this, text, realm, + userFieldSize); + userField = realmPanel.getUserField(); + passField = realmPanel.getPassField(); + setWorkPanel(realmPanel); + } + + public void actionPerformed(ActionEvent ae) { + if(ae.getSource() == cancelButton) { + wasOk = false; + wasCanceled = true; + dispose(true); + } + else if(ae.getSource() == okButton) { + wasCanceled = false; + wasOk = true; + props.setProperty("userName", userField.getText()); + props.setProperty("password", passField.getText()); + setUserField(""); + setPassField(""); + dispose(true); + } + } + + + public void itemStateChanged(ItemEvent e) { + } + + public void setVisible(boolean b) { + userField.requestFocus(); + super.setVisible(b); + } + + public void returnInTextField() { + okButton.requestFocus(); + } + + public TextField getUserField() { + return userField; + } + + public void setUserField(String string) { + // realmPanel.setUserField(string); + userField.setText(string); + } + + public void setPassField(String string) { + passField.setText(string); + } + + public String getAnswer() { + return userField.getText(); + } + + public boolean wasOk() { + return wasOk; + } + + public boolean wasCanceled() { + return wasCanceled; + } + + private void setRealm(String realm) { + this.realm = realm; + } +} + + +class RealmPanel extends Postcard { + private TextField userField; + private TextField passField; + private PasswordDialog dialog; + +public RealmPanel(PasswordDialog myDialog, String text, + String realm, int cols) +{ + super(new Panel()); + Panel panel = getPanel(); + this.dialog = myDialog; + + // set up the stuff on top of the text fields + Panel northPanel = new Panel(); + northPanel.setLayout(new BorderLayout()); + Label textLabel = new Label(text); + textLabel.setBackground(Color.lightGray); + Label realmLabel = new Label("Realm: " + realm); + realmLabel.setBackground(Color.lightGray); + northPanel.add(textLabel, BorderLayout.NORTH); + northPanel.add(realmLabel, BorderLayout.CENTER); + + panel.setLayout(new BorderLayout()); + panel.add(northPanel, BorderLayout.NORTH); + + // set up the text fields + + // set up the user name label and field + Panel centerPanel = new Panel(); + centerPanel.setLayout(new BorderLayout()); + + Panel userPanel = new Panel(); + userPanel.setLayout(new BorderLayout()); + Label nameLabel = new Label("User Name: "); + nameLabel.setBackground(Color.lightGray); + userPanel.add(nameLabel, BorderLayout.WEST); + if (cols != 0) { + userField = new TextField("", cols); + } + else { + userField = new TextField(); + } + userPanel.add(userField, BorderLayout.CENTER); + centerPanel.add(userPanel, BorderLayout.NORTH); + + // set up the password label and field + Panel passPanel = new Panel(); + passPanel.setLayout(new BorderLayout()); + Label passLabel = new Label("Password: "); + passLabel.setBackground(Color.lightGray); + passPanel.add(passLabel, BorderLayout.WEST); + if (cols != 0) { + passField = new TextField("", cols); + } + else { + passField = new TextField(); + } + passField.setEchoChar('*'); + passPanel.add(passField, BorderLayout.CENTER); + centerPanel.add(passPanel, BorderLayout.CENTER); + // + + // add the center panel to the main panel + panel.add(centerPanel, BorderLayout.CENTER); +} + +public TextField getUserField() +{ + return userField; +} + + public void setUserField(String string) { + userField.setText(string); + } + + public TextField getPassField() { + return passField; + } + + public void setPassField(String string) { + passField.setText(string); + } + +} + diff --git a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/NavigationImpl.java b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/NavigationImpl.java index 2c363162539..1d46d806eea 100644 --- a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/NavigationImpl.java +++ b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/NavigationImpl.java @@ -31,6 +31,7 @@ import org.mozilla.webclient.BrowserControl; import org.mozilla.webclient.Navigation; import org.mozilla.webclient.WindowControl; import org.mozilla.webclient.WrapperFactory; +import org.mozilla.webclient.Prompt; import java.io.InputStream; import java.util.Properties; @@ -130,6 +131,18 @@ public void stop() } } +public void setPrompt(Prompt yourPrompt) +{ + ParameterCheck.nonNull(yourPrompt); + myFactory.throwExceptionIfNotInitialized(); + Assert.assert(-1 != nativeWebShell); + + synchronized(myBrowserControl) { + nativeSetPrompt(nativeWebShell, yourPrompt); + } + +} + // // Native methods // @@ -146,6 +159,8 @@ public native void nativeRefresh(int webShellPtr, long loadFlags); public native void nativeStop(int webShellPtr); +public native void nativeSetPrompt(int webShellPtr, Prompt yourPrompt); + // ----VERTIGO_TEST_START // @@ -158,7 +173,7 @@ public static void main(String [] args) Log.setApplicationName("NavigationImpl"); Log.setApplicationVersion("0.0"); - Log.setApplicationVersionDate("$Id: NavigationImpl.java,v 1.3.8.1 2000-11-07 02:40:38 edburns%acm.org Exp $"); + Log.setApplicationVersionDate("$Id: NavigationImpl.java,v 1.3.8.2 2000-12-01 01:33:41 edburns%acm.org Exp $"); try { org.mozilla.webclient.BrowserControlFactory.setAppData(args[0]); diff --git a/mozilla/java/webclient/src_moz/CBrowserContainer.cpp b/mozilla/java/webclient/src_moz/CBrowserContainer.cpp index 2224cab2e13..31ec6d4aa39 100644 --- a/mozilla/java/webclient/src_moz/CBrowserContainer.cpp +++ b/mozilla/java/webclient/src_moz/CBrowserContainer.cpp @@ -38,6 +38,8 @@ #include "dom_util.h" +#include "nsActions.h" + static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); #if defined(XP_UNIX) || defined(XP_MAC) || defined(XP_BEOS) @@ -47,12 +49,136 @@ static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); #define WC_ITOA(intVal, buf, radix) itoa(intVal, buf, radix) #endif +static jobject gAuthProperties = nsnull; + +class wsPromptEvent : public nsActionEvent { +public: + wsPromptEvent (WebShellInitContext *yourInitContext, + jobject yourPromptGlobalRef, + const PRUnichar *dialogTitle, + const PRUnichar *text, + const PRUnichar *passwordRealm, + PRUint32 savePassword, + PRUnichar **outUser, + PRUnichar **outPwd, + PRBool *_retval); + void * handleEvent (void); + +protected: + WebShellInitContext *mInitContext; + jobject mPromptGlobalRef; + nsAutoString mDialogTitle; + nsAutoString mText; + nsAutoString mPasswordRealm; + PRUint32 mSavePassword; + PRUnichar **mOutUser; + PRUnichar **mOutPwd; + PRBool *mRetVal; +}; + +wsPromptEvent::wsPromptEvent(WebShellInitContext *yourInitContext, + jobject yourPromptGlobalRef, + const PRUnichar *dialogTitle, + const PRUnichar *text, + const PRUnichar *passwordRealm, + PRUint32 savePassword, + PRUnichar **outUser, + PRUnichar **outPwd, + PRBool *_retval) : + mInitContext(yourInitContext), mPromptGlobalRef(yourPromptGlobalRef), + mDialogTitle(dialogTitle), mText(text), + mPasswordRealm(passwordRealm), mOutUser(outUser), + mOutPwd(outPwd), mRetVal(_retval) +{ + +} + +void *wsPromptEvent::handleEvent() +{ + JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION); + jstring title = nsnull; + jstring text = nsnull; + jstring passwordRealm = nsnull; + jboolean result = JNI_FALSE; + jstring user = nsnull; + jstring password = nsnull; + const jchar *userJchar = nsnull; + const jchar *passwordJchar = nsnull; + jclass promptClass = nsnull; + jmethodID mid = nsnull; + nsAutoString autoUser; + nsAutoString autoPassword; + if (!gAuthProperties) { + return (void *) NS_ERROR_FAILURE; + } + + // step one, convert to strings + if (mDialogTitle.GetUnicode()) { + title = ::util_NewString(env, + (const jchar *) mDialogTitle.GetUnicode(), + mDialogTitle.Length()); + } + if (mText.GetUnicode()) { + text = ::util_NewString(env, (const jchar *) mText.GetUnicode(), + mText.Length()); + } + if (mPasswordRealm.GetUnicode()) { + passwordRealm = ::util_NewString(env, + (const jchar *) + mPasswordRealm.GetUnicode(), + mPasswordRealm.Length()); + } + +#ifdef BAL_INTERFACE +#else + // step two, call the java method. + if (!(promptClass = env->GetObjectClass(mPromptGlobalRef))) { + return (void *) NS_ERROR_FAILURE; + } + 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, title, text, + passwordRealm, (jint) mSavePassword, + gAuthProperties); +#endif + + // pull userName and password entries out of the properties table + + user = (jstring) ::util_GetFromPropertiesObject(env, gAuthProperties, + USER_NAME_KEY, (jobject) + &(mInitContext->shareContext)); + userJchar = ::util_GetStringChars(env, user); + autoUser = (PRUnichar *) userJchar; + *mOutUser = autoUser.ToNewUnicode(); + ::util_ReleaseStringChars(env, user, userJchar); + + password = (jstring) ::util_GetFromPropertiesObject(env, gAuthProperties, + PASSWORD_KEY, (jobject) + &(mInitContext->shareContext)); + passwordJchar = ::util_GetStringChars(env, password); + autoPassword = (PRUnichar *) passwordJchar; + *mOutPwd = autoPassword.ToNewUnicode(); + ::util_ReleaseStringChars(env, password, passwordJchar); + + *mRetVal = (result == JNI_TRUE) ? PR_TRUE : PR_FALSE; + + ::util_DeleteString(env, title); + ::util_DeleteString(env, text); + ::util_DeleteString(env, passwordRealm); + + return (void *) NS_OK; +} + + CBrowserContainer::CBrowserContainer(nsIWebBrowser *pOwner, JNIEnv *env, WebShellInitContext *yourInitContext) : m_pOwner(pOwner), mJNIEnv(env), mInitContext(yourInitContext), - mDocTarget(nsnull), mMouseTarget(nsnull), mDomEventTarget(nsnull), - inverseDepth(-1), properties(nsnull), currentDOMEvent(nsnull) + mDocTarget(nsnull), mMouseTarget(nsnull), mPrompt(nsnull), + mDomEventTarget(nsnull), inverseDepth(-1), + properties(nsnull), currentDOMEvent(nsnull) { NS_INIT_REFCNT(); // initialize the string constants (including properties keys) @@ -170,7 +296,50 @@ NS_IMETHODIMP CBrowserContainer::PromptUsernameAndPassword(const PRUnichar *dial PRUnichar **pwd, PRBool *_retval) { - return NS_ERROR_NOT_IMPLEMENTED; + nsresult rv = NS_ERROR_FAILURE; + + // if the user hasn't given us a prompt, oh well + if (!mPrompt) { + return NS_OK; + } + + JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION); + + // PENDING(edburns): uniformly apply checks for this throughout the + // code + PR_ASSERT(mInitContext); + PR_ASSERT(mInitContext->initComplete); + + // try to initialize the properties object for basic auth + if (!gAuthProperties) { + gAuthProperties = + ::util_CreatePropertiesObject(env, (jobject) + &(mInitContext->shareContext)); + if (!gAuthProperties) { + printf("Error: can't create properties object for authentitication"); + return NS_OK; + } + } + else { + ::util_ClearPropertiesObject(env, gAuthProperties, (jobject) + &(mInitContext->shareContext)); + } + + wsPromptEvent *actionEvent = nsnull; + void *voidResult = nsnull; + if (!(actionEvent = new wsPromptEvent(mInitContext, mPrompt, + dialogTitle, text, + passwordRealm, savePassword, + user, pwd, _retval))) { + ::util_ThrowExceptionToJava(env, "Exception: PromptUserNameAndPassword: can't create wsPromptEvent"); + return rv; + } + // the out params to this method are set in wsPromptEvent::handleEvent() + voidResult = ::util_PostSynchronousEvent(mInitContext, + (PLEvent *) *actionEvent); + + return (nsresult) voidResult; + } /* boolean promptPassword (in wstring text, in wstring title, out wstring pwd); */ @@ -1019,6 +1188,24 @@ NS_IMETHODIMP CBrowserContainer::AddDocumentLoadListener(jobject target) return rv; } +NS_IMETHODIMP CBrowserContainer::SetPrompt(jobject target) +{ + nsresult rv = NS_OK; + JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION); + + if (mPrompt) { + ::util_DeleteGlobalRef(env, mPrompt); + mPrompt = nsnull; + } + if (nsnull == (mPrompt = ::util_NewGlobalRef(env, target))) { + ::util_ThrowExceptionToJava(env, "Exception: Navigation.nativeSetPrompt(): can't create NewGlobalRef\n\tfor argument"); + rv = NS_ERROR_NULL_POINTER; + } + + return rv; +} + + NS_IMETHODIMP CBrowserContainer::RemoveMouseListener() { nsresult rv = NS_OK; diff --git a/mozilla/java/webclient/src_moz/CBrowserContainer.h b/mozilla/java/webclient/src_moz/CBrowserContainer.h index a36035490d3..f735921256e 100644 --- a/mozilla/java/webclient/src_moz/CBrowserContainer.h +++ b/mozilla/java/webclient/src_moz/CBrowserContainer.h @@ -86,6 +86,7 @@ protected: WebShellInitContext *mInitContext; jobject mDocTarget; jobject mMouseTarget; + jobject mPrompt; nsCOMPtr mDomEventTarget; // diff --git a/mozilla/java/webclient/src_moz/NavigationImpl.cpp b/mozilla/java/webclient/src_moz/NavigationImpl.cpp index ceab6704a75..86e6ebd2ef8 100644 --- a/mozilla/java/webclient/src_moz/NavigationImpl.cpp +++ b/mozilla/java/webclient/src_moz/NavigationImpl.cpp @@ -191,3 +191,34 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_NavigationImpl ::util_PostEvent(initContext, event); } } + +JNIEXPORT void JNICALL +Java_org_mozilla_webclient_wrapper_1native_NavigationImpl_nativeSetPrompt +(JNIEnv *env, jobject obj, jint webShellPtr, jobject userPrompt) +{ + JNIEnv * pEnv = env; + jobject jobj = obj; + + WebShellInitContext* initContext = (WebShellInitContext *) webShellPtr; + + if (initContext == nsnull) { + ::util_ThrowExceptionToJava(env, "Exception: null webShellPtr passed to nativeSetPrompt"); + return; + } + + if (userPrompt == nsnull) { + ::util_ThrowExceptionToJava(env, "Exception: null properties passed to nativeSetPrompt"); + return; + } + + if (!initContext->initComplete) { + return; + } + + // IMPORTANT: do the DeleteGlobalRef when we set a new prompt! + + PR_ASSERT(initContext->browserContainer); + + initContext->browserContainer->SetPrompt(userPrompt); +} + diff --git a/mozilla/java/webclient/src_moz/motif/NativeLoaderStub.cpp b/mozilla/java/webclient/src_moz/motif/NativeLoaderStub.cpp index afa7199ba21..f4c24f89feb 100644 --- a/mozilla/java/webclient/src_moz/motif/NativeLoaderStub.cpp +++ b/mozilla/java/webclient/src_moz/motif/NativeLoaderStub.cpp @@ -143,6 +143,7 @@ void (* nativeLoadURL) (JNIEnv *, jobject, jint, jstring); void (* nativeLoadFromStream) (JNIEnv *, jobject, jint, jobject, jstring, jstring, jint, jobject); void (* nativeRefresh) (JNIEnv *, jobject, jint, jlong); void (* nativeStop) (JNIEnv *, jobject, jint); +void (* nativeSetPrompt) (JNIEnv *, jobject, jint, jobject); // from RDFEnumeration.h void (* nativeFinalize) (JNIEnv *, jobject, jint); jboolean (* nativeHasMoreElements) (JNIEnv *, jobject, jint, jint); @@ -275,6 +276,10 @@ void locateBrowserControlStubFunctions(void * dll) { if (!nativeStop) { printf("got dlsym error %s\n", dlerror()); } + nativeSetPrompt = (void (*) (JNIEnv *, jobject, jint, jobject)) dlsym(dll, "Java_org_mozilla_webclient_wrapper_1native_NavigationImpl_nativeSetPrompt"); + if (!nativeSetPrompt) { + printf("got dlsym error %s\n", dlerror()); + } nativeAddRef = (void (*) (JNIEnv *, jobject, jint)) dlsym(dll, "Java_org_mozilla_webclient_wrapper_1native_ISupportsPeer_nativeAddRef"); if (!nativeAddRef) { @@ -791,6 +796,12 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_NavigationImpl (* nativeStop) (env, obj, webShellPtr); } +JNIEXPORT void JNICALL +Java_org_mozilla_webclient_wrapper_1native_NavigationImpl_nativeSetPrompt +(JNIEnv *env, jobject obj, jint webShellPtr, jobject userPrompt) +{ + (* nativeSetPrompt) (env, obj, webShellPtr, userPrompt); +} // RDFEnumeration diff --git a/mozilla/java/webclient/src_moz/wcIBrowserContainer.h b/mozilla/java/webclient/src_moz/wcIBrowserContainer.h index 94764aebf2f..c2bdf339467 100644 --- a/mozilla/java/webclient/src_moz/wcIBrowserContainer.h +++ b/mozilla/java/webclient/src_moz/wcIBrowserContainer.h @@ -46,6 +46,7 @@ public: NS_IMETHOD AddMouseListener(jobject target) = 0; NS_IMETHOD AddDocumentLoadListener(jobject target) = 0; + NS_IMETHOD SetPrompt(jobject target) = 0; NS_IMETHOD RemoveAllListeners() = 0; NS_IMETHOD RemoveMouseListener() = 0; NS_IMETHOD RemoveDocumentLoadListener() = 0; @@ -55,6 +56,7 @@ public: #define NS_DECL_WCIBROWSERCONTAINER \ NS_IMETHOD AddMouseListener(jobject target); \ NS_IMETHOD AddDocumentLoadListener(jobject target); \ + NS_IMETHOD SetPrompt(jobject target); \ NS_IMETHOD RemoveAllListeners(); \ NS_IMETHOD RemoveMouseListener(); \ NS_IMETHOD RemoveDocumentLoadListener(); diff --git a/mozilla/java/webclient/src_share/jni_util.cpp b/mozilla/java/webclient/src_share/jni_util.cpp index 16698e038c2..3dfabef00e5 100644 --- a/mozilla/java/webclient/src_share/jni_util.cpp +++ b/mozilla/java/webclient/src_share/jni_util.cpp @@ -41,6 +41,7 @@ JavaVM *gVm = nsnull; // declared in ns_globals.h, which is included in static jmethodID gPropertiesInitMethodID = nsnull; static jmethodID gPropertiesSetPropertyMethodID = nsnull; +static jmethodID gPropertiesGetPropertyMethodID = nsnull; static jmethodID gPropertiesClearMethodID = nsnull; @@ -60,6 +61,8 @@ jobject SHIFT_KEY; jobject META_KEY; jobject BUTTON_KEY; jobject CLICK_COUNT_KEY; +jobject USER_NAME_KEY; +jobject PASSWORD_KEY; jobject TRUE_VALUE; jobject FALSE_VALUE; jobject ONE_VALUE; @@ -160,6 +163,18 @@ jboolean util_InitStringConstants(JNIEnv *env) "ClickCount")))) { return JNI_FALSE; } + if (nsnull == (USER_NAME_KEY = + ::util_NewGlobalRef(env, (jobject) + ::util_NewStringUTF(env, + "userName")))) { + return JNI_FALSE; + } + if (nsnull == (PASSWORD_KEY = + ::util_NewGlobalRef(env, (jobject) + ::util_NewStringUTF(env, + "password")))) { + return JNI_FALSE; + } if (nsnull == (TRUE_VALUE = ::util_NewGlobalRef(env, (jobject) ::util_NewStringUTF(env, "true")))) { @@ -479,18 +494,17 @@ jobject util_CreatePropertiesObject(JNIEnv *env, jobject initContextObj) #else util_Assert(initContextObj); ShareInitContext *initContext = (ShareInitContext *) initContextObj; + jclass propertiesClass = nsnull; - if (nsnull == initContext->propertiesClass) { - if (nsnull == (initContext->propertiesClass = - ::util_FindClass(env, "java/util/Properties"))) { - return result; - } + if (nsnull == (propertiesClass = + ::util_FindClass(env, "java/util/Properties"))) { + return result; } if (nsnull == gPropertiesInitMethodID) { - util_Assert(initContext->propertiesClass); + util_Assert(propertiesClass); if (nsnull == (gPropertiesInitMethodID = - env->GetMethodID(initContext->propertiesClass, + env->GetMethodID(propertiesClass, "", "()V"))) { return result; } @@ -498,7 +512,7 @@ jobject util_CreatePropertiesObject(JNIEnv *env, jobject initContextObj) util_Assert(gPropertiesInitMethodID); result = ::util_NewGlobalRef(env, - env->NewObject(initContext->propertiesClass, + env->NewObject(propertiesClass, gPropertiesInitMethodID)); #endif @@ -528,11 +542,16 @@ void util_ClearPropertiesObject(JNIEnv *env, jobject propertiesObject, #else util_Assert(initContextObj); ShareInitContext *initContext = (ShareInitContext *) initContextObj; + jclass propertiesClass = nsnull; + + if (nsnull == (propertiesClass = + ::util_FindClass(env, "java/util/Properties"))) { + return; + } if (nsnull == gPropertiesClearMethodID) { - util_Assert(initContext->propertiesClass); if (nsnull == (gPropertiesClearMethodID = - env->GetMethodID(initContext->propertiesClass, "clear", "()V"))) { + env->GetMethodID(propertiesClass, "clear", "()V"))) { return; } } @@ -555,11 +574,16 @@ void util_StoreIntoPropertiesObject(JNIEnv *env, jobject propertiesObject, #else util_Assert(initContextObj); ShareInitContext *initContext = (ShareInitContext *) initContextObj; + jclass propertiesClass = nsnull; + + if (nsnull == (propertiesClass = + ::util_FindClass(env, "java/util/Properties"))) { + return; + } if (nsnull == gPropertiesSetPropertyMethodID) { - util_Assert(initContext->propertiesClass); if (nsnull == (gPropertiesSetPropertyMethodID = - env->GetMethodID(initContext->propertiesClass, + env->GetMethodID(propertiesClass, "setProperty", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/Object;"))) { return; @@ -575,6 +599,41 @@ void util_StoreIntoPropertiesObject(JNIEnv *env, jobject propertiesObject, #endif } +jobject util_GetFromPropertiesObject(JNIEnv *env, jobject propertiesObject, + jobject name, jobject initContextObj) +{ + jobject result = nsnull; +#ifdef BAL_INTERFACE + if (nsnull != externalGetFromPropertiesObject) { + result = externalGetFromPropertiesObject(env, propertiesObject, name, + initContextObj); + } +#else + util_Assert(initContextObj); + ShareInitContext *initContext = (ShareInitContext *) initContextObj; + jclass propertiesClass = nsnull; + + if (nsnull == (propertiesClass = + ::util_FindClass(env, "java/util/Properties"))) { + return result; + } + + if (nsnull == gPropertiesGetPropertyMethodID) { + if (nsnull == (gPropertiesGetPropertyMethodID = + env->GetMethodID(propertiesClass, + "getProperty", + "(Ljava/lang/String;)Ljava/lang/String;"))) { + return result; + } + } + util_Assert(gPropertiesGetPropertyMethodID); + + result = env->CallObjectMethod(propertiesObject, + gPropertiesGetPropertyMethodID, name); +#endif + return result; +} + JNIEXPORT jvalue JNICALL JNU_CallMethodByName(JNIEnv *env, jboolean *hasException, diff --git a/mozilla/java/webclient/src_share/jni_util.h b/mozilla/java/webclient/src_share/jni_util.h index b450ed9552d..91575a36088 100644 --- a/mozilla/java/webclient/src_share/jni_util.h +++ b/mozilla/java/webclient/src_share/jni_util.h @@ -76,6 +76,8 @@ extern jobject SHIFT_KEY; extern jobject META_KEY; extern jobject BUTTON_KEY; extern jobject CLICK_COUNT_KEY; +extern jobject USER_NAME_KEY; +extern jobject PASSWORD_KEY; extern jobject TRUE_VALUE; extern jobject FALSE_VALUE; extern jobject ONE_VALUE; @@ -295,6 +297,16 @@ void util_StoreIntoPropertiesObject(JNIEnv *env, jobject propertiesObject, jobject name, jobject value, jobject reserved); +/** + + * A JNI wrapper to get a value for a name out of a PropertiesObject + * created by CreatePropertiesObject + + */ + +jobject util_GetFromPropertiesObject(JNIEnv *, jobject propertiesObject, + jobject name, jobject reserved); + // // Functions provided by the browser specific native code diff --git a/mozilla/java/webclient/src_share/jni_util_export.cpp b/mozilla/java/webclient/src_share/jni_util_export.cpp index 0efccab7bbe..7be4c00112e 100644 --- a/mozilla/java/webclient/src_share/jni_util_export.cpp +++ b/mozilla/java/webclient/src_share/jni_util_export.cpp @@ -42,6 +42,8 @@ fpClearPropertiesObjectType externalClearPropertiesObject = nsnull; // jni_util_ fpStoreIntoPropertiesObjectType externalStoreIntoPropertiesObject = nsnull; // jni_util_export.h +fpGetFromPropertiesObjectType externalGetFromPropertiesObject = nsnull; // jni_util_export.h + JNIEXPORT const char * JNICALL util_GetStringUTFChars(JNIEnv *env, jstring inString) { @@ -191,6 +193,11 @@ JNIEXPORT void JNICALL util_SetStoreIntoPropertiesObjectFunction(fpStoreIntoProp externalStoreIntoPropertiesObject = fp; } +JNIEXPORT void JNICALL util_SetGetFromPropertiesObjectFunction(fpGetFromPropertiesObjectType fp) +{ + externalGetFromPropertiesObject = fp; +} + JNIEXPORT void JNICALL util_InitializeEventMaskValuesFromClass(const char *className, char *maskNames[], diff --git a/mozilla/java/webclient/src_share/jni_util_export.h b/mozilla/java/webclient/src_share/jni_util_export.h index 73e50b7c6bc..24e192888d2 100644 --- a/mozilla/java/webclient/src_share/jni_util_export.h +++ b/mozilla/java/webclient/src_share/jni_util_export.h @@ -188,6 +188,26 @@ typedef JNIEXPORT void (JNICALL * fpStoreIntoPropertiesObjectType) (JNIEnv *env, jobject propertiesObject, jobject name, jobject value, jobject reserved); +/** + + * Called after webclient has called fpCreatePropertiesObjectType when + * webclient wants to get values from the properties object. + + * @param env not used + + * @param propertiesObject obtained from fpCreatePropertiesObjectType + + * @param name the name of the property + + * @returns the return value from the properties object + + */ + + +typedef JNIEXPORT jobject (JNICALL * fpGetFromPropertiesObjectType) + (JNIEnv *env, jobject propertiesObject, jobject name, jobject reserved); + + /** * This function must be called at app initialization. @@ -258,6 +278,16 @@ JNIEXPORT void JNICALL util_SetClearPropertiesObjectFunction(fpDestroyProperties JNIEXPORT void JNICALL util_SetStoreIntoPropertiesObjectFunction(fpStoreIntoPropertiesObjectType fp); +/** + + * This function must be called at app initialization. + + * @see fpGetFromPropertiesObjectType + + */ + +JNIEXPORT void JNICALL util_SetGetFromPropertiesObjectFunction(fpGetFromPropertiesObjectType fp); + /** @@ -330,6 +360,17 @@ extern fpClearPropertiesObjectType externalClearPropertiesObject; extern fpStoreIntoPropertiesObjectType externalStoreIntoPropertiesObject; +/** + + * defined in jni_util_export.cpp + + * The function pointer set with util_SetGetFromPropertiesObjectFunction + + */ + +extern fpGetFromPropertiesObjectType externalGetFromPropertiesObject; + + /** * Called by the mozilla event listener implementation class at