![electron-roller[bot]](/assets/img/avatar_default.png)
* chore: bump chromium in DEPS to 139.0.7258.6 * chore: bump chromium in DEPS to 139.0.7258.5 * chore: bump chromium in DEPS to 140.0.7270.1 * chore: bump chromium in DEPS to 140.0.7271.1 * chore: bump chromium in DEPS to 140.0.7273.0 * chore: bump chromium in DEPS to 140.0.7273.1 * chore: bump chromium in DEPS to 140.0.7275.1 * chore: bump chromium in DEPS to 140.0.7275.4 * chore: bump chromium in DEPS to 140.0.7277.1 * chore: bump chromium in DEPS to 140.0.7279.1 * chore: bump chromium in DEPS to 140.0.7281.1 * chore: bump chromium in DEPS to 140.0.7283.1 * chore: bump chromium in DEPS to 140.0.7285.1 * chore: bump chromium in DEPS to 140.0.7287.1 * chore: bump chromium in DEPS to 140.0.7289.0 * chore: bump chromium in DEPS to 140.0.7289.1 * chore: bump chromium in DEPS to 140.0.7291.1 * chore: bump chromium in DEPS to 140.0.7293.1 * chore: bump chromium in DEPS to 140.0.7295.1 * chore: bump chromium in DEPS to 140.0.7296.0 * chore: bump chromium to 140.0.7281.0 (main) (#47616) cherry picked from603cafad7e
* chore: bump chromium in DEPS to 140.0.7269.2 * chore: bump chromium in DEPS to 140.0.7270.0 * chore: bump chromium in DEPS to 140.0.7271.0 * chore: bump chromium in DEPS to 140.0.7273.0 * 6516731: [ExclusiveAccessForAndroid] remove unneeded includes & deps | https://chromium-review.googlesource.com/c/chromium/src/+/6516731 * 6694809: dbus: Ensure systemd scope is started before using any portal services | https://chromium-review.googlesource.com/c/chromium/src/+/6694809 * chore: patch chromium * chore: export patches * chore: bump chromium in DEPS to 140.0.7275.0 * 6677511: [pepper] More pepper removal | https://chromium-review.googlesource.com/c/chromium/src/+/6677511 * 6513641: [gin] Rename gin::Wrappable to gin::DeprecatedWrappable | https://chromium-review.googlesource.com/c/chromium/src/+/6513641 * chore: export chromium patches * 6513641: [gin] Rename gin::Wrappable to gin::DeprecatedWrappable | https://chromium-review.googlesource.com/c/chromium/src/+/6513641 * chore: bump chromium in DEPS to 140.0.7277.0 * chore: bump chromium in DEPS to 140.0.7279.0 * chore: bump chromium in DEPS to 140.0.7281.0 * 6677314: Plumb enabled client hints in the network requestion to network layer https://chromium-review.googlesource.com/c/chromium/src/+/6677314 * 6351556: [source-phase-imports] Support Wasm Source Phase Imports https://chromium-review.googlesource.com/c/chromium/src/+/6351556 * 6700077: [renderer] Avoid calls to deprecated GetIsolate methods https://chromium-review.googlesource.com/c/chromium/src/+/6700077 * 6692873: Reland "Reland "FSA: Only normalize the hardcoded rules once during initialization"" https://chromium-review.googlesource.com/c/chromium/src/+/6692873 * 6686234: [gin] Cleanup NamedPropertyInterceptor for Wrappable https://chromium-review.googlesource.com/c/chromium/src/+/6686234 * chore: export patches * 6667723: Remove content_enable_legacy_ipc GN arg. https://chromium-review.googlesource.com/c/chromium/src/+/6667723 * 6646566: ui: Move NativeWindowTracker to its own directory https://chromium-review.googlesource.com/c/chromium/src/+/6646566 * fix: add missing includes * 6580522: [WAR, DNR] Fix unsafe redirect error to web accessible resource https://chromium-review.googlesource.com/c/chromium/src/+/6580522 * 6680477: Implement `completeCode` endpoint and expose to DevTools https://chromium-review.googlesource.com/c/chromium/src/+/6680477 * 6677511: [pepper] More pepper removal https://chromium-review.googlesource.com/c/chromium/src/+/6677511 * 6696689: Rename views::WidgetFocusManager -> NativeViewFocusManager https://chromium-review.googlesource.com/c/chromium/src/+/6696689 * 6702812: Move wtf/text/string_impl*.* to "blink" namespace https://chromium-review.googlesource.com/c/chromium/src/+/6702812 * chore: fix dialog patch * 6702431: [animation-trigger] Parse timeline-trigger-name https://chromium-review.googlesource.com/c/chromium/src/+/6702431 * chore: fixup patch indices * feat: replace webFrame.routingId with webFrame.frameToken * feat: WebFrameMain.prototype.frameToken * test: refactor to use replacement APIs * chore: fixup pip patch * test: adjust webFrame tests for frameToken changes * 6703757: Reland "Enable -fsanitize=array-bounds in non-UBSan builds" https://chromium-review.googlesource.com/c/chromium/src/+/6703757 * test: switch to frameTokens * test: routingId is fine to test in the main process * docs: add routingId to breaking changes * docs: update plugin-crashed event * chore: fixup linux dialog patch --------- Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: alice <alice@makenotion.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> Co-authored-by: Samuel Maddock <smaddock@slack-corp.com> (cherry picked from commit603cafad7e
) --------- Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> Co-authored-by: alice <alice@makenotion.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> Co-authored-by: Samuel Maddock <smaddock@slack-corp.com>
251 lines
8.3 KiB
C++
251 lines
8.3 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 "content/public/browser/web_contents.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 {
|
|
|
|
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(OwnedByWidgetPassKey{});
|
|
set_owned_by_client(OwnedByClientPassKey{});
|
|
|
|
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_;
|
|
};
|
|
|
|
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);
|
|
AddChildViewRaw(devtools_web_view_.get());
|
|
AddChildViewRaw(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
|