Skip to content
Snippets Groups Projects
Commit ef525cc4 authored by mdm@chromium.org's avatar mdm@chromium.org
Browse files

Add default browser checking and setting on Linux.

BUG=11972
TEST=none

Review URL: http://codereview.chromium.org/155100

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20380 0039d316-1c4b-4281-b951-d872f2087c98
parent 93fd78f4
No related merge requests found
...@@ -84,6 +84,11 @@ deps_os = { ...@@ -84,6 +84,11 @@ deps_os = {
"src/third_party/WebKit/WebKit/mac": "src/third_party/WebKit/WebKit/mac":
Var("webkit_trunk") + "/WebKit/mac@" + Var("webkit_revision"), Var("webkit_trunk") + "/WebKit/mac@" + Var("webkit_revision"),
}, },
"unix": {
# Linux, really.
"src/third_party/xdg-utils":
"/trunk/deps/third_party/xdg-utils@20073",
},
} }
......
// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/shell_integration.h"
#include <stdlib.h>
#include <vector>
#include "base/process_util.h"
#if defined(GOOGLE_CHROME_BUILD)
#define DESKTOP_APP_NAME "google-chrome.desktop"
#else // CHROMIUM_BUILD
#define DESKTOP_APP_NAME "chromium-browser.desktop"
#endif
// We delegate the difficult of setting the default browser in Linux desktop
// environments to a new xdg utility, xdg-settings. We'll have to include a copy
// of it for this to work, obviously, but that's actually the suggested approach
// for xdg utilities anyway.
bool ShellIntegration::SetAsDefaultBrowser() {
std::vector<std::string> argv;
argv.push_back("xdg-settings");
argv.push_back("set");
argv.push_back("default-web-browser");
argv.push_back(DESKTOP_APP_NAME);
int success_code;
base::ProcessHandle handle;
base::file_handle_mapping_vector no_files;
if (!base::LaunchApp(argv, no_files, false, &handle))
return false;
base::WaitForExitCode(handle, &success_code);
return success_code == EXIT_SUCCESS;
}
static std::string getDefaultBrowser() {
std::vector<std::string> argv;
argv.push_back("xdg-settings");
argv.push_back("get");
argv.push_back("default-web-browser");
std::string output;
base::GetAppOutput(CommandLine(argv), &output);
// If GetAppOutput() fails, we'll return the empty string.
return output;
}
bool ShellIntegration::IsDefaultBrowser() {
std::string browser = getDefaultBrowser();
// Allow for an optional newline at the end.
if (browser.length() > 0 && browser[browser.length() - 1] == '\n')
browser.resize(browser.length() - 1);
if (!browser.length()) {
// We don't know what the default browser is; chances are, we can't
// set it either. So, check to see if we were run in the wrapper
// and pretend that we are the default unless we were run from it,
// to avoid warning that we aren't the default when it's useless.
return !getenv("CHROME_WRAPPER");
}
return !browser.compare(DESKTOP_APP_NAME);
}
bool ShellIntegration::IsFirefoxDefaultBrowser() {
return getDefaultBrowser().find("irefox") != std::string::npos;
}
...@@ -1434,6 +1434,7 @@ ...@@ -1434,6 +1434,7 @@
'browser/shell_integration.cc', 'browser/shell_integration.cc',
'browser/shell_integration.h', 'browser/shell_integration.h',
'browser/shell_integration_mac.mm', 'browser/shell_integration_mac.mm',
'browser/shell_integration_linux.cc',
'browser/spellcheck_worditerator.cc', 'browser/spellcheck_worditerator.cc',
'browser/spellcheck_worditerator.h', 'browser/spellcheck_worditerator.h',
'browser/spellchecker.cc', 'browser/spellchecker.cc',
...@@ -2551,7 +2552,19 @@ ...@@ -2551,7 +2552,19 @@
'copies': [ 'copies': [
{ {
'destination': '<(PRODUCT_DIR)', 'destination': '<(PRODUCT_DIR)',
'files': ['<(INTERMEDIATE_DIR)/repack/chrome.pak'], 'files': ['<(INTERMEDIATE_DIR)/repack/chrome.pak',
'tools/build/linux/chrome-wrapper',
'../third_party/xdg-utils/scripts/xdg-settings',
],
# The wrapper script above may need to generate a .desktop file,
# which requires an icon. So, copy one next to the script.
'conditions': [
['branding=="Chrome"', {
'files': ['app/theme/google_chrome/product_logo_48.png']
}, { # else: 'branding!="Chrome"
'files': ['app/theme/chromium/product_logo_48.png']
}],
],
}, },
{ {
'destination': '<(PRODUCT_DIR)/locales', 'destination': '<(PRODUCT_DIR)/locales',
......
...@@ -138,20 +138,6 @@ void AutomationProvider::OnMessageFromExternalHost( ...@@ -138,20 +138,6 @@ void AutomationProvider::OnMessageFromExternalHost(
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
#if defined(OS_LINUX)
bool ShellIntegration::SetAsDefaultBrowser() {
// http://code.google.com/p/chromium/issues/detail?id=11972
return true;
}
bool ShellIntegration::IsDefaultBrowser() {
// http://code.google.com/p/chromium/issues/detail?id=11972
return true;
}
#endif
//--------------------------------------------------------------------------
// static // static
bool FirstRun::ProcessMasterPreferences(const FilePath& user_data_dir, bool FirstRun::ProcessMasterPreferences(const FilePath& user_data_dir,
......
#!/bin/sh
# Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# Running Chromium via this script makes it possible to set Chromium as the
# default browser directly out of a compile, without needing to package it.
DESKTOP="chromium-browser"
TITLE="Chromium"
# Check to see if there is a desktop file of the given name
exists_desktop_file() {
# Build a search list from $XDG_DATA_HOME and $XDG_DATA_DIRS, the latter
# of which can itself be a colon-separated list of directories to search.
search="${XDG_DATA_HOME:-$HOME/.local/share}:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}"
IFS=:
for dir in $search; do
unset IFS
[ "$dir" -a -d "$dir/applications" ] || continue
[ -r "$dir/applications/$DESKTOP.desktop" ] && return
done
# Didn't find it in the search path
return 1
}
# Generate a desktop file that will run this script
generate_desktop_file() {
apps="${XDG_DATA_HOME:-$HOME/.local/share}/applications"
cat > "$apps/$DESKTOP.desktop" << EOF
[Desktop Entry]
Version=1.0
Encoding=UTF-8
Name=$TITLE
Exec=$CHROME_WRAPPER %U
Terminal=false
Icon=$HERE/product_logo_48.png
Type=Application
Categories=Application;Network;WebBrowser;
MimeType=text/html;text/xml;application/xhtml_xml;
EOF
}
# Let the wrapped binary know that it has been run through the wrapper
export CHROME_WRAPPER="`readlink -f "$0"`"
HERE="`dirname "$CHROME_WRAPPER"`"
case ":$PATH:" in
*:$HERE:*)
# $PATH already contains $HERE
;;
*)
# Append $HERE to $PATH
export PATH="$PATH:$HERE"
;;
esac
exists_desktop_file || generate_desktop_file
exec "$HERE/chrome" "$@"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment