Attachment #469714: Rolled up and rebased patch for bug #584615

View | Details | Raw Unified | Return to bug 584615
Collapse All | Expand All

(-)a/content/html/content/public/nsHTMLMediaElement.h (-4 / +2 lines)
Line     Link Here 
 Lines 184-193   public: Link Here 
184
  gfxASurface* GetPrintSurface() { return mPrintSurface; }
184
  gfxASurface* GetPrintSurface() { return mPrintSurface; }
185
185
186
  // Dispatch events
186
  // Dispatch events
187
  nsresult DispatchSimpleEvent(const nsAString& aName);
187
  nsresult DispatchEvent(const nsAString& aName);
188
  nsresult DispatchProgressEvent(const nsAString& aName);
188
  nsresult DispatchAsyncEvent(const nsAString& aName);
189
  nsresult DispatchAsyncSimpleEvent(const nsAString& aName);
190
  nsresult DispatchAsyncProgressEvent(const nsAString& aName);
191
  nsresult DispatchAudioAvailableEvent(float* aFrameBuffer,
189
  nsresult DispatchAudioAvailableEvent(float* aFrameBuffer,
192
                                       PRUint32 aFrameBufferLength,
190
                                       PRUint32 aFrameBufferLength,
193
                                       PRUint64 aTime);
191
                                       PRUint64 aTime);
(-)a/content/html/content/src/nsHTMLMediaElement.cpp (-87 / +46 lines)
Line     Link Here 
 Lines 69-75    Link Here 
69
69
70
#include "nsEventDispatcher.h"
70
#include "nsEventDispatcher.h"
71
#include "nsIDOMDocumentEvent.h"
71
#include "nsIDOMDocumentEvent.h"
72
#include "nsIDOMProgressEvent.h"
73
#include "nsMediaError.h"
72
#include "nsMediaError.h"
74
#include "nsICategoryManager.h"
73
#include "nsICategoryManager.h"
75
#include "nsCharSeparatedTokenizer.h"
74
#include "nsCharSeparatedTokenizer.h"
 Lines 189-199   class nsAsyncEventRunner : public nsMediaEvent Link Here 
189
{
188
{
190
private:
189
private:
191
  nsString mName;
190
  nsString mName;
192
  PRPackedBool mProgress;
193
191
194
public:
192
public:
195
  nsAsyncEventRunner(const nsAString& aName, nsHTMLMediaElement* aElement, PRBool aProgress) :
193
  nsAsyncEventRunner(const nsAString& aName, nsHTMLMediaElement* aElement) :
196
    nsMediaEvent(aElement), mName(aName), mProgress(aProgress)
194
    nsMediaEvent(aElement), mName(aName)
197
  {
195
  {
198
  }
196
  }
199
197
 Lines 203-211   public: Link Here 
203
    if (IsCancelled())
201
    if (IsCancelled())
204
      return NS_OK;
202
      return NS_OK;
205
203
206
    return mProgress ?
204
    return mElement->DispatchEvent(mName);
207
      mElement->DispatchProgressEvent(mName) :
208
      mElement->DispatchSimpleEvent(mName);
209
  }
205
  }
210
};
206
};
211
207
 Lines 505-511   void nsHTMLMediaElement::AbortExistingLoads() Link Here 
505
      mNetworkState == nsIDOMHTMLMediaElement::NETWORK_IDLE)
501
      mNetworkState == nsIDOMHTMLMediaElement::NETWORK_IDLE)
506
  {
502
  {
507
    mError = new nsMediaError(nsIDOMMediaError::MEDIA_ERR_ABORTED);
503
    mError = new nsMediaError(nsIDOMMediaError::MEDIA_ERR_ABORTED);
508
    DispatchProgressEvent(NS_LITERAL_STRING("abort"));
504
    DispatchEvent(NS_LITERAL_STRING("abort"));
509
  }
505
  }
510
506
511
  mError = nsnull;
507
  mError = nsnull;
 Lines 528-536   void nsHTMLMediaElement::AbortExistingLoads() Link Here 
528
      // will now be reported as 0. The playback position was non-zero when
524
      // will now be reported as 0. The playback position was non-zero when
529
      // we destroyed the decoder, so fire a timeupdate event so that the
525
      // we destroyed the decoder, so fire a timeupdate event so that the
530
      // change will be reflected in the controls.
526
      // change will be reflected in the controls.
531
      DispatchAsyncSimpleEvent(NS_LITERAL_STRING("timeupdate"));
527
      DispatchAsyncEvent(NS_LITERAL_STRING("timeupdate"));
532
    }
528
    }
533
    DispatchSimpleEvent(NS_LITERAL_STRING("emptied"));
529
    DispatchEvent(NS_LITERAL_STRING("emptied"));
534
  }
530
  }
535
531
536
  // We may have changed mPaused, mAutoplaying, mNetworkState and other
532
  // We may have changed mPaused, mAutoplaying, mNetworkState and other
 Lines 546-552   void nsHTMLMediaElement::NoSupportedMediaSourceError() Link Here 
546
542
547
  mError = new nsMediaError(nsIDOMMediaError::MEDIA_ERR_SRC_NOT_SUPPORTED);
