From 0635fbf5eb9b05b87f005d438a34b658bd06e616 Mon Sep 17 00:00:00 2001 From: "danm%netscape.com" Date: Sat, 26 Jun 1999 21:48:29 +0000 Subject: [PATCH] added 'content' property to JS window git-svn-id: svn://10.0.0.236/trunk@37057 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/dom/public/base/nsIDOMWindow.h | 4 + mozilla/dom/public/idl/base/Window.idl | 11 ++- mozilla/dom/src/base/nsGlobalWindow.cpp | 97 +++++++++++-------- mozilla/dom/src/base/nsGlobalWindow.h | 3 + mozilla/dom/src/base/nsJSWindow.cpp | 61 ++++++++---- mozilla/layout/generic/nsFrameFrame.cpp | 41 +++++--- .../layout/html/document/src/nsFrameFrame.cpp | 41 +++++--- mozilla/webshell/public/nsIBrowserWindow.h | 1 + .../webshell/tests/viewer/nsBrowserWindow.cpp | 8 ++ .../webshell/tests/viewer/nsBrowserWindow.h | 1 + .../xpfe/appshell/public/nsIWebShellWindow.h | 8 +- .../xpfe/appshell/src/nsWebShellWindow.cpp | 71 +++++++++++++- mozilla/xpfe/appshell/src/nsWebShellWindow.h | 8 +- mozilla/xpfe/browser/src/contentframe.xul | 5 +- 14 files changed, 252 insertions(+), 108 deletions(-) diff --git a/mozilla/dom/public/base/nsIDOMWindow.h b/mozilla/dom/public/base/nsIDOMWindow.h index dde6bda57dd..568c9e62df1 100644 --- a/mozilla/dom/public/base/nsIDOMWindow.h +++ b/mozilla/dom/public/base/nsIDOMWindow.h @@ -58,6 +58,8 @@ public: NS_IMETHOD GetTop(nsIDOMWindow** aTop)=0; + NS_IMETHOD GetContent(nsIDOMWindow** aContent)=0; + NS_IMETHOD GetMenubar(nsIDOMBarProp** aMenubar)=0; NS_IMETHOD GetToolbar(nsIDOMBarProp** aToolbar)=0; @@ -173,6 +175,7 @@ public: NS_IMETHOD GetHistory(nsIDOMHistory** aHistory); \ NS_IMETHOD GetParent(nsIDOMWindow** aParent); \ NS_IMETHOD GetTop(nsIDOMWindow** aTop); \ + NS_IMETHOD GetContent(nsIDOMWindow** aContent); \ NS_IMETHOD GetMenubar(nsIDOMBarProp** aMenubar); \ NS_IMETHOD GetToolbar(nsIDOMBarProp** aToolbar); \ NS_IMETHOD GetLocationbar(nsIDOMBarProp** aLocationbar); \ @@ -243,6 +246,7 @@ public: NS_IMETHOD GetHistory(nsIDOMHistory** aHistory) { return _to GetHistory(aHistory); } \ NS_IMETHOD GetParent(nsIDOMWindow** aParent) { return _to GetParent(aParent); } \ NS_IMETHOD GetTop(nsIDOMWindow** aTop) { return _to GetTop(aTop); } \ + NS_IMETHOD GetContent(nsIDOMWindow** aContent) { return _to GetContent(aContent); } \ NS_IMETHOD GetMenubar(nsIDOMBarProp** aMenubar) { return _to GetMenubar(aMenubar); } \ NS_IMETHOD GetToolbar(nsIDOMBarProp** aToolbar) { return _to GetToolbar(aToolbar); } \ NS_IMETHOD GetLocationbar(nsIDOMBarProp** aLocationbar) { return _to GetLocationbar(aLocationbar); } \ diff --git a/mozilla/dom/public/idl/base/Window.idl b/mozilla/dom/public/idl/base/Window.idl index a830368e7ee..41de63e6ebd 100644 --- a/mozilla/dom/public/idl/base/Window.idl +++ b/mozilla/dom/public/idl/base/Window.idl @@ -9,6 +9,7 @@ readonly attribute History history; readonly attribute Window parent; readonly attribute Window top; + readonly attribute Window content; readonly attribute BarProp menubar; readonly attribute BarProp toolbar; readonly attribute BarProp locationbar; @@ -56,11 +57,11 @@ long setTimeout(/* ... */); long setInterval(/* ... */); - void createPopup(in Element element, in Element popupContent, - in long xPos, in long yPos, - in DOMString popupType, in DOMString anchorAlignment, - in DOMString popupAlignment); - + void createPopup(in Element element, in Element popupContent, + in long xPos, in long yPos, + in DOMString popupType, in DOMString anchorAlignment, + in DOMString popupAlignment); + Window open(/* ... */); Window openDialog(/* ... */); }; diff --git a/mozilla/dom/src/base/nsGlobalWindow.cpp b/mozilla/dom/src/base/nsGlobalWindow.cpp index eeec29dcd7a..a4a3eef53d0 100644 --- a/mozilla/dom/src/base/nsGlobalWindow.cpp +++ b/mozilla/dom/src/base/nsGlobalWindow.cpp @@ -330,19 +330,13 @@ GlobalWindowImpl::SetWebShell(nsIWebShell *aWebShell) nsCOMPtr chromeShell; mWebShell->GetContainingChromeShell(getter_AddRefs(chromeShell)); if (chromeShell) { - // Convert the chrome shell to a DOM window. - nsCOMPtr contextOwner = do_QueryInterface(chromeShell); - if (contextOwner) { - nsCOMPtr globalObject; - if (NS_OK == contextOwner->GetScriptGlobalObject(getter_AddRefs(globalObject))) { - nsCOMPtr chromeWindow = do_QueryInterface(globalObject); - if (chromeWindow) { - nsCOMPtr chromeDoc; - chromeWindow->GetDocument(getter_AddRefs(chromeDoc)); - nsCOMPtr realDoc = do_QueryInterface(chromeDoc); - mChromeDocument = realDoc.get(); // Don't addref it - } - } + nsCOMPtr chromeWindow; + WebShellToDOMWindow(chromeShell, getter_AddRefs(chromeWindow)); + if (chromeWindow) { + nsCOMPtr chromeDoc; + chromeWindow->GetDocument(getter_AddRefs(chromeDoc)); + nsCOMPtr realDoc = do_QueryInterface(chromeDoc); + mChromeDocument = realDoc.get(); // Don't addref it } } } @@ -591,20 +585,12 @@ GlobalWindowImpl::GetParent(nsIDOMWindow** aParent) *aParent = nsnull; if (nsnull != mWebShell) { - nsIWebShell *mParentWebShell; - mWebShell->GetParent(mParentWebShell); + nsIWebShell *parentWebShell; + mWebShell->GetParent(parentWebShell); - if (nsnull != mParentWebShell) { - nsIScriptContextOwner *mParentContextOwner; - if (NS_OK == mParentWebShell->QueryInterface(kIScriptContextOwnerIID, (void**)&mParentContextOwner)) { - nsIScriptGlobalObject *mParentGlobalObject; - if (NS_OK == mParentContextOwner->GetScriptGlobalObject(&mParentGlobalObject)) { - ret = mParentGlobalObject->QueryInterface(kIDOMWindowIID, (void**)aParent); - NS_RELEASE(mParentGlobalObject); - } - NS_RELEASE(mParentContextOwner); - } - NS_RELEASE(mParentWebShell); + if (nsnull != parentWebShell) { + ret = WebShellToDOMWindow(parentWebShell, aParent); + NS_RELEASE(parentWebShell); } else { *aParent = this; @@ -636,27 +622,35 @@ GlobalWindowImpl::GetTop(nsIDOMWindow** aTop) *aTop = nsnull; if (nsnull != mWebShell) { - nsIWebShell *mRootWebShell; - mWebShell->GetRootWebShell(mRootWebShell); - - - if (nsnull != mRootWebShell) { - nsIScriptContextOwner *mRootContextOwner; - if (NS_OK == mRootWebShell->QueryInterface(kIScriptContextOwnerIID, (void**)&mRootContextOwner)) { - nsIScriptGlobalObject *mRootGlobalObject; - if (NS_OK == mRootContextOwner->GetScriptGlobalObject(&mRootGlobalObject)) { - ret = mRootGlobalObject->QueryInterface(kIDOMWindowIID, (void**)aTop); - NS_RELEASE(mRootGlobalObject); - } - NS_RELEASE(mRootContextOwner); - } - NS_RELEASE(mRootWebShell); + nsIWebShell *rootWebShell; + mWebShell->GetRootWebShell(rootWebShell); + if (nsnull != rootWebShell) { + WebShellToDOMWindow(rootWebShell, aTop); + NS_RELEASE(rootWebShell); } } return ret; } +NS_IMETHODIMP +GlobalWindowImpl::GetContent(nsIDOMWindow** aContent) +{ + nsresult rv; + + *aContent = nsnull; + + nsCOMPtr browser; + rv = GetBrowserWindowInterface(*getter_AddRefs(browser)); + if (NS_SUCCEEDED(rv) && browser) { + nsCOMPtr contentShell; + rv = browser->GetContentWebShell(getter_AddRefs(contentShell)); + if (NS_SUCCEEDED(rv) && contentShell) + rv = WebShellToDOMWindow(contentShell, aContent); + } + return rv; +} + NS_IMETHODIMP GlobalWindowImpl::GetClosed(PRBool* aClosed) { @@ -2060,6 +2054,27 @@ GlobalWindowImpl::ReadyOpenedWebShell(nsIWebShell *aWebShell, nsIDOMWindow **aDO return res; } +// simple utility conversion routine +nsresult +GlobalWindowImpl::WebShellToDOMWindow(nsIWebShell *aWebShell, nsIDOMWindow **aDOMWindow) +{ + nsresult rv; + + NS_ASSERTION(aWebShell, "null in param to WebShellToDOMWindow"); + NS_ASSERTION(aDOMWindow, "null out param to WebShellToDOMWindow"); + + *aDOMWindow = nsnull; + + nsCOMPtr owner = do_QueryInterface(aWebShell, &rv); + if (owner) { + nsCOMPtr scriptobj; + rv = owner->GetScriptGlobalObject(getter_AddRefs(scriptobj)); + if (NS_SUCCEEDED(rv) && scriptobj) + rv = scriptobj->QueryInterface(nsIDOMWindow::GetIID(), (void **) aDOMWindow); + } + return rv; +} + NS_IMETHODIMP GlobalWindowImpl::CreatePopup(nsIDOMElement* aElement, nsIDOMElement* aPopupContent, PRInt32 aXPos, PRInt32 aYPos, diff --git a/mozilla/dom/src/base/nsGlobalWindow.h b/mozilla/dom/src/base/nsGlobalWindow.h index 4c17e1c9d45..af2487b7257 100644 --- a/mozilla/dom/src/base/nsGlobalWindow.h +++ b/mozilla/dom/src/base/nsGlobalWindow.h @@ -85,6 +85,7 @@ public: NS_IMETHOD GetLocation(nsIDOMLocation** aLocation); NS_IMETHOD GetParent(nsIDOMWindow** aOpener); NS_IMETHOD GetTop(nsIDOMWindow** aTop); + NS_IMETHOD GetContent(nsIDOMWindow** aContent); NS_IMETHOD GetClosed(PRBool* aClosed); NS_IMETHOD GetMenubar(nsIDOMBarProp** aMenubar); NS_IMETHOD GetToolbar(nsIDOMBarProp** aToolbar); @@ -225,6 +226,8 @@ protected: nsresult SizeAndShowOpenedWebShell(nsIWebShell *aOuterShell, char *aFeatures); nsresult ReadyOpenedWebShell(nsIWebShell *aWebShell, nsIDOMWindow **aDOMWindow); + static nsresult WebShellToDOMWindow(nsIWebShell *aWebShell, nsIDOMWindow **aDOMWindow); + nsIScriptContext *mContext; void *mScriptObject; nsIDOMDocument *mDocument; diff --git a/mozilla/dom/src/base/nsJSWindow.cpp b/mozilla/dom/src/base/nsJSWindow.cpp index afad9ea396f..94fe3b5b469 100644 --- a/mozilla/dom/src/base/nsJSWindow.cpp +++ b/mozilla/dom/src/base/nsJSWindow.cpp @@ -79,27 +79,28 @@ enum Window_slots { WINDOW_HISTORY = -6, WINDOW_PARENT = -7, WINDOW_TOP = -8, - WINDOW_MENUBAR = -9, - WINDOW_TOOLBAR = -10, - WINDOW_LOCATIONBAR = -11, - WINDOW_PERSONALBAR = -12, - WINDOW_STATUSBAR = -13, - WINDOW_SCROLLBARS = -14, - WINDOW_DIRECTORIES = -15, - WINDOW_CLOSED = -16, - WINDOW_FRAMES = -17, - WINDOW_OPENER = -18, - WINDOW_STATUS = -19, - WINDOW_DEFAULTSTATUS = -20, - WINDOW_NAME = -21, - WINDOW_INNERWIDTH = -22, - WINDOW_INNERHEIGHT = -23, - WINDOW_OUTERWIDTH = -24, - WINDOW_OUTERHEIGHT = -25, - WINDOW_SCREENX = -26, - WINDOW_SCREENY = -27, - WINDOW_PAGEXOFFSET = -28, - WINDOW_PAGEYOFFSET = -29 + WINDOW_CONTENT = -9, + WINDOW_MENUBAR = -10, + WINDOW_TOOLBAR = -11, + WINDOW_LOCATIONBAR = -12, + WINDOW_PERSONALBAR = -13, + WINDOW_STATUSBAR = -14, + WINDOW_SCROLLBARS = -15, + WINDOW_DIRECTORIES = -16, + WINDOW_CLOSED = -17, + WINDOW_FRAMES = -18, + WINDOW_OPENER = -19, + WINDOW_STATUS = -20, + WINDOW_DEFAULTSTATUS = -21, + WINDOW_NAME = -22, + WINDOW_INNERWIDTH = -23, + WINDOW_INNERHEIGHT = -24, + WINDOW_OUTERWIDTH = -25, + WINDOW_OUTERHEIGHT = -26, + WINDOW_SCREENX = -27, + WINDOW_SCREENY = -28, + WINDOW_PAGEXOFFSET = -29, + WINDOW_PAGEYOFFSET = -30 }; /***********************************************************************/ @@ -260,6 +261,23 @@ GetWindowProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) } break; } + case WINDOW_CONTENT: + { + secMan->CheckScriptAccess(scriptCX, obj, "window.content", &ok); + if (!ok) { + //Need to throw error here + return JS_FALSE; + } + nsIDOMWindow* prop; + if (NS_OK == a->GetContent(&prop)) { + // get the js object + nsJSUtils::nsConvertObjectToJSVal((nsISupports *)prop, cx, vp); + } + else { + return JS_FALSE; + } + break; + } case WINDOW_MENUBAR: { secMan->CheckScriptAccess(scriptCX, obj, "window.menubar", &ok); @@ -2537,6 +2555,7 @@ static JSPropertySpec WindowProperties[] = {"history", WINDOW_HISTORY, JSPROP_ENUMERATE | JSPROP_READONLY}, {"parent", WINDOW_PARENT, JSPROP_ENUMERATE | JSPROP_READONLY}, {"top", WINDOW_TOP, JSPROP_ENUMERATE | JSPROP_READONLY}, + {"content", WINDOW_CONTENT, JSPROP_ENUMERATE | JSPROP_READONLY}, {"menubar", WINDOW_MENUBAR, JSPROP_ENUMERATE | JSPROP_READONLY}, {"toolbar", WINDOW_TOOLBAR, JSPROP_ENUMERATE | JSPROP_READONLY}, {"locationbar", WINDOW_LOCATIONBAR, JSPROP_ENUMERATE | JSPROP_READONLY}, diff --git a/mozilla/layout/generic/nsFrameFrame.cpp b/mozilla/layout/generic/nsFrameFrame.cpp index 0a0d9eee0eb..2dde99ea4e5 100644 --- a/mozilla/layout/generic/nsFrameFrame.cpp +++ b/mozilla/layout/generic/nsFrameFrame.cpp @@ -808,20 +808,32 @@ nsHTMLFrameInnerFrame::CreateWebShell(nsIPresContext& aPresContext, nsWebShellType parentType; outerShell->GetWebShellType(parentType); nsIAtom* typeAtom = NS_NewAtom("type"); - nsAutoString value; - content->GetAttribute(kNameSpaceID_None, typeAtom, value); - if (value.EqualsIgnoreCase("content")) { - // The web shell's type is content. - mWebShell->SetWebShellType(nsWebShellContent); - nsCOMPtr shellAsContainer; - shellAsContainer = do_QueryInterface(mWebShell); - shellAsContainer->ContentShellAdded(mWebShell, content); + nsAutoString value, valuePiece; + PRBool isContent; + + isContent = PR_FALSE; + if (NS_SUCCEEDED(content->GetAttribute(kNameSpaceID_None, typeAtom, value))) { + + // we accept "content" and "content-xxx" values. + // at time of writing, we expect "xxx" to be "primary", but + // someday it might be an integer expressing priority + value.Left(valuePiece, 7); + if (valuePiece.EqualsIgnoreCase("content") && + (value.Length() == 7 || + value.Mid(valuePiece, 7, 1) == 1 && valuePiece.Equals("-"))) + isContent = PR_TRUE; } - else { + if (isContent) { + // The web shell's type is content. + mWebShell->SetWebShellType(nsWebShellContent); + nsCOMPtr shellAsContainer; + shellAsContainer = do_QueryInterface(mWebShell); + shellAsContainer->ContentShellAdded(mWebShell, content); + } else { // Inherit our type from our parent webshell. If it is - // chrome, we'll be chrome. If it is content, we'll be - // content. - mWebShell->SetWebShellType(parentType); + // chrome, we'll be chrome. If it is content, we'll be + // content. + mWebShell->SetWebShellType(parentType); } // Make sure all shells have links back to the nearest enclosing chrome @@ -832,8 +844,9 @@ nsHTMLFrameInnerFrame::CreateWebShell(nsIPresContext& aPresContext, outerShell->GetWebShellType(chromeShellType); if (chromeShellType == nsWebShellChrome) chromeShell = dont_QueryInterface(outerShell); - else outerShell->GetContainingChromeShell(getter_AddRefs(chromeShell)); - + else + outerShell->GetContainingChromeShell(getter_AddRefs(chromeShell)); + mWebShell->SetContainingChromeShell(chromeShell); #endif // INCLUDE_XUL diff --git a/mozilla/layout/html/document/src/nsFrameFrame.cpp b/mozilla/layout/html/document/src/nsFrameFrame.cpp index 0a0d9eee0eb..2dde99ea4e5 100644 --- a/mozilla/layout/html/document/src/nsFrameFrame.cpp +++ b/mozilla/layout/html/document/src/nsFrameFrame.cpp @@ -808,20 +808,32 @@ nsHTMLFrameInnerFrame::CreateWebShell(nsIPresContext& aPresContext, nsWebShellType parentType; outerShell->GetWebShellType(parentType); nsIAtom* typeAtom = NS_NewAtom("type"); - nsAutoString value; - content->GetAttribute(kNameSpaceID_None, typeAtom, value); - if (value.EqualsIgnoreCase("content")) { - // The web shell's type is content. - mWebShell->SetWebShellType(nsWebShellContent); - nsCOMPtr shellAsContainer; - shellAsContainer = do_QueryInterface(mWebShell); - shellAsContainer->ContentShellAdded(mWebShell, content); + nsAutoString value, valuePiece; + PRBool isContent; + + isContent = PR_FALSE; + if (NS_SUCCEEDED(content->GetAttribute(kNameSpaceID_None, typeAtom, value))) { + + // we accept "content" and "content-xxx" values. + // at time of writing, we expect "xxx" to be "primary", but + // someday it might be an integer expressing priority + value.Left(valuePiece, 7); + if (valuePiece.EqualsIgnoreCase("content") && + (value.Length() == 7 || + value.Mid(valuePiece, 7, 1) == 1 && valuePiece.Equals("-"))) + isContent = PR_TRUE; } - else { + if (isContent) { + // The web shell's type is content. + mWebShell->SetWebShellType(nsWebShellContent); + nsCOMPtr shellAsContainer; + shellAsContainer = do_QueryInterface(mWebShell); + shellAsContainer->ContentShellAdded(mWebShell, content); + } else { // Inherit our type from our parent webshell. If it is - // chrome, we'll be chrome. If it is content, we'll be - // content. - mWebShell->SetWebShellType(parentType); + // chrome, we'll be chrome. If it is content, we'll be + // content. + mWebShell->SetWebShellType(parentType); } // Make sure all shells have links back to the nearest enclosing chrome @@ -832,8 +844,9 @@ nsHTMLFrameInnerFrame::CreateWebShell(nsIPresContext& aPresContext, outerShell->GetWebShellType(chromeShellType); if (chromeShellType == nsWebShellChrome) chromeShell = dont_QueryInterface(outerShell); - else outerShell->GetContainingChromeShell(getter_AddRefs(chromeShell)); - + else + outerShell->GetContainingChromeShell(getter_AddRefs(chromeShell)); + mWebShell->SetContainingChromeShell(chromeShell); #endif // INCLUDE_XUL diff --git a/mozilla/webshell/public/nsIBrowserWindow.h b/mozilla/webshell/public/nsIBrowserWindow.h index 38d60e847f3..89d2df9e20f 100644 --- a/mozilla/webshell/public/nsIBrowserWindow.h +++ b/mozilla/webshell/public/nsIBrowserWindow.h @@ -95,6 +95,7 @@ public: NS_IMETHOD IsMenuBarVisible(PRBool *aVisible) = 0; NS_IMETHOD GetWebShell(nsIWebShell*& aResult) = 0; + NS_IMETHOD GetContentWebShell(nsIWebShell **aResult) = 0; // XXX minimize, maximize // XXX event control: enable/disable window close box, stick to glass, modal diff --git a/mozilla/webshell/tests/viewer/nsBrowserWindow.cpp b/mozilla/webshell/tests/viewer/nsBrowserWindow.cpp index c7508034e8a..b241277f804 100644 --- a/mozilla/webshell/tests/viewer/nsBrowserWindow.cpp +++ b/mozilla/webshell/tests/viewer/nsBrowserWindow.cpp @@ -1607,6 +1607,14 @@ nsBrowserWindow::GetWebShell(nsIWebShell*& aResult) return NS_OK; } +NS_IMETHODIMP +nsBrowserWindow::GetContentWebShell(nsIWebShell **aResult) +{ + *aResult = mWebShell; + NS_IF_ADDREF(mWebShell); + return NS_OK; +} + //---------------------------------------- NS_IMETHODIMP diff --git a/mozilla/webshell/tests/viewer/nsBrowserWindow.h b/mozilla/webshell/tests/viewer/nsBrowserWindow.h index 7da8323173c..65f2a9135f3 100644 --- a/mozilla/webshell/tests/viewer/nsBrowserWindow.h +++ b/mozilla/webshell/tests/viewer/nsBrowserWindow.h @@ -95,6 +95,7 @@ public: NS_IMETHOD ShowMenuBar(PRBool aShow); NS_IMETHOD IsMenuBarVisible(PRBool *aVisible); NS_IMETHOD GetWebShell(nsIWebShell*& aResult); + NS_IMETHOD GetContentWebShell(nsIWebShell **aResult); // nsIStreamObserver NS_IMETHOD OnStartBinding(nsIURI* aURL, const char *aContentType); diff --git a/mozilla/xpfe/appshell/public/nsIWebShellWindow.h b/mozilla/xpfe/appshell/public/nsIWebShellWindow.h index 61717bc2315..d35abed2555 100644 --- a/mozilla/xpfe/appshell/public/nsIWebShellWindow.h +++ b/mozilla/xpfe/appshell/public/nsIWebShellWindow.h @@ -44,12 +44,12 @@ public: NS_IMETHOD GetWidget(nsIWidget *& aWidget) = 0; NS_IMETHOD ConvertWebShellToDOMWindow(nsIWebShell* aShell, nsIDOMWindow** aDOMWindow) = 0; - NS_IMETHOD AddWebShellInfo(const nsString& aID, nsIWebShell* aChildShell) = 0; + NS_IMETHOD AddWebShellInfo(const nsString& aID, PRBool aPrimary, nsIWebShell* aChildShell) = 0; - NS_IMETHOD GetContentShellById(const nsString& anID, nsIWebShell** aResult) = 0; + NS_IMETHOD GetContentShellById(const nsString& anID, nsIWebShell** aResult) = 0; - NS_IMETHOD LockUntilChromeLoad() = 0; - NS_IMETHOD GetLockedState(PRBool& aResult) = 0; + NS_IMETHOD LockUntilChromeLoad() = 0; + NS_IMETHOD GetLockedState(PRBool& aResult) = 0; }; diff --git a/mozilla/xpfe/appshell/src/nsWebShellWindow.cpp b/mozilla/xpfe/appshell/src/nsWebShellWindow.cpp index 0d51bcc11a7..eca15930214 100644 --- a/mozilla/xpfe/appshell/src/nsWebShellWindow.cpp +++ b/mozilla/xpfe/appshell/src/nsWebShellWindow.cpp @@ -161,6 +161,7 @@ static NS_DEFINE_CID(kXULPopupListenerCID, NS_XULPOPUPLISTENER_CID); const char * kThrobberOnStr = "resource:/res/throbber/anims07.gif"; const char * kThrobberOffStr = "resource:/res/throbber/anims00.gif"; +const char * kPrimaryContentTypeValue = "content-primary"; struct ThreadedWindowEvent { PLEvent event; @@ -171,11 +172,13 @@ struct ThreadedWindowEvent { // subsequently be filled in when we receive a webshell added notification. struct nsWebShellInfo { nsString id; // The identifier of the iframe or frame node in the XUL tree. + PRBool primary; // whether it's considered a/the primary content nsIWebShell* child; // The child web shell that will end up being used for the content area. - nsWebShellInfo(const nsString& anID, nsIWebShell* aChildShell) + nsWebShellInfo(const nsString& anID, PRBool aPrimary, nsIWebShell* aChildShell) { id = anID; + primary = aPrimary; child = aChildShell; NS_IF_ADDREF(aChildShell); } @@ -947,10 +950,11 @@ nsWebShellWindow::GetContentShellById(const nsString& aID, nsIWebShell** aChildS //------------------------------------------------------------------------------ NS_IMETHODIMP nsWebShellWindow::AddWebShellInfo(const nsString& aID, + PRBool aPrimary, nsIWebShell* aChildShell) { - nsWebShellInfo* webShellInfo = new nsWebShellInfo(aID, + nsWebShellInfo* webShellInfo = new nsWebShellInfo(aID, aPrimary, aChildShell); if (mContentShells == nsnull) @@ -1229,10 +1233,21 @@ NS_IMETHODIMP nsWebShellWindow::ContentShellAdded(nsIWebShell* aChildShell, nsIContent* frameNode) { // Find out the id of the frameNode in question - nsIAtom* idAtom = NS_NewAtom("id"); + nsIAtom *idAtom = NS_NewAtom("id"); + nsIAtom *typeAtom = NS_NewAtom("type"); + PRBool isPrimary; nsAutoString value; - frameNode->GetAttribute(kNameSpaceID_None, idAtom, value); - AddWebShellInfo(value, aChildShell); + + // right now, any webshell with type "content" or "content-XXX" is + // considered a content webshell. but only "content-primary" is + // considered primary. + frameNode->GetAttribute(kNameSpaceID_None, typeAtom, value); + isPrimary = value.EqualsIgnoreCase(kPrimaryContentTypeValue) ? PR_TRUE : PR_FALSE; + frameNode->GetAttribute(kNameSpaceID_None, idAtom, value); + + AddWebShellInfo(value, isPrimary, aChildShell); + + NS_RELEASE(typeAtom); NS_RELEASE(idAtom); return NS_OK; } @@ -1489,6 +1504,7 @@ nsWebShellWindow::ShowModalInternal() } +/* return the main, outermost webshell in this window */ NS_IMETHODIMP nsWebShellWindow::GetWebShell(nsIWebShell *& aWebShell) { @@ -1497,6 +1513,51 @@ nsWebShellWindow::GetWebShell(nsIWebShell *& aWebShell) return NS_OK; } +/* return the webshell intended to hold (html) content. In a simple + browser window, that would be the main content area. If no such + webshell was found for any reason, the outermost webshell will be + returned. (Note that is the main chrome webshell, and probably + not what you wanted, but at least it's a webshell.) + Also note that if no content webshell was marked "primary," + we return the chrome webshell, even if (non-primary) content webshells + do exist. Thas was done intentionally. The selection would be + nondeterministic, and it seems dangerous to set a precedent like that. +*/ +NS_IMETHODIMP +nsWebShellWindow::GetContentWebShell(nsIWebShell **aResult) +{ + nsresult rv; + nsIWebShell *content; + + content = nsnull; + rv = NS_ERROR_FAILURE; + + // first, try looking in the webshell list + // (note this list isn't dynamic: it's set up when the webshell is added, + // but not updated when its attributes are poked. could be a problem...) + if (mContentShells) { + PRInt32 count = mContentShells->Count(); + for (PRInt32 ctr = 0; ctr < count; ctr++) { + nsWebShellInfo* webInfo = (nsWebShellInfo*)(mContentShells->ElementAt(ctr)); + if (webInfo->primary) { + content = webInfo->child; + break; + } + } + } + + if (!content) + // couldn't find it? then return our chrome webshell + content = mWebShell; + + if (content) { + NS_ADDREF(content); + rv = NS_OK; + } + *aResult = content; + return rv; +} + NS_IMETHODIMP nsWebShellWindow::GetWidget(nsIWidget *& aWidget) { diff --git a/mozilla/xpfe/appshell/src/nsWebShellWindow.h b/mozilla/xpfe/appshell/src/nsWebShellWindow.h index 2b4d9ba214c..a9adb0f1390 100644 --- a/mozilla/xpfe/appshell/src/nsWebShellWindow.h +++ b/mozilla/xpfe/appshell/src/nsWebShellWindow.h @@ -97,10 +97,11 @@ public: nsIWebShell *&aNewWebShell); NS_IMETHOD AddWebShellInfo(const nsString& aID, - nsIWebShell* aChildShell); + PRBool aPrimary, + nsIWebShell* aChildShell); - NS_IMETHOD GetContentShellById(const nsString& anID, nsIWebShell** aResult); - NS_IMETHOD LockUntilChromeLoad() { mLockedUntilChromeLoad = PR_TRUE; return NS_OK; } + NS_IMETHOD GetContentShellById(const nsString& anID, nsIWebShell** aResult); + NS_IMETHOD LockUntilChromeLoad() { mLockedUntilChromeLoad = PR_TRUE; return NS_OK; } NS_IMETHOD GetLockedState(PRBool& aResult) { aResult = mLockedUntilChromeLoad; return NS_OK; } NS_IMETHOD FindWebShellWithName(const PRUnichar* aName, @@ -113,6 +114,7 @@ public: NS_IMETHOD ShowModal(); NS_IMETHOD Close(); NS_IMETHOD GetWebShell(nsIWebShell *& aWebShell); + NS_IMETHOD GetContentWebShell(nsIWebShell **aResult); NS_IMETHOD GetWidget(nsIWidget *& aWidget); NS_IMETHOD ConvertWebShellToDOMWindow(nsIWebShell* aShell, nsIDOMWindow** aDOMWindow); // nsWebShellWindow methods... diff --git a/mozilla/xpfe/browser/src/contentframe.xul b/mozilla/xpfe/browser/src/contentframe.xul index 169655e12ec..6d1eba27b40 100644 --- a/mozilla/xpfe/browser/src/contentframe.xul +++ b/mozilla/xpfe/browser/src/contentframe.xul @@ -17,6 +17,9 @@ - + + +