electron/shell/browser/ui/inspectable_web_contents_view.h

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

88 lines
2.6 KiB
C
Raw Normal View History

// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Copyright (c) 2013 Adam Roben <adam@roben.org>. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE-CHROMIUM file.
#ifndef ELECTRON_SHELL_BROWSER_UI_INSPECTABLE_WEB_CONTENTS_VIEW_H_
#define ELECTRON_SHELL_BROWSER_UI_INSPECTABLE_WEB_CONTENTS_VIEW_H_
#include <string>
#include "base/memory/raw_ptr.h"
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
#include "chrome/browser/devtools/devtools_contents_resizing_strategy.h"
#include "ui/gfx/native_widget_types.h"
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
#include "ui/views/view.h"
class DevToolsContentsResizingStrategy;
chore: more iwyu (#43063) * chore: iwyu shell/browser/electron_pdf_document_helper_client.h * chore: iwyu shell/browser/hid/electron_hid_delegate.h * chore: iwyu content/public/browser/web_contents.h * chore: iwyu shell/browser/usb/electron_usb_delegate.h * chore: iwyu shell/browser/browser_observer.h * chore: iwyu shell/browser/bluetooth/electron_bluetooth_delegate.h * chore: iwyu shell/browser/serial/electron_serial_delegate.h * chore: iwyu shell/browser/api/frame_subscriber.h * chore: iwyu mojo/public/cpp/bindings/ * chore: iwyu components/ * chore: iwyu extensions/ * chore: iwyu shell/common/gin_helper/ * chore: iwyu v8/ * chore: iwyu base/containers/linked_list.h * chore: iwyu shell/browser/native_window.h * chore: iwyu shell/browser/api/electron_api_base_window.h * chore: iwyu shell/common/node_includes.h * chore: iwyu gin/handle.h * chore: iwyu base/functional/callback.h * chore: iwyu ui/gfx/ * chore: iwyu content/public/browser/render_frame_host.h * fix: mac * fix: mac * fix: win * chore: iwyu base/files/file_path.h * chore: iwyu base/unguessable_token.h * chore: iwyu ui/display/screen.h * chore: iwyu chrome/browser/predictors/preconnect_manager.h * chore: iwyu base/observer_list_types.h * chore: iwyu content/public/browser/web_contents.h * chore: iwyu chrome/browser/devtools/devtools_eye_dropper.h * chore: iwyu shell/browser/ui/inspectable_web_contents.h * chore: iwyu content/public/browser/keyboard_event_processing_result.h * chore: iwyu net/cookies/canonical_cookie.h * chore: iwyu net/base/address_list.h * chore: iwyu net/cert/x509_certificate.h * chore: iwyu net/cookies/cookie_change_dispatcher.h * chore: iwyu net/dns/public/host_resolver_results.h * fix: mac * Revert "chore: iwyu net/cert/x509_certificate.h" This reverts commit 002896f71146e90f1e29e090a1d6eede48cee11e.
2024-07-29 12:42:57 -05:00
namespace gfx {
class RoundedCornersF;
} // namespace gfx
namespace views {
class WebView;
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
class Widget;
class WidgetDelegate;
} // namespace views
namespace electron {
class InspectableWebContents;
2015-06-25 12:29:34 +08:00
class InspectableWebContentsViewDelegate;
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
class InspectableWebContentsView : public views::View {
public:
explicit InspectableWebContentsView(
InspectableWebContents* inspectable_web_contents);
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
~InspectableWebContentsView() override;
InspectableWebContents* inspectable_web_contents() {
return inspectable_web_contents_;
}
2015-06-25 12:29:34 +08:00
// The delegate manages its own life.
void SetDelegate(InspectableWebContentsViewDelegate* delegate) {
delegate_ = delegate;
}
2018-04-17 21:46:27 -04:00
InspectableWebContentsViewDelegate* GetDelegate() const { return delegate_; }
2015-06-25 12:29:34 +08: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 SetCornerRadii(const gfx::RoundedCornersF& corner_radii);
void ShowDevTools(bool activate);
void CloseDevTools();
bool IsDevToolsViewShowing();
bool IsDevToolsViewFocused();
void SetIsDocked(bool docked, bool activate);
void SetContentsResizingStrategy(
const DevToolsContentsResizingStrategy& strategy);
void SetTitle(const std::u16string& title);
const std::u16string GetTitle();
// views::View:
void Layout(PassKey) override;
private:
views::View* GetContentsView() const;
// Owns us.
raw_ptr<InspectableWebContents> inspectable_web_contents_;
raw_ptr<InspectableWebContentsViewDelegate> delegate_ =
nullptr; // weak references.
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
std::unique_ptr<views::Widget> devtools_window_;
raw_ptr<views::WebView> devtools_window_web_view_ = nullptr;
raw_ptr<views::WebView> contents_web_view_ = nullptr;
raw_ptr<views::View> no_contents_view_ = nullptr;
raw_ptr<views::WebView> devtools_web_view_ = nullptr;
DevToolsContentsResizingStrategy strategy_;
bool devtools_visible_ = false;
raw_ptr<views::WidgetDelegate> devtools_window_delegate_ = nullptr;
std::u16string title_;
};
} // namespace electron
#endif // ELECTRON_SHELL_BROWSER_UI_INSPECTABLE_WEB_CONTENTS_VIEW_H_