Skip to content

Commit 18846f8

Browse files
author
Alexandre Lissy
committed
WIP FELT: Add an about:restartforced page
Differential Revision: https://phabricator.services.mozilla.com/D262889
1 parent 688e57f commit 18846f8

File tree

10 files changed

+143
-0
lines changed

10 files changed

+143
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
5+
/* eslint-env mozilla/remote-page */
6+
7+
var AboutRestartForced = {
8+
/* Only do autofocus if we're the toplevel frame; otherwise we
9+
don't want to call attention to ourselves! The key part is
10+
that autofocus happens on insertion into the tree, so we
11+
can remove the button, add @autofocus, and reinsert the
12+
button.
13+
*/
14+
addAutofocus() {
15+
if (window.top == window) {
16+
var button = document.getElementById("restart");
17+
var parent = button.parentNode;
18+
button.remove();
19+
button.setAttribute("autofocus", "true");
20+
parent.insertAdjacentElement("afterbegin", button);
21+
}
22+
},
23+
restart() {
24+
Services.startup.quit(
25+
Ci.nsIAppStartup.eRestart | Ci.nsIAppStartup.eAttemptQuit
26+
);
27+
},
28+
init() {
29+
this.addAutofocus();
30+
},
31+
};
32+
33+
AboutRestartForced.init();
34+
35+
let restartButton = document.getElementById("restart");
36+
restartButton.onclick = function () {
37+
AboutRestartForced.restart();
38+
};
39+
40+
// Dispatch this event so tests can detect that we finished loading the page.
41+
let event = new CustomEvent("AboutRestartForcedLoad", { bubbles: true });
42+
document.dispatchEvent(event);
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<!-- This Source Code Form is subject to the terms of the Mozilla Public
3+
- License, v. 2.0. If a copy of the MPL was not distributed with this
4+
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
5+
<!DOCTYPE html>
6+
7+
<html xmlns="http://www.w3.org/1999/xhtml">
8+
<head>
9+
<meta
10+
http-equiv="Content-Security-Policy"
11+
content="default-src chrome:; object-src 'none'"
12+
/>
13+
<meta name="color-scheme" content="light dark" />
14+
<title data-l10n-id="restart-forced-title"></title>
15+
<link
16+
rel="stylesheet"
17+
type="text/css"
18+
media="all"
19+
href="chrome://browser/skin/aboutRestartRequired.css"
20+
/>
21+
<!-- If the location of the favicon is changed here, the
22+
FAVICON_ERRORPAGE_URL symbol in
23+
toolkit/components/places/src/nsFaviconService.h should be updated. -->
24+
<link
25+
rel="icon"
26+
type="image/png"
27+
id="favicon"
28+
href="chrome://global/skin/icons/info.svg"
29+
/>
30+
<link rel="localization" href="branding/brand.ftl" />
31+
<link rel="localization" href="browser/aboutRestartForced.ftl" />
32+
</head>
33+
<body>
34+
<!-- PAGE CONTAINER (for styling purposes only) -->
35+
<div id="errorPageContainer">
36+
<div id="text-container">
37+
<div class="title" id="title">
38+
<h1
39+
class="title-text"
40+
id="title-text"
41+
data-l10n-id="restart-forced-heading"
42+
/>
43+
</div>
44+
<div id="errorLongContent">
45+
<div id="errorLongDesc">
46+
<p data-l10n-id="restart-forced-intro" />
47+
<p data-l10n-id="window-restoration-info" />
48+
</div>
49+
</div>
50+
</div>
51+
<!-- Restart Button -->
52+
<div id="restartButtonContainer" class="button-container">
53+
<button
54+
id="restart"
55+
data-l10n-id="restart-button-label"
56+
class="primary"
57+
autocomplete="off"
58+
></button>
59+
</div>
60+
</div>
61+
</body>
62+
<script src="chrome://browser/content/aboutRestartForced.js" />
63+
</html>

browser/base/jar.mn

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ browser.jar:
1010
content/browser/aboutDialog.css (content/aboutDialog.css)
1111
content/browser/aboutRestartRequired.js (content/aboutRestartRequired.js)
1212
content/browser/aboutRestartRequired.xhtml (content/aboutRestartRequired.xhtml)
13+
content/browser/aboutRestartForced.js (content/aboutRestartForced.js)
14+
content/browser/aboutRestartForced.xhtml (content/aboutRestartForced.xhtml)
1315
content/browser/aboutRobots.xhtml (content/aboutRobots.xhtml)
1416
content/browser/aboutRobots.js (content/aboutRobots.js)
1517
content/browser/aboutRobots.css (content/aboutRobots.css)

