Open Bug 541923 Opened 14 years ago Updated 2 years ago

focus problem invoking firefox with createprocess

Categories

(Firefox :: General, defect)

3.6 Branch
x86
Windows XP
defect

Tracking

()

UNCONFIRMED

People

(Reporter: wastecontainer, Unassigned)

Details

User-Agent:       Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; User-agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; http://bsalsa.com) ; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)
Build Identifier: 3.6 final (same problem also in 3.0-3.5)

As I understand loadDivertedInBackground option (default false, I set it to true with about:config) should prevent Firefox from getting focus when an external application launches a URL with Firefox.

With loadDivertedInBackground false (default) the Firefox window gets focus. With loadDivertedInBackground true the Firefox window gets NO focus (correctly). The problem is that instead the focus goes to an invisible window of the class FirefoxMessageWindow. In other words, the focus is taken from the app that was active before and goes to nirvana, since an invisible window cannot handle it.

To reproduce:

Use the Win32 API function CreateProcess() to launch Firefox.


Reproducible: Always

Steps to Reproduce:
1.Use the Win32 API function CreateProcess() to launch Firefox
2.After this use the API function GetForeGroundWindow() and you will see the handle of FirefoxMessageWindow is returned.
3.This can be checked with the GetClassName() function.

Actual Results:  
FirefoxMessageWindow steals focus from the active application.

Expected Results:  
FirefoxMessageWindow should never get focus, since it's a hidden messaging window.

Do not steal focus with loadDivertedInBackground == true :)
You assumption about that setting is incorrect. When you open a web page from an external app Firefox will have focus.  A new tab will open for that web page.  The setting determines if that new tab will be opened in the background or become the new current tab.

http://kb.mozillazine.org/About:config_entries

browser.tabs.loadDivertedInBackground

Determines behavior of pages normally meant to open in a new window (such as target="_blank" or from an external program), but that have instead been loaded in a new tab.
True: Load the new tab in the background, leaving focus on the current tab
False (default): Load the new tab in the foreground, taking the focus from the current tab.
Note: Setting this preference to True will still bring the browser to the front when opening links from outside the browser.
Status: UNCONFIRMED → RESOLVED
Closed: 14 years ago
Resolution: --- → INVALID
Status: RESOLVED → VERIFIED
> Note: Setting this preference to True will still bring the browser to the front
> when opening links from outside the browser.

This is definitely not true. I've tested it again 2 minutes ago with Firefox 3.6 on WindowsXP SP3.

1. test: loadDivertedInBackground = false (default)

