Bring WebKit up to speed with latest Encrypted Media spec.
authorjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 8 Feb 2013 23:31:29 +0000 (23:31 +0000)
committerjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 8 Feb 2013 23:31:29 +0000 (23:31 +0000)
https://bugs.webkit.org/show_bug.cgi?id=97037

Reviewed by Eric Carlson.

Source/JavaScriptCore:

Define the ENABLE_ENCRYPTED_MEDIA_V2 setting.

* Configurations/FeatureDefines.xcconfig:

Source/WebCore:

The most recent version of the Encrypted Media Extensions spec breaks functionality out of the
HTMLMediaElement and into new MediaKeys and MediaKeySession classes. Since the CDM functionality
has been pulled out of the media element, we create a proxy CDM class and factory system for
creating specific CDM key system implementations. The spec also breaks out MediaKeyEvent
into distinct event classes, MediaKeyNeededEvent and MediaKeyMessageEvent, for needkey and
keymessage events, respectively.

Tests: media/encrypted-media/encrypted-media-v2-events.html
       media/encrypted-media/encrypted-media-v2-syntax.html

CDM is a proxy class (a la MediaPlayer) for a specific CDMPrivateInterface implementation. A CDM
implementation is registered with the CDMFactory and will be created if that implementation supports
the key system passed into the MediaKeys constructor. CDMSession is a pure-virtual interface exposed
by concrete CDMPrivate subclasses.  Its lifetime is owned by MediaKeySession.
* Modules/encryptedmedia/CDM.cpp: Added.
(WebCore::installedCDMFactories): Initialize all the known CDM subtypes. Ports will add CDM implementations here.
(WebCore::CDM::registerCDMFactory): Registers a new CDMFactory using the passed in function pointers.
(WebCore::CDMFactoryForKeySystem): Return the first CDM factory which supports the requested key system.
(WebCore::CDM::supportsKeySystem): Walk the installed CDMs and ask if the given key system is supported.
(WebCore::CDM::supportsKeySystemMIMETypeAndCodec): Ditto, with an additional MIME type and codec string.
(WebCore::CDM::create): Simple constructor wrapper.
(WebCore::CDM::CDM): Simple constructor; calls bestCDMForKeySystem() to create it's private implementation.
(WebCore::CDM::~CDM): Simple destructor.
(WebCore::CDM::createSession): Creates a new CDMSession.
* Modules/encryptedmedia/CDM.h: Added.
(WebCore::CDM::keySystem): Simple accessor for m_keySystem.
(WebCore::CDMSession::CDMSession): Simple constructor.
(WebCore::CDMSession::~CDMSession): Simple destructor.
* Modules/encryptedmedia/CDMPrivate.h: Added.
(WebCore::CDMPrivateInterface::CDMPrivateInterface): Simple constructor.
(WebCore::CDMPrivateInterface::~CDMPrivateInterface): Simple destructor.

The new classes, MediaKeyMessageEvent and MediaKeyNeededEvent, take distinct subsets of the initializers of
the original MediaKeyMessageEvent.
* Modules/encryptedmedia/MediaKeyMessageEvent.cpp: Copied from Source/WebCore/html/MediaKeyEvent.cpp.
(WebCore::MediaKeyMessageEventInit::MediaKeyMessageEventInit): Initializer now only takes message and destinationURL
    parameters.
(WebCore::MediaKeyMessageEvent::MediaKeyMessageEvent): Simple constructor.
(WebCore::MediaKeyMessageEvent::~MediaKeyMessageEvent): Simple destructor.
(WebCore::MediaKeyMessageEvent::interfaceName): Standard interfaceName.
* Modules/encryptedmedia/MediaKeyMessageEvent.h: Copied from Source/WebCore/html/MediaKeyEvent.h.
(WebCore::MediaKeyMessageEvent::create): Simple construction wrapper.
(WebCore::MediaKeyMessageEvent::message): Simple accessor for m_message.
(WebCore::MediaKeyMessageEvent::destinationURL): Simple accessor for m_destinationURL.
* Modules/encryptedmedia/MediaKeyMessageEvent.idl: Copied from Source/WebCore/html/MediaKeyEvent.idl.
* Modules/encryptedmedia/MediaKeyNeededEvent.cpp: Copied from Source/WebCore/html/MediaKeyEvent.h.
(WebCore::MediaKeyNeededEventInit::MediaKeyNeededEventInit): Initializer now only takes initData parameter.
(WebCore::MediaKeyNeededEvent::MediaKeyNeededEvent): Simple constructor.
(WebCore::MediaKeyNeededEvent::~MediaKeyNeededEvent): Simple destructor.
(WebCore::MediaKeyNeededEvent::interfaceName): Standard interfaceName.
* Modules/encryptedmedia/MediaKeyNeededEvent.h: Copied from Source/WebCore/html/MediaKeyEvent.h.
(WebCore::MediaKeyNeededEvent::create): Simple construction wrapper.
(WebCore::MediaKeyNeededEvent::initData): Simple accessor for m_initData.
* Modules/encryptedmedia/MediaKeyNeededEvent.idl: Copied from Source/WebCore/html/MediaKeyEvent.idl.

MediaKeySession is a new class that maps keys and key requests to a given session ID:
* Modules/encryptedmedia/MediaKeySession.cpp: Added.
(WebCore::MediaKeySession::create): Simple construction wrapper.
(WebCore::MediaKeySession::MediaKeySession): Simple constructor.
(WebCore::MediaKeySession::~MediaKeySession): Simple destructor; calls close().
(WebCore::MediaKeySession::setError): Simple setter for m_error;
(WebCore::MediaKeySession::close): Tell the CDM to clear any saved session keys.
(WebCore::MediaKeySession::generateKeyRequest): Start a one-shot timer, handled in keyRequestTimerFired.
(WebCore::MediaKeySession::keyRequestTimerFired): Follow the steps in the spec; ask the CDM to generate a key request.
(WebCore::MediaKeySession::addKey): Start a one-shot timer, handled in addKeyTimerFired.
(WebCore::MediaKeySession::addKeyTimerFired): Follow the steps in the spec; provide the key data to the CDM.
* Modules/encryptedmedia/MediaKeySession.h: Added.
(WebCore::MediaKeySession::keySystem): Simple accessor for m_keySystem.
(WebCore::MediaKeySession::sessionId): Simple accessor for m_sessionId.
(WebCore::MediaKeySession::error): Simple accessor for m_error;
* Modules/encryptedmedia/MediaKeySession.idl:

MediaKeySession inherits from EventTarget, and must override the pure virtual functions in that class:
* Modules/encryptedmedia/MediaKeySession.cpp: Added.
(WebCore::MediaKeySession::interfaceName):
* Modules/encryptedmedia/MediaKeySession.h: Added.
(WebCore::MediaKeySession::refEventTarget):
(WebCore::MediaKeySession::derefEventTarget):
(WebCore::MediaKeySession::eventTargetData):
(WebCore::MediaKeySession::ensureEventTargetData):
(WebCore::MediaKeySession::scriptExecutionContext):

MediaKeys is a new class that encapsulates a CDM and a number of key sessions:
* Modules/encryptedmedia/MediaKeys.cpp: Added.
(WebCore::MediaKeys::create): Throw an exception if the key system parameter is unsupported; create a CDM object
    and a new MediaKeys session.
(WebCore::MediaKeys::MediaKeys): Simple constructor.
(WebCore::MediaKeys::~MediaKeys): Simple destructor.
(WebCore::MediaKeys::createSession): Follow the spec and create a new key session.
* Modules/encryptedmedia/MediaKeys.h: Added.
* Modules/encryptedmedia/MediaKeys.idl: Copied from Source/WebCore/html/MediaError.idl.

Provide a new interface to HTMLMediaElement for MediaPlayer which does not require a sessionId or a key system:
* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::mediaPlayerKeyNeeded):
* platform/graphics/MediaPlayer.cpp:
(WebCore::MediaPlayer::keyNeeded):

MediaKeyError now has a systemCode parameter and member variable.
* html/MediaKeyError.h:
(WebCore::MediaKeyError::create): Take a systemCode parameter with a default (0) value.
(WebCore::MediaKeyError::MediaKeyError): Ditto.
(WebCore::MediaKeyError::systemCode): Simple accessor for m_systemCode.
* html/MediaKeyError.idl:

Add new methods to HTMLMediaElement to support MediaKeys. Support different initializer
for the MediaKeyNeededEvent.
* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::setMediaKeys): Simple setter for m_mediaKeys.
(WebCore::HTMLMediaElement::mediaPlayerKeyNeeded): This version takes fewer parameters
    than the deprecated version.
* html/HTMLMediaElement.h:
(WebCore::HTMLMediaElement::mediaKeys): Simple accessor for m_mediaKeys.
* html/HTMLMediaElement.idl: Add the mediaKeys attribute.

Add an ENABLE(ENCRYPTED_MEDIA_V2) check to the existing ENABLE(ENCRYPTED_MEDIA) one:
* html/MediaError.h:
* html/MediaError.idl:
* platform/graphics/MediaPlayer.cpp:
(WebCore::bestMediaEngineForTypeAndCodecs):
(WebCore::MediaPlayer::supportsType):
* platform/graphics/MediaPlayer.h:
(WebCore::MediaPlayer::keyNeeded): This version takes fewer parameters than the
    deprecated version.

Support the new version of canPlayType which takes an extra parameter:
* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h:
* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
(WebCore::MediaPlayerPrivateAVFoundationObjC::registerMediaEngine):
(WebCore::MediaPlayerPrivateAVFoundationObjC::extendedSupportsType):
* platform/graphics/mac/MediaPlayerPrivateQTKit.h:
* platform/graphics/mac/MediaPlayerPrivateQTKit.mm:
(WebCore::MediaPlayerPrivateQTKit::registerMediaEngine):
(WebCore::MediaPlayerPrivateQTKit::extendedSupportsType):

Add a mock CDM for use within DRT and WKTR to test the MediaKeys and MediaKeySession
APIs and events:
* testing/Internals.cpp:
(WebCore::Internals::initializeMockCDM): Add the MockCDM class to the CDM factories.
* testing/Internals.h:
* testing/Internals.idl: Add the initializeMockCDM() method.
* testing/MockCDM.cpp: Added.
(WebCore::MockCDM::supportsKeySystem): Only supports the 'com.webcore.mock' key system.
(WebCore::MockCDM::supportsMIMEType): Only supports the 'video/mock' mime type.
(WebCore::initDataPrefix): Static method which returns a Uint8Array containing 'mock'.
(WebCore::keyPrefix): Static method which returns a Uint8Array containing 'key'.
(WebCore::keyRequest): Static method which returns a Uint8Array containing 'request'.
(WebCore::generateSessionId): Return a monotonically increasing number.
(WebCore::MockCDMSession::MockCDMSession): Simple constructor.
(WebCore::MockCDMSession::generateKeyRequest): Ignores the parameters and returns a keyRequest() array.
(WebCore::MockCDMSession::releaseKeys): No-op.
(WebCore::MockCDMSession::addKey): Checks that the key starts with the keyPrefix() array.
* testing/MockCDM.h: Added.
(WebCore::MockCDM::create):
(WebCore::MockCDM::~MockCDM): Simple destructor.
(WebCore::MockCDM::MockCDM): Simple constructor.

Add the new classes to the built system:
* Configurations/FeatureDefines.xcconfig:
* DerivedSources.make:
* WebCore.exp.in:
* WebCore.xcodeproj/project.pbxproj:

Miscelaneous changes:
* dom/EventNames.in: Add the two new event types, MediaKeyMessageEvent and MediaKeyNeededEvent.
* dom/EventTargetFactory.in: Add the new EventTarget, MediaKeySession.
* page/DOMWindow.idl: Add constructors for the new classes to the window object.

Source/WTF:

Define the ENABLE_ENCRYPTED_MEDIA_V2 setting.

* wtf/Platform.h:

LayoutTests:

Added new tests for the updated Encrypted Media Extensions spec.

* media/encrypted-media/encrypted-media-v2-events-expected.txt: Added.
* media/encrypted-media/encrypted-media-v2-events.html: Added.
* media/encrypted-media/encrypted-media-v2-syntax-expected.txt: Added.
* media/encrypted-media/encrypted-media-v2-syntax.html: Added.
* platform/Chromium/TestExpectations: Skip the new media/encrypted-media/ v2 tests.
* platform/mac/media/encrypted-media/encrypted-media-can-play-type-expected.txt: Added.

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

52 files changed:
LayoutTests/ChangeLog
LayoutTests/media/encrypted-media/encrypted-media-v2-events-expected.txt [new file with mode: 0644]
LayoutTests/media/encrypted-media/encrypted-media-v2-events.html [new file with mode: 0644]
LayoutTests/media/encrypted-media/encrypted-media-v2-syntax-expected.txt [new file with mode: 0644]
LayoutTests/media/encrypted-media/encrypted-media-v2-syntax.html [new file with mode: 0644]
LayoutTests/platform/chromium/TestExpectations
LayoutTests/platform/mac/media/encrypted-media/encrypted-media-can-play-type-expected.txt [new file with mode: 0644]
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/Configurations/FeatureDefines.xcconfig
Source/WTF/ChangeLog
Source/WTF/wtf/Platform.h
Source/WebCore/ChangeLog
Source/WebCore/Configurations/FeatureDefines.xcconfig
Source/WebCore/DerivedSources.make
Source/WebCore/Modules/encryptedmedia/CDM.cpp [new file with mode: 0644]
Source/WebCore/Modules/encryptedmedia/CDM.h [new file with mode: 0644]
Source/WebCore/Modules/encryptedmedia/CDMPrivate.h [new file with mode: 0644]
Source/WebCore/Modules/encryptedmedia/MediaKeyMessageEvent.cpp [new file with mode: 0644]
Source/WebCore/Modules/encryptedmedia/MediaKeyMessageEvent.h [new file with mode: 0644]
Source/WebCore/Modules/encryptedmedia/MediaKeyMessageEvent.idl [new file with mode: 0644]
Source/WebCore/Modules/encryptedmedia/MediaKeyNeededEvent.cpp [new file with mode: 0644]
Source/WebCore/Modules/encryptedmedia/MediaKeyNeededEvent.h [new file with mode: 0644]
Source/WebCore/Modules/encryptedmedia/MediaKeyNeededEvent.idl [new file with mode: 0644]
Source/WebCore/Modules/encryptedmedia/MediaKeySession.cpp [new file with mode: 0644]
Source/WebCore/Modules/encryptedmedia/MediaKeySession.h [new file with mode: 0644]
Source/WebCore/Modules/encryptedmedia/MediaKeySession.idl [new file with mode: 0644]
Source/WebCore/Modules/encryptedmedia/MediaKeys.cpp [new file with mode: 0644]
Source/WebCore/Modules/encryptedmedia/MediaKeys.h [new file with mode: 0644]
Source/WebCore/Modules/encryptedmedia/MediaKeys.idl [new file with mode: 0644]
Source/WebCore/WebCore.exp.in
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/dom/EventNames.in
Source/WebCore/dom/EventTargetFactory.in
Source/WebCore/html/HTMLMediaElement.cpp
Source/WebCore/html/HTMLMediaElement.h
Source/WebCore/html/HTMLMediaElement.idl
Source/WebCore/html/MediaError.h
Source/WebCore/html/MediaError.idl
Source/WebCore/html/MediaKeyError.h
Source/WebCore/html/MediaKeyError.idl
Source/WebCore/page/DOMWindow.idl
Source/WebCore/platform/graphics/MediaPlayer.cpp
Source/WebCore/platform/graphics/MediaPlayer.h
Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h
Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm
Source/WebCore/platform/graphics/mac/MediaPlayerPrivateQTKit.h
Source/WebCore/platform/graphics/mac/MediaPlayerPrivateQTKit.mm
Source/WebCore/testing/Internals.cpp
Source/WebCore/testing/Internals.h
Source/WebCore/testing/Internals.idl
Source/WebCore/testing/MockCDM.cpp [new file with mode: 0644]
Source/WebCore/testing/MockCDM.h [new file with mode: 0644]

index 36f62db..4262671 100644 (file)
@@ -1,3 +1,19 @@
+2013-02-08  Jer Noble  <jer.noble@apple.com>
+
+        Bring WebKit up to speed with latest Encrypted Media spec.
+        https://bugs.webkit.org/show_bug.cgi?id=97037
+
+        Reviewed by Eric Carlson.
+
+        Added new tests for the updated Encrypted Media Extensions spec.
+
+        * media/encrypted-media/encrypted-media-v2-events-expected.txt: Added.
+        * media/encrypted-media/encrypted-media-v2-events.html: Added.
+        * media/encrypted-media/encrypted-media-v2-syntax-expected.txt: Added.
+        * media/encrypted-media/encrypted-media-v2-syntax.html: Added.
+        * platform/Chromium/TestExpectations: Skip the new media/encrypted-media/ v2 tests.
+        * platform/mac/media/encrypted-media/encrypted-media-can-play-type-expected.txt: Added.
+
 2013-02-08  Stephen Chenney  <schenney@chromium.org>
 
         [Chromium] Expectations as a result of removing Skia code suppressions
