Mozilla/mozilla/java/webclient/src_moz/DocumentLoaderObserverImpl.cpp
edburns%acm.org 6bd98defd0 bug: http://bugzilla.mozilla.org/show_bug.cgi?id=34665
This change replaces all printfs in src_moz with calls to PR_LOG.  No
printfs should appear in src_moz anymore.

You won't see any console output from native code unless you define

NSPR_LOG_MODULES=webclient:3

in your environment.  Furthermore, if you want PR_LOG statements in
webclient to go to a file instead, define

WEBCLIENT_LOG_FILE=C:\VALIDDIR\filename.txt

in your environment.  This file will get created fresh each time, since
PR_LOG uses fopen(filename, "w").

New Files:

I've created ns_globals.h, included from jni_util.h.  ns_globals.h holds
an extern * to a struct used in the PR_LOG calls.

Significant changes:

WrapperFactoryImpl.cpp

nativeAppInitialize(){

Added:

#if DEBUG_RAPTOR_CANVAS
    prLogModuleInfo = PR_NewLogModule("webclient");
    const char *webclientLogFile = PR_GetEnv("WEBCLIENT_LOG_FILE");
    if (nsnull != webclientLogFile) {
        PR_SetLogFile(webclientLogFile);
        // If this fails, it just goes to stdout/stderr
    }
#endif
}

All the other files in this checkin follow the this pattern:

Before checkin:

       printf("InitMozillaStuff(%lx): Create the Event Queue for the UI thread...\n",
               initContext);

After checkin:

    if (prLogModuleInfo) {
        PR_LOG(prLogModuleInfo, 3,
               ("InitMozillaStuff(%lx): Create the Event Queue for the UI thread...\n",
               initContext));
    }

See http://lxr.mozilla.org/mozilla/source/nsprpub/pr/include/prlog.h#190

for the definition of PR_LOG


git-svn-id: svn://10.0.0.236/trunk@65380 18797224-902f-48f8-a5cc-f745e15eee43
2000-04-05 21:38:27 +00:00

