Changeset 1417


Ignore:
Timestamp:
02/22/18 09:28:20 (7 months ago)
Author:
gogo
Message:

Change the initial iframe src to javascript:'' and change the iframe initialisation so it's not reliant on the load event.

This is to allow for using Xinha from an external server, that is, a CDN, previously same-origin restrictions on the iframe prevented this from working because the iframe was provided with the "blank.html" file to load, which would come from the CDN and so Xinha having by then be loaded into the containing document on a different origin did not have permission to edit the document.

I've tested in a variety of browsers and javascript:'' appears to be pretty reliably working.

Credit does have to go to TinyMCE's source code which appears to use javascript:'' in some cases, and that's where I got the idea from after hunting to see how they solved the problem.

Of couse, you can use Xinha from a CDN now, but not the PHP based plugins, namely MootoolsFileManager? and Linker, of course these plugins need to run on the server to which you are uploading/selecting files and links, so they can't work in a CDN environment. It would be possible I expect to direct Linker to a scan.php implementation on your server, but MootoolsFileManager? is a bit much to ask. POSSIBLY an external_plugins could be made, but then you are dealing with things which are outside of _editor_url.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/XinhaCore.js

    r1415 r1417  
    11601160  this.debug = false; 
    11611161 
     1162  /** Paths to various resources loaded by Xinha during operation. 
     1163   *  
     1164   * Note that the iframe_src is the document loaded in the iframe to start with 
     1165   * due to modern security requirements, if you are using Xinha from 
     1166   * an external server (CDN), special care needs be taken, javascript:''  
     1167   * which is now the default seems to be ok, but if you have problems you could 
     1168   * change this to an absolute path to a file on the server which has the page 
     1169   * that is using Xinha (ie, /myserver/blank.html ), the contents should  
     1170   * just be a blank html page (see popups/blank.html) 
     1171   *  
     1172   * @type Array 
     1173   */ 
     1174   
    11621175  this.URIs = 
    11631176  { 
     1177   "iframe_src": 'javascript:\'\'', 
    11641178   "blank": _editor_url + "popups/blank.html", 
    11651179   "link":  _editor_url + "modules/CreateLink/link.html", 
     
    27232737    // create the IFRAME & add to container 
    27242738  var iframe = document.createElement("iframe"); 
    2725   iframe.src = this.popupURL(editor.config.URIs.blank); 
     2739  iframe.src = this.popupURL(editor.config.URIs.iframe_src); 
    27262740  iframe.id = "XinhaIFrame_" + this._textArea.id; 
    27272741  fw.ed_cell.appendChild(iframe); 
     
    28292843  // Add an event to initialize the iframe once loaded. 
    28302844  editor._iframeLoadDone = false; 
    2831   if (Xinha.is_opera)  
     2845  if (iframe.src == 'javascript:\'\'' || iframe.src == '' || Xinha.is_opera) 
    28322846  { 
    28332847    editor.initIframe(); 
    28342848  } 
     2849  // I suspect we no longer need this and can just use editor.initIframe (certainly  
     2850  // iframe.src is javascritp:'' by default.  But I will leave this for posterity 
     2851  // just in case 
    28352852  else  
    28362853  { 
     
    33963413  var doc = null; 
    33973414  var editor = this; 
     3415 
     3416  // It is possible that we need to wait a bit more for the iframe 
     3417  //  browsers vary a bit on how they treat the iframe load events 
     3418  //  so even though we should just be able to listen to load, maybe 
     3419  //  that doesn't work quite right, just waiting a bit if it fails 
     3420  //  and then trying again seems like a good idea. 
     3421  if(typeof editor._iframeWaitingRetries == 'undefined' )     
     3422  { 
     3423    editor._iframeWaitingRetries = 10; 
     3424  } 
     3425  
     3426  // For each retry we lengthen the delay, just so we don't spam the console 
     3427  //  with messages really 
     3428  var retryDelay = (625 / (editor._iframeWaitingRetries * editor._iframeWaitingRetries ) ) * 50; 
     3429  editor._iframeWaitingRetries--; 
     3430 
    33983431  try 
    33993432  { 
     
    34103443    if ( !doc ) 
    34113444    { 
    3412       if ( Xinha.is_gecko ) 
    3413       { 
    3414         setTimeout(function() { editor.initIframe(); }, 50); 
     3445      if( editor._iframeWaitingRetries > 0 ) 
     3446      { 
     3447        Xinha.debugMsg("Still waiting for Iframe..."); 
     3448        editor.setLoadingMessage(Xinha._lc("Waiting for Iframe to load...")); 
     3449        setTimeout(function() { editor.initIframe(); }, retryDelay); 
    34153450        return false; 
    34163451      } 
    34173452      else 
    34183453      { 
    3419         alert("ERROR: IFRAME can't be initialized."); 
     3454        // Give up 
     3455        Xinha.debugMsg("Xinha: Unable to access the Iframe document object, this may be the result of a Cross-Origin restriction, very slow network, or some other issue.", 'warn'); 
     3456        Xinha.debugMsg("You may wish to try changing xinha_config.URIs.iframe_src from "+editor.config.URIs.iframe_src+" to a url of a blank page on your server (eg '/blank.html') and see if that helps.", 'warn'); 
     3457        editor.setLoadingMessage(Xinha._lc("Error Loading Xinha.  Developers, check the Error Console for information.")); 
     3458        return false; 
    34203459      } 
    34213460    } 
     
    34233462  catch(ex) 
    34243463  { // try later 
    3425     setTimeout(function() { editor.initIframe(); }, 50); 
    3426     return false; 
     3464    if(editor._iframeWaitingRetries > 0) 
     3465    { 
     3466      Xinha.debugMsg("Still waiting for Iframe..."); 
     3467      editor.setLoadingMessage(Xinha._lc("Waiting for Iframe to load...")); 
     3468      setTimeout(function() { editor.initIframe(); }, retryDelay); 
     3469      return false; 
     3470    } 
     3471    else 
     3472    { 
     3473      Xinha.debugMsg(ex, 'warn'); 
     3474      Xinha.debugMsg("Xinha: Unable to access the Iframe document object, this may be the result of a Cross-Origin restriction, very slow network, or some other issue.", 'warn'); 
     3475      Xinha.debugMsg("You may wish to try changing xinha_config.URIs.iframe_src from "+editor.config.URIs.iframe_src+" to a url of a blank page on your server (eg '/blank.html') and see if that helps.", 'warn'); 
     3476      editor.setLoadingMessage(Xinha._lc("Error Loading Xinha.  Developers, check the Error Console for information.")); 
     3477      return false; 
     3478    } 
    34273479  } 
    34283480   
     
    74907542    url = Xinha.getPluginDir(plugin) + "/popups/" + popup; 
    74917543  } 
    7492   else if ( file.match(/^\/.*?/) || file.match(/^https?:\/\//)) 
     7544  else if ( file.match(/^\/.*?/) || file.match(/^[a-z]+?:/)) 
    74937545  { 
    74947546    url = file; 
Note: See TracChangeset for help on using the changeset viewer.