Bug 454971. Support 'new Audio()' constructor. r+sr=roc

--HG--
extra : rebase_source : 1738d65cd16a79d69408055a8d9feb5ab5d97923
This commit is contained in:
Matthew Gregan 2009-05-19 17:18:41 +12:00
Родитель 97e33b8c4d
Коммит 07f0682802
9 изменённых файлов: 172 добавлений и 5 удалений

Просмотреть файл

@ -36,13 +36,15 @@
*
* ***** END LICENSE BLOCK ***** */
#include "nsIDOMHTMLAudioElement.h"
#include "nsIJSNativeInitializer.h"
#include "nsHTMLMediaElement.h"
typedef PRUint16 nsMediaNetworkState;
typedef PRUint16 nsMediaReadyState;
class nsHTMLAudioElement : public nsHTMLMediaElement,
public nsIDOMHTMLAudioElement
public nsIDOMHTMLAudioElement,
public nsIJSNativeInitializer
{
public:
nsHTMLAudioElement(nsINodeInfo *aNodeInfo, PRBool aFromParser = PR_FALSE);
@ -66,5 +68,9 @@ public:
// nsIDOMHTMLAudioElement
NS_DECL_NSIDOMHTMLAUDIOELEMENT
// nsIJSNativeInitializer
NS_IMETHOD Initialize(nsISupports* aOwner, JSContext* aContext,
JSObject* aObj, PRUint32 argc, jsval* argv);
virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
};

Просмотреть файл

@ -156,6 +156,7 @@ INCLUDES += \
-I$(srcdir)/../../../xbl/src \
-I$(srcdir)/../../../../layout/style \
-I$(srcdir)/../../../../layout/tables \
-I$(srcdir)/../../../../dom/base \
-I$(srcdir) \
$(NULL)

Просмотреть файл

