2014-10-31 18:17:05 +00:00
|
|
|
// Copyright (c) 2013 GitHub, Inc.
|
2014-04-25 09:49:37 +00:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
2014-01-02 14:47:54 +00:00
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2014-03-16 00:30:26 +00:00
|
|
|
#include "atom/browser/browser.h"
|
2014-01-02 14:47:54 +00:00
|
|
|
|
2017-10-05 04:30:14 +00:00
|
|
|
#include <fcntl.h>
|
2017-10-07 03:32:46 +00:00
|
|
|
#include <stdlib.h>
|
2014-01-02 14:47:54 +00:00
|
|
|
|
2014-03-16 00:30:26 +00:00
|
|
|
#include "atom/browser/native_window.h"
|
|
|
|
#include "atom/browser/window_list.h"
|
|
|
|
#include "atom/common/atom_version.h"
|
2017-10-05 04:30:14 +00:00
|
|
|
#include "base/command_line.h"
|
2017-10-07 03:32:46 +00:00
|
|
|
#include "base/environment.h"
|
2017-10-05 04:30:14 +00:00
|
|
|
#include "base/process/launch.h"
|
2015-04-14 07:55:41 +00:00
|
|
|
#include "brightray/common/application_info.h"
|
2017-10-02 14:21:30 +00:00
|
|
|
|
|
|
|
#if defined(USE_X11)
|
|
|
|
#include "chrome/browser/ui/libgtkui/gtk_util.h"
|
2017-01-26 10:55:19 +00:00
|
|
|
#include "chrome/browser/ui/libgtkui/unity_service.h"
|
2017-10-02 14:21:30 +00:00
|
|
|
#endif
|
2014-01-02 14:47:54 +00:00
|
|
|
|
|
|
|
namespace atom {
|
|
|
|
|
2017-10-07 03:32:46 +00:00
|
|
|
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);
|
2018-04-18 01:55:30 +00:00
|
|
|
if (devnull < 0)
|
|
|
|
return false;
|
2017-10-07 03:32:46 +00:00
|
|
|
|
|
|
|
base::LaunchOptions options;
|
2017-12-08 08:39:51 +00:00
|
|
|
options.fds_to_remap.push_back(std::make_pair(devnull, STDIN_FILENO));
|
2017-10-07 03:32:46 +00:00
|
|
|
|
|
|
|
base::Process process = base::LaunchProcess(argv, options);
|
|
|
|
close(devnull);
|
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
if (!process.IsValid())
|
|
|
|
return false;
|
2017-10-07 03:32:46 +00:00
|
|
|
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;
|
|
|
|
}
|
2017-10-05 04:30:14 +00:00
|
|
|
|
2014-01-02 14:47:54 +00:00
|
|
|
void Browser::Focus() {
|
|
|
|
// Focus on the first visible window.
|
2017-04-06 21:43:37 +00:00
|
|
|
for (const auto& window : WindowList::GetWindows()) {
|
2014-01-02 14:47:54 +00:00
|
|
|
if (window->IsVisible()) {
|
|
|
|
window->Focus(true);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
void Browser::AddRecentDocument(const base::FilePath& path) {}
|
2014-11-17 05:05:06 +00:00
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
void Browser::ClearRecentDocuments() {}
|
2014-11-17 08:13:47 +00:00
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
void Browser::SetAppUserModelID(const base::string16& name) {}
|
2015-11-03 07:09:31 +00:00
|
|
|
|
2016-08-16 05:54:30 +00:00
|
|
|
bool Browser::SetAsDefaultProtocolClient(const std::string& protocol,
|
2016-08-22 00:50:58 +00:00
|
|
|
mate::Arguments* args) {
|
2017-10-03 15:10:38 +00:00
|
|
|
return SetDefaultWebClient(protocol);
|
2016-03-21 18:24:25 +00:00
|
|
|
}
|
|
|
|
|
2017-10-05 04:30:14 +00:00
|
|
|
bool Browser::IsDefaultProtocolClient(const std::string& protocol,
|
2017-10-07 04:36:18 +00:00
|
|
|
mate::Arguments* args) {
|
|
|
|
std::unique_ptr<base::Environment> env(base::Environment::Create());
|
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
if (protocol.empty())
|
|
|
|
return false;
|
2017-10-07 04:36:18 +00:00
|
|
|
|
|
|
|
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()));
|
2017-10-02 14:21:30 +00:00
|
|
|
|
2017-10-07 04:36:18 +00:00
|
|
|
std::string reply;
|
|
|
|
int success_code;
|
2018-04-18 01:55:30 +00:00
|
|
|
bool ran_ok = base::GetAppOutputWithExitCode(base::CommandLine(argv), &reply,
|
|
|
|
&success_code);
|
2017-10-02 14:21:30 +00:00
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
if (!ran_ok || success_code != EXIT_SUCCESS)
|
|
|
|
return false;
|
2017-10-02 14:21:30 +00:00
|
|
|
|
2017-10-07 04:36:18 +00:00
|
|
|
// Allow any reply that starts with "yes".
|
2018-04-18 01:55:30 +00:00
|
|
|
return base::StartsWith(reply, "yes", base::CompareCase::SENSITIVE) ? true
|
|
|
|
: false;
|
2017-10-02 14:21:30 +00:00
|
|
|
}
|
|
|
|
|
2017-10-07 03:40:58 +00:00
|
|
|
// Todo implement
|
2017-10-02 14:21:30 +00:00
|
|
|
bool Browser::RemoveAsDefaultProtocolClient(const std::string& protocol,
|
|
|
|
mate::Arguments* args) {
|
2016-04-25 05:17:01 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-07-01 13:18:39 +00:00
|
|
|
bool Browser::SetBadgeCount(int count) {
|
|
|
|
if (IsUnityRunning()) {
|
|
|
|
unity::SetDownloadCount(count);
|
2016-07-02 01:36:11 +00:00
|
|
|
badge_count_ = count;
|
2016-07-01 13:18:39 +00:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2016-07-01 08:39:01 +00:00
|
|
|
}
|
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
void Browser::SetLoginItemSettings(LoginItemSettings settings) {}
|
2016-07-11 17:57:53 +00:00
|
|
|
|
2017-01-27 19:24:46 +00:00
|
|
|
Browser::LoginItemSettings Browser::GetLoginItemSettings(
|
2017-03-29 19:29:52 +00:00
|
|
|
const LoginItemSettings& options) {
|
2016-07-11 17:57:53 +00:00
|
|
|
return LoginItemSettings();
|
|
|
|
}
|
|
|
|
|
2014-01-02 14:47:54 +00:00
|
|
|
std::string Browser::GetExecutableFileVersion() const {
|
2015-04-14 07:55:41 +00:00
|
|
|
return brightray::GetApplicationVersion();
|
2014-01-02 14:47:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string Browser::GetExecutableFileProductName() const {
|
2015-04-14 07:55:41 +00:00
|
|
|
return brightray::GetApplicationName();
|
2014-01-02 14:47:54 +00:00
|
|
|
}
|
|
|
|
|
2016-07-01 08:39:01 +00:00
|
|
|
bool Browser::IsUnityRunning() {
|
2016-06-25 23:55:24 +00:00
|
|
|
return unity::IsRunning();
|
|
|
|
}
|
|
|
|
|
2014-01-02 14:47:54 +00:00
|
|
|
} // namespace atom
|