Web Inspector: Push Remote Inspector debugging connection management into JavaScriptCore
authorjoepeck@webkit.org <joepeck@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 4 Dec 2013 18:20:37 +0000 (18:20 +0000)
committerjoepeck@webkit.org <joepeck@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 4 Dec 2013 18:20:37 +0000 (18:20 +0000)
commit64488c7dc0eeaf41eeacc41dd68953827fa28a03
tree278696968dc3f54ebb047e3d79d5491994e6773a
parente11dfd8b320107da646fed7620df0cd41819f5dc
Web Inspector: Push Remote Inspector debugging connection management into JavaScriptCore
https://bugs.webkit.org/show_bug.cgi?id=124613

Reviewed by Timothy Hatcher.

Source/JavaScriptCore:

Move the ENABLE(REMOTE_INSPECTOR) remote debugger connection management
into JavaScriptCore (originally from WebKit/mac). Include enhancements:

  * allow for different types of remote debuggable targets,
    eventually at least a JSContext, WebView, WKView.
  * allow debuggables to be registered and debugged on any thread. Unlike
    WebViews, JSContexts may be run entirely off of the main thread.
  * move the remote connection (XPC connection) itself off of the main thread,
    it doesn't need to be on the main thread.

Make JSContext @class and JavaScriptCore::JSContextRef
"JavaScript" Remote Debuggables.

* inspector/remote/RemoteInspectorDebuggable.h: Added.
* inspector/remote/RemoteInspectorDebuggable.cpp: Added.
(Inspector::RemoteInspectorDebuggable::RemoteInspectorDebuggable):
(Inspector::RemoteInspectorDebuggable::~RemoteInspectorDebuggable):
(Inspector::RemoteInspectorDebuggable::init):
(Inspector::RemoteInspectorDebuggable::update):
(Inspector::RemoteInspectorDebuggable::setRemoteDebuggingAllowed):
(Inspector::RemoteInspectorDebuggable::info):
RemoteInspectorDebuggable defines a debuggable target. As long as
something creates a debuggable and is set to allow remote inspection
it will be listed in remote debuggers. For the different types of
debuggables (JavaScript and Web) there is different basic information
that may be listed.

* inspector/InspectorFrontendChannel.h: Added.
(Inspector::InspectorFrontendChannel::~InspectorFrontendChannel):
The only thing a debuggable needs for remote debugging is an
InspectorFrontendChannel a way to send messages to a remote frontend.
This class provides that method, and is vended to the
RemoteInspectorDebuggable when a remote connection is setup.

* inspector/remote/RemoteInspector.h: Added.
* inspector/remote/RemoteInspector.mm: Added.
Singleton, created at least when the first Debuggable is created.
This class manages the list of debuggables, any connection to a
remote debugger proxy (XPC service "com.apple.webinspector").

(Inspector::dispatchAsyncOnQueueSafeForAnyDebuggable):
(Inspector::RemoteInspector::shared):
(Inspector::RemoteInspector::RemoteInspector):
(Inspector::RemoteInspector::nextAvailableIdentifier):
(Inspector::RemoteInspector::registerDebuggable):
(Inspector::RemoteInspector::unregisterDebuggable):
(Inspector::RemoteInspector::updateDebuggable):
Debuggable management. When debuggables are added, removed, or updated
we stash a copy of the debuggable information and push an update to
debuggers. Stashing a copy of the information in the RemoteInspector
is a thread safe way to avoid walking over all debuggables to gather
the information when it is needed.

(Inspector::RemoteInspector::start):
(Inspector::RemoteInspector::stop):
Runtime API to enable / disable the feature.

(Inspector::RemoteInspector::listingForDebuggable):
(Inspector::RemoteInspector::pushListingNow):
(Inspector::RemoteInspector::pushListingSoon):
Pushing a listing to remote debuggers.

(Inspector::RemoteInspector::sendMessageToRemoteFrontend):
(Inspector::RemoteInspector::setupXPCConnectionIfNeeded):
(Inspector::RemoteInspector::xpcConnectionReceivedMessage):
(Inspector::RemoteInspector::xpcConnectionFailed):
(Inspector::RemoteInspector::xpcConnectionUnhandledMessage):
XPC setup, send, and receive handling.

(Inspector::RemoteInspector::updateHasActiveDebugSession):
Applications being debugged may want to know when a debug
session is active. This provides that notification.