diff --git a/LayoutTests/media/encrypted-media/encrypted-media-v2-events-expected.txt b/LayoutTests/media/encrypted-media/encrypted-media-v2-events-expected.txt
new file mode 100644 (file)
index 0000000..7b2963a
--- /dev/null
@@ -0,0 +1,11 @@
+This tests the events created by MediaKeys.
+
+RUN(mediaKeys = new MediaKeys("com.webcore.mock"))
+RUN(mediaKeySession = mediaKeys.createSession("video/mock", initData))
+EVENT(webkitkeymessage)
+RUN(mediaKeySession.addKey(invalidKey))
+EVENT(webkitkeyerror)
+RUN(mediaKeySession.addKey(validKey))
+EVENT(webkitkeyadded)
+END OF TEST
+
diff --git a/LayoutTests/media/encrypted-media/encrypted-media-v2-events.html b/LayoutTests/media/encrypted-media/encrypted-media-v2-events.html
new file mode 100644 (file)
index 0000000..1c7e24c
--- /dev/null
@@ -0,0 +1,49 @@
+<!DOCTYPE html>
+<html>
+    <head>
+        <title>MediaKeys</title>
+        <script src=../video-test.js></script>
+        <script>
+            function stringToUint8Array(str)
+            {
+                var arr=[];
+                for(var i=0,j=str.length;i<j;++i)
+                  arr[i]=str.charCodeAt(i);
+                return new Uint8Array(arr);
+            }
+
+            var mediaKeys;
+            var mediaKeySession;
+            var initData = stringToUint8Array('mock');
+            var invalidKey = stringToUint8Array('invalid');
+            var validKey = stringToUint8Array('key');
+
+            function runTest() 
+            {
+                // Initialize the MockCDM. It supports the key system 'com.apple.mock', the 
+                // mime type 'video/mock'. It requires init data to begin with 'mock', and
+                // keys to begin with 'key'.
+                if (internals)
+                    internals.initializeMockCDM();
+
+                run('mediaKeys = new MediaKeys("com.webcore.mock")');
+                run('mediaKeySession = mediaKeys.createSession("video/mock", initData)');
+                waitForEvent('webkitkeymessage', keyMessage, false, false, mediaKeySession);
+                waitForEvent('webkitkeyerror', keyError, false, false, mediaKeySession);
+                waitForEvent('webkitkeyadded', null, true, false, mediaKeySession);
+            }
+
+            function keyMessage(event)
+            {
+                run('mediaKeySession.addKey(invalidKey)');
+            }
+
+            function keyError(event)
+            {
+                run('mediaKeySession.addKey(validKey)');
+            }
+        </script>
+    </head>
+    <body onload="runTest()">
+        <p>This tests the events created by MediaKeys.</p>
+</html>
\ No newline at end of file
diff --git a/LayoutTests/media/encrypted-media/encrypted-media-v2-syntax-expected.txt b/LayoutTests/media/encrypted-media/encrypted-media-v2-syntax-expected.txt
new file mode 100644 (file)
index 0000000..2305111
--- /dev/null
@@ -0,0 +1,26 @@
+This tests the basic API of MediaKeys and MediaKeySession.
+
+Test MediaKeys.
+EXPECTED (typeof window.MediaKeys == 'object') OK
+TEST(new MediaKeys("")) THROWS(DOMException.INVALID_ACCESS_ERR) OK
+TEST(new MediaKeys("unsupported")) THROWS(DOMException.NOT_SUPPORTED_ERR) OK
+RUN(mediaKeys = new MediaKeys("com.webcore.mock"))
+EXPECTED (mediaKeys.keySystem == 'com.webcore.mock') OK
+EXPECTED (typeof mediaKeys.createSession == 'function') OK
+TEST(mediaKeys.createSession("", new Uint8Array(1))) THROWS(DOMException.INVALID_ACCESS_ERR) OK
+TEST(mediaKeys.createSession("unsupported/type")) THROWS(DOMException.NOT_SUPPORTED_ERR) OK
+
+Test MediaKeySession.
+RUN(mediaKeySession = mediaKeys.createSession("video/mock", initData))
+EXPECTED (typeof mediaKeySession == 'object') OK
+EXPECTED (typeof mediaKeySession.addEventListener == 'function') OK
+EXPECTED (typeof mediaKeySession.addKey == 'function') OK
+EXPECTED (mediaKeySession.error == 'null') OK
+EXPECTED (mediaKeySession.keySystem == 'com.webcore.mock') OK
+EXPECTED (mediaKeySession.sessionId != 'null') OK
+EXPECTED (mediaKeySession.onwebkitkeyadded == 'null') OK
+EXPECTED (mediaKeySession.onwebkitkeyerror == 'null') OK
+EXPECTED (mediaKeySession.onwebkitkeymessage == 'null') OK
+TEST(mediaKeySession.addKey(null)) THROWS(DOMException.INVALID_ACCESS_ERR) OK
+END OF TEST
+
diff --git a/LayoutTests/media/encrypted-media/encrypted-media-v2-syntax.html b/LayoutTests/media/encrypted-media/encrypted-media-v2-syntax.html
new file mode 100644 (file)
index 0000000..9a7451f
--- /dev/null
@@ -0,0 +1,57 @@
+<!DOCTYPE html>
+<html>
+    <head>
+        <title>MediaKeys</title>
+        <script src=../video-test.js></script>
+        <script>
+            function stringToUint8Array(str)
+            {
+                var arr=[];
+                for(var i=0,j=str.length;i<j;++i)
+                  arr[i]=str.charCodeAt(i);
+                return new Uint8Array(arr);
+            }
+
+            var mediaKeys;
+            var mediaKeySession;
+            var initData = stringToUint8Array('mock');
+
+            function runTest() 
+            {
+                // Initialize the MockCDM. It supports the key system 'com.apple.mock', the 
+                // mime type 'video/mock'. It requires init data to begin with 'mock', and
+                // keys to begin with 'key'.
+                if (internals)
+                    internals.initializeMockCDM();
+
+                consoleWrite("Test MediaKeys.");
+                testExpected('typeof window.MediaKeys', 'object');
+                testException('new MediaKeys("")', "DOMException.INVALID_ACCESS_ERR");
+                testException('new MediaKeys("unsupported")', "DOMException.NOT_SUPPORTED_ERR");
+                run('mediaKeys = new MediaKeys("com.webcore.mock")');
+                testExpected('mediaKeys.keySystem', 'com.webcore.mock');
+                testExpected('typeof mediaKeys.createSession', 'function');
+                testException('mediaKeys.createSession("", new Uint8Array(1))', "DOMException.INVALID_ACCESS_ERR");
+                testException('mediaKeys.createSession("unsupported/type")', "DOMException.NOT_SUPPORTED_ERR");
+                consoleWrite("");
+
+                consoleWrite("Test MediaKeySession.");
+                run('mediaKeySession = mediaKeys.createSession("video/mock", initData)');
+                testExpected('typeof mediaKeySession', 'object');
+                testExpected('typeof mediaKeySession.addEventListener', 'function');
+                testExpected('typeof mediaKeySession.addKey', 'function');
+                testExpected('mediaKeySession.error', null);
+                testExpected('mediaKeySession.keySystem', 'com.webcore.mock');
+                testExpected('mediaKeySession.sessionId', null, '!=');
+                testExpected('mediaKeySession.onwebkitkeyadded', null);
+                testExpected('mediaKeySession.onwebkitkeyerror', null);
+                testExpected('mediaKeySession.onwebkitkeymessage', null);
+                testException('mediaKeySession.addKey(null)', "DOMException.INVALID_ACCESS_ERR");
+                endTest();
+            }
+        </script>
+    </head>
+    <body onload="runTest()">
+        <p>This tests the basic API of MediaKeys and MediaKeySession.</p>
+    </body>
+</html>
\ No newline at end of file
index 5e207c2..dab5934 100644 (file)
@@ -4354,3 +4354,5 @@ webkit.org/b/109262 [ Debug SnowLeopard ] fast/table/table-cell-before-after-con
 webkit.org/b/109312 [ Win ] fast/canvas/canvas-drawImage-shadow.html [ Pass Failure ]
 webkit.org/b/109312 [ Win ] platform/chromium/virtual/gpu/fast/canvas/canvas-drawImage-shadow.html [ Pass Failure ]
 
+webkit.org/b/97037 media/encrypted-media/encrypted-media-v2-events.html [ Failure ]
+webkit.org/b/97037 media/encrypted-media/encrypted-media-v2-syntax.html [ Failure ]
diff --git a/LayoutTests/platform/mac/media/encrypted-media/encrypted-media-can-play-type-expected.txt b/LayoutTests/platform/mac/media/encrypted-media/encrypted-media-can-play-type-expected.txt
new file mode 100644 (file)
index 0000000..2acc77a
--- /dev/null
@@ -0,0 +1,75 @@
+Test Encrypted Media extension of HTMLMediaElement canPlayType() method.
+
+The test is designed to pass with any implementation regardless of supported media types and relies on the expected log to detect the expected results for some types. To get sufficient coverage, it is important that an implementation support clearkey encryption of at least one of the types below.
+
+Always return the empty string for no type.
+EXPECTED (video.canPlayType() == '') OK
+
+Always return the empty string for an empty type.
+EXPECTED (video.canPlayType('') == '') OK
+EXPECTED (video.canPlayType('', '') == '') OK
+EXPECTED (video.canPlayType('', null) == '') OK
+EXPECTED (video.canPlayType('', undefined) == '') OK
+EXPECTED (video.canPlayType('', 'webkit-org.w3.clearkey') == '') OK
+EXPECTED (video.canPlayType('', 'WeBkIt-OrG.W3.ClEaRkEy') == '') OK
+EXPECTED (video.canPlayType('', 'com.example.invalid') == '') OK
+
+Always return the empty string for when no container is specified.
+EXPECTED (video.canPlayType('video/') == '') OK
+EXPECTED (video.canPlayType('video/', '') == '') OK
+EXPECTED (video.canPlayType('video/', null) == '') OK
+EXPECTED (video.canPlayType('video/', undefined) == '') OK
+EXPECTED (video.canPlayType('video/', 'webkit-org.w3.clearkey') == '') OK
+EXPECTED (video.canPlayType('video/', 'WeBkIt-OrG.W3.ClEaRkEy') == '') OK
+EXPECTED (video.canPlayType('video/', 'com.example.invalid') == '') OK
+
+Always return the empty string for an unsupported container.
+EXPECTED (video.canPlayType('video/blahblah') == '') OK
+EXPECTED (video.canPlayType('video/blahblah', '') == '') OK
+EXPECTED (video.canPlayType('video/blahblah', null) == '') OK
+EXPECTED (video.canPlayType('video/blahblah', undefined) == '') OK
+EXPECTED (video.canPlayType('video/blahblah', 'webkit-org.w3.clearkey') == '') OK
+EXPECTED (video.canPlayType('video/blahblah', 'WeBkIt-OrG.W3.ClEaRkEy') == '') OK
+EXPECTED (video.canPlayType('video/blahblah', 'com.example.invalid') == '') OK
+
+Empty key system parameters should not affect the result of video/mp4 types.
+Result of video.canPlayType('video/mp4; Codecs="avc1.4D400C"'): 'probably'
+EXPECTED (video.canPlayType('video/mp4; Codecs="avc1.4D400C"', '') == 'probably') OK
+EXPECTED (video.canPlayType('video/mp4; Codecs="avc1.4D400C"', null) == 'probably') OK
+EXPECTED (video.canPlayType('video/mp4; Codecs="avc1.4D400C"', undefined) == 'probably') OK
+There are currently no implementations supporting encryption of video/mp4.
+EXPECTED (video.canPlayType('video/mp4; Codecs="avc1.4D400C"', 'webkit-org.w3.clearkey') == '') OK
+EXPECTED (video.canPlayType('video/mp4; Codecs="avc1.4D400C"', 'WeBkIt-OrG.W3.ClEaRkEy') == '') OK
+EXPECTED (video.canPlayType('video/mp4; Codecs="avc1.4D400C"', 'com.example.invalid') == '') OK
+
+Empty key system parameters should not affect the result of audio/mpeg types.
+Result of video.canPlayType('audio/mpeg'): 'maybe'
+EXPECTED (video.canPlayType('audio/mpeg', '') == 'maybe') OK
+EXPECTED (video.canPlayType('audio/mpeg', null) == 'maybe') OK
+EXPECTED (video.canPlayType('audio/mpeg', undefined) == 'maybe') OK
+There are currently no implementations supporting encryption of audio/mpeg.
+EXPECTED (video.canPlayType('audio/mpeg', 'webkit-org.w3.clearkey') == '') OK
+EXPECTED (video.canPlayType('audio/mpeg', 'WeBkIt-OrG.W3.ClEaRkEy') == '') OK
+EXPECTED (video.canPlayType('audio/mpeg', 'com.example.invalid') == '') OK
+
+Empty key system parameters should not affect the result of audio/wav types.
+Result of video.canPlayType('audio/wav'): 'maybe'
+EXPECTED (video.canPlayType('audio/wav', '') == 'maybe') OK
+EXPECTED (video.canPlayType('audio/wav', null) == 'maybe') OK
+EXPECTED (video.canPlayType('audio/wav', undefined) == 'maybe') OK
+There are currently no implementations supporting encryption of audio/wav.
+EXPECTED (video.canPlayType('audio/wav', 'webkit-org.w3.clearkey') == '') OK
+EXPECTED (video.canPlayType('audio/wav', 'WeBkIt-OrG.W3.ClEaRkEy') == '') OK
+EXPECTED (video.canPlayType('audio/wav', 'com.example.invalid') == '') OK
+
+Empty key system parameters should not affect the result of video/webm types.
+Result of video.canPlayType('video/webm'): ''
+EXPECTED (video.canPlayType('video/webm', '') == '') OK
+EXPECTED (video.canPlayType('video/webm', null) == '') OK
+EXPECTED (video.canPlayType('video/webm', undefined) == '') OK
+All implementations that support WebM and Encrypted Media support encrypted WebM.
+EXPECTED (video.canPlayType('video/webm', 'webkit-org.w3.clearkey') == '') OK
+EXPECTED (video.canPlayType('video/webm', 'WeBkIt-OrG.W3.ClEaRkEy') == '') OK
+EXPECTED (video.canPlayType('video/webm', 'com.example.invalid') == '') OK
+END OF TEST
+
index 7df67d3..b7772b1 100644 (file)
@@ -1,3 +1,14 @@
+2013-02-08  Jer Noble  <jer.noble@apple.com>
+
+        Bring WebKit up to speed with latest Encrypted Media spec.
+        https://bugs.webkit.org/show_bug.cgi?id=97037
+
+        Reviewed by Eric Carlson.
+
+        Define the ENABLE_ENCRYPTED_MEDIA_V2 setting.
+
+        * Configurations/FeatureDefines.xcconfig:
+
 2013-02-08  Gavin Barraclough  <barraclough@apple.com>
 
         Objective-C API for JavaScriptCore
index 9470237..29d1df6 100644 (file)
@@ -65,11 +65,11 @@ ENABLE_DIALOG_ELEMENT = ;
 ENABLE_DIRECTORY_UPLOAD = ;
 ENABLE_DOM4_EVENTS_CONSTRUCTOR = ENABLE_DOM4_EVENTS_CONSTRUCTOR;
 ENABLE_DRAGGABLE_REGION = ;
-ENABLE_ENCRYPTED_MEDIA = $(ENABLE_ENCRYPTED_MEDIA_$(PLATFORM_NAME));
-ENABLE_ENCRYPTED_MEDIA_macosx = $(ENABLE_ENCRYPTED_MEDIA_macosx_$(TARGET_MAC_OS_X_VERSION_MAJOR));
-ENABLE_ENCRYPTED_MEDIA_macosx_1070 = ;
-ENABLE_ENCRYPTED_MEDIA_macosx_1080 = ;
-ENABLE_ENCRYPTED_MEDIA_macosx_1090 = ENABLE_ENCRYPTED_MEDIA;
+ENABLE_ENCRYPTED_MEDIA_V2 = $(ENABLE_ENCRYPTED_MEDIA_V2_$(REAL_PLATFORM_NAME));
+ENABLE_ENCRYPTED_MEDIA_V2_macosx = $(ENABLE_ENCRYPTED_MEDIA_macosx_$(TARGET_MAC_OS_X_VERSION_MAJOR));
+ENABLE_ENCRYPTED_MEDIA_V2_macosx_1070 = ;
+ENABLE_ENCRYPTED_MEDIA_V2_macosx_1080 = ;
+ENABLE_ENCRYPTED_MEDIA_V2_macosx_1090 = ENABLE_ENCRYPTED_MEDIA_V2;
 ENABLE_FILE_SYSTEM = ;
 ENABLE_FILTERS = ENABLE_FILTERS;
 ENABLE_FULLSCREEN_API = $(ENABLE_FULLSCREEN_API_$(PLATFORM_NAME));
@@ -167,4 +167,4 @@ ENABLE_WORKERS = ENABLE_WORKERS;
 ENABLE_XHR_TIMEOUT = ENABLE_XHR_TIMEOUT;
 ENABLE_XSLT = ENABLE_XSLT;
 
-FEATURE_DEFINES = $(ENABLE_3D_RENDERING) $(ENABLE_ACCELERATED_2D_CANVAS) $(ENABLE_BLOB) $(ENABLE_CANVAS_PATH) $(ENABLE_CANVAS_PROXY) $(ENABLE_CHANNEL_MESSAGING) $(ENABLE_CSP_NEXT) $(ENABLE_CSS_BOX_DECORATION_BREAK) $(ENABLE_CSS_DEVICE_ADAPTATION) $(ENABLE_CSS_EXCLUSIONS) $(ENABLE_CSS_FILTERS) $(ENABLE_CSS_IMAGE_ORIENTATION) $(ENABLE_CSS_IMAGE_RESOLUTION) $(ENABLE_CSS_REGIONS) $(ENABLE_CSS_SHADERS) $(ENABLE_CSS_COMPOSITING) $(ENABLE_CSS_STICKY_POSITION) $(ENABLE_CSS_TRANSFORMS_ANIMATIONS_UNPREFIXED) $(ENABLE_CSS_VARIABLES) $(ENABLE_CSS3_CONDITIONAL_RULES) $(ENABLE_CSS3_TEXT) $(ENABLE_CUSTOM_SCHEME_HANDLER) $(ENABLE_DASHBOARD_SUPPORT) $(ENABLE_DATALIST_ELEMENT) $(ENABLE_DATA_TRANSFER_ITEMS) $(ENABLE_DETAILS_ELEMENT) $(ENABLE_DEVICE_ORIENTATION) $(ENABLE_DIALOG_ELEMENT) $(ENABLE_DIRECTORY_UPLOAD) $(ENABLE_DOM4_EVENTS_CONSTRUCTOR) $(ENABLE_DRAGGABLE_REGION) $(ENABLE_ENCRYPTED_MEDIA) $(ENABLE_FILE_SYSTEM) $(ENABLE_FILTERS) $(ENABLE_FULLSCREEN_API) $(ENABLE_GAMEPAD) $(ENABLE_GEOLOCATION) $(ENABLE_HIDDEN_PAGE_DOM_TIMER_THROTTLING) $(ENABLE_HIGH_DPI_CANVAS) $(ENABLE_ICONDATABASE) $(ENABLE_IFRAME_SEAMLESS) $(ENABLE_INDEXED_DATABASE) $(ENABLE_INPUT_SPEECH) $(ENABLE_INPUT_TYPE_COLOR) $(ENABLE_INPUT_TYPE_DATE) $(ENABLE_INPUT_TYPE_DATETIME) $(ENABLE_INPUT_TYPE_DATETIMELOCAL) $(ENABLE_INPUT_TYPE_MONTH) $(ENABLE_INPUT_TYPE_TIME) $(ENABLE_INPUT_TYPE_WEEK) $(ENABLE_JAVASCRIPT_DEBUGGER) $(ENABLE_LEGACY_CSS_VENDOR_PREFIXES) $(ENABLE_LEGACY_NOTIFICATIONS) $(ENABLE_LEGACY_VENDOR_PREFIXES) $(ENABLE_LEGACY_WEB_AUDIO) $(ENABLE_LINK_PREFETCH) $(ENABLE_LINK_PRERENDER) $(ENABLE_MATHML) $(ENABLE_MEDIA_SOURCE) $(ENABLE_MEDIA_STATISTICS) $(ENABLE_METER_ELEMENT) $(ENABLE_MHTML) $(ENABLE_MICRODATA) $(ENABLE_MOUSE_CURSOR_SCALE) $(ENABLE_NAVIGATOR_CONTENT_UTILS) $(ENABLE_NOTIFICATIONS) $(ENABLE_PAGE_VISIBILITY_API) $(ENABLE_PDFKIT_PLUGIN) $(ENABLE_PLUGIN_PROXY_FOR_VIDEO) $(ENABLE_PROGRESS_ELEMENT) $(ENABLE_PROXIMITY_EVENTS) $(ENABLE_QUOTA) $(ENABLE_REQUEST_ANIMATION_FRAME) $(ENABLE_RESOLUTION_MEDIA_QUERY) $(ENABLE_SCRIPTED_SPEECH) $(ENABLE_SHADOW_DOM) $(ENABLE_SHARED_WORKERS) $(ENABLE_SPEECH_SYNTHESIS) $(ENABLE_SQL_DATABASE) $(ENABLE_STYLE_SCOPED) $(ENABLE_SUBPIXEL_LAYOUT) $(ENABLE_SVG) $(ENABLE_SVG_DOM_OBJC_BINDINGS) $(ENABLE_SVG_FONTS) $(ENABLE_TEMPLATE_ELEMENT) $(ENABLE_TEXT_AUTOSIZING) $(ENABLE_TEXT_NOTIFICATIONS_ONLY) $(ENABLE_TOUCH_ICON_LOADING) $(ENABLE_USERSELECT_ALL) $(ENABLE_VIDEO) $(ENABLE_VIDEO_TRACK) $(ENABLE_WEBGL) $(ENABLE_WEB_AUDIO) $(ENABLE_WEB_SOCKETS) $(ENABLE_WEB_TIMING) $(ENABLE_WORKERS) $(ENABLE_XHR_TIMEOUT) $(ENABLE_XSLT) $(FEATURE_DEFINES_$(PLATFORM_NAME));
+FEATURE_DEFINES = $(ENABLE_3D_RENDERING) $(ENABLE_ACCELERATED_2D_CANVAS) $(ENABLE_BLOB) $(ENABLE_CANVAS_PATH) $(ENABLE_CANVAS_PROXY) $(ENABLE_CHANNEL_MESSAGING) $(ENABLE_CSP_NEXT) $(ENABLE_CSS_BOX_DECORATION_BREAK) $(ENABLE_CSS_DEVICE_ADAPTATION) $(ENABLE_CSS_EXCLUSIONS) $(ENABLE_CSS_FILTERS) $(ENABLE_CSS_IMAGE_ORIENTATION) $(ENABLE_CSS_IMAGE_RESOLUTION) $(ENABLE_CSS_REGIONS) $(ENABLE_CSS_SHADERS) $(ENABLE_CSS_COMPOSITING) $(ENABLE_CSS_STICKY_POSITION) $(ENABLE_CSS_TRANSFORMS_ANIMATIONS_UNPREFIXED) $(ENABLE_CSS_VARIABLES) $(ENABLE_CSS3_CONDITIONAL_RULES) $(ENABLE_CSS3_TEXT) $(ENABLE_CUSTOM_SCHEME_HANDLER) $(ENABLE_DASHBOARD_SUPPORT) $(ENABLE_DATALIST_ELEMENT) $(ENABLE_DATA_TRANSFER_ITEMS) $(ENABLE_DETAILS_ELEMENT) $(ENABLE_DEVICE_ORIENTATION) $(ENABLE_DIALOG_ELEMENT) $(ENABLE_DIRECTORY_UPLOAD) $(ENABLE_DOM4_EVENTS_CONSTRUCTOR) $(ENABLE_DRAGGABLE_REGION) $(ENABLE_ENCRYPTED_MEDIA_V2) $(ENABLE_FILE_SYSTEM) $(ENABLE_FILTERS) $(ENABLE_FULLSCREEN_API) $(ENABLE_GAMEPAD) $(ENABLE_GEOLOCATION) $(ENABLE_HIDDEN_PAGE_DOM_TIMER_THROTTLING) $(ENABLE_HIGH_DPI_CANVAS) $(ENABLE_ICONDATABASE) $(ENABLE_IFRAME_SEAMLESS) $(ENABLE_INDEXED_DATABASE) $(ENABLE_INPUT_SPEECH) $(ENABLE_INPUT_TYPE_COLOR) $(ENABLE_INPUT_TYPE_DATE) $(ENABLE_INPUT_TYPE_DATETIME) $(ENABLE_INPUT_TYPE_DATETIMELOCAL) $(ENABLE_INPUT_TYPE_MONTH) $(ENABLE_INPUT_TYPE_TIME) $(ENABLE_INPUT_TYPE_WEEK) $(ENABLE_JAVASCRIPT_DEBUGGER) $(ENABLE_LEGACY_CSS_VENDOR_PREFIXES) $(ENABLE_LEGACY_NOTIFICATIONS) $(ENABLE_LEGACY_VENDOR_PREFIXES) $(ENABLE_LEGACY_WEB_AUDIO) $(ENABLE_LINK_PREFETCH) $(ENABLE_LINK_PRERENDER) $(ENABLE_MATHML) $(ENABLE_MEDIA_SOURCE) $(ENABLE_MEDIA_STATISTICS) $(ENABLE_METER_ELEMENT) $(ENABLE_MHTML) $(ENABLE_MICRODATA) $(ENABLE_MOUSE_CURSOR_SCALE) $(ENABLE_NAVIGATOR_CONTENT_UTILS) $(ENABLE_NOTIFICATIONS) $(ENABLE_PAGE_VISIBILITY_API) $(ENABLE_PDFKIT_PLUGIN) $(ENABLE_PLUGIN_PROXY_FOR_VIDEO) $(ENABLE_PROGRESS_ELEMENT) $(ENABLE_PROXIMITY_EVENTS) $(ENABLE_QUOTA) $(ENABLE_REQUEST_ANIMATION_FRAME) $(ENABLE_RESOLUTION_MEDIA_QUERY) $(ENABLE_SCRIPTED_SPEECH) $(ENABLE_SHADOW_DOM) $(ENABLE_SHARED_WORKERS) $(ENABLE_SPEECH_SYNTHESIS) $(ENABLE_SQL_DATABASE) $(ENABLE_STYLE_SCOPED) $(ENABLE_SUBPIXEL_LAYOUT) $(ENABLE_SVG) $(ENABLE_SVG_DOM_OBJC_BINDINGS) $(ENABLE_SVG_FONTS) $(ENABLE_TEMPLATE_ELEMENT) $(ENABLE_TEXT_AUTOSIZING) $(ENABLE_TEXT_NOTIFICATIONS_ONLY) $(ENABLE_TOUCH_ICON_LOADING) $(ENABLE_USERSELECT_ALL) $(ENABLE_VIDEO) $(ENABLE_VIDEO_TRACK) $(ENABLE_WEBGL) $(ENABLE_WEB_AUDIO) $(ENABLE_WEB_SOCKETS) $(ENABLE_WEB_TIMING) $(ENABLE_WORKERS) $(ENABLE_XHR_TIMEOUT) $(ENABLE_XSLT) $(FEATURE_DEFINES_$(PLATFORM_NAME));
index 7521402..a27d971 100644 (file)
@@ -1,3 +1,14 @@
+2013-02-08  Jer Noble  <jer.noble@apple.com>
+
+        Bring WebKit up to speed with latest Encrypted Media spec.
+        https://bugs.webkit.org/show_bug.cgi?id=97037
+
+        Reviewed by Eric Carlson.
+
+        Define the ENABLE_ENCRYPTED_MEDIA_V2 setting.
+
+        * wtf/Platform.h:
+
 2013-02-08  Adam Barth  <abarth@webkit.org>
 
         Use WeakPtrs to communicate between the HTMLDocumentParser and the BackgroundHTMLParser
