OLD | NEW |
---|---|
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #include "chrome/browser/gtk/options/advanced_contents_gtk.h" | 5 #include "chrome/browser/gtk/options/advanced_contents_gtk.h" |
6 | 6 |
7 #include <sys/types.h> | 7 #include <sys/types.h> |
8 #include <sys/wait.h> | 8 #include <sys/wait.h> |
9 | 9 |
10 #include "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
(...skipping 20 matching lines...) Expand all Loading... | |
31 #include "chrome/common/pref_member.h" | 31 #include "chrome/common/pref_member.h" |
32 #include "chrome/common/pref_names.h" | 32 #include "chrome/common/pref_names.h" |
33 #include "chrome/common/process_watcher.h" | 33 #include "chrome/common/process_watcher.h" |
34 #include "grit/chromium_strings.h" | 34 #include "grit/chromium_strings.h" |
35 #include "grit/generated_resources.h" | 35 #include "grit/generated_resources.h" |
36 #include "grit/locale_settings.h" | 36 #include "grit/locale_settings.h" |
37 #include "net/base/cookie_policy.h" | 37 #include "net/base/cookie_policy.h" |
38 | 38 |
39 namespace { | 39 namespace { |
40 | 40 |
41 // Command used to configure the gconf proxy settings. The command was renamed | 41 // Command used to configure GNOME proxy settings. The command was renamed |
42 // in January 2009, so both are used to work on both old and new systems. | 42 // in January 2009, so both are used to work on both old and new systems. |
43 const char kOldProxyConfigBinary[] = "gnome-network-preferences"; | 43 const char* kOldGNOMEProxyConfigCommand[] = {"gnome-network-preferences", NULL}; |
44 const char kProxyConfigBinary[] = "gnome-network-properties"; | 44 const char* kGNOMEProxyConfigCommand[] = {"gnome-network-properties", NULL}; |
45 // KDE3 and KDE4 are only slightly different, but incompatible. Go figure. | |
46 // const char* kKDE3ProxyConfigCommand[] = {"kcmshell", "proxy", NULL}; | |
47 // const char* kKDE4ProxyConfigCommand[] = {"kcmshell4", "proxy", NULL}; | |
45 | 48 |
46 // The pixel width we wrap labels at. | 49 // The pixel width we wrap labels at. |
47 // TODO(evanm): make the labels wrap at the appropriate width. | 50 // TODO(evanm): make the labels wrap at the appropriate width. |
48 const int kWrapWidth = 475; | 51 const int kWrapWidth = 475; |
49 | 52 |
50 GtkWidget* CreateWrappedLabel(int string_id) { | 53 GtkWidget* CreateWrappedLabel(int string_id) { |
51 GtkWidget* label = gtk_label_new( | 54 GtkWidget* label = gtk_label_new( |
52 l10n_util::GetStringUTF8(string_id).c_str()); | 55 l10n_util::GetStringUTF8(string_id).c_str()); |
53 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); | 56 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); |
54 gtk_widget_set_size_request(label, kWrapWidth, -1); | 57 gtk_widget_set_size_request(label, kWrapWidth, -1); |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
304 class NetworkSection : public OptionsPageBase { | 307 class NetworkSection : public OptionsPageBase { |
305 public: | 308 public: |
306 explicit NetworkSection(Profile* profile); | 309 explicit NetworkSection(Profile* profile); |
307 virtual ~NetworkSection() {} | 310 virtual ~NetworkSection() {} |
308 | 311 |
309 GtkWidget* get_page_widget() const { | 312 GtkWidget* get_page_widget() const { |
310 return page_; | 313 return page_; |
311 } | 314 } |
312 | 315 |
313 private: | 316 private: |
317 struct ProxyConfigCommand { | |
318 std::string binary; | |
319 const char** argv; | |
320 }; | |
314 // The callback functions for invoking the proxy config dialog. | 321 // The callback functions for invoking the proxy config dialog. |
315 static void OnChangeProxiesButtonClicked(GtkButton *button, | 322 static void OnChangeProxiesButtonClicked(GtkButton *button, |
316 NetworkSection* section); | 323 NetworkSection* section); |
324 // Search PATH to find one of the commands. Store the full path to | |
325 // it in the |binary| field and the command array index in in |index|. | |
326 static bool SearchPATH(ProxyConfigCommand* commands, size_t ncommands, | |
mattm
2009/08/20 22:56:23
should be SearchPath?
| |
327 size_t* index); | |
328 // Start the given proxy configuration utility. | |
329 static void StartProxyConfigUtil(const ProxyConfigCommand& command); | |
317 | 330 |
318 // The widget containing the options for this section. | 331 // The widget containing the options for this section. |
319 GtkWidget* page_; | 332 GtkWidget* page_; |
320 | 333 |
321 DISALLOW_COPY_AND_ASSIGN(NetworkSection); | 334 DISALLOW_COPY_AND_ASSIGN(NetworkSection); |
322 }; | 335 }; |
323 | 336 |
324 NetworkSection::NetworkSection(Profile* profile) | 337 NetworkSection::NetworkSection(Profile* profile) |
325 : OptionsPageBase(profile) { | 338 : OptionsPageBase(profile) { |
326 page_ = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); | 339 page_ = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); |
(...skipping 20 matching lines...) Expand all Loading... | |
347 } | 360 } |
348 | 361 |
349 // static | 362 // static |
350 void NetworkSection::OnChangeProxiesButtonClicked(GtkButton *button, | 363 void NetworkSection::OnChangeProxiesButtonClicked(GtkButton *button, |
351 NetworkSection* section) { | 364 NetworkSection* section) { |
352 section->UserMetricsRecordAction(L"Options_ChangeProxies", NULL); | 365 section->UserMetricsRecordAction(L"Options_ChangeProxies", NULL); |
353 | 366 |
354 scoped_ptr<base::EnvironmentVariableGetter> env_getter( | 367 scoped_ptr<base::EnvironmentVariableGetter> env_getter( |
355 base::EnvironmentVariableGetter::Create()); | 368 base::EnvironmentVariableGetter::Create()); |
356 | 369 |
370 ProxyConfigCommand command; | |
371 bool found_command = false; | |
357 switch (base::GetDesktopEnvironment(env_getter.get())) { | 372 switch (base::GetDesktopEnvironment(env_getter.get())) { |
358 case base::DESKTOP_ENVIRONMENT_GNOME: { | 373 case base::DESKTOP_ENVIRONMENT_GNOME: { |
359 const char* path = getenv("PATH"); | 374 size_t index; |
360 FilePath bin_path; | 375 ProxyConfigCommand commands[2]; |
361 bool have_bin_path = false; | 376 commands[0].argv = kGNOMEProxyConfigCommand; |
362 StringTokenizer tk(path, ":"); | 377 commands[1].argv = kOldGNOMEProxyConfigCommand; |
363 while (tk.GetNext()) { | 378 found_command = SearchPATH(commands, 2, &index); |
364 bin_path = FilePath(tk.token()).Append(kProxyConfigBinary); | 379 if (found_command) |
365 if (file_util::PathExists(bin_path)) { | 380 command = commands[index]; |
366 have_bin_path = true; | |
367 break; | |
368 } | |
369 bin_path = FilePath(tk.token()).Append(kOldProxyConfigBinary); | |
370 if (file_util::PathExists(bin_path)) { | |
371 have_bin_path = true; | |
372 break; | |
373 } | |
374 } | |
375 if (!have_bin_path) { | |
376 LOG(ERROR) << "Could not find Gnome network settings in PATH"; | |
377 BrowserList::GetLastActive()-> | |
378 OpenURL(GURL(l10n_util::GetStringUTF8(IDS_LINUX_PROXY_CONFIG_URL)), | |
379 GURL(), NEW_FOREGROUND_TAB, PageTransition::LINK); | |
380 return; | |
381 } | |
382 std::vector<std::string> argv; | |
383 argv.push_back(bin_path.value()); | |
384 base::file_handle_mapping_vector no_files; | |
385 base::environment_vector env; | |
386 base::ProcessHandle handle; | |
387 env.push_back(std::make_pair("GTK_PATH", | |
388 getenv("CHROMIUM_SAVED_GTK_PATH"))); | |
389 if (!base::LaunchApp(argv, env, no_files, false, &handle)) { | |
390 LOG(ERROR) << "OpenProxyConfigDialogTask failed"; | |
391 BrowserList::GetLastActive()-> | |
392 OpenURL(GURL(l10n_util::GetStringUTF8(IDS_LINUX_PROXY_CONFIG_URL)), | |
393 GURL(), NEW_FOREGROUND_TAB, PageTransition::LINK); | |
394 return; | |
395 } | |
396 ProcessWatcher::EnsureProcessGetsReaped(handle); | |
397 break; | 381 break; |
398 } | 382 } |
399 | 383 |
400 case base::DESKTOP_ENVIRONMENT_KDE: | 384 case base::DESKTOP_ENVIRONMENT_KDE3: |
401 NOTIMPLEMENTED() << "Bug 17363: obey KDE proxy settings."; | 385 // command.argv = kKDE3ProxyConfigCommand; |
402 // Fall through to default behavior for now. | 386 // found_command = SearchPATH(&command, 1, NULL); |
387 break; | |
388 | |
389 case base::DESKTOP_ENVIRONMENT_KDE4: | |
390 // command.argv = kKDE4ProxyConfigCommand; | |
391 // found_command = SearchPATH(&command, 1, NULL); | |
392 break; | |
403 | 393 |
404 case base::DESKTOP_ENVIRONMENT_OTHER: | 394 case base::DESKTOP_ENVIRONMENT_OTHER: |
405 BrowserList::GetLastActive()-> | |
406 OpenURL(GURL(l10n_util::GetStringUTF8(IDS_LINUX_PROXY_CONFIG_URL)), | |
407 GURL(), NEW_FOREGROUND_TAB, PageTransition::LINK); | |
408 break; | 395 break; |
409 } | 396 } |
397 | |
398 if (!found_command) { | |
mattm
2009/08/20 22:56:23
minor nit, but I think it's cleaner to swap the or
Mike Mammarella
2009/08/20 23:11:59
Done.
| |
399 const char* name = base::GetDesktopEnvironmentName(env_getter.get()); | |
400 if (name) | |
401 LOG(ERROR) << "Could not find " << name << " network settings in PATH"; | |
402 BrowserList::GetLastActive()-> | |
403 OpenURL(GURL(l10n_util::GetStringUTF8(IDS_LINUX_PROXY_CONFIG_URL)), | |
404 GURL(), NEW_FOREGROUND_TAB, PageTransition::LINK); | |
405 } else { | |
406 StartProxyConfigUtil(command); | |
407 } | |
408 } | |
409 | |
410 // static | |
411 bool NetworkSection::SearchPATH(ProxyConfigCommand* commands, size_t ncommands, | |
412 size_t* index) { | |
413 const char* path = getenv("PATH"); | |
414 FilePath bin_path; | |
415 StringTokenizer tk(path, ":"); | |
416 // Search PATH looking for the commands in order. | |
417 while (tk.GetNext()) { | |
418 for (size_t i = 0; i < ncommands; i++) { | |
419 bin_path = FilePath(tk.token()).Append(commands[i].argv[0]); | |
420 if (file_util::PathExists(bin_path)) { | |
421 commands[i].binary = bin_path.value(); | |
422 if (index) | |
423 *index = i; | |
424 return true; | |
425 } | |
426 } | |
427 } | |
428 // Did not find any of the binaries in PATH. | |
429 return false; | |
430 } | |
431 | |
432 // static | |
433 void NetworkSection::StartProxyConfigUtil(const ProxyConfigCommand& command) { | |
434 std::vector<std::string> argv; | |
435 argv.push_back(command.binary); | |
436 for (size_t i = 1; command.argv[i]; i++) | |
437 argv.push_back(command.argv[i]); | |
438 base::file_handle_mapping_vector no_files; | |
439 base::environment_vector env; | |
440 base::ProcessHandle handle; | |
441 env.push_back(std::make_pair("GTK_PATH", getenv("CHROMIUM_SAVED_GTK_PATH"))); | |
442 if (!base::LaunchApp(argv, env, no_files, false, &handle)) { | |
443 LOG(ERROR) << "StartProxyConfigUtil failed to start " << command.binary; | |
444 BrowserList::GetLastActive()-> | |
445 OpenURL(GURL(l10n_util::GetStringUTF8(IDS_LINUX_PROXY_CONFIG_URL)), | |
446 GURL(), NEW_FOREGROUND_TAB, PageTransition::LINK); | |
447 return; | |
448 } | |
449 ProcessWatcher::EnsureProcessGetsReaped(handle); | |
410 } | 450 } |
411 | 451 |
412 /////////////////////////////////////////////////////////////////////////////// | 452 /////////////////////////////////////////////////////////////////////////////// |
413 // PrivacySection | 453 // PrivacySection |
414 | 454 |
415 class PrivacySection : public OptionsPageBase { | 455 class PrivacySection : public OptionsPageBase { |
416 public: | 456 public: |
417 explicit PrivacySection(Profile* profile); | 457 explicit PrivacySection(Profile* profile); |
418 virtual ~PrivacySection() {} | 458 virtual ~PrivacySection() {} |
419 | 459 |
(...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1057 l10n_util::GetStringUTF8(IDS_OPTIONS_ADVANCED_SECTION_TITLE_CONTENT), | 1097 l10n_util::GetStringUTF8(IDS_OPTIONS_ADVANCED_SECTION_TITLE_CONTENT), |
1058 web_content_section_->get_page_widget(), false); | 1098 web_content_section_->get_page_widget(), false); |
1059 | 1099 |
1060 security_section_.reset(new SecuritySection(profile_)); | 1100 security_section_.reset(new SecuritySection(profile_)); |
1061 options_builder.AddOptionGroup( | 1101 options_builder.AddOptionGroup( |
1062 l10n_util::GetStringUTF8(IDS_OPTIONS_ADVANCED_SECTION_TITLE_SECURITY), | 1102 l10n_util::GetStringUTF8(IDS_OPTIONS_ADVANCED_SECTION_TITLE_SECURITY), |
1063 security_section_->get_page_widget(), false); | 1103 security_section_->get_page_widget(), false); |
1064 | 1104 |
1065 page_ = options_builder.get_page_widget(); | 1105 page_ = options_builder.get_page_widget(); |
1066 } | 1106 } |
OLD | NEW |