diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
commit | 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch) | |
tree | 46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebKit2/UIProcess/WebInspectorProxy.cpp | |
parent | 32761a6cee1d0dee366b885b7b9c777e67885688 (diff) | |
download | WebKitGtk-tarball-master.tar.gz |
webkitgtk-2.16.5HEADwebkitgtk-2.16.5master
Diffstat (limited to 'Source/WebKit2/UIProcess/WebInspectorProxy.cpp')
-rw-r--r-- | Source/WebKit2/UIProcess/WebInspectorProxy.cpp | 672 |
1 files changed, 432 insertions, 240 deletions
diff --git a/Source/WebKit2/UIProcess/WebInspectorProxy.cpp b/Source/WebKit2/UIProcess/WebInspectorProxy.cpp index 2d2297f8c..38c8039f7 100644 --- a/Source/WebKit2/UIProcess/WebInspectorProxy.cpp +++ b/Source/WebKit2/UIProcess/WebInspectorProxy.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010 Apple Inc. All rights reserved. + * Copyright (C) 2010, 2014, 2016 Apple Inc. All rights reserved. * Portions Copyright (c) 2011 Motorola Mobility, Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -27,19 +27,23 @@ #include "config.h" #include "WebInspectorProxy.h" -#if ENABLE(INSPECTOR) - -#include "APIURLRequest.h" +#include "APINavigationAction.h" +#include "APIProcessPoolConfiguration.h" +#include "WKArray.h" +#include "WKContextMenuItem.h" +#include "WKMutableArray.h" +#include "WebAutomationSession.h" #include "WebFramePolicyListenerProxy.h" #include "WebFrameProxy.h" #include "WebInspectorMessages.h" #include "WebInspectorProxyMessages.h" -#include "WebPageCreationParameters.h" +#include "WebInspectorUIMessages.h" #include "WebPageGroup.h" #include "WebPageProxy.h" #include "WebPreferences.h" +#include "WebProcessPool.h" #include "WebProcessProxy.h" -#include <WebCore/SchemeRegistry.h> +#include <WebCore/NotImplemented.h> #include <wtf/NeverDestroyed.h> #if ENABLE(INSPECTOR_SERVER) @@ -50,129 +54,55 @@ using namespace WebCore; namespace WebKit { -const unsigned WebInspectorProxy::minimumWindowWidth = 750; +const unsigned WebInspectorProxy::minimumWindowWidth = 500; const unsigned WebInspectorProxy::minimumWindowHeight = 400; const unsigned WebInspectorProxy::initialWindowWidth = 1000; const unsigned WebInspectorProxy::initialWindowHeight = 650; -const unsigned WebInspectorProxy::minimumAttachedWidth = 750; -const unsigned WebInspectorProxy::minimumAttachedHeight = 250; - -class WebInspectorPageGroups { -public: - static WebInspectorPageGroups& shared() - { - static NeverDestroyed<WebInspectorPageGroups> instance; - return instance; - } - - unsigned inspectorLevel(WebPageGroup& inspectedPageGroup) - { - return isInspectorPageGroup(inspectedPageGroup) ? inspectorPageGroupLevel(inspectedPageGroup) + 1 : 1; - } - - bool isInspectorPageGroup(WebPageGroup& group) - { - return m_pageGroupLevel.contains(&group); - } - - unsigned inspectorPageGroupLevel(WebPageGroup& group) - { - ASSERT(isInspectorPageGroup(group)); - return m_pageGroupLevel.get(&group); - } - - WebPageGroup* inspectorPageGroupForLevel(unsigned level) - { - // The level is the key of the HashMap, so it cannot be 0. - ASSERT(level); - - auto iterator = m_pageGroupByLevel.find(level); - if (iterator != m_pageGroupByLevel.end()) - return iterator->value.get(); - - RefPtr<WebPageGroup> group = createInspectorPageGroup(level); - m_pageGroupByLevel.set(level, group.get()); - m_pageGroupLevel.set(group.get(), level); - return group.get(); - } - -private: - static PassRefPtr<WebPageGroup> createInspectorPageGroup(unsigned level) - { - RefPtr<WebPageGroup> pageGroup = WebPageGroup::create(String::format("__WebInspectorPageGroupLevel%u__", level), false, false); - -#ifndef NDEBUG - // Allow developers to inspect the Web Inspector in debug builds. - pageGroup->preferences()->setDeveloperExtrasEnabled(true); - pageGroup->preferences()->setLogsPageMessagesToSystemConsoleEnabled(true); -#endif - - pageGroup->preferences()->setApplicationChromeModeEnabled(true); - - return pageGroup.release(); - } - - typedef HashMap<unsigned, RefPtr<WebPageGroup> > PageGroupByLevelMap; - typedef HashMap<WebPageGroup*, unsigned> PageGroupLevelMap; - - PageGroupByLevelMap m_pageGroupByLevel; - PageGroupLevelMap m_pageGroupLevel; -}; - -WebInspectorProxy::WebInspectorProxy(WebPageProxy* page) - : m_page(page) - , m_isVisible(false) - , m_isAttached(false) - , m_isDebuggingJavaScript(false) - , m_isProfilingJavaScript(false) - , m_isProfilingPage(false) - , m_showMessageSent(false) - , m_createdInspectorPage(false) - , m_ignoreFirstBringToFront(false) - , m_attachmentSide(AttachmentSideBottom) -#if PLATFORM(GTK) || PLATFORM(EFL) - , m_inspectorView(0) - , m_inspectorWindow(0) -#endif -#if ENABLE(INSPECTOR_SERVER) - , m_remoteInspectionPageId(0) +WebInspectorProxy::WebInspectorProxy(WebPageProxy* inspectedPage) + : m_inspectedPage(inspectedPage) +#if PLATFORM(MAC) && WK_API_ENABLED + , m_closeTimer(RunLoop::main(), this, &WebInspectorProxy::closeTimerFired) #endif { - m_level = WebInspectorPageGroups::shared().inspectorLevel(m_page->pageGroup()); - m_page->process().addMessageReceiver(Messages::WebInspectorProxy::messageReceiverName(), m_page->pageID(), *this); + m_inspectedPage->process().addMessageReceiver(Messages::WebInspectorProxy::messageReceiverName(), m_inspectedPage->pageID(), *this); } WebInspectorProxy::~WebInspectorProxy() { } -WebPageGroup* WebInspectorProxy::inspectorPageGroup() const +unsigned WebInspectorProxy::inspectionLevel() const +{ + return inspectorLevelForPage(inspectedPage()); +} + +WebPreferences& WebInspectorProxy::inspectorPagePreferences() const { - return WebInspectorPageGroups::shared().inspectorPageGroupForLevel(m_level); + ASSERT(m_inspectorPage); + return m_inspectorPage->pageGroup().preferences(); } void WebInspectorProxy::invalidate() { #if ENABLE(INSPECTOR_SERVER) if (m_remoteInspectionPageId) - WebInspectorServer::shared().unregisterPage(m_remoteInspectionPageId); + WebInspectorServer::singleton().unregisterPage(m_remoteInspectionPageId); #endif - m_page->process().removeMessageReceiver(Messages::WebInspectorProxy::messageReceiverName(), m_page->pageID()); - - m_page->close(); + m_inspectedPage->process().removeMessageReceiver(Messages::WebInspectorProxy::messageReceiverName(), m_inspectedPage->pageID()); didClose(); + platformInvalidate(); - m_page = 0; + m_inspectedPage = nullptr; } // Public APIs bool WebInspectorProxy::isFront() { - if (!m_page) + if (!m_inspectedPage) return false; return platformIsFront(); @@ -180,7 +110,7 @@ bool WebInspectorProxy::isFront() void WebInspectorProxy::connect() { - if (!m_page) + if (!m_inspectedPage) return; if (m_showMessageSent) @@ -189,12 +119,14 @@ void WebInspectorProxy::connect() m_showMessageSent = true; m_ignoreFirstBringToFront = true; - m_page->process().send(Messages::WebInspector::Show(), m_page->pageID()); + eagerlyCreateInspectorPage(); + + m_inspectedPage->process().send(Messages::WebInspector::Show(), m_inspectedPage->pageID()); } void WebInspectorProxy::show() { - if (!m_page) + if (!m_inspectedPage) return; if (isConnected()) { @@ -210,7 +142,7 @@ void WebInspectorProxy::show() void WebInspectorProxy::hide() { - if (!m_page) + if (!m_inspectedPage) return; m_isVisible = false; @@ -220,68 +152,102 @@ void WebInspectorProxy::hide() void WebInspectorProxy::close() { - if (!m_page) + if (!m_inspectedPage) return; - m_page->process().send(Messages::WebInspector::Close(), m_page->pageID()); + m_inspectedPage->process().send(Messages::WebInspector::Close(), m_inspectedPage->pageID()); didClose(); } +void WebInspectorProxy::closeForCrash() +{ + close(); + + platformDidCloseForCrash(); +} + void WebInspectorProxy::showConsole() { - if (!m_page) + if (!m_inspectedPage) return; - m_page->process().send(Messages::WebInspector::ShowConsole(), m_page->pageID()); + eagerlyCreateInspectorPage(); + + m_inspectedPage->process().send(Messages::WebInspector::ShowConsole(), m_inspectedPage->pageID()); } void WebInspectorProxy::showResources() { - if (!m_page) + if (!m_inspectedPage) return; - m_page->process().send(Messages::WebInspector::ShowResources(), m_page->pageID()); + eagerlyCreateInspectorPage(); + + m_inspectedPage->process().send(Messages::WebInspector::ShowResources(), m_inspectedPage->pageID()); +} + +void WebInspectorProxy::showTimelines() +{ + if (!m_inspectedPage) + return; + + eagerlyCreateInspectorPage(); + + m_inspectedPage->process().send(Messages::WebInspector::ShowTimelines(), m_inspectedPage->pageID()); } void WebInspectorProxy::showMainResourceForFrame(WebFrameProxy* frame) { - if (!m_page) + if (!m_inspectedPage) return; - m_page->process().send(Messages::WebInspector::ShowMainResourceForFrame(frame->frameID()), m_page->pageID()); + eagerlyCreateInspectorPage(); + + m_inspectedPage->process().send(Messages::WebInspector::ShowMainResourceForFrame(frame->frameID()), m_inspectedPage->pageID()); } void WebInspectorProxy::attachBottom() { - attach(AttachmentSideBottom); + attach(AttachmentSide::Bottom); } void WebInspectorProxy::attachRight() { - attach(AttachmentSideRight); + attach(AttachmentSide::Right); +} + +void WebInspectorProxy::attachLeft() +{ + attach(AttachmentSide::Left); } void WebInspectorProxy::attach(AttachmentSide side) { - if (!m_page || !canAttach()) + if (!m_inspectedPage || !canAttach()) return; m_isAttached = true; m_attachmentSide = side; - inspectorPageGroup()->preferences()->setInspectorAttachmentSide(side); + inspectorPagePreferences().setInspectorAttachmentSide(static_cast<uint32_t>(side)); if (m_isVisible) - inspectorPageGroup()->preferences()->setInspectorStartsAttached(true); + inspectorPagePreferences().setInspectorStartsAttached(true); + + m_inspectedPage->process().send(Messages::WebInspector::SetAttached(true), m_inspectedPage->pageID()); switch (m_attachmentSide) { - case AttachmentSideBottom: - m_page->process().send(Messages::WebInspector::AttachedBottom(), m_page->pageID()); + case AttachmentSide::Bottom: + m_inspectorPage->process().send(Messages::WebInspectorUI::AttachedBottom(), m_inspectorPage->pageID()); + break; + + case AttachmentSide::Right: + m_inspectorPage->process().send(Messages::WebInspectorUI::AttachedRight(), m_inspectorPage->pageID()); break; - case AttachmentSideRight: - m_page->process().send(Messages::WebInspector::AttachedRight(), m_page->pageID()); + case AttachmentSide::Left: + m_inspectorPage->process().send(Messages::WebInspectorUI::AttachedLeft(), m_inspectorPage->pageID()); break; } @@ -290,103 +256,105 @@ void WebInspectorProxy::attach(AttachmentSide side) void WebInspectorProxy::detach() { - if (!m_page) + if (!m_inspectedPage) return; m_isAttached = false; if (m_isVisible) - inspectorPageGroup()->preferences()->setInspectorStartsAttached(false); + inspectorPagePreferences().setInspectorStartsAttached(false); - m_page->process().send(Messages::WebInspector::Detached(), m_page->pageID()); + m_inspectedPage->process().send(Messages::WebInspector::SetAttached(false), m_inspectedPage->pageID()); + m_inspectorPage->process().send(Messages::WebInspectorUI::Detached(), m_inspectorPage->pageID()); platformDetach(); } void WebInspectorProxy::setAttachedWindowHeight(unsigned height) { - inspectorPageGroup()->preferences()->setInspectorAttachedHeight(height); + inspectorPagePreferences().setInspectorAttachedHeight(height); platformSetAttachedWindowHeight(height); } void WebInspectorProxy::setAttachedWindowWidth(unsigned width) { - inspectorPageGroup()->preferences()->setInspectorAttachedWidth(width); + inspectorPagePreferences().setInspectorAttachedWidth(width); platformSetAttachedWindowWidth(width); } -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()); - - // FIXME: have the WebProcess notify us on state changes. - m_isDebuggingJavaScript = !m_isDebuggingJavaScript; -} - -void WebInspectorProxy::toggleJavaScriptProfiling() +void WebInspectorProxy::startWindowDrag() { - 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()); - - // FIXME: have the WebProcess notify us on state changes. - m_isProfilingJavaScript = !m_isProfilingJavaScript; + platformStartWindowDrag(); } void WebInspectorProxy::togglePageProfiling() { - if (!m_page) + if (!m_inspectedPage) return; if (m_isProfilingPage) - m_page->process().send(Messages::WebInspector::StopPageProfiling(), m_page->pageID()); + m_inspectedPage->process().send(Messages::WebInspector::StopPageProfiling(), m_inspectedPage->pageID()); else - m_page->process().send(Messages::WebInspector::StartPageProfiling(), m_page->pageID()); + m_inspectedPage->process().send(Messages::WebInspector::StartPageProfiling(), m_inspectedPage->pageID()); // FIXME: have the WebProcess notify us on state changes. m_isProfilingPage = !m_isProfilingPage; } -bool WebInspectorProxy::isInspectorPage(WebPageProxy& page) +void WebInspectorProxy::toggleElementSelection() { - return WebInspectorPageGroups::shared().isInspectorPageGroup(page.pageGroup()); + if (!m_inspectedPage) + return; + + if (m_elementSelectionActive) { + m_ignoreElementSelectionChange = true; + m_inspectedPage->process().send(Messages::WebInspector::StopElementSelection(), m_inspectedPage->pageID()); + } else { + connect(); + m_inspectedPage->process().send(Messages::WebInspector::StartElementSelection(), m_inspectedPage->pageID()); + } } -static bool isMainInspectorPage(const WebInspectorProxy* webInspectorProxy, WKURLRequestRef requestRef) +bool WebInspectorProxy::isMainOrTestInspectorPage(const URL& url) { - // Use URL so we can compare just the paths. - URL inspectorURL(URL(), webInspectorProxy->inspectorPageURL()); - URL requestURL(URL(), toImpl(requestRef)->resourceRequest().url()); + // Use URL so we can compare the paths and protocols. + URL mainPageURL(URL(), WebInspectorProxy::inspectorPageURL()); + if (url.protocol() == mainPageURL.protocol() && decodeURLEscapeSequences(url.path()) == decodeURLEscapeSequences(mainPageURL.path())) + return true; + + // We might not have a Test URL in Production builds. + String testPageURLString = WebInspectorProxy::inspectorTestPageURL(); + if (testPageURLString.isNull()) + return false; - ASSERT(WebCore::SchemeRegistry::shouldTreatURLSchemeAsLocal(inspectorURL.protocol())); + URL testPageURL(URL(), testPageURLString); + return url.protocol() == testPageURL.protocol() && decodeURLEscapeSequences(url.path()) == decodeURLEscapeSequences(testPageURL.path()); +} - return WebCore::SchemeRegistry::shouldTreatURLSchemeAsLocal(requestURL.protocol()) && decodeURLEscapeSequences(requestURL.path()) == decodeURLEscapeSequences(inspectorURL.path()); +static void webProcessDidCrash(WKPageRef, const void* clientInfo) +{ + WebInspectorProxy* webInspectorProxy = static_cast<WebInspectorProxy*>(const_cast<void*>(clientInfo)); + ASSERT(webInspectorProxy); + webInspectorProxy->closeForCrash(); } -static void decidePolicyForNavigationAction(WKPageRef, WKFrameRef frameRef, WKFrameNavigationType, WKEventModifiers, WKEventMouseButton, WKFrameRef, WKURLRequestRef requestRef, WKFramePolicyListenerRef listenerRef, WKTypeRef, const void* clientInfo) +static void decidePolicyForNavigationAction(WKPageRef pageRef, WKNavigationActionRef navigationActionRef, WKFramePolicyListenerRef listenerRef, WKTypeRef, const void* clientInfo) { // Allow non-main frames to navigate anywhere. - if (!toImpl(frameRef)->isMainFrame()) { - toImpl(listenerRef)->use(); + API::FrameInfo* sourceFrame = toImpl(navigationActionRef)->sourceFrame(); + if (sourceFrame && !sourceFrame->isMainFrame()) { + toImpl(listenerRef)->use({ }); return; } const WebInspectorProxy* webInspectorProxy = static_cast<const WebInspectorProxy*>(clientInfo); ASSERT(webInspectorProxy); + WebCore::ResourceRequest request = toImpl(navigationActionRef)->request(); + // Allow loading of the main inspector file. - if (isMainInspectorPage(webInspectorProxy, requestRef)) { - toImpl(listenerRef)->use(); + if (WebInspectorProxy::isMainOrTestInspectorPage(request.url())) { + toImpl(listenerRef)->use({ }); return; } @@ -394,115 +362,208 @@ static void decidePolicyForNavigationAction(WKPageRef, WKFrameRef frameRef, WKFr toImpl(listenerRef)->ignore(); // And instead load it in the inspected page. - webInspectorProxy->page()->loadRequest(toImpl(requestRef)->resourceRequest()); + webInspectorProxy->inspectedPage()->loadRequest(request); +} + +static void getContextMenuFromProposedMenu(WKPageRef pageRef, WKArrayRef proposedMenuRef, WKArrayRef* newMenuRef, WKHitTestResultRef, WKTypeRef, const void*) +{ + WKMutableArrayRef menuItems = WKMutableArrayCreate(); + + size_t count = WKArrayGetSize(proposedMenuRef); + for (size_t i = 0; i < count; ++i) { + WKContextMenuItemRef contextMenuItem = static_cast<WKContextMenuItemRef>(WKArrayGetItemAtIndex(proposedMenuRef, i)); + switch (WKContextMenuItemGetTag(contextMenuItem)) { + case kWKContextMenuItemTagOpenLinkInNewWindow: + case kWKContextMenuItemTagOpenImageInNewWindow: + case kWKContextMenuItemTagOpenFrameInNewWindow: + case kWKContextMenuItemTagOpenMediaInNewWindow: + case kWKContextMenuItemTagDownloadLinkToDisk: + case kWKContextMenuItemTagDownloadImageToDisk: + break; + default: + WKArrayAppendItem(menuItems, contextMenuItem); + break; + } + } + + *newMenuRef = menuItems; } #if ENABLE(INSPECTOR_SERVER) void WebInspectorProxy::enableRemoteInspection() { if (!m_remoteInspectionPageId) - m_remoteInspectionPageId = WebInspectorServer::shared().registerPage(this); + m_remoteInspectionPageId = WebInspectorServer::singleton().registerPage(this); } void WebInspectorProxy::remoteFrontendConnected() { - m_page->process().send(Messages::WebInspector::RemoteFrontendConnected(), m_page->pageID()); + m_inspectedPage->process().send(Messages::WebInspector::RemoteFrontendConnected(), m_inspectedPage->pageID()); } void WebInspectorProxy::remoteFrontendDisconnected() { - m_page->process().send(Messages::WebInspector::RemoteFrontendDisconnected(), m_page->pageID()); + m_inspectedPage->process().send(Messages::WebInspector::RemoteFrontendDisconnected(), m_inspectedPage->pageID()); } void WebInspectorProxy::dispatchMessageFromRemoteFrontend(const String& message) { - m_page->process().send(Messages::WebInspector::DispatchMessageFromRemoteFrontend(message), m_page->pageID()); + m_inspectedPage->process().send(Messages::WebInspector::SendMessageToBackend(message), m_inspectedPage->pageID()); } #endif -// Called by WebInspectorProxy messages -void WebInspectorProxy::createInspectorPage(uint64_t& inspectorPageID, WebPageCreationParameters& inspectorPageParameters) +void WebInspectorProxy::eagerlyCreateInspectorPage() { - inspectorPageID = 0; - - if (!m_page) + if (m_inspectorPage) return; - m_isAttached = shouldOpenAttached(); - m_attachmentSide = static_cast<AttachmentSide>(inspectorPageGroup()->preferences()->inspectorAttachmentSide()); - - WebPageProxy* inspectorPage = platformCreateInspectorPage(); - ASSERT(inspectorPage); - if (!inspectorPage) + m_inspectorPage = platformCreateInspectorPage(); + ASSERT(m_inspectorPage); + if (!m_inspectorPage) return; - inspectorPageID = inspectorPage->pageID(); - inspectorPageParameters = inspectorPage->creationParameters(); + trackInspectorPage(m_inspectorPage); - WKPagePolicyClientV1 policyClient = { - { 1, this }, - 0, /* decidePolicyForNavigationAction_deprecatedForUseWithV0 */ - 0, /* decidePolicyForNewWindowAction */ - 0, /* decidePolicyForResponse_deprecatedForUseWithV0 */ - 0, /* unableToImplementPolicy */ + WKPageNavigationClientV0 navigationClient = { + { 0, this }, decidePolicyForNavigationAction, - 0, /* decidePolicyForResponse */ + 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 }; - WKPageSetPagePolicyClient(toAPI(inspectorPage), &policyClient.base); + WKPageContextMenuClientV3 contextMenuClient = { + { 3, this }, + nullptr, // getContextMenuFromProposedMenu_deprecatedForUseWithV0 + nullptr, // customContextMenuItemSelected + nullptr, // contextMenuDismissed + getContextMenuFromProposedMenu, + nullptr, // showContextMenu + nullptr, // hideContextMenu + }; - String url = inspectorPageURL(); + WKPageSetPageNavigationClient(toAPI(m_inspectorPage), &navigationClient.base); + WKPageSetPageContextMenuClient(toAPI(m_inspectorPage), &contextMenuClient.base); - url.append("?dockSide="); + m_inspectorPage->process().addMessageReceiver(Messages::WebInspectorProxy::messageReceiverName(), m_inspectedPage->pageID(), *this); + m_inspectorPage->process().assumeReadAccessToBaseURL(WebInspectorProxy::inspectorBaseURL()); +} - if (m_isAttached) { - switch (m_attachmentSide) { - case AttachmentSideBottom: - url.append("bottom"); - m_page->process().send(Messages::WebInspector::AttachedBottom(), m_page->pageID()); - break; - case AttachmentSideRight: - url.append("right"); - m_page->process().send(Messages::WebInspector::AttachedRight(), m_page->pageID()); - break; - } - } else - url.append("undocked"); +// Called by WebInspectorProxy messages +void WebInspectorProxy::createInspectorPage(IPC::Attachment connectionIdentifier, bool canAttach, bool underTest) +{ + if (!m_inspectedPage) + return; - m_page->process().assumeReadAccessToBaseURL(inspectorBaseURL()); + m_underTest = underTest; + eagerlyCreateInspectorPage(); - inspectorPage->loadRequest(URL(URL(), url)); + ASSERT(m_inspectorPage); + if (!m_inspectorPage) + return; - m_createdInspectorPage = true; + m_connectionIdentifier = WTFMove(connectionIdentifier); + + m_inspectorPage->process().send(Messages::WebInspectorUI::EstablishConnection(m_connectionIdentifier, m_inspectedPage->pageID(), m_underTest, inspectionLevel()), m_inspectorPage->pageID()); + + if (!m_underTest) { + m_canAttach = platformCanAttach(canAttach); + m_isAttached = shouldOpenAttached(); + m_attachmentSide = static_cast<AttachmentSide>(inspectorPagePreferences().inspectorAttachmentSide()); + + m_inspectedPage->process().send(Messages::WebInspector::SetAttached(m_isAttached), m_inspectedPage->pageID()); + + if (m_isAttached) { + switch (m_attachmentSide) { + case AttachmentSide::Bottom: + m_inspectorPage->process().send(Messages::WebInspectorUI::AttachedBottom(), m_inspectorPage->pageID()); + break; + + case AttachmentSide::Right: + m_inspectorPage->process().send(Messages::WebInspectorUI::AttachedRight(), m_inspectorPage->pageID()); + break; + + case AttachmentSide::Left: + m_inspectorPage->process().send(Messages::WebInspectorUI::AttachedLeft(), m_inspectorPage->pageID()); + break; + } + } else + m_inspectorPage->process().send(Messages::WebInspectorUI::Detached(), m_inspectorPage->pageID()); + + m_inspectorPage->process().send(Messages::WebInspectorUI::SetDockingUnavailable(!m_canAttach), m_inspectorPage->pageID()); + } + + m_inspectorPage->loadRequest(URL(URL(), m_underTest ? WebInspectorProxy::inspectorTestPageURL() : WebInspectorProxy::inspectorPageURL())); } void WebInspectorProxy::open() { + if (m_underTest) + return; + + if (!m_inspectorPage) + return; + m_isVisible = true; + m_inspectorPage->process().send(Messages::WebInspectorUI::SetIsVisible(m_isVisible), m_inspectorPage->pageID()); platformOpen(); } void WebInspectorProxy::didClose() { - if (!m_createdInspectorPage) + if (!m_inspectorPage) return; m_isVisible = false; - m_isDebuggingJavaScript = false; - m_isProfilingJavaScript = false; m_isProfilingPage = false; - m_createdInspectorPage = false; m_showMessageSent = false; m_ignoreFirstBringToFront = false; + untrackInspectorPage(m_inspectorPage); + + m_inspectorPage->process().send(Messages::WebInspectorUI::SetIsVisible(m_isVisible), m_inspectorPage->pageID()); + m_inspectorPage->process().removeMessageReceiver(Messages::WebInspectorProxy::messageReceiverName(), m_inspectedPage->pageID()); + if (m_isAttached) platformDetach(); + + // Null out m_inspectorPage after platformDetach(), so the views can be cleaned up correctly. + m_inspectorPage = nullptr; + m_isAttached = false; + m_canAttach = false; + m_underTest = false; + + m_connectionIdentifier = IPC::Attachment(); platformDidClose(); } +void WebInspectorProxy::frontendLoaded() +{ + if (auto* automationSession = m_inspectedPage->process().processPool().automationSession()) + automationSession->inspectorFrontendLoaded(*m_inspectedPage); +} + void WebInspectorProxy::bringToFront() { // WebCore::InspectorFrontendClientLocal tells us to do this on load. We want to @@ -521,7 +582,17 @@ void WebInspectorProxy::bringToFront() void WebInspectorProxy::attachAvailabilityChanged(bool available) { - platformAttachAvailabilityChanged(available); + bool previousCanAttach = m_canAttach; + + m_canAttach = platformCanAttach(available); + + if (previousCanAttach == m_canAttach) + return; + + if (m_inspectorPage && !m_underTest) + m_inspectorPage->process().send(Messages::WebInspectorUI::SetDockingUnavailable(!m_canAttach), m_inspectorPage->pageID()); + + platformAttachAvailabilityChanged(m_canAttach); } void WebInspectorProxy::inspectedURLChanged(const String& urlString) @@ -529,6 +600,23 @@ void WebInspectorProxy::inspectedURLChanged(const String& urlString) platformInspectedURLChanged(urlString); } +void WebInspectorProxy::elementSelectionChanged(bool active) +{ + m_elementSelectionActive = active; + + if (m_ignoreElementSelectionChange) { + m_ignoreElementSelectionChange = false; + if (!m_isVisible) + close(); + return; + } + + if (active) + platformBringInspectedPageToFront(); + else if (isConnected()) + bringToFront(); +} + void WebInspectorProxy::save(const String& filename, const String& content, bool base64Encoded, bool forceSaveAs) { platformSave(filename, content, base64Encoded, forceSaveAs); @@ -539,41 +627,145 @@ void WebInspectorProxy::append(const String& filename, const String& content) platformAppend(filename, content); } -bool WebInspectorProxy::canAttach() +bool WebInspectorProxy::shouldOpenAttached() { - // Keep this in sync with InspectorFrontendClientLocal::canAttachWindow. There are two implementations - // to make life easier in the multi-process world we have. WebInspectorProxy uses canAttach to decide if - // we can attach on open (on the UI process side). And InspectorFrontendClientLocal::canAttachWindow is - // used to decide if we can attach when the attach button is pressed (on the WebProcess side). + return inspectorPagePreferences().inspectorStartsAttached() && canAttach(); +} - // If we are already attached, allow attaching again to allow switching sides. - if (m_isAttached) - return true; +#if ENABLE(INSPECTOR_SERVER) +void WebInspectorProxy::sendMessageToRemoteFrontend(const String& message) +{ + ASSERT(m_remoteInspectionPageId); + WebInspectorServer::singleton().sendMessageOverConnection(m_remoteInspectionPageId, message); +} +#endif - // Don't allow attaching to another inspector -- two inspectors in one window is too much! - if (m_level > 1) - return false; +// Unsupported configurations can use the stubs provided here. - // Don't allow the attach if the window would be too small to accommodate the minimum inspector height. - unsigned inspectedPageHeight = platformInspectedWindowHeight(); - unsigned inspectedPageWidth = platformInspectedWindowWidth(); - unsigned maximumAttachedHeight = inspectedPageHeight * 3 / 4; - return minimumAttachedHeight <= maximumAttachedHeight && minimumAttachedWidth <= inspectedPageWidth; +#if PLATFORM(IOS) || (PLATFORM(MAC) && !WK_API_ENABLED) + +WebPageProxy* WebInspectorProxy::platformCreateInspectorPage() +{ + notImplemented(); + return nullptr; } -bool WebInspectorProxy::shouldOpenAttached() +void WebInspectorProxy::platformOpen() { - return inspectorPageGroup()->preferences()->inspectorStartsAttached() && canAttach(); + notImplemented(); } -#if ENABLE(INSPECTOR_SERVER) -void WebInspectorProxy::sendMessageToRemoteFrontend(const String& message) +void WebInspectorProxy::platformDidClose() { - ASSERT(m_remoteInspectionPageId); - WebInspectorServer::shared().sendMessageOverConnection(m_remoteInspectionPageId, message); + notImplemented(); } -#endif -} // namespace WebKit +void WebInspectorProxy::platformDidCloseForCrash() +{ + notImplemented(); +} + +void WebInspectorProxy::platformInvalidate() +{ + notImplemented(); +} + +void WebInspectorProxy::platformBringToFront() +{ + notImplemented(); +} + +void WebInspectorProxy::platformBringInspectedPageToFront() +{ + notImplemented(); +} + +void WebInspectorProxy::platformHide() +{ + notImplemented(); +} + +bool WebInspectorProxy::platformIsFront() +{ + notImplemented(); + return false; +} + +void WebInspectorProxy::platformInspectedURLChanged(const String&) +{ + notImplemented(); +} + +void WebInspectorProxy::platformSave(const String& suggestedURL, const String& content, bool base64Encoded, bool forceSaveDialog) +{ + notImplemented(); +} -#endif // ENABLE(INSPECTOR) +void WebInspectorProxy::platformAppend(const String& suggestedURL, const String& content) +{ + notImplemented(); +} + +unsigned WebInspectorProxy::platformInspectedWindowHeight() +{ + notImplemented(); + return 0; +} + +unsigned WebInspectorProxy::platformInspectedWindowWidth() +{ + notImplemented(); + return 0; +} + +void WebInspectorProxy::platformAttach() +{ + notImplemented(); +} + +void WebInspectorProxy::platformDetach() +{ + notImplemented(); +} + +void WebInspectorProxy::platformSetAttachedWindowHeight(unsigned) +{ + notImplemented(); +} + +void WebInspectorProxy::platformStartWindowDrag() +{ + notImplemented(); +} + +String WebInspectorProxy::inspectorPageURL() +{ + notImplemented(); + return String(); +} + +String WebInspectorProxy::inspectorTestPageURL() +{ + notImplemented(); + return String(); +} + +String WebInspectorProxy::inspectorBaseURL() +{ + notImplemented(); + return String(); +} + +void WebInspectorProxy::platformSetAttachedWindowWidth(unsigned) +{ + notImplemented(); +} + +void WebInspectorProxy::platformAttachAvailabilityChanged(bool) +{ + notImplemented(); +} + +#endif // PLATFORM(IOS) || (PLATFORM(MAC) && !WK_API_ENABLED) + +} // namespace WebKit |