|
| 1 | +// GA Debugger uses a few of devtools internal assets for various UI elements |
| 2 | +// such as the split view and beacon inspector (a VariableView). Unfortunately, |
| 3 | +// the Devtools framework is in a state of flux, with asset paths and import |
| 4 | +// methods changing regularly with each release of Firefox. |
| 5 | +// |
| 6 | +// This helper module provides methods for loading script dependencies in either |
| 7 | +// commonJS or the older JSM format. Method calls accept the latest paths, |
| 8 | +// resolving them to the correct location for the current browser version. The |
| 9 | +// correct commonJS or JSM module is then loaded and returned to the caller. |
| 10 | +// |
| 11 | +// It also provides methods for loading stylesheets (again, with differing paths) |
| 12 | +// into an XUL document. |
| 13 | +// |
| 14 | +// ** This is a temporary fix and will remain here unitl the old versions are |
| 15 | +// phased out, at which point the min version for this extension will be changed |
| 16 | +// to 44 ** |
| 17 | + |
| 18 | +'use strict'; |
| 19 | + |
| 20 | +const { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components; |
| 21 | +const appInfo = Cc['@mozilla.org/xre/app-info;1'].getService(Ci.nsIXULAppInfo); |
| 22 | +const appMajorVer = parseInt(appInfo.version); |
| 23 | + |
| 24 | +let ResourceLoader = {}, |
| 25 | + require; |
| 26 | + |
| 27 | +if (appMajorVer >= 48) { |
| 28 | + require = Cu.import("resource://devtools/shared/Loader.jsm", {}).require; |
| 29 | +} |
| 30 | + |
| 31 | +ResourceLoader.require = function (url) { |
| 32 | + |
| 33 | + if (url === 'devtools/client/shared/l10n') { |
| 34 | + // Prior to v48, the localization helpers were in ViewHelpers.jsm |
| 35 | + if (appMajorVer < 48) { |
| 36 | + return { |
| 37 | + LocalizationHelper: ResourceLoader.require('devtools/client/shared/widgets/view-helpers').ViewHelpers.L10N |
| 38 | + } |
| 39 | + } |
| 40 | + } else if (url === 'devtools/client/shared/widgets/view-helpers') { |
| 41 | + if (appMajorVer < 44) { |
| 42 | + // Prior to v44, ViewHelpers was in a different directory. (see: https://bugzil.la/912121) |
| 43 | + url = 'resource:///modules/devtools/ViewHelpers.jsm'; |
| 44 | + } else if (appMajorVer < 49) { |
| 45 | + // Prior to v49, ViewHelpers was JSM. from 49 it's a commonJS module |
| 46 | + url = 'resource://devtools/client/shared/widgets/ViewHelpers.jsm'; |
| 47 | + } |
| 48 | + } else if (url === 'devtools/shared/event-emitter') { |
| 49 | + // Proior to v48, event-emitter must be loaded as JSM |
| 50 | + if (appMajorVer < 44) { |
| 51 | + return Cu.import('resource://gre/modules/devtools/event-emitter.js', {}).EventEmitter; |
| 52 | + } else if (appMajorVer < 48) { |
| 53 | + return Cu.import('resource://devtools/shared/event-emitter.js', {}).EventEmitter; |
| 54 | + } |
| 55 | + } else if (url === 'resource://devtools/client/shared/widgets/SideMenuWidget.jsm') { |
| 56 | + // Proior to v44, SideMenuWidget.jsm existed elsewhere. (see: https://bugzil.la/912121) |
| 57 | + if (appMajorVer < 44) { |
| 58 | + url = 'resource:///modules/devtools/SideMenuWidget.jsm'; |
| 59 | + } |
| 60 | + } else if (url === 'resource://devtools/client/shared/widgets/VariablesView.jsm') { |
| 61 | + // Proior to v44, VariablesView.jsm existed elsewhere. (see: https://bugzil.la/912121) |
| 62 | + if (appMajorVer < 44) { |
| 63 | + url = 'resource:///modules/devtools/VariablesView.jsm'; |
| 64 | + } |
| 65 | + } else if (url === 'promise') { |
| 66 | + // Proior to v48, promise must be loaded as JSM |
| 67 | + if (appMajorVer < 48) { |
| 68 | + return Cu.import('resource://gre/modules/Promise.jsm', {}).Promise; |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + if (appMajorVer >= 48 && !url.endsWith('.jsm')) { |
| 73 | + return require(url); |
| 74 | + } else { |
| 75 | + return Cu.import(url, {}); |
| 76 | + } |
| 77 | +} |
| 78 | + |
| 79 | + |
| 80 | +ResourceLoader.loadStyleSheet = function(url, doc) { |
| 81 | + if (appMajorVer < 44) { |
| 82 | + if (url === 'chrome://devtools/content/shared/widgets/widgets.css') { |
| 83 | + url = 'chrome://browser/content/devtools/widgets.css'; |
| 84 | + } else { |
| 85 | + url = url.replace('chrome://devtools/skin/', 'chrome://browser/skin/devtools/') |
| 86 | + } |
| 87 | + } |
| 88 | + var pi = doc.createProcessingInstruction('xml-stylesheet', 'href="' + url + '" type="text/css"'); |
| 89 | + doc.insertBefore(pi, doc.firstChild); |
| 90 | +} |
| 91 | + |
| 92 | + |
| 93 | +ResourceLoader.getAppMajorVersion = function () { |
| 94 | + return appMajorVer; |
| 95 | +} |
| 96 | + |
| 97 | +this.EXPORTED_SYMBOLS = ['ResourceLoader']; |
0 commit comments