Open Firefox. Go to another app (so that Firefox window is deactivated) and launch a URL externally (I'm doing it with CreateProcess).

Result: Firefox takes focus back

2. test: loadDivertedInBackground = true

Open Firefox. Go to another app (so that Firefox window is deactivated) and launch a URL externally (I'm doing it with CreateProcess).

Result: Firefox gets NO focus, the Firefox window goes NOT to front and is NOT activated (contrary to your statement). The focus is still removed from the app that had the focus before, but it is set to a window of the class FirefoxMessageWindow, which is hidden. The result is that focus is completely lost for all applications.

It's always reproducible.
Dao 

Do you know what the behavior for loadDivertedInBackground = true is supposed to be?  Is the browser window supposed to get focus or not?
I don't know...

(In reply to comment #2)
> Result: Firefox gets NO focus, the Firefox window goes NOT to front and is NOT
> activated (contrary to your statement).

I can confirm this.

> The focus is still removed from the app
> that had the focus before, but it is set to a window of the class
> FirefoxMessageWindow, which is hidden. The result is that focus is completely
> lost for all applications.

I'm not seeing this. The other application remains focused over here.
(In reply to comment #4)
Ok.  I had found this changeset and was hoping you'd know.
http://hg.mozilla.org/mozilla-central/rev/d05dc3d31c75

The behavior of opening URLs from other applications seems to have changed from earlier versions of Firefox (maybe versions 1 and/or 2) where the browser window would get focus from the other app but the new tab would not get focus.  But the current behavior does make more sense.  I guess the mozillazine knowledge base will need to be updated.

But I also see the focus remaining with the other application when opening a URL from that application with loadDivertedInBackground = true.  I used MS Word and ctrl-clicked on a URL, and I tried opening a link from Thunderbird.  I think the createprocess method used here is the difference.  It's different from the browser being invoked to open a URL from another app. AFAIK in that case the app goes to the OS to ask for a URL to be opened.  And the OS invokes Firefox to open it.
Status: VERIFIED → UNCONFIRMED
Resolution: INVALID → ---
Summary: loadDivertedInBackground option not working correctly → focus problem invoking firefox with createprocess
>I think the createprocess method used here is the difference.
> It's different from the browser being invoked to open a URL from another app

Is there any other way to open an URL with Firefox from an external application besides using CreateProcess()?

I think also CreateProcess() is the problem here, as Firefox seems also to be the only Application that ignores all SW_ directives. E.g. you cannot start Firefox minimized using CreateProcess(), as passing SW_HIDE is ignored (I've tested all 12 SW_ options and none work, all 12 work with Notepad.exe).
Well your assuming that Firefox is installed.  A safer, more user friendly way would be to use the OS to open the default web browser.  For that you can use ShellExecute:

http://support.microsoft.com/kb/224816
http://msdn.microsoft.com/en-us/library/bb762153%28VS.85%29.aspx
No, I'm not assuming it's installed, I'm checking of course first if it's there.

But ShellExecute won't solve the problem at all. ShellExecute is a wrapper for CreateProcess(), it makes an internal CreateProcess() call, so the result will stay exactly the same. To make sure I've tested it few minutes ago. Focus is still lost from my application window and Firefox does not get it either. All SW_ paratemeters are also ignored.
p.s.

My application lets the user choose whether to launch IE, Firefox or the default system browser, so it is user friendly.
What's the current status of the bug? I'm asking because it was set prematurely to solved before.
Version: unspecified → 3.6 Branch
I'm having the same problem in Ubuntu 12.04, Xfce Desktop, Thunderbird 14.0, Firefox 14.0.1.
howdy y'all,

this bug ...
- 775400 – external links sent to firefox cause firefox to steal focus
https://bugzilla.mozilla.org/show_bug.cgi?id=775400

... covers what may be the same thing. focus goes to some non-detectable-by-me thing instead of staying in the source app or going to the firefox window/tab.

should that one be duped to this one? as mlnease pointed out, the behavior has appeared in ff14.0.1. it did NOT occur in ff13. that makes _me_ think the two items are different.

take care,
lee
Same here.

After clicking a link in a Thunderbird message, TB looses focus to a hidden window of the class "FirefoxMessageWindow", width: 121px, height: 33px as reported by AHK Window Spy:

http://i.imgur.com/VjB88r2.png

In order to e.g. delete the current message in TB, after having clicked on a link in that message, first a second click in the message window is required in order to give back focus to TB.
Not shell integration so moving to general since I am unsure what component this should be in
Component: Shell Integration → General

(In reply to Robert Strong (Robert they/them) [:rstrong] (use needinfo to contact me) from comment #14)

Not shell integration so moving to general since I am unsure what component
this should be. might be this problem still exist. http://insurancearcade.com

I’m using WP with cPanel on my host and domain. I’m a newbie and I don’t have much time and resources to learn web design or coding or such. I migrated my http://www.xyguru.com/ blog to an independent domain and literally everything got worse.

  1. Why is editing interface different (worse) than I use in my wp.com blog? wp.com interface was frustrating enough.
    http://www.xyguru.com/services/dynamic-website-development/
  2. I cannot edit my previous posts. I have no idea what’s going on. HTML tab works fine but I cannot edit the post in “preview” tab.
    http://www.xyguru.com/services/html-website-development/
  3. I cannot comment on my own post! It wants me to fill in nonexistent boxes.
    http://www.xyguru.com/services/php-web-development/
  4. Could you tell me how do I make my website Google-free? I don’t want Google analytics, Google fonts or anything Google related because I don’t want surveillance bothering my visitors. http://www.xyguru.com/services/wordpress-website-development/

Yet a lot of plugins seem to be related with Google. I still want to be able to run email notification for subscribers. Google crawlers and indexing are welcome. Anything beyond that I don’t want. http://www.xyguru.com/services/custom-software/

Having these problems, Still dunno what to. Any suggestions will be welcome

Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.