From 25794bac66f669e2d1993dfd4b7f2c080fdfab68 Mon Sep 17 00:00:00 2001 From: "rpotts%netscape.com" Date: Fri, 12 Oct 2001 21:42:24 +0000 Subject: [PATCH] bug #90722.(r=danm@netscape.com, sr=mscott@netscape.com) Added nsIWindowWatcher::GetWindowByName(...). git-svn-id: svn://10.0.0.236/trunk@105296 18797224-902f-48f8-a5cc-f745e15eee43 --- .../windowwatcher/public/nsIWindowWatcher.idl | 10 +++++ .../windowwatcher/src/nsWindowWatcher.cpp | 44 +++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/mozilla/embedding/components/windowwatcher/public/nsIWindowWatcher.idl b/mozilla/embedding/components/windowwatcher/public/nsIWindowWatcher.idl index 0bd20b131b7..f42495fc63a 100644 --- a/mozilla/embedding/components/windowwatcher/public/nsIWindowWatcher.idl +++ b/mozilla/embedding/components/windowwatcher/public/nsIWindowWatcher.idl @@ -136,6 +136,16 @@ interface nsIWindowWatcher : nsISupports { */ nsIWebBrowserChrome getChromeForWindow(in nsIDOMWindow aWindow); + /** + Retrieve an existing window (or frame). + @param aTargetName the window name + @param aCurrentWindow a starting point in the window hierarchy to + begin the search. If null, each toplevel window + will be searched. + */ + nsIDOMWindow getWindowByName(in wstring aTargetName, + in nsIDOMWindow aCurrentWindow); + /** The Watcher serves as a global storage facility for the current active (frontmost non-floating-palette-type) window, storing and returning it on demand. Users must keep this attribute current, including after diff --git a/mozilla/embedding/components/windowwatcher/src/nsWindowWatcher.cpp b/mozilla/embedding/components/windowwatcher/src/nsWindowWatcher.cpp index d77cf0ea582..7a532e12faf 100644 --- a/mozilla/embedding/components/windowwatcher/src/nsWindowWatcher.cpp +++ b/mozilla/embedding/components/windowwatcher/src/nsWindowWatcher.cpp @@ -960,6 +960,50 @@ nsWindowWatcher::GetChromeForWindow(nsIDOMWindow *aWindow, nsIWebBrowserChrome * return NS_OK; } +NS_IMETHODIMP +nsWindowWatcher::GetWindowByName(const PRUnichar *aTargetName, + nsIDOMWindow *aCurrentWindow, + nsIDOMWindow **aResult) +{ + if (!aResult) { + return NS_ERROR_INVALID_ARG; + } + + *aResult = nsnull; + + nsCOMPtr webNav; + nsCOMPtr treeItem; + + // First, check if the TargetName exists in the aCurrentWindow hierarchy + webNav = do_GetInterface(aCurrentWindow); + if (webNav) { + nsCOMPtr docShellTreeItem; + + docShellTreeItem = do_QueryInterface(webNav); + if (docShellTreeItem) { + docShellTreeItem->FindItemWithName(aTargetName, nsnull, + getter_AddRefs(treeItem)); + } + } + + // Next, see if the TargetName exists in any window hierarchy + if (!treeItem) { + FindItemWithName(aTargetName, getter_AddRefs(treeItem)); + } + + if (treeItem) { + nsCOMPtr domWindow; + + domWindow = do_GetInterface(treeItem); + if (domWindow) { + *aResult = domWindow; + NS_ADDREF(*aResult); + } + } + + return NS_OK; +} + PRBool nsWindowWatcher::AddEnumerator(nsWatcherWindowEnumerator* inEnumerator) {