single window mode aviary branch merge. bug 172962, 263689 r=blizzard,bryner

This commit is contained in:
danm-moz%comcast.net 2004-12-07 16:09:34 +00:00
parent bc969ec68e
commit cf9c5debce

View File

@ -39,10 +39,12 @@
#include "XRemoteService.h" #include "XRemoteService.h"
#include "XRemoteContentListener.h" #include "XRemoteContentListener.h"
#include "nsIBrowserDOMWindow.h"
#include <nsIGenericFactory.h> #include <nsIGenericFactory.h>
#include <nsIWebNavigation.h> #include <nsIWebNavigation.h>
#include <nsIDOMWindowInternal.h> #include <nsIDOMWindowInternal.h>
#include <nsIDOMChromeWindow.h>
#include <nsIDocShell.h> #include <nsIDocShell.h>
#include <nsIScriptGlobalObject.h> #include <nsIScriptGlobalObject.h>
#include <nsIBaseWindow.h> #include <nsIBaseWindow.h>
@ -761,6 +763,8 @@ XRemoteService::OpenURL(nsCString &aArgument,
aArgument.Truncate(index); aArgument.Truncate(index);
} }
nsCOMPtr<nsIBrowserDOMWindow> bwin;
// If it's OK to open a new browser window and a new window flag // If it's OK to open a new browser window and a new window flag
// wasn't passed in then try to find a current window. If that's // wasn't passed in then try to find a current window. If that's
// not found then go ahead and open a new window. // not found then go ahead and open a new window.
@ -776,9 +780,20 @@ XRemoteService::OpenURL(nsCString &aArgument,
FindWindow(NS_LITERAL_STRING("navigator:browser").get(), FindWindow(NS_LITERAL_STRING("navigator:browser").get(),
getter_AddRefs(lastUsedWindow)); getter_AddRefs(lastUsedWindow));
if (lastUsedWindow) if (lastUsedWindow) {
finalWindow = lastUsedWindow; finalWindow = lastUsedWindow;
else nsCOMPtr<nsIWebNavigation> navNav(do_GetInterface(finalWindow));
nsCOMPtr<nsIDocShellTreeItem> navItem(do_QueryInterface(navNav));
if (navItem) {
nsCOMPtr<nsIDocShellTreeItem> rootItem;
navItem->GetRootTreeItem(getter_AddRefs(rootItem));
nsCOMPtr<nsIDOMWindow> rootWin(do_GetInterface(rootItem));
nsCOMPtr<nsIDOMChromeWindow> chromeWin(do_QueryInterface(rootWin));
if (chromeWin)
chromeWin->GetBrowserDOMWindow(getter_AddRefs(bwin));
}
}
if (!finalWindow || !bwin)
newWindow = PR_TRUE; newWindow = PR_TRUE;
} }
#endif #endif
@ -787,11 +802,14 @@ XRemoteService::OpenURL(nsCString &aArgument,
if (!MayOpenURL(aArgument)) if (!MayOpenURL(aArgument))
return NS_ERROR_ABORT; return NS_ERROR_ABORT;
nsresult rv = NS_OK;
// try to fixup the argument passed in // try to fixup the argument passed in
nsString url; nsString url;
url.AssignWithConversion(aArgument.get()); url.AssignWithConversion(aArgument.get());
nsresult rv = NS_OK; nsCOMPtr<nsIURI> uri;
NS_NewURI(getter_AddRefs(uri), url);
if (newWindow) { if (newWindow) {
nsXPIDLCString urlString; nsXPIDLCString urlString;
@ -833,10 +851,8 @@ XRemoteService::OpenURL(nsCString &aArgument,
// now the listenerref is the only reference // now the listenerref is the only reference
NS_RELEASE(listener); NS_RELEASE(listener);
// create our uri object // double-check our uri object
nsCOMPtr<nsIURI> uri; if (!uri)
rv = NS_NewURI(getter_AddRefs(uri), url);
if (NS_FAILED(rv))
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
// open a channel // open a channel
@ -850,22 +866,27 @@ XRemoteService::OpenURL(nsCString &aArgument,
} }
else if (newTab && aOpenBrowser) { else if (newTab && aOpenBrowser) {
// We open new tabs simply by broadcasting a request to all interested NS_ASSERTION(bwin && uri, "failed to open remote URL in new tab");
// observers, which will typically be all open windows. The observers if (bwin && uri) {
// can check the notification subject against themselves (in the case of nsCOMPtr<nsIDOMWindow> container;
// a browser window observer, anyway) to determine if they should be rv = bwin->OpenURI(uri, 0,
// opening the tab. nsIBrowserDOMWindow::OPEN_NEWTAB,
nsCOMPtr<nsIObserverService> nsIBrowserDOMWindow::OPEN_EXTERNAL,
obsServ(do_GetService("@mozilla.org/observer-service;1")); getter_AddRefs(container));
}
if (!obsServ)
return NS_ERROR_FAILURE;
return obsServ->NotifyObservers(finalWindow, "open-new-tab-request",
url.get());
} }
else { else if (bwin && uri) { // unspecified new browser URL; use prefs
nsCOMPtr<nsIDOMWindow> container;
rv = bwin->OpenURI(uri, 0,
nsIBrowserDOMWindow::OPEN_DEFAULTWINDOW,
nsIBrowserDOMWindow::OPEN_EXTERNAL,
getter_AddRefs(container));
if (NS_SUCCEEDED(rv))
return NS_OK;
}
else { // non-browser URLs
// find the primary content shell for the window that we've been // find the primary content shell for the window that we've been
// asked to load into. // asked to load into.
nsCOMPtr<nsIScriptGlobalObject> scriptObject; nsCOMPtr<nsIScriptGlobalObject> scriptObject;