543
  mError = new nsMediaError(nsIDOMMediaError::MEDIA_ERR_SRC_NOT_SUPPORTED);
548
  mNetworkState = nsIDOMHTMLMediaElement::NETWORK_NO_SOURCE;
544
  mNetworkState = nsIDOMHTMLMediaElement::NETWORK_NO_SOURCE;
549
  DispatchAsyncProgressEvent(NS_LITERAL_STRING("error"));
545
  DispatchAsyncEvent(NS_LITERAL_STRING("error"));
550
  // This clears mDelayingLoadEvent, so AddRemoveSelfReference will be called
546
  // This clears mDelayingLoadEvent, so AddRemoveSelfReference will be called
551
  ChangeDelayLoadStatus(PR_FALSE);
547
  ChangeDelayLoadStatus(PR_FALSE);
552
}
548
}
 Lines 606-612   void nsHTMLMediaElement::SelectResource() Link Here 
606
  mNetworkState = nsIDOMHTMLMediaElement::NETWORK_LOADING;
602
  mNetworkState = nsIDOMHTMLMediaElement::NETWORK_LOADING;
607
  // Load event was delayed, and still is, so no need to call
603
  // Load event was delayed, and still is, so no need to call
608
  // AddRemoveSelfReference, since it must still be held
604
  // AddRemoveSelfReference, since it must still be held
609
  DispatchAsyncProgressEvent(NS_LITERAL_STRING("loadstart"));
605
  DispatchAsyncEvent(NS_LITERAL_STRING("loadstart"));
610
606
611
  nsAutoString src;
607
  nsAutoString src;
612
  nsCOMPtr<nsIURI> uri;
608
  nsCOMPtr<nsIURI> uri;
 Lines 716-722   void nsHTMLMediaElement::SuspendLoad(nsIURI* aURI) Link Here 
716
  mLoadIsSuspended = PR_TRUE;
712
  mLoadIsSuspended = PR_TRUE;
717
  mPreloadURI = aURI;
713
  mPreloadURI = aURI;
718
  mNetworkState = nsIDOMHTMLMediaElement::NETWORK_IDLE;
714
  mNetworkState = nsIDOMHTMLMediaElement::NETWORK_IDLE;
719
  DispatchAsyncProgressEvent(NS_LITERAL_STRING("suspend"));
715
  DispatchAsyncEvent(NS_LITERAL_STRING("suspend"));
720
  ChangeDelayLoadStatus(PR_FALSE);
716
  ChangeDelayLoadStatus(PR_FALSE);
721
}
717
}
722
718
 Lines 953-959   nsresult nsHTMLMediaElement::LoadWithChannel(nsIChannel *aChannel, Link Here 
953
    return rv;
949
    return rv;
954
  }
950
  }
955
951
956
  DispatchAsyncProgressEvent(NS_LITERAL_STRING("loadstart"));
952
  DispatchAsyncEvent(NS_LITERAL_STRING("loadstart"));
957
953
958
  return NS_OK;
954
  return NS_OK;
959
}
955
}
 Lines 977-983   NS_IMETHODIMP nsHTMLMediaElement::MozLoadFrom(nsIDOMHTMLMediaElement* aOther) Link Here 
977
    return rv;
973
    return rv;
978
  }
974
  }
979
975
980
  DispatchAsyncProgressEvent(NS_LITERAL_STRING("loadstart"));
976
  DispatchAsyncEvent(NS_LITERAL_STRING("loadstart"));
981
977
982
  return NS_OK;
978
  return NS_OK;
983
}
979
}
 Lines 1076-1083   NS_IMETHODIMP nsHTMLMediaElement::Pause() Link Here 
1076
  AddRemoveSelfReference();
1072
  AddRemoveSelfReference();
1077
1073
1078
  if (!oldPaused) {
1074
  if (!oldPaused) {
1079
    DispatchAsyncSimpleEvent(NS_LITERAL_STRING("timeupdate"));
1075
    DispatchAsyncEvent(NS_LITERAL_STRING("timeupdate"));
1080
    DispatchAsyncSimpleEvent(NS_LITERAL_STRING("pause"));
1076
    DispatchAsyncEvent(NS_LITERAL_STRING("pause"));
1081
  }
1077
  }
1082
1078
1083
  return NS_OK;
1079
  return NS_OK;
 Lines 1107-1113   NS_IMETHODIMP nsHTMLMediaElement::SetVolume(float aVolume) Link Here 
1107
    mAudioStream->SetVolume(mVolume);
1103
    mAudioStream->SetVolume(mVolume);
1108
  }
1104
  }
1109
1105
1110
  DispatchAsyncSimpleEvent(NS_LITERAL_STRING("volumechange"));
1106
  DispatchAsyncEvent(NS_LITERAL_STRING("volumechange"));
1111
1107
1112
  return NS_OK;
1108
  return NS_OK;
1113
}
1109
}
 Lines 1177-1183   NS_IMETHODIMP nsHTMLMediaElement::SetMuted(PRBool aMuted) Link Here 
1177
    mAudioStream->SetVolume(mMuted ? 0.0 : mVolume);
