Bug 1480544 - Allow Console API to log messages on stdout, r=bgrins
authorAndrea Marchesini <amarchesini@mozilla.com>
Thu, 15 Nov 2018 21:47:58 +0100
changeset 503151 210675b3647c5097e23b47ae1accb32412bad46d
parent 503150 fda2edef30ab3bb950b635d05470f5635a75a6e9
child 503152 2d70da7f951facbb18549d20834c82f619e0c3dc
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbgrins
bugs1480544
milestone65.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 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.
devtools/client/framework/toolbox-process-window.js
devtools/docs/getting-started/development-profiles.md
dom/console/Console.cpp
embedding/ios/GeckoEmbed/GeckoEmbed/browser/defaults/preferences/prefs.js
js/src/tests/user.js
js/xpconnect/src/XPCShellImpl.cpp
layout/tools/reftest/README.txt
mobile/android/app/mobile.js
modules/libpref/init/StaticPrefList.h
modules/libpref/init/all.js
services/fxaccounts/tests/mochitest/test_invalidEmailCase.html
testing/geckodriver/src/prefs.rs
testing/marionette/client/marionette_driver/geckoinstance.py
testing/profiles/common/user.js
testing/tps/tps/testrunner.py
testing/web-platform/tests/tools/wptrunner/wptrunner/browsers/fennec.py
--- a/devtools/client/framework/toolbox-process-window.js
+++ b/devtools/client/framework/toolbox-process-window.js
@@ -99,16 +99,17 @@ var connect = async function() {
 };
 
 // Certain options should be toggled since we can assume chrome debugging here
 function setPrefDefaults() {
   Services.prefs.setBoolPref("devtools.inspector.showUserAgentStyles", true);
   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);
   Services.prefs.setBoolPref("devtools.preference.new-panel-enabled", false);
   Services.prefs.setBoolPref("layout.css.emulate-moz-box-with-flex", false);
 
   Services.prefs.setBoolPref("devtools.performance.enabled", false);
 }
--- a/devtools/docs/getting-started/development-profiles.md
+++ b/devtools/docs/getting-started/development-profiles.md
@@ -24,16 +24,18 @@ Next time you start Firefox with `./mach
 
 ## Enable additional logging
 
 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`.<br /><br />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<br />(found at `devtools/shared/event-emitter.js`). |
 
 Preferences marked with a (`*`) also require `browser.dom.window.dump.enabled` in order to work. You might not want to enable *all* of those all the time, as they can cause the output to be way too verbose, but they might be useful if you're working on a server actor, for example<!--TODO link to actors doc-->.
 
 Restart the browser to apply configuration changes.
 
 ## Enable remote debugging and the Browser Toolbox
--- a/dom/console/Console.cpp
+++ b/dom/console/Console.cpp
@@ -1088,17 +1088,19 @@ Console::Console(JSContext* aCx, nsIGlob
   , mDumpToStdout(false)
   , mChromeInstance(false)
   , mMaxLogLevel(ConsoleLogLevel::All)
   , mStatus(eUnknown)
   , mCreationTimeStamp(TimeStamp::Now())
 {
   // 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);
 }
 
 Console::~Console()
 {
   AssertIsOnOwningThread();
--- 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);
--- a/js/src/tests/user.js
+++ b/js/src/tests/user.js
@@ -1,10 +1,11 @@
 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);
 user_pref("security.fileuri.strict_origin_policy", false);
 user_pref("dom.allow_scripts_to_close_windows", true);
 user_pref("dom.disable_open_during_load", false);
 user_pref("dom.max_script_run_time", 0);
 user_pref("dom.max_chrome_script_run_time", 0);
--- a/js/xpconnect/src/XPCShellImpl.cpp
+++ b/js/xpconnect/src/XPCShellImpl.cpp
@@ -1286,16 +1286,17 @@ XRE_XPCShellMain(int argc, char** argv, 
         if (NS_FAILED(rv)) {
             printf("NS_InitXPCOM2 failed!\n");
             return 1;
         }
 
         // 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();
         cx = jsapi.cx();
 
         // Override the default XPConnect interrupt callback. We could store the
         // old one and restore it before shutting down, but there's not really a
         // reason to bother.
--- a/layout/tools/reftest/README.txt
+++ b/layout/tools/reftest/README.txt
@@ -389,18 +389,19 @@ 4. Specification of default preferences
    overwrite them with the specified <preference> values.
 
 This test manifest format could be used by other harnesses, such as ones
 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.)
 
 At some point in the future there will hopefully be a cleaner way to do
 this.  For now, go to your object directory, and run (perhaps using
 MOZ_NO_REMOTE=1 or the -profile <directory> option)
 
 ./firefox -reftest /path/to/srcdir/mozilla/layout/reftests/reftest.list > reftest.out
