From c0950f9d8a28a132d920c6c133148118ddfb641b Mon Sep 17 00:00:00 2001 From: Andrea Marchesini Date: Thu, 15 Nov 2018 21:47:58 +0100 Subject: [PATCH] Bug 1480544 - Allow Console API to log messages on stdout, r=bgrins This patch introduces 2 new prefs: - devtools.console.stdout.chrome: if true, console API writes on stdout when used by chrome code - devtools.console.stdout.content: console API write on stdout when used by content code. --- .../client/framework/toolbox-process-window.js | 1 + .../getting-started/development-profiles.md | 2 ++ dom/console/Console.cpp | 4 +++- .../browser/defaults/preferences/prefs.js | 1 + js/src/tests/user.js | 1 + js/xpconnect/src/XPCShellImpl.cpp | 1 + layout/tools/reftest/README.txt | 5 +++-- mobile/android/app/mobile.js | 1 + modules/libpref/init/StaticPrefList.h | 18 ++++++++++++++++++ modules/libpref/init/all.js | 4 ++++ .../tests/mochitest/test_invalidEmailCase.html | 1 + testing/geckodriver/src/prefs.rs | 1 + .../client/marionette_driver/geckoinstance.py | 6 ++++-- testing/profiles/common/user.js | 1 + testing/tps/tps/testrunner.py | 1 + .../wptrunner/wptrunner/browsers/fennec.py | 3 ++- 16 files changed, 45 insertions(+), 6 deletions(-) diff --git a/devtools/client/framework/toolbox-process-window.js b/devtools/client/framework/toolbox-process-window.js index a44a16e09eb0..05cd0f3a47b3 100644 --- a/devtools/client/framework/toolbox-process-window.js +++ b/devtools/client/framework/toolbox-process-window.js @@ -104,6 +104,7 @@ function setPrefDefaults() { Services.prefs.setBoolPref("devtools.performance.ui.show-platform-data", true); Services.prefs.setBoolPref("devtools.inspector.showAllAnonymousContent", true); Services.prefs.setBoolPref("browser.dom.window.dump.enabled", true); + Services.prefs.setBoolPref("devtools.console.stdout.chrome", true); Services.prefs.setBoolPref("devtools.command-button-noautohide.enabled", true); // Bug 1225160 - Using source maps with browser debugging can lead to a crash Services.prefs.setBoolPref("devtools.debugger.source-maps-enabled", false); diff --git a/devtools/docs/getting-started/development-profiles.md b/devtools/docs/getting-started/development-profiles.md index 5d141a425b15..d1ce89231826 100644 --- a/devtools/docs/getting-started/development-profiles.md +++ b/devtools/docs/getting-started/development-profiles.md @@ -29,6 +29,8 @@ You can change the value of these preferences by going to `about:config`: | Preference name | Value | Comments | | --------------- | --------------- | -------- | | `browser.dom.window.dump.enabled` | `true` | Adds global `dump` function to log strings to `stdout` | +| `devtools.console.stdout.chrome` | `true` | Allows console API to write to `stdout` when used by chrome content | +| `devtools.console.stdout.content` | `true` | Allows console API to write to `stdout` when used by content | | `devtools.debugger.log` (*) | `true` | Dump packets sent over remote debugging protocol to `stdout`.

The [remote protocol inspector add-on](https://github.com/firebug/rdp-inspector/wiki) might be useful too. | | `devtools.dump.emit` (*) | `true` | Log event notifications from the EventEmitter class
(found at `devtools/shared/event-emitter.js`). | diff --git a/dom/console/Console.cpp b/dom/console/Console.cpp index f90d38b84d54..e4860c4d6eea 100644 --- a/dom/console/Console.cpp +++ b/dom/console/Console.cpp @@ -1093,7 +1093,9 @@ Console::Console(JSContext* aCx, nsIGlobalObject* aGlobal, { // Let's enable the dumping to stdout by default for chrome. if (nsContentUtils::ThreadsafeIsSystemCaller(aCx)) { - mDumpToStdout = DOMPrefs::DumpEnabled(); + mDumpToStdout = StaticPrefs::devtools_console_stdout_chrome(); + } else { + mDumpToStdout = StaticPrefs::devtools_console_stdout_content(); } mozilla::HoldJSObjects(this); diff --git a/embedding/ios/GeckoEmbed/GeckoEmbed/browser/defaults/preferences/prefs.js b/embedding/ios/GeckoEmbed/GeckoEmbed/browser/defaults/preferences/prefs.js index 464b02234842..124a79b02fd0 100644 --- a/embedding/ios/GeckoEmbed/GeckoEmbed/browser/defaults/preferences/prefs.js +++ b/embedding/ios/GeckoEmbed/GeckoEmbed/browser/defaults/preferences/prefs.js @@ -1,3 +1,4 @@ pref("toolkit.defaultChromeURI", "chrome://mybrowser/content/hello.xul"); pref("browser.dom.window.dump.enabled", true); +pref("devtools.console.stdout.chrome", true); pref("dom.max_script_run_time", 0); diff --git a/js/src/tests/user.js b/js/src/tests/user.js index a82dbd06eb30..364219870aef 100755 --- a/js/src/tests/user.js +++ b/js/src/tests/user.js @@ -1,5 +1,6 @@ user_pref("app.update.disabledForTesting", true); user_pref("browser.dom.window.dump.enabled", true); +user_pref("devtools.console.stdout.chrome", true); user_pref("browser.sessionstore.resume_from_crash", false); user_pref("browser.shell.checkDefaultBrowser", false); user_pref("browser.xul.error_pages.enabled", true); diff --git a/js/xpconnect/src/XPCShellImpl.cpp b/js/xpconnect/src/XPCShellImpl.cpp index 2cc28c901429..6715a1900a6f 100644 --- a/js/xpconnect/src/XPCShellImpl.cpp +++ b/js/xpconnect/src/XPCShellImpl.cpp @@ -1291,6 +1291,7 @@ XRE_XPCShellMain(int argc, char** argv, char** envp, // xpc::ErrorReport::LogToConsoleWithStack needs this to print errors // to stderr. Preferences::SetBool("browser.dom.window.dump.enabled", true); + Preferences::SetBool("devtools.console.stdout.chrome", true); AutoJSAPI jsapi; jsapi.Init(); diff --git a/layout/tools/reftest/README.txt b/layout/tools/reftest/README.txt index b8e574eab15a..e67477532803 100644 --- a/layout/tools/reftest/README.txt +++ b/layout/tools/reftest/README.txt @@ -394,8 +394,9 @@ that do not depend on XUL, or even ones testing other layout engines. Running Tests ============= -(If you're not using a DEBUG build, first set browser.dom.window.dump.enabled -to true (in about:config, in the profile you'll be using to run the tests). +(If you're not using a DEBUG build, first set browser.dom.window.dump.enabled, +devtools.console.stdout.chrome and devtools.console.stdout.content to true (in +about:config, in the profile you'll be using to run the tests). Create the option as a new boolean if it doesn't exist already. If you skip this step you won't get any output in the terminal.) diff --git a/mobile/android/app/mobile.js b/mobile/android/app/mobile.js index 25c8bd0416e8..9830f5596b3e 100644 --- a/mobile/android/app/mobile.js +++ b/mobile/android/app/mobile.js @@ -623,6 +623,7 @@ pref("browser.firstrun.show.localepicker", false); // $ adb shell setprop log.redirect-stdio true // $ adb shell start pref("browser.dom.window.dump.enabled", true); +pref("devtools.console.stdout.chrome", true); // controls if we want camera support pref("device.camera.enabled", true); diff --git a/modules/libpref/init/StaticPrefList.h b/modules/libpref/init/StaticPrefList.h index 9e8cff8800b4..5f61fe02c725 100644 --- a/modules/libpref/init/StaticPrefList.h +++ b/modules/libpref/init/StaticPrefList.h @@ -1776,6 +1776,24 @@ VARCACHE_PREF( RelaxedAtomicBool, false ) +#ifdef MOZILLA_OFFICIAL +# define PREF_VALUE false +#else +# define PREF_VALUE true +#endif +VARCACHE_PREF( + "devtools.console.stdout.chrome", + devtools_console_stdout_chrome, + RelaxedAtomicBool, PREF_VALUE +) +#undef PREF_VALUE + +VARCACHE_PREF( + "devtools.console.stdout.content", + devtools_console_stdout_content, + RelaxedAtomicBool, false +) + //--------------------------------------------------------------------------- // Feature-Policy prefs //--------------------------------------------------------------------------- diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js index f0882fc39f5b..9a825bb99a08 100644 --- a/modules/libpref/init/all.js +++ b/modules/libpref/init/all.js @@ -1096,10 +1096,14 @@ pref("toolkit.asyncshutdown.log", false); // it being specified, dump is disabled in artifact builds (see Bug 1490412). #ifdef MOZILLA_OFFICIAL pref("browser.dom.window.dump.enabled", false, sticky); +pref("devtools.console.stdout.chrome", false, sticky); #else pref("browser.dom.window.dump.enabled", true, sticky); +pref("devtools.console.stdout.chrome", true, sticky); #endif +pref("devtools.console.stdout.content", false, sticky); + // Controls whether EventEmitter module throws dump message on each emit pref("toolkit.dump.emit", false); diff --git a/services/fxaccounts/tests/mochitest/test_invalidEmailCase.html b/services/fxaccounts/tests/mochitest/test_invalidEmailCase.html index 59d00016ea09..d95d9d18e2cd 100644 --- a/services/fxaccounts/tests/mochitest/test_invalidEmailCase.html +++ b/services/fxaccounts/tests/mochitest/test_invalidEmailCase.html @@ -118,6 +118,7 @@ SpecialPowers.pushPrefEnv({"set": [ ["identity.fxaccounts.enabled", true], // fx accounts ["identity.fxaccounts.auth.uri", TEST_SERVER], // our sjs server ["browser.dom.window.dump.enabled", true], + ["devtools.console.stdout.chrome", true], ]}, function() { runTest(); } ); diff --git a/testing/geckodriver/src/prefs.rs b/testing/geckodriver/src/prefs.rs index 57aadc2ff4c4..d23a504243b2 100644 --- a/testing/geckodriver/src/prefs.rs +++ b/testing/geckodriver/src/prefs.rs @@ -18,6 +18,7 @@ lazy_static! { // Enable the dump function, which sends messages to the system // console ("browser.dom.window.dump.enabled", Pref::new(true)), + ("devtools.console.stdout.chrome", Pref::new(true)), // Disable safebrowsing components ("browser.safebrowsing.blockedURIs.enabled", Pref::new(false)), diff --git a/testing/marionette/client/marionette_driver/geckoinstance.py b/testing/marionette/client/marionette_driver/geckoinstance.py index f4eb0a8abfbe..cee88aae7efc 100644 --- a/testing/marionette/client/marionette_driver/geckoinstance.py +++ b/testing/marionette/client/marionette_driver/geckoinstance.py @@ -376,8 +376,9 @@ class GeckoInstance(object): class FennecInstance(GeckoInstance): fennec_prefs = { - # Enable output of dump() + # Enable output for dump() and chrome console API "browser.dom.window.dump.enabled": True, + "devtools.console.stdout.chrome": True, # Disable Android snippets "browser.snippets.enabled": False, @@ -504,8 +505,9 @@ class DesktopInstance(GeckoInstance): # We use a larger number than the default 22 to have some buffer "browser.contentblocking.introCount": 99, - # Enable output of dump() + # Enable output for dump() and chrome console API "browser.dom.window.dump.enabled": True, + "devtools.console.stdout.chrome": True, # Indicate that the download panel has been shown once so that whichever # download test runs first doesn"t show the popup inconsistently diff --git a/testing/profiles/common/user.js b/testing/profiles/common/user.js index 4eee7bc528f3..8b3037d12308 100644 --- a/testing/profiles/common/user.js +++ b/testing/profiles/common/user.js @@ -3,6 +3,7 @@ user_pref("app.update.disabledForTesting", true); user_pref("browser.chrome.guess_favicon", false); user_pref("browser.dom.window.dump.enabled", true); +user_pref("devtools.console.stdout.chrome", true); // Use a python-eval-able empty JSON array even though asrouter expects plain object user_pref("browser.newtabpage.activity-stream.asrouter.providers.snippets", "[]"); user_pref("browser.newtabpage.activity-stream.feeds.section.topstories", false); diff --git a/testing/tps/tps/testrunner.py b/testing/tps/tps/testrunner.py index 560baa7f4c57..c2537ee72f73 100644 --- a/testing/tps/tps/testrunner.py +++ b/testing/tps/tps/testrunner.py @@ -59,6 +59,7 @@ class TPSTestRunner(object): 'app.update.disabledForTesting': True, 'security.turn_off_all_security_so_that_viruses_can_take_over_this_computer': True, 'browser.dom.window.dump.enabled': True, + 'devtools.console.stdout.chrome': True, 'browser.sessionstore.resume_from_crash': False, 'browser.shell.checkDefaultBrowser': False, 'browser.tabs.warnOnClose': False, diff --git a/testing/web-platform/tests/tools/wptrunner/wptrunner/browsers/fennec.py b/testing/web-platform/tests/tools/wptrunner/wptrunner/browsers/fennec.py index 0e40cec048ac..87216822e1d7 100644 --- a/testing/web-platform/tests/tools/wptrunner/wptrunner/browsers/fennec.py +++ b/testing/web-platform/tests/tools/wptrunner/wptrunner/browsers/fennec.py @@ -39,8 +39,9 @@ class FennecProfile(FirefoxProfile): "app.normandy.api_url": "", # Increase the APZ content response timeout in tests to 1 minute. "apz.content_response_timeout": 60000, - # Enable output of dump() + # Enable output for dump() and chrome console API "browser.dom.window.dump.enabled": True, + "devtools.console.stdout.chrome": True, # Disable safebrowsing components "browser.safebrowsing.blockedURIs.enabled": False, "browser.safebrowsing.downloads.enabled": False,