@@ -1594,6 +1594,8 @@ var gProtectionsHandler = {
1594
1594
1595
1595
// Add an observer to observe that the history has been cleared.
1596
1596
Services . obs . addObserver ( this , "browser:purge-session-history" ) ;
1597
+
1598
+ window . ensureCustomElements ( "moz-button-group" , "moz-toggle" ) ;
1597
1599
} ,
1598
1600
1599
1601
uninit ( ) {
@@ -1729,11 +1731,14 @@ var gProtectionsHandler = {
1729
1731
1730
1732
onPopupShown ( event ) {
1731
1733
if ( event . target == this . _protectionsPopup ) {
1732
- window . ensureCustomElements ( "moz-button-group" ) ;
1733
-
1734
1734
PopupNotifications . suppressWhileOpen ( this . _protectionsPopup ) ;
1735
1735
1736
1736
window . addEventListener ( "focus" , this , true ) ;
1737
+ this . _protectionsPopupTPSwitch . addEventListener ( "toggle" , this ) ;
1738
+ this . _protectionsPopupSiteNotWorkingTPSwitch . addEventListener (
1739
+ "toggle" ,
1740
+ this
1741
+ ) ;
1737
1742
1738
1743
// Insert the info message if needed. This will be shown once and then
1739
1744
// remain collapsed.
@@ -1752,6 +1757,11 @@ var gProtectionsHandler = {
1752
1757
onPopupHidden ( event ) {
1753
1758
if ( event . target == this . _protectionsPopup ) {
1754
1759
window . removeEventListener ( "focus" , this , true ) ;
1760
+ this . _protectionsPopupTPSwitch . removeEventListener ( "toggle" , this ) ;
1761
+ this . _protectionsPopupSiteNotWorkingTPSwitch . removeEventListener (
1762
+ "toggle" ,
1763
+ this
1764
+ ) ;
1755
1765
}
1756
1766
} ,
1757
1767
@@ -2025,20 +2035,30 @@ var gProtectionsHandler = {
2025
2035
2026
2036
// We handle focus here when the panel is shown.
2027
2037
handleEvent ( event ) {
2028
- let elem = document . activeElement ;
2029
- let position = elem . compareDocumentPosition ( this . _protectionsPopup ) ;
2038
+ switch ( event . type ) {
2039
+ case "focus" : {
2040
+ let elem = document . activeElement ;
2041
+ let position = elem . compareDocumentPosition ( this . _protectionsPopup ) ;
2030
2042
2031
- if (
2032
- ! (
2033
- position &
2034
- ( Node . DOCUMENT_POSITION_CONTAINS | Node . DOCUMENT_POSITION_CONTAINED_BY )
2035
- ) &&
2036
- ! this . _protectionsPopup . hasAttribute ( "noautohide" )
2037
- ) {
2038
- // Hide the panel when focusing an element that is
2039
- // neither an ancestor nor descendant unless the panel has
2040
- // @noautohide (e.g. for a tour).
2041
- PanelMultiView . hidePopup ( this . _protectionsPopup ) ;
2043
+ if (
2044
+ ! (
2045
+ position &
2046
+ ( Node . DOCUMENT_POSITION_CONTAINS |
2047
+ Node . DOCUMENT_POSITION_CONTAINED_BY )
2048
+ ) &&
2049
+ ! this . _protectionsPopup . hasAttribute ( "noautohide" )
2050
+ ) {
2051
+ // Hide the panel when focusing an element that is
2052
+ // neither an ancestor nor descendant unless the panel has
2053
+ // @noautohide (e.g. for a tour).
2054
+ PanelMultiView . hidePopup ( this . _protectionsPopup ) ;
2055
+ }
2056
+ break ;
2057
+ }
2058
+ case "toggle" : {
2059
+ this . onTPSwitchCommand ( event ) ;
2060
+ break ;
2061
+ }
2042
2062
}
2043
2063
} ,
2044
2064
@@ -2067,12 +2087,7 @@ var gProtectionsHandler = {
2067
2087
2068
2088
let currentlyEnabled = ! this . hasException ;
2069
2089
2070
- for ( let tpSwitch of [
2071
- this . _protectionsPopupTPSwitch ,
2072
- this . _protectionsPopupSiteNotWorkingTPSwitch ,
2073
- ] ) {
2074
- tpSwitch . toggleAttribute ( "enabled" , currentlyEnabled ) ;
2075
- }
2090
+ this . updateProtectionsToggles ( currentlyEnabled ) ;
2076
2091
2077
2092
this . _notBlockingWhyLink . setAttribute (
2078
2093
"tooltip" ,
@@ -2084,13 +2099,6 @@ var gProtectionsHandler = {
2084
2099
// Toggle the breakage link according to the current enable state.
2085
2100
this . toggleBreakageLink ( ) ;
2086
2101
2087
- // Give the button an accessible label for screen readers.
2088
- document . l10n . setAttributes (
2089
- this . _protectionsPopupTPSwitch ,
2090
- currentlyEnabled ? "protections-disable" : "protections-enable" ,
2091
- { host }
2092
- ) ;
2093
-
2094
2102
// Update the tooltip of the blocked tracker counter.
2095
2103
this . maybeUpdateEarliestRecordedDateTooltip ( ) ;
2096
2104
@@ -2111,6 +2119,31 @@ var gProtectionsHandler = {
2111
2119
this . _protectionsPopup . toggleAttribute ( "hasException" , this . hasException ) ;
2112
2120
} ,
2113
2121
2122
+ /**
2123
+ * Updates the "pressed" state and labels for both toggles in the different
2124
+ * panel subviews.
2125
+ *
2126
+ * @param {boolean } isPressed - Whether or not the toggles should be pressed.
2127
+ * True if ETP is enabled for a given site.
2128
+ */
2129
+ updateProtectionsToggles ( isPressed ) {
2130
+ let host = gIdentityHandler . getHostForDisplay ( ) ;
2131
+ for ( let toggle of [
2132
+ this . _protectionsPopupTPSwitch ,
2133
+ this . _protectionsPopupSiteNotWorkingTPSwitch ,
2134
+ ] ) {
2135
+ toggle . toggleAttribute ( "pressed" , isPressed ) ;
2136
+ toggle . toggleAttribute ( "disabled" , ! ! this . _TPSwitchCommanding ) ;
2137
+ document . l10n . setAttributes (
2138
+ toggle ,
2139
+ isPressed
2140
+ ? "protections-panel-etp-on-toggle"
2141
+ : "protections-panel-etp-off-toggle" ,
2142
+ { host }
2143
+ ) ;
2144
+ }
2145
+ } ,
2146
+
2114
2147
/*
2115
2148
* This function sorts the category items into the Blocked/Allowed/None Detected
2116
2149
* sections. It's called immediately in onContentBlockingEvent if the popup
@@ -2203,12 +2236,8 @@ var gProtectionsHandler = {
2203
2236
// styling after toggling the TP switch.
2204
2237
let newExceptionState =
2205
2238
this . _protectionsPopup . toggleAttribute ( "hasException" ) ;
2206
- for ( let tpSwitch of [
2207
- this . _protectionsPopupTPSwitch ,
2208
- this . _protectionsPopupSiteNotWorkingTPSwitch ,
2209
- ] ) {
2210
- tpSwitch . toggleAttribute ( "enabled" , ! newExceptionState ) ;
2211
- }
2239
+
2240
+ this . updateProtectionsToggles ( ! newExceptionState ) ;
2212
2241
2213
2242
// Toggle the breakage link if needed.
2214
2243
this . toggleBreakageLink ( ) ;
@@ -2452,11 +2481,11 @@ var gProtectionsHandler = {
2452
2481
this . _protectionsPopupTPSwitchBreakageLink . hidden =
2453
2482
ContentBlockingAllowList . includes ( gBrowser . selectedBrowser ) ||
2454
2483
! this . anyBlocking ||
2455
- ! this . _protectionsPopupTPSwitch . hasAttribute ( "enabled " ) ;
2484
+ ! this . _protectionsPopupTPSwitch . hasAttribute ( "pressed " ) ;
2456
2485
// The "Site Fixed?" link behaves similarly but for the opposite state.
2457
2486
this . _protectionsPopupTPSwitchBreakageFixedLink . hidden =
2458
2487
! ContentBlockingAllowList . includes ( gBrowser . selectedBrowser ) ||
2459
- this . _protectionsPopupTPSwitch . hasAttribute ( "enabled " ) ;
2488
+ this . _protectionsPopupTPSwitch . hasAttribute ( "pressed " ) ;
2460
2489
} ,
2461
2490
2462
2491
submitBreakageReport ( uri ) {
0 commit comments