Labs/Jetpack/Reboot/JEP/108: Difference between revisions

From MozillaWiki
< Labs‎ | Jetpack‎ | Reboot‎ | JEP
Jump to navigation Jump to search
No edit summary
No edit summary
 
(28 intermediate revisions by one other user not shown)
Line 1: Line 1:
== JEP 108 - Background Pages ==
== JEP 108 - Page Worker ==


* Champion: Daniel Buchner - daniel@mozilla.com
* Champion: Daniel Buchner - daniel@mozilla.com
* Status: Accepted/In-Queue
* Status: Under Review
* Bug Ticket:
* Bug: [https://bugzilla.mozilla.org/show_bug.cgi?id=546740 546740]
* Type: API
* Type: API




=== Proposal ===
=== Proposal ===
Background Pages are like a more open and free sandbox for doing most anything in a traditional web page with a DOM context, but with a key difference: the page is augmented with escalated, descending, chrome privileges. It is essentially along the same line of a Web Worker, just more open and accessible.  
Page Worker is like a more open sandbox for doing most anything in a traditional web page with a DOM context, but with a key difference: the page is augmented with escalated, waterfall chrome privileges. It is essentially along the same line of a Web Worker, just more open and accessible.


=== Use-Cases ===
1. Google Maps API Data
If you wanted to utilize the data available via Google Maps API, you would need to instantiate the API's script within the context of a DOM. This is due to Google Maps reliance on the elements and script it pulls in to make data fetching possible. I might want to have a Jetpack that searches the page for addresses and business titles allowing the user to mouseover those items and view geolocalized details about such places in a tooltip.


=== Key Issues ===
2. Native Type Proxy & DOM-Reliant Script Execution Environment
 
It is almost a certainty that developers will want to use their js library of choice to interact with web content.  To enable this more easily, they could use this JEP's DOM as a Native Type proxy and as the primary location to instantiate their DOM dependent code.


=== Dependencies & Requirements ===
=== Dependencies & Requirements ===
* We must be able to give the code in the top window of this page chrome privileges that are strictly one-way/descending in nature.
* We must be able to give the code in the top window of this page chrome privileges that are strictly one-way/descending in nature.
* Dynamically generated code sent to the Background Page should be injected and executed in the Background Page's window context.
* Dynamically generated code sent to the Page Worker should be injected and executed in the Page Worker's window context.




Line 22: Line 25:
* TBD
* TBD


== API Methods ==
==== Page Worker Global: <i>$page</i> ====
==== Page Worker Method: <i>run</i> ====
<b>Description:</b>
Allows you to run code in the Page Worker's window context.
<b>Arguments:</b>
#<b><i>options</i></b> - (<i>object</i>)
#* bind: (<i>mixed</i>) a variable that will be bound as the 'this' keyword in the function
#* arguments: (<i>array</i>) an array of mixed variables passed as the function arguments
#* timeout: (<i>number</i>) a number that is used to set the timeout duration
#* interval: (<i>number</i>)  a number that is used to set the interval duration
#<b><i>action</i></b> - (<i>function</i>) a function to be executed within the DOM of the Page Worker - by default, the Page Worker's window object is the bound 'this' within the function
<b>Returns:</b>
<b><i>user defined return value</i></b> - The function's return value as specified by the user
or
<i>If timeout or interval options are used:</i>
<b><i>array</i></b> - an array whose first item is the function's user defined return value, and second is a variable the user can save to clear the timing event
<b>Notes:</b>
<b>Examples:</b>
<pre class="brush:js;">
$page.run({ interval: 10000 }, function(){
    return window.location;
});
</pre>
==== Page Worker Method: <i>empty</i> ====
<b>Description:</b>
Empties the Page Worker's of all elements (this includes the body, which is then reinserted fresh).
<b>Arguments:</b>
<i>This method takes no arguments</i>
<b>Returns:</b>
The Page Worker Global object: <i>$page</i>
<b>Examples:</b>
<pre class="brush:js;">
$page.empty();
</pre>
==== Page Worker Method: <i>reset</i> ====
<b>Description:</b>
Resets the Page Worker to a blank HTML page with no elements and a clean global window object.
<b>Arguments:</b>
<i>This method takes no arguments</i>
<b>Returns:</b>
The Page Worker Global object: <i>$page</i>
<b>Examples:</b>


=== API Methods ===
<pre class="brush:js;">
* $Moz.toBackground(function(){ return window.document; })  //should return the Background Page's HTML document
$page.reset();
</pre>

Latest revision as of 01:51, 7 May 2010

JEP 108 - Page Worker

  • Champion: Daniel Buchner - daniel@mozilla.com
  • Status: Under Review
  • Bug: 546740
  • Type: API


Proposal

Page Worker is like a more open sandbox for doing most anything in a traditional web page with a DOM context, but with a key difference: the page is augmented with escalated, waterfall chrome privileges. It is essentially along the same line of a Web Worker, just more open and accessible.

Use-Cases

1. Google Maps API Data If you wanted to utilize the data available via Google Maps API, you would need to instantiate the API's script within the context of a DOM. This is due to Google Maps reliance on the elements and script it pulls in to make data fetching possible. I might want to have a Jetpack that searches the page for addresses and business titles allowing the user to mouseover those items and view geolocalized details about such places in a tooltip.

2. Native Type Proxy & DOM-Reliant Script Execution Environment It is almost a certainty that developers will want to use their js library of choice to interact with web content. To enable this more easily, they could use this JEP's DOM as a Native Type proxy and as the primary location to instantiate their DOM dependent code.

Dependencies & Requirements

  • We must be able to give the code in the top window of this page chrome privileges that are strictly one-way/descending in nature.
  • Dynamically generated code sent to the Page Worker should be injected and executed in the Page Worker's window context.


Internal Methods

  • TBD

API Methods

Page Worker Global: $page

Page Worker Method: run

Description:

Allows you to run code in the Page Worker's window context.

Arguments:

  1. options - (object)
    • bind: (mixed) a variable that will be bound as the 'this' keyword in the function
    • arguments: (array) an array of mixed variables passed as the function arguments
    • timeout: (number) a number that is used to set the timeout duration
    • interval: (number) a number that is used to set the interval duration
  2. action - (function) a function to be executed within the DOM of the Page Worker - by default, the Page Worker's window object is the bound 'this' within the function

Returns:

user defined return value - The function's return value as specified by the user

or

If timeout or interval options are used:

array - an array whose first item is the function's user defined return value, and second is a variable the user can save to clear the timing event

Notes:


Examples:

$page.run({ interval: 10000 }, function(){
    return window.location;
});

Page Worker Method: empty

Description:

Empties the Page Worker's of all elements (this includes the body, which is then reinserted fresh).

Arguments:

This method takes no arguments

Returns:

The Page Worker Global object: $page

Examples:

$page.empty();

Page Worker Method: reset

Description:

Resets the Page Worker to a blank HTML page with no elements and a clean global window object.

Arguments:

This method takes no arguments

Returns:

The Page Worker Global object: $page

Examples:

$page.reset();