(Inspector::RemoteInspector::receivedSetupMessage):
(Inspector::RemoteInspector::receivedDataMessage):
(Inspector::RemoteInspector::receivedDidCloseMessage):
(Inspector::RemoteInspector::receivedGetListingMessage):
(Inspector::RemoteInspector::receivedIndicateMessage):
(Inspector::RemoteInspector::receivedConnectionDiedMessage):
Dispatching incoming remote debugging protocol messages.
These are wrapping above the inspector protocol messages.

* inspector/remote/RemoteInspectorConstants.h: Added.
Protocol messages and dictionary keys inside the messages.

(Inspector::RemoteInspectorDebuggableInfo::RemoteInspectorDebuggableInfo):
* inspector/remote/RemoteInspectorDebuggableConnection.h: Added.
* inspector/remote/RemoteInspectorDebuggableConnection.mm: Added.
This is a connection between the RemoteInspector singleton and a RemoteInspectorDebuggable.

(Inspector::RemoteInspectorDebuggableConnection::RemoteInspectorDebuggableConnection):
(Inspector::RemoteInspectorDebuggableConnection::~RemoteInspectorDebuggableConnection):
Allow for dispatching messages on JavaScript debuggables on a dispatch_queue
instead of the main queue.

(Inspector::RemoteInspectorDebuggableConnection::destination):
(Inspector::RemoteInspectorDebuggableConnection::connectionIdentifier):
Needed in the remote debugging protocol to identify the remote debugger.

(Inspector::RemoteInspectorDebuggableConnection::dispatchSyncOnDebuggable):
(Inspector::RemoteInspectorDebuggableConnection::dispatchAsyncOnDebuggable):
(Inspector::RemoteInspectorDebuggableConnection::setup):
(Inspector::RemoteInspectorDebuggableConnection::closeFromDebuggable):
(Inspector::RemoteInspectorDebuggableConnection::close):
(Inspector::RemoteInspectorDebuggableConnection::sendMessageToBackend):
(Inspector::RemoteInspectorDebuggableConnection::sendMessageToFrontend):
The connection is a thin channel between the two sides that can be closed
from either side, so there is some logic around multi-threaded access.

* inspector/remote/RemoteInspectorXPCConnection.h: Added.
(Inspector::RemoteInspectorXPCConnection::Client::~Client):
* inspector/remote/RemoteInspectorXPCConnection.mm: Added.
(Inspector::RemoteInspectorXPCConnection::RemoteInspectorXPCConnection):
(Inspector::RemoteInspectorXPCConnection::~RemoteInspectorXPCConnection):
(Inspector::RemoteInspectorXPCConnection::close):
(Inspector::RemoteInspectorXPCConnection::deserializeMessage):
(Inspector::RemoteInspectorXPCConnection::handleEvent):
(Inspector::RemoteInspectorXPCConnection::sendMessage):
This is a connection between the RemoteInspector singleton and an XPC service
named "com.apple.webinspector". This handles serialization of the dictionary
messages to and from the service. The receiving is done on a non-main queue.

* API/JSContext.h:
* API/JSContext.mm:
(-[JSContext name]):
(-[JSContext setName:]):
ObjC API to enable/disable JSContext remote inspection and give a name.

* API/JSContextRef.h:
* API/JSContextRef.cpp:
(JSGlobalContextGetName):
(JSGlobalContextSetName):
C API to give a JSContext a name.

* runtime/JSGlobalObject.cpp:
(JSC::JSGlobalObject::setName):
* runtime/JSGlobalObject.h:
(JSC::JSGlobalObject::name):
Shared handling of the APIs above.

* runtime/JSGlobalObjectDebuggable.cpp: Added.
(JSC::JSGlobalObjectDebuggable::JSGlobalObjectDebuggable):
(JSC::JSGlobalObjectDebuggable::name):
(JSC::JSGlobalObjectDebuggable::connect):
(JSC::JSGlobalObjectDebuggable::disconnect):
(JSC::JSGlobalObjectDebuggable::dispatchMessageFromRemoteFrontend):
* runtime/JSGlobalObjectDebuggable.h: Added.
Stub for the actual remote debugging implementation. We will push
down the appropriate WebCore/inspector peices suitable for debugging
just a JavaScript context.

* CMakeLists.txt:
* JavaScriptCore.xcodeproj/project.pbxproj:
* GNUmakefile.am:
* GNUmakefile.list.am:
* JavaScriptCore.vcxproj/JavaScriptCore.vcxproj:
* JavaScriptCore.vcxproj/JavaScriptCore.vcxproj.filters:
Update build files.

