electron/shell/browser/browser_linux.cc

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

232 lines
6.9 KiB
C++
Raw Normal View History

// 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.
#include "shell/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
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"
perf: prefer GURL string_view getters (#43471) * chore: avoid double-call to url.scheme() in WebContentsZoomController::SetZoomMode() Co-authored-by: Charles Kerr <charles@charleskerr.com> * perf: use gurl.scheme_piece() in GetAppInfoHelperForProtocol() Co-authored-by: Charles Kerr <charles@charleskerr.com> * perf: use gurl.scheme_piece() in Browser::GetApplicationNameForProtocol() Co-authored-by: Charles Kerr <charles@charleskerr.com> * refactor: add std::less<> to HandlersMap This lets us search it using string_view keys Co-authored-by: Charles Kerr <charles@charleskerr.com> * refactor: ProtocolRegistry::FindRegistered() now takes a std::string_view Co-authored-by: Charles Kerr <charles@charleskerr.com> * perf: use gurl.scheme_piece() in InspectableWebContents::LoadNetworkResource() Co-authored-by: Charles Kerr <charles@charleskerr.com> * refactor: ProtocolRegistry::FindIntercepted() now takes a std::string_view Co-authored-by: Charles Kerr <charles@charleskerr.com> * perf: use gurl.scheme_piece() in SimpleURLLoaderWrapper::GetURLLoaderFactoryForURL() Co-authored-by: Charles Kerr <charles@charleskerr.com> * perf: use gurl.scheme_piece() in ProxyingURLLoaderFactory::CreateLoaderAndStart() Co-authored-by: Charles Kerr <charles@charleskerr.com> * perf: use gurl.host_piece() in ElectronWebUIControllerFactory::GetWebUIType() Co-authored-by: Charles Kerr <charles@charleskerr.com> * perf: use gurl.host_piece() in ElectronWebUIControllerFactory::CreateWebUIControllerForURL() Co-authored-by: Charles Kerr <charles@charleskerr.com> --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Charles Kerr <charles@charleskerr.com>
2024-08-24 01:58:59 +00:00
#include "base/strings/strcat.h"
#include "electron/electron_version.h"
#include "shell/browser/javascript_environment.h"
#include "shell/browser/native_window.h"
#include "shell/browser/window_list.h"
#include "shell/common/application_info.h"
#include "shell/common/gin_converters/login_item_settings_converter.h"
chore: bump chromium to 110.0.5415.0 (main) (#36186) * chore: bump chromium in DEPS to 109.0.5386.0 * chore: bump chromium in DEPS to 109.0.5388.0 * chore: bump chromium in DEPS to 109.0.5390.0 * chore: bump chromium in DEPS to 109.0.5392.0 * chore: bump chromium in DEPS to 109.0.5394.0 * chore: bump chromium in DEPS to 109.0.5396.0 * chore: bump chromium in DEPS to 109.0.5398.0 * chore: bump chromium in DEPS to 109.0.5400.0 * chore: update galactus * chore: bump chromium in DEPS to 109.0.5402.0 * chore: bump chromium in DEPS to 109.0.5403.0 * chore: bump chromium in DEPS to 109.0.5406.0 * chore: update patches * 4004247: Delete unused DocumentWebContentsDelegate Ref: https://chromium-review.googlesource.com/c/chromium/src/+/4004247 * chore: bump chromium in DEPS to 109.0.5408.1 * chore: update patches * 3949284: Support pkey debug mode without pkey 0 access Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3949284 * chore: bump chromium in DEPS to 109.0.5410.0 * chore: update patches * 4000944: [Extensions] Create an API directory in //chrome/renderer/extensions Ref: https://chromium-review.googlesource.com/c/chromium/src/+/4000944 * 3988524: Remove DocumentOverlayWindowViews | https://chromium-review.googlesource.com/c/chromium/src/+/3988524 Co-authored-by: George Xu <33054982+georgexu99@users.noreply.github.com> * chore: bump chromium in DEPS to 109.0.5412.0 * chore: update patches * 3984022: Add AddChildWindowToBrowser to DisplayClient mojo interface Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3984022 * 3957079: Delete the CryptoToken component extension and internal API Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3957079 * 4004421: Migreate ScopedAllowIO to ScopedAllowBlocking Ref: https://chromium-review.googlesource.com/c/chromium/src/+/4004421 Co-authored-by: George Xu <georgexu99@users.noreply.github.com> * chore: bump chromium in DEPS to 109.0.5414.0 * chore: update patches * 4016180: Split PPAPI Mojo interfaces out of RenderFrameHostImpl. Ref: https://chromium-review.googlesource.com/c/chromium/src/+/4016180 * 3970838: [MPArch] Convert HostZoomMap and ZoomController off of RenderViewHost ids Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3970838 * 3997795: Don't add Chromium as a login item Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3997795 * 3993482: Remove RefCountedString::TakeString Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3993482 * 3990749: Allow forward-declared sources in base::ScopedObservation<> Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3990749 * fixup! 3957079: Delete the CryptoToken component extension and internal API * chore: bump chromium in DEPS to 110.0.5415.0 * 3883790: Move devtools_frame_token to the RenderFrameHost, to preserve RFH identity across MPArch activations. https://chromium-review.googlesource.com/c/chromium/src/+/3883790 * 4022205: Move license tooling into //tools/licenses https://chromium-review.googlesource.com/c/chromium/src/+/4022205 * chore: fixup patch indices * fixup! 3957079: Delete the CryptoToken component extension and internal API * 4008687: Finish ScopedAllowIO migration https://chromium-review.googlesource.com/c/chromium/src/+/4008687 * 3991548: Move WindowButtonOrderObserver and WindowFrameAction to LinuxUi https://chromium-review.googlesource.com/c/chromium/src/+/3991548 * fixup! 3984022: Add AddChildWindowToBrowser to DisplayClient mojo interface * 4016595: Migrate non-default ScopedObservation<> instantiations to ScopedObservationTraits<> in chrome/browser/ https://chromium-review.googlesource.com/c/chromium/src/+/4016595 * 4000481: Rename :chromedriver to :chromedriver_server Ref: https://chromium-review.googlesource.com/c/chromium/src/+/4000481 * 4008687: Finish ScopedAllowIO migration https://chromium-review.googlesource.com/c/chromium/src/+/4008687 * 3988524: Remove DocumentOverlayWindowViews https://chromium-review.googlesource.com/c/chromium/src/+/3988524 * fixup! 3997795: Don't add Chromium as a login item * chore: fixup patches * 3996872: Plumb input event task runner to EventFactoryEvdev https://chromium-review.googlesource.com/c/chromium/src/+/3996872 * 4014994: Enable SiteIsolationForGuests by default. https://chromium-review.googlesource.com/c/chromium/src/+/4014994 * chore: adopt new thread restrictions api for //electron (#36357) chore: add thread blocking api * fixup! 4014994: Enable SiteIsolationForGuests by default. * pull parent HWND for dialogs on ui thread * chore: set parent_window in MessageBoxSettings * chore: remove redundant patch * chore: revert accidental deletion * chore: update patches Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: Samuel Attard <sattard@salesforce.com> Co-authored-by: Keeley Hammond <khammond@slack-corp.com> Co-authored-by: VerteDinde <vertedinde@electronjs.org> Co-authored-by: George Xu <33054982+georgexu99@users.noreply.github.com> Co-authored-by: George Xu <georgexu99@users.noreply.github.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> Co-authored-by: Robo <hop2deep@gmail.com> Co-authored-by: Jeremy Rose <jeremya@chromium.org> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com>
2022-11-17 19:59:23 +00:00
#include "shell/common/thread_restrictions.h"
chore: bump chromium to 100.0.4857.0 (main) (#32419) * chore: bump chromium in DEPS to 99.0.4819.0 * chore: update patches * chore: bump chromium in DEPS to 99.0.4824.0 * chore: update patches * chore: bump chromium in DEPS to 99.0.4827.0 * chore: update patches * 3352511: PiP: Add inkdrop and pointer cursor to PiP window buttons https://chromium-review.googlesource.com/c/chromium/src/+/3352511 * 3309164: webhid: Show FIDO devices in the chooser if allowed https://chromium-review.googlesource.com/c/chromium/src/+/3309164 * 3297868: hid: Add experimental HIDDevice.forget() https://chromium-review.googlesource.com/c/chromium/src/+/3297868 * 3362491: [Extensions] Move i18n API to //extensions https://chromium-review.googlesource.com/c/chromium/src/+/3362491 * MCC Refactor step0: Allow embedders to register associated_interface binders with RenderFrameHostImpl::associated_registry_. https://chromium-review.googlesource.com/c/chromium/src/+/3281481 * 3352616: [Gtk] Remove libgtk from the link-line https://chromium-review.googlesource.com/c/chromium/src/+/3352616 * 3249211: Clear-Site-Data support for partitioned cookies https://chromium-review.googlesource.com/c/chromium/src/+/3249211 * [Extensions][COIL] Use [allow|block]list in //extensions/common https://chromium-review.googlesource.com/c/chromium/src/+/3372668 * Begin ScopedUserPrefUpdate migration to modern base::Value https://chromium-review.googlesource.com/c/chromium/src/+/3376154 * [Code Health] Refactor PrefService GetDict + GetList to use base::Value https://chromium-review.googlesource.com/c/chromium/src/+/3343526 * 3354997: [CodeHealth] Remove deprecated SetDictionary method https://chromium-review.googlesource.com/c/chromium/src/+/3354997 * 3287323: Add LacrosPrefStore for lacros settings https://chromium-review.googlesource.com/c/chromium/src/+/3287323 * 3365916: [PA] Clean up remaining lazy commit code https://chromium-review.googlesource.com/c/chromium/src/+/3365916 * [MPArch] Target the external protocol error at the responsible frame. https://chromium-review.googlesource.com/c/chromium/src/+/3011560 * Pass origin to RegisterNonNetworkSubresourceURLLoaderFactories https://chromium-review.googlesource.com/c/chromium/src/+/3350608 * Linux: Send OSCrypt raw encryption key to the Network Service https://chromium-review.googlesource.com/c/chromium/src/+/3320484 * [PlzServiceWorker] Remove remaining references to PlzServiceWorker. https://chromium-review.googlesource.com/c/chromium/src/+/3359441 * chore: fixup for lint * 3327621: Fix tablet mode detection for Win 11. https://chromium-review.googlesource.com/c/chromium/src/+/3327621 * 3342428: ax_mac: move AXTextMarker conversion utils under ui umbrella https://chromium-review.googlesource.com/c/chromium/src/+/3342428 * 3353974: Mac: Use base::Feature for overlay features https://chromium-review.googlesource.com/c/chromium/src/+/3353974 * chore: bump chromium in DEPS to 99.0.4828.0 * chore: update patches * chore: bump chromium in DEPS to 99.0.4837.0 * chore: update patches * chore: update patches * 3379142: Drop FALLTHROUGH macro Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3379142 * 3381749: C++17: Allow use of std::map::try_emplace and std::map::insert_or_assign Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3381749 * chore: bump chromium in DEPS to 99.0.4839.0 * chore: update patches * chore: bump chromium in DEPS to 99.0.4840.0 * chore: bump chromium in DEPS to 99.0.4844.0 * 3395881: [api] Deprecate Local<v8::Context> v8::Object::CreationContext() Ref: https://chromium-review.googlesource.com/c/v8/v8/+/3395881 * chore: update patches * chore: bump chromium in DEPS to 100.0.4845.0 * chore: update patches * chore: bump chromium in DEPS to 100.0.4847.0 * chore: update patches * chore: bump chromium in DEPS to 100.0.4849.0 * chore: update patches * chore: bump chromium in DEPS to 100.0.4851.0 * chore: bump chromium in DEPS to 100.0.4853.0 * update patches * chore: update patches * update patches * 3383599: Fonts Access: Remove prototype that uses a font picker. https://chromium-review.googlesource.com/c/chromium/src/+/3383599 * 3404768: Remove ALLOW_UNUSED macros https://chromium-review.googlesource.com/c/chromium/src/+/3404768 * 3374762: Remove ignore_result.h https://chromium-review.googlesource.com/c/chromium/src/+/3374762 * 3399305: [unseasoned-pdf] Apply proper frame offsets for touch selections https://chromium-review.googlesource.com/c/chromium/src/+/3399305 * 3402210: [Extensions] Don't trigger unload event for already unloaded extension https://chromium-review.googlesource.com/c/chromium/src/+/3402210 * 3410912: Combine URLLoaderClient OnReceiveResponse and OnStartLoadingResponseBody. https://chromium-review.googlesource.com/c/chromium/src/+/3410912 * 3370428: Make the AuthSchemes policy support dynamic refresh https://chromium-review.googlesource.com/c/chromium/src/+/3370428 * 3407603: Finish ScopedUserPrefUpdate migration to modern base::Value https://chromium-review.googlesource.com/c/chromium/src/+/3407603 * 3378352: ozone/x11: move code from //ui/p/x11 to //ui/ozone/p/x11 https://chromium-review.googlesource.com/c/chromium/src/+/3378352 * 3370810: Delete chrome/service, AKA the Cloud Print service process. https://chromium-review.googlesource.com/c/chromium/src/+/3370810 * chore: bump chromium in DEPS to 100.0.4855.0 * chore: update patches * fixup! 3370810: Delete chrome/service, AKA the Cloud Print service process. * revert 3348007 to fix windows build * 3318572: [Code health] Fix gn check errors in //extensions/browser:* https://chromium-review.googlesource.com/c/chromium/src/+/3318572 * fix printing.patch * fix iwyu issue * 3408515: win: Make ShorcutOperation an enum class and modernize names https://chromium-review.googlesource.com/c/chromium/src/+/3408515 * 3388333: [UIA] Remove dead code accessibility_misc_utils.h/cc https://chromium-review.googlesource.com/c/chromium/src/+/3388333 * fix windows build? i hope * patch gn visibility of //ui/ozone/platform/x11 * missing include base/logging.h * use BUILDFLAG for USE_NSS_CERTS https://chromium-review.googlesource.com/c/chromium/src/+/3379123 * defined(OS_*) ==> BUILDFLAG(IS_*) https://bugs.chromium.org/p/chromium/issues/detail?id=1234043 * fixup! 3404768: Remove ALLOW_UNUSED macros * another attempt to fix windows build * temporarily disable the custom scheme service worker test https://github.com/electron/electron/issues/32664 * fix loading mv3 extensions not sure what cl broke this unfort. * fixup! 3404768: Remove ALLOW_UNUSED macros * patch nan https://chromium-review.googlesource.com/c/v8/v8/+/3395880 * fix node test * fix nullptr in FindPdfFrame * patch perfetto to fix build issue on win-ia32 https://source.chromium.org/chromium/_/android/platform/external/perfetto.git/+/bc44c3c7533c00e56f88c06c592d634aecc884be * fix build for linux-x64-testing-no-run-as-node * fix patch * skip <webview>.capturePage() test https://github.com/electron/electron/issues/32705 * test: fix failing tests of focus/blur events of WebContents (#32711) * inherit stdio from app module test child processes this prevents them from timing out due to full stdout buffers * test to see if we can get better logs on windows ci * try again for appveyor log things * skip contentTracing tests on ia32 * ci: disable gpu compositing * drop applied patch * fix merge fail * Revert "ci: disable gpu compositing" This reverts commit 0344129fcb19ea3e87e06c1110d751f22eba3fec. Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: John Kleinschmidt <jkleinsc@github.com> Co-authored-by: VerteDinde <khammond@slack-corp.com> Co-authored-by: VerteDinde <vertedinde@electronjs.org> Co-authored-by: Jeremy Rose <jeremya@chromium.org> Co-authored-by: Jeremy Rose <nornagon@nornagon.net> Co-authored-by: Cheng Zhao <zcbenz@gmail.com> Co-authored-by: deepak1556 <hop2deep@gmail.com>
2022-02-10 02:58:52 +00:00
#if BUILDFLAG(IS_LINUX)
#include "shell/browser/linux/unity_service.h"
#include "ui/gtk/gtk_util.h" // nogncheck
#endif
2014-01-02 14:47:54 +00:00
namespace electron {
namespace {
2017-10-07 03:32:46 +00:00
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 [[maybe_unused, nodiscard]] LaunchXdgUtilityScopedAllowBaseSyncPrimitives
: public base::ScopedAllowBaseSyncPrimitivesForTesting {};
2017-10-07 03:32:46 +00:00
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;
options.fds_to_remap.emplace_back(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;
LaunchXdgUtilityScopedAllowBaseSyncPrimitives allow_base_sync_primitives;
2017-10-07 03:32:46 +00:00
return process.WaitForExit(exit_code);
}
std::optional<std::string> GetXdgAppOutput(
const std::vector<std::string>& argv) {
std::string reply;
int success_code;
chore: bump chromium to 110.0.5415.0 (main) (#36186) * chore: bump chromium in DEPS to 109.0.5386.0 * chore: bump chromium in DEPS to 109.0.5388.0 * chore: bump chromium in DEPS to 109.0.5390.0 * chore: bump chromium in DEPS to 109.0.5392.0 * chore: bump chromium in DEPS to 109.0.5394.0 * chore: bump chromium in DEPS to 109.0.5396.0 * chore: bump chromium in DEPS to 109.0.5398.0 * chore: bump chromium in DEPS to 109.0.5400.0 * chore: update galactus * chore: bump chromium in DEPS to 109.0.5402.0 * chore: bump chromium in DEPS to 109.0.5403.0 * chore: bump chromium in DEPS to 109.0.5406.0 * chore: update patches * 4004247: Delete unused DocumentWebContentsDelegate Ref: https://chromium-review.googlesource.com/c/chromium/src/+/4004247 * chore: bump chromium in DEPS to 109.0.5408.1 * chore: update patches * 3949284: Support pkey debug mode without pkey 0 access Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3949284 * chore: bump chromium in DEPS to 109.0.5410.0 * chore: update patches * 4000944: [Extensions] Create an API directory in //chrome/renderer/extensions Ref: https://chromium-review.googlesource.com/c/chromium/src/+/4000944 * 3988524: Remove DocumentOverlayWindowViews | https://chromium-review.googlesource.com/c/chromium/src/+/3988524 Co-authored-by: George Xu <33054982+georgexu99@users.noreply.github.com> * chore: bump chromium in DEPS to 109.0.5412.0 * chore: update patches * 3984022: Add AddChildWindowToBrowser to DisplayClient mojo interface Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3984022 * 3957079: Delete the CryptoToken component extension and internal API Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3957079 * 4004421: Migreate ScopedAllowIO to ScopedAllowBlocking Ref: https://chromium-review.googlesource.com/c/chromium/src/+/4004421 Co-authored-by: George Xu <georgexu99@users.noreply.github.com> * chore: bump chromium in DEPS to 109.0.5414.0 * chore: update patches * 4016180: Split PPAPI Mojo interfaces out of RenderFrameHostImpl. Ref: https://chromium-review.googlesource.com/c/chromium/src/+/4016180 * 3970838: [MPArch] Convert HostZoomMap and ZoomController off of RenderViewHost ids Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3970838 * 3997795: Don't add Chromium as a login item Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3997795 * 3993482: Remove RefCountedString::TakeString Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3993482 * 3990749: Allow forward-declared sources in base::ScopedObservation<> Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3990749 * fixup! 3957079: Delete the CryptoToken component extension and internal API * chore: bump chromium in DEPS to 110.0.5415.0 * 3883790: Move devtools_frame_token to the RenderFrameHost, to preserve RFH identity across MPArch activations. https://chromium-review.googlesource.com/c/chromium/src/+/3883790 * 4022205: Move license tooling into //tools/licenses https://chromium-review.googlesource.com/c/chromium/src/+/4022205 * chore: fixup patch indices * fixup! 3957079: Delete the CryptoToken component extension and internal API * 4008687: Finish ScopedAllowIO migration https://chromium-review.googlesource.com/c/chromium/src/+/4008687 * 3991548: Move WindowButtonOrderObserver and WindowFrameAction to LinuxUi https://chromium-review.googlesource.com/c/chromium/src/+/3991548 * fixup! 3984022: Add AddChildWindowToBrowser to DisplayClient mojo interface * 4016595: Migrate non-default ScopedObservation<> instantiations to ScopedObservationTraits<> in chrome/browser/ https://chromium-review.googlesource.com/c/chromium/src/+/4016595 * 4000481: Rename :chromedriver to :chromedriver_server Ref: https://chromium-review.googlesource.com/c/chromium/src/+/4000481 * 4008687: Finish ScopedAllowIO migration https://chromium-review.googlesource.com/c/chromium/src/+/4008687 * 3988524: Remove DocumentOverlayWindowViews https://chromium-review.googlesource.com/c/chromium/src/+/3988524 * fixup! 3997795: Don't add Chromium as a login item * chore: fixup patches * 3996872: Plumb input event task runner to EventFactoryEvdev https://chromium-review.googlesource.com/c/chromium/src/+/3996872 * 4014994: Enable SiteIsolationForGuests by default. https://chromium-review.googlesource.com/c/chromium/src/+/4014994 * chore: adopt new thread restrictions api for //electron (#36357) chore: add thread blocking api * fixup! 4014994: Enable SiteIsolationForGuests by default. * pull parent HWND for dialogs on ui thread * chore: set parent_window in MessageBoxSettings * chore: remove redundant patch * chore: revert accidental deletion * chore: update patches Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: Samuel Attard <sattard@salesforce.com> Co-authored-by: Keeley Hammond <khammond@slack-corp.com> Co-authored-by: VerteDinde <vertedinde@electronjs.org> Co-authored-by: George Xu <33054982+georgexu99@users.noreply.github.com> Co-authored-by: George Xu <georgexu99@users.noreply.github.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> Co-authored-by: Robo <hop2deep@gmail.com> Co-authored-by: Jeremy Rose <jeremya@chromium.org> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com>
2022-11-17 19:59:23 +00:00
ScopedAllowBlockingForElectron allow_blocking;
bool ran_ok = base::GetAppOutputWithExitCode(base::CommandLine(argv), &reply,
&success_code);
if (!ran_ok || success_code != EXIT_SUCCESS)
return std::optional<std::string>();
return std::make_optional(reply);
}
2017-10-07 03:32:46 +00:00
bool SetDefaultWebClient(const std::string& protocol) {
auto env = base::Environment::Create();
2017-10-07 03:32:46 +00:00
std::vector<std::string> argv = {kXdgSettings, "set"};
2017-10-07 03:32:46 +00:00
if (!protocol.empty()) {
argv.emplace_back(kXdgSettingsDefaultSchemeHandler);
argv.emplace_back(protocol);
2017-10-07 03:32:46 +00:00
}
std::string desktop_name;
if (!env->GetVar("CHROME_DESKTOP", &desktop_name)) {
return false;
}
argv.emplace_back(desktop_name);
2017-10-07 03:32:46 +00:00
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
} // namespace
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
2016-08-16 05:54:30 +00:00
bool Browser::SetAsDefaultProtocolClient(const std::string& protocol,
2020-07-28 23:43:43 +00:00
gin::Arguments* args) {
2017-10-03 15:10:38 +00:00
return SetDefaultWebClient(protocol);
}
2017-10-05 04:30:14 +00:00
bool Browser::IsDefaultProtocolClient(const std::string& protocol,
2020-07-28 23:43:43 +00:00
gin::Arguments* args) {
auto env = base::Environment::Create();
2018-04-18 01:55:30 +00:00
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};
// Allow any reply that starts with "yes".
const std::optional<std::string> output = GetXdgAppOutput(argv);
return output && output->starts_with("yes");
}
// Todo implement
bool Browser::RemoveAsDefaultProtocolClient(const std::string& protocol,
2020-07-28 23:43:43 +00:00
gin::Arguments* args) {
2016-04-25 05:17:01 +00:00
return false;
}
std::u16string Browser::GetApplicationNameForProtocol(const GURL& url) {
const std::vector<std::string> argv = {
"xdg-mime", "query", "default",
perf: prefer GURL string_view getters (#43471) * chore: avoid double-call to url.scheme() in WebContentsZoomController::SetZoomMode() Co-authored-by: Charles Kerr <charles@charleskerr.com> * perf: use gurl.scheme_piece() in GetAppInfoHelperForProtocol() Co-authored-by: Charles Kerr <charles@charleskerr.com> * perf: use gurl.scheme_piece() in Browser::GetApplicationNameForProtocol() Co-authored-by: Charles Kerr <charles@charleskerr.com> * refactor: add std::less<> to HandlersMap This lets us search it using string_view keys Co-authored-by: Charles Kerr <charles@charleskerr.com> * refactor: ProtocolRegistry::FindRegistered() now takes a std::string_view Co-authored-by: Charles Kerr <charles@charleskerr.com> * perf: use gurl.scheme_piece() in InspectableWebContents::LoadNetworkResource() Co-authored-by: Charles Kerr <charles@charleskerr.com> * refactor: ProtocolRegistry::FindIntercepted() now takes a std::string_view Co-authored-by: Charles Kerr <charles@charleskerr.com> * perf: use gurl.scheme_piece() in SimpleURLLoaderWrapper::GetURLLoaderFactoryForURL() Co-authored-by: Charles Kerr <charles@charleskerr.com> * perf: use gurl.scheme_piece() in ProxyingURLLoaderFactory::CreateLoaderAndStart() Co-authored-by: Charles Kerr <charles@charleskerr.com> * perf: use gurl.host_piece() in ElectronWebUIControllerFactory::GetWebUIType() Co-authored-by: Charles Kerr <charles@charleskerr.com> * perf: use gurl.host_piece() in ElectronWebUIControllerFactory::CreateWebUIControllerForURL() Co-authored-by: Charles Kerr <charles@charleskerr.com> --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Charles Kerr <charles@charleskerr.com>
2024-08-24 01:58:59 +00:00
base::StrCat({"x-scheme-handler/", url.scheme_piece()})};
return base::ASCIIToUTF16(GetXdgAppOutput(argv).value_or(std::string()));
}
bool Browser::SetBadgeCount(std::optional<int> count) {
if (IsUnityRunning() && count.has_value()) {
unity::SetDownloadCount(count.value());
badge_count_ = count.value();
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) {}
v8::Local<v8::Value> Browser::GetLoginItemSettings(
2017-03-29 19:29:52 +00:00
const LoginItemSettings& options) {
LoginItemSettings settings;
return gin::ConvertToV8(JavascriptEnvironment::GetIsolate(), settings);
}
2014-01-02 14:47:54 +00:00
std::string Browser::GetExecutableFileVersion() const {
2018-10-24 10:49:10 +00:00
return GetApplicationVersion();
2014-01-02 14:47:54 +00:00
}
std::string Browser::GetExecutableFileProductName() const {
2018-10-24 10:49:10 +00:00
return GetApplicationName();
2014-01-02 14:47:54 +00:00
}
2016-07-01 08:39:01 +00:00
bool Browser::IsUnityRunning() {
return unity::IsRunning();
}
2019-03-14 20:39:52 +00:00
bool Browser::IsEmojiPanelSupported() {
return false;
}
void Browser::ShowAboutPanel() {
const auto& opts = about_panel_options_;
GtkWidget* dialogWidget = gtk_about_dialog_new();
GtkAboutDialog* dialog = GTK_ABOUT_DIALOG(dialogWidget);
const std::string* str;
const base::Value::List* list;
if ((str = opts.FindString("applicationName"))) {
gtk_about_dialog_set_program_name(dialog, str->c_str());
}
if ((str = opts.FindString("applicationVersion"))) {
gtk_about_dialog_set_version(dialog, str->c_str());
}
if ((str = opts.FindString("copyright"))) {
gtk_about_dialog_set_copyright(dialog, str->c_str());
}
if ((str = opts.FindString("website"))) {
gtk_about_dialog_set_website(dialog, str->c_str());
}
if ((str = opts.FindString("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 ((list = opts.FindList("authors"))) {
std::vector<const char*> cstrs;
for (const auto& authorVal : *list) {
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());
}
}
// destroy the widget when it closes
g_signal_connect_swapped(dialogWidget, "response",
G_CALLBACK(gtk_widget_destroy), dialogWidget);
gtk_widget_show_all(dialogWidget);
}
void Browser::SetAboutPanelOptions(base::Value::Dict options) {
about_panel_options_ = std::move(options);
}
2014-01-02 14:47:54 +00:00
} // namespace electron