LCOV - code coverage report
Current view: directory - xpfe/appshell/src - nsContentTreeOwner.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 481 0 0.0 %
Date: 2012-06-02 Functions: 69 0 0.0 %

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

Generated by: LCOV version 1.7