From d3547ee818ac093c7078a275f57c09badad5a68e Mon Sep 17 00:00:00 2001 From: Michael Kaply Date: Fri, 4 Oct 2019 19:47:56 +0000 Subject: [PATCH] Bug 158968 - Implement kiosk mode. r=Gijs Differential Revision: https://phabricator.services.mozilla.com/D41848 --HG-- extra : moz-landing-system : lando --- .../browser-fullScreenAndPointerLock.js | 21 +++++++++++++++++-- browser/base/content/browser.js | 12 ++++++++++- browser/base/content/nsContextMenu.js | 11 ++++++++++ browser/components/BrowserContentHandler.jsm | 10 +++++++++ .../enterprisepolicies/docs/index.rst | 18 ++++++++++++++++ .../components/enterprisepolicies/moz.build | 2 ++ browser/components/nsIBrowserHandler.idl | 1 + browser/docs/index.rst | 1 + 8 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 browser/components/enterprisepolicies/docs/index.rst diff --git a/browser/base/content/browser-fullScreenAndPointerLock.js b/browser/base/content/browser-fullScreenAndPointerLock.js index 28779f2d1809..6597dcb70124 100644 --- a/browser/base/content/browser-fullScreenAndPointerLock.js +++ b/browser/base/content/browser-fullScreenAndPointerLock.js @@ -8,6 +8,17 @@ ChromeUtils.import("resource:///modules/PermissionUI.jsm", this); +var { XPCOMUtils } = ChromeUtils.import( + "resource://gre/modules/XPCOMUtils.jsm" +); + +XPCOMUtils.defineLazyServiceGetter( + this, + "BrowserHandler", + "@mozilla.org/browser/clh;1", + "nsIBrowserHandler" +); + var PointerlockFsWarning = { _element: null, _origin: null, @@ -649,6 +660,9 @@ var FullScreen = { }, showNavToolbox(trackMouse = true) { + if (BrowserHandler.kiosk) { + return; + } this._fullScrToggler.hidden = true; gNavToolbox.removeAttribute("fullscreenShouldAnimate"); gNavToolbox.style.marginTop = ""; @@ -690,11 +704,13 @@ var FullScreen = { } // a textbox in chrome is focused (location bar anyone?): don't collapse chrome + // unless we are kiosk mode let focused = document.commandDispatcher.focusedElement; if ( focused && focused.ownerDocument == document && - focused.localName == "input" + focused.localName == "input" && + !BrowserHandler.kiosk ) { // But try collapse the chrome again when anything happens which can make // it lose the focus. We cannot listen on "blur" event on focused here @@ -725,7 +741,8 @@ var FullScreen = { if ( aAnimate && - Services.prefs.getBoolPref("toolkit.cosmeticAnimations.enabled") + Services.prefs.getBoolPref("toolkit.cosmeticAnimations.enabled") && + !BrowserHandler.kiosk ) { gNavToolbox.setAttribute("fullscreenShouldAnimate", true); // Hide the fullscreen toggler until the transition ends. diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js index 684ac85f82cb..62f8902b3c75 100644 --- a/browser/base/content/browser.js +++ b/browser/base/content/browser.js @@ -266,6 +266,7 @@ XPCOMUtils.defineLazyServiceGetters(this, { ], Marionette: ["@mozilla.org/remote/marionette;1", "nsIMarionette"], WindowsUIUtils: ["@mozilla.org/windows-ui-utils;1", "nsIWindowsUIUtils"], + BrowserHandler: ["@mozilla.org/browser/clh;1", "nsIBrowserHandler"], }); if (AppConstants.MOZ_CRASHREPORTER) { @@ -2178,6 +2179,15 @@ var gBrowserInit = { Services.obs.notifyObservers(window, "browser-delayed-startup-finished"); TelemetryTimestamps.add("delayedStartupFinished"); + + if (BrowserHandler.kiosk) { + // We don't modify popup windows for kiosk mode + if (!gURLBar.readOnly) { + // Don't show status tooltips in kiosk mode + document.getElementById("statuspanel").hidden = true; + window.fullScreen = true; + } + } }, _setInitialFocus() { @@ -3853,7 +3863,7 @@ function getDefaultHomePage() { } function BrowserFullScreen() { - window.fullScreen = !window.fullScreen; + window.fullScreen = !window.fullScreen || BrowserHandler.kiosk; } function getWebNavigation() { diff --git a/browser/base/content/nsContextMenu.js b/browser/base/content/nsContextMenu.js index 2d93901aa231..f2919e6c84d9 100644 --- a/browser/base/content/nsContextMenu.js +++ b/browser/base/content/nsContextMenu.js @@ -35,9 +35,20 @@ XPCOMUtils.defineLazyGetter(this, "ReferrerInfo", () => ) ); +XPCOMUtils.defineLazyServiceGetter( + this, + "BrowserHandler", + "@mozilla.org/browser/clh;1", + "nsIBrowserHandler" +); + var gContextMenuContentData = null; function openContextMenu(aMessage, aBrowser, aActor) { + if (BrowserHandler.kiosk) { + // Don't display context menus in kiosk mode + return; + } let data = aMessage.data; let browser = aBrowser; let actor = aActor; diff --git a/browser/components/BrowserContentHandler.jsm b/browser/components/BrowserContentHandler.jsm index 3bee9063b9f1..816804234808 100644 --- a/browser/components/BrowserContentHandler.jsm +++ b/browser/components/BrowserContentHandler.jsm @@ -93,6 +93,8 @@ function resolveURIInternal(aCmdLine, aArgument) { return uri; } +let gKiosk = false; + let gRemoteInstallPage = null; function getNewInstallPage() { @@ -393,6 +395,9 @@ nsBrowserContentHandler.prototype = { /* nsICommandLineHandler */ handle: function bch_handle(cmdLine) { + if (cmdLine.handleFlag("kiosk", false)) { + gKiosk = true; + } if (cmdLine.handleFlag("browser", false)) { openBrowserWindow(cmdLine, gSystemPrincipal); cmdLine.preventDefault = true; @@ -606,6 +611,7 @@ nsBrowserContentHandler.prototype = { info += " --setDefaultBrowser Set this app as the default browser.\n"; info += " --first-startup Run post-install actions before opening a new window.\n"; + info += " --kiosk Start the browser in kiosk mode.\n"; return info; }, @@ -821,6 +827,10 @@ nsBrowserContentHandler.prototype = { return this.mFeatures; }, + get kiosk() { + return gKiosk; + }, + /* nsIContentHandler */ handleContent: function bch_handleContent(contentType, context, request) { diff --git a/browser/components/enterprisepolicies/docs/index.rst b/browser/components/enterprisepolicies/docs/index.rst new file mode 100644 index 000000000000..c9528161d8c9 --- /dev/null +++ b/browser/components/enterprisepolicies/docs/index.rst @@ -0,0 +1,18 @@ +Enterprise Policies +=================== + +Introduction +------------ + +Firefox provides policies to manage various aspects of Firefox. The best documentation is in `GitHub `_. + +Kiosk Mode +---------- + +The kiosk mode provided by Firefox on the command line (--kiosk) is a very basic mode intended for kiosks where the content loaded in the browser is strictly limited by the owner of the kiosk and either there is no keyboard or keyboard access is limited (particularly Ctrl and Alt). It is their responsibility to ensure the content does not surprise/confuse users or break browser UI in this setup. + +It does three main things: + +1. Switch all main browser windows (not popup windows) into full screen mode. +2. Don't show the context menu. +3. Don't show status for URLs or pageloading. diff --git a/browser/components/enterprisepolicies/moz.build b/browser/components/enterprisepolicies/moz.build index b42c784b7db9..165bcb0eb97d 100644 --- a/browser/components/enterprisepolicies/moz.build +++ b/browser/components/enterprisepolicies/moz.build @@ -7,6 +7,8 @@ with Files("**"): BUG_COMPONENT = ("Firefox", "Enterprise Policies") +SPHINX_TREES['docs'] = 'docs' + DIRS += [ 'helpers', 'schemas', diff --git a/browser/components/nsIBrowserHandler.idl b/browser/components/nsIBrowserHandler.idl index 74292f9d975a..dc33c434d075 100644 --- a/browser/components/nsIBrowserHandler.idl +++ b/browser/components/nsIBrowserHandler.idl @@ -11,6 +11,7 @@ interface nsIBrowserHandler : nsISupports { attribute AUTF8String startPage; attribute AUTF8String defaultArgs; + attribute boolean kiosk; /** * Extract the width and height specified on the command line, if present. diff --git a/browser/docs/index.rst b/browser/docs/index.rst index c91f2520d174..3f77665c8bda 100644 --- a/browser/docs/index.rst +++ b/browser/docs/index.rst @@ -9,6 +9,7 @@ This is the nascent documentation of the Firefox front-end code. urlbar/index BrowserUsageTelemetry + components/enterprisepolicies/docs/index extensions/formautofill/docs/index components/newtab/docs/index installer/windows/installer/index