Add a DiagnosticLogging method taking an arbitrary dictionary of values.
authorachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 15 Apr 2019 23:48:55 +0000 (23:48 +0000)
committerachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 15 Apr 2019 23:48:55 +0000 (23:48 +0000)
https://bugs.webkit.org/show_bug.cgi?id=196773

Source/WebCore:

Patch by Jer Noble <jer.noble@apple.com> on 2019-04-15
Reviewed by Alex Christensen.

* page/DiagnosticLoggingClient.h:

Source/WebKit:

Patch by Jer Noble <jer.noble@apple.com> on 2019-04-15
Reviewed by Alex Christensen.

In addition to adding the new logging delegate method (and piping everything into it),
add a new APIObject class to represent a signed integer.

* Shared/API/APINumber.h:
* Shared/API/APIObject.h:
* Shared/Cocoa/APIObject.mm:
(API::Object::newObject):
* Shared/Cocoa/WKNSNumber.mm:
(-[WKNSNumber dealloc]):
(-[WKNSNumber objCType]):
(-[WKNSNumber getValue:]):
(-[WKNSNumber longLongValue]):
(-[WKNSNumber _apiObject]):
* Shared/UserData.cpp:
(WebKit::UserData::encode):
(WebKit::UserData::decode):
* UIProcess/API/APIDiagnosticLoggingClient.h:
* UIProcess/API/C/WKPageDiagnosticLoggingClient.h:
* UIProcess/API/Cocoa/_WKDiagnosticLoggingDelegate.h:
* UIProcess/Cocoa/DiagnosticLoggingClient.h:
* UIProcess/Cocoa/DiagnosticLoggingClient.mm:
(WebKit::DiagnosticLoggingClient::logDiagnosticMessageWithValueDictionary):
* UIProcess/ProvisionalPageProxy.cpp:
(WebKit::ProvisionalPageProxy::didReceiveMessage):
* UIProcess/WebPageDiagnosticLoggingClient.cpp:
(WebKit::WebPageDiagnosticLoggingClient::logDiagnosticMessageWithValueDictionary):
* UIProcess/WebPageDiagnosticLoggingClient.h:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::logDiagnosticMessageWithValueDictionary):
* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in:
* WebProcess/WebCoreSupport/WebDiagnosticLoggingClient.cpp:
(WebKit::WebDiagnosticLoggingClient::logDiagnosticMessageWithValueDictionary):
* WebProcess/WebCoreSupport/WebDiagnosticLoggingClient.h:

Tools:

Reviewed by Jer Noble.

* TestWebKitAPI/Tests/WebKitCocoa/WKWebViewDiagnosticLogging.mm:
(-[TestLoggingDelegate _webView:logDiagnosticMessage:description:valueDictionary:]):
(TEST):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@244307 268f45cc-cd09-0410-ab3c-d52691b4dbfc

25 files changed:
Source/WebCore/ChangeLog
Source/WebCore/loader/EmptyClients.cpp
Source/WebCore/page/DiagnosticLoggingClient.h
Source/WebCore/testing/Internals.cpp
Source/WebCore/testing/Internals.h
Source/WebCore/testing/Internals.idl
Source/WebKit/ChangeLog
Source/WebKit/Shared/API/APINumber.h
Source/WebKit/Shared/API/APIObject.h
Source/WebKit/Shared/Cocoa/APIObject.mm
Source/WebKit/Shared/Cocoa/WKNSNumber.mm
Source/WebKit/Shared/UserData.cpp
Source/WebKit/UIProcess/API/APIDiagnosticLoggingClient.h
Source/WebKit/UIProcess/API/Cocoa/_WKDiagnosticLoggingDelegate.h
Source/WebKit/UIProcess/Cocoa/DiagnosticLoggingClient.h
Source/WebKit/UIProcess/Cocoa/DiagnosticLoggingClient.mm
Source/WebKit/UIProcess/ProvisionalPageProxy.cpp
Source/WebKit/UIProcess/WebPageDiagnosticLoggingClient.h
Source/WebKit/UIProcess/WebPageProxy.cpp
Source/WebKit/UIProcess/WebPageProxy.h
Source/WebKit/UIProcess/WebPageProxy.messages.in
Source/WebKit/WebProcess/WebCoreSupport/WebDiagnosticLoggingClient.cpp
Source/WebKit/WebProcess/WebCoreSupport/WebDiagnosticLoggingClient.h
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebViewDiagnosticLogging.mm

