Web Replay: CodeGeneratorJS should guard includes of replay-related headers
https://bugs.webkit.org/show_bug.cgi?id=131407

Reviewed by Timothy Hatcher.

This patch adds guards to headers that are only required by generated replay code
that is itself guarded. Other ports probably haven't added the headers to their
build files, so we don't want to emit the unused header includes.

This patch also converts generated uses of DEFINE_STATIC_LOCAL to NeverDestroyed<T>.
Finally, a new bindings test was added to document changes to generated replay code.

Test: Source/WebCore/bindings/scripts/test/TestNondeterministic.idl

* bindings/scripts/CodeGeneratorJS.pm:
(GenerateImplementation):
(GenerateImplementationFunctionCall):

* bindings/scripts/test/GObject/WebKitDOMTestNondeterministic.cpp: Added.
* bindings/scripts/test/GObject/WebKitDOMTestNondeterministic.h: Added.
* bindings/scripts/test/GObject/WebKitDOMTestNondeterministic.symbols: Added.
* bindings/scripts/test/GObject/WebKitDOMTestNondeterministicPrivate.h: Added.
* bindings/scripts/test/JS/JSTestNondeterministic.cpp: Added.
* bindings/scripts/test/JS/JSTestNondeterministic.h: Added.
* bindings/scripts/test/ObjC/DOMTestNondeterministic.h: Added.
* bindings/scripts/test/ObjC/DOMTestNondeterministic.mm: Added.
* bindings/scripts/test/ObjC/DOMTestNondeterministicInternal.h: Added.
* bindings/scripts/test/TestNondeterministic.idl: Added.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@167140 268f45cc-cd09-0410-ab3c-d52691b4dbfc
[Mac] Add IconServices to WebProcess sandbox profile
https://bugs.webkit.org/show_bug.cgi?id=131558
<rdar://problem/16552397>

Reviewed by Brady Eidson.

* WebProcess/com.apple.WebProcess.sb.in:



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@167141 268f45cc-cd09-0410-ab3c-d52691b4dbfc
JSMainThreadExecState::call() should clear exceptions before returning.
<https://webkit.org/b/131530>

Reviewed by Geoffrey Garen.

Source/JavaScriptCore: 

Added a version of JSC::call() that return any uncaught exception instead
of leaving it pending in the VM.

As part of this change, I updated various parts of the code base to use the
new API as needed.

* bindings/ScriptFunctionCall.cpp:
(Deprecated::ScriptFunctionCall::call):
- ScriptFunctionCall::call() is only used by the inspector to inject scripts.
  The injected scripts that will include Inspector scripts that should catch
  and handle any exceptions that were thrown.  We should not be seeing any
  exceptions returned from this call.  However, we do have checks for
  exceptions in case there are bugs in the Inspector scripts which allowed
  the exception to leak through.  Hence, it is proper to clear the exception
  here, and only record the fact that an exception was seen (if present).

* bindings/ScriptFunctionCall.h:
* inspector/InspectorEnvironment.h:
* runtime/CallData.cpp:
(JSC::call):
* runtime/CallData.h:

Source/WebCore: 

Test: fast/dom/regress-131530.html

Previously, JSMainThreadExecState::call() did not clear any pending
exceptions in the VM before returning.  On returning, the
JSMainThreadExecState destructor may re-enter the VM to notify
MutationObservers.  This may result in a crash because the VM expects
exceptions to be cleared at entry.

We now change JSMainThreadExecState::call() to return the exception
(if present) via an argument, and clear it from the VM before returning.

As part of this change, I updated various parts of the code base to use the
new API as needed.

* bindings/js/JSCallbackData.cpp:
(WebCore::JSCallbackData::invokeCallback):
* bindings/js/JSCustomXPathNSResolver.cpp:
(WebCore::JSCustomXPathNSResolver::lookupNamespaceURI):
* bindings/js/JSDOMGlobalObjectTask.cpp:
- Assert that there's no unhandled exception after the Microtask returns.
  See comment for WebCore::JSMainThreadExecState::runTask below for more
  details.

