[Extension] Introduce App Security 48/155748/8
authoryh106.jung <yh106.jung@samsung.com>
Mon, 16 Oct 2017 05:17:22 +0000 (14:17 +0900)
committerjaekuk lee <juku1999@samsung.com>
Tue, 31 Oct 2017 00:43:14 +0000 (00:43 +0000)
This patch adds a new extension 'App Security' which can lock each
application by own PIN.

Change-Id: I09da544338057b50d6ea788501431adbfbced4a2
Signed-off-by: yh106.jung <yh106.jung@samsung.com>
wrt/wrt_support/extensions_repo/app_security/background.js [new file with mode: 0644]
wrt/wrt_support/extensions_repo/app_security/content.js [new file with mode: 0644]
wrt/wrt_support/extensions_repo/app_security/manifest.json [new file with mode: 0644]
wrt/wrt_support/extensions_repo/app_security/modal_style.css [new file with mode: 0644]

diff --git a/wrt/wrt_support/extensions_repo/app_security/background.js b/wrt/wrt_support/extensions_repo/app_security/background.js
new file mode 100644 (file)
index 0000000..fce6212
--- /dev/null
@@ -0,0 +1,66 @@
+const { app } = require('electron').remote;
+var messagePort;
+var appId;
+var pins;
+var verified = false;
+
+chrome.storage.local.get(null, function(items){
+  pins = items;
+});
+
+chrome.runtime.onConnect.addListener(function(port) {
+  messagePort = port;
+  messagePort.onMessage.addListener(function(message) {
+    console.log('background: ' + message);
+
+    var messages = message.split(':');
+    switch (messages[0]) {
+      case 'id':
+        if (!verified) {
+          appId = messages[1];
+          for (var id in pins) {
+            if (id === appId) {
+              if (pins[appId] === 'skip') {
+                messagePort.postMessage('verified');
+                verified = true;
+              } else {
+                messagePort.postMessage('show:verify');
+              }
+            return;
+            }
+          }
+          messagePort.postMessage('show:register');
+        }
+        break;
+      case 'register':
+        var store = {};
+        store[appId] = messages[1];
+        chrome.storage.local.set(store, function() {
+          messagePort.postMessage('verified');
+          verified = true;
+        });
+        break;
+      case 'verify':
+        if (pins[appId] === messages[1]) {
+          messagePort.postMessage('verified');
+          verified = true;
+        } else {
+          messagePort.postMessage('wrongpin');
+        }
+        break;
+      case 'skip':
+        var store = {};
+        store[appId] = 'skip';
+        chrome.storage.local.set(store, function() {
+          messagePort.postMessage('verified');
+          verified = true;
+        });
+        break;
+      case 'exit':
+        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
new file mode 100644 (file)
index 0000000..dbbb280
--- /dev/null
@@ -0,0 +1,78 @@
+const MODAL_HTML = '<div id="asModal" class="modal"> \
+                   <div class="modal-content"> \
+                   <span class="close">&times;</span> \
+                   <div class="modal-centered"> \
+                   <p id="asTitle"></p> \
+                   <input id="asPin" type="password" name="pin" pattern="[0-9]{4}"" maxlength="4"> \
+                   <input id="asSubmit" type="submit" value="Submit"> \
+                   <input id="asSkip" type="checkbox" value="Skip">Skip this app \
+                   </div> \
+                   </div> \
+                   </div>';
+
+document.body.insertAdjacentHTML('beforeend', MODAL_HTML);
+
+var modalType = 'register';
+var messagePort = chrome.runtime.connect();
+var modal = document.getElementById('asModal');
+var title = document.getElementById('asTitle');
+var pin = document.getElementById('asPin');
+var submit = document.getElementById('asSubmit');
+var skip = document.getElementById('asSkip');
+var close = document.getElementsByClassName('close')[0];
+
+messagePort.onMessage.addListener(function(message) {
+  console.log('content: ' + message);
+
+  var messages = message.split(':');
+  switch (messages[0]) {
+    case 'show':
+      modalType = messages[1];
+      showModal();
+      break;
+    case 'verified':
+      hideModal();
+      break;
+    case 'wrongpin':
+      alert('Please check the pin.');
+      pin.value = '';
+      pin.focus();
+    default:
+      break;
+  }
+});
+
+submit.onclick = function() {
+  if (asSkip.checked)
+    messagePort.postMessage('skip');
+  else if (pin.value.length === 4)
+    messagePort.postMessage(modalType + ':' + pin.value);
+}
+
+close.onclick = function() {
+  if (asSkip.checked)
+    messagePort.postMessage('skip');
+  else
+    messagePort.postMessage('exit');
+  hideModal();
+};
+
+function showModal() {
+  if (modalType === 'register') {
+    title.textContent = 'New PIN';
+
+  } else if (modalType === 'verify') {
+    title.textContent = 'Enter PIN';
+    skip.disabled = true;
+  }
+
+  modal.style.display = 'block';
+}
+
+function hideModal() {
+  modal.style.display = 'none';
+}
+
+var urls = location.href.split('/');
+console.log('id:' + urls[urls.length - 2]);
+messagePort.postMessage('id:' + urls[urls.length - 2]);
diff --git a/wrt/wrt_support/extensions_repo/app_security/manifest.json b/wrt/wrt_support/extensions_repo/app_security/manifest.json
new file mode 100644 (file)
index 0000000..90b6217
--- /dev/null
@@ -0,0 +1,17 @@
+{
+  "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"]
+    }
+  ]
+}
diff --git a/wrt/wrt_support/extensions_repo/app_security/modal_style.css b/wrt/wrt_support/extensions_repo/app_security/modal_style.css
new file mode 100644 (file)
index 0000000..0c55e0e
--- /dev/null
@@ -0,0 +1,44 @@
+/* The Modal (background) */
+.modal {
+    display: none; /* Hidden by default */
+    position: fixed; /* Stay in place */
+    z-index: 1; /* Sit on top */
+    padding-top: 100px; /* Location of the box */
+    left: 0;
+    top: 0;
+    width: 100%; /* Full width */
+    height: 100%; /* Full height */
+    overflow: auto; /* Enable scroll if needed */
+    background-color: rgb(0,0,0); /* Fallback color */
+    background-color: rgba(0,0,0,0.8); /* Black w/ opacity */
+}
+
+/* Modal Content */
+.modal-content {
+    background-color: #fefefe;
+    margin: auto;
+    padding: 20px;
+    border: 1px solid #888;
+    width: 50%;
+}
+
+.modal-centered {
+  vertical-align: middle;
+  text-align: center;
+  clear: right;
+}
+
+/* The Close Button */
+.close {
+    color: #aaaaaa;
+    float: right;
+    font-size: 28px;
+    font-weight: bold;
+}
+
+.close:hover,
+.close:focus {
+    color: #000;
+    text-decoration: none;
+    cursor: pointer;
+}