Backed out changeset e110a9187bb1 (bug 895091)

--HG--
rename : content/media/WebVTTListener.cpp => content/media/WebVTTLoadListener.cpp
rename : content/media/WebVTTListener.h => content/media/WebVTTLoadListener.h
This commit is contained in:
Ralph Giles 2013-09-18 13:47:07 -07:00
Родитель c93be09128
Коммит aaf5811e76
17 изменённых файлов: 234 добавлений и 485 удалений

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

@ -451,9 +451,6 @@
@BINPATH@/components/SettingsManager.manifest
@BINPATH@/components/SettingsService.js
@BINPATH@/components/SettingsService.manifest
@BINPATH@/components/webvtt.xpt
@BINPATH@/components/WebVTT.manifest
@BINPATH@/components/WebVTTParserWrapper.js
#ifdef MOZ_B2G_RIL
@BINPATH@/components/NetworkManager.manifest
@BINPATH@/components/NetworkManager.js

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

@ -375,9 +375,6 @@
@BINPATH@/components/crypto-SDR.js
@BINPATH@/components/jsconsole-clhandler.manifest
@BINPATH@/components/jsconsole-clhandler.js
@BINPATH@/components/webvtt.xpt
@BINPATH@/components/WebVTT.manifest
@BINPATH@/components/WebVTTParserWrapper.js
#ifdef MOZ_GTK
@BINPATH@/components/nsFilePicker.manifest
@BINPATH@/components/nsFilePicker.js

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

@ -8,7 +8,7 @@
#include "mozilla/dom/HTMLTrackElement.h"
#include "mozilla/dom/HTMLTrackElementBinding.h"
#include "mozilla/dom/HTMLUnknownElement.h"
#include "WebVTTListener.h"
#include "WebVTTLoadListener.h"
#include "nsAttrValueInlines.h"
#include "nsCOMPtr.h"
#include "nsContentPolicyUtils.h"
@ -87,7 +87,7 @@ NS_IMPL_RELEASE_INHERITED(HTMLTrackElement, Element)
NS_IMPL_CYCLE_COLLECTION_INHERITED_4(HTMLTrackElement, nsGenericHTMLElement,
mTrack, mChannel, mMediaParent,
mListener)
mLoadListener)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(HTMLTrackElement)
NS_INTERFACE_MAP_END_INHERITING(nsGenericHTMLElement)
@ -238,13 +238,13 @@ HTMLTrackElement::LoadResource()
channelPolicy);
NS_ENSURE_TRUE_VOID(NS_SUCCEEDED(rv));
mListener = new WebVTTListener(this);
rv = mListener->LoadResource();
mLoadListener = new WebVTTLoadListener(this);
rv = mLoadListener->LoadResource();
NS_ENSURE_TRUE_VOID(NS_SUCCEEDED(rv));
channel->SetNotificationCallbacks(mListener);
channel->SetNotificationCallbacks(mLoadListener);
LOG(PR_LOG_DEBUG, ("opening webvtt channel"));
rv = channel->AsyncOpen(mListener, nullptr);
rv = channel->AsyncOpen(mLoadListener, nullptr);
NS_ENSURE_TRUE_VOID(NS_SUCCEEDED(rv));
mChannel = channel;

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

