Web Replay: detect possible replay divergence from unexpected DOM event dispatches
https://bugs.webkit.org/show_bug.cgi?id=131193

Reviewed by Andreas Kling.

Add assertions to catch potential nondeterministic behavior.

The assertion added by this patch catches dispatched DOM events
that are triggered by nondeterministic event loop cycles. If we
did not capture an event loop input in the current event loop
cycle nor are we manually simulating an event loop input during
playback, then DOM events fired during the unordered cycle could
run JavaScript and diverge the execution.

During playback, we can assert that EventLoopInputDispatcher is dispatching
when a DOM event is be dispatched to a document that is being replayed.

During capturing, event loop inputs are captured rather than
dispatched, so we add some accounting to track what caused a DOM
event. To approximate the extent of computation triggered by an
event loop input, we add RAII helpers to call sites where event
loop inputs are captured.

The assertions are disabled by default until the most common
sources of nondeterminism are handled and playback errors are
gracefully surfaced to the user. <https://webkit.org/b/131279>

No new tests. This patch adds extra assertions for debugging purposes.

* WebCore.xcodeproj/project.pbxproj:
* inspector/InspectorInstrumentation.cpp: Notify ReplayAgent of dispatched DOM event.
(WebCore::InspectorInstrumentation::willDispatchEventImpl):
(WebCore::InspectorInstrumentation::willDispatchEventOnWindowImpl):
* inspector/InspectorReplayAgent.cpp: Forward dispatched DOM events to ReplayController.
(WebCore::InspectorReplayAgent::willDispatchEvent): Added.
* inspector/InspectorReplayAgent.h:
* replay/CapturingInputCursor.cpp:
(WebCore::CapturingInputCursor::CapturingInputCursor):
(WebCore::CapturingInputCursor::setWithinEventLoopInputExtent): Added.
* replay/CapturingInputCursor.h:
* replay/EventLoopInput.cpp: Added.
(WebCore::EventLoopInputExtent::EventLoopInputExtent): Added.
(WebCore::EventLoopInputExtent::~EventLoopInputExtent): Added.
* replay/EventLoopInput.h:
* replay/EventLoopInputDispatcher.h:
(WebCore::EventLoopInputDispatcher::isDispatching): Add a getter.
* replay/ReplayController.cpp:
(WebCore::logDispatchedDOMEvent): Added. This is useful for understanding script-visible events.
(WebCore::ReplayController::willDispatchEvent): Added.
* replay/ReplayController.h:
* replay/UserInputBridge.cpp: Add extent helpers to call sites that capture inputs.
(WebCore::UserInputBridge::handleMousePressEvent):
(WebCore::UserInputBridge::handleMouseReleaseEvent):
(WebCore::UserInputBridge::handleMouseMoveEvent):
(WebCore::UserInputBridge::handleMouseMoveOnScrollbarEvent):
(WebCore::UserInputBridge::handleKeyEvent):
(WebCore::UserInputBridge::handleWheelEvent):
(WebCore::UserInputBridge::scrollRecursively):
(WebCore::UserInputBridge::logicalScrollRecursively):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@166880 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Handle clicks on DataDetectors UI for scanned phone numbers
<rdar://problem/16379588> and https://bugs.webkit.org/show_bug.cgi?id=131309

Reviewed by Tim Horton.

WebContextMenuItemDatas never need to know about a ContextMenu, so remove that concept.
Also add the concept of a selection handler for UIProcess-native menu items.
* Shared/WebContextMenuItemData.cpp:
(WebKit::WebContextMenuItemData::WebContextMenuItemData):
(WebKit::WebContextMenuItemData::encode):
(WebKit::kitItems):
(WebKit::WebContextMenuItemData::decode):
* Shared/WebContextMenuItemData.h:
(WebKit::WebContextMenuItemData::selectionHandler):

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::showContextMenu):
(WebKit::WebPageProxy::internalShowContextMenu): Make the decoder argument optional. Make consulting the client optional.
* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in:
* UIProcess/mac/WebPageProxyMac.mm:
(WebKit::WebPageProxy::showTelephoneNumberMenu):

* UIProcess/mac/WebContextMenuProxyMac.mm:
(-[WKSelectionHandlerWrapper initWithSelectionHandler:std::]):
(-[WKSelectionHandlerWrapper executeSelectionHandler]):
(-[WKMenuTarget forwardContextMenuAction:]):
(WebKit::nsMenuItemVector):
(WebKit::WebContextMenuProxyMac::contextMenuItemSelected): If the represented object is a WKSelectionHandlerWrapper,
  execute the selection handler. Do nothing else.

Instead of getting rects from ranges, creating highlights, and storing those highlights,
work in terms of a TelephoneNumberData object that wraps both a range and a highlight.
This makes it easier to track where the mouse is down and to know what phone number we should act on when clicked.
* WebProcess/WebPage/TelephoneNumberOverlayController.cpp:
(WebKit::TelephoneNumberOverlayController::rectsForDrawing): Deleted.
* WebProcess/WebPage/TelephoneNumberOverlayController.h:
(WebKit::TelephoneNumberData::create):
(WebKit::TelephoneNumberData::range):
(WebKit::TelephoneNumberData::highlight):
(WebKit::TelephoneNumberData::TelephoneNumberData):
* WebProcess/WebPage/mac/TelephoneNumberOverlayControllerMac.mm:
(WebKit::TelephoneNumberOverlayController::drawRect):
(WebKit::TelephoneNumberOverlayController::handleTelephoneClick): Pass the phone number text and the point to WebPage.
(WebKit::TelephoneNumberOverlayController::mouseEvent):
(WebKit::TelephoneNumberOverlayController::clearMouseDownInformation):
(WebKit::TelephoneNumberOverlayController::clearHighlights):

* WebProcess/WebPage/WebContextMenu.cpp:
(WebKit::WebContextMenu::menuItemsWithUserData):

* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/mac/WebPageMac.mm:
(WebKit::WebPage::handleTelephoneNumberClick): Message the phone number and coordinate to the UIProcess.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@166881 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Tried to fix the Mac build.

* WebProcess/Plugins/PDF/PDFPlugin.mm:



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@166882 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Split CSS Selectors pseudo class and pseudo elements
https://bugs.webkit.org/show_bug.cgi?id=131295

Reviewed by Andreas Kling.

Split pseudo class and pseudo element to make it clearer what pseudo types
are possible for a given match type.

Pseudo Element types are separated and Pseudo Class are left in place. The Pseudo Class
will have to be renamed too but that will be done separately to make this change smaller.

* css/CSSGrammar.y.in:
* css/CSSParser.cpp:
(WebCore::CSSParser::rewriteSpecifiersWithElementName):
(WebCore::CSSParser::rewriteSpecifiers):
Use a method isPseudoElementCueFunction() to abstract the #ifdef out of the parser.

* css/CSSParserValues.cpp:
(WebCore::CSSParserSelector::parsePseudoElementSelector):

(WebCore::CSSParserSelector::parsePseudoElementCueFunctionSelector):
Rename to specify this is for the pseudo element cue function, not the pseudo element cue.

(WebCore::CSSParserSelector::parsePseudoClassAndCompatibilityElementSelector):
(WebCore::CSSParserSelector::parsePseudoCueFunctionSelector): Deleted.
* css/CSSParserValues.h:
(WebCore::CSSParserSelector::isPseudoElementCueFunction):
* css/CSSSelector.cpp:
(WebCore::CSSSelector::specificityForOneSelector):
(WebCore::CSSSelector::pseudoId):
(WebCore::CSSSelector::parsePseudoElementType):
(WebCore::CSSSelector::operator==):
* css/CSSSelector.h:
(WebCore::CSSSelector::pseudoType):
(WebCore::CSSSelector::setPseudoElementType):
(WebCore::CSSSelector::pseudoElementType):
(WebCore::CSSSelector::isUnknownPseudoElement):
(WebCore::CSSSelector::isCustomPseudoElement):
(WebCore::pseudoClassIsRelativeToSiblings):
(WebCore::CSSSelector::isSiblingSelector):
* css/RuleFeature.cpp:
(WebCore::RuleFeatureSet::collectFeaturesFromSelector):
* css/RuleSet.cpp:
(WebCore::determinePropertyWhitelistType):
(WebCore::RuleSet::findBestRuleSetAndAdd):
* css/SelectorChecker.cpp:
(WebCore::SelectorChecker::matchRecursively):
(WebCore::SelectorChecker::checkOne):
(WebCore::SelectorChecker::checkScrollbarPseudoClass):
(WebCore::SelectorChecker::determineLinkMatchType):
* css/SelectorPseudoClassAndCompatibilityElementMap.in:
* css/SelectorPseudoElementTypeMap.in:
* css/SelectorPseudoTypeMap.h:
* css/makeSelectorPseudoClassAndCompatibilityElementMap.py:
* css/makeSelectorPseudoElementsMap.py:
(enumerablePseudoType):
* page/DOMWindow.cpp:
(WebCore::DOMWindow::getMatchedCSSRules):

* rendering/style/RenderStyleConstants.h:
All the fullscreen pseudo types are pseudo class selectors. They should not have a pseudo ID.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@166883 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Another build fix after r166879.

* WebProcess/WebPage/mac/WebPageMac.mm:


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@166884 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Make it possible to disable some of the FTL's more interesting features
https://bugs.webkit.org/show_bug.cgi?id=131312

Reviewed by Mark Hahnenberg.

* dfg/DFGByteCodeParser.cpp:
(JSC::DFG::ByteCodeParser::handleGetById):
(JSC::DFG::ByteCodeParser::handlePutById):
(JSC::DFG::ByteCodeParser::parse):
* runtime/Options.h:



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@166885 268f45cc-cd09-0410-ab3c-d52691b4dbfc
[iOS WebKit2] Make back-buffers purgeable when possible
https://bugs.webkit.org/show_bug.cgi?id=131213
<rdar://problem/15373906>

Reviewed by Simon Fraser.

We should make back-buffers volatile when their owning
layer falls out of use (either stops being repainted or
is unparented), as they are inherently recreatable.

* Shared/mac/RemoteLayerBackingStore.h:
(WebKit::RemoteLayerBackingStore::volatility):
(WebKit::RemoteLayerBackingStore::lastDisplayTime):
Add storage and a getter for the backing store's last paint time.
Add setter/getter for volatility of backing store.
Add RemoteLayerTreeContext param to constructor.

* Shared/mac/RemoteLayerBackingStore.mm:
(WebKit::RemoteLayerBackingStore::RemoteLayerBackingStore):
(WebKit::RemoteLayerBackingStore::~RemoteLayerBackingStore):
Inform the RemoteLayerTreeContext when backing store
is created and destroyed. Since we only have a Context in
the Web process, this will only happen there.

(WebKit::RemoteLayerBackingStore::encode):
(WebKit::RemoteLayerBackingStore::decode):
Move some assertions out of #else blocks which are preceded by returns.

(WebKit::RemoteLayerBackingStore::display):
Update the last display time.
If the backing store was volatile, make it non-volatile.

(WebKit::RemoteLayerBackingStore::setVolatility):
Mark the relevant surfaces as volatile or not.
setVolatility:
    - fails and returns false if any surfaces weren't marked
      volatile because they were in use
    - marks the whole backing store for repaint if the front
      surface was purged

* Shared/mac/RemoteLayerTreeTransaction.mm:
(WebKit::RemoteLayerTreeTransaction::LayerProperties::encode):
(WebKit::RemoteLayerTreeTransaction::LayerProperties::decode):
Make it possible to remove the RemoteLayerBackingStore on layers
that went from drawing contents to not drawing contents.

