@@ -40,6 +40,7 @@ ChromeUtils.defineESModuleGetters(this, {
40
40
FileUtils : "resource://gre/modules/FileUtils.sys.mjs" ,
41
41
NetUtil : "resource://gre/modules/NetUtil.sys.mjs" ,
42
42
PlacesUtils : "resource://gre/modules/PlacesUtils.sys.mjs" ,
43
+ PrivateBrowsingUtils : "resource://gre/modules/PrivateBrowsingUtils.sys.mjs" ,
43
44
} ) ;
44
45
45
46
const { Integration } = ChromeUtils . importESModule (
@@ -710,6 +711,24 @@ var DownloadsPanel = {
710
711
if ( ! this . _openedManually ) {
711
712
this . _delayPopupItems ( ) ;
712
713
}
714
+
715
+ let isPrivate =
716
+ window && PrivateBrowsingUtils . isContentWindowPrivate ( window ) ;
717
+
718
+ if (
719
+ // If private, show message asking whether to delete files at end of session
720
+ isPrivate &&
721
+ Services . prefs . getBoolPref (
722
+ "browser.download.enableDeletePrivate" ,
723
+ false
724
+ ) &&
725
+ ! Services . prefs . getBoolPref (
726
+ "browser.download.deletePrivate.chosen" ,
727
+ false
728
+ )
729
+ ) {
730
+ PrivateDownloadsSubview . openWhenReady ( ) ;
731
+ }
713
732
} , console . error ) ;
714
733
} , 0 ) ;
715
734
} ,
@@ -1343,7 +1362,11 @@ var DownloadsViewController = {
1343
1362
// nsIController
1344
1363
1345
1364
supportsCommand ( aCommand ) {
1346
- if ( aCommand === "downloadsCmd_clearList" ) {
1365
+ if (
1366
+ aCommand === "downloadsCmd_clearList" ||
1367
+ aCommand === "downloadsCmd_deletePrivate" ||
1368
+ aCommand === "downloadsCmd_dismissDeletePrivate"
1369
+ ) {
1347
1370
return true ;
1348
1371
}
1349
1372
// Firstly, determine if this is a command that we can handle.
@@ -1379,16 +1402,22 @@ var DownloadsViewController = {
1379
1402
1380
1403
isCommandEnabled ( aCommand ) {
1381
1404
// Handle commands that are not selection-specific.
1382
- if ( aCommand == "downloadsCmd_clearList" ) {
1383
- return DownloadsCommon . getData ( window ) . canRemoveFinished ;
1405
+ switch ( aCommand ) {
1406
+ case "downloadsCmd_clearList" : {
1407
+ return DownloadsCommon . getData ( window ) . canRemoveFinished ;
1408
+ }
1409
+ case "downloadsCmd_deletePrivate" :
1410
+ case "downloadsCmd_dismissDeletePrivate" :
1411
+ return true ;
1412
+ default : {
1413
+ // Other commands are selection-specific.
1414
+ let element = DownloadsView . richListBox . selectedItem ;
1415
+ return (
1416
+ element &&
1417
+ DownloadsView . itemForElement ( element ) . isCommandEnabled ( aCommand )
1418
+ ) ;
1419
+ }
1384
1420
}
1385
-
1386
- // Other commands are selection-specific.
1387
- let element = DownloadsView . richListBox . selectedItem ;
1388
- return (
1389
- element &&
1390
- DownloadsView . itemForElement ( element ) . isCommandEnabled ( aCommand )
1391
- ) ;
1392
1421
} ,
1393
1422
1394
1423
doCommand ( aCommand ) {
@@ -1427,6 +1456,14 @@ var DownloadsViewController = {
1427
1456
downloadsCmd_clearList ( ) {
1428
1457
DownloadsCommon . getData ( window ) . removeFinished ( ) ;
1429
1458
} ,
1459
+
1460
+ downloadsCmd_deletePrivate ( ) {
1461
+ PrivateDownloadsSubview . choose ( true /* deletePrivate */ ) ;
1462
+ } ,
1463
+
1464
+ downloadsCmd_dismissDeletePrivate ( ) {
1465
+ PrivateDownloadsSubview . choose ( false /* deletePrivate */ ) ;
1466
+ } ,
1430
1467
} ;
1431
1468
1432
1469
XPCOMUtils . defineConstant (
@@ -1781,3 +1818,66 @@ XPCOMUtils.defineConstant(
1781
1818
"DownloadsBlockedSubview" ,
1782
1819
DownloadsBlockedSubview
1783
1820
) ;
1821
+
1822
+ /**
1823
+ * Manages the private browsing downloads subview that appears when you download a file in private browsing mode
1824
+ */
1825
+ var PrivateDownloadsSubview = {
1826
+ /**
1827
+ * Slides in the private downloads subview.
1828
+ *
1829
+ * @param element
1830
+ * The download richlistitem element that was clicked.
1831
+ */
1832
+ openWhenReady ( ) {
1833
+ DownloadsView . subViewOpen = true ;
1834
+ DownloadsViewController . updateCommands ( ) ;
1835
+
1836
+ this . mainView . addEventListener ( "ViewShown" , this , { once : true } ) ;
1837
+ this . mainView . toggleAttribute ( "showing-private-browsing-choice" , true ) ;
1838
+ } ,
1839
+
1840
+ handleEvent ( event ) {
1841
+ // This is called when the main view is shown or the panel is hidden.
1842
+
1843
+ // Focus the proper element if we're going back to the main panel.
1844
+ if ( event . type == "ViewShown" ) {
1845
+ this . panelMultiView . showSubView ( this . subview ) ;
1846
+ }
1847
+ } ,
1848
+
1849
+ /**
1850
+ * Sets whether to delete files at the end of private download session
1851
+ * Based on user response to download notification prompt
1852
+ *
1853
+ * @param deletePrivate
1854
+ * True if the user chose to delete files at the end of the session
1855
+ */
1856
+ choose ( deletePrivate ) {
1857
+ if ( deletePrivate ) {
1858
+ Services . prefs . setBoolPref ( "browser.download.deletePrivate" , true ) ;
1859
+ }
1860
+ Services . prefs . setBoolPref ( "browser.download.deletePrivate.chosen" , true ) ;
1861
+ DownloadsView . subViewOpen = false ;
1862
+ this . mainView . toggleAttribute ( "showing-private-browsing-choice" , false ) ;
1863
+ this . panelMultiView . goBack ( ) ;
1864
+ } ,
1865
+ } ;
1866
+
1867
+ ChromeUtils . defineLazyGetter ( PrivateDownloadsSubview , "panelMultiView" , ( ) =>
1868
+ document . getElementById ( "downloadsPanel-multiView" )
1869
+ ) ;
1870
+
1871
+ ChromeUtils . defineLazyGetter ( PrivateDownloadsSubview , "mainView" , ( ) =>
1872
+ document . getElementById ( "downloadsPanel-mainView" )
1873
+ ) ;
1874
+
1875
+ ChromeUtils . defineLazyGetter ( PrivateDownloadsSubview , "subview" , ( ) =>
1876
+ document . getElementById ( "downloadsPanel-privateBrowsing" )
1877
+ ) ;
1878
+
1879
+ XPCOMUtils . defineConstant (
1880
+ this ,
1881
+ "PrivateDownloadsSubview" ,
1882
+ PrivateDownloadsSubview
1883
+ ) ;
0 commit comments