JDK-6643769 : Applet main windows steals focus on Popup windows which is running Applet.
  • Type: Bug
  • Component: deploy
  • Sub-Component: plugin
  • Affected Version: 1.4.2_21,5.0,5.0u17,6
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: windows,windows_xp,windows_vista
  • CPU: generic,x86
  • Submitted: 2007-12-19
  • Updated: 2011-01-19
  • Resolved: 2009-01-30
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other Other JDK 6 JDK 7
1.4.2_23Fixed 5.0u18Fixed 6u11-revFixed 7Fixed
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :
1.4.2_06, 1.5.0_06-13, 1.6.0, and 1.6.0_1-3

ADDITIONAL OS VERSION INFORMATION :
Windows XP

A DESCRIPTION OF THE PROBLEM :
User run the Applet on main page, and then he pop up windows which run Applet also. When the main page is refreshed automatically, the main page steal focus from the pop up windows.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Step to Reproduce:

1. Launch TestMainApplet.html
2. Click link ���Test Popup with Applet��� and focus this windows.
3. Wait 5 seconds.

Note: From step 2, if you click with ���Test Popup without Applet���, you cannot replicate problem since 1.5.0.



EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Whenever TestMainApplet.html is refreshed, the ���Test Popup with Applet��� window is still focused.
ACTUAL -
Whenever TestMainApplet.html is refreshed, the ���Main Test Refresh��� window is focused back.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
//Source code HelloWorldApplet.java:

import java.applet.*;
import java.awt.*;
  
public class HelloWorldApplet extends Applet
{ 
     public void init()
     {
     }
  
     public void stop()
     {
     }

     public void paint(Graphics g)
     {
      g.drawString("Hell World",20,20);
     }

} 

//Source code HelloWorldApplet2.java:

import java.applet.*;
import java.awt.*;
  
public class HelloWorldApplet2 extends Applet
{ 
     public void init()
     {
     }
  
     public void stop()
     {
     }

     public void paint(Graphics g)
     {
      g.drawString("Hell World2",0,20);
     }

} 

//Source code TestMainApplet.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> Main Test Refresh Applet </TITLE>
<meta http-equiv="REFRESH" content="5">
</HEAD>
<BODY>
<applet code="HelloWorldApplet.class">
<param name="cache_archive_ex" value="HelloWorldApplet.jar">
<param name=initial_focus value="true">
</applet>
<a href="TestApplet2.html" target="Test">Test Popup with Applet</a>
<a href="TestPopupwithoutApplet.html" target="Test">Test Popup without Applet</a>
</BODY>
</HTML>
////////////////////////

//Source code TestApplet2.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Test Popup with Applet </TITLE>
<META NAME="Generator" CONTENT="EditPlus">

</HEAD>

<BODY>
<applet code="HelloWorldApplet2.class">
<param name="cache_archive_ex" value="HelloWorldApplet.jar">
</applet>
</BODY>
</HTML>
///////////////////////////////////


//Source code TestPopupwithoutApplet.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> Test Popup withou Applet </TITLE>
</HEAD>
<BODY>
<p>Popup without Applet</p>
</BODY>
</HTML>
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Disable refresh automatically on main page.

Comments
EVALUATION A fix is in the InPlaceActivate method of our activeX control, we should check if the iVerb is OLEIVERB_SHOW before calling ::SetFocus. Same fix applies to both old and new plugin.
18-11-2008

EVALUATION By the way, this fix works in conjunction with specifying the "initial_focus" applet parameter to be "false", to prevent the plugin from attempting to grab the focus via another synthetic window activation.
12-11-2008

EVALUATION The problem is caused by the synthetic window activations we are asking the AWT to perform on the EmbeddedFrame containing the applet. Commenting out the call to JVMManager.getManager().synthesizeWindowActivation() in IExplorerPlugin.OnFrameWindowActivate(), deploy/src/plugin/share/classes/sun/plugin2/main/server/IExplorerPlugin.java, solves the problem at least with IE 7 on my end. The sending of synthetic window activations upon this event dates back to the classic Java Plug-In (see CAxControl::OnFrameWindowActivate(), deploy/src/plugin/win32/com/iexplorer/AxControl.cpp). However, we found that sending this event upon deactivation was the wrong thing to do earlier in the 6u10 release (see the comments in IExplorerPlugin.OnFrameWindowActivate and bug 6662588) and it may well be that we should simply ignore the OnFrameWindowActivate event altogether. At least in the new plugin the fix appears to be very simple and we should get it in the hands of the customer as quickly as possible to resolve the escalation.
12-11-2008

EVALUATION In the sun.applet.AppletPanel class, on receiving the APPLET_START message the applet requests focus by default. On reloading the applet in the browser, this message is sent to the applet ones again and it requests focus. Distinguish these two cases (first start and reload) is in scope of the plugin, so I'm reassigning the CR. (By the way, the testcase uses initial_focus param set to true in the applet). Why the applet doesn't steal focus from non-applet window since 1.5 I can think of two reasons. 1) In that release there have been changed the way the EmbeddedFrame is activated. 2) The window belongs to a different thread in contrast to the window with applet (the latter has active EmbeddedFrame inside that belongs to the same thread). This problem is a separate issue though.
22-01-2008

EVALUATION I can easily reproduce the problem with at least JDK7. There is no clear specification for this particular case, so I can't say for sure, what is the right behavior: should the main page steal focus or not. My own opinion is it shouldn't, regardless of the second page contains any applet or not.
28-12-2007