From 47cd167f41eef025ceb37410d25ff99f84755cd5 Mon Sep 17 00:00:00 2001
From: Andreas Fernandez <a.fernandez@scripting-base.de>
Date: Tue, 15 Nov 2022 14:54:42 +0100
Subject: [PATCH] [TASK] Drop backend.js
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The file backend.js contained some basic preparations for the backend
context that are partially not required anymore. The remaining settings
are converted to a global assignment set in BackendController.

The `window.name` property is now hard-coded to be `typo3-backend` for
use with the EXT:adminpanel, which requires some changes in acceptance
tests as `window.name` had an empty value before.
`window.opener` is nulled, otherwise, this might cause issues with
inter-frame communication if the backend was e.g. opened via a link in
an email.

With the remaining assigned being migrated, backend.js serves no purpose
anymore and is dropped now.

Resolves: #99101
Releases: main
Change-Id: I1b92184c1e5063f7a494c62060adfb5b67a2878e
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/76607
Tested-by: core-ci <typo3@b13.com>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Frank Nägler <frank.naegler@typo3.com>
Reviewed-by: Frank Nägler <frank.naegler@typo3.com>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
---
 .../Resources/Private/Templates/Main.html     |  2 +-
 .../Classes/Controller/BackendController.php  |  4 +++
 .../Private/Templates/Backend/Main.html       |  3 ---
 .../Resources/Public/JavaScript/backend.js    | 25 -------------------
 .../FormEngine/ElementsGroupCest.php          | 12 ++++-----
 .../FormEngine/FalMetadataCest.php            | 12 ++++-----
 ...eContentElementLocalizeSynchronizeCest.php | 16 ++++++------
 .../InlinePagesLocalizeResourceCest.php       |  6 ++---
 .../Classes/Controller/PreviewController.php  |  1 -
 9 files changed, 28 insertions(+), 53 deletions(-)
 delete mode 100644 typo3/sysext/backend/Resources/Public/JavaScript/backend.js

diff --git a/typo3/sysext/adminpanel/Resources/Private/Templates/Main.html b/typo3/sysext/adminpanel/Resources/Private/Templates/Main.html
index a5590e8b655c..adf9dd06299e 100644
--- a/typo3/sysext/adminpanel/Resources/Private/Templates/Main.html
+++ b/typo3/sysext/adminpanel/Resources/Private/Templates/Main.html
@@ -65,7 +65,7 @@
         <f:render partial="Modules/Item" arguments="{uid: uid, icon: icon, label: label, information: information, mainContent: mainContent, data: data, languageKey: languageKey}" debug="false" />
         <div class="typo3-adminPanel-module">
             <div class="typo3-adminPanel-module-trigger">
-                <a href="{backendUrl}" class="typo3-adminPanel-backend-url" target="adminpanelWindow">
+                <a href="{backendUrl}" class="typo3-adminPanel-backend-url" target="typo3-backend">
                     <f:variable name="icon">
                         <core:icon identifier="actions-window-open" alternativeMarkupIdentifier="inline" />
                     </f:variable>
diff --git a/typo3/sysext/backend/Classes/Controller/BackendController.php b/typo3/sysext/backend/Classes/Controller/BackendController.php
index 79f711cc4d4e..73dca8e25d34 100644
--- a/typo3/sysext/backend/Classes/Controller/BackendController.php
+++ b/typo3/sysext/backend/Classes/Controller/BackendController.php
@@ -82,6 +82,10 @@ class BackendController
         $this->setUpBasicPageRendererForBackend($pageRenderer, $this->extensionConfiguration, $request, $this->getLanguageService());
 
         $javaScriptRenderer = $pageRenderer->getJavaScriptRenderer();
