From 444875c6ef5a1760784a0f72ac5973afe6ca70d1 Mon Sep 17 00:00:00 2001 From: Sanghyup Lee Date: Thu, 16 Nov 2017 14:32:57 +0900 Subject: [PATCH] [WRT][Extension] Improve app securiy extension This patch includes below changes. - User can set current application's pin with page action. - Register popup doesn't displayed by default. - Application will close with 'X' button only when verificaton failed. Change-Id: I3587ae685d4def98bfa7fbcb4f2ce01e00b22f94 Signed-off-by: Sanghyup Lee --- .../extensions_repo/app_security/background.js | 27 ++++++++++++++++++---- .../extensions_repo/app_security/content.js | 11 ++++++++- .../extensions_repo/app_security/manifest.json | 8 ++++--- 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/wrt/wrt_support/extensions_repo/app_security/background.js b/wrt/wrt_support/extensions_repo/app_security/background.js index fce6212..8dbe397 100644 --- a/wrt/wrt_support/extensions_repo/app_security/background.js +++ b/wrt/wrt_support/extensions_repo/app_security/background.js @@ -4,8 +4,21 @@ var appId; var pins; var verified = false; -chrome.storage.local.get(null, function(items){ - pins = items; +function updatePins() { + chrome.storage.local.get(null, function(items){ + pins = items; + }); +} + +updatePins(); + +chrome.pageAction.onClicked.addListener(function(tab) { + if (verified) { + if (pins[appId]) + messagePort.postMessage('reregister:' + pins[appId]); + else + messagePort.postMessage('show:register'); + } }); chrome.runtime.onConnect.addListener(function(port) { @@ -26,10 +39,11 @@ chrome.runtime.onConnect.addListener(function(port) { } else { messagePort.postMessage('show:verify'); } - return; + return; } } - messagePort.postMessage('show:register'); + // Don't show register popup by default. + verified = true; } break; case 'register': @@ -38,6 +52,7 @@ chrome.runtime.onConnect.addListener(function(port) { chrome.storage.local.set(store, function() { messagePort.postMessage('verified'); verified = true; + updatePins(); }); break; case 'verify': @@ -55,9 +70,11 @@ chrome.runtime.onConnect.addListener(function(port) { messagePort.postMessage('verified'); verified = true; }); + updatePins(); break; case 'exit': - app.quit(); + if (!verified) + app.quit(); break; default: break; diff --git a/wrt/wrt_support/extensions_repo/app_security/content.js b/wrt/wrt_support/extensions_repo/app_security/content.js index dbbb280..ea0cc2f 100644 --- a/wrt/wrt_support/extensions_repo/app_security/content.js +++ b/wrt/wrt_support/extensions_repo/app_security/content.js @@ -37,6 +37,15 @@ messagePort.onMessage.addListener(function(message) { alert('Please check the pin.'); pin.value = ''; pin.focus(); + break; + case 'reregister': + modalType = 'register'; + if (messages[1] == 'skip') + skip.checked = true; + else + pin.value = messages[1]; + showModal(); + break; default: break; } @@ -60,7 +69,7 @@ close.onclick = function() { function showModal() { if (modalType === 'register') { title.textContent = 'New PIN'; - + skip.disabled = false; } else if (modalType === 'verify') { title.textContent = 'Enter PIN'; skip.disabled = true; diff --git a/wrt/wrt_support/extensions_repo/app_security/manifest.json b/wrt/wrt_support/extensions_repo/app_security/manifest.json index 90b6217..59c3e57 100644 --- a/wrt/wrt_support/extensions_repo/app_security/manifest.json +++ b/wrt/wrt_support/extensions_repo/app_security/manifest.json @@ -2,16 +2,18 @@ "manifest_version": 2, "name": "app_security", "version": "1.0.0", - "background": { "scripts": ["background.js"] }, - "content_scripts": [ { "matches": [""], "js": ["content.js"], "css": ["modal_style.css"] } - ] + ], + "page_action": { + "default_icon" : "icon.png" + }, + "manifest_version": 2 } -- 2.7.4