Opened 12 years ago

Closed 7 years ago

#3833 closed enhancement (wontfix)

[patch][cla] allow Dojo to work in Firefox extensions

Reported by: guest Owned by: Bryan Forbes
Priority: high Milestone: future
Component: IO Version: 0.9
Keywords: firefox extension, cometd Cc: dbrown@…, James Burke
Blocked By: Blocking:

Description (last modified by James Burke)

I have included a patch in unified diff format, that allows Dojo to work within a Firefox extension, while keeping normal browser functionality.

This is in relation to forum post:
http://dojotoolkit.org/forum/dojo-core-dojo-0-9/dojo-core-support/dojo-firefox-extension

This patch updates /dojo.js and /src/io/ScriptScrIO.js

The reason for this patch is that within a Firefox extension there is no Head element to attach the script element too.

ScriptScrIO.js goes one step further then dojo.js and implements the same code as dojo.js but then also implements the ability to use AJAX to get the JS file. The reasoning for this extra step is because the code to add the JS file to the Firefox XUL only allows for the loading of local files. This is a problem if the user is using the cometd section of Dojo. This is because cometd needs to talk to the server which in normal cases is not local to the extension user. Therefore it uses AJAX in to get the source of the external JS file (this AJAX is able to go to a different domain because it is being ran as a extension and therefore has higher security levels). Once AJAX can retrieved the source it URI encodes it and passes it in a, data URI to the Firefox JS load function.

This gives the ability for Dojo to be smart enough to know if it is running in a normal browser window or as a Firefox extension, and also smart enough to know if it needs to load the required JS files from the local machine or from a remote server.

The only other possible requirement to have Dojo work as a Firefox extension is to set the variable: baseRelativePath. This value will be dependent on the developer and therefore was not hard coded to allow developers to easily set this variable like the normally would. In my case I set the variable to:

var djConfig = {
baseRelativePath : "chrome://myExtension/content/dojo/",
};

Files Seperate:
http://www.port21.com/Code/Dojo/FirefoxExtensionPatch/Dojo-dojo-js-udiff
http://www.port21.com/Code/Dojo/FirefoxExtensionPatch/Dojo-src-io-ScriptSrcIO-js-udiff

Files Ziped:
http://www.port21.com/Code/Dojo/FirefoxExtensionPatch/Dojo-FirefoxExtensionPatch.zip

Attachments (4)

Dojo-dojo-js-udiff (1.1 KB) - added by guest 12 years ago.
Dojo-src-io-ScriptSrcIO-js-udiff (2.4 KB) - added by guest 12 years ago.
Dojo-FirefoxExtensionPatch.zip (1.8 KB) - added by guest 12 years ago.
simpleSidebar.tgz (4.7 KB) - added by Adam Peller 11 years ago.
FF extension example, provided by Allen Cypher (IBM, CCLA) See Readme.txt

Download all attachments as: .zip

Change History (23)

Changed 12 years ago by guest

Attachment: Dojo-dojo-js-udiff added

Changed 12 years ago by guest

Changed 12 years ago by guest

comment:1 Changed 12 years ago by dylan

Component: GeneralIO
Keywords: cometd added
Milestone: 1.0
Owner: changed from anonymous to alex

comment:2 Changed 12 years ago by Adam Peller

Milestone: 1.02.0
Summary: Patch to allow Dojo to work in Firefox extensions[patch][cla needed?] allow Dojo to work in Firefox extensions

dbrown, have you signed a CLA?

comment:3 Changed 12 years ago by guest

Yes I signed one and faxed it in before I submitted this

comment:4 Changed 12 years ago by alex

Status: newassigned
Summary: [patch][cla needed?] allow Dojo to work in Firefox extensions[patch][cla] allow Dojo to work in Firefox extensions

thanks for confirming the CLA. Much appreciated.

comment:5 Changed 12 years ago by alex

Milestone: 2.01.3

Milestone 2.0 deleted

comment:6 Changed 11 years ago by James Burke

Cc: James Burke added
Description: modified (diff)

comment:7 Changed 11 years ago by alex

(In [15409]) dev-time support for detecting and loading a XUL-based host-environment. Also adds a host environment file build specifically for use in extensions and a trivial patch to allow the build system to be told that it's in a browser-like environment.

Refs #3833 !strict

comment:8 Changed 11 years ago by James Burke

alex: do you have a way to test this or some sort of instructions we could commit that would give a reproducible way to try out the code? There is another ticket open for a windows script host hostenv, and I am hoping to do the same for that one too. It is harder to support these other hostenvs without easy ways to jump in and test them. I am not smart enough to remember how it works unless there is a real test/instructions.

comment:9 Changed 11 years ago by James Burke

alex: a couple of other questions:

1) I haven't thought this all the way through, maybe this would not be good: there seems like a good amount of copy/paste with the hostenv_browser. I wonder if we could use some if statements in the hostenv_browser and then use some conditional build comments that test for kwArgs.profileProperties.hostenvType to strip out stuff not needed for normal browser builds. Maybe still need an FF hostenv but it might be smaller.

2) I don't get the buildUtil.js change. I don't see isBrowser defined anywhere in the buildscripts, and no where else in [15409]?

comment:10 Changed 11 years ago by alex

(In [15420]) removing bad impls of createElement() and elem(). Refs #7802. Refs #3833. !strict

comment:11 Changed 11 years ago by alex

James:

WRT the isBrowser, there's a hostenv check on line 355 of buildUtil.js which sets dojo.isBrowser to make sure that you're using browser params for the package system to ensure that the right stuff gets loaded, particularly in _base.js where you might have requireIf statements that exclude some things in non-browser environments. Since FF extensions are "browser++" environments but don't use the browser hostenv, we need another way to set this.

comment:12 Changed 11 years ago by James Burke

Alex: what I cannot see is how isBrowser is ever set. Maybe you do this in the build profile perhaps? I wonder if it is worth just changing line 355 from this:

if(hostenvType == "browser" || isBrowser)

to something like this:

if(hostenvType == "browser" || hostenvType == "ff_ext")

comment:13 Changed 11 years ago by bill

Milestone: 1.3future

Changed 11 years ago by Adam Peller

Attachment: simpleSidebar.tgz added

FF extension example, provided by Allen Cypher (IBM, CCLA) See Readme.txt

comment:14 Changed 11 years ago by James Burke

(In [16774]) Fixes #8669, cannot build rhino hostenv builds, and refs #3833, building Dojo for firefox extensions.

comment:15 Changed 10 years ago by petschm

The environment uses mozIJSSubScriptLoader to load other scripts, it seems the scriptloader doesn't support unicode. When i use it with dojo.currency the currency symbols are not displayed correct.
I removed the "monkey-patch" with the mozIJSSubScriptLoader and added a nsIScriptableUnicodeConverter to the _getText method and now it works fine.

The drawback is that you don't see any syntax errors with filename and line number anymore.

comment:16 Changed 9 years ago by Chris Mitchell

Owner: alex deleted
Status: assignednew

comment:17 Changed 9 years ago by Chris Mitchell

Owner: set to dylan

comment:18 Changed 8 years ago by bill

Owner: changed from dylan to Bryan Forbes

Bulk change to reassign IO tickets to Bryan, since he is working on new dojo/request module. Some of these tickets should probably be closed as already fixed, invalid, or wontfix.

comment:19 Changed 7 years ago by Kitson Kelly

Resolution: wontfix
Status: newclosed

I am afraid this a horribly stale ticket. Significant movement in Dojo and browser extensions would require a different approach for this patch or concept to work.

Note: See TracTickets for help on using tickets.