![trop[bot]](/assets/img/avatar_default.png)
* refactor: remove InspectableWebContentsViewMac in favor of the Views version
* cherry-pick: refactor: remove InspectableWebContentsViewMac in favor of the Views version (#41326)
commit e67ab9a93d
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>
254 lines
8.2 KiB
C++
254 lines
8.2 KiB
C++
// 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.
|
|
|
|
#include "shell/browser/ui/inspectable_web_contents_view.h"
|
|
|
|
#include <memory>
|
|
#include <utility>
|
|
|
|
#include "base/memory/raw_ptr.h"
|
|
#include "base/strings/utf_string_conversions.h"
|
|
#include "shell/browser/ui/drag_util.h"
|
|
#include "shell/browser/ui/inspectable_web_contents.h"
|
|
#include "shell/browser/ui/inspectable_web_contents_delegate.h"
|
|
#include "shell/browser/ui/inspectable_web_contents_view_delegate.h"
|
|
#include "ui/base/models/image_model.h"
|
|
#include "ui/views/controls/label.h"
|
|
#include "ui/views/controls/webview/webview.h"
|
|
#include "ui/views/widget/widget.h"
|
|
#include "ui/views/widget/widget_delegate.h"
|
|
#include "ui/views/window/client_view.h"
|
|
|
|
namespace electron {
|
|
|
|
namespace {
|
|
|
|
class DevToolsWindowDelegate : public views::ClientView,
|
|
public views::WidgetDelegate {
|
|
public:
|
|
DevToolsWindowDelegate(InspectableWebContentsView* shell,
|
|
views::View* view,
|
|
views::Widget* widget)
|
|
: views::ClientView(widget, view),
|
|
shell_(shell),
|
|
view_(view),
|
|
widget_(widget) {
|
|
SetOwnedByWidget(true);
|
|
set_owned_by_client();
|
|
|
|
if (shell->GetDelegate())
|
|
icon_ = shell->GetDelegate()->GetDevToolsWindowIcon();
|
|
}
|
|
~DevToolsWindowDelegate() override = default;
|
|
|
|
// disable copy
|
|
DevToolsWindowDelegate(const DevToolsWindowDelegate&) = delete;
|
|
DevToolsWindowDelegate& operator=(const DevToolsWindowDelegate&) = delete;
|
|
|
|
// views::WidgetDelegate:
|
|
views::View* GetInitiallyFocusedView() override { return view_; }
|
|
std::u16string GetWindowTitle() const override { return shell_->GetTitle(); }
|
|
ui::ImageModel GetWindowAppIcon() override { return GetWindowIcon(); }
|
|
ui::ImageModel GetWindowIcon() override { return icon_; }
|
|
views::Widget* GetWidget() override { return widget_; }
|
|
const views::Widget* GetWidget() const override { return widget_; }
|
|
views::View* GetContentsView() override { return view_; }
|
|
views::ClientView* CreateClientView(views::Widget* widget) override {
|
|
return this;
|
|
}
|
|
|
|
// views::ClientView:
|
|
views::CloseRequestResult OnWindowCloseRequested() override {
|
|
shell_->inspectable_web_contents()->CloseDevTools();
|
|
return views::CloseRequestResult::kCannotClose;
|
|
}
|
|
|
|
private:
|
|
raw_ptr<InspectableWebContentsView> shell_;
|
|
raw_ptr<views::View> view_;
|
|
raw_ptr<views::Widget> widget_;
|
|
ui::ImageModel icon_;
|
|
};
|
|
|
|
} // namespace
|
|
|
|
InspectableWebContentsView::InspectableWebContentsView(
|
|
InspectableWebContents* inspectable_web_contents)
|
|
: inspectable_web_contents_(inspectable_web_contents),
|
|
devtools_web_view_(new views::WebView(nullptr)),
|
|
title_(u"Developer Tools") {
|
|
if (!inspectable_web_contents_->is_guest() &&
|
|
inspectable_web_contents_->GetWebContents()->GetNativeView()) {
|
|
auto* contents_web_view = new views::WebView(nullptr);
|
|
contents_web_view->SetWebContents(
|
|
inspectable_web_contents_->GetWebContents());
|
|
contents_web_view_ = contents_web_view;
|
|
} else {
|
|
no_contents_view_ = new views::Label(u"No content under offscreen mode");
|
|
}
|
|
|
|
devtools_web_view_->SetVisible(false);
|
|
AddChildView(devtools_web_view_.get());
|
|
AddChildView(GetContentsView());
|
|
}
|
|
|
|
InspectableWebContentsView::~InspectableWebContentsView() {
|
|
if (devtools_window_)
|
|
inspectable_web_contents()->SaveDevToolsBounds(
|
|
devtools_window_->GetWindowBoundsInScreen());
|
|
}
|
|
|
|
void InspectableWebContentsView::SetCornerRadii(
|
|
const gfx::RoundedCornersF& corner_radii) {
|
|
// WebView won't exist for offscreen rendering.
|
|
if (contents_web_view_) {
|
|
contents_web_view_->holder()->SetCornerRadii(corner_radii);
|
|
}
|
|
}
|
|
|
|
void InspectableWebContentsView::ShowDevTools(bool activate) {
|
|
if (devtools_visible_)
|
|
return;
|
|
|
|
devtools_visible_ = true;
|
|
if (devtools_window_) {
|
|
devtools_window_web_view_->SetWebContents(
|
|
inspectable_web_contents_->GetDevToolsWebContents());
|
|
devtools_window_->SetBounds(inspectable_web_contents()->dev_tools_bounds());
|
|
if (activate) {
|
|
devtools_window_->Show();
|
|
} else {
|
|
devtools_window_->ShowInactive();
|
|
}
|
|
|
|
// Update draggable regions to account for the new dock position.
|
|
if (GetDelegate())
|
|
GetDelegate()->DevToolsResized();
|
|
} else {
|
|
devtools_web_view_->SetVisible(true);
|
|
devtools_web_view_->SetWebContents(
|
|
inspectable_web_contents_->GetDevToolsWebContents());
|
|
devtools_web_view_->RequestFocus();
|
|
DeprecatedLayoutImmediately();
|
|
}
|
|
}
|
|
|
|
void InspectableWebContentsView::CloseDevTools() {
|
|
if (!devtools_visible_)
|
|
return;
|
|
|
|
devtools_visible_ = false;
|
|
if (devtools_window_) {
|
|
auto save_bounds = devtools_window_->IsMinimized()
|
|
? devtools_window_->GetRestoredBounds()
|
|
: devtools_window_->GetWindowBoundsInScreen();
|
|
inspectable_web_contents()->SaveDevToolsBounds(save_bounds);
|
|
|
|
devtools_window_.reset();
|
|
devtools_window_web_view_ = nullptr;
|
|
devtools_window_delegate_ = nullptr;
|
|
} else {
|
|
devtools_web_view_->SetVisible(false);
|
|
devtools_web_view_->SetWebContents(nullptr);
|
|
DeprecatedLayoutImmediately();
|
|
}
|
|
}
|
|
|
|
bool InspectableWebContentsView::IsDevToolsViewShowing() {
|
|
return devtools_visible_;
|
|
}
|
|
|
|
bool InspectableWebContentsView::IsDevToolsViewFocused() {
|
|
if (devtools_window_web_view_)
|
|
return devtools_window_web_view_->HasFocus();
|
|
else if (devtools_web_view_)
|
|
return devtools_web_view_->HasFocus();
|
|
else
|
|
return false;
|
|
}
|
|
|
|
void InspectableWebContentsView::SetIsDocked(bool docked, bool activate) {
|
|
CloseDevTools();
|
|
|
|
if (!docked) {
|
|
devtools_window_ = std::make_unique<views::Widget>();
|
|
devtools_window_web_view_ = new views::WebView(nullptr);
|
|
devtools_window_delegate_ = new DevToolsWindowDelegate(
|
|
this, devtools_window_web_view_, devtools_window_.get());
|
|
|
|
views::Widget::InitParams params(
|
|
views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET,
|
|
views::Widget::InitParams::TYPE_WINDOW);
|
|
params.delegate = devtools_window_delegate_;
|
|
params.bounds = inspectable_web_contents()->dev_tools_bounds();
|
|
|
|
#if BUILDFLAG(IS_LINUX)
|
|
params.wm_role_name = "devtools";
|
|
if (GetDelegate())
|
|
GetDelegate()->GetDevToolsWindowWMClass(¶ms.wm_class_name,
|
|
¶ms.wm_class_class);
|
|
#endif
|
|
|
|
devtools_window_->Init(std::move(params));
|
|
devtools_window_->UpdateWindowIcon();
|
|
devtools_window_->widget_delegate()->SetHasWindowSizeControls(true);
|
|
}
|
|
|
|
ShowDevTools(activate);
|
|
}
|
|
|
|
void InspectableWebContentsView::SetContentsResizingStrategy(
|
|
const DevToolsContentsResizingStrategy& strategy) {
|
|
strategy_.CopyFrom(strategy);
|
|
DeprecatedLayoutImmediately();
|
|
}
|
|
|
|
void InspectableWebContentsView::SetTitle(const std::u16string& title) {
|
|
if (devtools_window_) {
|
|
title_ = title;
|
|
devtools_window_->UpdateWindowTitle();
|
|
}
|
|
}
|
|
|
|
const std::u16string InspectableWebContentsView::GetTitle() {
|
|
return title_;
|
|
}
|
|
|
|
void InspectableWebContentsView::Layout(PassKey) {
|
|
if (!devtools_web_view_->GetVisible()) {
|
|
GetContentsView()->SetBoundsRect(GetContentsBounds());
|
|
// Propagate layout call to all children, for example browser views.
|
|
LayoutSuperclass<View>(this);
|
|
return;
|
|
}
|
|
|
|
gfx::Size container_size(width(), height());
|
|
gfx::Rect new_devtools_bounds;
|
|
gfx::Rect new_contents_bounds;
|
|
ApplyDevToolsContentsResizingStrategy(
|
|
strategy_, container_size, &new_devtools_bounds, &new_contents_bounds);
|
|
|
|
// DevTools cares about the specific position, so we have to compensate RTL
|
|
// layout here.
|
|
new_devtools_bounds.set_x(GetMirroredXForRect(new_devtools_bounds));
|
|
new_contents_bounds.set_x(GetMirroredXForRect(new_contents_bounds));
|
|
|
|
devtools_web_view_->SetBoundsRect(new_devtools_bounds);
|
|
GetContentsView()->SetBoundsRect(new_contents_bounds);
|
|
|
|
// Propagate layout call to all children, for example browser views.
|
|
LayoutSuperclass<View>(this);
|
|
|
|
if (GetDelegate())
|
|
GetDelegate()->DevToolsResized();
|
|
}
|
|
|
|
views::View* InspectableWebContentsView::GetContentsView() const {
|
|
DCHECK(contents_web_view_ || no_contents_view_);
|
|
|
|
return contents_web_view_ ? contents_web_view_ : no_contents_view_;
|
|
}
|
|
|
|
} // namespace electron
|