index e03e30d..2197aac 100644 (file)
@@ -1,3 +1,12 @@
+2019-04-15  Jer Noble  <jer.noble@apple.com>
+
+        Add a DiagnosticLogging method taking an arbitrary dictionary of values.
+        https://bugs.webkit.org/show_bug.cgi?id=196773
+
+        Reviewed by Alex Christensen.
+
+        * page/DiagnosticLoggingClient.h:
+
 2019-04-15  Justin Fan  <justin_fan@apple.com>
 
         Let WTF::convertSafely deduce types from arguments.
index d159085..0e7cfba 100644 (file)
@@ -131,6 +131,7 @@ class EmptyDiagnosticLoggingClient final : public DiagnosticLoggingClient {
     void logDiagnosticMessageWithResult(const String&, const String&, DiagnosticLoggingResultType, ShouldSample) final { }
     void logDiagnosticMessageWithValue(const String&, const String&, double, unsigned, ShouldSample) final { }
     void logDiagnosticMessageWithEnhancedPrivacy(const String&, const String&, ShouldSample) final { }
+    void logDiagnosticMessageWithValueDictionary(const String&, const String&, const ValueDictionary&, ShouldSample) final { }
 };
 
 #if ENABLE(DRAG_SUPPORT)
index 84aa51d..550c22b 100644 (file)
@@ -28,7 +28,9 @@
 #include "DiagnosticLoggingResultType.h"
 #include <wtf/FastMalloc.h>
 #include <wtf/Forward.h>
+#include <wtf/HashMap.h>
 #include <wtf/RandomNumber.h>
+#include <wtf/Variant.h>
 
 namespace WebCore {
 
@@ -42,6 +44,11 @@ public:
     virtual void logDiagnosticMessageWithValue(const String& message, const String& description, double value, unsigned significantFigures, ShouldSample) = 0;
     virtual void logDiagnosticMessageWithEnhancedPrivacy(const String& message, const String& description, ShouldSample) = 0;
 
+    using ValuePayload = Variant<String, uint64_t, int64_t, bool, double>;
+    using ValueDictionary = HashMap<String, ValuePayload>;
+
+    virtual void logDiagnosticMessageWithValueDictionary(const String& message, const String& description, const ValueDictionary&, ShouldSample) = 0;
+
     static bool shouldLogAfterSampling(ShouldSample);
 
     virtual ~DiagnosticLoggingClient() = default;
index b90635c..603ce7c 100644 (file)
@@ -56,6 +56,7 @@
 #include "DOMStringList.h"
 #include "DOMWindow.h"
 #include "DeprecatedGlobalSettings.h"
+#include "DiagnosticLoggingClient.h"
 #include "DisabledAdaptations.h"
 #include "DisplayList.h"
 #include "Document.h"
@@ -4999,4 +5000,24 @@ void Internals::processDidResume()
     PlatformMediaSessionManager::sharedManager().processDidResume();
 }
 
