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 // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/nix/xdg_util.h" #include "base/nix/xdg_util.h"
#include "chrome/browser/background/background_mode_manager.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/browser/ui/gtk/gtk_util.h"
#include "chrome/common/auto_start_linux.h" #include "chrome/common/auto_start_linux.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
...@@ -40,7 +40,7 @@ void EnableLaunchOnStartupCallback() { ...@@ -40,7 +40,7 @@ void EnableLaunchOnStartupCallback() {
std::string command_line = wrapper_script + std::string command_line = wrapper_script +
" --" + switches::kNoStartupWindow; " --" + switches::kNoStartupWindow;
if (!AutoStart::AddApplication( if (!AutoStart::AddApplication(
ShellIntegration::GetDesktopName(environment.get()), ShellIntegrationLinux::GetDesktopName(environment.get()),
version_info->Name(), version_info->Name(),
command_line, command_line,
false)) { false)) {
...@@ -50,7 +50,8 @@ void EnableLaunchOnStartupCallback() { ...@@ -50,7 +50,8 @@ void EnableLaunchOnStartupCallback() {
void DisableLaunchOnStartupCallback() { void DisableLaunchOnStartupCallback() {
scoped_ptr<base::Environment> environment(base::Environment::Create()); 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."; NOTREACHED() << "Failed to deregister launch on login.";
} }
} }
......
...@@ -17,12 +17,6 @@ ...@@ -17,12 +17,6 @@
class CommandLine; class CommandLine;
#if defined(USE_X11)
namespace base {
class Environment;
}
#endif
class ShellIntegration { class ShellIntegration {
public: public:
// Sets Chrome as the default browser (only for the current user). Returns // Sets Chrome as the default browser (only for the current user). Returns
...@@ -119,34 +113,6 @@ class ShellIntegration { ...@@ -119,34 +113,6 @@ class ShellIntegration {
const FilePath& user_data_dir, const FilePath& user_data_dir,
const FilePath& extension_path); 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) #if defined(OS_WIN)
// Generates Win7 app id for given app name and profile path. The returned app // 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 // id is in the format of "|app_name|[.<profile_id>]". "profile_id" is
......
...@@ -232,21 +232,6 @@ const char kXdgSettingsDefaultSchemeHandler[] = "default-url-scheme-handler"; ...@@ -232,21 +232,6 @@ const char kXdgSettingsDefaultSchemeHandler[] = "default-url-scheme-handler";
} // namespace } // 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 { namespace {
// Utility function to get the path to the version of a script shipped with // Utility function to get the path to the version of a script shipped with
...@@ -307,7 +292,7 @@ bool SetDefaultWebClient(const std::string& protocol) { ...@@ -307,7 +292,7 @@ bool SetDefaultWebClient(const std::string& protocol) {
argv.push_back(kXdgSettingsDefaultSchemeHandler); argv.push_back(kXdgSettingsDefaultSchemeHandler);
argv.push_back(protocol); argv.push_back(protocol);
} }
argv.push_back(ShellIntegration::GetDesktopName(env.get())); argv.push_back(ShellIntegrationLinux::GetDesktopName(env.get()));
int exit_code; int exit_code;
bool ran_ok = LaunchXdgUtility(argv, &exit_code); bool ran_ok = LaunchXdgUtility(argv, &exit_code);
...@@ -338,7 +323,7 @@ ShellIntegration::DefaultWebClientState GetIsDefaultWebClient( ...@@ -338,7 +323,7 @@ ShellIntegration::DefaultWebClientState GetIsDefaultWebClient(
argv.push_back(kXdgSettingsDefaultSchemeHandler); argv.push_back(kXdgSettingsDefaultSchemeHandler);
argv.push_back(protocol); argv.push_back(protocol);
} }
argv.push_back(ShellIntegration::GetDesktopName(env.get())); argv.push_back(ShellIntegrationLinux::GetDesktopName(env.get()));
std::string reply; std::string reply;
int success_code; int success_code;
...@@ -402,9 +387,24 @@ bool ShellIntegration::IsFirefoxDefaultBrowser() { ...@@ -402,9 +387,24 @@ bool ShellIntegration::IsFirefoxDefaultBrowser() {
return browser.find("irefox") != std::string::npos; return browser.find("irefox") != std::string::npos;
} }
// static namespace ShellIntegrationLinux {
bool ShellIntegration::GetDesktopShortcutTemplate(
base::Environment* env, std::string* output) { 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)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
std::vector<FilePath> search_paths; std::vector<FilePath> search_paths;
...@@ -446,8 +446,7 @@ bool ShellIntegration::GetDesktopShortcutTemplate( ...@@ -446,8 +446,7 @@ bool ShellIntegration::GetDesktopShortcutTemplate(
return false; return false;
} }
// static FilePath GetDesktopShortcutFilename(const GURL& url) {
FilePath ShellIntegration::GetDesktopShortcutFilename(const GURL& url) {
// Use a prefix, because xdg-desktop-menu requires it. // Use a prefix, because xdg-desktop-menu requires it.
std::string filename = std::string filename =
std::string(chrome::kBrowserProcessExecutableName) + "-" + url.spec(); std::string(chrome::kBrowserProcessExecutableName) + "-" + url.spec();
...@@ -471,8 +470,7 @@ FilePath ShellIntegration::GetDesktopShortcutFilename(const GURL& url) { ...@@ -471,8 +470,7 @@ FilePath ShellIntegration::GetDesktopShortcutFilename(const GURL& url) {
return FilePath(); return FilePath();
} }
// static std::string GetDesktopFileContents(
std::string ShellIntegration::GetDesktopFileContents(
const std::string& template_contents, const std::string& template_contents,
const std::string& app_name, const std::string& app_name,
const GURL& url, const GURL& url,
...@@ -590,9 +588,8 @@ std::string ShellIntegration::GetDesktopFileContents( ...@@ -590,9 +588,8 @@ std::string ShellIntegration::GetDesktopFileContents(
return output_buffer; return output_buffer;
} }
// static bool CreateDesktopShortcut(
bool ShellIntegration::CreateDesktopShortcut( const ShellIntegration::ShortcutInfo& shortcut_info,
const ShortcutInfo& shortcut_info,
const std::string& shortcut_template) { const std::string& shortcut_template) {
DCHECK(!shortcut_info.is_platform_app); DCHECK(!shortcut_info.is_platform_app);
DCHECK(shortcut_info.extension_id.empty()); DCHECK(shortcut_info.extension_id.empty());
...@@ -601,24 +598,22 @@ bool ShellIntegration::CreateDesktopShortcut( ...@@ -601,24 +598,22 @@ bool ShellIntegration::CreateDesktopShortcut(
shortcut_info, FilePath(), shortcut_template); shortcut_info, FilePath(), shortcut_template);
} }
namespace ShellIntegrationLinux {
bool CreateDesktopShortcutForChromeApp( bool CreateDesktopShortcutForChromeApp(
const ShellIntegration::ShortcutInfo& shortcut_info, const ShellIntegration::ShortcutInfo& shortcut_info,
const FilePath& web_app_path, const FilePath& web_app_path,
const std::string& shortcut_template) { const std::string& shortcut_template) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
FilePath shortcut_filename = ShellIntegration::GetDesktopShortcutFilename( FilePath shortcut_filename =
shortcut_info.url); ShellIntegrationLinux::GetDesktopShortcutFilename(shortcut_info.url);
if (shortcut_filename.empty()) if (shortcut_filename.empty())
return false; return false;
std::string icon_name = CreateShortcutIcon(shortcut_info, shortcut_filename); std::string icon_name =CreateShortcutIcon(shortcut_info, shortcut_filename);
std::string app_name = std::string app_name =
web_app::GenerateApplicationNameFromInfo(shortcut_info); web_app::GenerateApplicationNameFromInfo(shortcut_info);
std::string contents = ShellIntegration::GetDesktopFileContents( std::string contents = ShellIntegrationLinux::GetDesktopFileContents(
shortcut_template, shortcut_template,
app_name, app_name,
shortcut_info.url, shortcut_info.url,
......
...@@ -11,9 +11,39 @@ ...@@ -11,9 +11,39 @@
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/file_path.h" #include "base/file_path.h"
#include "chrome/browser/shell_integration.h" #include "chrome/browser/shell_integration.h"
#include "googleurl/src/gurl.h"
namespace base {
class Environment;
}
namespace ShellIntegrationLinux { 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( bool CreateDesktopShortcutForChromeApp(
const ShellIntegration::ShortcutInfo& shortcut_info, const ShellIntegration::ShortcutInfo& shortcut_info,
const FilePath& web_app_path, const FilePath& web_app_path,
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "chrome/installer/util/browser_distribution.h" #include "chrome/installer/util/browser_distribution.h"
#elif defined(OS_POSIX) && !defined(OS_MACOSX) #elif defined(OS_POSIX) && !defined(OS_MACOSX)
#include "base/environment.h" #include "base/environment.h"
#include "chrome/browser/shell_integration_linux.h"
#endif #endif
#define FPL FILE_PATH_LITERAL #define FPL FILE_PATH_LITERAL
...@@ -92,8 +93,8 @@ TEST(ShellIntegrationTest, GetDesktopShortcutTemplate) { ...@@ -92,8 +93,8 @@ TEST(ShellIntegrationTest, GetDesktopShortcutTemplate) {
temp_dir.path().AppendASCII(kTemplateFilename), temp_dir.path().AppendASCII(kTemplateFilename),
kTestData1, strlen(kTestData1))); kTestData1, strlen(kTestData1)));
std::string contents; std::string contents;
ASSERT_TRUE(ShellIntegration::GetDesktopShortcutTemplate(&env, ASSERT_TRUE(ShellIntegrationLinux::GetDesktopShortcutTemplate(&env,
&contents)); &contents));
EXPECT_EQ(kTestData1, contents); EXPECT_EQ(kTestData1, contents);
} }
...@@ -110,8 +111,8 @@ TEST(ShellIntegrationTest, GetDesktopShortcutTemplate) { ...@@ -110,8 +111,8 @@ TEST(ShellIntegrationTest, GetDesktopShortcutTemplate) {
.AppendASCII(kTemplateFilename), .AppendASCII(kTemplateFilename),
kTestData2, strlen(kTestData2))); kTestData2, strlen(kTestData2)));
std::string contents; std::string contents;
ASSERT_TRUE(ShellIntegration::GetDesktopShortcutTemplate(&env, ASSERT_TRUE(ShellIntegrationLinux::GetDesktopShortcutTemplate(&env,
&contents)); &contents));
EXPECT_EQ(kTestData2, contents); EXPECT_EQ(kTestData2, contents);
} }
...@@ -132,8 +133,8 @@ TEST(ShellIntegrationTest, GetDesktopShortcutTemplate) { ...@@ -132,8 +133,8 @@ TEST(ShellIntegrationTest, GetDesktopShortcutTemplate) {
.AppendASCII(kTemplateFilename), .AppendASCII(kTemplateFilename),
kTestData2, strlen(kTestData2))); kTestData2, strlen(kTestData2)));
std::string contents; std::string contents;
ASSERT_TRUE(ShellIntegration::GetDesktopShortcutTemplate(&env, ASSERT_TRUE(ShellIntegrationLinux::GetDesktopShortcutTemplate(&env,
&contents)); &contents));
EXPECT_EQ(kTestData1, contents); EXPECT_EQ(kTestData1, contents);
} }
} }
...@@ -155,7 +156,7 @@ TEST(ShellIntegrationTest, GetDesktopShortcutFilename) { ...@@ -155,7 +156,7 @@ TEST(ShellIntegrationTest, GetDesktopShortcutFilename) {
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); i++) { for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); i++) {
EXPECT_EQ(std::string(chrome::kBrowserProcessExecutableName) + "-" + EXPECT_EQ(std::string(chrome::kBrowserProcessExecutableName) + "-" +
test_cases[i].path, test_cases[i].path,
ShellIntegration::GetDesktopShortcutFilename( ShellIntegrationLinux::GetDesktopShortcutFilename(
GURL(test_cases[i].url)).value()) << GURL(test_cases[i].url)).value()) <<
" while testing " << test_cases[i].url; " while testing " << test_cases[i].url;
} }
...@@ -352,7 +353,7 @@ TEST(ShellIntegrationTest, GetDesktopFileContents) { ...@@ -352,7 +353,7 @@ TEST(ShellIntegrationTest, GetDesktopFileContents) {
SCOPED_TRACE(i); SCOPED_TRACE(i);
EXPECT_EQ( EXPECT_EQ(
test_cases[i].expected_output, test_cases[i].expected_output,
ShellIntegration::GetDesktopFileContents( ShellIntegrationLinux::GetDesktopFileContents(
test_cases[i].template_contents, test_cases[i].template_contents,
web_app::GenerateApplicationNameFromURL(GURL(test_cases[i].url)), web_app::GenerateApplicationNameFromURL(GURL(test_cases[i].url)),
GURL(test_cases[i].url), GURL(test_cases[i].url),
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/utf_string_conversions.h" #include "base/utf_string_conversions.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/shell_integration.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/gtk/gtk_util.h"
#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
#include "chrome/browser/ui/web_applications/web_app_ui.h" #include "chrome/browser/ui/web_applications/web_app_ui.h"
...@@ -219,10 +220,10 @@ void CreateApplicationShortcutsDialogGtk::CreateDesktopShortcut( ...@@ -219,10 +220,10 @@ void CreateApplicationShortcutsDialogGtk::CreateDesktopShortcut(
scoped_ptr<base::Environment> env(base::Environment::Create()); scoped_ptr<base::Environment> env(base::Environment::Create());
std::string shortcut_template; std::string shortcut_template;
if (ShellIntegration::GetDesktopShortcutTemplate(env.get(), if (ShellIntegrationLinux::GetDesktopShortcutTemplate(env.get(),
&shortcut_template)) { &shortcut_template)) {
ShellIntegration::CreateDesktopShortcut(shortcut_info, ShellIntegrationLinux::CreateDesktopShortcut(shortcut_info,
shortcut_template); shortcut_template);
Release(); Release();
} else { } else {
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 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 // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include "base/environment.h" #include "base/environment.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "chrome/browser/shell_integration.h" #include "chrome/browser/shell_integration_linux.h"
// Unity data typedefs. // Unity data typedefs.
typedef struct _UnityInspector UnityInspector; typedef struct _UnityInspector UnityInspector;
...@@ -77,7 +77,7 @@ void EnsureMethodsLoaded() { ...@@ -77,7 +77,7 @@ void EnsureMethodsLoaded() {
dlsym(unity_lib, "unity_launcher_entry_get_for_desktop_id")); dlsym(unity_lib, "unity_launcher_entry_get_for_desktop_id"));
if (entry_get_for_desktop_id) { if (entry_get_for_desktop_id) {
scoped_ptr<base::Environment> env(base::Environment::Create()); 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()); chrome_entry = entry_get_for_desktop_id(desktop_id.c_str());
entry_set_count = entry_set_count =
......
...@@ -21,8 +21,8 @@ bool CreatePlatformShortcut( ...@@ -21,8 +21,8 @@ bool CreatePlatformShortcut(
scoped_ptr<base::Environment> env(base::Environment::Create()); scoped_ptr<base::Environment> env(base::Environment::Create());
std::string shortcut_template; std::string shortcut_template;
if (!ShellIntegration::GetDesktopShortcutTemplate(env.get(), if (!ShellIntegrationLinux::GetDesktopShortcutTemplate(env.get(),
&shortcut_template)) { &shortcut_template)) {
return false; return false;
} }
return ShellIntegrationLinux::CreateDesktopShortcutForChromeApp( 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