track top EGroupware window in egw object to be used as egw.top instead of window.top, which can throw a security exception

This commit is contained in:
Ralf Becker 2020-05-18 20:55:57 +02:00
parent 5b8e02fded
commit 588cd10043
11 changed files with 30 additions and 29 deletions

View File

@ -33,7 +33,7 @@ function et2_loadXMLFromURL(_url, _callback, _context, _fail_callback) {
// catch security exception if opener is from a different domain // catch security exception if opener is from a different domain
} }
if (typeof win == "undefined") { if (typeof win == "undefined") {
win = top; win = egw.top;
} }
win.jQuery.ajax({ win.jQuery.ajax({
// we add the full url (protocol and domain) as sometimes just the path // we add the full url (protocol and domain) as sometimes just the path

View File

@ -39,7 +39,7 @@ function et2_loadXMLFromURL(_url : string, _callback : Function, _context : obje
} }
if (typeof win == "undefined") if (typeof win == "undefined")
{ {
win = top; win = egw.top;
} }
win.jQuery.ajax({ win.jQuery.ajax({
// we add the full url (protocol and domain) as sometimes just the path // we add the full url (protocol and domain) as sometimes just the path

View File

@ -406,7 +406,7 @@ var et2_dataview = /** @class */ (function () {
if (typeof this.scrollbarWidth === 'undefined') { if (typeof this.scrollbarWidth === 'undefined') {
// Clone the table and attach it to the outer body tag // Clone the table and attach it to the outer body tag
var clone = this.table.clone(); var clone = this.table.clone();
jQuery(window.top.document.getElementsByTagName("body")[0]) jQuery(egw.top.document.getElementsByTagName("body")[0])
.append(clone); .append(clone);
// Read the scrollbar width // Read the scrollbar width
this.scrollbarWidth = this.constructor.prototype.scrollbarWidth = this.scrollbarWidth = this.constructor.prototype.scrollbarWidth =

View File

@ -571,7 +571,7 @@ export class et2_dataview
{ {
// Clone the table and attach it to the outer body tag // Clone the table and attach it to the outer body tag
var clone = this.table.clone(); var clone = this.table.clone();
jQuery(window.top.document.getElementsByTagName("body")[0]) jQuery(egw.top.document.getElementsByTagName("body")[0])
.append(clone); .append(clone);
// Read the scrollbar width // Read the scrollbar width

View File

@ -145,6 +145,11 @@
webserverUrl: egw_webserverUrl webserverUrl: egw_webserverUrl
}; };
} }
// set top window in egw object
if (typeof window.egw.top === "undefined")
{
window.egw.top = window;
}
// focus window / call window.focus(), if data-window-focus is specified // focus window / call window.focus(), if data-window-focus is specified
var window_focus = egw_script.getAttribute('data-window-focus'); var window_focus = egw_script.getAttribute('data-window-focus');

View File

@ -68,9 +68,9 @@ var EgwApp = /** @class */ (function () {
} }
// Make sure we're running in the top window when we init sidebox // Make sure we're running in the top window when we init sidebox
//@ts-ignore //@ts-ignore
if (window.app[this.appname] === this && window.top.app[this.appname] !== this && window.top.app[this.appname]) { if (window.app[this.appname] === this && egw.top.app[this.appname] !== this && egw.top.app[this.appname]) {
//@ts-ignore //@ts-ignore
window.top.app[this.appname]._init_sidebox(sidebox); egw.top.app[this.appname]._init_sidebox(sidebox);
} }
else { else {
this._init_sidebox(sidebox); this._init_sidebox(sidebox);

View File

@ -150,10 +150,10 @@ export abstract class EgwApp
} }
// Make sure we're running in the top window when we init sidebox // Make sure we're running in the top window when we init sidebox
//@ts-ignore //@ts-ignore
if(window.app[this.appname] === this && window.top.app[this.appname] !== this && window.top.app[this.appname]) if(window.app[this.appname] === this && egw.top.app[this.appname] !== this && egw.top.app[this.appname])
{ {
//@ts-ignore //@ts-ignore
window.top.app[this.appname]._init_sidebox(sidebox); egw.top.app[this.appname]._init_sidebox(sidebox);
} }
else else
{ {

View File

@ -59,6 +59,11 @@ declare interface IegwGlobal
*/ */
webserverUrl : string; webserverUrl : string;
/**
* Reference to top window of EGroupware (no need to check for security exceptions!)
*/
top : Window;
/** /**
* implemented in egw_config.js * implemented in egw_config.js
*/ */

View File

@ -75,9 +75,9 @@ egw.extend('message', egw.MODULE_WND_LOCAL, function(_app, _wnd)
} }
// if we are NOT in a popup then call the message on top window // if we are NOT in a popup then call the message on top window
if (!this.is_popup() && _wnd !== _wnd.top) if (!this.is_popup() && _wnd !== egw.top)
{ {
egw(_wnd.top).message(_msg, _type); egw(egw.top).message(_msg, _type);
return; return;
} }
// handle message display for non-framework templates, eg. idots or jerryr // handle message display for non-framework templates, eg. idots or jerryr

View File

@ -366,7 +366,7 @@ egw.extend('open', egw.MODULE_WND_LOCAL, function(_egw, _wnd)
if (typeof(_app) == 'undefined') _app = false; if (typeof(_app) == 'undefined') _app = false;
if (typeof(_returnID) == 'undefined') _returnID = false; if (typeof(_returnID) == 'undefined') _returnID = false;
var $wnd = jQuery(_wnd.top); var $wnd = jQuery(egw.top);
var positionLeft = ($wnd.outerWidth()/2)-(_width/2)+_wnd.screenX; var positionLeft = ($wnd.outerWidth()/2)-(_width/2)+_wnd.screenX;
var positionTop = ($wnd.outerHeight()/2)-(_height/2)+_wnd.screenY; var positionTop = ($wnd.outerHeight()/2)-(_height/2)+_wnd.screenY;

View File

@ -149,17 +149,7 @@ function egw_insertJS(_html)
*/ */
function egw_topWindow() function egw_topWindow()
{ {
if (typeof window.parent != "undefined" && typeof window.parent.top != "undefined") return egw.top;
{
return window.parent.top;
}
if (typeof window.opener != "undefined" && typeof window.opener.top != "undefined")
{
return window.opener.top;
}
return window.top;
} }
/** /**
@ -288,14 +278,15 @@ window.egw_getFramework = function()
{ {
return framework; return framework;
} }
else if (typeof window.parent.egw_getFramework != "undefined" && window != window.parent) try {
{ if (typeof window.parent.egw_getFramework != "undefined" && window != window.parent)
return window.parent.egw_getFramework(); {
} return window.parent.egw_getFramework();
else }
{
return null;
} }
catch (e) {}
return null;
} }
/** /**