Modified: trunk/Source/WebKit/UIProcess/win/WebInspectorProxyWin.cpp (233690 => 233691)
--- trunk/Source/WebKit/UIProcess/win/WebInspectorProxyWin.cpp 2018-07-10 17:34:34 UTC (rev 233690)
+++ trunk/Source/WebKit/UIProcess/win/WebInspectorProxyWin.cpp 2018-07-10 18:22:15 UTC (rev 233691)
@@ -27,112 +27,365 @@
#include "config.h"
#include "WebInspectorProxy.h"
+#include "APINavigationAction.h"
+#include "APIPageConfiguration.h"
+#include "CFURLExtras.h"
+#include "PageClientImpl.h"
+#include "WebFramePolicyListenerProxy.h"
+#include "WebPageGroup.h"
+#include "WebPageProxy.h"
+#include "WebPreferences.h"
+#include "WebProcessPool.h"
+#include "WebView.h"
+#include <WebCore/InspectorFrontendClientLocal.h>
#include <WebCore/NotImplemented.h>
+#include <WebCore/WebCoreBundleWin.h>
+#include <WebCore/WebCoreInstanceHandle.h>
+#include <WebCore/WindowMessageBroadcaster.h>
+#include <WebKit/WKPage.h>
namespace WebKit {
-WebPageProxy* WebInspectorProxy::platformCreateFrontendPage()
+static const LPCWSTR WebInspectorProxyPointerProp = L"WebInspectorProxyPointer";
+static const LPCWSTR WebInspectorProxyClassName = L"WebInspectorProxyClass";
+
+struct InspectedWindowInfo {
+ int left;
+ int top;
+ int viewWidth;
+ int viewHeight;
+ int parentWidth;
+ int parentHeight;
+};
+
+static InspectedWindowInfo getInspectedWindowInfo(HWND inspectedWindow, HWND parentWindow)
{
- notImplemented();
- return nullptr;
+ RECT rect;
+ ::GetClientRect(inspectedWindow, &rect);
+ ::MapWindowPoints(inspectedWindow, parentWindow, (LPPOINT)&rect, 2);
+
+ RECT parentRect;
+ ::GetClientRect(parentWindow, &parentRect);
+ return { rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, parentRect.right - parentRect.left, parentRect.bottom - parentRect.top };
}
-void WebInspectorProxy::platformCreateFrontendWindow()
+void WebInspectorProxy::windowReceivedMessage(HWND hwnd, UINT msg, WPARAM, LPARAM lParam)
{
- notImplemented();
+ switch (msg) {
+ case WM_WINDOWPOSCHANGING: {
+ if (!m_isAttached)
+ return;
+
+ auto windowPos = reinterpret_cast<WINDOWPOS*>(lParam);
+
+ if (windowPos->flags & SWP_NOSIZE)
+ return;
+
+ HWND parent = GetParent(hwnd);
+ RECT parentRect;
+ GetClientRect(parent, &parentRect);
+
+ RECT inspectorRect;
+ GetClientRect(m_inspectorViewWindow, &inspectorRect);
+
+ switch (m_attachmentSide) {
+ case AttachmentSide::Bottom: {
+ unsigned inspectorHeight = WebCore::InspectorFrontendClientLocal::constrainedAttachedWindowHeight(inspectorRect.bottom - inspectorRect.top, windowPos->cy);
+ windowPos->cy -= inspectorHeight;
+ ::SetWindowPos(m_inspectorViewWindow, 0, windowPos->x, windowPos->y + windowPos->cy, windowPos->cx, inspectorHeight, SWP_NOZORDER);
+ break;
+ }
+ case AttachmentSide::Left:
+ case AttachmentSide::Right: {
+ unsigned inspectorWidth = WebCore::InspectorFrontendClientLocal::constrainedAttachedWindowWidth(inspectorRect.right - inspectorRect.left, windowPos->cx);
+ windowPos->cx -= inspectorWidth;
+ ::SetWindowPos(m_inspectorViewWindow, 0, windowPos->x + windowPos->cx, windowPos->y, inspectorWidth, windowPos->cy, SWP_NOZORDER);
+ break;
+ }
+ default:
+ break;
+ }
+ break;
+ }
+ default:
+ break;
+ }
}
-void WebInspectorProxy::platformCloseFrontendPageAndWindow()
+LRESULT CALLBACK WebInspectorProxy::wndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
- notImplemented();
+ WebInspectorProxy* client = reinterpret_cast<WebInspectorProxy*>(::GetProp(hwnd, WebInspectorProxyPointerProp));
+ switch (msg) {
+ case WM_SIZE:
+ ::SetWindowPos(client->m_inspectorViewWindow, 0, 0, 0, LOWORD(lParam), HIWORD(lParam), SWP_NOZORDER);
+ return 0;
+ case WM_CLOSE:
+ client->close();
+ return 0;
+ default:
+ break;
+ }
+ return ::DefWindowProc(hwnd, msg, wParam, lParam);
}
-void WebInspectorProxy::platformDidCloseForCrash()
+bool WebInspectorProxy::registerWindowClass()
{
- notImplemented();
+ static bool haveRegisteredWindowClass = false;
+
+ if (haveRegisteredWindowClass)
+ return true;
+ haveRegisteredWindowClass = true;
+
+ WNDCLASSEX wcex;
+ wcex.cbSize = sizeof(WNDCLASSEX);
+ wcex.style = 0;
+ wcex.lpfnWndProc = wndProc;
+ wcex.cbClsExtra = 0;
+ wcex.cbWndExtra = 0;
+ wcex.hInstance = WebCore::instanceHandle();
+ wcex.hIcon = 0;
+ wcex.hCursor = LoadCursor(0, IDC_ARROW);
+ wcex.hbrBackground = 0;
+ wcex.lpszMenuName = 0;
+ wcex.lpszClassName = WebInspectorProxyClassName;
+ wcex.hIconSm = 0;
+ return ::RegisterClassEx(&wcex);
}
-void WebInspectorProxy::platformInvalidate()
+static void decidePolicyForNavigationAction(WKPageRef pageRef, WKNavigationActionRef navigationActionRef, WKFramePolicyListenerRef listenerRef, WKTypeRef, const void* clientInfo)
{
- notImplemented();
-}
+ // Allow non-main frames to navigate anywhere.
+ API::FrameInfo* sourceFrame = toImpl(navigationActionRef)->sourceFrame();
+ if (sourceFrame && !sourceFrame->isMainFrame()) {
+ toImpl(listenerRef)->use({ });
+ return;
+ }
-void WebInspectorProxy::platformHide()
-{
- notImplemented();
+ const WebInspectorProxy* webInspectorProxy = static_cast<const WebInspectorProxy*>(clientInfo);
+ ASSERT(webInspectorProxy);
+
+ WebCore::ResourceRequest request = toImpl(navigationActionRef)->request();
+
+ // Allow loading of the main inspector file.
+ if (WebInspectorProxy::isMainOrTestInspectorPage(request.url())) {
+ toImpl(listenerRef)->use({ });
+ return;
+ }
+
+ // Prevent everything else from loading in the inspector's page.
+ toImpl(listenerRef)->ignore();
+
+ // And instead load it in the inspected page.
+ webInspectorProxy->inspectedPage()->loadRequest(WTFMove(request));
}
-void WebInspectorProxy::platformBringToFront()
+static void webProcessDidCrash(WKPageRef, const void* clientInfo)
{
- notImplemented();
+ WebInspectorProxy* webInspectorProxy = static_cast<WebInspectorProxy*>(const_cast<void*>(clientInfo));
+ ASSERT(webInspectorProxy);
+ webInspectorProxy->closeForCrash();
}
-void WebInspectorProxy::platformBringInspectedPageToFront()
+WebPageProxy* WebInspectorProxy::platformCreateFrontendPage()
{
- notImplemented();
-}
+ ASSERT(inspectedPage());
-bool WebInspectorProxy::platformIsFront()
-{
- notImplemented();
- return false;
+ RefPtr<WebPreferences> preferences = WebPreferences::create(String(), "WebKit2.", "WebKit2.");
+#if ENABLE(DEVELOPER_MODE)
+ // Allow developers to inspect the Web Inspector in debug builds without changing settings.
+ preferences->setDeveloperExtrasEnabled(true);
+ preferences->setLogsPageMessagesToSystemConsoleEnabled(true);
+#endif
+ preferences->setAllowFileAccessFromFileURLs(true);
+ preferences->setJavaScriptRuntimeFlags({ });
+ RefPtr<WebPageGroup> pageGroup = WebPageGroup::create(inspectorPageGroupIdentifierForPage(inspectedPage()), false, false);
+ auto pageConfiguration = API::PageConfiguration::create();
+ pageConfiguration->setProcessPool(&inspectorProcessPool(inspectionLevel()));
+ pageConfiguration->setPreferences(preferences.get());
+ pageConfiguration->setPageGroup(pageGroup.get());
+
+ WKPageNavigationClientV0 navigationClient = {
+ { 0, this },
+ decidePolicyForNavigationAction,
+ nullptr, // decidePolicyForNavigationResponse
+ nullptr, // decidePolicyForPluginLoad
+ nullptr, // didStartProvisionalNavigation
+ nullptr, // didReceiveServerRedirectForProvisionalNavigation
+ nullptr, // didFailProvisionalNavigation
+ nullptr, // didCommitNavigation
+ nullptr, // didFinishNavigation
+ nullptr, // didFailNavigation
+ nullptr, // didFailProvisionalLoadInSubframe
+ nullptr, // didFinishDocumentLoad
+ nullptr, // didSameDocumentNavigation
+ nullptr, // renderingProgressDidChange
+ nullptr, // canAuthenticateAgainstProtectionSpace
+ nullptr, // didReceiveAuthenticationChallenge
+ webProcessDidCrash,
+ nullptr, // copyWebCryptoMasterKey
+
+ nullptr, // didBeginNavigationGesture
+ nullptr, // willEndNavigationGesture
+ nullptr, // didEndNavigationGesture
+ nullptr, // didRemoveNavigationGestureSnapshot
+ };
+
+ RECT r = { 0, 0, initialWindowWidth, initialWindowHeight };
+ auto page = inspectedPage();
+ m_inspectedViewWindow = page->viewWidget();
+ m_inspectedViewParentWindow = ::GetParent(m_inspectedViewWindow);
+ auto view = WebView::create(r, pageConfiguration, m_inspectedViewParentWindow);
+ m_inspectorView = &view.leakRef();
+ auto inspectorPage = m_inspectorView->page();
+ m_inspectorViewWindow = inspectorPage->viewWidget();
+ WKPageSetPageNavigationClient(toAPI(inspectorPage), &navigationClient.base);
+
+ return inspectorPage;
}
-void WebInspectorProxy::platformInspectedURLChanged(const String& /* url */)
+void WebInspectorProxy::platformCloseFrontendPageAndWindow()
{
- notImplemented();
+ WebCore::WindowMessageBroadcaster::removeListener(m_inspectedViewWindow, this);
+ m_inspectorView = nullptr;
+ m_inspectorPage = nullptr;
+ if (m_inspectorViewWindow) {
+ ::DestroyWindow(m_inspectorViewWindow);
+ m_inspectorViewWindow = nullptr;
+ }
+ if (m_inspectorDetachWindow) {
+ ::RemoveProp(m_inspectorDetachWindow, WebInspectorProxyPointerProp);
+ ::DestroyWindow(m_inspectorDetachWindow);
+ m_inspectorDetachWindow = nullptr;
+ }
+ m_inspectedViewWindow = nullptr;
+ m_inspectedViewParentWindow = nullptr;
}
String WebInspectorProxy::inspectorPageURL()
{
- return String();
+ RetainPtr<CFURLRef> htmlURLRef = adoptCF(CFBundleCopyResourceURL(WebCore::webKitBundle(), CFSTR("Main"), CFSTR("html"), CFSTR("WebInspectorUI")));
+ return CFURLGetString(htmlURLRef.get());
}
String WebInspectorProxy::inspectorTestPageURL()
{
- return String();
+ RetainPtr<CFURLRef> htmlURLRef = adoptCF(CFBundleCopyResourceURL(WebCore::webKitBundle(), CFSTR("Test"), CFSTR("html"), CFSTR("WebInspectorUI")));
+ return CFURLGetString(htmlURLRef.get());
}
String WebInspectorProxy::inspectorBaseURL()
{
- return String();
+ RetainPtr<CFURLRef> baseURLRef = adoptCF(CFBundleCopyResourceURL(WebCore::webKitBundle(), CFSTR("WebInspectorUI"), nullptr, nullptr));
+ return CFURLGetString(baseURLRef.get());
}
unsigned WebInspectorProxy::platformInspectedWindowHeight()
{
- return 0;
+ RECT rect;
+ ::GetClientRect(m_inspectedViewWindow, &rect);
+ return rect.bottom - rect.top;
}
unsigned WebInspectorProxy::platformInspectedWindowWidth()
{
- return 0;
+ RECT rect;
+ ::GetClientRect(m_inspectedViewWindow, &rect);
+ return rect.right - rect.left;
}
void WebInspectorProxy::platformAttach()
{
- notImplemented();
+ static const unsigned defaultAttachedSize = 300;
+ static const unsigned minimumAttachedWidth = 750;
+ static const unsigned minimumAttachedHeight = 250;
+
+ unsigned inspectedHeight = platformInspectedWindowHeight();
+ unsigned inspectedWidth = platformInspectedWindowWidth();
+
+ if (m_inspectorDetachWindow && ::GetParent(m_inspectorViewWindow) == m_inspectorDetachWindow) {
+ ::SetParent(m_inspectorViewWindow, m_inspectedViewParentWindow);
+ ::ShowWindow(m_inspectorDetachWindow, SW_HIDE);
+ }
+
+ WebCore::WindowMessageBroadcaster::addListener(m_inspectedViewWindow, this);
+
+ if (m_attachmentSide == AttachmentSide::Bottom) {
+ unsigned maximumAttachedHeight = platformInspectedWindowHeight() * 3 / 4;
+ platformSetAttachedWindowHeight(std::max(minimumAttachedHeight, std::min(defaultAttachedSize, maximumAttachedHeight)));
+ } else {
+ unsigned maximumAttachedWidth = platformInspectedWindowWidth() * 3 / 4;
+ platformSetAttachedWindowWidth(std::max(minimumAttachedWidth, std::min(defaultAttachedSize, maximumAttachedWidth)));
+ }
+ ::ShowWindow(m_inspectorViewWindow, SW_SHOW);
}
void WebInspectorProxy::platformDetach()
{
+ if (!inspectedPage()->isValid())
+ return;
+
+ if (!m_inspectorDetachWindow) {
+ static bool haveRegisteredClass = false;
+ registerWindowClass();
+ m_inspectorDetachWindow = ::CreateWindowEx(0, WebInspectorProxyClassName, 0, WS_OVERLAPPEDWINDOW,
+ CW_USEDEFAULT, CW_USEDEFAULT, initialWindowWidth, initialWindowHeight,
+ 0, 0, WebCore::instanceHandle(), 0);
+ ::SetProp(m_inspectorDetachWindow, WebInspectorProxyPointerProp, reinterpret_cast<HANDLE>(this));
+ }
+
+ WebCore::WindowMessageBroadcaster::removeListener(m_inspectedViewWindow, this);
+
+ RECT rect;
+ ::GetClientRect(m_inspectorDetachWindow, &rect);
+ auto windowInfo = getInspectedWindowInfo(m_inspectedViewWindow, m_inspectedViewParentWindow);
+ ::SetParent(m_inspectorViewWindow, m_inspectorDetachWindow);
+ ::SetWindowPos(m_inspectorViewWindow, 0, 0, 0, rect.right - rect.left, rect.bottom - rect.top, SWP_NOZORDER);
+ ::SetWindowPos(m_inspectedViewWindow, 0, windowInfo.left, windowInfo.top, windowInfo.parentWidth - windowInfo.left, windowInfo.parentHeight - windowInfo.top, SWP_NOZORDER);
+
+ if (m_isVisible)
+ ::ShowWindow(m_inspectorDetachWindow, SW_SHOW);
+}
+
+void WebInspectorProxy::platformSetAttachedWindowHeight(unsigned height)
+{
+ auto windowInfo = getInspectedWindowInfo(m_inspectedViewWindow, m_inspectedViewParentWindow);
+ ::SetWindowPos(m_inspectorViewWindow, 0, windowInfo.left, windowInfo.parentHeight - height, windowInfo.parentWidth - windowInfo.left, height, SWP_NOZORDER);
+ ::SetWindowPos(m_inspectedViewWindow, 0, windowInfo.left, windowInfo.top, windowInfo.parentWidth - windowInfo.left, windowInfo.parentHeight - windowInfo.top, SWP_NOZORDER);
+}
+
+void WebInspectorProxy::platformSetAttachedWindowWidth(unsigned width)
+{
+ auto windowInfo = getInspectedWindowInfo(m_inspectedViewWindow, m_inspectedViewParentWindow);
+ ::SetWindowPos(m_inspectorViewWindow, 0, windowInfo.parentWidth - width, windowInfo.top, width, windowInfo.parentHeight - windowInfo.top, SWP_NOZORDER);
+ ::SetWindowPos(m_inspectedViewWindow, 0, windowInfo.left, windowInfo.top, windowInfo.parentWidth - windowInfo.left, windowInfo.parentHeight - windowInfo.top, SWP_NOZORDER);
+}
+
+bool WebInspectorProxy::platformIsFront()
+{
notImplemented();
+ return false;
}
-void WebInspectorProxy::platformSetAttachedWindowHeight(unsigned /* height */)
+void WebInspectorProxy::platformHide()
{
notImplemented();
}
-void WebInspectorProxy::platformSetAttachedWindowWidth(unsigned /* width */)
+void WebInspectorProxy::platformBringToFront()
{
notImplemented();
}
-void WebInspectorProxy::platformStartWindowDrag()
+void WebInspectorProxy::platformBringInspectedPageToFront()
{
notImplemented();
}
+void WebInspectorProxy::platformInspectedURLChanged(const String& /* url */)
+{
+ notImplemented();
+}
+
void WebInspectorProxy::platformSave(const String&, const String&, bool, bool)
{
notImplemented();
@@ -148,4 +401,24 @@
notImplemented();
}
-} // namespace WebKit
+void WebInspectorProxy::platformCreateFrontendWindow()
+{
+ platformDetach();
+}
+
+void WebInspectorProxy::platformDidCloseForCrash()
+{
+ notImplemented();
+}
+
+void WebInspectorProxy::platformInvalidate()
+{
+ notImplemented();
+}
+
+void WebInspectorProxy::platformStartWindowDrag()
+{
+ notImplemented();
+}
+
+}