+void Internals::testDictionaryLogging()
+{
+    auto* document = contextDocument();
+    if (!document)
+        return;
+
+    auto* page = document->page();
+    if (!page)
+        return;
+
+    DiagnosticLoggingClient::ValueDictionary dictionary;
+    dictionary.set("stringKey"_s, String("stringValue"));
+    dictionary.set("uint64Key"_s, std::numeric_limits<uint64_t>::max());
+    dictionary.set("int64Key"_s, std::numeric_limits<int64_t>::min());
+    dictionary.set("boolKey"_s, true);
+    dictionary.set("doubleKey"_s, 2.7182818284590452353602874);
+
+    page->diagnosticLoggingClient().logDiagnosticMessageWithValueDictionary("testMessage"_s, "testDescription"_s, dictionary, ShouldSample::No);
+}
+
 } // namespace WebCore
index cd2aed9..ee64537 100644 (file)
@@ -814,6 +814,8 @@ public:
     void processWillSuspend();
     void processDidResume();
 
+    void testDictionaryLogging();
+        
 private:
     explicit Internals(Document&);
     Document* contextDocument() const;
index 4e44430..f2069ef 100644 (file)
@@ -744,4 +744,6 @@ enum CompositingPolicy {
 
     void processWillSuspend();
     void processDidResume();
+
+    void testDictionaryLogging();
 };
index 76399dd..bfde676 100644 (file)
@@ -1,3 +1,45 @@
+2019-04-15  Jer Noble  <jer.noble@apple.com>
+
+        Add a DiagnosticLogging method taking an arbitrary dictionary of values.
+        https://bugs.webkit.org/show_bug.cgi?id=196773
+
+        Reviewed by Alex Christensen.
+
+        In addition to adding the new logging delegate method (and piping everything into it), 
+        add a new APIObject class to represent a signed integer.
+
+        * Shared/API/APINumber.h:
+        * Shared/API/APIObject.h:
+        * Shared/Cocoa/APIObject.mm:
+        (API::Object::newObject):
+        * Shared/Cocoa/WKNSNumber.mm:
+        (-[WKNSNumber dealloc]):
+        (-[WKNSNumber objCType]):
+        (-[WKNSNumber getValue:]):
+        (-[WKNSNumber longLongValue]):
+        (-[WKNSNumber _apiObject]):
+        * Shared/UserData.cpp:
+        (WebKit::UserData::encode):
+        (WebKit::UserData::decode):
+        * UIProcess/API/APIDiagnosticLoggingClient.h:
+        * UIProcess/API/C/WKPageDiagnosticLoggingClient.h:
+        * UIProcess/API/Cocoa/_WKDiagnosticLoggingDelegate.h:
+        * UIProcess/Cocoa/DiagnosticLoggingClient.h:
+        * UIProcess/Cocoa/DiagnosticLoggingClient.mm:
+        (WebKit::DiagnosticLoggingClient::logDiagnosticMessageWithValueDictionary):
+        * UIProcess/ProvisionalPageProxy.cpp:
+        (WebKit::ProvisionalPageProxy::didReceiveMessage):
+        * UIProcess/WebPageDiagnosticLoggingClient.cpp:
+        (WebKit::WebPageDiagnosticLoggingClient::logDiagnosticMessageWithValueDictionary):
+        * UIProcess/WebPageDiagnosticLoggingClient.h:
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::logDiagnosticMessageWithValueDictionary):
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/WebPageProxy.messages.in:
+        * WebProcess/WebCoreSupport/WebDiagnosticLoggingClient.cpp:
+        (WebKit::WebDiagnosticLoggingClient::logDiagnosticMessageWithValueDictionary):
+        * WebProcess/WebCoreSupport/WebDiagnosticLoggingClient.h:
+
 2019-04-15  Dean Jackson  <dino@apple.com>
 
         Provide option to not create a longpress gesture recognizer
index fe57349..9dcd47a 100644 (file)
@@ -69,6 +69,7 @@ private:
 typedef Number<bool, API::Object::Type::Boolean> Boolean;
 typedef Number<double, API::Object::Type::Double> Double;
 typedef Number<uint64_t, API::Object::Type::UInt64> UInt64;
+typedef Number<int64_t, API::Object::Type::Int64> Int64;
 
 } // namespace API
 
