Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4211)

Unified Diff: chrome_linux/xdg-settings

Issue 7192017: Update reference builds to r89207. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/reference_builds/
Patch Set: '' Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome_linux/xdg-mime ('k') | chrome_mac/Chromium.app/Contents/Info.plist » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome_linux/xdg-settings
===================================================================
--- chrome_linux/xdg-settings (revision 89368)
+++ chrome_linux/xdg-settings (working copy)
@@ -129,7 +129,65 @@
echo "$@" >&2
}
+# This handles backslashes but not quote marks.
+first_word()
+{
+ read first rest
+ echo "$first"
+}
+
#-------------------------------------------------------------
+# map a binary to a .desktop file
+binary_to_desktop_file()
+{
+ search="${XDG_DATA_HOME:-$HOME/.local/share}:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}"
+ binary="`which "$1"`"
+ binary="`readlink -f "$binary"`"
+ base="`basename "$binary"`"
+ IFS=:
+ for dir in $search; do
+ unset IFS
+ [ "$dir" ] || continue
+ [ -d "$dir/applications" -o -d "$dir/applnk" ] || continue
+ for file in "$dir"/applications/*.desktop "$dir"/applications/*/*.desktop "$dir"/applnk/*.desktop "$dir"/applnk/*/*.desktop; do
+ [ -r "$file" ] || continue
+ # Check to make sure it's worth the processing.
+ grep -q "^Exec.*$base" "$file" || continue
+ # Make sure it's a visible desktop file (e.g. not "preferred-web-browser.desktop").
+ grep -Eq "^(NoDisplay|Hidden)=true" "$file" && continue
+ command="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- | first_word`"
+ command="`which "$command"`"
+ if [ x"`readlink -f "$command"`" = x"$binary" ]; then
+ # Fix any double slashes that got added path composition
+ echo "$file" | sed -e 's,//*,/,g'
+ return
+ fi
+ done
+ done
+}
+
+#-------------------------------------------------------------
+# map a .desktop file to a binary
+## FIXME: handle vendor dir case
+desktop_file_to_binary()
+{
+ search="${XDG_DATA_HOME:-$HOME/.local/share}:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}"
+ desktop="`basename "$1"`"
+ IFS=:
+ for dir in $search; do
+ unset IFS
+ [ "$dir" -a -d "$dir/applications" ] || continue
+ file="$dir/applications/$desktop"
+ [ -r "$file" ] || continue
+ # Remove any arguments (%F, %f, %U, %u, etc.).
+ command="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- | first_word`"
+ command="`which "$command"`"
+ readlink -f "$command"
+ return
+ done
+}
+
+#-------------------------------------------------------------
# Exit script on successfully completing the desired operation
exit_success()
@@ -287,7 +345,7 @@
;;
--version)
- echo "xdg-settings 1.0.2"
+ echo "xdg-settings 1.1.0 rc1"
exit_success
;;
esac
@@ -311,11 +369,45 @@
detectDE()
{
+ # see https://bugs.freedesktop.org/show_bug.cgi?id=34164
+ unset GREP_OPTIONS
+
if [ x"$KDE_FULL_SESSION" = x"true" ]; then DE=kde;
elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then DE=gnome;
elif `dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.GetNameOwner string:org.gnome.SessionManager > /dev/null 2>&1` ; then DE=gnome;
elif xprop -root _DT_SAVE_MODE 2> /dev/null | grep ' = \"xfce4\"$' >/dev/null 2>&1; then DE=xfce;
+ elif xprop -root 2> /dev/null | grep -i '^xfce_desktop_window' >/dev/null 2>&1; then DE=xfce
fi
+
+ if [ x"$DE" = x"" ]; then
+ # fallback to checking $DESKTOP_SESSION
+ case "$DESKTOP_SESSION" in
+ gnome)
+ DE=gnome;
+ ;;
+ LXDE)
+ DE=lxde;
+ ;;
+ xfce|xfce4)
+ DE=xfce;
+ ;;
+ esac
+ fi
+
+ if [ x"$DE" = x"" ]; then
+ # fallback to uname output for other platforms
+ case "$(uname 2>/dev/null)" in
+ Darwin)
+ DE=darwin;
+ ;;
+ esac
+ fi
+
+ if [ x"$DE" = x"gnome" ]; then
+ # gnome-default-applications-properties is only available in GNOME 2.x
+ # but not in GNOME 3.x
+ which gnome-default-applications-properties > /dev/null 2>&1 || DE="gnome3"
+ fi
}
#----------------------------------------------------------------------------
@@ -325,10 +417,10 @@
kfmclient_fix_exit_code()
{
- version=`kde${KDE_SESSION_VERSION}-config --version 2>/dev/null | grep KDE`
- major=`echo $version | sed 's/KDE: \([0-9]\).*/\1/'`
- minor=`echo $version | sed 's/KDE: [0-9]*\.\([0-9]\).*/\1/'`
- release=`echo $version | sed 's/KDE: [0-9]*\.[0-9]*\.\([0-9]\).*/\1/'`
+ version=`LC_ALL=C.UTF-8 kde-config --version 2>/dev/null | grep '^KDE'`
+ major=`echo $version | sed 's/KDE.*: \([0-9]\).*/\1/'`
+ minor=`echo $version | sed 's/KDE.*: [0-9]*\.\([0-9]\).*/\1/'`
+ release=`echo $version | sed 's/KDE.*: [0-9]*\.[0-9]*\.\([0-9]\).*/\1/'`
test "$major" -gt 3 && return $1
test "$minor" -gt 5 && return $1
test "$release" -gt 4 && return $1
@@ -353,59 +445,6 @@
# {{{ default browser
# {{{ utility functions
-# This handles backslashes but not quote marks.
-first_word()
-{
- read first rest
- echo "$first"
-}
-
-binary_to_desktop_file()
-{
- search="${XDG_DATA_HOME:-$HOME/.local/share}:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}"
- binary="`which "$1"`"
- binary="`readlink -f "$binary"`"
- base="`basename "$binary"`"
- IFS=:
- for dir in $search; do
- unset IFS
- [ "$dir" ] || continue
- [ -d "$dir/applications" -o -d "$dir/applnk" ] || continue
- for file in "$dir"/applications/*.desktop "$dir"/applnk/*.desktop; do
- [ -r "$file" ] || continue
- # Check to make sure it's worth the processing.
- grep -q "^Exec.*$base" "$file" || continue
- # Make sure it's a visible desktop file (e.g. not "preferred-web-browser.desktop").
- grep -Eq "^(NoDisplay|Hidden)=true" "$file" && continue
- command="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- | first_word`"
- command="`which "$command"`"
- if [ x"`readlink -f "$command"`" = x"$binary" ]; then
- # Fix any double slashes that got added path composition
- echo "$file" | sed -e 's,//*,/,g'
- return
- fi
- done
- done
-}
-
-desktop_file_to_binary()
-{
- search="${XDG_DATA_HOME:-$HOME/.local/share}:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}"
- desktop="`basename "$1"`"
- IFS=:
- for dir in $search; do
- unset IFS
- [ "$dir" -a -d "$dir/applications" ] || continue
- file="$dir/applications/$desktop"
- [ -r "$file" ] || continue
- # Remove any arguments (%F, %f, %U, %u, etc.).
- command="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- | first_word`"
- command="`which "$command"`"
- readlink -f "$command"
- return
- done
-}
-
# In order to remove an application from the automatically-generated list of
# applications for handling a given MIME type, the desktop environment may copy
# the global .desktop file into the user's .local directory, and remove that
@@ -416,21 +455,26 @@
# This function is hard-coded for text/html but it could be adapted if needed.
fix_local_desktop_file()
{
+ if test -z "$2" ; then
+ MIME="text/html"
+ else
+ MIME="$2"
+ fi
apps="${XDG_DATA_HOME:-$HOME/.local/share}/applications"
# No local desktop file?
[ ! -f "$apps/$1" ] && return
- MIME="`grep "^MimeType=" "$apps/$1" | cut -d= -f 2-`"
- case "$MIME" in
- text/html\;*|*\;text/html\;*|*\;text/html\;|*\;text/html)
- # Already has text/html? Great!
+ MIMETYPES="`grep "^MimeType=" "$apps/$1" | cut -d= -f 2-`"
+ case "$MIMETYPES" in
+ $MIME\;*|*\;$MIME\;*|*\;$MIME\;|*\;$MIME)
+ # Already has the mime-type? Great!
return 0
;;
esac
- # Add text/html to the list
+ # Add the mime-type to the list
temp="`mktemp "$apps/$1.XXXXXX"`" || return
grep -v "^MimeType=" "$apps/$1" >> "$temp"
- echo "MimeType=text/html;$MIME" >> "$temp"
+ echo "MimeType=$MIME;$MIMETYPES" >> "$temp"
oldlines="`wc -l < "$apps/$1"`"
newlines="`wc -l < "$temp"`"
@@ -464,22 +508,32 @@
get_browser_mime()
{
+ if test -z "$1" ; then
+ MIME="text/html"
+ else
+ MIME="$1"
+ fi
xdg_mime_fixup
- xdg-mime query default text/html
+ xdg-mime query default "$MIME"
}
set_browser_mime()
{
xdg_mime_fixup
- orig="`get_browser_mime`"
+ if test -z "$2" ; then
+ MIME="text/html"
+ else
+ MIME="$2"
+ fi
+ orig="`get_browser_mime $MIME`"
# Fixing the local desktop file can actually change the default browser all
# by itself, so we fix it only after querying to find the current default.
- fix_local_desktop_file "$1" || return
+ fix_local_desktop_file "$1" "$MIME" || return
mkdir -p "${XDG_DATA_HOME:-$HOME/.local/share}/applications"
- xdg-mime default "$1" text/html || return
+ xdg-mime default "$1" "$MIME" || return
if [ x"`get_browser_mime`" != x"$1" ]; then
# Put back the original value
- xdg-mime default "$orig" text/html
+ xdg-mime default "$orig" "$MIME"
exit_failure_operation_failed
fi
}
@@ -649,6 +703,45 @@
}
# }}} GNOME
+# {{{ GNOME 3.x
+
+get_browser_gnome3()
+{
+ get_browser_mime "x-scheme-handler/http"
+}
+
+check_browser_gnome3()
+{
+ desktop="$1"
+ check="`desktop_file_to_binary "$1"`"
+ if [ -z "$check" ]; then
+ echo no
+ exit_success
+ fi
+ # Check HTTP and HTTPS, but not about: and unknown:.
+ for protocol in http https; do
+ browser="`get_browser_mime "x-scheme-handler/$protocol"`"
+ if [ x"$browser" != x"$desktop" ]; then
+ echo no
+ exit_success
+ fi
+ done
+ echo yes
+ exit_success
+}
+
+set_browser_gnome3()
+{
+ binary="`desktop_file_to_binary "$1"`"
+ [ "$binary" ] || exit_failure_file_missing
+ set_browser_mime "$1" || return
+
+ # Set the default browser.
+ for protocol in http https about unknown; do
+ set_browser_mime "$1" "x-scheme-handler/$protocol" || return
+ done
+}
+# }}} GNOME 3.x
# {{{ xfce
get_browser_xfce()
@@ -858,7 +951,7 @@
detectDE
case "$DE" in
- kde|gnome|xfce)
+ kde|gnome*|xfce)
dispatch_specific "$@"
;;
« no previous file with comments | « chrome_linux/xdg-mime ('k') | chrome_mac/Chromium.app/Contents/Info.plist » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698