browser/components/about/AboutRedirector.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ static const RedirEntry kRedirMap[] = {
126126
nsIAboutModule::HIDE_FROM_ABOUTABOUT},
127127
{"restartrequired", "chrome://browser/content/aboutRestartRequired.xhtml",
128128
nsIAboutModule::ALLOW_SCRIPT | nsIAboutModule::HIDE_FROM_ABOUTABOUT},
129+
{"restartforced", "chrome://browser/content/aboutRestartForced.xhtml",
130+
nsIAboutModule::ALLOW_SCRIPT | nsIAboutModule::HIDE_FROM_ABOUTABOUT},
129131
{"protections", "chrome://browser/content/protections.html",
130132
nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT |
131133
nsIAboutModule::URI_MUST_LOAD_IN_CHILD | nsIAboutModule::ALLOW_SCRIPT |

browser/components/about/components.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pages = [
2121
'profiling',
2222
'reader',
2323
'restartrequired',
24+
'restartforced',
2425
'rights',
2526
'robots',
2627
'sessionrestore',
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# This Source Code Form is subject to the terms of the Mozilla Public
2+
# License, v. 2.0. If a copy of the MPL was not distributed with this
3+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
4+
5+
restart-forced-title = Restart Forced
6+
restart-forced-heading = Restart to Keep Using { -brand-short-name }
7+
restart-forced-intro = Policy requires that { -brand-short-name } needs to be restarted.
8+
window-restoration-info = Your windows and tabs will be quickly restored, but private ones will not.
9+
10+
restart-button-label = Restart { -brand-short-name }

docshell/base/nsDocShell.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3559,6 +3559,16 @@ nsDocShell::DisplayLoadError(nsresult aError, nsIURI* aURI,
35593559
errorPage.AssignLiteral("restartrequired");
35603560
error = "restartrequired";
35613561

3562+
// DisplayLoadError requires a non-empty messageStr to proceed and call
3563+
// LoadErrorPage. If the page doesn't have a title, we will use a blank
3564+
// space which will be trimmed and thus treated as empty by the front-end.
3565+
if (messageStr.IsEmpty()) {
3566+
messageStr.AssignLiteral(u" ");
3567+
}
3568+
} else if (NS_ERROR_RESTART_FORCED == aError) {
3569+
errorPage.AssignLiteral("restartforced");
3570+
error = "restartForced";
3571+
35623572
// DisplayLoadError requires a non-empty messageStr to proceed and call
35633573
// LoadErrorPage. If the page doesn't have a title, we will use a blank
35643574
// space which will be trimmed and thus treated as empty by the front-end.
@@ -6319,6 +6329,7 @@ nsresult nsDocShell::FilterStatusForErrorPage(
63196329
aStatus == NS_ERROR_PROXY_TOO_MANY_REQUESTS ||
63206330
aStatus == NS_ERROR_MALFORMED_URI ||
63216331
aStatus == NS_ERROR_BLOCKED_BY_POLICY ||
6332+
aStatus == NS_ERROR_RESTART_FORCED ||
63226333
aStatus == NS_ERROR_DOM_COOP_FAILED ||
63236334
aStatus == NS_ERROR_DOM_COEP_FAILED ||
63246335
aStatus == NS_ERROR_DOM_INVALID_HEADER_VALUE) &&
@@ -8536,6 +8547,9 @@ nsresult nsDocShell::PerformRetargeting(nsDocShellLoadState* aLoadState) {
85368547
if (shouldLoad == nsIContentPolicy::REJECT_POLICY) {
85378548
return NS_ERROR_BLOCKED_BY_POLICY;
85388549
}
8550+
if (shouldLoad == nsIContentPolicy::REJECT_RESTARTFORCED) {
8551+
return NS_ERROR_RESTART_FORCED;
8552+
}
85398553
}
85408554

85418555
return NS_ERROR_CONTENT_BLOCKED;

dom/base/nsIContentPolicy.idl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,11 @@ interface nsIContentPolicy : nsISupports
522522
*/
523523
const short REJECT_POLICY = -5;
524524

525+
/**
526+
* Returned from shouldLoad or shouldProcess if restart is forced
527+
*/
528+
const short REJECT_RESTARTFORCED = -6;
529+
525530
/**
526531
* Returned from shouldLoad or shouldProcess if the load or process request
527532
* is not rejected.

dom/security/nsContentSecurityManager.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,9 @@ static nsresult DoContentSecurityChecks(nsIChannel* aChannel,
539539
if (shouldLoad == nsIContentPolicy::REJECT_POLICY) {
540540
return NS_ERROR_BLOCKED_BY_POLICY;
541541
}
542+
if (shouldLoad == nsIContentPolicy::REJECT_RESTARTFORCED) {
543+
return NS_ERROR_RESTART_FORCED;
544+
}
542545
}
543546
return NS_ERROR_CONTENT_BLOCKED;
544547
}

xpcom/base/ErrorList.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -984,6 +984,7 @@ def SUCCESS(code):
984984
# Error code for when the content process had a different buildID than the
985985
# parent
986986
errors["NS_ERROR_BUILDID_MISMATCH"] = FAILURE(17)
987+
errors["NS_ERROR_RESTART_FORCED"] = FAILURE(18)
987988

988989
errors["NS_PROPTABLE_PROP_OVERWRITTEN"] = SUCCESS(11)
989990
# Error codes for FindBroadcaster in XULBroadcastManager.cpp

0 commit comments

Comments
 (0)