Changeset 618
- Timestamp:
- 01/19/08 10:01:21 (11 months ago)
- Files:
-
- branches/aa2/src/chrome/chromeFiles/content/browser.js (modified) (4 diffs)
- branches/aa2/src/chrome/chromeFiles/content/menucommander.js (modified) (1 diff)
- branches/aa2/src/chrome/chromeFiles/content/miscapis.js (modified) (4 diffs)
- branches/aa2/src/chrome/chromeFiles/content/prefmanager.js (modified) (2 diffs)
- branches/aa2/src/chrome/chromeFiles/content/scriptdownloader.js (modified) (4 diffs)
- branches/aa2/src/chrome/chromeFiles/content/utils.js (modified) (3 diffs)
- branches/aa2/src/chrome/chromeFiles/content/xmlhttprequester.js (modified) (1 diff)
- branches/aa2/src/components/greasemonkey.js (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/aa2/src/chrome/chromeFiles/content/browser.js
r548 r618 124 124 */ 125 125 GM_BrowserUI.contentLoad = function(e) { 126 var safeWin; 126 127 var unsafeWin; 127 128 var href; … … 132 133 } 133 134 134 unsafeWin = e.target.defaultView.wrappedJSObject; 135 href = e.target.location.href; 135 safeWin = e.target.defaultView; 136 unsafeWin = safeWin.wrappedJSObject; 137 href = safeWin.location.href; 136 138 137 139 if (GM_isGreasemonkeyable(href)) { … … 149 151 } 150 152 151 if (!href.match(/\.user\.js$/)) { 152 return; 153 } 154 155 var browser = this.tabBrowser.getBrowserForDocument(e.target); 153 // Show the greasemonkey install banner if we are navigating to a .user.js 154 // file in a top-level tab. 155 if (href.match(/\.user\.js$/) && safeWin == safeWin.top) { 156 var browser = this.tabBrowser.getBrowserForDocument(safeWin.document); 157 this.showInstallBanner(browser); 158 } 159 }; 160 161 162 /** 163 * Shows the install banner across the top of the tab that is displayed when 164 * a user selects "show script source" in the install dialog. 165 */ 166 GM_BrowserUI.showInstallBanner = function(browser) { 156 167 var greeting = this.bundle.getString("greeting.msg"); 157 168 … … 565 576 }; 566 577 578 GM_BrowserUI.hideStatusImmediately = function() { 579 if (this.showAnimation) { 580 this.showAnimation.stop(); 581 this.showAnimation = null; 582 } 583 584 if (this.hideAnimation) { 585 this.hideAnimation.stop(); 586 this.hideAnimation = null; 587 } 588 589 if (this.autoHideTimer) { 590 window.clearTimeout(this.autoHideTimer); 591 this.autoHideTimer = null; 592 } 593 594 this.statusLabel.style.width = "0"; 595 this.statusLabel.collapsed = true; 596 }; 597 567 598 GM_BrowserUI.hideStatus = function() { 568 599 if (!this.hideAnimation) { branches/aa2/src/chrome/chromeFiles/content/menucommander.js
r548 r618 20 20 GM_MenuCommander.prototype.registerMenuCommand = 21 21 function(commandName, commandFunc, accelKey, accelModifiers, accessKey) { 22 GM_apiLeakCheck(); 23 22 24 GM_log("> GM_MenuCommander.registerMenuCommand"); 23 25 branches/aa2/src/chrome/chromeFiles/content/miscapis.js
r548 r618 8 8 9 9 GM_ScriptStorage.prototype.setValue = function(name, val) { 10 GM_apiLeakCheck(); 11 10 12 this.prefMan.setValue(name, val); 11 13 }; 12 14 13 15 GM_ScriptStorage.prototype.getValue = function(name, defVal) { 16 GM_apiLeakCheck(); 17 14 18 return this.prefMan.getValue(name, defVal); 15 19 }; … … 20 24 21 25 GM_Resources.prototype.getResourceURL = function(name) { 26 GM_apiLeakCheck(); 27 22 28 var dep = this.getDep_(name); 23 29 … … 40 46 41 47 GM_Resources.prototype.getResourceText = function(name) { 48 GM_apiLeakCheck(); 49 42 50 var dep = this.getDep_(name); 43 51 return getContents(getDependencyFileURI(this.script, dep)); … … 65 73 66 74 GM_ScriptLogger.prototype.log = function(message) { 75 GM_apiLeakCheck(); 76 67 77 GM_log(this.prefix + message, true); 68 78 }; branches/aa2/src/chrome/chromeFiles/content/prefmanager.js
r548 r618 1 1 var GM_prefRoot = new GM_PrefManager(); 2 3 GM_PrefManager.MIN_INT_32 = -0x80000000; 4 GM_PrefManager.MAX_INT_32 = 0x7FFFFFFF; 2 5 3 6 /** … … 59 62 this.setValue = function(prefName, value) { 60 63 var prefType = typeof(value); 64 var goodType = false; 61 65 62 66 switch (prefType) { 63 67 case "string": 64 68 case "boolean": 69 goodType = true; 65 70 break; 66 71 case "number": 67 if (value % 1 != 0) { 68 // NOTE: Non localised strings 69 throw new Error("Cannot set preference to non integral number"); 72 if (value % 1 == 0 && 73 value >= GM_PrefManager.MIN_INT_32 && 74 value <= GM_PrefManager.MAX_INT_32) { 75 goodType = true; 70 76 } 71 77 break; 72 default: 73 throw new Error("Cannot set preference with datatype: " + prefType); 78 } 79 80 if (!goodType) { 81 throw new Error("Unsupported type for GM_setValue. Supported types " + 82 "are: string, bool, and 32 bit integers."); 74 83 } 75 84 branches/aa2/src/chrome/chromeFiles/content/scriptdownloader.js
r548 r618 38 38 39 39 ScriptDownloader.prototype.handleScriptDownloadComplete = function() { 40 this.win_.GM_BrowserUI.refreshStatus(); 41 this.win_.GM_BrowserUI.hideStatusImmediately(); 42 40 43 try { 41 44 // If loading from file, status might be zero on success 42 45 if (this.req_.status != 200 && this.req_.status != 0) { 43 this.win_.GM_BrowserUI.refreshStatus();44 this.win_.GM_BrowserUI.hideStatus();45 46 46 // NOTE: Unlocalized string 47 47 alert('Error loading user script:\n' + … … 84 84 // NOTE: unlocalized string 85 85 alert("Script could not be installed " + e); 86 this.win_.GM_BrowserUI.refreshStatus();87 this.win_.GM_BrowserUI.hideStatus();88 86 throw e; 89 87 } … … 219 217 return; 220 218 } 221 this.win_.GM_BrowserUI.hideStatus();222 this.win_.GM_BrowserUI.refreshStatus();223 219 this.win_.openDialog("chrome://greasemonkey/content/install.xul", "", 224 220 "chrome,centerscreen,modal,dialog,titlebar,resizable", … … 227 223 228 224 ScriptDownloader.prototype.showScriptView = function() { 229 this.win_.GM_BrowserUI.hideStatus();230 this.win_.GM_BrowserUI.refreshStatus();231 225 this.win_.GM_BrowserUI.showScriptView(this); 232 226 }; branches/aa2/src/chrome/chromeFiles/content/utils.js
r548 r618 6 6 var GM_consoleService = Components.classes["@mozilla.org/consoleservice;1"] 7 7 .getService(Components.interfaces.nsIConsoleService); 8 9 function GM_apiLeakCheck() { 10 var stack = Components.stack; 11 12 do { 13 if (2 == stack.language) { 14 if ('file' != stack.filename.substr(0, 4) && 15 'chrome' != stack.filename.substr(0, 6)) { 16 throw new Error("Greasemonkey access violation"); 17 } 18 } 19 20 stack = stack.caller; 21 } while (stack); 22 }; 8 23 9 24 function GM_isDef(thing) { … … 74 89 75 90 function openInEditor(aFile, promptTitle) { 76 var editor, editorPath; 91 var editor = getEditor(promptTitle); 92 if (!editor) { 93 // The user did not choose an editor. 94 return; 95 } 96 77 97 try { 78 editorPath = GM_prefRoot.getValue("editor"); 79 } catch(e) { 80 GM_log( "Failed to get 'editor' value:" + e ); 81 if (GM_prefRoot.exists("editor")) { 82 GM_log("A value for 'editor' exists, so let's remove it because it's causing problems"); 83 GM_prefRoot.remove("editor"); 84 } 85 editorPath = false; 86 } 98 launchApplicationWithDoc(editor, aFile); 99 } catch (e) { 100 // Something may be wrong with the editor the user selected. Remove so that 101 // next time they can pick a different one. 102 alert("Could not launch editor:\n" + e); 103 GM_prefRoot.remove("editor"); 104 throw e; 105 } 106 } 107 108 function getEditor(promptTitle) { 109 var editorPath = GM_prefRoot.getValue("editor"); 110 87 111 if (editorPath) { 88 // check whether the editor path is valid89 GM_log("Try editor with path " + editorPath); 90 editor = Components.classes["@mozilla.org/file/local;1"]91 .createInstance(Components.interfaces.nsILocalFile);112 GM_log("Found saved editor preference: " + editorPath); 113 114 var editor = Components.classes["@mozilla.org/file/local;1"] 115 .createInstance(Components.interfaces.nsILocalFile); 92 116 editor.followLinks = true; 93 117 editor.initWithPath(editorPath); 94 } else { 118 119 // make sure the editor preference is still valid 120 if (editor.exists() && editor.isExecutable()) { 121 return editor; 122 } else { 123 GM_log("Editor preference either does not exist or is not executable"); 124 GM_prefRoot.remove("editor"); 125 } 126 } 127 128 // Ask the user to choose a new editor. Sometimes users get confused and 129 // pick a non-executable file, so we set this up in a loop so that if they do 130 // that we can give them an error and try again. 131 while (true) { 132 GM_log("Asking user to choose editor..."); 95 133 var nsIFilePicker = Components.interfaces.nsIFilePicker; 96 134 var filePicker = Components.classes["@mozilla.org/filepicker;1"] … … 102 140 103 141 if (filePicker.show() != nsIFilePicker.returnOK) { 104 return false; 105 } 106 editor = filePicker.file; 107 GM_log("User selected: " + editor.path); 108 GM_prefRoot.setValue("editor", editor.path); 109 } 110 111 if (editor.exists() && editor.isExecutable()) { 112 try { 113 GM_log("launching ..."); 114 115 var process = Components.classes["@mozilla.org/process/util;1"] 116 .getService(Components.interfaces.nsIProcess); 117 process.init(editor); 118 process.run(false, // non-blocking 119 [aFile.path], 120 1); // number of arguments in second param 121 return true; 122 } catch (e) { 123 GM_log("Failed to launch editor: " + e, true); 124 } 142 // The user canceled, return null. 143 GM_log("User canceled file picker dialog"); 144 return null; 145 } 146 147 GM_log("User selected: " + filePicker.file.path); 148 149 if (filePicker.file.exists() && filePicker.file.isExecutable()) { 150 GM_prefRoot.setValue("editor", filePicker.file.path); 151 return filePicker.file; 152 } else { 153 // TODO: i18n 154 alert("Please pick an executable application to use to edit user " + 155 "scripts."); 156 } 157 } 158 } 159 160 function launchApplicationWithDoc(appFile, docFile) { 161 var xulRuntime = Components.classes["@mozilla.org/xre/app-info;1"] 162 .getService(Components.interfaces.nsIXULRuntime); 163 // See Mozilla bug: https://bugzilla.mozilla.org/show_bug.cgi?id=411819 164 // TODO: remove this when nsIMIMEInfo works on windows again. 165 if (xulRuntime.OS.toLowerCase().substring(0, 3) == "win") { 166 var process = Components.classes["@mozilla.org/process/util;1"] 167 .createInstance(Components.interfaces.nsIProcess); 168 process.init(appFile); 169 process.run(false, // blocking 170 [docFile.path], // args 171 1); // number of args 125 172 } else { 126 GM_log("Editor '" + editorPath + "' does not exist or isn't executable. " + 127 "Put it back, check the permissions, or just give up and reset " + 128 "editor using about:config", true); 129 } 130 return false; 131 }; 173 var mimeInfoService = 174 Components.classes["@mozilla.org/uriloader/external-helper-app-service;1"] 175 .getService(Components.interfaces.nsIMIMEService); 176 var mimeInfo = mimeInfoService.getFromTypeAndExtension( 177 "application/x-userscript+javascript", "user.js" ); 178 mimeInfo.preferredAction = mimeInfo.useHelperApp; 179 mimeInfo.preferredApplicationHandler = appFile; 180 mimeInfo.launchWithFile(docFile); 181 } 182 } 132 183 133 184 function parseScriptName(sourceUri) { branches/aa2/src/chrome/chromeFiles/content/xmlhttprequester.js
r590 r618 13 13 // text/xml and we can't support that 14 14 GM_xmlhttpRequester.prototype.contentStartRequest = function(details) { 15 GM_apiLeakCheck(); 16 15 17 // don't actually need the timer functionality, but this pops it 16 18 // out into chromeWindow's thread so that we get that security branches/aa2/src/components/greasemonkey.js
r548 r618 313 313 314 314 openInTab: function(unsafeContentWin, url) { 315 GM_apiLeakCheck(); 316 315 317 var unsafeTop = new XPCNativeWrapper(unsafeContentWin, "top").top; 316 318
