Skip to content

Commit

Permalink
[embedlite-components] Cleanup C++ logging. JB#49804
Browse files Browse the repository at this point in the history
Logs can be enabled with EMBEDLITE_COMPONENTS_LOGGING=1
environment variable.
  • Loading branch information
rainemak committed May 15, 2020
1 parent 91dc56f commit 522a195
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 24 deletions.
2 changes: 1 addition & 1 deletion chromehelper/EmbedChromeListener.cpp
Expand Up @@ -5,10 +5,10 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "EmbedChromeListener.h"
#include "../logger/EmbedComponentsLog.h"

#include "nsServiceManagerUtils.h"
#include "nsIObserverService.h"
#include "mozilla/embedlite/EmbedLog.h"
#include "nsStringGlue.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsIDOMWindow.h"
Expand Down
5 changes: 1 addition & 4 deletions chromehelper/EmbedChromeManager.cpp
Expand Up @@ -4,15 +4,12 @@
* 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/. */

#define LOG_COMPONENT "EmbedChromeManager"
#include "mozilla/embedlite/EmbedLog.h"

#include "EmbedChromeManager.h"
#include "EmbedChromeListener.h"
#include "../logger/EmbedComponentsLog.h"

#include "nsServiceManagerUtils.h"
#include "nsIObserverService.h"

#include "nsStringGlue.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsIDOMWindow.h"
Expand Down
1 change: 1 addition & 0 deletions chromehelper/Makefile.am
Expand Up @@ -5,6 +5,7 @@ libchromehelper_la_SOURCES = \
EmbedChromeListener.cpp \
EmbedChromeManager.cpp \
nsEmbedChromeModule.cpp \
../logger/EmbedComponentsLog.cpp \
$(NULL)

libchromehelper_la_CPPFLAGS = \
Expand Down
2 changes: 2 additions & 0 deletions embedlite-components.pro
@@ -1,12 +1,14 @@
TEMPLATE = subdirs

SOURCES += chromehelper/*.cpp \
logger/*.cpp \
history/*.cpp \
prompt/*.cpp \
touchhelper/*.cpp \
widgetfactory/*.cpp

HEADERS += chromehelper/*.h \
logger/*.h \
history/*.h \
prompt/*.h \
touchhelper/*.h \
Expand Down
18 changes: 18 additions & 0 deletions logger/EmbedComponentsLog.cpp
@@ -0,0 +1,18 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* 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/.
*
* Copyright (c) 2020 Open Mobile Platform LLC.
*/

#include "EmbedComponentsLog.h"

#include <cstdlib>
#include <cstring>

bool mozilla::embedlite::LoggingEnabled()
{
static const char *hasEmbedLog = getenv("EMBEDLITE_COMPONENTS_LOGGING");
return hasEmbedLog && strcmp(hasEmbedLog, "1") == 0;
}
30 changes: 30 additions & 0 deletions logger/EmbedComponentsLog.h
@@ -0,0 +1,30 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* 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/.
*
* Copyright (c) 2020 Open Mobile Platform LLC.
*/

#ifndef MOZ_EMBEDLITE_COMPONENTS_LOG_H
#define MOZ_EMBEDLITE_COMPONENTS_LOG_H

#include <stdio.h>

namespace mozilla {
namespace embedlite {
bool LoggingEnabled();
}
}


#ifndef LOGT
#define LOGT(FMT, ...) if (mozilla::embedlite::LoggingEnabled()) { \
fprintf(stderr, \
"EmbedLiteComponents [%p] %s::%d: " FMT "\n", this, __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__); \
} else { \
do {} while (0); \
}
#endif

#endif
8 changes: 3 additions & 5 deletions prompt/EmbedPromptService.cpp
Expand Up @@ -3,10 +3,8 @@
* 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/. */

#define LOG_COMPONENT "EmbedPromptService"
#include "mozilla/embedlite/EmbedLog.h"

#include "EmbedPromptService.h"
#include "../logger/EmbedComponentsLog.h"

#include "nsStringGlue.h"
#include "nsIAuthPrompt.h"
Expand Down Expand Up @@ -912,10 +910,10 @@ EmbedAuthPromptService::DoResponseAsyncPrompt(EmbedAsyncAuthPrompt* prompt,
continue;
}
if (confirmed) {
// printf("Ok, calling onAuthAvailable to finish auth.\n");
LOGT("Ok, calling onAuthAvailable to finish auth.");
consumer->mCallback->OnAuthAvailable(consumer->mContext, prompt->mAuthInfo);
} else {
// printf("Cancelled, calling onAuthCancelled to finish auth.\n");
LOGT("Cancelled, calling onAuthCancelled to finish auth.");
consumer->mCallback->OnAuthCancelled(consumer->mContext, true);
}
}
Expand Down
1 change: 1 addition & 0 deletions prompt/Makefile.am
Expand Up @@ -6,6 +6,7 @@ libprompt_la_SOURCES = \
EmbedPromptService.cpp \
nsEmbedPromptModule.cpp \
../widgetfactory/EmbedliteGenericFactory.cpp \
../logger/EmbedComponentsLog.cpp \
nsAlertsService.cpp \
$(NULL)

