allow a hidden pref to reuse browser windows when we get a GURL event. r=lordpixel,sr=sfraser. bug#98504

This commit is contained in:
pinkerton%netscape.com 2001-10-19 14:14:15 +00:00
Родитель 6630d79543
Коммит aa7509b85f
4 изменённых файлов: 100 добавлений и 43 удалений

Просмотреть файл

@ -45,6 +45,16 @@
#include "nsAEGetURLSuiteHandler.h"
#include "nsCommandLineServiceMac.h"
#include "nsCOMPtr.h"
#include "nsIServiceManager.h"
#include "nsIPref.h"
#include "nsIWindowMediator.h"
#include "nsIXULWindow.h"
PRBool AEGetURLSuiteHandler::sReuseWindowPrefInited = PR_FALSE;
PRBool AEGetURLSuiteHandler::sReuseWindow = PR_FALSE;
/*----------------------------------------------------------------------------
AEGetURLSuiteHandler
@ -52,6 +62,14 @@
----------------------------------------------------------------------------*/
AEGetURLSuiteHandler::AEGetURLSuiteHandler()
{
if ( !sReuseWindowPrefInited ) {
nsCOMPtr<nsIPref> prefService ( do_GetService(NS_PREF_CONTRACTID) );
if ( prefService ) {
prefService->GetBoolPref("browser.always_reuse_window", &sReuseWindow);
prefService->RegisterCallback("browser.always_reuse_window", ReuseWindowPrefCallback, nsnull);
}
sReuseWindowPrefInited = PR_TRUE;
}
}
/*----------------------------------------------------------------------------
@ -144,16 +162,49 @@ void AEGetURLSuiteHandler::HandleGetURLEvent(const AppleEvent *appleEvent, Apple
targetWindow = tokenContainer.GetWindowPtr();
}
if (targetWindow)
{
LoadURLInWindow(targetWindow, urlString);
}
else
{
nsMacCommandLine& cmdLine = nsMacCommandLine::GetMacCommandLine();
cmdLine.DispatchURLToNewBrowser(urlString);
}
// if the AE didn't specify a target, the user may still want it to reuse
// an existing window. Look if they have the pref specified. If they did
// specify the window, we have its windowPtr so dispatch to that.
PRBool dispatched = PR_FALSE;
if ( !targetWindow )
{
if ( sReuseWindow ) {
// nsCOMPtr<nsIWindowMediator> mediator ( do_GetService(NS_WINDOWMEDIATOR_CONTRACTID) );
static NS_DEFINE_CID(kWindowMediatorCID, NS_WINDOWMEDIATOR_CID);
nsCOMPtr<nsIWindowMediator> mediator ( do_GetService(kWindowMediatorCID) );
if ( mediator ) {
nsCOMPtr<nsISimpleEnumerator> windowEnum;
mediator->GetZOrderXULWindowEnumerator(NS_LITERAL_STRING("navigator:browser").get(), PR_TRUE, getter_AddRefs(windowEnum));
if ( windowEnum ) {
nsCOMPtr<nsISupports> windowSupports;
windowEnum->GetNext(getter_AddRefs(windowSupports));
nsCOMPtr<nsIXULWindow> xulwindow ( do_QueryInterface(windowSupports) );
if ( xulwindow )
LoadURLInXULWindow(xulwindow, urlString);
else
LoadURLInWindow(nsnull, urlString);
}
}
}
else
LoadURLInWindow(nsnull, urlString);
}
else
LoadURLInWindow(targetWindow, urlString);
nsMemory::Free(urlString);
}
int
AEGetURLSuiteHandler::ReuseWindowPrefCallback ( const char* inPref, void* inClosure )
{
nsCOMPtr<nsIPref> prefService ( do_GetService(NS_PREF_CONTRACTID) );
if ( prefService )
prefService->GetBoolPref("browser.always_reuse_window", &sReuseWindow);
return NS_OK;
}

Просмотреть файл

@ -42,6 +42,7 @@
#define nsAEGetURLSuiteHandler_h_
#include "nsAEUtils.h"
#include "prtypes.h"
class AEGetURLSuiteHandler
@ -64,6 +65,10 @@ protected:
void HandleGetURLEvent(const AppleEvent *appleEvent, AppleEvent *reply);
static int ReuseWindowPrefCallback ( const char* inPref, void* inClosure ) ;
static PRBool sReuseWindowPrefInited;
static PRBool sReuseWindow;
};

Просмотреть файл

@ -63,6 +63,7 @@
#include "nsMacUtils.h"
#include "nsXPIDLString.h"
#include "nsXULWindow.h"
#include "nsWindowUtils.h"
#include "nsAEUtils.h"
@ -474,33 +475,40 @@ void GetWindowGlobalBounds(WindowPtr wind, Rect* outBounds)
----------------------------------------------------------------------------*/
void LoadURLInWindow(WindowPtr wind, const char* urlString)
{
OSErr err = noErr;
OSErr err = noErr;
if (wind == nil)
{
// this makes a new window
nsMacCommandLine& cmdLine = nsMacCommandLine::GetMacCommandLine();
err = cmdLine.DispatchURLToNewBrowser(urlString);
ThrowIfOSErr(err);
}
// existing window. Go through hoops to load a URL in it
nsCOMPtr<nsIXULWindow> xulWindow;
GetXULWindowFromWindowPtr(wind, getter_AddRefs(xulWindow));
ThrowErrIfNil(xulWindow, paramErr);
nsCOMPtr<nsIDocShellTreeItem> contentShell;
xulWindow->GetPrimaryContentShell(getter_AddRefs(contentShell));
ThrowErrIfNil(contentShell, paramErr);
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(contentShell));
ThrowErrIfNil(webNav, paramErr);
nsAutoString urlWString; urlWString.AssignWithConversion(urlString);
webNav->LoadURI(urlWString.get(), nsIWebNavigation::LOAD_FLAGS_NONE);
if ( !wind )
{
// this makes a new window
nsMacCommandLine& cmdLine = nsMacCommandLine::GetMacCommandLine();
err = cmdLine.DispatchURLToNewBrowser(urlString);
ThrowIfOSErr(err);
}
else {
// existing window. Go through hoops to load a URL in it
nsCOMPtr<nsIXULWindow> xulWindow;
GetXULWindowFromWindowPtr(wind, getter_AddRefs(xulWindow));
ThrowErrIfNil(xulWindow, paramErr);
LoadURLInXULWindow(xulWindow, urlString);
}
}
void LoadURLInXULWindow(nsIXULWindow* inWindow, const char* urlString)
{
nsCOMPtr<nsIDocShellTreeItem> contentShell;
inWindow->GetPrimaryContentShell(getter_AddRefs(contentShell));
ThrowErrIfNil(contentShell, paramErr);
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(contentShell));
ThrowErrIfNil(webNav, paramErr);
nsAutoString urlWString; urlWString.AssignWithConversion(urlString);
webNav->LoadURI(urlWString.get(), nsIWebNavigation::LOAD_FLAGS_NONE);
}
#pragma mark -
/*----------------------------------------------------------------------------

Просмотреть файл

@ -45,10 +45,7 @@
#include "nsAEDefs.h"
#ifdef __cplusplus
extern "C" {
#endif
class nsIXULWindow;
long CountWindowsOfKind(TWindowKind windowKind);
@ -61,6 +58,7 @@ void GetWindowUrlString(WindowPtr wind, char** outUrlStringPtr);
void GetWindowGlobalBounds(WindowPtr wind, Rect* outRect);
void LoadURLInWindow(WindowPtr wind, const char* urlString);
void LoadURLInXULWindow(nsIXULWindow* inWindow, const char* urlString);
Boolean WindowIsResizeable(WindowPtr wind);
Boolean WindowIsZoomable(WindowPtr wind);
@ -72,9 +70,4 @@ Boolean WindowIsFloating(WindowPtr wind);
Boolean WindowIsModified(WindowPtr wind);
#ifdef __cplusplus
}
#endif
#endif // nsWindowUtils_h_