Bug 1205334 - Part 2: Show an error message in about:accounts when restricted. r=antlam,sebastian
authorNick Alexander <nalexander@mozilla.com>
Thu, 17 Sep 2015 14:51:54 -0400
changeset 295951 39669760cd58e5ae5c1900cd2ab6382c5f9a033a
parent 295950 58045af5f29504df9a0f7598ac8180aa74c34d0d
child 295952 f8c449c0dfd45c6a57074fbd5d8d4c53980b14cb
push id5245
push userraliiev@mozilla.com
push dateThu, 29 Oct 2015 11:30:51 +0000
treeherdermozilla-beta@dac831dc1bd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersantlam, sebastian
bugs1205334
milestone43.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1205334 - Part 2: Show an error message in about:accounts when restricted. r=antlam,sebastian
mobile/android/chrome/content/aboutAccounts.js
mobile/android/chrome/content/aboutAccounts.xhtml
mobile/android/locales/en-US/chrome/aboutAccounts.dtd
--- a/mobile/android/chrome/content/aboutAccounts.js
+++ b/mobile/android/chrome/content/aboutAccounts.js
@@ -32,16 +32,19 @@ Cu.import("resource://gre/modules/Servic
 Cu.import("resource://gre/modules/XPCOMUtils.jsm"); /*global XPCOMUtils */
 
 const ACTION_URL_PARAM = "action";
 
 const COMMAND_LOADED = "fxaccounts:loaded";
 
 const log = Cu.import("resource://gre/modules/AndroidLog.jsm", {}).AndroidLog.bind("FxAccounts");
 
+XPCOMUtils.defineLazyServiceGetter(this, "ParentalControls",
+  "@mozilla.org/parental-controls-service;1", "nsIParentalControlsService");
+
 // Shows the toplevel element with |id| to be shown - all other top-level
 // elements are hidden.
 // If |id| is 'spinner', then 'remote' is also shown, with opacity 0.
 function show(id) {
   let allTop = document.querySelectorAll(".toplevel");
   for (let elt of allTop) {
     if (elt.getAttribute("id") == id) {
       elt.style.display = 'block';
@@ -181,16 +184,29 @@ function getURLForAction(action, urlPara
 function updateDisplayedEmail(user) {
   let emailDiv = document.getElementById("email");
   if (emailDiv && user) {
     emailDiv.textContent = user.email;
   }
 }
 
 function init() {
+  // Test for restrictions before getFirefoxAccount(), since that will fail if
+  // we are restricted.
+  if (!ParentalControls.isAllowed(ParentalControls.MODIFY_ACCOUNTS)) {
+    // It's better to log and show an error message than to invite user
+    // confusion by removing about:accounts entirely.  That is, if the user is
+    // restricted, this way they'll discover as much and may be able to get
+    // out of their restricted profile.  If we remove about:accounts entirely,
+    // it will look like Fennec is buggy, and the user will be very confused.
+    log.e("This profile cannot connect to Firefox Accounts: showing restricted error.");
+    show("restrictedError");
+    return;
+  }
+
   Accounts.getFirefoxAccount().then(user => {
     // It's possible for the window to start closing before getting the user
     // completes.  Tests in particular can cause this.
     if (window.closed) {
       return;
     }
 
     updateDisplayedEmail(user);
--- a/mobile/android/chrome/content/aboutAccounts.xhtml
+++ b/mobile/android/chrome/content/aboutAccounts.xhtml
@@ -64,11 +64,20 @@
           <div class="text">&aboutAccounts.noConnection.title;</div>
         </div>
         <div class="button-row">
           <button id="buttonRetry" class="button" tabindex="1">&aboutAccounts.retry.label;</button>
         </div>
       </div>
     </div>
 
+    <div id="restrictedError" class="toplevel">
+      <div class="container flex-column">
+        <div class="text-container flex-column">
+          <div class="text">&aboutAccounts.restrictedError.title;</div>
+          <div class="hint">&aboutAccounts.restrictedError.description;</div>
+        </div>
+      </div>
+    </div>
+
     <script type="application/javascript;version=1.8" src="chrome://browser/content/aboutAccounts.js"></script>
   </body>
 </html>
--- a/mobile/android/locales/en-US/chrome/aboutAccounts.dtd
+++ b/mobile/android/locales/en-US/chrome/aboutAccounts.dtd
@@ -3,8 +3,11 @@
    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
 
 <!ENTITY aboutAccounts.connected.title "Firefox Accounts">
 <!ENTITY aboutAccounts.connected.description "You are connected as">
 <!ENTITY aboutAccounts.syncPreferences.label "Tap here to check Sync settings">
 
 <!ENTITY aboutAccounts.noConnection.title "No Internet connection">
 <!ENTITY aboutAccounts.retry.label "Try again">
+
+<!ENTITY aboutAccounts.restrictedError.title "Restricted">
+<!ENTITY aboutAccounts.restrictedError.description "You cannot manage Firefox Accounts from this profile.">