1. Using CORS to load WebGL textures from cross-domain images

    In Firefox, as well as in Chrome, it is now possible to load cross-domain images into WebGL textures, if they have been approved by CORS.

    Most prominently, this feature allows for impressive 3D mapping applications such as Google MapsGL and Nokia Maps 3D.

    What happened

    Earlier this year, the Editor’s Draft WebGL specification got updated in response to a security concern. The additions were:

    1. A mandatory clause disallowing usage of cross-domain elements as WebGL textures in the general case.
    2. A non-normative clause specifically allowing cross-domain elements that have CORS approval. For that occasion, the HTML specification on the <img> element got updated to add a new crossorigin attribute.

    The first got implemented in Firefox 5, the second is now in Firefox 8.

    How to use this feature

    There are two CORS modes: “anonymous” and “use-credentials”. We’ll focus on “anonymous” as it’s the common case. A great example of images served with anonymous CORS is Google Maps imagery, such as:

    http://khm0.googleapis.com/kh?v=95&x=0&y=0&z=0

    In order to load it with CORS as a WebGL texture, we set the crossOrigin attribute on it:

    var earthImage = new Image();
    earthImage.crossOrigin = "anonymous";

    Now we load it as usual:

        earthImage.onload = function() {
          // whatever you usually to do load WebGL textures
        };
        earthImage.src = "http://khm0.googleapis.com/kh?v=95&x=0&y=0&z=0";

    That’s it! Aside from setting the crossOrigin attribute, we didn’t have to do anything. Here is the full self-contained example.

    The HTTP headers

    If we study the HTTP headers for this image (using, for example, Firefox’s Web Console), we find that the Request Headers contain

    Origin: null

    which is the effect of having set this crossOrigin attribute on the img element. And the Response Headers contain

    Access-Control-Allow-Origin: null

    which is the effect of the server supporting CORS for this file.

    Doing this in HTML

    Of course, one could also set this attribute in HTML, in which case it’s case-insensitive:

    <img src="http://khm0.googleapis.com/kh?v=95&x=0&y=0&z=0" crossorigin="anonymous">

    And since “anonymous” is both the missing-value-default and the invalid-value-default for the crossorigin attribute, we can pass any invalid value for it, or even just omit its value:

    <img src="http://khm0.googleapis.com/kh?v=95&x=0&y=0&z=0" crossorigin>

    Coming soon: CORS approval for Canvas 2D drawImage

    What if you first draw a CORS-approved cross-domain image onto a 2D
    canvas, and then use that canvas as the source of a WebGL texture? The
    good news is that this will work in Firefox 9, which is hitting the Beta
    channel soon. This fix means that demos like this will work really
    nicely in Firefox 9.

  2. Want to go to Full Frontal in Brighton, England this Friday? We got tickets!

    photo by Lily

    Full Frontal is a JavaScript centric conference in Brighton, England on the 11/11/11. The simplest way to describe it is “a splendid kick into your lower back side” event when it comes to what’s hot and amazing int he world of scripting.

    The Mozilla Developer Network has 3 tickets to give out, one of which also entitles you to attend the speakers dinner the day before the conference. Tickets for the conference are gone, so here is your last chance.

    If you want to take part in this, you need to be able to get to Brighton, England on the 11th and be open to also come on the 10th for the speaker’s dinner (one of you). Please say if you can’t come on the 10th – you can still win a ticket. We will need your name for the organisers to put on the list.

    First and foremost though, in order to win a ticket add a comment here why you deserve to get a Mozilla ticket and what you can do as a thank you to help the open web.

    The best reasons and offers will get the tickets. We will announce the pick on the 9th here and contact you so please leave a valid email in the comment (this will not be shown to the public).

    For extra brownie points, why not tell us what new initiatives of Mozilla get you most excited and what we could be doing to make them a reality faster.

    See you in Brighton, it rocks!

    We picked the winners, now! Let’s get full frontal!

  3. Wiki Wednesday: November 2, 2011

    Here are today’s Wiki Wednesday articles! If you know about these topics, please try to find a few minutes to look over these articles that are marked as needing technical intervention and see if you can fix them up. You can do so either by logging into the wiki and editing the articles directly, or by emailing your notes, sample code, or feedback to mdnwiki@mozilla.org.

    Contributors to Wiki Wednesday will get recognition in the next Wiki Wednesday announcement. Thanks in advance for your help!

    JavaScript

    Thanks to BYK for contributing to these docs since last time!

    SpiderMonkey

    Developing Mozilla

    Extensions

    XUL

    Thanks to Neil Rashbrook for his contributions!

    XPCOM

    Thanks to Neil Rashbrook for even more contributions!

    Interfaces

    Thanks again to Neil Rashbrook for his continuing contributions!

    Plugins

    CSS

    Thanks to BYK for contributing.

    SVG

    HTML

    DOM

  4. Webinar: Canvas with Rob Hawkes

    Update 2011-11-10: Video of this webinar is now available:

    You can download the code that Rob demos in the webinar.

    You might also check out the recording of the webinar created by BigBlueButton. It syncs the audio with the slides and chat window using Popcorn.js. On the downside, BBB starts recording as soon as anyone joins the conference audio bridge, which in this case happened an hour before the webinar started. Fast-forward to time 58:20 for the start of the webinar.

    Please join us on Tuesday, November 8th at 17:00 UTC (convert to your local time) for a webinar on using the Canvas API, with our own Rob Hawkes, author of Foundation HTML5 Canvas.

    Canvas is the topic for the November Dev Derby. Rob is planning to show how to make an image editor for avatars using Canvas. Spark your imagination with the webinar, create some new and amazing use of Canvas, and submit it to the Dev Derby.

    We will use BigBlueButton for web-conferencing, and will avoid using the feature that led to the server problems with the September webinar. We will be recording the session, and I promise to double- and triple-check the recording set-up in advance :-)

    Add this event to your calendar:

    We’d like to get a rough estimate of how many people will be attending. If you happen to use Plancast, and you plan to attend the seminar, please join the event on Plancast.

    To join the webinar:

    1. Go to the BigBlueButton server for Mozilla.
    2. For Full Name, enter your name.
    3. Select “Mozilla Developer Network” in the Room list.
    4. For Password, enter MDNHacks.
    5. Note: Big Blue Button uses Flash, so make sure you have the latest version installed, especially if you are running Mac OS X Lion.