Skip to content

Commit

Permalink
merge mozilla-inbound to mozilla-central a=merge
Browse files Browse the repository at this point in the history
  • Loading branch information
BavarianTomcat committed Apr 23, 2015
2 parents 51a4f46 + d7660b2 commit ad1045a
Show file tree
Hide file tree
Showing 144 changed files with 3,868 additions and 633 deletions.
2 changes: 1 addition & 1 deletion dom/base/EventSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ EventSource::InitChannelAndRequestEventSource()

nsRefPtr<nsCORSListenerProxy> listener =
new nsCORSListenerProxy(this, mPrincipal, mWithCredentials);
rv = listener->Init(mHttpChannel);
rv = listener->Init(mHttpChannel, DataURIHandling::Allow);
NS_ENSURE_SUCCESS(rv, rv);

// Start reading from the channel
Expand Down
2 changes: 1 addition & 1 deletion dom/base/ImportManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ ImportLoader::Open()
nsRefPtr<nsCORSListenerProxy> corsListener =
new nsCORSListenerProxy(this, principal,
/* aWithCredentials */ false);
rv = corsListener->Init(channel, true);
rv = corsListener->Init(channel, DataURIHandling::Allow);
NS_ENSURE_SUCCESS_VOID(rv);

rv = channel->AsyncOpen(corsListener, nullptr);
Expand Down
2 changes: 1 addition & 1 deletion dom/base/Navigator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1225,7 +1225,7 @@ Navigator::SendBeacon(const nsAString& aUrl,
principal,
true);

rv = cors->Init(channel, true);
rv = cors->Init(channel, DataURIHandling::Allow);
NS_ENSURE_SUCCESS(rv, false);

nsCOMPtr<nsINetworkInterceptController> interceptController = do_QueryInterface(docShell);
Expand Down
2 changes: 1 addition & 1 deletion dom/base/nsScriptLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ nsScriptLoader::StartLoad(nsScriptLoadRequest *aRequest, const nsAString &aType,
nsRefPtr<nsCORSListenerProxy> corsListener =
new nsCORSListenerProxy(listener, mDocument->NodePrincipal(),
withCredentials);
rv = corsListener->Init(channel);
rv = corsListener->Init(channel, DataURIHandling::Allow);
NS_ENSURE_SUCCESS(rv, rv);
listener = corsListener;
}
Expand Down
2 changes: 1 addition & 1 deletion dom/base/nsSyncLoadService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ nsSyncLoader::LoadDocument(nsIChannel* aChannel,
if (aLoaderPrincipal) {
nsRefPtr<nsCORSListenerProxy> corsListener =
new nsCORSListenerProxy(listener, aLoaderPrincipal, false);
rv = corsListener->Init(mChannel);
rv = corsListener->Init(mChannel, DataURIHandling::Disallow);
NS_ENSURE_SUCCESS(rv, rv);
listener = corsListener;
}
Expand Down
2 changes: 1 addition & 1 deletion dom/base/nsXMLHttpRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2889,7 +2889,7 @@ nsXMLHttpRequest::Send(nsIVariant* aVariant, const Nullable<RequestBody>& aBody)
// a same-origin request right now, since it could be redirected.
nsRefPtr<nsCORSListenerProxy> corsListener =
new nsCORSListenerProxy(listener, mPrincipal, withCredentials);
rv = corsListener->Init(mChannel, true);
rv = corsListener->Init(mChannel, DataURIHandling::Allow);
NS_ENSURE_SUCCESS(rv, rv);
listener = corsListener;
}
Expand Down
1 change: 1 addition & 0 deletions dom/base/test/mochitest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -780,3 +780,4 @@ skip-if = buildapp == 'mulet' || buildapp == 'b2g'
[test_bug1118689.html]
skip-if = buildapp == 'mulet' || buildapp == 'b2g'
[test_integer_attr_with_leading_zero.html]
[test_script_loader_crossorigin_data_url.html]
38 changes: 38 additions & 0 deletions dom/base/test/test_script_loader_crossorigin_data_url.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!DOCTYPE html>
<meta charset=utf-8>
<title>Test for handling of 'crossorigin' attribute on script with data: URL</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<script>
// We're going to mess with window.onerror.
setup({ allow_uncaught_exception: true });
</script>
<!-- First check that data: scripts with @crossorigin run at all -->
<script>
var ran = false;
</script>
<script crossorigin src="data:application/javascript,ran = true"></script>
<script>
test(function() {
assert_true(ran);
}, "script@crossorigin with data: src should have run");
</script>
<!-- Then check that their syntax errors are not sanitized -->
<script>
var errorFired = false;
ran = false;
window.onerror = function(message, uri, line) {
errorFired = true;
test(function() {
assert_equals(line, 3);
}, "Should have a useful line number for exception in script@crossorigin with data: src");
}
</script>
<script crossorigin src="data:application/javascript,var%20a;%0aran=true%0anoSuchFunctionHere()"></script>
<script>
test(function() {
assert_true(ran, "Script with error should have run");
assert_true(errorFired, "Script with error should have fired onerror");
}, "Should run and correctly fire onerror");
</script>
2 changes: 1 addition & 1 deletion dom/fetch/FetchDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ FetchDriver::HttpFetch(bool aCORSFlag, bool aCORSPreflightFlag, bool aAuthentica
// directly.
nsRefPtr<nsCORSListenerProxy> corsListener =
new nsCORSListenerProxy(this, mPrincipal, useCredentials);
rv = corsListener->Init(chan, true /* allow data uri */);
rv = corsListener->Init(chan, DataURIHandling::Allow);
if (NS_WARN_IF(NS_FAILED(rv))) {
return FailWithNetworkError();
}
Expand Down
57 changes: 38 additions & 19 deletions dom/html/HTMLMediaElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ void HTMLMediaElement::ShutdownDecoder()
RemoveMediaElementFromURITable();
NS_ASSERTION(mDecoder, "Must have decoder to shut down");
mDecoder->Shutdown();
mDecoder = nullptr;
SetDecoder(nullptr);
}

