summaryrefslogtreecommitdiffstats
path: root/devtools/shared/platform/chrome
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /devtools/shared/platform/chrome
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'devtools/shared/platform/chrome')
-rw-r--r--devtools/shared/platform/chrome/clipboard.js28
-rw-r--r--devtools/shared/platform/chrome/moz.build10
-rw-r--r--devtools/shared/platform/chrome/stack.js75
3 files changed, 113 insertions, 0 deletions
diff --git a/devtools/shared/platform/chrome/clipboard.js b/devtools/shared/platform/chrome/clipboard.js
new file mode 100644
index 000000000..fd98dfbc5
--- /dev/null
+++ b/devtools/shared/platform/chrome/clipboard.js
@@ -0,0 +1,28 @@
+/* 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/. */
+
+// Helpers for clipboard handling.
+
+"use strict";
+
+const {Cc, Ci} = require("chrome");
+const clipboardHelper = Cc["@mozilla.org/widget/clipboardhelper;1"]
+ .getService(Ci.nsIClipboardHelper);
+var clipboard = require("sdk/clipboard");
+
+function copyString(string) {
+ clipboardHelper.copyString(string);
+}
+
+function getCurrentFlavors() {
+ return clipboard.currentFlavors;
+}
+
+function getData() {
+ return clipboard.get();
+}
+
+exports.copyString = copyString;
+exports.getCurrentFlavors = getCurrentFlavors;
+exports.getData = getData;
diff --git a/devtools/shared/platform/chrome/moz.build b/devtools/shared/platform/chrome/moz.build
new file mode 100644
index 000000000..bb3bdacbb
--- /dev/null
+++ b/devtools/shared/platform/chrome/moz.build
@@ -0,0 +1,10 @@
+# -*- 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/.
+
+DevToolsModules(
+ 'clipboard.js',
+ 'stack.js',
+)
diff --git a/devtools/shared/platform/chrome/stack.js b/devtools/shared/platform/chrome/stack.js
new file mode 100644
index 000000000..abbe54120
--- /dev/null
+++ b/devtools/shared/platform/chrome/stack.js
@@ -0,0 +1,75 @@
+/* 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/. */
+
+// A few wrappers for stack-manipulation. This version of the module
+// is used in chrome code.
+
+"use strict";
+
+(function (factory) {
+ // This file might be require()d, but might also be loaded via
+ // Cu.import. Account for the differences here.
+ if (this.module && module.id.indexOf("stack") >= 0) {
+ // require.
+ const {components, Cu} = require("chrome");
+ factory.call(this, components, Cu, exports);
+ } else {
+ // Cu.import.
+ this.isWorker = false;
+ factory.call(this, Components, Components.utils, this);
+ this.EXPORTED_SYMBOLS = ["callFunctionWithAsyncStack", "describeNthCaller",
+ "getStack"];
+ }
+}).call(this, function (components, Cu, exports) {
+ /**
+ * Return a description of the Nth caller, suitable for logging.
+ *
+ * @param {Number} n the caller to describe
+ * @return {String} a description of the nth caller.
+ */
+ function describeNthCaller(n) {
+ if (isWorker) {
+ return "";
+ }
+
+ let caller = components.stack;
+ // Do one extra iteration to skip this function.
+ while (n >= 0) {
+ --n;
+ caller = caller.caller;
+ }
+
+ let func = caller.name;
+ let file = caller.filename;
+ if (file.includes(" -> ")) {
+ file = caller.filename.split(/ -> /)[1];
+ }
+ let path = file + ":" + caller.lineNumber;
+
+ return func + "() -> " + path;
+ }
+
+ /**
+ * Return a stack object that can be serialized and, when
+ * deserialized, passed to callFunctionWithAsyncStack.
+ */
+ function getStack() {
+ return components.stack.caller;
+ }
+
+ /**
+ * Like Cu.callFunctionWithAsyncStack but handles the isWorker case
+ * -- |Cu| isn't defined in workers.
+ */
+ function callFunctionWithAsyncStack(callee, stack, id) {
+ if (isWorker) {
+ return callee();
+ }
+ return Cu.callFunctionWithAsyncStack(callee, stack, id);
+ }
+
+ exports.callFunctionWithAsyncStack = callFunctionWithAsyncStack;
+ exports.describeNthCaller = describeNthCaller;
+ exports.getStack = getStack;
+});