From 04c2f8c9da63ea7d3b505fe5a0085c759baef233 Mon Sep 17 00:00:00 2001 From: suresh-khurdiya-epam Date: Thu, 2 Nov 2023 11:01:37 +0530 Subject: [PATCH] [ONEM-32477]:WPE 2.38 - port debug logs->DetailsConsoleMessage --- Source/WebKit/UIProcess/API/APIUIClient.h | 2 ++ Source/WebKit/UIProcess/API/C/WKPage.cpp | 12 +++++++++++ .../WebKit/UIProcess/API/C/WKPageUIClient.h | 12 +++++++++++ Source/WebKit/UIProcess/WebPageProxy.cpp | 6 ++++++ Source/WebKit/UIProcess/WebPageProxy.h | 2 ++ .../WebKit/UIProcess/WebPageProxy.messages.in | 2 ++ .../InjectedBundlePageUIClient.cpp | 6 +++++- .../WebCoreSupport/WebChromeClient.cpp | 1 + .../WebCoreSupport/WebFrameLoaderClient.cpp | 20 +++++++++++++++++-- 9 files changed, 60 insertions(+), 3 deletions(-) diff --git a/Source/WebKit/UIProcess/API/APIUIClient.h b/Source/WebKit/UIProcess/API/APIUIClient.h index 68e80682d1d0c..4007857b0e8e4 100644 --- a/Source/WebKit/UIProcess/API/APIUIClient.h +++ b/Source/WebKit/UIProcess/API/APIUIClient.h @@ -231,6 +231,8 @@ class UIClient { virtual void startXRSession(WebKit::WebPageProxy&, CompletionHandler)>&& completionHandler) { completionHandler(nil); } virtual void endXRSession(WebKit::WebPageProxy&) { } #endif + + virtual void willAddDetailedMessageToConsole( WebKit::WebPageProxy&, const WTF::String& source, const WTF::String& level, uint64_t line, uint64_t col, const WTF::String& message, const WTF::String& url) { } }; } // namespace API diff --git a/Source/WebKit/UIProcess/API/C/WKPage.cpp b/Source/WebKit/UIProcess/API/C/WKPage.cpp index 2ded6f050d456..18dd13ce0745f 100644 --- a/Source/WebKit/UIProcess/API/C/WKPage.cpp +++ b/Source/WebKit/UIProcess/API/C/WKPage.cpp @@ -2068,6 +2068,18 @@ void WKPageSetPageUIClient(WKPageRef pageRef, const WKPageUIClientBase* wkClient m_client.didResignInputElementStrongPasswordAppearance(toAPI(&page), toAPI(userInfo), m_client.base.clientInfo); } + void willAddDetailedMessageToConsole(WebPageProxy& page, const String& source, const String& level, + uint64_t line, uint64_t column, const String& message, const String& url) final + { + fprintf(stderr, "SK:WKPage.cpp: *** willAddDetailedMessageToConsole->m_client:message:%s \n", message.utf8().data()); + if (!m_client.willAddDetailedMessageToConsole) + return; + + fprintf(stderr, "SK:WKPage.cpp: willAddDetailedMessageToConsole->m_client:message:%s \n", message.utf8().data()); + m_client.willAddDetailedMessageToConsole(toAPI(page), toAPI(source.impl()), toAPI(level.impl()), + line, column, toAPI(message.impl()), toAPI(url.impl()), m_client.base.clientInfo); + } + #if ENABLE(POINTER_LOCK) void requestPointerLock(WebPageProxy* page) final { diff --git a/Source/WebKit/UIProcess/API/C/WKPageUIClient.h b/Source/WebKit/UIProcess/API/C/WKPageUIClient.h index 63323ea918dcd..f17386e18027d 100644 --- a/Source/WebKit/UIProcess/API/C/WKPageUIClient.h +++ b/Source/WebKit/UIProcess/API/C/WKPageUIClient.h @@ -154,6 +154,7 @@ typedef void (*WKPageRunJavaScriptAlertCallback_deprecatedForUseWithV5)(WKPageRe typedef bool (*WKPageRunJavaScriptConfirmCallback_deprecatedForUseWithV5)(WKPageRef page, WKStringRef message, WKFrameRef frame, WKSecurityOriginRef securityOrigin, const void *clientInfo); typedef WKStringRef (*WKPageRunJavaScriptPromptCallback_deprecatedForUseWithV5)(WKPageRef page, WKStringRef message, WKStringRef defaultValue, WKFrameRef frame, WKSecurityOriginRef securityOrigin, const void *clientInfo); typedef bool (*WKPageRunBeforeUnloadConfirmPanelCallback_deprecatedForUseWithV6)(WKPageRef page, WKStringRef message, WKFrameRef frame, const void *clientInfo); +typedef void (*WKPageWillAddDetailedMessageToConsoleCallback)(WKPageRef page, WKStringRef source, WKStringRef level, uint64_t line, uint64_t column, WKStringRef message, WKStringRef url, const void* clientInfo); typedef struct WKPageUIClientBase { int version; @@ -757,6 +758,7 @@ typedef struct WKPageUIClientV8 { WKFullscreenMayReturnToInlineCallback fullscreenMayReturnToInline; // Version 8. + WKPageWillAddDetailedMessageToConsoleCallback willAddDetailedMessageToConsole; WKRequestPointerLockCallback requestPointerLock; WKDidLosePointerLockCallback didLosePointerLock; } WKPageUIClientV8; @@ -845,6 +847,7 @@ typedef struct WKPageUIClientV9 { WKFullscreenMayReturnToInlineCallback fullscreenMayReturnToInline; // Version 8. + WKPageWillAddDetailedMessageToConsoleCallback willAddDetailedMessageToConsole; WKRequestPointerLockCallback requestPointerLock; WKDidLosePointerLockCallback didLosePointerLock; @@ -936,6 +939,7 @@ typedef struct WKPageUIClientV10 { WKFullscreenMayReturnToInlineCallback fullscreenMayReturnToInline; // Version 8. + WKPageWillAddDetailedMessageToConsoleCallback willAddDetailedMessageToConsole; WKRequestPointerLockCallback requestPointerLock; WKDidLosePointerLockCallback didLosePointerLock; @@ -1031,6 +1035,7 @@ typedef struct WKPageUIClientV11 { WKFullscreenMayReturnToInlineCallback fullscreenMayReturnToInline; // Version 8. + WKPageWillAddDetailedMessageToConsoleCallback willAddDetailedMessageToConsole; WKRequestPointerLockCallback requestPointerLock; WKDidLosePointerLockCallback didLosePointerLock; @@ -1129,6 +1134,7 @@ typedef struct WKPageUIClientV12 { WKFullscreenMayReturnToInlineCallback fullscreenMayReturnToInline; // Version 8. + WKPageWillAddDetailedMessageToConsoleCallback willAddDetailedMessageToConsole; WKRequestPointerLockCallback requestPointerLock; WKDidLosePointerLockCallback didLosePointerLock; @@ -1230,6 +1236,7 @@ typedef struct WKPageUIClientV13 { WKFullscreenMayReturnToInlineCallback fullscreenMayReturnToInline; // Version 8. + WKPageWillAddDetailedMessageToConsoleCallback willAddDetailedMessageToConsole; WKRequestPointerLockCallback requestPointerLock; WKDidLosePointerLockCallback didLosePointerLock; @@ -1334,6 +1341,7 @@ typedef struct WKPageUIClientV14 { WKFullscreenMayReturnToInlineCallback fullscreenMayReturnToInline; // Version 8. + WKPageWillAddDetailedMessageToConsoleCallback willAddDetailedMessageToConsole; WKRequestPointerLockCallback requestPointerLock; WKDidLosePointerLockCallback didLosePointerLock; @@ -1441,6 +1449,7 @@ typedef struct WKPageUIClientV15 { WKFullscreenMayReturnToInlineCallback fullscreenMayReturnToInline; // Version 8. + WKPageWillAddDetailedMessageToConsoleCallback willAddDetailedMessageToConsole; WKRequestPointerLockCallback requestPointerLock; WKDidLosePointerLockCallback didLosePointerLock; @@ -1552,6 +1561,7 @@ typedef struct WKPageUIClientV16 { WKFullscreenMayReturnToInlineCallback fullscreenMayReturnToInline; // Version 8. + WKPageWillAddDetailedMessageToConsoleCallback willAddDetailedMessageToConsole; WKRequestPointerLockCallback requestPointerLock; WKDidLosePointerLockCallback didLosePointerLock; @@ -1666,6 +1676,7 @@ typedef struct WKPageUIClientV17 { WKFullscreenMayReturnToInlineCallback fullscreenMayReturnToInline; // Version 8. + WKPageWillAddDetailedMessageToConsoleCallback willAddDetailedMessageToConsole; WKRequestPointerLockCallback requestPointerLock; WKDidLosePointerLockCallback didLosePointerLock; @@ -1782,6 +1793,7 @@ typedef struct WKPageUIClientV18 { WKFullscreenMayReturnToInlineCallback fullscreenMayReturnToInline; // Version 8. + WKPageWillAddDetailedMessageToConsoleCallback willAddDetailedMessageToConsole; WKRequestPointerLockCallback requestPointerLock; WKDidLosePointerLockCallback didLosePointerLock; diff --git a/Source/WebKit/UIProcess/WebPageProxy.cpp b/Source/WebKit/UIProcess/WebPageProxy.cpp index 641cff85d7098..ef63584e8eacc 100644 --- a/Source/WebKit/UIProcess/WebPageProxy.cpp +++ b/Source/WebKit/UIProcess/WebPageProxy.cpp @@ -11703,6 +11703,12 @@ bool WebPageProxy::shouldAvoidSynchronouslyWaitingToPreventDeadlock() const return false; } +void WebPageProxy::willAddDetailedMessageToConsole(const String& src, const String& level, uint64_t line, uint64_t col, const String& message, const String& url) +{ + fprintf(stderr, "SK: WebPageProxy::willAddDetailedMessageToConsole ->m_ uiClient->will message:%s\n", message.utf8().data()); + m_uiClient->willAddDetailedMessageToConsole(*this, src, level, line, col, message, url); +} + } // namespace WebKit #undef WEBPAGEPROXY_RELEASE_LOG diff --git a/Source/WebKit/UIProcess/WebPageProxy.h b/Source/WebKit/UIProcess/WebPageProxy.h index f03f888117b8b..ae6bf67c72270 100644 --- a/Source/WebKit/UIProcess/WebPageProxy.h +++ b/Source/WebKit/UIProcess/WebPageProxy.h @@ -1808,6 +1808,8 @@ class WebPageProxy final : public API::ObjectImpl void getApplicationManifest(CompletionHandler&)>&&); #endif + void willAddDetailedMessageToConsole(const String& src, const String& level, uint64_t line, uint64_t col, const String& message, const String& url); + WebPreferencesStore preferencesStore() const; void setDefersLoadingForTesting(bool); diff --git a/Source/WebKit/UIProcess/WebPageProxy.messages.in b/Source/WebKit/UIProcess/WebPageProxy.messages.in index 428db2d7661a4..e4570e4f5a37e 100644 --- a/Source/WebKit/UIProcess/WebPageProxy.messages.in +++ b/Source/WebKit/UIProcess/WebPageProxy.messages.in @@ -101,6 +101,8 @@ messages -> WebPageProxy { EndDateTimePicker(); #endif + WillAddDetailedMessageToConsole(String src, String level, uint64_t line, uint64_t column, String message, String url); + # Policy messages DecidePolicyForResponse(WebCore::FrameIdentifier frameID, struct WebKit::FrameInfoData frameInfo, WebCore::PolicyCheckIdentifier policyCheckIdentifier, uint64_t navigationID, WebCore::ResourceResponse response, WebCore::ResourceRequest request, bool canShowMIMEType, String downloadAttribute, bool wasAllowedByInjectedBundle, uint64_t listenerID, WebKit::UserData userData) DecidePolicyForNavigationActionAsync(WebCore::FrameIdentifier frameID, struct WebKit::FrameInfoData frameInfo, WebCore::PolicyCheckIdentifier policyCheckIdentifier, uint64_t navigationID, struct WebKit::NavigationActionData navigationActionData, struct WebKit::FrameInfoData originatingFrameInfoData, std::optional originatingPageID, WebCore::ResourceRequest originalRequest, WebCore::ResourceRequest request, IPC::FormDataReference requestBody, WebCore::ResourceResponse redirectResponse, WebKit::UserData userData, uint64_t listenerID) diff --git a/Source/WebKit/WebProcess/InjectedBundle/InjectedBundlePageUIClient.cpp b/Source/WebKit/WebProcess/InjectedBundle/InjectedBundlePageUIClient.cpp index 67b1ac1ba34fe..943325929426e 100644 --- a/Source/WebKit/WebProcess/InjectedBundle/InjectedBundlePageUIClient.cpp +++ b/Source/WebKit/WebProcess/InjectedBundle/InjectedBundlePageUIClient.cpp @@ -46,12 +46,16 @@ InjectedBundlePageUIClient::InjectedBundlePageUIClient(const WKBundlePageUIClien void InjectedBundlePageUIClient::willAddMessageToConsole(WebPage* page, MessageSource, MessageLevel, const String& message, unsigned lineNumber, unsigned /*columnNumber*/, const String& /*sourceID*/) { - if (m_client.willAddMessageToConsole) + fprintf(stderr, "SK: InjectedBundlePageUIClient::willAddMessageToConsole :messahe:%s\n", message.utf8().data()); + if (m_client.willAddMessageToConsole) { + fprintf(stderr, "SK: InjectedBundlePageUIClient::willAddMessageToConsole->m_client.willAddMessageToConsole \n"); m_client.willAddMessageToConsole(toAPI(page), toAPI(message.impl()), lineNumber, m_client.base.clientInfo); + } } void InjectedBundlePageUIClient::willAddMessageWithArgumentsToConsole(WebPage* page, MessageSource, MessageLevel, const String& message, Span messageArguments, unsigned lineNumber, unsigned columnNumber, const String& sourceID) { + fprintf(stderr, "SK: InjectedBundlePageUIClient::willAddMessageWithArgumentsToConsole \n"); if (m_client.willAddMessageWithDetailsToConsole) m_client.willAddMessageWithDetailsToConsole(toAPI(page), toAPI(message.impl()), toAPI(&API::Array::createStringArray(messageArguments).leakRef()), lineNumber, columnNumber, toAPI(sourceID.impl()), m_client.base.clientInfo); } diff --git a/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.cpp b/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.cpp index 0019ce67547ce..97e238bd2855e 100644 --- a/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.cpp +++ b/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.cpp @@ -411,6 +411,7 @@ void WebChromeClient::setResizable(bool resizable) void WebChromeClient::addMessageToConsole(MessageSource source, MessageLevel level, const String& message, unsigned lineNumber, unsigned columnNumber, const String& sourceID) { // Notify the bundle client. + fprintf(stderr, "\n WebChromeClient::addMessageToConsole->m_page.injectedBundleUIClient().willAddMessageToConsole: message:%s\n", message.utf8().data()); m_page.injectedBundleUIClient().willAddMessageToConsole(&m_page, source, level, message, lineNumber, columnNumber, sourceID); } diff --git a/Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp b/Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp index 72cd56ea4c039..f02c011a060ea 100644 --- a/Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp +++ b/Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp @@ -281,6 +281,13 @@ void WebFrameLoaderClient::dispatchDidReceiveResponse(DocumentLoader*, ResourceL return; webPage->injectedBundleResourceLoadClient().didReceiveResponseForResource(*webPage, m_frame, identifier, response); + + if (response.httpStatusCode() >= 400) { + String message = "Failed to load resource: the server responded with a status of " + String::number(response.httpStatusCode()) + " (" + response.httpStatusText() + ')'; + fprintf(stderr, "SK: WebFrameLoaderClient::dispatchDidReceiveResponse->webPage->send(WillAddDetailedMessageToConsole: message:%s \n", message.utf8().data()); + LOG(Loading,"Using Log WebFrameLoaderClient::dispatchDidReceiveResponse"); + webPage->send(Messages::WebPageProxy::WillAddDetailedMessageToConsole("Network"_s, "Error"_s, 0, 0, message, response.url().string())); + } } void WebFrameLoaderClient::dispatchDidReceiveContentLength(DocumentLoader*, ResourceLoaderIdentifier identifier, int dataLength) @@ -320,6 +327,13 @@ void WebFrameLoaderClient::dispatchDidFailLoading(DocumentLoader*, ResourceLoade webPage->injectedBundleResourceLoadClient().didFailLoadForResource(*webPage, m_frame, identifier, error); webPage->removeResourceRequest(identifier); + + auto errorDescription = error.localizedDescription(); + auto errorMessage = makeString("Failed to load resource", errorDescription.isEmpty() ? "" : ": ", errorDescription); + fprintf(stderr, "SK: **** WebFrameLoaderClient:dispatchDidFailLoading:->webPage->send(WillAddDetailedMessageToConsole: message:%s \n", errorMessage.utf8().data()); + fprintf(stderr, "dispatchedDidFailLoading: isTimeout=%d, isCancellation=%d, isAccessControl=%d, errorCode=%d description:%s)",error.isTimeout(), error.isCancellation(), error.isAccessControl(), error.errorCode(),error.localizedDescription().utf8().data()); + LOG(Loading,"Using Log WebFrameLoaderClient::dispatchDidFailLoading"); + webPage->send(Messages::WebPageProxy::WillAddDetailedMessageToConsole("Network"_s, "Error"_s, 0, 0, errorMessage, error.failingURL().string())); } bool WebFrameLoaderClient::dispatchDidLoadResourceFromMemoryCache(DocumentLoader*, const ResourceRequest&, const ResourceResponse&, int /*length*/) @@ -623,10 +637,12 @@ void WebFrameLoaderClient::dispatchDidFailLoad(const ResourceError& error) auto& documentLoader = static_cast(*m_frame->coreFrame()->loader().documentLoader()); auto navigationID = documentLoader.navigationID(); - + + fprintf(stderr, "WebFrameLoaderClient::dispatchDidFailLoad"); // Notify the bundle client. webPage->injectedBundleLoaderClient().didFailLoadWithErrorForFrame(*webPage, m_frame, error, userData); - + fprintf(stderr, " dispatchDidFailLoad: isTimeout=%d, isCancellation=%d, isAccessControl=%d, errorCode=%d description:%s)",error.isTimeout(), error.isCancellation(), error.isAccessControl(), error.errorCode(),error.localizedDescription().utf8().data()); + LOG(Loading,"Using Log WebFrameLoaderClient::dispatchDidFailLoad"); // Notify the UIProcess. webPage->send(Messages::WebPageProxy::DidFailLoadForFrame(m_frame->frameID(), m_frame->info(), documentLoader.request(), navigationID, error, UserData(WebProcess::singleton().transformObjectsToHandles(userData.get()).get())));