Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 386164

Summary: Environment provider for globals used by Orion
Product: [ECD] Orion Reporter: Mihai Sucan <mihai.sucan>
Component: EditorAssignee: Silenio Quarti <Silenio_Quarti>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: mihai.sucan, Silenio_Quarti
Version: unspecified   
Target Milestone: 2.0 M1   
Hardware: All   
OS: All   
Whiteboard:

Description Mihai Sucan CLA 2012-07-27 15:37:56 EDT
Orion's code uses a number of globals that we would like to be able to override in an easier manner. We would like to be able to provide for each new orion instance the environment with which it needs to work. Currently we go through hoops to change the environment for every new Orion instance.

Currently we have one global requirejs implementation that holds all of the defined modules, across all Orion instances and all of the other requirejs modules within the Firefox codebase. For Orion we need to invoke the script that holds all of the orion modules we use, for every instance. For every instance we redefine the modules by unloading and loading them again. Each time with a different global environment: the new iframe where the Orion editor is loaded.

It would be much easier if we could give TextView an environment-provider of some kind that is used by all of the other Orion modules. Let us give Orion the window object. We want to execute the script that define()s each Orion module only once, without any globals. Then, at instancing time we would want to pass the window object of the iframe in the new Orion instance.

If further details are needed please let me know. Thank you!
Comment 1 Silenio Quarti CLA 2012-11-09 11:27:05 EST
Which globals are you interested? 

window
document

Are there others?
Comment 2 Mihai Sucan CLA 2012-11-09 11:53:25 EST
We can start with window and document, but anything you can find that falls into the following category any global object you use that is not part of standard JS. Something that requires an actual DOM. JavaScript modules in Firefox do not have "window", "document" or any associated DOM.

Beyond the two globals you mentioned: document.body is not always available, even in environments with a DOM.

Another example is setTimeout - a global method that lives on the window object. Orion code needs to use it as follows: givenWindow.setTimeout. Any other similar global function or property needs to be explicitly taken from the window object. (clearTimeout, setInterval, clearInterval, navigator, location, etc.)

Thank you very much for your work! Much appreciated!
Comment 3 Silenio Quarti CLA 2012-11-09 17:40:37 EST
I have released changes that should take care of: window, document, setTimeout, clearTimeout, setInterval and clearInterval.  These are fetched from the parent of text view now which is passed by the application at creation time. 

I am not sure what to do with respect to document.body.  Do you have any ideas?  Most of the references to document.body are in IE specific code.  There is only one common reference in tooltip.js.

There is one reference to navigator in util.js. It is used to determine OS and browser version. Is this an issue for you?

Please let me know whether these changes fix your problem.

http://git.eclipse.org/c/orion/org.eclipse.orion.client.git/commit/?id=6da1defc4ebf5e71efffb0da1f3dc529f31f9c46
Comment 4 Mihai Sucan CLA 2012-11-10 05:45:39 EST
Thank you Silenio!

Before we can make the change to run in a DOM-less environment we need to get all the globals figured-out.

The changes you committed seem to be sufficient for now. We have to make our code changes before we can be sure that everything works well.

The |navigator| global is known to not be available either, but that is immutable across different instances of Orion and we can add fake objects into the global scope, for all Orion instances at once. In the case of |navigator| it's actually better for us to fake it - we've had a bug report about users having issues when they change the browser user agent (which resulted in orion behaving differently).
Comment 5 Silenio Quarti CLA 2012-11-12 11:10:31 EST
Ok, I am closing this one for now. Please reopen if you find other places where the editor accesses globals. Thanks!