Enable nodeIntegration depending on the availability of Addons 80/202780/4
authorhyunduk.kim <hyunduk.kim@samsung.com>
Thu, 4 Apr 2019 06:16:26 +0000 (23:16 -0700)
committerhyunduk.kim <hyunduk.kim@samsung.com>
Thu, 11 Apr 2019 08:45:22 +0000 (01:45 -0700)
  . Add a method 'isAddonAvailable' to check the availablity of Addons

  . Set nodeIntegration in WebPreferences as true when Addons are
    available. That will enable node binding in renderer.
    To do that, this patch should work together with commit [1].

  [1] https://review.tizen.org/gerrit/202237

Change-Id: Ibfef3b1b6dd32db899d0de75ca90f46e07800756
Signed-off-by: hyunduk.kim <hyunduk.kim@samsung.com>
wrt_app/src/extension_manager.js
wrt_app/src/runtime.js
wrt_app/src/web_application.js

index 6d0f793e837322a0873a55b98147f972f9203ab0..293a3275805ddf58fa570471cfdd22c86a53bc11 100755 (executable)
@@ -18,6 +18,8 @@
 
 const fs = require('fs');
 const path = require('path');
+const EXT_PATH =
+          path.join(require('os').homedir(), 'data/electron/runtime_addon');
 const MANIFEST_FILE = 'manifest.json';
 const PRELOAD_JS_FILE = 'preload.js';
 const EXTENSIONS_DB_FILE = 'extensions_db.json';
@@ -28,8 +30,6 @@ const {BrowserWindow} = require('electron');
 
 class ExtensionManager {
     constructor() {
-        this.ext_path_ = path.join(__dirname.split('wrt')[0], 'electron/runtime_addon');
-        console.log('Extension path : ' + this.ext_path_);
         this.extensions_list_ = null;
         this.extensions_ = null;
         this.extensions_API_ = null;
@@ -49,7 +49,7 @@ class ExtensionManager {
         var extensions_list = [],
             filenames;
         try {
-            filenames = fs.readdirSync(this.ext_path_);
+            filenames = fs.readdirSync(EXT_PATH);
         } catch (e) {
             console.error('LoadExtensionsListFromPath - fs.readdirSync error : ' + e);
             return false;
@@ -57,7 +57,7 @@ class ExtensionManager {
         if (filenames) {
             for (var i in filenames) {
                 var filename = filenames[i],
-                    filepath = path.join(this.ext_path_, filename),
+                    filepath = path.join(EXT_PATH, filename),
                     stats = fs.statSync(filepath);
 
                 if (stats.isDirectory()) {
@@ -91,7 +91,7 @@ class ExtensionManager {
 
     loadJsonDB(db_path) {
         if (!db_path) {
-            db_path = path.join(this.ext_path_, EXTENSIONS_DB_FILE);
+            db_path = path.join(EXT_PATH, EXTENSIONS_DB_FILE);
         }
         var extensions_list;
         try {
@@ -108,7 +108,7 @@ class ExtensionManager {
 
     saveJsonDB(db_path) {
         if (!db_path) {
-            db_path = path.join(this.ext_path_, EXTENSIONS_DB_FILE);
+            db_path = path.join(EXT_PATH, EXTENSIONS_DB_FILE);
         }
         var fd;
         try {
@@ -124,7 +124,7 @@ class ExtensionManager {
 
     generateJsFromAPIs(js_path) {
         if (!js_path) {
-            js_path = path.join(this.ext_path_, PRELOAD_JS_FILE);
+            js_path = path.join(EXT_PATH, PRELOAD_JS_FILE);
         }
         console.log('preload.js : ' + js_path);
         var fd;
@@ -333,6 +333,10 @@ class ExtensionManager {
         }
     }
 
+    isAddonAvailable() {
+        return this.extensions_ != null;
+    }
+
     static getManifestFile() {
         return MANIFEST_FILE;
     }
@@ -342,7 +346,7 @@ class ExtensionManager {
     }
 
     static getExtensionsPath() {
-        return ext_path_;
+        return EXT_PATH;
     }
 }
 
index eb4559226b859d0b1b13157a0e4d3b60985f49ef..7b9af347c45f6a525ec731a0c47eeb2d1b210df7 100755 (executable)
@@ -99,6 +99,8 @@ class Runtime {
                 console.log('Tizen Web App launch');
                 if (!_this.webApplication) {
                     console.log('Creating WebApplication');
+                    options.isAddonAvailable = !options.noExtensions &&
+                            _this.extensionManager.isAddonAvailable();
                     options.launchMode = appControl.getData('http://samsung.com/appcontrol/data/launch_mode');
                     _this.webApplication = new WebApplication(options);
                     _this.webApplication.mainWindow.loadURL(src);
index b9c9e3a13fcb8c6be700c75c8dcc8ade2fc696df..de453707dc37df4b69207e0ddb7750369e99d8ac 100755 (executable)
@@ -22,7 +22,7 @@ const wrt = require('../browser/wrt');
 
 class WebApplication {
     constructor(options) {
-        let winopt = this.getBrowserWindowOption();
+        let winopt = this.getBrowserWindowOption(options);
         console.log('opt: ' + JSON.stringify(winopt));
         this.mainWindow = new BrowserWindow(winopt);
         if (options.devMode) {
@@ -42,12 +42,12 @@ class WebApplication {
             this.preloadState = 'none';
         }
     }
-    getBrowserWindowOption() {
+    getBrowserWindowOption(options) {
         return {
             fullscreen: false,
             show: false,
             webPreferences: {
-                nodeIntegration: false,
+                nodeIntegration: options.isAddonAvailable,
                 nodeIntegrationInWorker: false
             },
             'web-preferences': {