Source/WebCore:

Make a WebCore::Page a "Web" Remote Debuggable.

* bindings/js/JSDOMGlobalObject.cpp:
Disable JavaScript context inspection on JSGlobalObjects inside WebCore::Page's.

* page/Page.cpp:
(WebCore::Page::Page):
(WebCore::Page::remoteInspectionAllowed):
(WebCore::Page::setRemoteInspectionAllowed):
(WebCore::Page::remoteInspectorInformationDidChange):
* page/Page.h:
* page/PageDebuggable.h:
* page/PageDebuggable.cpp: Added.
(WebCore::PageDebuggable::PageDebuggable):
(WebCore::PageDebuggable::name):
(WebCore::PageDebuggable::url):
(WebCore::PageDebuggable::hasLocalDebugger):
(WebCore::PageDebuggable::connect):
(WebCore::PageDebuggable::disconnect):
(WebCore::PageDebuggable::dispatchMessageFromRemoteFrontend):
(WebCore::PageDebuggable::setIndicating):
Make a page a "Web" debuggable.

* GNUmakefile.list.am:
* WebCore.exp.in:
* WebCore.vcxproj/WebCore.vcxproj:
* WebCore.vcxproj/WebCore.vcxproj.filters:
* WebCore.xcodeproj/project.pbxproj:
Misc.

* inspector/InspectorClient.h:
(WebCore::InspectorClient::indicate):
(WebCore::InspectorClient::hideIndicate):
Forward indicate methods to WebKit clients.

* loader/FrameLoader.cpp:
(WebCore::FrameLoader::didChangeTitle):
(WebCore::FrameLoader::dispatchDidCommitLoad):
Push updates when remote debuggable information like the Page's
URL or title change.

* ForwardingHeaders/inspector/InspectorFrontendChannel.h:
* inspector/InspectorForwarding.h:
Re-export Inspector::InspectorFrontendChannel as WebCore::InspectorFrontendChannel
to avoid needlessly updating code all over the place.

* inspector/CodeGeneratorInspectorStrings.py:
* inspector/InspectorWorkerAgent.cpp:
* inspector/WorkerInspectorController.cpp:
* testing/Internals.cpp:
Update include names.

* page/ContextMenuController.cpp:
(WebCore::ContextMenuController::populate):
Make the "Inspect Element" context menu work correctly when there is a
remote inspector instead of a local inspector.

Source/WebKit:

* WebKit.xcodeproj/project.pbxproj:

Source/WebKit/blackberry:

* WebCoreSupport/InspectorClientBlackBerry.h:

Source/WebKit/cf:

* WebCoreSupport/WebInspectorClientCF.cpp:
(WebInspectorClient::sendMessageToFrontend):

Source/WebKit/efl:

* WebCoreSupport/InspectorClientEfl.h:

Source/WebKit/gtk:

* WebCoreSupport/InspectorClientGtk.h:

Source/WebKit/ios:

* WebCoreSupport/WebInspectorClientIOS.mm:
(WebInspectorClient::WebInspectorClient):
(WebInspectorClient::inspectorDestroyed):

Source/WebKit/mac:

Remove the old ENABLE(REMOTE_INSPECTOR) connection management implementation.

* WebCoreSupport/WebInspectorClient.h:
* WebCoreSupport/WebInspectorClient.mm:
(WebInspectorClient::indicate):
(WebInspectorClient::hideIndicate):
Hook up WebView indication through this new path.

