Now extensions can run if it is placed on right place.
Change-Id: I1d39d1b01c7f10b41533b329d7ed6995df675345
Signed-off-by: ws29.jung <ws29.jung@samsung.com>
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();
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')
sendToBackgroundPages('CHROME_TABS_ONCREATED')
- webContents.on('will-navigate', (event, url) => {
+ webContents.once('will-navigate', (event, url) => {
sendToBackgroundPages('CHROME_WEBNAVIGATION_ONBEFORENAVIGATE', {
frameId: 0,
parentFrameId: -1,
})
})
- webContents.on('did-navigate', (event, url) => {
+ webContents.once('did-navigate', (event, url) => {
sendToBackgroundPages('CHROME_WEBNAVIGATION_ONCOMPLETED', {
frameId: 0,
parentFrameId: -1,
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)
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]
}
if (!isWindowOrWebView(webContents)) return
hookWebContentsEvents(webContents)
- webContents.on('devtools-opened', function () {
+ webContents.once('devtools-opened', function () {
loadDevToolsExtensions(webContents, objectValues(manifestMap))
})
})
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])
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);
}
})
// 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.
// Check whether pattern matches.
// https://developer.chrome.com/extensions/match_patterns
+let firstInject = true
const matchesPattern = function (pattern) {
if (pattern === '<all_urls>') return true
// 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, {
// 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) {
}
}
}
+ firstInject = false;
}
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);
}
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);
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;