Enable Extension manager 74/182274/2
authorws29.jung <ws29.jung@samsung.com>
Fri, 22 Jun 2018 02:40:16 +0000 (11:40 +0900)
committerjaekuk lee <juku1999@samsung.com>
Fri, 22 Jun 2018 02:48:38 +0000 (02:48 +0000)
Now extensions can run if it is placed on right place.

Change-Id: I1d39d1b01c7f10b41533b329d7ed6995df675345
Signed-off-by: ws29.jung <ws29.jung@samsung.com>
atom/browser/api/atom_api_web_contents.cc
lib/browser/chrome-extension.js
lib/browser/init.js
lib/renderer/content-scripts-injector.js
wrt/src/extension_manager.js
wrt/src/runtime.js

index a784f77..c7d8426 100644 (file)
@@ -743,7 +743,7 @@ void WebContents::DidFailLoad(content::RenderFrameHost* render_frame_host,
 
 void WebContents::DidStartLoading() {
 #if defined(OS_TIZEN)
-  if (!owner_window()->IsVisible()) {
+  if (owner_window() && !owner_window()->IsVisible()) {
     std::string scheme = web_contents()->GetURL().scheme();
     if (std::string::npos != scheme.find("http")) {
       owner_window()->Show();
index b9d61a0..f8a1715 100644 (file)
@@ -1,7 +1,4 @@
 const {app, ipcMain, webContents, BrowserWindow} = require('electron')
-const {getAllWebContents} = process.atomBinding('web_contents')
-const renderProcessPreferences = process.atomBinding('render_process_preferences').forAllWebContents()
-
 const {Buffer} = require('buffer')
 const fs = require('fs')
 const path = require('path')
@@ -121,7 +118,7 @@ const hookWebContentsEvents = function (webContents) {
 
   sendToBackgroundPages('CHROME_TABS_ONCREATED')
 
-  webContents.on('will-navigate', (event, url) => {
+  webContents.once('will-navigate', (event, url) => {
     sendToBackgroundPages('CHROME_WEBNAVIGATION_ONBEFORENAVIGATE', {
       frameId: 0,
       parentFrameId: -1,
@@ -132,7 +129,7 @@ const hookWebContentsEvents = function (webContents) {
     })
   })
 
-  webContents.on('did-navigate', (event, url) => {
+  webContents.once('did-navigate', (event, url) => {
     sendToBackgroundPages('CHROME_WEBNAVIGATION_ONCOMPLETED', {
       frameId: 0,
       parentFrameId: -1,
@@ -250,6 +247,7 @@ const injectContentScripts = function (manifest) {
       extensionId: manifest.extensionId,
       contentScripts: manifest.content_scripts.map(contentScriptToEntry)
     }
+    const renderProcessPreferences = process.atomBinding('render_process_preferences').forAllWebContents()
     contentScripts[manifest.name] = renderProcessPreferences.addEntry(entry)
   } catch (e) {
     console.error('Failed to read content scripts', e)
@@ -259,6 +257,7 @@ const injectContentScripts = function (manifest) {
 const removeContentScripts = function (manifest) {
   if (!contentScripts[manifest.name]) return
 
+  const renderProcessPreferences = process.atomBinding('render_process_preferences').forAllWebContents()
   renderProcessPreferences.removeEntry(contentScripts[manifest.name])
   delete contentScripts[manifest.name]
 }
@@ -293,7 +292,7 @@ app.on('web-contents-created', function (event, webContents) {
   if (!isWindowOrWebView(webContents)) return
 
   hookWebContentsEvents(webContents)
-  webContents.on('devtools-opened', function () {
+  webContents.once('devtools-opened', function () {
     loadDevToolsExtensions(webContents, objectValues(manifestMap))
   })
 })
@@ -374,6 +373,7 @@ app.once('ready', function () {
     const manifest = getManifestFromPath(srcDirectory)
     if (manifest) {
       loadExtension(manifest)
+      const {getAllWebContents} = process.atomBinding('web_contents')
       for (const webContents of getAllWebContents()) {
         if (isWindowOrWebView(webContents)) {
           loadDevToolsExtensions(webContents, [manifest])
@@ -430,7 +430,7 @@ app.once('ready', function () {
     if (!manifest) return
     const page = backgroundPages[manifest.extensionId]
     if (!page) return
-      page.webContents.sendToAll(`CHROME_PAGEACTION_ONCLICKED_${manifest.extensionId}`, webContents.Id);
+    page.webContents.sendToAll(`CHROME_PAGEACTION_ONCLICKED_${manifest.extensionId}`, webContents.Id);
   }
 
 })
index cfcf26f..39be413 100644 (file)
@@ -156,7 +156,7 @@ app.setAppPath(packagePath)
 // Load the chrome extension support.
 // FIXME: When prelaunch, initializing electron modules
 //        in chrome-extension cause segmentation fault.
-//require('./chrome-extension')
+require('./chrome-extension')
 
 // Load internal desktop-capturer module.
 // FIXME: This is guard for bringup.
index 124fd58..b0401cc 100644 (file)
@@ -3,6 +3,7 @@ const {runInThisContext} = require('vm')
 
 // Check whether pattern matches.
 // https://developer.chrome.com/extensions/match_patterns
+let firstInject = true
 const matchesPattern = function (pattern) {
   if (pattern === '<all_urls>') return true
 
@@ -13,6 +14,8 @@ const matchesPattern = function (pattern) {
 // Run the code with chrome API integrated.
 const runContentScript = function (extensionId, url, code) {
   const context = {}
+  const fire = runContentScript.bind(window, extensionId, url, code)
+  document.removeEventListener('DOMContentLoaded', fire)
   require('./chrome-api').injectTo(extensionId, false, context)
   const wrapper = `(function (chrome) {\n  ${code}\n  })`
   const compiledWrapper = runInThisContext(wrapper, {
@@ -63,6 +66,7 @@ ipcRenderer.on('CHROME_TABS_EXECUTESCRIPT', function (event, senderWebContentsId
 // Read the renderer process preferences.
 const preferences = process.getRenderProcessPreferences()
 if (preferences) {
+  if (!firstInject) return
   for (const pref of preferences) {
     if (pref.contentScripts) {
       for (const script of pref.contentScripts) {
@@ -70,4 +74,5 @@ if (preferences) {
       }
     }
   }
+  firstInject = false;
 }
index 1b9b965..2c51b85 100755 (executable)
@@ -12,9 +12,9 @@ const {BrowserWindow} = require('electron');
 
 var EXTENSIONS_PATH = process.env.WAS_EXTENSIONS_PATH;
 if (!EXTENSIONS_PATH) {
-    var resourcePath = __dirname.split('app.asar')[0];
+    var resourcePath = __dirname.split('wrt')[0];
     extension_debug('WARNING! WAS_EXTENSIONS_PATH not set - extensions cannot be loaded');
-    EXTENSIONS_PATH = path.join(resourcePath, 'runtime_addon');
+    EXTENSIONS_PATH = path.join(resourcePath, 'electron/runtime_addon');
     extension_debug('Temporarily set WAS_EXTENSIONS_PATH=' + EXTENSIONS_PATH);
 }
 
@@ -256,8 +256,9 @@ class ExtensionManager {
             else extension_debug('extension.activate not defined!');
         } else if (this.extensions_[T_CRX] !== undefined && this.extensions_[T_CRX][name] !== undefined) {
             extension_path = this.extensions_[T_CRX][name];
-            extension_debug('activate 22: ' + extension_path + ' name:' + name);
+            extension_debug('activate 2: ' + extension_path + ' name:' + name);
             try {
+                extension_debug('BrowserWindow.addExtension: ' + extension_path);
                 BrowserWindow.addExtension(extension_path);
             } catch (e) {
                 extension_debug('activate - error on addExtension() : ' + e);
index 4bcc1f8..55b5c27 100755 (executable)
@@ -184,6 +184,23 @@ class Runtime {
             runtime_debug('handleIpcMessages: DEACTIVATE ' + name);
             return this.extensionManager.deactivate(app, name);
         });
+        ipcMain.on(IPC_MESSAGE.EXTENSIONS.INSTALLED, (sender, name) => {
+            runtime_debug('handleIpcMessages: INSTALLED ' + name);
+            this.extensionManager.build();
+            return this.extensionManager.activate(app, name);
+        });
+        ipcMain.on(IPC_MESSAGE.EXTENSIONS.UNINSTALLED, (sender, name) => {
+            runtime_debug('handleIpcMessages: UNINSTALLED ' + name);
+            return this.extensionManager.deactivate(app, name);
+        });
+        ipcMain.on(IPC_MESSAGE.EXTENSIONS.ACTIVATE, (sender, name) => {
+            runtime_debug('handleIpcMessages: ACTIVATE ' + name);
+            return this.extensionManager.activate(app, name);
+        });
+        ipcMain.on(IPC_MESSAGE.EXTENSIONS.DEACTIVATE, (sender, name) => {
+            runtime_debug('handleIpcMessages: DEACTIVATE ' + name);
+            return this.extensionManager.deactivate(app, name);
+        });
     }
 }
 module.exports = Runtime;