1173
    mAudioStream->SetVolume(mMuted ? 0.0 : mVolume);
1178
  }
1174
  }
1179
1175
1180
  DispatchAsyncSimpleEvent(NS_LITERAL_STRING("volumechange"));
1176
  DispatchAsyncEvent(NS_LITERAL_STRING("volumechange"));
1181
1177
1182
  return NS_OK;
1178
  return NS_OK;
1183
}
1179
}
 Lines 1301-1315   NS_IMETHODIMP nsHTMLMediaElement::Play() Link Here 
1301
  // seek to the effective start.
1297
  // seek to the effective start.
1302
  // TODO: The playback rate must be set to the default playback rate.
1298
  // TODO: The playback rate must be set to the default playback rate.
1303
  if (mPaused) {
1299
  if (mPaused) {
1304
    DispatchAsyncSimpleEvent(NS_LITERAL_STRING("play"));
1300
    DispatchAsyncEvent(NS_LITERAL_STRING("play"));
1305
    switch (mReadyState) {
1301
    switch (mReadyState) {
1306
    case nsIDOMHTMLMediaElement::HAVE_METADATA:
1302
    case nsIDOMHTMLMediaElement::HAVE_METADATA:
1307
    case nsIDOMHTMLMediaElement::HAVE_CURRENT_DATA:
1303
    case nsIDOMHTMLMediaElement::HAVE_CURRENT_DATA:
1308
      DispatchAsyncSimpleEvent(NS_LITERAL_STRING("waiting"));
1304
      DispatchAsyncEvent(NS_LITERAL_STRING("waiting"));
1309
      break;
1305
      break;
1310
    case nsIDOMHTMLMediaElement::HAVE_FUTURE_DATA:
1306
    case nsIDOMHTMLMediaElement::HAVE_FUTURE_DATA:
1311
    case nsIDOMHTMLMediaElement::HAVE_ENOUGH_DATA:
1307
    case nsIDOMHTMLMediaElement::HAVE_ENOUGH_DATA:
1312
      DispatchAsyncSimpleEvent(NS_LITERAL_STRING("playing"));
1308
      DispatchAsyncEvent(NS_LITERAL_STRING("playing"));
1313
      break;
1309
      break;
1314
    }
1310
    }
1315
  }
1311
  }
 Lines 1876-1883   void nsHTMLMediaElement::MetadataLoaded(PRUint32 aChannels, PRUint32 aRate) Link Here 
1876
  mChannels = aChannels;
1872
  mChannels = aChannels;
1877
  mRate = aRate;
1873
  mRate = aRate;
1878
  ChangeReadyState(nsIDOMHTMLMediaElement::HAVE_METADATA);
1874
  ChangeReadyState(nsIDOMHTMLMediaElement::HAVE_METADATA);
1879
  DispatchAsyncSimpleEvent(NS_LITERAL_STRING("durationchange"));
1875
  DispatchAsyncEvent(NS_LITERAL_STRING("durationchange"));
1880
  DispatchAsyncSimpleEvent(NS_LITERAL_STRING("loadedmetadata"));
1876
  DispatchAsyncEvent(NS_LITERAL_STRING("loadedmetadata"));
1881
}
1877
}
1882
1878
1883
void nsHTMLMediaElement::FirstFrameLoaded(PRBool aResourceFullyLoaded)
1879
void nsHTMLMediaElement::FirstFrameLoaded(PRBool aResourceFullyLoaded)
 Lines 1903-1919   void nsHTMLMediaElement::ResourceLoaded() Link Here 
1903
  AddRemoveSelfReference();
1899
  AddRemoveSelfReference();
1904
  ChangeReadyState(nsIDOMHTMLMediaElement::HAVE_ENOUGH_DATA);
1900
  ChangeReadyState(nsIDOMHTMLMediaElement::HAVE_ENOUGH_DATA);
1905
  // The download has stopped
1901
  // The download has stopped
1906
  DispatchAsyncSimpleEvent(NS_LITERAL_STRING("suspend"));
1902
  DispatchAsyncEvent(NS_LITERAL_STRING("suspend"));
1907
}
1903
}
1908
1904
1909
void nsHTMLMediaElement::NetworkError()
1905
void nsHTMLMediaElement::NetworkError()
1910
{
1906
{
1911
  mError = new nsMediaError(nsIDOMMediaError::MEDIA_ERR_NETWORK);
1907
  mError = new nsMediaError(nsIDOMMediaError::MEDIA_ERR_NETWORK);
1912
  mBegun = PR_FALSE;
1908
  mBegun = PR_FALSE;
1913
  DispatchAsyncProgressEvent(NS_LITERAL_STRING("error"));
1909
  DispatchAsyncEvent(NS_LITERAL_STRING("error"));
1914
  mNetworkState = nsIDOMHTMLMediaElement::NETWORK_EMPTY;
1910
  mNetworkState = nsIDOMHTMLMediaElement::NETWORK_EMPTY;
1915
  AddRemoveSelfReference();
1911
  AddRemoveSelfReference();
1916
  DispatchAsyncSimpleEvent(NS_LITERAL_STRING("emptied"));
1912
  DispatchAsyncEvent(NS_LITERAL_STRING("emptied"));
1917
  ChangeDelayLoadStatus(PR_FALSE);
1913
  ChangeDelayLoadStatus(PR_FALSE);
1918
}
1914
}
1919
1915
 Lines 1921-1930   void nsHTMLMediaElement::DecodeError() Link Here 
