summaryrefslogtreecommitdiffstats
path: root/www/firefox36/files/patch-browser_app_mozilla.in
blob: d06f6f07ff11baba65d0077915c8e6440f5a673d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
--- browser/app/mozilla.in.orig	Tue Oct 26 10:26:11 2004
+++ browser/app/mozilla.in	Mon Feb 28 02:14:53 2005
@@ -28,52 +28,110 @@
 ## The script will setup all the environment voodoo needed to make
 ## the mozilla-bin binary to work.
 ##
-
+#!/bin/sh
+#
+# The contents of this file are subject to the Netscape Public License
+# Version 1.0 (the "NPL"); you may not use this file except in
+# compliance with the NPL.  You may obtain a copy of the NPL at
+# http://www.mozilla.org/NPL/
+#
+# Software distributed under the NPL is distributed on an "AS IS" basis,
+# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
+# for the specific language governing rights and limitations under the
+# NPL.
+#
+# The Initial Developer of this code under the NPL is Netscape
+# Communications Corporation.  Portions created by Netscape are
+# Copyright (C) 1998 Netscape Communications Corporation.  All Rights
+# Reserved.
+#
+
+# $from: mozilla.in,v 1.3.4.9 2004/10/26 09:26:11 bryner%brianryner.com Exp $
+# Usage:
+#
+# $ mozilla [args]
+#
+# The script will setup all the environment voodoo needed to make
+# the mozilla-bin binary to work.
+#
+
+#
+# MOZ_PIS, "Mozilla Plugable Init Scripts"
+# MOZ_PIS_ is the name space used
+# These variables and there meaning are specified in
+# mozilla/xpfe/bootstrap/init.d/README
 moz_pis_startstop_scripts()
 {
-  MOZ_USER_DIR="%MOZ_USER_DIR%"
-  # MOZ_PIS_ is the name space for "Mozilla Plugable Init Scripts"
-  # These variables and there meaning are specified in
-  # mozilla/xpfe/bootstrap/init.d/README
-  MOZ_PIS_API=2
-  MOZ_PIS_MOZBINDIR="${dist_bin}"
-  MOZ_PIS_SESSION_PID="$$"
-  MOZ_PIS_USER_DIR="${MOZ_USER_DIR}"
-  export MOZ_PIS_API MOZ_PIS_MOZBINDIR MOZ_PIS_SESSION_PID MOZ_PIS_USER_DIR
-  
-  case "${1}" in
-    "start")
-      for curr_pis in "${dist_bin}/init.d"/S* "${HOME}/${MOZ_USER_DIR}/init.d"/S* ; do
-        if [ -x "${curr_pis}" ] ; then
-          case "${curr_pis}" in
-            *.sh) .  "${curr_pis}"         ;;
-            *)       "${curr_pis}" "start" ;;
-          esac
-        fi
-      done
-      ;;
-    "stop")
-      for curr_pis in "${HOME}/${MOZ_USER_DIR}/init.d"/K* "${dist_bin}/init.d"/K* ; do
-        if [ -x "${curr_pis}" ] ; then
-          case "${curr_pis}" in
-            *.sh) . "${curr_pis}"        ;;
-            *)      "${curr_pis}" "stop" ;;
-          esac
-        fi
-      done
-      ;;
-    *)
-      echo 1>&2 "$0: Internal error in moz_pis_startstop_scripts."
-      exit 1
-      ;;
-  esac
+    MOZ_PIS_API=2
+    MOZ_PIS_MOZBINDIR="${dist_bin}"
+    MOZ_PIS_SESSION_PID="$$"
+    MOZ_PIS_USER_DIR="${MOZ_USER_DIR}"
+    export MOZ_PIS_API MOZ_PIS_MOZBINDIR MOZ_PIS_SESSION_PID MOZ_PIS_USER_DIR
+
+    case "${1}" in
+	"start")
+	    for curr_pis in "${MOZ_PIS_MOZBINDIR}/init.d"/S* \
+			    "${HOME}/${MOZ_PIS_USER_DIR}/init.d"/S*; do
+		if [ -x "${curr_pis}" ]; then
+		    case "${curr_pis}" in
+			*.sh)
+			    . "${curr_pis}"
+			    ;;
+			*)
+			    ${curr_pis} "start"
+			    ;;
+		    esac
+		fi
+	    done
+	    ;;
+	"stop")
+	    for curr_pis in "${MOZ_PIS_MOZBINDIR}/init.d"/K* \
+			    "${HOME}/${MOZ_PIS_USER_DIR}/init.d"/K*; do
+		if [ -x "${curr_pis}" ]; then
+		    case "${curr_pis}" in
+			*.sh)
+			    . "${curr_pis}"
+			    ;;
+			*)
+			    ${curr_pis} "stop"
+			    ;;
+		    esac
+		fi
+	    done
+	    ;;
+	*)
+	    echo "$0: Internal error in moz_pis_startstop_scripts." 1>&2
+	    exit 1
+	    ;;
+    esac
 }
 
