diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /devtools/shared/platform | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-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')
-rw-r--r-- | devtools/shared/platform/README.md | 13 | ||||
-rw-r--r-- | devtools/shared/platform/chrome/clipboard.js | 28 | ||||
-rw-r--r-- | devtools/shared/platform/chrome/moz.build | 10 | ||||
-rw-r--r-- | devtools/shared/platform/chrome/stack.js | 75 | ||||
-rw-r--r-- | devtools/shared/platform/content/.eslintrc.js | 12 | ||||
-rw-r--r-- | devtools/shared/platform/content/clipboard.js | 34 | ||||
-rw-r--r-- | devtools/shared/platform/content/moz.build | 16 | ||||
-rw-r--r-- | devtools/shared/platform/content/stack.js | 49 | ||||
-rw-r--r-- | devtools/shared/platform/content/test/.eslintrc.js | 6 | ||||
-rw-r--r-- | devtools/shared/platform/content/test/mochitest.ini | 5 | ||||
-rw-r--r-- | devtools/shared/platform/content/test/test_clipboard.html | 53 | ||||
-rw-r--r-- | devtools/shared/platform/content/test/test_stack.js | 48 | ||||
-rw-r--r-- | devtools/shared/platform/content/test/xpcshell.ini | 7 | ||||
-rw-r--r-- | devtools/shared/platform/moz.build | 10 |
14 files changed, 366 insertions, 0 deletions
diff --git a/devtools/shared/platform/README.md b/devtools/shared/platform/README.md new file mode 100644 index 000000000..84accd495 --- /dev/null +++ b/devtools/shared/platform/README.md @@ -0,0 +1,13 @@ +This directory is treated specially by the loaders. + +In particular, when running in chrome, a resource like +"devtools/shared/platform/mumble" will be found in the chrome +subdirectory; and when running in content, it will be found in the +content subdirectory. + +Outside of tests, it's not ok to require a specific version of a file; +and there is an eslint test to check for that. That is, +require("devtools/shared/platform/client/mumble") is an error. + +When adding a new file, you must add two copies, one to chrome and one +to content. Otherwise, one case or the other will fail to work. 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; +}); diff --git a/devtools/shared/platform/content/.eslintrc.js b/devtools/shared/platform/content/.eslintrc.js new file mode 100644 index 000000000..515fe0261 --- /dev/null +++ b/devtools/shared/platform/content/.eslintrc.js @@ -0,0 +1,12 @@ +"use strict"; + +module.exports = { + // Extend from the devtools eslintrc. + "extends": "../../../.eslintrc.js", + + "rules": { + /* eslint-disable max-len */ + // All code in this directory must be content-clean. + "mozilla/reject-some-requires": ["error", "^(chrome|chrome:.*|resource:.*|devtools/server/.*|.*\\.jsm|devtools/shared/platform/(chome|content)/.*)$"], + }, +}; diff --git a/devtools/shared/platform/content/clipboard.js b/devtools/shared/platform/content/clipboard.js new file mode 100644 index 000000000..b43b996c2 --- /dev/null +++ b/devtools/shared/platform/content/clipboard.js @@ -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/. */ + +// Helpers for clipboard handling. + +/* globals document */ + +"use strict"; + +function copyString(string) { + let doCopy = function (e) { + e.clipboardData.setData("text/plain", string); + e.preventDefault(); + }; + + document.addEventListener("copy", doCopy); + document.execCommand("copy", false, null); + document.removeEventListener("copy", doCopy); +} + +function getCurrentFlavors() { + // See bug 1295692. + return []; +} + +function getData() { + // See bug 1295692. + return null; +} + +exports.copyString = copyString; +exports.getCurrentFlavors = getCurrentFlavors; +exports.getData = getData; diff --git a/devtools/shared/platform/content/moz.build b/devtools/shared/platform/content/moz.build new file mode 100644 index 000000000..b62205eb8 --- /dev/null +++ b/devtools/shared/platform/content/moz.build @@ -0,0 +1,16 @@ +# -*- 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', +) + +XPCSHELL_TESTS_MANIFESTS += ['test/xpcshell.ini'] + +MOCHITEST_MANIFESTS += [ + 'test/mochitest.ini', +] diff --git a/devtools/shared/platform/content/stack.js b/devtools/shared/platform/content/stack.js new file mode 100644 index 000000000..87c7c4111 --- /dev/null +++ b/devtools/shared/platform/content/stack.js @@ -0,0 +1,49 @@ +/* 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 content code. Note that this particular copy of the +// file can only be loaded via require(), because Cu.import doesn't +// exist in the content case. So, we don't need the code to handle +// both require and import here. + +"use strict"; + +/** + * Looks like Cu.callFunctionWithAsyncStack, but just calls the callee. + */ +function callFunctionWithAsyncStack(callee, stack, id) { + return callee(); +} + +/** + * 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 stack = new Error().stack.split("\n"); + // Add one here to skip this function. + return stack[n + 1]; +} + +/** + * Return a stack object that can be serialized and, when + * deserialized, passed to callFunctionWithAsyncStack. + */ +function getStack() { + // There's no reason for this to do anything fancy, since it's only + // used to pass back into callFunctionWithAsyncStack, which we can't + // implement. + return null; +} + +exports.callFunctionWithAsyncStack = callFunctionWithAsyncStack; +exports.describeNthCaller = describeNthCaller; +exports.getStack = getStack; diff --git a/devtools/shared/platform/content/test/.eslintrc.js b/devtools/shared/platform/content/test/.eslintrc.js new file mode 100644 index 000000000..59adf410a --- /dev/null +++ b/devtools/shared/platform/content/test/.eslintrc.js @@ -0,0 +1,6 @@ +"use strict"; + +module.exports = { + // Extend from the common devtools xpcshell eslintrc config. + "extends": "../../../../.eslintrc.xpcshell.js" +}; diff --git a/devtools/shared/platform/content/test/mochitest.ini b/devtools/shared/platform/content/test/mochitest.ini new file mode 100644 index 000000000..f62cada6b --- /dev/null +++ b/devtools/shared/platform/content/test/mochitest.ini @@ -0,0 +1,5 @@ +[DEFAULT] +support-files = + +[test_clipboard.html] +subsuite = clipboard diff --git a/devtools/shared/platform/content/test/test_clipboard.html b/devtools/shared/platform/content/test/test_clipboard.html new file mode 100644 index 000000000..ccf5e6ccf --- /dev/null +++ b/devtools/shared/platform/content/test/test_clipboard.html @@ -0,0 +1,53 @@ +<!DOCTYPE html> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=1290230 +--> +<head> + <title>Test for Bug 1290230 - clipboard helpers</title> + <script type="text/javascript" src="/MochiKit/MochiKit.js"></script> + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" + href="chrome://mochikit/content/tests/SimpleTest/test.css"> + <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script> + +<script type="application/javascript;version=1.8"> +"use strict"; +var exports = {} +</script> + + <script type="application/javascript;version=1.8" + src="resource://devtools/shared/platform/content/clipboard.js"></script> + +</head> +<body onload="do_tests()"> +<script type="application/javascript;version=1.8"> +"use strict"; + +const RESULT = "lark bunting"; + +function doCopy(e) { + console.log(e.isTrusted); + copyString(RESULT); +} + +function do_tests() { + let elt = document.querySelector("#key"); + elt.addEventListener("keydown", doCopy); + + // Set the clipboard to something other than what we expect. + SpecialPowers.clipboardCopyString("snowy owl"); + + elt.focus(); + synthesizeKey("x", {}); + + is(SpecialPowers.getClipboardData("text/unicode"), RESULT, "clipboard copying worked"); + + SimpleTest.finish(); +} + +SimpleTest.waitForExplicitFinish(); + +</script> +<div id="key" tabindex="-1">Type Here</div> +</body> diff --git a/devtools/shared/platform/content/test/test_stack.js b/devtools/shared/platform/content/test/test_stack.js new file mode 100644 index 000000000..4dbb66541 --- /dev/null +++ b/devtools/shared/platform/content/test/test_stack.js @@ -0,0 +1,48 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// There isn't really very much about the content stack.js that we can +// test, but we'll do what we can. + +"use strict"; + +var Cu = Components.utils; +const {require} = Cu.import("resource://devtools/shared/Loader.jsm", {}); + +// Make sure to explicitly require the content version of this module. +// We have to use the ".." trick due to the way the loader remaps +// devtools/shared/platform. +const { + callFunctionWithAsyncStack, + getStack, + describeNthCaller +} = require("devtools/shared/platform/../content/stack"); + +function f3() { + return describeNthCaller(2); +} + +function f2() { + return f3(); +} + +function f1() { + return f2(); +} + +function run_test() { + let value = 7; + + const changeValue = () => { + value = 9; + }; + + callFunctionWithAsyncStack(changeValue, getStack(), "test_stack"); + equal(value, 9, "callFunctionWithAsyncStack worked"); + + let stack = getStack(); + equal(JSON.parse(JSON.stringify(stack)), stack, "stack is serializable"); + + let desc = f1(); + ok(desc.includes("f1"), "stack description includes f1"); +} diff --git a/devtools/shared/platform/content/test/xpcshell.ini b/devtools/shared/platform/content/test/xpcshell.ini new file mode 100644 index 000000000..fa475165a --- /dev/null +++ b/devtools/shared/platform/content/test/xpcshell.ini @@ -0,0 +1,7 @@ +[DEFAULT] +tags = devtools +head = +tail = +firefox-appdir = browser + +[test_stack.js] diff --git a/devtools/shared/platform/moz.build b/devtools/shared/platform/moz.build new file mode 100644 index 000000000..84f56dce1 --- /dev/null +++ b/devtools/shared/platform/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/. + +DIRS += [ + 'chrome', + 'content', +] |