📄 mocojoey.js.svn-base
字号:
/* ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1/GPL 2.0/LGPL 2.1 * * The contents of this file are subject to the Mozilla Public License Version * 1.1 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * * The Original Code is Joey Mozilla Project. * * The Initial Developer of the Original Code is * Doug Turner <dougt@meer.net>. * Portions created by the Initial Developer are Copyright (C) 2007 * the Initial Developer. All Rights Reserved. * * Contributor(s): * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), * in which case the provisions of the GPL or the LGPL are applicable instead * of those above. If you wish to allow use of your version of this file only * under the terms of either the GPL or the LGPL, and not to allow others to * use your version of this file under the terms of the MPL, indicate your * decision by deleting the provisions above and replace them with the notice * and other provisions required by the GPL or the LGPL. If you do not delete * the provisions above, a recipient may use your version of this file under * the terms of any one of the MPL, the GPL or the LGPL. * * ***** END LICENSE BLOCK ***** */var moco_joey_url = "https://joey.labs.mozilla.com";var g_joey_hasLogged = false;var g_joey_in_progress = false;function getJoeyURL(){ var psvc = Components.classes["@mozilla.org/preferences-service;1"] .getService(Components.interfaces.nsIPrefBranch); var url = moco_joey_url; if (psvc.prefHasUserValue("joey.service_url")) url = psvc.getCharPref("joey.service_url"); return url;}function debug(str){ var console = Components.classes["@mozilla.org/consoleservice;1"] .getService(Components.interfaces.nsIConsoleService); console.logStringMessage("Joey!: "+ str);}function JoeyStreamListener(self, aCallbackFunc, aListener){ this.mOwner = self; this.mCallbackFunc = aCallbackFunc;}JoeyStreamListener.prototype = { mBytes: [], mStream: null, mCount: 0, mOwner: null, // nsIStreamListener onStartRequest: function (aRequest, aContext) { this.mStream = Components.classes["@mozilla.org/scriptableinputstream;1"] .createInstance(Components.interfaces.nsIScriptableInputStream); }, onDataAvailable: function (aRequest, aContext, aStream, aSourceOffset, aCount) { this.mStream.init(aStream); this.mBytes += this.mStream.read(aCount); this.mCountRead += aCount; }, onStopRequest: function (aRequest, aContext, aStatus) { var joeyResponse = -1; try { var httpChannel = aRequest.QueryInterface(Components.interfaces.nsIHttpChannel); joeyResponse = httpChannel.getResponseHeader("X-joey-status"); } catch (e) {} this.mCallbackFunc(this.mOwner, joeyResponse, this.mBytes); }, // nsIChannelEventSink onChannelRedirect: function (aOldChannel, aNewChannel, aFlags) { }, // nsIInterfaceRequestor getInterface: function (aIID) { try { return this.QueryInterface(aIID); } catch(ex) {} }, // nsIProgressEventSink onProgress : function (aRequest, aContext, aProgress, aProgressMax) { if (this.mOwner != null && this.mOwner.joey_listener != null) this.mOwner.joey_listener.onProgressChange(aProgress, aProgressMax); }, onStatus : function (aRequest, aContext, aStatus, aStatusArg) { }, // nsIHttpEventSink (not implementing will cause annoying exceptions) onRedirect : function (aOldChannel, aNewChannel) { }, QueryInterface : function(aIID) { if (aIID.equals(Components.interfaces.nsISupports) || aIID.equals(Components.interfaces.nsIInterfaceRequestor) || aIID.equals(Components.interfaces.nsIChannelEventSink) || aIID.equals(Components.interfaces.nsIProgressEventSink) || aIID.equals(Components.interfaces.nsIHttpEventSink) || aIID.equals(Components.interfaces.nsIStreamListener)) return this; throw Components.results.NS_NOINTERFACE; }};function mocoJoey(){ this._init(); }mocoJoey.prototype = { joey_listener: null, joey_username: "", joey_password: "", joey_data: "", joey_content_type: "", joey_title: "", joey_url: "", xmlhttp: null, setLoginInfo: function() { this.joey_username = ""; this.joey_password = ""; var passwordManager = Components.classes["@mozilla.org/passwordmanager;1"] .getService(Components.interfaces.nsIPasswordManager); var e = passwordManager.enumerator; while (e.hasMoreElements()) { try { var pass = e.getNext().QueryInterface(Components.interfaces.nsIPassword); if (pass.host == getJoeyURL()) { this.joey_username = pass.user; this.joey_password = pass.password; return true; } } catch (ex) {} } /* We get the strings from the locale properties file */ var stringBundle = Components.classes["@mozilla.org/intl/stringbundle;1"] .getService(Components.interfaces.nsIStringBundleService); var joeyStrings = stringBundle.createBundle("chrome://joey/locale/joey.properties"); var promptTitle = joeyStrings.GetStringFromName("promptUserPass.windowtitle"); var promptQuestion = joeyStrings.GetStringFromName("promptUserPass.question"); var promptButton = joeyStrings.GetStringFromName("promptUserPass.button"); /* All good, render the prompt with right strings.. */ var prompts = Components.classes["@mozilla.org/embedcomp/prompt-service;1"] .getService(Components.interfaces.nsIPromptService); var u = {value: ""}; // default the username to user var p = {value: ""}; // default the password to pass var check = {value: true}; // default the checkbox to true var result = prompts.promptUsernameAndPassword(null, promptTitle, promptQuestion, u, p, promptButton, check); if (!result) { // cancel was pressed. return false; } // result is true if OK was pressed, false if cancel was pressed. username.value, // password.value, and check.value are set if OK was pressed. if (check.value) passwordManager.addUser(getJoeyURL(), u.value, u.value); this.joey_username = u.value; this.joey_password = p.value; return true; }, uploadData: function(title, url, data, type) { this.joey_isfile = false; this.uploadDataInternal( title, url, data, type); }, uploadFile: function(title, url, file, type) { this.joey_isfile = true; this.uploadDataInternal( title, url, file, type); }, uploadDataInternal: function(title, url, data, type) { if (g_joey_in_progress == true) return -1; g_joey_in_progress = true; this.joey_title = title; this.joey_url = url; this.joey_content_type = type; this.joey_data = data; // kick off the action if (g_joey_hasLogged == false) { if (this.setLoginInfo() == false) { g_joey_in_progress = false; this.joey_title = null; this.joey_url = null; this.joey_content_type = null; this.joey_data = null; return -1; } this.loginToService(); } else this.uploadDataFromGlobals(); }, setListener: function(listener) { this.joey_listener = listener; }, _init: function() { const osvr = Components.classes['@mozilla.org/observer-service;1'] .getService(Components.interfaces.nsIObserverService);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -