Bug 1425574 - Fill the feature gap between Console.jsm and Console API - part 7 - Console active, r=smaug

This commit is contained in:
Andrea Marchesini 2018-01-04 19:19:44 +01:00
parent 3768013399
commit 331c19665d
3 changed files with 22 additions and 4 deletions

View File

@ -820,6 +820,7 @@ Console::Console(nsPIDOMWindowInner* aWindow)
, mOuterID(0)
, mInnerID(0)
, mDumpToStdout(false)
, mChromeInstance(false)
, mStatus(eUnknown)
, mCreationTimeStamp(TimeStamp::Now())
{
@ -1068,12 +1069,23 @@ Console::ProfileMethod(const GlobalObject& aGlobal, const nsAString& aAction,
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;
}
@ -1227,8 +1239,7 @@ 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;
}

View File

@ -398,6 +398,9 @@ private:
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;
@ -434,6 +437,7 @@ private:
RefPtr<ConsoleInstanceDumpCallback> mDumpFunction;
bool mDumpToStdout;
nsString mDumpPrefix;
bool mChromeInstance;
enum {
eUnknown,

View File

@ -33,6 +33,9 @@ ConsoleInstance::ConsoleInstance(const ConsoleInstanceOptions& aOptions)
}
mConsole->mDumpPrefix = aOptions.mPrefix;
// Let's inform that this is a custom instance.
mConsole->mChromeInstance = true;
}
ConsoleInstance::~ConsoleInstance()