electron/shell/browser/browser_linux.cc
electron-roller[bot] 8532e1239e
chore: bump chromium to 93.0.4530.0 (master) (#29256)
* chore: bump chromium in DEPS to 92.0.4512.6

* 2887336: [CaptureHandle][#2] Propagate CaptureHandleConfig in browser process

https://chromium-review.googlesource.com/c/chromium/src/+/2887336

* refactor: base::Optional -> absl::optional

* chore: fixup patch indices

* chore: bump chromium in DEPS to 92.0.4514.0

* 2899417: Make build work when enable_pdf is set to false.

https://chromium-review.googlesource.com/c/chromium/src/+/2899417

* 2904731: use BrowserContext instead of Profile in PreconnectManager

https://chromium-review.googlesource.com/c/chromium/src/+/2904731

* 2295749: fix: check IsSecureEventInputEnabled in constructor before setting SetPasswordInputEnabled to true

https://chromium-review.googlesource.com/c/chromium/src/+/2295749

* 2893803: Add a GetWebView to RenderFrame.

https://chromium-review.googlesource.com/c/chromium/src/+/2893803

* 2892345: Implement WebContents::ForEachRenderFrameHost

https://chromium-review.googlesource.com/c/chromium/src/+/2892345

* chore: fixup patch indices

* 2892048: Real instance methods for BrowserContext: remaining 5 methods.

https://chromium-review.googlesource.com/c/chromium/src/+/2892048

* 2902821: [mojo] Don't require full header includes for referenced interfaces

https://chromium-review.googlesource.com/c/chromium/src/+/2902821

* 2496500: Remove last deprecated extension Event ctor.

https://chromium-review.googlesource.com/c/chromium/src/+/2496500

* chore: fixup malformed pepper support patch

* chore: bump chromium in DEPS to 92.0.4515.0

* 2908461: Add CreateEmptyPrintPagesParamsPtr() inside print_view_manager_base.cc.

https://chromium-review.googlesource.com/c/chromium/src/+/2908461

* 2880838: viz: add optional HDRMetadata to TransferableResource

https://chromium-review.googlesource.com/c/chromium/src/+/2880838

* chore: fixup patch indices

* chore: bump chromium in DEPS to 92.0.4515.5

* chore: update patches

* chore: bump chromium in DEPS to 92.0.4515.7

* chore: bump chromium in DEPS to 92.0.4515.9

* chore: bump chromium in DEPS to 93.0.4522.0

* chore: bump chromium in DEPS to 93.0.4523.0

* chore: bump chromium in DEPS to 93.0.4524.0

* chore: update patches

* chore: enable_pak_file_integrity_checks was reverted

* chore: update patches

* refactor: base/optional was replaced with absl::optional

Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2910202

* refactor: replace all usages of base::nullopt with absl::nullopt

Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2910202

* chore: add missing base::Contains include

Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2910202

* refactor: replace all usages of base::make_optional with
absl::make_optional

Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2910202

* refactor: replace WorldScriptContext() with GetScriptContextFromWorldId

Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2893213

* chore: clean up left over opening namespace

Refs: 95bfe6d08f

* chore: add missing base::Contains include

Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2910202

* refactor: replace GetCurrentDisplayIterator with the hard checker
GetCurrentDisplay

This code looks suspicious but if the iterator was invalid before it
will also be invalid now.

Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2893191

* refactor: headers are now passed directly in extensions client

Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2918906

* refactor: base::DictionaryValue::empty() has been removed

Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2912424

* chore: add missing includes for network URLLoaderFactory

Refs: unknown, probably a side effect of header changes

* refactor: make convenience wrapper around AppendArg

There is no converter FromV8 for base::StringPiece (apparently its not
possible).  So we now take in an std::string and use the construct for
StringPiece to do implicit conversion.

Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2905544

* chore: add patch

* chore: bump chromium in DEPS to 93.0.4525.0

* chore: update patches

* refactor: CanResize has been de-virtualized

Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2485774

* chore: update resource integrity patch

* chore: add character encoding idl patch

* chore: bump chromium in DEPS to 93.0.4526.0

* chore: update patches

* chore: bump chromium in DEPS to 93.0.4527.0

* chore: bump chromium in DEPS to 93.0.4528.0

* chore: update patches

* chore: update idl encoding patch

* chore: bump chromium in DEPS to 93.0.4529.0

* chore: update patches

* chore: bump chromium in DEPS to 93.0.4530.0

* chore: update patches

* fix: only SetCanResize after the widget has been initialized

* chore: add patch for vr on windows gn gen

* spec: fix focus related tests on linux due to delay in focus swap

* chore: remove new usages of base::Optional from main

Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com>
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com>
Co-authored-by: Samuel Attard <sattard@slack-corp.com>
Co-authored-by: Samuel Attard <samuel.r.attard@gmail.com>
2021-06-03 01:05:04 -07:00

231 lines
6.8 KiB
C++

// 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 "shell/browser/browser.h"
#include <fcntl.h>
#include <stdlib.h>
#include "base/command_line.h"
#include "base/environment.h"
#include "base/process/launch.h"
#include "electron/electron_version.h"
#include "shell/browser/native_window.h"
#include "shell/browser/window_list.h"
#include "shell/common/application_info.h"
#if defined(OS_LINUX)
#include "shell/browser/linux/unity_service.h"
#include "ui/gtk/gtk_util.h"
#endif
namespace electron {
const char kXdgSettings[] = "xdg-settings";
const char kXdgSettingsDefaultSchemeHandler[] = "default-url-scheme-handler";
// The use of the ForTesting flavors is a hack workaround to avoid having to
// patch these as friends into the associated guard classes.
class LaunchXdgUtilityScopedAllowBaseSyncPrimitives
: public base::ScopedAllowBaseSyncPrimitivesForTesting {};
class GetXdgAppOutputScopedAllowBlocking
: public base::ScopedAllowBlockingForTesting {};
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.emplace_back(devnull, STDIN_FILENO);
base::Process process = base::LaunchProcess(argv, options);
close(devnull);
if (!process.IsValid())
return false;
LaunchXdgUtilityScopedAllowBaseSyncPrimitives allow_base_sync_primitives;
return process.WaitForExit(exit_code);
}
absl::optional<std::string> GetXdgAppOutput(
const std::vector<std::string>& argv) {
std::string reply;
int success_code;
GetXdgAppOutputScopedAllowBlocking allow_blocking;
bool ran_ok = base::GetAppOutputWithExitCode(base::CommandLine(argv), &reply,
&success_code);
if (!ran_ok || success_code != EXIT_SUCCESS)
return absl::optional<std::string>();
return absl::make_optional(reply);
}
bool SetDefaultWebClient(const std::string& protocol) {
std::unique_ptr<base::Environment> env(base::Environment::Create());
std::vector<std::string> argv = {kXdgSettings, "set"};
if (!protocol.empty()) {
argv.emplace_back(kXdgSettingsDefaultSchemeHandler);
argv.emplace_back(protocol);
}
std::string desktop_name;
if (!env->GetVar("CHROME_DESKTOP", &desktop_name)) {
return false;
}
argv.emplace_back(desktop_name);
int exit_code;
bool ran_ok = LaunchXdgUtility(argv, &exit_code);
return ran_ok && exit_code == EXIT_SUCCESS;
}
void Browser::AddRecentDocument(const base::FilePath& path) {}
void Browser::ClearRecentDocuments() {}
bool Browser::SetAsDefaultProtocolClient(const std::string& protocol,
gin::Arguments* args) {
return SetDefaultWebClient(protocol);
}
bool Browser::IsDefaultProtocolClient(const std::string& protocol,
gin::Arguments* args) {
std::unique_ptr<base::Environment> env(base::Environment::Create());
if (protocol.empty())
return false;
std::string desktop_name;
if (!env->GetVar("CHROME_DESKTOP", &desktop_name))
return false;
const std::vector<std::string> argv = {kXdgSettings, "check",
kXdgSettingsDefaultSchemeHandler,
protocol, desktop_name};
const auto output = GetXdgAppOutput(argv);
if (!output)
return false;
// Allow any reply that starts with "yes".
return base::StartsWith(output.value(), "yes", base::CompareCase::SENSITIVE);
}
// Todo implement
bool Browser::RemoveAsDefaultProtocolClient(const std::string& protocol,
gin::Arguments* args) {
return false;
}
std::u16string Browser::GetApplicationNameForProtocol(const GURL& url) {
const std::vector<std::string> argv = {
"xdg-mime", "query", "default",
std::string("x-scheme-handler/") + url.scheme()};
return base::ASCIIToUTF16(GetXdgAppOutput(argv).value_or(std::string()));
}
bool Browser::SetBadgeCount(absl::optional<int> count) {
if (IsUnityRunning() && count.has_value()) {
unity::SetDownloadCount(count.value());
badge_count_ = count.value();
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();
}
bool Browser::IsEmojiPanelSupported() {
return false;
}
void Browser::ShowAboutPanel() {
const auto& opts = about_panel_options_;
if (!opts.is_dict()) {
LOG(WARNING) << "Called showAboutPanel(), but didn't use "
"setAboutPanelSettings() first";
return;
}
GtkWidget* dialogWidget = gtk_about_dialog_new();
GtkAboutDialog* dialog = GTK_ABOUT_DIALOG(dialogWidget);
const std::string* str;
const base::Value* val;
if ((str = opts.FindStringKey("applicationName"))) {
gtk_about_dialog_set_program_name(dialog, str->c_str());
}
if ((str = opts.FindStringKey("applicationVersion"))) {
gtk_about_dialog_set_version(dialog, str->c_str());
}
if ((str = opts.FindStringKey("copyright"))) {
gtk_about_dialog_set_copyright(dialog, str->c_str());
}
if ((str = opts.FindStringKey("website"))) {
gtk_about_dialog_set_website(dialog, str->c_str());
}
if ((str = opts.FindStringKey("iconPath"))) {
GError* error = nullptr;
constexpr int width = 64; // width of about panel icon in pixels
constexpr int height = 64; // height of about panel icon in pixels
// set preserve_aspect_ratio to true
GdkPixbuf* icon =
gdk_pixbuf_new_from_file_at_size(str->c_str(), width, height, &error);
if (error != nullptr) {
g_warning("%s", error->message);
g_clear_error(&error);
} else {
gtk_about_dialog_set_logo(dialog, icon);
g_clear_object(&icon);
}
}
if ((val = opts.FindListKey("authors"))) {
std::vector<const char*> cstrs;
for (const auto& authorVal : val->GetList()) {
if (authorVal.is_string()) {
cstrs.push_back(authorVal.GetString().c_str());
}
}
if (cstrs.empty()) {
LOG(WARNING) << "No author strings found in 'authors' array";
} else {
cstrs.push_back(nullptr); // null-terminated char* array
gtk_about_dialog_set_authors(dialog, cstrs.data());
}
}
gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialogWidget);
}
void Browser::SetAboutPanelOptions(base::DictionaryValue options) {
about_panel_options_ = std::move(options);
}
} // namespace electron