1921
{
1917
{
1922
  mError = new nsMediaError(nsIDOMMediaError::MEDIA_ERR_DECODE);
1918
  mError = new nsMediaError(nsIDOMMediaError::MEDIA_ERR_DECODE);
1923
  mBegun = PR_FALSE;
1919
  mBegun = PR_FALSE;
1924
  DispatchAsyncProgressEvent(NS_LITERAL_STRING("error"));
1920
  DispatchAsyncEvent(NS_LITERAL_STRING("error"));
1925
  mNetworkState = nsIDOMHTMLMediaElement::NETWORK_EMPTY;
1921
  mNetworkState = nsIDOMHTMLMediaElement::NETWORK_EMPTY;
1926
  AddRemoveSelfReference();
1922
  AddRemoveSelfReference();
1927
  DispatchAsyncSimpleEvent(NS_LITERAL_STRING("emptied"));
1923
  DispatchAsyncEvent(NS_LITERAL_STRING("emptied"));
1928
  ChangeDelayLoadStatus(PR_FALSE);
1924
  ChangeDelayLoadStatus(PR_FALSE);
1929
}
1925
}
1930
1926
 Lines 1934-1952   void nsHTMLMediaElement::PlaybackEnded() Link Here 
1934
  // We changed the state of IsPlaybackEnded which can affect AddRemoveSelfReference
1930
  // We changed the state of IsPlaybackEnded which can affect AddRemoveSelfReference
1935
  AddRemoveSelfReference();
1931
  AddRemoveSelfReference();
1936
1932
1937
  DispatchAsyncSimpleEvent(NS_LITERAL_STRING("ended"));
1933
  DispatchAsyncEvent(NS_LITERAL_STRING("ended"));
1938
}
1934
}
1939
1935
1940
void nsHTMLMediaElement::SeekStarted()
1936
void nsHTMLMediaElement::SeekStarted()
1941
{
1937
{
1942
  DispatchAsyncSimpleEvent(NS_LITERAL_STRING("seeking"));
1938
  DispatchAsyncEvent(NS_LITERAL_STRING("seeking"));
1943
}
1939
}
1944
1940
1945
void nsHTMLMediaElement::SeekCompleted()
1941
void nsHTMLMediaElement::SeekCompleted()
1946
{
1942
{
1947
  mPlayingBeforeSeek = PR_FALSE;
1943
  mPlayingBeforeSeek = PR_FALSE;
1948
  SetPlayedOrSeeked(PR_TRUE);
1944
  SetPlayedOrSeeked(PR_TRUE);
1949
  DispatchAsyncSimpleEvent(NS_LITERAL_STRING("seeked"));
1945
  DispatchAsyncEvent(NS_LITERAL_STRING("seeked"));
1950
  // We changed whether we're seeking so we need to AddRemoveSelfReference
1946
  // We changed whether we're seeking so we need to AddRemoveSelfReference
1951
  AddRemoveSelfReference();
1947
  AddRemoveSelfReference();
1952
}
1948
}
 Lines 1956-1962   void nsHTMLMediaElement::DownloadSuspended() Link Here 
1956
  if (mBegun) {
1952
  if (mBegun) {
1957
    mNetworkState = nsIDOMHTMLMediaElement::NETWORK_IDLE;
1953
    mNetworkState = nsIDOMHTMLMediaElement::NETWORK_IDLE;
1958
    AddRemoveSelfReference();
1954
    AddRemoveSelfReference();
1959
    DispatchAsyncSimpleEvent(NS_LITERAL_STRING("suspend"));
1955
    DispatchAsyncEvent(NS_LITERAL_STRING("suspend"));
1960
  }
1956
  }
1961
}
1957
}
1962
1958
 Lines 1971-1977   void nsHTMLMediaElement::DownloadResumed() Link Here 
1971
void nsHTMLMediaElement::DownloadStalled()
1967
void nsHTMLMediaElement::DownloadStalled()
1972
{
1968
{
1973
  if (mNetworkState == nsIDOMHTMLMediaElement::NETWORK_LOADING) {
1969
  if (mNetworkState == nsIDOMHTMLMediaElement::NETWORK_LOADING) {
1974
    DispatchAsyncProgressEvent(NS_LITERAL_STRING("stalled"));
1970
    DispatchAsyncEvent(NS_LITERAL_STRING("stalled"));
1975
  }
1971
  }
1976
}
1972
}
1977
1973
 Lines 1994-2000   void nsHTMLMediaElement::UpdateReadyStateForData(NextFrameStatus aNextFrame) Link Here 
