summaryrefslogtreecommitdiff
path: root/Source/WebKit2/WebProcess/WebPage/WebInspector.cpp
diff options
context:
space:
mode:
authorOswald Buddenhagen <oswald.buddenhagen@qt.io>2017-05-30 12:48:17 +0200
committerOswald Buddenhagen <oswald.buddenhagen@qt.io>2017-05-30 12:48:17 +0200
commit881da28418d380042aa95a97f0cbd42560a64f7c (patch)
treea794dff3274695e99c651902dde93d934ea7a5af /Source/WebKit2/WebProcess/WebPage/WebInspector.cpp
parent7e104c57a70fdf551bb3d22a5d637cdcbc69dbea (diff)
parent0fcedcd17cc00d3dd44c718b3cb36c1033319671 (diff)
downloadqtwebkit-881da28418d380042aa95a97f0cbd42560a64f7c.tar.gz
Merge 'wip/next' into dev
Change-Id: Iff9ee5e23bb326c4371ec8ed81d56f2f05d680e9
Diffstat (limited to 'Source/WebKit2/WebProcess/WebPage/WebInspector.cpp')
-rw-r--r--Source/WebKit2/WebProcess/WebPage/WebInspector.cpp355
1 files changed, 150 insertions, 205 deletions
diff --git a/Source/WebKit2/WebProcess/WebPage/WebInspector.cpp b/Source/WebKit2/WebProcess/WebPage/WebInspector.cpp
index e4437d655..7337ac414 100644
--- a/Source/WebKit2/WebProcess/WebPage/WebInspector.cpp
+++ b/Source/WebKit2/WebProcess/WebPage/WebInspector.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2010 Apple Inc. All rights reserved.
+ * Copyright (C) 2010, 2014, 2015 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -26,313 +26,258 @@
#include "config.h"
#include "WebInspector.h"
-#if ENABLE(INSPECTOR)
#include "WebFrame.h"
-#include "WebInspectorFrontendClient.h"
+#include "WebInspectorMessages.h"
#include "WebInspectorProxyMessages.h"
+#include "WebInspectorUIMessages.h"
#include "WebPage.h"
-#include "WebPageCreationParameters.h"
#include "WebProcess.h"
-#include <WebCore/Frame.h>
+#include <WebCore/Chrome.h>
+#include <WebCore/Document.h>
+#include <WebCore/FrameLoadRequest.h>
+#include <WebCore/FrameView.h>
#include <WebCore/InspectorController.h>
-#include <WebCore/InspectorFrontendChannel.h>
#include <WebCore/InspectorFrontendClient.h>
+#include <WebCore/InspectorPageAgent.h>
+#include <WebCore/MainFrame.h>
+#include <WebCore/NotImplemented.h>
#include <WebCore/Page.h>
#include <WebCore/ScriptController.h>
-#include <WebCore/ScriptValue.h>
-#include <wtf/text/StringConcatenate.h>
+#include <WebCore/WindowFeatures.h>
using namespace WebCore;
+static const float minimumAttachedHeight = 250;
+static const float maximumAttachedHeightRatio = 0.75;
+static const float minimumAttachedWidth = 500;
+
namespace WebKit {
-PassRefPtr<WebInspector> WebInspector::create(WebPage* page, InspectorFrontendChannel* frontendChannel)
+Ref<WebInspector> WebInspector::create(WebPage* page)
{
- return adoptRef(new WebInspector(page, frontendChannel));
+ return adoptRef(*new WebInspector(page));
}
-WebInspector::WebInspector(WebPage* page, InspectorFrontendChannel* frontendChannel)
+WebInspector::WebInspector(WebPage* page)
: m_page(page)
- , m_inspectorPage(0)
- , m_frontendClient(0)
- , m_frontendChannel(frontendChannel)
-#if PLATFORM(MAC)
- , m_hasLocalizedStringsURL(false)
- , m_usesWebKitUserInterface(false)
-#endif
-#if ENABLE(INSPECTOR_SERVER)
- , m_remoteFrontendConnected(false)
-#endif
-{
-}
-
-// Called from WebInspectorClient
-WebPage* WebInspector::createInspectorPage()
-{
- if (!m_page)
- return 0;
-
- ASSERT(!m_inspectorPage);
- ASSERT(!m_frontendClient);
-
- uint64_t inspectorPageID = 0;
- WebPageCreationParameters parameters;
-
- if (!WebProcess::shared().parentProcessConnection()->sendSync(Messages::WebInspectorProxy::CreateInspectorPage(),
- Messages::WebInspectorProxy::CreateInspectorPage::Reply(inspectorPageID, parameters),
- m_page->pageID(), CoreIPC::Connection::NoTimeout)) {
- return 0;
- }
-
- if (!inspectorPageID)
- return 0;
-
- WebProcess::shared().createWebPage(inspectorPageID, parameters);
- m_inspectorPage = WebProcess::shared().webPage(inspectorPageID);
- ASSERT(m_inspectorPage);
-
- OwnPtr<WebInspectorFrontendClient> frontendClient = adoptPtr(new WebInspectorFrontendClient(m_page, m_inspectorPage));
- m_frontendClient = frontendClient.get();
- m_inspectorPage->corePage()->inspectorController()->setInspectorFrontendClient(frontendClient.release());
- return m_inspectorPage;
-}
-
-void WebInspector::destroyInspectorPage()
-{
- m_inspectorPage = 0;
- m_frontendClient = 0;
- m_frontendChannel = 0;
-}
-
-// Called from WebInspectorFrontendClient
-void WebInspector::didClose()
-{
- WebProcess::shared().parentProcessConnection()->send(Messages::WebInspectorProxy::DidClose(), m_page->pageID());
- destroyInspectorPage();
-}
-
-void WebInspector::bringToFront()
-{
- WebProcess::shared().parentProcessConnection()->send(Messages::WebInspectorProxy::BringToFront(), m_page->pageID());
-}
-
-void WebInspector::inspectedURLChanged(const String& urlString)
{
- WebProcess::shared().parentProcessConnection()->send(Messages::WebInspectorProxy::InspectedURLChanged(urlString), m_page->pageID());
}
-void WebInspector::save(const String& filename, const String& content, bool forceSaveAs)
+WebInspector::~WebInspector()
{
- WebProcess::shared().parentProcessConnection()->send(Messages::WebInspectorProxy::Save(filename, content, forceSaveAs), m_page->pageID());
+ if (m_frontendConnection)
+ m_frontendConnection->invalidate();
}
-void WebInspector::append(const String& filename, const String& content)
-{
- WebProcess::shared().parentProcessConnection()->send(Messages::WebInspectorProxy::Append(filename, content), m_page->pageID());
-}
+// Called from WebInspectorClient
+void WebInspector::openFrontendConnection(bool underTest)
+{
+#if USE(UNIX_DOMAIN_SOCKETS)
+ IPC::Connection::SocketPair socketPair = IPC::Connection::createPlatformConnection();
+ IPC::Connection::Identifier connectionIdentifier(socketPair.server);
+ IPC::Attachment connectionClientPort(socketPair.client);
+#elif OS(DARWIN)
+ mach_port_t listeningPort;
+ mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &listeningPort);
+
+ IPC::Connection::Identifier connectionIdentifier(listeningPort);
+ IPC::Attachment connectionClientPort(listeningPort, MACH_MSG_TYPE_MAKE_SEND);
+#else
+ notImplemented();
+ return;
+#endif
-void WebInspector::attachBottom()
-{
- WebProcess::shared().parentProcessConnection()->send(Messages::WebInspectorProxy::AttachBottom(), m_page->pageID());
-}
+ m_frontendConnection = IPC::Connection::createServerConnection(connectionIdentifier, *this);
+ m_frontendConnection->open();
-void WebInspector::attachRight()
-{
- WebProcess::shared().parentProcessConnection()->send(Messages::WebInspectorProxy::AttachRight(), m_page->pageID());
+ WebProcess::singleton().parentProcessConnection()->send(Messages::WebInspectorProxy::CreateInspectorPage(connectionClientPort, canAttachWindow(), underTest), m_page->pageID());
}
-void WebInspector::detach()
+void WebInspector::closeFrontendConnection()
{
- WebProcess::shared().parentProcessConnection()->send(Messages::WebInspectorProxy::Detach(), m_page->pageID());
-}
+ WebProcess::singleton().parentProcessConnection()->send(Messages::WebInspectorProxy::DidClose(), m_page->pageID());
-void WebInspector::setAttachedWindowHeight(unsigned height)
-{
- WebProcess::shared().parentProcessConnection()->send(Messages::WebInspectorProxy::SetAttachedWindowHeight(height), m_page->pageID());
-}
+ // If we tried to close the frontend before it was created, then no connection exists yet.
+ if (m_frontendConnection) {
+ m_frontendConnection->invalidate();
+ m_frontendConnection = nullptr;
+ }
-void WebInspector::setAttachedWindowWidth(unsigned width)
-{
- WebProcess::shared().parentProcessConnection()->send(Messages::WebInspectorProxy::SetAttachedWindowWidth(width), m_page->pageID());
+ m_attached = false;
+ m_previousCanAttach = false;
}
-void WebInspector::setToolbarHeight(unsigned height)
+void WebInspector::bringToFront()
{
- WebProcess::shared().parentProcessConnection()->send(Messages::WebInspectorProxy::SetToolbarHeight(height), m_page->pageID());
+ WebProcess::singleton().parentProcessConnection()->send(Messages::WebInspectorProxy::BringToFront(), m_page->pageID());
}
// Called by WebInspector messages
void WebInspector::show()
{
- m_page->corePage()->inspectorController()->show();
+ if (!m_page->corePage())
+ return;
+
+ m_page->corePage()->inspectorController().show();
}
void WebInspector::close()
{
- m_page->corePage()->inspectorController()->close();
-}
+ if (!m_page->corePage())
+ return;
-void WebInspector::didSave(const String& url)
-{
- ASSERT(m_inspectorPage);
- m_inspectorPage->corePage()->mainFrame()->script()->executeScript(makeString("InspectorFrontendAPI.savedURL(\"", url, "\")"));
-}
+ // Close could be called multiple times during teardown.
+ if (!m_frontendConnection)
+ return;
-void WebInspector::didAppend(const String& url)
-{
- ASSERT(m_inspectorPage);
- m_inspectorPage->corePage()->mainFrame()->script()->executeScript(makeString("InspectorFrontendAPI.appendedToURL(\"", url, "\")"));
+ m_page->corePage()->inspectorController().disconnectFrontend(this);
+ closeFrontendConnection();
}
-void WebInspector::attachedBottom()
+void WebInspector::openInNewTab(const String& urlString)
{
- if (m_frontendClient)
- m_frontendClient->setAttachedWindow(InspectorFrontendClient::DOCKED_TO_BOTTOM);
-}
+ Page* inspectedPage = m_page->corePage();
+ if (!inspectedPage)
+ return;
-void WebInspector::attachedRight()
-{
- if (m_frontendClient)
- m_frontendClient->setAttachedWindow(InspectorFrontendClient::DOCKED_TO_RIGHT);
-}
+ Frame& inspectedMainFrame = inspectedPage->mainFrame();
+ FrameLoadRequest request(inspectedMainFrame.document()->securityOrigin(), ResourceRequest(urlString), "_blank", LockHistory::No, LockBackForwardList::No, MaybeSendReferrer, AllowNavigationToInvalidURL::Yes, NewFrameOpenerPolicy::Allow, ReplaceDocumentIfJavaScriptURL, ShouldOpenExternalURLsPolicy::ShouldNotAllow);
-void WebInspector::detached()
-{
- if (m_frontendClient)
- m_frontendClient->setAttachedWindow(InspectorFrontendClient::UNDOCKED);
+ Page* newPage = inspectedPage->chrome().createWindow(&inspectedMainFrame, request, WindowFeatures(), NavigationAction(request.resourceRequest(), NavigationType::LinkClicked));
+ if (!newPage)
+ return;
+
+ newPage->mainFrame().loader().load(request);
}
-void WebInspector::evaluateScriptForTest(long callID, const String& script)
+void WebInspector::evaluateScriptForTest(const String& script)
{
- m_page->corePage()->inspectorController()->evaluateForTestInFrontend(callID, script);
+ if (!m_page->corePage())
+ return;
+
+ m_page->corePage()->inspectorController().evaluateForTestInFrontend(script);
}
void WebInspector::showConsole()
{
- m_page->corePage()->inspectorController()->show();
- if (m_frontendClient)
- m_frontendClient->showConsole();
+ if (!m_page->corePage())
+ return;
+
+ m_page->corePage()->inspectorController().show();
+ m_frontendConnection->send(Messages::WebInspectorUI::ShowConsole(), 0);
}
void WebInspector::showResources()
{
- m_page->corePage()->inspectorController()->show();
- if (m_frontendClient)
- m_frontendClient->showResources();
+ if (!m_page->corePage())
+ return;
+
+ m_page->corePage()->inspectorController().show();
+ m_frontendConnection->send(Messages::WebInspectorUI::ShowResources(), 0);
}
-void WebInspector::showMainResourceForFrame(uint64_t frameID)
+void WebInspector::showMainResourceForFrame(uint64_t frameIdentifier)
{
- WebFrame* frame = WebProcess::shared().webFrame(frameID);
+ WebFrame* frame = WebProcess::singleton().webFrame(frameIdentifier);
if (!frame)
return;
- m_page->corePage()->inspectorController()->show();
- if (m_frontendClient)
- m_frontendClient->showMainResourceForFrame(frame->coreFrame());
-}
+ if (!m_page->corePage())
+ return;
-void WebInspector::startJavaScriptDebugging()
-{
-#if ENABLE(JAVASCRIPT_DEBUGGER)
- m_page->corePage()->inspectorController()->show();
- if (m_frontendClient)
- m_frontendClient->setDebuggingEnabled(true);
-#endif
-}
+ m_page->corePage()->inspectorController().show();
-void WebInspector::stopJavaScriptDebugging()
-{
-#if ENABLE(JAVASCRIPT_DEBUGGER)
- m_page->corePage()->inspectorController()->show();
- if (m_frontendClient)
- m_frontendClient->setDebuggingEnabled(false);
-#endif
+ String inspectorFrameIdentifier = m_page->corePage()->inspectorController().pageAgent()->frameId(frame->coreFrame());
+ m_frontendConnection->send(Messages::WebInspectorUI::ShowMainResourceForFrame(inspectorFrameIdentifier), 0);
}
-void WebInspector::setJavaScriptProfilingEnabled(bool enabled)
+void WebInspector::startPageProfiling()
{
-#if ENABLE(JAVASCRIPT_DEBUGGER)
- m_page->corePage()->inspectorController()->show();
- if (!m_frontendClient)
+ if (!m_page->corePage())
return;
- m_page->corePage()->inspectorController()->setProfilerEnabled(enabled);
-#endif
+ m_page->corePage()->inspectorController().show();
+ m_frontendConnection->send(Messages::WebInspectorUI::StartPageProfiling(), 0);
}
-void WebInspector::startJavaScriptProfiling()
+void WebInspector::stopPageProfiling()
{
-#if ENABLE(JAVASCRIPT_DEBUGGER)
- m_page->corePage()->inspectorController()->show();
- if (m_frontendClient)
- m_frontendClient->startProfilingJavaScript();
-#endif
-}
+ if (!m_page->corePage())
+ return;
-void WebInspector::stopJavaScriptProfiling()
-{
-#if ENABLE(JAVASCRIPT_DEBUGGER)
- m_page->corePage()->inspectorController()->show();
- if (m_frontendClient)
- m_frontendClient->stopProfilingJavaScript();
-#endif
+ m_page->corePage()->inspectorController().show();
+ m_frontendConnection->send(Messages::WebInspectorUI::StopPageProfiling(), 0);
}
-void WebInspector::startPageProfiling()
+bool WebInspector::canAttachWindow()
{
- m_page->corePage()->inspectorController()->show();
- if (m_frontendClient)
- m_frontendClient->setTimelineProfilingEnabled(true);
-}
+ if (!m_page->corePage())
+ return false;
-void WebInspector::stopPageProfiling()
-{
- m_page->corePage()->inspectorController()->show();
- if (m_frontendClient)
- m_frontendClient->setTimelineProfilingEnabled(false);
+ // Don't allow attaching to another inspector -- two inspectors in one window is too much!
+ if (m_page->isInspectorPage())
+ return false;
+
+ // If we are already attached, allow attaching again to allow switching sides.
+ if (m_attached)
+ return true;
+
+ // Don't allow the attach if the window would be too small to accommodate the minimum inspector size.
+ unsigned inspectedPageHeight = m_page->corePage()->mainFrame().view()->visibleHeight();
+ unsigned inspectedPageWidth = m_page->corePage()->mainFrame().view()->visibleWidth();
+ unsigned maximumAttachedHeight = inspectedPageHeight * maximumAttachedHeightRatio;
+ return minimumAttachedHeight <= maximumAttachedHeight && minimumAttachedWidth <= inspectedPageWidth;
}
void WebInspector::updateDockingAvailability()
{
- if (!m_frontendClient)
+ if (m_attached)
return;
- bool canAttachWindow = m_frontendClient->canAttachWindow();
- WebProcess::shared().parentProcessConnection()->send(Messages::WebInspectorProxy::AttachAvailabilityChanged(canAttachWindow), m_page->pageID());
- m_frontendClient->setDockingUnavailable(!canAttachWindow);
+ bool canAttachWindow = this->canAttachWindow();
+ if (m_previousCanAttach == canAttachWindow)
+ return;
+
+ m_previousCanAttach = canAttachWindow;
+
+ WebProcess::singleton().parentProcessConnection()->send(Messages::WebInspectorProxy::AttachAvailabilityChanged(canAttachWindow), m_page->pageID());
}
-#if ENABLE(INSPECTOR_SERVER)
-void WebInspector::sendMessageToRemoteFrontend(const String& message)
+void WebInspector::sendMessageToBackend(const String& message)
{
- ASSERT(m_remoteFrontendConnected);
- WebProcess::shared().parentProcessConnection()->send(Messages::WebInspectorProxy::SendMessageToRemoteFrontend(message), m_page->pageID());
+ if (!m_page->corePage())
+ return;
+
+ m_page->corePage()->inspectorController().dispatchMessageFromFrontend(message);
}
-void WebInspector::dispatchMessageFromRemoteFrontend(const String& message)
+bool WebInspector::sendMessageToFrontend(const String& message)
{
- m_page->corePage()->inspectorController()->dispatchMessageFromFrontend(message);
+#if ENABLE(INSPECTOR_SERVER)
+ if (m_remoteFrontendConnected)
+ WebProcess::singleton().parentProcessConnection()->send(Messages::WebInspectorProxy::SendMessageToRemoteFrontend(message), m_page->pageID());
+ else
+#endif
+ m_frontendConnection->send(Messages::WebInspectorUI::SendMessageToFrontend(message), 0);
+ return true;
}
+#if ENABLE(INSPECTOR_SERVER)
void WebInspector::remoteFrontendConnected()
{
- ASSERT(!m_remoteFrontendConnected);
- // Switching between in-process and remote inspectors isn't supported yet.
- ASSERT(!m_inspectorPage);
-
- m_page->corePage()->inspectorController()->connectFrontend(m_frontendChannel);
- m_remoteFrontendConnected = true;
+ if (m_page->corePage()) {
+ m_remoteFrontendConnected = true;
+ m_page->corePage()->inspectorController().connectFrontend(this);
+ }
}
void WebInspector::remoteFrontendDisconnected()
{
- ASSERT(m_remoteFrontendConnected);
- m_page->corePage()->inspectorController()->disconnectFrontend();
m_remoteFrontendConnected = false;
+
+ if (m_page->corePage())
+ m_page->corePage()->inspectorController().disconnectFrontend(this);
}
#endif
} // namespace WebKit
-
-#endif // ENABLE(INSPECTOR)