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

Bug 363959

Summary: Investigate how to avoid requiring API key for remote Dojo
Product: z_Archived Reporter: Will Smythe <smythew>
Component: EDTAssignee: Huang Ji Yong <hjiyong>
Status: CLOSED FIXED QA Contact:
Severity: enhancement    
Priority: P1 CC: chenzhh, dan.darnell, hjiyong, svihovec
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Bug Depends on:    
Bug Blocks: 369445    
Attachments:
Description Flags
Design
none
New includeDojo.html none

Description Will Smythe CLA 2011-11-16 14:12:02 EST
The Dojo and Google docs do not indicate that an API key is required to use the remotely hosted Dojo libraries. An API key is required, however, to use the 'fancy' Google loading APIs, which is not a requirement.

We should investigate whether this is true, and if so, we should switch the Dojo remote project to not require an API key. Secondarily, we should consider making Dojo remote the default again (for new projets) since it results in much smaller deployed apps and we always believed it to be faster.
Comment 1 Brian Svihovec CLA 2011-11-16 16:25:42 EST
The Google map is still part of the Dojo Sample.
Comment 2 Will Smythe CLA 2011-11-16 16:40:16 EST
I don't see the relationship between the Dojo libraries hosted on Google and the Google Map widget. The Google Map widget uses a different set of .js files and does not require an API key. It was shipped in the Dojo samples project because at  the time this was the easiest way to ship it. There is a work item to pull the Google Map widget into its own library (which is where it belongs) - the widget will continue to reference the same .js files it does today (i.e. Google Map specific js files hosted on Google).
Comment 3 Lisa Lasher CLA 2011-11-18 14:30:10 EST
changing from defect to enhancement (work item)
Comment 4 Will Smythe CLA 2011-12-08 23:29:42 EST
This enhancement specifically relates to the need to reduce number of files deployed for even a basic app.
Comment 5 fahua jin CLA 2011-12-30 02:50:04 EST
I investigated the problem, and updated the code to the same approach as we did for AOL in RBD - add below tag to import the JS directly instead of loading the JS by Google loader. 

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/dojo/1.6.1/dojo/dojo.xd.js"></script>

It works for FF & WebKit, but it has problems in IE. It seems that it's caused by JS load problem. Jiyong is working with me for it now.
Comment 6 fahua jin CLA 2011-12-30 02:50:54 EST
BTW, we had more discussions in defect #60859 in RTC.
Comment 7 fahua jin CLA 2012-01-06 00:24:14 EST
Simply update the includeDojo.html could not solve the problem in IE (js files have not been completely loaded while trying to call the functions), more elegant way is reading the contents of file includeDojo.html and directly output to the generated handler file. 

Jiyong is the HTML generator owner, and he will find a better way to include the file in handler file.
Comment 8 Huang Ji Yong CLA 2012-01-09 09:52:34 EST
Created attachment 209212 [details]
Design

Hi Guys,
I investigate this problem together with bug 364295, because both problems are related to the html generator of includeFile.
Both problems can be solved by using RBD's approach which will paste the html content of the includeFile to the generated HTML. But this method require the html generator to have the ability to access the file IO. Thus, the plugin have to depend on eclipse IDE which will break the rule of generator and make it unable to use in command line. 
I find an alternative method to fix this problem without reading the file content in generator time. It will parse the includeFile content to extract script tag and load the script appropriate. Please check the pdf file for detail.
I can't decide which method to take. Welcome for comments.
Comment 9 Huang Ji Yong CLA 2012-01-10 02:43:16 EST
The last solution is to rewrite the includeFile to make it loaded synchronously.
Then we can define a rule for includeFile for user to comply for.
Comment 10 Brian Svihovec CLA 2012-01-10 11:28:11 EST
Can you attach the proposed includeDojo.html file from comment 5, or the latest version of the file that matches the design document?  

Can you elaborate on why Eclipse File IO is required to read the content of the includeDojo.html file?  I believe we have File Locators that work off of IFile and File, which means we should be able to resolve the file and read the content using Java File IO.  

Assuming we did figure out a way to read the file content using Java File IO, would we modify deployment to add the content of all includeFiles directly to the HTML file?  Does RBD add the content of all includeFiles directly to the HTML file, or is it hard coded to do this just for includeDojo.html?

For the proposed solution of parsing the include file to extract the script tags, would this parsing happen during deployment or at runtime?  I believe it would be at runtime, which I assume means a general solution for processing all 'includeFile' attributes, and not just includeDojo.html?

For the solution proposed in comment 9, can you describe this in more detail?  What is the rule that the user must comply with?

NOTE: The defect mentioned in comment 8 is 364925, not 364295
Comment 11 Huang Ji Yong CLA 2012-01-11 04:12:23 EST
Hi Brian,
Thanks for your reply.
Firstly, I must clarify the design document aims for all includeFile including includeDojo.html.

