1

XUL ウィンドウにプラス 1 ボタンを追加しようとしていますが、次のエラーが発生します。

Error: Permission denied for <https://plusone.google.com> to call method ChromeWindow.postMessage
Source file: https://ssl.gstatic.com/webclient/js/gc/22431124-0a127465/googleapis.client__plusone.js
Line: 14

iframe を追加していhttps://plusone.google.com/u/0/_/+1/fastbutton?url=ます ...

XUL ウィンドウにボタンを追加して、+1それを受け入れさせる方法はありpostMessageますか?


私が開発しようとしているアドオンは、以下の画像にあります。唯一の問題は、許可によるクリックが登録されないことです。

+1

bootstrap.js(ブートストラップ-vsdoc.js )

/// <reference path="bootstrap-vsdoc.js" />

/// <summary>
/// Made by Bruno Leonardo Michels
/// </summary>

var watcher = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
                        .getService(Components.interfaces.nsIWindowWatcher);

var listenOpen = {
    observe : function(cWindow, cEvent) {
        if (cEvent != "domwindowopened") return;
            cWindow.addEventListener("load", start, false);
    }
};

function startup(data, reason) {
    watcher.registerNotification(listenOpen);

    var mWindows = watcher.getWindowEnumerator();
    while (mWindows.hasMoreElements()) {
        start(mWindows.getNext());
    }
}
function shutdown(data, reason) {
    watcher.unregisterNotification(listenOpen);

    var mWindows = watcher.getWindowEnumerator();
    while (mWindows.hasMoreElements()) {
        end(mWindows.getNext());
    }
}
function install(data, reason) {

}
function uninstall(data, reason) {

}

/// #region Methods

function getWindow(cWindow)
{
    try
    {
        if (cWindow instanceof Components.interfaces.nsIDOMEvent)
        {
            cWindow = cWindow.currentTarget;
        }
        if (cWindow.document.documentElement.getAttribute("windowtype") != "navigator:browser")
            return;
    }
    catch(ex) { }

    return cWindow;
}

function ajaxGet(cWindow, url, cb)
{
    var xmlhttp;
    xmlhttp = new cWindow.XMLHttpRequest();
    xmlhttp.open("GET", url, true);
    xmlhttp.onreadystatechange=function()
    {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
        {
            cb(xmlhttp);
        }
    };
    xmlhttp.send();
}

var eventList = [];
function bind(gBrowser, cWindow, target, eventName, fn)
{
    var ev = function(e) { fn(gBrowser, cWindow, e); };
    eventList.push(ev);
    target.addEventListener(eventName, eventList[eventList.length-1], false);
}
function unbind(target, eventName, fn)
{
    var b = target.removeEventListener ?
        function( elem, type, handle ) {
            if ( elem.removeEventListener ) {
                elem.removeEventListener( type, handle, false );
            }
        } :
        function( elem, type, handle ) {
            if ( elem.detachEvent ) {
                elem.detachEvent( "on" + type, handle );
            }
        };

    b(target, eventName, fn);
}
function unbindAll(target, eventName)
{
    for (var i in eventList)
    {
        unbind(target, eventName, eventList[i]);
    }
}

/// #endregion

/// #region Events

