Esempio n. 1
0
// xxxbsmedberg Move me to nsIWindowMediator
NS_IMETHODIMP
nsChromeRegistry::ReloadChrome()
{
    UpdateSelectedLocale();
    FlushAllCaches();
    // Do a reload of all top level windows.
    nsresult rv = NS_OK;

    // Get the window mediator
    nsCOMPtr<nsIWindowMediator> windowMediator
    (do_GetService(NS_WINDOWMEDIATOR_CONTRACTID));
    if (windowMediator) {
        nsCOMPtr<nsISimpleEnumerator> windowEnumerator;

        rv = windowMediator->GetEnumerator(nsnull, getter_AddRefs(windowEnumerator));
        if (NS_SUCCEEDED(rv)) {
            // Get each dom window
            PRBool more;
            rv = windowEnumerator->HasMoreElements(&more);
            if (NS_FAILED(rv)) return rv;
            while (more) {
                nsCOMPtr<nsISupports> protoWindow;
                rv = windowEnumerator->GetNext(getter_AddRefs(protoWindow));
                if (NS_SUCCEEDED(rv)) {
                    nsCOMPtr<nsIDOMWindowInternal> domWindow =
                        do_QueryInterface(protoWindow);
                    if (domWindow) {
                        nsCOMPtr<nsIDOMLocation> location;
                        domWindow->GetLocation(getter_AddRefs(location));
                        if (location) {
                            rv = location->Reload(PR_FALSE);
                            if (NS_FAILED(rv)) return rv;
                        }
                    }
                }
                rv = windowEnumerator->HasMoreElements(&more);
                if (NS_FAILED(rv)) return rv;
            }
        }
    }
    return rv;
}
Esempio n. 2
0
// XXXbsmedberg: move this to nsIWindowMediator
NS_IMETHODIMP nsChromeRegistry::RefreshSkins()
{
    nsCOMPtr<nsIWindowMediator> windowMediator
    (do_GetService(NS_WINDOWMEDIATOR_CONTRACTID));
    if (!windowMediator)
        return NS_OK;

    nsCOMPtr<nsISimpleEnumerator> windowEnumerator;
    windowMediator->GetEnumerator(nsnull, getter_AddRefs(windowEnumerator));
    PRBool more;
    windowEnumerator->HasMoreElements(&more);
    while (more) {
        nsCOMPtr<nsISupports> protoWindow;
        windowEnumerator->GetNext(getter_AddRefs(protoWindow));
        if (protoWindow) {
            nsCOMPtr<nsIDOMWindowInternal> domWindow = do_QueryInterface(protoWindow);
            if (domWindow)
                FlushSkinBindingsForWindow(domWindow);
        }
        windowEnumerator->HasMoreElements(&more);
    }

    FlushSkinCaches();

    windowMediator->GetEnumerator(nsnull, getter_AddRefs(windowEnumerator));
    windowEnumerator->HasMoreElements(&more);
    while (more) {
        nsCOMPtr<nsISupports> protoWindow;
        windowEnumerator->GetNext(getter_AddRefs(protoWindow));
        if (protoWindow) {
            nsCOMPtr<nsIDOMWindowInternal> domWindow = do_QueryInterface(protoWindow);
            if (domWindow)
                RefreshWindow(domWindow);
        }
        windowEnumerator->HasMoreElements(&more);
    }

    return NS_OK;
}
NS_IMETHODIMP nsChromeTreeOwner::FindItemWithName(const PRUnichar* aName,
   nsIDocShellTreeItem* aRequestor, nsIDocShellTreeItem* aOriginalRequestor,
   nsIDocShellTreeItem** aFoundItem)
{
   NS_ENSURE_ARG_POINTER(aFoundItem);

   *aFoundItem = nsnull;

   PRBool fIs_Content = PR_FALSE;

   /* Special Cases */
   if(!aName || !*aName)
      return NS_OK;

   nsDependentString name(aName);

   if(name.LowerCaseEqualsLiteral("_blank"))
      return NS_OK;
   // _main is an IE target which should be case-insensitive but isn't
   // see bug 217886 for details
   if(name.LowerCaseEqualsLiteral("_content") || name.EqualsLiteral("_main"))
      {
      NS_ENSURE_STATE(mXULWindow);
      fIs_Content = PR_TRUE;
      mXULWindow->GetPrimaryContentShell(aFoundItem);
      if(*aFoundItem)
         return NS_OK;
      // Otherwise fall through and ask the other windows for a content area.
      }

   nsCOMPtr<nsIWindowMediator> windowMediator(do_GetService(kWindowMediatorCID));
   NS_ENSURE_TRUE(windowMediator, NS_ERROR_FAILURE);

   nsCOMPtr<nsISimpleEnumerator> windowEnumerator;
   NS_ENSURE_SUCCESS(windowMediator->GetXULWindowEnumerator(nsnull, 
      getter_AddRefs(windowEnumerator)), NS_ERROR_FAILURE);
   
   PRBool more;
   
   windowEnumerator->HasMoreElements(&more);
   while(more)
      {
      nsCOMPtr<nsISupports> nextWindow = nsnull;
      windowEnumerator->GetNext(getter_AddRefs(nextWindow));
      nsCOMPtr<nsIXULWindow> xulWindow(do_QueryInterface(nextWindow));
      NS_ENSURE_TRUE(xulWindow, NS_ERROR_FAILURE);

      nsCOMPtr<nsIDocShellTreeItem> shellAsTreeItem;
     
      if(fIs_Content)
         {
         xulWindow->GetPrimaryContentShell(aFoundItem);
         }
      else
         {
         // Note that we don't look for targetable content shells here...
         // in fact, we aren't looking for content shells at all!
         nsCOMPtr<nsIDocShell> shell;
         xulWindow->GetDocShell(getter_AddRefs(shell));
         shellAsTreeItem = do_QueryInterface(shell);
         if (shellAsTreeItem) {
           // Get the root tree item of same type, since roots are the only
           // things that call into the treeowner to look for named items.
           nsCOMPtr<nsIDocShellTreeItem> root;
           shellAsTreeItem->GetSameTypeRootTreeItem(getter_AddRefs(root));
           shellAsTreeItem = root;
         }
         if(shellAsTreeItem && aRequestor != shellAsTreeItem)
            {
            // Do this so we can pass in the tree owner as the requestor so the child knows not
            // to call back up.
            nsCOMPtr<nsIDocShellTreeOwner> shellOwner;
            shellAsTreeItem->GetTreeOwner(getter_AddRefs(shellOwner));
            nsCOMPtr<nsISupports> shellOwnerSupports(do_QueryInterface(shellOwner));

            shellAsTreeItem->FindItemWithName(aName, shellOwnerSupports,
                                              aOriginalRequestor, aFoundItem);
            }
         }
      if(*aFoundItem)
         return NS_OK;   
      windowEnumerator->HasMoreElements(&more);
      }
   return NS_OK;      
}