* bindings/js/JSErrorHandler.cpp:
(WebCore::JSErrorHandler::handleEvent):
* bindings/js/JSEventListener.cpp:
(WebCore::JSEventListener::handleEvent):
* bindings/js/JSHTMLDocumentCustom.cpp:
(WebCore::JSHTMLDocument::open):
- Document.open() cannot be the first function on the JS stack.  Hence,
  there is no need to use JSMainThreadExecState to call into the VM, as
  this is only needed to catch the event of returning from the first
  function for the purpose of notifying MutationObservers.  Change to
  call JSC::call() directly.

* bindings/js/JSMainThreadExecState.cpp:
(WebCore::functionCallHandlerFromAnyThread):
* bindings/js/JSMainThreadExecState.h:
(WebCore::JSMainThreadExecState::call):
(WebCore::JSMainThreadExecState::evaluate):
- Remove the explicitly acquisition of the JSLock here because we now
  acquire the JSLock as part of the JSMainThreadExecState instance.
(WebCore::JSMainThreadExecState::runTask):
- Added an assert to verify that the task does not return with an
  unhandled exception.  Currently, the only Microtask in use is for the
  Promise implementation, which will eat the exception before returning.
  This assertion is added here to verify that this contract does not
  inadvertantly change in the future.
(WebCore::JSMainThreadExecState::JSMainThreadExecState):
- Now acquires the JSLock as well since by definition, we're only
  instantiating the JSMainThreadExecState because we're about to enter
  the VM.

* bindings/js/JSMutationCallback.cpp:
(WebCore::JSMutationCallback::call):
* bindings/js/JSNodeFilterCondition.cpp:
(WebCore::JSNodeFilterCondition::acceptNode):
- acceptNode() is only used in the TreeWalker and NodeIterator APIs which
  cannot be the first function on the JS stack.  Hence, we should call
  JSC::call() directly instead of going through JSMainThreadExecState.

* bindings/js/ScheduledAction.cpp:
(WebCore::ScheduledAction::executeFunctionInContext):
* bindings/objc/WebScriptObject.mm:
(WebCore::addExceptionToConsole):
(-[WebScriptObject callWebScriptMethod:withArguments:]):

LayoutTests: 

* fast/dom/regress-131530-expected.txt: Added.
* fast/dom/regress-131530.html: Added.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@167142 268f45cc-cd09-0410-ab3c-d52691b4dbfc
[iOS WebKit2]: Share NSURLCache directory for webkit processes
https://bugs.webkit.org/show_bug.cgi?id=131513
<rdar://problem/16420859>

Reviewed by Alexey Proskuryakov.

Use iOS specific NSURLCache API to share the cache directory used by the networking process,
web process and Safari.

* NetworkProcess/cocoa/NetworkProcessCocoa.mm:
(WebKit::NetworkProcess::platformInitializeNetworkProcessCocoa):
* WebProcess/cocoa/WebProcessCocoa.mm:
(WebKit::WebProcess::platformInitializeWebProcess):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@167143 268f45cc-cd09-0410-ab3c-d52691b4dbfc
[Win] Build fix after r167138

* platform/graphics/ca/GraphicsLayerCA.h: The TileController is
only available on Mac/Cocoa builds.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@167144 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Regression: media controls and status messages are no longer localized.
https://bugs.webkit.org/show_bug.cgi?id=120956

Reviewed by Jer Noble.

* English.lproj/mediaControlsLocalizedStrings.js: Added.
(mediaControlsLocalizedStrings): Moved from mediaControlsApple.js.
* English.lproj/mediaControlsLocalizedStringsiOS.js: Added.
(mediaControlsLocalizedStringsiOS): Moved from mediaControlsiOS.js.
* Modules/mediacontrols/mediaControlsApple.js:
(Controller.prototype.UIString): Get strings from external file.
* Modules/mediacontrols/mediaControlsiOS.js:
(ControllerIOS.prototype.UIString): Ditto.
* WebCore.vcxproj/copyWebCoreResourceFiles.cmd: Copy to Windows bundle.
* WebCore.xcodeproj/project.pbxproj: Copy new files to bundle.
* rendering/RenderThemeIOS.mm:
(WebCore::RenderThemeIOS::mediaControlsScript): Load the locale-specific
string resource when loading the media controls.
* rendering/RenderThemeMac.mm:
(WebCore::RenderThemeMac::mediaControlsScript): Ditto.
* rendering/RenderThemeWin.cpp:
(WebCore::RenderThemeWin::mediaControlsScript): Ditto.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@167145 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Try to fix windows build.
        
* platform/graphics/ca/GraphicsLayerCA.h:



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@167146 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Try to fix windows build.
        
Patch by Antti Koivisto <antti@apple.com> on 2014-04-11

* platform/graphics/ca/GraphicsLayerCA.h:



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@167147 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Aggregate multiple "respondToChangedSelection" calls to one scan for telephone numbers
https://bugs.webkit.org/show_bug.cgi?id=131559

Reviewed by Gavin Barraclough.

No new tests (Perf-only change to an untested feature)

* editing/Editor.cpp:
(WebCore::Editor::Editor):
(WebCore::Editor::respondToChangedSelection): Start a one shot timer for scanSelectionForTelephoneNumbers
  instead of scanning synchronously.
(WebCore::Editor::scanSelectionForTelephoneNumbers):
* editing/Editor.h:


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@167148 268f45cc-cd09-0410-ab3c-d52691b4dbfc
[ASan] Build broke because libCompileRuntimeToLLVMIR.a links to libclang_rt.asan_osx_dynamic.dylib
<http://webkit.org/b/131556>
<rdar://problem/16591856>

Reviewed by Brent Fulgham.

* Configurations/CompileRuntimeToLLVMIR.xcconfig: Clear
OTHER_LDFLAGS so the ASan build does not try to link to
libclang_rt.asan_osx_dynamic.dylib.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@167149 268f45cc-cd09-0410-ab3c-d52691b4dbfc
[CSS Shapes] shape-outside from image doesn't load properly
https://bugs.webkit.org/show_bug.cgi?id=131491

Reviewed by Bem Jones-Bey.

Source/WebCore:

Make RenderImage::imageChanged() call super if there's a shape-outside
image because the shape-outside imageChanged() logic is in RenderBox.

Test: http/tests/css/shape-image-file.html

* rendering/RenderElement.h:
(WebCore::RenderElement::hasShapeOutside):
* rendering/RenderImage.cpp:
(WebCore::RenderImage::imageChanged):

LayoutTests:

* http/tests/css/shape-image-file-expected.html: Added.
* http/tests/css/shape-image-file.html: Added.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@167150 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Autocorrection causes ASSERT when replacing alternative string
https://bugs.webkit.org/show_bug.cgi?id=131475

Reviewed by Ryosuke Niwa.

In AlternativeTextController::applyAlternativeTextToRange(), we attempt to create
a Range that crosses from outside of a shadow root to inside of one. Instead,
we should keep the Range entirely within the shadow root.

Test: ManualTests/autocorrection/autocorrection-accept-crash.html

* editing/AlternativeTextController.cpp:
(WebCore::AlternativeTextController::applyAlternativeTextToRange):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@167151 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Support document-relative and custom-frame page overlays
https://bugs.webkit.org/show_bug.cgi?id=131560
<rdar://problem/16595556>

Reviewed by Simon Fraser.

Add "document-relative" overlays, which attach to (and scroll with) the document,
and can be given a frame rect within the document to avoid overallocation of backing store.

* WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
(WebKit::WebFrameLoaderClient::didChangeScrollOffset):
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::mainFrame):
(WebKit::WebPage::mainFrameView):
(WebKit::WebPage::didChangeScrollOffsetForFrame):
* WebProcess/WebPage/WebPage.h:
Let the PageOverlayController know *which* frame scrolled, instead of "any frame".

* WebProcess/WebPage/FindController.cpp:
(WebKit::FindController::updateFindUIAfterPageScroll):
Factor out shared code.

(WebKit::FindController::willMoveToWebPage):
(WebKit::FindController::drawRect):
We can use clearRect() instead of a transparency layer and fillRect().
I've looked through all the other overlay clients I know of and none of them
depend on having a transparency layer at the overlay level.

* WebProcess/WebPage/PageOverlay.cpp:
(WebKit::PageOverlay::create):
(WebKit::PageOverlay::PageOverlay):
(WebKit::PageOverlay::bounds):
(WebKit::PageOverlay::frame):
(WebKit::PageOverlay::setFrame):
(WebKit::PageOverlay::drawRect):
Add OverlayType, which allows creation of Document or View relative overlays.
All overlays up to this point are View relative, so we default to that.
Document-relative overlays scroll with the page instead of repainting as
the page scrolls. They can also be given an explicit frame, allowing them
to be smaller than the entire document.