index 0adf5c5..2ae85fc 100644 (file)
@@ -88,6 +88,7 @@ public:
         Boolean,
         Double,
         UInt64,
+        Int64,
         
         // Geometry types
         Point,
index 3102042..457fd0c 100644 (file)
@@ -163,6 +163,7 @@ void* Object::newObject(size_t size, Type type)
     case Type::Boolean:
     case Type::Double:
     case Type::UInt64:
+    case Type::Int64:
         wrapper = [WKNSNumber alloc];
         ((WKNSNumber *)wrapper)->_type = type;
         break;
index fe672ab..5739525 100644 (file)
@@ -33,6 +33,7 @@ using namespace WebKit;
         API::ObjectStorage<API::Boolean> _boolean;
         API::ObjectStorage<API::Double> _double;
         API::ObjectStorage<API::UInt64> _uint64;
+        API::ObjectStorage<API::Int64> _int64;
     } _number;
 }
 
@@ -51,6 +52,10 @@ using namespace WebKit;
         _number._uint64->~Number<uint64_t, API::Object::Type::UInt64>();
         break;
 
+    case API::Object::Type::Int64:
+        _number._int64->~Number<int64_t, API::Object::Type::Int64>();
+        break;
+
     default:
         ASSERT_NOT_REACHED();
     }
@@ -75,6 +80,10 @@ using namespace WebKit;
         return @encode(uint64_t);
         break;
 
+    case API::Object::Type::Int64:
+        return @encode(int64_t);
+        break;
+
     default:
         ASSERT_NOT_REACHED();
     }
@@ -97,6 +106,10 @@ using namespace WebKit;
         *reinterpret_cast<uint64_t*>(value) = _number._uint64->value();
         break;
 
+    case API::Object::Type::Int64:
+        *reinterpret_cast<int64_t*>(value) = _number._int64->value();
+        break;
+
     default:
         ASSERT_NOT_REACHED();
     }
@@ -128,6 +141,14 @@ using namespace WebKit;
     return super.unsignedLongLongValue;
 }
 
+- (long long)longLongValue
+{
+    if (_type == API::Object::Type::Int64)
+        return _number._int64->value();
+
+    return super.longLongValue;
+}
+
 // MARK: NSCopying protocol implementation
 
 - (id)copyWithZone:(NSZone *)zone
@@ -152,6 +173,10 @@ using namespace WebKit;
         return *_number._uint64;
         break;
 
+    case API::Object::Type::Int64:
+        return *_number._int64;
+        break;
+
     default:
         ASSERT_NOT_REACHED();
     }
index 533373c..fd9e424 100644 (file)
@@ -310,6 +310,10 @@ void UserData::encode(IPC::Encoder& encoder, const API::Object& object)
         static_cast<const API::UInt64&>(object).encode(encoder);
         break;
 
