diff --git a/content/base/public/nsContentPolicyUtils.h b/content/base/public/nsContentPolicyUtils.h index 15b151503467..a57ac60c1bf4 100644 --- a/content/base/public/nsContentPolicyUtils.h +++ b/content/base/public/nsContentPolicyUtils.h @@ -141,7 +141,6 @@ NS_CP_ContentTypeName(PRUint32 contentType) CASE_RETURN( TYPE_OBJECT_SUBREQUEST ); CASE_RETURN( TYPE_DTD ); CASE_RETURN( TYPE_FONT ); - CASE_RETURN( TYPE_MEDIA ); default: return ""; } diff --git a/content/base/public/nsIContentPolicy.idl b/content/base/public/nsIContentPolicy.idl index 47016388bfc1..d9ed73815b76 100644 --- a/content/base/public/nsIContentPolicy.idl +++ b/content/base/public/nsIContentPolicy.idl @@ -51,7 +51,7 @@ interface nsIDOMNode; * by launching a dialog to prompt the user for something). */ -[scriptable,uuid(344f9cb0-9a17-44c5-ab96-ee707884266c)] +[scriptable,uuid(58cf9dca-40b3-6211-a508-7351f437a53e)] interface nsIContentPolicy : nsISupports { const unsigned long TYPE_OTHER = 1; @@ -131,11 +131,6 @@ interface nsIContentPolicy : nsISupports */ const unsigned long TYPE_FONT = 14; - /** - * Indicates a video or audio load. - */ - const unsigned long TYPE_MEDIA = 15; - ////////////////////////////////////////////////////////////////////// /** diff --git a/content/html/content/public/nsHTMLMediaElement.h b/content/html/content/public/nsHTMLMediaElement.h index a8b8e89bfdaa..578a2201e553 100644 --- a/content/html/content/public/nsHTMLMediaElement.h +++ b/content/html/content/public/nsHTMLMediaElement.h @@ -138,10 +138,6 @@ public: // events can be fired. void ChangeReadyState(nsMediaReadyState aState); - // Gets the pref browser.media.enforce_same_site_origin, which determines - // if we should check Access Controls, or allow cross domain loads. - PRBool ShouldCheckAllowOrigin(); - // Is the media element actively playing as defined by the HTML 5 specification. // http://www.whatwg.org/specs/web-apps/current-work/#actively PRBool IsActivelyPlaying() const; diff --git a/content/html/content/src/nsHTMLMediaElement.cpp b/content/html/content/src/nsHTMLMediaElement.cpp index dd32d1060009..9357ee50c6a6 100644 --- a/content/html/content/src/nsHTMLMediaElement.cpp +++ b/content/html/content/src/nsHTMLMediaElement.cpp @@ -69,10 +69,6 @@ #include "nsHTMLMediaError.h" #include "nsICategoryManager.h" -#include "nsIContentPolicy.h" -#include "nsContentPolicyUtils.h" -#include "nsContentErrors.h" - #ifdef MOZ_OGG #include "nsOggDecoder.h" #endif @@ -173,7 +169,7 @@ nsresult nsHTMLMediaElement::LoadWithChannel(nsIChannel *aChannel, if (mBegun) { mBegun = PR_FALSE; - mError = new nsHTMLMediaError(nsIDOMHTMLMediaError::MEDIA_ERR_ABORTED); + mError = new nsHTMLMediaError(nsHTMLMediaError::MEDIA_ERR_ABORTED); DispatchProgressEvent(NS_LITERAL_STRING("abort")); return NS_OK; } @@ -666,23 +662,6 @@ nsresult nsHTMLMediaElement::InitializeDecoder(const nsAString& aURISpec) baseURL); NS_ENSURE_SUCCESS(rv, rv); - nsCOMPtr elementPrincipal = NodePrincipal(); - NS_ENSURE_TRUE(elementPrincipal, NS_ERROR_FAILURE); - - PRInt16 shouldLoad = nsIContentPolicy::ACCEPT; - rv = NS_CheckContentLoadPolicy(nsIContentPolicy::TYPE_MEDIA, - uri, - elementPrincipal, - this, - EmptyCString(), // mime type - nsnull, // extra - &shouldLoad, - nsContentUtils::GetContentPolicy(), - nsContentUtils::GetSecurityManager()); - if (NS_FAILED(rv) || NS_CP_REJECTED(shouldLoad)) { - return NS_ERROR_CONTENT_BLOCKED; - } - if (mDecoder) { mDecoder->ElementAvailable(this); rv = mDecoder->Load(uri, nsnull, nsnull); @@ -723,7 +702,7 @@ void nsHTMLMediaElement::ResourceLoaded() void nsHTMLMediaElement::NetworkError() { - mError = new nsHTMLMediaError(nsIDOMHTMLMediaError::MEDIA_ERR_NETWORK); + mError = new nsHTMLMediaError(nsHTMLMediaError::MEDIA_ERR_NETWORK); mBegun = PR_FALSE; DispatchProgressEvent(NS_LITERAL_STRING("error")); mNetworkState = nsIDOMHTMLMediaElement::EMPTY; @@ -754,23 +733,6 @@ void nsHTMLMediaElement::SeekCompleted() DispatchAsyncSimpleEvent(NS_LITERAL_STRING("seeked")); } -PRBool nsHTMLMediaElement::ShouldCheckAllowOrigin() -{ - nsCOMPtr prefs = do_GetService("@mozilla.org/preferences-service;1"); - PRBool checkOrigin = PR_TRUE; - if (prefs) { - nsCOMPtr prefBranch; - prefs->GetBranch(nsnull, getter_AddRefs(prefBranch)); - if (prefBranch) { - nsresult res = prefBranch->GetBoolPref("browser.media.enforce_same_site_origin", - &checkOrigin); - if (NS_FAILED(res)) - return PR_TRUE; - } - } - return checkOrigin; -} - void nsHTMLMediaElement::ChangeReadyState(nsMediaReadyState aState) { // Handle raising of "waiting" event during seek (see 4.7.10.8) diff --git a/content/media/video/public/nsMediaDecoder.h b/content/media/video/public/nsMediaDecoder.h index 168c97c38008..ab9c96ca6256 100644 --- a/content/media/video/public/nsMediaDecoder.h +++ b/content/media/video/public/nsMediaDecoder.h @@ -170,10 +170,6 @@ class nsMediaDecoder : public nsIObserver // thread by the owning object before that object disposes of this object. virtual void Shutdown(); - // Returns a weak reference to the media element we're decoding for, - // if it's available. - nsHTMLMediaElement* GetMediaElement(); - protected: // Start timer to update download progress information. diff --git a/content/media/video/public/nsMediaStream.h b/content/media/video/public/nsMediaStream.h index 935f29ba2a88..568216fdc34e 100644 --- a/content/media/video/public/nsMediaStream.h +++ b/content/media/video/public/nsMediaStream.h @@ -42,7 +42,6 @@ #include "nsIChannel.h" #include "nsIPrincipal.h" #include "nsIURI.h" -#include "nsIStreamListener.h" #include "prlock.h" class nsMediaDecoder; diff --git a/content/media/video/src/nsChannelToPipeListener.cpp b/content/media/video/src/nsChannelToPipeListener.cpp index afbb6fa28ddc..4eb2afaeca25 100644 --- a/content/media/video/src/nsChannelToPipeListener.cpp +++ b/content/media/video/src/nsChannelToPipeListener.cpp @@ -41,8 +41,6 @@ #include "nsIScriptSecurityManager.h" #include "nsChannelToPipeListener.h" #include "nsICachingChannel.h" -#include "nsDOMError.h" -#include "nsHTMLMediaElement.h" #define HTTP_OK_CODE 200 #define HTTP_PARTIAL_RESPONSE_CODE 206 @@ -98,19 +96,6 @@ nsresult nsChannelToPipeListener::GetInputStream(nsIInputStream** aStream) nsresult nsChannelToPipeListener::OnStartRequest(nsIRequest* aRequest, nsISupports* aContext) { - nsHTMLMediaElement* element = mDecoder->GetMediaElement(); - NS_ENSURE_TRUE(element, NS_ERROR_FAILURE); - if (element->ShouldCheckAllowOrigin()) { - // If the request was cancelled by nsCrossSiteListenerProxy due to failing - // the Access Control check, send an error through to the media element. - nsresult status; - nsresult rv = aRequest->GetStatus(&status); - if (NS_FAILED(rv) || status == NS_ERROR_DOM_BAD_URI) { - mDecoder->NetworkError(); - return NS_ERROR_DOM_BAD_URI; - } - } - mIntervalStart = PR_IntervalNow(); mIntervalEnd = mIntervalStart; mTotalBytes = 0; diff --git a/content/media/video/src/nsMediaDecoder.cpp b/content/media/video/src/nsMediaDecoder.cpp index c8b833acb9c2..7e188e92222c 100644 --- a/content/media/video/src/nsMediaDecoder.cpp +++ b/content/media/video/src/nsMediaDecoder.cpp @@ -51,7 +51,6 @@ #include "gfxImageSurface.h" #include "nsPresContext.h" #include "nsMediaDecoder.h" -#include "nsDOMError.h" #ifdef PR_LOGGING // Logging object for decoder @@ -236,7 +235,3 @@ void nsMediaDecoder::ElementUnavailable() mElement = nsnull; } -nsHTMLMediaElement* nsMediaDecoder::GetMediaElement() -{ - return mElement; -} diff --git a/content/media/video/src/nsMediaStream.cpp b/content/media/video/src/nsMediaStream.cpp index 8edb016f26b9..593cc3ce9618 100644 --- a/content/media/video/src/nsMediaStream.cpp +++ b/content/media/video/src/nsMediaStream.cpp @@ -51,9 +51,6 @@ #include "nsIStreamListener.h" #include "nsIScriptSecurityManager.h" #include "nsChannelToPipeListener.h" -#include "nsCrossSiteListenerProxy.h" -#include "nsHTMLMediaElement.h" -#include "nsIDocument.h" // For HTTP seeking, if number of bytes needing to be // seeked forward is less than this value then a read is @@ -109,36 +106,11 @@ nsresult nsDefaultStreamStrategy::Open(nsIStreamListener** aStreamListener) nsresult rv = mListener->Init(); NS_ENSURE_SUCCESS(rv, rv); - nsCOMPtr listener = do_QueryInterface(mListener); - if (aStreamListener) { *aStreamListener = mListener; NS_ADDREF(mListener); } else { - // Ensure that if we're loading cross domain, that the server is sending - // an authorizing Access-Control header. - nsHTMLMediaElement* element = mDecoder->GetMediaElement(); - NS_ENSURE_TRUE(element, NS_ERROR_FAILURE); - nsIPrincipal* elementPrincipal = element->NodePrincipal(); - NS_ENSURE_TRUE(elementPrincipal, NS_ERROR_FAILURE); - if (element->ShouldCheckAllowOrigin()) { - listener = new nsCrossSiteListenerProxy(mListener, - elementPrincipal, - mChannel, - PR_FALSE, - &rv); - NS_ENSURE_TRUE(listener, NS_ERROR_OUT_OF_MEMORY); - NS_ENSURE_SUCCESS(rv, rv); - } else { - // Ensure that we never load a local file from some page on a - // web server. - rv = nsContentUtils::GetSecurityManager()-> - CheckLoadURIWithPrincipal(elementPrincipal, - mURI, - nsIScriptSecurityManager::STANDARD); - NS_ENSURE_SUCCESS(rv, rv); - } - rv = mChannel->AsyncOpen(listener, nsnull); + rv = mChannel->AsyncOpen(mListener, nsnull); NS_ENSURE_SUCCESS(rv, rv); } @@ -280,24 +252,6 @@ nsresult nsFileStreamStrategy::Open(nsIStreamListener** aStreamListener) rv = NS_NewLocalFileInputStream(getter_AddRefs(mInput), file); } else { - // Ensure that we never load a local file from some page on a - // web server. - nsHTMLMediaElement* element = mDecoder->GetMediaElement(); - NS_ENSURE_TRUE(element, NS_ERROR_FAILURE); - - nsCOMPtr uri; - rv = mChannel->GetURI(getter_AddRefs(uri)); - NS_ENSURE_SUCCESS(rv, rv); - - nsIPrincipal* elementPrincipal = element->NodePrincipal(); - NS_ENSURE_TRUE(elementPrincipal, NS_ERROR_FAILURE); - - rv = nsContentUtils::GetSecurityManager()-> - CheckLoadURIWithPrincipal(elementPrincipal, - mURI, - nsIScriptSecurityManager::STANDARD); - NS_ENSURE_SUCCESS(rv, rv); - rv = mChannel->Open(getter_AddRefs(mInput)); } NS_ENSURE_SUCCESS(rv, rv); @@ -408,7 +362,7 @@ public: } // These methods have the same thread calling requirements - // as those with the same name in nsMediaStream. + // as those with the same name in nsMediaStream virtual nsresult Open(nsIStreamListener** aListener); virtual nsresult Close(); virtual nsresult Read(char* aBuffer, PRUint32 aCount, PRUint32* aBytes); @@ -422,14 +376,13 @@ public: // Return PR_TRUE if the stream has been cancelled. PRBool IsCancelled() const; - // This must be called on the main thread only, and at a time when the - // strategy is not reading from the current channel/stream. It's primary - // purpose is to be called from a Seek to reset to the new byte range - // request HTTP channel. - nsresult OpenInternal(nsIChannel* aChannel, PRInt64 aOffset); - - // Opens the HTTP channel, using a byte range request to start at aOffset. - nsresult OpenInternal(nsIStreamListener **aStreamListener, PRInt64 aOffset); + // This must be called on the main thread only, and at a + // time when the strategy is not reading from the current + // channel/stream. It's primary purpose is to be called from + // a Seek to reset to the new byte range request http channel. + void Reset(nsIChannel* aChannel, + nsChannelToPipeListener* aListener, + nsIInputStream* aStream); private: // Listener attached to channel to constantly download the @@ -459,25 +412,18 @@ private: PRPackedBool mCancelled; }; +void nsHttpStreamStrategy::Reset(nsIChannel* aChannel, + nsChannelToPipeListener* aListener, + nsIInputStream* aStream) +{ + nsAutoLock lock(mLock); + mChannel = aChannel; + mListener = aListener; + mPipeInput = aStream; +} + nsresult nsHttpStreamStrategy::Open(nsIStreamListener **aStreamListener) { - return OpenInternal(aStreamListener, 0); -} - -nsresult nsHttpStreamStrategy::OpenInternal(nsIChannel* aChannel, - PRInt64 aOffset) -{ - nsAutoLock lock(mLock); - mChannel = aChannel; - return OpenInternal(static_cast(nsnull), aOffset); -} - -nsresult nsHttpStreamStrategy::OpenInternal(nsIStreamListener **aStreamListener, - PRInt64 aOffset) -{ - NS_ASSERTION(NS_IsMainThread(), "Only call on main thread"); - NS_ENSURE_TRUE(mChannel, NS_ERROR_NULL_POINTER); - if (aStreamListener) { *aStreamListener = nsnull; } @@ -488,61 +434,34 @@ nsresult nsHttpStreamStrategy::OpenInternal(nsIStreamListener **aStreamListener, nsresult rv = mListener->Init(); NS_ENSURE_SUCCESS(rv, rv); - nsCOMPtr listener = do_QueryInterface(mListener); - if (aStreamListener) { *aStreamListener = mListener; NS_ADDREF(*aStreamListener); } else { - // Ensure that if we're loading cross domain, that the server is sending - // an authorizing Access-Control header. - nsHTMLMediaElement* element = mDecoder->GetMediaElement(); - NS_ENSURE_TRUE(element, NS_ERROR_FAILURE); - nsIPrincipal* elementPrincipal = element->NodePrincipal(); - NS_ENSURE_TRUE(elementPrincipal, NS_ERROR_FAILURE); - if (element->ShouldCheckAllowOrigin()) { - listener = new nsCrossSiteListenerProxy(mListener, - elementPrincipal, - mChannel, - PR_FALSE, - &rv); - NS_ENSURE_TRUE(listener, NS_ERROR_OUT_OF_MEMORY); - NS_ENSURE_SUCCESS(rv, rv); - } else { - rv = nsContentUtils::GetSecurityManager()-> - CheckLoadURIWithPrincipal(elementPrincipal, - mURI, - nsIScriptSecurityManager::STANDARD); - NS_ENSURE_SUCCESS(rv, rv); - - } // 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. nsCOMPtr hc = do_QueryInterface(mChannel); if (hc) { - nsCAutoString rangeString("bytes="); - rangeString.AppendInt(aOffset); - rangeString.Append("-"); - hc->SetRequestHeader(NS_LITERAL_CSTRING("Range"), rangeString, PR_FALSE); + hc->SetRequestHeader(NS_LITERAL_CSTRING("Range"), + NS_LITERAL_CSTRING("bytes=0-"), + PR_FALSE); } - rv = mChannel->AsyncOpen(listener, nsnull); + rv = mChannel->AsyncOpen(mListener, nsnull); NS_ENSURE_SUCCESS(rv, rv); } rv = mListener->GetInputStream(getter_AddRefs(mPipeInput)); NS_ENSURE_SUCCESS(rv, rv); - mPosition = aOffset; + mPosition = 0; return NS_OK; } - nsresult nsHttpStreamStrategy::Close() { - NS_ASSERTION(NS_IsMainThread(), "Only call on main thread"); nsAutoLock lock(mLock); if (mChannel) { mChannel->Cancel(NS_BINDING_ABORTED); @@ -579,9 +498,11 @@ class nsByteRangeEvent : public nsRunnable { public: nsByteRangeEvent(nsHttpStreamStrategy* aStrategy, + nsMediaDecoder* aDecoder, nsIURI* aURI, PRInt64 aOffset) : mStrategy(aStrategy), + mDecoder(aDecoder), mURI(aURI), mOffset(aOffset), mResult(NS_OK) @@ -611,16 +532,35 @@ public: return NS_OK; } - nsCOMPtr channel; mStrategy->Close(); - mResult = NS_NewChannel(getter_AddRefs(channel), + mResult = NS_NewChannel(getter_AddRefs(mChannel), mURI, nsnull, nsnull, nsnull, nsIRequest::LOAD_NORMAL); NS_ENSURE_SUCCESS(mResult, mResult); - mResult = mStrategy->OpenInternal(channel, mOffset); + nsCOMPtr hc = do_QueryInterface(mChannel); + if (hc) { + nsCAutoString rangeString("bytes="); + rangeString.AppendInt(mOffset); + rangeString.Append("-"); + hc->SetRequestHeader(NS_LITERAL_CSTRING("Range"), rangeString, PR_FALSE); + } + + mListener = new nsChannelToPipeListener(mDecoder, PR_TRUE); + NS_ENSURE_TRUE(mListener, NS_ERROR_OUT_OF_MEMORY); + + mResult = mListener->Init(); + NS_ENSURE_SUCCESS(mResult, mResult); + + mResult = mChannel->AsyncOpen(mListener, nsnull); + NS_ENSURE_SUCCESS(mResult, mResult); + + mResult = mListener->GetInputStream(getter_AddRefs(mStream)); + NS_ENSURE_SUCCESS(mResult, mResult); + + mStrategy->Reset(mChannel, mListener, mStream); return NS_OK; } @@ -725,7 +665,7 @@ nsresult nsHttpStreamStrategy::Seek(PRInt32 aWhence, PRInt64 aOffset) // Don't acquire mLock in this scope as we do a synchronous call to the main thread // which would deadlock if that thread is calling Close(). - nsCOMPtr event = new nsByteRangeEvent(this, mURI, aOffset); + nsCOMPtr event = new nsByteRangeEvent(this, mDecoder, mURI, aOffset); NS_DispatchToMainThread(event, NS_DISPATCH_SYNC); // If the sync request fails, or a call to Cancel() is made during the request, diff --git a/content/media/video/src/nsOggDecoder.cpp b/content/media/video/src/nsOggDecoder.cpp index 62a273e93be4..383cdcf0ff36 100644 --- a/content/media/video/src/nsOggDecoder.cpp +++ b/content/media/video/src/nsOggDecoder.cpp @@ -1212,6 +1212,7 @@ private: nsRefPtr mDecoder; }; + void nsOggDecoder::Shutdown() { ChangeState(PLAY_STATE_SHUTDOWN); diff --git a/content/media/video/test/320x240.allow-origin.ogg b/content/media/video/test/320x240.allow-origin.ogg deleted file mode 100644 index 093158432ac6..000000000000 Binary files a/content/media/video/test/320x240.allow-origin.ogg and /dev/null differ diff --git a/content/media/video/test/320x240.allow-origin.ogg^headers^ b/content/media/video/test/320x240.allow-origin.ogg^headers^ deleted file mode 100644 index cb762eff8068..000000000000 --- a/content/media/video/test/320x240.allow-origin.ogg^headers^ +++ /dev/null @@ -1 +0,0 @@ -Access-Control-Allow-Origin: * diff --git a/content/media/video/test/Makefile.in b/content/media/video/test/Makefile.in index e7d113f3d9fa..483a183e081c 100644 --- a/content/media/video/test/Makefile.in +++ b/content/media/video/test/Makefile.in @@ -43,9 +43,7 @@ relativesrcdir = content/media/video/test include $(DEPTH)/config/autoconf.mk include $(topsrcdir)/config/rules.mk -_TEST_FILES = test_access_control.html \ - file_access_controls.html \ - test_autoplay.html \ +_TEST_FILES = test_autoplay.html \ test_bug461281.html \ test_constants.html \ test_controls.html \ @@ -72,13 +70,10 @@ _TEST_FILES = test_access_control.html \ test_wav_8bit.html \ test_wav_ended1.html \ 320x240.ogg \ - 320x240.allow-origin.ogg \ - 320x240.allow-origin.ogg^headers^ \ bug461281.ogg \ seek.ogg \ r11025_s16_c1.wav \ r11025_u8_c1.wav \ - redirect.sjs \ # test_bug448534.html \ $(NULL) diff --git a/content/media/video/test/file_access_controls.html b/content/media/video/test/file_access_controls.html deleted file mode 100644 index ef32489e395e..000000000000 --- a/content/media/video/test/file_access_controls.html +++ /dev/null @@ -1,134 +0,0 @@ - - - - - - - - - - - - - diff --git a/content/media/video/test/redirect.sjs b/content/media/video/test/redirect.sjs deleted file mode 100644 index da419fc2fae4..000000000000 --- a/content/media/video/test/redirect.sjs +++ /dev/null @@ -1,5 +0,0 @@ -function handleRequest(request, response) -{ - response.setStatusLine(request.httpVersion, 301, "Moved Permanently"); - response.setHeader("Location", request.queryString, false); -} diff --git a/content/media/video/test/test_access_control.html b/content/media/video/test/test_access_control.html deleted file mode 100644 index a39a3f22820f..000000000000 --- a/content/media/video/test/test_access_control.html +++ /dev/null @@ -1,36 +0,0 @@ - - - - - Test for Bug 451958 - - - - - -Mozilla Bug 451958 -

- -
-
-
- - diff --git a/modules/libpref/src/init/all.js b/modules/libpref/src/init/all.js index 7b9e75184edd..12dd37c161d4 100644 --- a/modules/libpref/src/init/all.js +++ b/modules/libpref/src/init/all.js @@ -131,10 +131,6 @@ pref("browser.chrome.image_icons.max_size", 1024); pref("browser.triple_click_selects_paragraph", true); -// When loading