+        $javaScriptRenderer->addGlobalAssignment(['window' => [
+            'name' => 'typo3-backend', // reset window name to a standardized value
+            'opener' => null, // remove any previously set opener value
+        ]]);
         $javaScriptRenderer->addJavaScriptModuleInstruction(
             JavaScriptModuleInstruction::create('@typo3/backend/login-refresh.js')
                 ->invoke('initialize', [
diff --git a/typo3/sysext/backend/Resources/Private/Templates/Backend/Main.html b/typo3/sysext/backend/Resources/Private/Templates/Backend/Main.html
index 8e9bb70e45e8..07ceb89a3631 100644
--- a/typo3/sysext/backend/Resources/Private/Templates/Backend/Main.html
+++ b/typo3/sysext/backend/Resources/Private/Templates/Backend/Main.html
@@ -4,9 +4,6 @@
 >
 
 <f:be.pageRenderer
-    includeJsFiles="{
-        0: 'EXT:backend/Resources/Public/JavaScript/backend.js'
-    }"
     includeJavaScriptModules="{
         0: 'bootstrap',
         1: '@typo3/backend/module/router.js',
diff --git a/typo3/sysext/backend/Resources/Public/JavaScript/backend.js b/typo3/sysext/backend/Resources/Public/JavaScript/backend.js
deleted file mode 100644
index 742f7571cc40..000000000000
--- a/typo3/sysext/backend/Resources/Public/JavaScript/backend.js
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * This file is part of the TYPO3 CMS project.
- *
- * It is free software; you can redistribute it and/or modify it under
- * the terms of the GNU General Public License, either version 2
- * of the License, or any later version.
- *
- * For the full copyright and license information, please read the
- * LICENSE.txt file that was distributed with this source code.
- *
- * The TYPO3 project - inspiring people to share!
- */
-
-// Reset the current window name in case it was a preview before
-if (window.name === 'newTYPO3frontendWindow') {
-  window.name = '';
-}
-
-// Remove window.opener from backend
-window.opener = undefined;
-
-/**
- * common storage and global object, could later hold more information about the current user etc.
- */
-var TYPO3 = TYPO3 || {};
diff --git a/typo3/sysext/core/Tests/Acceptance/Application/FormEngine/ElementsGroupCest.php b/typo3/sysext/core/Tests/Acceptance/Application/FormEngine/ElementsGroupCest.php
index a0de40a191ea..7b9382e21642 100644
--- a/typo3/sysext/core/Tests/Acceptance/Application/FormEngine/ElementsGroupCest.php
+++ b/typo3/sysext/core/Tests/Acceptance/Application/FormEngine/ElementsGroupCest.php
@@ -104,13 +104,13 @@ class ElementsGroupCest
         $I->seeNumberOfElements('select[data-formengine-input-name="data[tx_styleguide_elements_group][1][group_db_1]"] option', 4);
         $I->click($formWizardsWrap . ' div:nth-of-type(4) > div > a:nth-of-type(1)');
 
-        $I->switchToWindow();
+        $I->switchToWindow('typo3-backend');
         $I->switchToIFrame('modal_frame');
 
         $I->amGoingTo('click + button to select record and close DB-Browser');
         $I->click('#recordlist-be_users > div:nth-child(1) > table:nth-child(1) > tbody:nth-child(2) > tr:nth-child(1) > td:nth-child(2) > span:nth-child(1) > a:nth-child(1)');
 
-        $I->switchToWindow();
+        $I->switchToWindow('typo3-backend');
         $I->switchToContentFrame();
         $I->seeNumberOfElements('select[data-formengine-input-name="data[tx_styleguide_elements_group][1][group_db_1]"] option', 5);
     }
@@ -126,7 +126,7 @@ class ElementsGroupCest
         $I->seeNumberOfElements('select[data-formengine-input-name="data[tx_styleguide_elements_group][1][group_db_1]"] option', 4);
         $I->click($formWizardsWrap . ' div:nth-of-type(4) > div > a:nth-of-type(1)');
 
-        $I->switchToWindow();
+        $I->switchToWindow('typo3-backend');
         $I->switchToIFrame('modal_frame');
 
         $I->amGoingTo('click record + in DB-Browser');
@@ -134,7 +134,7 @@ class ElementsGroupCest
         $I->amGoingTo('click + button to select record and close DB-Browser');
         $I->click('#recordlist-be_users > div:nth-child(1) > table:nth-child(1) > tbody:nth-child(2) > tr:nth-child(1) > td:nth-child(2) > span:nth-child(1) > a:nth-child(1)');
 
-        $I->switchToWindow();
+        $I->switchToWindow('typo3-backend');
         $I->switchToContentFrame();
         $I->seeNumberOfElements('select[data-formengine-input-name="data[tx_styleguide_elements_group][1][group_db_1]"] option', 6);
     }
@@ -150,7 +150,7 @@ class ElementsGroupCest
         $I->seeNumberOfElements('select[data-formengine-input-name="data[tx_styleguide_elements_group][1][group_db_1]"] option', 4);
         $I->click($formWizardsWrap . ' div:nth-of-type(4) > div > a:nth-of-type(1)');
 
-        $I->switchToWindow();
+        $I->switchToWindow('typo3-backend');
         $I->switchToIFrame('modal_frame');
 
         $I->amGoingTo('search record foo in DB-Browser');
@@ -166,7 +166,7 @@ class ElementsGroupCest
 
         $I->amGoingTo('click + button to select record and close DB-Browser');
         $I->click('#recordlist-be_users > div:nth-child(1) > table:nth-child(1) > tbody:nth-child(2) > tr:nth-child(1) > td:nth-child(2) > span:nth-child(1) > a:nth-child(1)');
