Bug 912121 - Create shims for popular DevTools modules in add-ons. rs=devtools
authorJ. Ryan Stinnett <jryans@gmail.com>
Thu, 17 Sep 2015 16:28:42 -0500
changeset 263702 ab023cef6c94e29a01c270bfbab7aa8461b37988
parent 263701 f5c50b4960f074ae1997da13bca56b724c332c99
child 263703 b0a086cc8fa96130f904338f3d5efb149c8b8580
push id65396
push usercbook@mozilla.com
push dateTue, 22 Sep 2015 10:50:42 +0000
treeherdermozilla-inbound@9a5faeebdcb5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdevtools
bugs912121
milestone44.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 912121 - Create shims for popular DevTools modules in add-ons. rs=devtools For popular modules used by many DevTools add-ons, add shim files which wrap the modules and make them available at their previous location. Each shim includes a deprecation warning to make devs and users aware of the issue.
devtools/client/moz.build
devtools/client/shims/gDevTools.jsm
devtools/client/shims/moz.build
devtools/server/dbg-server.jsm
devtools/server/moz.build
devtools/server/shims/dbg-server.jsm
devtools/server/shims/moz.build
devtools/shared/client/dbg-client.jsm
devtools/shared/client/moz.build
devtools/shared/moz.build
devtools/shared/shims/Console.jsm
devtools/shared/shims/Loader.jsm
devtools/shared/shims/Simulator.jsm
devtools/shared/shims/dbg-client.jsm
devtools/shared/shims/event-emitter.js
devtools/shared/shims/moz.build
mobile/android/tests/browser/chrome/test_debugger_server.html
modules/libpref/init/all.js
--- a/devtools/client/moz.build
+++ b/devtools/client/moz.build
@@ -22,16 +22,17 @@ DIRS += [
     'netmonitor',
     'performance',
     'projecteditor',
     'promisedebugger',
     'responsivedesign',
     'scratchpad',
     'shadereditor',
     'shared',
+    'shims',
     'sourceeditor',
     'storage',
     'styleeditor',
     'styleinspector',
     'tilt',
     'webaudioeditor',
     'webconsole',
     'webide',
new file mode 100644
--- /dev/null
+++ b/devtools/client/shims/gDevTools.jsm
@@ -0,0 +1,36 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+/**
+ * This file only exists to support add-ons which import this module at a
+ * specific path.
+ */
+
+const Cu = Components.utils;
+
+const { Services } = Cu.import("resource://gre/modules/Services.jsm", {});
+
+const WARNING_PREF = "devtools.migration.warnings";
+if (Services.prefs.getBoolPref(WARNING_PREF)) {
+  const { Deprecated } = Cu.import("resource://gre/modules/Deprecated.jsm", {});
+  Deprecated.warning("This path to gDevTools.jsm is deprecated.  Please use " +
+                     "Cu.import(\"resource:///modules/devtools/client/" +
+                     "framework/gDevTools.jsm\") to load this module.",
+                     "https://bugzil.la/912121");
+}
+
+this.EXPORTED_SYMBOLS = [
+  "gDevTools",
+  "DevTools",
+  "gDevToolsBrowser"
+];
+
+const module =
+  Cu.import("resource:///modules/devtools/client/framework/gDevTools.jsm", {});
+
+for (let symbol of this.EXPORTED_SYMBOLS) {
+  this[symbol] = module[symbol];
+}
new file mode 100644
--- /dev/null
+++ b/devtools/client/shims/moz.build
@@ -0,0 +1,13 @@
+# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+# Unlike most DevTools build files, this file does not use DevToolsModules
+# because these files are here for add-on compatibility, and so they must be
+# installed to previously defined locations.
+
+EXTRA_JS_MODULES.devtools += [
+    'gDevTools.jsm',
+]
--- a/devtools/server/moz.build
+++ b/devtools/server/moz.build
@@ -3,16 +3,17 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 include('../templates.mozbuild')
 
 DIRS += [
     'actors',
+    'shims',
 ]
 
 BROWSER_CHROME_MANIFESTS += ['tests/browser/browser.ini']
 MOCHITEST_CHROME_MANIFESTS += ['tests/mochitest/chrome.ini']
 XPCSHELL_TESTS_MANIFESTS += ['tests/unit/xpcshell.ini']
 
 XPIDL_SOURCES += [
     'nsIJSInspector.idl',
@@ -25,13 +26,12 @@ SOURCES += [
 ]
 
 FINAL_LIBRARY = 'xul'
 
 DevToolsModules(
     'child.js',
     'content-globals.js',
     'content-server.jsm',
-    'dbg-server.jsm',
     'main.js',
     'protocol.js',
     'worker.js'
 )
rename from devtools/server/dbg-server.jsm
rename to devtools/server/shims/dbg-server.jsm
--- a/devtools/server/dbg-server.jsm
+++ b/devtools/server/shims/dbg-server.jsm
@@ -1,26 +1,37 @@
-/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
-/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
+
 /**
- * Loads the remote debugging protocol code into a sandbox, in order to
- * shield it from the debuggee. This way, when debugging chrome globals,
- * debugger and debuggee will be in separate compartments.
+ * This file only exists to support add-ons which import this module at a
+ * specific path.
  */
 
-const Ci = Components.interfaces;
-const Cc = Components.classes;
 const Cu = Components.utils;
 
-const { require } = Cu.import("resource://gre/modules/devtools/shared/Loader.jsm", {});
+const { Services } = Cu.import("resource://gre/modules/Services.jsm", {});
 
-this.EXPORTED_SYMBOLS = ["DebuggerServer", "ActorPool"];
+const WARNING_PREF = "devtools.migration.warnings";
+if (Services.prefs.getBoolPref(WARNING_PREF)) {
+  const { Deprecated } = Cu.import("resource://gre/modules/Deprecated.jsm", {});
+  Deprecated.warning("dbg-server.jsm is deprecated.  Please use " +
+                     "require(\"devtools/server/main\") to load this " +
+                     "module.",
+                     "https://bugzil.la/912121");
+}
 
-var server = require("devtools/server/main");
+this.EXPORTED_SYMBOLS = [
+  "DebuggerServer",
+  "ActorPool",
+  "OriginalLocation",
+];
 
-this.DebuggerServer = server.DebuggerServer;
-this.ActorPool = server.ActorPool;
-this.OriginalLocation = server.OriginalLocation;
+const { require } =
+  Cu.import("resource://gre/modules/devtools/shared/Loader.jsm", {});
+const module = require("devtools/server/main");
+
+for (let symbol of this.EXPORTED_SYMBOLS) {
+  this[symbol] = module[symbol];
+}
new file mode 100644
--- /dev/null
+++ b/devtools/server/shims/moz.build
@@ -0,0 +1,13 @@
+# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+# Unlike most DevTools build files, this file does not use DevToolsModules
+# because these files are here for add-on compatibility, and so they must be
+# installed to previously defined locations.
+
+EXTRA_JS_MODULES.devtools += [
+    'dbg-server.jsm',
+]
--- a/devtools/shared/client/moz.build
+++ b/devtools/shared/client/moz.build
@@ -1,11 +1,10 @@
 # -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
 # vim: set filetype=python:
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 DevToolsModules(
     'connection-manager.js',
-    'dbg-client.jsm',
     'main.js',
 )
--- a/devtools/shared/moz.build
+++ b/devtools/shared/moz.build
@@ -16,16 +16,17 @@ DIRS += [
     'jsbeautify',
     'layout',
     'performance',
     'pretty-fast',
     'qrcode',
     'security',
     'sourcemap',
     'shared',
+    'shims',
     'styleinspector',
     'tern',
     'touch',
     'transport',
     'webconsole'
 ]
 
 MOCHITEST_CHROME_MANIFESTS += ['tests/mochitest/chrome.ini']
new file mode 100644
--- /dev/null
+++ b/devtools/shared/shims/Console.jsm
@@ -0,0 +1,35 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+/**
+ * This file only exists to support add-ons which import this module at a
+ * specific path.
+ */
+
+const Cu = Components.utils;
+
+const { Services } = Cu.import("resource://gre/modules/Services.jsm", {});
+
+const WARNING_PREF = "devtools.migration.warnings";
+if (Services.prefs.getBoolPref(WARNING_PREF)) {
+  const { Deprecated } = Cu.import("resource://gre/modules/Deprecated.jsm", {});
+  Deprecated.warning("This path to Console.jsm is deprecated.  Please use " +
+                     "Cu.import(\"resource://gre/modules/devtools/shared/" +
+                     "Console.jsm\") to load this module.",
+                     "https://bugzil.la/912121");
+}
+
+this.EXPORTED_SYMBOLS = [
+  "console",
+  "ConsoleAPI"
+];
+
+const module =
+  Cu.import("resource://gre/modules/devtools/shared/Console.jsm", {});
+
+for (let symbol of this.EXPORTED_SYMBOLS) {
+  this[symbol] = module[symbol];
+}
new file mode 100644
--- /dev/null
+++ b/devtools/shared/shims/Loader.jsm
@@ -0,0 +1,39 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+/**
+ * This file only exists to support add-ons which import this module at a
+ * specific path.
+ */
+
+const Cu = Components.utils;
+
+const { Services } = Cu.import("resource://gre/modules/Services.jsm", {});
+
+const WARNING_PREF = "devtools.migration.warnings";
+if (Services.prefs.getBoolPref(WARNING_PREF)) {
+  const { Deprecated } = Cu.import("resource://gre/modules/Deprecated.jsm", {});
+  Deprecated.warning("This path to Loader.jsm is deprecated.  Please use " +
+                     "Cu.import(\"resource://gre/modules/devtools/shared/" +
+                     "Loader.jsm\") to load this module.",
+                     "https://bugzil.la/912121");
+}
+
+this.EXPORTED_SYMBOLS = [
+  "DevToolsLoader",
+  "devtools",
+  "BuiltinProvider",
+  "SrcdirProvider",
+  "require",
+  "loader"
+];
+
+const module =
+  Cu.import("resource://gre/modules/devtools/shared/Loader.jsm", {});
+
+for (let symbol of this.EXPORTED_SYMBOLS) {
+  this[symbol] = module[symbol];
+}
new file mode 100644
--- /dev/null
+++ b/devtools/shared/shims/Simulator.jsm
@@ -0,0 +1,34 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+/**
+ * This file only exists to support add-ons which import this module at a
+ * specific path.
+ */
+
+const Cu = Components.utils;
+
+const { Services } = Cu.import("resource://gre/modules/Services.jsm", {});
+
+const WARNING_PREF = "devtools.migration.warnings";
+if (Services.prefs.getBoolPref(WARNING_PREF)) {
+  const { Deprecated } = Cu.import("resource://gre/modules/Deprecated.jsm", {});
+  Deprecated.warning("This path to Simulator.jsm is deprecated.  Please use " +
+                     "Cu.import(\"resource://gre/modules/devtools/shared/" +
+                     "apps/Simulator.jsm\") to load this module.",
+                     "https://bugzil.la/912121");
+}
+
+this.EXPORTED_SYMBOLS = [
+  "Simulator",
+];
+
+const module =
+  Cu.import("resource://gre/modules/devtools/shared/apps/Simulator.jsm", {});
+
+for (let symbol of this.EXPORTED_SYMBOLS) {
+  this[symbol] = module[symbol];
+}
rename from devtools/shared/client/dbg-client.jsm
rename to devtools/shared/shims/dbg-client.jsm
--- a/devtools/shared/client/dbg-client.jsm
+++ b/devtools/shared/shims/dbg-client.jsm
@@ -1,29 +1,43 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
-// Just a compatibility wrapper for addons that are used
-// to import the jsm instead of the js module
+/**
+ * This file only exists to support add-ons which import this module at a
+ * specific path.
+ */
 
 const Cu = Components.utils;
 
-const { require } = Cu.import("resource://gre/modules/devtools/shared/Loader.jsm", {});
+const { Services } = Cu.import("resource://gre/modules/Services.jsm", {});
+
+const WARNING_PREF = "devtools.migration.warnings";
+if (Services.prefs.getBoolPref(WARNING_PREF)) {
+  const { Deprecated } = Cu.import("resource://gre/modules/Deprecated.jsm", {});
+  Deprecated.warning("dbg-client.jsm is deprecated.  Please use " +
+                     "require(\"devtools/shared/client/main\") to load this " +
+                     "module.", "https://bugzil.la/912121");
+}
+
+const { require } =
+  Cu.import("resource://gre/modules/devtools/shared/Loader.jsm", {});
 
 this.EXPORTED_SYMBOLS = ["DebuggerTransport",
                          "DebuggerClient",
                          "RootClient",
                          "LongStringClient",
                          "EnvironmentClient",
                          "ObjectClient"];
 
-var client = require("devtools/shared/client/main");
+let client = require("devtools/shared/client/main");
 
 this.DebuggerClient = client.DebuggerClient;
 this.RootClient = client.RootClient;
 this.LongStringClient = client.LongStringClient;
 this.EnvironmentClient = client.EnvironmentClient;
 this.ObjectClient = client.ObjectClient;
 
-this.DebuggerTransport = require("devtools/shared/transport/transport").DebuggerTransport;
+this.DebuggerTransport =
+  require("devtools/shared/transport/transport").DebuggerTransport;
new file mode 100644
--- /dev/null
+++ b/devtools/shared/shims/event-emitter.js
@@ -0,0 +1,42 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+/**
+ * This file only exists to support add-ons which import this module at a
+ * specific path.
+ */
+
+(function (factory) { // Module boilerplate
+  if (this.module && module.id.indexOf("event-emitter") >= 0) { // require
+    factory.call(this, require, exports, module);
+  } else { // Cu.import
+    const Cu = Components.utils;
+    const { require } =
+      Cu.import("resource://gre/modules/devtools/shared/Loader.jsm", {});
+    this.isWorker = false;
+    this.promise = Cu.import("resource://gre/modules/Promise.jsm", {}).Promise;
+    factory.call(this, require, this, { exports: this });
+    this.EXPORTED_SYMBOLS = ["EventEmitter"];
+  }
+}).call(this, function (require, exports, module) {
+  const { Cu } = require("chrome");
+  const Services = require("Services");
+  const WARNING_PREF = "devtools.migration.warnings";
+  // Cu and Services aren't accessible from workers
+  if (Cu && Services && Services.prefs &&
+      Services.prefs.getBoolPref(WARNING_PREF)) {
+    const { Deprecated } =
+      Cu.import("resource://gre/modules/Deprecated.jsm", {});
+    Deprecated.warning("This path to event-emitter.js is deprecated.  Please " +
+                       "use require(\"devtools/shared/event-emitter\") to " +
+                       "load this module.",
+                       "https://bugzil.la/912121");
+  }
+
+  const EventEmitter = require("devtools/shared/event-emitter");
+  this.EventEmitter = EventEmitter;
+  module.exports = EventEmitter;
+});
new file mode 100644
--- /dev/null
+++ b/devtools/shared/shims/moz.build
@@ -0,0 +1,17 @@
+# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+# Unlike most DevTools build files, this file does not use DevToolsModules
+# because these files are here for add-on compatibility, and so they must be
+# installed to previously defined locations.
+
+EXTRA_JS_MODULES.devtools += [
+    'Console.jsm',
+    'dbg-client.jsm',
+    'event-emitter.js',
+    'Loader.jsm',
+    'Simulator.jsm',
+]
--- a/mobile/android/tests/browser/chrome/test_debugger_server.html
+++ b/mobile/android/tests/browser/chrome/test_debugger_server.html
@@ -14,18 +14,19 @@ Migrated from Robocop: https://bugzilla.
 
   "use strict";
 
   const { utils: Cu } = Components;
 
   const DEBUGGER_USB_ENABLED = "devtools.remote.usb.enabled";
 
   Cu.import("resource://gre/modules/Services.jsm");
-  const { DebuggerServer } =
-    Cu.import("resource://gre/modules/devtools/server/dbg-server.jsm", {});
+  const { require } =
+    Cu.import("resource://gre/modules/devtools/shared/Loader.jsm", {});
+  const { DebuggerServer } = require("devtools/server/main");
 
   let win = Services.wm.getMostRecentWindow("navigator:browser");
 
   win.RemoteDebugger.init();
 
   SimpleTest.registerCleanupFunction(function() {
     Services.prefs.clearUserPref(DEBUGGER_USB_ENABLED);
   });
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -889,16 +889,20 @@ pref("devtools.gcli.imgurClientID", '0df
 pref("devtools.gcli.imgurUploadURL", "https://api.imgur.com/3/image");
 
 // GCLI commands directory
 pref("devtools.commands.dir", "");
 
 // Allows setting the performance marks for which telemetry metrics will be recorded.
 pref("devtools.telemetry.supported_performance_marks", "contentInteractive,navigationInteractive,navigationLoaded,visuallyLoaded,fullyLoaded,mediaEnumerated,scanEnd");
 
+// Deprecation warnings after DevTools file migration.  Bug 1204127 tracks
+// enabling this.
+pref("devtools.migration.warnings", false);
+
 // view source
 pref("view_source.syntax_highlight", true);
 pref("view_source.wrap_long_lines", false);
 pref("view_source.editor.external", false);
 pref("view_source.editor.path", "");
 // allows to add further arguments to the editor; use the %LINE% placeholder
 // for jumping to a specific line (e.g. "/line:%LINE%" or "--goto %LINE%")
 pref("view_source.editor.args", "");