diff options
-rw-r--r-- | DEPS | 5 | ||||
-rw-r--r-- | chrome/browser/shell_integration_linux.cc | 69 | ||||
-rw-r--r-- | chrome/chrome.gyp | 15 | ||||
-rw-r--r-- | chrome/common/temp_scaffolding_stubs.cc | 14 | ||||
-rwxr-xr-x | chrome/tools/build/linux/chrome-wrapper | 62 |
5 files changed, 150 insertions, 15 deletions
@@ -84,6 +84,11 @@ deps_os = { "src/third_party/WebKit/WebKit/mac": Var("webkit_trunk") + "/WebKit/mac@" + Var("webkit_revision"), }, + "unix": { + # Linux, really. + "src/third_party/xdg-utils": + "/trunk/deps/third_party/xdg-utils@20073", + }, } diff --git a/chrome/browser/shell_integration_linux.cc b/chrome/browser/shell_integration_linux.cc new file mode 100644 index 0000000..34b817b --- /dev/null +++ b/chrome/browser/shell_integration_linux.cc @@ -0,0 +1,69 @@ +// 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; +} diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index 13e7e95..26c37fef 100644 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -1434,6 +1434,7 @@ 'browser/shell_integration.cc', 'browser/shell_integration.h', 'browser/shell_integration_mac.mm', + 'browser/shell_integration_linux.cc', 'browser/spellcheck_worditerator.cc', 'browser/spellcheck_worditerator.h', 'browser/spellchecker.cc', @@ -2551,7 +2552,19 @@ 'copies': [ { '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', diff --git a/chrome/common/temp_scaffolding_stubs.cc b/chrome/common/temp_scaffolding_stubs.cc index bd2797f..b24fc9a 100644 --- a/chrome/common/temp_scaffolding_stubs.cc +++ b/chrome/common/temp_scaffolding_stubs.cc @@ -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 bool FirstRun::ProcessMasterPreferences(const FilePath& user_data_dir, diff --git a/chrome/tools/build/linux/chrome-wrapper b/chrome/tools/build/linux/chrome-wrapper new file mode 100755 index 0000000..70b068d --- /dev/null +++ b/chrome/tools/build/linux/chrome-wrapper @@ -0,0 +1,62 @@ +#!/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" "$@" |