| OLD | NEW |
| 1 /* | 1 /* |
| 2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2013 Eyeo GmbH | 3 * Copyright (C) 2006-2013 Eyeo GmbH |
| 4 * | 4 * |
| 5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
| 6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
| 7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
| 8 * | 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 */ | 82 */ |
| 83 get platformVersion() | 83 get platformVersion() |
| 84 { | 84 { |
| 85 let platformVersion = Services.appinfo.platformVersion; | 85 let platformVersion = Services.appinfo.platformVersion; |
| 86 Utils.__defineGetter__("platformVersion", function() platformVersion); | 86 Utils.__defineGetter__("platformVersion", function() platformVersion); |
| 87 return Utils.platformVersion; | 87 return Utils.platformVersion; |
| 88 }, | 88 }, |
| 89 | 89 |
| 90 /** | 90 /** |
| 91 * Retrieves a string from global.properties string bundle, will throw if stri
ng isn't found. | 91 * Retrieves a string from global.properties string bundle, will throw if stri
ng isn't found. |
| 92 * | 92 * |
| 93 * @param {String} name string name | 93 * @param {String} name string name |
| 94 * @return {String} | 94 * @return {String} |
| 95 */ | 95 */ |
| 96 getString: function(name) | 96 getString: function(name) |
| 97 { | 97 { |
| 98 // Randomize URI to work around bug 719376 | 98 // Randomize URI to work around bug 719376 |
| 99 let stringBundle = Services.strings.createBundle("chrome://adblockplus/local
e/global.properties?" + Math.random()); | 99 let stringBundle = Services.strings.createBundle("chrome://adblockplus/local
e/global.properties?" + Math.random()); |
| 100 Utils.getString = function(name) | 100 Utils.getString = function(name) |
| 101 { | 101 { |
| 102 return stringBundle.GetStringFromName(name); | 102 return stringBundle.GetStringFromName(name); |
| 103 } | 103 } |
| 104 return Utils.getString(name); | 104 return Utils.getString(name); |
| 105 }, | 105 }, |
| 106 | 106 |
| 107 /** | 107 /** |
| 108 * Shows an alert message like window.alert() but with a custom title. | 108 * Shows an alert message like window.alert() but with a custom title. |
| 109 * | 109 * |
| 110 * @param {Window} parentWindow parent window of the dialog (can be null) | 110 * @param {Window} parentWindow parent window of the dialog (can be null) |
| 111 * @param {String} message message to be displayed | 111 * @param {String} message message to be displayed |
| 112 * @param {String} [title] dialog title, default title will be used if omitte
d | 112 * @param {String} [title] dialog title, default title will be used if omitte
d |
| 113 */ | 113 */ |
| 114 alert: function(parentWindow, message, title) | 114 alert: function(parentWindow, message, title) |
| 115 { | 115 { |
| 116 if (!title) | 116 if (!title) |
| 117 title = Utils.getString("default_dialog_title"); | 117 title = Utils.getString("default_dialog_title"); |
| 118 Utils.promptService.alert(parentWindow, title, message); | 118 Utils.promptService.alert(parentWindow, title, message); |
| 119 }, | 119 }, |
| 120 | 120 |
| 121 /** | 121 /** |
| 122 * Asks the user for a confirmation like window.confirm() but with a custom ti
tle. | 122 * Asks the user for a confirmation like window.confirm() but with a custom ti
tle. |
| 123 * | 123 * |
| 124 * @param {Window} parentWindow parent window of the dialog (can be null) | 124 * @param {Window} parentWindow parent window of the dialog (can be null) |
| 125 * @param {String} message message to be displayed | 125 * @param {String} message message to be displayed |
| 126 * @param {String} [title] dialog title, default title will be used if omitte
d | 126 * @param {String} [title] dialog title, default title will be used if omitte
d |
| 127 * @return {Bool} | 127 * @return {Bool} |
| 128 */ | 128 */ |
| 129 confirm: function(parentWindow, message, title) | 129 confirm: function(parentWindow, message, title) |
| 130 { | 130 { |
| 131 if (!title) | 131 if (!title) |
| 132 title = Utils.getString("default_dialog_title"); | 132 title = Utils.getString("default_dialog_title"); |
| 133 return Utils.promptService.confirm(parentWindow, title, message); | 133 return Utils.promptService.confirm(parentWindow, title, message); |
| 134 }, | 134 }, |
| 135 | 135 |
| 136 /** | 136 /** |
| 137 * Retrieves the window for a document node. | 137 * Retrieves the window for a document node. |
| 138 * @return {Window} will be null if the node isn't associated with a window | 138 * @return {Window} will be null if the node isn't associated with a window |
| 139 */ | 139 */ |
| 140 getWindow: function(/**Node*/ node) | 140 getWindow: function(/**Node*/ node) |
| 141 { | 141 { |
| 142 if ("ownerDocument" in node && node.ownerDocument) | 142 if ("ownerDocument" in node && node.ownerDocument) |
| 143 node = node.ownerDocument; | 143 node = node.ownerDocument; |
| 144 | 144 |
| 145 if ("defaultView" in node) | 145 if ("defaultView" in node) |
| 146 return node.defaultView; | 146 return node.defaultView; |
| 147 | 147 |
| 148 return null; | 148 return null; |
| 149 }, | 149 }, |
| 150 | 150 |
| 151 /** | 151 /** |
| 152 * Retrieves the top-level chrome window for a content window. | 152 * Retrieves the top-level chrome window for a content window. |
| 153 */ | 153 */ |
| 154 getChromeWindow: function(/**Window*/ window) /**Window*/ | 154 getChromeWindow: function(/**Window*/ window) /**Window*/ |
| 155 { | 155 { |
| 156 return window.QueryInterface(Ci.nsIInterfaceRequestor) | 156 return window.QueryInterface(Ci.nsIInterfaceRequestor) |
| 157 .getInterface(Ci.nsIWebNavigation) | 157 .getInterface(Ci.nsIWebNavigation) |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 /** | 231 /** |
| 232 * Gets the DOM window associated with a particular request (if any). | 232 * Gets the DOM window associated with a particular request (if any). |
| 233 */ | 233 */ |
| 234 getRequestWindow: function(/**nsIChannel*/ channel) /**nsIDOMWindow*/ | 234 getRequestWindow: function(/**nsIChannel*/ channel) /**nsIDOMWindow*/ |
| 235 { | 235 { |
| 236 try | 236 try |
| 237 { | 237 { |
| 238 if (channel.notificationCallbacks) | 238 if (channel.notificationCallbacks) |
| 239 return channel.notificationCallbacks.getInterface(Ci.nsILoadContext).ass
ociatedWindow; | 239 return channel.notificationCallbacks.getInterface(Ci.nsILoadContext).ass
ociatedWindow; |
| 240 } catch(e) {} | 240 } catch(e) {} |
| 241 | 241 |
| 242 try | 242 try |
| 243 { | 243 { |
| 244 if (channel.loadGroup && channel.loadGroup.notificationCallbacks) | 244 if (channel.loadGroup && channel.loadGroup.notificationCallbacks) |
| 245 return channel.loadGroup.notificationCallbacks.getInterface(Ci.nsILoadCo
ntext).associatedWindow; | 245 return channel.loadGroup.notificationCallbacks.getInterface(Ci.nsILoadCo
ntext).associatedWindow; |
| 246 } catch(e) {} | 246 } catch(e) {} |
| 247 | 247 |
| 248 return null; | 248 return null; |
| 249 }, | 249 }, |
| 250 | 250 |
| 251 /** | 251 /** |
| 252 * Generates filter subscription checksum. | 252 * Generates filter subscription checksum. |
| 253 * | 253 * |
| 254 * @param {Array of String} lines filter subscription lines (with checksum lin
e removed) | 254 * @param {Array of String} lines filter subscription lines (with checksum lin
e removed) |
| 255 * @return {String} checksum or null | 255 * @return {String} checksum or null |
| 256 */ | 256 */ |
| 257 generateChecksum: function(lines) | 257 generateChecksum: function(lines) |
| 258 { | 258 { |
| 259 let stream = null; | 259 let stream = null; |
| 260 try | 260 try |
| 261 { | 261 { |
| 262 // Checksum is an MD5 checksum (base64-encoded without the trailing "=") o
f | 262 // Checksum is an MD5 checksum (base64-encoded without the trailing "=") o
f |
| 263 // all lines in UTF-8 without the checksum line, joined with "\n". | 263 // all lines in UTF-8 without the checksum line, joined with "\n". |
| 264 | 264 |
| 265 let converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"].createI
nstance(Ci.nsIScriptableUnicodeConverter); | 265 let converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"].createI
nstance(Ci.nsIScriptableUnicodeConverter); |
| 266 converter.charset = "UTF-8"; | 266 converter.charset = "UTF-8"; |
| 267 stream = converter.convertToInputStream(lines.join("\n")); | 267 stream = converter.convertToInputStream(lines.join("\n")); |
| 268 | 268 |
| 269 let hashEngine = Cc["@mozilla.org/security/hash;1"].createInstance(Ci.nsIC
ryptoHash); | 269 let hashEngine = Cc["@mozilla.org/security/hash;1"].createInstance(Ci.nsIC
ryptoHash); |
| 270 hashEngine.init(hashEngine.MD5); | 270 hashEngine.init(hashEngine.MD5); |
| 271 hashEngine.updateFromStream(stream, stream.available()); | 271 hashEngine.updateFromStream(stream, stream.available()); |
| 272 return hashEngine.finish(true).replace(/=+$/, ""); | 272 return hashEngine.finish(true).replace(/=+$/, ""); |
| 273 } | 273 } |
| 274 catch (e) | 274 catch (e) |
| 275 { | 275 { |
| 276 return null; | 276 return null; |
| 277 } | 277 } |
| 278 finally | 278 finally |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 546 XPCOMUtils.defineLazyServiceGetter(Utils, "parentMessageManager", "@mozilla.org/
parentprocessmessagemanager;1", "nsIFrameMessageManager"); | 546 XPCOMUtils.defineLazyServiceGetter(Utils, "parentMessageManager", "@mozilla.org/
parentprocessmessagemanager;1", "nsIFrameMessageManager"); |
| 547 XPCOMUtils.defineLazyServiceGetter(Utils, "httpProtocol", "@mozilla.org/network/
protocol;1?name=http", "nsIHttpProtocolHandler"); | 547 XPCOMUtils.defineLazyServiceGetter(Utils, "httpProtocol", "@mozilla.org/network/
protocol;1?name=http", "nsIHttpProtocolHandler"); |
| 548 XPCOMUtils.defineLazyServiceGetter(Utils, "clipboard", "@mozilla.org/widget/clip
board;1", "nsIClipboard"); | 548 XPCOMUtils.defineLazyServiceGetter(Utils, "clipboard", "@mozilla.org/widget/clip
board;1", "nsIClipboard"); |
| 549 XPCOMUtils.defineLazyServiceGetter(Utils, "clipboardHelper", "@mozilla.org/widge
t/clipboardhelper;1", "nsIClipboardHelper"); | 549 XPCOMUtils.defineLazyServiceGetter(Utils, "clipboardHelper", "@mozilla.org/widge
t/clipboardhelper;1", "nsIClipboardHelper"); |
| 550 XPCOMUtils.defineLazyGetter(Utils, "crypto", function() | 550 XPCOMUtils.defineLazyGetter(Utils, "crypto", function() |
| 551 { | 551 { |
| 552 try | 552 try |
| 553 { | 553 { |
| 554 let ctypes = Components.utils.import("resource://gre/modules/ctypes.jsm", nu
ll).ctypes; | 554 let ctypes = Components.utils.import("resource://gre/modules/ctypes.jsm", nu
ll).ctypes; |
| 555 | 555 |
| 556 let nsslib = ctypes.open(ctypes.libraryName("nss3")); | 556 let nsslib; |
| 557 try |
| 558 { |
| 559 nsslib = ctypes.open(ctypes.libraryName("nss3")); |
| 560 } |
| 561 catch (e) |
| 562 { |
| 563 // It seems that on Mac OS X the full path name needs to be specified |
| 564 let file = Services.dirsvc.get("GreD", Ci.nsILocalFile); |
| 565 file.append(ctypes.libraryName("nss3")); |
| 566 nsslib = ctypes.open(file.path); |
| 567 } |
| 557 | 568 |
| 558 let result = {}; | 569 let result = {}; |
| 559 | 570 |
| 560 // seccomon.h | 571 // seccomon.h |
| 561 result.siUTF8String = 14; | 572 result.siUTF8String = 14; |
| 562 | 573 |
| 563 // secoidt.h | 574 // secoidt.h |
| 564 result.SEC_OID_ISO_SHA_WITH_RSA_SIGNATURE = 15; | 575 result.SEC_OID_ISO_SHA_WITH_RSA_SIGNATURE = 15; |
| 565 | 576 |
| 566 // The following types are opaque to us | 577 // The following types are opaque to us |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 697 Cu.reportError(e); | 708 Cu.reportError(e); |
| 698 // Expected, ctypes isn't supported in Gecko 1.9.2 | 709 // Expected, ctypes isn't supported in Gecko 1.9.2 |
| 699 return null; | 710 return null; |
| 700 } | 711 } |
| 701 }); | 712 }); |
| 702 | 713 |
| 703 if ("@mozilla.org/messenger/headerparser;1" in Cc) | 714 if ("@mozilla.org/messenger/headerparser;1" in Cc) |
| 704 XPCOMUtils.defineLazyServiceGetter(Utils, "headerParser", "@mozilla.org/messen
ger/headerparser;1", "nsIMsgHeaderParser"); | 715 XPCOMUtils.defineLazyServiceGetter(Utils, "headerParser", "@mozilla.org/messen
ger/headerparser;1", "nsIMsgHeaderParser"); |
| 705 else | 716 else |
| 706 Utils.headerParser = null; | 717 Utils.headerParser = null; |
| OLD | NEW |