<?xml version='1.0'?>
<!DOCTYPE bindings SYSTEM "/ts.dtd"><bindings xmlns:islands="http://bar.yandex.ru/ui/islands" xmlns:xbl="http://www.mozilla.org/xbl" xmlns="http://www.mozilla.org/xbl" xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

    <binding extends="chrome://global/content/bindings/notification.xml#notification" id="notification">
        <resources>
            <stylesheet src="../../styles/ts/notification.css"/>
            <stylesheet src="../../bindings/islands/islands.css"/>
        </resources>

        <content flex="1">
            <xul:hbox flex="1">
                <xul:image anonid="messageImage" class="messageImage2" xbl:inherits="type,value" onclick="_doAction(_goToYaHome, _targetURL ? 11 : 12);"/>

                <xul:hbox class="notification-message">
                    <xul:stack anonid="user-message">
                        <xul:hbox anonid="user-message-no-uri" hidden="true">
                            &typosquatting.notification.warningnouri;
                            <xul:hbox onclick="_doAction(_leaveHere, 7);">
                                <islands:button label="&typosquatting.notification.actionbutton.leave.label;" islands:size="S" islands:type="normal"/>
                            </xul:hbox>
                        </xul:hbox>
                        <xul:hbox anonid="user-message-uri">
                            &typosquatting.notification.warning.start;
                            <xul:label anonid="link" xbl:inherits="value=data-targetURL" onclick="_doAction(_goToRecommendedURL, 2);"/>&typosquatting.notification.warning.end;
                            <xul:hbox onclick="_doAction(_goToRecommendedURL, 3);">
                                <islands:button label="&typosquatting.notification.actionbutton.transfer.label;" islands:size="S" islands:type="normal"/>
                            </xul:hbox>
                        </xul:hbox>
                    </xul:stack>
                </xul:hbox>

            </xul:hbox>

            <xul:hbox anonid="close-button" onclick="_doAction(_refuseNotification, _targetURL ? 4 : 8);" tooltiptext="&typosquatting.notification.closebutton.tooltip;">
                <xul:hbox>&typosquatting.notification.closebutton.label;</xul:hbox>
                <xul:image class="image-close"/>
            </xul:hbox>
        </content>

        <implementation>
            <field name="_messageNoUri">
                document.getAnonymousElementByAttribute(this, "anonid", "user-message-no-uri");
            </field>

            <field name="_message">
                document.getAnonymousElementByAttribute(this, "anonid", "user-message-uri")
            </field>

            <field name="_targetURL">
                this.getAttribute("data-targetURL");
            </field>

            <field name="_maliciousURL">
                this.getAttribute("data-malicious-site");
            </field>

            <field name="_referrer"><![CDATA[this.browser.webNavigation.referringURI && this.browser.webNavigation.referringURI.spec || "";]]></field>

            <field name="_tabData">
                this.typo.mWindowListener.getTabData(this.browser, this.typo.NOTIFICATION_OBJECT_NAME);
            </field>

            <constructor><![CDATA[if (this._constructed)
{
return;
}

this._constructed = true;
if (! this._targetURL)
{
this._messageNoUri.hidden = false;
this._message.hidden = true;
}

this._sendStatistic(this._targetURL ? 1 : 6);
var browser = this.browser;
var API = this.typo.API;
this._tabData.codeID = this._targetURL ? 9 : 10;
this._tabData.show = true;
var handler = {
handleEvent: function handler_handleEvent(aEvent) {
switch (aEvent.type) {
case "pagehide":
browser.removeEventListener("pagehide",this);
if (! this.typo._wdgtxConstructed)
{
return;
}

API.Async.nextTick((function (codeID) {
var url = "";
try {
url = browser.currentURI.spec;
}
catch (e) {

}

this._sendStatistic(codeID,url);
}
).bind(this,this._tabData.codeID));
this._resetTabData();
}

}
,
typo: this.typo,
_tabData: this._tabData,
_maliciousURL: this._maliciousURL,
_referrer: this._referrer,
_sendStatistic: this._sendStatistic,
_resetTabData: function handler__resetTabData() {
["show", "action", "codeID"].forEach((function (key) {
delete this._tabData[key];
}
).bind(this));
}
};
browser.addEventListener("pagehide",handler,false);
this.typo.addNotification(this);]]></constructor>

            <destructor><![CDATA[typeof this.typo.releaseNotification === "function" && this.typo.releaseNotification(this);]]></destructor>

            <method name="wdgtxDestructor">
                <body><![CDATA[if (! this._constructed)
return;
this._constructed = false;
this.close();]]></body>
            </method>

            <method name="_doAction">
                <parameter name="callback"/>
                <parameter name="codeID"/>
                <body><![CDATA[this._tabData.action = true;
this._tabData.codeID = codeID;
this.close();
if (typeof callback === "function")
{
callback.bind(this)();
}
]]></body>
            </method>

            <method name="_goToYaHome">
                <body><![CDATA[var url = this.typo.module.yaUrl;
this._navigateCurrentTab(url);]]></body>
            </method>

            <method name="_goToRecommendedURL">
                <body><![CDATA[this._navigateCurrentTab(this._targetURL);]]></body>
            </method>

            <method name="_leaveHere">
                <body><![CDATA[try {
let url = this.typo.API.Settings.PrefsModule.get("browser.startup.homepage") || "about:blank";
url = url.split("|")[0];
this._navigateCurrentTab(url);
}
catch (e) {

}
]]></body>
            </method>

            <method name="_navigateCurrentTab">
                <parameter name="aURL"/>
                <body><![CDATA[this.typo.API.Controls.navigateBrowser({
"url": aURL,
"target": "current tab"});]]></body>
            </method>

            <method name="_refuseNotification">
                <body><![CDATA[this.close();]]></body>
            </method>

            <method name="_sendStatistic">
                <parameter name="codeID"/>
                <parameter name="to"/>
                <body><![CDATA[this.typo.sendStatistic(codeID,this._maliciousURL,this._referrer,to);]]></body>
            </method>

        </implementation>
    </binding>

</bindings>