index 1b14fc9..5a09ab1 100644 (file)
 
 #if PLATFORM(MAC) && !PLATFORM(IOS) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
 #define HAVE_AVFOUNDATION_TEXT_TRACK_SUPPORT 1
+#define ENABLE_ENCRYPTED_MEDIA_V2 1
 #endif
 
 #if PLATFORM(MAC) || PLATFORM(GTK) || PLATFORM(EFL) || (PLATFORM(WIN) && !OS(WINCE) && !PLATFORM(WIN_CAIRO)) || PLATFORM(BLACKBERRY)
index 173f9c6..b4625cc 100644 (file)
@@ -1,3 +1,178 @@
+2013-02-08  Jer Noble  <jer.noble@apple.com>
+
+        Bring WebKit up to speed with latest Encrypted Media spec.
+        https://bugs.webkit.org/show_bug.cgi?id=97037
+
+        Reviewed by Eric Carlson.
+
+        The most recent version of the Encrypted Media Extensions spec breaks functionality out of the
+        HTMLMediaElement and into new MediaKeys and MediaKeySession classes. Since the CDM functionality
+        has been pulled out of the media element, we create a proxy CDM class and factory system for
+        creating specific CDM key system implementations. The spec also breaks out MediaKeyEvent
+        into distinct event classes, MediaKeyNeededEvent and MediaKeyMessageEvent, for needkey and
+        keymessage events, respectively.
+
+        Tests: media/encrypted-media/encrypted-media-v2-events.html
+               media/encrypted-media/encrypted-media-v2-syntax.html
+
+        CDM is a proxy class (a la MediaPlayer) for a specific CDMPrivateInterface implementation. A CDM
+        implementation is registered with the CDMFactory and will be created if that implementation supports
+        the key system passed into the MediaKeys constructor. CDMSession is a pure-virtual interface exposed
+        by concrete CDMPrivate subclasses.  Its lifetime is owned by MediaKeySession.
+        * Modules/encryptedmedia/CDM.cpp: Added.
+        (WebCore::installedCDMFactories): Initialize all the known CDM subtypes. Ports will add CDM implementations here.
+        (WebCore::CDM::registerCDMFactory): Registers a new CDMFactory using the passed in function pointers.
+        (WebCore::CDMFactoryForKeySystem): Return the first CDM factory which supports the requested key system.
+        (WebCore::CDM::supportsKeySystem): Walk the installed CDMs and ask if the given key system is supported.
+        (WebCore::CDM::supportsKeySystemMIMETypeAndCodec): Ditto, with an additional MIME type and codec string.
+        (WebCore::CDM::create): Simple constructor wrapper.
+        (WebCore::CDM::CDM): Simple constructor; calls bestCDMForKeySystem() to create it's private implementation.
+        (WebCore::CDM::~CDM): Simple destructor.
+        (WebCore::CDM::createSession): Creates a new CDMSession.
+        * Modules/encryptedmedia/CDM.h: Added.
+        (WebCore::CDM::keySystem): Simple accessor for m_keySystem.
+        (WebCore::CDMSession::CDMSession): Simple constructor.
+        (WebCore::CDMSession::~CDMSession): Simple destructor.
+        * Modules/encryptedmedia/CDMPrivate.h: Added.
+        (WebCore::CDMPrivateInterface::CDMPrivateInterface): Simple constructor.
+        (WebCore::CDMPrivateInterface::~CDMPrivateInterface): Simple destructor.
+
+        The new classes, MediaKeyMessageEvent and MediaKeyNeededEvent, take distinct subsets of the initializers of
+        the original MediaKeyMessageEvent.
+        * Modules/encryptedmedia/MediaKeyMessageEvent.cpp: Copied from Source/WebCore/html/MediaKeyEvent.cpp.
+        (WebCore::MediaKeyMessageEventInit::MediaKeyMessageEventInit): Initializer now only takes message and destinationURL
+            parameters.
+        (WebCore::MediaKeyMessageEvent::MediaKeyMessageEvent): Simple constructor.
+        (WebCore::MediaKeyMessageEvent::~MediaKeyMessageEvent): Simple destructor.
+        (WebCore::MediaKeyMessageEvent::interfaceName): Standard interfaceName.
+        * Modules/encryptedmedia/MediaKeyMessageEvent.h: Copied from Source/WebCore/html/MediaKeyEvent.h.
+        (WebCore::MediaKeyMessageEvent::create): Simple construction wrapper.
+        (WebCore::MediaKeyMessageEvent::message): Simple accessor for m_message.
+        (WebCore::MediaKeyMessageEvent::destinationURL): Simple accessor for m_destinationURL.
+        * Modules/encryptedmedia/MediaKeyMessageEvent.idl: Copied from Source/WebCore/html/MediaKeyEvent.idl.
+        * Modules/encryptedmedia/MediaKeyNeededEvent.cpp: Copied from Source/WebCore/html/MediaKeyEvent.h.
+        (WebCore::MediaKeyNeededEventInit::MediaKeyNeededEventInit): Initializer now only takes initData parameter.
+        (WebCore::MediaKeyNeededEvent::MediaKeyNeededEvent): Simple constructor.
+        (WebCore::MediaKeyNeededEvent::~MediaKeyNeededEvent): Simple destructor.
+        (WebCore::MediaKeyNeededEvent::interfaceName): Standard interfaceName.
+        * Modules/encryptedmedia/MediaKeyNeededEvent.h: Copied from Source/WebCore/html/MediaKeyEvent.h.
+        (WebCore::MediaKeyNeededEvent::create): Simple construction wrapper.
+        (WebCore::MediaKeyNeededEvent::initData): Simple accessor for m_initData.
+        * Modules/encryptedmedia/MediaKeyNeededEvent.idl: Copied from Source/WebCore/html/MediaKeyEvent.idl.
+
+        MediaKeySession is a new class that maps keys and key requests to a given session ID:
+        * Modules/encryptedmedia/MediaKeySession.cpp: Added.
+        (WebCore::MediaKeySession::create): Simple construction wrapper.
+        (WebCore::MediaKeySession::MediaKeySession): Simple constructor.
+        (WebCore::MediaKeySession::~MediaKeySession): Simple destructor; calls close().
+        (WebCore::MediaKeySession::setError): Simple setter for m_error;
+        (WebCore::MediaKeySession::close): Tell the CDM to clear any saved session keys.
+        (WebCore::MediaKeySession::generateKeyRequest): Start a one-shot timer, handled in keyRequestTimerFired.
+        (WebCore::MediaKeySession::keyRequestTimerFired): Follow the steps in the spec; ask the CDM to generate a key request.
+        (WebCore::MediaKeySession::addKey): Start a one-shot timer, handled in addKeyTimerFired.
+        (WebCore::MediaKeySession::addKeyTimerFired): Follow the steps in the spec; provide the key data to the CDM.
+        * Modules/encryptedmedia/MediaKeySession.h: Added.
+        (WebCore::MediaKeySession::keySystem): Simple accessor for m_keySystem.
+        (WebCore::MediaKeySession::sessionId): Simple accessor for m_sessionId.
+        (WebCore::MediaKeySession::error): Simple accessor for m_error;
+        * Modules/encryptedmedia/MediaKeySession.idl:
+
+        MediaKeySession inherits from EventTarget, and must override the pure virtual functions in that class:
+        * Modules/encryptedmedia/MediaKeySession.cpp: Added.
+        (WebCore::MediaKeySession::interfaceName):
+        * Modules/encryptedmedia/MediaKeySession.h: Added.
+        (WebCore::MediaKeySession::refEventTarget):
+        (WebCore::MediaKeySession::derefEventTarget):
+        (WebCore::MediaKeySession::eventTargetData):
+        (WebCore::MediaKeySession::ensureEventTargetData):
+        (WebCore::MediaKeySession::scriptExecutionContext):
+
+        MediaKeys is a new class that encapsulates a CDM and a number of key sessions:
+        * Modules/encryptedmedia/MediaKeys.cpp: Added.
+        (WebCore::MediaKeys::create): Throw an exception if the key system parameter is unsupported; create a CDM object
+            and a new MediaKeys session.
+        (WebCore::MediaKeys::MediaKeys): Simple constructor.
+        (WebCore::MediaKeys::~MediaKeys): Simple destructor.
+        (WebCore::MediaKeys::createSession): Follow the spec and create a new key session.
+        * Modules/encryptedmedia/MediaKeys.h: Added.
+        * Modules/encryptedmedia/MediaKeys.idl: Copied from Source/WebCore/html/MediaError.idl.
+
+        Provide a new interface to HTMLMediaElement for MediaPlayer which does not require a sessionId or a key system:
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::mediaPlayerKeyNeeded):
+        * platform/graphics/MediaPlayer.cpp:
+        (WebCore::MediaPlayer::keyNeeded):
+
+        MediaKeyError now has a systemCode parameter and member variable.
+        * html/MediaKeyError.h:
+        (WebCore::MediaKeyError::create): Take a systemCode parameter with a default (0) value.
+        (WebCore::MediaKeyError::MediaKeyError): Ditto.
+        (WebCore::MediaKeyError::systemCode): Simple accessor for m_systemCode.
+        * html/MediaKeyError.idl:
+
+        Add new methods to HTMLMediaElement to support MediaKeys. Support different initializer
+        for the MediaKeyNeededEvent.
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::setMediaKeys): Simple setter for m_mediaKeys.
+        (WebCore::HTMLMediaElement::mediaPlayerKeyNeeded): This version takes fewer parameters
+            than the deprecated version.
+        * html/HTMLMediaElement.h:
+        (WebCore::HTMLMediaElement::mediaKeys): Simple accessor for m_mediaKeys.
+        * html/HTMLMediaElement.idl: Add the mediaKeys attribute.
+
+        Add an ENABLE(ENCRYPTED_MEDIA_V2) check to the existing ENABLE(ENCRYPTED_MEDIA) one:
+        * html/MediaError.h:
+        * html/MediaError.idl:
+        * platform/graphics/MediaPlayer.cpp:
+        (WebCore::bestMediaEngineForTypeAndCodecs):
+        (WebCore::MediaPlayer::supportsType):
+        * platform/graphics/MediaPlayer.h:
+        (WebCore::MediaPlayer::keyNeeded): This version takes fewer parameters than the
+            deprecated version.
+
+        Support the new version of canPlayType which takes an extra parameter:
+        * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h:
+        * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
+        (WebCore::MediaPlayerPrivateAVFoundationObjC::registerMediaEngine):
+        (WebCore::MediaPlayerPrivateAVFoundationObjC::extendedSupportsType):
+        * platform/graphics/mac/MediaPlayerPrivateQTKit.h:
+        * platform/graphics/mac/MediaPlayerPrivateQTKit.mm:
+        (WebCore::MediaPlayerPrivateQTKit::registerMediaEngine):
+        (WebCore::MediaPlayerPrivateQTKit::extendedSupportsType):
+
+        Add a mock CDM for use within DRT and WKTR to test the MediaKeys and MediaKeySession
+        APIs and events:
+        * testing/Internals.cpp:
+        (WebCore::Internals::initializeMockCDM): Add the MockCDM class to the CDM factories.
+        * testing/Internals.h:
+        * testing/Internals.idl: Add the initializeMockCDM() method.
+        * testing/MockCDM.cpp: Added.
+        (WebCore::MockCDM::supportsKeySystem): Only supports the 'com.webcore.mock' key system.
+        (WebCore::MockCDM::supportsMIMEType): Only supports the 'video/mock' mime type.
+        (WebCore::initDataPrefix): Static method which returns a Uint8Array containing 'mock'.
+        (WebCore::keyPrefix): Static method which returns a Uint8Array containing 'key'.
+        (WebCore::keyRequest): Static method which returns a Uint8Array containing 'request'.
+        (WebCore::generateSessionId): Return a monotonically increasing number.
+        (WebCore::MockCDMSession::MockCDMSession): Simple constructor.
+        (WebCore::MockCDMSession::generateKeyRequest): Ignores the parameters and returns a keyRequest() array.
+        (WebCore::MockCDMSession::releaseKeys): No-op.
+        (WebCore::MockCDMSession::addKey): Checks that the key starts with the keyPrefix() array.
+        * testing/MockCDM.h: Added.
+        (WebCore::MockCDM::create):
+        (WebCore::MockCDM::~MockCDM): Simple destructor.
+        (WebCore::MockCDM::MockCDM): Simple constructor.
+
+        Add the new classes to the built system:
+        * Configurations/FeatureDefines.xcconfig:
+        * DerivedSources.make:
+        * WebCore.exp.in:
+        * WebCore.xcodeproj/project.pbxproj:
+
+        Miscelaneous changes:
+        * dom/EventNames.in: Add the two new event types, MediaKeyMessageEvent and MediaKeyNeededEvent.
+        * dom/EventTargetFactory.in: Add the new EventTarget, MediaKeySession.
+        * page/DOMWindow.idl: Add constructors for the new classes to the window object.
+
 2013-02-08  Chris Fleizach  <cfleizach@apple.com>
 
         Refactor platform-specific code in SpeechSynthesis
index 9470237..79772fb 100644 (file)
@@ -65,11 +65,11 @@ ENABLE_DIALOG_ELEMENT = ;
 ENABLE_DIRECTORY_UPLOAD = ;
 ENABLE_DOM4_EVENTS_CONSTRUCTOR = ENABLE_DOM4_EVENTS_CONSTRUCTOR;
 ENABLE_DRAGGABLE_REGION = ;
-ENABLE_ENCRYPTED_MEDIA = $(ENABLE_ENCRYPTED_MEDIA_$(PLATFORM_NAME));
-ENABLE_ENCRYPTED_MEDIA_macosx = $(ENABLE_ENCRYPTED_MEDIA_macosx_$(TARGET_MAC_OS_X_VERSION_MAJOR));
-ENABLE_ENCRYPTED_MEDIA_macosx_1070 = ;
-ENABLE_ENCRYPTED_MEDIA_macosx_1080 = ;
-ENABLE_ENCRYPTED_MEDIA_macosx_1090 = ENABLE_ENCRYPTED_MEDIA;
+ENABLE_ENCRYPTED_MEDIA_V2 = $(ENABLE_ENCRYPTED_MEDIA_V2_$(REAL_PLATFORM_NAME));
+ENABLE_ENCRYPTED_MEDIA_V2_macosx = $(ENABLE_ENCRYPTED_MEDIA_V2_macosx_$(TARGET_MAC_OS_X_VERSION_MAJOR));
+ENABLE_ENCRYPTED_MEDIA_V2_macosx_1070 = ;
+ENABLE_ENCRYPTED_MEDIA_V2_macosx_1080 = ;
+ENABLE_ENCRYPTED_MEDIA_V2_macosx_1090 = ENABLE_ENCRYPTED_MEDIA_V2;
 ENABLE_FILE_SYSTEM = ;
 ENABLE_FILTERS = ENABLE_FILTERS;
 ENABLE_FULLSCREEN_API = $(ENABLE_FULLSCREEN_API_$(PLATFORM_NAME));
@@ -167,4 +167,4 @@ ENABLE_WORKERS = ENABLE_WORKERS;
 ENABLE_XHR_TIMEOUT = ENABLE_XHR_TIMEOUT;
 ENABLE_XSLT = ENABLE_XSLT;
 