Expand Down
22 changes: 12 additions & 10 deletions prompt/nsAlertsService.cpp
Expand Up @@ -3,6 +3,8 @@
* 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/. */

#include "../logger/EmbedComponentsLog.h"

#include "nsXULAppAPI.h"

#include "nsAlertsService.h"
Expand Down Expand Up @@ -31,7 +33,7 @@ nsEmbedAlertsService::~nsEmbedAlertsService()
bool nsEmbedAlertsService::ShouldShowAlert()
{
bool result = true;
printf(">>>>>>Func:%s::%d\n", __PRETTY_FUNCTION__, __LINE__);
LOGT("");
return result;
}

Expand All @@ -42,14 +44,14 @@ NS_IMETHODIMP nsEmbedAlertsService::ShowAlertNotification(const nsAString& aImag
const nsAString& aLang, const nsAString & data, nsIPrincipal *principal,
bool aInPrivateBrowsing, bool aRequireInteraction)
{
printf(">>>>>>Func:%s::%d image:%s, title:%s, text:%s, clickable:%i, cookie:%s, name:%s\n", __PRETTY_FUNCTION__, __LINE__,
NS_ConvertUTF16toUTF8(aImageUrl).get(),
NS_ConvertUTF16toUTF8(aAlertTitle).get(),
NS_ConvertUTF16toUTF8(aAlertText).get(),
aAlertTextClickable,
NS_ConvertUTF16toUTF8(aAlertCookie).get(),
NS_ConvertUTF16toUTF8(aAlertName).get()
);
LOGT("image: '%s', title: '%s', text: '%s', clickable: %i, cookie: '%s', name: '%s'", __PRETTY_FUNCTION__, __LINE__,
NS_ConvertUTF16toUTF8(aImageUrl).get(),
NS_ConvertUTF16toUTF8(aAlertTitle).get(),
NS_ConvertUTF16toUTF8(aAlertText).get(),
aAlertTextClickable,
NS_ConvertUTF16toUTF8(aAlertCookie).get(),
NS_ConvertUTF16toUTF8(aAlertName).get()
);

// Do not display the alert. Instead call alertfinished and get out.
if (aAlertListener)
Expand All @@ -60,6 +62,6 @@ NS_IMETHODIMP nsEmbedAlertsService::ShowAlertNotification(const nsAString& aImag

NS_IMETHODIMP nsEmbedAlertsService::CloseAlert(const nsAString & name, nsIPrincipal*)
{
printf("nsEmbedAlertsService::CloseAlert: name:%s", NS_ConvertUTF16toUTF8(name).get());
LOGT("name: '%s'", NS_ConvertUTF16toUTF8(name).get());
return NS_OK;
}
2 changes: 1 addition & 1 deletion touchhelper/EmbedTouchListener.cpp
Expand Up @@ -5,10 +5,10 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "EmbedTouchListener.h"
#include "../logger/EmbedComponentsLog.h"

#include "nsServiceManagerUtils.h"
#include "nsIObserverService.h"
#include "mozilla/embedlite/EmbedLog.h"

#include "nsIInterfaceRequestorUtils.h"
#include "nsIDOMWindow.h"
Expand Down
4 changes: 1 addition & 3 deletions touchhelper/EmbedTouchManager.cpp
Expand Up @@ -4,11 +4,9 @@
* 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/. */

#define LOG_COMPONENT "EmbedTouchManager"
#include "mozilla/embedlite/EmbedLog.h"

#include "EmbedTouchManager.h"
#include "EmbedTouchListener.h"
#include "../logger/EmbedComponentsLog.h"

#include "nsServiceManagerUtils.h"
#include "nsIObserverService.h"
Expand Down
1 change: 1 addition & 0 deletions touchhelper/Makefile.am
Expand Up @@ -5,6 +5,7 @@ libtouchhelper_la_SOURCES = \
nsEmbedTouchModule.cpp \
EmbedTouchManager.cpp \
EmbedTouchListener.cpp \
../logger/EmbedComponentsLog.cpp \
$(NULL)

libtouchhelper_la_CPPFLAGS = \
Expand Down

0 comments on commit 522a195

Please sign in to comment.