From eed68ae1a9160b575daadf8a5fbd48fa32a68d2c Mon Sep 17 00:00:00 2001 From: Matthew Noorenberghe Date: Tue, 7 Oct 2014 00:44:37 -0700 Subject: [PATCH] Bug 1077996 - Allow disabling Loop FxA support and related items (contacts, direct calling) via loop.fxa.enabled. r=mikedeboer --HG-- extra : rebase_source : 99b0d348b6725c35c048a491e83c65e5b5e1b13d --- browser/components/loop/MozLoopAPI.jsm | 7 ++++++ browser/components/loop/MozLoopService.jsm | 12 ++++++++++ browser/components/loop/content/js/panel.js | 10 +++++++- browser/components/loop/content/js/panel.jsx | 10 +++++++- .../loop/test/desktop-local/panel_test.js | 23 +++++++++++++++++++ 5 files changed, 60 insertions(+), 2 deletions(-) diff --git a/browser/components/loop/MozLoopAPI.jsm b/browser/components/loop/MozLoopAPI.jsm index dc2c2e336ffa7..84c9774e31670 100644 --- a/browser/components/loop/MozLoopAPI.jsm +++ b/browser/components/loop/MozLoopAPI.jsm @@ -474,6 +474,13 @@ function injectLoopAPI(targetWindow) { } }, + fxAEnabled: { + enumerable: true, + get: function() { + return MozLoopService.fxAEnabled; + }, + }, + logInToFxA: { enumerable: true, writable: true, diff --git a/browser/components/loop/MozLoopService.jsm b/browser/components/loop/MozLoopService.jsm index 52f9a834e46e5..653515308e1d4 100644 --- a/browser/components/loop/MozLoopService.jsm +++ b/browser/components/loop/MozLoopService.jsm @@ -85,6 +85,7 @@ let gPushHandler = null; let gHawkClient = null; let gLocalizedStrings = null; let gInitializeTimer = null; +let gFxAEnabled = true; let gFxAOAuthClientPromise = null; let gFxAOAuthClient = null; let gFxAOAuthTokenData = null; @@ -1073,6 +1074,13 @@ this.MozLoopService = { return; } + if (Services.prefs.getPrefType("loop.fxa.enabled") == Services.prefs.PREF_BOOL) { + gFxAEnabled = Services.prefs.getBoolPref("loop.fxa.enabled"); + if (!gFxAEnabled) { + this.logOutFromFxA(); + } + } + // If expiresTime is in the future then kick-off registration. if (MozLoopServiceInternal.urlExpiryTimeIsInFuture()) { gInitializeTimerFunc(); @@ -1260,6 +1268,10 @@ this.MozLoopService = { MozLoopServiceInternal.doNotDisturb = aFlag; }, + get fxAEnabled() { + return gFxAEnabled; + }, + get userProfile() { return gFxAOAuthProfile; }, diff --git a/browser/components/loop/content/js/panel.js b/browser/components/loop/content/js/panel.js index 134747ecbb455..3562c476331c6 100644 --- a/browser/components/loop/content/js/panel.js +++ b/browser/components/loop/content/js/panel.js @@ -230,6 +230,12 @@ loop.panel = (function(_, mozL10n) { render: function() { var cx = React.addons.classSet; + + // For now all of the menu entries require FxA so hide the whole gear if FxA is disabled. + if (!navigator.mozLoop.fxAEnabled) { + return null; + } + return ( React.DOM.div({className: "settings-menu dropdown"}, React.DOM.a({className: "button-settings", onClick: this.showDropdownMenu, @@ -248,6 +254,7 @@ loop.panel = (function(_, mozL10n) { __("settings_menu_item_signout") : __("settings_menu_item_signin"), onClick: this.handleClickAuthEntry, + displayed: navigator.mozLoop.fxAEnabled, icon: this._isSignedIn() ? "signout" : "signin"}) ) ) @@ -405,7 +412,7 @@ loop.panel = (function(_, mozL10n) { }, render: function() { - if (navigator.mozLoop.userProfile) { + if (!navigator.mozLoop.fxAEnabled || navigator.mozLoop.userProfile) { return null; } return ( @@ -582,6 +589,7 @@ loop.panel = (function(_, mozL10n) { return { init: init, UserIdentity: UserIdentity, + AuthLink: AuthLink, AvailabilityDropdown: AvailabilityDropdown, CallUrlResult: CallUrlResult, PanelView: PanelView, diff --git a/browser/components/loop/content/js/panel.jsx b/browser/components/loop/content/js/panel.jsx index def5147c96f9e..255c78b4eca45 100644 --- a/browser/components/loop/content/js/panel.jsx +++ b/browser/components/loop/content/js/panel.jsx @@ -230,6 +230,12 @@ loop.panel = (function(_, mozL10n) { render: function() { var cx = React.addons.classSet; + + // For now all of the menu entries require FxA so hide the whole gear if FxA is disabled. + if (!navigator.mozLoop.fxAEnabled) { + return null; + } + return (
@@ -405,7 +412,7 @@ loop.panel = (function(_, mozL10n) { }, render: function() { - if (navigator.mozLoop.userProfile) { + if (!navigator.mozLoop.fxAEnabled || navigator.mozLoop.userProfile) { return null; } return ( @@ -582,6 +589,7 @@ loop.panel = (function(_, mozL10n) { return { init: init, UserIdentity: UserIdentity, + AuthLink: AuthLink, AvailabilityDropdown: AvailabilityDropdown, CallUrlResult: CallUrlResult, PanelView: PanelView, diff --git a/browser/components/loop/test/desktop-local/panel_test.js b/browser/components/loop/test/desktop-local/panel_test.js index 0d805ea75af0c..8888dc43b655e 100644 --- a/browser/components/loop/test/desktop-local/panel_test.js +++ b/browser/components/loop/test/desktop-local/panel_test.js @@ -25,6 +25,7 @@ describe("loop.panel", function() { navigator.mozLoop = { doNotDisturb: true, + fxAEnabled: true, getStrings: function() { return JSON.stringify({textContent: "fakeText"}); }, @@ -177,7 +178,18 @@ describe("loop.panel", function() { sinon.assert.calledOnce(navigator.mozLoop.logInToFxA); }); + + it("should be hidden if FxA is not enabled", + function() { + navigator.mozLoop.fxAEnabled = false; + var view = TestUtils.renderIntoDocument(loop.panel.AuthLink()); + expect(view.getDOMNode()).to.be.null; + }); + + afterEach(function() { + navigator.mozLoop.fxAEnabled = true; }); + }); describe("SettingsDropdown", function() { var view; @@ -188,6 +200,17 @@ describe("loop.panel", function() { navigator.mozLoop.openFxASettings = sandbox.stub(); }); + afterEach(function() { + navigator.mozLoop.fxAEnabled = true; + }); + + it("should be hidden if FxA is not enabled", + function() { + navigator.mozLoop.fxAEnabled = false; + var view = TestUtils.renderIntoDocument(loop.panel.SettingsDropdown()); + expect(view.getDOMNode()).to.be.null; + }); + it("should show a signin entry when user is not authenticated", function() { navigator.mozLoop.loggedInToFxA = false;