diff options
author | acolwell@chromium.org <acolwell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-25 17:45:34 +0000 |
---|---|---|
committer | acolwell@chromium.org <acolwell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-25 17:45:34 +0000 |
commit | 21953d048622b80c20dc35e850087bf097098949 (patch) | |
tree | c3116dc1230bda941c52818cdc8f5ff464a8e25f /webkit/glue/media | |
parent | 80d560d2c50848be0100db7ce00fedac298a3187 (diff) | |
download | chromium_src-21953d048622b80c20dc35e850087bf097098949.zip chromium_src-21953d048622b80c20dc35e850087bf097098949.tar.gz chromium_src-21953d048622b80c20dc35e850087bf097098949.tar.bz2 |
Make playback fail if redirected to a different origin.
Fixing spec compliance.
http://dev.w3.org/html5/spec/Overview.html#concept-media-load-resource
BUG=72578
TEST=BufferedResourceLoaderTest.HasSingleOrigin(), SimpleDataSourceTest.HasSingleOrigin()
Review URL: http://codereview.chromium.org/6580014
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@76064 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue/media')
-rw-r--r-- | webkit/glue/media/buffered_resource_loader.cc | 15 | ||||
-rw-r--r-- | webkit/glue/media/buffered_resource_loader_unittest.cc | 19 | ||||
-rw-r--r-- | webkit/glue/media/simple_data_source.cc | 10 | ||||
-rw-r--r-- | webkit/glue/media/simple_data_source_unittest.cc | 18 |
4 files changed, 27 insertions, 35 deletions
diff --git a/webkit/glue/media/buffered_resource_loader.cc b/webkit/glue/media/buffered_resource_loader.cc index a86d2dd..e7354f6 100644 --- a/webkit/glue/media/buffered_resource_loader.cc +++ b/webkit/glue/media/buffered_resource_loader.cc @@ -248,18 +248,21 @@ void BufferedResourceLoader::willSendRequest( return; } - if (!IsProtocolSupportedForMedia(newRequest.url())) { + // Only allow |single_origin_| if we haven't seen a different origin yet. + if (single_origin_) + single_origin_ = url_.GetOrigin() == GURL(newRequest.url()).GetOrigin(); + + // Enforce same-origin policy and cause redirects to other origins to + // look like network errors. + // http://dev.w3.org/html5/spec/Overview.html#concept-media-load-resource + // http://dev.w3.org/html5/spec/Overview.html#fetch + if (!single_origin_ || !IsProtocolSupportedForMedia(newRequest.url())) { // Set the url in the request to an invalid value (empty url). newRequest.setURL(WebKit::WebURL()); DoneStart(net::ERR_ADDRESS_INVALID); - Stop(); return; } - // Only allow |single_origin_| if we haven't seen a different origin yet. - if (single_origin_) - single_origin_ = url_.GetOrigin() == GURL(newRequest.url()).GetOrigin(); - url_ = newRequest.url(); } diff --git a/webkit/glue/media/buffered_resource_loader_unittest.cc b/webkit/glue/media/buffered_resource_loader_unittest.cc index dc67edf..158b6dc3 100644 --- a/webkit/glue/media/buffered_resource_loader_unittest.cc +++ b/webkit/glue/media/buffered_resource_loader_unittest.cc @@ -526,28 +526,17 @@ TEST_F(BufferedResourceLoaderTest, HasSingleOrigin) { // Test redirect to a different domain. Initialize(kHttpUrl, -1, -1); Start(); + EXPECT_CALL(*this, StartCallback(net::ERR_ADDRESS_INVALID)); Redirect(kHttpRedirectToDifferentDomainUrl1); - FullResponse(1024); EXPECT_FALSE(loader_->HasSingleOrigin()); StopWhenLoad(); - // Test redirect twice to a different domain. + // Test redirect to the same domain and then to a different domain. Initialize(kHttpUrl, -1, -1); Start(); - Redirect(kHttpRedirectToDifferentDomainUrl1); - Redirect(kHttpRedirectToDifferentDomainUrl2); - FullResponse(1024); - EXPECT_FALSE(loader_->HasSingleOrigin()); - StopWhenLoad(); - - // Test to a different domain and then back to the same domain. - // NOTE: A different origin was encountered at least once so that - // makes HasSingleOrigin() become false. - Initialize(kHttpUrl, -1, -1); - Start(); - Redirect(kHttpRedirectToDifferentDomainUrl1); Redirect(kHttpRedirectToSameDomainUrl1); - FullResponse(1024); + EXPECT_CALL(*this, StartCallback(net::ERR_ADDRESS_INVALID)); + Redirect(kHttpRedirectToDifferentDomainUrl1); EXPECT_FALSE(loader_->HasSingleOrigin()); StopWhenLoad(); } diff --git a/webkit/glue/media/simple_data_source.cc b/webkit/glue/media/simple_data_source.cc index 07f75878..fee89fe 100644 --- a/webkit/glue/media/simple_data_source.cc +++ b/webkit/glue/media/simple_data_source.cc @@ -113,11 +113,21 @@ void SimpleDataSource::willSendRequest( WebKit::WebURLRequest& newRequest, const WebKit::WebURLResponse& redirectResponse) { DCHECK(MessageLoop::current() == render_loop_); + base::AutoLock auto_lock(lock_); // Only allow |single_origin_| if we haven't seen a different origin yet. if (single_origin_) single_origin_ = url_.GetOrigin() == GURL(newRequest.url()).GetOrigin(); + // Enforce same-origin policy and cause redirects to other origins to + // look like network errors. + // http://dev.w3.org/html5/spec/Overview.html#concept-media-load-resource + // http://dev.w3.org/html5/spec/Overview.html#fetch + if (!single_origin_) { + DoneInitialization_Locked(false); + return; + } + url_ = newRequest.url(); } diff --git a/webkit/glue/media/simple_data_source_unittest.cc b/webkit/glue/media/simple_data_source_unittest.cc index a9a70a4..125fd33 100644 --- a/webkit/glue/media/simple_data_source_unittest.cc +++ b/webkit/glue/media/simple_data_source_unittest.cc @@ -254,26 +254,16 @@ TEST_F(SimpleDataSourceTest, HasSingleOrigin) { // Test redirect to a different domain. InitializeDataSource(kHttpUrl, media::NewExpectedCallback()); + EXPECT_CALL(host_, SetError(media::PIPELINE_ERROR_NETWORK)); Redirect(kHttpRedirectToDifferentDomainUrl1); - RequestSucceeded(false); - EXPECT_FALSE(data_source_->HasSingleOrigin()); - DestroyDataSource(); - - // Test redirect twice to a different domain. - InitializeDataSource(kHttpUrl, media::NewExpectedCallback()); - Redirect(kHttpRedirectToDifferentDomainUrl1); - Redirect(kHttpRedirectToDifferentDomainUrl2); - RequestSucceeded(false); EXPECT_FALSE(data_source_->HasSingleOrigin()); DestroyDataSource(); - // Test to a different domain and then back to the same domain. - // NOTE: A different origin was encountered at least once so that - // makes HasSingleOrigin() become false. + // Test redirect to the same domain and then to a different domain. InitializeDataSource(kHttpUrl, media::NewExpectedCallback()); - Redirect(kHttpRedirectToDifferentDomainUrl1); Redirect(kHttpRedirectToSameDomainUrl1); - RequestSucceeded(false); + EXPECT_CALL(host_, SetError(media::PIPELINE_ERROR_NETWORK)); + Redirect(kHttpRedirectToDifferentDomainUrl1); EXPECT_FALSE(data_source_->HasSingleOrigin()); DestroyDataSource(); } |