From: SangYong Park Date: Wed, 26 Jun 2019 10:14:38 +0000 (+0900) Subject: Add WRTWindow and WRTWebContents X-Git-Tag: accepted/tizen/unified/20190814.021400~12^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F19%2F208619%2F2;p=platform%2Fframework%2Fweb%2Fwrtjs.git Add WRTWindow and WRTWebContents It is customized module of BrowserWindow and WebContents. related to https://review.tizen.org/gerrit/#/c/platform/framework/web/chromium-efl/+/208618/ Change-Id: I336c171e384316373e9cbb404efa7da4fb29e8a2 Signed-off-by: SangYong Park --- diff --git a/wrt_app/browser/wrt_web_contents.js b/wrt_app/browser/wrt_web_contents.js new file mode 100644 index 0000000..994cca2 --- /dev/null +++ b/wrt_app/browser/wrt_web_contents.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +const binding = process.binding('wrt_web_contents') +const { WRTWebContents } = binding +const { WebContents: AtomWebContents } = process.atomBinding('web_contents') + +const parent = AtomWebContents.prototype +AtomWebContents.prototype = WRTWebContents.prototype + +Object.setPrototypeOf(WRTWebContents.prototype, parent) + +WRTWebContents.prototype._init = function () { + parent._init.call(this) +} + +module.exports = { + create (options = {}) { + return binding.create(options) + } +} diff --git a/wrt_app/browser/wrt_window.js b/wrt_app/browser/wrt_window.js new file mode 100644 index 0000000..b4eb6c5 --- /dev/null +++ b/wrt_app/browser/wrt_window.js @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +const { WRTWindow } = process.binding('wrt_window') +const { BrowserWindow, TopLevelWindow } = require('electron') +const WRTWebContents = require('../browser/wrt_web_contents'); + +Object.setPrototypeOf(WRTWindow.prototype, BrowserWindow.prototype) + +WRTWindow.prototype._init = function () { + BrowserWindow.prototype._init.call(this) + this.setup() + let self = this + this.webContents.on('new-window', (event, url, frameName, disposition, options) => { + event.preventDefault() + let parentOptions = self.browserWindowOptions || {} + parentOptions.webContents = options.webContents || WRTWebContents() + const win = new WRTWindow(parentOptions) + event.newGuest = win + }) +} + +const isWindow = (win) => { + return win && win.constructor.name === 'WRTWindow' +} + +WRTWindow.fromId = (id) => { + const win = TopLevelWindow.fromId(id) + return isWindow(win) ? win : null +} + +WRTWindow.getAllWindows = () => { + return TopLevelWindow.getAllWindows().filter(isWindow) +} + +module.exports = WRTWindow diff --git a/wrt_app/src/web_application.js b/wrt_app/src/web_application.js index 78ef215..ec85403 100755 --- a/wrt_app/src/web_application.js +++ b/wrt_app/src/web_application.js @@ -16,9 +16,11 @@ 'use strict'; -const {BrowserWindow, app, protocol} = require('electron'); +const { app, protocol } = require('electron'); const WAS_EVENT = require('./was_event'); const wrt = require('../browser/wrt'); +const WRTWebContents = require('../browser/wrt_web_contents'); +const WRTWindow = require('../browser/wrt_window'); class WebApplication { constructor(options) { @@ -165,7 +167,7 @@ class WebApplication { } }); } - getBrowserWindowOption(options) { + getWindowOption(options) { return { fullscreen: false, show: false, @@ -173,6 +175,7 @@ class WebApplication { nodeIntegration: options.isAddonAvailable, nodeIntegrationInWorker: false }, + webContents: WRTWebContents.create(), 'web-preferences': { 'direct-write': true, 'subpixel-font-scaling': false, @@ -181,8 +184,8 @@ class WebApplication { }; } createMainWindow(options) { - let winopt = this.getBrowserWindowOption(options); - this.mainWindow = new BrowserWindow(winopt); + let winopt = this.getWindowOption(options); + this.mainWindow = new WRTWindow(winopt); if (options.devMode) { this.mainWindow.webContents.openDevTools({ detached: true @@ -235,7 +238,7 @@ class WebApplication { console.log('App has been terminated; return'); return; } - let windows = BrowserWindow.getAllWindows(); + let windows = WRTWindow.getAllWindows(); if (!this.multitaskingSupport) { // FIXME : terminate app after visibilitychange event handling setTimeout(() => { @@ -254,7 +257,7 @@ class WebApplication { console.log('WebApplication : resume firstRendered is false'); return; } - BrowserWindow.getAllWindows().forEach((window) => { + WRTWindow.getAllWindows().forEach((window) => { if (!this.backgroundSupport) window.setEnabled(true); }); @@ -284,12 +287,12 @@ class WebApplication { console.log('WebApplication : show'); this.preloadState = 'none'; if (!this.mainWindow.isVisible()) { - console.log('show browserWindow'); + console.log('show window'); this.mainWindow.show(); } } closeWindows() { - BrowserWindow.getAllWindows().forEach((window) => { + WRTWindow.getAllWindows().forEach((window) => { if (window != this.mainWindow) window.destroy(); });