--- a/mobile/android/app/mobile.js
+++ b/mobile/android/app/mobile.js
@@ -618,16 +618,17 @@ pref("browser.firstrun.show.localepicker
 //
 // On Android, you also need to do the following for the output
 // to show up in logcat:
 //
 // $ adb shell stop
 // $ 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);
 pref("media.realtime_decoder.enabled", true);
 
 pref("javascript.options.showInConsole", true);
 
 pref("full-screen-api.enabled", true);
--- a/modules/libpref/init/StaticPrefList.h
+++ b/modules/libpref/init/StaticPrefList.h
@@ -1771,16 +1771,34 @@ VARCACHE_PREF(
 //---------------------------------------------------------------------------
 
 VARCACHE_PREF(
   "devtools.enabled",
    devtools_enabled,
   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
 //---------------------------------------------------------------------------
 
 #ifdef NIGHTLY_BUILD
 # define PREF_VALUE true
 #else
 # define PREF_VALUE false
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -1091,20 +1091,24 @@ pref("toolkit.asyncshutdown.crash_timeou
 pref("toolkit.asyncshutdown.log", false);
 
 // Enable JS dump() function.
 // IMPORTANT: Keep this in condition in sync with StaticPrefList.h. The value
 // of MOZILLA_OFFICIAL is different between full and artifact builds, so without
 // 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);
 
 // Enable recording/replaying executions.
 #if defined(XP_MACOSX) && defined(NIGHTLY_BUILD)
 pref("devtools.recordreplay.enabled", true);
 pref("devtools.recordreplay.enableRewinding", true);
 #endif
--- a/services/fxaccounts/tests/mochitest/test_invalidEmailCase.html
+++ b/services/fxaccounts/tests/mochitest/test_invalidEmailCase.html
@@ -113,16 +113,17 @@ function runTest() {
     }
   );
 }
 
 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(); }
 );
 
 </script>
 </pre>
 </body>
 </html>
--- a/testing/geckodriver/src/prefs.rs
+++ b/testing/geckodriver/src/prefs.rs
@@ -13,16 +13,17 @@ lazy_static! {
         ("app.normandy.api_url", Pref::new("")),
 
         // Disable automatically upgrading Firefox
         ("app.update.disabledForTesting", Pref::new(true)),
 
         // 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)),
         ("browser.safebrowsing.downloads.enabled", Pref::new(false)),
         ("browser.safebrowsing.passwords.enabled", Pref::new(false)),
         ("browser.safebrowsing.malware.enabled", Pref::new(false)),
         ("browser.safebrowsing.phishing.enabled", Pref::new(false)),
 
--- a/testing/marionette/client/marionette_driver/geckoinstance.py
+++ b/testing/marionette/client/marionette_driver/geckoinstance.py
@@ -371,18 +371,19 @@ class GeckoInstance(object):
             self.prefs = None
 
         self.close(clean=clean)
         self.start()
 
 
 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,
         "browser.snippets.syncPromo.enabled": False,
         "browser.snippets.firstrunHomepage.enabled": False,
 
         # Disable safebrowsing components
         "browser.safebrowsing.blockedURIs.enabled": False,
@@ -499,18 +500,19 @@ class DesktopInstance(GeckoInstance):
         # app.update.enabled is being removed. Once Firefox 62 becomes stable,
         # the line below can be removed as well.
         "app.update.enabled": False,
 
         # Don't show the content blocking introduction panel
         # 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
         "browser.download.panel.shown": True,
 
         # Do not show the EULA notification which can interfer with tests
         "browser.EULA.override": True,
 
--- a/testing/profiles/common/user.js
+++ b/testing/profiles/common/user.js
@@ -1,13 +1,14 @@
 // Common preferences file used by both unittest and perf harnesses.
 /* globals user_pref */
 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);
 user_pref("browser.newtabpage.activity-stream.feeds.snippets", false);
 user_pref("browser.newtabpage.activity-stream.tippyTop.service.endpoint", "");
 // For Activity Stream firstrun page, use an empty string to avoid fetching.
 user_pref("browser.newtabpage.activity-stream.fxaccounts.endpoint", "");
 // Tell the search service we are running in the US.  This also has the desired
--- a/testing/tps/tps/testrunner.py
+++ b/testing/tps/tps/testrunner.py
@@ -54,16 +54,17 @@ class TPSTestRunner(object):
         'MOZ_NO_REMOTE': '1',
         'XPCOM_DEBUG_BREAK': 'warn',
     }
 
     default_preferences = {
         '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,
         'browser.warnOnQuit': False,
         # Allow installing extensions dropped into the profile folder
         'extensions.autoDisableScopes': 10,
         'extensions.getAddons.get.url': 'http://127.0.0.1:4567/addons/api/%IDS%.json',
         # Our pretend addons server doesn't support metadata...
--- a/testing/web-platform/tests/tools/wptrunner/wptrunner/browsers/fennec.py
+++ b/testing/web-platform/tests/tools/wptrunner/wptrunner/browsers/fennec.py
@@ -34,18 +34,19 @@ from .firefox import (get_timeout_multip
 
 class FennecProfile(FirefoxProfile):
     # WPT-specific prefs are set in FennecBrowser.start()
     FirefoxProfile.preferences.update({
         # Make sure Shield doesn't hit the network.
         "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,
         "browser.safebrowsing.passwords.enabled": False,
         "browser.safebrowsing.malware.enabled": False,
         "browser.safebrowsing.phishing.enabled": False,
         # Do not restore the last open set of tabs if the browser has crashed
         "browser.sessionstore.resume_from_crash": False,