Wed, 31 Dec 2014 07:53:36 +0100
Correct small whitespace inconsistency, lost while renaming variables.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, you can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | var EXPORTED_SYMBOLS = ["controller", "utils", "elementslib", "os", |
michael@0 | 6 | "getBrowserController", "newBrowserController", |
michael@0 | 7 | "getAddonsController", "getPreferencesController", |
michael@0 | 8 | "newMail3PaneController", "getMail3PaneController", |
michael@0 | 9 | "wm", "platform", "getAddrbkController", |
michael@0 | 10 | "getMsgComposeController", "getDownloadsController", |
michael@0 | 11 | "Application", "findElement", |
michael@0 | 12 | "getPlacesController", 'isMac', 'isLinux', 'isWindows', |
michael@0 | 13 | "firePythonCallback", "getAddons" |
michael@0 | 14 | ]; |
michael@0 | 15 | |
michael@0 | 16 | const Cc = Components.classes; |
michael@0 | 17 | const Ci = Components.interfaces; |
michael@0 | 18 | const Cu = Components.utils; |
michael@0 | 19 | |
michael@0 | 20 | |
michael@0 | 21 | Cu.import("resource://gre/modules/AddonManager.jsm"); |
michael@0 | 22 | Cu.import("resource://gre/modules/Services.jsm"); |
michael@0 | 23 | |
michael@0 | 24 | // imports |
michael@0 | 25 | var assertions = {}; Cu.import('resource://mozmill/modules/assertions.js', assertions); |
michael@0 | 26 | var broker = {}; Cu.import('resource://mozmill/driver/msgbroker.js', broker); |
michael@0 | 27 | var controller = {}; Cu.import('resource://mozmill/driver/controller.js', controller); |
michael@0 | 28 | var elementslib = {}; Cu.import('resource://mozmill/driver/elementslib.js', elementslib); |
michael@0 | 29 | var findElement = {}; Cu.import('resource://mozmill/driver/mozelement.js', findElement); |
michael@0 | 30 | var os = {}; Cu.import('resource://mozmill/stdlib/os.js', os); |
michael@0 | 31 | var utils = {}; Cu.import('resource://mozmill/stdlib/utils.js', utils); |
michael@0 | 32 | var windows = {}; Cu.import('resource://mozmill/modules/windows.js', windows); |
michael@0 | 33 | |
michael@0 | 34 | |
michael@0 | 35 | const DEBUG = false; |
michael@0 | 36 | |
michael@0 | 37 | // This is a useful "check" timer. See utils.js, good for debugging |
michael@0 | 38 | if (DEBUG) { |
michael@0 | 39 | utils.startTimer(); |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | var assert = new assertions.Assert(); |
michael@0 | 43 | |
michael@0 | 44 | // platform information |
michael@0 | 45 | var platform = os.getPlatform(); |
michael@0 | 46 | var isMac = false; |
michael@0 | 47 | var isWindows = false; |
michael@0 | 48 | var isLinux = false; |
michael@0 | 49 | |
michael@0 | 50 | if (platform == "darwin"){ |
michael@0 | 51 | isMac = true; |
michael@0 | 52 | } |
michael@0 | 53 | |
michael@0 | 54 | if (platform == "winnt"){ |
michael@0 | 55 | isWindows = true; |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | if (platform == "linux"){ |
michael@0 | 59 | isLinux = true; |
michael@0 | 60 | } |
michael@0 | 61 | |
michael@0 | 62 | var wm = Services.wm; |
michael@0 | 63 | |
michael@0 | 64 | var appInfo = Services.appinfo; |
michael@0 | 65 | var Application = utils.applicationName; |
michael@0 | 66 | |
michael@0 | 67 | |
michael@0 | 68 | /** |
michael@0 | 69 | * Retrieves the list with information about installed add-ons. |
michael@0 | 70 | * |
michael@0 | 71 | * @returns {String} JSON data of installed add-ons |
michael@0 | 72 | */ |
michael@0 | 73 | function getAddons() { |
michael@0 | 74 | var addons = null; |
michael@0 | 75 | |
michael@0 | 76 | AddonManager.getAllAddons(function (addonList) { |
michael@0 | 77 | var tmp_list = [ ]; |
michael@0 | 78 | |
michael@0 | 79 | addonList.forEach(function (addon) { |
michael@0 | 80 | var tmp = { }; |
michael@0 | 81 | |
michael@0 | 82 | // We have to filter out properties of type 'function' of the addon |
michael@0 | 83 | // object, which will break JSON.stringify() and result in incomplete |
michael@0 | 84 | // addon information. |
michael@0 | 85 | for (var key in addon) { |
michael@0 | 86 | if (typeof(addon[key]) !== "function") { |
michael@0 | 87 | tmp[key] = addon[key]; |
michael@0 | 88 | } |
michael@0 | 89 | } |
michael@0 | 90 | |
michael@0 | 91 | tmp_list.push(tmp); |
michael@0 | 92 | }); |
michael@0 | 93 | |
michael@0 | 94 | addons = tmp_list; |
michael@0 | 95 | }); |
michael@0 | 96 | |
michael@0 | 97 | try { |
michael@0 | 98 | // Sychronize with getAllAddons so we do not return too early |
michael@0 | 99 | assert.waitFor(function () { |
michael@0 | 100 | return !!addons; |
michael@0 | 101 | }) |
michael@0 | 102 | |
michael@0 | 103 | return addons; |
michael@0 | 104 | } catch (e) { |
michael@0 | 105 | return null; |
michael@0 | 106 | } |
michael@0 | 107 | } |
michael@0 | 108 | |
michael@0 | 109 | /** |
michael@0 | 110 | * Retrieves application details for the Mozmill report |
michael@0 | 111 | * |
michael@0 | 112 | * @return {String} JSON data of application details |
michael@0 | 113 | */ |
michael@0 | 114 | function getApplicationDetails() { |
michael@0 | 115 | var locale = Cc["@mozilla.org/chrome/chrome-registry;1"] |
michael@0 | 116 | .getService(Ci.nsIXULChromeRegistry) |
michael@0 | 117 | .getSelectedLocale("global"); |
michael@0 | 118 | |
michael@0 | 119 | // Put all our necessary information into JSON and return it: |
michael@0 | 120 | // appinfo, startupinfo, and addons |
michael@0 | 121 | var details = { |
michael@0 | 122 | application_id: appInfo.ID, |
michael@0 | 123 | application_name: Application, |
michael@0 | 124 | application_version: appInfo.version, |
michael@0 | 125 | application_locale: locale, |
michael@0 | 126 | platform_buildid: appInfo.platformBuildID, |
michael@0 | 127 | platform_version: appInfo.platformVersion, |
michael@0 | 128 | addons: getAddons(), |
michael@0 | 129 | startupinfo: getStartupInfo(), |
michael@0 | 130 | paths: { |
michael@0 | 131 | appdata: Services.dirsvc.get('UAppData', Ci.nsIFile).path, |
michael@0 | 132 | profile: Services.dirsvc.get('ProfD', Ci.nsIFile).path |
michael@0 | 133 | } |
michael@0 | 134 | }; |
michael@0 | 135 | |
michael@0 | 136 | return JSON.stringify(details); |
michael@0 | 137 | } |
michael@0 | 138 | |
michael@0 | 139 | // get startup time if available |
michael@0 | 140 | // see http://blog.mozilla.com/tglek/2011/04/26/measuring-startup-speed-correctly/ |
michael@0 | 141 | function getStartupInfo() { |
michael@0 | 142 | var startupInfo = {}; |
michael@0 | 143 | |
michael@0 | 144 | try { |
michael@0 | 145 | var _startupInfo = Services.startup.getStartupInfo(); |
michael@0 | 146 | for (var time in _startupInfo) { |
michael@0 | 147 | // convert from Date object to ms since epoch |
michael@0 | 148 | startupInfo[time] = _startupInfo[time].getTime(); |
michael@0 | 149 | } |
michael@0 | 150 | } catch (e) { |
michael@0 | 151 | startupInfo = null; |
michael@0 | 152 | } |
michael@0 | 153 | |
michael@0 | 154 | return startupInfo; |
michael@0 | 155 | } |
michael@0 | 156 | |
michael@0 | 157 | |
michael@0 | 158 | |
michael@0 | 159 | function newBrowserController () { |
michael@0 | 160 | return new controller.MozMillController(utils.getMethodInWindows('OpenBrowserWindow')()); |
michael@0 | 161 | } |
michael@0 | 162 | |
michael@0 | 163 | function getBrowserController () { |
michael@0 | 164 | var browserWindow = wm.getMostRecentWindow("navigator:browser"); |
michael@0 | 165 | |
michael@0 | 166 | if (browserWindow == null) { |
michael@0 | 167 | return newBrowserController(); |
michael@0 | 168 | } else { |
michael@0 | 169 | return new controller.MozMillController(browserWindow); |
michael@0 | 170 | } |
michael@0 | 171 | } |
michael@0 | 172 | |
michael@0 | 173 | function getPlacesController () { |
michael@0 | 174 | utils.getMethodInWindows('PlacesCommandHook').showPlacesOrganizer('AllBookmarks'); |
michael@0 | 175 | |
michael@0 | 176 | return new controller.MozMillController(wm.getMostRecentWindow('')); |
michael@0 | 177 | } |
michael@0 | 178 | |
michael@0 | 179 | function getAddonsController () { |
michael@0 | 180 | if (Application == 'SeaMonkey') { |
michael@0 | 181 | utils.getMethodInWindows('toEM')(); |
michael@0 | 182 | } |
michael@0 | 183 | else if (Application == 'Thunderbird') { |
michael@0 | 184 | utils.getMethodInWindows('openAddonsMgr')(); |
michael@0 | 185 | } |
michael@0 | 186 | else if (Application == 'Sunbird') { |
michael@0 | 187 | utils.getMethodInWindows('goOpenAddons')(); |
michael@0 | 188 | } else { |
michael@0 | 189 | utils.getMethodInWindows('BrowserOpenAddonsMgr')(); |
michael@0 | 190 | } |
michael@0 | 191 | |
michael@0 | 192 | return new controller.MozMillController(wm.getMostRecentWindow('')); |
michael@0 | 193 | } |
michael@0 | 194 | |
michael@0 | 195 | function getDownloadsController() { |
michael@0 | 196 | utils.getMethodInWindows('BrowserDownloadsUI')(); |
michael@0 | 197 | |
michael@0 | 198 | return new controller.MozMillController(wm.getMostRecentWindow('')); |
michael@0 | 199 | } |
michael@0 | 200 | |
michael@0 | 201 | function getPreferencesController() { |
michael@0 | 202 | if (Application == 'Thunderbird') { |
michael@0 | 203 | utils.getMethodInWindows('openOptionsDialog')(); |
michael@0 | 204 | } else { |
michael@0 | 205 | utils.getMethodInWindows('openPreferences')(); |
michael@0 | 206 | } |
michael@0 | 207 | |
michael@0 | 208 | return new controller.MozMillController(wm.getMostRecentWindow('')); |
michael@0 | 209 | } |
michael@0 | 210 | |
michael@0 | 211 | // Thunderbird functions |
michael@0 | 212 | function newMail3PaneController () { |
michael@0 | 213 | return new controller.MozMillController(utils.getMethodInWindows('toMessengerWindow')()); |
michael@0 | 214 | } |
michael@0 | 215 | |
michael@0 | 216 | function getMail3PaneController () { |
michael@0 | 217 | var mail3PaneWindow = wm.getMostRecentWindow("mail:3pane"); |
michael@0 | 218 | |
michael@0 | 219 | if (mail3PaneWindow == null) { |
michael@0 | 220 | return newMail3PaneController(); |
michael@0 | 221 | } else { |
michael@0 | 222 | return new controller.MozMillController(mail3PaneWindow); |
michael@0 | 223 | } |
michael@0 | 224 | } |
michael@0 | 225 | |
michael@0 | 226 | // Thunderbird - Address book window |
michael@0 | 227 | function newAddrbkController () { |
michael@0 | 228 | utils.getMethodInWindows("toAddressBook")(); |
michael@0 | 229 | utils.sleep(2000); |
michael@0 | 230 | var addyWin = wm.getMostRecentWindow("mail:addressbook"); |
michael@0 | 231 | |
michael@0 | 232 | return new controller.MozMillController(addyWin); |
michael@0 | 233 | } |
michael@0 | 234 | |
michael@0 | 235 | function getAddrbkController () { |
michael@0 | 236 | var addrbkWindow = wm.getMostRecentWindow("mail:addressbook"); |
michael@0 | 237 | if (addrbkWindow == null) { |
michael@0 | 238 | return newAddrbkController(); |
michael@0 | 239 | } else { |
michael@0 | 240 | return new controller.MozMillController(addrbkWindow); |
michael@0 | 241 | } |
michael@0 | 242 | } |
michael@0 | 243 | |
michael@0 | 244 | function firePythonCallback (filename, method, args, kwargs) { |
michael@0 | 245 | obj = {'filename': filename, 'method': method}; |
michael@0 | 246 | obj['args'] = args || []; |
michael@0 | 247 | obj['kwargs'] = kwargs || {}; |
michael@0 | 248 | |
michael@0 | 249 | broker.sendMessage("firePythonCallback", obj); |
michael@0 | 250 | } |
michael@0 | 251 | |
michael@0 | 252 | function timer (name) { |
michael@0 | 253 | this.name = name; |
michael@0 | 254 | this.timers = {}; |
michael@0 | 255 | this.actions = []; |
michael@0 | 256 | |
michael@0 | 257 | frame.timers.push(this); |
michael@0 | 258 | } |
michael@0 | 259 | |
michael@0 | 260 | timer.prototype.start = function (name) { |
michael@0 | 261 | this.timers[name].startTime = (new Date).getTime(); |
michael@0 | 262 | } |
michael@0 | 263 | |
michael@0 | 264 | timer.prototype.stop = function (name) { |
michael@0 | 265 | var t = this.timers[name]; |
michael@0 | 266 | |
michael@0 | 267 | t.endTime = (new Date).getTime(); |
michael@0 | 268 | t.totalTime = (t.endTime - t.startTime); |
michael@0 | 269 | } |
michael@0 | 270 | |
michael@0 | 271 | timer.prototype.end = function () { |
michael@0 | 272 | frame.events.fireEvent("timer", this); |
michael@0 | 273 | frame.timers.remove(this); |
michael@0 | 274 | } |
michael@0 | 275 | |
michael@0 | 276 | // Initialization |
michael@0 | 277 | |
michael@0 | 278 | /** |
michael@0 | 279 | * Initialize Mozmill |
michael@0 | 280 | */ |
michael@0 | 281 | function initialize() { |
michael@0 | 282 | windows.init(); |
michael@0 | 283 | } |
michael@0 | 284 | |
michael@0 | 285 | initialize(); |