-#uncomment for debugging
+# uncomment for debugging
 #set -x
 
-moz_libdir=%MOZAPPDIR%
-MRE_HOME=%MREDIR%
+#
+# variables
+#
+#location="new-tab"
+#MOZILLA_UILOCALE="en-US"
+#MOZILLA_UIREGION="US"
+
+#
+# working definitions
+#
+MOZ_USER_DIR="%MOZ_USER_DIR%"
+moz_libdir="%MOZAPPDIR%"
+MRE_HOME="%MREDIR%"
+
+debugging=		# set the debugging level
+use_openFile="yes"	# use openFile() for file/dir
+here=`pwd`
+
+if [ ! -d "${MRE_HOME}" ]; then
+    # use moz_libdir as MRE_HOME
+    MRE_HOME="${moz_libdir}"
+fi
+export	MRE_HOME
 
 # Use run-mozilla.sh in the current dir if it exists
 # If not, then start resolving symlinks until we find run-mozilla.sh
@@ -82,149 +140,233 @@
 curdir=`dirname "$progname"`
 progbase=`basename "$progname"`
 run_moz="$curdir/run-mozilla.sh"
-if test -x "$run_moz"; then
-  dist_bin="$curdir"
-  found=1
+if [ -x "$run_moz" ]; then
+    dist_bin="$curdir"
+    found=1
 else
-  here=`/bin/pwd`
-  while [ -h "$progname" ]; do
-    bn=`basename "$progname"`
-    cd `dirname "$progname"`
-    progname=`/bin/ls -l "$bn" | sed -e 's/^.* -> //' `
-    if [ ! -x "$progname" ]; then
-      break
-    fi
-    curdir=`dirname "$progname"`
-    run_moz="$curdir/run-mozilla.sh"
-    if [ -x "$run_moz" ]; then
-      cd "$curdir"
-      dist_bin=`pwd`
-      run_moz="$dist_bin/run-mozilla.sh"
-      found=1
-      break
-    fi
-  done
-  cd "$here"
+    while [ -h "${progname}" ]; do
+	bn=`basename "${progname}"`
+	cd `dirname "${progname}"`
+	progname=`ls -l "${bn}" | sed -e 's/^.* -> //'`
+	if [ ! -x "$progname" ]; then
+	    break
+	fi
+    	curdir=`dirname "${progname}"`
+    	run_moz="${curdir}/run-mozilla.sh"
+    	if [ -x "${run_moz}" ]; then
+	    cd "$curdir"
+	    dist_bin=`pwd`
+	    run_moz="${dist_bin}/run-mozilla.sh"
+	    found=1
+	    break
+	fi
+    done
+    cd "${here}"
 fi
 if [ $found = 0 ]; then
-  # Check default compile-time libdir
-  if [ -x "$moz_libdir/run-mozilla.sh" ]; then
-    dist_bin="$moz_libdir"
-  else 
-    echo "Cannot find mozilla runtime directory. Exiting."
-    exit 1
-  fi
+    # Check default compile-time libdir
+    if [ -x "${moz_libdir}/run-mozilla.sh" ]; then
+	dist_bin="$moz_libdir"
+	run_moz="${dist_bin}/run-mozilla.sh"
+    else
+	echo "$0: Cannot find mozilla runtime directory. Exiting." 1>&2
+	exit 1
+    fi
 fi
 
-script_args=""
-moreargs=""
-debugging=0
 MOZILLA_BIN="${progbase}-bin"
+if [ "$OSTYPE" = "beos" ]; then
+    mimeset -F "$MOZILLA_BIN"
+fi
 