1994
  if (aNextFrame != NEXT_FRAME_AVAILABLE) {
1990
  if (aNextFrame != NEXT_FRAME_AVAILABLE) {
1995
    ChangeReadyState(nsIDOMHTMLMediaElement::HAVE_CURRENT_DATA);
1991
    ChangeReadyState(nsIDOMHTMLMediaElement::HAVE_CURRENT_DATA);
1996
    if (!mWaitingFired && aNextFrame == NEXT_FRAME_UNAVAILABLE_BUFFERING) {
1992
    if (!mWaitingFired && aNextFrame == NEXT_FRAME_UNAVAILABLE_BUFFERING) {
1997
      DispatchAsyncSimpleEvent(NS_LITERAL_STRING("waiting"));
1993
      DispatchAsyncEvent(NS_LITERAL_STRING("waiting"));
1998
      mWaitingFired = PR_TRUE;
1994
      mWaitingFired = PR_TRUE;
1999
    }
1995
    }
2000
    return;
1996
    return;
 Lines 2044-2057   void nsHTMLMediaElement::ChangeReadyState(nsMediaReadyState aState) Link Here 
2044
  // Handle raising of "waiting" event during seek (see 4.8.10.9)
2040
  // Handle raising of "waiting" event during seek (see 4.8.10.9)
2045
  if (mPlayingBeforeSeek &&
2041
  if (mPlayingBeforeSeek &&
2046
      oldState < nsIDOMHTMLMediaElement::HAVE_FUTURE_DATA) {
2042
      oldState < nsIDOMHTMLMediaElement::HAVE_FUTURE_DATA) {
2047
    DispatchAsyncSimpleEvent(NS_LITERAL_STRING("waiting"));
2043
    DispatchAsyncEvent(NS_LITERAL_STRING("waiting"));
2048
  }
2044
  }
2049
2045
2050
  if (oldState < nsIDOMHTMLMediaElement::HAVE_CURRENT_DATA &&
2046
  if (oldState < nsIDOMHTMLMediaElement::HAVE_CURRENT_DATA &&
2051
      mReadyState >= nsIDOMHTMLMediaElement::HAVE_CURRENT_DATA &&
2047
      mReadyState >= nsIDOMHTMLMediaElement::HAVE_CURRENT_DATA &&
2052
      !mLoadedFirstFrame)
2048
      !mLoadedFirstFrame)
2053
  {
2049
  {
2054
    DispatchAsyncSimpleEvent(NS_LITERAL_STRING("loadeddata"));
2050
    DispatchAsyncEvent(NS_LITERAL_STRING("loadeddata"));
2055
    mLoadedFirstFrame = PR_TRUE;
2051
    mLoadedFirstFrame = PR_TRUE;
2056
  }
2052
  }
2057
2053
 Lines 2061-2067   void nsHTMLMediaElement::ChangeReadyState(nsMediaReadyState aState) Link Here 
2061
2057
2062
  if (oldState < nsIDOMHTMLMediaElement::HAVE_FUTURE_DATA &&
2058
  if (oldState < nsIDOMHTMLMediaElement::HAVE_FUTURE_DATA &&
2063
      mReadyState >= nsIDOMHTMLMediaElement::HAVE_FUTURE_DATA) {
2059
      mReadyState >= nsIDOMHTMLMediaElement::HAVE_FUTURE_DATA) {
2064
    DispatchAsyncSimpleEvent(NS_LITERAL_STRING("canplay"));
2060
    DispatchAsyncEvent(NS_LITERAL_STRING("canplay"));
2065
  }
2061
  }
2066
2062
2067
  if (mReadyState == nsIDOMHTMLMediaElement::HAVE_ENOUGH_DATA) {
2063
  if (mReadyState == nsIDOMHTMLMediaElement::HAVE_ENOUGH_DATA) {
 Lines 2071-2082   void nsHTMLMediaElement::ChangeReadyState(nsMediaReadyState aState) Link Here 
2071
  if (oldState < nsIDOMHTMLMediaElement::HAVE_FUTURE_DATA &&
2067
  if (oldState < nsIDOMHTMLMediaElement::HAVE_FUTURE_DATA &&
2072
      mReadyState >= nsIDOMHTMLMediaElement::HAVE_FUTURE_DATA &&
2068
      mReadyState >= nsIDOMHTMLMediaElement::HAVE_FUTURE_DATA &&
2073
      IsPotentiallyPlaying()) {
2069
      IsPotentiallyPlaying()) {
2074
    DispatchAsyncSimpleEvent(NS_LITERAL_STRING("playing"));
2070
    DispatchAsyncEvent(NS_LITERAL_STRING("playing"));
2075
  }
2071
  }
2076
2072
2077
  if (oldState < nsIDOMHTMLMediaElement::HAVE_ENOUGH_DATA &&
2073
  if (oldState < nsIDOMHTMLMediaElement::HAVE_ENOUGH_DATA &&
2078
      mReadyState >= nsIDOMHTMLMediaElement::HAVE_ENOUGH_DATA) {
2074
      mReadyState >= nsIDOMHTMLMediaElement::HAVE_ENOUGH_DATA) {
2079
    DispatchAsyncSimpleEvent(NS_LITERAL_STRING("canplaythrough"));
2075
    DispatchAsyncEvent(NS_LITERAL_STRING("canplaythrough"));
2080
  }
2076
  }
2081
}
2077
}
2082
2078
 Lines 2099-2105   void nsHTMLMediaElement::NotifyAutoplayDataReady() Link Here 
2099
      SetPlayedOrSeeked(PR_TRUE);
2095
      SetPlayedOrSeeked(PR_TRUE);
2100
      mDecoder->Play();
2096
      mDecoder->Play();
2101
    }
2097
    }