* WebCoreSupport/WebFrameLoaderClient.mm:
(WebFrameLoaderClient::dispatchDidReceiveTitle):
* WebCoreSupport/WebInspectorClient.h:
* WebCoreSupport/WebInspectorClient.mm:
(WebInspectorClient::WebInspectorClient):
(WebInspectorClient::inspectorDestroyed):
* WebInspector/remote/WebInspectorClientRegistry.h: Removed.
* WebInspector/remote/WebInspectorClientRegistry.mm: Removed.
* WebInspector/remote/WebInspectorRelayDefinitions.h: Removed.
* WebInspector/remote/WebInspectorRemoteChannel.h: Removed.
* WebInspector/remote/WebInspectorRemoteChannel.mm: Removed.
* WebInspector/remote/WebInspectorServer.h: Removed.
* WebInspector/remote/WebInspectorServer.mm: Removed.
* WebInspector/remote/WebInspectorServerWebViewConnection.h: Removed.
* WebInspector/remote/WebInspectorServerWebViewConnection.mm: Removed.
* WebInspector/remote/WebInspectorServerWebViewConnectionController.h: Removed.
* WebInspector/remote/WebInspectorServerWebViewConnectionController.mm: Removed.
* WebInspector/remote/WebInspectorXPCWrapper.h: Removed.
* WebInspector/remote/WebInspectorXPCWrapper.m: Removed.
* WebKit.exp:
* WebView/WebView.mm:
(-[WebView _commonInitializationWithFrameName:groupName:]):
(+[WebView _enableRemoteInspector]):
(+[WebView _disableRemoteInspector]):
(+[WebView _disableAutoStartRemoteInspector]):
(+[WebView _isRemoteInspectorEnabled]):
(+[WebView _hasRemoteInspectorSession]):
(-[WebView allowsRemoteInspection]):
(-[WebView setAllowsRemoteInspection:]):
(-[WebView setIndicatingForRemoteInspector:]):
(-[WebView setHostApplicationBundleId:name:]):
(-[WebView _didCommitLoadForFrame:]):
* WebView/WebViewData.h:
* WebView/WebViewData.mm:
(-[WebViewPrivate init]):
(-[WebViewPrivate dealloc]):
* WebView/WebViewInternal.h:
* WebView/WebViewPrivate.h:
Remove old REMOTE_INSPECTOR.

Source/WebKit/win:

* WebCoreSupport/WebInspectorClient.h:

Source/WebKit/wince:

* WebCoreSupport/InspectorClientWinCE.h:

Source/WebKit2:

* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::WebPage):
* WebProcess/com.apple.WebProcess.sb.in:
Allow the WebProcess to access the "com.apple.webinspector" named
XPC service to expose its WebCore::Page's to remote debuggers.

Source/WTF:

