From b18d373624eb17b119220435f632938083b61abd Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Mon, 26 Oct 2015 21:13:34 +0000 Subject: [PATCH] fixing wired IE security errors "Permission denied", seems reload of opener caused references to egw and template cache in opener.top.etemplate2.prototype.templates becomming inaccessible, catching this errors and falling back to a window-local object --- etemplate/js/et2_core_widget.js | 2 +- etemplate/js/et2_widget_tabs.js | 8 +-- etemplate/js/et2_widget_taglist.js | 8 +-- etemplate/js/etemplate2.js | 61 +++++++++++++---------- phpgwapi/js/egw_action/egw_menu_dhtmlx.js | 5 +- phpgwapi/js/jsapi/egw.js | 10 ++++ 6 files changed, 55 insertions(+), 39 deletions(-) diff --git a/etemplate/js/et2_core_widget.js b/etemplate/js/et2_core_widget.js index 46e6b38997..c4ed083e47 100644 --- a/etemplate/js/et2_core_widget.js +++ b/etemplate/js/et2_core_widget.js @@ -952,7 +952,7 @@ var et2_widget = ClassWithAttributes.extend( * @param {string} _part name of array mgr to return */ getArrayMgr: function(_part) { - if (typeof this._mgrs[_part] != "undefined") + if (this._mgrs && typeof this._mgrs[_part] != "undefined") { return this._mgrs[_part]; } diff --git a/etemplate/js/et2_widget_tabs.js b/etemplate/js/et2_widget_tabs.js index e947d8d79f..cd7a978d51 100644 --- a/etemplate/js/et2_widget_tabs.js +++ b/etemplate/js/et2_widget_tabs.js @@ -325,7 +325,7 @@ var et2_tabbox = et2_valueWidget.extend([et2_IInput,et2_IResizeable], if (entry.widget_options && typeof entry.widget_options.class != 'undefined') { entry.flagDiv.addClass(entry.widget_options.class); - } + } entry.flagDiv.text(entry.label || "Tab"); if(entry.hidden) { @@ -431,13 +431,13 @@ var et2_tabbox = et2_valueWidget.extend([et2_IInput,et2_IResizeable], return null; } }, - + set_tab_height: function (_height) { this.tab_height = _height; this.tabContainer.css("height", _height); }, - + set_height: function(_value) { this.height = _value; @@ -469,7 +469,7 @@ var et2_tabbox = et2_valueWidget.extend([et2_IInput,et2_IResizeable], isValid: function(messages) { return true; }, - + resize: function (_height) { if(_height) diff --git a/etemplate/js/et2_widget_taglist.js b/etemplate/js/et2_widget_taglist.js index 97e3977779..0a41da1b17 100644 --- a/etemplate/js/et2_widget_taglist.js +++ b/etemplate/js/et2_widget_taglist.js @@ -205,7 +205,7 @@ var et2_taglist = et2_selectbox.extend( // Unbind change handler of widget's ancestor to stop it from bubbling // taglist has its own onchange $j(this.getDOMNode()).unbind('change.et2_inputWidget'); - + // onChange if(this.options.onchange && typeof this.options.onchange == 'function') { @@ -278,7 +278,7 @@ var et2_taglist = et2_selectbox.extend( { var label = jQuery('').text(item.label); if (typeof item.title != 'undefined') label.attr('title', item.title); - + return label; }, @@ -577,7 +577,7 @@ var et2_taglist_email = et2_taglist.extend( for(var i=0; i < parts.length; ++i) { items.push({id: parts[i], label: parts[i]}); - + } taglist.addToSelection(items); }, 10); @@ -627,4 +627,4 @@ et2_register_widget(et2_taglist_ro, ["taglist_ro","taglist_email_ro", "taglist_a // Require css // TODO: merge into etemplate2.css with all other widgets when done -if(typeof egw != 'undefined') egw(window).includeCSS(egw.webserverUrl + "/phpgwapi/js/jquery/magicsuggest/magicsuggest.css"); +if(typeof egw == 'function') egw(window).includeCSS(egw.webserverUrl + "/phpgwapi/js/jquery/magicsuggest/magicsuggest.css"); diff --git a/etemplate/js/etemplate2.js b/etemplate/js/etemplate2.js index 25356f9059..3dcc3baab6 100644 --- a/etemplate/js/etemplate2.js +++ b/etemplate/js/etemplate2.js @@ -108,16 +108,20 @@ try { { etemplate2.prototype.templates = opener.etemplate2.prototype.templates; } + else if (top.etemplate2) + { + etemplate2.prototype.templates = top.etemplate2.prototype.templates; + } } catch (e) { // catch security exception if opener is from a different domain + console.log('Security exception accessing etemplate2.prototype of opener or top!'); } if (typeof etemplate2.prototype.templates == "undefined") { - etemplate2.prototype.templates = top.etemplate2.prototype.templates || {}; + etemplate2.prototype.templates = {}; } - /** * Calls the resize event of all widgets * @@ -552,33 +556,38 @@ etemplate2.prototype.load = function(_name, _url, _data, _callback) // Load & process - if(!this.templates[_name]) - { - // Asynchronously load the XET file - et2_loadXMLFromURL(_url, function(_xmldoc) { + try { + if (this.templates[_name]) + { + // Set array managers first, or errors will happen + this.widgetContainer.setArrayMgrs(this._createArrayManagers(_data)); - // Scan for templates and store them - for(var i = 0; i < _xmldoc.childNodes.length; i++) { - var template = _xmldoc.childNodes[i]; - if(template.nodeName.toLowerCase() != "template") continue; - this.templates[template.getAttribute("id")] = template; - if(!_name) this.name = template.getAttribute("id"); - } + // Already have it _load.apply(this,[]); - }, this); - - // Split the given data into array manager objects and pass those to the - // widget container - do this here because file is loaded async - this.widgetContainer.setArrayMgrs(this._createArrayManagers(_data)); + return; + } } - else - { - // Set array managers first, or errors will happen - this.widgetContainer.setArrayMgrs(this._createArrayManagers(_data)); + catch (e) { + // wired security exception in IE denying access to template cache in opener + //this.templates = + etemplate2.prototype.templates = {}; + } + // Asynchronously load the XET file + et2_loadXMLFromURL(_url, function(_xmldoc) { - // Already have it + // Scan for templates and store them + for(var i = 0; i < _xmldoc.childNodes.length; i++) { + var template = _xmldoc.childNodes[i]; + if(template.nodeName.toLowerCase() != "template") continue; + this.templates[template.getAttribute("id")] = template; + if(!_name) this.name = template.getAttribute("id"); + } _load.apply(this,[]); - } + }, this); + + // Split the given data into array manager objects and pass those to the + // widget container - do this here because file is loaded async + this.widgetContainer.setArrayMgrs(this._createArrayManagers(_data)); }, this); }; @@ -607,7 +616,7 @@ etemplate2.prototype.autocomplete_fixer = function () { var self = this; var form = self.DOMContainer; - + // Safari always do the autofill for password field regardless of autocomplete = off // and since there's no other way to switch the autocomplete of, we should switch the // form autocomplete off (e.g. compose dialog, attachment password field) @@ -616,7 +625,7 @@ etemplate2.prototype.autocomplete_fixer = function () { return; } - + if (form) { // Stop submit propagation in order to not fire other possible submit events diff --git a/phpgwapi/js/egw_action/egw_menu_dhtmlx.js b/phpgwapi/js/egw_action/egw_menu_dhtmlx.js index 9f9cca474a..1d8d6136d7 100644 --- a/phpgwapi/js/egw_action/egw_menu_dhtmlx.js +++ b/phpgwapi/js/egw_action/egw_menu_dhtmlx.js @@ -17,10 +17,7 @@ */ // Need CSS, or it doesn't really work -if(typeof egw != 'undefined') -{ - egw(window).includeCSS(egw.webserverUrl + "/phpgwapi/js/egw_action/test/skins/dhtmlxmenu_egw.css"); -} +if(typeof egw == 'function') egw(window).includeCSS(egw.webserverUrl + "/phpgwapi/js/egw_action/test/skins/dhtmlxmenu_egw.css"); function egwMenuImpl(_structure) { //Create a new dhtmlxmenu object diff --git a/phpgwapi/js/jsapi/egw.js b/phpgwapi/js/jsapi/egw.js index 8b18d995a4..b8f99077a2 100644 --- a/phpgwapi/js/jsapi/egw.js +++ b/phpgwapi/js/jsapi/egw.js @@ -129,6 +129,16 @@ window.location.search += window.location.search ? "&cd=yes" : "?cd=yes"; } } + try { + egw(window).message; + } + catch (e) { + console.log('Security exception accessing window specific egw object --> creating new one', e); + window.egw = { + prefsOnly: true, + webserverUrl: egw_webserverUrl + }; + } // focus window / call window.focus(), if data-window-focus is specified var window_focus = egw_script.getAttribute('data-window-focus');