Closed Bug 400619 Opened 18 years ago Closed 18 years ago

NPRuntime-based plugins can't query DOM immediately after NPP_SetWindow

Categories

(Core Graveyard :: Plug-ins, defect)

x86
Windows XP
defect
Not set
major

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: kbrussel, Assigned: jst)

Details

(Keywords: regression)

Attachments

(2 files, 1 obsolete file)

User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9a9pre) Gecko/2007102105 Minefield/3.0a9pre Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9a9pre) Gecko/2007102105 Minefield/3.0a9pre It appears there is a race condition in the initialization of NPRuntime-based plug-ins where they are not able to make certain queries of the DOM via JavaScript immediately after the browser calls NPP_SetWindow, which should ordinarily indicate that the plug-in is fully initialized. Additionally, it appears that attempts to query the DOM at this point in initialization cause an error state to be set in the JavaScript interpreter. The only apparent way to clear this error state is to invoke the JavaScript interpreter manually. The attached test cases illustrate the problem. There are two pairs of tests. AppletsTest.html and AppletsTest2.html attempt to query the array window.document.applets from Java. The Java-side source code is in AppletsTest.java. AppletsTest makes this query very early in initialization. If you set the Java Console to be opened in the Java Control Panel you will see a JavaScript exception being thrown indicating that the NPN_HasProperty call of "applets" against the document is failing. This failed call sets an error condition in the JavaScript engine which can be shown by opening the Error Console in the Tools menu and clicking the "Print number of applets" or "Print number of forms" buttons on the page. The first click of either of these buttons will print an error, clearing the error condition. The second click will succeed. After the first success, even the button "Print number of applets from Java", which executes the same work as was done during initialization of the applet, will work. AppletsTest2 doesn't query the DOM during initialization of the applet. All three buttons work correctly. This indicates that it's the query of the DOM during plug-in bringup that causes the problems. FormsTest and FormsTest2 do the same thing, only they query window.document.forms rather than window.document.applets. FormsTest provokes the failure by making the DOM query during applet initialization, while FormsTest2 doesn't and both buttons work correctly. Since this test case fails similarly and doesn't touch the window.document.applets array, this strongly indicates a general bug in the initialization of NPRuntime-based plugins rather than a Java-specific problem. Note also that the fetch of the "document" property of the window works, but that fetches of the "applets" or "forms" arrays of the document fail. This failure occurs with the new NPRuntime-based Java Plug-In, but not with the old OJI-based Java Plug-In. It occurs on Firefox 3 builds as far back as August 27, indicating that it isn't related to any recent LiveConnect work to enable the NPRuntime-based Java Plug-In, and is instead a general bug in the scripting of NPRuntime-based plug-ins. It also occurs on the latest Firefox 3 nightly build. Reproducible: Always Steps to Reproduce: 1. Install the new NPRuntime-based Java Plug-In. 2. Enable the Java Console in the Java Control Panel. 3. Extract the attached test cases. 4. Navigate to AppletsTest.html. Note exception thrown in Java Control Panel. 5. Open Tools -> Error Console. Click either "Print number of applets" or "Print number of forms". Note error printed. 6. Click either of these buttons again. Note that they now work correctly. In addition, the "Print number of applets from Java" button now works correctly. 7. Compare to AppletsTest2.html, which does not perform DOM queries during applet initialization. All buttons work as soon as the page is loaded. Repeat with FormsTest.html and FormsTest2.html, indicating that this is not a problem specific to the window.document.applets property. Actual Results: DOM queries are broken during initialization of NPRuntime-based plug-ins. Expected Results: DOM queries work during initialization of NPRuntime-based plug-ins.
Attached file Test cases
Component: General → Plug-ins
Product: Firefox → Core
QA Contact: general → plugins
Version: unspecified → Trunk
After more investigation, the problem appears to be that the plug-in can not make queries of the DOM until certain JavaScript operations have been performed: either querying of certain DOM elements from pure JavaScript, or calling into the plug-in from JavaScript via NPRuntime. The problem appears to be completely deterministic and not a race condition.
Attached patch Fix.Splinter Review
This is a simple missing JS context push/pop, so security code down the rowad from NP_HasProperty() was failing since there was no JS context on the stack. All other code around here does the right thing, this AutoJSContextPusher was just missing from this function.
Assignee: nobody → jst
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true
Attachment #285786 - Flags: superreview?(jonas)
Attachment #285786 - Flags: review?(jonas)
Attachment #285786 - Flags: superreview?(jonas)
Attachment #285786 - Flags: superreview+
Attachment #285786 - Flags: review?(jonas)
Attachment #285786 - Flags: review+
Comment on attachment 285786 [details] [diff] [review] Fix. Requesting permission to land this for beta. This in an of itself may not be a beta blocker, but getting this in for the beta will significantly help Sun with their development and QA work on the new NPRuntime enabled Java plugin. And this is a trivial and very safe change.
Attachment #285786 - Flags: approval1.9?
Flags: blocking1.9+
Keywords: regression
Attachment #285786 - Flags: approvalM9?
Comment on attachment 285786 [details] [diff] [review] Fix. a=endgame drivers for M9
Attachment #285786 - Flags: approvalM9?
Attachment #285786 - Flags: approvalM9+
Attachment #285786 - Flags: approval1.9?
Attachment #285786 - Flags: approval1.9+
Fixed.
Status: ASSIGNED → RESOLVED
Closed: 18 years ago
Resolution: --- → FIXED
Comment on attachment 285795 [details] Second test case using JSObject.call and eval This testcase is obsolete as far as this bug goes. It's tracked in bug 400771.
Attachment #285795 - Attachment is obsolete: true
Fix verified with FF 3 nightly build from 11/1/2007. Thanks for the prompt fix.
Product: Core → Core Graveyard
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: