michael@0: /* -*- Mode: C++; tab-width: 3; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * vim: set ts=2 sw=2 et tw=79: michael@0: * michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: // Local Includes michael@0: #include "nsContentTreeOwner.h" michael@0: #include "nsXULWindow.h" michael@0: michael@0: // Helper Classes michael@0: #include "nsIServiceManager.h" michael@0: #include "nsAutoPtr.h" michael@0: michael@0: // Interfaces needed to be included michael@0: #include "nsIDOMNode.h" michael@0: #include "nsIDOMElement.h" michael@0: #include "nsIDOMNodeList.h" michael@0: #include "nsIDOMWindow.h" michael@0: #include "nsIDOMChromeWindow.h" michael@0: #include "nsIBrowserDOMWindow.h" michael@0: #include "nsIDOMXULElement.h" michael@0: #include "nsIEmbeddingSiteWindow.h" michael@0: #include "nsIPrompt.h" michael@0: #include "nsIAuthPrompt.h" michael@0: #include "nsIWindowMediator.h" michael@0: #include "nsIXULBrowserWindow.h" michael@0: #include "nsIPrincipal.h" michael@0: #include "nsIURIFixup.h" michael@0: #include "nsCDefaultURIFixup.h" michael@0: #include "nsIWebNavigation.h" michael@0: #include "nsDocShellCID.h" michael@0: #include "nsIExternalURLHandlerService.h" michael@0: #include "nsIMIMEInfo.h" michael@0: #include "nsIWidget.h" michael@0: #include "mozilla/BrowserElementParent.h" michael@0: michael@0: #include "nsIDOMDocument.h" michael@0: #include "nsIScriptObjectPrincipal.h" michael@0: #include "nsIURI.h" michael@0: #include "nsIDocument.h" michael@0: #if defined(XP_MACOSX) michael@0: #include "nsThreadUtils.h" michael@0: #endif michael@0: michael@0: #include "mozilla/Preferences.h" michael@0: #include "mozilla/dom/Element.h" michael@0: #include "mozilla/dom/ScriptSettings.h" michael@0: michael@0: using namespace mozilla; michael@0: michael@0: //***************************************************************************** michael@0: //*** nsSiteWindow declaration michael@0: //***************************************************************************** michael@0: michael@0: class nsSiteWindow : public nsIEmbeddingSiteWindow michael@0: { michael@0: public: michael@0: nsSiteWindow(nsContentTreeOwner *aAggregator); michael@0: virtual ~nsSiteWindow(); michael@0: michael@0: NS_DECL_ISUPPORTS michael@0: NS_DECL_NSIEMBEDDINGSITEWINDOW michael@0: michael@0: private: michael@0: nsContentTreeOwner *mAggregator; michael@0: }; michael@0: michael@0: //***************************************************************************** michael@0: //*** nsContentTreeOwner: Object Management michael@0: //***************************************************************************** michael@0: michael@0: nsContentTreeOwner::nsContentTreeOwner(bool fPrimary) : mXULWindow(nullptr), michael@0: mPrimary(fPrimary), mContentTitleSetting(false) michael@0: { michael@0: // note if this fails, QI on nsIEmbeddingSiteWindow(2) will simply fail michael@0: mSiteWindow = new nsSiteWindow(this); michael@0: } michael@0: michael@0: nsContentTreeOwner::~nsContentTreeOwner() michael@0: { michael@0: delete mSiteWindow; michael@0: } michael@0: michael@0: //***************************************************************************** michael@0: // nsContentTreeOwner::nsISupports michael@0: //***************************************************************************** michael@0: michael@0: NS_IMPL_ADDREF(nsContentTreeOwner) michael@0: NS_IMPL_RELEASE(nsContentTreeOwner) michael@0: michael@0: NS_INTERFACE_MAP_BEGIN(nsContentTreeOwner) michael@0: NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDocShellTreeOwner) michael@0: NS_INTERFACE_MAP_ENTRY(nsIDocShellTreeOwner) michael@0: NS_INTERFACE_MAP_ENTRY(nsIBaseWindow) michael@0: NS_INTERFACE_MAP_ENTRY(nsIWebBrowserChrome) michael@0: NS_INTERFACE_MAP_ENTRY(nsIWebBrowserChrome2) michael@0: NS_INTERFACE_MAP_ENTRY(nsIWebBrowserChrome3) michael@0: NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor) michael@0: NS_INTERFACE_MAP_ENTRY(nsIWindowProvider) michael@0: // NOTE: This is using aggregation because there are some properties and michael@0: // method on nsIBaseWindow (which we implement) and on michael@0: // nsIEmbeddingSiteWindow (which we also implement) that have the same name. michael@0: // And it just so happens that we want different behavior for these methods michael@0: // and properties depending on the interface through which they're called michael@0: // (SetFocus() is a good example here). If it were not for that, we could michael@0: // ditch the aggregation and just deal with not being able to use NS_DECL_* michael@0: // macros for this stuff.... michael@0: NS_INTERFACE_MAP_ENTRY_AGGREGATED(nsIEmbeddingSiteWindow, mSiteWindow) michael@0: NS_INTERFACE_MAP_END michael@0: michael@0: //***************************************************************************** michael@0: // nsContentTreeOwner::nsIInterfaceRequestor michael@0: //***************************************************************************** michael@0: michael@0: NS_IMETHODIMP nsContentTreeOwner::GetInterface(const nsIID& aIID, void** aSink) michael@0: { michael@0: NS_ENSURE_ARG_POINTER(aSink); michael@0: *aSink = 0; michael@0: michael@0: if(aIID.Equals(NS_GET_IID(nsIPrompt))) { michael@0: NS_ENSURE_STATE(mXULWindow); michael@0: return mXULWindow->GetInterface(aIID, aSink); michael@0: } michael@0: if(aIID.Equals(NS_GET_IID(nsIAuthPrompt))) { michael@0: NS_ENSURE_STATE(mXULWindow); michael@0: return mXULWindow->GetInterface(aIID, aSink); michael@0: } michael@0: if (aIID.Equals(NS_GET_IID(nsIDocShellTreeItem))) { michael@0: NS_ENSURE_STATE(mXULWindow); michael@0: nsCOMPtr shell; michael@0: mXULWindow->GetDocShell(getter_AddRefs(shell)); michael@0: if (shell) michael@0: return shell->QueryInterface(aIID, aSink); michael@0: return NS_ERROR_FAILURE; michael@0: } michael@0: michael@0: if (aIID.Equals(NS_GET_IID(nsIDOMWindow))) { michael@0: NS_ENSURE_STATE(mXULWindow); michael@0: nsCOMPtr shell; michael@0: mXULWindow->GetPrimaryContentShell(getter_AddRefs(shell)); michael@0: if (shell) { michael@0: nsCOMPtr thing(do_QueryInterface(shell)); michael@0: if (thing) michael@0: return thing->GetInterface(aIID, aSink); michael@0: } michael@0: return NS_ERROR_FAILURE; michael@0: } michael@0: michael@0: if (aIID.Equals(NS_GET_IID(nsIXULWindow))) { michael@0: NS_ENSURE_STATE(mXULWindow); michael@0: return mXULWindow->QueryInterface(aIID, aSink); michael@0: } michael@0: michael@0: return QueryInterface(aIID, aSink); michael@0: } michael@0: michael@0: //***************************************************************************** michael@0: // nsContentTreeOwner::nsIDocShellTreeOwner michael@0: //***************************************************************************** michael@0: michael@0: NS_IMETHODIMP nsContentTreeOwner::FindItemWithName(const char16_t* aName, michael@0: nsIDocShellTreeItem* aRequestor, nsIDocShellTreeItem* aOriginalRequestor, michael@0: nsIDocShellTreeItem** aFoundItem) michael@0: { michael@0: NS_DEFINE_CID(kWindowMediatorCID, NS_WINDOWMEDIATOR_CID); michael@0: michael@0: NS_ENSURE_ARG_POINTER(aFoundItem); michael@0: michael@0: *aFoundItem = nullptr; michael@0: michael@0: bool fIs_Content = false; michael@0: michael@0: /* Special Cases */ michael@0: if (!aName || !*aName) michael@0: return NS_OK; michael@0: michael@0: nsDependentString name(aName); michael@0: michael@0: if (name.LowerCaseEqualsLiteral("_blank")) michael@0: return NS_OK; michael@0: // _main is an IE target which should be case-insensitive but isn't michael@0: // see bug 217886 for details michael@0: if (name.LowerCaseEqualsLiteral("_content") || michael@0: name.EqualsLiteral("_main")) { michael@0: // If we're being called with an aRequestor and it's targetable, just michael@0: // return it -- _main and _content from inside targetable content shells michael@0: // should just be that content shell. Note that we don't have to worry michael@0: // about the case when it's not targetable because it's primary -- that michael@0: // will Just Work when we call GetPrimaryContentShell. michael@0: NS_ENSURE_STATE(mXULWindow); michael@0: if (aRequestor) { michael@0: // This better be the root item! michael@0: #ifdef DEBUG michael@0: nsCOMPtr debugRoot; michael@0: aRequestor->GetSameTypeRootTreeItem(getter_AddRefs(debugRoot)); michael@0: NS_ASSERTION(SameCOMIdentity(debugRoot, aRequestor), michael@0: "Bogus aRequestor"); michael@0: #endif michael@0: michael@0: int32_t count = mXULWindow->mTargetableShells.Count(); michael@0: for (int32_t i = 0; i < count; ++i) { michael@0: nsCOMPtr item = michael@0: do_QueryReferent(mXULWindow->mTargetableShells[i]); michael@0: if (SameCOMIdentity(item, aRequestor)) { michael@0: NS_ADDREF(*aFoundItem = aRequestor); michael@0: return NS_OK; michael@0: } michael@0: } michael@0: } michael@0: mXULWindow->GetPrimaryContentShell(aFoundItem); michael@0: if(*aFoundItem) michael@0: return NS_OK; michael@0: // Fall through and keep looking... michael@0: fIs_Content = true; michael@0: } michael@0: michael@0: nsCOMPtr windowMediator(do_GetService(kWindowMediatorCID)); michael@0: NS_ENSURE_TRUE(windowMediator, NS_ERROR_FAILURE); michael@0: michael@0: nsCOMPtr windowEnumerator; michael@0: NS_ENSURE_SUCCESS(windowMediator->GetXULWindowEnumerator(nullptr, michael@0: getter_AddRefs(windowEnumerator)), NS_ERROR_FAILURE); michael@0: michael@0: bool more; michael@0: michael@0: windowEnumerator->HasMoreElements(&more); michael@0: while(more) { michael@0: nsCOMPtr nextWindow = nullptr; michael@0: windowEnumerator->GetNext(getter_AddRefs(nextWindow)); michael@0: nsCOMPtr xulWindow(do_QueryInterface(nextWindow)); michael@0: NS_ENSURE_TRUE(xulWindow, NS_ERROR_FAILURE); michael@0: michael@0: if (fIs_Content) { michael@0: xulWindow->GetPrimaryContentShell(aFoundItem); michael@0: } else { michael@0: // Get all the targetable windows from xulWindow and search them michael@0: nsRefPtr win; michael@0: xulWindow->QueryInterface(NS_GET_IID(nsXULWindow), getter_AddRefs(win)); michael@0: if (win) { michael@0: int32_t count = win->mTargetableShells.Count(); michael@0: int32_t i; michael@0: for (i = 0; i < count && !*aFoundItem; ++i) { michael@0: nsCOMPtr shellAsTreeItem = michael@0: do_QueryReferent(win->mTargetableShells[i]); michael@0: if (shellAsTreeItem) { michael@0: // Get the root tree item of same type, since roots are the only michael@0: // things that call into the treeowner to look for named items. michael@0: // XXXbz ideally we could guarantee that mTargetableShells only michael@0: // contains roots, but the current treeowner apis don't allow michael@0: // that... yet. michael@0: nsCOMPtr root; michael@0: shellAsTreeItem->GetSameTypeRootTreeItem(getter_AddRefs(root)); michael@0: NS_ASSERTION(root, "Must have root tree item of same type"); michael@0: shellAsTreeItem.swap(root); michael@0: if (aRequestor != shellAsTreeItem) { michael@0: // Do this so we can pass in the tree owner as the michael@0: // requestor so the child knows not to call back up. michael@0: nsCOMPtr shellOwner; michael@0: shellAsTreeItem->GetTreeOwner(getter_AddRefs(shellOwner)); michael@0: nsCOMPtr shellOwnerSupports = michael@0: do_QueryInterface(shellOwner); michael@0: michael@0: shellAsTreeItem->FindItemWithName(aName, shellOwnerSupports, michael@0: aOriginalRequestor, michael@0: aFoundItem); michael@0: } michael@0: } michael@0: } michael@0: } michael@0: } michael@0: michael@0: if (*aFoundItem) michael@0: return NS_OK; michael@0: michael@0: windowEnumerator->HasMoreElements(&more); michael@0: } michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsContentTreeOwner::ContentShellAdded(nsIDocShellTreeItem* aContentShell, michael@0: bool aPrimary, bool aTargetable, michael@0: const nsAString& aID) michael@0: { michael@0: NS_ENSURE_STATE(mXULWindow); michael@0: return mXULWindow->ContentShellAdded(aContentShell, aPrimary, aTargetable, michael@0: aID); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsContentTreeOwner::ContentShellRemoved(nsIDocShellTreeItem* aContentShell) michael@0: { michael@0: NS_ENSURE_STATE(mXULWindow); michael@0: return mXULWindow->ContentShellRemoved(aContentShell); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsContentTreeOwner::GetPrimaryContentShell(nsIDocShellTreeItem** aShell) michael@0: { michael@0: NS_ENSURE_STATE(mXULWindow); michael@0: return mXULWindow->GetPrimaryContentShell(aShell); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsContentTreeOwner::GetContentWindow(JSContext* aCx, michael@0: JS::MutableHandle aVal) michael@0: { michael@0: NS_ENSURE_STATE(mXULWindow); michael@0: return NS_ERROR_NOT_IMPLEMENTED; michael@0: } michael@0: michael@0: NS_IMETHODIMP nsContentTreeOwner::SizeShellTo(nsIDocShellTreeItem* aShellItem, michael@0: int32_t aCX, int32_t aCY) michael@0: { michael@0: NS_ENSURE_STATE(mXULWindow); michael@0: return mXULWindow->SizeShellTo(aShellItem, aCX, aCY); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsContentTreeOwner::SetPersistence(bool aPersistPosition, michael@0: bool aPersistSize, michael@0: bool aPersistSizeMode) michael@0: { michael@0: NS_ENSURE_STATE(mXULWindow); michael@0: nsCOMPtr docShellElement = mXULWindow->GetWindowDOMElement(); michael@0: if (!docShellElement) michael@0: return NS_ERROR_FAILURE; michael@0: michael@0: nsAutoString persistString; michael@0: docShellElement->GetAttribute(NS_LITERAL_STRING("persist"), persistString); michael@0: michael@0: bool saveString = false; michael@0: int32_t index; michael@0: michael@0: // Set X michael@0: index = persistString.Find("screenX"); michael@0: if (!aPersistPosition && index >= 0) { michael@0: persistString.Cut(index, 7); michael@0: saveString = true; michael@0: } else if (aPersistPosition && index < 0) { michael@0: persistString.AppendLiteral(" screenX"); michael@0: saveString = true; michael@0: } michael@0: // Set Y michael@0: index = persistString.Find("screenY"); michael@0: if (!aPersistPosition && index >= 0) { michael@0: persistString.Cut(index, 7); michael@0: saveString = true; michael@0: } else if (aPersistPosition && index < 0) { michael@0: persistString.AppendLiteral(" screenY"); michael@0: saveString = true; michael@0: } michael@0: // Set CX michael@0: index = persistString.Find("width"); michael@0: if (!aPersistSize && index >= 0) { michael@0: persistString.Cut(index, 5); michael@0: saveString = true; michael@0: } else if (aPersistSize && index < 0) { michael@0: persistString.AppendLiteral(" width"); michael@0: saveString = true; michael@0: } michael@0: // Set CY michael@0: index = persistString.Find("height"); michael@0: if (!aPersistSize && index >= 0) { michael@0: persistString.Cut(index, 6); michael@0: saveString = true; michael@0: } else if (aPersistSize && index < 0) { michael@0: persistString.AppendLiteral(" height"); michael@0: saveString = true; michael@0: } michael@0: // Set SizeMode michael@0: index = persistString.Find("sizemode"); michael@0: if (!aPersistSizeMode && (index >= 0)) { michael@0: persistString.Cut(index, 8); michael@0: saveString = true; michael@0: } else if (aPersistSizeMode && (index < 0)) { michael@0: persistString.AppendLiteral(" sizemode"); michael@0: saveString = true; michael@0: } michael@0: michael@0: ErrorResult rv; michael@0: if(saveString) { michael@0: docShellElement->SetAttribute(NS_LITERAL_STRING("persist"), persistString, rv); michael@0: } michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsContentTreeOwner::GetPersistence(bool* aPersistPosition, michael@0: bool* aPersistSize, michael@0: bool* aPersistSizeMode) michael@0: { michael@0: NS_ENSURE_STATE(mXULWindow); michael@0: nsCOMPtr docShellElement = mXULWindow->GetWindowDOMElement(); michael@0: if (!docShellElement) michael@0: return NS_ERROR_FAILURE; michael@0: michael@0: nsAutoString persistString; michael@0: docShellElement->GetAttribute(NS_LITERAL_STRING("persist"), persistString); michael@0: michael@0: // data structure doesn't quite match the question, but it's close enough michael@0: // for what we want (since this method is never actually called...) michael@0: if (aPersistPosition) michael@0: *aPersistPosition = persistString.Find("screenX") >= 0 || persistString.Find("screenY") >= 0 ? true : false; michael@0: if (aPersistSize) michael@0: *aPersistSize = persistString.Find("width") >= 0 || persistString.Find("height") >= 0 ? true : false; michael@0: if (aPersistSizeMode) michael@0: *aPersistSizeMode = persistString.Find("sizemode") >= 0 ? true : false; michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsContentTreeOwner::GetTargetableShellCount(uint32_t* aResult) michael@0: { michael@0: NS_ENSURE_STATE(mXULWindow); michael@0: *aResult = mXULWindow->mTargetableShells.Count(); michael@0: return NS_OK; michael@0: } michael@0: michael@0: //***************************************************************************** michael@0: // nsContentTreeOwner::nsIWebBrowserChrome3 michael@0: //***************************************************************************** michael@0: michael@0: NS_IMETHODIMP nsContentTreeOwner::OnBeforeLinkTraversal(const nsAString &originalTarget, michael@0: nsIURI *linkURI, michael@0: nsIDOMNode *linkNode, michael@0: bool isAppTab, michael@0: nsAString &_retval) michael@0: { michael@0: NS_ENSURE_STATE(mXULWindow); michael@0: michael@0: nsCOMPtr xulBrowserWindow; michael@0: mXULWindow->GetXULBrowserWindow(getter_AddRefs(xulBrowserWindow)); michael@0: michael@0: if (xulBrowserWindow) michael@0: return xulBrowserWindow->OnBeforeLinkTraversal(originalTarget, linkURI, michael@0: linkNode, isAppTab, _retval); michael@0: michael@0: _retval = originalTarget; michael@0: return NS_OK; michael@0: } michael@0: michael@0: //***************************************************************************** michael@0: // nsContentTreeOwner::nsIWebBrowserChrome2 michael@0: //***************************************************************************** michael@0: michael@0: NS_IMETHODIMP nsContentTreeOwner::SetStatusWithContext(uint32_t aStatusType, michael@0: const nsAString &aStatusText, michael@0: nsISupports *aStatusContext) michael@0: { michael@0: // We only allow the status to be set from the primary content shell michael@0: if (!mPrimary && aStatusType != STATUS_LINK) michael@0: return NS_OK; michael@0: michael@0: NS_ENSURE_STATE(mXULWindow); michael@0: michael@0: nsCOMPtr xulBrowserWindow; michael@0: mXULWindow->GetXULBrowserWindow(getter_AddRefs(xulBrowserWindow)); michael@0: michael@0: if (xulBrowserWindow) michael@0: { michael@0: switch(aStatusType) michael@0: { michael@0: case STATUS_SCRIPT: michael@0: xulBrowserWindow->SetJSStatus(aStatusText); michael@0: break; michael@0: case STATUS_LINK: michael@0: { michael@0: nsCOMPtr element = do_QueryInterface(aStatusContext); michael@0: xulBrowserWindow->SetOverLink(aStatusText, element); michael@0: break; michael@0: } michael@0: } michael@0: } michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: //***************************************************************************** michael@0: // nsContentTreeOwner::nsIWebBrowserChrome michael@0: //***************************************************************************** michael@0: michael@0: NS_IMETHODIMP nsContentTreeOwner::SetStatus(uint32_t aStatusType, michael@0: const char16_t* aStatus) michael@0: { michael@0: return SetStatusWithContext(aStatusType, michael@0: aStatus ? static_cast(nsDependentString(aStatus)) michael@0: : EmptyString(), michael@0: nullptr); michael@0: } michael@0: michael@0: NS_IMETHODIMP nsContentTreeOwner::SetWebBrowser(nsIWebBrowser* aWebBrowser) michael@0: { michael@0: NS_ERROR("Haven't Implemented this yet"); michael@0: return NS_ERROR_FAILURE; michael@0: } michael@0: michael@0: NS_IMETHODIMP nsContentTreeOwner::GetWebBrowser(nsIWebBrowser** aWebBrowser) michael@0: { michael@0: // Unimplemented, and probably will remain so; xpfe windows have docshells, michael@0: // not webbrowsers. michael@0: NS_ENSURE_ARG_POINTER(aWebBrowser); michael@0: *aWebBrowser = 0; michael@0: return NS_ERROR_FAILURE; michael@0: } michael@0: michael@0: NS_IMETHODIMP nsContentTreeOwner::SetChromeFlags(uint32_t aChromeFlags) michael@0: { michael@0: NS_ENSURE_STATE(mXULWindow); michael@0: return mXULWindow->SetChromeFlags(aChromeFlags); michael@0: } michael@0: michael@0: NS_IMETHODIMP nsContentTreeOwner::GetChromeFlags(uint32_t* aChromeFlags) michael@0: { michael@0: NS_ENSURE_STATE(mXULWindow); michael@0: return mXULWindow->GetChromeFlags(aChromeFlags); michael@0: } michael@0: michael@0: NS_IMETHODIMP nsContentTreeOwner::DestroyBrowserWindow() michael@0: { michael@0: NS_ERROR("Haven't Implemented this yet"); michael@0: return NS_ERROR_FAILURE; michael@0: } michael@0: michael@0: NS_IMETHODIMP nsContentTreeOwner::SizeBrowserTo(int32_t aCX, int32_t aCY) michael@0: { michael@0: NS_ERROR("Haven't Implemented this yet"); michael@0: return NS_ERROR_FAILURE; michael@0: } michael@0: michael@0: NS_IMETHODIMP nsContentTreeOwner::ShowAsModal() michael@0: { michael@0: NS_ENSURE_STATE(mXULWindow); michael@0: return mXULWindow->ShowModal(); michael@0: } michael@0: michael@0: NS_IMETHODIMP nsContentTreeOwner::IsWindowModal(bool *_retval) michael@0: { michael@0: NS_ENSURE_STATE(mXULWindow); michael@0: *_retval = mXULWindow->mContinueModalLoop; michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP nsContentTreeOwner::ExitModalEventLoop(nsresult aStatus) michael@0: { michael@0: NS_ENSURE_STATE(mXULWindow); michael@0: return mXULWindow->ExitModalLoop(aStatus); michael@0: } michael@0: michael@0: //***************************************************************************** michael@0: // nsContentTreeOwner::nsIBaseWindow michael@0: //***************************************************************************** michael@0: michael@0: NS_IMETHODIMP nsContentTreeOwner::InitWindow(nativeWindow aParentNativeWindow, michael@0: nsIWidget* parentWidget, int32_t x, int32_t y, int32_t cx, int32_t cy) michael@0: { michael@0: // Ignore wigdet parents for now. Don't think those are a vaild thing to call. michael@0: NS_ENSURE_SUCCESS(SetPositionAndSize(x, y, cx, cy, false), NS_ERROR_FAILURE); michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP nsContentTreeOwner::Create() michael@0: { michael@0: NS_ASSERTION(false, "You can't call this"); michael@0: return NS_ERROR_UNEXPECTED; michael@0: } michael@0: michael@0: NS_IMETHODIMP nsContentTreeOwner::Destroy() michael@0: { michael@0: NS_ENSURE_STATE(mXULWindow); michael@0: return mXULWindow->Destroy(); michael@0: } michael@0: michael@0: NS_IMETHODIMP nsContentTreeOwner::GetUnscaledDevicePixelsPerCSSPixel(double* aScale) michael@0: { michael@0: NS_ENSURE_STATE(mXULWindow); michael@0: return mXULWindow->GetUnscaledDevicePixelsPerCSSPixel(aScale); michael@0: } michael@0: michael@0: NS_IMETHODIMP nsContentTreeOwner::SetPosition(int32_t aX, int32_t aY) michael@0: { michael@0: NS_ENSURE_STATE(mXULWindow); michael@0: return mXULWindow->SetPosition(aX, aY); michael@0: } michael@0: michael@0: NS_IMETHODIMP nsContentTreeOwner::GetPosition(int32_t* aX, int32_t* aY) michael@0: { michael@0: NS_ENSURE_STATE(mXULWindow); michael@0: return mXULWindow->GetPosition(aX, aY); michael@0: } michael@0: michael@0: NS_IMETHODIMP nsContentTreeOwner::SetSize(int32_t aCX, int32_t aCY, bool aRepaint) michael@0: { michael@0: NS_ENSURE_STATE(mXULWindow); michael@0: return mXULWindow->SetSize(aCX, aCY, aRepaint); michael@0: } michael@0: michael@0: NS_IMETHODIMP nsContentTreeOwner::GetSize(int32_t* aCX, int32_t* aCY) michael@0: { michael@0: NS_ENSURE_STATE(mXULWindow); michael@0: return mXULWindow->GetSize(aCX, aCY); michael@0: } michael@0: michael@0: NS_IMETHODIMP nsContentTreeOwner::SetPositionAndSize(int32_t aX, int32_t aY, michael@0: int32_t aCX, int32_t aCY, bool aRepaint) michael@0: { michael@0: NS_ENSURE_STATE(mXULWindow); michael@0: return mXULWindow->SetPositionAndSize(aX, aY, aCX, aCY, aRepaint); michael@0: } michael@0: michael@0: NS_IMETHODIMP nsContentTreeOwner::GetPositionAndSize(int32_t* aX, int32_t* aY, michael@0: int32_t* aCX, int32_t* aCY) michael@0: { michael@0: NS_ENSURE_STATE(mXULWindow); michael@0: return mXULWindow->GetPositionAndSize(aX, aY, aCX, aCY); michael@0: } michael@0: michael@0: NS_IMETHODIMP nsContentTreeOwner::Repaint(bool aForce) michael@0: { michael@0: NS_ENSURE_STATE(mXULWindow); michael@0: return mXULWindow->Repaint(aForce); michael@0: } michael@0: michael@0: NS_IMETHODIMP nsContentTreeOwner::GetParentWidget(nsIWidget** aParentWidget) michael@0: { michael@0: NS_ENSURE_STATE(mXULWindow); michael@0: return mXULWindow->GetParentWidget(aParentWidget); michael@0: } michael@0: michael@0: NS_IMETHODIMP nsContentTreeOwner::SetParentWidget(nsIWidget* aParentWidget) michael@0: { michael@0: NS_ASSERTION(false, "You can't call this"); michael@0: return NS_ERROR_NOT_IMPLEMENTED; michael@0: } michael@0: michael@0: NS_IMETHODIMP nsContentTreeOwner::GetParentNativeWindow(nativeWindow* aParentNativeWindow) michael@0: { michael@0: NS_ENSURE_STATE(mXULWindow); michael@0: return mXULWindow->GetParentNativeWindow(aParentNativeWindow); michael@0: } michael@0: michael@0: NS_IMETHODIMP nsContentTreeOwner::SetParentNativeWindow(nativeWindow aParentNativeWindow) michael@0: { michael@0: NS_ASSERTION(false, "You can't call this"); michael@0: return NS_ERROR_NOT_IMPLEMENTED; michael@0: } michael@0: michael@0: NS_IMETHODIMP nsContentTreeOwner::GetNativeHandle(nsAString& aNativeHandle) michael@0: { michael@0: NS_ENSURE_STATE(mXULWindow); michael@0: return mXULWindow->GetNativeHandle(aNativeHandle); michael@0: } michael@0: michael@0: NS_IMETHODIMP nsContentTreeOwner::GetVisibility(bool* aVisibility) michael@0: { michael@0: NS_ENSURE_STATE(mXULWindow); michael@0: return mXULWindow->GetVisibility(aVisibility); michael@0: } michael@0: michael@0: NS_IMETHODIMP nsContentTreeOwner::SetVisibility(bool aVisibility) michael@0: { michael@0: NS_ENSURE_STATE(mXULWindow); michael@0: return mXULWindow->SetVisibility(aVisibility); michael@0: } michael@0: michael@0: NS_IMETHODIMP nsContentTreeOwner::GetEnabled(bool *aEnabled) michael@0: { michael@0: NS_ENSURE_STATE(mXULWindow); michael@0: return mXULWindow->GetEnabled(aEnabled); michael@0: } michael@0: michael@0: NS_IMETHODIMP nsContentTreeOwner::SetEnabled(bool aEnable) michael@0: { michael@0: NS_ENSURE_STATE(mXULWindow); michael@0: return mXULWindow->SetEnabled(aEnable); michael@0: } michael@0: michael@0: NS_IMETHODIMP nsContentTreeOwner::GetMainWidget(nsIWidget** aMainWidget) michael@0: { michael@0: NS_ENSURE_ARG_POINTER(aMainWidget); michael@0: NS_ENSURE_STATE(mXULWindow); michael@0: michael@0: *aMainWidget = mXULWindow->mWindow; michael@0: NS_IF_ADDREF(*aMainWidget); michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP nsContentTreeOwner::SetFocus() michael@0: { michael@0: NS_ENSURE_STATE(mXULWindow); michael@0: return mXULWindow->SetFocus(); michael@0: } michael@0: michael@0: NS_IMETHODIMP nsContentTreeOwner::GetTitle(char16_t** aTitle) michael@0: { michael@0: NS_ENSURE_ARG_POINTER(aTitle); michael@0: NS_ENSURE_STATE(mXULWindow); michael@0: michael@0: return mXULWindow->GetTitle(aTitle); michael@0: } michael@0: michael@0: NS_IMETHODIMP nsContentTreeOwner::SetTitle(const char16_t* aTitle) michael@0: { michael@0: // We only allow the title to be set from the primary content shell michael@0: if(!mPrimary || !mContentTitleSetting) michael@0: return NS_OK; michael@0: michael@0: NS_ENSURE_STATE(mXULWindow); michael@0: michael@0: nsAutoString title; michael@0: nsAutoString docTitle(aTitle); michael@0: michael@0: if (docTitle.IsEmpty()) michael@0: docTitle.Assign(mTitleDefault); michael@0: michael@0: if (!docTitle.IsEmpty()) { michael@0: if (!mTitlePreface.IsEmpty()) { michael@0: // Title will be: "Preface: Doc Title - Mozilla" michael@0: title.Assign(mTitlePreface); michael@0: title.Append(docTitle); michael@0: } michael@0: else { michael@0: // Title will be: "Doc Title - Mozilla" michael@0: title = docTitle; michael@0: } michael@0: michael@0: if (!mWindowTitleModifier.IsEmpty()) michael@0: title += mTitleSeparator + mWindowTitleModifier; michael@0: } michael@0: else michael@0: title.Assign(mWindowTitleModifier); // Title will just be plain "Mozilla" michael@0: michael@0: // michael@0: // if there is no location bar we modify the title to display at least michael@0: // the scheme and host (if any) as an anti-spoofing measure. michael@0: // michael@0: nsCOMPtr docShellElement = mXULWindow->GetWindowDOMElement(); michael@0: michael@0: if (docShellElement) { michael@0: nsAutoString chromeString; michael@0: docShellElement->GetAttribute(NS_LITERAL_STRING("chromehidden"), chromeString); michael@0: if (chromeString.Find(NS_LITERAL_STRING("location")) != kNotFound) { michael@0: // michael@0: // location bar is turned off, find the browser location michael@0: // michael@0: // use the document's nsPrincipal to find the true owner michael@0: // in case of javascript: or data: documents michael@0: // michael@0: nsCOMPtr dsitem; michael@0: GetPrimaryContentShell(getter_AddRefs(dsitem)); michael@0: nsCOMPtr domdoc(do_GetInterface(dsitem)); michael@0: nsCOMPtr doc(do_QueryInterface(domdoc)); michael@0: if (doc) { michael@0: nsCOMPtr uri; michael@0: nsIPrincipal* principal = doc->GetPrincipal(); michael@0: if (principal) { michael@0: principal->GetURI(getter_AddRefs(uri)); michael@0: if (uri) { michael@0: // michael@0: // remove any user:pass information michael@0: // michael@0: nsCOMPtr fixup(do_GetService(NS_URIFIXUP_CONTRACTID)); michael@0: if (fixup) { michael@0: nsCOMPtr tmpuri; michael@0: nsresult rv = fixup->CreateExposableURI(uri,getter_AddRefs(tmpuri)); michael@0: if (NS_SUCCEEDED(rv) && tmpuri) { michael@0: // (don't bother if there's no host) michael@0: nsAutoCString host; michael@0: nsAutoCString prepath; michael@0: tmpuri->GetHost(host); michael@0: tmpuri->GetPrePath(prepath); michael@0: if (!host.IsEmpty()) { michael@0: // michael@0: // We have a scheme/host, update the title michael@0: // michael@0: title.Insert(NS_ConvertUTF8toUTF16(prepath) + michael@0: mTitleSeparator, 0); michael@0: } michael@0: } michael@0: } michael@0: } michael@0: } michael@0: } michael@0: } michael@0: nsIDocument* document = docShellElement->OwnerDoc(); michael@0: ErrorResult rv; michael@0: document->SetTitle(title, rv); michael@0: return rv.ErrorCode(); michael@0: } michael@0: michael@0: return mXULWindow->SetTitle(title.get()); michael@0: } michael@0: michael@0: //***************************************************************************** michael@0: // nsContentTreeOwner: nsIWindowProvider michael@0: //***************************************************************************** michael@0: NS_IMETHODIMP michael@0: nsContentTreeOwner::ProvideWindow(nsIDOMWindow* aParent, michael@0: uint32_t aChromeFlags, michael@0: bool aCalledFromJS, michael@0: bool aPositionSpecified, michael@0: bool aSizeSpecified, michael@0: nsIURI* aURI, michael@0: const nsAString& aName, michael@0: const nsACString& aFeatures, michael@0: bool* aWindowIsNew, michael@0: nsIDOMWindow** aReturn) michael@0: { michael@0: NS_ENSURE_ARG_POINTER(aParent); michael@0: michael@0: *aReturn = nullptr; michael@0: michael@0: if (!mXULWindow) { michael@0: // Nothing to do here michael@0: return NS_OK; michael@0: } michael@0: michael@0: #ifdef DEBUG michael@0: nsCOMPtr parentNav = do_GetInterface(aParent); michael@0: nsCOMPtr parentOwner = do_GetInterface(parentNav); michael@0: NS_ASSERTION(SameCOMIdentity(parentOwner, michael@0: static_cast(this)), michael@0: "Parent from wrong docshell tree?"); michael@0: #endif michael@0: michael@0: // If aParent is inside an