blob: 02b262c80a9f9886e7f85ddd4000044357940309 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/printing/printer_manager_dialog.h"
#include "base/environment.h"
#include "base/nix/xdg_util.h"
#include "base/process_util.h"
#include "content/browser/browser_thread.h"
#include "content/common/process_watcher.h"
using base::Environment;
namespace {
// KDE printer config command ("system-config-printer-kde") causes the
// OptionWidget to crash (https://bugs.kde.org/show_bug.cgi?id=271957).
// Therefore, use GNOME printer config command for KDE.
const char kGNOMEPrinterConfigCommand[] = "system-config-printer";
// Detect the command based on the deskop environment and open the printer
// manager dialog.
void DetectAndOpenPrinterConfigDialog() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
scoped_ptr<Environment> env(Environment::Create());
const char* command = NULL;
switch (base::nix::GetDesktopEnvironment(env.get())) {
case base::nix::DESKTOP_ENVIRONMENT_GNOME:
case base::nix::DESKTOP_ENVIRONMENT_KDE3:
case base::nix::DESKTOP_ENVIRONMENT_KDE4:
command = kGNOMEPrinterConfigCommand;
break;
case base::nix::DESKTOP_ENVIRONMENT_XFCE:
case base::nix::DESKTOP_ENVIRONMENT_OTHER:
break;
default:
NOTREACHED();
break;
}
if (!command) {
LOG(ERROR) << "Failed to detect the command to open printer config dialog";
return;
}
std::vector<std::string> argv;
argv.push_back(command);
base::LaunchOptions options;
base::ProcessHandle handle;
options.process_handle = &handle;
if (!base::LaunchProcess(argv, options)) {
LOG(ERROR) << "Failed to open printer manager dialog ";
return;
}
ProcessWatcher::EnsureProcessGetsReaped(handle);
}
} // anonymous namespace
namespace printing {
void PrinterManagerDialog::ShowPrinterManagerDialog() {
BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
NewRunnableFunction(&DetectAndOpenPrinterConfigDialog));
}
} // namespace printing
|