Commit 98566d7a authored by benwells@chromium.org's avatar benwells@chromium.org

Moved Linux specific shell integration declarations into own header.

This continues refactoring started in http://codereview.chromium.org/9958006/

BUG=None
TEST=Refactor; covered by existing tests


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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@132489 0039d316-1c4b-4281-b951-d872f2087c98
parent ab1c2c81
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Copyright (c) 2012 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.
......@@ -12,7 +12,7 @@
#include "base/logging.h"
#include "base/nix/xdg_util.h"
#include "chrome/browser/background/background_mode_manager.h"
#include "chrome/browser/shell_integration.h"
#include "chrome/browser/shell_integration_linux.h"
#include "chrome/browser/ui/gtk/gtk_util.h"
#include "chrome/common/auto_start_linux.h"
#include "chrome/common/chrome_switches.h"
......@@ -40,7 +40,7 @@ void EnableLaunchOnStartupCallback() {
std::string command_line = wrapper_script +
" --" + switches::kNoStartupWindow;
if (!AutoStart::AddApplication(
ShellIntegration::GetDesktopName(environment.get()),
ShellIntegrationLinux::GetDesktopName(environment.get()),
version_info->Name(),
command_line,
false)) {
......@@ -50,7 +50,8 @@ void EnableLaunchOnStartupCallback() {
void DisableLaunchOnStartupCallback() {
scoped_ptr<base::Environment> environment(base::Environment::Create());
if (!AutoStart::Remove(ShellIntegration::GetDesktopName(environment.get()))) {
if (!AutoStart::Remove(
ShellIntegrationLinux::GetDesktopName(environment.get()))) {
NOTREACHED() << "Failed to deregister launch on login.";
}
}
......
......@@ -17,12 +17,6 @@
class CommandLine;
#if defined(USE_X11)
namespace base {
class Environment;
}
#endif
class ShellIntegration {
public:
// Sets Chrome as the default browser (only for the current user). Returns
......@@ -119,34 +113,6 @@ class ShellIntegration {
const FilePath& user_data_dir,
const FilePath& extension_path);
#if defined(USE_X11)
// Returns filename of the desktop shortcut used to launch the browser.
static std::string GetDesktopName(base::Environment* env);
static bool GetDesktopShortcutTemplate(base::Environment* env,
std::string* output);
// Returns filename for .desktop file based on |url|, sanitized for security.
static FilePath GetDesktopShortcutFilename(const GURL& url);
// Returns contents for .desktop file based on |template_contents|, |url|
// and |title|. The |template_contents| should be contents of .desktop file
// used to launch Chrome.
static std::string GetDesktopFileContents(
const std::string& template_contents,
const std::string& app_name,
const GURL& url,
const std::string& extension_id,
const bool is_platform_app,
const FilePath& web_app_path,
const FilePath& extension_path,
const string16& title,
const std::string& icon_name);
static bool CreateDesktopShortcut(const ShortcutInfo& shortcut_info,
const std::string& shortcut_template);
#endif // defined(USE_X11)
#if defined(OS_WIN)
// Generates Win7 app id for given app name and profile path. The returned app
// id is in the format of "|app_name|[.<profile_id>]". "profile_id" is
......
......@@ -232,21 +232,6 @@ const char kXdgSettingsDefaultSchemeHandler[] = "default-url-scheme-handler";
} // namespace
// static
std::string ShellIntegration::GetDesktopName(base::Environment* env) {
#if defined(GOOGLE_CHROME_BUILD)
return "google-chrome.desktop";
#else // CHROMIUM_BUILD
// Allow $CHROME_DESKTOP to override the built-in value, so that development
// versions can set themselves as the default without interfering with
// non-official, packaged versions using the built-in value.
std::string name;
if (env->GetVar("CHROME_DESKTOP", &name) && !name.empty())
return name;
return "chromium-browser.desktop";
#endif
}
namespace {
// Utility function to get the path to the version of a script shipped with
......@@ -307,7 +292,7 @@ bool SetDefaultWebClient(const std::string& protocol) {
argv.push_back(kXdgSettingsDefaultSchemeHandler);
argv.push_back(protocol);
}
argv.push_back(ShellIntegration::GetDesktopName(env.get()));
argv.push_back(ShellIntegrationLinux::GetDesktopName(env.get()));
int exit_code;
bool ran_ok = LaunchXdgUtility(argv, &exit_code);
......@@ -338,7 +323,7 @@ ShellIntegration::DefaultWebClientState GetIsDefaultWebClient(
argv.push_back(kXdgSettingsDefaultSchemeHandler);
argv.push_back(protocol);
}
argv.push_back(ShellIntegration::GetDesktopName(env.get()));
argv.push_back(ShellIntegrationLinux::GetDesktopName(env.get()));
std::string reply;
int success_code;
......@@ -402,9 +387,24 @@ bool ShellIntegration::IsFirefoxDefaultBrowser() {
return browser.find("irefox") != std::string::npos;
}
// static
bool ShellIntegration::GetDesktopShortcutTemplate(
base::Environment* env, std::string* output) {
namespace ShellIntegrationLinux {
std::string GetDesktopName(base::Environment* env) {
#if defined(GOOGLE_CHROME_BUILD)
return "google-chrome.desktop";
#else // CHROMIUM_BUILD
// Allow $CHROME_DESKTOP to override the built-in value, so that development
// versions can set themselves as the default without interfering with
// non-official, packaged versions using the built-in value.
std::string name;
if (env->GetVar("CHROME_DESKTOP", &name) && !name.empty())
return name;
return "chromium-browser.desktop";
#endif
}
bool GetDesktopShortcutTemplate(base::Environment* env,
std::string* output) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
std::vector<FilePath> search_paths;
......@@ -446,8 +446,7 @@ bool ShellIntegration::GetDesktopShortcutTemplate(
return false;
}
// static
FilePath ShellIntegration::GetDesktopShortcutFilename(const GURL& url) {
FilePath GetDesktopShortcutFilename(const GURL& url) {
// Use a prefix, because xdg-desktop-menu requires it.
std::string filename =
std::string(chrome::kBrowserProcessExecutableName) + "-" + url.spec();
......@@ -471,8 +470,7 @@ FilePath ShellIntegration::GetDesktopShortcutFilename(const GURL& url) {
return FilePath();
}
// static
std::string ShellIntegration::GetDesktopFileContents(
std::string GetDesktopFileContents(
const std::string& template_contents,
const std::string& app_name,
const GURL& url,
......@@ -590,9 +588,8 @@ std::string ShellIntegration::GetDesktopFileContents(
return output_buffer;
}
// static
bool ShellIntegration::CreateDesktopShortcut(
const ShortcutInfo& shortcut_info,
bool CreateDesktopShortcut(
const ShellIntegration::ShortcutInfo& shortcut_info,
const std::string& shortcut_template) {
DCHECK(!shortcut_info.is_platform_app);
DCHECK(shortcut_info.extension_id.empty());
......@@ -601,24 +598,22 @@ bool ShellIntegration::CreateDesktopShortcut(
shortcut_info, FilePath(), shortcut_template);
}
namespace ShellIntegrationLinux {
bool CreateDesktopShortcutForChromeApp(
const ShellIntegration::ShortcutInfo& shortcut_info,
const FilePath& web_app_path,
const std::string& shortcut_template) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
FilePath shortcut_filename = ShellIntegration::GetDesktopShortcutFilename(
shortcut_info.url);
FilePath shortcut_filename =
ShellIntegrationLinux::GetDesktopShortcutFilename(shortcut_info.url);
if (shortcut_filename.empty())
return false;
std::string icon_name = CreateShortcutIcon(shortcut_info, shortcut_filename);
std::string icon_name =CreateShortcutIcon(shortcut_info, shortcut_filename);
std::string app_name =
web_app::GenerateApplicationNameFromInfo(shortcut_info);
std::string contents = ShellIntegration::GetDesktopFileContents(
std::string contents = ShellIntegrationLinux::GetDesktopFileContents(
shortcut_template,
app_name,
shortcut_info.url,
......
......@@ -11,9 +11,39 @@
#include "base/basictypes.h"
#include "base/file_path.h"
#include "chrome/browser/shell_integration.h"
#include "googleurl/src/gurl.h"
namespace base {
class Environment;
}
namespace ShellIntegrationLinux {
// Returns filename of the desktop shortcut used to launch the browser.
std::string GetDesktopName(base::Environment* env);
bool GetDesktopShortcutTemplate(base::Environment* env,
std::string* output);
// Returns filename for .desktop file based on |url|, sanitized for security.
FilePath GetDesktopShortcutFilename(const GURL& url);
// Returns contents for .desktop file based on |template_contents|, |url|
// and |title|. The |template_contents| should be contents of .desktop file
// used to launch Chrome.
std::string GetDesktopFileContents(const std::string& template_contents,
const std::string& app_name,
const GURL& url,
const std::string& extension_id,
const bool is_platform_app,
const FilePath& web_app_path,
const FilePath& extension_path,
const string16& title,
const std::string& icon_name);
bool CreateDesktopShortcut(const ShellIntegration::ShortcutInfo& shortcut_info,
const std::string& shortcut_template);
bool CreateDesktopShortcutForChromeApp(
const ShellIntegration::ShortcutInfo& shortcut_info,
const FilePath& web_app_path,
......
......@@ -24,6 +24,7 @@
#include "chrome/installer/util/browser_distribution.h"
#elif defined(OS_POSIX) && !defined(OS_MACOSX)
#include "base/environment.h"
#include "chrome/browser/shell_integration_linux.h"
#endif
#define FPL FILE_PATH_LITERAL
......@@ -92,8 +93,8 @@ TEST(ShellIntegrationTest, GetDesktopShortcutTemplate) {
temp_dir.path().AppendASCII(kTemplateFilename),
kTestData1, strlen(kTestData1)));
std::string contents;
ASSERT_TRUE(ShellIntegration::GetDesktopShortcutTemplate(&env,
&contents));
ASSERT_TRUE(ShellIntegrationLinux::GetDesktopShortcutTemplate(&env,
&contents));
EXPECT_EQ(kTestData1, contents);
}
......@@ -110,8 +111,8 @@ TEST(ShellIntegrationTest, GetDesktopShortcutTemplate) {
.AppendASCII(kTemplateFilename),
kTestData2, strlen(kTestData2)));
std::string contents;
ASSERT_TRUE(ShellIntegration::GetDesktopShortcutTemplate(&env,
&contents));
ASSERT_TRUE(ShellIntegrationLinux::GetDesktopShortcutTemplate(&env,
&contents));
EXPECT_EQ(kTestData2, contents);
}
......@@ -132,8 +133,8 @@ TEST(ShellIntegrationTest, GetDesktopShortcutTemplate) {
.AppendASCII(kTemplateFilename),
kTestData2, strlen(kTestData2)));
std::string contents;
ASSERT_TRUE(ShellIntegration::GetDesktopShortcutTemplate(&env,
&contents));
ASSERT_TRUE(ShellIntegrationLinux::GetDesktopShortcutTemplate(&env,
&contents));
EXPECT_EQ(kTestData1, contents);
}
}
......@@ -155,7 +156,7 @@ TEST(ShellIntegrationTest, GetDesktopShortcutFilename) {
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); i++) {
EXPECT_EQ(std::string(chrome::kBrowserProcessExecutableName) + "-" +
test_cases[i].path,
ShellIntegration::GetDesktopShortcutFilename(
ShellIntegrationLinux::GetDesktopShortcutFilename(
GURL(test_cases[i].url)).value()) <<
" while testing " << test_cases[i].url;
}
......@@ -352,7 +353,7 @@ TEST(ShellIntegrationTest, GetDesktopFileContents) {
SCOPED_TRACE(i);
EXPECT_EQ(
test_cases[i].expected_output,
ShellIntegration::GetDesktopFileContents(
ShellIntegrationLinux::GetDesktopFileContents(
test_cases[i].template_contents,
web_app::GenerateApplicationNameFromURL(GURL(test_cases[i].url)),
GURL(test_cases[i].url),
......
......@@ -11,6 +11,7 @@
#include "base/utf_string_conversions.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/shell_integration.h"
#include "chrome/browser/shell_integration_linux.h"
#include "chrome/browser/ui/gtk/gtk_util.h"
#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
#include "chrome/browser/ui/web_applications/web_app_ui.h"
......@@ -219,10 +220,10 @@ void CreateApplicationShortcutsDialogGtk::CreateDesktopShortcut(
scoped_ptr<base::Environment> env(base::Environment::Create());
std::string shortcut_template;
if (ShellIntegration::GetDesktopShortcutTemplate(env.get(),
&shortcut_template)) {
ShellIntegration::CreateDesktopShortcut(shortcut_info,
shortcut_template);
if (ShellIntegrationLinux::GetDesktopShortcutTemplate(env.get(),
&shortcut_template)) {
ShellIntegrationLinux::CreateDesktopShortcut(shortcut_info,
shortcut_template);
Release();
} else {
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
......
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Copyright (c) 2012 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.
......@@ -9,7 +9,7 @@
#include "base/environment.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/shell_integration.h"
#include "chrome/browser/shell_integration_linux.h"
// Unity data typedefs.
typedef struct _UnityInspector UnityInspector;
......@@ -77,7 +77,7 @@ void EnsureMethodsLoaded() {
dlsym(unity_lib, "unity_launcher_entry_get_for_desktop_id"));
if (entry_get_for_desktop_id) {
scoped_ptr<base::Environment> env(base::Environment::Create());
std::string desktop_id = ShellIntegration::GetDesktopName(env.get());
std::string desktop_id = ShellIntegrationLinux::GetDesktopName(env.get());
chrome_entry = entry_get_for_desktop_id(desktop_id.c_str());
entry_set_count =
......
......@@ -21,8 +21,8 @@ bool CreatePlatformShortcut(
scoped_ptr<base::Environment> env(base::Environment::Create());
std::string shortcut_template;
if (!ShellIntegration::GetDesktopShortcutTemplate(env.get(),
&shortcut_template)) {
if (!ShellIntegrationLinux::GetDesktopShortcutTemplate(env.get(),
&shortcut_template)) {
return false;
}
return ShellIntegrationLinux::CreateDesktopShortcutForChromeApp(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment