2008-07-09 01:22:20 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2010-03-14 18:44:37 -07:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
2008-07-09 01:22:20 -07:00
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is the Mozilla Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2007
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Chris Double <chris.double@double.co.nz>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2009-09-29 14:32:44 -07:00
|
|
|
|
2011-10-10 22:50:08 -07:00
|
|
|
#include "mozilla/Util.h"
|
|
|
|
|
2008-07-09 01:22:20 -07:00
|
|
|
#include "nsIDOMHTMLMediaElement.h"
|
|
|
|
#include "nsIDOMHTMLSourceElement.h"
|
|
|
|
#include "nsHTMLMediaElement.h"
|
2010-08-25 01:43:00 -07:00
|
|
|
#include "nsTimeRanges.h"
|
2008-07-09 01:22:20 -07:00
|
|
|
#include "nsGenericHTMLElement.h"
|
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsSize.h"
|
|
|
|
#include "nsIFrame.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIDOMDocument.h"
|
|
|
|
#include "nsDOMError.h"
|
|
|
|
#include "nsNodeInfoManager.h"
|
|
|
|
#include "nsNetUtil.h"
|
|
|
|
#include "nsXPCOMStrings.h"
|
|
|
|
#include "nsThreadUtils.h"
|
2010-09-02 17:03:03 -07:00
|
|
|
#include "nsIThreadInternal.h"
|
2008-12-16 18:11:07 -08:00
|
|
|
#include "nsContentUtils.h"
|
2010-09-09 21:20:10 -07:00
|
|
|
#include "nsFrameManager.h"
|
2008-07-09 01:22:20 -07:00
|
|
|
#include "nsIScriptSecurityManager.h"
|
|
|
|
#include "nsIXPConnect.h"
|
|
|
|
#include "jsapi.h"
|
|
|
|
|
|
|
|
#include "nsITimer.h"
|
|
|
|
|
|
|
|
#include "nsEventDispatcher.h"
|
2010-08-25 01:43:00 -07:00
|
|
|
#include "nsMediaError.h"
|
2008-10-29 22:20:08 -07:00
|
|
|
#include "nsICategoryManager.h"
|
2010-05-04 07:43:48 -07:00
|
|
|
#include "nsCharSeparatedTokenizer.h"
|
2009-09-14 19:30:43 -07:00
|
|
|
#include "nsMediaStream.h"
|
2008-07-09 01:22:20 -07:00
|
|
|
|
2010-03-01 15:41:49 -08:00
|
|
|
#include "nsIDOMHTMLVideoElement.h"
|
2009-01-24 03:00:17 -08:00
|
|
|
#include "nsIContentPolicy.h"
|
|
|
|
#include "nsContentPolicyUtils.h"
|
|
|
|
#include "nsContentErrors.h"
|
|
|
|
#include "nsCrossSiteListenerProxy.h"
|
2009-03-08 13:59:08 -07:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2010-03-17 20:00:18 -07:00
|
|
|
#include "nsICachingChannel.h"
|
2009-12-10 20:02:13 -08:00
|
|
|
#include "nsLayoutUtils.h"
|
|
|
|
#include "nsVideoFrame.h"
|
2010-03-01 15:41:49 -08:00
|
|
|
#include "BasicLayers.h"
|
2010-04-01 20:03:07 -07:00
|
|
|
#include <limits>
|
2010-04-22 17:26:38 -07:00
|
|
|
#include "nsIDocShellTreeItem.h"
|
2010-08-04 19:15:55 -07:00
|
|
|
#include "nsIAsyncVerifyRedirectCallback.h"
|
2010-09-02 17:03:03 -07:00
|
|
|
#include "nsIAppShell.h"
|
|
|
|
#include "nsWidgetsCID.h"
|
2009-01-24 03:00:17 -08:00
|
|
|
|
2010-08-25 06:10:00 -07:00
|
|
|
#include "nsIPrivateDOMEvent.h"
|
|
|
|
#include "nsIDOMNotifyAudioAvailableEvent.h"
|
2011-08-24 16:42:23 -07:00
|
|
|
#include "nsMediaFragmentURIParser.h"
|
2011-11-24 18:06:22 -08:00
|
|
|
#include "nsURIHashKey.h"
|
2010-08-25 06:10:00 -07:00
|
|
|
|
2008-07-29 23:50:14 -07:00
|
|
|
#ifdef MOZ_OGG
|
|
|
|
#include "nsOggDecoder.h"
|
|
|
|
#endif
|
2008-11-06 12:53:20 -08:00
|
|
|
#ifdef MOZ_WAVE
|
|
|
|
#include "nsWaveDecoder.h"
|
|
|
|
#endif
|
2010-06-08 16:31:27 -07:00
|
|
|
#ifdef MOZ_WEBM
|
|
|
|
#include "nsWebMDecoder.h"
|
|
|
|
#endif
|
2010-07-26 12:35:16 -07:00
|
|
|
#ifdef MOZ_RAW
|
|
|
|
#include "nsRawDecoder.h"
|
|
|
|
#endif
|
2008-07-29 23:50:14 -07:00
|
|
|
|
2009-09-29 14:32:44 -07:00
|
|
|
#ifdef PR_LOGGING
|
|
|
|
static PRLogModuleInfo* gMediaElementLog;
|
|
|
|
static PRLogModuleInfo* gMediaElementEventsLog;
|
|
|
|
#define LOG(type, msg) PR_LOG(gMediaElementLog, type, msg)
|
|
|
|
#define LOG_EVENT(type, msg) PR_LOG(gMediaElementEventsLog, type, msg)
|
|
|
|
#else
|
|
|
|
#define LOG(type, msg)
|
|
|
|
#define LOG_EVENT(type, msg)
|
|
|
|
#endif
|
2009-02-19 18:49:00 -08:00
|
|
|
|
2010-04-23 12:50:28 -07:00
|
|
|
#include "nsIContentSecurityPolicy.h"
|
|
|
|
#include "nsIChannelPolicy.h"
|
|
|
|
#include "nsChannelPolicy.h"
|
|
|
|
|
2011-05-24 23:31:59 -07:00
|
|
|
#include "mozilla/Preferences.h"
|
|
|
|
|
|
|
|
using namespace mozilla;
|
2010-10-25 05:17:38 -07:00
|
|
|
using namespace mozilla::dom;
|
2010-03-01 15:41:49 -08:00
|
|
|
using namespace mozilla::layers;
|
|
|
|
|
2010-11-24 10:34:57 -08:00
|
|
|
// Number of milliseconds between timeupdate events as defined by spec
|
|
|
|
#define TIMEUPDATE_MS 250
|
|
|
|
|
2009-10-01 07:10:13 -07:00
|
|
|
// Under certain conditions there may be no-one holding references to
|
|
|
|
// a media element from script, DOM parent, etc, but the element may still
|
|
|
|
// fire meaningful events in the future so we can't destroy it yet:
|
|
|
|
// 1) If the element is delaying the load event (or would be, if it were
|
|
|
|
// in a document), then events up to loadeddata or error could be fired,
|
|
|
|
// so we need to stay alive.
|
|
|
|
// 2) If the element is not paused and playback has not ended, then
|
|
|
|
// we will (or might) play, sending timeupdate and ended events and possibly
|
|
|
|
// audio output, so we need to stay alive.
|
|
|
|
// 3) if the element is seeking then we will fire seeking events and possibly
|
|
|
|
// start playing afterward, so we need to stay alive.
|
|
|
|
// 4) If autoplay could start playback in this element (if we got enough data),
|
|
|
|
// then we need to stay alive.
|
|
|
|
// 5) if the element is currently loading and not suspended,
|
|
|
|
// script might be waiting for progress events or a 'suspend' event,
|
|
|
|
// so we need to stay alive. If we're already suspended then (all other
|
|
|
|
// conditions being met) it's OK to just disappear without firing any more
|
|
|
|
// events, since we have the freedom to remain suspended indefinitely. Note
|
|
|
|
// that we could use this 'suspended' loophole to garbage-collect a suspended
|
|
|
|
// element in case 4 even if it had 'autoplay' set, but we choose not to.
|
|
|
|
// If someone throws away all references to a loading 'autoplay' element
|
|
|
|
// sound should still eventually play.
|
|
|
|
//
|
|
|
|
// Media elements owned by inactive documents (i.e. documents not contained in any
|
|
|
|
// document viewer) should never hold a self-reference because none of the
|
|
|
|
// above conditions are allowed: the element will stop loading and playing
|
|
|
|
// and never resume loading or playing unless its owner document changes to
|
|
|
|
// an active document (which can only happen if there is an external reference
|
|
|
|
// to the element).
|
|
|
|
// Media elements with no owner doc should be able to hold a self-reference.
|
|
|
|
// Something native must have created the element and may expect it to
|
|
|
|
// stay alive to play.
|
|
|
|
|
|
|
|
// It's very important that any change in state which could change the value of
|
|
|
|
// needSelfReference in AddRemoveSelfReference be followed by a call to
|
|
|
|
// AddRemoveSelfReference before this element could die!
|
|
|
|
// It's especially important if needSelfReference would change to 'true',
|
|
|
|
// since if we neglect to add a self-reference, this element might be
|
|
|
|
// garbage collected while there are still event listeners that should
|
|
|
|
// receive events. If we neglect to remove the self-reference then the element
|
|
|
|
// just lives longer than it needs to.
|
|
|
|
|
2009-02-19 18:49:00 -08:00
|
|
|
class nsMediaEvent : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
nsMediaEvent(nsHTMLMediaElement* aElement) :
|
|
|
|
mElement(aElement),
|
2009-03-08 13:59:08 -07:00
|
|
|
mLoadID(mElement->GetCurrentLoadID()) {}
|
2009-02-19 18:49:00 -08:00
|
|
|
~nsMediaEvent() {}
|
|
|
|
|
|
|
|
NS_IMETHOD Run() = 0;
|
|
|
|
|
|
|
|
protected:
|
2011-09-28 23:19:26 -07:00
|
|
|
bool IsCancelled() {
|
2009-03-08 13:59:08 -07:00
|
|
|
return mElement->GetCurrentLoadID() != mLoadID;
|
2009-02-19 18:49:00 -08:00
|
|
|
}
|
|
|
|
|
2010-02-24 11:14:14 -08:00
|
|
|
nsRefPtr<nsHTMLMediaElement> mElement;
|
2009-03-08 13:59:08 -07:00
|
|
|
PRUint32 mLoadID;
|
2009-02-19 18:49:00 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
class nsAsyncEventRunner : public nsMediaEvent
|
2008-07-09 01:22:20 -07:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
nsString mName;
|
2009-11-05 23:32:52 -08:00
|
|
|
|
2008-07-09 01:22:20 -07:00
|
|
|
public:
|
2010-09-09 20:29:06 -07:00
|
|
|
nsAsyncEventRunner(const nsAString& aName, nsHTMLMediaElement* aElement) :
|
|
|
|
nsMediaEvent(aElement), mName(aName)
|
2008-07-09 01:22:20 -07:00
|
|
|
{
|
|
|
|
}
|
2009-11-05 23:32:52 -08:00
|
|
|
|
2010-08-25 06:10:00 -07:00
|
|
|
NS_IMETHOD Run()
|
|
|
|
{
|
2009-02-19 18:49:00 -08:00
|
|
|
// Silently cancel if our load has been cancelled.
|
|
|
|
if (IsCancelled())
|
|
|
|
return NS_OK;
|
2010-08-25 06:10:00 -07:00
|
|
|
|
2010-09-09 20:29:06 -07:00
|
|
|
return mElement->DispatchEvent(mName);
|
2008-07-09 01:22:20 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-09-02 17:03:03 -07:00
|
|
|
class nsSourceErrorEventRunner : public nsMediaEvent
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
nsCOMPtr<nsIContent> mSource;
|
2009-02-15 17:05:28 -08:00
|
|
|
public:
|
2010-09-02 17:03:03 -07:00
|
|
|
nsSourceErrorEventRunner(nsHTMLMediaElement* aElement,
|
|
|
|
nsIContent* aSource)
|
|
|
|
: nsMediaEvent(aElement),
|
|
|
|
mSource(aSource)
|
|
|
|
{
|
2009-02-15 17:05:28 -08:00
|
|
|
}
|
|
|
|
|
2009-02-19 18:49:00 -08:00
|
|
|
NS_IMETHOD Run() {
|
2010-09-02 17:03:03 -07:00
|
|
|
// Silently cancel if our load has been cancelled.
|
|
|
|
if (IsCancelled())
|
|
|
|
return NS_OK;
|
|
|
|
LOG_EVENT(PR_LOG_DEBUG, ("%p Dispatching simple event source error", mElement.get()));
|
2011-10-18 03:53:36 -07:00
|
|
|
return nsContentUtils::DispatchTrustedEvent(mElement->OwnerDoc(),
|
2010-09-02 17:03:03 -07:00
|
|
|
mSource,
|
|
|
|
NS_LITERAL_STRING("error"),
|
2011-09-29 16:34:37 -07:00
|
|
|
false,
|
|
|
|
true);
|
2009-02-19 18:49:00 -08:00
|
|
|
}
|
2009-02-15 17:05:28 -08:00
|
|
|
};
|
|
|
|
|
2009-07-09 19:03:03 -07:00
|
|
|
/**
|
|
|
|
* There is a reference cycle involving this class: MediaLoadListener
|
|
|
|
* holds a reference to the nsHTMLMediaElement, which holds a reference
|
|
|
|
* to an nsIChannel, which holds a reference to this listener.
|
|
|
|
* We break the reference cycle in OnStartRequest by clearing mElement.
|
|
|
|
*/
|
2009-05-13 14:52:50 -07:00
|
|
|
class nsHTMLMediaElement::MediaLoadListener : public nsIStreamListener,
|
|
|
|
public nsIChannelEventSink,
|
2010-02-24 11:14:14 -08:00
|
|
|
public nsIInterfaceRequestor,
|
|
|
|
public nsIObserver
|
2008-12-15 19:32:03 -08:00
|
|
|
{
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIREQUESTOBSERVER
|
|
|
|
NS_DECL_NSISTREAMLISTENER
|
2009-05-13 14:52:50 -07:00
|
|
|
NS_DECL_NSICHANNELEVENTSINK
|
2010-02-24 11:14:14 -08:00
|
|
|
NS_DECL_NSIOBSERVER
|
2009-05-13 14:52:50 -07:00
|
|
|
NS_DECL_NSIINTERFACEREQUESTOR
|
2008-12-15 19:32:03 -08:00
|
|
|
|
|
|
|
public:
|
2009-02-19 18:49:00 -08:00
|
|
|
MediaLoadListener(nsHTMLMediaElement* aElement)
|
2011-05-03 19:43:48 -07:00
|
|
|
: mElement(aElement),
|
|
|
|
mLoadID(aElement->GetCurrentLoadID())
|
2008-12-15 19:32:03 -08:00
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(mElement, "Must pass an element to call back");
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsRefPtr<nsHTMLMediaElement> mElement;
|
|
|
|
nsCOMPtr<nsIStreamListener> mNextListener;
|
2011-05-03 19:43:48 -07:00
|
|
|
PRUint32 mLoadID;
|
2008-12-15 19:32:03 -08:00
|
|
|
};
|
|
|
|
|
2010-02-24 11:14:14 -08:00
|
|
|
NS_IMPL_ISUPPORTS5(nsHTMLMediaElement::MediaLoadListener, nsIRequestObserver,
|
2009-05-13 14:52:50 -07:00
|
|
|
nsIStreamListener, nsIChannelEventSink,
|
2010-02-24 11:14:14 -08:00
|
|
|
nsIInterfaceRequestor, nsIObserver)
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLMediaElement::MediaLoadListener::Observe(nsISupports* aSubject,
|
|
|
|
const char* aTopic, const PRUnichar* aData)
|
|
|
|
{
|
|
|
|
nsContentUtils::UnregisterShutdownObserver(this);
|
|
|
|
|
|
|
|
// Clear mElement to break cycle so we don't leak on shutdown
|
|
|
|
mElement = nsnull;
|
2010-02-24 14:48:32 -08:00
|
|
|
return NS_OK;
|
2010-02-24 11:14:14 -08:00
|
|
|
}
|
2008-12-15 19:32:03 -08:00
|
|
|
|
2009-02-19 18:49:00 -08:00
|
|
|
NS_IMETHODIMP nsHTMLMediaElement::MediaLoadListener::OnStartRequest(nsIRequest* aRequest, nsISupports* aContext)
|
2008-12-15 19:32:03 -08:00
|
|
|
{
|
2010-02-24 11:14:14 -08:00
|
|
|
nsContentUtils::UnregisterShutdownObserver(this);
|
|
|
|
|
2009-07-09 19:03:03 -07:00
|
|
|
// The element is only needed until we've had a chance to call
|
|
|
|
// InitializeDecoderForChannel. So make sure mElement is cleared here.
|
|
|
|
nsRefPtr<nsHTMLMediaElement> element;
|
|
|
|
element.swap(mElement);
|
|
|
|
|
2011-05-03 19:43:48 -07:00
|
|
|
if (mLoadID != element->GetCurrentLoadID()) {
|
|
|
|
// The channel has been cancelled before we had a chance to create
|
|
|
|
// a decoder. Abort, don't dispatch an "error" event, as the new load
|
|
|
|
// may not be in an error state.
|
|
|
|
return NS_BINDING_ABORTED;
|
|
|
|
}
|
|
|
|
|
2009-03-17 17:34:48 -07:00
|
|
|
// Don't continue to load if the request failed or has been canceled.
|
|
|
|
nsresult status;
|
2011-11-15 23:50:19 -08:00
|
|
|
nsresult rv = aRequest->GetStatus(&status);
|
2009-03-17 17:34:48 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (NS_FAILED(status)) {
|
2009-07-09 19:03:03 -07:00
|
|
|
if (element)
|
|
|
|
element->NotifyLoadError();
|
2009-03-17 17:34:48 -07:00
|
|
|
return status;
|
|
|
|
}
|
2008-12-15 19:32:03 -08:00
|
|
|
|
|
|
|
nsCOMPtr<nsIChannel> channel = do_QueryInterface(aRequest);
|
|
|
|
if (channel &&
|
2009-07-09 19:03:03 -07:00
|
|
|
element &&
|
2009-07-09 21:05:40 -07:00
|
|
|
NS_SUCCEEDED(rv = element->InitializeDecoderForChannel(channel, getter_AddRefs(mNextListener))) &&
|
2008-12-15 19:32:03 -08:00
|
|
|
mNextListener) {
|
|
|
|
rv = mNextListener->OnStartRequest(aRequest, aContext);
|
|
|
|
} else {
|
2009-02-15 08:26:32 -08:00
|
|
|
// If InitializeDecoderForChannel() returned an error, fire a network
|
|
|
|
// error.
|
2009-07-09 19:03:03 -07:00
|
|
|
if (NS_FAILED(rv) && !mNextListener && element) {
|
2009-02-19 18:49:00 -08:00
|
|
|
// Load failed, attempt to load the next candidate resource. If there
|
2009-09-21 17:08:13 -07:00
|
|
|
// are none, this will trigger a MEDIA_ERR_SRC_NOT_SUPPORTED error.
|
2009-07-09 19:03:03 -07:00
|
|
|
element->NotifyLoadError();
|
2009-02-15 08:26:32 -08:00
|
|
|
}
|
|
|
|
// If InitializeDecoderForChannel did not return a listener (but may
|
|
|
|
// have otherwise succeeded), we abort the connection since we aren't
|
|
|
|
// interested in keeping the channel alive ourselves.
|
2008-12-15 19:32:03 -08:00
|
|
|
rv = NS_BINDING_ABORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2009-02-19 18:49:00 -08:00
|
|
|
NS_IMETHODIMP nsHTMLMediaElement::MediaLoadListener::OnStopRequest(nsIRequest* aRequest, nsISupports* aContext,
|
2011-11-15 23:50:19 -08:00
|
|
|
nsresult aStatus)
|
2008-12-15 19:32:03 -08:00
|
|
|
{
|
|
|
|
if (mNextListener) {
|
|
|
|
return mNextListener->OnStopRequest(aRequest, aContext, aStatus);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-02-19 18:49:00 -08:00
|
|
|
NS_IMETHODIMP nsHTMLMediaElement::MediaLoadListener::OnDataAvailable(nsIRequest* aRequest, nsISupports* aContext,
|
2011-11-15 23:50:19 -08:00
|
|
|
nsIInputStream* aStream, PRUint32 aOffset,
|
|
|
|
PRUint32 aCount)
|
2008-12-15 19:32:03 -08:00
|
|
|
{
|
2009-05-04 23:13:26 -07:00
|
|
|
if (!mNextListener) {
|
|
|
|
NS_ERROR("Must have a chained listener; OnStartRequest should have canceled this request");
|
|
|
|
return NS_BINDING_ABORTED;
|
|
|
|
}
|
2008-12-15 19:32:03 -08:00
|
|
|
return mNextListener->OnDataAvailable(aRequest, aContext, aStream, aOffset, aCount);
|
|
|
|
}
|
|
|
|
|
2010-08-04 19:15:55 -07:00
|
|
|
NS_IMETHODIMP nsHTMLMediaElement::MediaLoadListener::AsyncOnChannelRedirect(nsIChannel* aOldChannel,
|
|
|
|
nsIChannel* aNewChannel,
|
|
|
|
PRUint32 aFlags,
|
|
|
|
nsIAsyncVerifyRedirectCallback* cb)
|
2009-05-13 14:52:50 -07:00
|
|
|
{
|
2010-08-04 19:15:55 -07:00
|
|
|
// TODO is this really correct?? See bug #579329.
|
2009-05-17 15:20:37 -07:00
|
|
|
if (mElement)
|
|
|
|
mElement->OnChannelRedirect(aOldChannel, aNewChannel, aFlags);
|
2009-05-13 14:52:50 -07:00
|
|
|
nsCOMPtr<nsIChannelEventSink> sink = do_QueryInterface(mNextListener);
|
|
|
|
if (sink)
|
2010-08-04 19:15:55 -07:00
|
|
|
return sink->AsyncOnChannelRedirect(aOldChannel, aNewChannel, aFlags, cb);
|
|
|
|
|
|
|
|
cb->OnRedirectVerifyCallback(NS_OK);
|
2009-05-13 14:52:50 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsHTMLMediaElement::MediaLoadListener::GetInterface(const nsIID & aIID, void **aResult)
|
|
|
|
{
|
|
|
|
return QueryInterface(aIID, aResult);
|
|
|
|
}
|
|
|
|
|
2009-03-08 13:59:08 -07:00
|
|
|
NS_IMPL_ADDREF_INHERITED(nsHTMLMediaElement, nsGenericHTMLElement)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsHTMLMediaElement, nsGenericHTMLElement)
|
2009-02-19 18:49:00 -08:00
|
|
|
|
2009-03-08 13:59:08 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(nsHTMLMediaElement)
|
2009-02-19 18:49:00 -08:00
|
|
|
|
2009-03-08 13:59:08 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsHTMLMediaElement, nsGenericHTMLElement)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mSourcePointer)
|
2009-03-08 14:01:03 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mLoadBlockedDoc)
|
2011-04-28 07:08:03 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mSourceLoadCandidate)
|
2009-03-08 13:59:08 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(nsHTMLMediaElement, nsGenericHTMLElement)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mSourcePointer)
|
2010-02-24 11:14:14 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mLoadBlockedDoc)
|
2011-04-28 07:08:03 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mSourceLoadCandidate)
|
2009-03-08 13:59:08 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsHTMLMediaElement)
|
2010-02-24 11:14:14 -08:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIObserver)
|
2009-03-08 13:59:08 -07:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(nsGenericHTMLElement)
|
2009-02-15 17:05:28 -08:00
|
|
|
|
2008-07-09 01:22:20 -07:00
|
|
|
// nsIDOMHTMLMediaElement
|
|
|
|
NS_IMPL_URI_ATTR(nsHTMLMediaElement, Src, src)
|
|
|
|
NS_IMPL_BOOL_ATTR(nsHTMLMediaElement, Controls, controls)
|
2008-07-29 21:55:27 -07:00
|
|
|
NS_IMPL_BOOL_ATTR(nsHTMLMediaElement, Autoplay, autoplay)
|
2011-11-20 14:59:01 -08:00
|
|
|
NS_IMPL_BOOL_ATTR(nsHTMLMediaElement, Loop, loop)
|
2011-12-15 11:36:46 -08:00
|
|
|
NS_IMPL_BOOL_ATTR(nsHTMLMediaElement, DefaultMuted, muted)
|
2011-07-15 03:18:27 -07:00
|
|
|
NS_IMPL_ENUM_ATTR_DEFAULT_VALUE(nsHTMLMediaElement, Preload, preload, NULL)
|
2008-07-09 01:22:20 -07:00
|
|
|
|
2009-02-19 20:05:07 -08:00
|
|
|
/* readonly attribute nsIDOMHTMLMediaElement mozAutoplayEnabled; */
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHODIMP nsHTMLMediaElement::GetMozAutoplayEnabled(bool *aAutoplayEnabled)
|
2009-02-19 20:05:07 -08:00
|
|
|
{
|
2010-10-14 17:13:29 -07:00
|
|
|
*aAutoplayEnabled = mAutoplayEnabled;
|
2009-02-19 20:05:07 -08:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-08-25 01:43:00 -07:00
|
|
|
/* readonly attribute nsIDOMMediaError error; */
|
|
|
|
NS_IMETHODIMP nsHTMLMediaElement::GetError(nsIDOMMediaError * *aError)
|
2008-07-09 01:22:20 -07:00
|
|
|
{
|
|
|
|
NS_IF_ADDREF(*aError = mError);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-07-29 21:55:27 -07:00
|
|
|
/* readonly attribute boolean ended; */
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHODIMP nsHTMLMediaElement::GetEnded(bool *aEnded)
|
2008-07-29 21:55:27 -07:00
|
|
|
{
|
2011-09-29 16:34:37 -07:00
|
|
|
*aEnded = mDecoder ? mDecoder->IsEnded() : false;
|
2008-07-29 21:55:27 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-07-09 01:22:20 -07:00
|
|
|
/* readonly attribute DOMString currentSrc; */
|
|
|
|
NS_IMETHODIMP nsHTMLMediaElement::GetCurrentSrc(nsAString & aCurrentSrc)
|
|
|
|
{
|
|
|
|
nsCAutoString src;
|
2011-08-24 16:42:23 -07:00
|
|
|
GetCurrentSpec(src);
|
2008-07-09 01:22:20 -07:00
|
|
|
aCurrentSrc = NS_ConvertUTF8toUTF16(src);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* readonly attribute unsigned short networkState; */
|
|
|
|
NS_IMETHODIMP nsHTMLMediaElement::GetNetworkState(PRUint16 *aNetworkState)
|
|
|
|
{
|
2008-07-09 02:50:08 -07:00
|
|
|
*aNetworkState = mNetworkState;
|
2008-07-09 01:22:20 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-05-17 15:20:37 -07:00
|
|
|
nsresult
|
|
|
|
nsHTMLMediaElement::OnChannelRedirect(nsIChannel *aChannel,
|
|
|
|
nsIChannel *aNewChannel,
|
|
|
|
PRUint32 aFlags)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aChannel == mChannel, "Channels should match!");
|
|
|
|
mChannel = aNewChannel;
|
2010-04-21 17:32:52 -07:00
|
|
|
|
|
|
|
// Handle forwarding of Range header so that the intial detection
|
|
|
|
// of seeking support (via result code 206) works across redirects.
|
|
|
|
nsCOMPtr<nsIHttpChannel> http = do_QueryInterface(aChannel);
|
|
|
|
NS_ENSURE_STATE(http);
|
|
|
|
|
|
|
|
NS_NAMED_LITERAL_CSTRING(rangeHdr, "Range");
|
|
|
|
|
|
|
|
nsCAutoString rangeVal;
|
|
|
|
if (NS_SUCCEEDED(http->GetRequestHeader(rangeHdr, rangeVal))) {
|
|
|
|
NS_ENSURE_STATE(!rangeVal.IsEmpty());
|
|
|
|
|
|
|
|
http = do_QueryInterface(aNewChannel);
|
|
|
|
NS_ENSURE_STATE(http);
|
|
|
|
|
2011-09-29 16:34:37 -07:00
|
|
|
nsresult rv = http->SetRequestHeader(rangeHdr, rangeVal, false);
|
2010-04-21 17:32:52 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2009-05-17 15:20:37 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-03-08 13:59:08 -07:00
|
|
|
void nsHTMLMediaElement::AbortExistingLoads()
|
2008-10-29 22:20:08 -07:00
|
|
|
{
|
2009-03-08 13:59:08 -07:00
|
|
|
// Abort any already-running instance of the resource selection algorithm.
|
|
|
|
mLoadWaitStatus = NOT_WAITING;
|
|
|
|
|
|
|
|
// Set a new load ID. This will cause events which were enqueued
|
2009-03-15 23:05:28 -07:00
|
|
|
// with a different load ID to silently be cancelled.
|
2009-03-08 13:59:08 -07:00
|
|
|
mCurrentLoadID++;
|
2009-02-19 18:49:00 -08:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool fireTimeUpdate = false;
|
2011-11-24 18:06:22 -08:00
|
|
|
|
2008-12-15 19:32:03 -08:00
|
|
|
if (mDecoder) {
|
2011-11-24 18:06:22 -08:00
|
|
|
RemoveMediaElementFromURITable();
|
2010-07-25 15:45:41 -07:00
|
|
|
fireTimeUpdate = mDecoder->GetCurrentTime() != 0.0;
|
2008-12-15 19:32:03 -08:00
|
|
|
mDecoder->Shutdown();
|
|
|
|
mDecoder = nsnull;
|
2008-10-29 22:20:08 -07:00
|
|
|
}
|
2011-11-24 18:06:22 -08:00
|
|
|
mLoadingSrc = nsnull;
|
2008-10-29 22:20:08 -07:00
|
|
|
|
2009-03-08 13:59:08 -07:00
|
|
|
if (mNetworkState == nsIDOMHTMLMediaElement::NETWORK_LOADING ||
|
|
|
|
mNetworkState == nsIDOMHTMLMediaElement::NETWORK_IDLE)
|
|
|
|
{
|
2010-09-09 20:29:06 -07:00
|
|
|
DispatchEvent(NS_LITERAL_STRING("abort"));
|
2008-07-09 01:22:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
mError = nsnull;
|
2011-09-29 16:34:37 -07:00
|
|
|
mLoadedFirstFrame = false;
|
|
|
|
mAutoplaying = true;
|
|
|
|
mIsLoadingFromSourceChildren = false;
|
|
|
|
mSuspendedAfterFirstFrame = false;
|
|
|
|
mAllowSuspendAfterFirstFrame = true;
|
2011-11-24 18:06:22 -08:00
|
|
|
mLoadIsSuspended = false;
|
2010-07-25 15:45:18 -07:00
|
|
|
mSourcePointer = nsnull;
|
2008-07-09 01:22:20 -07:00
|
|
|
|
2008-11-05 14:53:29 -08:00
|
|
|
// TODO: The playback rate must be set to the default playback rate.
|
2008-07-09 01:22:20 -07:00
|
|
|
|
2008-12-14 19:38:16 -08:00
|
|
|
if (mNetworkState != nsIDOMHTMLMediaElement::NETWORK_EMPTY) {
|
|
|
|
mNetworkState = nsIDOMHTMLMediaElement::NETWORK_EMPTY;
|
|
|
|
ChangeReadyState(nsIDOMHTMLMediaElement::HAVE_NOTHING);
|
2011-09-29 16:34:37 -07:00
|
|
|
mPaused = true;
|
2009-03-08 13:59:08 -07:00
|
|
|
|
2010-07-25 15:45:41 -07:00
|
|
|
if (fireTimeUpdate) {
|
|
|
|
// Since we destroyed the decoder above, the current playback position
|
|
|
|
// will now be reported as 0. The playback position was non-zero when
|
|
|
|
// we destroyed the decoder, so fire a timeupdate event so that the
|
|
|
|
// change will be reflected in the controls.
|
2011-09-29 16:34:37 -07:00
|
|
|
FireTimeUpdate(false);
|
2010-07-25 15:45:41 -07:00
|
|
|
}
|
2010-09-09 20:29:06 -07:00
|
|
|
DispatchEvent(NS_LITERAL_STRING("emptied"));
|
2008-07-09 01:22:20 -07:00
|
|
|
}
|
2009-03-08 14:01:03 -07:00
|
|
|
|
2009-10-01 07:10:13 -07:00
|
|
|
// We may have changed mPaused, mAutoplaying, mNetworkState and other
|
|
|
|
// things which can affect AddRemoveSelfReference
|
|
|
|
AddRemoveSelfReference();
|
|
|
|
|
2011-09-29 16:34:37 -07:00
|
|
|
mIsRunningSelectResource = false;
|
2008-12-15 19:32:03 -08:00
|
|
|
}
|
|
|
|
|
2009-09-21 17:08:13 -07:00
|
|
|
void nsHTMLMediaElement::NoSupportedMediaSourceError()
|
2009-02-15 08:26:32 -08:00
|
|
|
{
|
2009-10-01 07:10:13 -07:00
|
|
|
NS_ASSERTION(mDelayingLoadEvent, "Load event not delayed during source selection?");
|
|
|
|
|
2010-08-25 01:43:00 -07:00
|
|
|
mError = new nsMediaError(nsIDOMMediaError::MEDIA_ERR_SRC_NOT_SUPPORTED);
|
2009-03-08 13:59:08 -07:00
|
|
|
mNetworkState = nsIDOMHTMLMediaElement::NETWORK_NO_SOURCE;
|
2010-09-09 20:29:06 -07:00
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("error"));
|
2009-10-01 07:10:13 -07:00
|
|
|
// This clears mDelayingLoadEvent, so AddRemoveSelfReference will be called
|
2011-09-29 16:34:37 -07:00
|
|
|
ChangeDelayLoadStatus(false);
|
2009-02-15 08:26:32 -08:00
|
|
|
}
|
|
|
|
|
2010-09-02 17:03:03 -07:00
|
|
|
typedef void (nsHTMLMediaElement::*SyncSectionFn)();
|
|
|
|
|
|
|
|
// Runs a "synchronous section", a function that must run once the event loop
|
|
|
|
// has reached a "stable state". See:
|
|
|
|
// http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html#synchronous-section
|
|
|
|
class nsSyncSection : public nsMediaEvent
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
SyncSectionFn mClosure;
|
|
|
|
public:
|
|
|
|
nsSyncSection(nsHTMLMediaElement* aElement,
|
|
|
|
SyncSectionFn aClosure) :
|
|
|
|
nsMediaEvent(aElement),
|
|
|
|
mClosure(aClosure)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD Run() {
|
|
|
|
// Silently cancel if our load has been cancelled.
|
|
|
|
if (IsCancelled())
|
|
|
|
return NS_OK;
|
|
|
|
(mElement.get()->*mClosure)();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID);
|
|
|
|
|
|
|
|
// Asynchronously awaits a stable state, whereupon aClosure runs on the main
|
|
|
|
// thread. This adds an event which run aClosure to the appshell's list of
|
|
|
|
// sections synchronous the next time control returns to the event loop.
|
|
|
|
void AsyncAwaitStableState(nsHTMLMediaElement* aElement,
|
|
|
|
SyncSectionFn aClosure)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIRunnable> event = new nsSyncSection(aElement, aClosure);
|
|
|
|
nsCOMPtr<nsIAppShell> appShell = do_GetService(kAppShellCID);
|
|
|
|
appShell->RunInStableState(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsHTMLMediaElement::QueueLoadFromSourceTask()
|
|
|
|
{
|
2011-09-29 16:34:37 -07:00
|
|
|
ChangeDelayLoadStatus(true);
|
2010-09-02 17:03:03 -07:00
|
|
|
mNetworkState = nsIDOMHTMLMediaElement::NETWORK_LOADING;
|
|
|
|
AsyncAwaitStableState(this, &nsHTMLMediaElement::LoadFromSourceChildren);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsHTMLMediaElement::QueueSelectResourceTask()
|
|
|
|
{
|
|
|
|
// Don't allow multiple async select resource calls to be queued.
|
|
|
|
if (mIsRunningSelectResource)
|
|
|
|
return;
|
2011-09-29 16:34:37 -07:00
|
|
|
mIsRunningSelectResource = true;
|
2010-09-02 17:03:03 -07:00
|
|
|
mNetworkState = nsIDOMHTMLMediaElement::NETWORK_NO_SOURCE;
|
|
|
|
AsyncAwaitStableState(this, &nsHTMLMediaElement::SelectResource);
|
|
|
|
}
|
|
|
|
|
2008-12-15 19:32:03 -08:00
|
|
|
/* void load (); */
|
|
|
|
NS_IMETHODIMP nsHTMLMediaElement::Load()
|
|
|
|
{
|
2009-03-08 13:59:08 -07:00
|
|
|
if (mIsRunningLoadMethod)
|
2008-12-15 19:32:03 -08:00
|
|
|
return NS_OK;
|
2011-09-29 16:34:37 -07:00
|
|
|
SetPlayedOrSeeked(false);
|
|
|
|
mIsRunningLoadMethod = true;
|
2009-03-08 13:59:08 -07:00
|
|
|
AbortExistingLoads();
|
|
|
|
QueueSelectResourceTask();
|
2011-09-29 16:34:37 -07:00
|
|
|
mIsRunningLoadMethod = false;
|
2009-03-08 13:59:08 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool HasSourceChildren(nsIContent *aElement)
|
2009-03-08 13:59:08 -07:00
|
|
|
{
|
2011-09-27 00:54:58 -07:00
|
|
|
for (nsIContent* child = aElement->GetFirstChild();
|
|
|
|
child;
|
|
|
|
child = child->GetNextSibling()) {
|
|
|
|
if (child->IsHTML(nsGkAtoms::source))
|
2009-03-08 13:59:08 -07:00
|
|
|
{
|
2011-09-29 16:34:37 -07:00
|
|
|
return true;
|
2009-03-08 13:59:08 -07:00
|
|
|
}
|
|
|
|
}
|
2011-09-29 16:34:37 -07:00
|
|
|
return false;
|
2009-03-08 13:59:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsHTMLMediaElement::SelectResource()
|
|
|
|
{
|
2011-06-15 00:37:38 -07:00
|
|
|
if (!HasAttr(kNameSpaceID_None, nsGkAtoms::src) && !HasSourceChildren(this)) {
|
2010-09-02 17:03:03 -07:00
|
|
|
// The media element has neither a src attribute nor any source
|
|
|
|
// element children, abort the load.
|
|
|
|
mNetworkState = nsIDOMHTMLMediaElement::NETWORK_EMPTY;
|
2009-10-01 07:10:13 -07:00
|
|
|
// This clears mDelayingLoadEvent, so AddRemoveSelfReference will be called
|
2011-09-29 16:34:37 -07:00
|
|
|
ChangeDelayLoadStatus(false);
|
|
|
|
mIsRunningSelectResource = false;
|
2009-03-08 13:59:08 -07:00
|
|
|
return;
|
|
|
|
}
|
2008-12-15 19:32:03 -08:00
|
|
|
|
2011-09-29 16:34:37 -07:00
|
|
|
ChangeDelayLoadStatus(true);
|
2010-09-02 17:03:03 -07:00
|
|
|
|
2009-02-15 08:26:32 -08:00
|
|
|
mNetworkState = nsIDOMHTMLMediaElement::NETWORK_LOADING;
|
2009-10-01 07:10:13 -07:00
|
|
|
// Load event was delayed, and still is, so no need to call
|
|
|
|
// AddRemoveSelfReference, since it must still be held
|
2010-09-09 20:29:06 -07:00
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("loadstart"));
|
2009-02-15 08:26:32 -08:00
|
|
|
|
2009-03-08 13:59:08 -07:00
|
|
|
// If we have a 'src' attribute, use that exclusively.
|
2011-11-15 23:50:19 -08:00
|
|
|
nsAutoString src;
|
2009-03-08 13:59:08 -07:00
|
|
|
if (GetAttr(kNameSpaceID_None, nsGkAtoms::src, src)) {
|
2011-11-15 23:50:19 -08:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
2009-03-08 13:59:08 -07:00
|
|
|
nsresult rv = NewURIFromString(src, getter_AddRefs(uri));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2009-11-05 23:32:52 -08:00
|
|
|
LOG(PR_LOG_DEBUG, ("%p Trying load from src=%s", this, NS_ConvertUTF16toUTF8(src).get()));
|
2010-10-16 12:57:50 -07:00
|
|
|
NS_ASSERTION(!mIsLoadingFromSourceChildren,
|
|
|
|
"Should think we're not loading from source children by default");
|
2010-09-02 17:03:03 -07:00
|
|
|
mLoadingSrc = uri;
|
2010-08-19 15:50:37 -07:00
|
|
|
if (mPreloadAction == nsHTMLMediaElement::PRELOAD_NONE) {
|
|
|
|
// preload:none media, suspend the load here before we make any
|
|
|
|
// network requests.
|
2011-11-24 18:06:22 -08:00
|
|
|
SuspendLoad();
|
2011-09-29 16:34:37 -07:00
|
|
|
mIsRunningSelectResource = false;
|
2010-08-19 15:50:37 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-11-24 18:06:22 -08:00
|
|
|
rv = LoadResource();
|
2010-09-02 17:03:03 -07:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2011-09-29 16:34:37 -07:00
|
|
|
mIsRunningSelectResource = false;
|
2009-03-08 13:59:08 -07:00
|
|
|
return;
|
2010-09-02 17:03:03 -07:00
|
|
|
}
|
2009-03-08 13:59:08 -07:00
|
|
|
}
|
2009-09-21 17:08:13 -07:00
|
|
|
NoSupportedMediaSourceError();
|
2009-03-08 13:59:08 -07:00
|
|
|
} else {
|
|
|
|
// Otherwise, the source elements will be used.
|
2011-09-29 16:34:37 -07:00
|
|
|
mIsLoadingFromSourceChildren = true;
|
2009-03-08 13:59:08 -07:00
|
|
|
LoadFromSourceChildren();
|
|
|
|
}
|
2011-09-29 16:34:37 -07:00
|
|
|
mIsRunningSelectResource = false;
|
2009-02-19 18:49:00 -08:00
|
|
|
}
|
2009-01-26 18:32:33 -08:00
|
|
|
|
2009-03-08 13:59:08 -07:00
|
|
|
void nsHTMLMediaElement::NotifyLoadError()
|
2009-02-19 18:49:00 -08:00
|
|
|
{
|
2010-10-16 12:57:50 -07:00
|
|
|
if (!mIsLoadingFromSourceChildren) {
|
2010-09-02 17:03:03 -07:00
|
|
|
LOG(PR_LOG_DEBUG, ("NotifyLoadError(), no supported media error"));
|
2009-09-21 17:08:13 -07:00
|
|
|
NoSupportedMediaSourceError();
|
2011-04-28 07:08:03 -07:00
|
|
|
} else if (mSourceLoadCandidate) {
|
2010-09-02 17:03:03 -07:00
|
|
|
DispatchAsyncSourceError(mSourceLoadCandidate);
|
2009-03-08 13:59:08 -07:00
|
|
|
QueueLoadFromSourceTask();
|
2011-04-28 07:08:03 -07:00
|
|
|
} else {
|
|
|
|
NS_WARNING("Should know the source we were loading from!");
|
2009-03-08 13:59:08 -07:00
|
|
|
}
|
|
|
|
}
|
2009-02-19 18:49:00 -08:00
|
|
|
|
2010-08-25 06:10:00 -07:00
|
|
|
void nsHTMLMediaElement::NotifyAudioAvailable(float* aFrameBuffer,
|
|
|
|
PRUint32 aFrameBufferLength,
|
2010-10-06 15:58:36 -07:00
|
|
|
float aTime)
|
2010-08-25 06:10:00 -07:00
|
|
|
{
|
2010-09-05 19:14:50 -07:00
|
|
|
// Auto manage the memory for the frame buffer, so that if we add an early
|
|
|
|
// return-on-error here in future, we won't forget to release the memory.
|
|
|
|
// Otherwise we hand ownership of the memory over to the event created by
|
|
|
|
// DispatchAudioAvailableEvent().
|
|
|
|
nsAutoArrayPtr<float> frameBuffer(aFrameBuffer);
|
2010-08-25 06:10:00 -07:00
|
|
|
// Do same-origin check on element and media before allowing MozAudioAvailable events.
|
|
|
|
if (!mMediaSecurityVerified) {
|
|
|
|
nsCOMPtr<nsIPrincipal> principal = GetCurrentPrincipal();
|
|
|
|
nsresult rv = NodePrincipal()->Subsumes(principal, &mAllowAudioData);
|
|
|
|
if (NS_FAILED(rv)) {
|
2011-09-29 16:34:37 -07:00
|
|
|
mAllowAudioData = false;
|
2010-08-25 06:10:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-05 19:14:50 -07:00
|
|
|
DispatchAudioAvailableEvent(frameBuffer.forget(), aFrameBufferLength, aTime);
|
2010-08-25 06:10:00 -07:00
|
|
|
}
|
|
|
|
|
2009-03-08 13:59:08 -07:00
|
|
|
void nsHTMLMediaElement::LoadFromSourceChildren()
|
|
|
|
{
|
2009-10-01 07:10:13 -07:00
|
|
|
NS_ASSERTION(mDelayingLoadEvent,
|
|
|
|
"Should delay load event (if in document) during load");
|
2010-10-16 12:57:50 -07:00
|
|
|
NS_ASSERTION(mIsLoadingFromSourceChildren,
|
2010-09-02 17:03:03 -07:00
|
|
|
"Must remember we're loading from source children");
|
2011-09-29 16:34:37 -07:00
|
|
|
while (true) {
|
2010-09-02 17:03:03 -07:00
|
|
|
nsIContent* child = GetNextSource();
|
|
|
|
if (!child) {
|
2009-03-08 13:59:08 -07:00
|
|
|
// Exhausted candidates, wait for more candidates to be appended to
|
|
|
|
// the media element.
|
|
|
|
mLoadWaitStatus = WAITING_FOR_SOURCE;
|
2010-09-02 17:03:03 -07:00
|
|
|
mNetworkState = nsIDOMHTMLMediaElement::NETWORK_NO_SOURCE;
|
2011-09-29 16:34:37 -07:00
|
|
|
ChangeDelayLoadStatus(false);
|
2009-03-08 13:59:08 -07:00
|
|
|
return;
|
2009-02-15 08:26:32 -08:00
|
|
|
}
|
2009-02-19 18:49:00 -08:00
|
|
|
|
2010-09-02 17:03:03 -07:00
|
|
|
// Must have src attribute.
|
2011-11-15 23:50:19 -08:00
|
|
|
nsAutoString src;
|
2010-09-02 17:03:03 -07:00
|
|
|
if (!child->GetAttr(kNameSpaceID_None, nsGkAtoms::src, src)) {
|
|
|
|
DispatchAsyncSourceError(child);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we have a type attribute, it must be a supported type.
|
2011-11-15 23:50:19 -08:00
|
|
|
nsAutoString type;
|
|
|
|
if (child->GetAttr(kNameSpaceID_None, nsGkAtoms::type, type) &&
|
|
|
|
GetCanPlay(type) == CANPLAY_NO) {
|
2010-09-02 17:03:03 -07:00
|
|
|
DispatchAsyncSourceError(child);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
LOG(PR_LOG_DEBUG, ("%p Trying load from <source>=%s type=%s", this,
|
|
|
|
NS_ConvertUTF16toUTF8(src).get(), NS_ConvertUTF16toUTF8(type).get()));
|
2011-11-15 23:50:19 -08:00
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
2010-09-02 17:03:03 -07:00
|
|
|
NewURIFromString(src, getter_AddRefs(uri));
|
|
|
|
if (!uri) {
|
|
|
|
DispatchAsyncSourceError(child);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
mLoadingSrc = uri;
|
|
|
|
NS_ASSERTION(mNetworkState == nsIDOMHTMLMediaElement::NETWORK_LOADING,
|
|
|
|
"Network state should be loading");
|
2009-11-05 23:32:52 -08:00
|
|
|
|
2010-08-19 15:50:37 -07:00
|
|
|
if (mPreloadAction == nsHTMLMediaElement::PRELOAD_NONE) {
|
|
|
|
// preload:none media, suspend the load here before we make any
|
|
|
|
// network requests.
|
2011-11-24 18:06:22 -08:00
|
|
|
SuspendLoad();
|
2010-08-19 15:50:37 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-11-24 18:06:22 -08:00
|
|
|
if (NS_SUCCEEDED(LoadResource())) {
|
2009-03-08 13:59:08 -07:00
|
|
|
return;
|
2011-11-15 23:50:19 -08:00
|
|
|
}
|
2008-12-15 19:32:03 -08:00
|
|
|
|
2009-03-08 13:59:08 -07:00
|
|
|
// If we fail to load, loop back and try loading the next resource.
|
2010-09-02 17:03:03 -07:00
|
|
|
DispatchAsyncSourceError(child);
|
2009-03-08 13:59:08 -07:00
|
|
|
}
|
|
|
|
NS_NOTREACHED("Execution should not reach here!");
|
|
|
|
}
|
2008-12-15 19:32:03 -08:00
|
|
|
|
2011-11-24 18:06:22 -08:00
|
|
|
void nsHTMLMediaElement::SuspendLoad()
|
2010-08-19 15:50:37 -07:00
|
|
|
{
|
2011-09-29 16:34:37 -07:00
|
|
|
mLoadIsSuspended = true;
|
2010-08-19 15:50:37 -07:00
|
|
|
mNetworkState = nsIDOMHTMLMediaElement::NETWORK_IDLE;
|
2010-09-09 20:29:06 -07:00
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("suspend"));
|
2011-09-29 16:34:37 -07:00
|
|
|
ChangeDelayLoadStatus(false);
|
2010-08-19 15:50:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsHTMLMediaElement::ResumeLoad(PreloadAction aAction)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mLoadIsSuspended, "Can only resume preload if halted for one");
|
2011-09-29 16:34:37 -07:00
|
|
|
mLoadIsSuspended = false;
|
2010-08-19 15:50:37 -07:00
|
|
|
mPreloadAction = aAction;
|
2011-09-29 16:34:37 -07:00
|
|
|
ChangeDelayLoadStatus(true);
|
2010-08-19 15:50:37 -07:00
|
|
|
mNetworkState = nsIDOMHTMLMediaElement::NETWORK_LOADING;
|
2010-10-16 12:57:50 -07:00
|
|
|
if (!mIsLoadingFromSourceChildren) {
|
2010-08-19 15:50:37 -07:00
|
|
|
// We were loading from the element's src attribute.
|
2011-11-24 18:06:22 -08:00
|
|
|
if (NS_FAILED(LoadResource())) {
|
2010-08-19 15:50:37 -07:00
|
|
|
NoSupportedMediaSourceError();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// We were loading from a child <source> element. Try to resume the
|
|
|
|
// load of that child, and if that fails, try the next child.
|
2011-11-24 18:06:22 -08:00
|
|
|
if (NS_FAILED(LoadResource())) {
|
2010-08-19 15:50:37 -07:00
|
|
|
LoadFromSourceChildren();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool IsAutoplayEnabled()
|
2010-08-19 15:50:37 -07:00
|
|
|
{
|
2011-05-24 23:31:59 -07:00
|
|
|
return Preferences::GetBool("media.autoplay.enabled");
|
2010-08-19 15:50:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsHTMLMediaElement::UpdatePreloadAction()
|
|
|
|
{
|
|
|
|
PreloadAction nextAction = PRELOAD_UNDEFINED;
|
2010-10-16 11:41:53 -07:00
|
|
|
// If autoplay is set, or we're playing, we should always preload data,
|
|
|
|
// as we'll need it to play.
|
|
|
|
if ((IsAutoplayEnabled() && HasAttr(kNameSpaceID_None, nsGkAtoms::autoplay)) ||
|
|
|
|
!mPaused)
|
|
|
|
{
|
2010-08-19 15:50:37 -07:00
|
|
|
nextAction = nsHTMLMediaElement::PRELOAD_ENOUGH;
|
|
|
|
} else {
|
|
|
|
// Find the appropriate preload action by looking at the attribute.
|
|
|
|
const nsAttrValue* val = mAttrsAndChildren.GetAttr(nsGkAtoms::preload,
|
|
|
|
kNameSpaceID_None);
|
2011-05-24 23:32:00 -07:00
|
|
|
PRUint32 preloadDefault =
|
|
|
|
Preferences::GetInt("media.preload.default",
|
|
|
|
nsHTMLMediaElement::PRELOAD_ATTR_METADATA);
|
|
|
|
PRUint32 preloadAuto =
|
|
|
|
Preferences::GetInt("media.preload.auto",
|
|
|
|
nsHTMLMediaElement::PRELOAD_ENOUGH);
|
2010-08-19 15:50:37 -07:00
|
|
|
if (!val) {
|
2011-02-15 16:54:47 -08:00
|
|
|
// Attribute is not set. Use the preload action specified by the
|
|
|
|
// media.preload.default pref, or just preload metadata if not present.
|
|
|
|
nextAction = static_cast<PreloadAction>(preloadDefault);
|
2010-08-19 15:50:37 -07:00
|
|
|
} else if (val->Type() == nsAttrValue::eEnum) {
|
|
|
|
PreloadAttrValue attr = static_cast<PreloadAttrValue>(val->GetEnumValue());
|
|
|
|
if (attr == nsHTMLMediaElement::PRELOAD_ATTR_EMPTY ||
|
|
|
|
attr == nsHTMLMediaElement::PRELOAD_ATTR_AUTO)
|
|
|
|
{
|
2011-02-15 16:54:47 -08:00
|
|
|
nextAction = static_cast<PreloadAction>(preloadAuto);
|
2010-08-19 15:50:37 -07:00
|
|
|
} else if (attr == nsHTMLMediaElement::PRELOAD_ATTR_METADATA) {
|
|
|
|
nextAction = nsHTMLMediaElement::PRELOAD_METADATA;
|
|
|
|
} else if (attr == nsHTMLMediaElement::PRELOAD_ATTR_NONE) {
|
|
|
|
nextAction = nsHTMLMediaElement::PRELOAD_NONE;
|
|
|
|
}
|
|
|
|
} else {
|
2011-02-15 16:54:47 -08:00
|
|
|
// Use the suggested "missing value default" of "metadata", or the value
|
|
|
|
// specified by the media.preload.default, if present.
|
|
|
|
nextAction = static_cast<PreloadAction>(preloadDefault);
|
2010-08-19 15:50:37 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((mBegun || mIsRunningSelectResource) && nextAction < mPreloadAction) {
|
|
|
|
// We've started a load or are already downloading, and the preload was
|
|
|
|
// changed to a state where we buffer less. We don't support this case,
|
|
|
|
// so don't change the preload behaviour.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mPreloadAction = nextAction;
|
|
|
|
if (nextAction == nsHTMLMediaElement::PRELOAD_ENOUGH) {
|
|
|
|
if (mLoadIsSuspended) {
|
|
|
|
// Our load was previouly suspended due to the media having preload
|
|
|
|
// value "none". The preload value has changed to preload:auto, so
|
|
|
|
// resume the load.
|
|
|
|
ResumeLoad(PRELOAD_ENOUGH);
|
|
|
|
} else {
|
|
|
|
// Preload as much of the video as we can, i.e. don't suspend after
|
|
|
|
// the first frame.
|
|
|
|
StopSuspendingAfterFirstFrame();
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (nextAction == nsHTMLMediaElement::PRELOAD_METADATA) {
|
|
|
|
// Ensure that the video can be suspended after first frame.
|
2011-09-29 16:34:37 -07:00
|
|
|
mAllowSuspendAfterFirstFrame = true;
|
2010-08-19 15:50:37 -07:00
|
|
|
if (mLoadIsSuspended) {
|
|
|
|
// Our load was previouly suspended due to the media having preload
|
|
|
|
// value "none". The preload value has changed to preload:metadata, so
|
|
|
|
// resume the load. We'll pause the load again after we've read the
|
|
|
|
// metadata.
|
|
|
|
ResumeLoad(PRELOAD_METADATA);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-24 18:06:22 -08:00
|
|
|
nsresult nsHTMLMediaElement::LoadResource()
|
2009-03-08 13:59:08 -07:00
|
|
|
{
|
2009-10-01 07:10:13 -07:00
|
|
|
NS_ASSERTION(mDelayingLoadEvent,
|
|
|
|
"Should delay load event (if in document) during load");
|
2009-02-19 18:49:00 -08:00
|
|
|
|
2010-08-25 06:10:00 -07:00
|
|
|
// If a previous call to mozSetup() was made, kill that media stream
|
|
|
|
// in order to use this new src instead.
|
|
|
|
if (mAudioStream) {
|
|
|
|
mAudioStream->Shutdown();
|
|
|
|
mAudioStream = nsnull;
|
|
|
|
}
|
|
|
|
|
2009-03-08 13:59:08 -07:00
|
|
|
if (mChannel) {
|
|
|
|
mChannel->Cancel(NS_BINDING_ABORTED);
|
|
|
|
mChannel = nsnull;
|
|
|
|
}
|
|
|
|
|
2011-11-24 18:06:22 -08:00
|
|
|
nsHTMLMediaElement* other = LookupMediaElementURITable(mLoadingSrc);
|
|
|
|
if (other) {
|
|
|
|
// Clone it.
|
|
|
|
nsresult rv = InitializeDecoderAsClone(other->mDecoder);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2009-03-08 13:59:08 -07:00
|
|
|
PRInt16 shouldLoad = nsIContentPolicy::ACCEPT;
|
2011-11-15 23:50:19 -08:00
|
|
|
nsresult rv = NS_CheckContentLoadPolicy(nsIContentPolicy::TYPE_MEDIA,
|
2011-11-24 18:06:22 -08:00
|
|
|
mLoadingSrc,
|
2011-11-15 23:50:19 -08:00
|
|
|
NodePrincipal(),
|
|
|
|
static_cast<nsGenericElement*>(this),
|
|
|
|
EmptyCString(), // mime type
|
|
|
|
nsnull, // extra
|
|
|
|
&shouldLoad,
|
|
|
|
nsContentUtils::GetContentPolicy(),
|
|
|
|
nsContentUtils::GetSecurityManager());
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (NS_CP_REJECTED(shouldLoad)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2009-03-08 13:59:08 -07:00
|
|
|
|
2009-04-09 18:28:24 -07:00
|
|
|
nsCOMPtr<nsILoadGroup> loadGroup = GetDocumentLoadGroup();
|
2010-04-23 12:50:28 -07:00
|
|
|
|
|
|
|
// check for a Content Security Policy to pass down to the channel
|
|
|
|
// created to load the media content
|
|
|
|
nsCOMPtr<nsIChannelPolicy> channelPolicy;
|
|
|
|
nsCOMPtr<nsIContentSecurityPolicy> csp;
|
|
|
|
rv = NodePrincipal()->GetCsp(getter_AddRefs(csp));
|
|
|
|
NS_ENSURE_SUCCESS(rv,rv);
|
|
|
|
if (csp) {
|
|
|
|
channelPolicy = do_CreateInstance("@mozilla.org/nschannelpolicy;1");
|
|
|
|
channelPolicy->SetContentSecurityPolicy(csp);
|
|
|
|
channelPolicy->SetLoadType(nsIContentPolicy::TYPE_MEDIA);
|
|
|
|
}
|
2010-11-16 05:26:48 -08:00
|
|
|
nsCOMPtr<nsIChannel> channel;
|
|
|
|
rv = NS_NewChannel(getter_AddRefs(channel),
|
2011-11-24 18:06:22 -08:00
|
|
|
mLoadingSrc,
|
2009-03-08 13:59:08 -07:00
|
|
|
nsnull,
|
2009-04-09 18:28:24 -07:00
|
|
|
loadGroup,
|
2009-03-08 13:59:08 -07:00
|
|
|
nsnull,
|
2010-04-23 12:50:28 -07:00
|
|
|
nsICachingChannel::LOAD_BYPASS_LOCAL_CACHE_IF_BUSY,
|
|
|
|
channelPolicy);
|
2009-03-08 13:59:08 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv,rv);
|
|
|
|
|
2010-11-16 05:26:48 -08:00
|
|
|
// The listener holds a strong reference to us. This creates a
|
|
|
|
// reference cycle, once we've set mChannel, which is manually broken
|
|
|
|
// in the listener's OnStartRequest method after it is finished with
|
|
|
|
// the element. The cycle will also be broken if we get a shutdown
|
|
|
|
// notification before OnStartRequest fires. Necko guarantees that
|
|
|
|
// OnStartRequest will eventually fire if we don't shut down first.
|
2009-05-13 14:52:50 -07:00
|
|
|
nsRefPtr<MediaLoadListener> loadListener = new MediaLoadListener(this);
|
2009-11-05 23:32:52 -08:00
|
|
|
|
2010-11-16 05:26:48 -08:00
|
|
|
channel->SetNotificationCallbacks(loadListener);
|
2009-03-08 13:59:08 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIStreamListener> listener;
|
|
|
|
if (ShouldCheckAllowOrigin()) {
|
2010-11-16 05:26:48 -08:00
|
|
|
listener =
|
2011-03-28 13:18:45 -07:00
|
|
|
new nsCORSListenerProxy(loadListener,
|
|
|
|
NodePrincipal(),
|
|
|
|
channel,
|
2011-09-29 16:34:37 -07:00
|
|
|
false,
|
2011-03-28 13:18:45 -07:00
|
|
|
&rv);
|
2009-03-08 13:59:08 -07:00
|
|
|
} else {
|
|
|
|
rv = nsContentUtils::GetSecurityManager()->
|
|
|
|
CheckLoadURIWithPrincipal(NodePrincipal(),
|
2011-11-24 18:06:22 -08:00
|
|
|
mLoadingSrc,
|
2009-03-08 13:59:08 -07:00
|
|
|
nsIScriptSecurityManager::STANDARD);
|
|
|
|
listener = loadListener;
|
|
|
|
}
|
2010-11-16 05:26:48 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-03-08 13:59:08 -07:00
|
|
|
|
2010-11-16 05:26:48 -08:00
|
|
|
nsCOMPtr<nsIHttpChannel> hc = do_QueryInterface(channel);
|
2009-03-08 13:59:08 -07:00
|
|
|
if (hc) {
|
|
|
|
// Use a byte range request from the start of the resource.
|
|
|
|
// This enables us to detect if the stream supports byte range
|
|
|
|
// requests, and therefore seeking, early.
|
|
|
|
hc->SetRequestHeader(NS_LITERAL_CSTRING("Range"),
|
|
|
|
NS_LITERAL_CSTRING("bytes=0-"),
|
2011-09-29 16:34:37 -07:00
|
|
|
false);
|
2010-07-28 21:58:07 -07:00
|
|
|
|
2010-09-16 10:36:23 -07:00
|
|
|
SetRequestHeaders(hc);
|
2008-12-15 19:32:03 -08:00
|
|
|
}
|
|
|
|
|
2010-11-16 05:26:48 -08:00
|
|
|
rv = channel->AsyncOpen(listener, nsnull);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-03-08 13:59:08 -07:00
|
|
|
|
|
|
|
// Else the channel must be open and starting to download. If it encounters
|
2010-05-13 05:19:50 -07:00
|
|
|
// a non-catastrophic failure, it will set a new task to continue loading
|
2010-11-16 05:26:48 -08:00
|
|
|
// another candidate. It's safe to set it as mChannel now.
|
|
|
|
mChannel = channel;
|
|
|
|
|
|
|
|
// loadListener will be unregistered either on shutdown or when
|
|
|
|
// OnStartRequest for the channel we just opened fires.
|
|
|
|
nsContentUtils::RegisterShutdownObserver(loadListener);
|
2009-03-08 13:59:08 -07:00
|
|
|
return NS_OK;
|
2008-12-15 19:32:03 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsHTMLMediaElement::LoadWithChannel(nsIChannel *aChannel,
|
|
|
|
nsIStreamListener **aListener)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aChannel);
|
|
|
|
NS_ENSURE_ARG_POINTER(aListener);
|
|
|
|
|
|
|
|
*aListener = nsnull;
|
|
|
|
|
2009-03-08 13:59:08 -07:00
|
|
|
AbortExistingLoads();
|
2008-12-15 19:32:03 -08:00
|
|
|
|
2011-11-24 18:06:22 -08:00
|
|
|
nsresult rv = aChannel->GetOriginalURI(getter_AddRefs(mLoadingSrc));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2011-11-23 15:30:03 -08:00
|
|
|
|
2011-11-24 18:06:22 -08:00
|
|
|
ChangeDelayLoadStatus(true);
|
|
|
|
rv = InitializeDecoderForChannel(aChannel, aListener);
|
2008-12-15 19:32:03 -08:00
|
|
|
if (NS_FAILED(rv)) {
|
2011-09-29 16:34:37 -07:00
|
|
|
ChangeDelayLoadStatus(false);
|
2009-09-14 19:30:44 -07:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2010-09-09 20:29:06 -07:00
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("loadstart"));
|
2009-09-14 19:30:44 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsHTMLMediaElement::MozLoadFrom(nsIDOMHTMLMediaElement* aOther)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aOther);
|
|
|
|
|
|
|
|
AbortExistingLoads();
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(aOther);
|
|
|
|
nsHTMLMediaElement* other = static_cast<nsHTMLMediaElement*>(content.get());
|
|
|
|
if (!other || !other->mDecoder)
|
|
|
|
return NS_OK;
|
|
|
|
|
2011-09-29 16:34:37 -07:00
|
|
|
ChangeDelayLoadStatus(true);
|
2009-09-14 19:30:44 -07:00
|
|
|
|
2011-11-24 18:06:22 -08:00
|
|
|
mLoadingSrc = other->mLoadingSrc;
|
2009-09-14 19:30:44 -07:00
|
|
|
nsresult rv = InitializeDecoderAsClone(other->mDecoder);
|
|
|
|
if (NS_FAILED(rv)) {
|
2011-09-29 16:34:37 -07:00
|
|
|
ChangeDelayLoadStatus(false);
|
2008-12-15 19:32:03 -08:00
|
|
|
return rv;
|
|
|
|
}
|
2008-07-09 01:22:20 -07:00
|
|
|
|
2010-09-09 20:29:06 -07:00
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("loadstart"));
|
2008-07-09 01:22:20 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* readonly attribute unsigned short readyState; */
|
|
|
|
NS_IMETHODIMP nsHTMLMediaElement::GetReadyState(PRUint16 *aReadyState)
|
|
|
|
{
|
2008-07-09 02:50:08 -07:00
|
|
|
*aReadyState = mReadyState;
|
2008-07-09 01:22:20 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* readonly attribute boolean seeking; */
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHODIMP nsHTMLMediaElement::GetSeeking(bool *aSeeking)
|
2008-07-09 01:22:20 -07:00
|
|
|
{
|
2008-10-19 00:39:21 -07:00
|
|
|
*aSeeking = mDecoder && mDecoder->IsSeeking();
|
2008-07-09 01:22:20 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-01-16 19:03:00 -08:00
|
|
|
/* attribute double currentTime; */
|
|
|
|
NS_IMETHODIMP nsHTMLMediaElement::GetCurrentTime(double *aCurrentTime)
|
2008-07-09 01:22:20 -07:00
|
|
|
{
|
|
|
|
*aCurrentTime = mDecoder ? mDecoder->GetCurrentTime() : 0.0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-01-16 19:03:00 -08:00
|
|
|
NS_IMETHODIMP nsHTMLMediaElement::SetCurrentTime(double aCurrentTime)
|
2008-07-09 01:22:20 -07:00
|
|
|
{
|
2009-05-17 19:00:44 -07:00
|
|
|
StopSuspendingAfterFirstFrame();
|
|
|
|
|
2009-09-29 14:32:44 -07:00
|
|
|
if (!mDecoder) {
|
2009-11-05 23:32:52 -08:00
|
|
|
LOG(PR_LOG_DEBUG, ("%p SetCurrentTime(%f) failed: no decoder", this, aCurrentTime));
|
2008-10-19 00:39:21 -07:00
|
|
|
return NS_ERROR_DOM_INVALID_STATE_ERR;
|
2009-09-29 14:32:44 -07:00
|
|
|
}
|
2008-10-19 00:39:21 -07:00
|
|
|
|
2009-09-29 14:32:44 -07:00
|
|
|
if (mReadyState == nsIDOMHTMLMediaElement::HAVE_NOTHING) {
|
2009-11-05 23:32:52 -08:00
|
|
|
LOG(PR_LOG_DEBUG, ("%p SetCurrentTime(%f) failed: no source", this, aCurrentTime));
|
2009-05-19 02:55:04 -07:00
|
|
|
return NS_ERROR_DOM_INVALID_STATE_ERR;
|
2009-09-29 14:32:44 -07:00
|
|
|
}
|
2009-05-19 02:55:04 -07:00
|
|
|
|
2008-10-19 00:39:21 -07:00
|
|
|
// Detect for a NaN and invalid values.
|
2009-09-29 14:32:44 -07:00
|
|
|
if (aCurrentTime != aCurrentTime) {
|
2009-11-05 23:32:52 -08:00
|
|
|
LOG(PR_LOG_DEBUG, ("%p SetCurrentTime(%f) failed: bad time", this, aCurrentTime));
|
2008-10-19 00:39:21 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
2009-09-29 14:32:44 -07:00
|
|
|
}
|
2008-10-19 00:39:21 -07:00
|
|
|
|
2009-05-19 02:55:04 -07:00
|
|
|
// Clamp the time to [0, duration] as required by the spec
|
2011-01-16 19:03:00 -08:00
|
|
|
double clampedTime = NS_MAX(0.0, aCurrentTime);
|
|
|
|
double duration = mDecoder->GetDuration();
|
2009-05-19 02:55:04 -07:00
|
|
|
if (duration >= 0) {
|
2010-02-22 11:41:19 -08:00
|
|
|
clampedTime = NS_MIN(clampedTime, duration);
|
2009-05-19 02:55:04 -07:00
|
|
|
}
|
2008-10-19 00:39:21 -07:00
|
|
|
|
2008-12-14 19:38:16 -08:00
|
|
|
mPlayingBeforeSeek = IsPotentiallyPlaying();
|
2008-10-23 01:02:18 -07:00
|
|
|
// The media backend is responsible for dispatching the timeupdate
|
|
|
|
// event if it changes the playback position as a result of the seek.
|
2009-11-05 23:32:52 -08:00
|
|
|
LOG(PR_LOG_DEBUG, ("%p SetCurrentTime(%f) starting seek", this, aCurrentTime));
|
2009-05-19 02:55:04 -07:00
|
|
|
nsresult rv = mDecoder->Seek(clampedTime);
|
2009-10-01 07:10:13 -07:00
|
|
|
|
|
|
|
// We changed whether we're seeking so we need to AddRemoveSelfReference
|
|
|
|
AddRemoveSelfReference();
|
|
|
|
|
2008-10-19 00:39:21 -07:00
|
|
|
return rv;
|
2008-07-09 01:22:20 -07:00
|
|
|
}
|
|
|
|
|
2011-01-16 19:03:00 -08:00
|
|
|
/* readonly attribute double duration; */
|
|
|
|
NS_IMETHODIMP nsHTMLMediaElement::GetDuration(double *aDuration)
|
2008-07-09 01:22:20 -07:00
|
|
|
{
|
2011-01-16 19:03:00 -08:00
|
|
|
*aDuration = mDecoder ? mDecoder->GetDuration() : std::numeric_limits<double>::quiet_NaN();
|
2008-07-09 01:22:20 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-08-09 03:10:48 -07:00
|
|
|
/* readonly attribute nsIDOMHTMLTimeRanges seekable; */
|
|
|
|
NS_IMETHODIMP nsHTMLMediaElement::GetSeekable(nsIDOMTimeRanges** aSeekable)
|
|
|
|
{
|
2011-11-15 23:50:19 -08:00
|
|
|
nsRefPtr<nsTimeRanges> ranges = new nsTimeRanges();
|
2011-08-09 03:10:48 -07:00
|
|
|
if (mDecoder && mReadyState > nsIDOMHTMLMediaElement::HAVE_NOTHING) {
|
|
|
|
mDecoder->GetSeekable(ranges);
|
|
|
|
}
|
2011-11-15 23:50:19 -08:00
|
|
|
ranges.forget(aSeekable);
|
2011-08-09 03:10:48 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-28 14:54:17 -07:00
|
|
|
/* readonly attribute boolean paused; */
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHODIMP nsHTMLMediaElement::GetPaused(bool *aPaused)
|
2008-07-09 01:22:20 -07:00
|
|
|
{
|
2008-07-09 02:50:08 -07:00
|
|
|
*aPaused = mPaused;
|
2008-07-09 01:22:20 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* void pause (); */
|
|
|
|
NS_IMETHODIMP nsHTMLMediaElement::Pause()
|
|
|
|
{
|
2008-12-14 19:38:16 -08:00
|
|
|
if (mNetworkState == nsIDOMHTMLMediaElement::NETWORK_EMPTY) {
|
2010-09-02 17:03:03 -07:00
|
|
|
LOG(PR_LOG_DEBUG, ("Loading due to Pause()"));
|
2009-01-08 00:44:38 -08:00
|
|
|
nsresult rv = Load();
|
2008-07-09 01:22:20 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-01-08 00:44:38 -08:00
|
|
|
} else if (mDecoder) {
|
|
|
|
mDecoder->Pause();
|
2008-07-09 01:22:20 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool oldPaused = mPaused;
|
2011-09-29 16:34:37 -07:00
|
|
|
mPaused = true;
|
|
|
|
mAutoplaying = false;
|
2009-10-01 07:10:13 -07:00
|
|
|
// We changed mPaused and mAutoplaying which can affect AddRemoveSelfReference
|
|
|
|
AddRemoveSelfReference();
|
2009-11-05 23:32:52 -08:00
|
|
|
|
2008-07-09 01:22:20 -07:00
|
|
|
if (!oldPaused) {
|
2011-09-29 16:34:37 -07:00
|
|
|
FireTimeUpdate(false);
|
2010-09-09 20:29:06 -07:00
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("pause"));
|
2008-07-09 01:22:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-01-16 19:03:00 -08:00
|
|
|
/* attribute double volume; */
|
|
|
|
NS_IMETHODIMP nsHTMLMediaElement::GetVolume(double *aVolume)
|
2008-07-09 01:22:20 -07:00
|
|
|
{
|
2009-02-25 02:59:00 -08:00
|
|
|
*aVolume = mVolume;
|
|
|
|
|
2008-07-09 01:22:20 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-01-16 19:03:00 -08:00
|
|
|
NS_IMETHODIMP nsHTMLMediaElement::SetVolume(double aVolume)
|
2008-07-09 01:22:20 -07:00
|
|
|
{
|
2011-11-15 23:50:19 -08:00
|
|
|
if (aVolume < 0.0 || aVolume > 1.0)
|
2008-09-30 22:44:16 -07:00
|
|
|
return NS_ERROR_DOM_INDEX_SIZE_ERR;
|
|
|
|
|
2009-02-25 02:59:00 -08:00
|
|
|
if (aVolume == mVolume)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
mVolume = aVolume;
|
|
|
|
|
2010-08-25 06:10:00 -07:00
|
|
|
if (mDecoder && !mMuted) {
|
2009-02-25 02:59:00 -08:00
|
|
|
mDecoder->SetVolume(mVolume);
|
2010-08-25 06:10:00 -07:00
|
|
|
} else if (mAudioStream && !mMuted) {
|
|
|
|
mAudioStream->SetVolume(mVolume);
|
|
|
|
}
|
2009-02-25 02:59:00 -08:00
|
|
|
|
2010-09-09 20:29:06 -07:00
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("volumechange"));
|
2008-07-09 01:22:20 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-08-25 06:10:00 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLMediaElement::GetMozChannels(PRUint32 *aMozChannels)
|
|
|
|
{
|
|
|
|
if (!mDecoder && !mAudioStream) {
|
|
|
|
return NS_ERROR_DOM_INVALID_STATE_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aMozChannels = mChannels;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLMediaElement::GetMozSampleRate(PRUint32 *aMozSampleRate)
|
|
|
|
{
|
|
|
|
if (!mDecoder && !mAudioStream) {
|
|
|
|
return NS_ERROR_DOM_INVALID_STATE_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aMozSampleRate = mRate;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLMediaElement::GetMozFrameBufferLength(PRUint32 *aMozFrameBufferLength)
|
|
|
|
{
|
|
|
|
// The framebuffer (via MozAudioAvailable events) is only available
|
|
|
|
// when reading vs. writing audio directly.
|
|
|
|
if (!mDecoder) {
|
|
|
|
return NS_ERROR_DOM_INVALID_STATE_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aMozFrameBufferLength = mDecoder->GetFrameBufferLength();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLMediaElement::SetMozFrameBufferLength(PRUint32 aMozFrameBufferLength)
|
|
|
|
{
|
|
|
|
if (!mDecoder)
|
|
|
|
return NS_ERROR_DOM_INVALID_STATE_ERR;
|
|
|
|
|
|
|
|
return mDecoder->RequestFrameBufferLength(aMozFrameBufferLength);
|
|
|
|
}
|
|
|
|
|
2008-07-09 01:22:20 -07:00
|
|
|
/* attribute boolean muted; */
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHODIMP nsHTMLMediaElement::GetMuted(bool *aMuted)
|
2008-07-09 01:22:20 -07:00
|
|
|
{
|
2008-07-09 02:50:08 -07:00
|
|
|
*aMuted = mMuted;
|
2008-07-09 01:22:20 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHODIMP nsHTMLMediaElement::SetMuted(bool aMuted)
|
2008-07-09 01:22:20 -07:00
|
|
|
{
|
2009-02-25 02:59:00 -08:00
|
|
|
if (aMuted == mMuted)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
mMuted = aMuted;
|
2008-07-09 01:22:20 -07:00
|
|
|
|
|
|
|
if (mDecoder) {
|
2009-02-25 02:59:00 -08:00
|
|
|
mDecoder->SetVolume(mMuted ? 0.0 : mVolume);
|
2010-08-25 06:10:00 -07:00
|
|
|
} else if (mAudioStream) {
|
|
|
|
mAudioStream->SetVolume(mMuted ? 0.0 : mVolume);
|
2008-07-09 01:22:20 -07:00
|
|
|
}
|
|
|
|
|
2010-09-09 20:29:06 -07:00
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("volumechange"));
|
2008-07-09 01:22:20 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-11-24 18:06:22 -08:00
|
|
|
class MediaElementSetForURI : public nsURIHashKey {
|
|
|
|
public:
|
|
|
|
MediaElementSetForURI(const nsIURI* aKey) : nsURIHashKey(aKey) {}
|
|
|
|
MediaElementSetForURI(const MediaElementSetForURI& toCopy)
|
|
|
|
: nsURIHashKey(toCopy), mElements(toCopy.mElements) {}
|
|
|
|
nsTArray<nsHTMLMediaElement*> mElements;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef nsTHashtable<MediaElementSetForURI> MediaElementURITable;
|
|
|
|
// Elements in this table must have non-null mDecoder and mLoadingSrc, and those
|
|
|
|
// can't change while the element is in the table. The table is keyed by
|
|
|
|
// the element's mLoadingSrc. Each entry has a list of all elements with the
|
|
|
|
// same mLoadingSrc.
|
|
|
|
static MediaElementURITable* gElementTable;
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHTMLMediaElement::AddMediaElementToURITable()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mDecoder && mDecoder->GetStream(), "Call this only with decoder Load called");
|
|
|
|
if (!gElementTable) {
|
|
|
|
gElementTable = new MediaElementURITable();
|
|
|
|
gElementTable->Init();
|
|
|
|
}
|
|
|
|
MediaElementSetForURI* entry = gElementTable->PutEntry(mLoadingSrc);
|
|
|
|
entry->mElements.AppendElement(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHTMLMediaElement::RemoveMediaElementFromURITable()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mDecoder, "Don't call this without decoder!");
|
|
|
|
NS_ASSERTION(mLoadingSrc, "Can't have decoder without source!");
|
|
|
|
if (!gElementTable)
|
|
|
|
return;
|
|
|
|
MediaElementSetForURI* entry = gElementTable->GetEntry(mLoadingSrc);
|
|
|
|
if (!entry)
|
|
|
|
return;
|
|
|
|
entry->mElements.RemoveElement(this);
|
|
|
|
if (entry->mElements.IsEmpty()) {
|
|
|
|
gElementTable->RemoveEntry(mLoadingSrc);
|
|
|
|
if (gElementTable->Count() == 0) {
|
|
|
|
delete gElementTable;
|
|
|
|
gElementTable = nsnull;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsHTMLMediaElement*
|
|
|
|
nsHTMLMediaElement::LookupMediaElementURITable(nsIURI* aURI)
|
|
|
|
{
|
|
|
|
if (!gElementTable)
|
|
|
|
return nsnull;
|
|
|
|
MediaElementSetForURI* entry = gElementTable->GetEntry(aURI);
|
|
|
|
if (!entry)
|
|
|
|
return nsnull;
|
|
|
|
for (PRUint32 i = 0; i < entry->mElements.Length(); ++i) {
|
|
|
|
nsHTMLMediaElement* elem = entry->mElements[i];
|
|
|
|
bool equal;
|
|
|
|
// Look for elements that have the same principal.
|
|
|
|
// XXX when we implement crossorigin for video, we'll also need to check
|
|
|
|
// for the same crossorigin mode here. Ditto for anything else that could
|
|
|
|
// cause us to send different headers.
|
|
|
|
if (NS_SUCCEEDED(elem->NodePrincipal()->Equals(NodePrincipal(), &equal)) && equal) {
|
|
|
|
NS_ASSERTION(elem->mDecoder && elem->mDecoder->GetStream(), "Decoder gone");
|
|
|
|
return elem;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2011-09-18 02:22:18 -07:00
|
|
|
nsHTMLMediaElement::nsHTMLMediaElement(already_AddRefed<nsINodeInfo> aNodeInfo)
|
2008-07-09 01:22:20 -07:00
|
|
|
: nsGenericHTMLElement(aNodeInfo),
|
2009-03-15 23:05:28 -07:00
|
|
|
mCurrentLoadID(0),
|
2008-12-14 19:38:16 -08:00
|
|
|
mNetworkState(nsIDOMHTMLMediaElement::NETWORK_EMPTY),
|
|
|
|
mReadyState(nsIDOMHTMLMediaElement::HAVE_NOTHING),
|
2009-03-15 23:05:28 -07:00
|
|
|
mLoadWaitStatus(NOT_WAITING),
|
2009-02-25 02:59:00 -08:00
|
|
|
mVolume(1.0),
|
2010-08-25 06:10:00 -07:00
|
|
|
mChannels(0),
|
|
|
|
mRate(0),
|
2010-09-14 16:24:47 -07:00
|
|
|
mPreloadAction(PRELOAD_UNDEFINED),
|
2008-10-19 00:39:21 -07:00
|
|
|
mMediaSize(-1,-1),
|
2010-11-24 10:34:57 -08:00
|
|
|
mLastCurrentTime(0.0),
|
2011-08-24 16:42:23 -07:00
|
|
|
mFragmentStart(-1.0),
|
|
|
|
mFragmentEnd(-1.0),
|
2011-09-29 16:34:37 -07:00
|
|
|
mAllowAudioData(false),
|
|
|
|
mBegun(false),
|
|
|
|
mLoadedFirstFrame(false),
|
|
|
|
mAutoplaying(true),
|
|
|
|
mAutoplayEnabled(true),
|
|
|
|
mPaused(true),
|
|
|
|
mMuted(false),
|
|
|
|
mPlayingBeforeSeek(false),
|
|
|
|
mPausedForInactiveDocument(false),
|
|
|
|
mWaitingFired(false),
|
|
|
|
mIsRunningLoadMethod(false),
|
|
|
|
mIsLoadingFromSourceChildren(false),
|
|
|
|
mDelayingLoadEvent(false),
|
|
|
|
mIsRunningSelectResource(false),
|
|
|
|
mSuspendedAfterFirstFrame(false),
|
|
|
|
mAllowSuspendAfterFirstFrame(true),
|
|
|
|
mHasPlayedOrSeeked(false),
|
|
|
|
mHasSelfReference(false),
|
|
|
|
mShuttingDown(false),
|
|
|
|
mLoadIsSuspended(false),
|
|
|
|
mMediaSecurityVerified(false)
|
2008-07-09 01:22:20 -07:00
|
|
|
{
|
2009-09-29 14:32:44 -07:00
|
|
|
#ifdef PR_LOGGING
|
|
|
|
if (!gMediaElementLog) {
|
|
|
|
gMediaElementLog = PR_NewLogModule("nsMediaElement");
|
|
|
|
}
|
|
|
|
if (!gMediaElementEventsLog) {
|
|
|
|
gMediaElementEventsLog = PR_NewLogModule("nsMediaElementEvents");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-05-07 18:32:32 -07:00
|
|
|
RegisterFreezableElement();
|
2009-10-01 07:10:13 -07:00
|
|
|
NotifyOwnerDocumentActivityChanged();
|
2008-07-09 01:22:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsHTMLMediaElement::~nsHTMLMediaElement()
|
|
|
|
{
|
2009-10-01 07:10:13 -07:00
|
|
|
NS_ASSERTION(!mHasSelfReference,
|
|
|
|
"How can we be destroyed if we're still holding a self reference?");
|
|
|
|
|
2009-05-07 18:32:32 -07:00
|
|
|
UnregisterFreezableElement();
|
2008-10-19 00:39:21 -07:00
|
|
|
if (mDecoder) {
|
2011-11-24 18:06:22 -08:00
|
|
|
RemoveMediaElementFromURITable();
|
2008-10-19 00:39:21 -07:00
|
|
|
mDecoder->Shutdown();
|
|
|
|
}
|
2008-12-15 19:32:03 -08:00
|
|
|
if (mChannel) {
|
|
|
|
mChannel->Cancel(NS_BINDING_ABORTED);
|
|
|
|
}
|
2010-08-25 06:10:00 -07:00
|
|
|
if (mAudioStream) {
|
|
|
|
mAudioStream->Shutdown();
|
|
|
|
}
|
2008-07-09 01:22:20 -07:00
|
|
|
}
|
|
|
|
|
2009-05-17 19:00:44 -07:00
|
|
|
void nsHTMLMediaElement::StopSuspendingAfterFirstFrame()
|
|
|
|
{
|
2011-09-29 16:34:37 -07:00
|
|
|
mAllowSuspendAfterFirstFrame = false;
|
2009-05-17 19:00:44 -07:00
|
|
|
if (!mSuspendedAfterFirstFrame)
|
|
|
|
return;
|
2011-09-29 16:34:37 -07:00
|
|
|
mSuspendedAfterFirstFrame = false;
|
2009-05-17 19:00:44 -07:00
|
|
|
if (mDecoder) {
|
2011-09-29 16:34:37 -07:00
|
|
|
mDecoder->Resume(true);
|
2009-05-17 19:00:44 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
void nsHTMLMediaElement::SetPlayedOrSeeked(bool aValue)
|
2009-06-26 00:25:17 -07:00
|
|
|
{
|
2011-11-15 23:50:19 -08:00
|
|
|
if (aValue == mHasPlayedOrSeeked) {
|
2009-06-26 00:25:17 -07:00
|
|
|
return;
|
2011-11-15 23:50:19 -08:00
|
|
|
}
|
2009-06-26 00:25:17 -07:00
|
|
|
|
|
|
|
mHasPlayedOrSeeked = aValue;
|
|
|
|
|
|
|
|
// Force a reflow so that the poster frame hides or shows immediately.
|
2009-12-24 13:20:05 -08:00
|
|
|
nsIFrame* frame = GetPrimaryFrame();
|
2011-11-15 23:50:19 -08:00
|
|
|
if (!frame) {
|
|
|
|
return;
|
|
|
|
}
|
2009-12-24 13:20:05 -08:00
|
|
|
frame->PresContext()->PresShell()->FrameNeedsReflow(frame,
|
|
|
|
nsIPresShell::eTreeChange,
|
|
|
|
NS_FRAME_IS_DIRTY);
|
2009-06-26 00:25:17 -07:00
|
|
|
}
|
|
|
|
|
2008-12-15 19:32:03 -08:00
|
|
|
NS_IMETHODIMP nsHTMLMediaElement::Play()
|
2008-07-09 01:22:20 -07:00
|
|
|
{
|
2009-05-17 19:00:44 -07:00
|
|
|
StopSuspendingAfterFirstFrame();
|
2011-09-29 16:34:37 -07:00
|
|
|
SetPlayedOrSeeked(true);
|
2009-05-17 19:00:44 -07:00
|
|
|
|
2008-12-14 19:38:16 -08:00
|
|
|
if (mNetworkState == nsIDOMHTMLMediaElement::NETWORK_EMPTY) {
|
2009-02-10 17:23:19 -08:00
|
|
|
nsresult rv = Load();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2011-11-24 18:06:22 -08:00
|
|
|
}
|
|
|
|
if (mLoadIsSuspended) {
|
2010-08-19 15:50:37 -07:00
|
|
|
ResumeLoad(PRELOAD_ENOUGH);
|
2011-11-24 18:06:22 -08:00
|
|
|
}
|
|
|
|
// Even if we just did Load() or ResumeLoad(), we could already have a decoder
|
|
|
|
// here if we managed to clone an existing decoder.
|
|
|
|
if (mDecoder) {
|
2009-02-10 17:23:19 -08:00
|
|
|
if (mDecoder->IsEnded()) {
|
|
|
|
SetCurrentTime(0);
|
|
|
|
}
|
2009-10-01 07:10:13 -07:00
|
|
|
if (!mPausedForInactiveDocument) {
|
|
|
|
nsresult rv = mDecoder->Play();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2008-10-21 02:19:33 -07:00
|
|
|
}
|
|
|
|
|
2009-11-05 23:32:52 -08:00
|
|
|
// TODO: If the playback has ended, then the user agent must set
|
2009-03-08 13:59:08 -07:00
|
|
|
// seek to the effective start.
|
2008-11-05 14:53:29 -08:00
|
|
|
// TODO: The playback rate must be set to the default playback rate.
|
2009-02-10 17:23:19 -08:00
|
|
|
if (mPaused) {
|
2010-09-09 20:29:06 -07:00
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("play"));
|
2009-02-10 17:23:19 -08:00
|
|
|
switch (mReadyState) {
|
2011-03-23 15:28:57 -07:00
|
|
|
case nsIDOMHTMLMediaElement::HAVE_NOTHING:
|
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("waiting"));
|
|
|
|
break;
|
2009-02-10 17:23:19 -08:00
|
|
|
case nsIDOMHTMLMediaElement::HAVE_METADATA:
|
|
|
|
case nsIDOMHTMLMediaElement::HAVE_CURRENT_DATA:
|
2011-09-29 16:34:37 -07:00
|
|
|
FireTimeUpdate(false);
|
2010-09-09 20:29:06 -07:00
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("waiting"));
|
2009-02-10 17:23:19 -08:00
|
|
|
break;
|
|
|
|
case nsIDOMHTMLMediaElement::HAVE_FUTURE_DATA:
|
|
|
|
case nsIDOMHTMLMediaElement::HAVE_ENOUGH_DATA:
|
2010-09-09 20:29:06 -07:00
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("playing"));
|
2009-02-10 17:23:19 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-07-09 01:22:20 -07:00
|
|
|
|
2011-09-29 16:34:37 -07:00
|
|
|
mPaused = false;
|
|
|
|
mAutoplaying = false;
|
2009-10-01 07:10:13 -07:00
|
|
|
// We changed mPaused and mAutoplaying which can affect AddRemoveSelfReference
|
2010-10-16 11:41:53 -07:00
|
|
|
// and our preload status.
|
2009-10-01 07:10:13 -07:00
|
|
|
AddRemoveSelfReference();
|
2010-10-16 11:41:53 -07:00
|
|
|
UpdatePreloadAction();
|
2008-07-09 01:22:20 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool nsHTMLMediaElement::ParseAttribute(PRInt32 aNamespaceID,
|
2008-12-15 19:32:03 -08:00
|
|
|
nsIAtom* aAttribute,
|
|
|
|
const nsAString& aValue,
|
|
|
|
nsAttrValue& aResult)
|
2008-07-09 01:22:20 -07:00
|
|
|
{
|
2010-08-19 15:50:37 -07:00
|
|
|
// Mappings from 'preload' attribute strings to an enumeration.
|
|
|
|
static const nsAttrValue::EnumTable kPreloadTable[] = {
|
|
|
|
{ "", nsHTMLMediaElement::PRELOAD_ATTR_EMPTY },
|
|
|
|
{ "none", nsHTMLMediaElement::PRELOAD_ATTR_NONE },
|
|
|
|
{ "metadata", nsHTMLMediaElement::PRELOAD_ATTR_METADATA },
|
|
|
|
{ "auto", nsHTMLMediaElement::PRELOAD_ATTR_AUTO },
|
|
|
|
{ 0 }
|
|
|
|
};
|
|
|
|
|
2008-07-09 01:22:20 -07:00
|
|
|
if (aNamespaceID == kNameSpaceID_None) {
|
2011-11-15 23:50:19 -08:00
|
|
|
if (ParseImageAttribute(aAttribute, aValue, aResult)) {
|
2011-09-29 16:34:37 -07:00
|
|
|
return true;
|
2008-07-09 01:22:20 -07:00
|
|
|
}
|
2011-11-15 23:50:19 -08:00
|
|
|
if (aAttribute == nsGkAtoms::preload) {
|
2011-09-29 16:34:37 -07:00
|
|
|
return aResult.ParseEnumValue(aValue, kPreloadTable, false);
|
2010-08-19 15:50:37 -07:00
|
|
|
}
|
2008-07-09 01:22:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue,
|
|
|
|
aResult);
|
|
|
|
}
|
2008-10-19 00:39:21 -07:00
|
|
|
|
2011-12-15 11:36:46 -08:00
|
|
|
void nsHTMLMediaElement::DoneCreatingElement()
|
|
|
|
{
|
|
|
|
if (HasAttr(kNameSpaceID_None, nsGkAtoms::muted))
|
|
|
|
mMuted = true;
|
|
|
|
}
|
|
|
|
|
2008-12-15 19:32:03 -08:00
|
|
|
nsresult nsHTMLMediaElement::SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
|
|
|
|
nsIAtom* aPrefix, const nsAString& aValue,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aNotify)
|
2008-07-09 01:22:20 -07:00
|
|
|
{
|
2009-11-05 23:32:52 -08:00
|
|
|
nsresult rv =
|
2008-07-09 01:22:20 -07:00
|
|
|
nsGenericHTMLElement::SetAttr(aNameSpaceID, aName, aPrefix, aValue,
|
2011-11-15 23:50:19 -08:00
|
|
|
aNotify);
|
2010-08-19 15:50:37 -07:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2010-09-02 17:03:03 -07:00
|
|
|
if (aNameSpaceID == kNameSpaceID_None && aName == nsGkAtoms::src) {
|
|
|
|
Load();
|
|
|
|
}
|
2009-05-17 19:00:44 -07:00
|
|
|
if (aNotify && aNameSpaceID == kNameSpaceID_None) {
|
2010-09-02 17:03:03 -07:00
|
|
|
if (aName == nsGkAtoms::autoplay) {
|
2009-05-17 19:00:44 -07:00
|
|
|
StopSuspendingAfterFirstFrame();
|
|
|
|
if (mReadyState == nsIDOMHTMLMediaElement::HAVE_ENOUGH_DATA) {
|
|
|
|
NotifyAutoplayDataReady();
|
|
|
|
}
|
2009-10-01 07:10:13 -07:00
|
|
|
// This attribute can affect AddRemoveSelfReference
|
|
|
|
AddRemoveSelfReference();
|
2010-08-19 15:50:37 -07:00
|
|
|
UpdatePreloadAction();
|
|
|
|
} else if (aName == nsGkAtoms::preload) {
|
|
|
|
UpdatePreloadAction();
|
2009-05-17 19:00:44 -07:00
|
|
|
}
|
2008-07-09 01:22:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2009-11-05 23:32:52 -08:00
|
|
|
nsresult nsHTMLMediaElement::UnsetAttr(PRInt32 aNameSpaceID, nsIAtom* aAttr,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aNotify)
|
2009-10-01 07:10:13 -07:00
|
|
|
{
|
|
|
|
nsresult rv = nsGenericHTMLElement::UnsetAttr(aNameSpaceID, aAttr, aNotify);
|
2010-08-19 15:50:37 -07:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2009-10-01 07:10:13 -07:00
|
|
|
if (aNotify && aNameSpaceID == kNameSpaceID_None) {
|
|
|
|
if (aAttr == nsGkAtoms::autoplay) {
|
|
|
|
// This attribute can affect AddRemoveSelfReference
|
|
|
|
AddRemoveSelfReference();
|
2010-08-19 15:50:37 -07:00
|
|
|
UpdatePreloadAction();
|
|
|
|
} else if (aAttr == nsGkAtoms::preload) {
|
|
|
|
UpdatePreloadAction();
|
2009-10-01 07:10:13 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2008-07-09 01:22:20 -07:00
|
|
|
nsresult nsHTMLMediaElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
|
|
|
|
nsIContent* aBindingParent,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aCompileEventHandlers)
|
2008-07-09 01:22:20 -07:00
|
|
|
{
|
2010-10-14 17:13:29 -07:00
|
|
|
nsresult rv = nsGenericHTMLElement::BindToTree(aDocument,
|
|
|
|
aParent,
|
|
|
|
aBindingParent,
|
|
|
|
aCompileEventHandlers);
|
2010-02-24 11:14:14 -08:00
|
|
|
if (aDocument) {
|
|
|
|
mAutoplayEnabled =
|
2010-10-14 17:13:29 -07:00
|
|
|
IsAutoplayEnabled() && (!aDocument || !aDocument->IsStaticDocument()) &&
|
|
|
|
!IsEditable();
|
2010-08-19 15:50:37 -07:00
|
|
|
// The preload action depends on the value of the autoplay attribute.
|
|
|
|
// It's value may have changed, so update it.
|
|
|
|
UpdatePreloadAction();
|
2011-11-21 16:34:21 -08:00
|
|
|
|
|
|
|
if (aDocument->HasAudioAvailableListeners()) {
|
|
|
|
// The document already has listeners for the "MozAudioAvailable"
|
|
|
|
// event, so the decoder must be notified so it initiates
|
|
|
|
// "MozAudioAvailable" event dispatch.
|
|
|
|
NotifyAudioAvailableListener();
|
|
|
|
}
|
2010-02-24 11:14:14 -08:00
|
|
|
}
|
2009-02-15 17:05:28 -08:00
|
|
|
|
2008-07-09 01:22:20 -07:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
void nsHTMLMediaElement::UnbindFromTree(bool aDeep,
|
|
|
|
bool aNullParent)
|
2008-07-09 01:22:20 -07:00
|
|
|
{
|
2008-12-14 19:38:16 -08:00
|
|
|
if (!mPaused && mNetworkState != nsIDOMHTMLMediaElement::NETWORK_EMPTY)
|
2008-08-03 18:51:01 -07:00
|
|
|
Pause();
|
2008-07-09 01:22:20 -07:00
|
|
|
nsGenericHTMLElement::UnbindFromTree(aDeep, aNullParent);
|
|
|
|
}
|
|
|
|
|
2010-07-26 12:35:16 -07:00
|
|
|
#ifdef MOZ_RAW
|
|
|
|
static const char gRawTypes[][16] = {
|
|
|
|
"video/x-raw",
|
|
|
|
"video/x-raw-yuv"
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char* gRawCodecs[] = {
|
|
|
|
nsnull
|
|
|
|
};
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool IsRawEnabled()
|
2010-07-26 12:35:16 -07:00
|
|
|
{
|
2011-05-24 23:31:59 -07:00
|
|
|
return Preferences::GetBool("media.raw.enabled");
|
2010-07-26 12:35:16 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool IsRawType(const nsACString& aType)
|
2010-07-26 12:35:16 -07:00
|
|
|
{
|
2011-11-15 23:50:19 -08:00
|
|
|
if (!IsRawEnabled()) {
|
2011-09-29 16:34:37 -07:00
|
|
|
return false;
|
2011-11-15 23:50:19 -08:00
|
|
|
}
|
|
|
|
|
2011-10-10 22:50:08 -07:00
|
|
|
for (PRUint32 i = 0; i < ArrayLength(gRawTypes); ++i) {
|
2011-11-15 23:50:19 -08:00
|
|
|
if (aType.EqualsASCII(gRawTypes[i])) {
|
2011-09-29 16:34:37 -07:00
|
|
|
return true;
|
2011-11-15 23:50:19 -08:00
|
|
|
}
|
2010-07-26 12:35:16 -07:00
|
|
|
}
|
2011-11-15 23:50:19 -08:00
|
|
|
|
2011-09-29 16:34:37 -07:00
|
|
|
return false;
|
2010-07-26 12:35:16 -07:00
|
|
|
}
|
|
|
|
#endif
|
2008-10-29 22:20:08 -07:00
|
|
|
#ifdef MOZ_OGG
|
2008-12-16 18:11:07 -08:00
|
|
|
// See http://www.rfc-editor.org/rfc/rfc5334.txt for the definitions
|
|
|
|
// of Ogg media types and codec types
|
2010-06-10 11:11:11 -07:00
|
|
|
const char nsHTMLMediaElement::gOggTypes[3][16] = {
|
2008-10-29 22:20:08 -07:00
|
|
|
"video/ogg",
|
|
|
|
"audio/ogg",
|
|
|
|
"application/ogg"
|
|
|
|
};
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
char const *const nsHTMLMediaElement::gOggCodecs[3] = {
|
2008-12-16 18:11:07 -08:00
|
|
|
"vorbis",
|
|
|
|
"theora",
|
|
|
|
nsnull
|
|
|
|
};
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
bool
|
|
|
|
nsHTMLMediaElement::IsOggEnabled()
|
2008-12-12 00:17:57 -08:00
|
|
|
{
|
2011-05-24 23:31:59 -07:00
|
|
|
return Preferences::GetBool("media.ogg.enabled");
|
2008-12-12 00:17:57 -08:00
|
|
|
}
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
bool
|
|
|
|
nsHTMLMediaElement::IsOggType(const nsACString& aType)
|
2008-10-29 22:20:08 -07:00
|
|
|
{
|
2011-11-15 23:50:19 -08:00
|
|
|
if (!IsOggEnabled()) {
|
2011-09-29 16:34:37 -07:00
|
|
|
return false;
|
2011-11-15 23:50:19 -08:00
|
|
|
}
|
|
|
|
|
2011-10-10 22:50:08 -07:00
|
|
|
for (PRUint32 i = 0; i < ArrayLength(gOggTypes); ++i) {
|
2011-11-15 23:50:19 -08:00
|
|
|
if (aType.EqualsASCII(gOggTypes[i])) {
|
2011-09-29 16:34:37 -07:00
|
|
|
return true;
|
2011-11-15 23:50:19 -08:00
|
|
|
}
|
2008-10-29 22:20:08 -07:00
|
|
|
}
|
2011-11-15 23:50:19 -08:00
|
|
|
|
2011-09-29 16:34:37 -07:00
|
|
|
return false;
|
2008-10-29 22:20:08 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-11-06 12:53:20 -08:00
|
|
|
#ifdef MOZ_WAVE
|
2008-12-16 18:11:07 -08:00
|
|
|
// See http://www.rfc-editor.org/rfc/rfc2361.txt for the definitions
|
|
|
|
// of WAVE media types and codec types. However, the audio/vnd.wave
|
|
|
|
// MIME type described there is not used.
|
2010-06-10 11:11:11 -07:00
|
|
|
const char nsHTMLMediaElement::gWaveTypes[4][16] = {
|
2008-11-06 12:53:20 -08:00
|
|
|
"audio/x-wav",
|
|
|
|
"audio/wav",
|
|
|
|
"audio/wave",
|
|
|
|
"audio/x-pn-wav"
|
|
|
|
};
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
char const *const nsHTMLMediaElement::gWaveCodecs[2] = {
|
2008-12-16 18:11:07 -08:00
|
|
|
"1", // Microsoft PCM Format
|
|
|
|
nsnull
|
|
|
|
};
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
bool
|
|
|
|
nsHTMLMediaElement::IsWaveEnabled()
|
2008-12-12 00:17:57 -08:00
|
|
|
{
|
2011-05-24 23:31:59 -07:00
|
|
|
return Preferences::GetBool("media.wave.enabled");
|
2008-12-12 00:17:57 -08:00
|
|
|
}
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
bool
|
|
|
|
nsHTMLMediaElement::IsWaveType(const nsACString& aType)
|
2008-11-06 12:53:20 -08:00
|
|
|
{
|
2011-11-15 23:50:19 -08:00
|
|
|
if (!IsWaveEnabled()) {
|
2011-09-29 16:34:37 -07:00
|
|
|
return false;
|
2011-11-15 23:50:19 -08:00
|
|
|
}
|
|
|
|
|
2011-10-10 22:50:08 -07:00
|
|
|
for (PRUint32 i = 0; i < ArrayLength(gWaveTypes); ++i) {
|
2011-11-15 23:50:19 -08:00
|
|
|
if (aType.EqualsASCII(gWaveTypes[i])) {
|
2011-09-29 16:34:37 -07:00
|
|
|
return true;
|
2011-11-15 23:50:19 -08:00
|
|
|
}
|
2008-11-06 12:53:20 -08:00
|
|
|
}
|
2011-11-15 23:50:19 -08:00
|
|
|
|
2011-09-29 16:34:37 -07:00
|
|
|
return false;
|
2008-11-06 12:53:20 -08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-06-08 16:31:27 -07:00
|
|
|
#ifdef MOZ_WEBM
|
2010-06-10 11:11:11 -07:00
|
|
|
const char nsHTMLMediaElement::gWebMTypes[2][17] = {
|
2010-06-08 16:31:27 -07:00
|
|
|
"video/webm",
|
|
|
|
"audio/webm"
|
|
|
|
};
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
char const *const nsHTMLMediaElement::gWebMCodecs[4] = {
|
2010-06-08 16:31:27 -07:00
|
|
|
"vp8",
|
|
|
|
"vp8.0",
|
|
|
|
"vorbis",
|
|
|
|
nsnull
|
|
|
|
};
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
bool
|
|
|
|
nsHTMLMediaElement::IsWebMEnabled()
|
2010-06-08 16:31:27 -07:00
|
|
|
{
|
2011-05-24 23:31:59 -07:00
|
|
|
return Preferences::GetBool("media.webm.enabled");
|
2010-06-08 16:31:27 -07:00
|
|
|
}
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
bool
|
|
|
|
nsHTMLMediaElement::IsWebMType(const nsACString& aType)
|
2010-06-08 16:31:27 -07:00
|
|
|
{
|
2011-11-15 23:50:19 -08:00
|
|
|
if (!IsWebMEnabled()) {
|
2011-09-29 16:34:37 -07:00
|
|
|
return false;
|
2011-11-15 23:50:19 -08:00
|
|
|
}
|
|
|
|
|
2011-10-10 22:50:08 -07:00
|
|
|
for (PRUint32 i = 0; i < ArrayLength(gWebMTypes); ++i) {
|
2011-11-15 23:50:19 -08:00
|
|
|
if (aType.EqualsASCII(gWebMTypes[i])) {
|
2011-09-29 16:34:37 -07:00
|
|
|
return true;
|
2011-11-15 23:50:19 -08:00
|
|
|
}
|
2010-06-08 16:31:27 -07:00
|
|
|
}
|
2011-11-15 23:50:19 -08:00
|
|
|
|
2011-09-29 16:34:37 -07:00
|
|
|
return false;
|
2010-06-08 16:31:27 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-10-29 22:20:08 -07:00
|
|
|
/* static */
|
2010-06-08 16:31:27 -07:00
|
|
|
nsHTMLMediaElement::CanPlayStatus
|
|
|
|
nsHTMLMediaElement::CanHandleMediaType(const char* aMIMEType,
|
2010-06-10 11:11:11 -07:00
|
|
|
char const *const ** aCodecList)
|
2008-10-29 22:20:08 -07:00
|
|
|
{
|
2010-07-26 12:35:16 -07:00
|
|
|
#ifdef MOZ_RAW
|
|
|
|
if (IsRawType(nsDependentCString(aMIMEType))) {
|
|
|
|
*aCodecList = gRawCodecs;
|
|
|
|
return CANPLAY_MAYBE;
|
|
|
|
}
|
|
|
|
#endif
|
2008-10-29 22:20:08 -07:00
|
|
|
#ifdef MOZ_OGG
|
2008-12-16 18:11:07 -08:00
|
|
|
if (IsOggType(nsDependentCString(aMIMEType))) {
|
|
|
|
*aCodecList = gOggCodecs;
|
2010-06-08 16:31:27 -07:00
|
|
|
return CANPLAY_MAYBE;
|
2008-12-16 18:11:07 -08:00
|
|
|
}
|
2008-11-06 12:53:20 -08:00
|
|
|
#endif
|
|
|
|
#ifdef MOZ_WAVE
|
2008-12-16 18:11:07 -08:00
|
|
|
if (IsWaveType(nsDependentCString(aMIMEType))) {
|
|
|
|
*aCodecList = gWaveCodecs;
|
2010-06-08 16:31:27 -07:00
|
|
|
return CANPLAY_MAYBE;
|
2008-12-16 18:11:07 -08:00
|
|
|
}
|
2008-10-29 22:20:08 -07:00
|
|
|
#endif
|
2010-06-08 16:31:27 -07:00
|
|
|
#ifdef MOZ_WEBM
|
|
|
|
if (IsWebMType(nsDependentCString(aMIMEType))) {
|
|
|
|
*aCodecList = gWebMCodecs;
|
|
|
|
return CANPLAY_YES;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return CANPLAY_NO;
|
2008-10-29 22:20:08 -07:00
|
|
|
}
|
|
|
|
|
2009-05-24 17:42:19 -07:00
|
|
|
/* static */
|
2011-09-28 23:19:26 -07:00
|
|
|
bool nsHTMLMediaElement::ShouldHandleMediaType(const char* aMIMEType)
|
2009-05-24 17:42:19 -07:00
|
|
|
{
|
2010-07-26 12:35:16 -07:00
|
|
|
#ifdef MOZ_RAW
|
|
|
|
if (IsRawType(nsDependentCString(aMIMEType)))
|
2011-09-29 16:34:37 -07:00
|
|
|
return true;
|
2010-07-26 12:35:16 -07:00
|
|
|
#endif
|
2009-05-24 17:42:19 -07:00
|
|
|
#ifdef MOZ_OGG
|
|
|
|
if (IsOggType(nsDependentCString(aMIMEType)))
|
2011-09-29 16:34:37 -07:00
|
|
|
return true;
|
2010-06-08 16:31:27 -07:00
|
|
|
#endif
|
|
|
|
#ifdef MOZ_WEBM
|
|
|
|
if (IsWebMType(nsDependentCString(aMIMEType)))
|
2011-09-29 16:34:37 -07:00
|
|
|
return true;
|
2009-05-24 17:42:19 -07:00
|
|
|
#endif
|
|
|
|
// We should not return true for Wave types, since there are some
|
|
|
|
// Wave codecs actually in use in the wild that we don't support, and
|
|
|
|
// we should allow those to be handled by plugins or helper apps.
|
|
|
|
// Furthermore people can play Wave files on most platforms by other
|
|
|
|
// means.
|
2011-09-29 16:34:37 -07:00
|
|
|
return false;
|
2009-05-24 17:42:19 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2010-06-10 11:11:11 -07:00
|
|
|
CodecListContains(char const *const * aCodecs, const nsAString& aCodec)
|
2008-12-16 18:11:07 -08:00
|
|
|
{
|
|
|
|
for (PRInt32 i = 0; aCodecs[i]; ++i) {
|
|
|
|
if (aCodec.EqualsASCII(aCodecs[i]))
|
2011-09-29 16:34:37 -07:00
|
|
|
return true;
|
2008-12-16 18:11:07 -08:00
|
|
|
}
|
2011-09-29 16:34:37 -07:00
|
|
|
return false;
|
2008-12-16 18:11:07 -08:00
|
|
|
}
|
|
|
|
|
2010-06-08 16:31:27 -07:00
|
|
|
/* static */
|
|
|
|
nsHTMLMediaElement::CanPlayStatus
|
|
|
|
nsHTMLMediaElement::GetCanPlay(const nsAString& aType)
|
2008-12-16 18:11:07 -08:00
|
|
|
{
|
|
|
|
nsContentTypeParser parser(aType);
|
|
|
|
nsAutoString mimeType;
|
|
|
|
nsresult rv = parser.GetType(mimeType);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return CANPLAY_NO;
|
|
|
|
|
|
|
|
NS_ConvertUTF16toUTF8 mimeTypeUTF8(mimeType);
|
2010-06-10 11:11:11 -07:00
|
|
|
char const *const * supportedCodecs;
|
2010-06-08 16:31:27 -07:00
|
|
|
CanPlayStatus status = CanHandleMediaType(mimeTypeUTF8.get(),
|
|
|
|
&supportedCodecs);
|
|
|
|
if (status == CANPLAY_NO)
|
2008-12-16 18:11:07 -08:00
|
|
|
return CANPLAY_NO;
|
|
|
|
|
|
|
|
nsAutoString codecs;
|
|
|
|
rv = parser.GetParameter("codecs", codecs);
|
2010-06-08 16:31:27 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
2008-12-16 18:11:07 -08:00
|
|
|
// Parameter not found or whatever
|
2010-06-08 16:31:27 -07:00
|
|
|
return status;
|
|
|
|
}
|
2008-12-16 18:11:07 -08:00
|
|
|
|
|
|
|
CanPlayStatus result = CANPLAY_YES;
|
|
|
|
// See http://www.rfc-editor.org/rfc/rfc4281.txt for the description
|
|
|
|
// of the 'codecs' parameter
|
2010-05-04 07:43:48 -07:00
|
|
|
nsCharSeparatedTokenizer tokenizer(codecs, ',');
|
2011-09-28 23:19:26 -07:00
|
|
|
bool expectMoreTokens = false;
|
2008-12-16 18:11:07 -08:00
|
|
|
while (tokenizer.hasMoreTokens()) {
|
|
|
|
const nsSubstring& token = tokenizer.nextToken();
|
|
|
|
|
2009-07-26 15:01:41 -07:00
|
|
|
if (!CodecListContains(supportedCodecs, token)) {
|
2008-12-16 18:11:07 -08:00
|
|
|
// Totally unsupported codec
|
|
|
|
return CANPLAY_NO;
|
|
|
|
}
|
2010-05-04 07:43:48 -07:00
|
|
|
expectMoreTokens = tokenizer.lastTokenEndedWithSeparator();
|
2008-12-16 18:11:07 -08:00
|
|
|
}
|
|
|
|
if (expectMoreTokens) {
|
|
|
|
// Last codec name was empty
|
|
|
|
return CANPLAY_NO;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLMediaElement::CanPlayType(const nsAString& aType, nsAString& aResult)
|
|
|
|
{
|
|
|
|
switch (GetCanPlay(aType)) {
|
2011-11-15 23:50:19 -08:00
|
|
|
case CANPLAY_NO:
|
|
|
|
aResult.Truncate();
|
|
|
|
break;
|
|
|
|
case CANPLAY_YES:
|
|
|
|
aResult.AssignLiteral("probably");
|
|
|
|
break;
|
2008-12-16 18:11:07 -08:00
|
|
|
default:
|
2011-11-15 23:50:19 -08:00
|
|
|
case CANPLAY_MAYBE:
|
|
|
|
aResult.AssignLiteral("maybe");
|
|
|
|
break;
|
2008-12-16 18:11:07 -08:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-10-01 07:10:13 -07:00
|
|
|
already_AddRefed<nsMediaDecoder>
|
|
|
|
nsHTMLMediaElement::CreateDecoder(const nsACString& aType)
|
2008-10-29 22:20:08 -07:00
|
|
|
{
|
2010-07-26 12:35:16 -07:00
|
|
|
#ifdef MOZ_RAW
|
|
|
|
if (IsRawType(aType)) {
|
|
|
|
nsRefPtr<nsRawDecoder> decoder = new nsRawDecoder();
|
2011-11-15 23:50:19 -08:00
|
|
|
if (decoder->Init(this)) {
|
|
|
|
return decoder.forget();
|
2010-07-26 12:35:16 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2008-10-29 22:20:08 -07:00
|
|
|
#ifdef MOZ_OGG
|
|
|
|
if (IsOggType(aType)) {
|
2009-10-01 07:10:13 -07:00
|
|
|
nsRefPtr<nsOggDecoder> decoder = new nsOggDecoder();
|
2011-11-15 23:50:19 -08:00
|
|
|
if (decoder->Init(this)) {
|
|
|
|
return decoder.forget();
|
2008-10-29 22:20:08 -07:00
|
|
|
}
|
|
|
|
}
|
2008-11-06 12:53:20 -08:00
|
|
|
#endif
|
|
|
|
#ifdef MOZ_WAVE
|
|
|
|
if (IsWaveType(aType)) {
|
2009-10-01 07:10:13 -07:00
|
|
|
nsRefPtr<nsWaveDecoder> decoder = new nsWaveDecoder();
|
2011-11-15 23:50:19 -08:00
|
|
|
if (decoder->Init(this)) {
|
|
|
|
return decoder.forget();
|
2008-11-06 12:53:20 -08:00
|
|
|
}
|
|
|
|
}
|
2010-06-08 16:31:27 -07:00
|
|
|
#endif
|
|
|
|
#ifdef MOZ_WEBM
|
|
|
|
if (IsWebMType(aType)) {
|
|
|
|
nsRefPtr<nsWebMDecoder> decoder = new nsWebMDecoder();
|
2011-11-15 23:50:19 -08:00
|
|
|
if (decoder->Init(this)) {
|
|
|
|
return decoder.forget();
|
2010-06-08 16:31:27 -07:00
|
|
|
}
|
|
|
|
}
|
2008-10-29 22:20:08 -07:00
|
|
|
#endif
|
2009-10-01 07:10:13 -07:00
|
|
|
return nsnull;
|
2008-10-29 22:20:08 -07:00
|
|
|
}
|
|
|
|
|
2009-09-14 19:30:44 -07:00
|
|
|
nsresult nsHTMLMediaElement::InitializeDecoderAsClone(nsMediaDecoder* aOriginal)
|
|
|
|
{
|
2011-11-24 18:06:22 -08:00
|
|
|
NS_ASSERTION(mLoadingSrc, "mLoadingSrc must already be set");
|
|
|
|
|
2011-11-24 18:06:20 -08:00
|
|
|
nsMediaStream* originalStream = aOriginal->GetStream();
|
2009-09-14 19:30:44 -07:00
|
|
|
if (!originalStream)
|
|
|
|
return NS_ERROR_FAILURE;
|
2009-10-01 07:10:13 -07:00
|
|
|
nsRefPtr<nsMediaDecoder> decoder = aOriginal->Clone();
|
|
|
|
if (!decoder)
|
2009-09-14 19:30:44 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2009-11-05 23:32:52 -08:00
|
|
|
LOG(PR_LOG_DEBUG, ("%p Cloned decoder %p from %p", this, decoder.get(), aOriginal));
|
2009-09-29 14:32:44 -07:00
|
|
|
|
2009-10-01 07:10:13 -07:00
|
|
|
if (!decoder->Init(this)) {
|
2009-09-14 19:30:44 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2011-01-16 19:03:00 -08:00
|
|
|
double duration = aOriginal->GetDuration();
|
2009-10-14 18:28:59 -07:00
|
|
|
if (duration >= 0) {
|
2011-04-13 15:12:23 -07:00
|
|
|
decoder->SetDuration(duration);
|
2011-08-09 03:10:48 -07:00
|
|
|
decoder->SetSeekable(aOriginal->IsSeekable());
|
2009-10-14 18:28:59 -07:00
|
|
|
}
|
|
|
|
|
2009-10-01 07:10:13 -07:00
|
|
|
nsMediaStream* stream = originalStream->CloneData(decoder);
|
2009-09-14 19:30:44 -07:00
|
|
|
if (!stream) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
mNetworkState = nsIDOMHTMLMediaElement::NETWORK_LOADING;
|
|
|
|
|
2010-09-20 17:49:50 -07:00
|
|
|
nsresult rv = decoder->Load(stream, nsnull, aOriginal);
|
2009-09-14 19:30:44 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2009-10-01 07:10:13 -07:00
|
|
|
return FinishDecoderSetup(decoder);
|
2009-09-14 19:30:44 -07:00
|
|
|
}
|
|
|
|
|
2008-10-29 22:20:08 -07:00
|
|
|
nsresult nsHTMLMediaElement::InitializeDecoderForChannel(nsIChannel *aChannel,
|
|
|
|
nsIStreamListener **aListener)
|
|
|
|
{
|
2011-11-24 18:06:22 -08:00
|
|
|
NS_ASSERTION(mLoadingSrc, "mLoadingSrc must already be set");
|
|
|
|
|
2008-10-29 22:20:08 -07:00
|
|
|
nsCAutoString mimeType;
|
|
|
|
aChannel->GetContentType(mimeType);
|
|
|
|
|
2009-10-01 07:10:13 -07:00
|
|
|
nsRefPtr<nsMediaDecoder> decoder = CreateDecoder(mimeType);
|
|
|
|
if (!decoder) {
|
2008-10-29 22:20:08 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
2009-10-01 07:10:13 -07:00
|
|
|
}
|
2008-10-29 22:20:08 -07:00
|
|
|
|
2009-11-05 23:32:52 -08:00
|
|
|
LOG(PR_LOG_DEBUG, ("%p Created decoder %p for type %s", this, decoder.get(), mimeType.get()));
|
2009-09-29 14:32:44 -07:00
|
|
|
|
2008-12-14 19:38:16 -08:00
|
|
|
mNetworkState = nsIDOMHTMLMediaElement::NETWORK_LOADING;
|
2008-12-15 19:32:03 -08:00
|
|
|
|
2009-10-01 07:10:13 -07:00
|
|
|
nsMediaStream* stream = nsMediaStream::Create(decoder, aChannel);
|
2009-09-14 19:30:43 -07:00
|
|
|
if (!stream)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2010-09-20 17:49:50 -07:00
|
|
|
nsresult rv = decoder->Load(stream, aListener, nsnull);
|
2009-09-14 19:30:44 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
2009-02-10 17:23:19 -08:00
|
|
|
return rv;
|
2009-09-14 19:30:44 -07:00
|
|
|
}
|
2009-02-10 17:23:19 -08:00
|
|
|
|
2009-09-14 19:30:43 -07:00
|
|
|
// Decoder successfully created, the decoder now owns the nsMediaStream
|
|
|
|
// which owns the channel.
|
2009-04-09 18:28:24 -07:00
|
|
|
mChannel = nsnull;
|
|
|
|
|
2009-10-01 07:10:13 -07:00
|
|
|
return FinishDecoderSetup(decoder);
|
2009-09-14 19:30:44 -07:00
|
|
|
}
|
|
|
|
|
2009-10-01 07:10:13 -07:00
|
|
|
nsresult nsHTMLMediaElement::FinishDecoderSetup(nsMediaDecoder* aDecoder)
|
2009-09-14 19:30:44 -07:00
|
|
|
{
|
2011-11-24 18:06:22 -08:00
|
|
|
NS_ASSERTION(mLoadingSrc, "mLoadingSrc set up");
|
2011-11-23 15:30:03 -08:00
|
|
|
|
2011-12-01 02:16:26 -08:00
|
|
|
nsCAutoString src;
|
|
|
|
GetCurrentSpec(src);
|
2011-12-09 03:57:34 -08:00
|
|
|
printf("*** nsHTMLElement::FinishDecoderSetup() mDecoder=%p stream=%p src=%s\n",
|
|
|
|
aDecoder, aDecoder->GetStream(), src.get());
|
2011-11-24 18:06:22 -08:00
|
|
|
mDecoder = aDecoder;
|
|
|
|
AddMediaElementToURITable();
|
2010-09-02 17:03:03 -07:00
|
|
|
|
2010-08-25 06:10:00 -07:00
|
|
|
// Force a same-origin check before allowing events for this media resource.
|
2011-09-29 16:34:37 -07:00
|
|
|
mMediaSecurityVerified = false;
|
2010-08-25 06:10:00 -07:00
|
|
|
|
2009-10-01 07:10:13 -07:00
|
|
|
// The new stream has not been suspended by us.
|
2011-09-29 16:34:37 -07:00
|
|
|
mPausedForInactiveDocument = false;
|
2009-10-01 07:10:13 -07:00
|
|
|
// But we may want to suspend it now.
|
|
|
|
// This will also do an AddRemoveSelfReference.
|
|
|
|
NotifyOwnerDocumentActivityChanged();
|
|
|
|
|
2009-09-14 19:30:44 -07:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
2009-02-25 02:59:00 -08:00
|
|
|
mDecoder->SetVolume(mMuted ? 0.0 : mVolume);
|
|
|
|
|
2009-02-10 17:23:19 -08:00
|
|
|
if (!mPaused) {
|
2011-09-29 16:34:37 -07:00
|
|
|
SetPlayedOrSeeked(true);
|
2009-10-01 07:10:13 -07:00
|
|
|
if (!mPausedForInactiveDocument) {
|
|
|
|
rv = mDecoder->Play();
|
|
|
|
}
|
2009-02-10 17:23:19 -08:00
|
|
|
}
|
|
|
|
|
2011-11-21 16:34:21 -08:00
|
|
|
if (OwnerDoc()->HasAudioAvailableListeners()) {
|
|
|
|
NotifyAudioAvailableListener();
|
|
|
|
}
|
|
|
|
|
2011-09-29 16:34:37 -07:00
|
|
|
mBegun = true;
|
2009-02-10 17:23:19 -08:00
|
|
|
return rv;
|
2008-10-29 22:20:08 -07:00
|
|
|
}
|
2008-07-09 01:22:20 -07:00
|
|
|
|
2008-12-15 19:32:03 -08:00
|
|
|
nsresult nsHTMLMediaElement::NewURIFromString(const nsAutoString& aURISpec, nsIURI** aURI)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aURI);
|
|
|
|
|
|
|
|
*aURI = nsnull;
|
|
|
|
|
2011-10-18 03:53:36 -07:00
|
|
|
nsCOMPtr<nsIDocument> doc = OwnerDoc();
|
2008-12-15 19:32:03 -08:00
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> baseURI = GetBaseURI();
|
2011-11-15 23:50:19 -08:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
nsresult rv = nsContentUtils::NewURIWithDocumentCharset(getter_AddRefs(uri),
|
2008-12-15 19:32:03 -08:00
|
|
|
aURISpec,
|
|
|
|
doc,
|
|
|
|
baseURI);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool equal;
|
2008-12-15 19:32:03 -08:00
|
|
|
if (aURISpec.IsEmpty() &&
|
|
|
|
doc->GetDocumentURI() &&
|
2011-11-15 23:50:19 -08:00
|
|
|
NS_SUCCEEDED(doc->GetDocumentURI()->Equals(uri, &equal)) &&
|
2008-12-15 19:32:03 -08:00
|
|
|
equal) {
|
|
|
|
// It's not possible for a media resource to be embedded in the current
|
|
|
|
// document we extracted aURISpec from, so there's no point returning
|
|
|
|
// the current document URI just to let the caller attempt and fail to
|
|
|
|
// decode it.
|
|
|
|
return NS_ERROR_DOM_INVALID_STATE_ERR;
|
|
|
|
}
|
|
|
|
|
2011-11-15 23:50:19 -08:00
|
|
|
uri.forget(aURI);
|
2008-12-15 19:32:03 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-08-24 16:42:23 -07:00
|
|
|
void nsHTMLMediaElement::ProcessMediaFragmentURI()
|
|
|
|
{
|
|
|
|
nsCAutoString ref;
|
|
|
|
GetCurrentSpec(ref);
|
|
|
|
nsMediaFragmentURIParser parser(ref);
|
|
|
|
parser.Parse();
|
|
|
|
double start = parser.GetStartTime();
|
|
|
|
if (mDecoder) {
|
|
|
|
double end = parser.GetEndTime();
|
|
|
|
if (end < 0.0 || end > start) {
|
|
|
|
mFragmentEnd = end;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
start = -1.0;
|
|
|
|
end = -1.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (start > 0.0) {
|
|
|
|
SetCurrentTime(start);
|
|
|
|
mFragmentStart = start;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-25 06:10:00 -07:00
|
|
|
void nsHTMLMediaElement::MetadataLoaded(PRUint32 aChannels, PRUint32 aRate)
|
2008-07-09 01:22:20 -07:00
|
|
|
{
|
2010-08-25 06:10:00 -07:00
|
|
|
mChannels = aChannels;
|
|
|
|
mRate = aRate;
|
2008-12-14 19:38:16 -08:00
|
|
|
ChangeReadyState(nsIDOMHTMLMediaElement::HAVE_METADATA);
|
2010-09-09 20:29:06 -07:00
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("durationchange"));
|
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("loadedmetadata"));
|
2011-08-24 16:42:23 -07:00
|
|
|
if (mDecoder && mDecoder->IsSeekable()) {
|
|
|
|
ProcessMediaFragmentURI();
|
|
|
|
mDecoder->SetEndTime(mFragmentEnd);
|
|
|
|
}
|
2008-07-09 01:22:20 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
void nsHTMLMediaElement::FirstFrameLoaded(bool aResourceFullyLoaded)
|
2008-07-09 01:22:20 -07:00
|
|
|
{
|
2011-05-11 19:02:34 -07:00
|
|
|
ChangeReadyState(aResourceFullyLoaded ?
|
|
|
|
nsIDOMHTMLMediaElement::HAVE_ENOUGH_DATA :
|
|
|
|
nsIDOMHTMLMediaElement::HAVE_CURRENT_DATA);
|
2011-09-29 16:34:37 -07:00
|
|
|
ChangeDelayLoadStatus(false);
|
2009-05-17 19:00:44 -07:00
|
|
|
|
|
|
|
NS_ASSERTION(!mSuspendedAfterFirstFrame, "Should not have already suspended");
|
|
|
|
|
|
|
|
if (mDecoder && mAllowSuspendAfterFirstFrame && mPaused &&
|
2009-05-18 16:06:10 -07:00
|
|
|
!aResourceFullyLoaded &&
|
2009-05-17 19:00:44 -07:00
|
|
|
!HasAttr(kNameSpaceID_None, nsGkAtoms::autoplay) &&
|
2010-08-19 15:50:37 -07:00
|
|
|
mPreloadAction == nsHTMLMediaElement::PRELOAD_METADATA) {
|
2011-09-29 16:34:37 -07:00
|
|
|
mSuspendedAfterFirstFrame = true;
|
2009-05-17 19:00:44 -07:00
|
|
|
mDecoder->Suspend();
|
|
|
|
}
|
2008-07-09 01:22:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsHTMLMediaElement::ResourceLoaded()
|
|
|
|
{
|
2011-09-29 16:34:37 -07:00
|
|
|
mBegun = false;
|
2009-10-09 04:48:55 -07:00
|
|
|
mNetworkState = nsIDOMHTMLMediaElement::NETWORK_IDLE;
|
2009-10-01 07:10:13 -07:00
|
|
|
AddRemoveSelfReference();
|
2011-05-08 14:10:44 -07:00
|
|
|
if (mReadyState >= nsIDOMHTMLMediaElement::HAVE_METADATA) {
|
|
|
|
ChangeReadyState(nsIDOMHTMLMediaElement::HAVE_ENOUGH_DATA);
|
|
|
|
}
|
2010-09-02 17:03:03 -07:00
|
|
|
// Ensure a progress event is dispatched at the end of download.
|
2010-09-09 20:29:06 -07:00
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("progress"));
|
2010-09-02 17:03:03 -07:00
|
|
|
// The download has stopped.
|
2010-09-09 20:29:06 -07:00
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("suspend"));
|
2008-07-09 01:22:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsHTMLMediaElement::NetworkError()
|
|
|
|
{
|
2010-09-02 17:03:03 -07:00
|
|
|
Error(nsIDOMMediaError::MEDIA_ERR_NETWORK);
|
2008-07-09 01:22:20 -07:00
|
|
|
}
|
|
|
|
|
2009-09-21 17:08:13 -07:00
|
|
|
void nsHTMLMediaElement::DecodeError()
|
|
|
|
{
|
2011-07-11 20:39:34 -07:00
|
|
|
if (mDecoder) {
|
2011-11-24 18:06:22 -08:00
|
|
|
RemoveMediaElementFromURITable();
|
2011-07-11 20:39:34 -07:00
|
|
|
mDecoder->Shutdown();
|
|
|
|
mDecoder = nsnull;
|
|
|
|
}
|
2011-11-24 18:06:22 -08:00
|
|
|
mLoadingSrc = nsnull;
|
2010-10-16 12:57:50 -07:00
|
|
|
if (mIsLoadingFromSourceChildren) {
|
2010-10-06 15:58:36 -07:00
|
|
|
mError = nsnull;
|
2011-04-28 07:08:03 -07:00
|
|
|
if (mSourceLoadCandidate) {
|
|
|
|
DispatchAsyncSourceError(mSourceLoadCandidate);
|
|
|
|
QueueLoadFromSourceTask();
|
|
|
|
} else {
|
|
|
|
NS_WARNING("Should know the source we were loading from!");
|
|
|
|
}
|
2010-10-06 15:58:36 -07:00
|
|
|
} else {
|
|
|
|
Error(nsIDOMMediaError::MEDIA_ERR_DECODE);
|
|
|
|
}
|
2010-09-02 17:03:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsHTMLMediaElement::LoadAborted()
|
|
|
|
{
|
|
|
|
Error(nsIDOMMediaError::MEDIA_ERR_ABORTED);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsHTMLMediaElement::Error(PRUint16 aErrorCode)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aErrorCode == nsIDOMMediaError::MEDIA_ERR_DECODE ||
|
|
|
|
aErrorCode == nsIDOMMediaError::MEDIA_ERR_NETWORK ||
|
|
|
|
aErrorCode == nsIDOMMediaError::MEDIA_ERR_ABORTED,
|
|
|
|
"Only use nsIDOMMediaError codes!");
|
|
|
|
mError = new nsMediaError(aErrorCode);
|
2011-09-29 16:34:37 -07:00
|
|
|
mBegun = false;
|
2010-09-09 20:29:06 -07:00
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("error"));
|
2010-09-02 17:03:03 -07:00
|
|
|
if (mReadyState == nsIDOMHTMLMediaElement::HAVE_NOTHING) {
|
|
|
|
mNetworkState = nsIDOMHTMLMediaElement::NETWORK_EMPTY;
|
2010-09-09 20:29:06 -07:00
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("emptied"));
|
2010-09-02 17:03:03 -07:00
|
|
|
} else {
|
|
|
|
mNetworkState = nsIDOMHTMLMediaElement::NETWORK_IDLE;
|
|
|
|
}
|
2009-10-01 07:10:13 -07:00
|
|
|
AddRemoveSelfReference();
|
2011-09-29 16:34:37 -07:00
|
|
|
ChangeDelayLoadStatus(false);
|
2009-09-21 17:08:13 -07:00
|
|
|
}
|
|
|
|
|
2008-10-19 00:39:21 -07:00
|
|
|
void nsHTMLMediaElement::PlaybackEnded()
|
2008-07-09 01:22:20 -07:00
|
|
|
{
|
2008-12-14 10:02:54 -08:00
|
|
|
NS_ASSERTION(mDecoder->IsEnded(), "Decoder fired ended, but not in ended state");
|
2009-10-01 07:10:13 -07:00
|
|
|
// We changed the state of IsPlaybackEnded which can affect AddRemoveSelfReference
|
|
|
|
AddRemoveSelfReference();
|
|
|
|
|
2011-08-01 11:11:20 -07:00
|
|
|
if (mDecoder && mDecoder->IsInfinite()) {
|
|
|
|
LOG(PR_LOG_DEBUG, ("%p, got duration by reaching the end of the stream", this));
|
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("durationchange"));
|
|
|
|
}
|
|
|
|
|
2011-11-20 14:59:01 -08:00
|
|
|
if (HasAttr(kNameSpaceID_None, nsGkAtoms::loop)) {
|
|
|
|
SetCurrentTime(0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-09-29 16:34:37 -07:00
|
|
|
FireTimeUpdate(false);
|
2010-09-09 20:29:06 -07:00
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("ended"));
|
2008-07-09 01:22:20 -07:00
|
|
|
}
|
|
|
|
|
2008-10-19 00:39:21 -07:00
|
|
|
void nsHTMLMediaElement::SeekStarted()
|
|
|
|
{
|
2010-09-09 20:29:06 -07:00
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("seeking"));
|
2011-09-29 16:34:37 -07:00
|
|
|
FireTimeUpdate(false);
|
2008-10-19 00:39:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsHTMLMediaElement::SeekCompleted()
|
|
|
|
{
|
2011-09-29 16:34:37 -07:00
|
|
|
mPlayingBeforeSeek = false;
|
|
|
|
SetPlayedOrSeeked(true);
|
2010-09-09 20:29:06 -07:00
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("seeked"));
|
2009-10-01 07:10:13 -07:00
|
|
|
// We changed whether we're seeking so we need to AddRemoveSelfReference
|
|
|
|
AddRemoveSelfReference();
|
2008-10-19 00:39:21 -07:00
|
|
|
}
|
|
|
|
|
2009-05-17 19:03:37 -07:00
|
|
|
void nsHTMLMediaElement::DownloadSuspended()
|
|
|
|
{
|
2011-07-23 14:45:37 -07:00
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("progress"));
|
2009-05-17 19:03:37 -07:00
|
|
|
if (mBegun) {
|
|
|
|
mNetworkState = nsIDOMHTMLMediaElement::NETWORK_IDLE;
|
2009-10-01 07:10:13 -07:00
|
|
|
AddRemoveSelfReference();
|
2010-09-09 20:29:06 -07:00
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("suspend"));
|
2009-05-17 19:03:37 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsHTMLMediaElement::DownloadResumed()
|
|
|
|
{
|
|
|
|
if (mBegun) {
|
|
|
|
mNetworkState = nsIDOMHTMLMediaElement::NETWORK_LOADING;
|
2009-10-01 07:10:13 -07:00
|
|
|
AddRemoveSelfReference();
|
2009-05-17 19:03:37 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsHTMLMediaElement::DownloadStalled()
|
|
|
|
{
|
|
|
|
if (mNetworkState == nsIDOMHTMLMediaElement::NETWORK_LOADING) {
|
2010-09-09 20:29:06 -07:00
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("stalled"));
|
2009-05-17 19:03:37 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool nsHTMLMediaElement::ShouldCheckAllowOrigin()
|
2009-01-24 03:00:17 -08:00
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
return Preferences::GetBool("media.enforce_same_site_origin", true);
|
2009-01-24 03:00:17 -08:00
|
|
|
}
|
|
|
|
|
2009-02-10 17:43:45 -08:00
|
|
|
void nsHTMLMediaElement::UpdateReadyStateForData(NextFrameStatus aNextFrame)
|
2009-02-05 00:02:21 -08:00
|
|
|
{
|
|
|
|
if (mReadyState < nsIDOMHTMLMediaElement::HAVE_METADATA) {
|
2009-03-31 17:52:56 -07:00
|
|
|
// aNextFrame might have a next frame because the decoder can advance
|
|
|
|
// on its own thread before ResourceLoaded or MetadataLoaded gets
|
|
|
|
// a chance to run.
|
|
|
|
// The arrival of more data can't change us out of this readyState.
|
2009-02-05 00:02:21 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-05-18 15:44:17 -07:00
|
|
|
if (aNextFrame != NEXT_FRAME_AVAILABLE) {
|
2009-02-05 00:02:21 -08:00
|
|
|
ChangeReadyState(nsIDOMHTMLMediaElement::HAVE_CURRENT_DATA);
|
2009-02-10 17:43:45 -08:00
|
|
|
if (!mWaitingFired && aNextFrame == NEXT_FRAME_UNAVAILABLE_BUFFERING) {
|
2011-09-29 16:34:37 -07:00
|
|
|
FireTimeUpdate(false);
|
2010-09-09 20:29:06 -07:00
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("waiting"));
|
2011-09-29 16:34:37 -07:00
|
|
|
mWaitingFired = true;
|
2009-02-10 17:43:45 -08:00
|
|
|
}
|
2009-02-05 00:02:21 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-05-18 22:14:20 -07:00
|
|
|
// Now see if we should set HAVE_ENOUGH_DATA.
|
|
|
|
// If it's something we don't know the size of, then we can't
|
|
|
|
// make a real estimate, so we go straight to HAVE_ENOUGH_DATA once
|
|
|
|
// we've downloaded enough data that our download rate is considered
|
|
|
|
// reliable. We have to move to HAVE_ENOUGH_DATA at some point or
|
2010-07-22 15:48:32 -07:00
|
|
|
// autoplay elements for live streams will never play. Otherwise we
|
|
|
|
// move to HAVE_ENOUGH_DATA if we can play through the entire media
|
|
|
|
// without stopping to buffer.
|
|
|
|
nsMediaDecoder::Statistics stats = mDecoder->GetStatistics();
|
2009-05-18 22:14:20 -07:00
|
|
|
if (stats.mTotalBytes < 0 ? stats.mDownloadRateReliable :
|
2010-07-22 15:48:32 -07:00
|
|
|
stats.mTotalBytes == stats.mDownloadPosition ||
|
|
|
|
mDecoder->CanPlayThrough())
|
|
|
|
{
|
2009-02-05 00:02:21 -08:00
|
|
|
ChangeReadyState(nsIDOMHTMLMediaElement::HAVE_ENOUGH_DATA);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ChangeReadyState(nsIDOMHTMLMediaElement::HAVE_FUTURE_DATA);
|
|
|
|
}
|
|
|
|
|
2009-09-29 14:32:44 -07:00
|
|
|
#ifdef PR_LOGGING
|
2009-03-18 16:59:34 -07:00
|
|
|
static const char* gReadyStateToString[] = {
|
|
|
|
"HAVE_NOTHING",
|
|
|
|
"HAVE_METADATA",
|
|
|
|
"HAVE_CURRENT_DATA",
|
|
|
|
"HAVE_FUTURE_DATA",
|
|
|
|
"HAVE_ENOUGH_DATA"
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2008-07-09 01:22:20 -07:00
|
|
|
void nsHTMLMediaElement::ChangeReadyState(nsMediaReadyState aState)
|
|
|
|
{
|
2009-02-05 00:02:21 -08:00
|
|
|
nsMediaReadyState oldState = mReadyState;
|
2009-03-18 16:59:34 -07:00
|
|
|
mReadyState = aState;
|
|
|
|
|
2009-11-05 23:32:52 -08:00
|
|
|
if (mNetworkState == nsIDOMHTMLMediaElement::NETWORK_EMPTY ||
|
2009-03-18 16:59:34 -07:00
|
|
|
oldState == mReadyState) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-09-29 14:32:44 -07:00
|
|
|
LOG(PR_LOG_DEBUG, ("%p Ready state changed to %s", this, gReadyStateToString[aState]));
|
2009-02-05 00:02:21 -08:00
|
|
|
|
2008-12-14 19:38:16 -08:00
|
|
|
// Handle raising of "waiting" event during seek (see 4.8.10.9)
|
2009-03-18 16:59:34 -07:00
|
|
|
if (mPlayingBeforeSeek &&
|
|
|
|
oldState < nsIDOMHTMLMediaElement::HAVE_FUTURE_DATA) {
|
2010-09-09 20:29:06 -07:00
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("waiting"));
|
2009-02-05 00:02:21 -08:00
|
|
|
}
|
2008-07-09 01:22:20 -07:00
|
|
|
|
2009-03-18 16:59:34 -07:00
|
|
|
if (oldState < nsIDOMHTMLMediaElement::HAVE_CURRENT_DATA &&
|
2009-11-05 23:32:52 -08:00
|
|
|
mReadyState >= nsIDOMHTMLMediaElement::HAVE_CURRENT_DATA &&
|
2009-03-18 16:59:34 -07:00
|
|
|
!mLoadedFirstFrame)
|
|
|
|
{
|
2010-09-09 20:29:06 -07:00
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("loadeddata"));
|
2011-09-29 16:34:37 -07:00
|
|
|
mLoadedFirstFrame = true;
|
2009-03-18 16:59:34 -07:00
|
|
|
}
|
2009-02-05 02:51:24 -08:00
|
|
|
|
2009-03-18 16:59:34 -07:00
|
|
|
if (mReadyState == nsIDOMHTMLMediaElement::HAVE_CURRENT_DATA) {
|
2011-09-29 16:34:37 -07:00
|
|
|
mWaitingFired = false;
|
2009-03-18 16:59:34 -07:00
|
|
|
}
|
|
|
|
|
2009-11-05 23:32:52 -08:00
|
|
|
if (oldState < nsIDOMHTMLMediaElement::HAVE_FUTURE_DATA &&
|
2009-03-18 16:59:34 -07:00
|
|
|
mReadyState >= nsIDOMHTMLMediaElement::HAVE_FUTURE_DATA) {
|
2010-09-09 20:29:06 -07:00
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("canplay"));
|
2009-03-18 16:59:34 -07:00
|
|
|
}
|
|
|
|
|
2009-03-31 17:52:56 -07:00
|
|
|
if (mReadyState == nsIDOMHTMLMediaElement::HAVE_ENOUGH_DATA) {
|
|
|
|
NotifyAutoplayDataReady();
|
2009-03-18 16:59:34 -07:00
|
|
|
}
|
2009-11-05 23:32:52 -08:00
|
|
|
|
|
|
|
if (oldState < nsIDOMHTMLMediaElement::HAVE_FUTURE_DATA &&
|
2009-03-18 16:59:34 -07:00
|
|
|
mReadyState >= nsIDOMHTMLMediaElement::HAVE_FUTURE_DATA &&
|
|
|
|
IsPotentiallyPlaying()) {
|
2010-09-09 20:29:06 -07:00
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("playing"));
|
2009-03-18 16:59:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (oldState < nsIDOMHTMLMediaElement::HAVE_ENOUGH_DATA &&
|
|
|
|
mReadyState >= nsIDOMHTMLMediaElement::HAVE_ENOUGH_DATA) {
|
2010-09-09 20:29:06 -07:00
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("canplaythrough"));
|
2008-12-15 19:32:03 -08:00
|
|
|
}
|
2008-07-09 01:22:20 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool nsHTMLMediaElement::CanActivateAutoplay()
|
2009-10-01 07:10:13 -07:00
|
|
|
{
|
|
|
|
return mAutoplaying &&
|
|
|
|
mPaused &&
|
|
|
|
HasAttr(kNameSpaceID_None, nsGkAtoms::autoplay) &&
|
2010-10-14 17:13:29 -07:00
|
|
|
mAutoplayEnabled &&
|
|
|
|
!IsEditable();
|
2009-10-01 07:10:13 -07:00
|
|
|
}
|
|
|
|
|
2009-03-31 17:52:56 -07:00
|
|
|
void nsHTMLMediaElement::NotifyAutoplayDataReady()
|
|
|
|
{
|
2009-10-01 07:10:13 -07:00
|
|
|
if (CanActivateAutoplay()) {
|
2011-09-29 16:34:37 -07:00
|
|
|
mPaused = false;
|
2009-10-01 07:10:13 -07:00
|
|
|
// We changed mPaused which can affect AddRemoveSelfReference
|
|
|
|
AddRemoveSelfReference();
|
|
|
|
|
2009-03-31 17:52:56 -07:00
|
|
|
if (mDecoder) {
|
2011-09-29 16:34:37 -07:00
|
|
|
SetPlayedOrSeeked(true);
|
2009-03-31 17:52:56 -07:00
|
|
|
mDecoder->Play();
|
|
|
|
}
|
2010-09-09 20:29:06 -07:00
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("play"));
|
2009-03-31 17:52:56 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-01 15:41:49 -08:00
|
|
|
ImageContainer* nsHTMLMediaElement::GetImageContainer()
|
|
|
|
{
|
|
|
|
if (mImageContainer)
|
|
|
|
return mImageContainer;
|
|
|
|
|
|
|
|
// If we have a print surface, this is just a static image so
|
|
|
|
// no image container is required
|
|
|
|
if (mPrintSurface)
|
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
// Only video frames need an image container.
|
2011-08-30 14:45:31 -07:00
|
|
|
nsCOMPtr<nsIDOMHTMLVideoElement> video = do_QueryObject(this);
|
2010-03-01 15:41:49 -08:00
|
|
|
if (!video)
|
|
|
|
return nsnull;
|
|
|
|
|
2010-12-06 18:05:55 -08:00
|
|
|
nsRefPtr<LayerManager> manager =
|
2011-10-18 03:53:36 -07:00
|
|
|
nsContentUtils::PersistentLayerManagerForDocument(OwnerDoc());
|
2010-03-01 15:41:49 -08:00
|
|
|
if (!manager)
|
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
mImageContainer = manager->CreateImageContainer();
|
2011-04-20 21:38:39 -07:00
|
|
|
if (manager->IsCompositingCheap()) {
|
2011-09-29 16:34:37 -07:00
|
|
|
mImageContainer->SetDelayedConversion(true);
|
2011-04-20 21:38:39 -07:00
|
|
|
}
|
2010-03-01 15:41:49 -08:00
|
|
|
return mImageContainer;
|
2008-07-09 01:22:20 -07:00
|
|
|
}
|
|
|
|
|
2010-08-25 06:10:00 -07:00
|
|
|
nsresult nsHTMLMediaElement::DispatchAudioAvailableEvent(float* aFrameBuffer,
|
|
|
|
PRUint32 aFrameBufferLength,
|
2010-10-06 15:58:36 -07:00
|
|
|
float aTime)
|
2010-08-25 06:10:00 -07:00
|
|
|
{
|
2010-09-05 19:14:50 -07:00
|
|
|
// Auto manage the memory for the frame buffer. If we fail and return
|
|
|
|
// an error, this ensures we free the memory in the frame buffer. Otherwise
|
|
|
|
// we hand off ownership of the frame buffer to the audioavailable event,
|
|
|
|
// which frees the memory when it's destroyed.
|
|
|
|
nsAutoArrayPtr<float> frameBuffer(aFrameBuffer);
|
|
|
|
|
2011-10-18 03:53:36 -07:00
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc = do_QueryInterface(OwnerDoc());
|
2011-08-30 14:45:31 -07:00
|
|
|
nsCOMPtr<nsIDOMEventTarget> target(do_QueryObject(this));
|
2011-05-23 09:46:36 -07:00
|
|
|
NS_ENSURE_TRUE(domDoc && target, NS_ERROR_INVALID_ARG);
|
2010-08-25 06:10:00 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMEvent> event;
|
2011-05-23 09:46:36 -07:00
|
|
|
nsresult rv = domDoc->CreateEvent(NS_LITERAL_STRING("MozAudioAvailableEvent"),
|
|
|
|
getter_AddRefs(event));
|
2010-08-25 06:10:00 -07:00
|
|
|
nsCOMPtr<nsIDOMNotifyAudioAvailableEvent> audioavailableEvent(do_QueryInterface(event));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = audioavailableEvent->InitAudioAvailableEvent(NS_LITERAL_STRING("MozAudioAvailable"),
|
2011-09-29 16:34:37 -07:00
|
|
|
true, true, frameBuffer.forget(), aFrameBufferLength,
|
2010-10-06 15:58:36 -07:00
|
|
|
aTime, mAllowAudioData);
|
2010-08-25 06:10:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool dummy;
|
2010-08-25 06:10:00 -07:00
|
|
|
return target->DispatchEvent(event, &dummy);
|
|
|
|
}
|
|
|
|
|
2010-09-09 20:29:06 -07:00
|
|
|
nsresult nsHTMLMediaElement::DispatchEvent(const nsAString& aName)
|
2008-07-09 01:22:20 -07:00
|
|
|
{
|
2010-09-09 20:29:06 -07:00
|
|
|
LOG_EVENT(PR_LOG_DEBUG, ("%p Dispatching event %s", this,
|
2009-09-29 14:32:44 -07:00
|
|
|
NS_ConvertUTF16toUTF8(aName).get()));
|
|
|
|
|
2010-09-09 21:20:10 -07:00
|
|
|
// Save events that occur while in the bfcache. These will be dispatched
|
|
|
|
// if the page comes out of the bfcache.
|
|
|
|
if (mPausedForInactiveDocument) {
|
|
|
|
mPendingEvents.AppendElement(aName);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-10-18 03:53:36 -07:00
|
|
|
return nsContentUtils::DispatchTrustedEvent(OwnerDoc(),
|
2009-11-05 23:32:52 -08:00
|
|
|
static_cast<nsIContent*>(this),
|
|
|
|
aName,
|
2011-09-29 16:34:37 -07:00
|
|
|
false,
|
|
|
|
true);
|
2008-07-09 01:22:20 -07:00
|
|
|
}
|
|
|
|
|
2010-09-09 20:29:06 -07:00
|
|
|
nsresult nsHTMLMediaElement::DispatchAsyncEvent(const nsAString& aName)
|
2008-07-09 01:22:20 -07:00
|
|
|
{
|
2010-09-09 20:29:06 -07:00
|
|
|
LOG_EVENT(PR_LOG_DEBUG, ("%p Queuing event %s", this,
|
|
|
|
NS_ConvertUTF16toUTF8(aName).get()));
|
2009-09-29 14:32:44 -07:00
|
|
|
|
2010-09-09 20:29:06 -07:00
|
|
|
nsCOMPtr<nsIRunnable> event = new nsAsyncEventRunner(aName, this);
|
2009-11-05 23:32:52 -08:00
|
|
|
NS_DispatchToMainThread(event, NS_DISPATCH_NORMAL);
|
|
|
|
return NS_OK;
|
2008-07-09 01:22:20 -07:00
|
|
|
}
|
|
|
|
|
2010-09-09 21:20:10 -07:00
|
|
|
nsresult nsHTMLMediaElement::DispatchPendingMediaEvents()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!mPausedForInactiveDocument,
|
|
|
|
"Must not be in bfcache when dispatching pending media events");
|
|
|
|
|
|
|
|
PRUint32 count = mPendingEvents.Length();
|
|
|
|
for (PRUint32 i = 0; i < count; ++i) {
|
|
|
|
DispatchAsyncEvent(mPendingEvents[i]);
|
|
|
|
}
|
|
|
|
mPendingEvents.Clear();
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool nsHTMLMediaElement::IsPotentiallyPlaying() const
|
2008-10-19 00:39:21 -07:00
|
|
|
{
|
2009-11-05 23:32:52 -08:00
|
|
|
// TODO:
|
|
|
|
// playback has not stopped due to errors,
|
2008-10-19 00:39:21 -07:00
|
|
|
// and the element has not paused for user interaction
|
2009-10-01 07:10:13 -07:00
|
|
|
return
|
2009-11-05 23:32:52 -08:00
|
|
|
!mPaused &&
|
2008-12-14 19:38:16 -08:00
|
|
|
(mReadyState == nsIDOMHTMLMediaElement::HAVE_ENOUGH_DATA ||
|
|
|
|
mReadyState == nsIDOMHTMLMediaElement::HAVE_FUTURE_DATA) &&
|
2008-10-19 00:39:21 -07:00
|
|
|
!IsPlaybackEnded();
|
|
|
|
}
|
2008-12-14 10:02:54 -08:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool nsHTMLMediaElement::IsPlaybackEnded() const
|
2008-10-19 00:39:21 -07:00
|
|
|
{
|
|
|
|
// TODO:
|
2009-03-08 13:59:08 -07:00
|
|
|
// the current playback position is equal to the effective end of the media resource.
|
2008-10-19 00:39:21 -07:00
|
|
|
// See bug 449157.
|
2008-12-14 19:38:16 -08:00
|
|
|
return mNetworkState >= nsIDOMHTMLMediaElement::HAVE_METADATA &&
|
2011-09-29 16:34:37 -07:00
|
|
|
mDecoder ? mDecoder->IsEnded() : false;
|
2008-10-19 00:39:21 -07:00
|
|
|
}
|
|
|
|
|
2009-03-31 17:52:56 -07:00
|
|
|
already_AddRefed<nsIPrincipal> nsHTMLMediaElement::GetCurrentPrincipal()
|
2008-09-06 16:47:28 -07:00
|
|
|
{
|
|
|
|
if (!mDecoder)
|
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
return mDecoder->GetCurrentPrincipal();
|
|
|
|
}
|
2008-09-26 05:56:21 -07:00
|
|
|
|
2008-10-19 00:39:21 -07:00
|
|
|
void nsHTMLMediaElement::UpdateMediaSize(nsIntSize size)
|
|
|
|
{
|
|
|
|
mMediaSize = size;
|
|
|
|
}
|
|
|
|
|
2009-10-01 07:10:13 -07:00
|
|
|
void nsHTMLMediaElement::NotifyOwnerDocumentActivityChanged()
|
2008-09-26 05:56:21 -07:00
|
|
|
{
|
2011-10-18 03:53:36 -07:00
|
|
|
nsIDocument* ownerDoc = OwnerDoc();
|
2009-10-01 07:10:13 -07:00
|
|
|
// Don't pause if we have no ownerDoc. Something native must have created
|
|
|
|
// us and be expecting us to work without a document.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool pauseForInactiveDocument =
|
2011-10-18 04:19:44 -07:00
|
|
|
!ownerDoc->IsActive() || !ownerDoc->IsVisible();
|
2008-10-28 11:48:39 -07:00
|
|
|
|
2009-10-01 07:10:13 -07:00
|
|
|
if (pauseForInactiveDocument != mPausedForInactiveDocument) {
|
|
|
|
mPausedForInactiveDocument = pauseForInactiveDocument;
|
|
|
|
if (mDecoder) {
|
|
|
|
if (pauseForInactiveDocument) {
|
|
|
|
mDecoder->Pause();
|
|
|
|
mDecoder->Suspend();
|
|
|
|
} else {
|
2011-09-29 16:34:37 -07:00
|
|
|
mDecoder->Resume(false);
|
2010-09-09 21:20:10 -07:00
|
|
|
DispatchPendingMediaEvents();
|
2010-01-06 17:13:27 -08:00
|
|
|
if (!mPaused && !mDecoder->IsEnded()) {
|
2009-10-01 07:10:13 -07:00
|
|
|
mDecoder->Play();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-10-28 11:48:39 -07:00
|
|
|
}
|
2009-01-21 15:54:40 -08:00
|
|
|
|
2009-10-01 07:10:13 -07:00
|
|
|
AddRemoveSelfReference();
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsHTMLMediaElement::AddRemoveSelfReference()
|
|
|
|
{
|
|
|
|
// XXX we could release earlier here in many situations if we examined
|
|
|
|
// which event listeners are attached. Right now we assume there is a
|
|
|
|
// potential listener for every event. We would also have to keep the
|
|
|
|
// element alive if it was playing and producing audio output --- right now
|
|
|
|
// that's covered by the !mPaused check.
|
2011-10-18 03:53:36 -07:00
|
|
|
nsIDocument* ownerDoc = OwnerDoc();
|
2009-10-01 07:10:13 -07:00
|
|
|
|
|
|
|
// See the comment at the top of this file for the explanation of this
|
|
|
|
// boolean expression.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool needSelfReference = !mShuttingDown &&
|
2011-10-18 04:19:44 -07:00
|
|
|
ownerDoc->IsActive() &&
|
2009-10-01 07:10:13 -07:00
|
|
|
(mDelayingLoadEvent ||
|
|
|
|
(!mPaused && mDecoder && !mDecoder->IsEnded()) ||
|
|
|
|
(mDecoder && mDecoder->IsSeeking()) ||
|
|
|
|
CanActivateAutoplay() ||
|
|
|
|
mNetworkState == nsIDOMHTMLMediaElement::NETWORK_LOADING);
|
|
|
|
|
|
|
|
if (needSelfReference != mHasSelfReference) {
|
|
|
|
mHasSelfReference = needSelfReference;
|
|
|
|
if (needSelfReference) {
|
2010-02-24 11:14:14 -08:00
|
|
|
// The observer service will hold a strong reference to us. This
|
|
|
|
// will do to keep us alive. We need to know about shutdown so that
|
|
|
|
// we can release our self-reference.
|
|
|
|
nsContentUtils::RegisterShutdownObserver(this);
|
2009-10-01 07:10:13 -07:00
|
|
|
} else {
|
|
|
|
// Dispatch Release asynchronously so that we don't destroy this object
|
|
|
|
// inside a call stack of method calls on this object
|
|
|
|
nsCOMPtr<nsIRunnable> event =
|
2010-04-20 16:21:35 -07:00
|
|
|
NS_NewRunnableMethod(this, &nsHTMLMediaElement::DoRemoveSelfReference);
|
2009-10-01 07:10:13 -07:00
|
|
|
NS_DispatchToMainThread(event);
|
|
|
|
}
|
2009-01-21 15:54:40 -08:00
|
|
|
}
|
2008-10-28 11:48:39 -07:00
|
|
|
}
|
2009-02-15 17:05:28 -08:00
|
|
|
|
2010-02-24 11:14:14 -08:00
|
|
|
void nsHTMLMediaElement::DoRemoveSelfReference()
|
|
|
|
{
|
|
|
|
// We don't need the shutdown observer anymore. Unregistering releases
|
|
|
|
// its reference to us, which we were using as our self-reference.
|
|
|
|
nsContentUtils::UnregisterShutdownObserver(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsHTMLMediaElement::Observe(nsISupports* aSubject,
|
|
|
|
const char* aTopic, const PRUnichar* aData)
|
|
|
|
{
|
2011-02-12 10:04:15 -08:00
|
|
|
NS_ENSURE_TRUE(nsContentUtils::IsCallerChrome(), NS_ERROR_NOT_AVAILABLE);
|
|
|
|
|
2010-02-24 11:14:14 -08:00
|
|
|
if (strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID) == 0) {
|
2011-09-29 16:34:37 -07:00
|
|
|
mShuttingDown = true;
|
2010-02-24 11:14:14 -08:00
|
|
|
AddRemoveSelfReference();
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2009-02-15 17:05:28 -08:00
|
|
|
nsHTMLMediaElement::IsNodeOfType(PRUint32 aFlags) const
|
|
|
|
{
|
2010-04-30 06:12:06 -07:00
|
|
|
return !(aFlags & ~(eCONTENT | eMEDIA));
|
2009-02-15 17:05:28 -08:00
|
|
|
}
|
|
|
|
|
2010-09-02 17:03:03 -07:00
|
|
|
void nsHTMLMediaElement::DispatchAsyncSourceError(nsIContent* aSourceElement)
|
|
|
|
{
|
|
|
|
LOG_EVENT(PR_LOG_DEBUG, ("%p Queuing simple source error event", this));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRunnable> event = new nsSourceErrorEventRunner(this, aSourceElement);
|
|
|
|
NS_DispatchToMainThread(event, NS_DISPATCH_NORMAL);
|
|
|
|
}
|
|
|
|
|
2009-02-15 17:05:28 -08:00
|
|
|
void nsHTMLMediaElement::NotifyAddedSource()
|
|
|
|
{
|
2010-09-02 17:03:03 -07:00
|
|
|
// If a source element is inserted as a child of a media element
|
|
|
|
// that has no src attribute and whose networkState has the value
|
|
|
|
// NETWORK_EMPTY, the user agent must invoke the media element's
|
|
|
|
// resource selection algorithm.
|
|
|
|
if (!HasAttr(kNameSpaceID_None, nsGkAtoms::src) &&
|
|
|
|
mNetworkState == nsIDOMHTMLMediaElement::NETWORK_EMPTY)
|
|
|
|
{
|
2009-03-08 13:59:08 -07:00
|
|
|
QueueSelectResourceTask();
|
2010-09-02 17:03:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// A load was paused in the resource selection algorithm, waiting for
|
|
|
|
// a new source child to be added, resume the resource selction algorithm.
|
|
|
|
if (mLoadWaitStatus == WAITING_FOR_SOURCE) {
|
2009-03-08 13:59:08 -07:00
|
|
|
QueueLoadFromSourceTask();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-02 17:03:03 -07:00
|
|
|
nsIContent* nsHTMLMediaElement::GetNextSource()
|
2009-03-08 13:59:08 -07:00
|
|
|
{
|
2011-08-30 14:45:31 -07:00
|
|
|
nsCOMPtr<nsIDOMNode> thisDomNode = do_QueryObject(this);
|
2009-03-08 13:59:08 -07:00
|
|
|
|
2010-09-02 17:03:03 -07:00
|
|
|
mSourceLoadCandidate = nsnull;
|
|
|
|
|
2011-11-15 23:50:19 -08:00
|
|
|
nsresult rv = NS_OK;
|
2009-03-08 13:59:08 -07:00
|
|
|
if (!mSourcePointer) {
|
|
|
|
// First time this has been run, create a selection to cover children.
|
|
|
|
mSourcePointer = do_CreateInstance("@mozilla.org/content/range;1");
|
|
|
|
|
|
|
|
rv = mSourcePointer->SelectNodeContents(thisDomNode);
|
|
|
|
if (NS_FAILED(rv)) return nsnull;
|
|
|
|
|
2011-09-29 16:34:37 -07:00
|
|
|
rv = mSourcePointer->Collapse(true);
|
2009-03-08 13:59:08 -07:00
|
|
|
if (NS_FAILED(rv)) return nsnull;
|
|
|
|
}
|
|
|
|
|
2011-09-29 16:34:37 -07:00
|
|
|
while (true) {
|
2009-03-08 13:59:08 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
nsCOMPtr<nsIDOMNode> startContainer;
|
|
|
|
rv = mSourcePointer->GetStartContainer(getter_AddRefs(startContainer));
|
|
|
|
if (NS_FAILED(rv)) return nsnull;
|
|
|
|
NS_ASSERTION(startContainer == thisDomNode,
|
|
|
|
"Should only iterate over direct children");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
PRInt32 startOffset = 0;
|
|
|
|
rv = mSourcePointer->GetStartOffset(&startOffset);
|
|
|
|
NS_ENSURE_SUCCESS(rv, nsnull);
|
|
|
|
|
2009-10-14 18:28:59 -07:00
|
|
|
if (PRUint32(startOffset) == GetChildCount())
|
2009-03-08 13:59:08 -07:00
|
|
|
return nsnull; // No more children.
|
|
|
|
|
|
|
|
// Advance the range to the next child.
|
2011-11-15 23:50:19 -08:00
|
|
|
rv = mSourcePointer->SetStart(thisDomNode, startOffset + 1);
|
2009-03-08 13:59:08 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, nsnull);
|
|
|
|
|
|
|
|
nsIContent* child = GetChildAt(startOffset);
|
|
|
|
|
2010-09-02 17:03:03 -07:00
|
|
|
// If child is a <source> element, it is the next candidate.
|
2011-11-15 23:50:19 -08:00
|
|
|
if (child && child->IsHTML(nsGkAtoms::source)) {
|
2010-09-02 17:03:03 -07:00
|
|
|
mSourceLoadCandidate = child;
|
|
|
|
return child;
|
2009-03-08 13:59:08 -07:00
|
|
|
}
|
2009-02-15 17:05:28 -08:00
|
|
|
}
|
2009-03-08 13:59:08 -07:00
|
|
|
NS_NOTREACHED("Execution should not reach here!");
|
|
|
|
return nsnull;
|
2009-02-15 17:05:28 -08:00
|
|
|
}
|
2009-03-08 14:01:03 -07:00
|
|
|
|
2011-11-15 23:50:19 -08:00
|
|
|
void nsHTMLMediaElement::ChangeDelayLoadStatus(bool aDelay)
|
|
|
|
{
|
2009-03-08 14:01:03 -07:00
|
|
|
if (mDelayingLoadEvent == aDelay)
|
|
|
|
return;
|
|
|
|
|
|
|
|
mDelayingLoadEvent = aDelay;
|
|
|
|
|
|
|
|
if (aDelay) {
|
2011-10-18 03:53:36 -07:00
|
|
|
mLoadBlockedDoc = OwnerDoc();
|
2009-03-08 14:01:03 -07:00
|
|
|
mLoadBlockedDoc->BlockOnload();
|
2009-09-29 14:32:44 -07:00
|
|
|
LOG(PR_LOG_DEBUG, ("%p ChangeDelayLoadStatus(%d) doc=0x%p", this, aDelay, mLoadBlockedDoc.get()));
|
2009-03-08 14:01:03 -07:00
|
|
|
} else {
|
2009-04-09 18:28:24 -07:00
|
|
|
if (mDecoder) {
|
|
|
|
mDecoder->MoveLoadsToBackground();
|
|
|
|
}
|
2009-09-29 14:32:44 -07:00
|
|
|
LOG(PR_LOG_DEBUG, ("%p ChangeDelayLoadStatus(%d) doc=0x%p", this, aDelay, mLoadBlockedDoc.get()));
|
2010-02-24 11:14:14 -08:00
|
|
|
// mLoadBlockedDoc might be null due to GC unlinking
|
|
|
|
if (mLoadBlockedDoc) {
|
2011-09-29 16:34:37 -07:00
|
|
|
mLoadBlockedDoc->UnblockOnload(false);
|
2010-02-24 11:14:14 -08:00
|
|
|
mLoadBlockedDoc = nsnull;
|
|
|
|
}
|
2009-03-08 14:01:03 -07:00
|
|
|
}
|
2009-10-01 07:10:13 -07:00
|
|
|
|
|
|
|
// We changed mDelayingLoadEvent which can affect AddRemoveSelfReference
|
|
|
|
AddRemoveSelfReference();
|
2009-03-08 14:01:03 -07:00
|
|
|
}
|
2009-04-09 18:28:24 -07:00
|
|
|
|
|
|
|
already_AddRefed<nsILoadGroup> nsHTMLMediaElement::GetDocumentLoadGroup()
|
|
|
|
{
|
2011-10-18 04:19:44 -07:00
|
|
|
return OwnerDoc()->GetDocumentLoadGroup();
|
2009-04-09 18:28:24 -07:00
|
|
|
}
|
2009-12-10 20:02:13 -08:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHTMLMediaElement::CopyInnerTo(nsGenericElement* aDest) const
|
|
|
|
{
|
|
|
|
nsresult rv = nsGenericHTMLElement::CopyInnerTo(aDest);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2011-10-18 03:53:36 -07:00
|
|
|
if (aDest->OwnerDoc()->IsStaticDocument()) {
|
2009-12-10 20:02:13 -08:00
|
|
|
nsHTMLMediaElement* dest = static_cast<nsHTMLMediaElement*>(aDest);
|
|
|
|
if (mPrintSurface) {
|
|
|
|
dest->mPrintSurface = mPrintSurface;
|
|
|
|
dest->mMediaSize = mMediaSize;
|
|
|
|
} else {
|
2009-12-24 13:20:05 -08:00
|
|
|
nsIFrame* frame = GetPrimaryFrame();
|
2011-12-03 13:50:16 -08:00
|
|
|
Element* element;
|
2009-12-10 20:02:13 -08:00
|
|
|
if (frame && frame->GetType() == nsGkAtoms::HTMLVideoFrame &&
|
|
|
|
static_cast<nsVideoFrame*>(frame)->ShouldDisplayPoster()) {
|
2011-12-03 13:50:16 -08:00
|
|
|
nsIContent* content = static_cast<nsVideoFrame*>(frame)->GetPosterImage();
|
|
|
|
element = content ? content->AsElement() : NULL;
|
2009-12-10 20:02:13 -08:00
|
|
|
} else {
|
2011-12-03 13:50:16 -08:00
|
|
|
element = const_cast<nsHTMLMediaElement*>(this);
|
2009-12-10 20:02:13 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
nsLayoutUtils::SurfaceFromElementResult res =
|
2011-12-03 13:50:16 -08:00
|
|
|
nsLayoutUtils::SurfaceFromElement(element,
|
2009-12-10 20:02:13 -08:00
|
|
|
nsLayoutUtils::SFE_WANT_NEW_SURFACE);
|
|
|
|
dest->mPrintSurface = res.mSurface;
|
|
|
|
dest->mMediaSize = nsIntSize(res.mSize.width, res.mSize.height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
2010-08-05 00:40:35 -07:00
|
|
|
|
2010-08-25 01:43:00 -07:00
|
|
|
nsresult nsHTMLMediaElement::GetBuffered(nsIDOMTimeRanges** aBuffered)
|
2010-08-05 00:40:35 -07:00
|
|
|
{
|
2011-11-15 23:50:19 -08:00
|
|
|
nsRefPtr<nsTimeRanges> ranges = new nsTimeRanges();
|
2010-08-05 00:40:35 -07:00
|
|
|
if (mReadyState >= nsIDOMHTMLMediaElement::HAVE_CURRENT_DATA && mDecoder) {
|
2010-09-09 20:29:06 -07:00
|
|
|
// If GetBuffered fails we ignore the error result and just return the
|
|
|
|
// time ranges we found up till the error.
|
|
|
|
mDecoder->GetBuffered(ranges);
|
2010-08-05 00:40:35 -07:00
|
|
|
}
|
2011-11-15 23:50:19 -08:00
|
|
|
ranges.forget(aBuffered);
|
2010-08-05 00:40:35 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-09-16 10:36:23 -07:00
|
|
|
|
|
|
|
void nsHTMLMediaElement::SetRequestHeaders(nsIHttpChannel* aChannel)
|
|
|
|
{
|
|
|
|
// Send Accept header for video and audio types only (Bug 489071)
|
|
|
|
SetAcceptHeader(aChannel);
|
|
|
|
|
2010-11-28 13:21:27 -08:00
|
|
|
// Apache doesn't send Content-Length when gzip transfer encoding is used,
|
|
|
|
// which prevents us from estimating the video length (if explicit Content-Duration
|
|
|
|
// and a length spec in the container are not present either) and from seeking.
|
|
|
|
// So, disable the standard "Accept-Encoding: gzip,deflate" that we usually send.
|
|
|
|
// See bug 614760.
|
|
|
|
aChannel->SetRequestHeader(NS_LITERAL_CSTRING("Accept-Encoding"),
|
2011-11-15 23:50:19 -08:00
|
|
|
EmptyCString(), false);
|
2010-11-28 13:21:27 -08:00
|
|
|
|
2010-09-16 10:36:23 -07:00
|
|
|
// Set the Referer header
|
2011-10-18 04:19:44 -07:00
|
|
|
aChannel->SetReferrer(OwnerDoc()->GetDocumentURI());
|
2010-09-16 10:36:23 -07:00
|
|
|
}
|
2010-11-24 10:34:57 -08:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
void nsHTMLMediaElement::FireTimeUpdate(bool aPeriodic)
|
2010-11-24 10:34:57 -08:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
|
|
|
|
|
|
|
|
TimeStamp now = TimeStamp::Now();
|
2011-01-16 19:03:00 -08:00
|
|
|
double time = 0;
|
2010-11-24 10:34:57 -08:00
|
|
|
GetCurrentTime(&time);
|
|
|
|
|
|
|
|
// Fire a timupdate event if this is not a periodic update (i.e. it's a
|
|
|
|
// timeupdate event mandated by the spec), or if it's a periodic update
|
|
|
|
// and TIMEUPDATE_MS has passed since the last timeupdate event fired and
|
|
|
|
// the time has changed.
|
|
|
|
if (!aPeriodic ||
|
|
|
|
(mLastCurrentTime != time &&
|
|
|
|
(mTimeUpdateTime.IsNull() ||
|
|
|
|
now - mTimeUpdateTime >= TimeDuration::FromMilliseconds(TIMEUPDATE_MS)))) {
|
|
|
|
DispatchAsyncEvent(NS_LITERAL_STRING("timeupdate"));
|
|
|
|
mTimeUpdateTime = now;
|
|
|
|
mLastCurrentTime = time;
|
|
|
|
}
|
2011-08-24 16:42:23 -07:00
|
|
|
if (mFragmentEnd >= 0.0 && time >= mFragmentEnd) {
|
|
|
|
Pause();
|
|
|
|
mFragmentEnd = -1.0;
|
|
|
|
mFragmentStart = -1.0;
|
|
|
|
mDecoder->SetEndTime(mFragmentEnd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsHTMLMediaElement::GetCurrentSpec(nsCString& aString)
|
|
|
|
{
|
2011-11-24 18:06:22 -08:00
|
|
|
if (mLoadingSrc) {
|
2011-08-24 16:42:23 -07:00
|
|
|
mLoadingSrc->GetSpec(aString);
|
2011-11-24 18:06:22 -08:00
|
|
|
} else {
|
|
|
|
aString.Truncate();
|
2011-08-24 16:42:23 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* attribute double initialTime; */
|
|
|
|
NS_IMETHODIMP nsHTMLMediaElement::GetInitialTime(double *aTime)
|
|
|
|
{
|
|
|
|
// If there is no start fragment then the initalTime is zero.
|
|
|
|
// Clamp to duration if it is greater than duration.
|
|
|
|
double duration = 0.0;
|
|
|
|
nsresult rv = GetDuration(&duration);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
*aTime = mFragmentStart < 0.0 ? 0.0 : mFragmentStart;
|
|
|
|
if (*aTime > duration) {
|
|
|
|
*aTime = duration;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* attribute double mozFragmentEnd; */
|
|
|
|
NS_IMETHODIMP nsHTMLMediaElement::GetMozFragmentEnd(double *aTime)
|
|
|
|
{
|
|
|
|
double duration = 0.0;
|
|
|
|
nsresult rv = GetDuration(&duration);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// If there is no end fragment, or the fragment end is greater than the
|
|
|
|
// duration, return the duration.
|
|
|
|
*aTime = (mFragmentEnd < 0.0 || mFragmentEnd > duration) ? duration : mFragmentEnd;
|
|
|
|
return NS_OK;
|
2010-11-24 10:34:57 -08:00
|
|
|
}
|
2011-11-21 16:34:21 -08:00
|
|
|
|
|
|
|
void nsHTMLMediaElement::NotifyAudioAvailableListener()
|
|
|
|
{
|
|
|
|
if (mDecoder) {
|
|
|
|
mDecoder->NotifyAudioAvailableListener();
|
|
|
|
}
|
|
|
|
}
|