function start(cWindow) {
    cWindow = getWindow(cWindow);

    if (!cWindow) return;

    with (cWindow)
    {
        bind(gBrowser, cWindow, gBrowser.tabContainer, "TabAttrModified", tabChange);

        var window = cWindow;
        var document = cWindow.document;

        var url = window.location.href;
        if (!/^http/i.test(url))url="http://www.orkutmanager.net/";
        var urlE= window.encodeURIComponent(url);

        var iconsBar = document.getElementById("urlbar-icons");

        function insScript(w)
        {
            var sc = document.createElement("script");
            sc.src = "https://apis.google.com/js/plusone.js";
            sc.type= "text/javascript";
            sc.setAttribute("extension", "plusoneany");
            (document.lastChild).appendChild(sc);
        }
        insScript(this);
        insScript(this.parent);
        insScript(this.top);

        var button = document.createElement("iframe");
        button.id = "extensions.plusoneany.button";
        button.setAttribute("src", "https://plusone.google.com/u/0/_/+1/fastbutton?url=" + urlE +
            "&size=small&count=true&hl=en-US&_methods=onPlusOne%2C_ready%2C_close%2C_open%2C_resizeMe");
        button.setAttribute("class", "urlbar-icon extensions-plusoneany");
        button.setAttribute("style", "border:0;padding:0;margin:0;width:70px;height:16px;");

        iconsBar.insertBefore(button, iconsBar.lastChild);
    }
}
function end(cWindow) {
    try
    {
        unbindAll(gBrowser.tabContainer, "TabAttrModified");
    }
    catch(ex){}

    try
    {
        var elements = cWindow.document.getElementsByClassName("extensions-plusoneany");

        for (var i in elements)
        {
            elements[i].parentNode.removeChild(elements[i]);
        }
    }
    catch(ex){}
}

function tabChange(gBrowser, cWindow, e) {
    var win = gBrowser.selectedBrowser.contentWindow;
    var uns = gBrowser.selectedBrowser.contentWindow.wrappedJSObject;

    uns.clearTimeout(uns.PlusOneAnyTimeout);

    uns.PlusOneAnyTimeout = uns.setTimeout(function() {
        var url = win.location.href;
        if (!/^http/i.test(url))url="http://www.orkutmanager.net/";
        var urlE= uns.encodeURIComponent(url);

        try {
            var ifr = cWindow.document.getElementById("extensions.plusoneany.button");
            ifr.setAttribute("src", "https://plusone.google.com/u/0/_/+1/fastbutton?url=" + urlE +
                "&size=small&count=true&hl=en-US&_methods=onPlusOne%2C_ready%2C_close%2C_open%2C_resizeMe");
        }catch(ex){}
    }, 500);
}

/// #endregion
4

4 に答える 4

1

@systempuntoout は、理論的には iframe タイプ属性を「コンテンツ」に設定することでこれを修正する必要があるということです。ただし、過去にこれに問題がありました。うまくいくかもしれませんが、この点で XUL には少しバグがあると思います。私だったら、XUL <iframe> の代わりに XUL <browser> 要素を埋め込み、実行したいコード (この場合はsrc が「https://plusone.google.com...」に設定された iframe)。そうすれば、ブラウザのメイン コンテンツ ウィンドウと同じように、コードが実際のコンテンツとして実行されます。

HTML ページをディスクに書き込んで (iframe ソースの一部が動的に生成されるため)、それを file:// URL で参照できます。この場合、コードは非常に短いので、一時ファイルをディスクに書き込む必要がなくなるデータ URI を使用することもできます。

つまり、HTML ファイルを (メモリ内またはディスク上に) 次のように作成します。

<html>
<body>
<iframe src="https://plusone.google.com..." />
</body>
</html>

次に、iframe に対して現在行っているのと同じように <browser> 要素を作成し、それを XUL ドキュメントに挿入し、それに対して loadURI() を呼び出して、(file: または data: URI を介して) HTML ファイルを参照します。

于 2011-08-02T13:13:23.637 に答える
1

この行を追加してタイプを指定しようとします:

ifr.setAttribute("type","content");
于 2011-08-02T20:46:37.760 に答える
0

これは役立つかもしれないと思います。それはあなたが抱えている問題かもしれません。

ドメイン間で window.postMessage をどのように使用しますか?

于 2011-07-27T00:02:31.363 に答える
0

非常に悪い答えですが、コンテンツを取得してhttps://apis.google.com/js/plusone.js評価することはできませんか? それはGoogleです、何がうまくいかないのですか;]

于 2011-08-01T21:22:56.163 に答える