URL Disaptching/Async listeners: forward debug messages

This makes it possible for the Asynchronous listener to get the
messages. It can then process them in a more fancy way.

The default implementation will still log the messages to the console
(if debug is enabled), but it will do so from the Async listener for
asynchronous requests now. This means they will probably be logged from
the same thread, and show up in a more readable way.

This also makes it possible to listen to several requests and log them
in a nice way (in a status window or whatever).
This commit is contained in:
Adrien Destugues 2016-10-31 22:14:39 +01:00
parent ed6d3d88c1
commit ed31589c37
3 changed files with 29 additions and 2 deletions

View File

@ -27,7 +27,8 @@ enum {
B_URL_PROTOCOL_DOWNLOAD_PROGRESS,
B_URL_PROTOCOL_UPLOAD_PROGRESS,
B_URL_PROTOCOL_REQUEST_COMPLETED,
B_URL_PROTOCOL_CERTIFICATE_VERIFICATION_FAILED
B_URL_PROTOCOL_CERTIFICATE_VERIFICATION_FAILED,
B_URL_PROTOCOL_DEBUG_MESSAGE
};
@ -53,6 +54,9 @@ public:
ssize_t bytesSent, ssize_t bytesTotal);
virtual void RequestCompleted(BUrlRequest* caller,
bool success);
virtual void DebugMessage(BUrlRequest* caller,
BUrlProtocolDebugMessage type,
const char* text);
virtual bool CertificateVerificationFailed(
BUrlRequest* caller,
BCertificate& certificate,

View File

@ -12,6 +12,7 @@
#include <AppKit.h>
#include <UrlProtocolAsynchronousListener.h>
#include <Debug.h>
#include <String.h>
extern const char* kUrlProtocolMessageType;
extern const char* kUrlProtocolCaller;
@ -142,6 +143,16 @@ BUrlProtocolAsynchronousListener::MessageReceived(BMessage* message)
}
break;
case B_URL_PROTOCOL_DEBUG_MESSAGE:
{
BUrlProtocolDebugMessage type
= (BUrlProtocolDebugMessage)message->FindInt32("url:type");
BString text = message->FindString("url:text");
DebugMessage(caller, type, text);
}
break;
case B_URL_PROTOCOL_CERTIFICATE_VERIFICATION_FAILED:
{
const char* error = message->FindString("url:error");

View File

@ -125,6 +125,18 @@ BUrlProtocolDispatchingListener::RequestCompleted(BUrlRequest* caller,
}
void
BUrlProtocolDispatchingListener::DebugMessage(BUrlRequest* caller,
BUrlProtocolDebugMessage type, const char* text)
{
BMessage message(B_URL_PROTOCOL_NOTIFICATION);
message.AddInt32("url:type", type);
message.AddString("url:text", text);
_SendMessage(&message, B_URL_PROTOCOL_DEBUG_MESSAGE, caller);
}
bool
BUrlProtocolDispatchingListener::CertificateVerificationFailed(
BUrlRequest* caller, BCertificate& certificate, const char* error)
@ -149,7 +161,7 @@ BUrlProtocolDispatchingListener::_SendMessage(BMessage* message,
int8 notification, BUrlRequest* caller)
{
ASSERT(message != NULL);
message->AddPointer(kUrlProtocolCaller, caller);
message->AddInt8(kUrlProtocolMessageType, notification);