From e985d3bb82c1ca1517bc65b5ddc48f6fce4b5410 Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Sun, 16 Jun 2024 06:20:46 +0000 Subject: [PATCH] Bug 1889369: enable tooltipsShowPidAndActiveness for tab card preview r=dwalker,desktop-theme-reviewers,tabbrowser-reviewers,emilio Differential Revision: https://phabricator.services.mozilla.com/D208652 UltraBlame original commit: 97d09ddde07b952a19f96ef45d0b83374022037f --- browser/base/content/main-popupset.inc.xhtml | 62 ++ browser/base/content/tabbrowser.js | 139 ++-- .../content/test/tabs/browser_tab_preview.js | 593 ++++++++++++++++++ .../tabpreview/tab-preview-panel.mjs | 206 ++++++ browser/components/tabpreview/tabpreview.css | 35 ++ 5 files changed, 982 insertions(+), 53 deletions(-) diff --git a/browser/base/content/main-popupset.inc.xhtml b/browser/base/content/main-popupset.inc.xhtml index be37d30c5598..d4bfc8dd9554 100644 --- a/browser/base/content/main-popupset.inc.xhtml +++ b/browser/base/content/main-popupset.inc.xhtml @@ -4536,6 +4536,68 @@ html div > < +html +: +div +class += +" +tab +- +preview +- +pid +- +activeness +" +> +< +html +: +div +class += +" +tab +- +preview +- +pid +" +> +< +/ +html +: +div +> +< +html +: +div +class += +" +tab +- +preview +- +activeness +" +> +< +/ +html +: +div +> +< +/ +html +: +div +> +< / html : diff --git a/browser/base/content/tabbrowser.js b/browser/base/content/tabbrowser.js index d588ff261209..cf0530231b51 100644 --- a/browser/base/content/tabbrowser.js +++ b/browser/base/content/tabbrowser.js @@ -22379,6 +22379,68 @@ break ; } } +getTabPids +( +tab +) +{ +if +( +! +tab +. +linkedBrowser +) +{ +return +[ +] +; +} +let +[ +contentPid +. +. +. +framePids +] += +E10SUtils +. +getBrowserPids +( +tab +. +linkedBrowser +gFissionBrowser +) +; +let +pids += +contentPid +? +[ +contentPid +] +: +[ +] +; +return +pids +. +concat +( +framePids +. +sort +( +) +) +; +} getTabTooltip ( tab @@ -22437,62 +22499,50 @@ false ) ) { -if -( -tab -. -linkedBrowser -) -{ -let -[ -contentPid -. -. -. -framePids -] +const +pids = -E10SUtils +this . -getBrowserPids +getTabPids ( tab -. -linkedBrowser -gFissionBrowser ) ; if ( -contentPid -) -{ -if -( -framePids -& -& -framePids +pids . length ) { +let +pidLabel += +pids +. +length +> +1 +? +" +pids +" +: +" +pid +" +; labelArray . push ( ( -pids { -contentPid +pidLabel } { -framePids -. -sort -( -) +pids . join ( @@ -22504,22 +22554,6 @@ join ) ; } -else -{ -labelArray -. -push -( -( -pid -{ -contentPid -} -) -) -; -} -} if ( tab @@ -22542,7 +22576,6 @@ A ; } } -} let label = diff --git a/browser/base/content/test/tabs/browser_tab_preview.js b/browser/base/content/test/tabs/browser_tab_preview.js index c3c7275eac3d..38fe41790ade 100644 --- a/browser/base/content/test/tabs/browser_tab_preview.js +++ b/browser/base/content/test/tabs/browser_tab_preview.js @@ -188,6 +188,16 @@ false ] [ " +browser +. +tabs +. +tooltipsShowPidAndActiveness +" +false +] +[ +" ui . tooltip @@ -464,6 +474,589 @@ add_task ( async function +pidAndActivenessHiddenByDefaultTests +( +) +{ +const +tabUrl1 += +" +data +: +text +/ +html +< +html +> +< +head +> +< +title +> +First +New +Tab +< +/ +title +> +< +/ +head +> +< +body +> +Hello +< +/ +body +> +< +/ +html +> +" +; +const +tab1 += +await +BrowserTestUtils +. +openNewForegroundTab +( +gBrowser +tabUrl1 +) +; +const +previewContainer += +document +. +getElementById +( +" +tab +- +preview +- +panel +" +) +; +await +openPreview +( +tab1 +) +; +Assert +. +equal +( +previewContainer +. +querySelector +( +" +. +tab +- +preview +- +pid +" +) +. +innerText +" +" +" +Tab +PID +is +not +shown +" +) +; +Assert +. +equal +( +previewContainer +. +querySelector +( +" +. +tab +- +preview +- +activeness +" +) +. +innerText +" +" +" +Tab +activeness +is +not +shown +" +) +; +await +closePreviews +( +) +; +BrowserTestUtils +. +removeTab +( +tab1 +) +; +EventUtils +. +synthesizeMouseAtCenter +( +document +. +documentElement +{ +type +: +" +mouseover +" +} +) +; +} +) +; +add_task +( +async +function +pidAndActivenessTests +( +) +{ +await +SpecialPowers +. +pushPrefEnv +( +{ +set +: +[ +[ +" +browser +. +tabs +. +tooltipsShowPidAndActiveness +" +true +] +] +} +) +; +const +tabUrl1 += +" +data +: +text +/ +html +< +html +> +< +head +> +< +title +> +Single +process +tab +< +/ +title +> +< +/ +head +> +< +body +> +Hello +< +/ +body +> +< +/ +html +> +" +; +const +tab1 += +await +BrowserTestUtils +. +openNewForegroundTab +( +gBrowser +tabUrl1 +) +; +const +tabUrl2 += +data +: +text +/ +html +< +html +> +< +head +> +< +title +> +Multi +- +process +tab +< +/ +title +> +< +/ +head +> +< +body +> +< +iframe +id += +" +inlineFrameExample +" +title += +" +Inline +Frame +Example +" +width += +" +300 +" +height += +" +200 +" +src += +" +https +: +/ +/ +example +. +com +" +> +< +/ +iframe +> +< +/ +body +> +< +/ +html +> +; +const +tab2 += +await +BrowserTestUtils +. +openNewForegroundTab +( +gBrowser +tabUrl2 +) +; +const +previewContainer += +document +. +getElementById +( +" +tab +- +preview +- +panel +" +) +; +await +openPreview +( +tab1 +) +; +Assert +. +stringMatches +( +previewContainer +. +querySelector +( +" +. +tab +- +preview +- +pid +" +) +. +innerText +/ +^ +pid +: +\ +d ++ +/ +" +Tab +PID +is +shown +on +single +process +tab +" +) +; +Assert +. +equal +( +previewContainer +. +querySelector +( +" +. +tab +- +preview +- +activeness +" +) +. +innerText +" +" +" +Tab +activeness +is +not +shown +on +inactive +tab +" +) +; +await +closePreviews +( +) +; +await +openPreview +( +tab2 +) +; +Assert +. +stringMatches +( +previewContainer +. +querySelector +( +" +. +tab +- +preview +- +pid +" +) +. +innerText +/ +^ +pids +: +\ +d ++ +\ +d ++ +/ +" +Tab +PIDs +are +shown +on +multi +- +process +tab +" +) +; +Assert +. +equal +( +previewContainer +. +querySelector +( +" +. +tab +- +preview +- +activeness +" +) +. +innerText +" +[ +A +] +" +" +Tab +activeness +is +shown +on +active +tab +" +) +; +await +closePreviews +( +) +; +BrowserTestUtils +. +removeTab +( +tab1 +) +; +BrowserTestUtils +. +removeTab +( +tab2 +) +; +await +SpecialPowers +. +popPrefEnv +( +) +; +EventUtils +. +synthesizeMouseAtCenter +( +document +. +documentElement +{ +type +: +" +mouseover +" +} +) +; +} +) +; +add_task +( +async +function thumbnailTests ( ) diff --git a/browser/components/tabpreview/tab-preview-panel.mjs b/browser/components/tabpreview/tab-preview-panel.mjs index 5246e07bf2ec..f8cebd49eeb7 100644 --- a/browser/components/tabpreview/tab-preview-panel.mjs +++ b/browser/components/tabpreview/tab-preview-panel.mjs @@ -207,6 +207,24 @@ showThumbnails false ) ; +XPCOMUtils +. +defineLazyPreferenceGetter +( +this +" +_prefShowPidAndActiveness +" +" +browser +. +tabs +. +tooltipsShowPidAndActiveness +" +false +) +; this . _timer @@ -733,6 +751,103 @@ this . _displayURI ; +if +( +this +. +_prefShowPidAndActiveness +) +{ +this +. +_panel +. +querySelector +( +" +. +tab +- +preview +- +pid +" +) +. +textContent += +this +. +_displayPids +; +this +. +_panel +. +querySelector +( +" +. +tab +- +preview +- +activeness +" +) +. +textContent += +this +. +_displayActiveness +; +} +else +{ +this +. +_panel +. +querySelector +( +" +. +tab +- +preview +- +pid +" +) +. +textContent += +" +" +; +this +. +_panel +. +querySelector +( +" +. +tab +- +preview +- +activeness +" +) +. +textContent += +" +" +; +} let thumbnailContainer = @@ -920,4 +1035,95 @@ spec ) ; } +get +_displayPids +( +) +{ +const +pids += +this +. +_win +. +gBrowser +. +getTabPids +( +this +. +_tab +) +; +if +( +! +pids +. +length +) +{ +return +" +" +; +} +let +pidLabel += +pids +. +length +> +1 +? +" +pids +" +: +" +pid +" +; +return +{ +pidLabel +} +: +{ +pids +. +join +( +" +" +) +} +; +} +get +_displayActiveness +( +) +{ +return +this +. +_tab +. +linkedBrowser +. +docShellIsActive +? +" +[ +A +] +" +: +" +" +; +} } diff --git a/browser/components/tabpreview/tabpreview.css b/browser/components/tabpreview/tabpreview.css index c1adc24b0e7c..5b039392d193 100644 --- a/browser/components/tabpreview/tabpreview.css +++ b/browser/components/tabpreview/tabpreview.css @@ -185,6 +185,41 @@ tab - preview - +pid +- +activeness +{ +color +: +var +( +- +- +text +- +color +- +deemphasized +) +; +display +: +flex +; +justify +- +content +: +space +- +between +; +} +. +tab +- +preview +- thumbnail - container