@ -31,7 +31,7 @@ static const nsAttrValue::EnumTable kKindTable[] = {
{ 0 }
};
class WebVTTListener;
class WebVTTLoadListener;
class HTMLTrackElement MOZ_FINAL : public nsGenericHTMLElement
{
@ -146,17 +146,18 @@ protected:
JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
void OnChannelRedirect(nsIChannel* aChannel, nsIChannel* aNewChannel,
uint32_t aFlags);
// Open a new channel to the HTMLTrackElement's src attribute and call
// mListener's LoadResource().
// Will open a new channel for the HTMLTrackElement's src attribute and load
// HTMLTrackElement's WebVTTLoadListener by calling WebVTTLoadListener's
// LoadResource().
void LoadResource();
friend class TextTrackCue;
friend class WebVTTListener;
friend class WebVTTLoadListener;
nsRefPtr<TextTrack> mTrack;
nsCOMPtr<nsIChannel> mChannel;
nsRefPtr<HTMLMediaElement> mMediaParent;
nsRefPtr<WebVTTListener> mListener;
nsRefPtr<WebVTTLoadListener> mLoadListener;
uint16_t mReadyState;
void CreateTextTrack();

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

@ -7,7 +7,6 @@
#include "mozilla/dom/TextTrackCue.h"
#include "nsIFrame.h"
#include "nsVideoFrame.h"
#include "nsComponentManagerUtils.h"
// Alternate value for the 'auto' keyword.
#define WEBVTT_AUTO -1
@ -27,8 +26,6 @@ NS_IMPL_RELEASE_INHERITED(TextTrackCue, nsDOMEventTargetHelper)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(TextTrackCue)
NS_INTERFACE_MAP_END_INHERITING(nsDOMEventTargetHelper)
StaticRefPtr<nsIWebVTTParserWrapper> TextTrackCue::sParserWrapper;
// Set cue setting defaults based on step 19 & seq.
// in http://dev.w3.org/html5/webvtt/#parsing
void
@ -153,39 +150,9 @@ already_AddRefed<DocumentFragment>
TextTrackCue::GetCueAsHTML()
{
MOZ_ASSERT(mDocument);
nsRefPtr<DocumentFragment> frag = mDocument->CreateDocumentFragment();
if (!sParserWrapper) {
nsresult rv;
nsCOMPtr<nsIWebVTTParserWrapper> parserWrapper =
do_CreateInstance(NS_WEBVTTPARSERWRAPPER_CONTRACTID, &rv);
if (NS_FAILED(rv)) {
return mDocument->CreateDocumentFragment();
}
sParserWrapper = parserWrapper;
}
nsPIDOMWindow* window = mDocument->GetWindow();
if (!window) {
return mDocument->CreateDocumentFragment();
}
nsCOMPtr<nsIDOMHTMLElement> div;
sParserWrapper->ConvertCueToDOMTree(window, this,
getter_AddRefs(div));
if (!div) {
return mDocument->CreateDocumentFragment();
}
nsRefPtr<DocumentFragment> docFrag = mDocument->CreateDocumentFragment();
nsCOMPtr<nsIDOMNode> throwAway;
docFrag->AppendChild(div, getter_AddRefs(throwAway));
return docFrag.forget();
}
void
TextTrackCue::SetTrackElement(HTMLTrackElement* aTrackElement)
{
mTrackElement = aTrackElement;
return frag.forget();
}
JSObject*

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

@ -11,8 +11,7 @@
#include "mozilla/dom/VTTCueBinding.h"
#include "nsCycleCollectionParticipant.h"
#include "nsDOMEventTargetHelper.h"
#include "nsIWebVTTParserWrapper.h"
#include "mozilla/StaticPtr.h"
#include "nsIDocument.h"
namespace mozilla {
namespace dom {
@ -284,8 +283,6 @@ public:
*/
already_AddRefed<DocumentFragment> GetCueAsHTML();
void SetTrackElement(HTMLTrackElement* aTrackElement);
private:
void CueChanged();
void SetDefaultCueSettings();
@ -315,8 +312,6 @@ private:
// anytime a property that relates to the display of the TextTrackCue is
// changed.
bool mReset;
static StaticRefPtr<nsIWebVTTParserWrapper> sParserWrapper;
};
} // namespace dom

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

@ -1,177 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "WebVTTListener.h"
#include "mozilla/dom/TextTrackCue.h"
#include "mozilla/dom/HTMLTrackElement.h"
#include "nsIInputStream.h"
#include "nsIWebVTTParserWrapper.h"
#include "nsComponentManagerUtils.h"
namespace mozilla {
namespace dom {
NS_IMPL_CYCLE_COLLECTION_2(WebVTTListener, mElement, mParserWrapper)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(WebVTTListener)
NS_INTERFACE_MAP_ENTRY(nsIWebVTTListener)
NS_INTERFACE_MAP_ENTRY(nsIStreamListener)
NS_INTERFACE_MAP_ENTRY(nsIChannelEventSink)
NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIWebVTTListener)
NS_INTERFACE_MAP_END
NS_IMPL_CYCLE_COLLECTING_ADDREF(WebVTTListener)
NS_IMPL_CYCLE_COLLECTING_RELEASE(WebVTTListener)
#ifdef PR_LOGGING
PRLogModuleInfo* gTextTrackLog;
# define LOG(...) PR_LOG(gTextTrackLog, PR_LOG_DEBUG, (__VA_ARGS__))
#else
# define LOG(msg)
#endif
WebVTTListener::WebVTTListener(HTMLTrackElement* aElement)
: mElement(aElement)
{
MOZ_ASSERT(mElement, "Must pass an element to the callback");
#ifdef PR_LOGGING
if (!gTextTrackLog) {
gTextTrackLog = PR_NewLogModule("TextTrack");
}
#endif
LOG("WebVTTListener created.");
}
WebVTTListener::~WebVTTListener()
{
LOG("WebVTTListener destroyed.");
}
NS_IMETHODIMP
WebVTTListener::GetInterface(const nsIID &aIID,
void** aResult)
{
return QueryInterface(aIID, aResult);
}
nsresult
WebVTTListener::LoadResource()
{
if (!HTMLTrackElement::IsWebVTTEnabled()) {
NS_WARNING("WebVTT support disabled."
" See media.webvtt.enabled in about:config. ");
return NS_ERROR_FAILURE;
}
nsresult rv;
mParserWrapper = do_CreateInstance(NS_WEBVTTPARSERWRAPPER_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsPIDOMWindow* window = mElement->OwnerDoc()->GetWindow();
rv = mParserWrapper->LoadParser(window);
NS_ENSURE_SUCCESS(rv, rv);
rv = mParserWrapper->Watch(this);
NS_ENSURE_SUCCESS(rv, rv);
mElement->mReadyState = HTMLTrackElement::LOADING;
return NS_OK;
}
NS_IMETHODIMP
WebVTTListener::AsyncOnChannelRedirect(nsIChannel* aOldChannel,
nsIChannel* aNewChannel,
uint32_t aFlags,
nsIAsyncVerifyRedirectCallback* cb)
{
if (mElement) {
mElement->OnChannelRedirect(aOldChannel, aNewChannel, aFlags);
}
return NS_OK;
}
NS_IMETHODIMP
WebVTTListener::OnStartRequest(nsIRequest* aRequest,
nsISupports* aContext)
{
return NS_OK;
}
NS_IMETHODIMP
WebVTTListener::OnStopRequest(nsIRequest* aRequest,
nsISupports* aContext,
nsresult aStatus)
{
if (mElement->mReadyState != HTMLTrackElement::ERROR) {
mElement->mReadyState = HTMLTrackElement::LOADED;
}
// Attempt to parse any final data the parser might still have.
mParserWrapper->Flush();
return NS_OK;
}
NS_METHOD
WebVTTListener::ParseChunk(nsIInputStream* aInStream, void* aClosure,
const char* aFromSegment, uint32_t aToOffset,
uint32_t aCount, uint32_t* aWriteCount)
{
WebVTTListener* listener = static_cast<WebVTTListener*>(aClosure);
if (NS_FAILED(listener->mParserWrapper->Parse(aFromSegment, aCount))) {
LOG("Unable to parse chunk of WEBVTT text. Aborting.");
*aWriteCount = 0;
return NS_ERROR_FAILURE;
}
*aWriteCount = aCount;
return NS_OK;
}
NS_IMETHODIMP
WebVTTListener::OnDataAvailable(nsIRequest* aRequest,
nsISupports* aContext,
nsIInputStream* aStream,
uint64_t aOffset,
uint32_t aCount)
{
uint32_t count = aCount;
while (count > 0) {
uint32_t read;
nsresult rv = aStream->ReadSegments(ParseChunk, this, count, &read);
NS_ENSURE_SUCCESS(rv, rv);
if (!read) {
return NS_ERROR_FAILURE;
}
count -= read;
}
return NS_OK;
}
NS_IMETHODIMP
WebVTTListener::OnCue(const JS::Value &aCue, JSContext* aCx)
{
if (!aCue.isObject()) {
return NS_ERROR_FAILURE;
}
TextTrackCue* cue;
nsresult rv = UNWRAP_OBJECT(VTTCue, aCx, &aCue.toObject(), cue);
NS_ENSURE_SUCCESS(rv, rv);
cue->SetTrackElement(mElement);
mElement->mTrack->AddCue(*cue);
return NS_OK;
}
NS_IMETHODIMP
WebVTTListener::OnRegion(const JS::Value &aRegion, JSContext* aCx)
{
// TODO: Implement VTTRegions see bug 897504
return NS_OK;
}
} // namespace dom
} // namespace mozilla

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

@ -1,60 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_dom_WebVTTLoadListener_h
#define mozilla_dom_WebVTTLoadListener_h
#include "nsIWebVTTListener.h"
#include "nsIStreamListener.h"
#include "nsIChannelEventSink.h"
#include "nsAutoPtr.h"
#include "nsIInterfaceRequestor.h"
#include "nsCycleCollectionParticipant.h"
class nsIWebVTTParserWrapper;
namespace mozilla {
namespace dom {
class HTMLTrackElement;
class WebVTTListener MOZ_FINAL : public nsIWebVTTListener,
public nsIStreamListener,
public nsIChannelEventSink,
public nsIInterfaceRequestor
{
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_NSIWEBVTTLISTENER
NS_DECL_NSIREQUESTOBSERVER
NS_DECL_NSISTREAMLISTENER
NS_DECL_NSICHANNELEVENTSINK
NS_DECL_NSIINTERFACEREQUESTOR
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(WebVTTListener,
nsIStreamListener)
public:
WebVTTListener(HTMLTrackElement* aElement);
~WebVTTListener();
/**
* Loads the WebVTTListener. Must call this in order for the listener to be
* ready to parse data that is passed to it.
*/
nsresult LoadResource();
private:
static NS_METHOD ParseChunk(nsIInputStream* aInStream, void* aClosure,
const char* aFromSegment, uint32_t aToOffset,
uint32_t aCount, uint32_t* aWriteCount);
nsRefPtr<HTMLTrackElement> mElement;
nsCOMPtr<nsIWebVTTParserWrapper> mParserWrapper;
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_WebVTTListener_h

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

@ -0,0 +1,141 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "WebVTTLoadListener.h"
#include "mozilla/dom/TextTrackCue.h"
#include "mozilla/dom/HTMLTrackElement.h"
#include "nsIInputStream.h"
namespace mozilla {
namespace dom {
NS_IMPL_CYCLE_COLLECTION_1(WebVTTLoadListener, mElement)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(WebVTTLoadListener)
NS_INTERFACE_MAP_ENTRY(nsIStreamListener)
NS_INTERFACE_MAP_ENTRY(nsIChannelEventSink)
NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIStreamListener)
NS_INTERFACE_MAP_END
NS_IMPL_CYCLE_COLLECTING_ADDREF(WebVTTLoadListener)
NS_IMPL_CYCLE_COLLECTING_RELEASE(WebVTTLoadListener)
#ifdef PR_LOGGING
PRLogModuleInfo* gTextTrackLog;
# define LOG(...) PR_LOG(gTextTrackLog, PR_LOG_DEBUG, (__VA_ARGS__))
#else
# define LOG(msg)
#endif
WebVTTLoadListener::WebVTTLoadListener(HTMLTrackElement* aElement)
: mElement(aElement)
{
MOZ_ASSERT(mElement, "Must pass an element to the callback");
#ifdef PR_LOGGING
if (!gTextTrackLog) {
gTextTrackLog = PR_NewLogModule("TextTrack");
}
#endif
LOG("WebVTTLoadListener created.");
}
WebVTTLoadListener::~WebVTTLoadListener()
{
LOG("WebVTTLoadListener destroyed.");
}
nsresult
WebVTTLoadListener::LoadResource()
{
if (!HTMLTrackElement::IsWebVTTEnabled()) {
NS_WARNING("WebVTT support disabled."
" See media.webvtt.enabled in about:config. ");
return NS_ERROR_FAILURE;
}
LOG("Loading text track resource.");
mElement->mReadyState = HTMLTrackElement::LOADING;
return NS_OK;
}
NS_IMETHODIMP
WebVTTLoadListener::OnStartRequest(nsIRequest* aRequest,
nsISupports* aContext)
{
return NS_OK;
}
NS_IMETHODIMP
WebVTTLoadListener::OnStopRequest(nsIRequest* aRequest,
nsISupports* aContext,
nsresult aStatus)
{
// Flush parser here.
if(mElement->mReadyState != HTMLTrackElement::ERROR) {
mElement->mReadyState = HTMLTrackElement::LOADED;
}
return NS_OK;
}
NS_IMETHODIMP
WebVTTLoadListener::OnDataAvailable(nsIRequest* aRequest,
nsISupports* aContext,
nsIInputStream* aStream,
uint64_t aOffset,
uint32_t aCount)
{
uint32_t count = aCount;
while (count > 0) {
uint32_t read;
nsresult rv = aStream->ReadSegments(ParseChunk, this, count, &read);
NS_ENSURE_SUCCESS(rv, rv);
if (!read) {
return NS_ERROR_FAILURE;
}
count -= read;
}
return NS_OK;
}
NS_IMETHODIMP
WebVTTLoadListener::AsyncOnChannelRedirect(nsIChannel* aOldChannel,
nsIChannel* aNewChannel,
uint32_t aFlags,
nsIAsyncVerifyRedirectCallback* cb)
{
if (mElement) {
mElement->OnChannelRedirect(aOldChannel, aNewChannel, aFlags);
}
return NS_OK;
}
NS_IMETHODIMP
WebVTTLoadListener::GetInterface(const nsIID &aIID,
void** aResult)
{
return QueryInterface(aIID, aResult);
}
NS_METHOD
WebVTTLoadListener::ParseChunk(nsIInputStream* aInStream, void* aClosure,
const char* aFromSegment, uint32_t aToOffset,
uint32_t aCount, uint32_t* aWriteCount)
{
// Call parser incrementally on new data.
if (1) {
LOG("WebVTT parser disabled.");
LOG("Unable to parse chunk of WEBVTT text. Aborting.");
*aWriteCount = 0;
return NS_ERROR_FAILURE;
}
*aWriteCount = aCount;
return NS_OK;
}
} // namespace dom
} // namespace mozilla

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

@ -0,0 +1,72 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_dom_WebVTTLoadListener_h
#define mozilla_dom_WebVTTLoadListener_h
#include "nsIStreamListener.h"
#include "nsIChannelEventSink.h"
#include "nsIInterfaceRequestor.h"
#include "nsAutoPtr.h"
#include "nsAutoRef.h"
#include "nsCycleCollectionParticipant.h"
namespace mozilla {
namespace dom {
class HTMLTrackElement;
/**
* Class that manages the WebVTT parsing library and functions as an
* interface between Gecko and WebVTT.
*
* Currently it's only designed to work with an HTMLTrackElement. The
* HTMLTrackElement controls the lifetime of the WebVTTLoadListener.
*
* The workflow of this class is as follows:
* - Gets Loaded via an HTMLTrackElement class.
* - As the HTMLTrackElement class gets new data WebVTTLoadListener's
* OnDataAvailable() function is called and data is passed to the WebVTT
* parser.
* - When the WebVTT parser has finished a cue it will call the callbacks
* that are exposed by the WebVTTLoadListener.
* - When it has returned a cue successfully the WebVTTLoadListener will create
* a new TextTrackCue and add it to the HTMLTrackElement's TextTrack.
*/
class WebVTTLoadListener MOZ_FINAL : public nsIStreamListener,
public nsIChannelEventSink,
public nsIInterfaceRequestor
{
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_NSIREQUESTOBSERVER
NS_DECL_NSISTREAMLISTENER
NS_DECL_NSICHANNELEVENTSINK
NS_DECL_NSIINTERFACEREQUESTOR
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(WebVTTLoadListener,
nsIStreamListener)
public:
WebVTTLoadListener(HTMLTrackElement* aElement);
~WebVTTLoadListener();
// Loads the WebVTT parser. Must call this function in order to the
// WebVTTLoadListener to be ready to accept data.
nsresult LoadResource();
private:
static NS_METHOD ParseChunk(nsIInputStream* aInStream, void* aClosure,
const char* aFromSegment, uint32_t aToOffset,
uint32_t aCount, uint32_t* aWriteCount);
nsRefPtr<HTMLTrackElement> mElement;
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_WebVTTLoadListener_h

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

@ -4,12 +4,11 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
PARALLEL_DIRS += [
'encoder',
'mediasource',
'webaudio',
'webvtt'
]
PARALLEL_DIRS += ['encoder']
PARALLEL_DIRS += ['mediasource']
PARALLEL_DIRS += ['webaudio']
if CONFIG['MOZ_RAW']:
PARALLEL_DIRS += ['raw']
@ -141,7 +140,7 @@ CPP_SOURCES += [
'VideoSegment.cpp',
'VideoStreamTrack.cpp',
'VideoUtils.cpp',
'WebVTTListener.cpp',
'WebVTTLoadListener.cpp',
]
FAIL_ON_WARNINGS = True

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

@ -1,3 +0,0 @@
# WebVTTParserWrapper
component {1604a67f-3b72-4027-bcba-6dddd5be6b10} WebVTTParserWrapper.js
contract @mozilla.org/webvttParserWrapper;1 {1604a67f-3b72-4027-bcba-6dddd5be6b10}

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

@ -1,62 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
// TODO: Import vtt.js
var Ci = Components.interfaces;
var WEBVTTPARSERWRAPPER_CID = "{1604a67f-3b72-4027-bcba-6dddd5be6b10}";
var WEBVTTPARSERWRAPPER_CONTRACTID = "@mozilla.org/webvttParserWrapper;1";
function WebVTTParserWrapper()
{
// Nothing
}
WebVTTParserWrapper.prototype =
{
loadParser: function(window)
{
// TODO: Instantiate JS WebVTT parser
},
parse: function(data, count)
{
// We can safely translate the string data to a Uint8Array as we are
// guaranteed character codes only from \u0000 => \u00ff
var buffer = new Uint8Array(count);
for (var i = 0; i < count; i++) {
buffer[i] = data.charCodeAt(i);
}
// TODO: Call parse on JS WebVTT parser
},
flush: function()
{
// TODO: Call flush on JS WebVTT parser
},
watch: function(callback)
{
// TODO: Set callbacks for oncue and onregion for JS WebVTT parser
},
convertCueToDOMTree: function(window, cue)
{
// TODO: Call convertCueToDOMTree on JS WebVTT parser
},
classDescription: "Wrapper for the JS WebVTTParser (vtt.js)",
classID: Components.ID(WEBVTTPARSERWRAPPER_CID),
QueryInterface: XPCOMUtils.generateQI([Ci.nsIWebVTTParserWrapper]),
classInfo: XPCOMUtils.generateCI({
classID: WEBVTTPARSERWRAPPER_CID,
contractID: WEBVTTPARSERWRAPPER_CONTRACTID,
interfaces: [Ci.nsIWebVTTParserWrapper]
})
};
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([WebVTTParserWrapper]);

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

@ -1,19 +0,0 @@
# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
XPIDL_SOURCES += [
'nsIWebVTTListener.idl',
'nsIWebVTTParserWrapper.idl',
]
MODULE = 'webvtt'
XPIDL_MODULE = 'webvtt'
EXTRA_COMPONENTS += [
'WebVTT.manifest',
'WebVTTParserWrapper.js',
]

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

@ -1,29 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsISupports.idl"
/**
* Listener for a JS WebVTT parser (vtt.js).
*/
[scriptable, uuid(2953cf08-403e-4419-8d20-ce286aac026b)]
interface nsIWebVTTListener : nsISupports
{
/**
* Is called when the WebVTTParser successfully parses a WebVTT cue.
*
* @param cue An object representing the data of a parsed WebVTT cue.
*/
[implicit_jscontext]
void onCue(in jsval cue);
/**
* Is called when the WebVTT parser successfully parses a WebVTT region.
*
* @param region An object representing the data of a parsed
* WebVTT region.
*/
[implicit_jscontext]
void onRegion(in jsval region);
};

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

@ -1,67 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsISupports.idl"
#include "nsIWebVTTListener.idl"
#include "nsIDOMHTMLElement.idl"
/**
* Interface for a wrapper of a JS WebVTT parser (vtt.js).
*/
[scriptable, uuid(1604a67f-3b72-4027-bcba-6dddd5be6b10)]
interface nsIWebVTTParserWrapper : nsISupports
{
/**
* Loads the JS WebVTTParser and sets it to use the passed window to create
* VTTRegions and VTTCues. This function must be called before calling
* parse, flush, or watch.
*
* @param window The window that the parser will use to create VTTCues and
* VTTRegions.
*
*/
void loadParser(in nsIDOMWindow window);
/**
* Attempts to parse the stream's data as WebVTT format. When it successfully
* parses a WebVTT region or WebVTT cue it will create a VTTRegion or VTTCue
* object and pass it back to the callee through its callbacks.
*
* @param data The data stream that contains the WebVTT data received by the
* Necko consumer so far.
* @param count The number of bytes in data to be parsed.
*/
void parse(in string data, in long count);
/**
* Flush indicates that no more data is expected from the stream. As such the
* parser should try to parse any kind of partial data it has.
*/
void flush();
/**
* Set this parser object to use an nsIWebVTTListener object for its onCue
* and onRegion callbacks.
*
* @param callback The nsIWebVTTListener object that exposes onCue and
* onRegion callbacks for the parser.
*/
void watch(in nsIWebVTTListener callback);
/**
* Convert the text content of a WebVTT cue to a document fragment so that
* we can display it on the page.
*
* @param window A window object with which the document fragment will be
* created.
* @param cue The cue whose content will be converted to a document
* fragment.
*/
nsIDOMHTMLElement convertCueToDOMTree(in nsIDOMWindow window,
in nsISupports cue);
};
%{C++
#define NS_WEBVTTPARSERWRAPPER_CONTRACTID "@mozilla.org/webvttParserWrapper;1"
%}

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

@ -331,9 +331,6 @@
@BINPATH@/components/amContentHandler.js
@BINPATH@/components/amWebInstallListener.js
@BINPATH@/components/nsBlocklistService.js
@BINPATH@/components/webvtt.xpt
@BINPATH@/components/WebVTT.manifest
@BINPATH@/components/WebVTTParserWrapper.js
#ifdef MOZ_UPDATER
@BINPATH@/components/nsUpdateService.manifest