* wtf/ios/WebCoreThread.cpp:
* wtf/ios/WebCoreThread.h:
Expose WebThreadRun/WebThreadRunSync iOS methods defined in WebCore through
WTF so that JavaScriptCore can use it. Another such method already existed.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@160099 268f45cc-cd09-0410-ab3c-d52691b4dbfc
89 files changed:
Source/JavaScriptCore/API/JSContext.h
Source/JavaScriptCore/API/JSContext.mm
Source/JavaScriptCore/API/JSContextRef.cpp
Source/JavaScriptCore/API/JSContextRef.h
Source/JavaScriptCore/CMakeLists.txt
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/GNUmakefile.am
Source/JavaScriptCore/GNUmakefile.list.am
Source/JavaScriptCore/JavaScriptCore.vcxproj/JavaScriptCore.vcxproj
Source/JavaScriptCore/JavaScriptCore.vcxproj/JavaScriptCore.vcxproj.filters
Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
Source/JavaScriptCore/inspector/InspectorFrontendChannel.h [moved from Source/WebCore/inspector/InspectorFrontendChannel.h with 83% similarity]
Source/JavaScriptCore/inspector/remote/RemoteInspector.h [new file with mode: 0644]
Source/JavaScriptCore/inspector/remote/RemoteInspector.mm [new file with mode: 0644]
Source/JavaScriptCore/inspector/remote/RemoteInspectorConstants.h [moved from Source/WebKit/mac/WebInspector/remote/WebInspectorRelayDefinitions.h with 95% similarity]
Source/JavaScriptCore/inspector/remote/RemoteInspectorDebuggable.cpp [moved from Source/WebKit/mac/WebInspector/remote/WebInspectorServerWebViewConnectionController.h with 51% similarity]
Source/JavaScriptCore/inspector/remote/RemoteInspectorDebuggable.h [new file with mode: 0644]
Source/JavaScriptCore/inspector/remote/RemoteInspectorDebuggableConnection.h [new file with mode: 0644]
Source/JavaScriptCore/inspector/remote/RemoteInspectorDebuggableConnection.mm [new file with mode: 0644]
Source/JavaScriptCore/inspector/remote/RemoteInspectorXPCConnection.h [new file with mode: 0644]
Source/JavaScriptCore/inspector/remote/RemoteInspectorXPCConnection.mm [new file with mode: 0644]
Source/JavaScriptCore/runtime/JSGlobalObject.cpp
Source/JavaScriptCore/runtime/JSGlobalObject.h
Source/JavaScriptCore/runtime/JSGlobalObjectDebuggable.cpp [moved from Source/WebKit/mac/WebInspector/remote/WebInspectorXPCWrapper.h with 53% similarity]
Source/JavaScriptCore/runtime/JSGlobalObjectDebuggable.h [moved from Source/WebKit/mac/WebInspector/remote/WebInspectorClientRegistry.h with 53% similarity]
Source/WTF/ChangeLog
Source/WTF/wtf/ios/WebCoreThread.cpp
Source/WTF/wtf/ios/WebCoreThread.h
Source/WebCore/ChangeLog
Source/WebCore/ForwardingHeaders/inspector/InspectorFrontendChannel.h [new file with mode: 0644]
Source/WebCore/GNUmakefile.list.am
Source/WebCore/WebCore.exp.in
Source/WebCore/WebCore.vcxproj/WebCore.vcxproj
Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/bindings/js/JSDOMGlobalObject.cpp
Source/WebCore/inspector/CodeGeneratorInspectorStrings.py
Source/WebCore/inspector/InspectorBackendDispatcher.cpp
Source/WebCore/inspector/InspectorClient.h
Source/WebCore/inspector/InspectorController.cpp
Source/WebCore/inspector/InspectorController.h
Source/WebCore/inspector/InspectorForwarding.h [moved from Source/WebKit/mac/WebInspector/remote/WebInspectorRemoteChannel.h with 62% similarity]
Source/WebCore/inspector/InspectorWorkerAgent.cpp
Source/WebCore/inspector/WorkerInspectorController.cpp
Source/WebCore/loader/FrameLoader.cpp
Source/WebCore/page/ContextMenuController.cpp
Source/WebCore/page/Page.cpp
Source/WebCore/page/Page.h
Source/WebCore/page/PageDebuggable.cpp [new file with mode: 0644]
Source/WebCore/page/PageDebuggable.h [moved from Source/WebKit/mac/WebInspector/remote/WebInspectorServerWebViewConnection.h with 54% similarity]
Source/WebCore/testing/Internals.cpp
Source/WebKit/ChangeLog
Source/WebKit/WebKit.xcodeproj/project.pbxproj
Source/WebKit/blackberry/ChangeLog
Source/WebKit/blackberry/WebCoreSupport/InspectorClientBlackBerry.h
Source/WebKit/cf/ChangeLog
Source/WebKit/cf/WebCoreSupport/WebInspectorClientCF.cpp
Source/WebKit/efl/ChangeLog
Source/WebKit/efl/WebCoreSupport/InspectorClientEfl.h
Source/WebKit/gtk/ChangeLog
Source/WebKit/gtk/WebCoreSupport/InspectorClientGtk.h
Source/WebKit/ios/ChangeLog
Source/WebKit/ios/WebCoreSupport/WebInspectorClientIOS.mm
Source/WebKit/mac/ChangeLog
Source/WebKit/mac/WebCoreSupport/WebFrameLoaderClient.mm
Source/WebKit/mac/WebCoreSupport/WebInspectorClient.h
Source/WebKit/mac/WebCoreSupport/WebInspectorClient.mm
Source/WebKit/mac/WebInspector/remote/WebInspectorClientRegistry.mm [deleted file]
Source/WebKit/mac/WebInspector/remote/WebInspectorRemoteChannel.mm [deleted file]
Source/WebKit/mac/WebInspector/remote/WebInspectorServer.h [deleted file]
Source/WebKit/mac/WebInspector/remote/WebInspectorServer.mm [deleted file]
Source/WebKit/mac/WebInspector/remote/WebInspectorServerWebViewConnection.mm [deleted file]
Source/WebKit/mac/WebInspector/remote/WebInspectorServerWebViewConnectionController.mm [deleted file]
Source/WebKit/mac/WebInspector/remote/WebInspectorXPCWrapper.m [deleted file]
Source/WebKit/mac/WebKit.exp
Source/WebKit/mac/WebView/WebView.mm
Source/WebKit/mac/WebView/WebViewData.h
Source/WebKit/mac/WebView/WebViewData.mm
Source/WebKit/mac/WebView/WebViewInternal.h
Source/WebKit/mac/WebView/WebViewPrivate.h
Source/WebKit/win/ChangeLog
Source/WebKit/win/WebCoreSupport/WebInspectorClient.h
Source/WebKit/wince/ChangeLog
Source/WebKit/wince/WebCoreSupport/InspectorClientWinCE.h
Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/WebCoreSupport/WebInspectorClient.h
Source/WebKit2/WebProcess/WebPage/WebInspector.cpp
Source/WebKit2/WebProcess/WebPage/WebPage.cpp
Source/WebKit2/WebProcess/com.apple.WebProcess.sb.in