This source file includes following definitions.
- ShowLinuxProxyConfigUrl
- StartProxyConfigUtil
- DetectAndStartProxyConfigUtil
- ShowNetworkProxySettings
#if !defined(OS_CHROMEOS)
#include "chrome/browser/ui/webui/options/advanced_options_utils.h"
#include "base/bind.h"
#include "base/environment.h"
#include "base/file_util.h"
#include "base/files/file_path.h"
#include "base/nix/xdg_util.h"
#include "base/process/launch.h"
#include "base/strings/string_util.h"
#include "chrome/browser/tab_contents/tab_util.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
using content::BrowserThread;
using content::OpenURLParams;
using content::Referrer;
using content::WebContents;
namespace options {
const char* kGNOME2ProxyConfigCommand[] = {"gnome-network-properties", NULL};
const char* kGNOME3ProxyConfigCommand[] = {"gnome-control-center", "network",
NULL};
const char* kKDE3ProxyConfigCommand[] = {"kcmshell", "proxy", NULL};
const char* kKDE4ProxyConfigCommand[] = {"kcmshell4", "proxy", NULL};
const char kLinuxProxyConfigUrl[] = "about:linux-proxy-config";
namespace {
void ShowLinuxProxyConfigUrl(int render_process_id, int render_view_id) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
scoped_ptr<base::Environment> env(base::Environment::Create());
const char* name = base::nix::GetDesktopEnvironmentName(env.get());
if (name)
LOG(ERROR) << "Could not find " << name << " network settings in $PATH";
OpenURLParams params(
GURL(kLinuxProxyConfigUrl), Referrer(), NEW_FOREGROUND_TAB,
content::PAGE_TRANSITION_LINK, false);
WebContents* web_contents =
tab_util::GetWebContentsByID(render_process_id, render_view_id);
if (web_contents)
web_contents->OpenURL(params);
}
bool StartProxyConfigUtil(const char* command[]) {
DCHECK_CURRENTLY_ON(BrowserThread::FILE);
scoped_ptr<base::Environment> env(base::Environment::Create());
std::string path;
if (!env->GetVar("PATH", &path)) {
LOG(ERROR) << "No $PATH variable. Assuming no " << command[0] << ".";
return false;
}
std::vector<std::string> paths;
Tokenize(path, ":", &paths);
bool found = false;
for (size_t i = 0; i < paths.size(); ++i) {
base::FilePath file(paths[i]);
if (base::PathExists(file.Append(command[0]))) {
found = true;
break;
}
}
if (!found)
return false;
std::vector<std::string> argv;
for (size_t i = 0; command[i]; ++i)
argv.push_back(command[i]);
base::ProcessHandle handle;
if (!base::LaunchProcess(argv, base::LaunchOptions(), &handle)) {
LOG(ERROR) << "StartProxyConfigUtil failed to start " << command[0];
return false;
}
base::EnsureProcessGetsReaped(handle);
return true;
}
void DetectAndStartProxyConfigUtil(int render_process_id,
int render_view_id) {
DCHECK_CURRENTLY_ON(BrowserThread::FILE);
scoped_ptr<base::Environment> env(base::Environment::Create());
bool launched = false;
switch (base::nix::GetDesktopEnvironment(env.get())) {
case base::nix::DESKTOP_ENVIRONMENT_GNOME:
case base::nix::DESKTOP_ENVIRONMENT_UNITY: {
launched = StartProxyConfigUtil(kGNOME2ProxyConfigCommand);
if (!launched) {
launched = StartProxyConfigUtil(kGNOME3ProxyConfigCommand);
}
break;
}
case base::nix::DESKTOP_ENVIRONMENT_KDE3:
launched = StartProxyConfigUtil(kKDE3ProxyConfigCommand);
break;
case base::nix::DESKTOP_ENVIRONMENT_KDE4:
launched = StartProxyConfigUtil(kKDE4ProxyConfigCommand);
break;
case base::nix::DESKTOP_ENVIRONMENT_XFCE:
case base::nix::DESKTOP_ENVIRONMENT_OTHER:
break;
}
if (launched)
return;
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
base::Bind(&ShowLinuxProxyConfigUrl, render_process_id, render_view_id));
}
}
void AdvancedOptionsUtilities::ShowNetworkProxySettings(
WebContents* web_contents) {
BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
base::Bind(&DetectAndStartProxyConfigUtil,
web_contents->GetRenderProcessHost()->GetID(),
web_contents->GetRenderViewHost()->GetRoutingID()));
}
}
#endif