-FEATURE_DEFINES = $(ENABLE_3D_RENDERING) $(ENABLE_ACCELERATED_2D_CANVAS) $(ENABLE_BLOB) $(ENABLE_CANVAS_PATH) $(ENABLE_CANVAS_PROXY) $(ENABLE_CHANNEL_MESSAGING) $(ENABLE_CSP_NEXT) $(ENABLE_CSS_BOX_DECORATION_BREAK) $(ENABLE_CSS_DEVICE_ADAPTATION) $(ENABLE_CSS_EXCLUSIONS) $(ENABLE_CSS_FILTERS) $(ENABLE_CSS_IMAGE_ORIENTATION) $(ENABLE_CSS_IMAGE_RESOLUTION) $(ENABLE_CSS_REGIONS) $(ENABLE_CSS_SHADERS) $(ENABLE_CSS_COMPOSITING) $(ENABLE_CSS_STICKY_POSITION) $(ENABLE_CSS_TRANSFORMS_ANIMATIONS_UNPREFIXED) $(ENABLE_CSS_VARIABLES) $(ENABLE_CSS3_CONDITIONAL_RULES) $(ENABLE_CSS3_TEXT) $(ENABLE_CUSTOM_SCHEME_HANDLER) $(ENABLE_DASHBOARD_SUPPORT) $(ENABLE_DATALIST_ELEMENT) $(ENABLE_DATA_TRANSFER_ITEMS) $(ENABLE_DETAILS_ELEMENT) $(ENABLE_DEVICE_ORIENTATION) $(ENABLE_DIALOG_ELEMENT) $(ENABLE_DIRECTORY_UPLOAD) $(ENABLE_DOM4_EVENTS_CONSTRUCTOR) $(ENABLE_DRAGGABLE_REGION) $(ENABLE_ENCRYPTED_MEDIA) $(ENABLE_FILE_SYSTEM) $(ENABLE_FILTERS) $(ENABLE_FULLSCREEN_API) $(ENABLE_GAMEPAD) $(ENABLE_GEOLOCATION) $(ENABLE_HIDDEN_PAGE_DOM_TIMER_THROTTLING) $(ENABLE_HIGH_DPI_CANVAS) $(ENABLE_ICONDATABASE) $(ENABLE_IFRAME_SEAMLESS) $(ENABLE_INDEXED_DATABASE) $(ENABLE_INPUT_SPEECH) $(ENABLE_INPUT_TYPE_COLOR) $(ENABLE_INPUT_TYPE_DATE) $(ENABLE_INPUT_TYPE_DATETIME) $(ENABLE_INPUT_TYPE_DATETIMELOCAL) $(ENABLE_INPUT_TYPE_MONTH) $(ENABLE_INPUT_TYPE_TIME) $(ENABLE_INPUT_TYPE_WEEK) $(ENABLE_JAVASCRIPT_DEBUGGER) $(ENABLE_LEGACY_CSS_VENDOR_PREFIXES) $(ENABLE_LEGACY_NOTIFICATIONS) $(ENABLE_LEGACY_VENDOR_PREFIXES) $(ENABLE_LEGACY_WEB_AUDIO) $(ENABLE_LINK_PREFETCH) $(ENABLE_LINK_PRERENDER) $(ENABLE_MATHML) $(ENABLE_MEDIA_SOURCE) $(ENABLE_MEDIA_STATISTICS) $(ENABLE_METER_ELEMENT) $(ENABLE_MHTML) $(ENABLE_MICRODATA) $(ENABLE_MOUSE_CURSOR_SCALE) $(ENABLE_NAVIGATOR_CONTENT_UTILS) $(ENABLE_NOTIFICATIONS) $(ENABLE_PAGE_VISIBILITY_API) $(ENABLE_PDFKIT_PLUGIN) $(ENABLE_PLUGIN_PROXY_FOR_VIDEO) $(ENABLE_PROGRESS_ELEMENT) $(ENABLE_PROXIMITY_EVENTS) $(ENABLE_QUOTA) $(ENABLE_REQUEST_ANIMATION_FRAME) $(ENABLE_RESOLUTION_MEDIA_QUERY) $(ENABLE_SCRIPTED_SPEECH) $(ENABLE_SHADOW_DOM) $(ENABLE_SHARED_WORKERS) $(ENABLE_SPEECH_SYNTHESIS) $(ENABLE_SQL_DATABASE) $(ENABLE_STYLE_SCOPED) $(ENABLE_SUBPIXEL_LAYOUT) $(ENABLE_SVG) $(ENABLE_SVG_DOM_OBJC_BINDINGS) $(ENABLE_SVG_FONTS) $(ENABLE_TEMPLATE_ELEMENT) $(ENABLE_TEXT_AUTOSIZING) $(ENABLE_TEXT_NOTIFICATIONS_ONLY) $(ENABLE_TOUCH_ICON_LOADING) $(ENABLE_USERSELECT_ALL) $(ENABLE_VIDEO) $(ENABLE_VIDEO_TRACK) $(ENABLE_WEBGL) $(ENABLE_WEB_AUDIO) $(ENABLE_WEB_SOCKETS) $(ENABLE_WEB_TIMING) $(ENABLE_WORKERS) $(ENABLE_XHR_TIMEOUT) $(ENABLE_XSLT) $(FEATURE_DEFINES_$(PLATFORM_NAME));
+FEATURE_DEFINES = $(ENABLE_3D_RENDERING) $(ENABLE_ACCELERATED_2D_CANVAS) $(ENABLE_BLOB) $(ENABLE_CANVAS_PATH) $(ENABLE_CANVAS_PROXY) $(ENABLE_CHANNEL_MESSAGING) $(ENABLE_CSP_NEXT) $(ENABLE_CSS_BOX_DECORATION_BREAK) $(ENABLE_CSS_DEVICE_ADAPTATION) $(ENABLE_CSS_EXCLUSIONS) $(ENABLE_CSS_FILTERS) $(ENABLE_CSS_IMAGE_ORIENTATION) $(ENABLE_CSS_IMAGE_RESOLUTION) $(ENABLE_CSS_REGIONS) $(ENABLE_CSS_SHADERS) $(ENABLE_CSS_COMPOSITING) $(ENABLE_CSS_STICKY_POSITION) $(ENABLE_CSS_TRANSFORMS_ANIMATIONS_UNPREFIXED) $(ENABLE_CSS_VARIABLES) $(ENABLE_CSS3_CONDITIONAL_RULES) $(ENABLE_CSS3_TEXT) $(ENABLE_CUSTOM_SCHEME_HANDLER) $(ENABLE_DASHBOARD_SUPPORT) $(ENABLE_DATALIST_ELEMENT) $(ENABLE_DATA_TRANSFER_ITEMS) $(ENABLE_DETAILS_ELEMENT) $(ENABLE_DEVICE_ORIENTATION) $(ENABLE_DIALOG_ELEMENT) $(ENABLE_DIRECTORY_UPLOAD) $(ENABLE_DOM4_EVENTS_CONSTRUCTOR) $(ENABLE_DRAGGABLE_REGION) $(ENABLE_ENCRYPTED_MEDIA_V2) $(ENABLE_FILE_SYSTEM) $(ENABLE_FILTERS) $(ENABLE_FULLSCREEN_API) $(ENABLE_GAMEPAD) $(ENABLE_GEOLOCATION) $(ENABLE_HIDDEN_PAGE_DOM_TIMER_THROTTLING) $(ENABLE_HIGH_DPI_CANVAS) $(ENABLE_ICONDATABASE) $(ENABLE_IFRAME_SEAMLESS) $(ENABLE_INDEXED_DATABASE) $(ENABLE_INPUT_SPEECH) $(ENABLE_INPUT_TYPE_COLOR) $(ENABLE_INPUT_TYPE_DATE) $(ENABLE_INPUT_TYPE_DATETIME) $(ENABLE_INPUT_TYPE_DATETIMELOCAL) $(ENABLE_INPUT_TYPE_MONTH) $(ENABLE_INPUT_TYPE_TIME) $(ENABLE_INPUT_TYPE_WEEK) $(ENABLE_JAVASCRIPT_DEBUGGER) $(ENABLE_LEGACY_CSS_VENDOR_PREFIXES) $(ENABLE_LEGACY_NOTIFICATIONS) $(ENABLE_LEGACY_VENDOR_PREFIXES) $(ENABLE_LEGACY_WEB_AUDIO) $(ENABLE_LINK_PREFETCH) $(ENABLE_LINK_PRERENDER) $(ENABLE_MATHML) $(ENABLE_MEDIA_SOURCE) $(ENABLE_MEDIA_STATISTICS) $(ENABLE_METER_ELEMENT) $(ENABLE_MHTML) $(ENABLE_MICRODATA) $(ENABLE_MOUSE_CURSOR_SCALE) $(ENABLE_NAVIGATOR_CONTENT_UTILS) $(ENABLE_NOTIFICATIONS) $(ENABLE_PAGE_VISIBILITY_API) $(ENABLE_PDFKIT_PLUGIN) $(ENABLE_PLUGIN_PROXY_FOR_VIDEO) $(ENABLE_PROGRESS_ELEMENT) $(ENABLE_PROXIMITY_EVENTS) $(ENABLE_QUOTA) $(ENABLE_REQUEST_ANIMATION_FRAME) $(ENABLE_RESOLUTION_MEDIA_QUERY) $(ENABLE_SCRIPTED_SPEECH) $(ENABLE_SHADOW_DOM) $(ENABLE_SHARED_WORKERS) $(ENABLE_SPEECH_SYNTHESIS) $(ENABLE_SQL_DATABASE) $(ENABLE_STYLE_SCOPED) $(ENABLE_SUBPIXEL_LAYOUT) $(ENABLE_SVG) $(ENABLE_SVG_DOM_OBJC_BINDINGS) $(ENABLE_SVG_FONTS) $(ENABLE_TEMPLATE_ELEMENT) $(ENABLE_TEXT_AUTOSIZING) $(ENABLE_TEXT_NOTIFICATIONS_ONLY) $(ENABLE_TOUCH_ICON_LOADING) $(ENABLE_USERSELECT_ALL) $(ENABLE_VIDEO) $(ENABLE_VIDEO_TRACK) $(ENABLE_WEBGL) $(ENABLE_WEB_AUDIO) $(ENABLE_WEB_SOCKETS) $(ENABLE_WEB_TIMING) $(ENABLE_WORKERS) $(ENABLE_XHR_TIMEOUT) $(ENABLE_XSLT) $(FEATURE_DEFINES_$(PLATFORM_NAME));
index 39bde8e..99cb4f8 100644 (file)
@@ -28,6 +28,7 @@
 
 VPATH = \
     $(WebCore) \
+       $(WebCore)/Modules/encryptedmedia \
     $(WebCore)/Modules/filesystem \
     $(WebCore)/Modules/geolocation \
     $(WebCore)/Modules/indexeddb \
@@ -62,6 +63,10 @@ VPATH = \
 #
 
 BINDING_IDLS = \
+    $(WebCore)/Modules/encryptedmedia/MediaKeyMessageEvent.idl \
+    $(WebCore)/Modules/encryptedmedia/MediaKeyNeededEvent.idl \
+    $(WebCore)/Modules/encryptedmedia/MediaKeySession.idl \
+    $(WebCore)/Modules/encryptedmedia/MediaKeys.idl \
     $(WebCore)/Modules/filesystem/DOMFileSystem.idl \
     $(WebCore)/Modules/filesystem/DOMFileSystemSync.idl \
     $(WebCore)/Modules/filesystem/DOMWindowFileSystem.idl \
@@ -366,8 +371,8 @@ BINDING_IDLS = \
     $(WebCore)/html/ImageData.idl \
     $(WebCore)/html/MediaController.idl \
     $(WebCore)/html/MediaError.idl \
-       $(WebCore)/html/MediaKeyError.idl \
-       $(WebCore)/html/MediaKeyEvent.idl \
+    $(WebCore)/html/MediaKeyError.idl \
+    $(WebCore)/html/MediaKeyEvent.idl \
     $(WebCore)/html/MicroDataItemValue.idl \
     $(WebCore)/html/RadioNodeList.idl \
     $(WebCore)/html/TextMetrics.idl \