+    case API::Object::Type::Int64:
+        static_cast<const API::Int64&>(object).encode(encoder);
+        break;
+
     case API::Object::Type::UserContentURLPattern: {
         auto& urlPattern = static_cast<const API::UserContentURLPattern&>(object);
         encoder << urlPattern.patternString();
@@ -572,6 +576,11 @@ bool UserData::decode(IPC::Decoder& decoder, RefPtr<API::Object>& result)
             return false;
         break;
 
+    case API::Object::Type::Int64:
+        if (!API::Int64::decode(decoder, result))
+            return false;
+        break;
+
     case API::Object::Type::UserContentURLPattern: {
         String string;
         if (!decoder.decode(string))
index 40ad0d4..92b2d67 100644 (file)
@@ -23,8 +23,7 @@
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef APIDiagnosticLoggingClient_h
-#define APIDiagnosticLoggingClient_h
+#pragma once
 
 #include <WebCore/DiagnosticLoggingResultType.h>
 #include <wtf/text/WTFString.h>
@@ -35,6 +34,8 @@ class WebPageProxy;
 
 namespace API {
 
+class Dictionary;
+
 class DiagnosticLoggingClient {
 public:
     virtual ~DiagnosticLoggingClient() { }
@@ -43,9 +44,8 @@ public:
     virtual void logDiagnosticMessageWithResult(WebKit::WebPageProxy*, const WTF::String& message, const WTF::String& description, WebCore::DiagnosticLoggingResultType) = 0;
     virtual void logDiagnosticMessageWithValue(WebKit::WebPageProxy*, const WTF::String& message, const WTF::String& description, const WTF::String& value) = 0;
     virtual void logDiagnosticMessageWithEnhancedPrivacy(WebKit::WebPageProxy*, const WTF::String& message, const WTF::String& description) = 0;
+
+    virtual void logDiagnosticMessageWithValueDictionary(WebKit::WebPageProxy*, const WTF::String& message, const WTF::String& description, Ref<API::Dictionary>&&) = 0;
 };
 
 } // namespace API
-
-#endif // APIDiagnosticLoggingClient_h
-
index c4768db..e9e3ed9 100644 (file)
@@ -40,5 +40,6 @@ typedef NS_ENUM(NSInteger, _WKDiagnosticLoggingResultType) {
 - (void)_webView:(WKWebView *)webView logDiagnosticMessageWithResult:(NSString *)message description:(NSString *)description result:(_WKDiagnosticLoggingResultType)result;
 - (void)_webView:(WKWebView *)webView logDiagnosticMessageWithValue:(NSString *)message description:(NSString *)description value:(NSString *) value;
 - (void)_webView:(WKWebView *)webView logDiagnosticMessageWithEnhancedPrivacy:(NSString *)message description:(NSString *)description WK_API_AVAILABLE(macos(10.13), ios(11.0));
+- (void)_webView:(WKWebView *)webView logDiagnosticMessage:(NSString *)message description:(NSString *)description valueDictionary:(NSDictionary *)valueDictionary WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
 
 @end
index e09a699..5fdccac 100644 (file)
@@ -51,6 +51,7 @@ private:
     void logDiagnosticMessageWithResult(WebPageProxy*, const String& message, const String& description, WebCore::DiagnosticLoggingResultType) override;
     void logDiagnosticMessageWithValue(WebPageProxy*, const String& message, const String& description, const String& value) override;
     void logDiagnosticMessageWithEnhancedPrivacy(WebPageProxy*, const String& message, const String& description) override;
+    void logDiagnosticMessageWithValueDictionary(WebPageProxy*, const String& message, const String& description, Ref<API::Dictionary>&&) override;
 
     WKWebView *m_webView;
     WeakObjCPtr<id <_WKDiagnosticLoggingDelegate>> m_delegate;
@@ -60,6 +61,7 @@ private:
         unsigned webviewLogDiagnosticMessageWithResult : 1;
         unsigned webviewLogDiagnosticMessageWithValue : 1;
         unsigned webviewLogDiagnosticMessageWithEnhancedPrivacy : 1;
+        unsigned webviewLogDiagnosticMessageWithValueDictionary : 1;
     } m_delegateMethods;
 };
 
index 8d7c08e..e47c4b8 100644 (file)
@@ -26,6 +26,7 @@
 #import "config.h"
 #import "DiagnosticLoggingClient.h"
 
+#import "APIDictionary.h"
 #import "WKSharedAPICast.h"
 #import "_WKDiagnosticLoggingDelegate.h"
 
@@ -49,6 +50,7 @@ void DiagnosticLoggingClient::setDelegate(id <_WKDiagnosticLoggingDelegate> dele
     m_delegateMethods.webviewLogDiagnosticMessageWithResult = [delegate respondsToSelector:@selector(_webView:logDiagnosticMessageWithResult:description:result:)];
     m_delegateMethods.webviewLogDiagnosticMessageWithValue = [delegate respondsToSelector:@selector(_webView:logDiagnosticMessageWithValue:description:value:)];
     m_delegateMethods.webviewLogDiagnosticMessageWithEnhancedPrivacy = [delegate respondsToSelector:@selector(_webView:logDiagnosticMessageWithEnhancedPrivacy:description:)];
+    m_delegateMethods.webviewLogDiagnosticMessageWithValueDictionary = [delegate respondsToSelector:@selector(_webView:logDiagnosticMessage:description:valueDictionary:)];
 }
 
 void DiagnosticLoggingClient::logDiagnosticMessage(WebKit::WebPageProxy*, const WTF::String& message, const WTF::String& description)
@@ -87,4 +89,11 @@ void DiagnosticLoggingClient::logDiagnosticMessageWithEnhancedPrivacy(WebKit::We
         [m_delegate.get() _webView:m_webView logDiagnosticMessageWithEnhancedPrivacy:message description:description];
 }
 
+void DiagnosticLoggingClient::logDiagnosticMessageWithValueDictionary(WebPageProxy*, const String& message, const String& description, Ref<API::Dictionary>&& valueDictionary)
+{
+    if (m_delegateMethods.webviewLogDiagnosticMessageWithValueDictionary)
+        [m_delegate.get() _webView:m_webView logDiagnosticMessage:message description:description valueDictionary:static_cast<NSDictionary*>(valueDictionary->wrapper())];
+}
+
+
 } // namespace WebKit
