diff options
author | fischman@chromium.org <fischman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-17 00:18:35 +0000 |
---|---|---|
committer | fischman@chromium.org <fischman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-17 00:18:35 +0000 |
commit | 6fa507fa08768cc01533150e04f7f88408cc8cfd (patch) | |
tree | 0ac2794ab302e5a75b684250c3a34b827c46ac83 /webkit/media | |
parent | 790475e4692957fa1164012ed89d3b13a455dc55 (diff) | |
download | chromium_src-6fa507fa08768cc01533150e04f7f88408cc8cfd.zip chromium_src-6fa507fa08768cc01533150e04f7f88408cc8cfd.tar.gz chromium_src-6fa507fa08768cc01533150e04f7f88408cc8cfd.tar.bz2 |
BufferedDataSource wants to know the content length of non-http(s) resources, so we now expose it from WebURLLoaderImpl.
BUG=110805
TEST=media layouttests still pass, esp. the data: ones.
Review URL: http://codereview.chromium.org/9718005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@127309 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/media')
-rw-r--r-- | webkit/media/buffered_data_source.cc | 6 | ||||
-rw-r--r-- | webkit/media/simple_data_source.cc | 319 | ||||
-rw-r--r-- | webkit/media/simple_data_source.h | 141 | ||||
-rw-r--r-- | webkit/media/simple_data_source_unittest.cc | 299 | ||||
-rw-r--r-- | webkit/media/webkit_media.gypi | 2 | ||||
-rw-r--r-- | webkit/media/webmediaplayer_impl.cc | 12 |
6 files changed, 3 insertions, 776 deletions
diff --git a/webkit/media/buffered_data_source.cc b/webkit/media/buffered_data_source.cc index 1f67f5b..1d39684 100644 --- a/webkit/media/buffered_data_source.cc +++ b/webkit/media/buffered_data_source.cc @@ -83,12 +83,6 @@ void BufferedDataSource::Initialize( DCHECK(!loader_.get()); url_ = url; - // This data source doesn't support data:// protocol so reject it. - if (url_.SchemeIs(kDataScheme)) { - initialize_cb.Run(media::DATASOURCE_ERROR_URL_NOT_SUPPORTED); - return; - } - initialize_cb_ = initialize_cb; if (url_.SchemeIs(kHttpScheme) || url_.SchemeIs(kHttpsScheme)) { diff --git a/webkit/media/simple_data_source.cc b/webkit/media/simple_data_source.cc deleted file mode 100644 index 3761148..0000000 --- a/webkit/media/simple_data_source.cc +++ /dev/null @@ -1,319 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "webkit/media/simple_data_source.h" - -#include "base/bind.h" -#include "base/message_loop.h" -#include "base/process_util.h" -#include "media/base/media_log.h" -#include "net/base/data_url.h" -#include "net/base/load_flags.h" -#include "net/http/http_request_headers.h" -#include "net/url_request/url_request_status.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebKitPlatformSupport.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLLoaderOptions.h" - -using WebKit::WebString; -using WebKit::WebURLLoaderOptions; - -namespace webkit_media { - -static const char kDataScheme[] = "data"; - -SimpleDataSource::SimpleDataSource( - MessageLoop* render_loop, - WebKit::WebFrame* frame) - : render_loop_(render_loop), - frame_(frame), - size_(-1), - single_origin_(true), - state_(UNINITIALIZED), - keep_test_loader_(false) { - DCHECK(render_loop); -} - -SimpleDataSource::~SimpleDataSource() { - base::AutoLock auto_lock(lock_); - DCHECK(state_ == UNINITIALIZED || state_ == STOPPED); -} - -void SimpleDataSource::set_host(media::DataSourceHost* host) { - DataSource::set_host(host); - - base::AutoLock auto_lock(lock_); - if (state_ == INITIALIZED) { - UpdateHostState(); - } -} - -void SimpleDataSource::Stop(const base::Closure& callback) { - base::AutoLock auto_lock(lock_); - state_ = STOPPED; - if (!callback.is_null()) - callback.Run(); - - // Post a task to the render thread to cancel loading the resource. - render_loop_->PostTask(FROM_HERE, - base::Bind(&SimpleDataSource::CancelTask, this)); -} - -void SimpleDataSource::Initialize( - const GURL& url, - const media::PipelineStatusCB& status_cb) { - DCHECK(MessageLoop::current() == render_loop_); - DCHECK(!status_cb.is_null()); - - // Reference to prevent destruction while inside the |initialize_cb_| - // call. This is a temporary fix to prevent crashes caused by holding the - // lock and running the destructor. - scoped_refptr<SimpleDataSource> destruction_guard(this); - { - base::AutoLock auto_lock(lock_); - DCHECK_EQ(state_, UNINITIALIZED); - state_ = INITIALIZING; - initialize_cb_ = status_cb; - - // Validate the URL. - url_ = url; - if (!url_.is_valid()) { - DoneInitialization_Locked(false); - return; - } - - // If |url_| contains a data:// scheme we can decode it immediately. - if (url_.SchemeIs(kDataScheme)) { - std::string mime_type, charset; - bool success = net::DataURL::Parse(url_, &mime_type, &charset, &data_); - - // Don't care about the mime-type just proceed if decoding was successful. - size_ = data_.length(); - DoneInitialization_Locked(success); - return; - } - - // For all other schemes issue a request for the full resource. - WebKit::WebURLRequest request(url_); - request.setTargetType(WebKit::WebURLRequest::TargetIsMedia); - - frame_->setReferrerForRequest(request, WebKit::WebURL()); - - // Disable compression, compression for audio/video doesn't make sense. - request.setHTTPHeaderField( - WebString::fromUTF8(net::HttpRequestHeaders::kAcceptEncoding), - WebString::fromUTF8("identity;q=1, *;q=0")); - - // This flag is for unittests as we don't want to reset |url_loader| - if (!keep_test_loader_) { - WebURLLoaderOptions options; - options.allowCredentials = true; - options.crossOriginRequestPolicy = - WebURLLoaderOptions::CrossOriginRequestPolicyAllow; - url_loader_.reset(frame_->createAssociatedURLLoader(options)); - } - - // Start the resource loading. - url_loader_->loadAsynchronously(request, this); - } -} - -void SimpleDataSource::Read(int64 position, - size_t size, - uint8* data, - const DataSource::ReadCB& read_cb) { - DCHECK_GE(size_, 0); - if (position >= size_) { - read_cb.Run(0); - } else { - size_t copied = std::min(size, static_cast<size_t>(size_ - position)); - memcpy(data, data_.c_str() + position, copied); - read_cb.Run(copied); - } -} - -bool SimpleDataSource::GetSize(int64* size_out) { - *size_out = size_; - return true; -} - -bool SimpleDataSource::IsStreaming() { - return false; -} - -void SimpleDataSource::SetPreload(media::Preload preload) { -} - -void SimpleDataSource::SetBitrate(int bitrate) { -} - -void SimpleDataSource::SetURLLoaderForTest(WebKit::WebURLLoader* mock_loader) { - url_loader_.reset(mock_loader); - keep_test_loader_ = true; -} - -void SimpleDataSource::willSendRequest( - WebKit::WebURLLoader* loader, - 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(); - - url_ = newRequest.url(); -} - -void SimpleDataSource::didSendData( - WebKit::WebURLLoader* loader, - unsigned long long bytesSent, - unsigned long long totalBytesToBeSent) { - NOTIMPLEMENTED(); -} - -void SimpleDataSource::didReceiveResponse( - WebKit::WebURLLoader* loader, - const WebKit::WebURLResponse& response) { - DCHECK(MessageLoop::current() == render_loop_); - size_ = response.expectedContentLength(); -} - -void SimpleDataSource::didDownloadData( - WebKit::WebURLLoader* loader, - int dataLength) { - NOTIMPLEMENTED(); -} - -void SimpleDataSource::didReceiveData( - WebKit::WebURLLoader* loader, - const char* data, - int data_length, - int encoded_data_length) { - DCHECK(MessageLoop::current() == render_loop_); - data_.append(data, data_length); -} - -void SimpleDataSource::didReceiveCachedMetadata( - WebKit::WebURLLoader* loader, - const char* data, - int dataLength) { - NOTIMPLEMENTED(); -} - -void SimpleDataSource::didFinishLoading( - WebKit::WebURLLoader* loader, - double finishTime) { - DCHECK(MessageLoop::current() == render_loop_); - // Reference to prevent destruction while inside the |initialize_cb_| - // call. This is a temporary fix to prevent crashes caused by holding the - // lock and running the destructor. - scoped_refptr<SimpleDataSource> destruction_guard(this); - { - base::AutoLock auto_lock(lock_); - // It's possible this gets called after Stop(), in which case |host_| is no - // longer valid. - if (state_ == STOPPED) - return; - - // Otherwise we should be initializing and have created a WebURLLoader. - DCHECK_EQ(state_, INITIALIZING); - - // If we don't get a content length or the request has failed, report it - // as a network error. - if (size_ == -1) - size_ = data_.length(); - DCHECK(static_cast<size_t>(size_) == data_.length()); - - DoneInitialization_Locked(true); - } -} - -void SimpleDataSource::didFail( - WebKit::WebURLLoader* loader, - const WebKit::WebURLError& error) { - DCHECK(MessageLoop::current() == render_loop_); - // Reference to prevent destruction while inside the |initialize_cb_| - // call. This is a temporary fix to prevent crashes caused by holding the - // lock and running the destructor. - scoped_refptr<SimpleDataSource> destruction_guard(this); - { - base::AutoLock auto_lock(lock_); - // It's possible this gets called after Stop(), in which case |host_| is no - // longer valid. - if (state_ == STOPPED) - return; - - // Otherwise we should be initializing and have created a WebURLLoader. - DCHECK_EQ(state_, INITIALIZING); - - // If we don't get a content length or the request has failed, report it - // as a network error. - if (size_ == -1) - size_ = data_.length(); - DCHECK(static_cast<size_t>(size_) == data_.length()); - - DoneInitialization_Locked(false); - } -} - -bool SimpleDataSource::HasSingleOrigin() { - DCHECK(MessageLoop::current() == render_loop_); - return single_origin_; -} - -void SimpleDataSource::Abort() { - DCHECK(MessageLoop::current() == render_loop_); - base::AutoLock auto_lock(lock_); - state_ = STOPPED; - initialize_cb_.Reset(); - CancelTask_Locked(); - frame_ = NULL; -} - -void SimpleDataSource::CancelTask() { - DCHECK(MessageLoop::current() == render_loop_); - base::AutoLock auto_lock(lock_); - CancelTask_Locked(); -} - -void SimpleDataSource::CancelTask_Locked() { - DCHECK(MessageLoop::current() == render_loop_); - lock_.AssertAcquired(); - DCHECK_EQ(state_, STOPPED); - - // Cancel any pending requests. - if (url_loader_.get()) { - url_loader_->cancel(); - url_loader_.reset(); - } -} - -void SimpleDataSource::DoneInitialization_Locked(bool success) { - lock_.AssertAcquired(); - media::PipelineStatus status = media::PIPELINE_ERROR_NETWORK; - if (success) { - state_ = INITIALIZED; - - UpdateHostState(); - status = media::PIPELINE_OK; - } else { - state_ = UNINITIALIZED; - url_loader_.reset(); - } - - initialize_cb_.Run(status); - initialize_cb_.Reset(); -} - -void SimpleDataSource::UpdateHostState() { - if (host()) { - host()->SetTotalBytes(size_); - host()->SetBufferedBytes(size_); - } -} - -} // namespace webkit_media diff --git a/webkit/media/simple_data_source.h b/webkit/media/simple_data_source.h deleted file mode 100644 index b8ca0d4..0000000 --- a/webkit/media/simple_data_source.h +++ /dev/null @@ -1,141 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// An extremely simple implementation of DataSource that downloads the entire -// media resource into memory before signaling that initialization has finished. -// Primarily used to test <audio> and <video> with buffering/caching removed -// from the equation. - -#ifndef WEBKIT_MEDIA_SIMPLE_DATA_SOURCE_H_ -#define WEBKIT_MEDIA_SIMPLE_DATA_SOURCE_H_ - -#include <algorithm> -#include <string> - -#include "base/memory/scoped_ptr.h" -#include "base/message_loop.h" -#include "googleurl/src/gurl.h" -#include "media/base/data_source.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLLoader.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLLoaderClient.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLRequest.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLResponse.h" -#include "webkit/media/web_data_source.h" - -class MessageLoop; - -namespace media { -class MediaLog; -} - -namespace webkit_media { - -class SimpleDataSource - : public WebDataSource, - public WebKit::WebURLLoaderClient { - public: - SimpleDataSource(MessageLoop* render_loop, WebKit::WebFrame* frame); - virtual ~SimpleDataSource(); - - // media::DataSource implementation. - virtual void set_host(media::DataSourceHost* host) OVERRIDE; - virtual void Stop(const base::Closure& callback) OVERRIDE; - virtual void Read(int64 position, - size_t size, - uint8* data, - const DataSource::ReadCB& read_cb) OVERRIDE; - virtual bool GetSize(int64* size_out) OVERRIDE; - virtual bool IsStreaming() OVERRIDE; - virtual void SetPreload(media::Preload preload) OVERRIDE; - virtual void SetBitrate(int bitrate) OVERRIDE; - - // Used to inject a mock used for unittests. - virtual void SetURLLoaderForTest(WebKit::WebURLLoader* mock_loader); - - // WebKit::WebURLLoaderClient implementations. - virtual void willSendRequest( - WebKit::WebURLLoader* loader, - WebKit::WebURLRequest& newRequest, - const WebKit::WebURLResponse& redirectResponse); - virtual void didSendData( - WebKit::WebURLLoader* loader, - unsigned long long bytesSent, - unsigned long long totalBytesToBeSent); - virtual void didReceiveResponse( - WebKit::WebURLLoader* loader, - const WebKit::WebURLResponse& response); - virtual void didDownloadData( - WebKit::WebURLLoader* loader, - int dataLength); - virtual void didReceiveData( - WebKit::WebURLLoader* loader, - const char* data, - int dataLength, - int encodedDataLength); - virtual void didReceiveCachedMetadata( - WebKit::WebURLLoader* loader, - const char* data, int dataLength); - virtual void didFinishLoading( - WebKit::WebURLLoader* loader, - double finishTime); - virtual void didFail( - WebKit::WebURLLoader* loader, - const WebKit::WebURLError&); - - // webkit_glue::WebDataSource implementation. - virtual void Initialize(const GURL& url, - const media::PipelineStatusCB& status_cb) OVERRIDE; - virtual bool HasSingleOrigin() OVERRIDE; - virtual void Abort() OVERRIDE; - - private: - // Cancels and deletes the resource loading on the render thread. - void CancelTask(); - void CancelTask_Locked(); - - // Perform initialization completion tasks under a lock. - void DoneInitialization_Locked(bool success); - - // Update host() stats like total bytes & buffered bytes. - void UpdateHostState(); - - // Primarily used for asserting the bridge is loading on the render thread. - MessageLoop* render_loop_; - - // A webframe for loading. - WebKit::WebFrame* frame_; - - // Does the work of loading and sends data back to this client. - scoped_ptr<WebKit::WebURLLoader> url_loader_; - - GURL url_; - std::string data_; - int64 size_; - bool single_origin_; - - // Simple state tracking variable. - enum State { - UNINITIALIZED, - INITIALIZING, - INITIALIZED, - STOPPED, - }; - State state_; - - // Used for accessing |state_|. - base::Lock lock_; - - // Filter callbacks. - media::PipelineStatusCB initialize_cb_; - - // Used to ensure mocks for unittests are used instead of reset in Start(). - bool keep_test_loader_; - - DISALLOW_COPY_AND_ASSIGN(SimpleDataSource); -}; - -} // namespace webkit_media - -#endif // WEBKIT_MEDIA_SIMPLE_DATA_SOURCE_H_ diff --git a/webkit/media/simple_data_source_unittest.cc b/webkit/media/simple_data_source_unittest.cc deleted file mode 100644 index 5d00f13..0000000 --- a/webkit/media/simple_data_source_unittest.cc +++ /dev/null @@ -1,299 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "base/bind.h" -#include "media/base/filters.h" -#include "media/base/mock_callback.h" -#include "media/base/mock_data_source_host.h" -#include "media/base/mock_filters.h" -#include "net/base/net_errors.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLError.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLLoader.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLRequest.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLResponse.h" -#include "webkit/media/simple_data_source.h" -#include "webkit/mocks/mock_webframeclient.h" -#include "webkit/mocks/mock_weburlloader.h" - -using ::testing::_; -using ::testing::DoAll; -using ::testing::InSequence; -using ::testing::Invoke; -using ::testing::NiceMock; -using ::testing::NotNull; -using ::testing::Return; -using ::testing::SetArgumentPointee; -using ::testing::StrictMock; -using ::testing::WithArgs; - -using WebKit::WebURLError; -using WebKit::WebURLLoader; -using WebKit::WebURLRequest; -using WebKit::WebURLResponse; -using WebKit::WebView; - -using webkit_glue::MockWebFrameClient; -using webkit_glue::MockWebURLLoader; - -namespace webkit_media { - -static const int kDataSize = 1024; -static const char kHttpUrl[] = "http://test"; -static const char kHttpsUrl[] = "https://test"; -static const char kFileUrl[] = "file://test"; -static const char kDataUrl[] = - "data:text/plain;base64,YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXoK"; -static const char kDataUrlDecoded[] = "abcdefghijklmnopqrstuvwxyz"; -static const char kInvalidUrl[] = "whatever://test"; -static const char kHttpRedirectToSameDomainUrl1[] = "http://test/ing"; -static const char kHttpRedirectToSameDomainUrl2[] = "http://test/ing2"; -static const char kHttpRedirectToDifferentDomainUrl1[] = "http://test2"; -static const char kHttpRedirectToDifferentDomainUrl2[] = "http://test2/ing"; - -class SimpleDataSourceTest : public testing::Test { - public: - SimpleDataSourceTest() - : view_(WebView::create(NULL)) { - view_->initializeMainFrame(&client_); - - for (int i = 0; i < kDataSize; ++i) { - data_[i] = i; - } - } - - virtual ~SimpleDataSourceTest() { - view_->close(); - } - - void InitializeDataSource(const char* url, - const media::PipelineStatusCB& status_cb) { - gurl_ = GURL(url); - - url_loader_ = new NiceMock<MockWebURLLoader>(); - - data_source_ = new SimpleDataSource(MessageLoop::current(), - view_->mainFrame()); - - // There is no need to provide a message loop to data source. - data_source_->set_host(&host_); - data_source_->SetURLLoaderForTest(url_loader_); - - data_source_->Initialize(gurl_, status_cb); - MessageLoop::current()->RunAllPending(); - } - - void RequestSucceeded() { - WebURLResponse response(gurl_); - response.setExpectedContentLength(kDataSize); - - data_source_->didReceiveResponse(NULL, response); - int64 size; - EXPECT_TRUE(data_source_->GetSize(&size)); - EXPECT_EQ(kDataSize, size); - - for (int i = 0; i < kDataSize; ++i) - data_source_->didReceiveData(NULL, data_ + i, 1, 1); - - InSequence s; - EXPECT_CALL(host_, SetTotalBytes(kDataSize)); - EXPECT_CALL(host_, SetBufferedBytes(kDataSize)); - - data_source_->didFinishLoading(NULL, 0); - - // Let the tasks to be executed. - MessageLoop::current()->RunAllPending(); - } - - void RequestFailed() { - InSequence s; - - WebURLError error; - error.reason = net::ERR_FAILED; - data_source_->didFail(NULL, error); - - // Let the tasks to be executed. - MessageLoop::current()->RunAllPending(); - } - - void Redirect(const char* url) { - GURL redirectUrl(url); - WebURLRequest newRequest(redirectUrl); - WebURLResponse redirectResponse(gurl_); - - data_source_->willSendRequest(url_loader_, newRequest, redirectResponse); - - MessageLoop::current()->RunAllPending(); - } - - void StopAndDestroyDataSource() { - data_source_->Stop(media::NewExpectedClosure()); - MessageLoop::current()->RunAllPending(); - data_source_ = NULL; - } - - void AbortAndDestroyDataSource() { - data_source_->Abort(); - MessageLoop::current()->RunAllPending(); - data_source_ = NULL; - } - - void AsyncRead() { - for (int i = 0; i < kDataSize; ++i) { - uint8 buffer[1]; - - EXPECT_CALL(*this, ReadCallback(1)); - data_source_->Read( - i, 1, buffer, - base::Bind(&SimpleDataSourceTest::ReadCallback, - base::Unretained(this))); - EXPECT_EQ(static_cast<uint8>(data_[i]), buffer[0]); - } - } - - MOCK_METHOD1(ReadCallback, void(size_t size)); - - protected: - GURL gurl_; - scoped_ptr<MessageLoop> message_loop_; - NiceMock<MockWebURLLoader>* url_loader_; - scoped_refptr<SimpleDataSource> data_source_; - StrictMock<media::MockDataSourceHost> host_; - - MockWebFrameClient client_; - WebView* view_; - - char data_[kDataSize]; - - DISALLOW_COPY_AND_ASSIGN(SimpleDataSourceTest); -}; - -TEST_F(SimpleDataSourceTest, InitializeHTTP) { - InitializeDataSource(kHttpUrl, - media::NewExpectedStatusCB(media::PIPELINE_OK)); - RequestSucceeded(); - StopAndDestroyDataSource(); -} - -TEST_F(SimpleDataSourceTest, InitializeHTTPS) { - InitializeDataSource(kHttpsUrl, - media::NewExpectedStatusCB(media::PIPELINE_OK)); - RequestSucceeded(); - StopAndDestroyDataSource(); -} - -TEST_F(SimpleDataSourceTest, InitializeFile) { - InitializeDataSource(kFileUrl, - media::NewExpectedStatusCB(media::PIPELINE_OK)); - RequestSucceeded(); - StopAndDestroyDataSource(); -} - -TEST_F(SimpleDataSourceTest, InitializeData) { - url_loader_ = new NiceMock<MockWebURLLoader>(); - - data_source_ = new SimpleDataSource(MessageLoop::current(), - view_->mainFrame()); - // There is no need to provide a message loop to data source. - data_source_->set_host(&host_); - data_source_->SetURLLoaderForTest(url_loader_); - - EXPECT_CALL(host_, SetTotalBytes(sizeof(kDataUrlDecoded))); - EXPECT_CALL(host_, SetBufferedBytes(sizeof(kDataUrlDecoded))); - - data_source_->Initialize(GURL(kDataUrl), - media::NewExpectedStatusCB(media::PIPELINE_OK)); - MessageLoop::current()->RunAllPending(); - - StopAndDestroyDataSource(); -} - -TEST_F(SimpleDataSourceTest, RequestFailed) { - InitializeDataSource(kHttpUrl, - media::NewExpectedStatusCB(media::PIPELINE_ERROR_NETWORK)); - RequestFailed(); - StopAndDestroyDataSource(); -} - -static void OnStatusCB(bool* called, media::PipelineStatus status) { - *called = true; -} - -TEST_F(SimpleDataSourceTest, StopWhenDownloading) { - // The callback should be deleted, but not executed. - // TODO(scherkus): should this really be the behaviour? Seems strange... - bool was_called = false; - InitializeDataSource(kHttpUrl, base::Bind(&OnStatusCB, &was_called)); - - EXPECT_CALL(*url_loader_, cancel()); - StopAndDestroyDataSource(); - EXPECT_FALSE(was_called); -} - -TEST_F(SimpleDataSourceTest, AbortWhenDownloading) { - // The callback should be deleted, but not executed. - // TODO(scherkus): should this really be the behaviour? Seems strange... - bool was_called = false; - InitializeDataSource(kHttpUrl, base::Bind(&OnStatusCB, &was_called)); - - EXPECT_CALL(*url_loader_, cancel()); - AbortAndDestroyDataSource(); - EXPECT_FALSE(was_called); -} - -TEST_F(SimpleDataSourceTest, AsyncRead) { - InitializeDataSource(kFileUrl, - media::NewExpectedStatusCB(media::PIPELINE_OK)); - RequestSucceeded(); - AsyncRead(); - StopAndDestroyDataSource(); -} - -// NOTE: This test will need to be reworked a little once -// http://code.google.com/p/chromium/issues/detail?id=72578 -// is fixed. -TEST_F(SimpleDataSourceTest, HasSingleOrigin) { - // Make sure no redirect case works as expected. - InitializeDataSource(kHttpUrl, - media::NewExpectedStatusCB(media::PIPELINE_OK)); - RequestSucceeded(); - EXPECT_TRUE(data_source_->HasSingleOrigin()); - StopAndDestroyDataSource(); - - // Test redirect to the same domain. - InitializeDataSource(kHttpUrl, - media::NewExpectedStatusCB(media::PIPELINE_OK)); - Redirect(kHttpRedirectToSameDomainUrl1); - RequestSucceeded(); - EXPECT_TRUE(data_source_->HasSingleOrigin()); - StopAndDestroyDataSource(); - - // Test redirect twice to the same domain. - InitializeDataSource(kHttpUrl, - media::NewExpectedStatusCB(media::PIPELINE_OK)); - Redirect(kHttpRedirectToSameDomainUrl1); - Redirect(kHttpRedirectToSameDomainUrl2); - RequestSucceeded(); - EXPECT_TRUE(data_source_->HasSingleOrigin()); - StopAndDestroyDataSource(); - - // Test redirect to a different domain. - InitializeDataSource(kHttpUrl, - media::NewExpectedStatusCB(media::PIPELINE_OK)); - Redirect(kHttpRedirectToDifferentDomainUrl1); - RequestSucceeded(); - EXPECT_FALSE(data_source_->HasSingleOrigin()); - StopAndDestroyDataSource(); - - // Test redirect to the same domain and then to a different domain. - InitializeDataSource(kHttpUrl, - media::NewExpectedStatusCB(media::PIPELINE_OK)); - Redirect(kHttpRedirectToSameDomainUrl1); - Redirect(kHttpRedirectToDifferentDomainUrl1); - RequestSucceeded(); - EXPECT_FALSE(data_source_->HasSingleOrigin()); - StopAndDestroyDataSource(); -} - -} // namespace webkit_media diff --git a/webkit/media/webkit_media.gypi b/webkit/media/webkit_media.gypi index 3f567be..cdab6f8 100644 --- a/webkit/media/webkit_media.gypi +++ b/webkit/media/webkit_media.gypi @@ -26,8 +26,6 @@ 'filter_helpers.cc', 'filter_helpers.h', 'media_stream_client.h', - 'simple_data_source.cc', - 'simple_data_source.h', 'skcanvas_video_renderer.cc', 'skcanvas_video_renderer.h', 'web_data_source.cc', diff --git a/webkit/media/webmediaplayer_impl.cc b/webkit/media/webmediaplayer_impl.cc index 42e6041..84d7766 100644 --- a/webkit/media/webmediaplayer_impl.cc +++ b/webkit/media/webmediaplayer_impl.cc @@ -28,7 +28,6 @@ #include "v8/include/v8.h" #include "webkit/media/buffered_data_source.h" #include "webkit/media/filter_helpers.h" -#include "webkit/media/simple_data_source.h" #include "webkit/media/webmediaplayer_delegate.h" #include "webkit/media/webmediaplayer_proxy.h" #include "webkit/media/webvideoframe_impl.h" @@ -237,14 +236,9 @@ void WebMediaPlayerImpl::load(const WebKit::WebURL& url) { } // Otherwise it's a regular request which requires resolving the URL first. - scoped_refptr<WebDataSource> data_source; - if (gurl.SchemeIs(kDataScheme)) { - data_source = new SimpleDataSource(main_loop_, frame_); - } else { - data_source = new BufferedDataSource(main_loop_, frame_, media_log_); - } - proxy_->set_data_source(data_source); - data_source->Initialize(url, base::Bind( + proxy_->set_data_source( + new BufferedDataSource(main_loop_, frame_, media_log_)); + proxy_->data_source()->Initialize(url, base::Bind( &WebMediaPlayerImpl::DataSourceInitialized, base::Unretained(this), gurl)); } |