electron/shell/browser/browser_mac.mm

536 lines
18 KiB
Text
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
// found in the LICENSE file.
#include "shell/browser/browser.h"
#include <memory>
#include <string>
#include <utility>
#include "base/mac/bundle_locations.h"
#include "base/mac/foundation_util.h"
2016-07-06 18:43:44 +00:00
#include "base/mac/mac_util.h"
#include "base/mac/scoped_cftyperef.h"
2016-07-01 08:39:01 +00:00
#include "base/strings/string_number_conversions.h"
2016-07-02 01:36:11 +00:00
#include "base/strings/sys_string_conversions.h"
2016-05-23 15:49:46 +00:00
#include "net/base/mac/url_conversions.h"
#include "shell/browser/badging/badge_manager.h"
#include "shell/browser/mac/dict_util.h"
#include "shell/browser/mac/electron_application.h"
#include "shell/browser/mac/electron_application_delegate.h"
#include "shell/browser/native_window.h"
#include "shell/browser/window_list.h"
#include "shell/common/api/electron_api_native_image.h"
#include "shell/common/application_info.h"
#include "shell/common/gin_converters/image_converter.h"
#include "shell/common/gin_helper/arguments.h"
#include "shell/common/gin_helper/dictionary.h"
#include "shell/common/gin_helper/error_thrower.h"
#include "shell/common/gin_helper/promise.h"
#include "shell/common/platform_util.h"
#include "ui/gfx/image/image.h"
2016-05-23 15:49:46 +00:00
#include "url/gurl.h"
namespace electron {
namespace {
NSString* GetAppPathForProtocol(const GURL& url) {
NSURL* ns_url = [NSURL
URLWithString:base::SysUTF8ToNSString(url.possibly_invalid_spec())];
base::ScopedCFTypeRef<CFErrorRef> out_err;
base::ScopedCFTypeRef<CFURLRef> openingApp(LSCopyDefaultApplicationURLForURL(
(CFURLRef)ns_url, kLSRolesAll, out_err.InitializeInto()));
if (out_err) {
// likely kLSApplicationNotFoundErr
return nullptr;
}
NSString* app_path = [base::mac::CFToNSCast(openingApp.get()) path];
return app_path;
}
gfx::Image GetApplicationIconForProtocol(NSString* _Nonnull app_path) {
NSImage* image = [[NSWorkspace sharedWorkspace] iconForFile:app_path];
gfx::Image icon(image);
return icon;
}
std::u16string GetAppDisplayNameForProtocol(NSString* app_path) {
NSString* app_display_name =
[[NSFileManager defaultManager] displayNameAtPath:app_path];
return base::SysNSStringToUTF16(app_display_name);
}
} // namespace
v8::Local<v8::Promise> Browser::GetApplicationInfoForProtocol(
v8::Isolate* isolate,
const GURL& url) {
gin_helper::Promise<gin_helper::Dictionary> promise(isolate);
v8::Local<v8::Promise> handle = promise.GetHandle();
gin_helper::Dictionary dict = gin::Dictionary::CreateEmpty(isolate);
NSString* ns_app_path = GetAppPathForProtocol(url);
if (!ns_app_path) {
promise.RejectWithErrorMessage(
"Unable to retrieve installation path to app");
return handle;
}
std::u16string app_path = base::SysNSStringToUTF16(ns_app_path);
std::u16string app_display_name = GetAppDisplayNameForProtocol(ns_app_path);
gfx::Image app_icon = GetApplicationIconForProtocol(ns_app_path);
dict.Set("name", app_display_name);
dict.Set("path", app_path);
dict.Set("icon", app_icon);
promise.Resolve(dict);
return handle;
}
void Browser::SetShutdownHandler(base::RepeatingCallback<bool()> handler) {
[[AtomApplication sharedApplication] setShutdownHandler:std::move(handler)];
2018-02-05 07:13:35 +00:00
}
2020-07-28 23:43:43 +00:00
void Browser::Focus(gin::Arguments* args) {
gin_helper::Dictionary opts;
bool steal_focus = false;
if (args->GetNext(&opts)) {
gin_helper::ErrorThrower thrower(args->isolate());
if (!opts.Get("steal", &steal_focus)) {
thrower.ThrowError(
"Expected options object to contain a 'steal' boolean property");
return;
}
}
[[AtomApplication sharedApplication] activateIgnoringOtherApps:steal_focus];
2013-05-30 11:24:47 +00:00
}
void Browser::Hide() {
[[AtomApplication sharedApplication] hide:nil];
}
2016-01-30 20:40:32 +00:00
void Browser::Show() {
[[AtomApplication sharedApplication] unhide:nil];
2016-01-30 20:40:32 +00:00
}
2014-11-17 05:05:06 +00:00
void Browser::AddRecentDocument(const base::FilePath& path) {
NSString* path_string = base::mac::FilePathToNSString(path);
if (!path_string)
return;
NSURL* u = [NSURL fileURLWithPath:path_string];
if (!u)
return;
2014-11-17 05:05:06 +00:00
[[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL:u];
}
2014-11-17 08:13:47 +00:00
void Browser::ClearRecentDocuments() {
[[NSDocumentController sharedDocumentController] clearRecentDocuments:nil];
2014-11-17 08:13:47 +00:00
}
2016-08-16 05:54:30 +00:00
bool Browser::RemoveAsDefaultProtocolClient(const std::string& protocol,
2020-07-28 23:43:43 +00:00
gin::Arguments* args) {
NSString* identifier = [base::mac::MainBundle() bundleIdentifier];
if (!identifier)
return false;
2016-08-16 07:40:44 +00:00
if (!Browser::IsDefaultProtocolClient(protocol, args))
return false;
NSString* protocol_ns = [NSString stringWithUTF8String:protocol.c_str()];
CFStringRef protocol_cf = base::mac::NSToCFCast(protocol_ns);
CFArrayRef bundleList = LSCopyAllHandlersForURLScheme(protocol_cf);
if (!bundleList) {
return false;
}
2016-06-18 13:26:26 +00:00
// On macOS, we can't query the default, but the handlers list seems to put
// Apple's defaults first, so we'll use the first option that isn't our bundle
CFStringRef other = nil;
2017-03-30 20:56:21 +00:00
for (CFIndex i = 0; i < CFArrayGetCount(bundleList); ++i) {
2018-04-20 18:47:04 +00:00
other =
base::mac::CFCast<CFStringRef>(CFArrayGetValueAtIndex(bundleList, i));
if (![identifier isEqualToString:(__bridge NSString*)other]) {
break;
}
}
2018-06-20 03:16:37 +00:00
// No other app was found set it to none instead of setting it back to itself.
if ([identifier isEqualToString:(__bridge NSString*)other]) {
other = base::mac::NSToCFCast(@"None");
}
OSStatus return_code = LSSetDefaultHandlerForURLScheme(protocol_cf, other);
return return_code == noErr;
}
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) {
if (protocol.empty())
return false;
NSString* identifier = [base::mac::MainBundle() bundleIdentifier];
if (!identifier)
return false;
NSString* protocol_ns = [NSString stringWithUTF8String:protocol.c_str()];
2018-04-20 18:47:04 +00:00
OSStatus return_code = LSSetDefaultHandlerForURLScheme(
base::mac::NSToCFCast(protocol_ns), base::mac::NSToCFCast(identifier));
return return_code == noErr;
}
2016-08-16 05:54:30 +00:00
bool Browser::IsDefaultProtocolClient(const std::string& protocol,
2020-07-28 23:43:43 +00:00
gin::Arguments* args) {
2016-04-25 05:17:01 +00:00
if (protocol.empty())
return false;
NSString* identifier = [base::mac::MainBundle() bundleIdentifier];
if (!identifier)
return false;
NSString* protocol_ns = [NSString stringWithUTF8String:protocol.c_str()];
2016-04-30 18:17:29 +00:00
base::ScopedCFTypeRef<CFStringRef> bundleId(
LSCopyDefaultHandlerForURLScheme(base::mac::NSToCFCast(protocol_ns)));
2016-04-25 05:17:01 +00:00
if (!bundleId)
return false;
2016-04-30 18:17:29 +00:00
// Ensure the comparison is case-insensitive
2016-04-25 05:17:01 +00:00
// as LS does not persist the case of the bundle id.
NSComparisonResult result =
[base::mac::CFToNSCast(bundleId) caseInsensitiveCompare:identifier];
2016-04-25 05:17:01 +00:00
return result == NSOrderedSame;
}
std::u16string Browser::GetApplicationNameForProtocol(const GURL& url) {
NSString* app_path = GetAppPathForProtocol(url);
if (!app_path) {
return std::u16string();
}
std::u16string app_display_name = GetAppDisplayNameForProtocol(app_path);
return app_display_name;
}
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: https://github.com/electron/electron/commit/95bfe6d08f65471394fb3005dbfa177cdf71210a * 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 08:05:04 +00:00
bool Browser::SetBadgeCount(absl::optional<int> count) {
DockSetBadgeText(!count.has_value() || count.value() != 0
? badging::BadgeManager::GetBadgeString(count)
: "");
if (count.has_value()) {
badge_count_ = count.value();
} else {
badge_count_ = 0;
}
return true;
2016-07-01 08:39:01 +00:00
}
2016-05-23 15:49:46 +00:00
void Browser::SetUserActivity(const std::string& type,
base::DictionaryValue user_info,
2020-07-28 23:43:43 +00:00
gin::Arguments* args) {
2016-05-23 15:49:46 +00:00
std::string url_string;
args->GetNext(&url_string);
[[AtomApplication sharedApplication]
setCurrentActivity:base::SysUTF8ToNSString(type)
2016-05-23 15:49:46 +00:00
withUserInfo:DictionaryValueToNSDictionary(user_info)
withWebpageURL:net::NSURLWithGURL(GURL(url_string))];
}
std::string Browser::GetCurrentActivityType() {
NSUserActivity* userActivity =
[[AtomApplication sharedApplication] getCurrentActivity];
return base::SysNSStringToUTF8(userActivity.activityType);
}
void Browser::InvalidateCurrentActivity() {
[[AtomApplication sharedApplication] invalidateCurrentActivity];
}
void Browser::ResignCurrentActivity() {
[[AtomApplication sharedApplication] resignCurrentActivity];
}
void Browser::UpdateCurrentActivity(const std::string& type,
base::DictionaryValue user_info) {
[[AtomApplication sharedApplication]
updateCurrentActivity:base::SysUTF8ToNSString(type)
withUserInfo:DictionaryValueToNSDictionary(user_info)];
}
bool Browser::WillContinueUserActivity(const std::string& type) {
bool prevent_default = false;
2017-09-14 07:12:34 +00:00
for (BrowserObserver& observer : observers_)
observer.OnWillContinueUserActivity(&prevent_default, type);
return prevent_default;
}
2017-09-14 07:12:34 +00:00
void Browser::DidFailToContinueUserActivity(const std::string& type,
const std::string& error) {
for (BrowserObserver& observer : observers_)
observer.OnDidFailToContinueUserActivity(type, error);
}
2016-05-23 15:49:46 +00:00
bool Browser::ContinueUserActivity(const std::string& type,
base::DictionaryValue user_info,
base::DictionaryValue details) {
bool prevent_default = false;
2017-01-24 03:34:39 +00:00
for (BrowserObserver& observer : observers_)
observer.OnContinueUserActivity(&prevent_default, type, user_info, details);
return prevent_default;
}
2017-09-14 07:12:34 +00:00
void Browser::UserActivityWasContinued(const std::string& type,
base::DictionaryValue user_info) {
for (BrowserObserver& observer : observers_)
observer.OnUserActivityWasContinued(type, user_info);
}
bool Browser::UpdateUserActivityState(const std::string& type,
base::DictionaryValue user_info) {
bool prevent_default = false;
for (BrowserObserver& observer : observers_)
observer.OnUpdateUserActivityState(&prevent_default, type, user_info);
return prevent_default;
}
Browser::LoginItemSettings Browser::GetLoginItemSettings(
2017-03-29 19:29:52 +00:00
const LoginItemSettings& options) {
2016-07-07 23:29:09 +00:00
LoginItemSettings settings;
#if defined(MAS_BUILD)
settings.open_at_login = platform_util::GetLoginItemEnabled();
#else
2018-04-20 18:47:04 +00:00
settings.open_at_login =
base::mac::CheckLoginItemStatus(&settings.open_as_hidden);
2016-07-07 23:29:09 +00:00
settings.restore_state = base::mac::WasLaunchedAsLoginItemRestoreState();
settings.opened_at_login = base::mac::WasLaunchedAsLoginOrResumeItem();
settings.opened_as_hidden = base::mac::WasLaunchedAsHiddenLoginItem();
#endif
2016-07-07 23:29:09 +00:00
return settings;
}
void RemoveFromLoginItems() {
chore: bump chromium to 096e5313aaf19dfa0c4710145c34d (master) (#26535) * chore: bump chromium in DEPS to 1d6b29cd85c1c3cba093b8b69b2727cc26eaac97 * update patches * chore: use 'libvulkan.so.1' in the linux manifests CL: https://chromium-review.googlesource.com/c/angle/angle/+/2538430 Upstream renamed libvulkan.so to libvulkan.so.1, so sync our manifests. * chore: update expected window-open default policy. CL: https://chromium-review.googlesource.com/c/chromium/src/+/2429247 Upstream CL contiues the work to make `strict-origin-when-cross-origin` the default referrer policy. This commit changes our window-open tests to expect that policy over the previous `no-referrer-when-downgrade`. * chore: bump chromium in DEPS to 69cb7c65ad845cdab1cd5f4256237e72fceba2dd * chore: re-export chromium patches No code changes; just line numbers. `git am` failed because the upstream changes were just large enough to require patching to fail w/o fuzzing. The broken patch was patches/chromium/feat_allow_disabling_blink_scheduler_throttling_per_renderview.patch * update patches * chore: bump chromium in DEPS to c6d97a240d30e5f5166856f5ae6ee14d95b9a4f0 * update patches * fixup! chore: update expected window-open default policy. * chore: disallow copying CppHeapCreateParams Experimental commit to resolve FTBS https://ci.appveyor.com/project/electron-bot/electron-ljo26/builds/36405680#L25345 which introduces a new struct CppHeapCreateParams that aggregates a vector of unique_ptrs. Our Windows CI is unhappy that this struct implicitly deletes its copy ctor, so this commit makes it explicit. Xref: https://chromium-review.googlesource.com/c/v8/v8/+/2536642 * update patches * chore: bump chromium in DEPS to 0df9a85ffa0ad4711b41a089842e40b87ba88055 * update patches * fixup! chore: bump chromium to ac06d6903a2c981ab90a8162f1ba0 (master) (#26499) * chore: update calls to gfx::RemoveAcceleratorChar. The call signature for gfx::RemoveAccelerator changed in https://chromium-review.googlesource.com/c/chromium/src/+/2546471 . This commit updates use to match that. * chore: bump chromium in DEPS to 43d6c496251e08d3781bfadbe9727688551f74a9 * update patches * chore: bump chromium in DEPS to 1fb5c9825be4e2271c4fef0e802f5d970b32f62f * update patches * chore: bump chromium in DEPS to 8a1f078d67825e727a598b89a8924699df8d3850 * chore: bump chromium in DEPS to 28ff715b3a97d8cedc143bad671edb08b6de5fc2 * chore: update patches * Remove most service manifest remnants from Content https://chromium-review.googlesource.com/c/chromium/src/+/2296482 * Reland "Portals: Fix a11y for orphaned portals" https://chromium-review.googlesource.com/c/chromium/src/+/2542812 * Convert CallbackList::Subscription to a standalone class. https://chromium-review.googlesource.com/c/chromium/src/+/2522860 * fix: actually apply the zlib patch * chore: bump chromium in DEPS to 75b464e6357190ca302ba9ce8f8c2bf5a3b709ae * chore: update patches * chore: bump chromium@b884b9b2f647c59a75f5d2055030afa33d50ca10 * chore: bump chromium in DEPS to 829261dadcefdc54ce5fdf7c5fac2929786a63ce * chore: bump chromium in DEPS to 5df3e69605c7c0130374aaccb91fc4726a558db2 * chore: bump chromium in DEPS to 22db748d5b7b90f87e6e97ef4c92a727ac753ea4 * chore: bump chromium in DEPS to 1475df80282b7eeeb0e153d8375bfe651f083bf8 * chore: bump chromium in DEPS to 6d34fe9e9b7386edd90574617bfa4008de972d72 * chore: update patches * Disable CertVerifierService for now 2559260: Enable CertVerifierService by default | https://chromium-review.googlesource.com/c/chromium/src/+/2559260 * Remove force_ignore_site_for_cookies until we figure out what to do instead 2499162: Remove |force_ignore_site_for_cookies| from IPCs (e.g. ResourceRequest). | https://chromium-review.googlesource.com/c/chromium/src/+/2499162 * chore: bump chromium in DEPS to 95aeb1c59ebc03d19ba077b0cd707463d1b2865e * update patches * Set site_for_cookies to request url so that URLLoader::ShouldForceIgnoreSiteForCookies returns true * 2490383: a11y inspect reorg: implement accessible tree formatter factory https://chromium-review.googlesource.com/c/chromium/src/+/2490383 * 2485887: [Extensions][web_accessible_resources] Use |matches|. https://chromium-review.googlesource.com/c/chromium/src/+/2485887 * update v8 headers * chore: bump chromium in DEPS to 38587dc379a8cf4d4a13e482a6e89f2fe681144e * update patches * 2555005: [api] Simplify ScriptOrigin https://chromium-review.googlesource.com/c/v8/v8/+/2555005 * 2563553: Remove Flash from PermissionRequestTypes and PermissionTypes. https://chromium-review.googlesource.com/c/chromium/src/+/2563553 * 2546146: Remove browser-hosted InterfaceProvider https://chromium-review.googlesource.com/c/chromium/src/+/2546146 * Actually apply nan patch * update patches * chore: bump chromium in DEPS to 6718d4b50c9db975c5642ca5b68e8dc7ee1b7615 * update patches * 2546146: Remove browser-hosted InterfaceProvider https://chromium-review.googlesource.com/c/chromium/src/+/2546146 * chore: bump chromium in DEPS to 338cc300e3fe3a4cb4883e9ccdc34a32f3dfe034 * chore: bump chromium in DEPS to d9baeb1d192c23ceb1e1c4bbe6af98380b263bc1 * chore: bump chromium in DEPS to 3ca3051932683739b304e721cc394b6c66f841fe * chore: bump chromium in DEPS to 89292a4ae29096e5313aaf19dfa0c4710145c34d * 2571639: mac: Remove code to support OS X 10.10 in //sandbox https://chromium-review.googlesource.com/c/chromium/src/+/2571639 * Fixup patch indices * Do not build MTLManagedObjectAdapter It's been removed in newer Mantle versions and uses a deprecated enum * update patches * Remove sendToAll https://github.com/electron/electron/pull/26771 * 2569367: Remove dead fullscreen code in RenderWidgetHostView and friends https://chromium-review.googlesource.com/c/chromium/src/+/2569367 * Remove deprecated performFileOperation usage * 2568359: mac: Ignore Wdeprecated-declarations for LSSharedFileList* functions. https://chromium-review.googlesource.com/c/chromium/src/+/2568359 * 2561401: Add OutputPresenterX11 which uses X11 present extension. https://chromium-review.googlesource.com/c/chromium/src/+/2561401 * 2565511: [objects] Remove MakeExternal case for uncached internal strings https://chromium-review.googlesource.com/c/v8/v8/+/2565511 * fixup: Add disconnect logic to ElectronBrowserHandlerImpl * Allow local networking override for ATS https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html * Refactor: clean up rfh getters in ElectronBrowserHandlerImpl * Update patches * Remove unneeded BindTo * Don't assign ElectronBrowserHandlerImpl at all Co-authored-by: Charles Kerr <charles@charleskerr.com> Co-authored-by: deepak1556 <hop2deep@gmail.com> Co-authored-by: John Kleinschmidt <jkleinsc@github.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>
2020-12-14 18:57:36 +00:00
#pragma clang diagnostic push // https://crbug.com/1154377
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
// logic to find the login item copied from GetLoginItemForApp in
// base/mac/mac_util.mm
base::ScopedCFTypeRef<LSSharedFileListRef> login_items(
LSSharedFileListCreate(NULL, kLSSharedFileListSessionLoginItems, NULL));
if (!login_items.get()) {
LOG(ERROR) << "Couldn't get a Login Items list.";
return;
}
base::scoped_nsobject<NSArray> login_items_array(
base::mac::CFToNSCast(LSSharedFileListCopySnapshot(login_items, NULL)));
NSURL* url = [NSURL fileURLWithPath:[base::mac::MainBundle() bundlePath]];
for (NSUInteger i = 0; i < [login_items_array count]; ++i) {
LSSharedFileListItemRef item =
reinterpret_cast<LSSharedFileListItemRef>(login_items_array[i]);
base::ScopedCFTypeRef<CFErrorRef> error;
CFURLRef item_url_ref =
LSSharedFileListItemCopyResolvedURL(item, 0, error.InitializeInto());
if (!error && item_url_ref) {
base::ScopedCFTypeRef<CFURLRef> item_url(item_url_ref);
if (CFEqual(item_url, url)) {
LSSharedFileListItemRemove(login_items, item);
return;
}
}
}
chore: bump chromium to 096e5313aaf19dfa0c4710145c34d (master) (#26535) * chore: bump chromium in DEPS to 1d6b29cd85c1c3cba093b8b69b2727cc26eaac97 * update patches * chore: use 'libvulkan.so.1' in the linux manifests CL: https://chromium-review.googlesource.com/c/angle/angle/+/2538430 Upstream renamed libvulkan.so to libvulkan.so.1, so sync our manifests. * chore: update expected window-open default policy. CL: https://chromium-review.googlesource.com/c/chromium/src/+/2429247 Upstream CL contiues the work to make `strict-origin-when-cross-origin` the default referrer policy. This commit changes our window-open tests to expect that policy over the previous `no-referrer-when-downgrade`. * chore: bump chromium in DEPS to 69cb7c65ad845cdab1cd5f4256237e72fceba2dd * chore: re-export chromium patches No code changes; just line numbers. `git am` failed because the upstream changes were just large enough to require patching to fail w/o fuzzing. The broken patch was patches/chromium/feat_allow_disabling_blink_scheduler_throttling_per_renderview.patch * update patches * chore: bump chromium in DEPS to c6d97a240d30e5f5166856f5ae6ee14d95b9a4f0 * update patches * fixup! chore: update expected window-open default policy. * chore: disallow copying CppHeapCreateParams Experimental commit to resolve FTBS https://ci.appveyor.com/project/electron-bot/electron-ljo26/builds/36405680#L25345 which introduces a new struct CppHeapCreateParams that aggregates a vector of unique_ptrs. Our Windows CI is unhappy that this struct implicitly deletes its copy ctor, so this commit makes it explicit. Xref: https://chromium-review.googlesource.com/c/v8/v8/+/2536642 * update patches * chore: bump chromium in DEPS to 0df9a85ffa0ad4711b41a089842e40b87ba88055 * update patches * fixup! chore: bump chromium to ac06d6903a2c981ab90a8162f1ba0 (master) (#26499) * chore: update calls to gfx::RemoveAcceleratorChar. The call signature for gfx::RemoveAccelerator changed in https://chromium-review.googlesource.com/c/chromium/src/+/2546471 . This commit updates use to match that. * chore: bump chromium in DEPS to 43d6c496251e08d3781bfadbe9727688551f74a9 * update patches * chore: bump chromium in DEPS to 1fb5c9825be4e2271c4fef0e802f5d970b32f62f * update patches * chore: bump chromium in DEPS to 8a1f078d67825e727a598b89a8924699df8d3850 * chore: bump chromium in DEPS to 28ff715b3a97d8cedc143bad671edb08b6de5fc2 * chore: update patches * Remove most service manifest remnants from Content https://chromium-review.googlesource.com/c/chromium/src/+/2296482 * Reland "Portals: Fix a11y for orphaned portals" https://chromium-review.googlesource.com/c/chromium/src/+/2542812 * Convert CallbackList::Subscription to a standalone class. https://chromium-review.googlesource.com/c/chromium/src/+/2522860 * fix: actually apply the zlib patch * chore: bump chromium in DEPS to 75b464e6357190ca302ba9ce8f8c2bf5a3b709ae * chore: update patches * chore: bump chromium@b884b9b2f647c59a75f5d2055030afa33d50ca10 * chore: bump chromium in DEPS to 829261dadcefdc54ce5fdf7c5fac2929786a63ce * chore: bump chromium in DEPS to 5df3e69605c7c0130374aaccb91fc4726a558db2 * chore: bump chromium in DEPS to 22db748d5b7b90f87e6e97ef4c92a727ac753ea4 * chore: bump chromium in DEPS to 1475df80282b7eeeb0e153d8375bfe651f083bf8 * chore: bump chromium in DEPS to 6d34fe9e9b7386edd90574617bfa4008de972d72 * chore: update patches * Disable CertVerifierService for now 2559260: Enable CertVerifierService by default | https://chromium-review.googlesource.com/c/chromium/src/+/2559260 * Remove force_ignore_site_for_cookies until we figure out what to do instead 2499162: Remove |force_ignore_site_for_cookies| from IPCs (e.g. ResourceRequest). | https://chromium-review.googlesource.com/c/chromium/src/+/2499162 * chore: bump chromium in DEPS to 95aeb1c59ebc03d19ba077b0cd707463d1b2865e * update patches * Set site_for_cookies to request url so that URLLoader::ShouldForceIgnoreSiteForCookies returns true * 2490383: a11y inspect reorg: implement accessible tree formatter factory https://chromium-review.googlesource.com/c/chromium/src/+/2490383 * 2485887: [Extensions][web_accessible_resources] Use |matches|. https://chromium-review.googlesource.com/c/chromium/src/+/2485887 * update v8 headers * chore: bump chromium in DEPS to 38587dc379a8cf4d4a13e482a6e89f2fe681144e * update patches * 2555005: [api] Simplify ScriptOrigin https://chromium-review.googlesource.com/c/v8/v8/+/2555005 * 2563553: Remove Flash from PermissionRequestTypes and PermissionTypes. https://chromium-review.googlesource.com/c/chromium/src/+/2563553 * 2546146: Remove browser-hosted InterfaceProvider https://chromium-review.googlesource.com/c/chromium/src/+/2546146 * Actually apply nan patch * update patches * chore: bump chromium in DEPS to 6718d4b50c9db975c5642ca5b68e8dc7ee1b7615 * update patches * 2546146: Remove browser-hosted InterfaceProvider https://chromium-review.googlesource.com/c/chromium/src/+/2546146 * chore: bump chromium in DEPS to 338cc300e3fe3a4cb4883e9ccdc34a32f3dfe034 * chore: bump chromium in DEPS to d9baeb1d192c23ceb1e1c4bbe6af98380b263bc1 * chore: bump chromium in DEPS to 3ca3051932683739b304e721cc394b6c66f841fe * chore: bump chromium in DEPS to 89292a4ae29096e5313aaf19dfa0c4710145c34d * 2571639: mac: Remove code to support OS X 10.10 in //sandbox https://chromium-review.googlesource.com/c/chromium/src/+/2571639 * Fixup patch indices * Do not build MTLManagedObjectAdapter It's been removed in newer Mantle versions and uses a deprecated enum * update patches * Remove sendToAll https://github.com/electron/electron/pull/26771 * 2569367: Remove dead fullscreen code in RenderWidgetHostView and friends https://chromium-review.googlesource.com/c/chromium/src/+/2569367 * Remove deprecated performFileOperation usage * 2568359: mac: Ignore Wdeprecated-declarations for LSSharedFileList* functions. https://chromium-review.googlesource.com/c/chromium/src/+/2568359 * 2561401: Add OutputPresenterX11 which uses X11 present extension. https://chromium-review.googlesource.com/c/chromium/src/+/2561401 * 2565511: [objects] Remove MakeExternal case for uncached internal strings https://chromium-review.googlesource.com/c/v8/v8/+/2565511 * fixup: Add disconnect logic to ElectronBrowserHandlerImpl * Allow local networking override for ATS https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html * Refactor: clean up rfh getters in ElectronBrowserHandlerImpl * Update patches * Remove unneeded BindTo * Don't assign ElectronBrowserHandlerImpl at all Co-authored-by: Charles Kerr <charles@charleskerr.com> Co-authored-by: deepak1556 <hop2deep@gmail.com> Co-authored-by: John Kleinschmidt <jkleinsc@github.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>
2020-12-14 18:57:36 +00:00
#pragma clang diagnostic pop
}
void Browser::SetLoginItemSettings(LoginItemSettings settings) {
#if defined(MAS_BUILD)
if (!platform_util::SetLoginItemEnabled(settings.open_at_login)) {
LOG(ERROR) << "Unable to set login item enabled on sandboxed app.";
}
#else
if (settings.open_at_login) {
2016-07-07 23:29:09 +00:00
base::mac::AddToLoginItems(settings.open_as_hidden);
} else {
RemoveFromLoginItems();
}
#endif
}
2013-12-05 02:26:01 +00:00
std::string Browser::GetExecutableFileVersion() const {
2018-10-24 10:49:10 +00:00
return GetApplicationVersion();
}
std::string Browser::GetExecutableFileProductName() const {
2018-10-24 10:49:10 +00:00
return GetApplicationName();
}
2013-08-06 08:19:56 +00:00
int Browser::DockBounce(BounceType type) {
return [[AtomApplication sharedApplication]
requestUserAttention:static_cast<NSRequestUserAttentionType>(type)];
2013-08-06 08:19:56 +00:00
}
void Browser::DockCancelBounce(int request_id) {
[[AtomApplication sharedApplication] cancelUserAttentionRequest:request_id];
2013-08-06 08:19:56 +00:00
}
void Browser::DockSetBadgeText(const std::string& label) {
NSDockTile* tile = [[AtomApplication sharedApplication] dockTile];
2013-08-06 08:19:56 +00:00
[tile setBadgeLabel:base::SysUTF8ToNSString(label)];
}
void Browser::DockDownloadFinished(const std::string& filePath) {
[[NSDistributedNotificationCenter defaultCenter]
2018-04-20 18:47:04 +00:00
postNotificationName:@"com.apple.DownloadFileFinished"
object:base::SysUTF8ToNSString(filePath)];
}
2013-08-06 08:39:31 +00:00
std::string Browser::DockGetBadgeText() {
NSDockTile* tile = [[AtomApplication sharedApplication] dockTile];
2013-08-06 08:39:31 +00:00
return base::SysNSStringToUTF8([tile badgeLabel]);
}
void Browser::DockHide() {
// Transforming application state from UIElement to Foreground is an
// asyncronous operation, and unfortunately there is currently no way to know
// when it is finished.
// So if we call DockHide => DockShow => DockHide => DockShow in a very short
// time, we would triger a bug of macOS that, there would be multiple dock
// icons of the app left in system.
// To work around this, we make sure DockHide does nothing if it is called
// immediately after DockShow. After some experiments, 1 second seems to be
// a proper interval.
if (!last_dock_show_.is_null() &&
base::Time::Now() - last_dock_show_ < base::TimeDelta::FromSeconds(1)) {
return;
}
for (auto* const& window : WindowList::GetWindows())
[window->GetNativeWindow().GetNativeNSWindow() setCanHide:NO];
2018-04-20 18:47:04 +00:00
ProcessSerialNumber psn = {0, kCurrentProcess};
TransformProcessType(&psn, kProcessTransformToUIElementApplication);
}
2016-08-01 22:22:37 +00:00
bool Browser::DockIsVisible() {
// Because DockShow has a slight delay this may not be true immediately
// after that call.
2018-04-20 18:47:04 +00:00
return ([[NSRunningApplication currentApplication] activationPolicy] ==
NSApplicationActivationPolicyRegular);
2016-08-01 22:22:37 +00:00
}
v8::Local<v8::Promise> Browser::DockShow(v8::Isolate* isolate) {
last_dock_show_ = base::Time::Now();
gin_helper::Promise<void> promise(isolate);
v8::Local<v8::Promise> handle = promise.GetHandle();
BOOL active = [[NSRunningApplication currentApplication] isActive];
2018-04-20 18:47:04 +00:00
ProcessSerialNumber psn = {0, kCurrentProcess};
if (active) {
2015-12-21 02:52:49 +00:00
// Workaround buggy behavior of TransformProcessType.
// http://stackoverflow.com/questions/7596643/
NSArray* runningApps = [NSRunningApplication
runningApplicationsWithBundleIdentifier:@"com.apple.dock"];
for (NSRunningApplication* app in runningApps) {
[app activateWithOptions:NSApplicationActivateIgnoringOtherApps];
break;
}
__block gin_helper::Promise<void> p = std::move(promise);
2015-12-21 02:52:49 +00:00
dispatch_time_t one_ms = dispatch_time(DISPATCH_TIME_NOW, USEC_PER_SEC);
dispatch_after(one_ms, dispatch_get_main_queue(), ^{
TransformProcessType(&psn, kProcessTransformToForegroundApplication);
2015-12-21 02:52:49 +00:00
dispatch_time_t one_ms = dispatch_time(DISPATCH_TIME_NOW, USEC_PER_SEC);
dispatch_after(one_ms, dispatch_get_main_queue(), ^{
[[NSRunningApplication currentApplication]
activateWithOptions:NSApplicationActivateIgnoringOtherApps];
p.Resolve();
2015-12-21 02:52:49 +00:00
});
});
} else {
TransformProcessType(&psn, kProcessTransformToForegroundApplication);
promise.Resolve();
}
return handle;
}
void Browser::DockSetMenu(ElectronMenuModel* model) {
ElectronApplicationDelegate* delegate =
(ElectronApplicationDelegate*)[NSApp delegate];
2014-11-16 15:04:31 +00:00
[delegate setApplicationDockMenu:model];
}
void Browser::DockSetIcon(v8::Isolate* isolate, v8::Local<v8::Value> icon) {
gfx::Image image;
if (!icon->IsNull()) {
api::NativeImage* native_image = nullptr;
if (!api::NativeImage::TryConvertNativeImage(isolate, icon, &native_image))
return;
image = native_image->image();
}
[[AtomApplication sharedApplication]
setApplicationIconImage:image.AsNSImage()];
}
2016-10-10 20:30:58 +00:00
void Browser::ShowAboutPanel() {
NSDictionary* options = DictionaryValueToNSDictionary(about_panel_options_);
// Credits must be a NSAttributedString instead of NSString
NSString* credits = (NSString*)options[@"Credits"];
if (credits != nil) {
base::scoped_nsobject<NSMutableDictionary> mutable_options(
[options mutableCopy]);
base::scoped_nsobject<NSAttributedString> creditString(
[[NSAttributedString alloc]
initWithString:credits
attributes:@{
NSForegroundColorAttributeName : [NSColor textColor]
}]);
[mutable_options setValue:creditString forKey:@"Credits"];
options = [NSDictionary dictionaryWithDictionary:mutable_options];
}
[[AtomApplication sharedApplication]
2016-10-10 20:30:58 +00:00
orderFrontStandardAboutPanelWithOptions:options];
}
void Browser::SetAboutPanelOptions(base::DictionaryValue options) {
2016-10-10 20:30:58 +00:00
about_panel_options_.Clear();
2016-10-12 17:52:59 +00:00
for (const auto& pair : options.DictItems()) {
std::string key = std::string(pair.first);
if (!key.empty() && pair.second.is_string()) {
2016-10-12 17:52:59 +00:00
key[0] = base::ToUpperASCII(key[0]);
auto val = std::make_unique<base::Value>(pair.second.Clone());
about_panel_options_.Set(key, std::move(val));
2016-10-12 17:52:59 +00:00
}
}
2016-10-10 20:30:58 +00:00
}
2019-03-14 20:39:52 +00:00
void Browser::ShowEmojiPanel() {
[[AtomApplication sharedApplication] orderFrontCharacterPalette:nil];
2019-03-14 20:39:52 +00:00
}
bool Browser::IsEmojiPanelSupported() {
return true;
}
bool Browser::IsSecureKeyboardEntryEnabled() {
return password_input_enabler_.get() != nullptr;
}
void Browser::SetSecureKeyboardEntryEnabled(bool enabled) {
if (enabled) {
password_input_enabler_ =
std::make_unique<ui::ScopedPasswordInputEnabler>();
} else {
password_input_enabler_.reset();
}
}
} // namespace electron