index f0a3c3b..98efcc8 100644 (file)
@@ -381,6 +381,7 @@ void ProvisionalPageProxy::didReceiveMessage(IPC::Connection& connection, IPC::D
         || decoder.messageName() == Messages::WebPageProxy::BackForwardAddItem::name()
         || decoder.messageName() == Messages::WebPageProxy::LogDiagnosticMessage::name()
         || decoder.messageName() == Messages::WebPageProxy::LogDiagnosticMessageWithEnhancedPrivacy::name()
+        || decoder.messageName() == Messages::WebPageProxy::LogDiagnosticMessageWithValueDictionary::name()
         || decoder.messageName() == Messages::WebPageProxy::SetNetworkRequestsInProgress::name()
 #if USE(QUICK_LOOK)
         || decoder.messageName() == Messages::WebPageProxy::DidStartLoadForQuickLookDocumentInMainFrame::name()
index baadc15..a5d322d 100644 (file)
@@ -52,6 +52,7 @@ public:
     void logDiagnosticMessageWithResult(WebPageProxy*, const String& message, const String& description, WebCore::DiagnosticLoggingResultType) override;
     void logDiagnosticMessageWithValue(WebPageProxy*, const String& message, const String& description, const String& value) override;
     void logDiagnosticMessageWithEnhancedPrivacy(WebPageProxy*, const String& message, const String& description) override;
+    void logDiagnosticMessageWithValueDictionary(WebKit::WebPageProxy*, const WTF::String& message, const WTF::String& description, Ref<API::Dictionary>&&) override { }
 };
 
 } // namespace WebKit
index 52d679a..b352e2e 100644 (file)
@@ -6532,6 +6532,27 @@ void WebPageProxy::logDiagnosticMessageWithEnhancedPrivacy(const String& message
     effectiveClient->logDiagnosticMessageWithEnhancedPrivacy(this, message, description);
 }
 
