diff options
author | Daniel Narvaez <dwnarvaez@gmail.com> | 2013-02-06 13:49:14 (GMT) |
---|---|---|
committer | Daniel Narvaez <dwnarvaez@gmail.com> | 2013-02-06 13:49:14 (GMT) |
commit | 821413607a0718156f9d25d895e89b1c3d37aa8b (patch) | |
tree | 01c285af734ed5bba64b73b489e1e0226a94a262 /apps/system/js/captive_portal.js | |
parent | c110fb485b3af0066c6df7aeac8c055e9d767efa (diff) |
Copy various bits from gaia
Diffstat (limited to 'apps/system/js/captive_portal.js')
-rw-r--r-- | apps/system/js/captive_portal.js | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/apps/system/js/captive_portal.js b/apps/system/js/captive_portal.js new file mode 100644 index 0000000..b23cb0d --- /dev/null +++ b/apps/system/js/captive_portal.js @@ -0,0 +1,73 @@ +/* -*Mode: js; js-indent-level: 2; indent-tabs-mode: nil -**/ +/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */ +'use strict'; + +var CaptivePortalLogin = (function() { + var eventId; + var isManualConnect = false; + var settings = window.navigator.mozSettings; + var notification = null; + var wifiManager = window.navigator.mozWifiManager; + var _ = window.navigator.mozL10n.get; + var captiveNotification_onTap = null; + + function handleLogin(id, url) { + //captive portal login needed + eventId = id; + var currentNetwork = wifiManager.connection.network; + var networkName = (currentNetwork && currentNetwork.ssid) ? + currentNetwork.ssid : ''; + var message = _('captive-wifi-available', { networkName: networkName}); + if (!isManualConnect) { + notification = NotificationScreen.addNotification({ + id: id, title: '', text: message, icon: null + }); + captiveNotification_onTap = function() { + notification.removeEventListener('tap', captiveNotification_onTap); + captiveNotification_onTap = null; + NotificationScreen.removeNotification(id); + new MozActivity({ + name: 'view', + data: { type: 'url', url: url } + }); + }; + notification.addEventListener('tap', captiveNotification_onTap); + } else { + settings.createLock().set({'wifi.connect_via_settings': false}); + new MozActivity({ + name: 'view', + data: { type: 'url', url: url } + }); + } + } + + function handleLoginAbort(id) { + if (id === eventId && notification) { + if (notification.parentNode) { + if (captiveNotification_onTap) { + notification.removeEventListener('tap', captiveNotification_onTap); + captiveNotification_onTap = null; + } + NotificationScreen.removeNotification(id); + notification = null; + } + } + } + + window.addEventListener('mozChromeEvent', function handleChromeEvent(e) { + switch (e.detail.type) { + case 'captive-portal-login': + handleLogin(e.detail.id, e.detail.url); + break; + case 'captive-portal-login-abort': + handleLoginAbort(e.detail.id); + break; + } + }); + + // Using settings API to know whether user is manually selecting + // wifi AP from settings app. + SettingsListener.observe('wifi.connect_via_settings', true, function(value) { + isManualConnect = value; + }); +})(); |