265 lines
7.3 KiB
C++

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is RaptorCanvas.
*
* The Initial Developer of the Original Code is Kirk Baker and
* Ian Wilkinson. Portions created by Kirk Baker and Ian Wilkinson are
* Copyright (C) 1999 Kirk Baker and Ian Wilkinson. All
* Rights Reserved.
*
* Contributor(s): Kirk Baker <kbaker@eb.com>
* Ian Wilkinson <iw@ennoble.com>
* Mark Lin <mark.lin@eng.sun.com>
* Mark Goddard
* Ed Burns <edburns@acm.org>
* Ann Sunhachawee
*/
#include "DocumentLoaderObserverImpl.h"
#include "nsString.h"
#include "DocumentLoaderObserverImpl.h"
#include<stdio.h>
#include "jni_util.h"
#include "nsActions.h"
#ifdef XP_PC
// PENDING(edburns): take this out
#include "winbase.h"
// end of take this out
#endif
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIDocumentLoaderObserverIID, NS_IDOCUMENT_LOADER_OBSERVER_IID);
jlong DocumentLoaderObserverImpl::maskValues[] = { -1L };
char *DocumentLoaderObserverImpl::maskNames[] = {
"START_DOCUMENT_LOAD_EVENT_MASK",
"END_DOCUMENT_LOAD_EVENT_MASK",
"START_URL_LOAD_EVENT_MASK",
"END_URL_LOAD_EVENT_MASK",
"PROGRESS_URL_LOAD_EVENT_MASK",
"STATUS_URL_LOAD_EVENT_MASK",
"UNKNOWN_CONTENT_EVENT_MASK",
"FETCH_INTERRUPT_EVENT_MASK",
nsnull
};
/*************
NS_IMETHODIMP_(nsrefcnt) DocumentLoaderObserverImpl::AddRef(void)
{
NS_PRECONDITION(PRInt32(mRefCnt) >= 0, "illegal refcnt");
++mRefCnt;
return mRefCnt;
}
**************/
NS_IMPL_ADDREF(DocumentLoaderObserverImpl);
NS_IMPL_RELEASE(DocumentLoaderObserverImpl);
DocumentLoaderObserverImpl::DocumentLoaderObserverImpl(){
}
DocumentLoaderObserverImpl::DocumentLoaderObserverImpl(JNIEnv *env,
WebShellInitContext *yourInitContext,
jobject yourTarget) :
mJNIEnv(env), mInitContext(yourInitContext), mTarget(yourTarget)
{
if (nsnull == gVm) { // declared in jni_util.h
::util_GetJavaVM(env, &gVm); // save this vm reference away for the callback!
}
if (-1 == maskValues[0]) {
InitializeMaskValues();
}
mRefCnt = 1; // PENDING(edburns): not sure about how right this is to do.
}
void DocumentLoaderObserverImpl::InitializeMaskValues()
{
// if we don't have a VM, do nothing
if (nsnull == gVm) {
return;
}
JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION_1_2);
if (nsnull == env) {
return;
}
jclass documentLoadEventClass = ::util_FindClass(env,
"org/mozilla/webclient/DocumentLoadEvent");
if (nsnull == documentLoadEventClass) {
return;
}
int i = 0;
jfieldID fieldID;
while (nsnull != maskNames[i]) {
fieldID = ::util_GetStaticFieldID(env, documentLoadEventClass,
maskNames[i], "J");
if (nsnull == fieldID) {
return;
}
maskValues[i] = ::util_GetStaticLongField(env, documentLoadEventClass,
fieldID);
i++;
}
}
NS_IMETHODIMP DocumentLoaderObserverImpl::QueryInterface(REFNSIID aIID, void** aInstance)
{
if (nsnull == aInstance)
return NS_ERROR_NULL_POINTER;
*aInstance = nsnull;
if (aIID.Equals(kIDocumentLoaderObserverIID)) {
*aInstance = (void*) ((nsIDocumentLoaderObserver*)this);
NS_ADDREF_THIS();
return NS_OK;
}
return NS_NOINTERFACE;
}
/* nsIDocumentLoaderObserver methods */
NS_IMETHODIMP DocumentLoaderObserverImpl::OnStartDocumentLoad(nsIDocumentLoader* loader,
nsIURI* aURL,
const char* aCommand)
{
#if DEBUG_RAPTOR_CANVAS
if (prLogModuleInfo) {
PR_LOG(prLogModuleInfo, 3,
("DocumentLoaderObserverImpl.cpp: OnStartDocumentLoad\n"));
}
#endif
util_SendEventToJava(mInitContext->env,
mInitContext->nativeEventThread, mTarget,
maskValues[START_DOCUMENT_LOAD_EVENT_MASK]);
return NS_OK;
}
NS_IMETHODIMP DocumentLoaderObserverImpl::OnEndDocumentLoad(nsIDocumentLoader* loader,
nsIChannel* channel,
nsresult aStatus)
{
#if DEBUG_RAPTOR_CANVAS
if (prLogModuleInfo) {
PR_LOG(prLogModuleInfo, 3,
("!!DocumentLoaderObserverImpl.cpp: OnEndDocumentLoad\n"));
}
#endif
util_SendEventToJava(mInitContext->env,
mInitContext->nativeEventThread, mTarget,
maskValues[END_DOCUMENT_LOAD_EVENT_MASK]);
return NS_OK;
}
NS_IMETHODIMP DocumentLoaderObserverImpl::OnStartURLLoad(nsIDocumentLoader* loader,
nsIChannel* channel)
{
#if DEBUG_RAPTOR_CANVAS
if (prLogModuleInfo) {
PR_LOG(prLogModuleInfo, 3,
("!DocumentLoaderObserverImpl: OnStartURLLoad\n"));
}
#endif
util_SendEventToJava(mInitContext->env, mInitContext->nativeEventThread, mTarget,
maskValues[START_URL_LOAD_EVENT_MASK]);
return NS_OK;
}
NS_IMETHODIMP DocumentLoaderObserverImpl::OnProgressURLLoad(nsIDocumentLoader* loader,
nsIChannel* channel,
PRUint32 aProgress,
PRUint32 aProgressMax)
{
#if DEBUG_RAPTOR_CANVAS
if (prLogModuleInfo) {
PR_LOG(prLogModuleInfo, 3,
("!DocumentLoaderObserverImpl: OnProgressURLLoad\n"));
}
#endif
util_SendEventToJava(mInitContext->env, mInitContext->nativeEventThread, mTarget,
maskValues[PROGRESS_URL_LOAD_EVENT_MASK]);
return NS_OK;
}
NS_IMETHODIMP DocumentLoaderObserverImpl::OnStatusURLLoad(nsIDocumentLoader* loader,
nsIChannel* channel,
nsString& aMsg)
{
#if DEBUG_RAPTOR_CANVAS
if (prLogModuleInfo) {
PR_LOG(prLogModuleInfo, 3,
("!DocumentLoaderObserverImpl: OnStatusURLLoad\n"));
}
#endif
util_SendEventToJava(mInitContext->env, mInitContext->nativeEventThread, mTarget,
maskValues[STATUS_URL_LOAD_EVENT_MASK]);
return NS_OK;
}
NS_IMETHODIMP DocumentLoaderObserverImpl::OnEndURLLoad(nsIDocumentLoader* loader,
nsIChannel* channel,
nsresult aStatus)
{
#if DEBUG_RAPTOR_CANVAS
if (prLogModuleInfo) {
PR_LOG(prLogModuleInfo, 3,
("!DocumentLoaderObserverImpl: OnEndURLLoad\n"));
}
#endif
util_SendEventToJava(mInitContext->env, mInitContext->nativeEventThread, mTarget,
maskValues[END_URL_LOAD_EVENT_MASK]);
return NS_OK;
}
NS_IMETHODIMP DocumentLoaderObserverImpl::HandleUnknownContentType(nsIDocumentLoader* loader,
nsIChannel* channel,
const char *aContentType,
const char *aCommand)
{
#if DEBUG_RAPTOR_CANVAS
if (prLogModuleInfo) {
PR_LOG(prLogModuleInfo, 3,
("!DocumentLoaderObserverImpl: HandleUnknownContentType\n"));
}
#endif
util_SendEventToJava(mInitContext->env, mInitContext->nativeEventThread, mTarget,
maskValues[UNKNOWN_CONTENT_EVENT_MASK]);
return NS_OK;
}