home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Narzedzia / AIMP2 / aimp_2.61.583.exe / $TEMP / YandexPackSetup.msi / fil10EFA091CE091D20B8C4DA9A913001FD < prev    next >
Text File  |  2010-07-12  |  25KB  |  708 lines

  1. var YaWelcome = {
  2.   onpenerYa: window.opener.Ya,
  3.   
  4.   nsIYa: Cc["@yandex.ru/yasearch;1"].getService(Ci.nsIYaSearch).wrappedJSObject,
  5.   yaAuth: Cc["@yandex.ru/yasearch;1"].getService(Ci.nsIYaSearch).wrappedJSObject.yaAuth,
  6.   
  7.   get observerService() {
  8.     return Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
  9.   },
  10.   
  11.   get dialogContentHeight() {
  12.     let dialogContent = document.getElementById("dialogcontent");
  13.     
  14.     let contentHeight = 0,
  15.         contentStyle = window.getComputedStyle(dialogContent, null);
  16.     
  17.     ["border-top-width", "border-bottom-width", "margin-top", "margin-bottom"]
  18.     .forEach(function(aPropName) {
  19.       contentHeight += parseInt(contentStyle.getPropertyValue(aPropName), 10);
  20.     });
  21.     
  22.     contentHeight += dialogContent.selectedPanel.currentHeight;
  23.     
  24.     return contentHeight;
  25.   },
  26.   
  27.   sizeToContent: function(aCenterWindow) {
  28.     if (window.outerHeight < 100 && !aCenterWindow)
  29.       return;
  30.     
  31.     let centerWindow = !!(aCenterWindow || window.outerHeight < 100);
  32.     
  33.     setTimeout(function() {
  34.       if (!centerWindow) {
  35.         window.sizeToContent();
  36.         return;
  37.       }
  38.       
  39.       if (window.outerHeight < 100)
  40.         window.outerHeight = 100;
  41.       
  42.       YaWelcome.toggleCollapsedView(YaWelcome.getAboutServiceCollapsedState());
  43.       
  44.       window.sizeToContent();
  45.       
  46.       window.centerWindowOnScreen();
  47.       
  48.       if (window.screenX == 50000 && window.screenY == 50000) {
  49.         let appInfo = YaWelcome.nsIYa.AppInfo;
  50.         if (appInfo.OS.isMacOS && appInfo.browser.isGreaterThenFx35) {
  51.           try {
  52.             let primaryScreen = Cc["@mozilla.org/gfx/screenmanager;1"]
  53.                                     .getService(Ci.nsIScreenManager)
  54.                                     .primaryScreen;
  55.             
  56.             let left = {}, top = {}, width = {}, height = {};
  57.             primaryScreen.GetAvailRect(left, top, width, height);
  58.             
  59.             window.moveTo((left.value + width.value - window.outerWidth)/2,
  60.                           (top.value + height.value - window.outerHeight)/2);
  61.           } catch(e) {}
  62.         }
  63.       }
  64.       
  65.       new YaDragWindow([document.getElementById("tabbox-welcome"),
  66.                         document.getElementById("tabbox-services")]);
  67.     
  68.     }, centerWindow ? 300 : 100);
  69.   },
  70.   
  71.   get LOGIN_STATES() {
  72.     return this.yaAuth.LOGIN_STATES;
  73.   },
  74.   
  75.   _loginProcessUsername: null,
  76.   
  77.   get loginProcessUsername(val) {
  78.     return this._loginProcessUsername;
  79.   },
  80.   
  81.   set loginProcessUsername(val) {
  82.     this._loginProcessUsername = this.yaAuth.normalizeUser(val).name;
  83.   },
  84.   
  85.   get loginState() {
  86.     let user = this.yaAuth.Users.getUser(this.loginProcessUsername);
  87.     if (!user)
  88.       return this.LOGIN_STATES.NO_AUTH;
  89.     
  90.     return user.auth.loginState;
  91.   },
  92.   
  93.   get authType() {
  94.     let user = this.yaAuth.Users.getUser(this.loginProcessUsername);
  95.     if (!user)
  96.       return null;
  97.     
  98.     return user.type;
  99.   },
  100.   
  101.   cancelDialog: function() {
  102.     return document.documentElement.cancelDialog();
  103.   },
  104.   
  105.   aboutService: "bar",
  106.   callbackElementId: "",
  107.   extraProps: {},
  108.   
  109.   get dialogContent() {
  110.     return document.getElementsByTagNameNS("http://bar.yandex.ru/firefox", "dialogcontent").item(0);
  111.   },
  112.   
  113.   getAboutServiceCollapsedState: function() {
  114.     if (!this.aboutService)
  115.       return false;
  116.     
  117.     const prefName = "yasearch.general.ui.mybar.collapsed.services";
  118.     var prefValue = this.nsIYa.getCharPref(prefName) || "";
  119.     
  120.     return !!(prefValue.indexOf("|" + this.aboutService + "|") > -1);
  121.   },
  122.   
  123.   setAboutServiceCollapsedState: function(aState) {
  124.     if (!this.aboutService)
  125.       return;
  126.     
  127.     const prefName = "yasearch.general.ui.mybar.collapsed.services";
  128.     var prefValue = this.nsIYa.getCharPref(prefName) || "";
  129.     
  130.     var serviceFlag = "|" + this.aboutService + "|";
  131.     
  132.     prefValue = prefValue.replace(serviceFlag, "");
  133.     
  134.     if (aState)
  135.       prefValue += serviceFlag;
  136.     
  137.     this.nsIYa.setCharPref(prefName, prefValue);
  138.   },
  139.   
  140.   get usernameText() {
  141.     return (document.getElementById("yasearch-username").value || "").replace(/^\s\s*/, "").replace(/\s\s*$/, "");
  142.   },
  143.   
  144.   get passwordText() {
  145.     return (document.getElementById("yasearch-password").value || "").replace(/^\s\s*/, "").replace(/\s\s*$/, "");
  146.   },
  147.   
  148.   onDialogLoad: function() {
  149.     window.outerWidth = 3;
  150.     window.outerHeight = 3;
  151.     
  152.     window.moveTo(50000,50000);
  153.     
  154.     let AppInfo = this.nsIYa.AppInfo;
  155.     if (AppInfo.OS.isWindows && AppInfo.browser.isGreaterThenFx30) {
  156.       let shadowAttribute = document.createAttribute("yashadow");
  157.       shadowAttribute.value = "window";
  158.       document.documentElement.attributes.setNamedItem(shadowAttribute);
  159.     } else if (AppInfo.OS.isLinux) {
  160.       document.documentElement.attributes.removeNamedItem("yatransparent");
  161.     }
  162.     
  163.     new YaUtils.KeyCorrector(document.getElementById("yasearch-username"));
  164.     new YaUtils.KeyCorrector(document.getElementById("yasearch-password"));
  165.     
  166.     if ("arguments" in window && window.arguments.length) {
  167.       this.aboutService = window.arguments[0] || "bar";
  168.       this.callbackElementId = window.arguments[1] || "";
  169.       this.extraProps = window.arguments[2] || { view: "auth" };
  170.     }
  171.     
  172.     if (this.aboutService == "bookmarks")
  173.       this.aboutService = "zakladki";
  174.     
  175.     if (this.aboutService == "mfd")
  176.       this.aboutService = "pdd";
  177.     
  178.     document.getElementById("dialogcontent").setAttribute("yaServiceName", this.aboutService);
  179.     
  180.     let serviceXSLTParams = { serviceType: this.aboutService };
  181.     let serviceData = this.nsIYa.Counters.getServiceLocalizedXML(this.aboutService);
  182.     if (serviceData) {
  183.       let serviceDataURL = serviceData.url;
  184.       if (serviceDataURL)
  185.         serviceXSLTParams.serviceURL = serviceDataURL.toString();
  186.       
  187.       if ("@action" in serviceDataURL) {
  188.         var serviceDataAction = parseInt(serviceDataURL.@action, 10);
  189.         if (serviceDataAction)
  190.           serviceXSLTParams.serviceURLAction = serviceDataAction + 1;
  191.       }
  192.     }
  193.     
  194.     let filePath = "services/mybar/services.about.";
  195.     let aboutService = this.nsIYa.getDOMDocContent2(filePath + "xsl", filePath + "xml", serviceXSLTParams);
  196.     
  197.     if (aboutService) {
  198.       document.getElementById("tabbox-welcome").setAttribute("title", aboutService.getAttribute("serviceTitle"));
  199.       document.getElementById("about-service-holder").appendChild(aboutService);
  200.     }
  201.     
  202.     document.getElementById("yasearch-username").popup.addEventListener("mouseup", this, true);
  203.     document.getElementById("yasearch-username").popup.addEventListener("mousemove", this, true);
  204.     
  205.     if (this.extraProps.view == "auto") {
  206.       let username = this.yaAuth.username;
  207.       if (!username) {
  208.         let mfdAuthData = this.nsIYa.yaMFD.getTopAuth();
  209.         if (mfdAuthData)
  210.           username = mfdAuthData.boxname;
  211.       }
  212.  
  213.       this.loginProcessUsername = username || null;
  214.       
  215.       if (this.authType == "mfd")
  216.         document.getElementById("dialogcontent").setAttribute("yaServiceName", "mfd");
  217.     }
  218.     
  219.     this.handleLoginStateChanged();
  220.     
  221.     this.sizeToContent(true);
  222.     
  223.     this.observerService.addObserver(this, "Ya-Login-State-Changed", false);
  224.     this.observerService.addObserver(this, "Ya-Refresh-Data", false);
  225.   },
  226.   
  227.   onDialogUnload: function() {
  228.     this.observerService.removeObserver(this, "Ya-Refresh-Data");
  229.     this.observerService.removeObserver(this, "Ya-Login-State-Changed");
  230.     
  231.     document.getElementById("yasearch-username").popup.removeEventListener("mouseup", this, true);
  232.     document.getElementById("yasearch-username").popup.removeEventListener("mousemove", this, true);
  233.   },
  234.   
  235.   onDialogAccept: function() {
  236.     if (!this.usernameText ||
  237.         !document.getElementById("yasearch-password").value)
  238.       return false;
  239.     
  240.     this.loginProcessUsername = this.usernameText;
  241.     
  242.     var cookiesHostName = "yandex.ru";
  243.     var cookiesAllowed = this.yaAuth.Cookies.isCookiesAllowedForHost(cookiesHostName);
  244.     
  245.     if (!cookiesAllowed) {
  246.       var cookieBehaviorValue = cookiesAllowed === null ? -1 : this.nsIYa.getIntPref("network.cookie.cookieBehavior");
  247.         
  248.       var dialogTextAppend = "";
  249.       
  250.       switch (cookieBehaviorValue) {
  251.         case 1:
  252.           dialogTextAppend = " " + this.getLocalizedString("Cookies3PartyDisabledText");
  253.           break;
  254.         
  255.         case 2:
  256.           break;
  257.         
  258.         default:
  259.           cookieBehaviorValue = -1;
  260.           dialogTextAppend = " " + this.getLocalizedString("Cookies3PartyDisabledYandexText");
  261.           break;
  262.       }
  263.       
  264.       var dialogText = this.getLocalizedFormattedString("CookiesDisabledText", [dialogTextAppend]);
  265.       
  266.       var prompter = this.nsIYa.promptService;
  267.       var dummy = { value: false };
  268.       if (prompter.confirmEx(window,
  269.                              null,
  270.                              dialogText,
  271.                              prompter.STD_YES_NO_BUTTONS + prompter.BUTTON_POS_0_DEFAULT,
  272.                              null, null, null, null, dummy) == 1) {
  273.         return false;
  274.       }
  275.       
  276.       if (cookieBehaviorValue != -1)
  277.         this.nsIYa.setIntPref("network.cookie.cookieBehavior", 0);
  278.       
  279.       if (!this.yaAuth.Cookies.isCookiesAllowedForHost(cookiesHostName))
  280.         this.yaAuth.Cookies.allowCookiesForHost(cookiesHostName);
  281.     }
  282.     
  283.     if (!this.yaAuth.initLoginProcess(this.usernameText,
  284.                                       this.passwordText,
  285.                                       document.getElementById("yasearch-store-password").checked,
  286.                                       true)) {
  287.       this.cancelDialog();
  288.     }
  289.     
  290.     return false;
  291.   },
  292.   
  293.   toggleCollapsedView: function(aCollapsed) {
  294.     var tabpanel = document.getElementById("login-tabpanel");
  295.     var collapsed = typeof aCollapsed == "boolean" ? aCollapsed : !(tabpanel.getAttribute("collapsed") == "true");
  296.     
  297.     tabpanel.setAttribute("collapsed", collapsed);
  298.     
  299.     this.sizeToContent();
  300.     
  301.     this.setAboutServiceCollapsedState(collapsed);
  302.   },
  303.   
  304.   handleWindowClick: function(aEvent) {
  305.     var target = aEvent.originalTarget,
  306.         targetHref;
  307.     
  308.     while (target &&
  309.            "getAttribute" in target &&
  310.            !(targetHref = target.getAttribute("href") || target.getAttribute("yahref"))) {
  311.       target = target.parentNode;
  312.     }
  313.     
  314.     if (targetHref) {
  315.       targetHref = targetHref.replace(/\{user\}/g, this.yaAuth.username);
  316.       
  317.       var action = target.hasAttribute("yaLinkAction") ? target.getAttribute("yaLinkAction") : null;
  318.       
  319.       if (/\/mail\.yandex\.(ru|ua|kz|by)\/messages$/.test(targetHref) &&
  320.           this.nsIYa.getBoolPref("yasearch.mail.uri.open.new")) {
  321.         targetHref += "?extra_cond=only_new";
  322.       }
  323.       
  324.       this.nsIYa.loadURI(targetHref, "tab", (action ? {action:action} : null));
  325.       
  326.       this.cancelDialog();
  327.       
  328.       return false;
  329.     }
  330.     
  331.     return true;
  332.   },
  333.   
  334.   checkAcceptButton: function() {
  335.     let disabled = this.loginState >= this.LOGIN_STATES.REQUEST ||
  336.                    this.usernameText.length < 2 ||
  337.                    this.passwordText.length < 2;
  338.     
  339.     let acceptButton = document.documentElement.getButton("accept");
  340.     if (acceptButton.disabled !== disabled)
  341.       acceptButton.disabled = disabled;
  342.     
  343.     document.getElementById("login-button").disabled = disabled;
  344.   },
  345.   
  346.   handleLoginEntered: function() {
  347.     let pass = this.yaAuth.PasswordManager.getStoredPassword(this.usernameText);
  348.     document.getElementById("yasearch-password").value = pass;
  349.     document.getElementById("yasearch-store-password").checked = !!pass;
  350.     
  351.     this.checkAcceptButton();
  352.   },
  353.   
  354.   getLocalizedString: function(aName) {
  355.     return document.getElementById("yasearch-string-bundle-welcome").getString(aName);
  356.   },
  357.   
  358.   getLocalizedFormattedString: function(aName, aStrArray) {
  359.     return document.getElementById("yasearch-string-bundle-welcome").getFormattedString(aName, aStrArray, aStrArray.length);
  360.   },
  361.   
  362.   _getHoverCellHelper: function(aEvent) {
  363.     let row = {},
  364.         col = {},
  365.         obj = {};
  366.     
  367.     let docBoxObject = document.documentElement.boxObject;
  368.     let x = aEvent.screenX - docBoxObject.screenX;
  369.     let y = aEvent.screenY - docBoxObject.screenY;
  370.     
  371.     aEvent.originalTarget.parentNode.treeBoxObject.getCellAt(x, y, row, col, obj);
  372.     
  373.     return (row.value >= 0) ? { row: row.value, column: col.value.id } : null;
  374.   },
  375.   
  376.   handleEvent: function(aEvent) {
  377.     if (!aEvent.isTrusted)
  378.       return;
  379.     
  380.     switch (aEvent.type) {
  381.       case "mouseup":
  382.         var rc = this._getHoverCellHelper(aEvent);
  383.         if (rc) {
  384.           if (rc.column && rc.column == "treecolAutoCompleteComment") {
  385.             aEvent.stopPropagation();
  386.             
  387.             let login2remove = document.getElementById("yasearch-username").controller.getValueAt(rc.row);
  388.             let rv = this.nsIYa.promptService.confirm(window,
  389.                               this.getLocalizedString("LogginRemoveUserTitle"),
  390.                               this.getLocalizedFormattedString("LogginRemoveUserMessage", [login2remove]));
  391.             
  392.             if (rv) {
  393.               let password2remove = this.yaAuth.PasswordManager.getStoredPassword(login2remove);
  394.               this.yaAuth.PasswordManager.removeUserData(login2remove);
  395.               
  396.               if (this.usernameText == login2remove) {
  397.                 document.getElementById("yasearch-username").value = "";
  398.                 
  399.                 if (this.passwordText == password2remove)
  400.                   document.getElementById("yasearch-password").value = "";
  401.                 
  402.                 document.getElementById("yasearch-store-password").checked = false;
  403.               }
  404.               
  405.               this.refreshHasSavedLoginsMode();
  406.               this.checkAcceptButton();
  407.             }
  408.           }
  409.         }
  410.         break;
  411.       
  412.       case "mousemove":
  413.         var rc = null;
  414.         try {
  415.           rc = this._getHoverCellHelper(aEvent);
  416.         } catch(e) {}
  417.         
  418.         if (!rc)
  419.           return;
  420.         
  421.         let onCommentColumn = (rc.column && rc.column == "treecolAutoCompleteComment") ? true : false;
  422.         if (this.yaAuth.PasswordManager.onHoverTreeUglyHack != onCommentColumn) {
  423.           this.yaAuth.PasswordManager.onHoverTreeUglyHack = onCommentColumn;
  424.           document.getElementById("yasearch-username").popup.invalidate();
  425.         }
  426.         
  427.         break;
  428.     }
  429.   },
  430.   
  431.   observe: function(aSubject, aTopic, aState) {
  432.     if (aTopic == "Ya-Login-State-Changed") {
  433.       if (aState == this.loginProcessUsername)
  434.         this.handleLoginStateChanged(true);
  435.       
  436.       return;
  437.     }
  438.     
  439.     if (aTopic != "Ya-Refresh-Data")
  440.       return;
  441.     
  442.     switch (aState) {
  443.       case "allServices":
  444.         var xulList;
  445.         
  446.         if (this.authType == "mfd") {
  447.           xulList = this.nsIYa.Counters.getUserServicesXULForMFDUser(this.loginProcessUsername);
  448.         } else {
  449.           xulList = this.nsIYa.Counters.getUserServicesXUL();
  450.           document.getElementById("tabbox-services").busy = false;
  451.         }
  452.         
  453.         if (xulList)
  454.           this.nsIYa.DOMUtils.replaceChildNodes(xulList, document.getElementById("user-info-services-list"));
  455.         
  456.         this.sizeToContent();
  457.         
  458.         break;
  459.         
  460.       case "yaru-user-data":
  461.         if (this.authType == "mfd") {
  462.           document.getElementById("user-info-name").value = this.loginProcessUsername.split("@")[0];
  463.         } else {
  464.           var yaruData = this.nsIYa.Counters.getYaruUserData();
  465.  
  466.           var avatar = document.getElementById("user-info-avatar");
  467.           avatar.holder.setAttribute("yahref", "http://{user}.ya.ru/");
  468.           avatar.holder.setAttribute("yaLinkAction", "3470");
  469.           avatar.avatarSrc = yaruData ? yaruData.avatar.toString() + "middle" : "";
  470.  
  471.           document.getElementById("user-info-name").value = (yaruData ? yaruData.title.toString() : "") || this.yaAuth.username;
  472.           document.getElementById("user-info-status").value = yaruData ? yaruData.mood.toString() : "";
  473.         }
  474.         
  475.         break;
  476.     }
  477.   },
  478.   
  479.   handleLoginStateChanged: function(aFromObserver) {
  480.     let connectionStatus = 0;
  481.     let lastStateIsRequest = document.getElementById("yasearch-connection-status").selectedIndex == 1;
  482.     
  483.     if (this.loginState == this.LOGIN_STATES.AUTH) {
  484.       if (lastStateIsRequest) {
  485.         if (this.callbackElementId && (this.callbackElementId == "yasearch-mail-button" || this.authType != "mfd")) {
  486.           let browser = this.nsIYa.getWindow("navigator:browser");
  487.           if (browser && browser.Ya) {
  488.             let elementToCall = browser.document.getElementById(this.callbackElementId);
  489.             if (elementToCall && "doCommand" in elementToCall) {
  490.               let clbckFn = elementToCall.id === "yasearch-bookmarks-button" ?
  491.                                 function() { browser.Ya.loadURI("zakladki.yandex.ru"); } :
  492.                                 function() { elementToCall.doCommand(); };
  493.               
  494.               new this.nsIYa.utils.G_Timer(clbckFn, 1000);
  495.             }
  496.           }
  497.         }
  498.         
  499.         this.cancelDialog();
  500.         return;
  501.       }
  502.       
  503.       this.showUserPage();
  504.       
  505.     } else {
  506.       switch (this.loginState) {
  507.         case this.LOGIN_STATES.NO_AUTH:
  508.           if (this._exitAfterLogout) {
  509.             document.documentElement.cancelDialog();
  510.             return;
  511.           }
  512.           
  513.           break;
  514.         
  515.         case this.LOGIN_STATES.REQUEST:
  516.           connectionStatus = 1;
  517.           break;
  518.         
  519.         case this.LOGIN_STATES.NET_ERROR:
  520.           connectionStatus = lastStateIsRequest ? 3 : 0;
  521.           break;
  522.         
  523.         case this.LOGIN_STATES.CAPTCHA_ERROR:
  524.           if (lastStateIsRequest) {
  525.             let prompter = this.nsIYa.promptService;
  526.             
  527.             let flags = prompter.BUTTON_POS_0 * prompter.BUTTON_TITLE_IS_STRING +
  528.                         prompter.BUTTON_POS_1 * prompter.BUTTON_TITLE_IS_STRING +
  529.                         prompter.BUTTON_POS_0_DEFAULT;
  530.             
  531.             let rv = prompter.confirmEx(window,
  532.                                         this.getLocalizedString("CaptchaDialogTitle"),
  533.                                         this.getLocalizedString("CaptchaDialogMsg"),
  534.                                         flags,
  535.                                         this.getLocalizedString("CaptchaDialogButtonOK"),
  536.                                         this.getLocalizedString("CaptchaDialogButtonCancel"),
  537.                                         null, null, {});
  538.             
  539.             if (rv !== 1) {
  540.               this.nsIYa.loadURI("https://passport.yandex.ru", "tab");
  541.               this.cancelDialog();
  542.               return;
  543.             }
  544.           }
  545.           
  546.         default:
  547.           if (lastStateIsRequest)
  548.             connectionStatus = 2;
  549.           break;
  550.       }
  551.       
  552.       if (lastStateIsRequest && this.yaAuth.loginFail)
  553.         connectionStatus = 4;
  554.       
  555.       this.showAuthPage();
  556.     }
  557.     
  558.     this.setConnectionStatus(connectionStatus);
  559.     
  560.     let controlsDisabled = (this.loginState >= this.LOGIN_STATES.REQUEST);
  561.     ["yasearch-username", "yasearch-password", "yasearch-store-password"]
  562.     .forEach(function(aControlId) {
  563.       document.getElementById(aControlId).disabled = controlsDisabled;
  564.     });
  565.     
  566.     if (!controlsDisabled) {
  567.       let passTextbox = document.getElementById("yasearch-password");
  568.       if (document.commandDispatcher.focusedElement == passTextbox.inputField) {
  569.         passTextbox.blur();
  570.         passTextbox.focus();
  571.       }
  572.     }
  573.   },
  574.   
  575.   setConnectionStatus: function(aStatusIndex) {
  576.     document.getElementById("yasearch-connection-status").selectedIndex = aStatusIndex;
  577.     this.sizeToContent();
  578.   },
  579.   
  580.   refreshHasSavedLoginsMode: function() {
  581.     document.getElementById("yasearch-username")
  582.             .setAttribute("yaHasSavedLogins", this.yaAuth.PasswordManager.hasSavedLogins);
  583.   },
  584.   
  585.   switchUser: function() {
  586.     this.extraProps.view == "auth";
  587.     
  588.     this.loginProcessUsername = null;
  589.     
  590.     document.getElementById("yasearch-username").value = "";
  591.     document.getElementById("yasearch-password").value = "";
  592.     
  593.     document.getElementById("yasearch-connection-status").selectedIndex = 0;
  594.     
  595.     this.handleLoginStateChanged();
  596.     
  597.     this.sizeToContent();
  598.   },
  599.   
  600.   showAuthPage: function() {
  601.     this.dialogContent.selectedIndex = 0;
  602.     
  603.     this.refreshHasSavedLoginsMode();
  604.     
  605.     if (this.usernameText == "") {
  606.       let username = this.nsIYa.getCharPref("yasearch.users.default");
  607.       if (username) {
  608.         let password = this.yaAuth.PasswordManager.getStoredPassword(username);
  609.         if (password) {
  610.           document.getElementById("yasearch-username").value = username;
  611.           document.getElementById("yasearch-password").value = password;
  612.         }
  613.         
  614.         document.getElementById("yasearch-store-password").checked = !!password;
  615.       }
  616.     }
  617.     
  618.     this.checkAcceptButton();
  619.   },
  620.   
  621.   showUserPage: function() {
  622.     document.getElementById("user-info-avatar").removeAttribute("yahref");
  623.     
  624.     this.observe(null, "Ya-Refresh-Data", "allServices");
  625.     this.observe(null, "Ya-Refresh-Data", "yaru-user-data");
  626.     
  627.     this.dialogContent.selectedIndex = 1;
  628.     
  629.     if (this.authType != "mfd") {
  630.       document.getElementById("tabbox-services").busy = true;
  631.       this.nsIYa.refreshHTTPData("allServices");
  632.       this.nsIYa.Counters.refreshYaRuUserData();
  633.     }
  634.   },
  635.   
  636.   _exitAfterLogout: false,
  637.   
  638.   logout: function(aExitAfterLogout) {
  639.     const NOPROMPT_PREF_NAME = "yasearch.general.ui.mybar.logout.noprompt";
  640.     
  641.     let forgetMe = { value: false };
  642.     let noprompt = this.nsIYa.getBoolPref(NOPROMPT_PREF_NAME);
  643.     
  644.     if (!noprompt) {
  645.       let savedPass = !!(this.yaAuth.PasswordManager.getStoredPassword(this.loginProcessUsername));
  646.       
  647.       let prompts = this.nsIYa.promptService;
  648.       let buttonFlags = prompts.BUTTON_POS_0 * prompts.BUTTON_TITLE_IS_STRING +
  649.                         prompts.BUTTON_POS_1 * prompts.BUTTON_TITLE_IS_STRING +
  650.                         prompts.BUTTON_POS_2 * prompts.BUTTON_TITLE_IS_STRING +
  651.                         prompts.BUTTON_POS_0_DEFAULT;
  652.       
  653.       let answerBtnIndex = prompts.confirmEx(null,
  654.                                              this.getLocalizedString("logOutTitle"),
  655.                                              this.getLocalizedString("logOutConfirm"),
  656.                                              buttonFlags,
  657.                                              this.getLocalizedString("logOutYesPrompt"),
  658.                                              this.getLocalizedString("logOutNoPrompt"),
  659.                                              this.getLocalizedString("logOutNoAlwaysPrompt"),
  660.                                              savedPass ? this.getLocalizedString("logOutForgetPass") : null,
  661.                                              forgetMe);
  662.       
  663.       switch (answerBtnIndex) {
  664.         case 0:
  665.           break;
  666.         
  667.         case 1:
  668.           return;
  669.         
  670.         case 2:
  671.           this.nsIYa.setBoolPref(NOPROMPT_PREF_NAME, true);
  672.           break;
  673.       }
  674.     }
  675.     
  676.     this._exitAfterLogout = aExitAfterLogout;
  677.     
  678.     this.yaAuth.dropAuth(this.loginProcessUsername, true, forgetMe.value);
  679.     
  680.     if (aExitAfterLogout)
  681.       this.cancelDialog();
  682.   },
  683.   
  684.   onNewLoginClick: function(aEvent) {
  685.     let url = "http://passport.yandex.ru/passport?mode=register";
  686.     
  687.     let clid4 = this.nsIYa.vendorData.clid4 || "";
  688.     
  689.     url += "&clid=" + clid4 +
  690.            "&retpath=http%3A%2F%2Fclck.yandex.ru%2Fredir%2Fdtype%3Dstred%2Fpid%3D12%2Fcid%3D1737%2Fpath%3D" +
  691.            clid4 + "%2F*";
  692.     
  693.     let serviceURL = "http://i.yandex.ru"
  694.     let serviceData = this.nsIYa.Counters.getServiceLocalizedXML(this.aboutService);
  695.     
  696.     if (serviceData) {
  697.       let afterRegURL = serviceData.afterregistration.toString() || serviceData.url.toString();
  698.       if (afterRegURL)
  699.         serviceURL = afterRegURL;
  700.     }
  701.     
  702.     url += encodeURIComponent(serviceURL);
  703.     
  704.     this.onpenerYa.loadURI(url, aEvent, {action:3100});
  705.     this.cancelDialog();
  706.   }
  707. }
  708.