* WebProcess/WebPage/PageOverlay.h:
(WebKit::PageOverlay::overlayType):
(WebKit::PageOverlay::webPage):
(WebKit::PageOverlay::client): Deleted.
* WebProcess/WebPage/PageOverlayController.cpp:
(WebKit::PageOverlayController::initialize):
(WebKit::PageOverlayController::installPageOverlay):
(WebKit::PageOverlayController::uninstallPageOverlay):
(WebKit::PageOverlayController::updateForceSynchronousScrollLayerPositionUpdates):
(WebKit::updateOverlayGeometry):
(WebKit::PageOverlayController::setPageOverlayNeedsDisplay):
(WebKit::PageOverlayController::didChangeViewSize):
(WebKit::PageOverlayController::didChangeDocumentSize):
(WebKit::PageOverlayController::didChangeDeviceScaleFactor):
(WebKit::PageOverlayController::didScrollFrame):
(WebKit::PageOverlayController::flushPageOverlayLayers):
(WebKit::PageOverlayController::didChangeOverlayFrame):
Keep two overlay root layers - one for view-relative
and one for document-relative overlays.
Don't force synchronous scrolling if we only have document-relative overlays.
Update the overlay's position as well as its size whenever necessary.
Update document-relative overlay geometry when the document size changes.
Only explicitly flush view-relative overlays; document-relative ones
are plugged into the WebCore layer tree and flushed along with the page.

* WebProcess/WebPage/PageOverlayController.h:
(WebKit::PageOverlayController::documentOverlayRootLayer):
(WebKit::PageOverlayController::viewOverlayRootLayer):
* WebProcess/WebPage/mac/RemoteLayerTreeDrawingArea.h:
* WebProcess/WebPage/mac/RemoteLayerTreeDrawingArea.mm:
(WebKit::RemoteLayerTreeDrawingArea::setRootCompositingLayer):
(WebKit::RemoteLayerTreeDrawingArea::mainFrameContentSizeChanged):
* WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.mm:
(WebKit::TiledCoreAnimationDrawingArea::mainFrameContentSizeChanged):
(WebKit::TiledCoreAnimationDrawingArea::setRootCompositingLayer):
Let the PageOverlay controller know when the document size changes.
When we set up compositing, push the document overlay root layer
down into WebCore.

* WebCore.exp.in:
* rendering/RenderLayerCompositor.cpp:
(WebCore::RenderLayerCompositor::RenderLayerCompositor):
(WebCore::RenderLayerCompositor::rebuildCompositingLayerTree):
(WebCore::RenderLayerCompositor::setDocumentOverlayRootLayer):
* rendering/RenderLayerCompositor.h:
Add the concept of a document overlay layer, which is plugged in as the
last child of the root content layer. Expose it to WebKit2.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@167152 268f45cc-cd09-0410-ab3c-d52691b4dbfc
[iOS][WK2] Videos should animate into and out of fullscreen.
https://bugs.webkit.org/show_bug.cgi?id=131497

Reviewed by Simon Fraser.

Source/WebCore:

Use AVPlayerViewController's new enterFullScreenWithCompletionHandler: and exitFullScreenWithCompletionHandler:
methods to animate into and out of full screen. To do so, use the provided initialFrame and finalFrame screen
rects to correctly place the AVPlayerViewController's view before entering or exiting fullscreen.

* platform/ios/WebVideoFullscreenControllerAVKit.mm:
(-[WebVideoFullscreenController enterFullscreen:]): Pass the media element's screen rect.
(-[WebVideoFullscreenController exitFullscreen]): Ditto.
* platform/ios/WebVideoFullscreenInterfaceAVKit.h:
* platform/ios/WebVideoFullscreenInterfaceAVKit.mm:
(-[WebAVPlayerController playerViewController:shouldExitFullScreenWithReason:]): Renamed from shouldDismissWithReason.
(WebVideoFullscreenInterfaceAVKit::enterFullscreen): Use the new AVKit APIs.
(WebVideoFullscreenInterfaceAVKit::exitFullscreen): Ditto.
* WebCore.exp.in: Modify the exported symbols for enter and exitFullscreen.

Source/WebKit2:

Pass a starting rect for the enterFullscreen animation and an ending rect
for the exitFullscreen animation.

* UIProcess/ios/WebVideoFullscreenManagerProxy.h:
* UIProcess/ios/WebVideoFullscreenManagerProxy.messages.in:
* UIProcess/ios/WebVideoFullscreenManagerProxy.mm:
(WebKit::WebVideoFullscreenManagerProxy::enterFullscreenWithID): Pass initialFrame.
* WebProcess/ios/WebVideoFullscreenManager.mm:
(WebKit::screenRectOfContents): Casts node -> element and returns its screenRect().
(WebKit::WebVideoFullscreenManager::enterFullscreenForNode): Pass initialFrame.
(WebKit::WebVideoFullscreenManager::exitFullscreenForNode): Pass finalFrame.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@167153 268f45cc-cd09-0410-ab3c-d52691b4dbfc
[iOS WebKit2] Expose a simplified zoom-to-rect to the WebProcess
https://bugs.webkit.org/show_bug.cgi?id=131563

Reviewed by Simon Fraser.

* UIProcess/PageClient.h:
* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in:
* UIProcess/ios/PageClientImplIOS.h:
* UIProcess/ios/PageClientImplIOS.mm:
(WebKit::PageClientImpl::zoomToRect):
* UIProcess/ios/WebPageProxyIOS.mm:
(WebKit::WebPageProxy::zoomToRect):
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::zoomToRect):
Add a simple message that calls WKContentView's zoom-to-rect code given just a rect and min/max scale.
We will use the center of the rect as the zoom origin, and will try to show the whole rect.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@167154 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Make the stylebot happier with r167154.

* UIProcess/PageClient.h:
* UIProcess/WebPageProxy.h:
* UIProcess/ios/PageClientImplIOS.h:


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@167155 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Web Replay: memoize nondeterministic attributes of the Navigator interface
https://bugs.webkit.org/show_bug.cgi?id=131340

Reviewed by Timothy Hatcher.

.:

* ManualTests/inspector/replay-window-navigator-basic.html: Added.

Source/WebCore:

Most attributes of window.navigator do not change very often, but they
could be easily changed by the user or embedder. So, memoize attribute values.

This change does not include navigator.mimeTypes and navigator.plugins,
which will be handled at a different level. <https://webkit.org/b/131341>

Test: ManualTests/inspector/replay-window-navigator-basic.html

* page/Navigator.idl: Add Nondeterministic attribute.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@167157 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Build fix (r167151): Do not dereference Node::document() before passing to Range::create()
<https://webkit.org/b/131475>

Fixes the following build failure:

    WebCore/editing/AlternativeTextController.cpp:275:71: error: indirection requires pointer operand ('WebCore::Document' invalid)
        int paragraphStartIndex = TextIterator::rangeLength(Range::create(*rootNode.document(), &rootNode, 0, paragraphRangeContainingCorrection.get()->startContainer(), paragraphRangeContainingCorrection.get()->startOffset()).get());
                                                                          ^~~~~~~~~~~~~~~~~~~~

* editing/AlternativeTextController.cpp:
(WebCore::AlternativeTextController::applyAlternativeTextToRange):
Remove unneeded '*' operator since Node::document() returns a
Document& and Range::create() accepts a Document& for its first
argument.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@167160 268f45cc-cd09-0410-ab3c-d52691b4dbfc
[EME][Mac] Using KeySession.update([renew]) should trigger KeyMessage event instead of NeedKey event
https://bugs.webkit.org/show_bug.cgi?id=131527

Reviewed by Eric Carlson.

Rather than triggering a needKey() event, necessatating the creation
of an entirely new MediaKeySession, cause a new key request to be
created by sending the same initData back into the AVSampleDataParser.

Also, do some drive-by clean up suggested by Darin in the review for
r166509.

* platform/graphics/avfoundation/objc/CDMSessionMediaSourceAVFObjC.mm:
(WebCore::isEqual): Support an alloc-free equality check between
    Uint8Array and static strings.
(WebCore::CDMSessionMediaSourceAVFObjC::update):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@167161 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Build Fix after r167151.

Unreviewed.

* editing/AlternativeTextController.cpp:
(WebCore::AlternativeTextController::applyAlternativeTextToRange):

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