diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /embedding/browser/nsCommandHandler.cpp | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | uxp-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz |
Add m-esr52 at 52.6.0
Diffstat (limited to 'embedding/browser/nsCommandHandler.cpp')
-rw-r--r-- | embedding/browser/nsCommandHandler.cpp | 139 |
1 files changed, 139 insertions, 0 deletions
diff --git a/embedding/browser/nsCommandHandler.cpp b/embedding/browser/nsCommandHandler.cpp new file mode 100644 index 0000000000..1e41e265a4 --- /dev/null +++ b/embedding/browser/nsCommandHandler.cpp @@ -0,0 +1,139 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "nsCommandHandler.h" +#include "nsWebBrowser.h" +#include "nsDocShellTreeOwner.h" + +#include "nsMemory.h" +#include "nsPIDOMWindow.h" + +nsCommandHandler::nsCommandHandler() + : mWindow(nullptr) +{ +} + +nsCommandHandler::~nsCommandHandler() +{ +} + +nsresult +nsCommandHandler::GetCommandHandler(nsICommandHandler** aCommandHandler) +{ + NS_ENSURE_ARG_POINTER(aCommandHandler); + + *aCommandHandler = nullptr; + if (!mWindow) { + return NS_ERROR_FAILURE; + } + + // Get the document tree owner + + nsCOMPtr<nsIDocShellTreeItem> docShellAsTreeItem = + do_QueryInterface(mWindow->GetDocShell()); + nsIDocShellTreeOwner* treeOwner = nullptr; + docShellAsTreeItem->GetTreeOwner(&treeOwner); + + // Make sure the tree owner is an an nsDocShellTreeOwner object + // by QI'ing for a hidden interface. If it doesn't have the interface + // then it's not safe to do the casting. + + nsCOMPtr<nsICDocShellTreeOwner> realTreeOwner(do_QueryInterface(treeOwner)); + if (realTreeOwner) { + nsDocShellTreeOwner* tree = static_cast<nsDocShellTreeOwner*>(treeOwner); + if (tree->mTreeOwner) { + nsresult rv; + rv = tree->mTreeOwner->QueryInterface(NS_GET_IID(nsICommandHandler), + (void**)aCommandHandler); + NS_RELEASE(treeOwner); + return rv; + } + + NS_RELEASE(treeOwner); + } + + *aCommandHandler = nullptr; + + return NS_OK; +} + +NS_IMPL_ADDREF(nsCommandHandler) +NS_IMPL_RELEASE(nsCommandHandler) + +NS_INTERFACE_MAP_BEGIN(nsCommandHandler) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsICommandHandler) + NS_INTERFACE_MAP_ENTRY(nsICommandHandlerInit) + NS_INTERFACE_MAP_ENTRY(nsICommandHandler) +NS_INTERFACE_MAP_END + +/////////////////////////////////////////////////////////////////////////////// +// nsICommandHandlerInit implementation + +NS_IMETHODIMP +nsCommandHandler::GetWindow(mozIDOMWindowProxy** aWindow) +{ + *aWindow = nullptr; + return NS_OK; +} + +NS_IMETHODIMP +nsCommandHandler::SetWindow(mozIDOMWindowProxy* aWindow) +{ + if (!aWindow) { + return NS_ERROR_FAILURE; + } + mWindow = nsPIDOMWindowOuter::From(aWindow); + return NS_OK; +} + +/////////////////////////////////////////////////////////////////////////////// +// nsICommandHandler implementation + +NS_IMETHODIMP +nsCommandHandler::Exec(const char* aCommand, const char* aStatus, + char** aResult) +{ + NS_ENSURE_ARG_POINTER(aCommand); + NS_ENSURE_ARG_POINTER(aResult); + + nsCOMPtr<nsICommandHandler> commandHandler; + GetCommandHandler(getter_AddRefs(commandHandler)); + + // Call the client's command handler to deal with this command + if (commandHandler) { + *aResult = nullptr; + return commandHandler->Exec(aCommand, aStatus, aResult); + } + + // Return an empty string + const char szEmpty[] = ""; + *aResult = (char*)nsMemory::Clone(szEmpty, sizeof(szEmpty)); + + return NS_OK; +} + +NS_IMETHODIMP +nsCommandHandler::Query(const char* aCommand, const char* aStatus, + char** aResult) +{ + NS_ENSURE_ARG_POINTER(aCommand); + NS_ENSURE_ARG_POINTER(aResult); + + nsCOMPtr<nsICommandHandler> commandHandler; + GetCommandHandler(getter_AddRefs(commandHandler)); + + // Call the client's command handler to deal with this command + if (commandHandler) { + *aResult = nullptr; + return commandHandler->Query(aCommand, aStatus, aResult); + } + + // Return an empty string + const char szEmpty[] = ""; + *aResult = (char*)nsMemory::Clone(szEmpty, sizeof(szEmpty)); + + return NS_OK; +} |