-# The following is to check for a currently running instance.
-# This is taken almost verbatim from the Mozilla RPM package's launch script.
-MOZ_CLIENT_PROGRAM="$dist_bin/mozilla-xremote-client"
-check_running() {
-    "${run_moz}" "$MOZ_CLIENT_PROGRAM" -a "${progbase}" 'ping()' 2>/dev/null >/dev/null
-    RETURN_VAL=$?
-    if [ $RETURN_VAL -eq 0 ]; then
-        echo 1
-        return 1
+# test for binary apps in ${dist_bin}
+if [ -x "${dist_bin}/${MOZILLA_BIN}" ]; then
+    MOZILLA_BIN="${dist_bin}/${progbase}-bin"
+else
+    echo "$0: Cannot find mozilla binary executable. Exiting." 1>&2
+    exit 1
+fi
+if [ -x "${dist_bin}/mozilla-xremote-client" ]; then
+    MOZ_CLIENT_PROGRAM="${dist_bin}/mozilla-xremote-client -a ${progbase}"
+else
+    MOZ_CLIENT_PROGRAM="${MOZILLA_BIN} -remote -a ${progbase}"
+fi
+
+# guest a default remote command
+_remote_cmd="xfeDoCommand(openBrowser)"
+
+# test for a running copy of firefox
+ALREADY_RUNNING=	# null
+if [ -n "${DISPLAY}" ]; then
+    if [ -n "${debugging}" ]; then
+	echo "${run_moz} ${MOZ_CLIENT_PROGRAM} ping()"
+	${run_moz} ${MOZ_CLIENT_PROGRAM} 'ping()' && ALREADY_RUNNING="yes"
     else
-        echo 0
-        return 0
+	${run_moz} ${MOZ_CLIENT_PROGRAM} 'ping()' >/dev/null 2>&1 &&
+		ALREADY_RUNNING="yes"
     fi
-}
-
-if [ "$OSTYPE" = "beos" ]; then
-  mimeset -F "$MOZILLA_BIN"
+elif [ -n "${debugging}" ]; then
+    echo "$0: WARN, no DISPLAY environment" 1>&2
 fi
 
-ALREADY_RUNNING=`check_running`
-
-################################################################ Parse Arguments
-# If there's a command line argument but it doesn't begin with a -
-# it's probably a url.  Try to send it to a running instance.
-_USE_EXIST=0
-_optOne="$1"
-case "${_optOne}" in
-	-*) 
-		;;
+# parse options
+script_args=	# null
+moreargs=	# null
+target=		# null
+while [ $# -gt 0 ]
+do
+    if [ -n "${target}" ]; then
+	# well, this can't be the target if not last
+	moreargs="${moreargs} ${target}"
+	target=	# null
+    fi
+    case "$1" in
+	-p | --pure | -pure)
+	    MOZILLA_BIN="${MOZILLA_BIN}.pure"
+	    shift
+	    ;;
+	-g | --debug)
+	    script_args="${script_args} -g"
+	    debugging=1
+	    shift
+	    ;;
+	-d | --debugger)
+	    if [ -n "$2" ]; then
+		script_args="${script_args} -d $2"
+		shift 2
+	    else
+		"$0: ERROR, -d needs an argument. Exiting" 1>&2
+		exit 1
+	    fi
+	    ;;
+	-UILocale)
+	    if [ -n "$2" ]; then
+		uilocale="$2"
+		shift 2
+	    else
+		echo "$0: ERROR, -UILocale needs an argument. Exiting" 1>&2
+		exit 1
+	    fi
+	    ;;
+	-UIRegion)
+	    if [ -n "$2" ]; then
+		uiregion="$2"
+		shift 2
+	    else
+		echo "$0: ERROR, -UIRegion needs an argument. Exiting" 1>&2
+		exit 1
+	    fi
+	    ;;
+	-browser)
+	    _remote_cmd="xfeDoCommand(openBrowser)"
+	    moreargs="${moreargs} $1"
+	    shift
+	    ;;
+	-mail)
+	    _remote_cmd="xfeDoCommand(openInbox)"
+	    moreargs="${moreargs} $1"
+	    shift
+	    ;;
+	-compose)
+	    _remote_cmd="xfeDoCommand(composeMessage)"
+	    moreargs="${moreargs} $1"
+	    shift
+	    ;;
+	-chat | -edit | -webcal)
+	    # don't use remote for this
+	    ALREADY_RUNNING=	# null
+	    moreargs="${moreargs} $1"
+	    shift
+	    ;;
+	-P)
+	    if [ -n "$2" ]; then
+		moreargs="${moreargs} $1 '$2'"
+		shift 2
+	    else
+		echo "$0: ERROR, -P needs an argument. Exiting" 1>&2
+		exit 1
+	    fi
+	    ;;
+	-*)
+	    moreargs="${moreargs} $1"
+	    shift
+	    ;;
 	*)
