OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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) | |
6 | |
7 #include "chrome/browser/ui/webui/settings_utils.h" | 5 #include "chrome/browser/ui/webui/settings_utils.h" |
8 | 6 |
9 #include <stddef.h> | 7 #include <stddef.h> |
10 | 8 |
11 #include "base/bind.h" | 9 #include "base/bind.h" |
12 #include "base/environment.h" | 10 #include "base/environment.h" |
13 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
14 #include "base/nix/xdg_util.h" | 12 #include "base/nix/xdg_util.h" |
15 #include "base/process/launch.h" | 13 #include "base/process/launch.h" |
16 #include "build/build_config.h" | 14 #include "build/build_config.h" |
17 #include "chrome/browser/tab_contents/tab_util.h" | 15 #include "chrome/browser/tab_contents/tab_util.h" |
18 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
19 #include "content/public/browser/render_process_host.h" | 17 #include "content/public/browser/render_process_host.h" |
20 #include "content/public/browser/render_view_host.h" | 18 #include "content/public/browser/render_view_host.h" |
21 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
22 | 20 |
23 using content::BrowserThread; | 21 using content::BrowserThread; |
24 using content::OpenURLParams; | 22 using content::OpenURLParams; |
25 using content::Referrer; | 23 using content::Referrer; |
26 | 24 |
27 namespace settings_utils { | 25 namespace { |
28 | 26 |
29 // Command used to configure GNOME 2 proxy settings. | 27 // Command used to configure GNOME 2 proxy settings. |
30 const char* kGNOME2ProxyConfigCommand[] = {"gnome-network-properties", NULL}; | 28 const char* const kGNOME2ProxyConfigCommand[] = {"gnome-network-properties", |
| 29 nullptr}; |
31 // In GNOME 3, we might need to run gnome-control-center instead. We try this | 30 // In GNOME 3, we might need to run gnome-control-center instead. We try this |
32 // only after gnome-network-properties is not found, because older GNOME also | 31 // only after gnome-network-properties is not found, because older GNOME also |
33 // has this but it doesn't do the same thing. See below where we use it. | 32 // has this but it doesn't do the same thing. See below where we use it. |
34 const char* kGNOME3ProxyConfigCommand[] = {"gnome-control-center", "network", | 33 const char* const kGNOME3ProxyConfigCommand[] = {"gnome-control-center", |
35 NULL}; | 34 "network", nullptr}; |
36 // KDE3, 4, and 5 are only slightly different, but incompatible. Go figure. | 35 // KDE3, 4, and 5 are only slightly different, but incompatible. Go figure. |
37 const char* kKDE3ProxyConfigCommand[] = {"kcmshell", "proxy", NULL}; | 36 const char* const kKDE3ProxyConfigCommand[] = {"kcmshell", "proxy", nullptr}; |
38 const char* kKDE4ProxyConfigCommand[] = {"kcmshell4", "proxy", NULL}; | 37 const char* const kKDE4ProxyConfigCommand[] = {"kcmshell4", "proxy", nullptr}; |
39 const char* kKDE5ProxyConfigCommand[] = {"kcmshell5", "proxy", NULL}; | 38 const char* const kKDE5ProxyConfigCommand[] = {"kcmshell5", "proxy", nullptr}; |
40 | 39 |
41 // The URL for Linux proxy configuration help when not running under a | 40 // The URL for Linux proxy configuration help when not running under a |
42 // supported desktop environment. | 41 // supported desktop environment. |
43 const char kLinuxProxyConfigUrl[] = "about:linux-proxy-config"; | 42 const char kLinuxProxyConfigUrl[] = "about:linux-proxy-config"; |
44 | 43 |
45 namespace { | |
46 | |
47 // Show the proxy config URL in the given tab. | 44 // Show the proxy config URL in the given tab. |
48 void ShowLinuxProxyConfigUrl(int render_process_id, int render_view_id) { | 45 void ShowLinuxProxyConfigUrl(int render_process_id, int render_view_id) { |
49 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 46 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
50 std::unique_ptr<base::Environment> env(base::Environment::Create()); | 47 std::unique_ptr<base::Environment> env(base::Environment::Create()); |
51 const char* name = base::nix::GetDesktopEnvironmentName(env.get()); | 48 const char* name = base::nix::GetDesktopEnvironmentName(env.get()); |
52 if (name) | 49 if (name) |
53 LOG(ERROR) << "Could not find " << name << " network settings in $PATH"; | 50 LOG(ERROR) << "Could not find " << name << " network settings in $PATH"; |
54 OpenURLParams params( | 51 OpenURLParams params( |
55 GURL(kLinuxProxyConfigUrl), Referrer(), NEW_FOREGROUND_TAB, | 52 GURL(kLinuxProxyConfigUrl), Referrer(), NEW_FOREGROUND_TAB, |
56 ui::PAGE_TRANSITION_LINK, false); | 53 ui::PAGE_TRANSITION_LINK, false); |
57 | 54 |
58 content::WebContents* web_contents = | 55 content::WebContents* web_contents = |
59 tab_util::GetWebContentsByID(render_process_id, render_view_id); | 56 tab_util::GetWebContentsByID(render_process_id, render_view_id); |
60 if (web_contents) | 57 if (web_contents) |
61 web_contents->OpenURL(params); | 58 web_contents->OpenURL(params); |
62 } | 59 } |
63 | 60 |
64 // Start the given proxy configuration utility. | 61 // Start the given proxy configuration utility. |
65 bool StartProxyConfigUtil(const char* command[]) { | 62 bool StartProxyConfigUtil(const char* const command[]) { |
66 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 63 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
67 // base::LaunchProcess() returns true ("success") if the fork() | 64 // base::LaunchProcess() returns true ("success") if the fork() |
68 // succeeds, but not necessarily the exec(). We'd like to be able to | 65 // succeeds, but not necessarily the exec(). We'd like to be able to |
69 // use StartProxyConfigUtil() to search possible options and stop on | 66 // use StartProxyConfigUtil() to search possible options and stop on |
70 // success, so we search $PATH first to predict whether the exec is | 67 // success, so we search $PATH first to predict whether the exec is |
71 // expected to succeed. | 68 // expected to succeed. |
72 std::unique_ptr<base::Environment> env(base::Environment::Create()); | 69 std::unique_ptr<base::Environment> env(base::Environment::Create()); |
73 if (!base::ExecutableExistsInPath(env.get(), command[0])) | 70 if (!base::ExecutableExistsInPath(env.get(), command[0])) |
74 return false; | 71 return false; |
75 | 72 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 case base::nix::DESKTOP_ENVIRONMENT_OTHER: | 122 case base::nix::DESKTOP_ENVIRONMENT_OTHER: |
126 break; | 123 break; |
127 } | 124 } |
128 | 125 |
129 if (launched) | 126 if (launched) |
130 return; | 127 return; |
131 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 128 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
132 base::Bind(&ShowLinuxProxyConfigUrl, render_process_id, render_view_id)); | 129 base::Bind(&ShowLinuxProxyConfigUrl, render_process_id, render_view_id)); |
133 } | 130 } |
134 | 131 |
135 } // anonymous namespace | 132 } // namespace |
| 133 |
| 134 namespace settings_utils { |
136 | 135 |
137 void ShowNetworkProxySettings(content::WebContents* web_contents) { | 136 void ShowNetworkProxySettings(content::WebContents* web_contents) { |
138 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 137 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
139 base::Bind(&DetectAndStartProxyConfigUtil, | 138 base::Bind(&DetectAndStartProxyConfigUtil, |
140 web_contents->GetRenderProcessHost()->GetID(), | 139 web_contents->GetRenderProcessHost()->GetID(), |
141 web_contents->GetRenderViewHost()->GetRoutingID())); | 140 web_contents->GetRenderViewHost()->GetRoutingID())); |
142 } | 141 } |
143 | 142 |
144 } // namespace settings_utils | 143 } // namespace settings_utils |
145 | |
146 #endif // !defined(OS_CHROMEOS) | |
OLD | NEW |