WebInspectorProxy.cpp [plain text]
#include "config.h"
#include "WebInspectorProxy.h"
#if ENABLE(INSPECTOR)
#include "WebFramePolicyListenerProxy.h"
#include "WebFrameProxy.h"
#include "WebInspectorMessages.h"
#include "WebPageCreationParameters.h"
#include "WebPageGroup.h"
#include "WebPageProxy.h"
#include "WebPreferences.h"
#include "WebProcessProxy.h"
#include "WebURLRequest.h"
#if ENABLE(INSPECTOR_SERVER)
#include "WebInspectorServer.h"
#endif
#if PLATFORM(WIN)
#include "WebView.h"
#endif
using namespace WebCore;
namespace WebKit {
static PassRefPtr<WebPageGroup> createInspectorPageGroup()
{
RefPtr<WebPageGroup> pageGroup = WebPageGroup::create("__WebInspectorPageGroup__", false, false);
#ifndef NDEBUG
pageGroup->preferences()->setDeveloperExtrasEnabled(true);
#endif
pageGroup->preferences()->setApplicationChromeModeEnabled(true);
pageGroup->preferences()->setSuppressesIncrementalRendering(true);
return pageGroup.release();
}
WebPageGroup* WebInspectorProxy::inspectorPageGroup()
{
static WebPageGroup* pageGroup = createInspectorPageGroup().leakRef();
return pageGroup;
}
WebInspectorProxy::WebInspectorProxy(WebPageProxy* page)
: m_page(page)
, m_isVisible(false)
, m_isAttached(false)
, m_isDebuggingJavaScript(false)
, m_isProfilingJavaScript(false)
, m_isProfilingPage(false)
#if PLATFORM(WIN)
, m_inspectorWindow(0)
#elif PLATFORM(GTK)
, m_inspectorView(0)
, m_inspectorWindow(0)
#endif
#if ENABLE(INSPECTOR_SERVER)
, m_remoteInspectionPageId(0)
#endif
{
}
WebInspectorProxy::~WebInspectorProxy()
{
}
void WebInspectorProxy::invalidate()
{
#if ENABLE(INSPECTOR_SERVER)
if (m_remoteInspectionPageId)
WebInspectorServer::shared().unregisterPage(m_remoteInspectionPageId);
#endif
m_page->close();
didClose();
m_page = 0;
m_isVisible = false;
m_isDebuggingJavaScript = false;
m_isProfilingJavaScript = false;
m_isProfilingPage = false;
}
bool WebInspectorProxy::isFront()
{
if (!m_page)
return false;
return platformIsFront();
}
void WebInspectorProxy::show()
{
if (!m_page)
return;
m_page->process()->send(Messages::WebInspector::Show(), m_page->pageID());
}
void WebInspectorProxy::close()
{
if (!m_page)
return;
m_page->process()->send(Messages::WebInspector::Close(), m_page->pageID());
}
void WebInspectorProxy::showConsole()
{
if (!m_page)
return;
m_page->process()->send(Messages::WebInspector::ShowConsole(), m_page->pageID());
}
void WebInspectorProxy::showResources()
{
if (!m_page)
return;
m_page->process()->send(Messages::WebInspector::ShowResources(), m_page->pageID());
}
void WebInspectorProxy::showMainResourceForFrame(WebFrameProxy* frame)
{
if (!m_page)
return;
m_page->process()->send(Messages::WebInspector::ShowMainResourceForFrame(frame->frameID()), m_page->pageID());
}
void WebInspectorProxy::attach()
{
if (!canAttach())
return;
m_isAttached = true;
if (m_isVisible)
inspectorPageGroup()->preferences()->setInspectorStartsAttached(true);
platformAttach();
}
void WebInspectorProxy::detach()
{
m_isAttached = false;
if (m_isVisible)
inspectorPageGroup()->preferences()->setInspectorStartsAttached(false);
platformDetach();
}
void WebInspectorProxy::setAttachedWindowHeight(unsigned height)
{
inspectorPageGroup()->preferences()->setInspectorAttachedHeight(height);
platformSetAttachedWindowHeight(height);
}
void WebInspectorProxy::toggleJavaScriptDebugging()
{
if (!m_page)
return;
if (m_isDebuggingJavaScript)
m_page->process()->send(Messages::WebInspector::StopJavaScriptDebugging(), m_page->pageID());
else
m_page->process()->send(Messages::WebInspector::StartJavaScriptDebugging(), m_page->pageID());
m_isDebuggingJavaScript = !m_isDebuggingJavaScript;
}
void WebInspectorProxy::toggleJavaScriptProfiling()
{
if (!m_page)
return;
if (m_isProfilingJavaScript)
m_page->process()->send(Messages::WebInspector::StopJavaScriptProfiling(), m_page->pageID());
else
m_page->process()->send(Messages::WebInspector::StartJavaScriptProfiling(), m_page->pageID());
m_isProfilingJavaScript = !m_isProfilingJavaScript;
}
void WebInspectorProxy::togglePageProfiling()
{
if (!m_page)
return;
if (m_isProfilingPage)
m_page->process()->send(Messages::WebInspector::StopPageProfiling(), m_page->pageID());
else
m_page->process()->send(Messages::WebInspector::StartPageProfiling(), m_page->pageID());
m_isProfilingPage = !m_isProfilingPage;
}
bool WebInspectorProxy::isInspectorPage(WebPageProxy* page)
{
return page->pageGroup() == inspectorPageGroup();
}
static void decidePolicyForNavigationAction(WKPageRef, WKFrameRef frameRef, WKFrameNavigationType, WKEventModifiers, WKEventMouseButton, WKURLRequestRef requestRef, WKFramePolicyListenerRef listenerRef, WKTypeRef, const void* clientInfo)
{
if (!toImpl(frameRef)->isMainFrame()) {
toImpl(listenerRef)->use();
return;
}
const WebInspectorProxy* webInspectorProxy = static_cast<const WebInspectorProxy*>(clientInfo);
ASSERT(webInspectorProxy);
KURL inspectorURL(KURL(), webInspectorProxy->inspectorPageURL());
KURL requestURL(KURL(), toImpl(requestRef)->url());
ASSERT(inspectorURL.isLocalFile());
if (requestURL.isLocalFile() && requestURL.fileSystemPath() == inspectorURL.fileSystemPath()) {
toImpl(listenerRef)->use();
return;
}
toImpl(listenerRef)->ignore();
webInspectorProxy->page()->loadURLRequest(toImpl(requestRef));
}
#if ENABLE(INSPECTOR_SERVER)
void WebInspectorProxy::enableRemoteInspection()
{
if (!m_remoteInspectionPageId)
m_remoteInspectionPageId = WebInspectorServer::shared().registerPage(this);
}
void WebInspectorProxy::remoteFrontendConnected()
{
m_page->process()->send(Messages::WebInspector::RemoteFrontendConnected(), m_page->pageID());
}
void WebInspectorProxy::remoteFrontendDisconnected()
{
m_page->process()->send(Messages::WebInspector::RemoteFrontendDisconnected(), m_page->pageID());
}
void WebInspectorProxy::dispatchMessageFromRemoteFrontend(const String& message)
{
m_page->process()->send(Messages::WebInspector::DispatchMessageFromRemoteFrontend(message), m_page->pageID());
}
#endif
void WebInspectorProxy::createInspectorPage(uint64_t& inspectorPageID, WebPageCreationParameters& inspectorPageParameters)
{
inspectorPageID = 0;
if (!m_page)
return;
m_isAttached = shouldOpenAttached();
WebPageProxy* inspectorPage = platformCreateInspectorPage();
ASSERT(inspectorPage);
if (!inspectorPage)
return;
inspectorPageID = inspectorPage->pageID();
inspectorPageParameters = inspectorPage->creationParameters();
WKPagePolicyClient policyClient = {
kWKPagePolicyClientCurrentVersion,
this,
decidePolicyForNavigationAction,
0,
0,
0
};
inspectorPage->initializePolicyClient(&policyClient);
String url = inspectorPageURL();
if (m_isAttached)
url += "?docked=true";
m_page->process()->assumeReadAccessToBaseURL(inspectorBaseURL());
inspectorPage->loadURL(url);
}
void WebInspectorProxy::didLoadInspectorPage()
{
m_isVisible = true;
platformOpen();
}
void WebInspectorProxy::didClose()
{
m_isVisible = false;
m_isDebuggingJavaScript = false;
m_isProfilingJavaScript = false;
m_isProfilingPage = false;
if (m_isAttached) {
detach();
}
platformDidClose();
}
void WebInspectorProxy::bringToFront()
{
platformBringToFront();
}
void WebInspectorProxy::inspectedURLChanged(const String& urlString)
{
platformInspectedURLChanged(urlString);
}
bool WebInspectorProxy::canAttach()
{
bool isInspectorPage = m_page->pageGroup() == inspectorPageGroup();
unsigned inspectedPageHeight = platformInspectedWindowHeight();
unsigned maximumAttachedHeight = inspectedPageHeight * 3 / 4;
return minimumAttachedHeight <= maximumAttachedHeight && !isInspectorPage;
}
bool WebInspectorProxy::shouldOpenAttached()
{
return inspectorPageGroup()->preferences()->inspectorStartsAttached() && canAttach();
}
#if ENABLE(INSPECTOR_SERVER)
void WebInspectorProxy::sendMessageToRemoteFrontend(const String& message)
{
ASSERT(m_remoteInspectionPageId);
WebInspectorServer::shared().sendMessageOverConnection(m_remoteInspectionPageId, message);
}
#endif
}
#endif // ENABLE(INSPECTOR)