* UIProcess/ios/ViewGestureControllerIOS.mm:
(WebKit::ViewGestureController::beginSwipeGesture):
(WebKit::ViewGestureController::removeSwipeSnapshot):
* UIProcess/mac/ViewGestureControllerMac.mm:
(WebKit::ViewGestureController::beginSwipeGesture):
(WebKit::ViewGestureController::removeSwipeSnapshot):
* UIProcess/mac/ViewSnapshotStore.mm:
(WebKit::ViewSnapshotStore::recordSnapshot):
Adopt the new names from WebCore.

* WebKit2.xcodeproj/project.pbxproj:
* WebProcess/WebPage/mac/PlatformCALayerRemote.cpp:
(WebKit::PlatformCALayerRemote::recursiveBuildTransaction):
Clear the backing store if the layer doesn't want to draw contents anymore.

(WebKit::PlatformCALayerRemote::ensureBackingStore):

* WebProcess/WebPage/mac/RemoteLayerTreeContext.h:
(WebKit::RemoteLayerTreeContext::backingStoreCollection):
* WebProcess/WebPage/mac/RemoteLayerTreeContext.mm:
(WebKit::RemoteLayerTreeContext::RemoteLayerTreeContext):
(WebKit::RemoteLayerTreeContext::backingStoreWasCreated):
(WebKit::RemoteLayerTreeContext::backingStoreWillBeDestroyed):
Keep a RemoteLayerBackingStoreCollection, which just keeps track
of all backing store (even unparented) created for layers in a
particular context. Forward backing store creation/deletion to it.
Remove a unused m_rootLayer member.

* WebProcess/WebPage/mac/RemoteLayerTreeDrawingArea.mm:
(WebKit::RemoteLayerTreeDrawingArea::flushLayers):
If any layers had backing store changes, start the timer
on the RemoteLayerBackingStoreCollection that will mark them
purgeable once they are no longer needed.

* Shared/mac/RemoteLayerBackingStoreCollection.mm:
* Shared/mac/RemoteLayerBackingStoreCollection.h:
Keep track of all backing store for our context.
When the timer fires, run through the backing store, finding
backing store that was last painted more than 1 second ago,
and mark them purgeable. If there was more recently-painted
backing store, let the timer fire again in another second;
otherwise, stop it.

* WebCore.exp.in:
* platform/graphics/cg/IOSurfacePool.cpp:
(WebCore::IOSurfacePool::takeSurface):
(WebCore::IOSurfacePool::markOlderSurfacesPurgeable):
(WebCore::IOSurfacePool::showPoolStatistics):
* platform/graphics/cocoa/IOSurface.h:
* platform/graphics/cocoa/IOSurface.mm:
(IOSurface::isVolatile):
(IOSurface::setIsVolatile):
Rename purgeability functions to match the system
and reduce confusion between purgeable memory
and volatile vs. non-volatile memory.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@166886 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Unreviewed. Fixing the GTK build.

* WebProcess/WebCoreSupport/gtk/WebEditorClientGtk.cpp: Include the Document header from WebCore
to avoid operating on an incomplete type.
* WebProcess/WebPage/TapHighlightController.cpp: Include the RenderElement instead of RenderObject
to make the RenderObject::style() inline accessible.
* WebProcess/WebPage/atk/WebPageAccessibilityObjectAtk.cpp: Include the Document header from WebCore


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@166887 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Make Mac only parts of TelephoneNumberOverlayController PLATFORM(MAC).

Unreviewed build fix for r166881.

* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in:
* UIProcess/mac/WebPageProxyMac.mm:
(WebKit::WebPageProxy::showTelephoneNumberMenu): Deleted.
* WebProcess/WebPage/TelephoneNumberOverlayController.cpp:
(WebKit::TelephoneNumberOverlayController::drawRect):
(WebKit::TelephoneNumberOverlayController::mouseEvent):
* WebProcess/WebPage/TelephoneNumberOverlayController.h:
* WebProcess/WebPage/mac/TelephoneNumberOverlayControllerMac.mm:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@166888 268f45cc-cd09-0410-ab3c-d52691b4dbfc