@@ -839,6 +844,10 @@ ifeq ($(findstring ENABLE_DETAILS_ELEMENT,$(FEATURE_DEFINES)), ENABLE_DETAILS_EL
     HTML_FLAGS := $(HTML_FLAGS) ENABLE_DETAILS_ELEMENT=1
 endif
 
+ifeq ($(findstring ENABLE_ENCRYPTED_MEDIA_V2,$(FEATURE_DEFINES)), ENABLE_ENCRYPTED_MEDIA_V2)
+       HTML_FLAGS := $(HTML_FLAGS) ENABLE_ENCRYPTED_MEDIA_V2=1
+endif
+
 ifeq ($(findstring ENABLE_METER_ELEMENT,$(FEATURE_DEFINES)), ENABLE_METER_ELEMENT)
     HTML_FLAGS := $(HTML_FLAGS) ENABLE_METER_ELEMENT=1
 endif
@@ -963,6 +972,7 @@ preprocess_idls_script = perl $(addprefix -I $(WebCore)/, $(sort $(dir $(1)))) $
 
 IDL_INCLUDES = \
     $(WebCore)/Modules/battery \
+       $(WebCore)/Modules/encryptedmedia \
     $(WebCore)/Modules/filesystem \
     $(WebCore)/Modules/gamepad \
     $(WebCore)/Modules/geolocation \
diff --git a/Source/WebCore/Modules/encryptedmedia/CDM.cpp b/Source/WebCore/Modules/encryptedmedia/CDM.cpp
new file mode 100644 (file)
index 0000000..f866535
--- /dev/null
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#if ENABLE(ENCRYPTED_MEDIA_V2)
+
+#include "CDM.h"
+
+#include "CDMPrivate.h"
+#include "MediaKeyError.h"
+#include "MediaKeys.h"
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+struct CDMFactory {
+    WTF_MAKE_NONCOPYABLE(CDMFactory); WTF_MAKE_FAST_ALLOCATED;
+public:
+    CDMFactory(CreateCDM constructor, CDMSupportsKeySystem supportsKeySystem)
+        : constructor(constructor)
+        , supportsKeySystem(supportsKeySystem)
+    {
+    }
+
+    CreateCDM constructor;
+    CDMSupportsKeySystem supportsKeySystem;
+};
+
+static Vector<CDMFactory*>& installedCDMFactories()
+{
+    DEFINE_STATIC_LOCAL(Vector<CDMFactory*>, cdms, ());
+    static bool queriedCDMs = false;
+    if (!queriedCDMs) {
+        queriedCDMs = true;
+
+        // FIXME: initialize specific UA CDMs. http://webkit.org/b/109318, http://webkit.org/b/109320
+    }
+
+    return cdms;
+}
+
+void CDM::registerCDMFactory(CreateCDM constructor, CDMSupportsKeySystem supportsKeySystem)
+{
+    installedCDMFactories().append(new CDMFactory(constructor, supportsKeySystem));
+}
+
+static CDMFactory* CDMFactoryForKeySystem(const String& keySystem)
+{
+    Vector<CDMFactory*>& cdmFactories = installedCDMFactories();
+    for (size_t i = 0; i < cdmFactories.size(); ++i) {
+        if (cdmFactories[i]->supportsKeySystem(keySystem))
+            return cdmFactories[i];
+    }
+    return 0;
+}
+
+bool CDM::supportsKeySystem(const String& keySystem)
+{
+    return CDMFactoryForKeySystem(keySystem);
+}
+
+PassOwnPtr<CDM> CDM::create(const String& keySystem)
+{
+    if (!supportsKeySystem(keySystem))
+        return nullptr;
+
+    return adoptPtr(new CDM(keySystem));
+}
+
+CDM::CDM(const String& keySystem)
+    : m_keySystem(keySystem)
+{
+    m_private = CDMFactoryForKeySystem(keySystem)->constructor(this);
+}
+
+CDM::~CDM()
+{
+}
+
+bool CDM::supportsMIMEType(const String& mimeType)
+{
+    return m_private->supportsMIMEType(mimeType);
+}
+
+PassOwnPtr<CDMSession> CDM::createSession()
+{
+    return m_private->createSession();
+}
+
+}
+
+#endif // ENABLE(ENCRYPTED_MEDIA_V2)
diff --git a/Source/WebCore/Modules/encryptedmedia/CDM.h b/Source/WebCore/Modules/encryptedmedia/CDM.h
new file mode 100644 (file)
index 0000000..0bc3e88
--- /dev/null
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef CDM_h
+#define CDM_h
+
+#if ENABLE(ENCRYPTED_MEDIA_V2)
+
+#include <wtf/Forward.h>
+#include <wtf/PassRefPtr.h>
+#include <wtf/Uint8Array.h>
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+class CDM;
+class CDMPrivateInterface;
+class CDMSession;
+class MediaKeyError;
+class MediaKeySession;
+class MediaKeys;
+
+typedef PassOwnPtr<CDMPrivateInterface> (*CreateCDM)(CDM*);
+typedef bool (*CDMSupportsKeySystem)(const String&);
+
+class CDMSession {
+public:
+    CDMSession() { }
+    virtual ~CDMSession() { }
+
+    virtual const String& sessionId() = 0;
+    virtual PassRefPtr<Uint8Array> generateKeyRequest(const String& mimeType, Uint8Array* initData, String& destinationURL, unsigned short& errorCode, unsigned long& systemCode) = 0;
+    virtual void releaseKeys() = 0;
+    virtual bool addKey(Uint8Array*, RefPtr<Uint8Array>& nextMessage, unsigned short& errorCode, unsigned long& systemCode) = 0;
+};
+
+class CDM {
+public:
+    static bool supportsKeySystem(const String&);
+    static PassOwnPtr<CDM> create(const String& keySystem);
+    static void registerCDMFactory(CreateCDM, CDMSupportsKeySystem);
+    ~CDM();
+
+    bool supportsMIMEType(const String&);
+    PassOwnPtr<CDMSession> createSession();
+
+    const String& keySystem() const { return m_keySystem; }
+
+private:
+    CDM(const String& keySystem);
+
+    String m_keySystem;
+    OwnPtr<CDMPrivateInterface> m_private;
+};
+
+}
+
+#endif // ENABLE(ENCRYPTED_MEDIA_V2)
+
+#endif // CDM_h
diff --git a/Source/WebCore/Modules/encryptedmedia/CDMPrivate.h b/Source/WebCore/Modules/encryptedmedia/CDMPrivate.h
new file mode 100644 (file)
index 0000000..82a5857
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef CDMPrivate_h
+#define CDMPrivate_h
+
+#if ENABLE(ENCRYPTED_MEDIA_V2)
+
+#include <wtf/OwnPtr.h>
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+class CDMSession;
+
+class CDMPrivateInterface {
+public:
+    CDMPrivateInterface() { }
+    virtual ~CDMPrivateInterface() { }
+
+    virtual bool supportsMIMEType(const String&) = 0;
+
+    virtual PassOwnPtr<CDMSession> createSession() = 0;
+};
+
+}
+
+#endif // ENABLE(ENCRYPTED_MEDIA_V2)
+
+#endif // CDMPrivate_h
diff --git a/Source/WebCore/Modules/encryptedmedia/MediaKeyMessageEvent.cpp b/Source/WebCore/Modules/encryptedmedia/MediaKeyMessageEvent.cpp
new file mode 100644 (file)
index 0000000..4a9c843
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2012 Google Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#include "config.h"
+
+#if ENABLE(ENCRYPTED_MEDIA_V2)
+
+#include "MediaKeyMessageEvent.h"
+
+#include "EventNames.h"
+#include <wtf/Uint8Array.h>
+
+namespace WebCore {
+
+MediaKeyMessageEventInit::MediaKeyMessageEventInit()
+{
+}
+
+MediaKeyMessageEvent::MediaKeyMessageEvent()
+{
+}
+
+MediaKeyMessageEvent::MediaKeyMessageEvent(const AtomicString& type, const MediaKeyMessageEventInit& initializer)
+    : Event(type, initializer)
+    , m_message(initializer.message)
+    , m_destinationURL(initializer.destinationURL)
+{
+}
+
+MediaKeyMessageEvent::~MediaKeyMessageEvent()
+{
+}
+
+const AtomicString& MediaKeyMessageEvent::interfaceName() const
+{
+    return eventNames().interfaceForMediaKeyMessageEvent;
+}
+
+} // namespace WebCore
+
+#endif
diff --git a/Source/WebCore/Modules/encryptedmedia/MediaKeyMessageEvent.h b/Source/WebCore/Modules/encryptedmedia/MediaKeyMessageEvent.h
new file mode 100644 (file)
index 0000000..666f9b4
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2012 Google Inc.  All rights reserved.
+ * Copyright (C) 2013 Apple Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#ifndef MediaKeyMessageEvent_h
+#define MediaKeyMessageEvent_h
+
+#if ENABLE(ENCRYPTED_MEDIA_V2)
+
+#include "Event.h"
+#include "MediaKeyError.h"
+
+namespace WebCore {
+
+struct MediaKeyMessageEventInit : public EventInit {
+    MediaKeyMessageEventInit();
+
+    RefPtr<Uint8Array> message;
+    String destinationURL;
+};
+
+class MediaKeyMessageEvent : public Event {
+public:
+    virtual ~MediaKeyMessageEvent();
+
+    static PassRefPtr<MediaKeyMessageEvent> create()
+    {
+        return adoptRef(new MediaKeyMessageEvent);
+    }
+
+    static PassRefPtr<MediaKeyMessageEvent> create(const AtomicString& type, const MediaKeyMessageEventInit& initializer)
+    {
+        return adoptRef(new MediaKeyMessageEvent(type, initializer));
+    }
+
+    virtual const AtomicString& interfaceName() const OVERRIDE;
+
+    Uint8Array* message() const { return m_message.get(); }
+    String destinationURL() const { return m_destinationURL; }
+
+private:
+    MediaKeyMessageEvent();
+    MediaKeyMessageEvent(const AtomicString& type, const MediaKeyMessageEventInit& initializer);
+
+    RefPtr<Uint8Array> m_message;
+    String m_destinationURL;
+};
+
+} // namespace WebCore
+
+#endif
+#endif
diff --git a/Source/WebCore/Modules/encryptedmedia/MediaKeyMessageEvent.idl b/Source/WebCore/Modules/encryptedmedia/MediaKeyMessageEvent.idl
new file mode 100644 (file)
index 0000000..d76b091
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2012 Google Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+interface [
+    Conditional=ENCRYPTED_MEDIA_V2,
+    V8EnabledAtRuntime=encryptedMedia,
+    ConstructorTemplate=Event 
+] MediaKeyMessageEvent : Event {
+    readonly attribute Uint8Array message;
+    readonly attribute [InitializedByEventConstructor] DOMString destinationURL;
+};
+
diff --git a/Source/WebCore/Modules/encryptedmedia/MediaKeyNeededEvent.cpp b/Source/WebCore/Modules/encryptedmedia/MediaKeyNeededEvent.cpp
new file mode 100644 (file)
index 0000000..5e06f8d
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2012 Google Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#include "config.h"
+
+#if ENABLE(ENCRYPTED_MEDIA_V2)
+
+#include "MediaKeyNeededEvent.h"
+
+#include "EventNames.h"
+#include <wtf/Uint8Array.h>
+
+namespace WebCore {
+
+MediaKeyNeededEventInit::MediaKeyNeededEventInit()
+{
+}
+
+MediaKeyNeededEvent::MediaKeyNeededEvent()
+{
+}
+
+MediaKeyNeededEvent::MediaKeyNeededEvent(const AtomicString& type, const MediaKeyNeededEventInit& initializer)
+    : Event(type, initializer)
+    , m_initData(initializer.initData)
+{
+}
+
+MediaKeyNeededEvent::~MediaKeyNeededEvent()
+{
+}
+
+const AtomicString& MediaKeyNeededEvent::interfaceName() const
+{
+    return eventNames().interfaceForMediaKeyNeededEvent;
+}
+
+} // namespace WebCore
+
+#endif
diff --git a/Source/WebCore/Modules/encryptedmedia/MediaKeyNeededEvent.h b/Source/WebCore/Modules/encryptedmedia/MediaKeyNeededEvent.h
new file mode 100644 (file)
index 0000000..5f698ab
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2012 Google Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#ifndef MediaKeyNeededEvent_h
+#define MediaKeyNeededEvent_h
+
+#if ENABLE(ENCRYPTED_MEDIA_V2)
+
+#include "Event.h"
+#include "MediaKeyError.h"
+
+namespace WebCore {
+
+struct MediaKeyNeededEventInit : public EventInit {
+    MediaKeyNeededEventInit();
+
+    RefPtr<Uint8Array> initData;
+};
+
+class MediaKeyNeededEvent : public Event {
+public:
+    virtual ~MediaKeyNeededEvent();
+
+    static PassRefPtr<MediaKeyNeededEvent> create()
+    {
+        return adoptRef(new MediaKeyNeededEvent);
+    }
+
+    static PassRefPtr<MediaKeyNeededEvent> create(const AtomicString& type, const MediaKeyNeededEventInit& initializer)
+    {
+        return adoptRef(new MediaKeyNeededEvent(type, initializer));
+    }
+
+    virtual const AtomicString& interfaceName() const OVERRIDE;
+
+    Uint8Array* initData() const { return m_initData.get(); }
+
+private:
+    MediaKeyNeededEvent();
+    MediaKeyNeededEvent(const AtomicString& type, const MediaKeyNeededEventInit& initializer);
+
+    RefPtr<Uint8Array> m_initData;
+};
+
+} // namespace WebCore
+
+#endif
+#endif
diff --git a/Source/WebCore/Modules/encryptedmedia/MediaKeyNeededEvent.idl b/Source/WebCore/Modules/encryptedmedia/MediaKeyNeededEvent.idl
new file mode 100644 (file)
index 0000000..b3d407b
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2012 Google Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+interface [
+    Conditional=ENCRYPTED_MEDIA_V2,
+    V8EnabledAtRuntime=encryptedMedia,
+    ConstructorTemplate=Event 
+] MediaKeyNeededEvent : Event {
+    readonly attribute Uint8Array initData;
+};
+
diff --git a/Source/WebCore/Modules/encryptedmedia/MediaKeySession.cpp b/Source/WebCore/Modules/encryptedmedia/MediaKeySession.cpp
new file mode 100644 (file)
index 0000000..55a134e
--- /dev/null
@@ -0,0 +1,234 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "MediaKeySession.h"
+
+#if ENABLE(ENCRYPTED_MEDIA_V2)
+
+#include "CDM.h"
+#include "Event.h"
+#include "GenericEventQueue.h"
+#include "MediaKeyError.h"
+#include "MediaKeyMessageEvent.h"
+#include "MediaKeys.h"
+
+namespace WebCore {
+
+PassRefPtr<MediaKeySession> MediaKeySession::create(ScriptExecutionContext* context, MediaKeys* keys, const String& keySystem)
+{
+    return adoptRef(new MediaKeySession(context, keys, keySystem));
+}
+
+MediaKeySession::MediaKeySession(ScriptExecutionContext* context, MediaKeys* keys, const String& keySystem)
+    : ContextDestructionObserver(context)
+    , m_keys(keys)
+    , m_keySystem(keySystem)
+    , m_asyncEventQueue(GenericEventQueue::create(this))
+    , m_session(keys->cdm()->createSession())
+    , m_keyRequestTimer(this, &MediaKeySession::keyRequestTimerFired)
+    , m_addKeyTimer(this, &MediaKeySession::addKeyTimerFired)
+{
+}
+
+MediaKeySession::~MediaKeySession()
+{
+    close();
+}
+
+void MediaKeySession::setError(MediaKeyError* error)
+{
+    m_error = error;
+}
+
+void MediaKeySession::close()
+{
+    if (m_session)
+        m_session->releaseKeys();
+    m_session = 0;
+    m_asyncEventQueue->cancelAllEvents();
+}
+
+const String& MediaKeySession::sessionId() const
+{
+    return m_session->sessionId();
+}
+
+void MediaKeySession::generateKeyRequest(const String& mimeType, Uint8Array* initData)
+{
+    m_pendingKeyRequests.append(PendingKeyRequest(mimeType, initData));
+    m_keyRequestTimer.startOneShot(0);
+}
+
+void MediaKeySession::keyRequestTimerFired(Timer<MediaKeySession>*)
+{
+    ASSERT(m_pendingKeyRequests.size());
+    if (!m_session)
+        return;
+
+    while (!m_pendingKeyRequests.isEmpty()) {
+        PendingKeyRequest request = m_pendingKeyRequests.takeFirst();
+
+        // NOTE: Continued from step 5 in MediaKeys::createSession().
+        // The user agent will asynchronously execute the following steps in the task:
+
+        // 1. Let cdm be the cdm loaded in the MediaKeys constructor.
+        // 2. Let destinationURL be null.
+        String destinationURL;
+        MediaKeyError::Code errorCode = 0;
+        unsigned long systemCode = 0;
+
+        // 3. Use cdm to generate a key request and follow the steps for the first matching condition from the following list:
+
+        RefPtr<Uint8Array> keyRequest = m_session->generateKeyRequest(request.mimeType, request.initData.get(), destinationURL, errorCode, systemCode);
+
+        // Otherwise [if a request is not successfully generated]:
+        if (!keyRequest) {
+            // 3.1. Create a new MediaKeyError object with the following attributes:
+            //      code = the appropriate MediaKeyError code
+            //      systemCode = a Key System-specific value, if provided, and 0 otherwise
+            RefPtr<MediaKeyError> error = MediaKeyError::create(errorCode, systemCode).get();
+
+            // 3.2. Set the MediaKeySession object's error attribute to the error object created in the previous step.
+            setError(error.get());
+
+            // 3.3. queue a task to fire a simple event named keyerror at the MediaKeySession object.
+            RefPtr<Event> event = Event::create(eventNames().webkitkeyerrorEvent, false, false);
+            event->setTarget(this);
+            m_asyncEventQueue->enqueueEvent(event.release());
+
+            // 3.4. Abort the task.
+            continue;
+        }
+
+        // 4. queue a task to fire a simple event named keymessage at the new object
+        //    The event is of type MediaKeyMessageEvent and has:
+        //    message = key request
+        //    destinationURL = destinationURL
+        MediaKeyMessageEventInit init;
+        init.bubbles = false;
+        init.cancelable = false;
+        init.message = keyRequest;
+        init.destinationURL = destinationURL;
+        RefPtr<MediaKeyMessageEvent> event = MediaKeyMessageEvent::create(eventNames().webkitkeymessageEvent, init);
+        event->setTarget(this);
+        m_asyncEventQueue->enqueueEvent(event);
+    }
+}
+
+void MediaKeySession::addKey(Uint8Array* key, ExceptionCode& ec)
+{
+    // From <http://dvcs.w3.org/hg/html-media/raw-file/tip/encrypted-media/encrypted-media.html#dom-addkey>:
+    // The addKey(key) method must run the following steps:
+    // 1. If the first or second argument [sic] is null or an empty array, throw an INVALID_ACCESS_ERR.
+    // NOTE: the reference to a "second argument" is a spec bug.
+    if (!key || !key->length()) {
+        ec = INVALID_ACCESS_ERR;
+        return;
+    }
+
+    // 2. Schedule a task to handle the call, providing key.
+    m_pendingKeys.append(key);
+    m_addKeyTimer.startOneShot(0);
+}
+
+void MediaKeySession::addKeyTimerFired(Timer<MediaKeySession>*)
+{
+    ASSERT(m_pendingKeys.size());
+    if (!m_session)
+        return;
+
+    while (!m_pendingKeys.isEmpty()) {
+        RefPtr<Uint8Array> pendingKey = m_pendingKeys.takeFirst();
+        unsigned short errorCode = 0;
+        unsigned long systemCode = 0;
+
+        // NOTE: Continued from step 2. of MediaKeySession::addKey()
+        // 2.1. Let cdm be the cdm loaded in the MediaKeys constructor.
+        // NOTE: This is m_session.
+        // 2.2. Let 'did store key' be false.
+        bool didStoreKey = false;
+        // 2.3. Let 'next message' be null.
+        RefPtr<Uint8Array> nextMessage;
+        // 2.4. Use cdm to handle key.
+        didStoreKey = m_session->addKey(pendingKey.get(), nextMessage, errorCode, systemCode);
+        // 2.5. If did store key is true and the media element is waiting for a key, queue a task to attempt to resume playback.
+        // TODO: Find and restart the media element
+
+        // 2.6. If next message is not null, queue a task to fire a simple event named keymessage at the MediaKeySession object.
+        //      The event is of type MediaKeyMessageEvent and has:
+        //      message = next message
+        //      destinationURL = null
+        if (nextMessage) {
+            MediaKeyMessageEventInit init;
+            init.bubbles = false;
+            init.cancelable = false;
+            init.message = nextMessage;
+            RefPtr<MediaKeyMessageEvent> event = MediaKeyMessageEvent::create(eventNames().webkitkeymessageEvent, init);
+            event->setTarget(this);
+            m_asyncEventQueue->enqueueEvent(event);
+        }
+
+        // 2.7. If did store key is true, queue a task to fire a simple event named keyadded at the MediaKeySession object.
+        if (didStoreKey) {
+            RefPtr<Event> keyaddedEvent = Event::create(eventNames().webkitkeyaddedEvent, false, false);
+            keyaddedEvent->setTarget(this);
+            m_asyncEventQueue->enqueueEvent(keyaddedEvent);
+        }
+
+        // 2.8. If any of the preceding steps in the task failed
+        if (!didStoreKey) {
+            // 2.8.1. Create a new MediaKeyError object with the following attributes:
+            //        code = the appropriate MediaKeyError code
+            //        systemCode = a Key System-specific value, if provided, and 0 otherwise
+            RefPtr<MediaKeyError> error = MediaKeyError::create(errorCode, systemCode).get();
+
+            // 2.8.2. Set the MediaKeySession object's error attribute to the error object created in the previous step.
+            setError(error.get());
+
+            // 2.8.3. queue a task to fire a simple event named keyerror at the MediaKeySession object.
+            RefPtr<Event> keyerrorEvent = Event::create(eventNames().webkitkeyerrorEvent, false, false);
+            keyerrorEvent->setTarget(this);
+            m_asyncEventQueue->enqueueEvent(keyerrorEvent.release());
+            
+            // 2.8.4. Abort the task.
+            // NOTE: no-op
+        }
+    }
+}
+
+const AtomicString& MediaKeySession::interfaceName() const
+{
+    return eventNames().interfaceForMediaKeySession;
+}
+
+ScriptExecutionContext* MediaKeySession::scriptExecutionContext() const
+{
+    return ContextDestructionObserver::scriptExecutionContext();
+}
+
+}
+
+#endif
diff --git a/Source/WebCore/Modules/encryptedmedia/MediaKeySession.h b/Source/WebCore/Modules/encryptedmedia/MediaKeySession.h
new file mode 100644 (file)
index 0000000..7443bdc
--- /dev/null
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef MediaKeySession_h
+#define MediaKeySession_h
+
+#if ENABLE(ENCRYPTED_MEDIA_V2)
+
+#include "ContextDestructionObserver.h"
+#include "EventTarget.h"
+#include "ExceptionCode.h"
+#include "Timer.h"
+#include <wtf/Deque.h>
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefCounted.h>
+#include <wtf/Uint8Array.h>
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+class GenericEventQueue;
+class MediaKeyError;
+class MediaKeys;
+class CDMSession;
+
+class MediaKeySession : public RefCounted<MediaKeySession>, public EventTarget, public ContextDestructionObserver {
+public:
+    static PassRefPtr<MediaKeySession> create(ScriptExecutionContext*, MediaKeys*, const String& keySystem);
+    ~MediaKeySession();
+
+    const String& keySystem() const { return m_keySystem; }
+    const String& sessionId() const;
+
+    void setError(MediaKeyError*);
+    MediaKeyError* error() { return m_error.get(); }
+
+    void setKeys(MediaKeys* keys) { m_keys = keys; }
+    MediaKeys* keys() const { return m_keys; }
+
+    void generateKeyRequest(const String& mimeType, Uint8Array* initData);
+    void addKey(Uint8Array* key, ExceptionCode&);
+    void close();
+
+    using RefCounted<MediaKeySession>::ref;
+    using RefCounted<MediaKeySession>::deref;
+
+    void enqueueEvent(PassRefPtr<Event>);
+
+    DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitkeyadded);
+    DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitkeyerror);
+    DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitkeymessage);
+
+    virtual const AtomicString& interfaceName() const OVERRIDE;
+    virtual ScriptExecutionContext* scriptExecutionContext() const OVERRIDE;
+
+protected:
+    MediaKeySession(ScriptExecutionContext*, MediaKeys*, const String& keySystem);
+    void keyRequestTimerFired(Timer<MediaKeySession>*);
+    void addKeyTimerFired(Timer<MediaKeySession>*);
+
+    MediaKeys* m_keys;
+    String m_keySystem;
+    String m_sessionId;
+    RefPtr<MediaKeyError> m_error;
+    OwnPtr<GenericEventQueue> m_asyncEventQueue;
+    OwnPtr<CDMSession> m_session;
+
+    struct PendingKeyRequest {
+        PendingKeyRequest(const String& mimeType, Uint8Array* initData) : mimeType(mimeType), initData(initData) { }
+        String mimeType;
+        RefPtr<Uint8Array> initData;
+    };
+    Deque<PendingKeyRequest> m_pendingKeyRequests;
+    Timer<MediaKeySession> m_keyRequestTimer;
+
+    Deque<RefPtr<Uint8Array> > m_pendingKeys;
+    Timer<MediaKeySession> m_addKeyTimer;
+
+private:
+    virtual void refEventTarget() OVERRIDE { ref(); }
+    virtual void derefEventTarget() OVERRIDE { deref(); }
+
+    virtual EventTargetData* eventTargetData() OVERRIDE { return &m_eventTargetData; }
+    virtual EventTargetData* ensureEventTargetData() OVERRIDE { return &m_eventTargetData; }
+
+    EventTargetData m_eventTargetData;
+};
+
+}
+
+#endif // ENABLE(ENCRYPTED_MEDIA_V2)
+
+#endif // MediaKeySession_h
diff --git a/Source/WebCore/Modules/encryptedmedia/MediaKeySession.idl b/Source/WebCore/Modules/encryptedmedia/MediaKeySession.idl
new file mode 100644 (file)
index 0000000..e3e79d7
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2013 Apple Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+     */
+
+interface [
+    Conditional=ENCRYPTED_MEDIA_V2,
+    V8EnabledAtRuntime=encryptedMedia,
+    EventTarget,
+] MediaKeySession {
+    // error state
+    readonly attribute MediaKeyError error;
+
+    // session properties
+    readonly attribute DOMString keySystem;
+    readonly attribute DOMString sessionId;
+
+    // session operations
+    void addKey(in Uint8Array key)
+        raises(DOMException);
+    void close();
+    
+    // EventListeners
+    attribute [V8EnabledAtRuntime=encryptedMedia] EventListener onwebkitkeyadded;
+    attribute [V8EnabledAtRuntime=encryptedMedia] EventListener onwebkitkeyerror;
+    attribute [V8EnabledAtRuntime=encryptedMedia] EventListener onwebkitkeymessage;
+
+    // EventTarget interface
+    void addEventListener(in DOMString type, 
+                          in EventListener listener, 
+                          in [Optional] boolean useCapture);
+    void removeEventListener(in DOMString type, 
+                             in EventListener listener, 
+                             in [Optional] boolean useCapture);
+    boolean dispatchEvent(in Event evt)
+        raises(EventException);
+};
diff --git a/Source/WebCore/Modules/encryptedmedia/MediaKeys.cpp b/Source/WebCore/Modules/encryptedmedia/MediaKeys.cpp
new file mode 100644 (file)
index 0000000..7c06a58
--- /dev/null
@@ -0,0 +1,120 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "MediaKeys.h"
+
+#if ENABLE(ENCRYPTED_MEDIA_V2)
+
+#include "CDM.h"
+#include "EventNames.h"
+#include "MediaKeyMessageEvent.h"
+#include "MediaKeySession.h"
+#include "UUID.h"
+#include <wtf/HashSet.h>
+
+namespace WebCore {
+
+PassRefPtr<MediaKeys> MediaKeys::create(const String& keySystem, ExceptionCode& ec)
+{
+    // From <http://dvcs.w3.org/hg/html-media/raw-file/tip/encrypted-media/encrypted-media.html#dom-media-keys-constructor>:
+    // The MediaKeys(keySystem) constructor must run the following steps:
+
+    // 1. If keySystem is null or an empty string, throw an INVALID_ACCESS_ERR exception and abort these steps.
+    if (keySystem.isNull() || keySystem.isEmpty()) {
+        ec = INVALID_ACCESS_ERR;
+        return 0;
+    }
+
+    // 2. If keySystem is not one of the user agent's supported Key Systems, throw a NOT_SUPPORTED_ERR and abort these steps.
+    if (!CDM::supportsKeySystem(keySystem)) {
+        ec = NOT_SUPPORTED_ERR;
+        return 0;
+    }
+
+    // 3. Let cdm be the content decryption module corresponding to keySystem.
+    // 4. Load cdm if necessary.
+    OwnPtr<CDM> cdm = CDM::create(keySystem);
+
+    // 5. Create a new MediaKeys object.
+    // 5.1 Let the keySystem attribute be keySystem.
+    // 6. Return the new object to the caller.
+    return adoptRef(new MediaKeys(keySystem, cdm.release()));
+}
+
+MediaKeys::MediaKeys(const String& keySystem, PassOwnPtr<CDM> cdm)
+    : m_keySystem(keySystem)
+    , m_cdm(cdm)
+{
+}
+
+MediaKeys::~MediaKeys()
+{
+    // From <http://dvcs.w3.org/hg/html-media/raw-file/tip/encrypted-media/encrypted-media.html#dom-media-keys-constructor>:
+    // When destroying a MediaKeys object, follow the steps in close().
+    for (size_t i = 0; i < m_sessions.size(); ++i) {
+        m_sessions[i]->close();
+        m_sessions[i]->setKeys(0);
+    }
+}
+
+PassRefPtr<MediaKeySession> MediaKeys::createSession(ScriptExecutionContext* context, const String& type, Uint8Array* initData, ExceptionCode& ec)
+{
+    // From <http://dvcs.w3.org/hg/html-media/raw-file/tip/encrypted-media/encrypted-media.html#dom-createsession>:
+    // The createSession(type, initData) method must run the following steps:
+    // Note: The contents of initData are container-specific Initialization Data.
+
+    // 1. If type is null or an empty string and initData is not null or an empty string, throw an
+    // INVALID_ACCESS_ERR exception and abort these steps.
+    if ((type.isNull() || type.isEmpty()) && (!initData || initData->length())) {
+        ec = INVALID_ACCESS_ERR;
+        return 0;
+    }
+
+    // 2. If type contains a MIME type that is not supported or is not supported by the keySystem, throw
+    // a NOT_SUPPORTED_ERR exception and abort these steps.
+    if (!type.isNull() && !type.isEmpty() && !m_cdm->supportsMIMEType(type)) {
+        ec = NOT_SUPPORTED_ERR;
+        return 0;
+    }
+
+    // 3. Create a new MediaKeySession object.
+    // 3.1 Let the keySystem attribute be keySystem.
+    // 3.2 Let the sessionId attribute be a unique Session ID string. It may be generated by cdm.
+    RefPtr<MediaKeySession> session = MediaKeySession::create(context, this, keySystem());
+
+    // 4. Add the new object to an internal list of session objects.
+    m_sessions.append(session);
+
+    // 5. Schedule a task to generate a key request, providing type, initData, and the new object.
+    session->generateKeyRequest(type, initData);
+
+    // 6. Return the new object to the caller.
+    return session;
+}
+
+}
+
+#endif
diff --git a/Source/WebCore/Modules/encryptedmedia/MediaKeys.h b/Source/WebCore/Modules/encryptedmedia/MediaKeys.h
new file mode 100644 (file)
index 0000000..a870083
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef MediaKeys_h
+#define MediaKeys_h
+
+#if ENABLE(ENCRYPTED_MEDIA_V2)
+
+#include "EventTarget.h"
+#include "ExceptionCode.h"
+#include <wtf/OwnPtr.h>
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefCounted.h>
+#include <wtf/Uint8Array.h>
+#include <wtf/Vector.h>
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+class CDM;
+class MediaKeySession;
+
+class MediaKeys : public RefCounted<MediaKeys> {
+public:
+    static PassRefPtr<MediaKeys> create(const String& keySystem, ExceptionCode&);
+    ~MediaKeys();
+
+    PassRefPtr<MediaKeySession> createSession(ScriptExecutionContext*, const String& mimeType, Uint8Array* initData, ExceptionCode&);
+
+    const String& keySystem() const { return m_keySystem; }
+    CDM* cdm() { return m_cdm.get(); }
+
+protected:
+    MediaKeys(const String& keySystem, PassOwnPtr<CDM>);
+
+    Vector<RefPtr<MediaKeySession> > m_sessions;
+
+    String m_keySystem;
+    OwnPtr<CDM> m_cdm;
+};
+
+}
+
+#endif // ENABLE(ENCRYPTED_MEDIA_V2)
+
+#endif // MediaKeys_h
diff --git a/Source/WebCore/Modules/encryptedmedia/MediaKeys.idl b/Source/WebCore/Modules/encryptedmedia/MediaKeys.idl
new file mode 100644 (file)
index 0000000..773501a
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2013 Apple Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+interface [
+    Conditional=ENCRYPTED_MEDIA_V2,
+    V8EnabledAtRuntime=encryptedMedia,
+    Constructor(in DOMString keySystem),
+    ConstructorRaisesException,
+] MediaKeys {
+    [CallWith=ScriptExecutionContext] MediaKeySession createSession(in [Optional=DefaultIsUndefined] DOMString type, in [Optional=DefaultIsUndefined] Uint8Array initData)
+        raises(DOMException);
+
+    readonly attribute DOMString keySystem;
+};
index 2c3ef93..e74521d 100644 (file)
@@ -2751,3 +2751,7 @@ __ZN7WebCore22RuntimeEnabledFeatures19isCSSRegionsEnabledE
 #if ENABLE(IFRAME_SEAMLESS)
 __ZN7WebCore22RuntimeEnabledFeatures25areSeamlessIFramesEnabledE
 #endif
