electron/shell/browser/ui/cocoa/electron_ns_window.mm

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

421 lines
14 KiB
Text
Raw Normal View History

2018-04-19 16:53:12 +09:00
// Copyright (c) 2018 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "shell/browser/ui/cocoa/electron_ns_window.h"
2018-04-19 16:53:12 +09:00
#include "base/strings/sys_string_conversions.h"
#include "electron/mas.h"
#include "shell/browser/api/electron_api_web_contents.h"
#include "shell/browser/native_window_mac.h"
#include "shell/browser/ui/cocoa/electron_preview_item.h"
#include "shell/browser/ui/cocoa/electron_touch_bar.h"
#include "shell/browser/ui/cocoa/root_view_mac.h"
#include "ui/base/cocoa/window_size_constants.h"
2018-04-19 16:53:12 +09:00
2023-03-02 11:21:51 -08:00
#import <objc/message.h>
#import <objc/runtime.h>
2018-04-19 16:53:12 +09:00
namespace electron {
int ScopedDisableResize::disable_resize_ = 0;
2018-04-19 16:53:12 +09:00
} // namespace electron
@interface NSWindow (PrivateAPI)
- (NSImage*)_cornerMask;
2023-03-02 11:21:51 -08:00
- (int64_t)_resizeDirectionForMouseLocation:(CGPoint)location;
@end
// See components/remote_cocoa/app_shim/native_widget_mac_nswindow.mm
@interface NSView (CRFrameViewAdditions)
- (void)cr_mouseDownOnFrameView:(NSEvent*)event;
@end
2023-03-02 11:21:51 -08:00
typedef void (*MouseDownImpl)(id, SEL, NSEvent*);
namespace {
MouseDownImpl g_nsthemeframe_mousedown;
MouseDownImpl g_nsnextstepframe_mousedown;
} // namespace
// This class is never instantiated, it's just a container for our swizzled
// mouseDown method.
@interface SwizzledMethodsClass : NSView
2023-03-02 11:21:51 -08:00
@end
@implementation SwizzledMethodsClass
2023-03-02 11:21:51 -08:00
- (void)swiz_nsthemeframe_mouseDown:(NSEvent*)event {
if ([self.window respondsToSelector:@selector(shell)]) {
electron::NativeWindowMac* shell =
(electron::NativeWindowMac*)[(id)self.window shell];
if (shell && !shell->has_frame())
[self cr_mouseDownOnFrameView:event];
g_nsthemeframe_mousedown(self, @selector(mouseDown:), event);
}
}
- (void)swiz_nsnextstepframe_mouseDown:(NSEvent*)event {
if ([self.window respondsToSelector:@selector(shell)]) {
electron::NativeWindowMac* shell =
(electron::NativeWindowMac*)[(id)self.window shell];
if (shell && !shell->has_frame()) {
[self cr_mouseDownOnFrameView:event];
}
g_nsnextstepframe_mousedown(self, @selector(mouseDown:), event);
}
}
- (void)swiz_nsview_swipeWithEvent:(NSEvent*)event {
if ([self.window respondsToSelector:@selector(shell)]) {
electron::NativeWindowMac* shell =
(electron::NativeWindowMac*)[(id)self.window shell];
if (shell) {
if (event.deltaY == 1.0) {
shell->NotifyWindowSwipe("up");
} else if (event.deltaX == -1.0) {
shell->NotifyWindowSwipe("right");
} else if (event.deltaY == -1.0) {
shell->NotifyWindowSwipe("down");
} else if (event.deltaX == 1.0) {
shell->NotifyWindowSwipe("left");
}
}
}
}
2023-03-02 11:21:51 -08:00
@end
namespace {
#if IS_MAS_BUILD()
2023-03-02 11:21:51 -08:00
void SwizzleMouseDown(NSView* frame_view,
SEL swiz_selector,
MouseDownImpl* orig_impl) {
Method original_mousedown =
class_getInstanceMethod([frame_view class], @selector(mouseDown:));
*orig_impl = (MouseDownImpl)method_getImplementation(original_mousedown);
Method new_mousedown =
class_getInstanceMethod([SwizzledMethodsClass class], swiz_selector);
2023-03-02 11:21:51 -08:00
method_setImplementation(original_mousedown,
method_getImplementation(new_mousedown));
}
#else
// components/remote_cocoa/app_shim/bridged_content_view.h overrides
// swipeWithEvent, so we can't just override the implementation
// in ElectronNSWindow like we do with for ex. rotateWithEvent.
void SwizzleSwipeWithEvent(NSView* view, SEL swiz_selector) {
Method original_swipe_with_event =
class_getInstanceMethod([view class], @selector(swipeWithEvent:));
Method new_swipe_with_event =
class_getInstanceMethod([SwizzledMethodsClass class], swiz_selector);
method_setImplementation(original_swipe_with_event,
method_getImplementation(new_swipe_with_event));
}
#endif
refactor: remove InspectableWebContentsViewMac in favor of the Views version (#45238) * refactor: remove InspectableWebContentsViewMac in favor of the Views version * cherry-pick: refactor: remove InspectableWebContentsViewMac in favor of the Views version (#41326) commit e67ab9a93dadccecff30de50ab4555191c30b6c4 Confilcts not resolved, except removal of the files removed by the original commit. * resolved conflicts and build issues after cherry-pick * cherry-picked: fix: add method allowing to disable headless mode in native widget https://github.com/electron/electron/pull/42996 fixing https://github.com/electron/electron/issues/42995 * fix: displaying select popup in window created as fullscreen window `constrainFrameRect:toScreen:` is not being call for windows created with `fullscreen: true` therefore `headless` mode was not being removed and `RenderWidgetHostNSViewBridge::DisplayPopupMenu` ignored displaying popup. Issue could be fixed by placing additional removal of `headless` mode in the `toggleFullScreen:`, but `orderWindow:relativeTo:` is called both for a regular and a fullscreen window, therefore there will be a single place fixing both cases. Because `electron::NativeWindowMac` lifetime may be shorter than `ElectronNSWindow` on which macOS may execute `orderWindow:relativeTo:` we need to clear `shell_` when `NativeWindow` is being closed. Fixes #43010. * fix: Content visibility when using `vibrancy` We need to put `NSVisualEffectView` before `ViewsCompositorSuperview` otherwise when using `vibrancy` in `BrowserWindow` `NSVisualEffectView` will hide content displayed by the compositor. Fixes #43003 Fixes #42336 In fact main issues reported in these tickets were not present after cherry-picking original refactor switching to `views::WebView`, so text could be selected and click event was properly generated. However both issues testcases were using `vibrancy` and actual content was invisible, because it was covered by the `NSVisualEffectView`. * fix: EXCEPTION_ACCESS_VIOLATION crash on BrowserWindow.destroy() Restored postponed deletion of the `NativeWindow`. Restoration caused `DCHECK(new_parent_ui_layer->GetCompositor());` failure in `BrowserCompositorMac::SetParentUiLayer` after the spec test: `chrome extensions chrome.webRequest does not take precedence over Electron webRequest - http` with stack: ``` 7 Electron Framework 0x000000011fe07830 content::BrowserCompositorMac::SetParentUiLayer(ui::Layer*) + 628 8 Electron Framework 0x000000011fe0c154 content::RenderWidgetHostViewMac::SetParentUiLayer(ui::Layer*) + 220 9 Electron Framework 0x000000011fe226a8 content::WebContentsViewMac::CreateViewForWidget(content::RenderWidgetHost*) + 600 10 Electron Framework 0x000000011fd37e4c content::WebContentsImpl::CreateRenderWidgetHostViewForRenderManager(content::RenderViewHost*) + 164 11 Electron Framework 0x000000011fb32278 content::RenderFrameHostManager::CreateSpeculativeRenderFrame(content::SiteInstanceImpl*, bool, scoped_refptr<content::BrowsingContextState> const&) + 816 12 Electron Framework 0x000000011fb2ab8c content::RenderFrameHostManager::CreateSpeculativeRenderFrameHost(content::SiteInstanceImpl*, content::SiteInstanceImpl*, bool) + 1308 13 Electron Framework 0x000000011fb28598 content::RenderFrameHostManager::GetFrameHostForNavigation(content::NavigationRequest*, content::BrowsingContextGroupSwap*, std::__Cr::basic_string<char, std::__Cr::char_traits<char>, std::__Cr::allocator<char>>*) + 1796 14 Electron Framework 0x000000011fa78660 content::NavigationRequest::SelectFrameHostForOnRequestFailedInternal(bool, bool, std::__Cr::optional<std::__Cr::basic_string<char, std::__Cr::char_traits<char>, std::__Cr::allocator<char>>> const&) + 280 15 Electron Framework 0x000000011fa6a994 content::NavigationRequest::OnRequestFailedInternal(network::URLLoaderCompletionStatus const&, bool, std::__Cr::optional<std::__Cr::basic_string<char, std::__Cr::char_traits<char>, std::__Cr::allocator<char>>> const&, bo + 1008 16 Electron Framework 0x000000011fa7772c content::NavigationRequest::OnRequestFailed(network::URLLoaderCompletionStatus const&) + 72 17 Electron Framework 0x000000011f8554ac content::NavigationURLLoaderImpl::NotifyRequestFailed(network::URLLoaderCompletionStatus const&) + 248 ``` This was probably the reason of removing `NativeWindow` immediately in order to cleanup `views_host_` in `WebContentsViewMac` to prevent using layer without compositor in `WebContentsViewMac::CreateViewForWidget`. `[ElectronNSWindowDelegate windowWillClose:]` is deleting window host and the compositor used by the `NativeWindow` therefore detach `NativeWindow` contents from parent. This will clear `views_host_` and prevent failing mentioned `DCHECK`. Fixes #42975 * chore: Applied review suggestions Co-authored-by: Michał Pichliński <michal.pichlinski@here.io> * refactor: directly cleanup shell Co-authored-by: Samuel Maddock <smaddock@slack-corp.com> --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Michał Pichliński <michal.pichlinski@here.io> Co-authored-by: Samuel Maddock <smaddock@slack-corp.com>
2025-01-23 11:54:15 +01:00
2023-03-02 11:21:51 -08:00
} // namespace
2018-04-19 16:53:12 +09:00
@implementation ElectronNSWindow
@synthesize acceptsFirstMouse;
@synthesize enableLargerThanScreen;
@synthesize disableAutoHideCursor;
@synthesize disableKeyOrMainWindow;
@synthesize vibrantView;
@synthesize cornerMask;
2018-04-19 16:53:12 +09:00
- (id)initWithShell:(electron::NativeWindowMac*)shell
styleMask:(NSUInteger)styleMask {
if ((self = [super initWithContentRect:ui::kWindowSizeDeterminedLater
styleMask:styleMask
backing:NSBackingStoreBuffered
defer:NO])) {
2023-03-02 11:21:51 -08:00
#if IS_MAS_BUILD()
// The first time we create a frameless window, we swizzle the
// implementation of -[NSNextStepFrame mouseDown:], replacing it with our
// own.
// This is only necessary on MAS where we can't directly refer to
// NSNextStepFrame or NSThemeFrame, as they are private APIs.
// See components/remote_cocoa/app_shim/native_widget_mac_nswindow.mm for
// the non-MAS-compatible way of doing this.
if (styleMask & NSWindowStyleMaskTitled) {
if (!g_nsthemeframe_mousedown) {
NSView* theme_frame = [[self contentView] superview];
DCHECK(strcmp(class_getName([theme_frame class]), "NSThemeFrame") == 0)
<< "Expected NSThemeFrame but was "
<< class_getName([theme_frame class]);
SwizzleMouseDown(theme_frame, @selector(swiz_nsthemeframe_mouseDown:),
&g_nsthemeframe_mousedown);
}
} else {
if (!g_nsnextstepframe_mousedown) {
NSView* nextstep_frame = [[self contentView] superview];
DCHECK(strcmp(class_getName([nextstep_frame class]),
"NSNextStepFrame") == 0)
<< "Expected NSNextStepFrame but was "
<< class_getName([nextstep_frame class]);
SwizzleMouseDown(nextstep_frame,
@selector(swiz_nsnextstepframe_mouseDown:),
&g_nsnextstepframe_mousedown);
}
}
#else
NSView* view = [[self contentView] superview];
SwizzleSwipeWithEvent(view, @selector(swiz_nsview_swipeWithEvent:));
2023-03-02 11:21:51 -08:00
#endif // IS_MAS_BUILD
shell_ = shell;
}
return self;
2018-04-19 16:53:12 +09:00
}
refactor: remove InspectableWebContentsViewMac in favor of the Views version (#45238) * refactor: remove InspectableWebContentsViewMac in favor of the Views version * cherry-pick: refactor: remove InspectableWebContentsViewMac in favor of the Views version (#41326) commit e67ab9a93dadccecff30de50ab4555191c30b6c4 Confilcts not resolved, except removal of the files removed by the original commit. * resolved conflicts and build issues after cherry-pick * cherry-picked: fix: add method allowing to disable headless mode in native widget https://github.com/electron/electron/pull/42996 fixing https://github.com/electron/electron/issues/42995 * fix: displaying select popup in window created as fullscreen window `constrainFrameRect:toScreen:` is not being call for windows created with `fullscreen: true` therefore `headless` mode was not being removed and `RenderWidgetHostNSViewBridge::DisplayPopupMenu` ignored displaying popup. Issue could be fixed by placing additional removal of `headless` mode in the `toggleFullScreen:`, but `orderWindow:relativeTo:` is called both for a regular and a fullscreen window, therefore there will be a single place fixing both cases. Because `electron::NativeWindowMac` lifetime may be shorter than `ElectronNSWindow` on which macOS may execute `orderWindow:relativeTo:` we need to clear `shell_` when `NativeWindow` is being closed. Fixes #43010. * fix: Content visibility when using `vibrancy` We need to put `NSVisualEffectView` before `ViewsCompositorSuperview` otherwise when using `vibrancy` in `BrowserWindow` `NSVisualEffectView` will hide content displayed by the compositor. Fixes #43003 Fixes #42336 In fact main issues reported in these tickets were not present after cherry-picking original refactor switching to `views::WebView`, so text could be selected and click event was properly generated. However both issues testcases were using `vibrancy` and actual content was invisible, because it was covered by the `NSVisualEffectView`. * fix: EXCEPTION_ACCESS_VIOLATION crash on BrowserWindow.destroy() Restored postponed deletion of the `NativeWindow`. Restoration caused `DCHECK(new_parent_ui_layer->GetCompositor());` failure in `BrowserCompositorMac::SetParentUiLayer` after the spec test: `chrome extensions chrome.webRequest does not take precedence over Electron webRequest - http` with stack: ``` 7 Electron Framework 0x000000011fe07830 content::BrowserCompositorMac::SetParentUiLayer(ui::Layer*) + 628 8 Electron Framework 0x000000011fe0c154 content::RenderWidgetHostViewMac::SetParentUiLayer(ui::Layer*) + 220 9 Electron Framework 0x000000011fe226a8 content::WebContentsViewMac::CreateViewForWidget(content::RenderWidgetHost*) + 600 10 Electron Framework 0x000000011fd37e4c content::WebContentsImpl::CreateRenderWidgetHostViewForRenderManager(content::RenderViewHost*) + 164 11 Electron Framework 0x000000011fb32278 content::RenderFrameHostManager::CreateSpeculativeRenderFrame(content::SiteInstanceImpl*, bool, scoped_refptr<content::BrowsingContextState> const&) + 816 12 Electron Framework 0x000000011fb2ab8c content::RenderFrameHostManager::CreateSpeculativeRenderFrameHost(content::SiteInstanceImpl*, content::SiteInstanceImpl*, bool) + 1308 13 Electron Framework 0x000000011fb28598 content::RenderFrameHostManager::GetFrameHostForNavigation(content::NavigationRequest*, content::BrowsingContextGroupSwap*, std::__Cr::basic_string<char, std::__Cr::char_traits<char>, std::__Cr::allocator<char>>*) + 1796 14 Electron Framework 0x000000011fa78660 content::NavigationRequest::SelectFrameHostForOnRequestFailedInternal(bool, bool, std::__Cr::optional<std::__Cr::basic_string<char, std::__Cr::char_traits<char>, std::__Cr::allocator<char>>> const&) + 280 15 Electron Framework 0x000000011fa6a994 content::NavigationRequest::OnRequestFailedInternal(network::URLLoaderCompletionStatus const&, bool, std::__Cr::optional<std::__Cr::basic_string<char, std::__Cr::char_traits<char>, std::__Cr::allocator<char>>> const&, bo + 1008 16 Electron Framework 0x000000011fa7772c content::NavigationRequest::OnRequestFailed(network::URLLoaderCompletionStatus const&) + 72 17 Electron Framework 0x000000011f8554ac content::NavigationURLLoaderImpl::NotifyRequestFailed(network::URLLoaderCompletionStatus const&) + 248 ``` This was probably the reason of removing `NativeWindow` immediately in order to cleanup `views_host_` in `WebContentsViewMac` to prevent using layer without compositor in `WebContentsViewMac::CreateViewForWidget`. `[ElectronNSWindowDelegate windowWillClose:]` is deleting window host and the compositor used by the `NativeWindow` therefore detach `NativeWindow` contents from parent. This will clear `views_host_` and prevent failing mentioned `DCHECK`. Fixes #42975 * chore: Applied review suggestions Co-authored-by: Michał Pichliński <michal.pichlinski@here.io> * refactor: directly cleanup shell Co-authored-by: Samuel Maddock <smaddock@slack-corp.com> --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Michał Pichliński <michal.pichlinski@here.io> Co-authored-by: Samuel Maddock <smaddock@slack-corp.com>
2025-01-23 11:54:15 +01:00
- (void)cleanup {
shell_ = nullptr;
}
2018-05-02 20:43:45 +09:00
- (electron::NativeWindowMac*)shell {
return shell_;
}
- (id)accessibilityFocusedUIElement {
views::Widget* widget = shell_->widget();
id superFocus = [super accessibilityFocusedUIElement];
if (!widget || shell_->IsFocused())
return superFocus;
return nil;
}
- (NSRect)originalContentRectForFrameRect:(NSRect)frameRect {
return [super contentRectForFrameRect:frameRect];
}
- (NSTouchBar*)makeTouchBar {
2018-04-19 16:53:12 +09:00
if (shell_->touch_bar())
return [shell_->touch_bar() makeTouchBar];
else
return nil;
}
// NSWindow overrides.
- (void)sendEvent:(NSEvent*)event {
// Draggable regions only respond to left-click dragging, but the system will
// still suppress right-clicks in a draggable region. Temporarily disabling
// draggable regions allows the underlying views to respond to right-click
// to potentially bring up a frame context menu.
BOOL shouldDisableDraggable =
(event.type == NSEventTypeRightMouseDown ||
(event.type == NSEventTypeLeftMouseDown &&
([event modifierFlags] & NSEventModifierFlagControl)));
if (shouldDisableDraggable) {
electron::api::WebContents::SetDisableDraggableRegions(true);
}
[super sendEvent:event];
if (shouldDisableDraggable) {
electron::api::WebContents::SetDisableDraggableRegions(false);
}
}
- (void)rotateWithEvent:(NSEvent*)event {
shell_->NotifyWindowRotateGesture(event.rotation);
}
- (NSRect)contentRectForFrameRect:(NSRect)frameRect {
if (shell_->has_frame())
return [super contentRectForFrameRect:frameRect];
else
return frameRect;
}
2018-04-19 16:53:12 +09:00
- (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen*)screen {
// Resizing is disabled.
if (electron::ScopedDisableResize::IsResizeDisabled())
return [self frame];
NSRect result = [super constrainFrameRect:frameRect toScreen:screen];
2018-04-19 16:53:12 +09:00
// Enable the window to be larger than screen.
if ([self enableLargerThanScreen]) {
// If we have a frame, ensure that we only position the window
// somewhere where the user can move or resize it (and not
// behind the menu bar, for instance)
//
// If there's no frame, put the window wherever the developer
// wanted it to go
if (shell_->has_frame()) {
result.size = frameRect.size;
} else {
result = frameRect;
}
}
return result;
2018-04-19 16:53:12 +09:00
}
- (void)setFrame:(NSRect)windowFrame display:(BOOL)displayViews {
// constrainFrameRect is not called on hidden windows so disable adjusting
// the frame directly when resize is disabled
if (!electron::ScopedDisableResize::IsResizeDisabled())
[super setFrame:windowFrame display:displayViews];
}
refactor: remove InspectableWebContentsViewMac in favor of the Views version (#45238) * refactor: remove InspectableWebContentsViewMac in favor of the Views version * cherry-pick: refactor: remove InspectableWebContentsViewMac in favor of the Views version (#41326) commit e67ab9a93dadccecff30de50ab4555191c30b6c4 Confilcts not resolved, except removal of the files removed by the original commit. * resolved conflicts and build issues after cherry-pick * cherry-picked: fix: add method allowing to disable headless mode in native widget https://github.com/electron/electron/pull/42996 fixing https://github.com/electron/electron/issues/42995 * fix: displaying select popup in window created as fullscreen window `constrainFrameRect:toScreen:` is not being call for windows created with `fullscreen: true` therefore `headless` mode was not being removed and `RenderWidgetHostNSViewBridge::DisplayPopupMenu` ignored displaying popup. Issue could be fixed by placing additional removal of `headless` mode in the `toggleFullScreen:`, but `orderWindow:relativeTo:` is called both for a regular and a fullscreen window, therefore there will be a single place fixing both cases. Because `electron::NativeWindowMac` lifetime may be shorter than `ElectronNSWindow` on which macOS may execute `orderWindow:relativeTo:` we need to clear `shell_` when `NativeWindow` is being closed. Fixes #43010. * fix: Content visibility when using `vibrancy` We need to put `NSVisualEffectView` before `ViewsCompositorSuperview` otherwise when using `vibrancy` in `BrowserWindow` `NSVisualEffectView` will hide content displayed by the compositor. Fixes #43003 Fixes #42336 In fact main issues reported in these tickets were not present after cherry-picking original refactor switching to `views::WebView`, so text could be selected and click event was properly generated. However both issues testcases were using `vibrancy` and actual content was invisible, because it was covered by the `NSVisualEffectView`. * fix: EXCEPTION_ACCESS_VIOLATION crash on BrowserWindow.destroy() Restored postponed deletion of the `NativeWindow`. Restoration caused `DCHECK(new_parent_ui_layer->GetCompositor());` failure in `BrowserCompositorMac::SetParentUiLayer` after the spec test: `chrome extensions chrome.webRequest does not take precedence over Electron webRequest - http` with stack: ``` 7 Electron Framework 0x000000011fe07830 content::BrowserCompositorMac::SetParentUiLayer(ui::Layer*) + 628 8 Electron Framework 0x000000011fe0c154 content::RenderWidgetHostViewMac::SetParentUiLayer(ui::Layer*) + 220 9 Electron Framework 0x000000011fe226a8 content::WebContentsViewMac::CreateViewForWidget(content::RenderWidgetHost*) + 600 10 Electron Framework 0x000000011fd37e4c content::WebContentsImpl::CreateRenderWidgetHostViewForRenderManager(content::RenderViewHost*) + 164 11 Electron Framework 0x000000011fb32278 content::RenderFrameHostManager::CreateSpeculativeRenderFrame(content::SiteInstanceImpl*, bool, scoped_refptr<content::BrowsingContextState> const&) + 816 12 Electron Framework 0x000000011fb2ab8c content::RenderFrameHostManager::CreateSpeculativeRenderFrameHost(content::SiteInstanceImpl*, content::SiteInstanceImpl*, bool) + 1308 13 Electron Framework 0x000000011fb28598 content::RenderFrameHostManager::GetFrameHostForNavigation(content::NavigationRequest*, content::BrowsingContextGroupSwap*, std::__Cr::basic_string<char, std::__Cr::char_traits<char>, std::__Cr::allocator<char>>*) + 1796 14 Electron Framework 0x000000011fa78660 content::NavigationRequest::SelectFrameHostForOnRequestFailedInternal(bool, bool, std::__Cr::optional<std::__Cr::basic_string<char, std::__Cr::char_traits<char>, std::__Cr::allocator<char>>> const&) + 280 15 Electron Framework 0x000000011fa6a994 content::NavigationRequest::OnRequestFailedInternal(network::URLLoaderCompletionStatus const&, bool, std::__Cr::optional<std::__Cr::basic_string<char, std::__Cr::char_traits<char>, std::__Cr::allocator<char>>> const&, bo + 1008 16 Electron Framework 0x000000011fa7772c content::NavigationRequest::OnRequestFailed(network::URLLoaderCompletionStatus const&) + 72 17 Electron Framework 0x000000011f8554ac content::NavigationURLLoaderImpl::NotifyRequestFailed(network::URLLoaderCompletionStatus const&) + 248 ``` This was probably the reason of removing `NativeWindow` immediately in order to cleanup `views_host_` in `WebContentsViewMac` to prevent using layer without compositor in `WebContentsViewMac::CreateViewForWidget`. `[ElectronNSWindowDelegate windowWillClose:]` is deleting window host and the compositor used by the `NativeWindow` therefore detach `NativeWindow` contents from parent. This will clear `views_host_` and prevent failing mentioned `DCHECK`. Fixes #42975 * chore: Applied review suggestions Co-authored-by: Michał Pichliński <michal.pichlinski@here.io> * refactor: directly cleanup shell Co-authored-by: Samuel Maddock <smaddock@slack-corp.com> --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Michał Pichliński <michal.pichlinski@here.io> Co-authored-by: Samuel Maddock <smaddock@slack-corp.com>
2025-01-23 11:54:15 +01:00
- (void)orderWindow:(NSWindowOrderingMode)place relativeTo:(NSInteger)otherWin {
if (shell_) {
// We initialize the window in headless mode to allow painting before it is
// shown, but we don't want the headless behavior of allowing the window to
// be placed unconstrained.
self.isHeadless = false;
shell_->widget()->DisableHeadlessMode();
}
[super orderWindow:place relativeTo:otherWin];
}
2018-04-19 16:53:12 +09:00
- (id)accessibilityAttributeValue:(NSString*)attribute {
if ([attribute isEqual:NSAccessibilityEnabledAttribute])
return [NSNumber numberWithBool:YES];
2018-04-19 16:53:12 +09:00
if (![attribute isEqualToString:@"AXChildren"])
return [super accessibilityAttributeValue:attribute];
// We want to remove the window title (also known as
// NSAccessibilityReparentingCellProxy), which VoiceOver already sees.
2018-04-19 16:53:12 +09:00
// * when VoiceOver is disabled, this causes Cmd+C to be used for TTS but
// still leaves the buttons available in the accessibility tree.
// * when VoiceOver is enabled, the full accessibility tree is used.
// Without removing the title and with VO disabled, the TTS would always read
// the window title instead of using Cmd+C to get the selected text.
NSPredicate* predicate =
[NSPredicate predicateWithFormat:@"(self.className != %@)",
@"NSAccessibilityReparentingCellProxy"];
2018-04-19 16:53:12 +09:00
2018-04-20 14:47:04 -04:00
NSArray* children = [super accessibilityAttributeValue:attribute];
chore: bump chromium to 117.0.5892.0 (main) (#39118) * chore: bump chromium in DEPS to 117.0.5892.0 * 4670267: Don't send javascript: or empty URLs to browser in CreateNewWindow. https://chromium-review.googlesource.com/c/chromium/src/+/4670267 * 4662090: Add metrics for WebGPU support https://chromium-review.googlesource.com/c/chromium/src/+/4662090 * 4672599: Use set_defaults for mac_app_bundle https://chromium-review.googlesource.com/c/chromium/src/+/4672599 * 4663771: usb: Add connection count tracking methods for UsbDelegate https://chromium-review.googlesource.com/c/chromium/src/+/4663771 * 4664578: Remove unused parameter from ExtensionsGuestViewManagerDelegate ctor https://chromium-review.googlesource.com/c/chromium/src/+/4664578 * 4622253: usb: Create classes for usb system tray icon https://chromium-review.googlesource.com/c/chromium/src/+/4622253 * 4678263: Remove ARC support from scoped_nsobject https://chromium-review.googlesource.com/c/chromium/src/+/4678263 * chore: follow-up ARC changes and missing guard corrections * chore: don't mark 0-param ctor explicit Follow up to https://chromium-review.googlesource.com/c/chromium/src/+/4664578 * chore: fixup patch indices * 4670865: Merge ObjectProxy::CallMethodAndBlock{,WithErrorDetails}. https://chromium-review.googlesource.com/c/chromium/src/+/4670865 * chore: follow-up ARC changes and missing guard corrections * fixup: retain ElectronApplicationDelegate * fix: correct rustc binary --------- Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
2023-07-19 00:26:27 +02:00
NSMutableArray* mutableChildren = [children mutableCopy];
[mutableChildren filterUsingPredicate:predicate];
return mutableChildren;
2018-04-19 16:53:12 +09:00
}
- (NSString*)accessibilityTitle {
return base::SysUTF8ToNSString(shell_->GetTitle());
}
2018-04-19 16:53:12 +09:00
- (BOOL)canBecomeMainWindow {
return !self.disableKeyOrMainWindow;
}
- (BOOL)canBecomeKeyWindow {
return !self.disableKeyOrMainWindow;
}
- (NSView*)frameView {
return [[self contentView] superview];
}
- (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item {
// By default "Close Window" is always disabled when window has no title, to
// support closing a window without title we need to manually do menu item
// validation. This code path is used by the "roundedCorners" option.
if ([item action] == @selector(performClose:))
return shell_->IsClosable();
return [super validateUserInterfaceItem:item];
}
// By overriding this built-in method the corners of the vibrant view (if set)
// will be smooth.
- (NSImage*)_cornerMask {
if (self.vibrantView != nil) {
return [self cornerMask];
} else {
return [super _cornerMask];
}
}
2018-04-19 16:53:12 +09:00
// Quicklook methods
- (BOOL)acceptsPreviewPanelControl:(QLPreviewPanel*)panel {
return YES;
}
- (void)beginPreviewPanelControl:(QLPreviewPanel*)panel {
panel.dataSource = static_cast<id<QLPreviewPanelDataSource>>([self delegate]);
}
- (void)endPreviewPanelControl:(QLPreviewPanel*)panel {
panel.dataSource = nil;
}
// Custom window button methods
- (BOOL)windowShouldClose:(id)sender {
return YES;
}
2018-04-19 16:53:12 +09:00
- (void)performClose:(id)sender {
2018-04-20 14:47:04 -04:00
if (shell_->title_bar_style() ==
electron::NativeWindowMac::TitleBarStyle::kCustomButtonsOnHover) {
2018-04-19 16:53:12 +09:00
[[self delegate] windowShouldClose:self];
} else if (!([self styleMask] & NSWindowStyleMaskTitled)) {
// performClose does not work for windows without title, so we have to
// emulate its behavior. This code path is used by "simpleFullscreen" and
// "roundedCorners" options.
if ([[self delegate] respondsToSelector:@selector(windowShouldClose:)]) {
if (![[self delegate] windowShouldClose:self])
return;
} else if ([self respondsToSelector:@selector(windowShouldClose:)]) {
if (![self windowShouldClose:self])
return;
}
[self close];
} else if (shell_->is_modal() && shell_->parent() && shell_->IsVisible()) {
// We don't want to actually call [window close] here since
// we've already called endSheet on the modal sheet.
return;
} else {
2018-04-19 16:53:12 +09:00
[super performClose:sender];
}
2018-04-19 16:53:12 +09:00
}
- (BOOL)toggleFullScreenMode:(id)sender {
if (!shell_->has_frame() && !shell_->HasStyleMask(NSWindowStyleMaskTitled))
return NO;
bool is_simple_fs = shell_->IsSimpleFullScreen();
bool always_simple_fs = shell_->always_simple_fullscreen();
// If we're in simple fullscreen mode and trying to exit it
// we need to ensure we exit it properly to prevent a crash
// with NSWindowStyleMaskTitled mode.
if (is_simple_fs || always_simple_fs) {
shell_->SetSimpleFullScreen(!is_simple_fs);
} else {
if (shell_->IsVisible()) {
// Until 10.13, AppKit would obey a call to -toggleFullScreen: made inside
// windowDidEnterFullScreen & windowDidExitFullScreen. Starting in 10.13,
// it behaves as though the transition is still in progress and just emits
// "not in a fullscreen state" when trying to exit fullscreen in the same
// runloop that entered it. To handle this, invoke -toggleFullScreen:
// asynchronously.
[super performSelector:@selector(toggleFullScreen:)
withObject:nil
afterDelay:0];
} else {
[super toggleFullScreen:sender];
}
// Exiting fullscreen causes Cocoa to redraw the NSWindow, which resets
// the enabled state for NSWindowZoomButton. We need to persist it.
bool maximizable = shell_->IsMaximizable();
shell_->SetMaximizable(maximizable);
}
return YES;
2018-04-19 16:53:12 +09:00
}
- (void)performMiniaturize:(id)sender {
2018-04-20 14:47:04 -04:00
if (shell_->title_bar_style() ==
electron::NativeWindowMac::TitleBarStyle::kCustomButtonsOnHover)
2018-04-19 16:53:12 +09:00
[self miniaturize:self];
else
[super performMiniaturize:sender];
}
@end