LCOV - code coverage report
Current view: top level - xpfe/appshell - nsContentTreeOwner.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 73 483 15.1 %
Date: 2017-07-14 16:53:18 Functions: 11 83 13.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 3; indent-tabs-mode: nil; c-basic-offset: 2 -*-
       2             :  * vim: set ts=2 sw=2 et tw=79:
       3             :  *
       4             :  * This Source Code Form is subject to the terms of the Mozilla Public
       5             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       6             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       7             : 
       8             : // Local Includes
       9             : #include "nsContentTreeOwner.h"
      10             : #include "nsXULWindow.h"
      11             : 
      12             : // Helper Classes
      13             : #include "nsIServiceManager.h"
      14             : #include "nsAutoPtr.h"
      15             : 
      16             : // Interfaces needed to be included
      17             : #include "nsIDOMNode.h"
      18             : #include "nsIDOMElement.h"
      19             : #include "nsIDOMNodeList.h"
      20             : #include "nsIDOMWindow.h"
      21             : #include "nsIDOMChromeWindow.h"
      22             : #include "nsIBrowserDOMWindow.h"
      23             : #include "nsIDOMXULElement.h"
      24             : #include "nsIEmbeddingSiteWindow.h"
      25             : #include "nsIPrompt.h"
      26             : #include "nsIAuthPrompt.h"
      27             : #include "nsIWindowMediator.h"
      28             : #include "nsIXULBrowserWindow.h"
      29             : #include "nsIPrincipal.h"
      30             : #include "nsIURIFixup.h"
      31             : #include "nsCDefaultURIFixup.h"
      32             : #include "nsIWebNavigation.h"
      33             : #include "nsDocShellCID.h"
      34             : #include "nsIExternalURLHandlerService.h"
      35             : #include "nsIMIMEInfo.h"
      36             : #include "nsIWidget.h"
      37             : #include "nsWindowWatcher.h"
      38             : #include "NullPrincipal.h"
      39             : #include "mozilla/BrowserElementParent.h"
      40             : 
      41             : #include "nsIDOMDocument.h"
      42             : #include "nsIScriptObjectPrincipal.h"
      43             : #include "nsIURI.h"
      44             : #include "nsIDocument.h"
      45             : #if defined(XP_MACOSX)
      46             : #include "nsThreadUtils.h"
      47             : #endif
      48             : 
      49             : #include "mozilla/Preferences.h"
      50             : #include "mozilla/dom/Element.h"
      51             : #include "mozilla/dom/ScriptSettings.h"
      52             : 
      53             : using namespace mozilla;
      54             : 
      55             : //*****************************************************************************
      56             : //*** nsSiteWindow declaration
      57             : //*****************************************************************************
      58             : 
      59             : class nsSiteWindow : public nsIEmbeddingSiteWindow
      60             : {
      61             :   // nsSiteWindow shares a lifetime with nsContentTreeOwner, and proxies it's
      62             :   // AddRef and Release calls to said object.
      63             :   // When nsContentTreeOwner is destroyed, nsSiteWindow will be destroyed as well.
      64             :   // nsContentTreeOwner is a friend class of nsSiteWindow such that it can call
      65             :   // nsSiteWindow's destructor, which is private, as public destructors
      66             :   // on reference counted classes are generally unsafe.
      67             :   friend class nsContentTreeOwner;
      68             : 
      69             : public:
      70             :   explicit nsSiteWindow(nsContentTreeOwner *aAggregator);
      71             : 
      72             :   NS_DECL_ISUPPORTS_INHERITED
      73             :   NS_DECL_NSIEMBEDDINGSITEWINDOW
      74             : 
      75             : private:
      76             :   virtual ~nsSiteWindow();
      77             :   nsContentTreeOwner *mAggregator;
      78             : };
      79             : 
      80             : //*****************************************************************************
      81             : //***    nsContentTreeOwner: Object Management
      82             : //*****************************************************************************
      83             : 
      84           3 : nsContentTreeOwner::nsContentTreeOwner(bool fPrimary) : mXULWindow(nullptr),
      85           3 :    mPrimary(fPrimary), mContentTitleSetting(false)
      86             : {
      87             :   // note if this fails, QI on nsIEmbeddingSiteWindow(2) will simply fail
      88           3 :   mSiteWindow = new nsSiteWindow(this);
      89           3 : }
      90             : 
      91           0 : nsContentTreeOwner::~nsContentTreeOwner()
      92             : {
      93           0 :   delete mSiteWindow;
      94           0 : }
      95             : 
      96             : //*****************************************************************************
      97             : // nsContentTreeOwner::nsISupports
      98             : //*****************************************************************************
      99             : 
     100          70 : NS_IMPL_ADDREF(nsContentTreeOwner)
     101          67 : NS_IMPL_RELEASE(nsContentTreeOwner)
     102             : 
     103          66 : NS_INTERFACE_MAP_BEGIN(nsContentTreeOwner)
     104          66 :    NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDocShellTreeOwner)
     105          66 :    NS_INTERFACE_MAP_ENTRY(nsIDocShellTreeOwner)
     106          60 :    NS_INTERFACE_MAP_ENTRY(nsIBaseWindow)
     107          60 :    NS_INTERFACE_MAP_ENTRY(nsIWebBrowserChrome)
     108          14 :    NS_INTERFACE_MAP_ENTRY(nsIWebBrowserChrome2)
     109          14 :    NS_INTERFACE_MAP_ENTRY(nsIWebBrowserChrome3)
     110          12 :    NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor)
     111           4 :    NS_INTERFACE_MAP_ENTRY(nsIWindowProvider)
     112             :    // NOTE: This is using aggregation because there are some properties and
     113             :    // method on nsIBaseWindow (which we implement) and on
     114             :    // nsIEmbeddingSiteWindow (which we also implement) that have the same name.
     115             :    // And it just so happens that we want different behavior for these methods
     116             :    // and properties depending on the interface through which they're called
     117             :    // (SetFocus() is a good example here).  If it were not for that, we could
     118             :    // ditch the aggregation and just deal with not being able to use NS_DECL_*
     119             :    // macros for this stuff....
     120           4 :    NS_INTERFACE_MAP_ENTRY_AGGREGATED(nsIEmbeddingSiteWindow, mSiteWindow)
     121           4 : NS_INTERFACE_MAP_END
     122             : 
     123             : //*****************************************************************************
     124             : // nsContentTreeOwner::nsIInterfaceRequestor
     125             : //*****************************************************************************
     126             : 
     127           8 : NS_IMETHODIMP nsContentTreeOwner::GetInterface(const nsIID& aIID, void** aSink)
     128             : {
     129           8 :   NS_ENSURE_ARG_POINTER(aSink);
     130           8 :   *aSink = 0;
     131             : 
     132           8 :   if(aIID.Equals(NS_GET_IID(nsIPrompt))) {
     133           0 :     NS_ENSURE_STATE(mXULWindow);
     134           0 :     return mXULWindow->GetInterface(aIID, aSink);
     135             :   }
     136           8 :   if(aIID.Equals(NS_GET_IID(nsIAuthPrompt))) {
     137           0 :     NS_ENSURE_STATE(mXULWindow);
     138           0 :     return mXULWindow->GetInterface(aIID, aSink);
     139             :   }
     140           8 :   if (aIID.Equals(NS_GET_IID(nsIDocShellTreeItem))) {
     141           1 :     NS_ENSURE_STATE(mXULWindow);
     142           2 :     nsCOMPtr<nsIDocShell> shell;
     143           1 :     mXULWindow->GetDocShell(getter_AddRefs(shell));
     144           1 :     if (shell)
     145           1 :       return shell->QueryInterface(aIID, aSink);
     146           0 :     return NS_ERROR_FAILURE;
     147             :   }
     148             : 
     149          14 :   if (aIID.Equals(NS_GET_IID(nsIDOMWindow)) ||
     150           7 :       aIID.Equals(NS_GET_IID(nsPIDOMWindowOuter))) {
     151           1 :     NS_ENSURE_STATE(mXULWindow);
     152           2 :     nsCOMPtr<nsIDocShellTreeItem> shell;
     153           1 :     mXULWindow->GetPrimaryContentShell(getter_AddRefs(shell));
     154           1 :     if (shell) {
     155           0 :       nsCOMPtr<nsIInterfaceRequestor> thing(do_QueryInterface(shell));
     156           0 :       if (thing)
     157           0 :         return thing->GetInterface(aIID, aSink);
     158             :     }
     159           1 :     return NS_ERROR_FAILURE;
     160             :   }
     161             : 
     162           6 :   if (aIID.Equals(NS_GET_IID(nsIXULWindow))) {
     163           1 :     NS_ENSURE_STATE(mXULWindow);
     164           1 :     return mXULWindow->QueryInterface(aIID, aSink);
     165             :   }
     166             : 
     167           5 :   return QueryInterface(aIID, aSink);
     168             : }
     169             : 
     170             : //*****************************************************************************
     171             : // nsContentTreeOwner::nsIDocShellTreeOwner
     172             : //*****************************************************************************
     173             : 
     174             : NS_IMETHODIMP
     175           0 : nsContentTreeOwner::ContentShellAdded(nsIDocShellTreeItem* aContentShell,
     176             :                                       bool aPrimary)
     177             : {
     178           0 :   NS_ENSURE_STATE(mXULWindow);
     179           0 :   return mXULWindow->ContentShellAdded(aContentShell, aPrimary);
     180             : }
     181             : 
     182             : NS_IMETHODIMP
     183           0 : nsContentTreeOwner::ContentShellRemoved(nsIDocShellTreeItem* aContentShell)
     184             : {
     185           0 :   NS_ENSURE_STATE(mXULWindow);
     186           0 :   return mXULWindow->ContentShellRemoved(aContentShell);
     187             : }
     188             : 
     189             : NS_IMETHODIMP
     190           0 : nsContentTreeOwner::GetPrimaryContentShell(nsIDocShellTreeItem** aShell)
     191             : {
     192           0 :    NS_ENSURE_STATE(mXULWindow);
     193           0 :    return mXULWindow->GetPrimaryContentShell(aShell);
     194             : }
     195             : 
     196             : NS_IMETHODIMP
     197           0 : nsContentTreeOwner::TabParentAdded(nsITabParent* aTab, bool aPrimary)
     198             : {
     199           0 :   NS_ENSURE_STATE(mXULWindow);
     200           0 :   return mXULWindow->TabParentAdded(aTab, aPrimary);
     201             : }
     202             : 
     203             : NS_IMETHODIMP
     204           0 : nsContentTreeOwner::TabParentRemoved(nsITabParent* aTab)
     205             : {
     206           0 :   NS_ENSURE_STATE(mXULWindow);
     207           0 :   return mXULWindow->TabParentRemoved(aTab);
     208             : }
     209             : 
     210             : NS_IMETHODIMP
     211           0 : nsContentTreeOwner::GetPrimaryTabParent(nsITabParent** aTab)
     212             : {
     213           0 :   NS_ENSURE_STATE(mXULWindow);
     214           0 :   return mXULWindow->GetPrimaryTabParent(aTab);
     215             : }
     216             : 
     217             : NS_IMETHODIMP
     218           0 : nsContentTreeOwner::GetPrimaryContentSize(int32_t* aWidth,
     219             :                                           int32_t* aHeight)
     220             : {
     221           0 :   NS_ENSURE_STATE(mXULWindow);
     222           0 :   return mXULWindow->GetPrimaryContentSize(aWidth, aHeight);
     223             : }
     224             : 
     225             : NS_IMETHODIMP
     226           0 : nsContentTreeOwner::SetPrimaryContentSize(int32_t aWidth,
     227             :                                           int32_t aHeight)
     228             : {
     229           0 :   NS_ENSURE_STATE(mXULWindow);
     230           0 :   return mXULWindow->SetPrimaryContentSize(aWidth, aHeight);
     231             : }
     232             : 
     233             : NS_IMETHODIMP
     234           0 : nsContentTreeOwner::GetRootShellSize(int32_t* aWidth,
     235             :                                      int32_t* aHeight)
     236             : {
     237           0 :   NS_ENSURE_STATE(mXULWindow);
     238           0 :   return mXULWindow->GetRootShellSize(aWidth, aHeight);
     239             : }
     240             : 
     241             : NS_IMETHODIMP
     242           0 : nsContentTreeOwner::SetRootShellSize(int32_t aWidth,
     243             :                                      int32_t aHeight)
     244             : {
     245           0 :   NS_ENSURE_STATE(mXULWindow);
     246           0 :   return mXULWindow->SetRootShellSize(aWidth, aHeight);
     247             : }
     248             : 
     249           0 : NS_IMETHODIMP nsContentTreeOwner::SizeShellTo(nsIDocShellTreeItem* aShellItem,
     250             :    int32_t aCX, int32_t aCY)
     251             : {
     252           0 :    NS_ENSURE_STATE(mXULWindow);
     253           0 :    return mXULWindow->SizeShellTo(aShellItem, aCX, aCY);
     254             : }
     255             : 
     256             : NS_IMETHODIMP
     257           0 : nsContentTreeOwner::SetPersistence(bool aPersistPosition,
     258             :                                    bool aPersistSize,
     259             :                                    bool aPersistSizeMode)
     260             : {
     261           0 :   NS_ENSURE_STATE(mXULWindow);
     262           0 :   nsCOMPtr<dom::Element> docShellElement = mXULWindow->GetWindowDOMElement();
     263           0 :   if (!docShellElement)
     264           0 :     return NS_ERROR_FAILURE;
     265             : 
     266           0 :   nsAutoString persistString;
     267           0 :   docShellElement->GetAttribute(NS_LITERAL_STRING("persist"), persistString);
     268             : 
     269           0 :   bool saveString = false;
     270             :   int32_t index;
     271             : 
     272             :   // Set X
     273           0 :   index = persistString.Find("screenX");
     274           0 :   if (!aPersistPosition && index >= 0) {
     275           0 :     persistString.Cut(index, 7);
     276           0 :     saveString = true;
     277           0 :   } else if (aPersistPosition && index < 0) {
     278           0 :     persistString.AppendLiteral(" screenX");
     279           0 :     saveString = true;
     280             :   }
     281             :   // Set Y
     282           0 :   index = persistString.Find("screenY");
     283           0 :   if (!aPersistPosition && index >= 0) {
     284           0 :     persistString.Cut(index, 7);
     285           0 :     saveString = true;
     286           0 :   } else if (aPersistPosition && index < 0) {
     287           0 :     persistString.AppendLiteral(" screenY");
     288           0 :     saveString = true;
     289             :   }
     290             :   // Set CX
     291           0 :   index = persistString.Find("width");
     292           0 :   if (!aPersistSize && index >= 0) {
     293           0 :     persistString.Cut(index, 5);
     294           0 :     saveString = true;
     295           0 :   } else if (aPersistSize && index < 0) {
     296           0 :     persistString.AppendLiteral(" width");
     297           0 :     saveString = true;
     298             :   }
     299             :   // Set CY
     300           0 :   index = persistString.Find("height");
     301           0 :   if (!aPersistSize && index >= 0) {
     302           0 :     persistString.Cut(index, 6);
     303           0 :     saveString = true;
     304           0 :   } else if (aPersistSize && index < 0) {
     305           0 :     persistString.AppendLiteral(" height");
     306           0 :     saveString = true;
     307             :   }
     308             :   // Set SizeMode
     309           0 :   index = persistString.Find("sizemode");
     310           0 :   if (!aPersistSizeMode && (index >= 0)) {
     311           0 :     persistString.Cut(index, 8);
     312           0 :     saveString = true;
     313           0 :   } else if (aPersistSizeMode && (index < 0)) {
     314           0 :     persistString.AppendLiteral(" sizemode");
     315           0 :     saveString = true;
     316             :   }
     317             : 
     318           0 :   ErrorResult rv;
     319           0 :   if(saveString) {
     320           0 :     docShellElement->SetAttribute(NS_LITERAL_STRING("persist"), persistString, rv);
     321             :   }
     322             : 
     323           0 :   return NS_OK;
     324             : }
     325             : 
     326             : NS_IMETHODIMP
     327           0 : nsContentTreeOwner::GetPersistence(bool* aPersistPosition,
     328             :                                    bool* aPersistSize,
     329             :                                    bool* aPersistSizeMode)
     330             : {
     331           0 :   NS_ENSURE_STATE(mXULWindow);
     332           0 :   nsCOMPtr<dom::Element> docShellElement = mXULWindow->GetWindowDOMElement();
     333           0 :   if (!docShellElement)
     334           0 :     return NS_ERROR_FAILURE;
     335             : 
     336           0 :   nsAutoString persistString;
     337           0 :   docShellElement->GetAttribute(NS_LITERAL_STRING("persist"), persistString);
     338             : 
     339             :   // data structure doesn't quite match the question, but it's close enough
     340             :   // for what we want (since this method is never actually called...)
     341           0 :   if (aPersistPosition)
     342           0 :     *aPersistPosition = persistString.Find("screenX") >= 0 || persistString.Find("screenY") >= 0 ? true : false;
     343           0 :   if (aPersistSize)
     344           0 :     *aPersistSize = persistString.Find("width") >= 0 || persistString.Find("height") >= 0 ? true : false;
     345           0 :   if (aPersistSizeMode)
     346           0 :     *aPersistSizeMode = persistString.Find("sizemode") >= 0 ? true : false;
     347             : 
     348           0 :   return NS_OK;
     349             : }
     350             : 
     351             : NS_IMETHODIMP
     352           0 : nsContentTreeOwner::GetTabCount(uint32_t* aResult)
     353             : {
     354           0 :   if (mXULWindow) {
     355           0 :     return mXULWindow->GetTabCount(aResult);
     356             :   }
     357             : 
     358           0 :   *aResult = 0;
     359           0 :   return NS_OK;
     360             : }
     361             : 
     362             : NS_IMETHODIMP
     363           0 : nsContentTreeOwner::GetHasPrimaryContent(bool* aResult)
     364             : {
     365           0 :   NS_ENSURE_STATE(mXULWindow);
     366           0 :   return mXULWindow->GetHasPrimaryContent(aResult);
     367             : }
     368             : 
     369             : //*****************************************************************************
     370             : // nsContentTreeOwner::nsIWebBrowserChrome3
     371             : //*****************************************************************************
     372             : 
     373           0 : NS_IMETHODIMP nsContentTreeOwner::OnBeforeLinkTraversal(const nsAString &originalTarget,
     374             :                                                         nsIURI *linkURI,
     375             :                                                         nsIDOMNode *linkNode,
     376             :                                                         bool isAppTab,
     377             :                                                         nsAString &_retval)
     378             : {
     379           0 :   NS_ENSURE_STATE(mXULWindow);
     380             : 
     381           0 :   nsCOMPtr<nsIXULBrowserWindow> xulBrowserWindow;
     382           0 :   mXULWindow->GetXULBrowserWindow(getter_AddRefs(xulBrowserWindow));
     383             : 
     384           0 :   if (xulBrowserWindow)
     385           0 :     return xulBrowserWindow->OnBeforeLinkTraversal(originalTarget, linkURI,
     386           0 :                                                    linkNode, isAppTab, _retval);
     387             : 
     388           0 :   _retval = originalTarget;
     389           0 :   return NS_OK;
     390             : }
     391             : 
     392           1 : NS_IMETHODIMP nsContentTreeOwner::ShouldLoadURI(nsIDocShell *aDocShell,
     393             :                                                 nsIURI *aURI,
     394             :                                                 nsIURI *aReferrer,
     395             :                                                 bool aHasPostData,
     396             :                                                 nsIPrincipal* aTriggeringPrincipal,
     397             :                                                 bool *_retval)
     398             : {
     399           1 :   NS_ENSURE_STATE(mXULWindow);
     400             : 
     401           2 :   nsCOMPtr<nsIXULBrowserWindow> xulBrowserWindow;
     402           1 :   mXULWindow->GetXULBrowserWindow(getter_AddRefs(xulBrowserWindow));
     403             : 
     404           1 :   if (xulBrowserWindow)
     405           0 :     return xulBrowserWindow->ShouldLoadURI(aDocShell, aURI, aReferrer, aHasPostData,
     406           0 :                                            aTriggeringPrincipal, _retval);
     407             : 
     408           1 :   *_retval = true;
     409           1 :   return NS_OK;
     410             : }
     411             : 
     412           0 : NS_IMETHODIMP nsContentTreeOwner::ShouldLoadURIInThisProcess(nsIURI* aURI,
     413             :                                                              bool* aRetVal)
     414             : {
     415           0 :   MOZ_ASSERT_UNREACHABLE("Should only be called in child process.");
     416             :   *aRetVal = true;
     417             :   return NS_OK;
     418             : }
     419             : 
     420           0 : NS_IMETHODIMP nsContentTreeOwner::ReloadInFreshProcess(nsIDocShell* aDocShell,
     421             :                                                        nsIURI* aURI,
     422             :                                                        nsIURI* aReferrer,
     423             :                                                        nsIPrincipal* aTriggeringPrincipal,
     424             :                                                        uint32_t aLoadFlags,
     425             :                                                        bool* aRetVal)
     426             : {
     427           0 :   NS_WARNING("Cannot reload in fresh process from a nsContentTreeOwner!");
     428           0 :   *aRetVal = false;
     429           0 :   return NS_OK;
     430             : }
     431             : 
     432           0 : NS_IMETHODIMP nsContentTreeOwner::StartPrerenderingDocument(nsIURI* aHref,
     433             :                                                             nsIURI* aReferrer,
     434             :                                                             nsIPrincipal* aTriggeringPrincipal)
     435             : {
     436           0 :   NS_WARNING("Cannot prerender a document in the parent process");
     437           0 :   return NS_ERROR_FAILURE;
     438             : }
     439             : 
     440           0 : NS_IMETHODIMP nsContentTreeOwner::ShouldSwitchToPrerenderedDocument(nsIURI* aHref,
     441             :                                                                     nsIURI* aReferrer,
     442             :                                                                     nsIRunnable* aSuccess,
     443             :                                                                     nsIRunnable* aFailure,
     444             :                                                                     bool* aRetval)
     445             : {
     446           0 :   NS_WARNING("Cannot switch to prerendered document in the parent process");
     447           0 :   *aRetval = false;
     448           0 :   return NS_OK;
     449             : }
     450             : 
     451             : //*****************************************************************************
     452             : // nsContentTreeOwner::nsIWebBrowserChrome2
     453             : //*****************************************************************************
     454             : 
     455           6 : NS_IMETHODIMP nsContentTreeOwner::SetStatusWithContext(uint32_t aStatusType,
     456             :                                                        const nsAString &aStatusText,
     457             :                                                        nsISupports *aStatusContext)
     458             : {
     459             :   // We only allow the status to be set from the primary content shell
     460           6 :   if (!mPrimary && aStatusType != STATUS_LINK)
     461           5 :     return NS_OK;
     462             : 
     463           1 :   NS_ENSURE_STATE(mXULWindow);
     464             : 
     465           2 :   nsCOMPtr<nsIXULBrowserWindow> xulBrowserWindow;
     466           1 :   mXULWindow->GetXULBrowserWindow(getter_AddRefs(xulBrowserWindow));
     467             : 
     468           1 :   if (xulBrowserWindow)
     469             :   {
     470           0 :     switch(aStatusType)
     471             :     {
     472             :     case STATUS_SCRIPT:
     473           0 :       xulBrowserWindow->SetJSStatus(aStatusText);
     474           0 :       break;
     475             :     case STATUS_LINK:
     476             :       {
     477           0 :         nsCOMPtr<nsIDOMElement> element = do_QueryInterface(aStatusContext);
     478           0 :         xulBrowserWindow->SetOverLink(aStatusText, element);
     479           0 :         break;
     480             :       }
     481             :     }
     482             :   }
     483             : 
     484           1 :   return NS_OK;
     485             : }
     486             : 
     487             : //*****************************************************************************
     488             : // nsContentTreeOwner::nsIWebBrowserChrome
     489             : //*****************************************************************************
     490             : 
     491           6 : NS_IMETHODIMP nsContentTreeOwner::SetStatus(uint32_t aStatusType,
     492             :                                             const char16_t* aStatus)
     493             : {
     494           6 :   return SetStatusWithContext(aStatusType,
     495          18 :       aStatus ? static_cast<const nsString &>(nsDependentString(aStatus))
     496             :               : EmptyString(),
     497          12 :       nullptr);
     498             : }
     499             : 
     500           0 : NS_IMETHODIMP nsContentTreeOwner::SetWebBrowser(nsIWebBrowser* aWebBrowser)
     501             : {
     502           0 :    NS_ERROR("Haven't Implemented this yet");
     503           0 :    return NS_ERROR_FAILURE;
     504             : }
     505             : 
     506           0 : NS_IMETHODIMP nsContentTreeOwner::GetWebBrowser(nsIWebBrowser** aWebBrowser)
     507             : {
     508             :   // Unimplemented, and probably will remain so; xpfe windows have docshells,
     509             :   // not webbrowsers.
     510           0 :   NS_ENSURE_ARG_POINTER(aWebBrowser);
     511           0 :   *aWebBrowser = 0;
     512           0 :   return NS_ERROR_FAILURE;
     513             : }
     514             : 
     515           0 : NS_IMETHODIMP nsContentTreeOwner::SetChromeFlags(uint32_t aChromeFlags)
     516             : {
     517           0 :    NS_ENSURE_STATE(mXULWindow);
     518           0 :    return mXULWindow->SetChromeFlags(aChromeFlags);
     519             : }
     520             : 
     521          10 : NS_IMETHODIMP nsContentTreeOwner::GetChromeFlags(uint32_t* aChromeFlags)
     522             : {
     523          10 :   NS_ENSURE_STATE(mXULWindow);
     524          10 :   return mXULWindow->GetChromeFlags(aChromeFlags);
     525             : }
     526             : 
     527           0 : NS_IMETHODIMP nsContentTreeOwner::DestroyBrowserWindow()
     528             : {
     529           0 :    NS_ERROR("Haven't Implemented this yet");
     530           0 :    return NS_ERROR_FAILURE;
     531             : }
     532             : 
     533           0 : NS_IMETHODIMP nsContentTreeOwner::SizeBrowserTo(int32_t aCX, int32_t aCY)
     534             : {
     535           0 :    NS_ERROR("Haven't Implemented this yet");
     536           0 :    return NS_ERROR_FAILURE;
     537             : }
     538             : 
     539           0 : NS_IMETHODIMP nsContentTreeOwner::ShowAsModal()
     540             : {
     541           0 :    NS_ENSURE_STATE(mXULWindow);
     542           0 :    return mXULWindow->ShowModal();
     543             : }
     544             : 
     545           0 : NS_IMETHODIMP nsContentTreeOwner::IsWindowModal(bool *_retval)
     546             : {
     547           0 :   NS_ENSURE_STATE(mXULWindow);
     548           0 :   *_retval = mXULWindow->mContinueModalLoop;
     549           0 :   return NS_OK;
     550             : }
     551             : 
     552           0 : NS_IMETHODIMP nsContentTreeOwner::ExitModalEventLoop(nsresult aStatus)
     553             : {
     554           0 :    NS_ENSURE_STATE(mXULWindow);
     555           0 :    return mXULWindow->ExitModalLoop(aStatus);
     556             : }
     557             : 
     558             : //*****************************************************************************
     559             : // nsContentTreeOwner::nsIBaseWindow
     560             : //*****************************************************************************
     561             : 
     562           0 : NS_IMETHODIMP nsContentTreeOwner::InitWindow(nativeWindow aParentNativeWindow,
     563             :    nsIWidget* parentWidget, int32_t x, int32_t y, int32_t cx, int32_t cy)
     564             : {
     565             :    // Ignore wigdet parents for now.  Don't think those are a vaild thing to call.
     566           0 :    NS_ENSURE_SUCCESS(SetPositionAndSize(x, y, cx, cy, 0), NS_ERROR_FAILURE);
     567             : 
     568           0 :    return NS_OK;
     569             : }
     570             : 
     571           0 : NS_IMETHODIMP nsContentTreeOwner::Create()
     572             : {
     573           0 :    NS_ASSERTION(false, "You can't call this");
     574           0 :    return NS_ERROR_UNEXPECTED;
     575             : }
     576             : 
     577           0 : NS_IMETHODIMP nsContentTreeOwner::Destroy()
     578             : {
     579           0 :    NS_ENSURE_STATE(mXULWindow);
     580           0 :    return mXULWindow->Destroy();
     581             : }
     582             : 
     583           0 : NS_IMETHODIMP nsContentTreeOwner::GetUnscaledDevicePixelsPerCSSPixel(double* aScale)
     584             : {
     585           0 :    NS_ENSURE_STATE(mXULWindow);
     586           0 :    return mXULWindow->GetUnscaledDevicePixelsPerCSSPixel(aScale);
     587             : }
     588             : 
     589           0 : NS_IMETHODIMP nsContentTreeOwner::GetDevicePixelsPerDesktopPixel(double* aScale)
     590             : {
     591           0 :    NS_ENSURE_STATE(mXULWindow);
     592           0 :    return mXULWindow->GetDevicePixelsPerDesktopPixel(aScale);
     593             : }
     594             : 
     595           0 : NS_IMETHODIMP nsContentTreeOwner::SetPositionDesktopPix(int32_t aX, int32_t aY)
     596             : {
     597           0 :    NS_ENSURE_STATE(mXULWindow);
     598           0 :    return mXULWindow->SetPositionDesktopPix(aX, aY);
     599             : }
     600             : 
     601           0 : NS_IMETHODIMP nsContentTreeOwner::SetPosition(int32_t aX, int32_t aY)
     602             : {
     603           0 :    NS_ENSURE_STATE(mXULWindow);
     604           0 :    return mXULWindow->SetPosition(aX, aY);
     605             : }
     606             : 
     607           0 : NS_IMETHODIMP nsContentTreeOwner::GetPosition(int32_t* aX, int32_t* aY)
     608             : {
     609           0 :    NS_ENSURE_STATE(mXULWindow);
     610           0 :    return mXULWindow->GetPosition(aX, aY);
     611             : }
     612             : 
     613           0 : NS_IMETHODIMP nsContentTreeOwner::SetSize(int32_t aCX, int32_t aCY, bool aRepaint)
     614             : {
     615           0 :    NS_ENSURE_STATE(mXULWindow);
     616           0 :    return mXULWindow->SetSize(aCX, aCY, aRepaint);
     617             : }
     618             : 
     619           0 : NS_IMETHODIMP nsContentTreeOwner::GetSize(int32_t* aCX, int32_t* aCY)
     620             : {
     621           0 :    NS_ENSURE_STATE(mXULWindow);
     622           0 :    return mXULWindow->GetSize(aCX, aCY);
     623             : }
     624             : 
     625           0 : NS_IMETHODIMP nsContentTreeOwner::SetPositionAndSize(int32_t aX, int32_t aY,
     626             :    int32_t aCX, int32_t aCY, uint32_t aFlags)
     627             : {
     628           0 :    NS_ENSURE_STATE(mXULWindow);
     629           0 :    return mXULWindow->SetPositionAndSize(aX, aY, aCX, aCY, aFlags);
     630             : }
     631             : 
     632           0 : NS_IMETHODIMP nsContentTreeOwner::GetPositionAndSize(int32_t* aX, int32_t* aY,
     633             :    int32_t* aCX, int32_t* aCY)
     634             : {
     635           0 :    NS_ENSURE_STATE(mXULWindow);
     636           0 :    return mXULWindow->GetPositionAndSize(aX, aY, aCX, aCY);
     637             : }
     638             : 
     639           0 : NS_IMETHODIMP nsContentTreeOwner::Repaint(bool aForce)
     640             : {
     641           0 :    NS_ENSURE_STATE(mXULWindow);
     642           0 :    return mXULWindow->Repaint(aForce);
     643             : }
     644             : 
     645           0 : NS_IMETHODIMP nsContentTreeOwner::GetParentWidget(nsIWidget** aParentWidget)
     646             : {
     647           0 :    NS_ENSURE_STATE(mXULWindow);
     648           0 :    return mXULWindow->GetParentWidget(aParentWidget);
     649             : }
     650             : 
     651           0 : NS_IMETHODIMP nsContentTreeOwner::SetParentWidget(nsIWidget* aParentWidget)
     652             : {
     653           0 :    NS_ASSERTION(false, "You can't call this");
     654           0 :    return NS_ERROR_NOT_IMPLEMENTED;
     655             : }
     656             : 
     657           0 : NS_IMETHODIMP nsContentTreeOwner::GetParentNativeWindow(nativeWindow* aParentNativeWindow)
     658             : {
     659           0 :    NS_ENSURE_STATE(mXULWindow);
     660           0 :    return mXULWindow->GetParentNativeWindow(aParentNativeWindow);
     661             : }
     662             : 
     663           0 : NS_IMETHODIMP nsContentTreeOwner::SetParentNativeWindow(nativeWindow aParentNativeWindow)
     664             : {
     665           0 :    NS_ASSERTION(false, "You can't call this");
     666           0 :    return NS_ERROR_NOT_IMPLEMENTED;
     667             : }
     668             : 
     669           0 : NS_IMETHODIMP nsContentTreeOwner::GetNativeHandle(nsAString& aNativeHandle)
     670             : {
     671           0 :    NS_ENSURE_STATE(mXULWindow);
     672           0 :    return mXULWindow->GetNativeHandle(aNativeHandle);
     673             : }
     674             : 
     675           0 : NS_IMETHODIMP nsContentTreeOwner::GetVisibility(bool* aVisibility)
     676             : {
     677           0 :    NS_ENSURE_STATE(mXULWindow);
     678           0 :    return mXULWindow->GetVisibility(aVisibility);
     679             : }
     680             : 
     681           0 : NS_IMETHODIMP nsContentTreeOwner::SetVisibility(bool aVisibility)
     682             : {
     683           0 :    NS_ENSURE_STATE(mXULWindow);
     684           0 :    return mXULWindow->SetVisibility(aVisibility);
     685             : }
     686             : 
     687           0 : NS_IMETHODIMP nsContentTreeOwner::GetEnabled(bool *aEnabled)
     688             : {
     689           0 :    NS_ENSURE_STATE(mXULWindow);
     690           0 :    return mXULWindow->GetEnabled(aEnabled);
     691             : }
     692             : 
     693           0 : NS_IMETHODIMP nsContentTreeOwner::SetEnabled(bool aEnable)
     694             : {
     695           0 :    NS_ENSURE_STATE(mXULWindow);
     696           0 :    return mXULWindow->SetEnabled(aEnable);
     697             : }
     698             : 
     699           0 : NS_IMETHODIMP nsContentTreeOwner::GetMainWidget(nsIWidget** aMainWidget)
     700             : {
     701           0 :    NS_ENSURE_ARG_POINTER(aMainWidget);
     702           0 :    NS_ENSURE_STATE(mXULWindow);
     703             : 
     704           0 :    *aMainWidget = mXULWindow->mWindow;
     705           0 :    NS_IF_ADDREF(*aMainWidget);
     706             : 
     707           0 :    return NS_OK;
     708             : }
     709             : 
     710           0 : NS_IMETHODIMP nsContentTreeOwner::SetFocus()
     711             : {
     712           0 :    NS_ENSURE_STATE(mXULWindow);
     713           0 :    return mXULWindow->SetFocus();
     714             : }
     715             : 
     716           0 : NS_IMETHODIMP nsContentTreeOwner::GetTitle(char16_t** aTitle)
     717             : {
     718           0 :    NS_ENSURE_ARG_POINTER(aTitle);
     719           0 :    NS_ENSURE_STATE(mXULWindow);
     720             : 
     721           0 :    return mXULWindow->GetTitle(aTitle);
     722             : }
     723             : 
     724           0 : NS_IMETHODIMP nsContentTreeOwner::SetTitle(const char16_t* aTitle)
     725             : {
     726             :    // We only allow the title to be set from the primary content shell
     727           0 :   if(!mPrimary || !mContentTitleSetting)
     728           0 :     return NS_OK;
     729             : 
     730           0 :   NS_ENSURE_STATE(mXULWindow);
     731             : 
     732           0 :   nsAutoString   title;
     733           0 :   nsAutoString   docTitle(aTitle);
     734             : 
     735           0 :   if (docTitle.IsEmpty())
     736           0 :     docTitle.Assign(mTitleDefault);
     737             : 
     738           0 :   if (!docTitle.IsEmpty()) {
     739           0 :     if (!mTitlePreface.IsEmpty()) {
     740             :       // Title will be: "Preface: Doc Title - Mozilla"
     741           0 :       title.Assign(mTitlePreface);
     742           0 :       title.Append(docTitle);
     743             :     }
     744             :     else {
     745             :       // Title will be: "Doc Title - Mozilla"
     746           0 :       title = docTitle;
     747             :     }
     748             : 
     749           0 :     if (!mWindowTitleModifier.IsEmpty())
     750           0 :       title += mTitleSeparator + mWindowTitleModifier;
     751             :   }
     752             :   else
     753           0 :     title.Assign(mWindowTitleModifier); // Title will just be plain "Mozilla"
     754             : 
     755             :   //
     756             :   // if there is no location bar we modify the title to display at least
     757             :   // the scheme and host (if any) as an anti-spoofing measure.
     758             :   //
     759           0 :   nsCOMPtr<dom::Element> docShellElement = mXULWindow->GetWindowDOMElement();
     760             : 
     761           0 :   if (docShellElement) {
     762           0 :     nsAutoString chromeString;
     763           0 :     docShellElement->GetAttribute(NS_LITERAL_STRING("chromehidden"), chromeString);
     764           0 :     if (chromeString.Find(NS_LITERAL_STRING("location")) != kNotFound) {
     765             :       //
     766             :       // location bar is turned off, find the browser location
     767             :       //
     768             :       // use the document's ContentPrincipal to find the true owner
     769             :       // in case of javascript: or data: documents
     770             :       //
     771           0 :       nsCOMPtr<nsIDocShellTreeItem> dsitem;
     772           0 :       GetPrimaryContentShell(getter_AddRefs(dsitem));
     773             :       nsCOMPtr<nsIScriptObjectPrincipal> doc =
     774           0 :         do_QueryInterface(dsitem ? dsitem->GetDocument() : nullptr);
     775           0 :       if (doc) {
     776           0 :         nsCOMPtr<nsIURI> uri;
     777           0 :         nsIPrincipal* principal = doc->GetPrincipal();
     778           0 :         if (principal) {
     779           0 :           principal->GetURI(getter_AddRefs(uri));
     780           0 :           if (uri) {
     781             :             //
     782             :             // remove any user:pass information
     783             :             //
     784           0 :             nsCOMPtr<nsIURIFixup> fixup(do_GetService(NS_URIFIXUP_CONTRACTID));
     785           0 :             if (fixup) {
     786           0 :               nsCOMPtr<nsIURI> tmpuri;
     787           0 :               nsresult rv = fixup->CreateExposableURI(uri,getter_AddRefs(tmpuri));
     788           0 :               if (NS_SUCCEEDED(rv) && tmpuri) {
     789             :                 // (don't bother if there's no host)
     790           0 :                 nsAutoCString host;
     791           0 :                 nsAutoCString prepath;
     792           0 :                 tmpuri->GetHost(host);
     793           0 :                 tmpuri->GetPrePath(prepath);
     794           0 :                 if (!host.IsEmpty()) {
     795             :                   //
     796             :                   // We have a scheme/host, update the title
     797             :                   //
     798           0 :                   title.Insert(NS_ConvertUTF8toUTF16(prepath) +
     799           0 :                                mTitleSeparator, 0);
     800             :                 }
     801             :               }
     802             :             }
     803             :           }
     804             :         }
     805             :       }
     806             :     }
     807           0 :     nsIDocument* document = docShellElement->OwnerDoc();
     808           0 :     ErrorResult rv;
     809           0 :     document->SetTitle(title, rv);
     810           0 :     return rv.StealNSResult();
     811             :   }
     812             : 
     813           0 :   return mXULWindow->SetTitle(title.get());
     814             : }
     815             : 
     816             : //*****************************************************************************
     817             : // nsContentTreeOwner: nsIWindowProvider
     818             : //*****************************************************************************
     819             : NS_IMETHODIMP
     820           0 : nsContentTreeOwner::ProvideWindow(mozIDOMWindowProxy* aParent,
     821             :                                   uint32_t aChromeFlags,
     822             :                                   bool aCalledFromJS,
     823             :                                   bool aPositionSpecified,
     824             :                                   bool aSizeSpecified,
     825             :                                   nsIURI* aURI,
     826             :                                   const nsAString& aName,
     827             :                                   const nsACString& aFeatures,
     828             :                                   bool aForceNoOpener,
     829             :                                   bool* aWindowIsNew,
     830             :                                   mozIDOMWindowProxy** aReturn)
     831             : {
     832           0 :   NS_ENSURE_ARG_POINTER(aParent);
     833             : 
     834           0 :   auto* parent = nsPIDOMWindowOuter::From(aParent);
     835             : 
     836           0 :   *aReturn = nullptr;
     837             : 
     838           0 :   if (!mXULWindow) {
     839             :     // Nothing to do here
     840           0 :     return NS_OK;
     841             :   }
     842             : 
     843             : #ifdef DEBUG
     844           0 :   nsCOMPtr<nsIWebNavigation> parentNav = do_GetInterface(aParent);
     845           0 :   nsCOMPtr<nsIDocShellTreeOwner> parentOwner = do_GetInterface(parentNav);
     846           0 :   NS_ASSERTION(SameCOMIdentity(parentOwner,
     847             :                                static_cast<nsIDocShellTreeOwner*>(this)),
     848             :                "Parent from wrong docshell tree?");
     849             : #endif
     850             : 
     851             :   // If aParent is inside an <iframe mozbrowser> and this isn't a request to
     852             :   // open a modal-type window, we're going to create a new <iframe mozbrowser>
     853             :   // and return its window here.
     854           0 :   nsCOMPtr<nsIDocShell> docshell = do_GetInterface(aParent);
     855           0 :   if (docshell && docshell->GetIsInMozBrowser() &&
     856           0 :       !(aChromeFlags & (nsIWebBrowserChrome::CHROME_MODAL |
     857             :                         nsIWebBrowserChrome::CHROME_OPENAS_DIALOG |
     858             :                         nsIWebBrowserChrome::CHROME_OPENAS_CHROME))) {
     859             : 
     860             :     BrowserElementParent::OpenWindowResult opened =
     861           0 :       BrowserElementParent::OpenWindowInProcess(parent, aURI, aName,
     862           0 :                                                 aFeatures, aForceNoOpener, aReturn);
     863             : 
     864             :     // If OpenWindowInProcess handled the open (by opening it or blocking the
     865             :     // popup), tell our caller not to proceed trying to create a new window
     866             :     // through other means.
     867           0 :     if (opened != BrowserElementParent::OPEN_WINDOW_IGNORED) {
     868           0 :       *aWindowIsNew = opened == BrowserElementParent::OPEN_WINDOW_ADDED;
     869           0 :       return *aWindowIsNew ? NS_OK : NS_ERROR_ABORT;
     870             :     }
     871             : 
     872             :     // If we're in an app and the target is _blank, send the url to the OS
     873           0 :     if (aName.LowerCaseEqualsLiteral("_blank")) {
     874             :       nsCOMPtr<nsIExternalURLHandlerService> exUrlServ(
     875           0 :                         do_GetService(NS_EXTERNALURLHANDLERSERVICE_CONTRACTID));
     876           0 :       if (exUrlServ) {
     877             : 
     878           0 :         nsCOMPtr<nsIHandlerInfo> info;
     879             :         bool found;
     880           0 :         exUrlServ->GetURLHandlerInfoFromOS(aURI, &found, getter_AddRefs(info));
     881             : 
     882           0 :         if (info && found) {
     883           0 :           info->LaunchWithURI(aURI, nullptr);
     884           0 :           return NS_ERROR_ABORT;
     885             :         }
     886             : 
     887             :       }
     888             :     }
     889             :   }
     890             : 
     891             :   int32_t openLocation =
     892           0 :     nsWindowWatcher::GetWindowOpenLocation(parent, aChromeFlags, aCalledFromJS,
     893           0 :                                            aPositionSpecified, aSizeSpecified);
     894             : 
     895           0 :   if (openLocation != nsIBrowserDOMWindow::OPEN_NEWTAB &&
     896             :       openLocation != nsIBrowserDOMWindow::OPEN_CURRENTWINDOW) {
     897             :     // Just open a window normally
     898           0 :     return NS_OK;
     899             :   }
     900             : 
     901           0 :   nsCOMPtr<mozIDOMWindowProxy> domWin;
     902           0 :   mXULWindow->GetWindowDOMWindow(getter_AddRefs(domWin));
     903           0 :   nsCOMPtr<nsIDOMChromeWindow> chromeWin = do_QueryInterface(domWin);
     904           0 :   if (!chromeWin) {
     905             :     // Really odd... but whatever
     906           0 :     NS_WARNING("nsXULWindow's DOMWindow is not a chrome window");
     907           0 :     return NS_OK;
     908             :   }
     909             : 
     910           0 :   nsCOMPtr<nsIBrowserDOMWindow> browserDOMWin;
     911           0 :   chromeWin->GetBrowserDOMWindow(getter_AddRefs(browserDOMWin));
     912           0 :   if (!browserDOMWin) {
     913           0 :     return NS_OK;
     914             :   }
     915             : 
     916           0 :   *aWindowIsNew = (openLocation != nsIBrowserDOMWindow::OPEN_CURRENTWINDOW);
     917             : 
     918             :   {
     919           0 :     dom::AutoNoJSAPI nojsapi;
     920             : 
     921           0 :     uint32_t flags = nsIBrowserDOMWindow::OPEN_NEW;
     922           0 :     if (aForceNoOpener) {
     923           0 :       flags |= nsIBrowserDOMWindow::OPEN_NO_OPENER;
     924             :     }
     925             : 
     926             :     // Get a new rendering area from the browserDOMWin.  We don't want
     927             :     // to be starting any loads here, so get it with a null URI. Since/
     928             :     // we are not loading any URI, we follow the principle of least privlege
     929             :     // and use a nullPrincipal as the triggeringPrincipal.
     930             :     //
     931             :     // This method handles setting the opener for us, so we don't need to set it
     932             :     // ourselves.
     933           0 :     RefPtr<NullPrincipal> nullPrincipal = NullPrincipal::Create();
     934           0 :     return browserDOMWin->OpenURI(nullptr, aParent, openLocation,
     935           0 :                                   flags, nullPrincipal, aReturn);
     936             :   }
     937             : }
     938             : 
     939             : //*****************************************************************************
     940             : // nsContentTreeOwner: Accessors
     941             : //*****************************************************************************
     942             : 
     943             : #if defined(XP_MACOSX)
     944             : class nsContentTitleSettingEvent : public Runnable
     945             : {
     946             : public:
     947             :   nsContentTitleSettingEvent(dom::Element* dse, const nsAString& wtm)
     948             :     : Runnable("nsContentTitleSettingEvent"),
     949             :       mElement(dse),
     950             :       mTitleDefault(wtm) {}
     951             : 
     952             :   NS_IMETHOD Run() override
     953             :   {
     954             :     ErrorResult rv;
     955             :     mElement->SetAttribute(NS_LITERAL_STRING("titledefault"), mTitleDefault, rv);
     956             :     mElement->RemoveAttribute(NS_LITERAL_STRING("titlemodifier"), rv);
     957             :     return NS_OK;
     958             :   }
     959             : 
     960             : private:
     961             :   nsCOMPtr<dom::Element> mElement;
     962             :   nsString mTitleDefault;
     963             : };
     964             : #endif
     965             : 
     966           3 : void nsContentTreeOwner::XULWindow(nsXULWindow* aXULWindow)
     967             : {
     968           3 :    mXULWindow = aXULWindow;
     969           3 :    if (mXULWindow && mPrimary) {
     970             :       // Get the window title modifiers
     971           2 :       nsCOMPtr<dom::Element> docShellElement = mXULWindow->GetWindowDOMElement();
     972             : 
     973           2 :       nsAutoString   contentTitleSetting;
     974             : 
     975           1 :       if(docShellElement)
     976             :          {
     977           1 :          docShellElement->GetAttribute(NS_LITERAL_STRING("contenttitlesetting"), contentTitleSetting);
     978           1 :          if(contentTitleSetting.EqualsLiteral("true"))
     979             :             {
     980           0 :             mContentTitleSetting = true;
     981           0 :             docShellElement->GetAttribute(NS_LITERAL_STRING("titledefault"), mTitleDefault);
     982           0 :             docShellElement->GetAttribute(NS_LITERAL_STRING("titlemodifier"), mWindowTitleModifier);
     983           0 :             docShellElement->GetAttribute(NS_LITERAL_STRING("titlepreface"), mTitlePreface);
     984             : 
     985             : #if defined(XP_MACOSX)
     986             :             // On OS X, treat the titlemodifier like it's the titledefault, and don't ever append
     987             :             // the separator + appname.
     988             :             if (mTitleDefault.IsEmpty()) {
     989             :                 NS_DispatchToCurrentThread(
     990             :                     new nsContentTitleSettingEvent(docShellElement,
     991             :                                                    mWindowTitleModifier));
     992             :                 mTitleDefault = mWindowTitleModifier;
     993             :                 mWindowTitleModifier.Truncate();
     994             :             }
     995             : #endif
     996           0 :             docShellElement->GetAttribute(NS_LITERAL_STRING("titlemenuseparator"), mTitleSeparator);
     997             :             }
     998             :          }
     999             :       else
    1000             :          {
    1001           0 :          NS_ERROR("This condition should never happen.  If it does, "
    1002             :             "we just won't get a modifier, but it still shouldn't happen.");
    1003             :          }
    1004             :       }
    1005           3 : }
    1006             : 
    1007           0 : nsXULWindow* nsContentTreeOwner::XULWindow()
    1008             : {
    1009           0 :    return mXULWindow;
    1010             : }
    1011             : 
    1012             : //*****************************************************************************
    1013             : //*** nsSiteWindow implementation
    1014             : //*****************************************************************************
    1015             : 
    1016           3 : nsSiteWindow::nsSiteWindow(nsContentTreeOwner *aAggregator)
    1017             : {
    1018           3 :   mAggregator = aAggregator;
    1019           3 : }
    1020             : 
    1021           0 : nsSiteWindow::~nsSiteWindow()
    1022             : {
    1023           0 : }
    1024             : 
    1025           0 : NS_IMPL_ADDREF_USING_AGGREGATOR(nsSiteWindow, mAggregator)
    1026           0 : NS_IMPL_RELEASE_USING_AGGREGATOR(nsSiteWindow, mAggregator)
    1027             : 
    1028           0 : NS_INTERFACE_MAP_BEGIN(nsSiteWindow)
    1029           0 :   NS_INTERFACE_MAP_ENTRY(nsISupports)
    1030           0 :   NS_INTERFACE_MAP_ENTRY(nsIEmbeddingSiteWindow)
    1031           0 : NS_INTERFACE_MAP_END_AGGREGATED(mAggregator)
    1032             : 
    1033             : NS_IMETHODIMP
    1034           0 : nsSiteWindow::SetDimensions(uint32_t aFlags,
    1035             :                     int32_t aX, int32_t aY, int32_t aCX, int32_t aCY)
    1036             : {
    1037             :   // XXX we're ignoring aFlags
    1038           0 :   return mAggregator->SetPositionAndSize(aX, aY, aCX, aCY,
    1039           0 :                                          nsIBaseWindow::eRepaint);
    1040             : }
    1041             : 
    1042             : NS_IMETHODIMP
    1043           0 : nsSiteWindow::GetDimensions(uint32_t aFlags,
    1044             :                     int32_t *aX, int32_t *aY, int32_t *aCX, int32_t *aCY)
    1045             : {
    1046             :   // XXX we're ignoring aFlags
    1047           0 :   return mAggregator->GetPositionAndSize(aX, aY, aCX, aCY);
    1048             : }
    1049             : 
    1050             : NS_IMETHODIMP
    1051           0 : nsSiteWindow::SetFocus(void)
    1052             : {
    1053             : #if 0
    1054             :   /* This implementation focuses the main document and could make sense.
    1055             :      However this method is actually being used from within
    1056             :      nsGlobalWindow::Focus (providing a hook for MDI embedding apps)
    1057             :      and it's better for our purposes to not pick a document and
    1058             :      focus it, but allow nsGlobalWindow to carry on unhindered.
    1059             :   */
    1060             :   nsXULWindow *window = mAggregator->XULWindow();
    1061             :   if (window) {
    1062             :     nsCOMPtr<nsIDocShell> docshell;
    1063             :     window->GetDocShell(getter_AddRefs(docshell));
    1064             :     if (docShell) {
    1065             :       nsCOMPtr<nsPIDOMWindowOuter> domWindow(docShell->GetWindow());
    1066             :       if (domWindow)
    1067             :         domWindow->Focus();
    1068             :     }
    1069             :   }
    1070             : #endif
    1071           0 :   return NS_OK;
    1072             : }
    1073             : 
    1074             : /* this implementation focuses another window. if there isn't another
    1075             :    window to focus, we do nothing. */
    1076             : NS_IMETHODIMP
    1077           0 : nsSiteWindow::Blur(void)
    1078             : {
    1079           0 :   NS_DEFINE_CID(kWindowMediatorCID, NS_WINDOWMEDIATOR_CID);
    1080             : 
    1081           0 :   nsCOMPtr<nsISimpleEnumerator> windowEnumerator;
    1082           0 :   nsCOMPtr<nsIXULWindow>        xulWindow;
    1083             :   bool                          more, foundUs;
    1084           0 :   nsXULWindow                  *ourWindow = mAggregator->XULWindow();
    1085             : 
    1086             :   {
    1087           0 :     nsCOMPtr<nsIWindowMediator> windowMediator(do_GetService(kWindowMediatorCID));
    1088           0 :     if (windowMediator)
    1089           0 :       windowMediator->GetZOrderXULWindowEnumerator(0, true,
    1090           0 :                         getter_AddRefs(windowEnumerator));
    1091             :   }
    1092             : 
    1093           0 :   if (!windowEnumerator)
    1094           0 :     return NS_ERROR_FAILURE;
    1095             : 
    1096             :   // step through the top-level windows
    1097           0 :   foundUs = false;
    1098           0 :   windowEnumerator->HasMoreElements(&more);
    1099           0 :   while (more) {
    1100             : 
    1101           0 :     nsCOMPtr<nsISupports>  nextWindow;
    1102           0 :     nsCOMPtr<nsIXULWindow> nextXULWindow;
    1103             : 
    1104           0 :     windowEnumerator->GetNext(getter_AddRefs(nextWindow));
    1105           0 :     nextXULWindow = do_QueryInterface(nextWindow);
    1106             : 
    1107             :     // got it!(?)
    1108           0 :     if (foundUs) {
    1109           0 :       xulWindow = nextXULWindow;
    1110           0 :       break;
    1111             :     }
    1112             : 
    1113             :     // remember the very first one, in case we have to wrap
    1114           0 :     if (!xulWindow)
    1115           0 :       xulWindow = nextXULWindow;
    1116             : 
    1117             :     // look for us
    1118           0 :     if (nextXULWindow == ourWindow)
    1119           0 :       foundUs = true;
    1120             : 
    1121           0 :     windowEnumerator->HasMoreElements(&more);
    1122             :   }
    1123             : 
    1124             :   // change focus to the window we just found
    1125           0 :   if (xulWindow) {
    1126           0 :     nsCOMPtr<nsIDocShell> docshell;
    1127           0 :     xulWindow->GetDocShell(getter_AddRefs(docshell));
    1128           0 :     if (!docshell) {
    1129           0 :       return NS_OK;
    1130             :     }
    1131             : 
    1132           0 :     nsCOMPtr<nsPIDOMWindowOuter> domWindow = docshell->GetWindow();
    1133           0 :     if (domWindow)
    1134           0 :       domWindow->Focus();
    1135             :   }
    1136           0 :   return NS_OK;
    1137             : }
    1138             : 
    1139             : NS_IMETHODIMP
    1140           0 : nsSiteWindow::GetVisibility(bool *aVisibility)
    1141             : {
    1142           0 :   return mAggregator->GetVisibility(aVisibility);
    1143             : }
    1144             : 
    1145             : NS_IMETHODIMP
    1146           0 : nsSiteWindow::SetVisibility(bool aVisibility)
    1147             : {
    1148           0 :   return mAggregator->SetVisibility(aVisibility);
    1149             : }
    1150             : 
    1151             : NS_IMETHODIMP
    1152           0 : nsSiteWindow::GetTitle(char16_t * *aTitle)
    1153             : {
    1154           0 :   return mAggregator->GetTitle(aTitle);
    1155             : }
    1156             : 
    1157             : NS_IMETHODIMP
    1158           0 : nsSiteWindow::SetTitle(const char16_t * aTitle)
    1159             : {
    1160           0 :   return mAggregator->SetTitle(aTitle);
    1161             : }
    1162             : 
    1163             : NS_IMETHODIMP
    1164           0 : nsSiteWindow::GetSiteWindow(void **aSiteWindow)
    1165             : {
    1166           0 :   return mAggregator->GetParentNativeWindow(aSiteWindow);
    1167             : }
    1168             : 

Generated by: LCOV version 1.13