Move inspector functions to WebApplication 21/249721/5
authorDongHyun Song <dh81.song@samsung.com>
Wed, 16 Dec 2020 08:37:57 +0000 (17:37 +0900)
committerDongHyun Song <dh81.song@samsung.com>
Wed, 16 Dec 2020 09:17:09 +0000 (18:17 +0900)
debugPort / inspectorSrc are members for WebApplication class.
Then, move related functions to WebApplication is more proper and
it can reduce to check webApplication instance.

Change-Id: I7fc4415e25249e574270a38900fdcb2bd1e934e7
Signed-off-by: DongHyun Song <dh81.song@samsung.com>
wrt_app/src/runtime.ts
wrt_app/src/web_application.ts

index 8687822..a729356 100644 (file)
@@ -24,7 +24,6 @@ import { WebApplication } from './web_application';
 class Runtime {
   webApplication?: WebApplication = undefined;
   isLaunched = false;
-  inspectorEnabledByVconf = false;
 
   constructor() {
     app.on('before-quit', (event: any) => {
@@ -91,7 +90,6 @@ class Runtime {
         console.log('Handling app-control event');
         this.webApplication.handleAppControlEvent(appControl);
       }
-      this.launchInspector(appControl);
     });
 
     wrt.on('suspend', () => {
@@ -168,39 +166,12 @@ class Runtime {
   private createWebApplicationAndLoadUrl(appControl: any) {
     console.log('Creating WebApplication');
     let launchMode = appControl.getData('http://samsung.com/appcontrol/data/launch_mode');
-    let src =  appControl.getLoadInfo().getSrc();
     let options: RuntimeOption = {
       isAddonAvailable: addonManager.isAddonAvailable(),
       launchMode: launchMode
     }
     this.webApplication = new WebApplication(options);
-    if (wrt.tv) {
-      this.inspectorEnabledByVconf = wrt.tv.needUseInspector();
-      if (this.inspectorEnabledByVconf && launchMode != 'backgroundExecution') {
-        this.webApplication.inspectorSrc = src;
-        src = "about:blank";
-      }
-    }
-    this.webApplication.loadUrl(src);
-  }
-
-  private launchInspector(appControl: NativeWRTjs.AppControl) {
-    this.launchInspector = (param) => {}; // call once
-    console.log('launchInspector');
-
-    // AUL public key/Vconf - To support inspector
-    if (this.checkInspectorCondition(appControl)) {
-      let debugPort = wrt.startInspectorServer();
-      let data = { "port" :  [ debugPort.toString() ] };
-      if (this.webApplication)
-        this.webApplication.debugPort = debugPort;
-      appControl.reply(data);
-    }
-  }
-
-  private checkInspectorCondition(appControl: NativeWRTjs.AppControl) {
-    let bundleDebug = (appControl.getData('__AUL_DEBUG__') === "1");
-    return (bundleDebug || this.inspectorEnabledByVconf);
+    this.webApplication.loadUrl(appControl);
   }
 
   private handleKeyEvents(key: string) {
index 147ff8e..25a2441 100755 (executable)
@@ -36,6 +36,7 @@ export class WebApplication {
   backgroundSupport = wrt.getBackgroundSupport();
   debugPort = 0;
   firstRendered = false;
+  contentSrc = '';
   inspectorSrc = '';
   loadFinished = false;
   pendingCallbacks: Map<number, any> = new Map();
@@ -371,9 +372,27 @@ Then you can get profile log from the initial loading.`;
       this.sendAppControlEvent();
   }
 
-  loadUrl(src: string) {
-    this.mainWindow.loadURL(src);
-    this.prelaunch(src);
+  private launchInspectorIfNeeded(appControl: NativeWRTjs.AppControl) {
+    console.log('launchInspectorIfNeeded');
+    let inspectorEnabledByVconf = wrt.tv ? wrt.tv.needUseInspector() : false;
+    if (inspectorEnabledByVconf && !this.backgroundExecution) {
+      this.inspectorSrc = this.contentSrc;
+      this.contentSrc = 'about:blank';
+    }
+    let hasAulDebug = (appControl.getData('__AUL_DEBUG__') === '1');
+    if (hasAulDebug || inspectorEnabledByVconf) {
+      let debugPort = wrt.startInspectorServer();
+      let data = { "port": [debugPort.toString()] };
+      this.debugPort = debugPort;
+      appControl.reply(data);
+    }
+  }
+
+  loadUrl(appControl: NativeWRTjs.AppControl) {
+    this.contentSrc = appControl.getLoadInfo().getSrc();
+    this.launchInspectorIfNeeded(appControl);
+    this.mainWindow.loadURL(this.contentSrc);
+    this.prelaunch(this.contentSrc);
     if (wrt.da) {
       this.mainWindow.emit('ready-to-show');
     }