injectFeatureLibraries(gadget, head, firstHeadChild);
// This can be one script block.
Element mainScriptTag = document.createElement("script");
GadgetContext context = gadget.getContext();
MessageBundle bundle = messageBundleFactory.getBundle(
gadget.getSpec(), context.getLocale(), context.getIgnoreCache(), context.getContainer());
injectMessageBundles(bundle, mainScriptTag);
injectDefaultPrefs(gadget, mainScriptTag);
injectPreloads(gadget, mainScriptTag);
// We need to inject our script before any developer scripts.
head.insertBefore(mainScriptTag, firstHeadChild);
Element body = (Element)DomUtil.getFirstNamedChildNode(document.getDocumentElement(), "body");
body.setAttribute("dir", bundle.getLanguageDirection());
injectOnLoadHandlers(body);
mutableContent.documentChanged();
} catch (GadgetException e) {