Refine MediaSession interruptions
https://bugs.webkit.org/show_bug.cgi?id=128125

Reviewed by Jer Noble.

Source/WebCore: 

Test: media/video-background-playback.html

* WebCore.exp.in: Export applicationWillEnterForeground and applicationWillEnterBackground for
    Internals.

* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::play): Ask the media session if playback is allowed instead of check
    to see if it is interrupted directly.
(WebCore::HTMLMediaElement::pause): Ask the media session if pausing is allowed instead of check
    to see if it is interrupted directly.
(WebCore::HTMLMediaElement::mediaType): Return media type based on media characteristics once
    the information is available.
(WebCore::HTMLMediaElement::resumePlayback): New.
* html/HTMLMediaElement.h:

* html/HTMLMediaSession.cpp:
(WebCore::restrictionName): New, use for logging only.
(WebCore::HTMLMediaSession::addBehaviorRestriction): Log  restriction changes.
(WebCore::HTMLMediaSession::removeBehaviorRestriction): Ditto.
* html/HTMLMediaSession.h:

* platform/audio/MediaSession.cpp:
(WebCore::stateName): New, used for logging.
(WebCore::MediaSession::MediaSession): Don't cache client media type because it can change.
(WebCore::MediaSession::setState): Log state changes.
(WebCore::MediaSession::beginInterruption): Remember the current state in case we want to use it
    to restore state when the interruption ends.
(WebCore::MediaSession::endInterruption): Resume playback if appropriate.
(WebCore::MediaSession::clientWillBeginPlayback): Track the client's playback state.
(WebCore::MediaSession::clientWillPausePlayback): Ditto.
(WebCore::MediaSession::mediaType): Ask client for state.
* platform/audio/MediaSession.h:

* platform/audio/MediaSessionManager.cpp:
(WebCore::MediaSessionManager::MediaSessionManager): m_interruptions -> m_interrupted.
(WebCore::MediaSessionManager::beginInterruption): Don't assume interruptions are always balanced.
(WebCore::MediaSessionManager::endInterruption): Ditto.
(WebCore::MediaSessionManager::addSession): 
(WebCore::MediaSessionManager::applicationWillEnterBackground): Interrupt client if it is not
    allowed to play in the background.
(WebCore::MediaSessionManager::applicationWillEnterForeground): End client interruption if it
    was stopped by an interruption.
* platform/audio/MediaSessionManager.h:

* platform/audio/ios/MediaSessionManagerIOS.h:
* platform/audio/ios/MediaSessionManagerIOS.mm:
(WebCore::MediaSessionManageriOS::~MediaSessionManageriOS): Clear the helper callback.
(WebCore::MediaSessionManageriOS::resetRestrictions): Mark video as not allowed to play
    while the application is in the background. Register for application suspend/resume
    notifications.
(-[WebMediaSessionHelper clearCallback]): Set _callback to nil.
(-[WebMediaSessionHelper applicationWillEnterForeground:]): New, notify client of application 
    state change.
(-[WebMediaSessionHelper applicationWillResignActive:]): Ditto.

* platform/audio/mac/AudioDestinationMac.h: Add resumePlayback.

* testing/Internals.cpp:
(WebCore::Internals::applicationWillEnterForeground): New, simulate application context switch.
(WebCore::Internals::applicationWillEnterBackground): Ditto.
(WebCore::Internals::setMediaSessionRestrictions): Add "BackgroundPlaybackNotPermitted" restriction.
* testing/Internals.h:
* testing/Internals.idl:

Source/WebKit: 

* WebKit.vcxproj/WebKitExportGenerator/WebKitExports.def.in: Export applicationWillEnterForeground
    and applicationWillEnterBackground for Internals.

LayoutTests: 

