1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/xpfe/appshell/src/nsContentTreeOwner.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,1179 @@ 1.4 +/* -*- Mode: C++; tab-width: 3; indent-tabs-mode: nil; c-basic-offset: 2 -*- 1.5 + * vim: set ts=2 sw=2 et tw=79: 1.6 + * 1.7 + * This Source Code Form is subject to the terms of the Mozilla Public 1.8 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.9 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.10 + 1.11 +// Local Includes 1.12 +#include "nsContentTreeOwner.h" 1.13 +#include "nsXULWindow.h" 1.14 + 1.15 +// Helper Classes 1.16 +#include "nsIServiceManager.h" 1.17 +#include "nsAutoPtr.h" 1.18 + 1.19 +// Interfaces needed to be included 1.20 +#include "nsIDOMNode.h" 1.21 +#include "nsIDOMElement.h" 1.22 +#include "nsIDOMNodeList.h" 1.23 +#include "nsIDOMWindow.h" 1.24 +#include "nsIDOMChromeWindow.h" 1.25 +#include "nsIBrowserDOMWindow.h" 1.26 +#include "nsIDOMXULElement.h" 1.27 +#include "nsIEmbeddingSiteWindow.h" 1.28 +#include "nsIPrompt.h" 1.29 +#include "nsIAuthPrompt.h" 1.30 +#include "nsIWindowMediator.h" 1.31 +#include "nsIXULBrowserWindow.h" 1.32 +#include "nsIPrincipal.h" 1.33 +#include "nsIURIFixup.h" 1.34 +#include "nsCDefaultURIFixup.h" 1.35 +#include "nsIWebNavigation.h" 1.36 +#include "nsDocShellCID.h" 1.37 +#include "nsIExternalURLHandlerService.h" 1.38 +#include "nsIMIMEInfo.h" 1.39 +#include "nsIWidget.h" 1.40 +#include "mozilla/BrowserElementParent.h" 1.41 + 1.42 +#include "nsIDOMDocument.h" 1.43 +#include "nsIScriptObjectPrincipal.h" 1.44 +#include "nsIURI.h" 1.45 +#include "nsIDocument.h" 1.46 +#if defined(XP_MACOSX) 1.47 +#include "nsThreadUtils.h" 1.48 +#endif 1.49 + 1.50 +#include "mozilla/Preferences.h" 1.51 +#include "mozilla/dom/Element.h" 1.52 +#include "mozilla/dom/ScriptSettings.h" 1.53 + 1.54 +using namespace mozilla; 1.55 + 1.56 +//***************************************************************************** 1.57 +//*** nsSiteWindow declaration 1.58 +//***************************************************************************** 1.59 + 1.60 +class nsSiteWindow : public nsIEmbeddingSiteWindow 1.61 +{ 1.62 +public: 1.63 + nsSiteWindow(nsContentTreeOwner *aAggregator); 1.64 + virtual ~nsSiteWindow(); 1.65 + 1.66 + NS_DECL_ISUPPORTS 1.67 + NS_DECL_NSIEMBEDDINGSITEWINDOW 1.68 + 1.69 +private: 1.70 + nsContentTreeOwner *mAggregator; 1.71 +}; 1.72 + 1.73 +//***************************************************************************** 1.74 +//*** nsContentTreeOwner: Object Management 1.75 +//***************************************************************************** 1.76 + 1.77 +nsContentTreeOwner::nsContentTreeOwner(bool fPrimary) : mXULWindow(nullptr), 1.78 + mPrimary(fPrimary), mContentTitleSetting(false) 1.79 +{ 1.80 + // note if this fails, QI on nsIEmbeddingSiteWindow(2) will simply fail 1.81 + mSiteWindow = new nsSiteWindow(this); 1.82 +} 1.83 + 1.84 +nsContentTreeOwner::~nsContentTreeOwner() 1.85 +{ 1.86 + delete mSiteWindow; 1.87 +} 1.88 + 1.89 +//***************************************************************************** 1.90 +// nsContentTreeOwner::nsISupports 1.91 +//***************************************************************************** 1.92 + 1.93 +NS_IMPL_ADDREF(nsContentTreeOwner) 1.94 +NS_IMPL_RELEASE(nsContentTreeOwner) 1.95 + 1.96 +NS_INTERFACE_MAP_BEGIN(nsContentTreeOwner) 1.97 + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDocShellTreeOwner) 1.98 + NS_INTERFACE_MAP_ENTRY(nsIDocShellTreeOwner) 1.99 + NS_INTERFACE_MAP_ENTRY(nsIBaseWindow) 1.100 + NS_INTERFACE_MAP_ENTRY(nsIWebBrowserChrome) 1.101 + NS_INTERFACE_MAP_ENTRY(nsIWebBrowserChrome2) 1.102 + NS_INTERFACE_MAP_ENTRY(nsIWebBrowserChrome3) 1.103 + NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor) 1.104 + NS_INTERFACE_MAP_ENTRY(nsIWindowProvider) 1.105 + // NOTE: This is using aggregation because there are some properties and 1.106 + // method on nsIBaseWindow (which we implement) and on 1.107 + // nsIEmbeddingSiteWindow (which we also implement) that have the same name. 1.108 + // And it just so happens that we want different behavior for these methods 1.109 + // and properties depending on the interface through which they're called 1.110 + // (SetFocus() is a good example here). If it were not for that, we could 1.111 + // ditch the aggregation and just deal with not being able to use NS_DECL_* 1.112 + // macros for this stuff.... 1.113 + NS_INTERFACE_MAP_ENTRY_AGGREGATED(nsIEmbeddingSiteWindow, mSiteWindow) 1.114 +NS_INTERFACE_MAP_END 1.115 + 1.116 +//***************************************************************************** 1.117 +// nsContentTreeOwner::nsIInterfaceRequestor 1.118 +//***************************************************************************** 1.119 + 1.120 +NS_IMETHODIMP nsContentTreeOwner::GetInterface(const nsIID& aIID, void** aSink) 1.121 +{ 1.122 + NS_ENSURE_ARG_POINTER(aSink); 1.123 + *aSink = 0; 1.124 + 1.125 + if(aIID.Equals(NS_GET_IID(nsIPrompt))) { 1.126 + NS_ENSURE_STATE(mXULWindow); 1.127 + return mXULWindow->GetInterface(aIID, aSink); 1.128 + } 1.129 + if(aIID.Equals(NS_GET_IID(nsIAuthPrompt))) { 1.130 + NS_ENSURE_STATE(mXULWindow); 1.131 + return mXULWindow->GetInterface(aIID, aSink); 1.132 + } 1.133 + if (aIID.Equals(NS_GET_IID(nsIDocShellTreeItem))) { 1.134 + NS_ENSURE_STATE(mXULWindow); 1.135 + nsCOMPtr<nsIDocShell> shell; 1.136 + mXULWindow->GetDocShell(getter_AddRefs(shell)); 1.137 + if (shell) 1.138 + return shell->QueryInterface(aIID, aSink); 1.139 + return NS_ERROR_FAILURE; 1.140 + } 1.141 + 1.142 + if (aIID.Equals(NS_GET_IID(nsIDOMWindow))) { 1.143 + NS_ENSURE_STATE(mXULWindow); 1.144 + nsCOMPtr<nsIDocShellTreeItem> shell; 1.145 + mXULWindow->GetPrimaryContentShell(getter_AddRefs(shell)); 1.146 + if (shell) { 1.147 + nsCOMPtr<nsIInterfaceRequestor> thing(do_QueryInterface(shell)); 1.148 + if (thing) 1.149 + return thing->GetInterface(aIID, aSink); 1.150 + } 1.151 + return NS_ERROR_FAILURE; 1.152 + } 1.153 + 1.154 + if (aIID.Equals(NS_GET_IID(nsIXULWindow))) { 1.155 + NS_ENSURE_STATE(mXULWindow); 1.156 + return mXULWindow->QueryInterface(aIID, aSink); 1.157 + } 1.158 + 1.159 + return QueryInterface(aIID, aSink); 1.160 +} 1.161 + 1.162 +//***************************************************************************** 1.163 +// nsContentTreeOwner::nsIDocShellTreeOwner 1.164 +//***************************************************************************** 1.165 + 1.166 +NS_IMETHODIMP nsContentTreeOwner::FindItemWithName(const char16_t* aName, 1.167 + nsIDocShellTreeItem* aRequestor, nsIDocShellTreeItem* aOriginalRequestor, 1.168 + nsIDocShellTreeItem** aFoundItem) 1.169 +{ 1.170 + NS_DEFINE_CID(kWindowMediatorCID, NS_WINDOWMEDIATOR_CID); 1.171 + 1.172 + NS_ENSURE_ARG_POINTER(aFoundItem); 1.173 + 1.174 + *aFoundItem = nullptr; 1.175 + 1.176 + bool fIs_Content = false; 1.177 + 1.178 + /* Special Cases */ 1.179 + if (!aName || !*aName) 1.180 + return NS_OK; 1.181 + 1.182 + nsDependentString name(aName); 1.183 + 1.184 + if (name.LowerCaseEqualsLiteral("_blank")) 1.185 + return NS_OK; 1.186 + // _main is an IE target which should be case-insensitive but isn't 1.187 + // see bug 217886 for details 1.188 + if (name.LowerCaseEqualsLiteral("_content") || 1.189 + name.EqualsLiteral("_main")) { 1.190 + // If we're being called with an aRequestor and it's targetable, just 1.191 + // return it -- _main and _content from inside targetable content shells 1.192 + // should just be that content shell. Note that we don't have to worry 1.193 + // about the case when it's not targetable because it's primary -- that 1.194 + // will Just Work when we call GetPrimaryContentShell. 1.195 + NS_ENSURE_STATE(mXULWindow); 1.196 + if (aRequestor) { 1.197 + // This better be the root item! 1.198 +#ifdef DEBUG 1.199 + nsCOMPtr<nsIDocShellTreeItem> debugRoot; 1.200 + aRequestor->GetSameTypeRootTreeItem(getter_AddRefs(debugRoot)); 1.201 + NS_ASSERTION(SameCOMIdentity(debugRoot, aRequestor), 1.202 + "Bogus aRequestor"); 1.203 +#endif 1.204 + 1.205 + int32_t count = mXULWindow->mTargetableShells.Count(); 1.206 + for (int32_t i = 0; i < count; ++i) { 1.207 + nsCOMPtr<nsIDocShellTreeItem> item = 1.208 + do_QueryReferent(mXULWindow->mTargetableShells[i]); 1.209 + if (SameCOMIdentity(item, aRequestor)) { 1.210 + NS_ADDREF(*aFoundItem = aRequestor); 1.211 + return NS_OK; 1.212 + } 1.213 + } 1.214 + } 1.215 + mXULWindow->GetPrimaryContentShell(aFoundItem); 1.216 + if(*aFoundItem) 1.217 + return NS_OK; 1.218 + // Fall through and keep looking... 1.219 + fIs_Content = true; 1.220 + } 1.221 + 1.222 + nsCOMPtr<nsIWindowMediator> windowMediator(do_GetService(kWindowMediatorCID)); 1.223 + NS_ENSURE_TRUE(windowMediator, NS_ERROR_FAILURE); 1.224 + 1.225 + nsCOMPtr<nsISimpleEnumerator> windowEnumerator; 1.226 + NS_ENSURE_SUCCESS(windowMediator->GetXULWindowEnumerator(nullptr, 1.227 + getter_AddRefs(windowEnumerator)), NS_ERROR_FAILURE); 1.228 + 1.229 + bool more; 1.230 + 1.231 + windowEnumerator->HasMoreElements(&more); 1.232 + while(more) { 1.233 + nsCOMPtr<nsISupports> nextWindow = nullptr; 1.234 + windowEnumerator->GetNext(getter_AddRefs(nextWindow)); 1.235 + nsCOMPtr<nsIXULWindow> xulWindow(do_QueryInterface(nextWindow)); 1.236 + NS_ENSURE_TRUE(xulWindow, NS_ERROR_FAILURE); 1.237 + 1.238 + if (fIs_Content) { 1.239 + xulWindow->GetPrimaryContentShell(aFoundItem); 1.240 + } else { 1.241 + // Get all the targetable windows from xulWindow and search them 1.242 + nsRefPtr<nsXULWindow> win; 1.243 + xulWindow->QueryInterface(NS_GET_IID(nsXULWindow), getter_AddRefs(win)); 1.244 + if (win) { 1.245 + int32_t count = win->mTargetableShells.Count(); 1.246 + int32_t i; 1.247 + for (i = 0; i < count && !*aFoundItem; ++i) { 1.248 + nsCOMPtr<nsIDocShellTreeItem> shellAsTreeItem = 1.249 + do_QueryReferent(win->mTargetableShells[i]); 1.250 + if (shellAsTreeItem) { 1.251 + // Get the root tree item of same type, since roots are the only 1.252 + // things that call into the treeowner to look for named items. 1.253 + // XXXbz ideally we could guarantee that mTargetableShells only 1.254 + // contains roots, but the current treeowner apis don't allow 1.255 + // that... yet. 1.256 + nsCOMPtr<nsIDocShellTreeItem> root; 1.257 + shellAsTreeItem->GetSameTypeRootTreeItem(getter_AddRefs(root)); 1.258 + NS_ASSERTION(root, "Must have root tree item of same type"); 1.259 + shellAsTreeItem.swap(root); 1.260 + if (aRequestor != shellAsTreeItem) { 1.261 + // Do this so we can pass in the tree owner as the 1.262 + // requestor so the child knows not to call back up. 1.263 + nsCOMPtr<nsIDocShellTreeOwner> shellOwner; 1.264 + shellAsTreeItem->GetTreeOwner(getter_AddRefs(shellOwner)); 1.265 + nsCOMPtr<nsISupports> shellOwnerSupports = 1.266 + do_QueryInterface(shellOwner); 1.267 + 1.268 + shellAsTreeItem->FindItemWithName(aName, shellOwnerSupports, 1.269 + aOriginalRequestor, 1.270 + aFoundItem); 1.271 + } 1.272 + } 1.273 + } 1.274 + } 1.275 + } 1.276 + 1.277 + if (*aFoundItem) 1.278 + return NS_OK; 1.279 + 1.280 + windowEnumerator->HasMoreElements(&more); 1.281 + } 1.282 + return NS_OK; 1.283 +} 1.284 + 1.285 +NS_IMETHODIMP 1.286 +nsContentTreeOwner::ContentShellAdded(nsIDocShellTreeItem* aContentShell, 1.287 + bool aPrimary, bool aTargetable, 1.288 + const nsAString& aID) 1.289 +{ 1.290 + NS_ENSURE_STATE(mXULWindow); 1.291 + return mXULWindow->ContentShellAdded(aContentShell, aPrimary, aTargetable, 1.292 + aID); 1.293 +} 1.294 + 1.295 +NS_IMETHODIMP 1.296 +nsContentTreeOwner::ContentShellRemoved(nsIDocShellTreeItem* aContentShell) 1.297 +{ 1.298 + NS_ENSURE_STATE(mXULWindow); 1.299 + return mXULWindow->ContentShellRemoved(aContentShell); 1.300 +} 1.301 + 1.302 +NS_IMETHODIMP 1.303 +nsContentTreeOwner::GetPrimaryContentShell(nsIDocShellTreeItem** aShell) 1.304 +{ 1.305 + NS_ENSURE_STATE(mXULWindow); 1.306 + return mXULWindow->GetPrimaryContentShell(aShell); 1.307 +} 1.308 + 1.309 +NS_IMETHODIMP 1.310 +nsContentTreeOwner::GetContentWindow(JSContext* aCx, 1.311 + JS::MutableHandle<JS::Value> aVal) 1.312 +{ 1.313 + NS_ENSURE_STATE(mXULWindow); 1.314 + return NS_ERROR_NOT_IMPLEMENTED; 1.315 +} 1.316 + 1.317 +NS_IMETHODIMP nsContentTreeOwner::SizeShellTo(nsIDocShellTreeItem* aShellItem, 1.318 + int32_t aCX, int32_t aCY) 1.319 +{ 1.320 + NS_ENSURE_STATE(mXULWindow); 1.321 + return mXULWindow->SizeShellTo(aShellItem, aCX, aCY); 1.322 +} 1.323 + 1.324 +NS_IMETHODIMP 1.325 +nsContentTreeOwner::SetPersistence(bool aPersistPosition, 1.326 + bool aPersistSize, 1.327 + bool aPersistSizeMode) 1.328 +{ 1.329 + NS_ENSURE_STATE(mXULWindow); 1.330 + nsCOMPtr<dom::Element> docShellElement = mXULWindow->GetWindowDOMElement(); 1.331 + if (!docShellElement) 1.332 + return NS_ERROR_FAILURE; 1.333 + 1.334 + nsAutoString persistString; 1.335 + docShellElement->GetAttribute(NS_LITERAL_STRING("persist"), persistString); 1.336 + 1.337 + bool saveString = false; 1.338 + int32_t index; 1.339 + 1.340 + // Set X 1.341 + index = persistString.Find("screenX"); 1.342 + if (!aPersistPosition && index >= 0) { 1.343 + persistString.Cut(index, 7); 1.344 + saveString = true; 1.345 + } else if (aPersistPosition && index < 0) { 1.346 + persistString.AppendLiteral(" screenX"); 1.347 + saveString = true; 1.348 + } 1.349 + // Set Y 1.350 + index = persistString.Find("screenY"); 1.351 + if (!aPersistPosition && index >= 0) { 1.352 + persistString.Cut(index, 7); 1.353 + saveString = true; 1.354 + } else if (aPersistPosition && index < 0) { 1.355 + persistString.AppendLiteral(" screenY"); 1.356 + saveString = true; 1.357 + } 1.358 + // Set CX 1.359 + index = persistString.Find("width"); 1.360 + if (!aPersistSize && index >= 0) { 1.361 + persistString.Cut(index, 5); 1.362 + saveString = true; 1.363 + } else if (aPersistSize && index < 0) { 1.364 + persistString.AppendLiteral(" width"); 1.365 + saveString = true; 1.366 + } 1.367 + // Set CY 1.368 + index = persistString.Find("height"); 1.369 + if (!aPersistSize && index >= 0) { 1.370 + persistString.Cut(index, 6); 1.371 + saveString = true; 1.372 + } else if (aPersistSize && index < 0) { 1.373 + persistString.AppendLiteral(" height"); 1.374 + saveString = true; 1.375 + } 1.376 + // Set SizeMode 1.377 + index = persistString.Find("sizemode"); 1.378 + if (!aPersistSizeMode && (index >= 0)) { 1.379 + persistString.Cut(index, 8); 1.380 + saveString = true; 1.381 + } else if (aPersistSizeMode && (index < 0)) { 1.382 + persistString.AppendLiteral(" sizemode"); 1.383 + saveString = true; 1.384 + } 1.385 + 1.386 + ErrorResult rv; 1.387 + if(saveString) { 1.388 + docShellElement->SetAttribute(NS_LITERAL_STRING("persist"), persistString, rv); 1.389 + } 1.390 + 1.391 + return NS_OK; 1.392 +} 1.393 + 1.394 +NS_IMETHODIMP 1.395 +nsContentTreeOwner::GetPersistence(bool* aPersistPosition, 1.396 + bool* aPersistSize, 1.397 + bool* aPersistSizeMode) 1.398 +{ 1.399 + NS_ENSURE_STATE(mXULWindow); 1.400 + nsCOMPtr<dom::Element> docShellElement = mXULWindow->GetWindowDOMElement(); 1.401 + if (!docShellElement) 1.402 + return NS_ERROR_FAILURE; 1.403 + 1.404 + nsAutoString persistString; 1.405 + docShellElement->GetAttribute(NS_LITERAL_STRING("persist"), persistString); 1.406 + 1.407 + // data structure doesn't quite match the question, but it's close enough 1.408 + // for what we want (since this method is never actually called...) 1.409 + if (aPersistPosition) 1.410 + *aPersistPosition = persistString.Find("screenX") >= 0 || persistString.Find("screenY") >= 0 ? true : false; 1.411 + if (aPersistSize) 1.412 + *aPersistSize = persistString.Find("width") >= 0 || persistString.Find("height") >= 0 ? true : false; 1.413 + if (aPersistSizeMode) 1.414 + *aPersistSizeMode = persistString.Find("sizemode") >= 0 ? true : false; 1.415 + 1.416 + return NS_OK; 1.417 +} 1.418 + 1.419 +NS_IMETHODIMP 1.420 +nsContentTreeOwner::GetTargetableShellCount(uint32_t* aResult) 1.421 +{ 1.422 + NS_ENSURE_STATE(mXULWindow); 1.423 + *aResult = mXULWindow->mTargetableShells.Count(); 1.424 + return NS_OK; 1.425 +} 1.426 + 1.427 +//***************************************************************************** 1.428 +// nsContentTreeOwner::nsIWebBrowserChrome3 1.429 +//***************************************************************************** 1.430 + 1.431 +NS_IMETHODIMP nsContentTreeOwner::OnBeforeLinkTraversal(const nsAString &originalTarget, 1.432 + nsIURI *linkURI, 1.433 + nsIDOMNode *linkNode, 1.434 + bool isAppTab, 1.435 + nsAString &_retval) 1.436 +{ 1.437 + NS_ENSURE_STATE(mXULWindow); 1.438 + 1.439 + nsCOMPtr<nsIXULBrowserWindow> xulBrowserWindow; 1.440 + mXULWindow->GetXULBrowserWindow(getter_AddRefs(xulBrowserWindow)); 1.441 + 1.442 + if (xulBrowserWindow) 1.443 + return xulBrowserWindow->OnBeforeLinkTraversal(originalTarget, linkURI, 1.444 + linkNode, isAppTab, _retval); 1.445 + 1.446 + _retval = originalTarget; 1.447 + return NS_OK; 1.448 +} 1.449 + 1.450 +//***************************************************************************** 1.451 +// nsContentTreeOwner::nsIWebBrowserChrome2 1.452 +//***************************************************************************** 1.453 + 1.454 +NS_IMETHODIMP nsContentTreeOwner::SetStatusWithContext(uint32_t aStatusType, 1.455 + const nsAString &aStatusText, 1.456 + nsISupports *aStatusContext) 1.457 +{ 1.458 + // We only allow the status to be set from the primary content shell 1.459 + if (!mPrimary && aStatusType != STATUS_LINK) 1.460 + return NS_OK; 1.461 + 1.462 + NS_ENSURE_STATE(mXULWindow); 1.463 + 1.464 + nsCOMPtr<nsIXULBrowserWindow> xulBrowserWindow; 1.465 + mXULWindow->GetXULBrowserWindow(getter_AddRefs(xulBrowserWindow)); 1.466 + 1.467 + if (xulBrowserWindow) 1.468 + { 1.469 + switch(aStatusType) 1.470 + { 1.471 + case STATUS_SCRIPT: 1.472 + xulBrowserWindow->SetJSStatus(aStatusText); 1.473 + break; 1.474 + case STATUS_LINK: 1.475 + { 1.476 + nsCOMPtr<nsIDOMElement> element = do_QueryInterface(aStatusContext); 1.477 + xulBrowserWindow->SetOverLink(aStatusText, element); 1.478 + break; 1.479 + } 1.480 + } 1.481 + } 1.482 + 1.483 + return NS_OK; 1.484 +} 1.485 + 1.486 +//***************************************************************************** 1.487 +// nsContentTreeOwner::nsIWebBrowserChrome 1.488 +//***************************************************************************** 1.489 + 1.490 +NS_IMETHODIMP nsContentTreeOwner::SetStatus(uint32_t aStatusType, 1.491 + const char16_t* aStatus) 1.492 +{ 1.493 + return SetStatusWithContext(aStatusType, 1.494 + aStatus ? static_cast<const nsString &>(nsDependentString(aStatus)) 1.495 + : EmptyString(), 1.496 + nullptr); 1.497 +} 1.498 + 1.499 +NS_IMETHODIMP nsContentTreeOwner::SetWebBrowser(nsIWebBrowser* aWebBrowser) 1.500 +{ 1.501 + NS_ERROR("Haven't Implemented this yet"); 1.502 + return NS_ERROR_FAILURE; 1.503 +} 1.504 + 1.505 +NS_IMETHODIMP nsContentTreeOwner::GetWebBrowser(nsIWebBrowser** aWebBrowser) 1.506 +{ 1.507 + // Unimplemented, and probably will remain so; xpfe windows have docshells, 1.508 + // not webbrowsers. 1.509 + NS_ENSURE_ARG_POINTER(aWebBrowser); 1.510 + *aWebBrowser = 0; 1.511 + return NS_ERROR_FAILURE; 1.512 +} 1.513 + 1.514 +NS_IMETHODIMP nsContentTreeOwner::SetChromeFlags(uint32_t aChromeFlags) 1.515 +{ 1.516 + NS_ENSURE_STATE(mXULWindow); 1.517 + return mXULWindow->SetChromeFlags(aChromeFlags); 1.518 +} 1.519 + 1.520 +NS_IMETHODIMP nsContentTreeOwner::GetChromeFlags(uint32_t* aChromeFlags) 1.521 +{ 1.522 + NS_ENSURE_STATE(mXULWindow); 1.523 + return mXULWindow->GetChromeFlags(aChromeFlags); 1.524 +} 1.525 + 1.526 +NS_IMETHODIMP nsContentTreeOwner::DestroyBrowserWindow() 1.527 +{ 1.528 + NS_ERROR("Haven't Implemented this yet"); 1.529 + return NS_ERROR_FAILURE; 1.530 +} 1.531 + 1.532 +NS_IMETHODIMP nsContentTreeOwner::SizeBrowserTo(int32_t aCX, int32_t aCY) 1.533 +{ 1.534 + NS_ERROR("Haven't Implemented this yet"); 1.535 + return NS_ERROR_FAILURE; 1.536 +} 1.537 + 1.538 +NS_IMETHODIMP nsContentTreeOwner::ShowAsModal() 1.539 +{ 1.540 + NS_ENSURE_STATE(mXULWindow); 1.541 + return mXULWindow->ShowModal(); 1.542 +} 1.543 + 1.544 +NS_IMETHODIMP nsContentTreeOwner::IsWindowModal(bool *_retval) 1.545 +{ 1.546 + NS_ENSURE_STATE(mXULWindow); 1.547 + *_retval = mXULWindow->mContinueModalLoop; 1.548 + return NS_OK; 1.549 +} 1.550 + 1.551 +NS_IMETHODIMP nsContentTreeOwner::ExitModalEventLoop(nsresult aStatus) 1.552 +{ 1.553 + NS_ENSURE_STATE(mXULWindow); 1.554 + return mXULWindow->ExitModalLoop(aStatus); 1.555 +} 1.556 + 1.557 +//***************************************************************************** 1.558 +// nsContentTreeOwner::nsIBaseWindow 1.559 +//***************************************************************************** 1.560 + 1.561 +NS_IMETHODIMP nsContentTreeOwner::InitWindow(nativeWindow aParentNativeWindow, 1.562 + nsIWidget* parentWidget, int32_t x, int32_t y, int32_t cx, int32_t cy) 1.563 +{ 1.564 + // Ignore wigdet parents for now. Don't think those are a vaild thing to call. 1.565 + NS_ENSURE_SUCCESS(SetPositionAndSize(x, y, cx, cy, false), NS_ERROR_FAILURE); 1.566 + 1.567 + return NS_OK; 1.568 +} 1.569 + 1.570 +NS_IMETHODIMP nsContentTreeOwner::Create() 1.571 +{ 1.572 + NS_ASSERTION(false, "You can't call this"); 1.573 + return NS_ERROR_UNEXPECTED; 1.574 +} 1.575 + 1.576 +NS_IMETHODIMP nsContentTreeOwner::Destroy() 1.577 +{ 1.578 + NS_ENSURE_STATE(mXULWindow); 1.579 + return mXULWindow->Destroy(); 1.580 +} 1.581 + 1.582 +NS_IMETHODIMP nsContentTreeOwner::GetUnscaledDevicePixelsPerCSSPixel(double* aScale) 1.583 +{ 1.584 + NS_ENSURE_STATE(mXULWindow); 1.585 + return mXULWindow->GetUnscaledDevicePixelsPerCSSPixel(aScale); 1.586 +} 1.587 + 1.588 +NS_IMETHODIMP nsContentTreeOwner::SetPosition(int32_t aX, int32_t aY) 1.589 +{ 1.590 + NS_ENSURE_STATE(mXULWindow); 1.591 + return mXULWindow->SetPosition(aX, aY); 1.592 +} 1.593 + 1.594 +NS_IMETHODIMP nsContentTreeOwner::GetPosition(int32_t* aX, int32_t* aY) 1.595 +{ 1.596 + NS_ENSURE_STATE(mXULWindow); 1.597 + return mXULWindow->GetPosition(aX, aY); 1.598 +} 1.599 + 1.600 +NS_IMETHODIMP nsContentTreeOwner::SetSize(int32_t aCX, int32_t aCY, bool aRepaint) 1.601 +{ 1.602 + NS_ENSURE_STATE(mXULWindow); 1.603 + return mXULWindow->SetSize(aCX, aCY, aRepaint); 1.604 +} 1.605 + 1.606 +NS_IMETHODIMP nsContentTreeOwner::GetSize(int32_t* aCX, int32_t* aCY) 1.607 +{ 1.608 + NS_ENSURE_STATE(mXULWindow); 1.609 + return mXULWindow->GetSize(aCX, aCY); 1.610 +} 1.611 + 1.612 +NS_IMETHODIMP nsContentTreeOwner::SetPositionAndSize(int32_t aX, int32_t aY, 1.613 + int32_t aCX, int32_t aCY, bool aRepaint) 1.614 +{ 1.615 + NS_ENSURE_STATE(mXULWindow); 1.616 + return mXULWindow->SetPositionAndSize(aX, aY, aCX, aCY, aRepaint); 1.617 +} 1.618 + 1.619 +NS_IMETHODIMP nsContentTreeOwner::GetPositionAndSize(int32_t* aX, int32_t* aY, 1.620 + int32_t* aCX, int32_t* aCY) 1.621 +{ 1.622 + NS_ENSURE_STATE(mXULWindow); 1.623 + return mXULWindow->GetPositionAndSize(aX, aY, aCX, aCY); 1.624 +} 1.625 + 1.626 +NS_IMETHODIMP nsContentTreeOwner::Repaint(bool aForce) 1.627 +{ 1.628 + NS_ENSURE_STATE(mXULWindow); 1.629 + return mXULWindow->Repaint(aForce); 1.630 +} 1.631 + 1.632 +NS_IMETHODIMP nsContentTreeOwner::GetParentWidget(nsIWidget** aParentWidget) 1.633 +{ 1.634 + NS_ENSURE_STATE(mXULWindow); 1.635 + return mXULWindow->GetParentWidget(aParentWidget); 1.636 +} 1.637 + 1.638 +NS_IMETHODIMP nsContentTreeOwner::SetParentWidget(nsIWidget* aParentWidget) 1.639 +{ 1.640 + NS_ASSERTION(false, "You can't call this"); 1.641 + return NS_ERROR_NOT_IMPLEMENTED; 1.642 +} 1.643 + 1.644 +NS_IMETHODIMP nsContentTreeOwner::GetParentNativeWindow(nativeWindow* aParentNativeWindow) 1.645 +{ 1.646 + NS_ENSURE_STATE(mXULWindow); 1.647 + return mXULWindow->GetParentNativeWindow(aParentNativeWindow); 1.648 +} 1.649 + 1.650 +NS_IMETHODIMP nsContentTreeOwner::SetParentNativeWindow(nativeWindow aParentNativeWindow) 1.651 +{ 1.652 + NS_ASSERTION(false, "You can't call this"); 1.653 + return NS_ERROR_NOT_IMPLEMENTED; 1.654 +} 1.655 + 1.656 +NS_IMETHODIMP nsContentTreeOwner::GetNativeHandle(nsAString& aNativeHandle) 1.657 +{ 1.658 + NS_ENSURE_STATE(mXULWindow); 1.659 + return mXULWindow->GetNativeHandle(aNativeHandle); 1.660 +} 1.661 + 1.662 +NS_IMETHODIMP nsContentTreeOwner::GetVisibility(bool* aVisibility) 1.663 +{ 1.664 + NS_ENSURE_STATE(mXULWindow); 1.665 + return mXULWindow->GetVisibility(aVisibility); 1.666 +} 1.667 + 1.668 +NS_IMETHODIMP nsContentTreeOwner::SetVisibility(bool aVisibility) 1.669 +{ 1.670 + NS_ENSURE_STATE(mXULWindow); 1.671 + return mXULWindow->SetVisibility(aVisibility); 1.672 +} 1.673 + 1.674 +NS_IMETHODIMP nsContentTreeOwner::GetEnabled(bool *aEnabled) 1.675 +{ 1.676 + NS_ENSURE_STATE(mXULWindow); 1.677 + return mXULWindow->GetEnabled(aEnabled); 1.678 +} 1.679 + 1.680 +NS_IMETHODIMP nsContentTreeOwner::SetEnabled(bool aEnable) 1.681 +{ 1.682 + NS_ENSURE_STATE(mXULWindow); 1.683 + return mXULWindow->SetEnabled(aEnable); 1.684 +} 1.685 + 1.686 +NS_IMETHODIMP nsContentTreeOwner::GetMainWidget(nsIWidget** aMainWidget) 1.687 +{ 1.688 + NS_ENSURE_ARG_POINTER(aMainWidget); 1.689 + NS_ENSURE_STATE(mXULWindow); 1.690 + 1.691 + *aMainWidget = mXULWindow->mWindow; 1.692 + NS_IF_ADDREF(*aMainWidget); 1.693 + 1.694 + return NS_OK; 1.695 +} 1.696 + 1.697 +NS_IMETHODIMP nsContentTreeOwner::SetFocus() 1.698 +{ 1.699 + NS_ENSURE_STATE(mXULWindow); 1.700 + return mXULWindow->SetFocus(); 1.701 +} 1.702 + 1.703 +NS_IMETHODIMP nsContentTreeOwner::GetTitle(char16_t** aTitle) 1.704 +{ 1.705 + NS_ENSURE_ARG_POINTER(aTitle); 1.706 + NS_ENSURE_STATE(mXULWindow); 1.707 + 1.708 + return mXULWindow->GetTitle(aTitle); 1.709 +} 1.710 + 1.711 +NS_IMETHODIMP nsContentTreeOwner::SetTitle(const char16_t* aTitle) 1.712 +{ 1.713 + // We only allow the title to be set from the primary content shell 1.714 + if(!mPrimary || !mContentTitleSetting) 1.715 + return NS_OK; 1.716 + 1.717 + NS_ENSURE_STATE(mXULWindow); 1.718 + 1.719 + nsAutoString title; 1.720 + nsAutoString docTitle(aTitle); 1.721 + 1.722 + if (docTitle.IsEmpty()) 1.723 + docTitle.Assign(mTitleDefault); 1.724 + 1.725 + if (!docTitle.IsEmpty()) { 1.726 + if (!mTitlePreface.IsEmpty()) { 1.727 + // Title will be: "Preface: Doc Title - Mozilla" 1.728 + title.Assign(mTitlePreface); 1.729 + title.Append(docTitle); 1.730 + } 1.731 + else { 1.732 + // Title will be: "Doc Title - Mozilla" 1.733 + title = docTitle; 1.734 + } 1.735 + 1.736 + if (!mWindowTitleModifier.IsEmpty()) 1.737 + title += mTitleSeparator + mWindowTitleModifier; 1.738 + } 1.739 + else 1.740 + title.Assign(mWindowTitleModifier); // Title will just be plain "Mozilla" 1.741 + 1.742 + // 1.743 + // if there is no location bar we modify the title to display at least 1.744 + // the scheme and host (if any) as an anti-spoofing measure. 1.745 + // 1.746 + nsCOMPtr<dom::Element> docShellElement = mXULWindow->GetWindowDOMElement(); 1.747 + 1.748 + if (docShellElement) { 1.749 + nsAutoString chromeString; 1.750 + docShellElement->GetAttribute(NS_LITERAL_STRING("chromehidden"), chromeString); 1.751 + if (chromeString.Find(NS_LITERAL_STRING("location")) != kNotFound) { 1.752 + // 1.753 + // location bar is turned off, find the browser location 1.754 + // 1.755 + // use the document's nsPrincipal to find the true owner 1.756 + // in case of javascript: or data: documents 1.757 + // 1.758 + nsCOMPtr<nsIDocShellTreeItem> dsitem; 1.759 + GetPrimaryContentShell(getter_AddRefs(dsitem)); 1.760 + nsCOMPtr<nsIDOMDocument> domdoc(do_GetInterface(dsitem)); 1.761 + nsCOMPtr<nsIScriptObjectPrincipal> doc(do_QueryInterface(domdoc)); 1.762 + if (doc) { 1.763 + nsCOMPtr<nsIURI> uri; 1.764 + nsIPrincipal* principal = doc->GetPrincipal(); 1.765 + if (principal) { 1.766 + principal->GetURI(getter_AddRefs(uri)); 1.767 + if (uri) { 1.768 + // 1.769 + // remove any user:pass information 1.770 + // 1.771 + nsCOMPtr<nsIURIFixup> fixup(do_GetService(NS_URIFIXUP_CONTRACTID)); 1.772 + if (fixup) { 1.773 + nsCOMPtr<nsIURI> tmpuri; 1.774 + nsresult rv = fixup->CreateExposableURI(uri,getter_AddRefs(tmpuri)); 1.775 + if (NS_SUCCEEDED(rv) && tmpuri) { 1.776 + // (don't bother if there's no host) 1.777 + nsAutoCString host; 1.778 + nsAutoCString prepath; 1.779 + tmpuri->GetHost(host); 1.780 + tmpuri->GetPrePath(prepath); 1.781 + if (!host.IsEmpty()) { 1.782 + // 1.783 + // We have a scheme/host, update the title 1.784 + // 1.785 + title.Insert(NS_ConvertUTF8toUTF16(prepath) + 1.786 + mTitleSeparator, 0); 1.787 + } 1.788 + } 1.789 + } 1.790 + } 1.791 + } 1.792 + } 1.793 + } 1.794 + nsIDocument* document = docShellElement->OwnerDoc(); 1.795 + ErrorResult rv; 1.796 + document->SetTitle(title, rv); 1.797 + return rv.ErrorCode(); 1.798 + } 1.799 + 1.800 + return mXULWindow->SetTitle(title.get()); 1.801 +} 1.802 + 1.803 +//***************************************************************************** 1.804 +// nsContentTreeOwner: nsIWindowProvider 1.805 +//***************************************************************************** 1.806 +NS_IMETHODIMP 1.807 +nsContentTreeOwner::ProvideWindow(nsIDOMWindow* aParent, 1.808 + uint32_t aChromeFlags, 1.809 + bool aCalledFromJS, 1.810 + bool aPositionSpecified, 1.811 + bool aSizeSpecified, 1.812 + nsIURI* aURI, 1.813 + const nsAString& aName, 1.814 + const nsACString& aFeatures, 1.815 + bool* aWindowIsNew, 1.816 + nsIDOMWindow** aReturn) 1.817 +{ 1.818 + NS_ENSURE_ARG_POINTER(aParent); 1.819 + 1.820 + *aReturn = nullptr; 1.821 + 1.822 + if (!mXULWindow) { 1.823 + // Nothing to do here 1.824 + return NS_OK; 1.825 + } 1.826 + 1.827 +#ifdef DEBUG 1.828 + nsCOMPtr<nsIWebNavigation> parentNav = do_GetInterface(aParent); 1.829 + nsCOMPtr<nsIDocShellTreeOwner> parentOwner = do_GetInterface(parentNav); 1.830 + NS_ASSERTION(SameCOMIdentity(parentOwner, 1.831 + static_cast<nsIDocShellTreeOwner*>(this)), 1.832 + "Parent from wrong docshell tree?"); 1.833 +#endif 1.834 + 1.835 + // If aParent is inside an <iframe mozbrowser> and this isn't a request to 1.836 + // open a modal-type window, we're going to create a new <iframe mozbrowser> 1.837 + // and return its window here. 1.838 + nsCOMPtr<nsIDocShell> docshell = do_GetInterface(aParent); 1.839 + if (docshell && docshell->GetIsInBrowserOrApp() && 1.840 + !(aChromeFlags & (nsIWebBrowserChrome::CHROME_MODAL | 1.841 + nsIWebBrowserChrome::CHROME_OPENAS_DIALOG | 1.842 + nsIWebBrowserChrome::CHROME_OPENAS_CHROME))) { 1.843 + 1.844 + BrowserElementParent::OpenWindowResult opened = 1.845 + BrowserElementParent::OpenWindowInProcess(aParent, aURI, aName, 1.846 + aFeatures, aReturn); 1.847 + 1.848 + // If OpenWindowInProcess handled the open (by opening it or blocking the 1.849 + // popup), tell our caller not to proceed trying to create a new window 1.850 + // through other means. 1.851 + if (opened != BrowserElementParent::OPEN_WINDOW_IGNORED) { 1.852 + *aWindowIsNew = opened == BrowserElementParent::OPEN_WINDOW_ADDED; 1.853 + return *aWindowIsNew ? NS_OK : NS_ERROR_ABORT; 1.854 + } 1.855 + 1.856 + // If we're in an app and the target is _blank, send the url to the OS 1.857 + if (aName.LowerCaseEqualsLiteral("_blank")) { 1.858 + nsCOMPtr<nsIExternalURLHandlerService> exUrlServ( 1.859 + do_GetService(NS_EXTERNALURLHANDLERSERVICE_CONTRACTID)); 1.860 + if (exUrlServ) { 1.861 + 1.862 + nsCOMPtr<nsIHandlerInfo> info; 1.863 + bool found; 1.864 + exUrlServ->GetURLHandlerInfoFromOS(aURI, &found, getter_AddRefs(info)); 1.865 + 1.866 + if (info && found) { 1.867 + info->LaunchWithURI(aURI, nullptr); 1.868 + return NS_ERROR_ABORT; 1.869 + } 1.870 + 1.871 + } 1.872 + } 1.873 + } 1.874 + 1.875 + // the parent window is fullscreen mode or not. 1.876 + bool isFullScreen = false; 1.877 + if (aParent) { 1.878 + aParent->GetFullScreen(&isFullScreen); 1.879 + } 1.880 + 1.881 + // Where should we open this? 1.882 + int32_t containerPref; 1.883 + if (NS_FAILED(Preferences::GetInt("browser.link.open_newwindow", 1.884 + &containerPref))) { 1.885 + return NS_OK; 1.886 + } 1.887 + 1.888 + bool isDisabledOpenNewWindow = 1.889 + isFullScreen && 1.890 + Preferences::GetBool("browser.link.open_newwindow.disabled_in_fullscreen"); 1.891 + 1.892 + if (isDisabledOpenNewWindow && (containerPref == nsIBrowserDOMWindow::OPEN_NEWWINDOW)) { 1.893 + containerPref = nsIBrowserDOMWindow::OPEN_NEWTAB; 1.894 + } 1.895 + 1.896 + if (containerPref != nsIBrowserDOMWindow::OPEN_NEWTAB && 1.897 + containerPref != nsIBrowserDOMWindow::OPEN_CURRENTWINDOW) { 1.898 + // Just open a window normally 1.899 + return NS_OK; 1.900 + } 1.901 + 1.902 + if (aCalledFromJS) { 1.903 + /* Now check our restriction pref. The restriction pref is a power-user's 1.904 + fine-tuning pref. values: 1.905 + 0: no restrictions - divert everything 1.906 + 1: don't divert window.open at all 1.907 + 2: don't divert window.open with features 1.908 + */ 1.909 + int32_t restrictionPref = 1.910 + Preferences::GetInt("browser.link.open_newwindow.restriction", 2); 1.911 + if (restrictionPref < 0 || restrictionPref > 2) { 1.912 + restrictionPref = 2; // Sane default behavior 1.913 + } 1.914 + 1.915 + if (isDisabledOpenNewWindow) { 1.916 + // In browser fullscreen, the window should be opened 1.917 + // in the current window with no features (see bug 803675) 1.918 + restrictionPref = 0; 1.919 + } 1.920 + 1.921 + if (restrictionPref == 1) { 1.922 + return NS_OK; 1.923 + } 1.924 + 1.925 + if (restrictionPref == 2 && 1.926 + // Only continue if there are no size/position features and no special 1.927 + // chrome flags. 1.928 + (aChromeFlags != nsIWebBrowserChrome::CHROME_ALL || 1.929 + aPositionSpecified || aSizeSpecified)) { 1.930 + return NS_OK; 1.931 + } 1.932 + } 1.933 + 1.934 + nsCOMPtr<nsIDOMWindow> domWin; 1.935 + mXULWindow->GetWindowDOMWindow(getter_AddRefs(domWin)); 1.936 + nsCOMPtr<nsIDOMChromeWindow> chromeWin = do_QueryInterface(domWin); 1.937 + if (!chromeWin) { 1.938 + // Really odd... but whatever 1.939 + NS_WARNING("nsXULWindow's DOMWindow is not a chrome window"); 1.940 + return NS_OK; 1.941 + } 1.942 + 1.943 + nsCOMPtr<nsIBrowserDOMWindow> browserDOMWin; 1.944 + chromeWin->GetBrowserDOMWindow(getter_AddRefs(browserDOMWin)); 1.945 + if (!browserDOMWin) { 1.946 + return NS_OK; 1.947 + } 1.948 + 1.949 + *aWindowIsNew = (containerPref != nsIBrowserDOMWindow::OPEN_CURRENTWINDOW); 1.950 + 1.951 + { 1.952 + dom::AutoNoJSAPI nojsapi; 1.953 + 1.954 + // Get a new rendering area from the browserDOMWin. We don't want 1.955 + // to be starting any loads here, so get it with a null URI. 1.956 + return browserDOMWin->OpenURI(nullptr, aParent, containerPref, 1.957 + nsIBrowserDOMWindow::OPEN_NEW, aReturn); 1.958 + } 1.959 +} 1.960 + 1.961 +//***************************************************************************** 1.962 +// nsContentTreeOwner: Accessors 1.963 +//***************************************************************************** 1.964 + 1.965 +#if defined(XP_MACOSX) 1.966 +class nsContentTitleSettingEvent : public nsRunnable 1.967 +{ 1.968 +public: 1.969 + nsContentTitleSettingEvent(dom::Element* dse, const nsAString& wtm) 1.970 + : mElement(dse), 1.971 + mTitleDefault(wtm) {} 1.972 + 1.973 + NS_IMETHOD Run() 1.974 + { 1.975 + ErrorResult rv; 1.976 + mElement->SetAttribute(NS_LITERAL_STRING("titledefault"), mTitleDefault, rv); 1.977 + mElement->RemoveAttribute(NS_LITERAL_STRING("titlemodifier"), rv); 1.978 + return NS_OK; 1.979 + } 1.980 + 1.981 +private: 1.982 + nsCOMPtr<dom::Element> mElement; 1.983 + nsString mTitleDefault; 1.984 +}; 1.985 +#endif 1.986 + 1.987 +void nsContentTreeOwner::XULWindow(nsXULWindow* aXULWindow) 1.988 +{ 1.989 + mXULWindow = aXULWindow; 1.990 + if (mXULWindow && mPrimary) { 1.991 + // Get the window title modifiers 1.992 + nsCOMPtr<dom::Element> docShellElement = mXULWindow->GetWindowDOMElement(); 1.993 + 1.994 + nsAutoString contentTitleSetting; 1.995 + 1.996 + if(docShellElement) 1.997 + { 1.998 + docShellElement->GetAttribute(NS_LITERAL_STRING("contenttitlesetting"), contentTitleSetting); 1.999 + if(contentTitleSetting.EqualsLiteral("true")) 1.1000 + { 1.1001 + mContentTitleSetting = true; 1.1002 + docShellElement->GetAttribute(NS_LITERAL_STRING("titledefault"), mTitleDefault); 1.1003 + docShellElement->GetAttribute(NS_LITERAL_STRING("titlemodifier"), mWindowTitleModifier); 1.1004 + docShellElement->GetAttribute(NS_LITERAL_STRING("titlepreface"), mTitlePreface); 1.1005 + 1.1006 +#if defined(XP_MACOSX) 1.1007 + // On OS X, treat the titlemodifier like it's the titledefault, and don't ever append 1.1008 + // the separator + appname. 1.1009 + if (mTitleDefault.IsEmpty()) { 1.1010 + NS_DispatchToCurrentThread( 1.1011 + new nsContentTitleSettingEvent(docShellElement, 1.1012 + mWindowTitleModifier)); 1.1013 + mTitleDefault = mWindowTitleModifier; 1.1014 + mWindowTitleModifier.Truncate(); 1.1015 + } 1.1016 +#endif 1.1017 + docShellElement->GetAttribute(NS_LITERAL_STRING("titlemenuseparator"), mTitleSeparator); 1.1018 + } 1.1019 + } 1.1020 + else 1.1021 + { 1.1022 + NS_ERROR("This condition should never happen. If it does, " 1.1023 + "we just won't get a modifier, but it still shouldn't happen."); 1.1024 + } 1.1025 + } 1.1026 +} 1.1027 + 1.1028 +nsXULWindow* nsContentTreeOwner::XULWindow() 1.1029 +{ 1.1030 + return mXULWindow; 1.1031 +} 1.1032 + 1.1033 +//***************************************************************************** 1.1034 +//*** nsSiteWindow implementation 1.1035 +//***************************************************************************** 1.1036 + 1.1037 +nsSiteWindow::nsSiteWindow(nsContentTreeOwner *aAggregator) 1.1038 +{ 1.1039 + mAggregator = aAggregator; 1.1040 +} 1.1041 + 1.1042 +nsSiteWindow::~nsSiteWindow() 1.1043 +{ 1.1044 +} 1.1045 + 1.1046 +NS_IMPL_ADDREF_USING_AGGREGATOR(nsSiteWindow, mAggregator) 1.1047 +NS_IMPL_RELEASE_USING_AGGREGATOR(nsSiteWindow, mAggregator) 1.1048 + 1.1049 +NS_INTERFACE_MAP_BEGIN(nsSiteWindow) 1.1050 + NS_INTERFACE_MAP_ENTRY(nsISupports) 1.1051 + NS_INTERFACE_MAP_ENTRY(nsIEmbeddingSiteWindow) 1.1052 +NS_INTERFACE_MAP_END_AGGREGATED(mAggregator) 1.1053 + 1.1054 +NS_IMETHODIMP 1.1055 +nsSiteWindow::SetDimensions(uint32_t aFlags, 1.1056 + int32_t aX, int32_t aY, int32_t aCX, int32_t aCY) 1.1057 +{ 1.1058 + // XXX we're ignoring aFlags 1.1059 + return mAggregator->SetPositionAndSize(aX, aY, aCX, aCY, true); 1.1060 +} 1.1061 + 1.1062 +NS_IMETHODIMP 1.1063 +nsSiteWindow::GetDimensions(uint32_t aFlags, 1.1064 + int32_t *aX, int32_t *aY, int32_t *aCX, int32_t *aCY) 1.1065 +{ 1.1066 + // XXX we're ignoring aFlags 1.1067 + return mAggregator->GetPositionAndSize(aX, aY, aCX, aCY); 1.1068 +} 1.1069 + 1.1070 +NS_IMETHODIMP 1.1071 +nsSiteWindow::SetFocus(void) 1.1072 +{ 1.1073 +#if 0 1.1074 + /* This implementation focuses the main document and could make sense. 1.1075 + However this method is actually being used from within 1.1076 + nsGlobalWindow::Focus (providing a hook for MDI embedding apps) 1.1077 + and it's better for our purposes to not pick a document and 1.1078 + focus it, but allow nsGlobalWindow to carry on unhindered. 1.1079 + */ 1.1080 + nsXULWindow *window = mAggregator->XULWindow(); 1.1081 + if (window) { 1.1082 + nsCOMPtr<nsIDocShell> docshell; 1.1083 + window->GetDocShell(getter_AddRefs(docshell)); 1.1084 + nsCOMPtr<nsIDOMWindow> domWindow(do_GetInterface(docshell)); 1.1085 + if (domWindow) 1.1086 + domWindow->Focus(); 1.1087 + } 1.1088 +#endif 1.1089 + return NS_OK; 1.1090 +} 1.1091 + 1.1092 +/* this implementation focuses another window. if there isn't another 1.1093 + window to focus, we do nothing. */ 1.1094 +NS_IMETHODIMP 1.1095 +nsSiteWindow::Blur(void) 1.1096 +{ 1.1097 + NS_DEFINE_CID(kWindowMediatorCID, NS_WINDOWMEDIATOR_CID); 1.1098 + 1.1099 + nsCOMPtr<nsISimpleEnumerator> windowEnumerator; 1.1100 + nsCOMPtr<nsIXULWindow> xulWindow; 1.1101 + bool more, foundUs; 1.1102 + nsXULWindow *ourWindow = mAggregator->XULWindow(); 1.1103 + 1.1104 + { 1.1105 + nsCOMPtr<nsIWindowMediator> windowMediator(do_GetService(kWindowMediatorCID)); 1.1106 + if (windowMediator) 1.1107 + windowMediator->GetZOrderXULWindowEnumerator(0, true, 1.1108 + getter_AddRefs(windowEnumerator)); 1.1109 + } 1.1110 + 1.1111 + if (!windowEnumerator) 1.1112 + return NS_ERROR_FAILURE; 1.1113 + 1.1114 + // step through the top-level windows 1.1115 + foundUs = false; 1.1116 + windowEnumerator->HasMoreElements(&more); 1.1117 + while (more) { 1.1118 + 1.1119 + nsCOMPtr<nsISupports> nextWindow; 1.1120 + nsCOMPtr<nsIXULWindow> nextXULWindow; 1.1121 + 1.1122 + windowEnumerator->GetNext(getter_AddRefs(nextWindow)); 1.1123 + nextXULWindow = do_QueryInterface(nextWindow); 1.1124 + 1.1125 + // got it!(?) 1.1126 + if (foundUs) { 1.1127 + xulWindow = nextXULWindow; 1.1128 + break; 1.1129 + } 1.1130 + 1.1131 + // remember the very first one, in case we have to wrap 1.1132 + if (!xulWindow) 1.1133 + xulWindow = nextXULWindow; 1.1134 + 1.1135 + // look for us 1.1136 + if (nextXULWindow == ourWindow) 1.1137 + foundUs = true; 1.1138 + 1.1139 + windowEnumerator->HasMoreElements(&more); 1.1140 + } 1.1141 + 1.1142 + // change focus to the window we just found 1.1143 + if (xulWindow) { 1.1144 + nsCOMPtr<nsIDocShell> docshell; 1.1145 + xulWindow->GetDocShell(getter_AddRefs(docshell)); 1.1146 + nsCOMPtr<nsIDOMWindow> domWindow(do_GetInterface(docshell)); 1.1147 + if (domWindow) 1.1148 + domWindow->Focus(); 1.1149 + } 1.1150 + return NS_OK; 1.1151 +} 1.1152 + 1.1153 +NS_IMETHODIMP 1.1154 +nsSiteWindow::GetVisibility(bool *aVisibility) 1.1155 +{ 1.1156 + return mAggregator->GetVisibility(aVisibility); 1.1157 +} 1.1158 + 1.1159 +NS_IMETHODIMP 1.1160 +nsSiteWindow::SetVisibility(bool aVisibility) 1.1161 +{ 1.1162 + return mAggregator->SetVisibility(aVisibility); 1.1163 +} 1.1164 + 1.1165 +NS_IMETHODIMP 1.1166 +nsSiteWindow::GetTitle(char16_t * *aTitle) 1.1167 +{ 1.1168 + return mAggregator->GetTitle(aTitle); 1.1169 +} 1.1170 + 1.1171 +NS_IMETHODIMP 1.1172 +nsSiteWindow::SetTitle(const char16_t * aTitle) 1.1173 +{ 1.1174 + return mAggregator->SetTitle(aTitle); 1.1175 +} 1.1176 + 1.1177 +NS_IMETHODIMP 1.1178 +nsSiteWindow::GetSiteWindow(void **aSiteWindow) 1.1179 +{ 1.1180 + return mAggregator->GetParentNativeWindow(aSiteWindow); 1.1181 +} 1.1182 +