From 3638d5ef12d4b4262c7e4ee067f67c3e3cc87aef Mon Sep 17 00:00:00 2001 From: "smfr%smfr.org" Date: Sat, 6 Aug 2005 20:28:42 +0000 Subject: [PATCH] Fix bug 302962. When someone calls Activate() or Deactivate() on an nsWebBrowser which doesn't have a content viewer yet (and hence no pres shell), don't just bail because nsGlobalWindow will complain. Instead, change nsDocShell to make the content viewer on demand, and go ahead and pass the activate/deactivate onto the dom window. This fixes a serious focus bug in Camino. r/sr=bryner, a=bsmdedberg. git-svn-id: svn://10.0.0.236/trunk@177273 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/docshell/base/nsDocShell.cpp | 18 +++++-------- mozilla/dom/src/base/nsGlobalWindow.cpp | 7 ++--- .../browser/webBrowser/nsWebBrowser.cpp | 27 ++++++------------- 3 files changed, 17 insertions(+), 35 deletions(-) diff --git a/mozilla/docshell/base/nsDocShell.cpp b/mozilla/docshell/base/nsDocShell.cpp index a40b0950276..36ae7c4dfe8 100644 --- a/mozilla/docshell/base/nsDocShell.cpp +++ b/mozilla/docshell/base/nsDocShell.cpp @@ -1248,21 +1248,17 @@ nsDocShell::GetEldestPresContext(nsPresContext** aPresContext) NS_IMETHODIMP nsDocShell::GetPresContext(nsPresContext ** aPresContext) { - nsresult rv = NS_OK; - NS_ENSURE_ARG_POINTER(aPresContext); *aPresContext = nsnull; - if (mContentViewer) { - nsCOMPtr docv(do_QueryInterface(mContentViewer)); + nsresult rv = EnsureContentViewer(); + if (NS_FAILED(rv)) + return rv; // we're probably being destroyed + + nsCOMPtr docv(do_QueryInterface(mContentViewer)); + NS_ENSURE_TRUE(docv, NS_ERROR_NO_INTERFACE); - if (docv) { - rv = docv->GetPresContext(aPresContext); - } - } - - // Fail silently, if no PresContext is available... - return rv; + return docv->GetPresContext(aPresContext); } NS_IMETHODIMP diff --git a/mozilla/dom/src/base/nsGlobalWindow.cpp b/mozilla/dom/src/base/nsGlobalWindow.cpp index fc7dfdc17b4..5d7ea921dcc 100644 --- a/mozilla/dom/src/base/nsGlobalWindow.cpp +++ b/mozilla/dom/src/base/nsGlobalWindow.cpp @@ -4936,8 +4936,8 @@ nsGlobalWindow::Activate() NS_ENSURE_TRUE(widget, NS_ERROR_FAILURE); return widget->SetFocus(); - */ + nsCOMPtr treeOwnerAsWin; GetTreeOwner(getter_AddRefs(treeOwnerAsWin)); if (treeOwnerAsWin) { @@ -4952,10 +4952,7 @@ nsGlobalWindow::Activate() nsCOMPtr presShell; mDocShell->GetPresShell(getter_AddRefs(presShell)); - if (!presShell) { - NS_WARNING( "no preshell for window" ); - return NS_ERROR_FAILURE; - } + NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE); nsIViewManager* vm = presShell->GetViewManager(); NS_ENSURE_TRUE(vm, NS_ERROR_FAILURE); diff --git a/mozilla/embedding/browser/webBrowser/nsWebBrowser.cpp b/mozilla/embedding/browser/webBrowser/nsWebBrowser.cpp index 4e5396eef51..283ae7cb073 100644 --- a/mozilla/embedding/browser/webBrowser/nsWebBrowser.cpp +++ b/mozilla/embedding/browser/webBrowser/nsWebBrowser.cpp @@ -1787,19 +1787,14 @@ NS_IMETHODIMP nsWebBrowser::Activate(void) if (mWWatch) mWWatch->SetActiveWindow(win); - /* Activate the window itself. Do this only if the PresShell has - been created, since DOMWindow->Activate asserts otherwise. - (This method can be called during window creation before - the PresShell exists. For ex, Windows apps responding to - WM_ACTIVATE). */ - NS_ENSURE_STATE(mDocShell); - nsCOMPtr presShell; - mDocShell->GetPresShell(getter_AddRefs(presShell)); - if(presShell) { - nsCOMPtr privateDOMWindow = do_QueryInterface(win); - if(privateDOMWindow) - privateDOMWindow->Activate(); - } + /* Activate the window itself. Note that this method can be called during + window creation before the PresShell exists (for ex, Windows apps + responding to WM_ACTIVATE), which case nsGlobalWindow::Activate() + will return early. + */ + nsCOMPtr privateDOMWindow = do_QueryInterface(win); + if (privateDOMWindow) + privateDOMWindow->Activate(); } mActivating = PR_FALSE; @@ -1814,12 +1809,6 @@ NS_IMETHODIMP nsWebBrowser::Deactivate(void) This seems harmless and maybe safer, but we have no real evidence either way just yet. */ - NS_ENSURE_STATE(mDocShell); - nsCOMPtr presShell; - mDocShell->GetPresShell(getter_AddRefs(presShell)); - if(!presShell) - return NS_OK; - nsCOMPtr domWindow; GetContentDOMWindow(getter_AddRefs(domWindow)); if (domWindow) {