2102
    DispatchAsyncSimpleEvent(NS_LITERAL_STRING("play"));
2098
    DispatchAsyncEvent(NS_LITERAL_STRING("play"));
2103
  }
2099
  }
2104
}
2100
}
2105
2101
 Lines 2150-2158   nsresult nsHTMLMediaElement::DispatchAudioAvailableEvent(float* aFrameBuffer, Link Here 
2150
  return target->DispatchEvent(event, &dummy);
2146
  return target->DispatchEvent(event, &dummy);
2151
}
2147
}
2152
2148
2153
nsresult nsHTMLMediaElement::DispatchSimpleEvent(const nsAString& aName)
2149
nsresult nsHTMLMediaElement::DispatchEvent(const nsAString& aName)
2154
{
2150
{
2155
  LOG_EVENT(PR_LOG_DEBUG, ("%p Dispatching simple event %s", this,
2151
  LOG_EVENT(PR_LOG_DEBUG, ("%p Dispatching event %s", this,
2156
                          NS_ConvertUTF16toUTF8(aName).get()));
2152
                          NS_ConvertUTF16toUTF8(aName).get()));
2157
2153
2158
  return nsContentUtils::DispatchTrustedEvent(GetOwnerDoc(),
2154
  return nsContentUtils::DispatchTrustedEvent(GetOwnerDoc(),
 Lines 2162-2216   nsresult nsHTMLMediaElement::DispatchSimpleEvent(const nsAString& aName) Link Here 
2162
                                              PR_TRUE);
2158
                                              PR_TRUE);
2163
}
2159
}
2164
2160
2165
nsresult nsHTMLMediaElement::DispatchAsyncSimpleEvent(const nsAString& aName)
2161
nsresult nsHTMLMediaElement::DispatchAsyncEvent(const nsAString& aName)
2166
{
2162
{
2167
  LOG_EVENT(PR_LOG_DEBUG, ("%p Queuing simple event %s", this, NS_ConvertUTF16toUTF8(aName).get()));
2163
  LOG_EVENT(PR_LOG_DEBUG, ("%p Queuing event %s", this,
2164
                           NS_ConvertUTF16toUTF8(aName).get()));
2168
2165
2169
  nsCOMPtr<nsIRunnable> event = new nsAsyncEventRunner(aName, this, PR_FALSE);
2166
  nsCOMPtr<nsIRunnable> event = new nsAsyncEventRunner(aName, this);
2170
  NS_DispatchToMainThread(event, NS_DISPATCH_NORMAL);
2167
  NS_DispatchToMainThread(event, NS_DISPATCH_NORMAL);
2171
  return NS_OK;
2168
  return NS_OK;
2172
}
2169
}
2173
2170
2174
nsresult nsHTMLMediaElement::DispatchAsyncProgressEvent(const nsAString& aName)
2175
{
2176
  LOG_EVENT(PR_LOG_DEBUG, ("%p Queuing progress event %s", this, NS_ConvertUTF16toUTF8(aName).get()));
2177
2178
  nsCOMPtr<nsIRunnable> event = new nsAsyncEventRunner(aName, this, PR_TRUE);
2179
  NS_DispatchToMainThread(event, NS_DISPATCH_NORMAL);
2180
  return NS_OK;
2181
}
2182
2183
nsresult nsHTMLMediaElement::DispatchProgressEvent(const nsAString& aName)
2184
{
2185
  nsCOMPtr<nsIDOMDocumentEvent> docEvent(do_QueryInterface(GetOwnerDoc()));
2186
  nsCOMPtr<nsIDOMEventTarget> target(do_QueryInterface(static_cast<nsIContent*>(this)));
2187
  NS_ENSURE_TRUE(docEvent && target, NS_ERROR_INVALID_ARG);
2188
2189
  nsCOMPtr<nsIDOMEvent> event;
2190
  nsresult rv = docEvent->CreateEvent(NS_LITERAL_STRING("ProgressEvent"), getter_AddRefs(event));
2191
  NS_ENSURE_SUCCESS(rv, rv);
2192
2193
  nsCOMPtr<nsIDOMProgressEvent> progressEvent(do_QueryInterface(event));
2194
  NS_ENSURE_TRUE(progressEvent, NS_ERROR_FAILURE);
2195
2196
  PRInt64 totalBytes = 0;
2197
  PRUint64 downloadPosition = 0;
2198
  if (mDecoder) {
2199
    nsMediaDecoder::Statistics stats = mDecoder->GetStatistics();
2200
    totalBytes = stats.mTotalBytes;
2201
    downloadPosition = stats.mDownloadPosition;
2202
  }
2203
  rv = progressEvent->InitProgressEvent(aName, PR_TRUE, PR_TRUE,
2204
    totalBytes >= 0, downloadPosition, totalBytes);
2205
  NS_ENSURE_SUCCESS(rv, rv);
2206
2207
  LOG_EVENT(PR_LOG_DEBUG, ("%p Dispatching progress event %s", this,
2208
                          NS_ConvertUTF16toUTF8(aName).get()));
2209
2210
  PRBool dummy;
2211
  return target->DispatchEvent(event, &dummy);
2212
}
2213
2214
nsresult nsHTMLMediaElement::DoneAddingChildren(PRBool aHaveNotified)
2171
nsresult nsHTMLMediaElement::DoneAddingChildren(PRBool aHaveNotified)
2215
{
2172
{
2216
  if (!mIsDoneAddingChildren) {
2173
  if (!mIsDoneAddingChildren) {
 Lines 2493-2499   nsresult nsHTMLMediaElement::GetBuffered(nsIDOMTimeRanges** aBuffered) Link Here 
2493
  nsTimeRanges* ranges = new nsTimeRanges();
2450
  nsTimeRanges* ranges = new nsTimeRanges();
2494
  NS_ADDREF(*aBuffered = ranges);
2451
  NS_ADDREF(*aBuffered = ranges);
2495
  if (mReadyState >= nsIDOMHTMLMediaElement::HAVE_CURRENT_DATA && mDecoder) {
2452
  if (mReadyState >= nsIDOMHTMLMediaElement::HAVE_CURRENT_DATA && mDecoder) {
2496
    return mDecoder->GetBuffered(ranges);
2453
    // If GetBuffered fails we ignore the error result and just return the
2454
    // time ranges we found up till the error.
2455
    mDecoder->GetBuffered(ranges);
2497
  }
2456
  }
2498
  return NS_OK;
2457
  return NS_OK;
2499
}
2458
}
(-)a/content/media/nsBuiltinDecoder.cpp (-4 / +4 lines)
Line     Link Here 
 Lines 355-361   void nsBuiltinDecoder::MetadataLoaded(PRUint32 aChannels, Link Here 
355
  else if (mElement) {
355
  else if (mElement) {
356
    // Resource was loaded during metadata loading, when progress
356
    // Resource was loaded during metadata loading, when progress
357
    // events are being ignored. Fire the final progress event.
357
    // events are being ignored. Fire the final progress event.
358
    mElement->DispatchAsyncProgressEvent(NS_LITERAL_STRING("progress"));
358
    mElement->DispatchAsyncEvent(NS_LITERAL_STRING("progress"));
359
  }
359
  }
360
360
361
  // Only inform the element of FirstFrameLoaded if not doing a load() in order
361
  // Only inform the element of FirstFrameLoaded if not doing a load() in order
 Lines 411-417   void nsBuiltinDecoder::ResourceLoaded() Link Here 
411
411
412
  // Ensure the final progress event gets fired
412
  // Ensure the final progress event gets fired
413
  if (mElement) {
413
  if (mElement) {
414
    mElement->DispatchAsyncProgressEvent(NS_LITERAL_STRING("progress"));
414
    mElement->DispatchAsyncEvent(NS_LITERAL_STRING("progress"));
415
    mElement->ResourceLoaded();
415
    mElement->ResourceLoaded();
416
  }
416
  }
417
}
417
}
 Lines 767-773   void nsBuiltinDecoder::PlaybackPositionChanged() Link Here 
767
  Invalidate();
767
  Invalidate();
768
768
769
  if (mElement && lastTime != mCurrentTime) {
769
  if (mElement && lastTime != mCurrentTime) {
770
    mElement->DispatchSimpleEvent(NS_LITERAL_STRING("timeupdate"));
770
    mElement->DispatchEvent(NS_LITERAL_STRING("timeupdate"));
771
  }
771
  }
772
}
772
}
773
773
 Lines 782-788   void nsBuiltinDecoder::DurationChanged() Link Here 