@ -59,6 +59,7 @@
#include "nsIScriptSecurityManager.h"
#include "nsIXPConnect.h"
#include "jsapi.h"
#include "nsJSUtils.h"
#include "nsIRenderingContext.h"
#include "nsITimer.h"
@ -68,13 +69,34 @@
#include "nsIDOMProgressEvent.h"
#include "nsHTMLMediaError.h"
NS_IMPL_NS_NEW_HTML_ELEMENT_CHECK_PARSER(Audio)
nsGenericHTMLElement*
NS_NewHTMLAudioElement(nsINodeInfo *aNodeInfo, PRBool aFromParser)
{
/*
* nsHTMLAudioElement's will be created without a nsINodeInfo passed in
* if someone says "var audio = new Audio();" in JavaScript, in a case like
* that we request the nsINodeInfo from the document's nodeinfo list.
*/
nsCOMPtr<nsINodeInfo> nodeInfo(aNodeInfo);
if (!nodeInfo) {
nsCOMPtr<nsIDocument> doc =
do_QueryInterface(nsContentUtils::GetDocumentFromCaller());
NS_ENSURE_TRUE(doc, nsnull);
nodeInfo = doc->NodeInfoManager()->GetNodeInfo(nsGkAtoms::audio, nsnull,
kNameSpaceID_None);
NS_ENSURE_TRUE(nodeInfo, nsnull);
}
return new nsHTMLAudioElement(nodeInfo, aFromParser);
}
NS_IMPL_ADDREF_INHERITED(nsHTMLAudioElement, nsHTMLMediaElement)
NS_IMPL_RELEASE_INHERITED(nsHTMLAudioElement, nsHTMLMediaElement)
NS_INTERFACE_TABLE_HEAD(nsHTMLAudioElement)
NS_HTML_CONTENT_INTERFACE_TABLE2(nsHTMLAudioElement, nsIDOMHTMLMediaElement, nsIDOMHTMLAudioElement)
NS_HTML_CONTENT_INTERFACE_TABLE3(nsHTMLAudioElement, nsIDOMHTMLMediaElement,
nsIDOMHTMLAudioElement, nsIJSNativeInitializer)
NS_HTML_CONTENT_INTERFACE_TABLE_TO_MAP_SEGUE(nsHTMLAudioElement,
nsHTMLMediaElement)
NS_HTML_CONTENT_INTERFACE_TABLE_TAIL_CLASSINFO(HTMLAudioElement)
@ -90,3 +112,21 @@ nsHTMLAudioElement::nsHTMLAudioElement(nsINodeInfo *aNodeInfo, PRBool aFromParse
nsHTMLAudioElement::~nsHTMLAudioElement()
{
}
NS_IMETHODIMP
nsHTMLAudioElement::Initialize(nsISupports* aOwner, JSContext* aContext,
JSObject *aObj, PRUint32 argc, jsval *argv)
{
if (argc <= 0) {
// Nothing to do here if we don't get any arguments.
return NS_OK;
}
// The only (optional) argument is the url of the audio
JSString* jsstr = JS_ValueToString(aContext, argv[0]);
if (!jsstr)
return NS_ERROR_FAILURE;
nsDependentJSString str(jsstr);
return SetAttr(kNameSpaceID_None, nsGkAtoms::src, str, PR_TRUE);
}

Просмотреть файл

@ -65,6 +65,8 @@ _TEST_FILES += \
dynamic_redirect.sjs \
test_access_control.html \
file_access_controls.html \
test_audio1.html \
test_audio2.html \
test_bug448534.html \
test_bug461281.html \
test_bug468190.html \
@ -108,6 +110,7 @@ _TEST_FILES += \
contentDuration5.sjs \
contentDuration6.sjs \
seek.ogv \
sound.ogg \
$(NULL)
# These tests disabled until we figure out random failures.
@ -165,7 +168,7 @@ _TEST_FILES += \
test_wav_timeupdate1.html \
test_wav_timeupdate2.html \
test_wav_trailing.html \
test_wav_trunc.html \
test_wav_trunc.html \
test_wav_trunc_seek.html \
r11025_s16_c1.wav \
r11025_s16_c1_trailing.wav \

Двоичные данные
content/media/video/test/sound.ogg Normal file

Двоичный файл не отображается.

Просмотреть файл

@ -0,0 +1,24 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Media test: Audio Constructor Test 1</title>
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<pre id="test">
<script class="testbody" type="text/javascript">
var a1 = new Audio();
a1.addEventListener('load', function() {
is(a1.networkState, HTMLMediaElement.NETWORK_LOADED, "Audio loaded");
SimpleTest.finish();
}, false);
a1.src = 'sound.ogg';
a1.load();
SimpleTest.waitForExplicitFinish();
</script>
</pre>
</body>
</html>

Просмотреть файл

@ -0,0 +1,23 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Media test: Audio Constructor Test 2</title>
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<pre id="test">
<script class="testbody" type="text/javascript">
var a1 = Audio('sound.ogg');
a1.addEventListener('load', function() {
is(a1.networkState, HTMLMediaElement.NETWORK_LOADED, "Audio loaded");
SimpleTest.finish();
}, false);
a1.load();
SimpleTest.waitForExplicitFinish();
</script>
</pre>
</body>
</html>

Просмотреть файл

@ -229,4 +229,12 @@
// {93ad72a6-02cd-4716-9626-d47d5ec275ec}
#define NS_DOMJSON_CID \
{ 0x93ad72a6, 0x02cd, 0x4716, { 0x96, 0x26, 0xd4, 0x7d, 0x5e, 0xc2, 0x75, 0xec } }
#ifdef MOZ_MEDIA
#define NS_HTMLAUDIOELEMENT_CID \
{ /* 1d40026b-4c44-4f6f-b158-26bb5e9c65e9 */ \
0x1d40026b, 0x4c44, 0x4f6f, \
{0xb1, 0x58, 0x26, 0xbb, 0x5e, 0x9c, 0x65, 0xe9}}
#endif
#endif /* nsLayoutCID_h__ */

Просмотреть файл

@ -223,6 +223,11 @@ class nsIDocumentLoaderFactory;
#define NS_HTMLOPTIONELEMENT_CONTRACTID \
"@mozilla.org/content/element/html;1?name=option"
#ifdef MOZ_MEDIA
#define NS_HTMLAUDIOELEMENT_CONTRACTID \
"@mozilla.org/content/element/html;1?name=audio"
#endif
/* 0ddf4df8-4dbb-4133-8b79-9afb966514f5 */
#define NS_PLUGINDOCLOADERFACTORY_CID \
{ 0x0ddf4df8, 0x4dbb, 0x4133, { 0x8b, 0x79, 0x9a, 0xfb, 0x96, 0x65, 0x14, 0xf5 } }
@ -492,6 +497,7 @@ MAKE_CTOR(CreatePreContentIterator, nsIContentIterator, NS_NewPre
MAKE_CTOR(CreateSubtreeIterator, nsIContentIterator, NS_NewContentSubtreeIterator)
// CreateHTMLImgElement, see below
// CreateHTMLOptionElement, see below
// CreateHTMLAudioElement, see below
MAKE_CTOR(CreateTextEncoder, nsIDocumentEncoder, NS_NewTextEncoder)
MAKE_CTOR(CreateHTMLCopyTextEncoder, nsIDocumentEncoder, NS_NewHTMLCopyTextEncoder)
MAKE_CTOR(CreateXMLContentSerializer, nsIContentSerializer, NS_NewXMLContentSerializer)
@ -673,6 +679,53 @@ UnregisterHTMLOptionElement(nsIComponentManager* aCompMgr,
return NS_OK;
}
#ifdef MOZ_MEDIA
static NS_IMETHODIMP
CreateHTMLAudioElement(nsISupports* aOuter, REFNSIID aIID, void** aResult)
{
*aResult = nsnull;
if (aOuter)
return NS_ERROR_NO_AGGREGATION;
// Note! NS_NewHTMLAudioElement is special cased to handle a null nodeinfo
nsCOMPtr<nsIContent> inst(NS_NewHTMLAudioElement(nsnull));
return inst ? inst->QueryInterface(aIID, aResult) : NS_ERROR_OUT_OF_MEMORY;
}
static NS_IMETHODIMP
RegisterHTMLAudioElement(nsIComponentManager *aCompMgr,
nsIFile* aPath,
const char* aRegistryLocation,
const char* aComponentType,
const nsModuleComponentInfo* aInfo)
{
nsCOMPtr<nsICategoryManager> catman =
do_GetService(NS_CATEGORYMANAGER_CONTRACTID);
if (!catman)
return NS_ERROR_FAILURE;
nsXPIDLCString previous;
nsresult rv = catman->AddCategoryEntry(JAVASCRIPT_GLOBAL_CONSTRUCTOR_CATEGORY,
"Audio", NS_HTMLAUDIOELEMENT_CONTRACTID,
PR_TRUE, PR_TRUE, getter_Copies(previous));
NS_ENSURE_SUCCESS(rv, rv);
return catman->AddCategoryEntry(JAVASCRIPT_GLOBAL_CONSTRUCTOR_PROTO_ALIAS_CATEGORY,
"Audio", "HTMLAudioElement",
PR_TRUE, PR_TRUE, getter_Copies(previous));
}
static NS_IMETHODIMP
UnregisterHTMLAudioElement(nsIComponentManager* aCompMgr,
nsIFile* aPath,
const char* aRegistryLocation,
const nsModuleComponentInfo* aInfo)
{
// XXX remove category entry
return NS_OK;
}
#endif
static NS_METHOD
RegisterDataDocumentContentPolicy(nsIComponentManager *aCompMgr,
nsIFile* aPath,
@ -1000,7 +1053,7 @@ static const nsModuleComponentInfo gComponents[] = {
nsnull,
nsInspectorCSSUtilsConstructor },
// Needed to support "new Option;" and "new Image;" in JavaScript
// Needed to support "new Option;", "new Image;" and "new Audio;" in JavaScript
{ "HTML img element",
NS_HTMLIMAGEELEMENT_CID,
NS_HTMLIMGELEMENT_CONTRACTID,
@ -1015,6 +1068,15 @@ static const nsModuleComponentInfo gComponents[] = {
RegisterHTMLOptionElement,
UnregisterHTMLOptionElement },
#ifdef MOZ_MEDIA
{ "HTML audio element",
NS_HTMLAUDIOELEMENT_CID,
NS_HTMLAUDIOELEMENT_CONTRACTID,
CreateHTMLAudioElement,
RegisterHTMLAudioElement,
UnregisterHTMLAudioElement },
#endif
#ifdef MOZ_ENABLE_CANVAS
{ "Canvas 2D Rendering Context",
NS_CANVASRENDERINGCONTEXT2D_CID,