Bug 1425574 - Fill the feature gap between Console.jsm and Console API - part 7 - Console active, r=smaug
authorAndrea Marchesini <amarchesini@mozilla.com>
Thu, 04 Jan 2018 19:19:44 +0100
changeset 449554 9f44d89eda685123154dfb9a7ce5736a57b72429
parent 449553 0882de3b96b9e39a5075f4c2885ff9a8a2ac0d8b
child 449555 7a4e812ee5adc626ba19828f770d720f0b9db9cd
push id8527
push userCallek@gmail.com
push dateThu, 11 Jan 2018 21:05:50 +0000
treeherdermozilla-beta@95342d212a7a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1425574
milestone59.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 1425574 - Fill the feature gap between Console.jsm and Console API - part 7 - Console active, r=smaug
dom/console/Console.cpp
dom/console/Console.h
dom/console/ConsoleInstance.cpp
--- a/dom/console/Console.cpp
+++ b/dom/console/Console.cpp
@@ -815,16 +815,17 @@ Console::Create(nsPIDOMWindowInner* aWin
   return console.forget();
 }
 
 Console::Console(nsPIDOMWindowInner* aWindow)
   : mWindow(aWindow)
   , mOuterID(0)
   , mInnerID(0)
   , mDumpToStdout(false)
+  , mChromeInstance(false)
   , mStatus(eUnknown)
   , mCreationTimeStamp(TimeStamp::Now())
 {
   if (mWindow) {
     mInnerID = mWindow->WindowID();
 
     // Without outerwindow any console message coming from this object will not
     // shown in the devtools webconsole. But this should be fine because
@@ -1063,22 +1064,33 @@ Console::ProfileMethod(const GlobalObjec
   if (!console) {
     return;
   }
 
   JSContext* cx = aGlobal.Context();
   console->ProfileMethodInternal(cx, aAction, aData);
 }
 
+bool
+Console::IsEnabled(JSContext* aCx) const
+{
+  // Console is always enabled if it is a custom Chrome-Only instance.
+  if (mChromeInstance) {
+    return true;
+  }
+
+  // Make all Console API no-op if DevTools aren't enabled.
+  return nsContentUtils::DevToolsEnabled(aCx);
+}
+
 void
 Console::ProfileMethodInternal(JSContext* aCx, const nsAString& aAction,
                                const Sequence<JS::Value>& aData)
 {
-  // Make all Console API no-op if DevTools aren't enabled.
-  if (!nsContentUtils::DevToolsEnabled(aCx)) {
+  if (!IsEnabled(aCx)) {
     return;
   }
 
   MaybeExecuteDumpFunction(aCx, aAction, aData);
 
   if (!NS_IsMainThread()) {
     // Here we are in a worker thread.
     RefPtr<ConsoleProfileRunnable> runnable =
@@ -1222,18 +1234,17 @@ Console::Method(const GlobalObject& aGlo
                           aData);
 }
 
 void
 Console::MethodInternal(JSContext* aCx, MethodName aMethodName,
                         const nsAString& aMethodString,
                         const Sequence<JS::Value>& aData)
 {
-  // Make all Console API no-op if DevTools aren't enabled.
-  if (!nsContentUtils::DevToolsEnabled(aCx)) {
+  if (!IsEnabled(aCx)) {
     return;
   }
 
   AssertIsOnOwningThread();
 
   RefPtr<ConsoleCallData> callData(new ConsoleCallData());
 
   ClearException ce(aCx);
--- a/dom/console/Console.h
+++ b/dom/console/Console.h
@@ -393,16 +393,19 @@ private:
                            const Sequence<JS::Value>& aData);
 
   void
   MaybeExecuteDumpFunctionForTrace(JSContext* aCx, nsIStackFrame* aStack);
 
   void
   ExecuteDumpFunction(const nsAString& aMessage);
 
+  bool
+  IsEnabled(JSContext* aCx) const;
+
   // All these nsCOMPtr are touched on main thread only.
   nsCOMPtr<nsPIDOMWindowInner> mWindow;
   nsCOMPtr<nsIConsoleAPIStorage> mStorage;
   RefPtr<JSObjectHolder> mSandbox;
 
   // Touched on the owner thread.
   nsDataHashtable<nsStringHashKey, DOMHighResTimeStamp> mTimerRegistry;
   nsDataHashtable<nsStringHashKey, uint32_t> mCounterRegistry;
@@ -429,16 +432,17 @@ private:
   uint64_t mInnerID;
 
   // Set only by ConsoleInstance:
   nsString mConsoleID;
   nsString mPassedInnerID;
   RefPtr<ConsoleInstanceDumpCallback> mDumpFunction;
   bool mDumpToStdout;
   nsString mDumpPrefix;
+  bool mChromeInstance;
 
   enum {
     eUnknown,
     eInitialized,
     eShuttingDown
   } mStatus;
 
   // This is used when Console is created and it's used only for JSM custom
--- a/dom/console/ConsoleInstance.cpp
+++ b/dom/console/ConsoleInstance.cpp
@@ -28,16 +28,19 @@ ConsoleInstance::ConsoleInstance(const C
   if (aOptions.mDump.WasPassed()) {
     mConsole->mDumpFunction = &aOptions.mDump.Value();
   } else {
     // For historical reasons, ConsoleInstance prints messages on stdout.
     mConsole->mDumpToStdout = true;
   }
 
   mConsole->mDumpPrefix = aOptions.mPrefix;
+
+  // Let's inform that this is a custom instance.
+  mConsole->mChromeInstance = true;
 }
 
 ConsoleInstance::~ConsoleInstance()
 {}
 
 JSObject*
 ConsoleInstance::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
 {