+void WebPageProxy::logDiagnosticMessageWithValueDictionary(const String& message, const String& description, const WebCore::DiagnosticLoggingClient::ValueDictionary& valueDictionary, WebCore::ShouldSample shouldSample)
+{
+    auto* effectiveClient = effectiveDiagnosticLoggingClient(shouldSample);
+    if (!effectiveClient)
+        return;
+
+    auto apiDictionary = API::Dictionary::create();
+
+    for (auto& keyValuePair : valueDictionary) {
+        apiDictionary->add(keyValuePair.key, WTF::switchOn(keyValuePair.value,
+            [](const String& value) -> Ref<Object> { return API::String::create(value); },
+            [](uint64_t value) -> Ref<Object> { return API::UInt64::create(value); },
+            [](int64_t value) -> Ref<Object> { return API::Int64::create(value); },
+            [](bool value) -> Ref<Object> { return API::Boolean::create(value); },
+            [](double value) -> Ref<Object> { return API::Double::create(value); }
+        ));
+    }
+
+    effectiveClient->logDiagnosticMessageWithValueDictionary(this, message, description, WTFMove(apiDictionary));
+}
+
 void WebPageProxy::logScrollingEvent(uint32_t eventType, MonotonicTime timestamp, uint64_t data)
 {
     PerformanceLoggingClient::ScrollingEvent event = static_cast<PerformanceLoggingClient::ScrollingEvent>(eventType);
index cf00c64..20bfeae 100644 (file)
@@ -70,6 +70,7 @@
 #include <WebCore/ActivityState.h>
 #include <WebCore/AutoplayEvent.h>
 #include <WebCore/Color.h>
+#include <WebCore/DiagnosticLoggingClient.h>
 #include <WebCore/DragActions.h>
 #include <WebCore/EventTrackingRegions.h>
 #include <WebCore/FontAttributes.h>
@@ -1345,6 +1346,7 @@ public:
     void logDiagnosticMessageWithResult(const String& message, const String& description, uint32_t result, WebCore::ShouldSample);
     void logDiagnosticMessageWithValue(const String& message, const String& description, double value, unsigned significantFigures, WebCore::ShouldSample);
     void logDiagnosticMessageWithEnhancedPrivacy(const String& message, const String& description, WebCore::ShouldSample);
+    void logDiagnosticMessageWithValueDictionary(const String& message, const String& description, const WebCore::DiagnosticLoggingClient::ValueDictionary&, WebCore::ShouldSample);
 
     // Performance logging.
     void logScrollingEvent(uint32_t eventType, MonotonicTime, uint64_t);
index 1553f85..2ac1021 100644 (file)
@@ -242,6 +242,7 @@ messages -> WebPageProxy {
     LogDiagnosticMessageWithResult(String message, String description, uint32_t result, enum:bool WebCore::ShouldSample shouldSample)
     LogDiagnosticMessageWithValue(String message, String description, double value, unsigned significantFigures, enum:bool WebCore::ShouldSample shouldSample)
     LogDiagnosticMessageWithEnhancedPrivacy(String message, String description, enum:bool WebCore::ShouldSample shouldSample)
+    LogDiagnosticMessageWithValueDictionary(String message, String description, WebCore::DiagnosticLoggingClient::ValueDictionary value, enum:bool WebCore::ShouldSample shouldSample)
 
     # Performance logging
     LogScrollingEvent(uint32_t eventType, MonotonicTime timestamp, uint64_t data)
index 7a3a9d6..d9cb4f3 100644 (file)
@@ -83,4 +83,14 @@ void WebDiagnosticLoggingClient::logDiagnosticMessageWithEnhancedPrivacy(const S
     m_page.send(Messages::WebPageProxy::LogDiagnosticMessageWithEnhancedPrivacy(message, description, ShouldSample::No));
 }
 
+void WebDiagnosticLoggingClient::logDiagnosticMessageWithValueDictionary(const String& message, const String& description, const ValueDictionary& value, ShouldSample shouldSample)
+{
+    ASSERT(!m_page.corePage() || m_page.corePage()->settings().diagnosticLoggingEnabled());
+
+    if (!shouldLogAfterSampling(shouldSample))
+        return;
+
+    m_page.send(Messages::WebPageProxy::LogDiagnosticMessageWithValueDictionary(message, description, value, ShouldSample::No));
+}
+
 } // namespace WebKit
index 0b7e545..bcccf38 100644 (file)
@@ -43,6 +43,7 @@ private:
     void logDiagnosticMessageWithResult(const String& message, const String& description, WebCore::DiagnosticLoggingResultType, WebCore::ShouldSample) override;
     void logDiagnosticMessageWithValue(const String& message, const String& description, double value, unsigned significantFigures, WebCore::ShouldSample) override;
     void logDiagnosticMessageWithEnhancedPrivacy(const String& message, const String& description, WebCore::ShouldSample) override;
+    void logDiagnosticMessageWithValueDictionary(const String& message, const String& description, const ValueDictionary&, WebCore::ShouldSample) override;
 
     WebPage& m_page;
 };