-		_USE_EXIST=1
-		;;
-esac
-
-_optLast=
-for i in "$@"; do 
-	_optLast="${i}"
-done #last arg
-
-if [ `expr "${_optLast}" : '.*:/.*'` -eq 0 -a \( -f "${_optLast}" -o -d "${_optLast}" \) ]; then
-	# Last argument seems to be a local file/directory
-	# Check, if it is absolutely specified (ie. /home/foo/file vs. ./file)
-	# If it is just "relatively" (./file) specified, make it absolutely
-	[ `expr "${_optLast}" : '/.*'` -eq 0 ] && _optLast="file://`pwd`/${_optLast}"
-fi
-################################################################ Parse Arguments
-
-########################################################################### Main
-if [ $ALREADY_RUNNING -eq 1 ]; then
-	# There's an instance already running. Use it.
-	# Any command line args passed in?
-	if [ $# -gt 0 ]; then
-		# There were "some" command line args.
-		if [ ${_USE_EXIST} -eq 1 ]; then
-			# We should use an existing instance, as _USE_EXIST=$_USE_EXIST=-1
-			_remote_cmd="openURL(${_optLast})"
-			"${run_moz}" "$MOZ_CLIENT_PROGRAM" -a "${progbase}" "${_remote_cmd}"
-			unset _remote_cmd
-			exit $?
-		fi
+	    target="$1"
+	    shift
+	    ;;
+    esac
+done
+
+# process target
+if [ -n "${target}" ]; then
+    if [ `expr "${target}" : '.*:.*'` -eq 0 ]; then
+	if [ `expr "${target}" : '/.*'` -eq 0 ]; then
+	    target="${here}/${target}"
+	fi
+	if [ -r "${target}" -o -d "${target}" ]; then
+	    [ -n "${use_openFile}" ] || target="file://${target}"
 	else
-		# No command line args. Open new window/tab
-		#exec "${run_moz}" "$MOZ_CLIENT_PROGRAM" -a "${progbase}" "xfeDoCommand(openBrowser)"
-		"${run_moz}" "$MOZ_CLIENT_PROGRAM" -a "${progbase}" "xfeDoCommand(openBrowser)"
-		exit $?
+	    echo "$0: WARN, target: ${target} not an URI/file/dir" 1>&2
+	    ALREADY_RUNNING=	# null
 	fi
+    else
+	# an former URI, don't use openFile
+	use_openFile=	# null
+    fi
 fi
-# Default action - no running instance or _USE_EXIST (${_USE_EXIST}) ! -eq 1
-########################################################################### Main
 
-while [ $# -gt 0 ]
-do
-  case "$1" in
-    -p | --pure | -pure)
-      MOZILLA_BIN="${MOZILLA_BIN}.pure"
-      shift
-      ;;
-    -g | --debug)
-      script_args="$script_args -g"
-      debugging=1
-      shift
-      ;;
-    -d | --debugger)
-      script_args="$script_args -d $2"
-      shift 2
-      ;;
-    *)
-      moreargs="$moreargs \"$1\""
-      shift 1
-      ;;
-  esac
-done
+# try remote protocol if running
+if [ -n "${ALREADY_RUNNING}" ]; then
+    if [ -n "${target}" ]; then
+	if [ -n "${use_openFile}" ]; then
+	    _remote_cmd="openFile(${target})"
+	elif [ -n "${location}" ]; then
+	    _remote_cmd="openURL(${target},${location})"
+	else
+	    _remote_cmd="openURL(${target})"
+	fi
+    fi
+    # FIXME problems with freedesktop StartupNotify
+    if [ -n "${debugging}" ]; then
+	echo "${run_moz} ${script_args} ${MOZ_CLIENT_PROGRAM} ${_remote_cmd}"
+    fi
+    ${run_moz} ${script_args} ${MOZ_CLIENT_PROGRAM} ${_remote_cmd} && exit 0
+fi
+
+# fallback to direct invocation
+
+# UILocale, UIRegion
+if [ -z "${uilocale}" -a -n "${MOZILLA_UILOCALE}" ]; then
+    uilocale="${MOZILLA_UILOCALE}"
+fi
+if [ -z "${uiregion}" -a -n "${MOZILLA_UIREGION}" ]; then
+    uiregion="${MOZILLA_UIREGION}"
+fi
+if [ -n "${uiregion}" -a -z "${uilocale}" ]; then
+    uilocale="en-US"
+fi
+if [ -n "${uilocale}" ]; then
+    if [ -n "${uiregion}" ]; then
+	moreargs="-UIRegion ${uiregion} ${more_args}"
+    fi
+    moreargs="-UILocale ${uilocale} ${more_args}"
+fi
 
-export MRE_HOME
-eval "set -- $moreargs"
+# real invocation
+if [ -n "${target}" ]; then
+    eval "set -- ${moreargs} \"${target}\""
+else
+    eval "set -- ${moreargs}"
+fi
 
 ## Start addon scripts
 moz_pis_startstop_scripts "start"
 
-if [ $debugging = 1 ]
-then
-  echo $dist_bin/run-mozilla.sh $script_args $dist_bin/$MOZILLA_BIN "$@"
+if [ -n "${debugging}" ]; then
+    echo "${run_moz} ${script_args} ${MOZILLA_BIN} $@"
 fi
-"$dist_bin/run-mozilla.sh" $script_args "$dist_bin/$MOZILLA_BIN" "$@"
+${run_moz} ${script_args} ${MOZILLA_BIN} "$@"
 exitcode=$?
 
 ## Stop addon scripts
OpenPOWER on IntegriCloud