LCOV - code coverage report
Current view: directory - embedding/browser/webBrowser - nsCommandHandler.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 63 0 0.0 %
Date: 2012-06-02 Functions: 11 0 0.0 %

       1                 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
       2                 :  *
       3                 :  * ***** BEGIN LICENSE BLOCK *****
       4                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       5                 :  *
       6                 :  * The contents of this file are subject to the Mozilla Public License Version
       7                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       8                 :  * the License. You may obtain a copy of the License at
       9                 :  * http://www.mozilla.org/MPL/
      10                 :  *
      11                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      12                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      13                 :  * for the specific language governing rights and limitations under the
      14                 :  * License.
      15                 :  *
      16                 :  * The Original Code is the Mozilla browser.
      17                 :  *
      18                 :  * The Initial Developer of the Original Code is
      19                 :  * Netscape Communications, Inc.
      20                 :  * Portions created by the Initial Developer are Copyright (C) 1999
      21                 :  * the Initial Developer. All Rights Reserved.
      22                 :  *
      23                 :  * Contributor(s):
      24                 :  *   Adam Lock <adamlock@netscape.com>
      25                 :  *
      26                 :  * Alternatively, the contents of this file may be used under the terms of
      27                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
      28                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      29                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      30                 :  * of those above. If you wish to allow use of your version of this file only
      31                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      32                 :  * use your version of this file under the terms of the MPL, indicate your
      33                 :  * decision by deleting the provisions above and replace them with the notice
      34                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      35                 :  * the provisions above, a recipient may use your version of this file under
      36                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      37                 :  *
      38                 :  * ***** END LICENSE BLOCK ***** */
      39                 : 
      40                 : #include "nsCommandHandler.h"
      41                 : #include "nsWebBrowser.h"
      42                 : #include "nsDocShellTreeOwner.h"
      43                 : 
      44                 : #include "nsIAllocator.h"
      45                 : #include "nsPIDOMWindow.h"
      46                 : 
      47               0 : nsCommandHandler::nsCommandHandler() :
      48               0 :     mWindow(nsnull)
      49                 : {
      50               0 : }
      51                 : 
      52               0 : nsCommandHandler::~nsCommandHandler()
      53                 : {
      54               0 : }
      55                 : 
      56               0 : nsresult nsCommandHandler::GetCommandHandler(nsICommandHandler **aCommandHandler)
      57                 : {
      58               0 :     NS_ENSURE_ARG_POINTER(aCommandHandler);
      59                 : 
      60               0 :     *aCommandHandler = nsnull;
      61               0 :     if (mWindow == nsnull)
      62                 :     {
      63               0 :         return NS_ERROR_FAILURE;
      64                 :     }
      65                 : 
      66               0 :     nsCOMPtr<nsPIDOMWindow> window(do_QueryInterface(mWindow));
      67               0 :     if (!window)
      68                 :     {
      69               0 :         return NS_ERROR_FAILURE;
      70                 :     }
      71                 : 
      72                 :     // Get the document tree owner
      73                 : 
      74                 :     nsCOMPtr<nsIDocShellTreeItem> docShellAsTreeItem =
      75               0 :       do_QueryInterface(window->GetDocShell());
      76               0 :     nsIDocShellTreeOwner *treeOwner = nsnull;
      77               0 :     docShellAsTreeItem->GetTreeOwner(&treeOwner);
      78                 : 
      79                 :     // Make sure the tree owner is an an nsDocShellTreeOwner object
      80                 :     // by QI'ing for a hidden interface. If it doesn't have the interface
      81                 :     // then it's not safe to do the casting.
      82                 : 
      83               0 :     nsCOMPtr<nsICDocShellTreeOwner> realTreeOwner(do_QueryInterface(treeOwner));
      84               0 :     if (realTreeOwner)
      85                 :     {
      86               0 :         nsDocShellTreeOwner *tree = static_cast<nsDocShellTreeOwner *>(treeOwner);
      87               0 :         if (tree->mTreeOwner)
      88                 :         {
      89                 :             nsresult rv;
      90               0 :             rv = tree->mTreeOwner->QueryInterface(NS_GET_IID(nsICommandHandler), (void **)aCommandHandler);
      91               0 :             NS_RELEASE(treeOwner);
      92               0 :             return rv;
      93                 :         }
      94                 :      
      95               0 :         NS_RELEASE(treeOwner);
      96                 :      }
      97                 : 
      98               0 :     *aCommandHandler = nsnull;
      99                 : 
     100               0 :     return NS_OK;
     101                 : }
     102                 : 
     103                 : 
     104               0 : NS_IMPL_ADDREF(nsCommandHandler)
     105               0 : NS_IMPL_RELEASE(nsCommandHandler)
     106                 : 
     107               0 : NS_INTERFACE_MAP_BEGIN(nsCommandHandler)
     108               0 :     NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsICommandHandler)
     109               0 :     NS_INTERFACE_MAP_ENTRY(nsICommandHandlerInit)
     110               0 :     NS_INTERFACE_MAP_ENTRY(nsICommandHandler)
     111               0 : NS_INTERFACE_MAP_END
     112                 : 
     113                 : ///////////////////////////////////////////////////////////////////////////////
     114                 : // nsICommandHandlerInit implementation
     115                 : 
     116                 : /* attribute nsIDocShell docShell; */
     117               0 : NS_IMETHODIMP nsCommandHandler::GetWindow(nsIDOMWindow * *aWindow)
     118                 : {
     119               0 :     *aWindow = nsnull;
     120               0 :     return NS_OK;
     121                 : }
     122                 : 
     123               0 : NS_IMETHODIMP nsCommandHandler::SetWindow(nsIDOMWindow * aWindow)
     124                 : {
     125               0 :     if (aWindow == nsnull)
     126                 :     {
     127               0 :        return NS_ERROR_FAILURE;
     128                 :     }
     129               0 :     mWindow = aWindow;
     130               0 :     return NS_OK;
     131                 : }
     132                 : 
     133                 : ///////////////////////////////////////////////////////////////////////////////
     134                 : // nsICommandHandler implementation
     135                 : 
     136                 : /* string exec (in string aCommand, in string aStatus); */
     137               0 : NS_IMETHODIMP nsCommandHandler::Exec(const char *aCommand, const char *aStatus, char **aResult)
     138                 : {
     139               0 :     NS_ENSURE_ARG_POINTER(aCommand);
     140               0 :     NS_ENSURE_ARG_POINTER(aResult);
     141                 : 
     142               0 :     nsCOMPtr<nsICommandHandler> commandHandler;
     143               0 :     GetCommandHandler(getter_AddRefs(commandHandler));
     144                 : 
     145                 :     // Call the client's command handler to deal with this command
     146               0 :     if (commandHandler)
     147                 :     {
     148               0 :         *aResult = nsnull;
     149               0 :         return commandHandler->Exec(aCommand, aStatus, aResult);
     150                 :     }
     151                 : 
     152                 :     // Return an empty string
     153               0 :     const char szEmpty[] = "";
     154               0 :     *aResult = (char *) nsAllocator::Clone(szEmpty, sizeof(szEmpty));
     155                 : 
     156               0 :     return NS_OK;
     157                 : }
     158                 : 
     159                 : /* string query (in string aCommand, in string aStatus); */
     160               0 : NS_IMETHODIMP nsCommandHandler::Query(const char *aCommand, const char *aStatus, char **aResult)
     161                 : {
     162               0 :     NS_ENSURE_ARG_POINTER(aCommand);
     163               0 :     NS_ENSURE_ARG_POINTER(aResult);
     164                 : 
     165               0 :     nsCOMPtr<nsICommandHandler> commandHandler;
     166               0 :     GetCommandHandler(getter_AddRefs(commandHandler));
     167                 : 
     168                 :     // Call the client's command handler to deal with this command
     169               0 :     if (commandHandler)
     170                 :     {
     171               0 :         *aResult = nsnull;
     172               0 :         return commandHandler->Query(aCommand, aStatus, aResult);
     173                 :     }
     174                 : 
     175                 :     // Return an empty string
     176               0 :     const char szEmpty[] = "";
     177               0 :     *aResult = (char *) nsAllocator::Clone(szEmpty, sizeof(szEmpty));
     178                 : 
     179               0 :     return NS_OK;
     180                 : }

Generated by: LCOV version 1.7