-
Notifications
You must be signed in to change notification settings - Fork 15k
/
browser_linux.cc
183 lines (144 loc) · 5.47 KB
/
browser_linux.cc
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
// Copyright (c) 2013 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "atom/browser/browser.h"
#include <fcntl.h>
#include <stdlib.h>
#include "atom/browser/native_window.h"
#include "atom/browser/window_list.h"
#include "atom/common/application_info.h"
#include "atom/common/atom_version.h"
#include "base/command_line.h"
#include "base/environment.h"
#include "base/process/launch.h"
#if defined(USE_X11)
#include "chrome/browser/ui/libgtkui/gtk_util.h"
#include "chrome/browser/ui/libgtkui/unity_service.h"
#endif
namespace atom {
const char kXdgSettings[] = "xdg-settings";
const char kXdgSettingsDefaultSchemeHandler[] = "default-url-scheme-handler";
bool LaunchXdgUtility(const std::vector<std::string>& argv, int* exit_code) {
*exit_code = EXIT_FAILURE;
int devnull = open("/dev/null", O_RDONLY);
if (devnull < 0)
return false;
base::LaunchOptions options;
options.fds_to_remap.push_back(std::make_pair(devnull, STDIN_FILENO));
base::Process process = base::LaunchProcess(argv, options);
close(devnull);
if (!process.IsValid())
return false;
return process.WaitForExit(exit_code);
}
bool SetDefaultWebClient(const std::string& protocol) {
std::unique_ptr<base::Environment> env(base::Environment::Create());
std::vector<std::string> argv;
argv.push_back(kXdgSettings);
argv.push_back("set");
if (!protocol.empty()) {
argv.push_back(kXdgSettingsDefaultSchemeHandler);
argv.push_back(protocol);
}
argv.push_back(libgtkui::GetDesktopName(env.get()));
int exit_code;
bool ran_ok = LaunchXdgUtility(argv, &exit_code);
return ran_ok && exit_code == EXIT_SUCCESS;
}
void Browser::Focus() {
// Focus on the first visible window.
for (auto* const window : WindowList::GetWindows()) {
if (window->IsVisible()) {
window->Focus(true);
break;
}
}
}
void Browser::AddRecentDocument(const base::FilePath& path) {}
void Browser::ClearRecentDocuments() {}
void Browser::SetAppUserModelID(const base::string16& name) {}
bool Browser::SetAsDefaultProtocolClient(const std::string& protocol,
mate::Arguments* args) {
return SetDefaultWebClient(protocol);
}
bool Browser::IsDefaultProtocolClient(const std::string& protocol,
mate::Arguments* args) {
std::unique_ptr<base::Environment> env(base::Environment::Create());
if (protocol.empty())
return false;
std::vector<std::string> argv;
argv.push_back(kXdgSettings);
argv.push_back("check");
argv.push_back(kXdgSettingsDefaultSchemeHandler);
argv.push_back(protocol);
argv.push_back(libgtkui::GetDesktopName(env.get()));
std::string reply;
int success_code;
bool ran_ok = base::GetAppOutputWithExitCode(base::CommandLine(argv), &reply,
&success_code);
if (!ran_ok || success_code != EXIT_SUCCESS)
return false;
// Allow any reply that starts with "yes".
return base::StartsWith(reply, "yes", base::CompareCase::SENSITIVE) ? true
: false;
}
// Todo implement
bool Browser::RemoveAsDefaultProtocolClient(const std::string& protocol,
mate::Arguments* args) {
return false;
}
bool Browser::SetBadgeCount(int count) {
if (IsUnityRunning()) {
unity::SetDownloadCount(count);
badge_count_ = count;
return true;
} else {
return false;
}
}
void Browser::SetLoginItemSettings(LoginItemSettings settings) {}
Browser::LoginItemSettings Browser::GetLoginItemSettings(
const LoginItemSettings& options) {
return LoginItemSettings();
}
std::string Browser::GetExecutableFileVersion() const {
return GetApplicationVersion();
}
std::string Browser::GetExecutableFileProductName() const {
return GetApplicationName();
}
bool Browser::IsUnityRunning() {
return unity::IsRunning();
}
void Browser::ShowAboutPanel() {
std::string app_name, version, copyright, icon_path, credits, website;
GtkWidget* dialog = gtk_about_dialog_new();
if (about_panel_options_.GetString("applicationName", &app_name))
gtk_about_dialog_set_program_name(GTK_ABOUT_DIALOG(dialog),
app_name.c_str());
if (about_panel_options_.GetString("applicationVersion", &version))
gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(dialog), version.c_str());
if (about_panel_options_.GetString("copyright", ©right))
gtk_about_dialog_set_copyright(GTK_ABOUT_DIALOG(dialog), copyright.c_str());
if (about_panel_options_.GetString("credits", &credits))
gtk_about_dialog_set_authors(GTK_ABOUT_DIALOG(dialog), credits.c_str());
if (about_panel_options_.GetString("website", &website))
gtk_about_dialog_set_website(GTK_ABOUT_DIALOG(dialog), website.c_str());
if (about_panel_options_.GetString("iconPath", &icon_path)) {
GdkPixbuf* icon = gdk_pixbuf_new_from_file(icon_path.c_str(), NULL);
gtk_about_dialog_set_logo(GTK_ABOUT_DIALOG(dialog), icon);
}
g_object_unref(icon), icon = NULL;
gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
}
void Browser::SetAboutPanelOptions(const base::DictionaryValue& options) {
about_panel_options_.Clear();
for (base::DictionaryValue::Iterator iter(options); !iter.IsAtEnd();
iter.Advance()) {
std::string key = iter.key();
if (!key.empty() && iter.value().is_string())
about_panel_options_.SetString(key, iter.value().GetString());
}
}
} // namespace atom