2007-07-05 23:31:44 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* vim:expandtab:shiftwidth=2:tabstop=2:cin:
|
2012-05-21 15:12:37 +04:00
|
|
|
* 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/. */
|
2007-07-05 23:31:44 +04:00
|
|
|
|
2007-08-14 20:47:41 +04:00
|
|
|
#include "nsLocalHandlerApp.h"
|
2007-10-04 10:10:47 +04:00
|
|
|
#include "nsIURI.h"
|
|
|
|
#include "nsIProcess.h"
|
2007-07-05 23:31:44 +04:00
|
|
|
|
|
|
|
// XXX why does nsMIMEInfoImpl have a threadsafe nsISupports? do we need one
|
|
|
|
// here too?
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsLocalHandlerApp, nsILocalHandlerApp, nsIHandlerApp)
|
2007-07-05 23:31:44 +04:00
|
|
|
|
2007-08-14 20:47:41 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//// nsIHandlerApp
|
2007-07-05 23:31:44 +04:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
NS_IMETHODIMP nsLocalHandlerApp::GetName(nsAString& aName) {
|
2007-07-05 23:31:44 +04:00
|
|
|
if (mName.IsEmpty() && mExecutable) {
|
|
|
|
// Don't want to cache this, just in case someone resets the app
|
|
|
|
// without changing the description....
|
|
|
|
mExecutable->GetLeafName(aName);
|
|
|
|
} else {
|
|
|
|
aName.Assign(mName);
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2007-07-05 23:31:44 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
NS_IMETHODIMP nsLocalHandlerApp::SetName(const nsAString& aName) {
|
2007-08-14 20:47:41 +04:00
|
|
|
mName.Assign(aName);
|
2007-07-05 23:31:44 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-09-25 06:45:16 +04:00
|
|
|
NS_IMETHODIMP
|
2019-05-01 11:47:10 +03:00
|
|
|
nsLocalHandlerApp::SetDetailedDescription(const nsAString& aDescription) {
|
2009-09-25 06:45:16 +04:00
|
|
|
mDetailedDescription.Assign(aDescription);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2019-05-01 11:47:10 +03:00
|
|
|
nsLocalHandlerApp::GetDetailedDescription(nsAString& aDescription) {
|
2009-09-25 06:45:16 +04:00
|
|
|
aDescription.Assign(mDetailedDescription);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2009-09-25 06:45:16 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-09-05 00:45:57 +04:00
|
|
|
NS_IMETHODIMP
|
2019-05-01 11:47:10 +03:00
|
|
|
nsLocalHandlerApp::Equals(nsIHandlerApp* aHandlerApp, bool* _retval) {
|
2007-09-05 00:45:57 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aHandlerApp);
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
*_retval = false;
|
2009-09-25 06:45:16 +04:00
|
|
|
|
2007-09-05 00:45:57 +04:00
|
|
|
// If the handler app isn't a local handler app, then it's not the same app.
|
|
|
|
nsCOMPtr<nsILocalHandlerApp> localHandlerApp = do_QueryInterface(aHandlerApp);
|
2009-09-25 06:45:16 +04:00
|
|
|
if (!localHandlerApp) return NS_OK;
|
2007-09-05 00:45:57 +04:00
|
|
|
|
|
|
|
// If either handler app doesn't have an executable, then they aren't
|
|
|
|
// the same app.
|
|
|
|
nsCOMPtr<nsIFile> executable;
|
|
|
|
nsresult rv = localHandlerApp->GetExecutable(getter_AddRefs(executable));
|
2009-09-25 06:45:16 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// Equality for two empty nsIHandlerApp
|
|
|
|
if (!executable && !mExecutable) {
|
2011-10-17 18:59:28 +04:00
|
|
|
*_retval = true;
|
2009-09-25 06:45:16 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// At least one is set so they are not equal
|
|
|
|
if (!mExecutable || !executable) return NS_OK;
|
|
|
|
|
|
|
|
// Check the command line parameter list lengths
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t len;
|
2009-09-25 06:45:16 +04:00
|
|
|
localHandlerApp->GetParameterCount(&len);
|
|
|
|
if (mParameters.Length() != len) return NS_OK;
|
|
|
|
|
|
|
|
// Check the command line params lists
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t idx = 0; idx < mParameters.Length(); idx++) {
|
2009-09-25 06:45:16 +04:00
|
|
|
nsAutoString param;
|
|
|
|
if (NS_FAILED(localHandlerApp->GetParameter(idx, param)) ||
|
|
|
|
!param.Equals(mParameters[idx]))
|
|
|
|
return NS_OK;
|
2007-09-05 00:45:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return executable->Equals(mExecutable, _retval);
|
|
|
|
}
|
|
|
|
|
2007-10-04 10:10:47 +04:00
|
|
|
NS_IMETHODIMP
|
2019-05-01 11:47:10 +03:00
|
|
|
nsLocalHandlerApp::LaunchWithURI(nsIURI* aURI,
|
|
|
|
nsIInterfaceRequestor* aWindowContext) {
|
2007-10-04 10:10:47 +04:00
|
|
|
// pass the entire URI to the handler.
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString spec;
|
2008-06-03 16:05:59 +04:00
|
|
|
aURI->GetAsciiSpec(spec);
|
2007-10-04 10:10:47 +04:00
|
|
|
return LaunchWithIProcess(spec);
|
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
nsresult nsLocalHandlerApp::LaunchWithIProcess(const nsCString& aArg) {
|
2007-10-04 10:10:47 +04:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIProcess> process = do_CreateInstance(NS_PROCESS_CONTRACTID, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
if (NS_FAILED(rv = process->Init(mExecutable))) return rv;
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
const char* string = aArg.get();
|
2007-10-04 10:10:47 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return process->Run(false, &string, 1);
|
2007-10-04 10:10:47 +04:00
|
|
|
}
|
2007-09-05 00:45:57 +04:00
|
|
|
|
2007-08-14 20:47:41 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//// nsILocalHandlerApp
|
2007-07-05 23:31:44 +04:00
|
|
|
|
2009-09-25 06:45:16 +04:00
|
|
|
NS_IMETHODIMP
|
2019-05-01 11:47:10 +03:00
|
|
|
nsLocalHandlerApp::GetExecutable(nsIFile** aExecutable) {
|
2007-08-14 20:47:41 +04:00
|
|
|
NS_IF_ADDREF(*aExecutable = mExecutable);
|
2007-07-05 23:31:44 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-09-25 06:45:16 +04:00
|
|
|
NS_IMETHODIMP
|
2019-05-01 11:47:10 +03:00
|
|
|
nsLocalHandlerApp::SetExecutable(nsIFile* aExecutable) {
|
2007-08-14 20:47:41 +04:00
|
|
|
mExecutable = aExecutable;
|
2007-07-05 23:31:44 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-08-14 20:47:41 +04:00
|
|
|
|
2009-09-25 06:45:16 +04:00
|
|
|
NS_IMETHODIMP
|
2019-05-01 11:47:10 +03:00
|
|
|
nsLocalHandlerApp::GetParameterCount(uint32_t* aParameterCount) {
|
2009-09-25 06:45:16 +04:00
|
|
|
*aParameterCount = mParameters.Length();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocalHandlerApp::ClearParameters() {
|
|
|
|
mParameters.Clear();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2019-05-01 11:47:10 +03:00
|
|
|
nsLocalHandlerApp::AppendParameter(const nsAString& aParam) {
|
2009-09-25 06:45:16 +04:00
|
|
|
mParameters.AppendElement(aParam);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2019-05-01 11:47:10 +03:00
|
|
|
nsLocalHandlerApp::GetParameter(uint32_t parameterIndex, nsAString& _retval) {
|
2009-09-25 06:45:16 +04:00
|
|
|
if (mParameters.Length() <= parameterIndex) return NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
_retval.Assign(mParameters[parameterIndex]);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2019-05-01 11:47:10 +03:00
|
|
|
nsLocalHandlerApp::ParameterExists(const nsAString& aParam, bool* _retval) {
|
2009-09-25 06:45:16 +04:00
|
|
|
*_retval = mParameters.Contains(aParam);
|
|
|
|
return NS_OK;
|
|
|
|
}
|