Index: lib/utils.js |
=================================================================== |
--- a/lib/utils.js |
+++ b/lib/utils.js |
@@ -84,48 +84,48 @@ let Utils = exports.Utils = |
{ |
let platformVersion = Services.appinfo.platformVersion; |
Utils.__defineGetter__("platformVersion", function() platformVersion); |
return Utils.platformVersion; |
}, |
/** |
* Retrieves a string from global.properties string bundle, will throw if string isn't found. |
- * |
+ * |
* @param {String} name string name |
* @return {String} |
*/ |
getString: function(name) |
{ |
// Randomize URI to work around bug 719376 |
let stringBundle = Services.strings.createBundle("chrome://adblockplus/locale/global.properties?" + Math.random()); |
Utils.getString = function(name) |
{ |
return stringBundle.GetStringFromName(name); |
} |
return Utils.getString(name); |
}, |
/** |
* Shows an alert message like window.alert() but with a custom title. |
- * |
+ * |
* @param {Window} parentWindow parent window of the dialog (can be null) |
* @param {String} message message to be displayed |
* @param {String} [title] dialog title, default title will be used if omitted |
*/ |
alert: function(parentWindow, message, title) |
{ |
if (!title) |
title = Utils.getString("default_dialog_title"); |
Utils.promptService.alert(parentWindow, title, message); |
}, |
/** |
* Asks the user for a confirmation like window.confirm() but with a custom title. |
- * |
+ * |
* @param {Window} parentWindow parent window of the dialog (can be null) |
* @param {String} message message to be displayed |
* @param {String} [title] dialog title, default title will be used if omitted |
* @return {Bool} |
*/ |
confirm: function(parentWindow, message, title) |
{ |
if (!title) |
@@ -136,20 +136,20 @@ let Utils = exports.Utils = |
/** |
* Retrieves the window for a document node. |
* @return {Window} will be null if the node isn't associated with a window |
*/ |
getWindow: function(/**Node*/ node) |
{ |
if ("ownerDocument" in node && node.ownerDocument) |
node = node.ownerDocument; |
- |
+ |
if ("defaultView" in node) |
return node.defaultView; |
- |
+ |
return null; |
}, |
/** |
* Retrieves the top-level chrome window for a content window. |
*/ |
getChromeWindow: function(/**Window*/ window) /**Window*/ |
{ |
@@ -233,17 +233,17 @@ let Utils = exports.Utils = |
*/ |
getRequestWindow: function(/**nsIChannel*/ channel) /**nsIDOMWindow*/ |
{ |
try |
{ |
if (channel.notificationCallbacks) |
return channel.notificationCallbacks.getInterface(Ci.nsILoadContext).associatedWindow; |
} catch(e) {} |
- |
+ |
try |
{ |
if (channel.loadGroup && channel.loadGroup.notificationCallbacks) |
return channel.loadGroup.notificationCallbacks.getInterface(Ci.nsILoadContext).associatedWindow; |
} catch(e) {} |
return null; |
}, |
@@ -256,21 +256,21 @@ let Utils = exports.Utils = |
*/ |
generateChecksum: function(lines) |
{ |
let stream = null; |
try |
{ |
// Checksum is an MD5 checksum (base64-encoded without the trailing "=") of |
// all lines in UTF-8 without the checksum line, joined with "\n". |
- |
+ |
let converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"].createInstance(Ci.nsIScriptableUnicodeConverter); |
converter.charset = "UTF-8"; |
stream = converter.convertToInputStream(lines.join("\n")); |
- |
+ |
let hashEngine = Cc["@mozilla.org/security/hash;1"].createInstance(Ci.nsICryptoHash); |
hashEngine.init(hashEngine.MD5); |
hashEngine.updateFromStream(stream, stream.available()); |
return hashEngine.finish(true).replace(/=+$/, ""); |
} |
catch (e) |
{ |
return null; |
@@ -548,17 +548,28 @@ XPCOMUtils.defineLazyServiceGetter(Utils |
XPCOMUtils.defineLazyServiceGetter(Utils, "clipboard", "@mozilla.org/widget/clipboard;1", "nsIClipboard"); |
XPCOMUtils.defineLazyServiceGetter(Utils, "clipboardHelper", "@mozilla.org/widget/clipboardhelper;1", "nsIClipboardHelper"); |
XPCOMUtils.defineLazyGetter(Utils, "crypto", function() |
{ |
try |
{ |
let ctypes = Components.utils.import("resource://gre/modules/ctypes.jsm", null).ctypes; |
- let nsslib = ctypes.open(ctypes.libraryName("nss3")); |
+ let nsslib; |
+ try |
+ { |
+ nsslib = ctypes.open(ctypes.libraryName("nss3")); |
+ } |
+ catch (e) |
+ { |
+ // It seems that on Mac OS X the full path name needs to be specified |
+ let file = Services.dirsvc.get("GreD", Ci.nsILocalFile); |
+ file.append(ctypes.libraryName("nss3")); |
+ nsslib = ctypes.open(file.path); |
+ } |
let result = {}; |
// seccomon.h |
result.siUTF8String = 14; |
// secoidt.h |
result.SEC_OID_ISO_SHA_WITH_RSA_SIGNATURE = 15; |