From 44d555792849fa401a02043f7993a29fdbd39bbc Mon Sep 17 00:00:00 2001 From: "joki%netscape.com" Date: Fri, 18 Sep 1998 00:35:55 +0000 Subject: [PATCH] Adding targetting of any named window git-svn-id: svn://10.0.0.236/trunk@10327 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/docshell/base/nsWebShell.cpp | 28 ++++++++++++----- mozilla/dom/src/base/nsGlobalWindow.cpp | 29 ++++++++++------- .../embed/ActiveX/WebShellContainer.cpp | 5 +++ .../embed/ActiveX/WebShellContainer.h | 1 + mozilla/webshell/public/nsIWebShell.h | 2 ++ mozilla/webshell/src/nsWebShell.cpp | 28 ++++++++++++----- .../webshell/tests/viewer/nsBrowserWindow.cpp | 31 +++++++++++++++++++ .../webshell/tests/viewer/nsBrowserWindow.h | 1 + 8 files changed, 100 insertions(+), 25 deletions(-) diff --git a/mozilla/docshell/base/nsWebShell.cpp b/mozilla/docshell/base/nsWebShell.cpp index f5ba899be15..bcaac426c9c 100644 --- a/mozilla/docshell/base/nsWebShell.cpp +++ b/mozilla/docshell/base/nsWebShell.cpp @@ -187,6 +187,7 @@ public: NS_IMETHOD ProgressLoadURL(nsIWebShell* aShell, const PRUnichar* aURL, PRInt32 aProgress, PRInt32 aProgressMax); NS_IMETHOD EndLoadURL(nsIWebShell* aShell, const PRUnichar* aURL, PRInt32 aStatus); NS_IMETHOD NewWebShell(nsIWebShell *&aNewWebShell); + NS_IMETHOD FindWebShellWithName(const PRUnichar* aName, nsIWebShell*& aResult); // nsILinkHandler NS_IMETHOD OnLinkClick(nsIFrame* aFrame, @@ -1349,6 +1350,14 @@ nsWebShell::NewWebShell(nsIWebShell *&aNewWebShell) return NS_OK; } +NS_IMETHODIMP +nsWebShell::FindWebShellWithName(const PRUnichar* aName, nsIWebShell*& aResult) +{ + if (nsnull != mContainer) { + return mContainer->FindWebShellWithName(aName, aResult); + } + return NS_OK; +} //---------------------------------------------------------------------- @@ -1475,14 +1484,19 @@ nsWebShell::GetTarget(const PRUnichar* aName) } else { // Look from the top of the tree downward - nsIWebShell* top; - GetRootWebShell(top); - top->FindChildWithName(aName, target); - if (nsnull == target) { - target = this; - NS_ADDREF(target); + if (nsnull != mContainer) { + mContainer->FindWebShellWithName(aName, target); + if (nsnull == target) { + mContainer->NewWebShell(target); + } + if (nsnull != target) { + target->SetName(aName); + } + else { + target = this; + NS_ADDREF(target); + } } - NS_RELEASE(top); } return target; diff --git a/mozilla/dom/src/base/nsGlobalWindow.cpp b/mozilla/dom/src/base/nsGlobalWindow.cpp index 5374b4a12bd..488993a10bb 100644 --- a/mozilla/dom/src/base/nsGlobalWindow.cpp +++ b/mozilla/dom/src/base/nsGlobalWindow.cpp @@ -798,6 +798,7 @@ GlobalWindowImpl::SetTimeoutOrInterval(JSContext *cx, nsTimeoutImpl *timeout, **insertion_point; jsdouble interval; PRInt64 now, delta; + JSPrincipals principals; if (argc >= 2) { if (!JS_ValueToNumber(cx, argv[1], &interval)) { @@ -836,6 +837,7 @@ GlobalWindowImpl::SetTimeoutOrInterval(JSContext *cx, timeout->interval = (PRInt32)interval; timeout->expr = expr; timeout->funobj = funobj; + timeout->principals = nsnull; if (expr) { timeout->argv = 0; timeout->argc = 0; @@ -929,7 +931,7 @@ GlobalWindowImpl::Open(JSContext *cx, PRUint32 mChrome = 0; PRInt32 mWidth, mHeight; PRInt32 mLeft, mTop; - nsAutoString mAbsURL, mName; + nsAutoString mAbsURL, name; JSString* str; *aReturn = nsnull; @@ -961,14 +963,14 @@ GlobalWindowImpl::Open(JSContext *cx, if (nsnull == mJSStrName) { return NS_ERROR_FAILURE; } - mName.SetString(JS_GetStringChars(mJSStrName)); + name.SetString(JS_GetStringChars(mJSStrName)); - if (NS_OK != CheckWindowName(cx, mName)) { + if (NS_OK != CheckWindowName(cx, name)) { return NS_ERROR_FAILURE; } } else { - mName.SetString(""); + name.SetString(""); } char *options; @@ -1030,13 +1032,19 @@ GlobalWindowImpl::Open(JSContext *cx, nsIBrowserWindow *newWindow = nsnull; nsIScriptGlobalObject *newGlobalObject = nsnull; - nsIWebShell *newWebShell; + nsIWebShell *newWebShell = nsnull; nsIWebShellContainer *webShellContainer, *newContainer; /* XXX check for existing window of same name. If exists, set url and * update chrome */ - if (NS_OK == mWebShell->GetContainer(webShellContainer)) { - if (NS_OK == webShellContainer->NewWebShell(newWebShell)) { + if (NS_OK == mWebShell->GetContainer(webShellContainer) && nsnull != webShellContainer) { + // Check for existing window of same name. + webShellContainer->FindWebShellWithName(name.GetUnicode(), newWebShell); + if (nsnull == newWebShell) { + // No window of that name so create a new one. + webShellContainer->NewWebShell(newWebShell); + } + if (nsnull != newWebShell) { if (NS_OK == newWebShell->GetContainer(newContainer) && nsnull != newContainer) { newContainer->QueryInterface(kIBrowserWindowIID, (void**)&newWindow); NS_RELEASE(newContainer); @@ -1045,7 +1053,7 @@ GlobalWindowImpl::Open(JSContext *cx, NS_RELEASE(webShellContainer); } - if (nsnull != newWindow) { + if (nsnull != newWindow && nsnull != newWebShell) { //How should we do default size/pos newWindow->Hide(); newWindow->SetChrome(mChrome); @@ -1053,6 +1061,7 @@ GlobalWindowImpl::Open(JSContext *cx, newWindow->MoveTo(mLeft, mTop); newWebShell->LoadURL(mAbsURL); + newWebShell->SetName(name); newWindow->Show(); @@ -1068,14 +1077,12 @@ GlobalWindowImpl::Open(JSContext *cx, return NS_ERROR_FAILURE; } - newWebShell->SetName(mName); - NS_RELEASE(newWindow); NS_RELEASE(newWebShell); NS_RELEASE(newContextOwner); } - nsIDOMWindow *newDOMWindow; + nsIDOMWindow *newDOMWindow = nsnull; if (nsnull != newGlobalObject && NS_OK == newGlobalObject->QueryInterface(kIDOMWindowIID, (void**)&newDOMWindow)) { *aReturn = newDOMWindow; } diff --git a/mozilla/webshell/embed/ActiveX/WebShellContainer.cpp b/mozilla/webshell/embed/ActiveX/WebShellContainer.cpp index 2460abdf096..628d3e0a9ab 100644 --- a/mozilla/webshell/embed/ActiveX/WebShellContainer.cpp +++ b/mozilla/webshell/embed/ActiveX/WebShellContainer.cpp @@ -101,3 +101,8 @@ CWebShellContainer::NewWebShell(nsIWebShell *&aNewWebShell) return rv; } +NS_IMETHODIMP +CWebShellContainer::FindWebshellWithName(const PRUnichar* aName, nsIWebShell*& aResult) +{ + return NS_ERROR_FAILURE; +} diff --git a/mozilla/webshell/embed/ActiveX/WebShellContainer.h b/mozilla/webshell/embed/ActiveX/WebShellContainer.h index 2f83855d9e2..93ea7a20e10 100644 --- a/mozilla/webshell/embed/ActiveX/WebShellContainer.h +++ b/mozilla/webshell/embed/ActiveX/WebShellContainer.h @@ -23,6 +23,7 @@ public: NS_IMETHOD ProgressLoadURL(nsIWebShell* aShell, const PRUnichar* aURL, PRInt32 aProgress, PRInt32 aProgressMax); NS_IMETHOD EndLoadURL(nsIWebShell* aShell, const PRUnichar* aURL, PRInt32 aStatus); NS_IMETHOD NewWebShell(nsIWebShell *&aNewWebShell); + NS_IMETHOD FindWebshellWithName(const PRUnichar* aName, nsIWebShell*& aResult); }; #endif \ No newline at end of file diff --git a/mozilla/webshell/public/nsIWebShell.h b/mozilla/webshell/public/nsIWebShell.h index 25ec000dd60..6e56055f8a8 100644 --- a/mozilla/webshell/public/nsIWebShell.h +++ b/mozilla/webshell/public/nsIWebShell.h @@ -66,6 +66,8 @@ public: //instances NS_IMETHOD NewWebShell(nsIWebShell *&aNewWebShell) = 0; + NS_IMETHOD FindWebShellWithName(const PRUnichar* aName, + nsIWebShell*& aResult) = 0; // NS_IMETHOD SetHistoryIndex(PRInt32 aIndex, PRInt32 aMaxIndex) = 0; diff --git a/mozilla/webshell/src/nsWebShell.cpp b/mozilla/webshell/src/nsWebShell.cpp index f5ba899be15..bcaac426c9c 100644 --- a/mozilla/webshell/src/nsWebShell.cpp +++ b/mozilla/webshell/src/nsWebShell.cpp @@ -187,6 +187,7 @@ public: NS_IMETHOD ProgressLoadURL(nsIWebShell* aShell, const PRUnichar* aURL, PRInt32 aProgress, PRInt32 aProgressMax); NS_IMETHOD EndLoadURL(nsIWebShell* aShell, const PRUnichar* aURL, PRInt32 aStatus); NS_IMETHOD NewWebShell(nsIWebShell *&aNewWebShell); + NS_IMETHOD FindWebShellWithName(const PRUnichar* aName, nsIWebShell*& aResult); // nsILinkHandler NS_IMETHOD OnLinkClick(nsIFrame* aFrame, @@ -1349,6 +1350,14 @@ nsWebShell::NewWebShell(nsIWebShell *&aNewWebShell) return NS_OK; } +NS_IMETHODIMP +nsWebShell::FindWebShellWithName(const PRUnichar* aName, nsIWebShell*& aResult) +{ + if (nsnull != mContainer) { + return mContainer->FindWebShellWithName(aName, aResult); + } + return NS_OK; +} //---------------------------------------------------------------------- @@ -1475,14 +1484,19 @@ nsWebShell::GetTarget(const PRUnichar* aName) } else { // Look from the top of the tree downward - nsIWebShell* top; - GetRootWebShell(top); - top->FindChildWithName(aName, target); - if (nsnull == target) { - target = this; - NS_ADDREF(target); + if (nsnull != mContainer) { + mContainer->FindWebShellWithName(aName, target); + if (nsnull == target) { + mContainer->NewWebShell(target); + } + if (nsnull != target) { + target->SetName(aName); + } + else { + target = this; + NS_ADDREF(target); + } } - NS_RELEASE(top); } return target; diff --git a/mozilla/webshell/tests/viewer/nsBrowserWindow.cpp b/mozilla/webshell/tests/viewer/nsBrowserWindow.cpp index 136d363a7f2..4ecb5a12439 100644 --- a/mozilla/webshell/tests/viewer/nsBrowserWindow.cpp +++ b/mozilla/webshell/tests/viewer/nsBrowserWindow.cpp @@ -1320,6 +1320,37 @@ nsBrowserWindow::NewWebShell(nsIWebShell*& aNewWebShell) return rv; } +NS_IMETHODIMP +nsBrowserWindow::FindWebShellWithName(const PRUnichar* aName, nsIWebShell*& aResult) +{ + PRInt32 i, n = gBrowsers.Count(); + + aResult = nsnull; + nsString aNameStr(aName); + + for (i = 0; i < n; i++) { + nsBrowserWindow* bw = (nsBrowserWindow*) gBrowsers.ElementAt(i); + nsIWebShell *ws; + + if (NS_OK == bw->GetWebShell(ws)) { + PRUnichar *name; + if (NS_OK == ws->GetName(&name)) { + if (aNameStr.Equals(name)) { + aResult = ws; + NS_ADDREF(aResult); + return NS_OK; + } + } + } + if (NS_OK == ws->FindChildWithName(aName, aResult)) { + if (nsnull != aResult) { + return NS_OK; + } + } + } + return NS_OK; +} + //---------------------------------------- // Stream observer implementation diff --git a/mozilla/webshell/tests/viewer/nsBrowserWindow.h b/mozilla/webshell/tests/viewer/nsBrowserWindow.h index bdee9b04a52..5d0755445cf 100644 --- a/mozilla/webshell/tests/viewer/nsBrowserWindow.h +++ b/mozilla/webshell/tests/viewer/nsBrowserWindow.h @@ -93,6 +93,7 @@ public: NS_IMETHOD ProgressLoadURL(nsIWebShell* aShell, const PRUnichar* aURL, PRInt32 aProgress, PRInt32 aProgressMax); NS_IMETHOD EndLoadURL(nsIWebShell* aShell, const PRUnichar* aURL, PRInt32 aStatus); NS_IMETHOD NewWebShell(nsIWebShell *&aNewWebShell); + NS_IMETHOD FindWebShellWithName(const PRUnichar* aName, nsIWebShell*& aResult); // nsINetSupport NS_IMETHOD_(void) Alert(const nsString &aText);