-        $I->switchToWindow();
+        $I->switchToWindow('typo3-backend');
         $I->click('.t3js-modal-close');
 
         $I->switchToContentFrame();
diff --git a/typo3/sysext/core/Tests/Acceptance/Application/FormEngine/FalMetadataCest.php b/typo3/sysext/core/Tests/Acceptance/Application/FormEngine/FalMetadataCest.php
index 80c8ffabbc26..33f7923c3dad 100644
--- a/typo3/sysext/core/Tests/Acceptance/Application/FormEngine/FalMetadataCest.php
+++ b/typo3/sysext/core/Tests/Acceptance/Application/FormEngine/FalMetadataCest.php
@@ -66,13 +66,13 @@ class FalMetadataCest
 
         $I->click('Images');
         $I->click('Add image');
-        $I->switchToWindow();
+        $I->switchToWindow('typo3-backend');
         $I->switchToIFrame('modal_frame');
         $I->waitForElement('.svg-tree-wrapper .nodes .node', 5);
         $I->click('.node[title="styleguide"]');
         $I->waitForText('fileadmin: /styleguide/', 5);
         $I->click('bus_lane.jpg');
-        $I->switchToWindow();
+        $I->switchToWindow('typo3-backend');
         $I->switchToContentFrame();
         $I->waitForText('bus_lane.jpg');
 
@@ -108,7 +108,7 @@ class FalMetadataCest
 
         $I->amGoingTo('Check metadata of sys_file_reference displayed in tt_content');
         $this->goToPageModule($I, $pageTree);
-        $I->switchToWindow();
+        $I->switchToWindow('typo3-backend');
         $I->switchToContentFrame();
         $I->click('tt_content with image');
         $I->waitForElementNotVisible('#t3js-ui-block');
@@ -158,13 +158,13 @@ class FalMetadataCest
 
         $I->click('Images');
         $I->click('Add image');
-        $I->switchToWindow();
+        $I->switchToWindow('typo3-backend');
         $I->switchToIFrame('modal_frame');
         $I->waitForElement('.svg-tree-wrapper .nodes .node', 5);
         $I->click('.node[title="styleguide"]');
         $I->waitForText('fileadmin: /styleguide/', 5);
         $I->click('bus_lane.jpg');
-        $I->switchToWindow();
+        $I->switchToWindow('typo3-backend');
         $I->switchToContentFrame();
         $I->waitForText('bus_lane.jpg');
 
