Skip to content

Commit

Permalink
refactor: remove DevTools legacy UI patching (#40331)
Browse files Browse the repository at this point in the history
  • Loading branch information
codebytere committed Oct 26, 2023
1 parent 30fbcfc commit 652f995
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 327 deletions.
2 changes: 1 addition & 1 deletion patches/devtools_frontend/.patches
@@ -1 +1 @@
fix_expose_globals_to_allow_patching_devtools_dock.patch
chore_expose_ui_to_allow_electron_to_set_dock_side.patch
@@ -0,0 +1,24 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Shelley Vohr <shelley.vohr@gmail.com>
Date: Wed, 25 Oct 2023 11:48:21 -0400
Subject: chore: expose UI to allow Electron to set dock side

This patch allows Electron to set the dock side via `webContents.openDevTools({ mode })`.

It also allows us to test certain aspects of devtools extensions. We should look for a way
to handle this without patching, but this is fairly clean for now and no longer requires
patching legacy devtools code.

diff --git a/front_end/entrypoints/main/MainImpl.ts b/front_end/entrypoints/main/MainImpl.ts
index c62a8e6dd401c8be227c3c2a86a8da86ee795fba..af1abee6d5b4414f300854c85bc0e0cc3ddec198 100644
--- a/front_end/entrypoints/main/MainImpl.ts
+++ b/front_end/entrypoints/main/MainImpl.ts
@@ -770,6 +770,8 @@ export class MainImpl {
globalThis.Main = globalThis.Main || {};
// @ts-ignore Exported for Tests.js
globalThis.Main.Main = MainImpl;
+// @ts-ignore Exported for Electron
+globalThis.EUI = UI || {};

let zoomActionDelegateInstance: ZoomActionDelegate;

This file was deleted.

3 changes: 2 additions & 1 deletion shell/browser/ui/inspectable_web_contents.cc
Expand Up @@ -605,7 +605,8 @@ void InspectableWebContents::LoadCompleted() {
}
#endif
std::u16string javascript = base::UTF8ToUTF16(
"UI.DockController.instance().setDockSide(\"" + dock_state_ + "\");");
"EUI.DockController.DockController.instance().setDockSide(\"" +
dock_state_ + "\");");
GetDevToolsWebContents()->GetPrimaryMainFrame()->ExecuteJavaScript(
javascript, base::NullCallback());
}
Expand Down
7 changes: 4 additions & 3 deletions spec/extensions-spec.ts
Expand Up @@ -573,10 +573,11 @@ describe('chrome extensions', () => {

const showLastPanel = () => {
// this is executed in the devtools context, where UI is a global
const { UI } = (window as any);
const tabs = UI.InspectorView.instance().tabbedPane.tabs;
const { EUI } = (window as any);
const instance = EUI.InspectorView.InspectorView.instance();
const tabs = instance.tabbedPane.tabs;
const lastPanelId = tabs[tabs.length - 1].id;
UI.InspectorView.instance().showPanel(lastPanelId);
instance.showPanel(lastPanelId);
};
devToolsWebContents.executeJavaScript(`(${showLastPanel})()`, false).then(() => {
showPanelTimeoutId = setTimeout(show, 100);
Expand Down
7 changes: 4 additions & 3 deletions spec/webview-spec.ts
Expand Up @@ -297,10 +297,11 @@ describe('<webview> tag', function () {
const showPanelIntervalId = setInterval(function () {
if (!webContents.isDestroyed() && webContents.devToolsWebContents) {
webContents.devToolsWebContents.executeJavaScript('(' + function () {
const { UI } = (window as any);
const tabs = UI.InspectorView.instance().tabbedPane.tabs;
const { EUI } = (window as any);
const instance = EUI.InspectorView.InspectorView.instance();
const tabs = instance.tabbedPane.tabs;
const lastPanelId: any = tabs[tabs.length - 1].id;
UI.InspectorView.instance().showPanel(lastPanelId);
instance.showPanel(lastPanelId);
}.toString() + ')()');
} else {
clearInterval(showPanelIntervalId);
Expand Down

0 comments on commit 652f995

Please sign in to comment.