Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(314)

Side by Side Diff: chrome/browser/ui/webui/options2/advanced_options_utils2_x11.cc

Issue 9003014: Replace WebUI::tab_contents() with web_contents() and switch all users to use web_contents.h inst... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/options2/advanced_options_utils2.h" 7 #include "chrome/browser/ui/webui/options2/advanced_options_utils2.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 namespace options2 { 24 namespace options2 {
24 25
25 // Command used to configure GNOME 2 proxy settings. 26 // Command used to configure GNOME 2 proxy settings.
26 const char* kGNOME2ProxyConfigCommand[] = {"gnome-network-properties", NULL}; 27 const char* kGNOME2ProxyConfigCommand[] = {"gnome-network-properties", NULL};
27 // In GNOME 3, we might need to run gnome-control-center instead. We try this 28 // In GNOME 3, we might need to run gnome-control-center instead. We try this
28 // only after gnome-network-properties is not found, because older GNOME also 29 // only after gnome-network-properties is not found, because older GNOME also
29 // has this but it doesn't do the same thing. See below where we use it. 30 // has this but it doesn't do the same thing. See below where we use it.
30 const char* kGNOME3ProxyConfigCommand[] = {"gnome-control-center", "network", 31 const char* kGNOME3ProxyConfigCommand[] = {"gnome-control-center", "network",
31 NULL}; 32 NULL};
32 // KDE3 and KDE4 are only slightly different, but incompatible. Go figure. 33 // KDE3 and KDE4 are only slightly different, but incompatible. Go figure.
33 const char* kKDE3ProxyConfigCommand[] = {"kcmshell", "proxy", NULL}; 34 const char* kKDE3ProxyConfigCommand[] = {"kcmshell", "proxy", NULL};
34 const char* kKDE4ProxyConfigCommand[] = {"kcmshell4", "proxy", NULL}; 35 const char* kKDE4ProxyConfigCommand[] = {"kcmshell4", "proxy", NULL};
35 36
36 // The URL for Linux proxy configuration help when not running under a 37 // The URL for Linux proxy configuration help when not running under a
37 // supported desktop environment. 38 // supported desktop environment.
38 const char kLinuxProxyConfigUrl[] = "about:linux-proxy-config"; 39 const char kLinuxProxyConfigUrl[] = "about:linux-proxy-config";
39 40
40 namespace { 41 namespace {
41 42
42 // Show the proxy config URL in the given tab. 43 // Show the proxy config URL in the given tab.
43 void ShowLinuxProxyConfigUrl(TabContents* tab_contents) { 44 void ShowLinuxProxyConfigUrl(WebContents* web_contents) {
44 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 45 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
45 scoped_ptr<base::Environment> env(base::Environment::Create()); 46 scoped_ptr<base::Environment> env(base::Environment::Create());
46 const char* name = base::nix::GetDesktopEnvironmentName(env.get()); 47 const char* name = base::nix::GetDesktopEnvironmentName(env.get());
47 if (name) 48 if (name)
48 LOG(ERROR) << "Could not find " << name << " network settings in $PATH"; 49 LOG(ERROR) << "Could not find " << name << " network settings in $PATH";
49 OpenURLParams params( 50 OpenURLParams params(
50 GURL(kLinuxProxyConfigUrl), Referrer(), NEW_FOREGROUND_TAB, 51 GURL(kLinuxProxyConfigUrl), Referrer(), NEW_FOREGROUND_TAB,
51 content::PAGE_TRANSITION_LINK, false); 52 content::PAGE_TRANSITION_LINK, false);
52 tab_contents->OpenURL(params); 53 web_contents->OpenURL(params);
53 } 54 }
54 55
55 // Start the given proxy configuration utility. 56 // Start the given proxy configuration utility.
56 bool StartProxyConfigUtil(TabContents* tab_contents, const char* command[]) { 57 bool StartProxyConfigUtil(WebContents* web_contents, const char* command[]) {
57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 58 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
58 // base::LaunchProcess() returns true ("success") if the fork() 59 // base::LaunchProcess() returns true ("success") if the fork()
59 // succeeds, but not necessarily the exec(). We'd like to be able to 60 // succeeds, but not necessarily the exec(). We'd like to be able to
60 // use StartProxyConfigUtil() to search possible options and stop on 61 // use StartProxyConfigUtil() to search possible options and stop on
61 // success, so we search $PATH first to predict whether the exec is 62 // success, so we search $PATH first to predict whether the exec is
62 // expected to succeed. 63 // expected to succeed.
63 // TODO(mdm): this is a useful check, and is very similar to some 64 // TODO(mdm): this is a useful check, and is very similar to some
64 // code in proxy_config_service_linux.cc. It should probably be in 65 // code in proxy_config_service_linux.cc. It should probably be in
65 // base:: somewhere. 66 // base:: somewhere.
66 scoped_ptr<base::Environment> env(base::Environment::Create()); 67 scoped_ptr<base::Environment> env(base::Environment::Create());
(...skipping 21 matching lines...) Expand all
88 if (!base::LaunchProcess(argv, base::LaunchOptions(), &handle)) { 89 if (!base::LaunchProcess(argv, base::LaunchOptions(), &handle)) {
89 LOG(ERROR) << "StartProxyConfigUtil failed to start " << command[0]; 90 LOG(ERROR) << "StartProxyConfigUtil failed to start " << command[0];
90 return false; 91 return false;
91 } 92 }
92 base::EnsureProcessGetsReaped(handle); 93 base::EnsureProcessGetsReaped(handle);
93 return true; 94 return true;
94 } 95 }
95 96
96 // Detect, and if possible, start the appropriate proxy config utility. On 97 // Detect, and if possible, start the appropriate proxy config utility. On
97 // failure to do so, show the Linux proxy config URL in a new tab instead. 98 // failure to do so, show the Linux proxy config URL in a new tab instead.
98 void DetectAndStartProxyConfigUtil(TabContents* tab_contents) { 99 void DetectAndStartProxyConfigUtil(WebContents* web_contents) {
99 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 100 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
100 scoped_ptr<base::Environment> env(base::Environment::Create()); 101 scoped_ptr<base::Environment> env(base::Environment::Create());
101 102
102 bool launched = false; 103 bool launched = false;
103 switch (base::nix::GetDesktopEnvironment(env.get())) { 104 switch (base::nix::GetDesktopEnvironment(env.get())) {
104 case base::nix::DESKTOP_ENVIRONMENT_GNOME: { 105 case base::nix::DESKTOP_ENVIRONMENT_GNOME: {
105 launched = StartProxyConfigUtil(tab_contents, kGNOME2ProxyConfigCommand); 106 launched = StartProxyConfigUtil(web_contents, kGNOME2ProxyConfigCommand);
106 if (!launched) { 107 if (!launched) {
107 // We try this second, even though it's the newer way, because this 108 // We try this second, even though it's the newer way, because this
108 // command existed in older versions of GNOME, but it didn't do the 109 // command existed in older versions of GNOME, but it didn't do the
109 // same thing. The older command is gone though, so this should do 110 // same thing. The older command is gone though, so this should do
110 // the right thing. (Also some distributions have blurred the lines 111 // the right thing. (Also some distributions have blurred the lines
111 // between GNOME 2 and 3, so we can't necessarily detect what the 112 // between GNOME 2 and 3, so we can't necessarily detect what the
112 // right thing is based on indications of which version we have.) 113 // right thing is based on indications of which version we have.)
113 launched = StartProxyConfigUtil(tab_contents, 114 launched = StartProxyConfigUtil(web_contents,
114 kGNOME3ProxyConfigCommand); 115 kGNOME3ProxyConfigCommand);
115 } 116 }
116 break; 117 break;
117 } 118 }
118 119
119 case base::nix::DESKTOP_ENVIRONMENT_KDE3: 120 case base::nix::DESKTOP_ENVIRONMENT_KDE3:
120 launched = StartProxyConfigUtil(tab_contents, kKDE3ProxyConfigCommand); 121 launched = StartProxyConfigUtil(web_contents, kKDE3ProxyConfigCommand);
121 break; 122 break;
122 123
123 case base::nix::DESKTOP_ENVIRONMENT_KDE4: 124 case base::nix::DESKTOP_ENVIRONMENT_KDE4:
124 launched = StartProxyConfigUtil(tab_contents, kKDE4ProxyConfigCommand); 125 launched = StartProxyConfigUtil(web_contents, kKDE4ProxyConfigCommand);
125 break; 126 break;
126 127
127 case base::nix::DESKTOP_ENVIRONMENT_XFCE: 128 case base::nix::DESKTOP_ENVIRONMENT_XFCE:
128 case base::nix::DESKTOP_ENVIRONMENT_OTHER: 129 case base::nix::DESKTOP_ENVIRONMENT_OTHER:
129 break; 130 break;
130 } 131 }
131 132
132 if (launched) 133 if (launched)
133 return; 134 return;
134 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 135 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
135 base::Bind(&ShowLinuxProxyConfigUrl, tab_contents)); 136 base::Bind(&ShowLinuxProxyConfigUrl, web_contents));
136 } 137 }
137 138
138 } // anonymous namespace 139 } // anonymous namespace
139 140
140 void AdvancedOptionsUtilities::ShowNetworkProxySettings( 141 void AdvancedOptionsUtilities::ShowNetworkProxySettings(
141 TabContents* tab_contents) { 142 WebContents* web_contents) {
142 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 143 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
143 base::Bind(&DetectAndStartProxyConfigUtil, tab_contents)); 144 base::Bind(&DetectAndStartProxyConfigUtil, web_contents));
144 } 145 }
145 146
146 } // namespace options2 147 } // namespace options2
147 148
148 #endif // !defined(OS_CHROMEOS) 149 #endif // !defined(OS_CHROMEOS)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698