void HTMLMediaElement::AbortExistingLoads()
Expand Down Expand Up @@ -700,7 +700,7 @@ void HTMLMediaElement::AbortExistingLoads()
mPendingEncryptedInitData.mInitDatas.Clear();
#endif // MOZ_EME
mSourcePointer = nullptr;
mLastNextFrameStatus = NEXT_FRAME_UNINITIALIZED;
mNextFrameStatus = NEXT_FRAME_UNINITIALIZED;

mTags = nullptr;

Expand Down Expand Up @@ -941,13 +941,13 @@ void HTMLMediaElement::NotifyMediaStreamTracksAvailable(DOMMediaStream* aStream)

bool videoHasChanged = IsVideo() && HasVideo() != !VideoTracks()->IsEmpty();

UpdateReadyStateForData(mLastNextFrameStatus);

if (videoHasChanged) {
// We are a video element and HasVideo() changed so update the screen
// wakelock
NotifyOwnerDocumentActivityChanged();
}

mReadyStateUpdater->Notify();
}

void HTMLMediaElement::LoadFromSourceChildren()
Expand Down Expand Up @@ -1275,7 +1275,7 @@ nsresult HTMLMediaElement::LoadResource()
new nsCORSListenerProxy(loadListener,
NodePrincipal(),
GetCORSMode() == CORS_USE_CREDENTIALS);
rv = corsListener->Init(channel);
rv = corsListener->Init(channel, DataURIHandling::Allow);
NS_ENSURE_SUCCESS(rv, rv);
listener = corsListener;
} else {
Expand Down Expand Up @@ -2045,8 +2045,9 @@ HTMLMediaElement::HTMLMediaElement(already_AddRefed<mozilla::dom::NodeInfo>& aNo
: nsGenericHTMLElement(aNodeInfo),
mCurrentLoadID(0),
mNetworkState(nsIDOMHTMLMediaElement::NETWORK_EMPTY),
mReadyState(nsIDOMHTMLMediaElement::HAVE_NOTHING),
mLastNextFrameStatus(NEXT_FRAME_UNINITIALIZED),
mReadyState(nsIDOMHTMLMediaElement::HAVE_NOTHING, "HTMLMediaElement::mReadyState"),
mReadyStateUpdater("HTMLMediaElement::mReadyStateUpdater"),
mNextFrameStatus(NEXT_FRAME_UNINITIALIZED, "HTMLMediaElement::mNextFrameStatus"),
mLoadWaitStatus(NOT_WAITING),
mVolume(1.0),
mPreloadAction(PRELOAD_UNDEFINED),
Expand Down Expand Up @@ -2087,7 +2088,7 @@ HTMLMediaElement::HTMLMediaElement(already_AddRefed<mozilla::dom::NodeInfo>& aNo
mMediaSecurityVerified(false),
mCORSMode(CORS_NONE),
mIsEncrypted(false),
mDownloadSuspendedByCache(false),
mDownloadSuspendedByCache(false, "HTMLMediaElement::mDownloadSuspendedByCache"),
mAudioChannelFaded(false),
mPlayingThroughTheAudioChannel(false),
mDisableVideo(false),
Expand All @@ -2100,6 +2101,7 @@ HTMLMediaElement::HTMLMediaElement(already_AddRefed<mozilla::dom::NodeInfo>& aNo
if (!gMediaElementEventsLog) {
gMediaElementEventsLog = PR_NewLogModule("nsMediaElementEvents");
}
EnsureStateWatchingLog();
#endif

mAudioChannel = AudioChannelService::GetDefaultAudioChannel();
Expand All @@ -2108,6 +2110,14 @@ HTMLMediaElement::HTMLMediaElement(already_AddRefed<mozilla::dom::NodeInfo>& aNo

RegisterActivityObserver();
NotifyOwnerDocumentActivityChanged();

MOZ_ASSERT(NS_IsMainThread());
mReadyStateUpdater->AddWeakCallback(this, &HTMLMediaElement::UpdateReadyStateInternal);
mReadyStateUpdater->Watch(mNextFrameStatus);
mReadyStateUpdater->Watch(mDownloadSuspendedByCache);
// Paradoxically, there is a self-edge whereby UpdateReadyStateInternal refuses
// to run until mReadyState reaches at least HAVE_METADATA by some other means.
mReadyStateUpdater->Watch(mReadyState);
}

HTMLMediaElement::~HTMLMediaElement()
Expand Down Expand Up @@ -2604,8 +2614,8 @@ HTMLMediaElement::ReportMSETelemetry()
ErrorResult ignore;
stalled = index != TimeRanges::NoIndex &&
(ranges->End(index, ignore) - t) < errorMargin;
stalled |= mLastNextFrameStatus == MediaDecoderOwner::NEXT_FRAME_UNAVAILABLE_BUFFERING &&
mReadyState == HTMLMediaElement::HAVE_CURRENT_DATA;
stalled |= mNextFrameStatus == MediaDecoderOwner::NEXT_FRAME_UNAVAILABLE_BUFFERING &&
mReadyState == HTMLMediaElement::HAVE_CURRENT_DATA;
if (stalled) {
state = STALLED;
}
Expand Down Expand Up @@ -2751,7 +2761,7 @@ nsresult HTMLMediaElement::InitializeDecoderForChannel(nsIChannel* aChannel,
// RtspMediaResource.
if (DecoderTraits::DecoderWaitsForOnConnected(mimeType)) {
decoder->SetResource(resource);
mDecoder = decoder;
SetDecoder(decoder);
if (aListener) {
*aListener = nullptr;
}
Expand All @@ -2777,7 +2787,7 @@ nsresult HTMLMediaElement::FinishDecoderSetup(MediaDecoder* aDecoder,
mPendingEvents.Clear();
// Set mDecoder now so if methods like GetCurrentSrc get called between
// here and Load(), they work.
mDecoder = aDecoder;
SetDecoder(aDecoder);

// Tell the decoder about its MediaResource now so things like principals are
// available immediately.
Expand All @@ -2802,7 +2812,7 @@ nsresult HTMLMediaElement::FinishDecoderSetup(MediaDecoder* aDecoder,

nsresult rv = aDecoder->Load(aListener, aCloneDonor);
if (NS_FAILED(rv)) {
mDecoder = nullptr;
SetDecoder(nullptr);
LOG(PR_LOG_DEBUG, ("%p Failed to load for decoder %p", this, aDecoder));
return rv;
}
Expand Down Expand Up @@ -3213,7 +3223,7 @@ void HTMLMediaElement::MetadataLoaded(const MediaInfo* aInfo,
if (!aInfo->HasVideo()) {
ResetState();
} else {
UpdateReadyStateForData(mLastNextFrameStatus);
mReadyStateUpdater->Notify();
}

if (IsVideo() && aInfo->HasVideo()) {
Expand Down Expand Up @@ -3496,7 +3506,16 @@ bool HTMLMediaElement::IsCORSSameOrigin()

void HTMLMediaElement::UpdateReadyStateForData(MediaDecoderOwner::NextFrameStatus aNextFrame)
{
mLastNextFrameStatus = aNextFrame;
mNextFrameStatus = aNextFrame;
}

void
HTMLMediaElement::UpdateReadyStateInternal()
{
if (!mDecoder && !mSrcStream) {
// Not initialized - bail out.
return;
}

if (mDecoder && mReadyState < nsIDOMHTMLMediaElement::HAVE_METADATA) {
// aNextFrame might have a next frame because the decoder can advance
Expand All @@ -3520,7 +3539,7 @@ void HTMLMediaElement::UpdateReadyStateForData(MediaDecoderOwner::NextFrameStatu
MetadataLoaded(&mediaInfo, nsAutoPtr<const MetadataTags>(nullptr));
}

if (aNextFrame == MediaDecoderOwner::NEXT_FRAME_UNAVAILABLE_SEEKING) {
if (mNextFrameStatus == MediaDecoderOwner::NEXT_FRAME_UNAVAILABLE_SEEKING) {
ChangeReadyState(nsIDOMHTMLMediaElement::HAVE_METADATA);
return;
}
Expand Down Expand Up @@ -3549,9 +3568,9 @@ void HTMLMediaElement::UpdateReadyStateForData(MediaDecoderOwner::NextFrameStatu
return;
}

if (aNextFrame != MediaDecoderOwner::NEXT_FRAME_AVAILABLE) {
if (mNextFrameStatus != MediaDecoderOwner::NEXT_FRAME_AVAILABLE) {
ChangeReadyState(nsIDOMHTMLMediaElement::HAVE_CURRENT_DATA);
if (!mWaitingFired && aNextFrame == MediaDecoderOwner::NEXT_FRAME_UNAVAILABLE_BUFFERING) {
if (!mWaitingFired && mNextFrameStatus == MediaDecoderOwner::NEXT_FRAME_UNAVAILABLE_BUFFERING) {
FireTimeUpdate(false);
DispatchAsyncEvent(NS_LITERAL_STRING("waiting"));
mWaitingFired = true;
Expand Down Expand Up @@ -3870,7 +3889,7 @@ void HTMLMediaElement::UpdateMediaSize(const nsIntSize& aSize)
}

mMediaInfo.mVideo.mDisplay = aSize;
UpdateReadyStateForData(mLastNextFrameStatus);
mReadyStateUpdater->Notify();
}

void HTMLMediaElement::UpdateInitialMediaSize(const nsIntSize& aSize)
Expand Down
23 changes: 20 additions & 3 deletions dom/html/HTMLMediaElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#ifdef MOZ_EME
#include "mozilla/dom/MediaKeys.h"
#endif
#include "StateWatching.h"
#include "nsGkAtoms.h"

// X.h on Linux #defines CurrentTime as 0L, so we have to #undef it here.
Expand Down Expand Up @@ -647,6 +648,17 @@ class HTMLMediaElement : public nsGenericHTMLElement,
class StreamListener;
class StreamSizeListener;

void SetDecoder(MediaDecoder* aDecoder)
{
if (mDecoder) {
mReadyStateUpdater->Unwatch(mDecoder->ReadyStateWatchTarget());
}
mDecoder = aDecoder;
if (mDecoder) {
mReadyStateUpdater->Watch(mDecoder->ReadyStateWatchTarget());
}
}

virtual void GetItemValueText(DOMString& text) override;
virtual void SetItemValueText(const nsAString& text) override;

Expand Down Expand Up @@ -1013,6 +1025,9 @@ class HTMLMediaElement : public nsGenericHTMLElement,
// MediaElement doesn't yet have one then it will create it.
TextTrackManager* GetOrCreateTextTrackManager();

// Recomputes ready state and fires events as necessary based on current state.
void UpdateReadyStateInternal();

class nsAsyncEventRunner;
using nsGenericHTMLElement::DispatchEvent;
// For nsAsyncEventRunner.
Expand Down Expand Up @@ -1090,10 +1105,12 @@ class HTMLMediaElement : public nsGenericHTMLElement,
// Media loading flags. See:
// http://www.whatwg.org/specs/web-apps/current-work/#video)
nsMediaNetworkState mNetworkState;
nsMediaReadyState mReadyState;
Watchable<nsMediaReadyState> mReadyState;

WatcherHolder mReadyStateUpdater;

// Last value passed from codec or stream source to UpdateReadyStateForData.
NextFrameStatus mLastNextFrameStatus;
Watchable<NextFrameStatus> mNextFrameStatus;

enum LoadAlgorithmState {
// No load algorithm instance is waiting for a source to be added to the
Expand Down Expand Up @@ -1328,7 +1345,7 @@ class HTMLMediaElement : public nsGenericHTMLElement,
#endif // MOZ_EME

// True if the media's channel's download has been suspended.
bool mDownloadSuspendedByCache;
Watchable<bool> mDownloadSuspendedByCache;

// Audio Channel.
AudioChannel mAudioChannel;
Expand Down
7 changes: 6 additions & 1 deletion dom/media/AbstractThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,12 @@ class XPCOMThreadWrapper : public AbstractThread
return in;
}

void FireTailDispatcher() { MOZ_ASSERT(mTailDispatcher.isSome()); mTailDispatcher.reset(); }
void FireTailDispatcher()
{
MOZ_DIAGNOSTIC_ASSERT(mTailDispatcher.isSome());
mTailDispatcher.ref().DrainDirectTasks();
mTailDispatcher.reset();
}

virtual TaskDispatcher& TailDispatcher() override
{
Expand Down
Loading

0 comments on commit ad1045a

Please sign in to comment.