diff --git a/java/webclient/classes_spec/org/mozilla/webclient/impl/WrapperFactory.java b/java/webclient/classes_spec/org/mozilla/webclient/impl/WrapperFactory.java index 2a838ca3c716a..7d1dd90478d19 100644 --- a/java/webclient/classes_spec/org/mozilla/webclient/impl/WrapperFactory.java +++ b/java/webclient/classes_spec/org/mozilla/webclient/impl/WrapperFactory.java @@ -77,6 +77,4 @@ public Object newImpl(String interfaceName, */ public int getNativeBrowserControl(BrowserControl bc); - - public Object getNativeEventThread(); } diff --git a/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/BookmarksImpl.java b/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/BookmarksImpl.java index ed2bfc49cf336..9f9df2cc82414 100644 --- a/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/BookmarksImpl.java +++ b/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/BookmarksImpl.java @@ -1,5 +1,4 @@ -/* -*- 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 @@ -77,10 +76,12 @@ public BookmarksImpl(WrapperFactory yourFactory) } public void startup() { + Assert.assert_it(isNativeEventThread()); nativeStartup(getWrapperFactory().getNativeWrapperFactory()); } public void shutdown() { + Assert.assert_it(isNativeEventThread()); nativeShutdown(getWrapperFactory().getNativeWrapperFactory()); } @@ -152,16 +153,24 @@ public TreeModel getBookmarks() throws IllegalStateException getWrapperFactory().verifyInitialized(); if (null == bookmarksTree) { - int nativeBookmarks; TreeNode root; - if (-1 == - (nativeBookmarks = - nativeGetBookmarks(getWrapperFactory().getNativeWrapperFactory()))) { + Integer nativeBookmarks = (Integer) + NativeEventThread.instance.pushBlockingWCRunnable(new WCRunnable() { + public Object run() { + Integer result = + new Integer(nativeGetBookmarks(getWrapperFactory(). + getNativeWrapperFactory())); + return result; + } + }); + + if (-1 == nativeBookmarks.intValue()) { throw new IllegalStateException("BookmarksImpl.getBookmarks(): Can't get bookmarks from native browser."); } // if we can't create a root, or we can't create a tree if ((null == (root = new BookmarkEntryImpl(getWrapperFactory().getNativeWrapperFactory(), - nativeBookmarks, null))) || + nativeBookmarks.intValue(), + null))) || (null == (bookmarksTree = new DefaultTreeModel(root)))) { throw new IllegalStateException("BookmarksImpl.getBookmarks(): Can't create RDFTreeModel."); } @@ -181,13 +190,23 @@ public void removeBookmark(BookmarkEntry bookmark) public BookmarkEntry newBookmarkEntry(String url) { + ParameterCheck.nonNull(url); BookmarkEntry result = null; + final String finalUrl = new String(url); getBookmarks(); - int newNode; - - if (-1 != (newNode = nativeNewRDFNode(getNativeBrowserControl(), url, false))) { + Integer newNode = (Integer) + NativeEventThread.instance.pushBlockingWCRunnable(new WCRunnable() { + public Object run() { + Integer result = + new Integer(nativeNewRDFNode(getNativeBrowserControl(), + finalUrl, false)); + return result; + } + }); + + if (-1 != newNode.intValue()) { result = new BookmarkEntryImpl(getNativeBrowserControl(), - newNode, null); + newNode.intValue(), null); // use put instead of setProperty for jdk1.1.x compatibility. result.getProperties().put(BookmarkEntry.NAME, url); result.getProperties().put(BookmarkEntry.URL, url); diff --git a/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/EventRegistrationImpl.java b/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/EventRegistrationImpl.java index 1468d3ebe4006..dd8c03393e7eb 100644 --- a/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/EventRegistrationImpl.java +++ b/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/EventRegistrationImpl.java @@ -81,7 +81,7 @@ public EventRegistrationImpl(WrapperFactory yourFactory, super(yourFactory, yourBrowserControl); // pull out the NativeEventThread from the WrapperFactory - nativeEventThread = getNativeEventThread(); + nativeEventThread = NativeEventThread.instance; } public void delete() @@ -265,7 +265,7 @@ public static void main(String [] args) Log.setApplicationName("EventRegistrationImpl"); Log.setApplicationVersion("0.0"); - Log.setApplicationVersionDate("$Id: EventRegistrationImpl.java,v 1.4 2004/04/15 22:58:06 edburns%acm.org Exp $"); + Log.setApplicationVersionDate("$Id: EventRegistrationImpl.java,v 1.5 2004/04/17 21:25:11 edburns%acm.org Exp $"); try { org.mozilla.webclient.BrowserControlFactory.setAppData(args[0]); diff --git a/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/ImplObjectNative.java b/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/ImplObjectNative.java index 4b85075311323..7dde44dd83aaa 100644 --- a/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/ImplObjectNative.java +++ b/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/ImplObjectNative.java @@ -99,9 +99,9 @@ protected int getNativeBrowserControl() { return nativeWebShell; } -protected NativeEventThread getNativeEventThread() { - return (NativeEventThread) - getWrapperFactory().getNativeEventThread(); +protected boolean isNativeEventThread() { + return (Thread.currentThread() == NativeEventThread.instance); } + } // end of class ImplObject diff --git a/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/NativeEventThread.java b/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/NativeEventThread.java index 471bbb4c5872f..1e75df99af32c 100644 --- a/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/NativeEventThread.java +++ b/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/NativeEventThread.java @@ -47,7 +47,7 @@ /** *

This is a singleton class. All native events pass thru this class - * by virtue of the {@link #pushRunnable} or {@link pushNotifyRunnable} + * by virtue of the {@link #pushRunnable} or {@link pushBlockingWCRunnable} * methods.

*/ @@ -56,18 +56,17 @@ public class NativeEventThread extends Thread { // // Class variables // + + static NativeEventThread instance = null; // // Attribute ivars // - /** - * store the exception property, set when running a Runnable causes - * an exception. - */ + private Object blockingResult; + + private Exception blockingException; - private Exception exception; - // // Relationship ivars // @@ -77,7 +76,7 @@ public class NativeEventThread extends Thread { private BrowserControlCanvas browserControlCanvas; - private Stack runnablesWithNotify; + private Stack blockingRunnables; private Stack runnables; @@ -93,12 +92,14 @@ public NativeEventThread(String threadName, WrapperFactory yourFactory, int yourNativeWrapperFactory) { super(threadName); + Assert.assert_it(null == instance); + instance = this; ParameterCheck.nonNull(yourFactory); wrapperFactory = yourFactory; nativeWrapperFactory = yourNativeWrapperFactory; - runnablesWithNotify = new Stack(); + blockingRunnables = new Stack(); runnables = new Stack(); } @@ -127,33 +128,18 @@ public void delete() { wrapperFactory = null; } - public Exception getAndClearException() { - synchronized (this) { - Exception result = exception; - exception = null; - } - return exception; - } - - public void setException(Exception e) { - synchronized (this) { - exception = e; - } - } - // // Methods from Thread // /** - * This method is the heart of webclient. It is called from - * {@link WrapperFactoryImpl#getNativeEventThread}. It calls - * nativeStartup, which does the per-window initialization, including - * creating the native event queue which corresponds to this instance, - * then enters into an infinite loop where processes native events, then - * checks to see if there are any listeners to add, and adds them if - * necessary. + * This method is the heart of webclient. It is called indirectly from + * {@link WrapperFactoryImpl#initialize}. It calls nativeStartup, which + * does the per-window initialization, including creating the native + * event queue which corresponds to this instance, then enters into an + * infinite loop where processes native events, then checks to see if + * there are any listeners to add, and adds them if necessary. * @see nativeProcessEvents @@ -164,7 +150,16 @@ public void setException(Exception e) { public void run() { // our owner must have put an event in the queue - Assert.assert_it(!runnablesWithNotify.empty()); + Assert.assert_it(!runnables.empty()); + ((Runnable)runnables.pop()).run(); + synchronized (wrapperFactory) { + try { + wrapperFactory.notify(); + } + catch (Exception e) { + System.out.println("NativeEventThread.run: exception trying to send notify() to WrapperFactoryImpl on startup:" + e + " " + e.getMessage()); + } + } // // Execute the event-loop. @@ -193,16 +188,32 @@ public void run() if (!runnables.empty()) { ((Runnable)runnables.pop()).run(); } - if (!runnablesWithNotify.empty()) { - ((Runnable)runnablesWithNotify.pop()).run(); - synchronized(wrapperFactory) { - try { - wrapperFactory.notify(); - } - catch (Exception e) { - System.out.println("NativeEventThread.run: Exception: trying to send notify() to wrapperFactory: " + e + " " + e.getMessage()); - } + if (!blockingRunnables.empty()) { + try { + blockingException = null; + blockingResult = + ((WCRunnable)blockingRunnables.pop()).run(); } + catch (RuntimeException e) { + blockingException = e; + } + // notify the pushBlockingWCRunnable() method. + try { + notify(); + } + catch (Exception e) { + System.out.println("NativeEventThread.run: Exception: trying to notify for blocking result:" + e + " " + e.getMessage()); + } + // wait for the result to be grabbed. This prevents the + // results from getting mixed up. + try { + wait(); + } + catch (Exception e) { + System.out.println("NativeEventThread.run: Exception: trying to waiting for pushBlockingWCRunnable:" + e + " " + e.getMessage()); + } + + } nativeProcessEvents(nativeWrapperFactory); } @@ -223,10 +234,32 @@ void pushRunnable(Runnable toInvoke) { } } - void pushNotifyRunnable(Runnable toInvoke) { + Object pushBlockingWCRunnable(WCRunnable toInvoke) { + Object result = null; + RuntimeException e = null; synchronized (this) { - runnablesWithNotify.push(toInvoke); + blockingRunnables.push(toInvoke); + try { + wait(); + } + catch (Exception se) { + System.out.println("NativeEventThread.pushBlockingWCRunnable: Exception: while waiting for blocking result: " + se + " " + se.getMessage()); + } + result = blockingResult; + if (null != blockingException) { + e = new RuntimeException(blockingException); + } + try { + notify(); + } + catch (Exception se) { + System.out.println("NativeEventThread.pushBlockingWCRunnable: Exception: trying to send notify() to NativeEventThread: " + se + " " + se.getMessage()); + } + } + if (null != e) { + throw e; } + return result; } /** diff --git a/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/NavigationImpl.java b/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/NavigationImpl.java index 6679f3ca25247..83e84597c0f07 100644 --- a/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/NavigationImpl.java +++ b/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/NavigationImpl.java @@ -1,5 +1,4 @@ -/* -*- 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 @@ -85,13 +84,12 @@ public void loadURL(String absoluteURL) final int bc = getNativeBrowserControl(); final String url = new String(absoluteURL); Assert.assert_it(-1 != bc); - - Runnable loadURL = new Runnable() { - public void run() { - NavigationImpl.this.nativeLoadURL(bc, url); - } - }; - getNativeEventThread().pushRunnable(loadURL); + + NativeEventThread.instance.pushRunnable(new Runnable() { + public void run() { + NavigationImpl.this.nativeLoadURL(bc, url); + } + }); } public void loadFromStream(InputStream stream, String uri, @@ -228,7 +226,7 @@ public static void main(String [] args) Log.setApplicationName("NavigationImpl"); Log.setApplicationVersion("0.0"); - Log.setApplicationVersionDate("$Id: NavigationImpl.java,v 1.4 2004/04/15 22:58:06 edburns%acm.org Exp $"); + Log.setApplicationVersionDate("$Id: NavigationImpl.java,v 1.5 2004/04/17 21:25:11 edburns%acm.org Exp $"); try { org.mozilla.webclient.BrowserControlFactory.setAppData(args[0]); diff --git a/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/PreferencesImpl.java b/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/PreferencesImpl.java index f41b48b1e147a..86d531459b725 100644 --- a/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/PreferencesImpl.java +++ b/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/PreferencesImpl.java @@ -1,5 +1,4 @@ -/* -*- 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 @@ -106,31 +105,55 @@ public void setPref(String prefName, String prefValue) if (null == prefName) { return; } + final String finalName = new String(prefName); // determine the type of pref value: String, boolean, integer try { - Integer intVal = Integer.valueOf(prefValue); - nativeSetIntPref(getWrapperFactory().getNativeWrapperFactory(), prefName, intVal.intValue()); + final Integer intVal = Integer.valueOf(prefValue); + NativeEventThread.instance.pushBlockingWCRunnable(new WCRunnable() { + public Object run() { + nativeSetIntPref(getWrapperFactory().getNativeWrapperFactory(), finalName, intVal.intValue()); + return null; + } + }); } catch (NumberFormatException e) { // it's not an integer if (null != prefValue && (prefValue.equals("true") || prefValue.equals("false"))) { - Boolean boolVal = Boolean.valueOf(prefValue); - nativeSetBoolPref(getWrapperFactory().getNativeWrapperFactory(), prefName, - boolVal.booleanValue()); + final Boolean boolVal = Boolean.valueOf(prefValue); + NativeEventThread.instance.pushBlockingWCRunnable(new WCRunnable(){ + public Object run() { + nativeSetBoolPref(getWrapperFactory().getNativeWrapperFactory(), + finalName, boolVal.booleanValue()); + return null; + } + }); } else { // it must be a string - nativeSetUnicharPref(getWrapperFactory().getNativeWrapperFactory(), prefName, prefValue); - } + final String finalValue = (null != prefValue) ? + new String(prefValue) : null; + NativeEventThread.instance.pushBlockingWCRunnable(new WCRunnable(){ + public Object run() { + nativeSetUnicharPref(getWrapperFactory().getNativeWrapperFactory(), finalName, finalValue); + return null; + } + }); + } } } public Properties getPrefs() { - props = nativeGetPrefs(getWrapperFactory().getNativeWrapperFactory(), props); - //Properties result = new Properties(); - // result.put("webclientpref", "webclient_value"); + props = (Properties) + NativeEventThread.instance.pushBlockingWCRunnable(new WCRunnable() { + public Object run() { + Properties result = + nativeGetPrefs(getWrapperFactory().getNativeWrapperFactory(), + PreferencesImpl.this.props); + return result; + } + }); return props; } diff --git a/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/ProfileManagerImpl.java b/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/ProfileManagerImpl.java index 1933c95ae71b4..f6cdf3f4f8187 100644 --- a/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/ProfileManagerImpl.java +++ b/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/ProfileManagerImpl.java @@ -1,4 +1,4 @@ -/* -*- 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 @@ -46,45 +46,76 @@ public ProfileManagerImpl(WrapperFactory yourFactory) } public void startup() { + Assert.assert_it(isNativeEventThread()); nativeStartup(getWrapperFactory().getNativeWrapperFactory(), null, null); } public void shutdown() { + Assert.assert_it(isNativeEventThread()); nativeShutdown(getWrapperFactory().getNativeWrapperFactory()); } public int getProfileCount() { - return nativeGetProfileCount(getWrapperFactory().getNativeWrapperFactory()); + Integer result = (Integer) + NativeEventThread.instance.pushBlockingWCRunnable(new WCRunnable() { + public Object run() { + Integer count = new Integer(nativeGetProfileCount(getWrapperFactory().getNativeWrapperFactory())); + return count; + } + }); + return result.intValue(); } public String [] getProfileList() { - String [] list = null; - list = nativeGetProfileList(getWrapperFactory().getNativeWrapperFactory()); + String [] list = + (String []) NativeEventThread.instance.pushBlockingWCRunnable(new WCRunnable() { + public Object run() { + Object result = nativeGetProfileList(getWrapperFactory().getNativeWrapperFactory()); + return result; + } + }); return list; } public boolean profileExists(String profileName) { - boolean exists = false; - exists = nativeProfileExists(getWrapperFactory().getNativeWrapperFactory(), - profileName); - return exists; + ParameterCheck.nonNull(profileName); + final String finalStr = new String(profileName); + Boolean exists = (Boolean) NativeEventThread.instance.pushBlockingWCRunnable(new WCRunnable() { + public Object run() { + Boolean result = new Boolean(nativeProfileExists(getWrapperFactory().getNativeWrapperFactory(), + finalStr)); + return result; + } + }); + return exists.booleanValue(); } public String getCurrentProfile() { - String currProfile = null; - currProfile = - nativeGetCurrentProfile(getWrapperFactory().getNativeWrapperFactory()); + String currProfile = (String) + NativeEventThread.instance.pushBlockingWCRunnable(new WCRunnable() { + public Object run() { + Object result = nativeGetCurrentProfile(getWrapperFactory().getNativeWrapperFactory()); + return result; + } + }); return currProfile; } public void setCurrentProfile(String profileName) { - nativeSetCurrentProfile(getWrapperFactory().getNativeWrapperFactory(), - profileName); + ParameterCheck.nonNull(profileName); + final String finalStr = new String(profileName); + NativeEventThread.instance.pushBlockingWCRunnable(new WCRunnable() { + public Object run() { + nativeSetCurrentProfile(getWrapperFactory().getNativeWrapperFactory(), + finalStr); + return null; + } + }); } public void createNewProfile(String profileName, @@ -92,21 +123,50 @@ public void createNewProfile(String profileName, String langcode, boolean useExistingDir) { - nativeCreateNewProfile(getWrapperFactory().getNativeWrapperFactory(), - profileName, nativeProfileDir, langcode, - useExistingDir); + ParameterCheck.nonNull(profileName); + final String finalProfileName = new String(profileName); + final String finalProfileDir = (null != nativeProfileDir) ? + new String(nativeProfileDir) : null; + final String finalLangcode = (null != langcode) ? + new String(langcode) : null; + final boolean finalExistingDir = useExistingDir; + NativeEventThread.instance.pushBlockingWCRunnable(new WCRunnable() { + public Object run() { + nativeCreateNewProfile(getWrapperFactory().getNativeWrapperFactory(), + finalProfileName, finalProfileDir, + finalLangcode, finalExistingDir); + return null; + } + }); } public void renameProfile(String currName, String newName) { - nativeRenameProfile(getWrapperFactory().getNativeWrapperFactory(), - currName, newName); + ParameterCheck.nonNull(currName); + ParameterCheck.nonNull(newName); + final String finalCurrName = new String(currName); + final String finalNewName = new String(newName); + NativeEventThread.instance.pushBlockingWCRunnable(new WCRunnable() { + public Object run() { + nativeRenameProfile(getWrapperFactory().getNativeWrapperFactory(), + finalCurrName, finalNewName); + return null; + } + }); } public void deleteProfile(String profileName, boolean canDeleteFiles) { - nativeDeleteProfile(getWrapperFactory().getNativeWrapperFactory(), - profileName, canDeleteFiles); + ParameterCheck.nonNull(profileName); + final String finalProfileName = new String(profileName); + final boolean finalCanDeleteFiles = canDeleteFiles; + NativeEventThread.instance.pushBlockingWCRunnable(new WCRunnable() { + public Object run() { + nativeDeleteProfile(getWrapperFactory().getNativeWrapperFactory(), + finalProfileName, finalCanDeleteFiles); + return null; + } + }); } public void cloneProfile(String currName) diff --git a/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/RDFEnumeration.java b/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/RDFEnumeration.java index feb6333324f3c..7c45184d1ae96 100644 --- a/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/RDFEnumeration.java +++ b/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/RDFEnumeration.java @@ -1,5 +1,4 @@ -/* -*- 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 @@ -103,7 +102,12 @@ public RDFEnumeration(int yourNativeContext, protected void finalize() throws Throwable { - nativeFinalize(nativeContext); + NativeEventThread.instance.pushBlockingWCRunnable(new WCRunnable() { + public Object run() { + nativeFinalize(RDFEnumeration.this.nativeContext); + return null; + } + }); super.finalize(); } @@ -114,19 +118,35 @@ protected void finalize() throws Throwable public boolean hasMoreElements() { Assert.assert_it(-1 != nativeRDFNode); - return nativeHasMoreElements(nativeContext, nativeRDFNode); + Boolean result = (Boolean) + NativeEventThread.instance.pushBlockingWCRunnable(new WCRunnable() { + public Object run() { + Boolean result = + new Boolean(nativeHasMoreElements(RDFEnumeration.this.nativeContext, + RDFEnumeration.this.nativeRDFNode)); + return result; + } + }); + return result.booleanValue(); } public Object nextElement() { Assert.assert_it(null != parent); Object result = null; - int nextNativeRDFNode; - - if (-1 != (nextNativeRDFNode = nativeNextElement(nativeContext, - nativeRDFNode))) { - result = parent.newRDFTreeNode(nativeContext, - nextNativeRDFNode, parent); + Integer nextNativeRDFNode = (Integer) + NativeEventThread.instance.pushBlockingWCRunnable(new WCRunnable() { + public Object run() { + Integer result = + new Integer(nativeNextElement(RDFEnumeration.this.nativeContext, + RDFEnumeration.this.nativeRDFNode)); + return result; + } + }); + + if (-1 != nextNativeRDFNode.intValue()) { + result = parent.newRDFTreeNode(nativeContext, + nextNativeRDFNode.intValue(), parent); } return result; diff --git a/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/WCRunnable.java b/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/WCRunnable.java new file mode 100644 index 0000000000000..e0c6be2da55e7 --- /dev/null +++ b/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/WCRunnable.java @@ -0,0 +1,37 @@ +/* + * 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 + * Ashutosh Kulkarni + * Jason Mawdsley + * Louis-Philippe Gagnon + */ + +package org.mozilla.webclient.impl.wrapper_native; + +/** + *

Extend the concept of java.lang.Runnable to allow for + * the thing to have a return Object.

+ * + */ + +public interface WCRunnable { + + public Object run(); + +} diff --git a/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/WrapperFactoryImpl.java b/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/WrapperFactoryImpl.java index abfb783838e96..de9443f3a5203 100644 --- a/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/WrapperFactoryImpl.java +++ b/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/WrapperFactoryImpl.java @@ -138,27 +138,13 @@ public BrowserControl newBrowserControl() throws InstantiationException, Illegal BrowserControl result = new BrowserControlImpl(this); final int nativeBrowserControl = nativeCreateBrowserControl(); - Runnable runnable = new Runnable() { - public void run() { + eventThread.pushBlockingWCRunnable(new WCRunnable() { + public Object run() { WrapperFactoryImpl.this.nativeInitBrowserControl(nativeWrapperFactory, nativeBrowserControl); + return null; } - }; - eventThread.pushNotifyRunnable(runnable); + }); - synchronized (this) { - try { - wait(); - } - catch (Exception e) { - System.out.println("WrapperFactoryImpl.initialize(): interrupted while waiting\n\t for NativeEventThread to notify(): " + e + - " " + e.getMessage()); - } - } - Exception e = eventThread.getAndClearException(); - if (null != e) { - throw new IllegalStateException(e.getMessage()); - } - browserControls.put(result, new Integer(nativeBrowserControl)); return result; } @@ -169,27 +155,12 @@ public void deleteBrowserControl(BrowserControl toDelete) { if (null != (nativeBc = (Integer) browserControls.get(toDelete))) { final int nativeBrowserControl = nativeBc.intValue(); - - Runnable runnable = new Runnable() { - public void run() { + eventThread.pushBlockingWCRunnable(new WCRunnable() { + public Object run() { WrapperFactoryImpl.this.nativeDestroyBrowserControl(nativeBrowserControl); + return null; } - }; - eventThread.pushNotifyRunnable(runnable); - - synchronized (this) { - try { - wait(); - } - catch (Exception e) { - System.out.println("WrapperFactoryImpl.deleteBrowserControl(): interrupted while waiting\n\t for NativeEventThread to notify(): " + e + - " " + e.getMessage()); - } - } - Exception e = eventThread.getAndClearException(); - if (null != e) { - throw new RuntimeException(e); - } + }); } } @@ -288,16 +259,15 @@ public void initialize(String verifiedBinDirAbsolutePath) throws SecurityExcepti nativeWrapperFactory); final String finalStr = new String(verifiedBinDirAbsolutePath); - Runnable runnable = new Runnable() { + + eventThread.pushRunnable(new Runnable() { public void run() { WrapperFactoryImpl.this.nativeAppInitialize(finalStr, nativeWrapperFactory, eventThread); } - }; + }); - eventThread.pushNotifyRunnable(runnable); - eventThread.start(); synchronized (this) { try { @@ -306,12 +276,9 @@ public void run() { catch (Exception e) { System.out.println("WrapperFactoryImpl.initialize(): interrupted while waiting\n\t for NativeEventThread to notify(): " + e + " " + e.getMessage()); + throw new UnsatisfiedLinkError(e.getMessage()); } } - Exception e = eventThread.getAndClearException(); - if (null != e) { - throw new UnsatisfiedLinkError(e.getMessage()); - } // // create app singletons @@ -323,34 +290,24 @@ public void run() { bookmarks = new BookmarksImpl(this); Assert.assert_it(null != bookmarks); - runnable = new Runnable() { - public void run() { - - ((Service)WrapperFactoryImpl.this.profileManager).startup(); - ((Service)WrapperFactoryImpl.this.prefs).startup(); - - ((Service)WrapperFactoryImpl.this.bookmarks).startup(); - - WrapperFactoryImpl.this.nativeAppSetup(nativeWrapperFactory); - } - }; - eventThread.pushNotifyRunnable(runnable); - - synchronized (this) { - // This causes the above Runnable to be executed. - try { - wait(); - } - catch (Exception exp) { - System.out.println("WrapperFactoryImpl.initialize(): interrupted while waiting\n\t for NativeEventThread to notify(): " + exp + - " " + exp.getMessage()); - } + initialized = true; + try { + eventThread.pushBlockingWCRunnable(new WCRunnable() { + public Object run() { + + ((Service)WrapperFactoryImpl.this.profileManager).startup(); + ((Service)WrapperFactoryImpl.this.prefs).startup(); + ((Service)WrapperFactoryImpl.this.bookmarks).startup(); + + WrapperFactoryImpl.this.nativeAppSetup(nativeWrapperFactory); + return null; + } + }); } - e = eventThread.getAndClearException(); - if (null != e) { - throw new UnsatisfiedLinkError(e.getMessage()); + catch (RuntimeException e) { + initialized = false; + System.out.println("WrapperFactoryImpl.initialize: Can't start up singleton services: " + e + " " + e.getMessage()); } - initialized = true; } public void verifyInitialized() throws IllegalStateException @@ -362,8 +319,8 @@ public void verifyInitialized() throws IllegalStateException public void terminate() throws Exception { - eventThread.pushNotifyRunnable(new Runnable() { - public void run() { + eventThread.pushBlockingWCRunnable(new WCRunnable() { + public Object run() { Assert.assert_it(null != bookmarks); ((Service)bookmarks).shutdown(); ((ImplObject)bookmarks).delete(); @@ -379,32 +336,14 @@ public void run() { ((ImplObject)profileManager).delete(); profileManager = null; nativeTerminate(nativeWrapperFactory); + return null; } }); - - synchronized (this) { - try { - wait(); - } - catch (Exception e) { - System.out.println("WrapperFactoryImpl.initialize(): interrupted while waiting\n\t for NativeEventThread to notify(): " + e + - " " + e.getMessage()); - } - } - Exception e = eventThread.getAndClearException(); - if (null != e) { - throw new IllegalStateException(e.getMessage()); - } + eventThread.delete(); eventThread = null; - } - public Object getNativeEventThread() { - verifyInitialized(); - return eventThread; - } - public int getNativeWrapperFactory() { return nativeWrapperFactory; } diff --git a/java/webclient/src_moz/PreferencesImpl.cpp b/java/webclient/src_moz/PreferencesImpl.cpp index e120bf77ae3b0..6818052c1eb9b 100644 --- a/java/webclient/src_moz/PreferencesImpl.cpp +++ b/java/webclient/src_moz/PreferencesImpl.cpp @@ -452,7 +452,6 @@ static int PR_CALLBACK prefChanged(const char *name, void *closure) if (nsnull == name || nsnull == closure) { return NS_ERROR_NULL_POINTER; } - nsresult rv; int result; JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION); peStruct *pes = (peStruct *) closure;