+
+#if ENABLE(ENCRYPTED_MEDIA_V2)
+__ZN7WebCore3CDM18registerCDMFactoryEPFN3WTF10PassOwnPtrINS_19CDMPrivateInterfaceEEEPS0_EPFbRKNS1_6StringEE
+#endif
index 40f986f..48f6cae 100644 (file)
                4B6FA6F40C39E48C00087011 /* SmartReplace.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B6FA6F20C39E48C00087011 /* SmartReplace.h */; settings = {ATTRIBUTES = (Private, ); }; };
                4B6FA6F50C39E48C00087011 /* SmartReplace.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B6FA6F30C39E48C00087011 /* SmartReplace.cpp */; };
                4B6FA6F70C39E4A100087011 /* SmartReplaceCF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B6FA6F60C39E4A100087011 /* SmartReplaceCF.cpp */; };
-               4B61737379636F616E277368 /* IDBHistograms.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B61737379636F616E277368 /* IDBHistograms.h */; };
                4B8AF4AA0B1CE02B00687690 /* ClipboardAccessPolicy.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B8AF4A90B1CE02B00687690 /* ClipboardAccessPolicy.h */; settings = {ATTRIBUTES = (Private, ); }; };
                4BAE95B10B2FA9CE00AED8A0 /* EditorDeleteAction.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BAE95B00B2FA9CE00AED8A0 /* EditorDeleteAction.h */; settings = {ATTRIBUTES = (Private, ); }; };
                4D273CF91669420800259CA1 /* InspectorInputAgent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4D273CF71669420800259CA1 /* InspectorInputAgent.cpp */; };
                977E2DCD12F0E28300C13379 /* HTMLSourceTracker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 977E2DCB12F0E28300C13379 /* HTMLSourceTracker.cpp */; };
                977E2DCE12F0E28300C13379 /* HTMLSourceTracker.h in Headers */ = {isa = PBXBuildFile; fileRef = 977E2DCC12F0E28300C13379 /* HTMLSourceTracker.h */; };
                977E2E0E12F0FC9C00C13379 /* XSSAuditor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 977E2E0B12F0FC9C00C13379 /* XSSAuditor.cpp */; };
-               977E2E0F12F0FC9C00C13379 /* XSSAuditor.h in Headers */ = {isa = PBXBuildFile; fileRef = 977E2E0C12F0FC9C00C13379 /* XSSAuditor.h */; };
                977E2E0E12F0FC9C00C13380 /* XSSAuditorDelegate.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 977E2E0B12F0FC9C00C13380 /* XSSAuditorDelegate.cpp */; };
+               977E2E0F12F0FC9C00C13379 /* XSSAuditor.h in Headers */ = {isa = PBXBuildFile; fileRef = 977E2E0C12F0FC9C00C13379 /* XSSAuditor.h */; };
                977E2E0F12F0FC9C00C13380 /* XSSAuditorDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 977E2E0C12F0FC9C00C13380 /* XSSAuditorDelegate.h */; };
                978AD67414130A8D00C7CAE3 /* HTMLSpanElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 978AD67114130A8D00C7CAE3 /* HTMLSpanElement.cpp */; };
                978AD67514130A8D00C7CAE3 /* HTMLSpanElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 978AD67214130A8D00C7CAE3 /* HTMLSpanElement.h */; };
                CCC2B51615F613060048CDD6 /* DeviceController.h in Headers */ = {isa = PBXBuildFile; fileRef = CCC2B51215F613060048CDD6 /* DeviceController.h */; settings = {ATTRIBUTES = (Private, ); }; };
                CD127DED14F3097D00E84779 /* WebCoreFullScreenWindow.mm in Sources */ = {isa = PBXBuildFile; fileRef = CD127DEB14F3097900E84779 /* WebCoreFullScreenWindow.mm */; };
                CD127DEE14F3098400E84779 /* WebCoreFullScreenWindow.h in Headers */ = {isa = PBXBuildFile; fileRef = CD127DEA14F3097900E84779 /* WebCoreFullScreenWindow.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               CD1B4A65160786AE00282DF9 /* MediaKeyNeededEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDA98DC216014EEE00FEA3B1 /* MediaKeyNeededEvent.cpp */; };
                CD1E7347167BC78E009A885D /* TextTrackRepresentation.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD1E7346167BC78E009A885D /* TextTrackRepresentation.cpp */; };
                CD27F6E51457685A0078207D /* JSMediaController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD27F6E2145767580078207D /* JSMediaController.cpp */; };
                CD27F6E7145770D30078207D /* MediaController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD27F6E6145770D30078207D /* MediaController.cpp */; };
                CD82030D1395AB6A00F956C6 /* WebVideoFullscreenHUDWindowController.mm in Sources */ = {isa = PBXBuildFile; fileRef = CD8203091395AB6A00F956C6 /* WebVideoFullscreenHUDWindowController.mm */; };
                CD8203101395ACE700F956C6 /* WebWindowAnimation.h in Headers */ = {isa = PBXBuildFile; fileRef = CD82030E1395ACE700F956C6 /* WebWindowAnimation.h */; settings = {ATTRIBUTES = (Private, ); }; };
                CD8203111395ACE700F956C6 /* WebWindowAnimation.mm in Sources */ = {isa = PBXBuildFile; fileRef = CD82030F1395ACE700F956C6 /* WebWindowAnimation.mm */; };
+               CDA98DA31601464100FEA3B1 /* JSMediaKeyError.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDA98D9B160128A500FEA3B1 /* JSMediaKeyError.cpp */; };
+               CDA98DD816025BEF00FEA3B1 /* MediaKeyMessageEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDA98DD516025BED00FEA3B1 /* MediaKeyMessageEvent.cpp */; };
+               CDA98DDF16026A3700FEA3B1 /* JSMediaKeyMessageEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDA98DDB16026A1800FEA3B1 /* JSMediaKeyMessageEvent.cpp */; };
+               CDA98DE016026A3700FEA3B1 /* JSMediaKeyNeededEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDA98DDD16026A1900FEA3B1 /* JSMediaKeyNeededEvent.cpp */; };
+               CDA98E0416039E1A00FEA3B1 /* JSMediaKeys.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDA98DCE1601597900FEA3B1 /* JSMediaKeys.cpp */; };
+               CDA98E0616039E1F00FEA3B1 /* JSMediaKeySession.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDA98DD01601597900FEA3B1 /* JSMediaKeySession.cpp */; };
+               CDA98E0B1603CD6000FEA3B1 /* CDM.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDA98E091603CD5900FEA3B1 /* CDM.cpp */; };
+               CDA98E0D1603FE4A00FEA3B1 /* MediaKeys.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDA98DCA1601508A00FEA3B1 /* MediaKeys.cpp */; };
+               CDA98E0E1603FE5800FEA3B1 /* MediaKeySession.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDA98DC716014F2C00FEA3B1 /* MediaKeySession.cpp */; };
                CDAA8D0A14D71B2E0061EA60 /* PlatformClockCM.mm in Sources */ = {isa = PBXBuildFile; fileRef = CDAA8D0814D385600061EA60 /* PlatformClockCM.mm */; };
                CDB859F7160D48A400E5B07F /* MediaKeyEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDB859F4160D489900E5B07F /* MediaKeyEvent.cpp */; };
                CDB859FA160D494900E5B07F /* JSMediaKeyEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDB859F8160D493E00E5B07F /* JSMediaKeyEvent.cpp */; };
-               CDB859FB160D494F00E5B07F /* JSMediaKeyError.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDB859F0160D42DD00E5B07F /* JSMediaKeyError.cpp */; };
+               CDC26B40160A8CC60026757B /* MockCDM.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDC26B3C160A62B00026757B /* MockCDM.cpp */; };
+               CDC26B41160A8CCE0026757B /* MockCDM.h in Headers */ = {isa = PBXBuildFile; fileRef = CDC26B3D160A62B00026757B /* MockCDM.h */; };
                CDC69DD61632026C007C38DF /* WebCoreFullScreenWarningView.h in Headers */ = {isa = PBXBuildFile; fileRef = CDC69DD41632026C007C38DF /* WebCoreFullScreenWarningView.h */; settings = {ATTRIBUTES = (Private, ); }; };
                CDC69DD71632026C007C38DF /* WebCoreFullScreenWarningView.mm in Sources */ = {isa = PBXBuildFile; fileRef = CDC69DD51632026C007C38DF /* WebCoreFullScreenWarningView.mm */; };
                CDC69DDA16371FD4007C38DF /* WebCoreFullScreenPlaceholderView.h in Headers */ = {isa = PBXBuildFile; fileRef = CDC69DD816371FD3007C38DF /* WebCoreFullScreenPlaceholderView.h */; settings = {ATTRIBUTES = (Private, ); }; };
                977E2DCB12F0E28300C13379 /* HTMLSourceTracker.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = HTMLSourceTracker.cpp; path = parser/HTMLSourceTracker.cpp; sourceTree = "<group>"; };
                977E2DCC12F0E28300C13379 /* HTMLSourceTracker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = HTMLSourceTracker.h; path = parser/HTMLSourceTracker.h; sourceTree = "<group>"; };
                977E2E0B12F0FC9C00C13379 /* XSSAuditor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = XSSAuditor.cpp; path = parser/XSSAuditor.cpp; sourceTree = "<group>"; };
-               977E2E0C12F0FC9C00C13379 /* XSSAuditor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = XSSAuditor.h; path = parser/XSSAuditor.h; sourceTree = "<group>"; };
                977E2E0B12F0FC9C00C13380 /* XSSAuditorDelegate.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = XSSAuditorDelegate.cpp; path = parser/XSSAuditorDelegate.cpp; sourceTree = "<group>"; };
+               977E2E0C12F0FC9C00C13379 /* XSSAuditor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = XSSAuditor.h; path = parser/XSSAuditor.h; sourceTree = "<group>"; };
                977E2E0C12F0FC9C00C13380 /* XSSAuditorDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = XSSAuditorDelegate.h; path = parser/XSSAuditorDelegate.h; sourceTree = "<group>"; };
                978AD67114130A8D00C7CAE3 /* HTMLSpanElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HTMLSpanElement.cpp; sourceTree = "<group>"; };
                978AD67214130A8D00C7CAE3 /* HTMLSpanElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HTMLSpanElement.h; sourceTree = "<group>"; };
                CD8203091395AB6A00F956C6 /* WebVideoFullscreenHUDWindowController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebVideoFullscreenHUDWindowController.mm; sourceTree = "<group>"; };
                CD82030E1395ACE700F956C6 /* WebWindowAnimation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebWindowAnimation.h; sourceTree = "<group>"; };
                CD82030F1395ACE700F956C6 /* WebWindowAnimation.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebWindowAnimation.mm; sourceTree = "<group>"; };
+               CDA98D9B160128A500FEA3B1 /* JSMediaKeyError.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSMediaKeyError.cpp; sourceTree = "<group>"; };
+               CDA98D9C160128A500FEA3B1 /* JSMediaKeyError.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSMediaKeyError.h; sourceTree = "<group>"; };
+               CDA98DC216014EEE00FEA3B1 /* MediaKeyNeededEvent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = MediaKeyNeededEvent.cpp; path = Modules/encryptedmedia/MediaKeyNeededEvent.cpp; sourceTree = "<group>"; };
+               CDA98DC316014EEE00FEA3B1 /* MediaKeyNeededEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MediaKeyNeededEvent.h; path = Modules/encryptedmedia/MediaKeyNeededEvent.h; sourceTree = "<group>"; };
+               CDA98DC416014EEE00FEA3B1 /* MediaKeyNeededEvent.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = MediaKeyNeededEvent.idl; path = Modules/encryptedmedia/MediaKeyNeededEvent.idl; sourceTree = "<group>"; };
+               CDA98DC716014F2C00FEA3B1 /* MediaKeySession.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = MediaKeySession.cpp; path = Modules/encryptedmedia/MediaKeySession.cpp; sourceTree = "<group>"; };
+               CDA98DC816014F2C00FEA3B1 /* MediaKeySession.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MediaKeySession.h; path = Modules/encryptedmedia/MediaKeySession.h; sourceTree = "<group>"; };
+               CDA98DC916014F4000FEA3B1 /* MediaKeySession.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = MediaKeySession.idl; path = Modules/encryptedmedia/MediaKeySession.idl; sourceTree = "<group>"; };
+               CDA98DCA1601508A00FEA3B1 /* MediaKeys.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = MediaKeys.cpp; path = Modules/encryptedmedia/MediaKeys.cpp; sourceTree = "<group>"; };
+               CDA98DCB1601508A00FEA3B1 /* MediaKeys.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MediaKeys.h; path = Modules/encryptedmedia/MediaKeys.h; sourceTree = "<group>"; };
+               CDA98DCC1601508A00FEA3B1 /* MediaKeys.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = MediaKeys.idl; path = Modules/encryptedmedia/MediaKeys.idl; sourceTree = "<group>"; };
+               CDA98DCE1601597900FEA3B1 /* JSMediaKeys.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSMediaKeys.cpp; sourceTree = "<group>"; };
+               CDA98DCF1601597900FEA3B1 /* JSMediaKeys.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSMediaKeys.h; sourceTree = "<group>"; };
+               CDA98DD01601597900FEA3B1 /* JSMediaKeySession.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSMediaKeySession.cpp; sourceTree = "<group>"; };
+               CDA98DD11601597900FEA3B1 /* JSMediaKeySession.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSMediaKeySession.h; sourceTree = "<group>"; };
+               CDA98DD516025BED00FEA3B1 /* MediaKeyMessageEvent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = MediaKeyMessageEvent.cpp; path = Modules/encryptedmedia/MediaKeyMessageEvent.cpp; sourceTree = "<group>"; };
+               CDA98DD616025BED00FEA3B1 /* MediaKeyMessageEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MediaKeyMessageEvent.h; path = Modules/encryptedmedia/MediaKeyMessageEvent.h; sourceTree = "<group>"; };
+               CDA98DD716025BEE00FEA3B1 /* MediaKeyMessageEvent.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = MediaKeyMessageEvent.idl; path = Modules/encryptedmedia/MediaKeyMessageEvent.idl; sourceTree = "<group>"; };
+               CDA98DDB16026A1800FEA3B1 /* JSMediaKeyMessageEvent.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = JSMediaKeyMessageEvent.cpp; sourceTree = "<group>"; };
+               CDA98DDC16026A1900FEA3B1 /* JSMediaKeyMessageEvent.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JSMediaKeyMessageEvent.h; sourceTree = "<group>"; };
+               CDA98DDD16026A1900FEA3B1 /* JSMediaKeyNeededEvent.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = JSMediaKeyNeededEvent.cpp; sourceTree = "<group>"; };
+               CDA98DDE16026A1900FEA3B1 /* JSMediaKeyNeededEvent.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JSMediaKeyNeededEvent.h; sourceTree = "<group>"; };
+               CDA98E091603CD5900FEA3B1 /* CDM.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = CDM.cpp; path = Modules/encryptedmedia/CDM.cpp; sourceTree = "<group>"; };
+               CDA98E0A1603CD5900FEA3B1 /* CDM.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CDM.h; path = Modules/encryptedmedia/CDM.h; sourceTree = "<group>"; };
+               CDA98E0C1603CF3C00FEA3B1 /* Modules/encryptedmedia/CDMPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Modules/encryptedmedia/CDMPrivate.h; sourceTree = "<group>"; };
                CDAA8D0714D385600061EA60 /* PlatformClockCM.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlatformClockCM.h; sourceTree = "<group>"; };
                CDAA8D0814D385600061EA60 /* PlatformClockCM.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PlatformClockCM.mm; sourceTree = "<group>"; };
-               CDB859F0160D42DD00E5B07F /* JSMediaKeyError.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSMediaKeyError.cpp; sourceTree = "<group>"; };
-               CDB859F1160D42DD00E5B07F /* JSMediaKeyError.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSMediaKeyError.h; sourceTree = "<group>"; };
                CDB859F2160D489900E5B07F /* MediaKeyError.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MediaKeyError.h; sourceTree = "<group>"; };
                CDB859F3160D489900E5B07F /* MediaKeyError.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = MediaKeyError.idl; sourceTree = "<group>"; };
                CDB859F4160D489900E5B07F /* MediaKeyEvent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MediaKeyEvent.cpp; sourceTree = "<group>"; };
                CDB859F8160D493E00E5B07F /* JSMediaKeyEvent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSMediaKeyEvent.cpp; sourceTree = "<group>"; };
                CDB859F9160D493E00E5B07F /* JSMediaKeyEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSMediaKeyEvent.h; sourceTree = "<group>"; };
                CDBD93BA1333BD4B002570E3 /* fullscreenQuickTime.css */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.css; path = fullscreenQuickTime.css; sourceTree = "<group>"; };