(In reply to comment #10)
> Can you attach the proposed includeDojo.html file from comment 5, or the latest
> version of the file that matches the design document?  

Attached the new includeDojo.html for remote Dojo

-----------------------------------------
> Can you elaborate on why Eclipse File IO is required to read the content of the
> includeDojo.html file?  I believe we have File Locators that work off of IFile
> and File, which means we should be able to resolve the file and read the
> content using Java File IO. 

I have an email thread from Joe when starting HTML gen work, he said "The projects can't have any references to eclipse UI or core and cannot have an activator. The reason is these project will be used in SDK mode and SDK should not rely on any non EDT eclipse API's."
 
We cannot get the file path of includeDojo.html by pure Java IO. We must rely on eclipse to get the workspace path, dependent project etc. (FileLocator as you said).
A possible solution may be transfer the path information to html generator by parameters. Which meas that we should add more parameters to the construction function of the generator. We can look into this solution if we decide to go this way.

-----------------------------------------
> Assuming we did figure out a way to read the file content using Java File IO,
> would we modify deployment to add the content of all includeFiles directly to
> the HTML file?  Does RBD add the content of all includeFiles directly to the
> HTML file, or is it hard coded to do this just for includeDojo.html?

RBD add the content of all includeFiles directly to the html file, not just for includeDojo.html. We would like to do the same in EDT.

----------------------------------------- 
> For the proposed solution of parsing the include file to extract the script
> tags, would this parsing happen during deployment or at runtime?  I believe it
> would be at runtime, which I assume means a general solution for processing all
> 'includeFile' attributes, and not just includeDojo.html?

Parsing happens in runtime, and it is for all 'includeFile' attribute.

-----------------------------------------
> For the solution proposed in comment 9, can you describe this in more detail? 
> What is the rule that the user must comply with?
The rule may be:
The script link in the 'includeFile' must written in a dynamic script tag manners. Such as
var script = document.createElement("script");
script.type = "text/javascript";
if (script.readyState){ //IE
	script.onreadystatechange = function(){
	if (script.readyState == "loaded" || script.readyState == "complete"){
		script.onreadystatechange = null;
                // The logic should go here
		callback();
	}
		};
	} else { //Others
		script.onload = function(){
                        // The logic should go here.
			callback();
		};
		script.onerror = function(){
			console.log("load " + this.src + " fail");
		}
	}
	script.src = "/" + egl__contextRoot + "/" + url;
	document.getElementsByTagName("head")[0].appendChild(script);

Additionally this load function should be included in the runtime such as egl.load(file, callback). So when user is writing a includeFile to link to an external script file, they should write in this manner
egl.load("mysrc.js", callbackFunc);

-----------------------------------------
> NOTE: The defect mentioned in comment 8 is 364925, not 364295

Sorry for the mistake.
Comment 12 Huang Ji Yong CLA 2012-01-11 04:13:18 EST
Created attachment 209302 [details]
New includeDojo.html
Comment 13 Brian Svihovec CLA 2012-01-11 11:50:39 EST
In the design document, it states, "The script tag <script src="src.js" /> is
loaded asynchronously in IE when using document.write"

In the attached HTML file (includeDojo.html), it appears that the script tag is no longer using document.write.  Is the problem related to the document.write that is used in the overall HTML file to include all dynamically loaded content?  

if(isLastFile){
		document.write(htmlString + "<script>egl.load(RUI_RUNTIME_JAVASCRIPT_FILES, function(){egl.startupInit();});<\/script>");
		isLastFile = false;
	}
Comment 14 Huang Ji Yong CLA 2012-01-11 21:04:13 EST
(In reply to comment #13)
> In the design document, it states, "The script tag <script src="src.js" /> is
> loaded asynchronously in IE when using document.write"
> 
> In the attached HTML file (includeDojo.html), it appears that the script tag is
> no longer using document.write.  Is the problem related to the document.write
> that is used in the overall HTML file to include all dynamically loaded
> content?  
> 
> if(isLastFile){
>         document.write(htmlString +
> "<script>egl.load(RUI_RUNTIME_JAVASCRIPT_FILES,
> function(){egl.startupInit();});<\/script>");
>         isLastFile = false;
>     }

The problem I stated in design document happens in the bootstrap code you pasted, not in the "includeFile"
In current implementation, the "includeFile" is dynamically added to html file in the 2 steps:
1. Get the content by ajax.
2. Paste into html by "document.write"
The problem described in the design document happens in step 2.
Comment 15 Brian Svihovec CLA 2012-01-12 16:21:57 EST
I am changing this to .8 I2, since I think it needs more discussion.

I believe our options at this point are:

1) Pass a FileLocator (Java IO) to the HTML Generator so that it can resolve includeHTML files on the EGLpath and include them in the HTML file.  The FileLocator is passed to the generator so that it can be configured as necessary by the IDE and SDK independently.  Including this information in the HTML file is unfortunate, because it is yet another thing that a user must remember to add in their own HTML file if they are going to be re-using deployed RUIHandlers in the future.

2) The solution proposed in comment 11, where a user invokes an EGL provided load function to synchronously load the content.  In this solution, how is the loading made synchronous?  Won't the load start, and then the browser will continue on to load the rest of the content in the include file and start running the application?

I am wondering if we should expose an 'initial load' list (i.e. RUI_RUNTIME_JAVASCRIPT_FILES, RUI_DEPENDENT_JAVASCRIPT_FILES, etc) through an API (i.e. registerRequiredFile, etc), so that the includeDojo.html file can add a file to the list that is loaded synchronously before the application starts?
Comment 16 fahua jin CLA 2012-01-30 22:19:58 EST
Assign owner to Jiyong because the problem should be fixed in the HTML generation component.
Comment 17 Tony Chen CLA 2012-02-10 00:41:41 EST
Moving to I3 because dojo 1.7 upgrade introduce a new loading method which may require us design how we load dojo.
Comment 18 Huang Ji Yong CLA 2012-02-28 04:41:52 EST
This task is proved to workable in modular loading prototype
Comment 19 Huang Ji Yong CLA 2012-03-05 02:03:21 EST
Change google runtime to make use of runtime AMD loader (runtime/dojo.js)
No need to use API key now.
Done as child of bug 363555
Comment 20 Lisa Lasher CLA 2012-03-30 18:35:59 EDT
close