Bug 1577079 - Fix source download feature r=jlast
authorDavid Walsh <dwalsh@mozilla.com>
Thu, 29 Aug 2019 16:21:32 +0000
changeset 551200 b1248ff798589712c53e7d5de49eebf596ee67ed
parent 551199 851753e78f79f73adeb7e488ffcc3ef76098e6b1
child 551201 8df1e9b9f39367a06d3c3eb3c53b41ded6ffa8cc
push id11865
push userbtara@mozilla.com
push dateMon, 02 Sep 2019 08:54:37 +0000
treeherdermozilla-beta@37f59c4671b3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjlast
bugs1577079
milestone70.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 1577079 - Fix source download feature r=jlast Differential Revision: https://phabricator.services.mozilla.com/D44012
devtools/client/debugger/flow-typed/npm-custom/devtools-shared-utils_vx.x.x.js
devtools/client/debugger/src/utils/utils.js
devtools/client/shared/build/build-debugger.js
new file mode 100644
--- /dev/null
+++ b/devtools/client/debugger/flow-typed/npm-custom/devtools-shared-utils_vx.x.x.js
@@ -0,0 +1,7 @@
+/* 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/>. */
+
+declare module "devtools-shared-utils" {
+  declare module.exports: any;
+}
--- a/devtools/client/debugger/src/utils/utils.js
+++ b/devtools/client/debugger/src/utils/utils.js
@@ -1,15 +1,16 @@
 /* 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/>. */
 
 // @flow
 
 import type { SourceContent } from "../types";
+import { saveAs } from "devtools-shared-utils";
 
 /**
  * Utils for utils, by utils
  * @module utils/utils
  */
 
 /**
  * @memberof utils/utils
@@ -55,28 +56,11 @@ export function waitForMs(ms: number): P
   return new Promise(resolve => setTimeout(resolve, ms));
 }
 
 export function downloadFile(content: SourceContent, fileName: string) {
   if (content.type !== "text") {
     return;
   }
 
-  const { body } = document;
-  if (!body) {
-    return;
-  }
-
-  const data = content.value;
-  const a = document.createElement("a");
-  const href = window.URL.createObjectURL(
-    new Blob([data], { type: "text/javascript" })
-  );
-
-  body.appendChild(a);
-  a.className = "download-anchor";
-  a.href = href;
-  a.setAttribute("download", fileName);
-  a.click();
-  body.removeChild(a);
-
-  window.URL.revokeObjectURL(href);
+  const data = new TextEncoder().encode(content.value);
+  saveAs(window, data, fileName);
 }
--- a/devtools/client/shared/build/build-debugger.js
+++ b/devtools/client/shared/build/build-debugger.js
@@ -25,16 +25,17 @@ const mappings = {
   react: "devtools/client/shared/vendor/react",
   "react-dom": "devtools/client/shared/vendor/react-dom",
   "react-dom-factories": "devtools/client/shared/vendor/react-dom-factories",
   "react-redux": "devtools/client/shared/vendor/react-redux",
   redux: "devtools/client/shared/vendor/redux",
   reselect: "devtools/client/shared/vendor/reselect",
   "prop-types": "devtools/client/shared/vendor/react-prop-types",
   "devtools-services": "Services",
+  "devtools-shared-utils": "devtools/shared/DevToolsUtils",
   "wasmparser/dist/WasmParser": "devtools/client/shared/vendor/WasmParser",
   "wasmparser/dist/WasmDis": "devtools/client/shared/vendor/WasmDis",
   "whatwg-url": "devtools/client/shared/vendor/whatwg-url",
   "framework-actions": "devtools/client/framework/actions/index",
   "inspector-shared-utils": "devtools/client/inspector/shared/utils",
   ...EXCLUDED_FILES,
 };