+               CDC26B3C160A62B00026757B /* MockCDM.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = MockCDM.cpp; sourceTree = "<group>"; };
+               CDC26B3D160A62B00026757B /* MockCDM.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MockCDM.h; sourceTree = "<group>"; };
                CDC69DD41632026C007C38DF /* WebCoreFullScreenWarningView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebCoreFullScreenWarningView.h; sourceTree = "<group>"; };
                CDC69DD51632026C007C38DF /* WebCoreFullScreenWarningView.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebCoreFullScreenWarningView.mm; sourceTree = "<group>"; };
                CDC69DD816371FD3007C38DF /* WebCoreFullScreenPlaceholderView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebCoreFullScreenPlaceholderView.h; sourceTree = "<group>"; };
                14DFB33F0A7DF7630018F769 /* Derived Sources */ = {
                        isa = PBXGroup;
                        children = (
+                               CDA98DCD1601515C00FEA3B1 /* EncryptedMedia */,
                                A83B79100CCB001B000B0825 /* Core */,
                                A83B790E0CCAFF97000B0825 /* CSS */,
                                A83B79120CCB003F000B0825 /* Events */,
                                A7BE7EDE14C9175A0014489D /* MallocStatistics.idl */,
                                EB081CD81696084400553730 /* TypeConversions.h */,
                                EB081CD91696084400553730 /* TypeConversions.idl */,
+                               CDC26B3C160A62B00026757B /* MockCDM.cpp */,
+                               CDC26B3D160A62B00026757B /* MockCDM.h */,
                        );
                        path = testing;
                        sourceTree = "<group>";
                971145FE14EF006E00674FD9 /* Modules */ = {
                        isa = PBXGroup;
                        children = (
+                               CDA98DBD16014E0800FEA3B1 /* encryptedmedia */,
                                971145FF14EF007900674FD9 /* geolocation */,
                                9712A55315004E3C0048AF10 /* indexeddb */,
                                B1A942DD15B5CE2200D525D1 /* mediasource */,
                                CD27F6E3145767580078207D /* JSMediaController.h */,
                                E44614100CD6826900FADA75 /* JSMediaError.cpp */,
                                E44614110CD6826900FADA75 /* JSMediaError.h */,
-                               CDB859F0160D42DD00E5B07F /* JSMediaKeyError.cpp */,
-                               CDB859F1160D42DD00E5B07F /* JSMediaKeyError.h */,
                                CDB859F8160D493E00E5B07F /* JSMediaKeyEvent.cpp */,
                                CDB859F9160D493E00E5B07F /* JSMediaKeyEvent.h */,
                                1059457515B42A0D004D37FD /* JSMicroDataItemValue.cpp */,
                        name = audio;
                        sourceTree = "<group>";
                };
+               CDA98DBD16014E0800FEA3B1 /* encryptedmedia */ = {
+                       isa = PBXGroup;
+                       children = (
+                               CDA98DD516025BED00FEA3B1 /* MediaKeyMessageEvent.cpp */,
+                               CDA98DD616025BED00FEA3B1 /* MediaKeyMessageEvent.h */,
+                               CDA98DD716025BEE00FEA3B1 /* MediaKeyMessageEvent.idl */,
+                               CDA98DC216014EEE00FEA3B1 /* MediaKeyNeededEvent.cpp */,
+                               CDA98DC316014EEE00FEA3B1 /* MediaKeyNeededEvent.h */,
+                               CDA98DC416014EEE00FEA3B1 /* MediaKeyNeededEvent.idl */,
+                               CDA98DCA1601508A00FEA3B1 /* MediaKeys.cpp */,
+                               CDA98DCB1601508A00FEA3B1 /* MediaKeys.h */,
+                               CDA98DCC1601508A00FEA3B1 /* MediaKeys.idl */,
+                               CDA98DC716014F2C00FEA3B1 /* MediaKeySession.cpp */,
+                               CDA98DC816014F2C00FEA3B1 /* MediaKeySession.h */,
+                               CDA98DC916014F4000FEA3B1 /* MediaKeySession.idl */,
+                               CDA98E091603CD5900FEA3B1 /* CDM.cpp */,
+                               CDA98E0A1603CD5900FEA3B1 /* CDM.h */,
+                               CDA98E0C1603CF3C00FEA3B1 /* Modules/encryptedmedia/CDMPrivate.h */,
+                       );
+                       name = encryptedmedia;
+                       sourceTree = "<group>";
+               };
+               CDA98DCD1601515C00FEA3B1 /* EncryptedMedia */ = {
+                       isa = PBXGroup;
+                       children = (
+                               CDA98D9B160128A500FEA3B1 /* JSMediaKeyError.cpp */,
+                               CDA98D9C160128A500FEA3B1 /* JSMediaKeyError.h */,
+                               CDA98DDB16026A1800FEA3B1 /* JSMediaKeyMessageEvent.cpp */,
+                               CDA98DDC16026A1900FEA3B1 /* JSMediaKeyMessageEvent.h */,
+                               CDA98DDD16026A1900FEA3B1 /* JSMediaKeyNeededEvent.cpp */,
+                               CDA98DDE16026A1900FEA3B1 /* JSMediaKeyNeededEvent.h */,
+                               CDA98DCE1601597900FEA3B1 /* JSMediaKeys.cpp */,
+                               CDA98DCF1601597900FEA3B1 /* JSMediaKeys.h */,
+                               CDA98DD01601597900FEA3B1 /* JSMediaKeySession.cpp */,
+                               CDA98DD11601597900FEA3B1 /* JSMediaKeySession.h */,
+                       );
+                       name = EncryptedMedia;
+                       sourceTree = "<group>";
+               };
                DF9AFD6F13FC31B00015FEB7 /* objc */ = {
                        isa = PBXGroup;
                        children = (
                                A740B59514C935AB00A77FA4 /* JSMallocStatistics.h in Headers */,
                                EBF5121D1696496C0056BD25 /* JSTypeConversions.h in Headers */,
                                41815C1F138319830057AAA4 /* WebCoreTestSupport.h in Headers */,
+                               CDC26B41160A8CCE0026757B /* MockCDM.h in Headers */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
                                A740B59714C935AF00A77FA4 /* JSMallocStatistics.cpp in Sources */,
                                EBF5121C1696496C0056BD25 /* JSTypeConversions.cpp in Sources */,
                                41815C1E138319830057AAA4 /* WebCoreTestSupport.cpp in Sources */,
+                               CDC26B40160A8CC60026757B /* MockCDM.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
                                CD27F6E51457685A0078207D /* JSMediaController.cpp in Sources */,
                                FD23A12513F5FA5900F67001 /* JSMediaElementAudioSourceNode.cpp in Sources */,
                                E44614180CD6826900FADA75 /* JSMediaError.cpp in Sources */,
-                               CDB859FB160D494F00E5B07F /* JSMediaKeyError.cpp in Sources */,
                                CDB859FA160D494900E5B07F /* JSMediaKeyEvent.cpp in Sources */,
                                BC3C39B60C0D3D8D005F4D7A /* JSMediaList.cpp in Sources */,
                                1464E06C135EC10600FDB00A /* JSMediaListCustom.cpp in Sources */,
                                977E2E0E12F0FC9C00C13379 /* XSSAuditor.cpp in Sources */,
                                977E2E0E12F0FC9C00C13380 /* XSSAuditorDelegate.cpp in Sources */,
                                FD537352137B651800008DCE /* ZeroPole.cpp in Sources */,
+                               CDA98DA31601464100FEA3B1 /* JSMediaKeyError.cpp in Sources */,
+                               CDA98DD816025BEF00FEA3B1 /* MediaKeyMessageEvent.cpp in Sources */,
+                               CDA98DDF16026A3700FEA3B1 /* JSMediaKeyMessageEvent.cpp in Sources */,
+                               CDA98DE016026A3700FEA3B1 /* JSMediaKeyNeededEvent.cpp in Sources */,
+                               CDA98E0416039E1A00FEA3B1 /* JSMediaKeys.cpp in Sources */,
+                               CDA98E0616039E1F00FEA3B1 /* JSMediaKeySession.cpp in Sources */,
+                               CDA98E0B1603CD6000FEA3B1 /* CDM.cpp in Sources */,
+                               CDA98E0D1603FE4A00FEA3B1 /* MediaKeys.cpp in Sources */,
+                               CDA98E0E1603FE5800FEA3B1 /* MediaKeySession.cpp in Sources */,
+                               CD1B4A65160786AE00282DF9 /* MediaKeyNeededEvent.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
index a2c3c9c..c04b025 100644 (file)
@@ -52,5 +52,7 @@ DeviceOrientationEvent conditional=DEVICE_ORIENTATION
 DeviceProximityEvent conditional=PROXIMITY_EVENTS
 OrientationEvent interfaceName=Event, conditional=ORIENTATION_EVENTS
 MediaKeyEvent conditional=ENCRYPTED_MEDIA
+MediaKeyMessageEvent conditional=ENCRYPTED_MEDIA_V2
+MediaKeyNeededEvent conditional=ENCRYPTED_MEDIA_V2
 TrackEvent conditional=VIDEO_TRACK
 AutocompleteErrorEvent conditional=REQUEST_AUTOCOMPLETE
index 825667b..cf5acf7 100644 (file)
@@ -14,6 +14,7 @@ IDBRequest conditional=INDEXED_DATABASE
 IDBTransaction conditional=INDEXED_DATABASE
 ScriptProcessorNode conditional=WEB_AUDIO
 LocalMediaStream conditional=MEDIA_STREAM
+MediaKeySession conditional=ENCRYPTED_MEDIA_V2
 MediaController conditional=VIDEO
 MediaSource conditional=MEDIA_SOURCE
 MediaStream conditional=MEDIA_STREAM
index 30afd36..ac774c5 100644 (file)
 #include "MediaStreamRegistry.h"
 #endif
 
+#if ENABLE(ENCRYPTED_MEDIA_V2)
+#include "MediaKeyNeededEvent.h"
+#include "MediaKeys.h"
+#endif
+
 using namespace std;
 
 namespace WebCore {
@@ -1966,6 +1971,25 @@ bool HTMLMediaElement::mediaPlayerKeyNeeded(MediaPlayer*, const String& keySyste
 }
 #endif
 
+#if ENABLE(ENCRYPTED_MEDIA_V2)
+void HTMLMediaElement::mediaPlayerKeyNeeded(MediaPlayer*, Uint8Array* initData)
+{
+    MediaKeyNeededEventInit initializer;
+    initializer.initData = initData;
+    initializer.bubbles = false;
+    initializer.cancelable = false;
+
+    RefPtr<Event> event = MediaKeyNeededEvent::create(eventNames().webkitneedkeyEvent, initializer);
+    event->setTarget(this);
+    m_asyncEventQueue->enqueueEvent(event.release());
+}
+
+void HTMLMediaElement::setMediaKeys(MediaKeys* mediaKeys)
+{
+    m_mediaKeys = mediaKeys;
+}
+#endif
+
 void HTMLMediaElement::progressEventTimerFired(Timer<HTMLMediaElement>*)
 {
     ASSERT(m_player);
@@ -2471,6 +2495,14 @@ void HTMLMediaElement::setSourceState(const String& state)
 #if ENABLE(ENCRYPTED_MEDIA)
 void HTMLMediaElement::webkitGenerateKeyRequest(const String& keySystem, PassRefPtr<Uint8Array> initData, ExceptionCode& ec)
 {
+#if ENABLE(ENCRYPTED_MEDIA_V2)
+    static bool firstTime = true;
+    if (firstTime && context() && context()->scriptExecutionContext()) {
+        context()->scriptExecutionContext()->addConsoleMessage(JSMessageSource, WarningMessageLevel, "'HTMLMediaElement.webkitGenerateKeyRequest()' is deprecated.  Use 'MediaKeys.createSession()' instead.");
+        firstTime = false;
+    }
+#endif
+
     if (keySystem.isEmpty()) {
         ec = SYNTAX_ERR;
         return;
@@ -2499,6 +2531,14 @@ void HTMLMediaElement::webkitGenerateKeyRequest(const String& keySystem, Excepti
 
 void HTMLMediaElement::webkitAddKey(const String& keySystem, PassRefPtr<Uint8Array> key, PassRefPtr<Uint8Array> initData, const String& sessionId, ExceptionCode& ec)
 {
+#if ENABLE(ENCRYPTED_MEDIA_V2)
+    static bool firstTime = true;
+    if (firstTime && context() && context()->scriptExecutionContext()) {
+        context()->scriptExecutionContext()->addConsoleMessage(JSMessageSource, WarningMessageLevel, "'HTMLMediaElement.webkitAddKey()' is deprecated.  Use 'MediaKeySession.addKey()' instead.");
+        firstTime = false;
+    }
+#endif
+
     if (keySystem.isEmpty()) {
         ec = SYNTAX_ERR;
         return;
index bac721d..8ff12d1 100644 (file)
@@ -66,6 +66,9 @@ class Widget;
 #if PLATFORM(MAC)
 class DisplaySleepDisabler;
 #endif
+#if ENABLE(ENCRYPTED_MEDIA_V2)
+class MediaKeys;
+#endif
 
 #if ENABLE(VIDEO_TRACK)
 class InbandTextTrackPrivate;
@@ -187,9 +190,16 @@ public:
     DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitkeyadded);
     DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitkeyerror);
     DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitkeymessage);
+#endif
+#if ENABLE(ENCRYPTED_MEDIA) || ENABLE(ENCRYPTED_MEDIA_V2)
     DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitneedkey);
 #endif
 
+#if ENABLE(ENCRYPTED_MEDIA_V2)
+    MediaKeys* mediaKeys() const { return m_mediaKeys.get(); }
+    void setMediaKeys(MediaKeys*);
+#endif
+
 // controls
     bool controls() const;
     void setControls(bool);
@@ -444,6 +454,10 @@ private:
     virtual bool mediaPlayerKeyNeeded(MediaPlayer*, const String& keySystem, const String& sessionId, const unsigned char* initData, unsigned initDataLength) OVERRIDE;
 #endif
 
+#if ENABLE(ENCRYPTED_MEDIA_V2)
+    virtual void mediaPlayerKeyNeeded(MediaPlayer*, Uint8Array*);
+#endif
+
     virtual String mediaPlayerReferrer() const OVERRIDE;
     virtual String mediaPlayerUserAgent() const OVERRIDE;
     virtual CORSMode mediaPlayerCORSMode() const OVERRIDE;
@@ -705,6 +719,10 @@ private:
 #endif
 
     friend class TrackDisplayUpdateScope;
+
+#if ENABLE(ENCRYPTED_MEDIA_V2)
+    RefPtr<MediaKeys> m_mediaKeys;
+#endif
 };
 
 #if ENABLE(VIDEO_TRACK)
index 2ece5ac..5ebf447 100644 (file)
@@ -45,7 +45,9 @@ attribute DOMString preload;
 readonly attribute TimeRanges buffered;
 void load();
 #if defined(ENABLE_ENCRYPTED_MEDIA) && ENABLE_ENCRYPTED_MEDIA
-DOMString canPlayType(in [Optional=DefaultIsUndefined] DOMString type, in [Optional=DefaultIsUndefined, TreatNullAs=NullString, TreatUndefinedAs=NullString] DOMString keySystem);
+    DOMString canPlayType(in [Optional=DefaultIsUndefined] DOMString type, in [Optional=DefaultIsUndefined, TreatNullAs=NullString, TreatUndefinedAs=NullString] DOMString keySystem);
+#elif defined(ENABLE_ENCRYPTED_MEDIA_V2) && ENABLE_ENCRYPTED_MEDIA_V2
+    DOMString canPlayType(in [Optional=DefaultIsUndefined] DOMString type, in [Optional=DefaultIsUndefined, TreatNullAs=NullString, TreatUndefinedAs=NullString] DOMString keySystem);
 #else
 DOMString canPlayType(in [Optional=DefaultIsUndefined] DOMString type);
 #endif
@@ -101,10 +103,13 @@ readonly attribute [Conditional=MEDIA_STATISTICS] unsigned long webkitVideoDecod
 [V8EnabledAtRuntime=encryptedMedia] void webkitCancelKeyRequest(in [TreatNullAs=NullString, TreatUndefinedAs=NullString] DOMString keySystem, in [Optional=DefaultIsNullString] DOMString sessionId)
     raises (DOMException);
 
-[V8EnabledAtRuntime=encryptedMedia] attribute EventListener onwebkitkeyadded;
-attribute [V8EnabledAtRuntime=encryptedMedia] EventListener onwebkitkeyerror;
-attribute [V8EnabledAtRuntime=encryptedMedia] EventListener onwebkitkeymessage;
-attribute [V8EnabledAtRuntime=encryptedMedia] EventListener onwebkitneedkey;
+    attribute [V8EnabledAtRuntime=encryptedMedia] EventListener onwebkitkeyadded;
+    attribute [V8EnabledAtRuntime=encryptedMedia] EventListener onwebkitkeyerror;
+    attribute [V8EnabledAtRuntime=encryptedMedia] EventListener onwebkitkeymessage;
+#endif
+    attribute [Conditional=ENCRYPTED_MEDIA|ENCRYPTED_MEDIA_V2, V8EnabledAtRuntime=encryptedMedia] EventListener onwebkitneedkey;
+#if defined(ENABLE_ENCRYPTED_MEDIA_V2) && ENABLE_ENCRYPTED_MEDIA_V2
+    attribute [V8EnabledAtRuntime=encryptedMedia] MediaKeys mediaKeys;
 #endif
 
 #if defined(ENABLE_VIDEO_TRACK) && ENABLE_VIDEO_TRACK
index 90f447f..b0bf5f7 100644 (file)
@@ -40,7 +40,7 @@ public:
         MEDIA_ERR_NETWORK,
         MEDIA_ERR_DECODE,
         MEDIA_ERR_SRC_NOT_SUPPORTED
-#if ENABLE(ENCRYPTED_MEDIA)
+#if ENABLE(ENCRYPTED_MEDIA) || ENABLE(ENCRYPTED_MEDIA_V2)
         , MEDIA_ERR_ENCRYPTED
 #endif
     };
index e2cd271..7337444 100644 (file)
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
  */
 
-[
+interface [
     Conditional=VIDEO,
     ImplementationLacksVTable
-] interface MediaError {
+] MediaError {
       const unsigned short MEDIA_ERR_ABORTED = 1;
       const unsigned short MEDIA_ERR_NETWORK = 2;
       const unsigned short MEDIA_ERR_DECODE = 3;
       const unsigned short MEDIA_ERR_SRC_NOT_SUPPORTED = 4;
-#if defined(ENABLE_ENCRYPTED_MEDIA) && ENABLE_ENCRYPTED_MEDIA
+#if (defined(ENABLE_ENCRYPTED_MEDIA) && ENABLE_ENCRYPTED_MEDIA) || (defined(ENABLE_ENCRYPTED_MEDIA_V2) && ENABLE_ENCRYPTED_MEDIA_V2)
       const unsigned short MEDIA_ERR_ENCRYPTED = 5;
 #endif
       readonly attribute unsigned short code;
index 12c736d..49e3843 100644 (file)
@@ -26,7 +26,7 @@
 #ifndef MediaKeyError_h
 #define MediaKeyError_h
 
-#if ENABLE(ENCRYPTED_MEDIA)
+#if ENABLE(ENCRYPTED_MEDIA) || ENABLE(ENCRYPTED_MEDIA_V2)
 
 #include <wtf/PassRefPtr.h>
 #include <wtf/RefCounted.h>
@@ -35,7 +35,7 @@ namespace WebCore {
 
 class MediaKeyError : public RefCounted<MediaKeyError> {
 public:
-    enum Code {
+    enum {
         MEDIA_KEYERR_UNKNOWN = 1,
         MEDIA_KEYERR_CLIENT,
         MEDIA_KEYERR_SERVICE,
@@ -43,15 +43,18 @@ public:
         MEDIA_KEYERR_HARDWARECHANGE,
         MEDIA_KEYERR_DOMAIN
     };
+    typedef unsigned short Code;
 
-    static PassRefPtr<MediaKeyError> create(Code code) { return adoptRef(new MediaKeyError(code)); }
+    static PassRefPtr<MediaKeyError> create(Code code, unsigned long systemCode = 0) { return adoptRef(new MediaKeyError(code, systemCode)); }
 
     Code code() const { return m_code; }
+    unsigned long systemCode() { return m_systemCode; }
 
 private:
-    explicit MediaKeyError(Code code) : m_code(code) { }
+    explicit MediaKeyError(Code code, unsigned long systemCode) : m_code(code), m_systemCode(systemCode) { }
 
     Code m_code;
+    unsigned long m_systemCode;
 };
 
 } // namespace WebCore
index f7279d3..9631551 100644 (file)
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
  */
 
-[
-    Conditional=ENCRYPTED_MEDIA,
+interface [
+    Conditional=ENCRYPTED_MEDIA|ENCRYPTED_MEDIA_V2,
     V8EnabledAtRuntime=encryptedMedia, 
     ImplementationLacksVTable
-] interface MediaKeyError {
+] MediaKeyError {
     const unsigned short MEDIA_KEYERR_UNKNOWN = 1;
     const unsigned short MEDIA_KEYERR_CLIENT = 2;
     const unsigned short MEDIA_KEYERR_SERVICE = 3;
@@ -35,4 +35,5 @@
     const unsigned short MEDIA_KEYERR_HARDWARECHANGE = 5;
     const unsigned short MEDIA_KEYERR_DOMAIN = 6;
     readonly attribute unsigned short code;
+    [Conditional=ENCRYPTED_MEDIA_V2] readonly attribute unsigned long systemCode;
 };
index 0255214..50ce43b 100644 (file)
 
     [Conditional=ENCRYPTED_MEDIA, V8EnabledAtRuntime=encryptedMedia] attribute MediaKeyErrorConstructor MediaKeyError;
     [Conditional=ENCRYPTED_MEDIA, V8EnabledAtRuntime=encryptedMedia] attribute MediaKeyEventConstructor MediaKeyEvent;
+    attribute [Conditional=ENCRYPTED_MEDIA_V2, V8EnabledAtRuntime=encryptedMedia] MediaKeysConstructor MediaKeys;
+    attribute [Conditional=ENCRYPTED_MEDIA_V2, V8EnabledAtRuntime=encryptedMedia] MediaKeyErrorConstructor MediaKeyError;
+    attribute [Conditional=ENCRYPTED_MEDIA_V2, V8EnabledAtRuntime=encryptedMedia] MediaKeyMessageEventConstructor MediaKeyMessageEvent;
+    attribute [Conditional=ENCRYPTED_MEDIA_V2, V8EnabledAtRuntime=encryptedMedia] MediaKeyNeededEventConstructor MediaKeyNeededEvent;
 
     [Conditional=VIDEO_TRACK, V8EnabledAtRuntime=webkitVideoTrack] attribute HTMLTrackElementConstructor HTMLTrackElement;
     [Conditional=VIDEO_TRACK, V8EnabledAtRuntime=webkitVideoTrack] attribute TextTrackConstructor TextTrack;
index 4b704ab..03d391c 100644 (file)
@@ -295,7 +295,7 @@ static MediaPlayerFactory* bestMediaEngineForTypeAndCodecs(const String& type, c
                 current = 0;
             continue;
         }
-#if ENABLE(ENCRYPTED_MEDIA)
+#if ENABLE(ENCRYPTED_MEDIA) || ENABLE(ENCRYPTED_MEDIA_V2)
         MediaPlayer::SupportsType engineSupport = engines[ndx]->supportsTypeAndCodecs(type, codecs, keySystem, url);
 #else
         UNUSED_PARAM(keySystem);
@@ -784,7 +784,7 @@ MediaPlayer::SupportsType MediaPlayer::supportsType(const ContentType& contentTy
     UNUSED_PARAM(client);
 #endif
 
-#if ENABLE(ENCRYPTED_MEDIA)
+#if ENABLE(ENCRYPTED_MEDIA) || ENABLE(ENCRYPTED_MEDIA_V2)
     return engine->supportsTypeAndCodecs(type, typeCodecs, system, url);
 #else
     ASSERT(system.isEmpty());
@@ -1081,6 +1081,14 @@ bool MediaPlayer::keyNeeded(const String& keySystem, const String& sessionId, co
 }
 #endif
 
+#if ENABLE(ENCRYPTED_MEDIA_V2)
+void MediaPlayer::keyNeeded(Uint8Array* initData)
+{
+    if (m_mediaPlayerClient)
+        m_mediaPlayerClient->mediaPlayerKeyNeeded(this, initData);
+}
+#endif
+
 String MediaPlayer::referrer() const
 {
     if (!m_mediaPlayerClient)
index 2b05176..cb5578b 100644 (file)
@@ -193,6 +193,10 @@ public:
     virtual bool mediaPlayerKeyNeeded(MediaPlayer*, const String& /* keySystem */, const String& /* sessionId */, const unsigned char* /* initData */, unsigned /* initDataLength */) { return false; }
 #endif
 
+#if ENABLE(ENCRYPTED_MEDIA_V2)
+    virtual void mediaPlayerKeyNeeded(MediaPlayer*, Uint8Array*) { }
+#endif
+    
     virtual String mediaPlayerReferrer() const { return String(); }
     virtual String mediaPlayerUserAgent() const { return String(); }
     virtual CORSMode mediaPlayerCORSMode() const { return Unspecified; }
@@ -430,6 +434,10 @@ public:
     bool keyNeeded(const String& keySystem, const String& sessionId, const unsigned char* initData, unsigned initDataLength);
 #endif
 
+#if ENABLE(ENCRYPTED_MEDIA_V2)
+    void keyNeeded(Uint8Array* initData);
+#endif
+
     String referrer() const;
     String userAgent() const;
 
@@ -480,7 +488,7 @@ private:
 
 typedef PassOwnPtr<MediaPlayerPrivateInterface> (*CreateMediaEnginePlayer)(MediaPlayer*);
 typedef void (*MediaEngineSupportedTypes)(HashSet<String>& types);
-#if ENABLE(ENCRYPTED_MEDIA)
+#if ENABLE(ENCRYPTED_MEDIA) || ENABLE(ENCRYPTED_MEDIA_V2)
 typedef MediaPlayer::SupportsType (*MediaEngineSupportsType)(const String& type, const String& codecs, const String& keySystem, const KURL& url);
 #else
 typedef MediaPlayer::SupportsType (*MediaEngineSupportsType)(const String& type, const String& codecs, const KURL& url);
index 62a02eb..3e466bc 100644 (file)
@@ -81,7 +81,7 @@ private:
     static PassOwnPtr<MediaPlayerPrivateInterface> create(MediaPlayer*);
     static void getSupportedTypes(HashSet<String>& types);
     static MediaPlayer::SupportsType supportsType(const String& type, const String& codecs, const KURL&);
-#if ENABLE(ENCRYPTED_MEDIA)
+#if ENABLE(ENCRYPTED_MEDIA) || ENABLE(ENCRYPTED_MEDIA_V2)
     static MediaPlayer::SupportsType extendedSupportsType(const String& type, const String& codecs, const String& keySystem, const KURL&);
 #endif
 
@@ -177,19 +177,14 @@ private:
 
 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
     RetainPtr<VTPixelTransferSessionRef> m_pixelTransferSession;
-#endif
 
-#if ENABLE(ENCRYPTED_MEDIA) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
+    friend class WebCoreAVFResourceLoader;
+    OwnPtr<WebCoreAVFResourceLoader> m_resourceLoader;
     RetainPtr<WebCoreAVFLoaderDelegate> m_loaderDelegate;
     HashMap<String, RetainPtr<AVAssetResourceLoadingRequest> > m_keyURIToRequestMap;
     HashMap<String, RetainPtr<AVAssetResourceLoadingRequest> > m_sessionIDToRequestMap;
 #endif
 
-#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
-    friend class WebCoreAVFResourceLoader;
-    OwnPtr<WebCoreAVFResourceLoader> m_resourceLoader;
-#endif
-
 #if HAVE(AVFOUNDATION_TEXT_TRACK_SUPPORT)
     RetainPtr<AVPlayerItemLegibleOutput> m_legibleOutput;
     InbandTextTrackPrivateAVFObjC* m_currentTrack;
index 8bb7885..340e59c 100644 (file)
@@ -194,7 +194,7 @@ PassOwnPtr<MediaPlayerPrivateInterface> MediaPlayerPrivateAVFoundationObjC::crea
 void MediaPlayerPrivateAVFoundationObjC::registerMediaEngine(MediaEngineRegistrar registrar)
 {
     if (isAvailable())
-#if ENABLE(ENCRYPTED_MEDIA)
+#if ENABLE(ENCRYPTED_MEDIA) || ENABLE(ENCRYPTED_MEDIA_V2)
         registrar(create, getSupportedTypes, extendedSupportsType, 0, 0, 0);
 #else
         registrar(create, getSupportedTypes, supportsType, 0, 0, 0);
@@ -206,7 +206,7 @@ MediaPlayerPrivateAVFoundationObjC::MediaPlayerPrivateAVFoundationObjC(MediaPlay
     , m_objcObserver(AdoptNS, [[WebCoreAVFMovieObserver alloc] initWithCallback:this])
     , m_videoFrameHasDrawn(false)
     , m_haveCheckedPlayability(false)
-#if ENABLE(ENCRYPTED_MEDIA)
+#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
     , m_loaderDelegate(AdoptNS, [[WebCoreAVFLoaderDelegate alloc] initWithCallback:this])
 #endif
 #if HAVE(AVFOUNDATION_TEXT_TRACK_SUPPORT)
@@ -815,7 +815,7 @@ MediaPlayer::SupportsType MediaPlayerPrivateAVFoundationObjC::supportsType(const
     return [AVURLAsset isPlayableExtendedMIMEType:typeString] ? MediaPlayer::IsSupported : MediaPlayer::MayBeSupported;;
 }
 
-#if ENABLE(ENCRYPTED_MEDIA)
+#if ENABLE(ENCRYPTED_MEDIA) || ENABLE(ENCRYPTED_MEDIA_V2)
 static bool keySystemIsSupported(const String& keySystem)
 {
     if (equalIgnoringCase(keySystem, "com.apple.lskd") || equalIgnoringCase(keySystem, "com.apple.lskd.1_0"))
index 3ee1a4c..8b11f83 100644 (file)
@@ -76,7 +76,7 @@ private:
     static PassOwnPtr<MediaPlayerPrivateInterface> create(MediaPlayer*);
     static void getSupportedTypes(HashSet<String>& types);
     static MediaPlayer::SupportsType supportsType(const String& type, const String& codecs, const KURL&);
-#if ENABLE(ENCRYPTED_MEDIA)
+#if ENABLE(ENCRYPTED_MEDIA) || ENABLE(ENCRYPTED_MEDIA_V2)
     static MediaPlayer::SupportsType extendedSupportsType(const String& type, const String& codecs, const String& keySystem, const KURL&);
 #endif
 
index ef7e380..56e334a 100644 (file)
@@ -190,7 +190,7 @@ PassOwnPtr<MediaPlayerPrivateInterface> MediaPlayerPrivateQTKit::create(MediaPla
 void MediaPlayerPrivateQTKit::registerMediaEngine(MediaEngineRegistrar registrar)
 {
     if (isAvailable())
-#if ENABLE(ENCRYPTED_MEDIA)
+#if ENABLE(ENCRYPTED_MEDIA) || ENABLE(ENCRYPTED_MEDIA_V2)
         registrar(create, getSupportedTypes, extendedSupportsType, getSitesInMediaCache, clearMediaCache, clearMediaCacheForSite);
 #else
         registrar(create, getSupportedTypes, supportsType, getSitesInMediaCache, clearMediaCache, clearMediaCacheForSite);
@@ -1552,7 +1552,7 @@ MediaPlayer::SupportsType MediaPlayerPrivateQTKit::supportsType(const String& ty
     return MediaPlayer::IsNotSupported;
 }
 
-#if ENABLE(ENCRYPTED_MEDIA)
+#if ENABLE(ENCRYPTED_MEDIA) || ENABLE(ENCRYPTED_MEDIA_V2)
 MediaPlayer::SupportsType MediaPlayerPrivateQTKit::extendedSupportsType(const String& type, const String& codecs, const String& keySystem, const KURL& url)
 {
     // QTKit does not support any encrytped media, so return IsNotSupported if the keySystem is non-NULL:
index ad4dd9d..fb3e471 100644 (file)
 #include "RenderLayerBacking.h"
 #endif
 
+#if ENABLE(ENCRYPTED_MEDIA_V2)
+#include "CDM.h"
+#include "MockCDM.h"
+#endif
+
 namespace WebCore {
 
 #if ENABLE(PAGE_POPUP)
@@ -1932,4 +1937,11 @@ void Internals::setUsesOverlayScrollbars(bool enabled)
     WebCore::Settings::setUsesOverlayScrollbars(enabled);
 }
 
+#if ENABLE(ENCRYPTED_MEDIA_V2)
+void Internals::initializeMockCDM()
+{
+    CDM::registerCDMFactory(MockCDM::create, MockCDM::supportsKeySytem);
+}
+#endif
+
 }
index 646b155..5dd6c4b 100644 (file)
@@ -280,6 +280,10 @@ public:
 
     String getCurrentCursorInfo(Document*, ExceptionCode&);
 
+#if ENABLE(ENCRYPTED_MEDIA_V2)
+    void initializeMockCDM();
+#endif
+
 private:
     explicit Internals(Document*);
     Document* contextDocument() const;
index a50b79c..17936c8 100644 (file)
     ArrayBuffer serializeObject(in SerializedScriptValue obj);
 
     void setUsesOverlayScrollbars(in boolean enabled);
+
+    [Conditional=ENCRYPTED_MEDIA_V2] void initializeMockCDM();
 };
diff --git a/Source/WebCore/testing/MockCDM.cpp b/Source/WebCore/testing/MockCDM.cpp
new file mode 100644 (file)
index 0000000..bc2affc
--- /dev/null
@@ -0,0 +1,144 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "MockCDM.h"
+
+#if ENABLE(ENCRYPTED_MEDIA_V2)
+
+#include "CDM.h"
+#include "MediaKeyError.h"
+#include <wtf/Uint8Array.h>
+
+namespace WebCore {
+
+class MockCDMSession : public CDMSession {
+public:
+    static PassOwnPtr<MockCDMSession> create() { return adoptPtr(new MockCDMSession()); }
+    virtual ~MockCDMSession() { }
+
+    virtual const String& sessionId() OVERRIDE { return m_sessionId; }
+    virtual PassRefPtr<Uint8Array> generateKeyRequest(const String& mimeType, Uint8Array* initData, String& destinationURL, unsigned short& errorCode, unsigned long& systemCode) OVERRIDE;
+    virtual void releaseKeys() OVERRIDE;
+    virtual bool addKey(Uint8Array*, RefPtr<Uint8Array>& nextMessage, unsigned short& errorCode, unsigned long& systemCode) OVERRIDE;
+
+protected:
+    MockCDMSession();
+
+    String m_sessionId;
+};
+
+bool MockCDM::supportsKeySytem(const String& keySystem)
+{
+    return equalIgnoringCase(keySystem, "com.webcore.mock");
+}
+
+bool MockCDM::supportsMIMEType(const String& mimeType)
+{
+    return equalIgnoringCase(mimeType, "video/mock");
+}
+
+PassOwnPtr<CDMSession> MockCDM::createSession()
+{
+    return MockCDMSession::create();
+}
+
+static Uint8Array* initDataPrefix()
+{
+    static const unsigned char prefixData[] = {'m', 'o', 'c', 'k'};
+    DEFINE_STATIC_LOCAL(RefPtr<Uint8Array>, prefix, ());
+    static bool initialized = false;
+    if (!initialized) {
+        initialized = true;
+        prefix = Uint8Array::create(prefixData, sizeof(prefixData) / sizeof(prefixData[0]));
+    }
+    return prefix.get();
+}
+
+static Uint8Array* keyPrefix()
+{
+    static const unsigned char prefixData[] = {'k', 'e', 'y'};
+    DEFINE_STATIC_LOCAL(RefPtr<WTF::Uint8Array>, prefix, ());
+    static bool initialized = false;
+    if (!initialized) {
+        initialized = true;
+        prefix = Uint8Array::create(prefixData, sizeof(prefixData) / sizeof(prefixData[0]));
+    }
+    return prefix.get();
+}
+
+static Uint8Array* keyRequest()
+{
+    static const unsigned char requestData[] = {'r', 'e', 'q', 'u', 'e', 's', 't'};
+    DEFINE_STATIC_LOCAL(RefPtr<WTF::Uint8Array>, request, ());
+    static bool initialized = false;
+    if (!initialized) {
+        initialized = true;
+        request = Uint8Array::create(requestData, sizeof(requestData) / sizeof(requestData[0]));
+    }
+    return request.get();
+}
+
+static String generateSessionId()
+{
+    static int monotonicallyIncreasingSessionId = 0;
+    return String::number(monotonicallyIncreasingSessionId++);
+}
+
+MockCDMSession::MockCDMSession()
+    : m_sessionId(generateSessionId())
+{
+}
+
+PassRefPtr<Uint8Array> MockCDMSession::generateKeyRequest(const String&, Uint8Array* initData, String&, unsigned short& errorCode, unsigned long&)
+{
+    for (unsigned i = 0; i < initDataPrefix()->length(); ++i) {
+        if (!initData || i >= initData->length() || initData->item(i) != initDataPrefix()->item(i)) {
+            errorCode = MediaKeyError::MEDIA_KEYERR_UNKNOWN;
+            return 0;
+        }
+    }
+    return keyRequest();
+}
+
+void MockCDMSession::releaseKeys()
+{
+    // no-op
+}
+
+bool MockCDMSession::addKey(Uint8Array* key, RefPtr<Uint8Array>&, unsigned short& errorCode, unsigned long&)
+{
+    for (unsigned i = 0; i < keyPrefix()->length(); ++i) {
+        if (i >= key->length() || key->item(i) != keyPrefix()->item(i)) {
+            errorCode = MediaKeyError::MEDIA_KEYERR_CLIENT;
+            return false;
+        }
+    }
+    return true;
+}
+
+}
+
+#endif // ENABLE(ENCRYPTED_MEDIA_V2)
diff --git a/Source/WebCore/testing/MockCDM.h b/Source/WebCore/testing/MockCDM.h
new file mode 100644 (file)
index 0000000..1ccc4c4
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef MockCDM_h
+#define MockCDM_h
+
+#if ENABLE(ENCRYPTED_MEDIA_V2)
+
+#include "CDMPrivate.h"
+#include <wtf/PassOwnPtr.h>
+
+namespace WebCore {
+
+class CDM;
+
+class MockCDM : public CDMPrivateInterface {
+public:
+    // CDMFactory support:
+    static PassOwnPtr<CDMPrivateInterface> create(CDM* cdm) { return adoptPtr(new MockCDM(cdm)); }
+    static bool supportsKeySytem(const String&);
+
+    virtual ~MockCDM() { }
+
+    virtual bool supportsMIMEType(const String& mimeType) OVERRIDE;
+    virtual PassOwnPtr<CDMSession> createSession() OVERRIDE;
+
+protected:
+    MockCDM(CDM* cdm) : m_cdm(cdm) { }
+    CDM* m_cdm;
+};
+
+}
+
+#endif // ENABLE(ENCRYPTED_MEDIA)
+
+#endif // MockCDM_h