Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/uriloader/exthandler/nsLocalHandlerApp.cpp
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2
 * vim:expandtab:shiftwidth=2:tabstop=2:cin:
3
 * This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#include "nsLocalHandlerApp.h"
8
#include "nsIURI.h"
9
#include "nsIProcess.h"
10
11
// XXX why does nsMIMEInfoImpl have a threadsafe nsISupports?  do we need one 
12
// here too?
13
NS_IMPL_ISUPPORTS(nsLocalHandlerApp, nsILocalHandlerApp, nsIHandlerApp)
14
15
////////////////////////////////////////////////////////////////////////////////
16
//// nsIHandlerApp
17
18
NS_IMETHODIMP nsLocalHandlerApp::GetName(nsAString& aName)
19
0
{
20
0
  if (mName.IsEmpty() && mExecutable) {
21
0
    // Don't want to cache this, just in case someone resets the app
22
0
    // without changing the description....
23
0
    mExecutable->GetLeafName(aName);
24
0
  } else {
25
0
    aName.Assign(mName);
26
0
  }
27
0
  
28
0
  return NS_OK;
29
0
}
30
31
NS_IMETHODIMP nsLocalHandlerApp::SetName(const nsAString & aName)
32
0
{
33
0
  mName.Assign(aName);
34
0
35
0
  return NS_OK;
36
0
}
37
38
NS_IMETHODIMP
39
nsLocalHandlerApp::SetDetailedDescription(const nsAString & aDescription)
40
0
{
41
0
  mDetailedDescription.Assign(aDescription);
42
0
43
0
  return NS_OK;
44
0
}
45
46
NS_IMETHODIMP
47
nsLocalHandlerApp::GetDetailedDescription(nsAString& aDescription)
48
0
{
49
0
  aDescription.Assign(mDetailedDescription);
50
0
  
51
0
  return NS_OK;
52
0
}
53
54
NS_IMETHODIMP
55
nsLocalHandlerApp::Equals(nsIHandlerApp *aHandlerApp, bool *_retval)
56
0
{
57
0
  NS_ENSURE_ARG_POINTER(aHandlerApp);
58
0
59
0
  *_retval = false;
60
0
61
0
  // If the handler app isn't a local handler app, then it's not the same app.
62
0
  nsCOMPtr <nsILocalHandlerApp> localHandlerApp = do_QueryInterface(aHandlerApp);
63
0
  if (!localHandlerApp)
64
0
    return NS_OK;
65
0
66
0
  // If either handler app doesn't have an executable, then they aren't
67
0
  // the same app.
68
0
  nsCOMPtr<nsIFile> executable;
69
0
  nsresult rv = localHandlerApp->GetExecutable(getter_AddRefs(executable));
70
0
  if (NS_FAILED(rv))
71
0
    return rv;
72
0
73
0
  // Equality for two empty nsIHandlerApp
74
0
  if (!executable && !mExecutable) {
75
0
    *_retval = true;
76
0
    return NS_OK;
77
0
  }
78
0
79
0
  // At least one is set so they are not equal
80
0
  if (!mExecutable || !executable)
81
0
    return NS_OK;
82
0
83
0
  // Check the command line parameter list lengths
84
0
  uint32_t len;
85
0
  localHandlerApp->GetParameterCount(&len);
86
0
  if (mParameters.Length() != len)
87
0
    return NS_OK;
88
0
89
0
  // Check the command line params lists
90
0
  for (uint32_t idx = 0; idx < mParameters.Length(); idx++) {
91
0
    nsAutoString param;
92
0
    if (NS_FAILED(localHandlerApp->GetParameter(idx, param)) ||
93
0
        !param.Equals(mParameters[idx]))
94
0
      return NS_OK;
95
0
  }
96
0
97
0
  return executable->Equals(mExecutable, _retval);
98
0
}
99
100
NS_IMETHODIMP
101
nsLocalHandlerApp::LaunchWithURI(nsIURI *aURI,
102
                                 nsIInterfaceRequestor *aWindowContext)
103
0
{
104
0
  // pass the entire URI to the handler.
105
0
  nsAutoCString spec;
106
0
  aURI->GetAsciiSpec(spec);
107
0
  return LaunchWithIProcess(spec);
108
0
}
109
110
nsresult
111
nsLocalHandlerApp::LaunchWithIProcess(const nsCString& aArg)
112
0
{
113
0
  nsresult rv;
114
0
  nsCOMPtr<nsIProcess> process = do_CreateInstance(NS_PROCESS_CONTRACTID, &rv);
115
0
  if (NS_FAILED(rv))
116
0
    return rv;
117
0
118
0
  if (NS_FAILED(rv = process->Init(mExecutable)))
119
0
    return rv;
120
0
121
0
  const char *string = aArg.get();
122
0
123
0
  return process->Run(false, &string, 1);
124
0
}
125
126
////////////////////////////////////////////////////////////////////////////////
127
//// nsILocalHandlerApp
128
129
NS_IMETHODIMP
130
nsLocalHandlerApp::GetExecutable(nsIFile **aExecutable)
131
0
{
132
0
  NS_IF_ADDREF(*aExecutable = mExecutable);
133
0
  return NS_OK;
134
0
}
135
136
NS_IMETHODIMP
137
nsLocalHandlerApp::SetExecutable(nsIFile *aExecutable)
138
0
{
139
0
  mExecutable = aExecutable;
140
0
  return NS_OK;
141
0
}
142
143
NS_IMETHODIMP
144
nsLocalHandlerApp::GetParameterCount(uint32_t *aParameterCount)
145
0
{
146
0
  *aParameterCount = mParameters.Length();
147
0
  return NS_OK;
148
0
}
149
150
NS_IMETHODIMP
151
nsLocalHandlerApp::ClearParameters()
152
0
{
153
0
  mParameters.Clear();
154
0
  return NS_OK;
155
0
}
156
157
NS_IMETHODIMP
158
nsLocalHandlerApp::AppendParameter(const nsAString & aParam)
159
0
{
160
0
  mParameters.AppendElement(aParam);
161
0
  return NS_OK;
162
0
}
163
164
NS_IMETHODIMP
165
nsLocalHandlerApp::GetParameter(uint32_t parameterIndex, nsAString & _retval)
166
0
{
167
0
  if (mParameters.Length() <= parameterIndex)
168
0
    return NS_ERROR_INVALID_ARG;
169
0
170
0
  _retval.Assign(mParameters[parameterIndex]);
171
0
  return NS_OK;
172
0
}
173
174
NS_IMETHODIMP
175
nsLocalHandlerApp::ParameterExists(const nsAString & aParam, bool *_retval)
176
0
{
177
0
  *_retval = mParameters.Contains(aParam);
178
0
  return NS_OK;
179
0
}