782
782
783
  if (mElement && oldDuration != mDuration) {
783
  if (mElement && oldDuration != mDuration) {
784
    LOG(PR_LOG_DEBUG, ("%p duration changed to %lldms", this, mDuration));
784
    LOG(PR_LOG_DEBUG, ("%p duration changed to %lldms", this, mDuration));
785
    mElement->DispatchSimpleEvent(NS_LITERAL_STRING("durationchange"));
785
    mElement->DispatchEvent(NS_LITERAL_STRING("durationchange"));
786
  }
786
  }
787
}
787
}
788
788
(-)a/content/media/nsMediaDecoder.cpp (-1 / +1 lines)
Line     Link Here 
 Lines 200-206   void nsMediaDecoder::Progress(PRBool aTimer) Link Here 
200
       now - mProgressTime >= TimeDuration::FromMilliseconds(PROGRESS_MS)) &&
200
       now - mProgressTime >= TimeDuration::FromMilliseconds(PROGRESS_MS)) &&
201
      !mDataTime.IsNull() &&
201
      !mDataTime.IsNull() &&
202
      now - mDataTime <= TimeDuration::FromMilliseconds(PROGRESS_MS)) {
202
      now - mDataTime <= TimeDuration::FromMilliseconds(PROGRESS_MS)) {
203
    mElement->DispatchAsyncProgressEvent(NS_LITERAL_STRING("progress"));
203
    mElement->DispatchAsyncEvent(NS_LITERAL_STRING("progress"));
204
    mProgressTime = now;
204
    mProgressTime = now;
205
  }
