Web Inspector: Network: add button to show system certificate dialog
[WebKit-https.git] / Source / WebCore / inspector / InspectorFrontendHost.cpp
index 6d28e1e..b1773aa 100644 (file)
@@ -30,6 +30,7 @@
 #include "config.h"
 #include "InspectorFrontendHost.h"
 
+#include "CertificateInfo.h"
 #include "ContextMenu.h"
 #include "ContextMenuController.h"
 #include "ContextMenuItem.h"
 #include "Editor.h"
 #include "Event.h"
 #include "FocusController.h"
+#include "Frame.h"
 #include "HitTestResult.h"
 #include "InspectorController.h"
 #include "InspectorFrontendClient.h"
 #include "JSDOMConvertInterface.h"
 #include "JSDOMExceptionHandling.h"
+#include "JSExecState.h"
 #include "JSInspectorFrontendHost.h"
-#include "JSMainThreadExecState.h"
-#include "MainFrame.h"
 #include "MouseEvent.h"
 #include "Node.h"
 #include "Page.h"
@@ -56,7 +57,7 @@
 #include <JavaScriptCore/ScriptFunctionCall.h>
 #include <pal/system/Sound.h>
 #include <wtf/StdLibExtras.h>
-
+#include <wtf/text/Base64.h>
 
 namespace WebCore {
 
@@ -218,9 +219,9 @@ float InspectorFrontendHost::zoomFactor()
 String InspectorFrontendHost::userInterfaceLayoutDirection()
 {
     if (m_client && m_client->userInterfaceLayoutDirection() == UserInterfaceLayoutDirection::RTL)
-        return ASCIILiteral("rtl");
+        return "rtl"_s;
 
-    return ASCIILiteral("ltr");
+    return "ltr"_s;
 }
 
 void InspectorFrontendHost::setAttachedWindowHeight(unsigned height)
@@ -269,27 +270,27 @@ unsigned InspectorFrontendHost::inspectionLevel()
 
 String InspectorFrontendHost::platform()
 {
-#if PLATFORM(MAC) || PLATFORM(IOS)
-    return ASCIILiteral("mac");
+#if PLATFORM(MAC) || PLATFORM(IOS_FAMILY)
+    return "mac"_s;
 #elif OS(WINDOWS)
-    return ASCIILiteral("windows");
+    return "windows"_s;
 #elif OS(LINUX)
-    return ASCIILiteral("linux");
+    return "linux"_s;
 #elif OS(FREEBSD)
-    return ASCIILiteral("freebsd");
+    return "freebsd"_s;
 #elif OS(OPENBSD)
-    return ASCIILiteral("openbsd");
+    return "openbsd"_s;
 #else
-    return ASCIILiteral("unknown");
+    return "unknown"_s;
 #endif
 }
 
 String InspectorFrontendHost::port()
 {
 #if PLATFORM(GTK)
-    return ASCIILiteral("gtk");
+    return "gtk"_s;
 #else
-    return ASCIILiteral("unknown");
+    return "unknown"_s;
 #endif
 }
 
@@ -438,4 +439,34 @@ void InspectorFrontendHost::inspectInspector()
         m_frontendPage->inspectorController().show();
 }
 
+bool InspectorFrontendHost::supportsShowCertificate() const
+{
+#if PLATFORM(COCOA)
+    return true;
+#else
+    return false;
+#endif
+}
+
+bool InspectorFrontendHost::showCertificate(const String& serializedCertificate)
+{
+    if (!m_client)
+        return false;
+
+    Vector<uint8_t> data;
+    if (!base64Decode(serializedCertificate, data))
+        return false;
+
+    CertificateInfo certificateInfo;
+    WTF::Persistence::Decoder decoder(data.data(), data.size());
+    if (!decoder.decode(certificateInfo))
+        return false;
+
+    if (certificateInfo.isEmpty())
+        return false;
+
+    m_client->showCertificate(certificateInfo);
+    return true;
+}
+
 } // namespace WebCore