@@ -207,7 +207,7 @@ class FalMetadataCest
     {
         $I->amGoingTo('Check if deactivating null checkboxes focuses text fields');
         $this->goToPageModule($I, $pageTree);
-        $I->switchToWindow();
+        $I->switchToWindow('typo3-backend');
         $I->switchToContentFrame();
         $I->click('tt_content with image');
         $I->waitForElementNotVisible('#t3js-ui-block');
diff --git a/typo3/sysext/core/Tests/Acceptance/Application/FormEngine/InlineContentElementLocalizeSynchronizeCest.php b/typo3/sysext/core/Tests/Acceptance/Application/FormEngine/InlineContentElementLocalizeSynchronizeCest.php
index 95ac666f67d1..45ceb9832701 100644
--- a/typo3/sysext/core/Tests/Acceptance/Application/FormEngine/InlineContentElementLocalizeSynchronizeCest.php
+++ b/typo3/sysext/core/Tests/Acceptance/Application/FormEngine/InlineContentElementLocalizeSynchronizeCest.php
@@ -39,7 +39,7 @@ class InlineContentElementLocalizeSynchronizeCest
     {
         // Add a content element type images and localize it
         $I->click('.module-body td[data-language-uid="0"] span[data-identifier="actions-add"]');
-        $I->switchToWindow();
+        $I->switchToWindow('typo3-backend');
         $I->waitForText('Images Only');
         $I->click('Images Only');
         $I->switchToContentFrame();
@@ -48,7 +48,7 @@ class InlineContentElementLocalizeSynchronizeCest
         // Inline add record in Resources tab
         $I->click('Images');
         $I->click('span[data-identifier="actions-insert-record"]', 'div.active');
-        $I->switchToWindow();
+        $I->switchToWindow('typo3-backend');
         $I->switchToIFrame('modal_frame');
         // Find page 'styleguide' in page tree of modal and click it
         $context = $I->executeInSelenium(function (RemoteWebDriver $webdriver) {
@@ -60,10 +60,10 @@ class InlineContentElementLocalizeSynchronizeCest
         $I->waitForElementVisible('#typo3-filelist a[data-file-name="telephone_box.jpg"]');
         $I->click('#typo3-filelist a[data-file-name="telephone_box.jpg"]');
         // Save, go back to page
-        $I->switchToWindow();
+        $I->switchToWindow('typo3-backend');
         $I->switchToContentFrame();
         $I->click('.module-docheader a[title="Close"]');
-        $I->switchToWindow();
+        $I->switchToWindow('typo3-backend');
         $I->waitForText('Save and close');
         $I->click('Save and close');
         // Switch to "All languages" view and localize content element
@@ -74,7 +74,7 @@ class InlineContentElementLocalizeSynchronizeCest
         $I->selectOption('select[name=languageMenu]', 'All languages');
         $I->waitForText('Translate');
         $I->click('Translate');
-        $I->switchToWindow();
+        $I->switchToWindow('typo3-backend');
         $I->waitForText('Localize page "staticdata - language 1" into styleguide demo language danish');
         $I->click('span[data-identifier="actions-localize"]');
         $I->click('Next');
@@ -87,7 +87,7 @@ class InlineContentElementLocalizeSynchronizeCest
         $I->waitForText('Edit Page Content on page "staticdata"', 3, 'h1');
         $I->click('Images');
         $I->click('span[data-identifier="actions-insert-record"]', 'div.active');
-        $I->switchToWindow();
+        $I->switchToWindow('typo3-backend');
         $I->switchToIFrame('modal_frame');
         // Find page 'styleguide' in page tree of modal and click it
         $context = $I->executeInSelenium(function (RemoteWebDriver $webdriver) {
@@ -99,10 +99,10 @@ class InlineContentElementLocalizeSynchronizeCest
         $I->waitForElementVisible('#typo3-filelist a[data-file-name="underground.jpg"]');
         $I->click('#typo3-filelist a[data-file-name="underground.jpg"]');
         // Save, go back to page
-        $I->switchToWindow();
+        $I->switchToWindow('typo3-backend');
         $I->switchToContentFrame();
         $I->click('.module-docheader a[title="Close"]');
-        $I->switchToWindow();
+        $I->switchToWindow('typo3-backend');
         $I->waitForText('Save and close');
         $I->click('Save and close');
         // Open the localized element and see that the second image can be synchronized
diff --git a/typo3/sysext/core/Tests/Acceptance/Application/FormEngine/InlinePagesLocalizeResourceCest.php b/typo3/sysext/core/Tests/Acceptance/Application/FormEngine/InlinePagesLocalizeResourceCest.php
index 511b5413f8e1..8b069d761433 100644
--- a/typo3/sysext/core/Tests/Acceptance/Application/FormEngine/InlinePagesLocalizeResourceCest.php
+++ b/typo3/sysext/core/Tests/Acceptance/Application/FormEngine/InlinePagesLocalizeResourceCest.php
@@ -43,7 +43,7 @@ class InlinePagesLocalizeResourceCest
         // Inline add record in Resources tab
         $I->click('Resources');
         $I->click('span[data-identifier="actions-insert-record"]', 'div.active');
-        $I->switchToWindow();
+        $I->switchToWindow('typo3-backend');
         $I->switchToIFrame('modal_frame');
         // Find page 'styleguide' in page tree of modal and click it
         $context = $I->executeInSelenium(function (RemoteWebDriver $webdriver) {
@@ -55,10 +55,10 @@ class InlinePagesLocalizeResourceCest
         $I->waitForElementVisible('#typo3-filelist a[data-file-name="telephone_box.jpg"]');
         $I->click('#typo3-filelist a[data-file-name="telephone_box.jpg"]');
         // Save, go back to list
-        $I->switchToWindow();
+        $I->switchToWindow('typo3-backend');
         $I->switchToContentFrame();
         $I->click('.module-docheader a[title="Close"]');
-        $I->switchToWindow();
+        $I->switchToWindow('typo3-backend');
         $I->waitForText('Save and close');
         $I->click('Save and close');
         // Edit the page translation and see if that resource has been added.
diff --git a/typo3/sysext/workspaces/Classes/Controller/PreviewController.php b/typo3/sysext/workspaces/Classes/Controller/PreviewController.php
index 85285553fbfe..24a0c535248d 100644
--- a/typo3/sysext/workspaces/Classes/Controller/PreviewController.php
+++ b/typo3/sysext/workspaces/Classes/Controller/PreviewController.php
@@ -95,7 +95,6 @@ class PreviewController
         if (!array_intersect($splitPreviewModes, $allPreviewModes)) {
             $splitPreviewModes = $allPreviewModes;
         }
-        $this->pageRenderer->addJsFile('EXT:backend/Resources/Public/JavaScript/backend.js');
         $this->pageRenderer->addInlineSetting('Workspaces', 'SplitPreviewModes', $splitPreviewModes);
         $this->pageRenderer->addInlineSetting('Workspaces', 'id', $pageUid);
 
-- 
GitLab