summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormdm@chromium.org <mdm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-20 23:14:57 +0000
committermdm@chromium.org <mdm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-20 23:14:57 +0000
commitc85cfbd98c6bf26e730fdd15538c624cb52352e9 (patch)
tree55c7af76f8cfcd1cccee33ebdc5e087543d938fc
parent11783f0ab7285b59c4fd40c42bbbf74fcea916e4 (diff)
downloadchromium_src-c85cfbd98c6bf26e730fdd15538c624cb52352e9.zip
chromium_src-c85cfbd98c6bf26e730fdd15538c624cb52352e9.tar.gz
chromium_src-c85cfbd98c6bf26e730fdd15538c624cb52352e9.tar.bz2
Linux: make the "change proxy settings" button able to start several proxy config utilities.
Currently it still only ever starts gnome-network-properties but it is now easy to update. BUG=none TEST=none Review URL: http://codereview.chromium.org/174106 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23910 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--base/linux_util.cc28
-rw-r--r--base/linux_util.h11
-rw-r--r--chrome/browser/gtk/options/advanced_contents_gtk.cc134
-rw-r--r--net/proxy/proxy_config_service_linux.cc3
4 files changed, 124 insertions, 52 deletions
diff --git a/base/linux_util.cc b/base/linux_util.cc
index 259899f..7bdab94 100644
--- a/base/linux_util.cc
+++ b/base/linux_util.cc
@@ -104,8 +104,10 @@ DesktopEnvironment GetDesktopEnvironment(EnvironmentVariableGetter* env) {
if (env->Getenv("DESKTOP_SESSION", &desktop_session)) {
if (desktop_session == "gnome")
return DESKTOP_ENVIRONMENT_GNOME;
- else if (desktop_session.substr(3) == "kde") // kde3 or kde4
- return DESKTOP_ENVIRONMENT_KDE;
+ else if (desktop_session == "kde4")
+ return DESKTOP_ENVIRONMENT_KDE4;
+ else if (desktop_session == "kde")
+ return DESKTOP_ENVIRONMENT_KDE3;
}
// Fall back on some older environment variables.
@@ -114,10 +116,30 @@ DesktopEnvironment GetDesktopEnvironment(EnvironmentVariableGetter* env) {
if (env->Getenv("GNOME_DESKTOP_SESSION_ID", &dummy)) {
return DESKTOP_ENVIRONMENT_GNOME;
} else if (env->Getenv("KDE_FULL_SESSION", &dummy)) {
- return DESKTOP_ENVIRONMENT_KDE;
+ if (env->Getenv("KDE_SESSION_VERSION", &dummy))
+ return DESKTOP_ENVIRONMENT_KDE4;
+ return DESKTOP_ENVIRONMENT_KDE3;
}
return DESKTOP_ENVIRONMENT_OTHER;
}
+const char* GetDesktopEnvironmentName(DesktopEnvironment env) {
+ switch (env) {
+ case DESKTOP_ENVIRONMENT_OTHER:
+ return NULL;
+ case DESKTOP_ENVIRONMENT_GNOME:
+ return "GNOME";
+ case DESKTOP_ENVIRONMENT_KDE3:
+ return "KDE3";
+ case DESKTOP_ENVIRONMENT_KDE4:
+ return "KDE4";
+ }
+ return NULL;
+}
+
+const char* GetDesktopEnvironmentName(EnvironmentVariableGetter* env) {
+ return GetDesktopEnvironmentName(GetDesktopEnvironment(env));
+}
+
} // namespace base
diff --git a/base/linux_util.h b/base/linux_util.h
index 693377c..4cfa9da 100644
--- a/base/linux_util.h
+++ b/base/linux_util.h
@@ -35,7 +35,10 @@ class EnvironmentVariableGetter {
enum DesktopEnvironment {
DESKTOP_ENVIRONMENT_OTHER,
DESKTOP_ENVIRONMENT_GNOME,
- DESKTOP_ENVIRONMENT_KDE,
+ // KDE3 and KDE4 are sufficiently different that we count
+ // them as two different desktop environments here.
+ DESKTOP_ENVIRONMENT_KDE3,
+ DESKTOP_ENVIRONMENT_KDE4,
};
// Return an entry from the DesktopEnvironment enum with a best guess
@@ -44,6 +47,12 @@ enum DesktopEnvironment {
// proxy settings, password manager, etc.
DesktopEnvironment GetDesktopEnvironment(EnvironmentVariableGetter* env);
+// Return a string representation of the given desktop environment.
+// May return NULL in the case of DESKTOP_ENVIRONMENT_OTHER.
+const char* GetDesktopEnvironmentName(DesktopEnvironment env);
+// Convenience wrapper that calls GetDesktopEnvironment() first.
+const char* GetDesktopEnvironmentName(EnvironmentVariableGetter* env);
+
} // namespace base
#endif // BASE_LINUX_UTIL_H__
diff --git a/chrome/browser/gtk/options/advanced_contents_gtk.cc b/chrome/browser/gtk/options/advanced_contents_gtk.cc
index 416c925..f6b6568 100644
--- a/chrome/browser/gtk/options/advanced_contents_gtk.cc
+++ b/chrome/browser/gtk/options/advanced_contents_gtk.cc
@@ -38,10 +38,13 @@
namespace {
-// Command used to configure the gconf proxy settings. The command was renamed
+// Command used to configure GNOME proxy settings. The command was renamed
// in January 2009, so both are used to work on both old and new systems.
-const char kOldProxyConfigBinary[] = "gnome-network-preferences";
-const char kProxyConfigBinary[] = "gnome-network-properties";
+const char* kOldGNOMEProxyConfigCommand[] = {"gnome-network-preferences", NULL};
+const char* kGNOMEProxyConfigCommand[] = {"gnome-network-properties", NULL};
+// KDE3 and KDE4 are only slightly different, but incompatible. Go figure.
+// const char* kKDE3ProxyConfigCommand[] = {"kcmshell", "proxy", NULL};
+// const char* kKDE4ProxyConfigCommand[] = {"kcmshell4", "proxy", NULL};
// The pixel width we wrap labels at.
// TODO(evanm): make the labels wrap at the appropriate width.
@@ -311,9 +314,19 @@ class NetworkSection : public OptionsPageBase {
}
private:
+ struct ProxyConfigCommand {
+ std::string binary;
+ const char** argv;
+ };
// The callback functions for invoking the proxy config dialog.
static void OnChangeProxiesButtonClicked(GtkButton *button,
NetworkSection* section);
+ // Search $PATH to find one of the commands. Store the full path to
+ // it in the |binary| field and the command array index in in |index|.
+ static bool SearchPATH(ProxyConfigCommand* commands, size_t ncommands,
+ size_t* index);
+ // Start the given proxy configuration utility.
+ static void StartProxyConfigUtil(const ProxyConfigCommand& command);
// The widget containing the options for this section.
GtkWidget* page_;
@@ -354,59 +367,86 @@ void NetworkSection::OnChangeProxiesButtonClicked(GtkButton *button,
scoped_ptr<base::EnvironmentVariableGetter> env_getter(
base::EnvironmentVariableGetter::Create());
+ ProxyConfigCommand command;
+ bool found_command = false;
switch (base::GetDesktopEnvironment(env_getter.get())) {
case base::DESKTOP_ENVIRONMENT_GNOME: {
- const char* path = getenv("PATH");
- FilePath bin_path;
- bool have_bin_path = false;
- StringTokenizer tk(path, ":");
- while (tk.GetNext()) {
- bin_path = FilePath(tk.token()).Append(kProxyConfigBinary);
- if (file_util::PathExists(bin_path)) {
- have_bin_path = true;
- break;
- }
- bin_path = FilePath(tk.token()).Append(kOldProxyConfigBinary);
- if (file_util::PathExists(bin_path)) {
- have_bin_path = true;
- break;
- }
- }
- if (!have_bin_path) {
- LOG(ERROR) << "Could not find Gnome network settings in PATH";
- BrowserList::GetLastActive()->
- OpenURL(GURL(l10n_util::GetStringUTF8(IDS_LINUX_PROXY_CONFIG_URL)),
- GURL(), NEW_FOREGROUND_TAB, PageTransition::LINK);
- return;
- }
- std::vector<std::string> argv;
- argv.push_back(bin_path.value());
- base::file_handle_mapping_vector no_files;
- base::environment_vector env;
- base::ProcessHandle handle;
- env.push_back(std::make_pair("GTK_PATH",
- getenv("CHROMIUM_SAVED_GTK_PATH")));
- if (!base::LaunchApp(argv, env, no_files, false, &handle)) {
- LOG(ERROR) << "OpenProxyConfigDialogTask failed";
- BrowserList::GetLastActive()->
- OpenURL(GURL(l10n_util::GetStringUTF8(IDS_LINUX_PROXY_CONFIG_URL)),
- GURL(), NEW_FOREGROUND_TAB, PageTransition::LINK);
- return;
- }
- ProcessWatcher::EnsureProcessGetsReaped(handle);
+ size_t index;
+ ProxyConfigCommand commands[2];
+ commands[0].argv = kGNOMEProxyConfigCommand;
+ commands[1].argv = kOldGNOMEProxyConfigCommand;
+ found_command = SearchPATH(commands, 2, &index);
+ if (found_command)
+ command = commands[index];
break;
}
- case base::DESKTOP_ENVIRONMENT_KDE:
- NOTIMPLEMENTED() << "Bug 17363: obey KDE proxy settings.";
- // Fall through to default behavior for now.
+ case base::DESKTOP_ENVIRONMENT_KDE3:
+ // command.argv = kKDE3ProxyConfigCommand;
+ // found_command = SearchPATH(&command, 1, NULL);
+ break;
+
+ case base::DESKTOP_ENVIRONMENT_KDE4:
+ // command.argv = kKDE4ProxyConfigCommand;
+ // found_command = SearchPATH(&command, 1, NULL);
+ break;
case base::DESKTOP_ENVIRONMENT_OTHER:
- BrowserList::GetLastActive()->
- OpenURL(GURL(l10n_util::GetStringUTF8(IDS_LINUX_PROXY_CONFIG_URL)),
- GURL(), NEW_FOREGROUND_TAB, PageTransition::LINK);
break;
}
+
+ if (found_command) {
+ StartProxyConfigUtil(command);
+ } else {
+ const char* name = base::GetDesktopEnvironmentName(env_getter.get());
+ if (name)
+ LOG(ERROR) << "Could not find " << name << " network settings in $PATH";
+ BrowserList::GetLastActive()->
+ OpenURL(GURL(l10n_util::GetStringUTF8(IDS_LINUX_PROXY_CONFIG_URL)),
+ GURL(), NEW_FOREGROUND_TAB, PageTransition::LINK);
+ }
+}
+
+// static
+bool NetworkSection::SearchPATH(ProxyConfigCommand* commands, size_t ncommands,
+ size_t* index) {
+ const char* path = getenv("PATH");
+ FilePath bin_path;
+ StringTokenizer tk(path, ":");
+ // Search $PATH looking for the commands in order.
+ while (tk.GetNext()) {
+ for (size_t i = 0; i < ncommands; i++) {
+ bin_path = FilePath(tk.token()).Append(commands[i].argv[0]);
+ if (file_util::PathExists(bin_path)) {
+ commands[i].binary = bin_path.value();
+ if (index)
+ *index = i;
+ return true;
+ }
+ }
+ }
+ // Did not find any of the binaries in $PATH.
+ return false;
+}
+
+// static
+void NetworkSection::StartProxyConfigUtil(const ProxyConfigCommand& command) {
+ std::vector<std::string> argv;
+ argv.push_back(command.binary);
+ for (size_t i = 1; command.argv[i]; i++)
+ argv.push_back(command.argv[i]);
+ base::file_handle_mapping_vector no_files;
+ base::environment_vector env;
+ base::ProcessHandle handle;
+ env.push_back(std::make_pair("GTK_PATH", getenv("CHROMIUM_SAVED_GTK_PATH")));
+ if (!base::LaunchApp(argv, env, no_files, false, &handle)) {
+ LOG(ERROR) << "StartProxyConfigUtil failed to start " << command.binary;
+ BrowserList::GetLastActive()->
+ OpenURL(GURL(l10n_util::GetStringUTF8(IDS_LINUX_PROXY_CONFIG_URL)),
+ GURL(), NEW_FOREGROUND_TAB, PageTransition::LINK);
+ return;
+ }
+ ProcessWatcher::EnsureProcessGetsReaped(handle);
}
///////////////////////////////////////////////////////////////////////////////
diff --git a/net/proxy/proxy_config_service_linux.cc b/net/proxy/proxy_config_service_linux.cc
index 855c6a4..2998a0c 100644
--- a/net/proxy/proxy_config_service_linux.cc
+++ b/net/proxy/proxy_config_service_linux.cc
@@ -554,7 +554,8 @@ void ProxyConfigServiceLinux::Delegate::SetupAndFetchInitialConfig(
}
break;
- case base::DESKTOP_ENVIRONMENT_KDE:
+ case base::DESKTOP_ENVIRONMENT_KDE3:
+ case base::DESKTOP_ENVIRONMENT_KDE4:
NOTIMPLEMENTED() << "Bug 17363: obey KDE proxy settings.";
break;