| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #if !defined(OS_CHROMEOS) | 5 #if !defined(OS_CHROMEOS) |
| 6 | 6 |
| 7 #include "chrome/browser/ui/webui/options/advanced_options_utils.h" | 7 #include "chrome/browser/ui/webui/options/advanced_options_utils.h" |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/environment.h" | 10 #include "base/environment.h" |
| 11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
| 12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
| 13 #include "base/nix/xdg_util.h" | 13 #include "base/nix/xdg_util.h" |
| 14 #include "base/process_util.h" | 14 #include "base/process_util.h" |
| 15 #include "base/string_util.h" | 15 #include "base/string_util.h" |
| 16 #include "content/browser/tab_contents/tab_contents.h" | |
| 17 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 17 #include "content/public/browser/web_contents.h" |
| 18 | 18 |
| 19 using content::BrowserThread; | 19 using content::BrowserThread; |
| 20 using content::OpenURLParams; | 20 using content::OpenURLParams; |
| 21 using content::Referrer; | 21 using content::Referrer; |
| 22 using content::WebContents; |
| 22 | 23 |
| 23 // Command used to configure GNOME 2 proxy settings. | 24 // Command used to configure GNOME 2 proxy settings. |
| 24 const char* kGNOME2ProxyConfigCommand[] = {"gnome-network-properties", NULL}; | 25 const char* kGNOME2ProxyConfigCommand[] = {"gnome-network-properties", NULL}; |
| 25 // In GNOME 3, we might need to run gnome-control-center instead. We try this | 26 // In GNOME 3, we might need to run gnome-control-center instead. We try this |
| 26 // only after gnome-network-properties is not found, because older GNOME also | 27 // only after gnome-network-properties is not found, because older GNOME also |
| 27 // has this but it doesn't do the same thing. See below where we use it. | 28 // has this but it doesn't do the same thing. See below where we use it. |
| 28 const char* kGNOME3ProxyConfigCommand[] = {"gnome-control-center", "network", | 29 const char* kGNOME3ProxyConfigCommand[] = {"gnome-control-center", "network", |
| 29 NULL}; | 30 NULL}; |
| 30 // KDE3 and KDE4 are only slightly different, but incompatible. Go figure. | 31 // KDE3 and KDE4 are only slightly different, but incompatible. Go figure. |
| 31 const char* kKDE3ProxyConfigCommand[] = {"kcmshell", "proxy", NULL}; | 32 const char* kKDE3ProxyConfigCommand[] = {"kcmshell", "proxy", NULL}; |
| 32 const char* kKDE4ProxyConfigCommand[] = {"kcmshell4", "proxy", NULL}; | 33 const char* kKDE4ProxyConfigCommand[] = {"kcmshell4", "proxy", NULL}; |
| 33 | 34 |
| 34 // The URL for Linux proxy configuration help when not running under a | 35 // The URL for Linux proxy configuration help when not running under a |
| 35 // supported desktop environment. | 36 // supported desktop environment. |
| 36 const char kLinuxProxyConfigUrl[] = "about:linux-proxy-config"; | 37 const char kLinuxProxyConfigUrl[] = "about:linux-proxy-config"; |
| 37 | 38 |
| 38 namespace { | 39 namespace { |
| 39 | 40 |
| 40 // Show the proxy config URL in the given tab. | 41 // Show the proxy config URL in the given tab. |
| 41 void ShowLinuxProxyConfigUrl(TabContents* tab_contents) { | 42 void ShowLinuxProxyConfigUrl(WebContents* web_contents) { |
| 42 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 43 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 43 scoped_ptr<base::Environment> env(base::Environment::Create()); | 44 scoped_ptr<base::Environment> env(base::Environment::Create()); |
| 44 const char* name = base::nix::GetDesktopEnvironmentName(env.get()); | 45 const char* name = base::nix::GetDesktopEnvironmentName(env.get()); |
| 45 if (name) | 46 if (name) |
| 46 LOG(ERROR) << "Could not find " << name << " network settings in $PATH"; | 47 LOG(ERROR) << "Could not find " << name << " network settings in $PATH"; |
| 47 OpenURLParams params( | 48 OpenURLParams params( |
| 48 GURL(kLinuxProxyConfigUrl), Referrer(), NEW_FOREGROUND_TAB, | 49 GURL(kLinuxProxyConfigUrl), Referrer(), NEW_FOREGROUND_TAB, |
| 49 content::PAGE_TRANSITION_LINK, false); | 50 content::PAGE_TRANSITION_LINK, false); |
| 50 tab_contents->OpenURL(params); | 51 web_contents->OpenURL(params); |
| 51 } | 52 } |
| 52 | 53 |
| 53 // Start the given proxy configuration utility. | 54 // Start the given proxy configuration utility. |
| 54 bool StartProxyConfigUtil(TabContents* tab_contents, const char* command[]) { | 55 bool StartProxyConfigUtil(WebContents* web_contents, const char* command[]) { |
| 55 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 56 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 56 // base::LaunchProcess() returns true ("success") if the fork() | 57 // base::LaunchProcess() returns true ("success") if the fork() |
| 57 // succeeds, but not necessarily the exec(). We'd like to be able to | 58 // succeeds, but not necessarily the exec(). We'd like to be able to |
| 58 // use StartProxyConfigUtil() to search possible options and stop on | 59 // use StartProxyConfigUtil() to search possible options and stop on |
| 59 // success, so we search $PATH first to predict whether the exec is | 60 // success, so we search $PATH first to predict whether the exec is |
| 60 // expected to succeed. | 61 // expected to succeed. |
| 61 // TODO(mdm): this is a useful check, and is very similar to some | 62 // TODO(mdm): this is a useful check, and is very similar to some |
| 62 // code in proxy_config_service_linux.cc. It should probably be in | 63 // code in proxy_config_service_linux.cc. It should probably be in |
| 63 // base:: somewhere. | 64 // base:: somewhere. |
| 64 scoped_ptr<base::Environment> env(base::Environment::Create()); | 65 scoped_ptr<base::Environment> env(base::Environment::Create()); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 86 if (!base::LaunchProcess(argv, base::LaunchOptions(), &handle)) { | 87 if (!base::LaunchProcess(argv, base::LaunchOptions(), &handle)) { |
| 87 LOG(ERROR) << "StartProxyConfigUtil failed to start " << command[0]; | 88 LOG(ERROR) << "StartProxyConfigUtil failed to start " << command[0]; |
| 88 return false; | 89 return false; |
| 89 } | 90 } |
| 90 base::EnsureProcessGetsReaped(handle); | 91 base::EnsureProcessGetsReaped(handle); |
| 91 return true; | 92 return true; |
| 92 } | 93 } |
| 93 | 94 |
| 94 // Detect, and if possible, start the appropriate proxy config utility. On | 95 // Detect, and if possible, start the appropriate proxy config utility. On |
| 95 // failure to do so, show the Linux proxy config URL in a new tab instead. | 96 // failure to do so, show the Linux proxy config URL in a new tab instead. |
| 96 void DetectAndStartProxyConfigUtil(TabContents* tab_contents) { | 97 void DetectAndStartProxyConfigUtil(WebContents* web_contents) { |
| 97 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 98 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 98 scoped_ptr<base::Environment> env(base::Environment::Create()); | 99 scoped_ptr<base::Environment> env(base::Environment::Create()); |
| 99 | 100 |
| 100 bool launched = false; | 101 bool launched = false; |
| 101 switch (base::nix::GetDesktopEnvironment(env.get())) { | 102 switch (base::nix::GetDesktopEnvironment(env.get())) { |
| 102 case base::nix::DESKTOP_ENVIRONMENT_GNOME: { | 103 case base::nix::DESKTOP_ENVIRONMENT_GNOME: { |
| 103 launched = StartProxyConfigUtil(tab_contents, kGNOME2ProxyConfigCommand); | 104 launched = StartProxyConfigUtil(web_contents, kGNOME2ProxyConfigCommand); |
| 104 if (!launched) { | 105 if (!launched) { |
| 105 // We try this second, even though it's the newer way, because this | 106 // We try this second, even though it's the newer way, because this |
| 106 // command existed in older versions of GNOME, but it didn't do the | 107 // command existed in older versions of GNOME, but it didn't do the |
| 107 // same thing. The older command is gone though, so this should do | 108 // same thing. The older command is gone though, so this should do |
| 108 // the right thing. (Also some distributions have blurred the lines | 109 // the right thing. (Also some distributions have blurred the lines |
| 109 // between GNOME 2 and 3, so we can't necessarily detect what the | 110 // between GNOME 2 and 3, so we can't necessarily detect what the |
| 110 // right thing is based on indications of which version we have.) | 111 // right thing is based on indications of which version we have.) |
| 111 launched = StartProxyConfigUtil(tab_contents, | 112 launched = StartProxyConfigUtil(web_contents, |
| 112 kGNOME3ProxyConfigCommand); | 113 kGNOME3ProxyConfigCommand); |
| 113 } | 114 } |
| 114 break; | 115 break; |
| 115 } | 116 } |
| 116 | 117 |
| 117 case base::nix::DESKTOP_ENVIRONMENT_KDE3: | 118 case base::nix::DESKTOP_ENVIRONMENT_KDE3: |
| 118 launched = StartProxyConfigUtil(tab_contents, kKDE3ProxyConfigCommand); | 119 launched = StartProxyConfigUtil(web_contents, kKDE3ProxyConfigCommand); |
| 119 break; | 120 break; |
| 120 | 121 |
| 121 case base::nix::DESKTOP_ENVIRONMENT_KDE4: | 122 case base::nix::DESKTOP_ENVIRONMENT_KDE4: |
| 122 launched = StartProxyConfigUtil(tab_contents, kKDE4ProxyConfigCommand); | 123 launched = StartProxyConfigUtil(web_contents, kKDE4ProxyConfigCommand); |
| 123 break; | 124 break; |
| 124 | 125 |
| 125 case base::nix::DESKTOP_ENVIRONMENT_XFCE: | 126 case base::nix::DESKTOP_ENVIRONMENT_XFCE: |
| 126 case base::nix::DESKTOP_ENVIRONMENT_OTHER: | 127 case base::nix::DESKTOP_ENVIRONMENT_OTHER: |
| 127 break; | 128 break; |
| 128 } | 129 } |
| 129 | 130 |
| 130 if (launched) | 131 if (launched) |
| 131 return; | 132 return; |
| 132 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 133 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 133 base::Bind(&ShowLinuxProxyConfigUrl, tab_contents)); | 134 base::Bind(&ShowLinuxProxyConfigUrl, web_contents)); |
| 134 } | 135 } |
| 135 | 136 |
| 136 } // anonymous namespace | 137 } // anonymous namespace |
| 137 | 138 |
| 138 void AdvancedOptionsUtilities::ShowNetworkProxySettings( | 139 void AdvancedOptionsUtilities::ShowNetworkProxySettings( |
| 139 TabContents* tab_contents) { | 140 WebContents* web_contents) { |
| 140 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 141 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 141 base::Bind(&DetectAndStartProxyConfigUtil, tab_contents)); | 142 base::Bind(&DetectAndStartProxyConfigUtil, web_contents)); |
| 142 } | 143 } |
| 143 | 144 |
| 144 #endif // !defined(OS_CHROMEOS) | 145 #endif // !defined(OS_CHROMEOS) |
| OLD | NEW |