[WRT][Extension] Improve app securiy extension 15/160415/10
authorSanghyup Lee <sh53.lee@samsung.com>
Thu, 16 Nov 2017 05:32:57 +0000 (14:32 +0900)
committerSungsik Han <ss440.han@samsung.com>
Tue, 21 Nov 2017 08:11:48 +0000 (08:11 +0000)
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 <sh53.lee@samsung.com>
wrt/wrt_support/extensions_repo/app_security/background.js
wrt/wrt_support/extensions_repo/app_security/content.js
wrt/wrt_support/extensions_repo/app_security/manifest.json

index fce6212..8dbe397 100644 (file)
@@ -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;
index dbbb280..ea0cc2f 100644 (file)
@@ -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;
index 90b6217..59c3e57 100644 (file)
@@ -2,16 +2,18 @@
   "manifest_version": 2,
   "name": "app_security",
   "version": "1.0.0",
-
   "background": {
     "scripts": ["background.js"]
   },
-
   "content_scripts": [
     {
       "matches": ["<all_urls>"],
       "js": ["content.js"],
       "css": ["modal_style.css"]
     }
-  ]
+  ],
+  "page_action": {
+    "default_icon" : "icon.png"
+  },
+  "manifest_version": 2
 }