* media/video-background-playback-expected.txt: Added.
* media/video-background-playback.html: Added.
* media/video-interruption-active-when-element-created-expected.txt: Removed.
* media/video-interruption-active-when-element-created.html: Removed.
* media/video-interruption-with-resume-allowing-play-expected.txt:
* media/video-interruption-with-resume-allowing-play.html:
* media/video-interruption-with-resume-not-allowing-play-expected.txt:
* media/video-interruption-with-resume-not-allowing-play.html:


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@163390 268f45cc-cd09-0410-ab3c-d52691b4dbfc
ASSERT in speculateMachineInt on 32-bit platforms
https://bugs.webkit.org/show_bug.cgi?id=128155

Reviewed by Filip Pizlo.

* dfg/DFGPredictionPropagationPhase.cpp:
(JSC::DFG::PredictionPropagationPhase::propagate):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@163391 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Fix Release build after r163390.

* platform/audio/MediaSession.cpp: Add "#if !LOG_DISABLED" around logging-only function.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@163393 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Rename String::getCharacters to String::characters
https://bugs.webkit.org/show_bug.cgi?id=128196

Reviewed by Andreas Kling.

Source/JavaScriptCore:

Update for WTF::String changes.

* yarr/YarrParser.h:
(JSC::Yarr::Parser::Parser):

Source/WebCore:

Update for WTF::String changes.

* dom/Document.cpp:
(WebCore::canonicalizedTitle):

Source/WTF:

This means String::characters() will end up calling either characters8() or characters16() which
makes more logical sense. It also frees up the getCharacters name so we can use it for a new function
that will do upconversion.

* wtf/text/StringBuilder.cpp:
(WTF::StringBuilder::appendUninitializedSlow):
* wtf/text/WTFString.h:
(WTF::String::characters<LChar>):
(WTF::String::characters<UChar>):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@163394 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Get rid of StringImpl::m_buffer
https://bugs.webkit.org/show_bug.cgi?id=128200

Reviewed by Michael Saboff.

Trade one lousy hack for another by changing the CreateEmptyUnique StringImpl
constructor to initialize its character buffer to point to m_length instead
since it will always be null.

Also change it to be an 8-bit string because why not.

* wtf/text/StringImpl.h:
(WTF::StringImpl::StringImpl):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@163396 268f45cc-cd09-0410-ab3c-d52691b4dbfc
JSC needs to be able to parse DWARF debug_line info
https://bugs.webkit.org/show_bug.cgi?id=127394

Reviewed by Geoffrey Garen.

If we want to encode IR maps in the DWARF debug line info metadata generated by LLVM, 
we'll need to know how to decode the .debug_line DWARF section. This patch implements 
an interpreter for the .debug_line DWARF section in accordance with the version 3 spec 
published at http://www.dwarfstd.org.

* JavaScriptCore.xcodeproj/project.pbxproj:
* ftl/FTLDWARFDebugLineInfo.cpp: Added.
(JSC::FTL::DebugLineInterpreter::DebugLineInterpreter):
(JSC::FTL::read):
(JSC::FTL::DebugLineInterpreter::parseULEB128):
(JSC::FTL::DebugLineInterpreter::parseSLEB128):
(JSC::FTL::DebugLineInterpreter::run):
(JSC::FTL::DebugLineInterpreter::parsePrologue):
(JSC::FTL::DebugLineInterpreter::parseIncludeDirectories):
(JSC::FTL::DebugLineInterpreter::parseFileEntries):
(JSC::FTL::DebugLineInterpreter::parseFileEntry):
(JSC::FTL::DebugLineInterpreter::interpretStatementProgram):
(JSC::FTL::DebugLineInterpreter::interpretOpcode):
(JSC::FTL::DebugLineInterpreter::printLineInfo):
(JSC::FTL::DebugLineInterpreter::resetInterpreterState):
* ftl/FTLDWARFDebugLineInfo.h: Added.
(JSC::FTL::DebugLineInterpreter::Prologue::Prologue):
* ftl/FTLValueRange.cpp: Random build fix for !ENABLE(FTL_JIT).


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