Merge "[Tizen6.5 Migration][Service] Print appcontrol data when service app is launch...
[platform/framework/web/wrtjs.git] / wrt_app / browser / wrt_window.ts
1 /*
2  * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16
17 import { BrowserWindow } from 'electron';
18 import * as WRTWebContents from '../browser/wrt_web_contents';
19
20 export const { WRTWindow } = process.wrtBinding('wrt_window');
21
22 Object.setPrototypeOf(WRTWindow.prototype, BrowserWindow.prototype);
23
24 WRTWindow.prototype._init = function () {
25   (BrowserWindow.prototype as any)._init.call(this);
26   // This removes a macOS specific hack present in electron
27   // that causes side effects on Tizen
28   this.webContents.removeAllListeners('load-url');
29   if (typeof this.setup === 'function')
30     this.setup();
31   this.constructor = BrowserWindow;
32   let self = this;
33   this.webContents.on('new-window', (event: Electron.NewWindowWebContentsEvent,
34                                      url: string,
35                                      frameName: string,
36                                      disposition: ('default' | 'foreground-tab' | 'background-tab' | 'new-window' | 'save-to-disk' | 'other'),
37                                      options: any) => {
38     event.preventDefault();
39     if (!options.webContents || options.webContents === self) {
40       options.webContents = WRTWebContents.create();
41       options.webContents.loadURL(url);
42     }
43     event.newGuest = new WRTWindow(options);
44   });
45 }