Bug 1363327 - Redirect about:debugging to shim page if DevTools are not installed draft
authorJulian Descottes <jdescottes@mozilla.com>
Fri, 12 May 2017 16:00:22 +0200
changeset 576937 d903ca619091c9bef05e8a0e7d9c0b4f963621ce
parent 576936 8eedfe3fa2dcefcc94aaa2b3e61a3a03171f1fa8
child 628359 7b75e09243292c58219cb25c9ddf09c105063278
push id58535
push userjdescottes@mozilla.com
push dateFri, 12 May 2017 14:16:03 +0000
bugs1363327
milestone55.0a1
Bug 1363327 - Redirect about:debugging to shim page if DevTools are not installed MozReview-Commit-ID: 3ERYkov4hTq
devtools/shim/aboutdebugging-registration.js
devtools/shim/aboutdebugging/aboutdebugging-shim.js
devtools/shim/aboutdebugging/aboutdebugging.xhtml
devtools/shim/aboutdebugging/moz.build
devtools/shim/jar.mn
devtools/shim/moz.build
--- a/devtools/shim/aboutdebugging-registration.js
+++ b/devtools/shim/aboutdebugging-registration.js
@@ -6,36 +6,46 @@
 
 // Register about:devtools-toolbox which allows to open a devtools toolbox
 // in a Firefox tab or a custom html iframe in browser.html
 const Ci = Components.interfaces;
 const Cu = Components.utils;
 
 const { XPCOMUtils } = Cu.import("resource://gre/modules/XPCOMUtils.jsm", {});
 const { Services } = Cu.import("resource://gre/modules/Services.jsm", {});
+const { DevToolsShim } = Cu.import("chrome://devtools-shim/content/DevToolsShim.jsm", {});
 
 const { nsIAboutModule } = Ci;
 
 function AboutDebugging() {}
 
 AboutDebugging.prototype = {
-  uri: Services.io.newURI("chrome://devtools/content/aboutdebugging/aboutdebugging.xhtml"),
   classDescription: "about:debugging",
   classID: Components.ID("1060afaf-dc9e-43da-8646-23a2faf48493"),
   contractID: "@mozilla.org/network/protocol/about;1?what=debugging",
 
   QueryInterface: XPCOMUtils.generateQI([nsIAboutModule]),
 
   newChannel: function (uri, loadInfo) {
-    let chan = Services.io.newChannelFromURIWithLoadInfo(
-      this.uri,
+    let aboutDebuggingUri = DevToolsShim.isInstalled()
+        ? "chrome://devtools/content/aboutdebugging/aboutdebugging.xhtml"
+        : "chrome://devtools-shim/content/aboutdebugging/aboutdebugging.xhtml";
+
+    let channel = Services.io.newChannelFromURIWithLoadInfo(
+      Services.io.newURI(aboutDebuggingUri),
       loadInfo
     );
-    chan.owner = Services.scriptSecurityManager.getSystemPrincipal();
-    return chan;
+
+    // Make sure the URI remains about:debugging
+    channel.originalURI = uri;
+    loadInfo.resultPrincipalURI = uri;
+
+    channel.owner = Services.scriptSecurityManager.getSystemPrincipal();
+
+    return channel;
   },
 
   getURIFlags: function (uri) {
     return nsIAboutModule.ALLOW_SCRIPT || nsIAboutModule.ENABLE_INDEXED_DB;
   }
 };
 
 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([
new file mode 100644
--- /dev/null
+++ b/devtools/shim/aboutdebugging/aboutdebugging-shim.js
@@ -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/. */
+
+/* eslint-env browser */
+
+"use strict";
+
+Components.utils.import("chrome://devtools-shim/content/DevToolsShim.jsm");
+
+const AboutDebuggingShim = {
+  init() {
+    // Show the aboutdebugging shim UI
+    let container = document.querySelector(".aboutdebugging-shim-container");
+    container.classList.remove("hidden");
+
+    let button = document.querySelector(".devtools-install-button");
+    button.addEventListener("click", this.onInstallButtonClick);
+
+    // Listen to devtools-registered to load about:debugging when the DevTools addon
+    // has been installed.
+    DevToolsShim.on("devtools-registered", () => {
+      window.location.reload();
+    });
+  },
+
+  onInstallButtonClick() {
+    dump("Clicked on install button\n");
+    // TODO: Call the UI Shim install process.
+  },
+};
+
+window.addEventListener("DOMContentLoaded", function () {
+  AboutDebuggingShim.init();
+}, {once: true});
new file mode 100644
--- /dev/null
+++ b/devtools/shim/aboutdebugging/aboutdebugging.xhtml
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- 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/. -->
+
+<!DOCTYPE html [
+<!ENTITY % htmlDTD PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd"> %htmlDTD;
+<!ENTITY % globalDTD SYSTEM "chrome://global/locale/global.dtd"> %globalDTD;
+]>
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+  <head>
+    <title>About Debugging</title>
+    <link rel="stylesheet" href="chrome://global/skin/in-content/common.css" type="text/css"/>
+    <script type="application/javascript" src="chrome://devtools-shim/content/aboutdebugging/aboutdebugging-shim.js"></script>
+    <style type="text/css">
+      .aboutdebugging-shim-container {
+        display: flex;
+        justify-content: center;
+      }
+
+      .aboutdebugging-shim-container.hidden {
+        display: none;
+      }
+
+      .aboutdebugging-shim {
+        display: flex;
+        flex-direction: column;
+        align-items: center;
+        margin: 30px;
+        padding: 30px;
+        border: 1px solid #aaa;
+      }
+
+      .devtools-not-installed {
+        margin-bottom: 10px;
+      }
+    </style>
+  </head>
+  <body id="body" dir="&locale.dir;">
+    <div class="aboutdebugging-shim-container hidden">
+      <div class="aboutdebugging-shim">
+        <span class="devtools-not-installed">
+          DevTools need to be installed to use about:debugging.
+        </span>
+        <button class="devtools-install-button">
+          Install now!
+        </button>
+      </div>
+    </div>
+  </body>
+</html>
new file mode 100644
--- /dev/null
+++ b/devtools/shim/aboutdebugging/moz.build
@@ -0,0 +1,9 @@
+# -*- Mode: python; 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/.
+
+EXTRA_JS_MODULES += [
+    'aboutdebugging-shim.js',
+]
--- a/devtools/shim/jar.mn
+++ b/devtools/shim/jar.mn
@@ -1,3 +1,5 @@
 devtools-shim.jar:
 %   content devtools-shim %content/
     content/DevToolsShim.jsm  (DevToolsShim.jsm)
+    content/aboutdebugging/aboutdebugging.xhtml  (aboutdebugging/aboutdebugging.xhtml)
+    content/aboutdebugging/aboutdebugging-shim.js  (aboutdebugging/aboutdebugging-shim.js)
--- a/devtools/shim/moz.build
+++ b/devtools/shim/moz.build
@@ -1,5 +1,9 @@
 JAR_MANIFESTS += ['jar.mn']
 
+DIRS += [
+    'aboutdebugging',
+]
+
 EXTRA_JS_MODULES += [
     'DevToolsShim.jsm',
 ]
\ No newline at end of file