index ab9ffde..02d27da 100644 (file)
@@ -1,3 +1,14 @@
+2019-04-15  Alex Christensen  <achristensen@webkit.org>
+
+        Add a DiagnosticLogging method taking an arbitrary dictionary of values.
+        https://bugs.webkit.org/show_bug.cgi?id=196773
+
+        Reviewed by Jer Noble.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/WKWebViewDiagnosticLogging.mm:
+        (-[TestLoggingDelegate _webView:logDiagnosticMessage:description:valueDictionary:]):
+        (TEST):
+
 2019-04-15  Aakash Jain  <aakash_jain@apple.com>
 
         ews-build should clearly indicate flaky test failures
index b1ba98d..e1625dd 100644 (file)
 #import "PlatformUtilities.h"
 #import "Test.h"
 #import "TestNavigationDelegate.h"
+#import "WKWebViewConfigurationExtras.h"
+#import <WebKit/WKPreferencesPrivate.h>
 #import <WebKit/WKWebViewPrivate.h>
 #import <WebKit/_WKDiagnosticLoggingDelegate.h>
 #import <wtf/RetainPtr.h>
 
+static bool isDone;
+
 @interface TestLoggingDelegate : NSObject <_WKDiagnosticLoggingDelegate>
 @end
 
 @implementation TestLoggingDelegate
+
+- (void)_webView:(WKWebView *)webView logDiagnosticMessage:(NSString *)message description:(NSString *)description valueDictionary:(NSDictionary *)valueDictionary
+{
+    EXPECT_TRUE([[valueDictionary objectForKey:@"stringKey"] isEqualToString:@"stringValue"]);
+    EXPECT_TRUE([[valueDictionary objectForKey:@"uint64Key"] unsignedLongLongValue] == std::numeric_limits<uint64_t>::max());
+    EXPECT_TRUE([[valueDictionary objectForKey:@"int64Key"] longLongValue] == std::numeric_limits<int64_t>::min());
+    EXPECT_TRUE([[valueDictionary objectForKey:@"boolKey"] boolValue]);
+    EXPECT_TRUE([[valueDictionary objectForKey:@"doubleKey"] doubleValue] == 2.7182818284590452353602874);
+
+    isDone = true;
+}
+
 @end
 
 TEST(WKWebView, PrivateSessionDiagnosticLoggingDelegate)
@@ -69,3 +85,13 @@ TEST(WKWebView, DiagnosticLoggingDelegateAfterClose)
     EXPECT_EQ(nil, webView.get()._diagnosticLoggingDelegate);
 }
 
+TEST(WKWebView, DiagnosticLoggingDictionary)
+{
+    auto webView = adoptNS([[WKWebView alloc] initWithFrame:CGRectZero configuration:[WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"WebProcessPlugInWithInternals"]]);
+    auto testLoggingDelegate = adoptNS([TestLoggingDelegate new]);
+    [webView _setDiagnosticLoggingDelegate:testLoggingDelegate.get()];
+    [webView configuration].preferences._diagnosticLoggingEnabled = YES;
+
+    [webView loadHTMLString:@"<script>window.internals.testDictionaryLogging()</script>" baseURL:nil];
+    TestWebKitAPI::Util::run(&isDone);
+}