Changeset 87361 in webkit


Ignore:
Timestamp:
May 25, 2011 11:20:35 PM (13 years ago)
Author:
simonjam@chromium.org
Message:

2011-05-25 James Simonsen <simonjam@chromium.org>

Reviewed by Adam Barth.

Add site-specific hack for zipcar.com with old versions of requirejs.
https://bugs.webkit.org/show_bug.cgi?id=61321

Old versions of requirejs (< 0.15.0) try to load scripts in parallel but execute them in
order. This used to work in webkit by setting a bogus script type (script/cache), then
changing the type to a valid one when they wanted to execute it. This hack translates the
behavior into the new API (by disabling forceAsync).

  • html/HTMLScriptElement.cpp: (WebCore::needsOldRequirejsQuirk): Added. (WebCore::HTMLScriptElement::insertedIntoDocument): If hack is needed, set a proper script type so script loads. If script isn't async, disable forceAsync so script executes in order.
Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r87360 r87361  
     12011-05-25  James Simonsen  <simonjam@chromium.org>
     2
     3        Reviewed by Adam Barth.
     4
     5        Add site-specific hack for zipcar.com with old versions of requirejs.
     6        https://bugs.webkit.org/show_bug.cgi?id=61321
     7
     8        Old versions of requirejs (< 0.15.0) try to load scripts in parallel but execute them in
     9        order. This used to work in webkit by setting a bogus script type (script/cache), then
     10        changing the type to a valid one when they wanted to execute it. This hack translates the
     11        behavior into the new API (by disabling forceAsync).
     12
     13        * html/HTMLScriptElement.cpp:
     14        (WebCore::needsOldRequirejsQuirk): Added.
     15        (WebCore::HTMLScriptElement::insertedIntoDocument):
     16        If hack is needed, set a proper script type so script loads.
     17        If script isn't async, disable forceAsync so script executes in order.
     18
    1192011-05-25  Andreas Kling  <kling@webkit.org>
    220
  • trunk/Source/WebCore/html/HTMLScriptElement.cpp

    r84357 r87361  
    3030#include "HTMLNames.h"
    3131#include "ScriptEventListener.h"
     32#include "Settings.h"
    3233#include "Text.h"
    3334
     
    8283}
    8384
     85static bool needsOldRequirejsQuirk(HTMLScriptElement* element)
     86{
     87    if (element->fastGetAttribute(typeAttr) != "script/cache")
     88        return false;
     89
     90    Document* document = element->document();
     91
     92    const KURL& url = document->url();
     93    if (!equalIgnoringCase(url.host(), "www.zipcar.com"))
     94        return false;
     95
     96    Settings* settings = document->settings();
     97    if (!settings)
     98        return false;
     99    if (!settings->needsSiteSpecificQuirks())
     100        return false;
     101
     102    return true;
     103}
     104
    84105void HTMLScriptElement::insertedIntoDocument()
    85106{
     107    if (needsOldRequirejsQuirk(this)) {
     108        if (!asyncAttributeValue())
     109            handleAsyncAttribute(); // Clear forceAsync, so this script loads in parallel, but executes in order.
     110        setAttribute(typeAttr, "text/javascript");
     111    }
    86112    HTMLElement::insertedIntoDocument();
    87113    ScriptElement::insertedIntoDocument();
Note: See TracChangeset for help on using the changeset viewer.