Follow-on fix for bug 457825. Use sheet principal for agent and user sheets. r=dbaron...
[wine-gecko.git] / embedding / browser / webBrowser / nsCommandHandler.cpp
blob197dfc251bd3608ca6228e67915991b607bce653
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
3 * ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
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/
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.
16 * The Original Code is the Mozilla browser.
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.
23 * Contributor(s):
24 * Adam Lock <adamlock@netscape.com>
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.
38 * ***** END LICENSE BLOCK ***** */
40 #include "nsCommandHandler.h"
41 #include "nsWebBrowser.h"
42 #include "nsDocShellTreeOwner.h"
44 #include "nsIAllocator.h"
45 #include "nsPIDOMWindow.h"
47 nsCommandHandler::nsCommandHandler() :
48 mWindow(nsnull)
52 nsCommandHandler::~nsCommandHandler()
56 nsresult nsCommandHandler::GetCommandHandler(nsICommandHandler **aCommandHandler)
58 NS_ENSURE_ARG_POINTER(aCommandHandler);
60 *aCommandHandler = nsnull;
61 if (mWindow == nsnull)
63 return NS_ERROR_FAILURE;
66 nsCOMPtr<nsPIDOMWindow> window(do_QueryInterface(mWindow));
67 if (!window)
69 return NS_ERROR_FAILURE;
72 // Get the document tree owner
74 nsCOMPtr<nsIDocShellTreeItem> docShellAsTreeItem =
75 do_QueryInterface(window->GetDocShell());
76 nsIDocShellTreeOwner *treeOwner = nsnull;
77 docShellAsTreeItem->GetTreeOwner(&treeOwner);
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.
83 nsCOMPtr<nsICDocShellTreeOwner> realTreeOwner(do_QueryInterface(treeOwner));
84 if (realTreeOwner)
86 nsDocShellTreeOwner *tree = static_cast<nsDocShellTreeOwner *>(treeOwner);
87 if (tree->mTreeOwner)
89 nsresult rv;
90 rv = tree->mTreeOwner->QueryInterface(NS_GET_IID(nsICommandHandler), (void **)aCommandHandler);
91 NS_RELEASE(treeOwner);
92 return rv;
95 NS_RELEASE(treeOwner);
98 *aCommandHandler = nsnull;
100 return NS_OK;
104 NS_IMPL_ADDREF(nsCommandHandler)
105 NS_IMPL_RELEASE(nsCommandHandler)
107 NS_INTERFACE_MAP_BEGIN(nsCommandHandler)
108 NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsICommandHandler)
109 NS_INTERFACE_MAP_ENTRY(nsICommandHandlerInit)
110 NS_INTERFACE_MAP_ENTRY(nsICommandHandler)
111 NS_INTERFACE_MAP_END
113 ///////////////////////////////////////////////////////////////////////////////
114 // nsICommandHandlerInit implementation
116 /* attribute nsIDocShell docShell; */
117 NS_IMETHODIMP nsCommandHandler::GetWindow(nsIDOMWindow * *aWindow)
119 *aWindow = nsnull;
120 return NS_OK;
123 NS_IMETHODIMP nsCommandHandler::SetWindow(nsIDOMWindow * aWindow)
125 if (aWindow == nsnull)
127 return NS_ERROR_FAILURE;
129 mWindow = aWindow;
130 return NS_OK;
133 ///////////////////////////////////////////////////////////////////////////////
134 // nsICommandHandler implementation
136 /* string exec (in string aCommand, in string aStatus); */
137 NS_IMETHODIMP nsCommandHandler::Exec(const char *aCommand, const char *aStatus, char **aResult)
139 NS_ENSURE_ARG_POINTER(aCommand);
140 NS_ENSURE_ARG_POINTER(aResult);
142 nsCOMPtr<nsICommandHandler> commandHandler;
143 GetCommandHandler(getter_AddRefs(commandHandler));
145 // Call the client's command handler to deal with this command
146 if (commandHandler)
148 *aResult = nsnull;
149 return commandHandler->Exec(aCommand, aStatus, aResult);
152 // Return an empty string
153 const char szEmpty[] = "";
154 *aResult = (char *) nsAllocator::Clone(szEmpty, sizeof(szEmpty));
156 return NS_OK;
159 /* string query (in string aCommand, in string aStatus); */
160 NS_IMETHODIMP nsCommandHandler::Query(const char *aCommand, const char *aStatus, char **aResult)
162 NS_ENSURE_ARG_POINTER(aCommand);
163 NS_ENSURE_ARG_POINTER(aResult);
165 nsCOMPtr<nsICommandHandler> commandHandler;
166 GetCommandHandler(getter_AddRefs(commandHandler));
168 // Call the client's command handler to deal with this command
169 if (commandHandler)
171 *aResult = nsnull;
172 return commandHandler->Query(aCommand, aStatus, aResult);
175 // Return an empty string
176 const char szEmpty[] = "";
177 *aResult = (char *) nsAllocator::Clone(szEmpty, sizeof(szEmpty));
179 return NS_OK;