2012年3月30日金曜日

アドオンからWebページのHTMLを書き換える

最初、innerHTML で書き換えてたのですがAMOの事前審査でセキリュティリスクがあると言われて拒否されました。。

https://developer.mozilla.org/en/XUL_School/DOM_Building_and_HTML_Insertion

そこで一旦HTMLからDOMを作り、それをWebページに追加する形にしたところ無事通過しました。


function HTMLParser(doc, aHTMLString)
{
        var html = doc.implementation.createDocument("http://www.w3.org/1999/xhtml", "html", null);
        var body = doc.createElementNS("http://www.w3.org/1999/xhtml", "body");
        html.documentElement.appendChild(body);

        body.appendChild(Components.classes["@mozilla.org/feed-unescapehtml;1"].getService(Components.interfaces.nsIScriptableUnescapeHTML).parseFragment(aHTMLString, false, null, body));

        return body;
}

0 件のコメント:

コメントを投稿