205
  }
206
206
(-)a/content/media/ogg/nsOggReader.cpp (-1 / +11 lines)
Line     Link Here 
 Lines 910-916   PRInt64 nsOggReader::FindEndTime(PRInt64 aEndOffset, Link Here 
910
      // We need more data if we've not encountered a page we've seen before,
910
      // We need more data if we've not encountered a page we've seen before,
911
      // or we've read to the end of file.
911
      // or we've read to the end of file.
912
      if (mustBackOff || readHead == aEndOffset) {
912
      if (mustBackOff || readHead == aEndOffset) {
913
        if (endTime != -1) {
913
        if (endTime != -1 || readStartOffset == 0) {
914
          // We have encountered a page before, or we're at the end of file.
914
          // We have encountered a page before, or we're at the end of file.
915
          break;
915
          break;
916
        }
916
        }
 Lines 1542-1547   nsresult nsOggReader::SeekBisection(PRInt64 aTarget, Link Here 
1542
nsresult nsOggReader::GetBuffered(nsTimeRanges* aBuffered, PRInt64 aStartTime)
1542
nsresult nsOggReader::GetBuffered(nsTimeRanges* aBuffered, PRInt64 aStartTime)
1543
{
1543
{
1544
  NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
1544
  NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
1545
1546
  // HasAudio and HasVideo are not used here as they take a lock and cause
1547
  // a deadlock. Accessing mInfo doesn't require a lock - it doesn't change
1548
  // after metadata is read and GetBuffered isn't called before metadata is
1549
  // read.
1550
  if (!mInfo.mHasVideo && !mInfo.mHasAudio) {
1551
    // No need to search through the file if there are no audio or video tracks
1552
    return NS_OK;
1553
  }
1554
1545
  nsMediaStream* stream = mDecoder->GetCurrentStream();
1555
  nsMediaStream* stream = mDecoder->GetCurrentStream();
1546
1556
1547
  // Traverse across the buffered byte ranges, determining the time ranges
1557
  // Traverse across the buffered byte ranges, determining the time ranges
(-)a/content/media/test/test_progress.html (-7 lines)
Line     Link Here 
 Lines 17-27   var videos = []; Link Here 
17
function do_progress(e) {
17
function do_progress(e) {
18
  var v = e.target;
18
  var v = e.target;
19
  ok(!v._finished, "Check no progress events after completed for " + v._name);
19
  ok(!v._finished, "Check no progress events after completed for " + v._name);
20
  ok(e.lengthComputable, "Check progress lengthComputable for " + v._name);
21
  ok(e.loaded >= v._last_progress_total, "Check progress increasing: " + e.loaded + " for " + v._name);
22
  v._last_progress_total = e.loaded;
23
  ok(e.loaded <= e.total, "Check progress in bounds: " + e.loaded + " for " + v._name);
24
  is(e.total, v._size, "Check progress total for " + v._name);
25
}
20
}
26
21
27
function do_ended(e) {
22
function do_ended(e) {
 Lines 41-49   for (var i=0; i<gProgressTests.length; ++i) { Link Here 
41
  v.src = test.name;
36
  v.src = test.name;
42
  v.autoplay = true;
37
  v.autoplay = true;
43
  v._name = test.name;
38
  v._name = test.name;
44
  v._size = test.size;
45
  v._finished = false;
39
  v._finished = false;
46
  v._last_progress_total = 0;
47
  v.addEventListener("ended", do_ended, false);
40
  v.addEventListener("ended", do_ended, false);
48
  v.addEventListener("progress", do_progress, false);
41
  v.addEventListener("progress", do_progress, false);
49
  document.body.appendChild(v);
42
  document.body.appendChild(v);
(-)a/content/media/wave/nsWaveDecoder.cpp (-2 / +2 lines)
Line     Link Here 
 Lines 1466-1472   nsWaveDecoder::ResourceLoaded() Link Here 
1466
1466
1467
  if (mElement) {
1467
  if (mElement) {
1468
    // Ensure the final progress event gets fired
1468
    // Ensure the final progress event gets fired
1469
    mElement->DispatchAsyncProgressEvent(NS_LITERAL_STRING("progress"));
1469
    mElement->DispatchAsyncEvent(NS_LITERAL_STRING("progress"));
1470
    mElement->ResourceLoaded();
1470
    mElement->ResourceLoaded();
1471
  }
1471
  }
1472
1472
 Lines 1673-1679   nsWaveDecoder::PlaybackPositionChanged() Link Here 
1673
1673
1674
  if (mElement && lastTime != mCurrentTime) {
1674
  if (mElement && lastTime != mCurrentTime) {
1675
    UpdateReadyStateForData();
1675
    UpdateReadyStateForData();
1676
    mElement->DispatchSimpleEvent(NS_LITERAL_STRING("timeupdate"));
1676
    mElement->DispatchEvent(NS_LITERAL_STRING("timeupdate"));
1677
  }
1677
  }
1678
}
1678
}
1679
1679

Return to bug 584615