diff options
author | scherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-03 01:49:16 +0000 |
---|---|---|
committer | scherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-03 01:49:16 +0000 |
commit | 8f2bf64884944e8b770852240e34e79f117acbb6 (patch) | |
tree | e7235339bc556dc5f933b75578cb12ca8f2ce905 | |
parent | ebc34fab52eabbb680eee966bb10e8f8a8cbd845 (diff) | |
download | chromium_src-8f2bf64884944e8b770852240e34e79f117acbb6.zip chromium_src-8f2bf64884944e8b770852240e34e79f117acbb6.tar.gz chromium_src-8f2bf64884944e8b770852240e34e79f117acbb6.tar.bz2 |
Revert 68094 - Refactoring BufferedDataSource to work with WebURLLoader instead of a MediaResourceLoaderBridge.
One thing to notice is that both buffered_data_source_unittest and simple_data_source_unittest need to have a way to inject a MockWebURLLoader into the BufferedResourceLoader and the SimpleDataSource. In order to make sure a new one is not created during a Start(), I introduced the function SetURLLoaderForTest and keep_test_loader flag.
Patch by annacc@chromium.org:
http://codereview.chromium.org/3863002/
BUG=16751
TEST=src/xcodebuild/Debug/test_shell_tests --gtest_filter=Buffered*
src/xcodebuild/Debug/test_shell_tests --gtest_filter=Simple*
src/webkit/tools/layout_tests/run_webkit_tests.sh --debug media
webkit/tools/layout_tests/run_webkit_tests.sh --debug http/tests/media
TBR=scherkus@chromium.org
Review URL: http://codereview.chromium.org/5619002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@68126 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/renderer/render_view.cc | 28 | ||||
-rw-r--r-- | webkit/glue/media/buffered_data_source.cc | 309 | ||||
-rw-r--r-- | webkit/glue/media/buffered_data_source.h | 107 | ||||
-rw-r--r-- | webkit/glue/media/buffered_data_source_unittest.cc | 227 | ||||
-rw-r--r-- | webkit/glue/media/simple_data_source.cc | 127 | ||||
-rw-r--r-- | webkit/glue/media/simple_data_source.h | 72 | ||||
-rw-r--r-- | webkit/glue/media/simple_data_source_unittest.cc | 95 | ||||
-rw-r--r-- | webkit/glue/mock_webframe.h | 352 | ||||
-rw-r--r-- | webkit/glue/mock_weburlloader_impl.h | 36 | ||||
-rw-r--r-- | webkit/glue/multipart_response_delegate.cc | 44 | ||||
-rw-r--r-- | webkit/glue/multipart_response_delegate.h | 3 | ||||
-rw-r--r-- | webkit/glue/multipart_response_delegate_unittest.cc | 16 | ||||
-rw-r--r-- | webkit/glue/plugins/webplugin_impl.cc | 4 | ||||
-rw-r--r-- | webkit/glue/webmediaplayer_impl.cc | 7 | ||||
-rw-r--r-- | webkit/glue/webmediaplayer_impl.h | 7 | ||||
-rw-r--r-- | webkit/support/webkit_support.cc | 29 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell.gypi | 2 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_webview_delegate.cc | 29 |
18 files changed, 487 insertions, 1007 deletions
diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc index 17733a9..0b2ca23 100644 --- a/chrome/renderer/render_view.cc +++ b/chrome/renderer/render_view.cc @@ -2818,9 +2818,28 @@ WebMediaPlayer* RenderView::createMediaPlayer( MessageLoop::current(), context->context())); } - // TODO(annacc): do we still need appcache_host? http://crbug.com/65135 - // WebApplicationCacheHostImpl* appcache_host = - // WebApplicationCacheHostImpl::FromFrame(frame); + WebApplicationCacheHostImpl* appcache_host = + WebApplicationCacheHostImpl::FromFrame(frame); + + // TODO(hclam): obtain the following parameters from |client|. + // Create two bridge factory for two data sources. + webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory_simple = + new webkit_glue::MediaResourceLoaderBridgeFactory( + GURL(frame->url()), // referrer + "null", // frame origin + "null", // main_frame_origin + base::GetCurrentProcId(), + appcache_host ? appcache_host->host_id() : appcache::kNoHostId, + routing_id()); + + webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory_buffered = + new webkit_glue::MediaResourceLoaderBridgeFactory( + GURL(frame->url()), // referrer + "null", // frame origin + "null", // main_frame_origin + base::GetCurrentProcId(), + appcache_host ? appcache_host->host_id() : appcache::kNoHostId, + routing_id()); scoped_refptr<webkit_glue::WebVideoRenderer> video_renderer; bool pts_logging = cmd_line->HasSwitch(switches::kEnableVideoLogging); @@ -2831,7 +2850,8 @@ WebMediaPlayer* RenderView::createMediaPlayer( scoped_ptr<webkit_glue::WebMediaPlayerImpl> result( new webkit_glue::WebMediaPlayerImpl(client, collection.release())); - if (!result->Initialize(frame, + if (!result->Initialize(bridge_factory_simple, + bridge_factory_buffered, cmd_line->HasSwitch(switches::kSimpleDataSource), video_renderer)) { return NULL; diff --git a/webkit/glue/media/buffered_data_source.cc b/webkit/glue/media/buffered_data_source.cc index a82ce87..c864767 100644 --- a/webkit/glue/media/buffered_data_source.cc +++ b/webkit/glue/media/buffered_data_source.cc @@ -4,33 +4,19 @@ #include "base/callback.h" #include "base/compiler_specific.h" -#include "base/format_macros.h" #include "base/message_loop.h" #include "base/process_util.h" #include "base/stl_util-inl.h" -#include "base/string_number_conversions.h" #include "base/string_util.h" #include "media/base/filter_host.h" #include "media/base/media_format.h" #include "net/base/load_flags.h" #include "net/base/net_errors.h" -#include "third_party/WebKit/WebKit/chromium/public/WebKit.h" -#include "third_party/WebKit/WebKit/chromium/public/WebKitClient.h" -#include "third_party/WebKit/WebKit/chromium/public/WebString.h" -#include "third_party/WebKit/WebKit/chromium/public/WebURLError.h" +#include "net/http/http_response_headers.h" #include "webkit/glue/media/buffered_data_source.h" -#include "webkit/glue/multipart_response_delegate.h" #include "webkit/glue/webkit_glue.h" #include "webkit/glue/webmediaplayer_impl.h" -using WebKit::WebFrame; -using WebKit::WebString; -using WebKit::WebURLError; -using WebKit::WebURLLoader; -using WebKit::WebURLRequest; -using WebKit::WebURLResponse; -using webkit_glue::MultipartResponseDelegate; - namespace { const char kHttpScheme[] = "http"; @@ -84,10 +70,10 @@ bool IsDataProtocol(const GURL& url) { } // namespace namespace webkit_glue { - ///////////////////////////////////////////////////////////////////////////// // BufferedResourceLoader BufferedResourceLoader::BufferedResourceLoader( + webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory, const GURL& url, int64 first_byte_position, int64 last_byte_position) @@ -97,10 +83,12 @@ BufferedResourceLoader::BufferedResourceLoader( completed_(false), range_requested_(false), partial_response_(false), + bridge_factory_(bridge_factory), url_(url), first_byte_position_(first_byte_position), last_byte_position_(last_byte_position), start_callback_(NULL), + bridge_(NULL), offset_(0), content_length_(kPositionNotSpecified), instance_size_(kPositionNotSpecified), @@ -109,24 +97,20 @@ BufferedResourceLoader::BufferedResourceLoader( read_size_(0), read_buffer_(NULL), first_offset_(0), - last_offset_(0), - keep_test_loader_(false) { + last_offset_(0) { } BufferedResourceLoader::~BufferedResourceLoader() { - if (!completed_ && url_loader_.get()) - url_loader_->cancel(); } void BufferedResourceLoader::Start(net::CompletionCallback* start_callback, - NetworkEventCallback* event_callback, - WebFrame* frame) { + NetworkEventCallback* event_callback) { // Make sure we have not started. + DCHECK(!bridge_.get()); DCHECK(!start_callback_.get()); DCHECK(!event_callback_.get()); DCHECK(start_callback); DCHECK(event_callback); - CHECK(frame); start_callback_.reset(start_callback); event_callback_.reset(event_callback); @@ -138,26 +122,21 @@ void BufferedResourceLoader::Start(net::CompletionCallback* start_callback, offset_ = first_byte_position_; } + // Creates the bridge on render thread since we can only access + // ResourceDispatcher on this thread. + bridge_.reset( + bridge_factory_->CreateBridge( + url_, + net::LOAD_NORMAL, + first_byte_position_, + last_byte_position_)); + // Increment the reference count right before we start the request. This // reference will be release when this request has ended. AddRef(); - // Prepare the request. - WebURLRequest request(url_); - request.setHTTPHeaderField(WebString::fromUTF8("Range"), - WebString::fromUTF8(GenerateHeaders( - first_byte_position_, - last_byte_position_))); - frame->setReferrerForRequest(request, WebKit::WebURL()); - // TODO(annacc): we should be using createAssociatedURLLoader() instead? - frame->dispatchWillSendRequest(request); - - // This flag is for unittests as we don't want to reset |url_loader| - if (!keep_test_loader_) - url_loader_.reset(WebKit::webKitClient()->createURLLoader()); - - // Start the resource loading. - url_loader_->loadAsynchronously(request, this); + // And start the resource loading. + bridge_->Start(this); } void BufferedResourceLoader::Stop() { @@ -174,15 +153,14 @@ void BufferedResourceLoader::Stop() { // Destroy internal buffer. buffer_.reset(); - if (url_loader_.get()) { + if (bridge_.get()) { + // Cancel the request. This method call will cancel the request + // asynchronously. We may still get data or messages until we receive + // a response completed message. if (deferred_) - url_loader_->setDefersLoading(false); + bridge_->SetDefersLoading(false); deferred_ = false; - - if (!completed_) { - url_loader_->cancel(); - completed_ = true; - } + bridge_->Cancel(); } } @@ -253,47 +231,38 @@ void BufferedResourceLoader::SetAllowDefer(bool is_allowed) { DisableDeferIfNeeded(); } -void BufferedResourceLoader::SetURLLoaderForTest(WebURLLoader* mock_loader) { - url_loader_.reset(mock_loader); - keep_test_loader_ = true; -} - ///////////////////////////////////////////////////////////////////////////// -// BufferedResourceLoader, WebKit::WebURLLoaderClient implementations. -void BufferedResourceLoader::willSendRequest( - WebURLLoader* loader, - WebURLRequest& newRequest, - const WebURLResponse& redirectResponse) { +// BufferedResourceLoader, +// webkit_glue::ResourceLoaderBridge::Peer implementations +bool BufferedResourceLoader::OnReceivedRedirect( + const GURL& new_url, + const webkit_glue::ResourceResponseInfo& info, + bool* has_new_first_party_for_cookies, + GURL* new_first_party_for_cookies) { + DCHECK(bridge_.get()); + + // Save the new URL. + url_ = new_url; + // TODO(wtc): should we return a new first party for cookies URL? + *has_new_first_party_for_cookies = false; // The load may have been stopped and |start_callback| is destroyed. // In this case we shouldn't do anything. - if (!start_callback_.get()) { - // Set the url in the request to an invalid value (empty url). - newRequest.setURL(WebKit::WebURL()); - return; - } + if (!start_callback_.get()) + return true; - if (!IsProtocolSupportedForMedia(newRequest.url())) { - // Set the url in the request to an invalid value (empty url). - newRequest.setURL(WebKit::WebURL()); + if (!IsProtocolSupportedForMedia(new_url)) { DoneStart(net::ERR_ADDRESS_INVALID); Stop(); - return; + return false; } - - url_ = newRequest.url(); -} - -void BufferedResourceLoader::didSendData( - WebURLLoader* loader, - unsigned long long bytes_sent, - unsigned long long total_bytes_to_be_sent) { - NOTIMPLEMENTED(); + return true; } -void BufferedResourceLoader::didReceiveResponse( - WebURLLoader* loader, - const WebURLResponse& response) { +void BufferedResourceLoader::OnReceivedResponse( + const webkit_glue::ResourceResponseInfo& info, + bool content_filtered) { + DCHECK(bridge_.get()); // The loader may have been stopped and |start_callback| is destroyed. // In this case we shouldn't do anything. @@ -306,18 +275,23 @@ void BufferedResourceLoader::didReceiveResponse( // response for HTTP and HTTPS protocol. if (IsHttpProtocol(url_)) { int error = net::OK; - - if (response.httpStatusCode() == kHttpPartialContent) - partial_response_ = true; - - if (range_requested_ && partial_response_) { - // If we have verified the partial response and it is correct, we will - // return net::OK. - if (!VerifyPartialResponse(response)) - error = net::ERR_INVALID_RESPONSE; - } else if (response.httpStatusCode() != kHttpOK) { - // We didn't request a range but server didn't reply with "200 OK". - error = net::ERR_FAILED; + if (!info.headers) { + // We expect to receive headers because this is a HTTP or HTTPS protocol, + // if not report failure. + error = net::ERR_INVALID_RESPONSE; + } else { + if (info.headers->response_code() == kHttpPartialContent) + partial_response_ = true; + + if (range_requested_ && partial_response_) { + // If we have verified the partial response and it is correct, we will + // return net::OK. + if (!VerifyPartialResponse(info)) + error = net::ERR_INVALID_RESPONSE; + } else if (info.headers->response_code() != kHttpOK) { + // We didn't request a range but server didn't reply with "200 OK". + error = net::ERR_FAILED; + } } if (error != net::OK) { @@ -331,9 +305,9 @@ void BufferedResourceLoader::didReceiveResponse( partial_response_ = range_requested_; } - // Expected content length can be -1, in that case |content_length_| is + // |info.content_length| can be -1, in that case |content_length_| is // not specified and this is a streaming response. - content_length_ = response.expectedContentLength(); + content_length_ = info.content_length; // If we have not requested a range, then the size of the instance is equal // to the content length. @@ -344,12 +318,8 @@ void BufferedResourceLoader::didReceiveResponse( DoneStart(net::OK); } -void BufferedResourceLoader::didReceiveData( - WebURLLoader* loader, - const char* data, - int data_length) { - DCHECK(!completed_); - DCHECK_GT(data_length, 0); +void BufferedResourceLoader::OnReceivedData(const char* data, int len) { + DCHECK(bridge_.get()); // If this loader has been stopped, |buffer_| would be destroyed. // In this case we shouldn't do anything. @@ -357,7 +327,7 @@ void BufferedResourceLoader::didReceiveData( return; // Writes more data to |buffer_|. - buffer_->Append(reinterpret_cast<const uint8*>(data), data_length); + buffer_->Append(reinterpret_cast<const uint8*>(data), len); // If there is an active read request, try to fulfill the request. if (HasPendingRead() && CanFulfillRead()) { @@ -380,28 +350,18 @@ void BufferedResourceLoader::didReceiveData( NotifyNetworkEvent(); } -void BufferedResourceLoader::didDownloadData( - WebKit::WebURLLoader* loader, - int dataLength) { - NOTIMPLEMENTED(); -} - -void BufferedResourceLoader::didReceiveCachedMetadata( - WebURLLoader* loader, - const char* data, - int data_length) { - NOTIMPLEMENTED(); -} +void BufferedResourceLoader::OnCompletedRequest( + const URLRequestStatus& status, + const std::string& security_info, + const base::Time& completion_time) { + DCHECK(bridge_.get()); -void BufferedResourceLoader::didFinishLoading( - WebURLLoader* loader, - double finishTime) { - DCHECK(!completed_); + // Saves the information that the request has completed. completed_ = true; // If there is a start callback, calls it. if (start_callback_.get()) { - DoneStart(net::OK); + DoneStart(status.os_error()); } // If there is a pending read but the request has ended, returns with what @@ -410,11 +370,16 @@ void BufferedResourceLoader::didFinishLoading( // Make sure we have a valid buffer before we satisfy a read request. DCHECK(buffer_.get()); - // Try to fulfill with what is in the buffer. - if (CanFulfillRead()) - ReadInternal(); - else - DoneRead(net::ERR_CACHE_MISS); + if (status.is_success()) { + // Try to fulfill with what is in the buffer. + if (CanFulfillRead()) + ReadInternal(); + else + DoneRead(net::ERR_CACHE_MISS); + } else { + // If the request has failed, then fail the read. + DoneRead(net::ERR_FAILED); + } } // There must not be any outstanding read request. @@ -423,31 +388,10 @@ void BufferedResourceLoader::didFinishLoading( // Notify that network response is completed. NotifyNetworkEvent(); - url_loader_.reset(); - Release(); -} - -void BufferedResourceLoader::didFail( - WebURLLoader* loader, - const WebURLError& error) { - DCHECK(!completed_); - completed_ = true; - - // If there is a start callback, calls it. - if (start_callback_.get()) { - DoneStart(error.reason); - } - - // If there is a pending read but the request failed, return with the - // reason for the error. - if (HasPendingRead()) { - DoneRead(error.reason); - } - - // Notify that network response is completed. - NotifyNetworkEvent(); - - url_loader_.reset(); + // We incremented the reference count when the loader was started. We balance + // that reference here so that we get destroyed. This is also the only safe + // place to destroy the ResourceLoaderBridge. + bridge_.reset(); Release(); } @@ -461,8 +405,8 @@ void BufferedResourceLoader::EnableDeferIfNeeded() { buffer_->forward_bytes() >= buffer_->forward_capacity()) { deferred_ = true; - if (url_loader_.get()) - url_loader_->setDefersLoading(true); + if (bridge_.get()) + bridge_->SetDefersLoading(true); NotifyNetworkEvent(); } @@ -474,8 +418,8 @@ void BufferedResourceLoader::DisableDeferIfNeeded() { buffer_->forward_bytes() < buffer_->forward_capacity() / 2)) { deferred_ = false; - if (url_loader_.get()) - url_loader_->setDefersLoading(false); + if (bridge_.get()) + bridge_->SetDefersLoading(false); NotifyNetworkEvent(); } @@ -536,21 +480,18 @@ void BufferedResourceLoader::ReadInternal() { } bool BufferedResourceLoader::VerifyPartialResponse( - const WebURLResponse& response) { - int first_byte_position, last_byte_position, instance_size; - - if (!MultipartResponseDelegate::ReadContentRanges(response, - &first_byte_position, - &last_byte_position, - &instance_size)) { + const ResourceResponseInfo& info) { + int64 first_byte_position, last_byte_position, instance_size; + if (!info.headers->GetContentRange(&first_byte_position, + &last_byte_position, + &instance_size)) { return false; } - if (instance_size != kPositionNotSpecified) { + if (instance_size != kPositionNotSpecified) instance_size_ = instance_size; - } - if (first_byte_position_ != kPositionNotSpecified && + if (first_byte_position_ != -1 && first_byte_position_ != first_byte_position) { return false; } @@ -560,27 +501,6 @@ bool BufferedResourceLoader::VerifyPartialResponse( return true; } -std::string BufferedResourceLoader::GenerateHeaders( - int64 first_byte_position, - int64 last_byte_position) { - // Construct the value for the range header. - std::string header; - if (first_byte_position > kPositionNotSpecified && - last_byte_position > kPositionNotSpecified) { - if (first_byte_position <= last_byte_position) { - header = base::StringPrintf("bytes=%" PRId64 "-%" PRId64, - first_byte_position, - last_byte_position); - } - } else if (first_byte_position > kPositionNotSpecified) { - header = base::StringPrintf("bytes=%" PRId64 "-", - first_byte_position); - } else if (last_byte_position > kPositionNotSpecified) { - NOTIMPLEMENTED() << "Suffix range not implemented"; - } - return header; -} - void BufferedResourceLoader::DoneRead(int error) { read_callback_->RunWithParams(Tuple1<int>(error)); read_callback_.reset(); @@ -605,12 +525,12 @@ void BufferedResourceLoader::NotifyNetworkEvent() { // BufferedDataSource BufferedDataSource::BufferedDataSource( MessageLoop* render_loop, - WebFrame* frame) + webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory) : total_bytes_(kPositionNotSpecified), loaded_(false), streaming_(false), - frame_(frame), single_origin_(true), + bridge_factory_(bridge_factory), loader_(NULL), network_activity_(false), initialize_callback_(NULL), @@ -638,7 +558,7 @@ BufferedResourceLoader* BufferedDataSource::CreateResourceLoader( int64 first_byte_position, int64 last_byte_position) { DCHECK(MessageLoop::current() == render_loop_); - return new BufferedResourceLoader(url_, + return new BufferedResourceLoader(bridge_factory_.get(), url_, first_byte_position, last_byte_position); } @@ -738,12 +658,12 @@ void BufferedDataSource::Abort() { // If we are told to abort, immediately return from any pending read // with an error. if (read_callback_.get()) { + { AutoLock auto_lock(lock_); DoneRead_Locked(net::ERR_FAILED); + } + CleanupTask(); } - - CleanupTask(); - frame_ = NULL; } ///////////////////////////////////////////////////////////////////////////// @@ -770,8 +690,7 @@ void BufferedDataSource::InitializeTask() { loader_ = CreateResourceLoader(0, 1024); loader_->Start( NewCallback(this, &BufferedDataSource::HttpInitialStartCallback), - NewCallback(this, &BufferedDataSource::NetworkEventCallback), - frame_); + NewCallback(this, &BufferedDataSource::NetworkEventCallback)); } else { // For all other protocols, assume they support range request. We fetch // the full range of the resource to obtain the instance size because @@ -779,8 +698,7 @@ void BufferedDataSource::InitializeTask() { loader_ = CreateResourceLoader(-1, -1); loader_->Start( NewCallback(this, &BufferedDataSource::NonHttpInitialStartCallback), - NewCallback(this, &BufferedDataSource::NetworkEventCallback), - frame_); + NewCallback(this, &BufferedDataSource::NetworkEventCallback)); } } @@ -857,8 +775,7 @@ void BufferedDataSource::RestartLoadingTask() { loader_->SetAllowDefer(!media_is_paused_); loader_->Start( NewCallback(this, &BufferedDataSource::PartialReadStartCallback), - NewCallback(this, &BufferedDataSource::NetworkEventCallback), - frame_); + NewCallback(this, &BufferedDataSource::NetworkEventCallback)); } void BufferedDataSource::WatchDogTask() { @@ -889,8 +806,7 @@ void BufferedDataSource::WatchDogTask() { loader_->SetAllowDefer(!media_is_paused_); loader_->Start( NewCallback(this, &BufferedDataSource::PartialReadStartCallback), - NewCallback(this, &BufferedDataSource::NetworkEventCallback), - frame_); + NewCallback(this, &BufferedDataSource::NetworkEventCallback)); } void BufferedDataSource::SetPlaybackRateTask(float playback_rate) { @@ -913,7 +829,7 @@ void BufferedDataSource::SetPlaybackRateTask(float playback_rate) { // prior to make this method call. void BufferedDataSource::ReadInternal() { DCHECK(MessageLoop::current() == render_loop_); - DCHECK(loader_); + DCHECK(loader_.get()); // First we prepare the intermediate read buffer for BufferedResourceLoader // to write to. @@ -988,8 +904,7 @@ void BufferedDataSource::HttpInitialStartCallback(int error) { loader_ = CreateResourceLoader(-1, -1); loader_->Start( NewCallback(this, &BufferedDataSource::HttpInitialStartCallback), - NewCallback(this, &BufferedDataSource::NetworkEventCallback), - frame_); + NewCallback(this, &BufferedDataSource::NetworkEventCallback)); return; } diff --git a/webkit/glue/media/buffered_data_source.h b/webkit/glue/media/buffered_data_source.h index f1002cd..7218390 100644 --- a/webkit/glue/media/buffered_data_source.h +++ b/webkit/glue/media/buffered_data_source.h @@ -19,38 +19,33 @@ #include "media/base/seekable_buffer.h" #include "net/base/completion_callback.h" #include "net/base/file_stream.h" -#include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" -#include "third_party/WebKit/WebKit/chromium/public/WebURLLoader.h" -#include "third_party/WebKit/WebKit/chromium/public/WebURLLoaderClient.h" -#include "third_party/WebKit/WebKit/chromium/public/WebURLRequest.h" +#include "webkit/glue/media/media_resource_loader_bridge_factory.h" #include "webkit/glue/media/web_data_source.h" #include "webkit/glue/webmediaplayer_impl.h" -namespace WebKit { -class WebURLResponse; -} - namespace webkit_glue { - ///////////////////////////////////////////////////////////////////////////// // BufferedResourceLoader // This class works inside demuxer thread and render thread. It contains a -// WebURLLoader and does the actual resource loading. This object does -// buffering internally, it defers the resource loading if buffer is full -// and un-defers the resource loading if it is under buffered. +// resource loader bridge and does the actual resource loading. This object +// does buffering internally, it defers the resource loading if buffer is +// full and un-defers the resource loading if it is under buffered. class BufferedResourceLoader : public base::RefCountedThreadSafe<BufferedResourceLoader>, - public WebKit::WebURLLoaderClient { + public webkit_glue::ResourceLoaderBridge::Peer { public: typedef Callback0::Type NetworkEventCallback; + // |bridge_factory| - Factory to create a ResourceLoaderBridge. // |url| - URL for the resource to be loaded. // |first_byte_position| - First byte to start loading from, -1 for not // specified. // |last_byte_position| - Last byte to be loaded, -1 for not specified. - BufferedResourceLoader(const GURL& url, - int64 first_byte_position, - int64 last_byte_position); + BufferedResourceLoader( + webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory, + const GURL& url, + int64 first_byte_position, + int64 last_byte_position); // Start the resource loading with the specified URL and range. // This method operates in asynchronous mode. Once there's a response from the @@ -67,8 +62,7 @@ class BufferedResourceLoader : // |event_callback| is called when the response is completed, data is // received, the request is suspended or resumed. virtual void Start(net::CompletionCallback* callback, - NetworkEventCallback* event_callback, - WebKit::WebFrame* frame); + NetworkEventCallback* event_callback); // Stop this loader, cancels and request and release internal buffer. virtual void Stop(); @@ -115,38 +109,23 @@ class BufferedResourceLoader : // Returns resulting URL. virtual const GURL& url() { return url_; } - // 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); - 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::ResourceLoaderBridge::Peer implementations. + virtual void OnUploadProgress(uint64 position, uint64 size) {} + virtual bool OnReceivedRedirect( + const GURL& new_url, + const webkit_glue::ResourceResponseInfo& info, + bool* has_new_first_party_for_cookies, + GURL* new_first_party_for_cookies); + virtual void OnReceivedResponse( + const webkit_glue::ResourceResponseInfo& info, + bool content_filtered); + virtual void OnDownloadedData(int len) {} + virtual void OnReceivedData(const char* data, int len); + virtual void OnCompletedRequest( + const URLRequestStatus& status, + const std::string& security_info, + const base::Time& completion_time); protected: friend class base::RefCountedThreadSafe<BufferedResourceLoader>; @@ -174,16 +153,7 @@ class BufferedResourceLoader : void ReadInternal(); // If we have made a range request, verify the response from the server. - bool VerifyPartialResponse(const WebKit::WebURLResponse& response); - - // Returns the value for a range request header using parameters - // |first_byte_position| and |last_byte_position|. Negative numbers other - // than -1 are not allowed for |first_byte_position| and |last_byte_position|. - // |first_byte_position| should always be less than or equal to - // |last_byte_position| if they are both not -1. - // Empty string is returned on invalid parameters. - std::string GenerateHeaders(int64 first_byte_position, - int64 last_byte_position); + bool VerifyPartialResponse(const ResourceResponseInfo& info); // Done with read. Invokes the read callback and reset parameters for the // read request. @@ -215,9 +185,7 @@ class BufferedResourceLoader : // True if response data received is a partial range. bool partial_response_; - // Does the work of loading and sends data back to this client. - scoped_ptr<WebKit::WebURLLoader> url_loader_; - + webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory_; GURL url_; int64 first_byte_position_; int64 last_byte_position_; @@ -227,6 +195,7 @@ class BufferedResourceLoader : // Members used during request start. scoped_ptr<net::CompletionCallback> start_callback_; + scoped_ptr<webkit_glue::ResourceLoaderBridge> bridge_; int64 offset_; int64 content_length_; int64 instance_size_; @@ -243,16 +212,14 @@ class BufferedResourceLoader : int first_offset_; int last_offset_; - // Used to ensure mocks for unittests are used instead of reset in Start(). - bool keep_test_loader_; - DISALLOW_COPY_AND_ASSIGN(BufferedResourceLoader); }; class BufferedDataSource : public WebDataSource { public: - BufferedDataSource(MessageLoop* render_loop, - WebKit::WebFrame* frame); + BufferedDataSource( + MessageLoop* render_loop, + webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory); virtual ~BufferedDataSource(); @@ -370,12 +337,12 @@ class BufferedDataSource : public WebDataSource { // i.e. range request is not supported. bool streaming_; - // A webframe for loading. - WebKit::WebFrame* frame_; - // True if the media resource has a single origin. bool single_origin_; + // A factory object to produce ResourceLoaderBridge. + scoped_ptr<webkit_glue::MediaResourceLoaderBridgeFactory> bridge_factory_; + // A resource loader for the media resource. scoped_refptr<BufferedResourceLoader> loader_; diff --git a/webkit/glue/media/buffered_data_source_unittest.cc b/webkit/glue/media/buffered_data_source_unittest.cc index 5fad3a4..81103b2 100644 --- a/webkit/glue/media/buffered_data_source_unittest.cc +++ b/webkit/glue/media/buffered_data_source_unittest.cc @@ -13,21 +13,13 @@ #include "media/base/mock_filter_host.h" #include "media/base/mock_filters.h" #include "net/base/net_errors.h" -#include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" -#include "third_party/WebKit/WebKit/chromium/public/WebFrameClient.h" -#include "third_party/WebKit/WebKit/chromium/public/WebString.h" -#include "third_party/WebKit/WebKit/chromium/public/WebURLError.h" -#include "third_party/WebKit/WebKit/chromium/public/WebURLLoader.h" -#include "third_party/WebKit/WebKit/chromium/public/WebURLRequest.h" -#include "third_party/WebKit/WebKit/chromium/public/WebURLResponse.h" -#include "third_party/WebKit/WebKit/chromium/public/WebView.h" +#include "net/http/http_response_headers.h" #include "webkit/glue/media/buffered_data_source.h" -#include "webkit/glue/mock_webframe.h" -#include "webkit/glue/mock_weburlloader_impl.h" +#include "webkit/glue/media/mock_media_resource_loader_bridge_factory.h" +#include "webkit/glue/mock_resource_loader_bridge.h" using ::testing::_; using ::testing::Assign; -using ::testing::AtLeast; using ::testing::DeleteArg; using ::testing::DoAll; using ::testing::InSequence; @@ -41,22 +33,11 @@ using ::testing::StrictMock; using ::testing::NiceMock; using ::testing::WithArgs; -using WebKit::WebURLError; -using WebKit::WebFrame; -using WebKit::WebFrameClient; -using WebKit::WebString; -using WebKit::WebURLLoader; -using WebKit::WebURLRequest; -using WebKit::WebURLResponse; -using WebKit::WebView; - namespace { const char* kHttpUrl = "http://test"; const char* kFileUrl = "file://test"; const int kDataSize = 1024; -const int kHttpOK = 200; -const int kHttpPartialContent = 206; enum NetworkState { NONE, @@ -71,23 +52,25 @@ namespace webkit_glue { // Submit a request completed event to the resource loader due to request // being canceled. Pretending the event is from external. ACTION_P(RequestCanceled, loader) { - WebURLError error; - error.reason = net::ERR_ABORTED; - error.domain = WebString::fromUTF8(net::kErrorDomain); - loader->didFail(NULL, error); + URLRequestStatus status; + status.set_status(URLRequestStatus::CANCELED); + status.set_os_error(net::ERR_ABORTED); + loader->OnCompletedRequest(status, "", base::Time()); } class BufferedResourceLoaderTest : public testing::Test { public: BufferedResourceLoaderTest() { - url_loader_ = new NiceMock<MockWebURLLoader>(); + bridge_.reset(new StrictMock<MockResourceLoaderBridge>()); for (int i = 0; i < kDataSize; ++i) data_[i] = i; } - virtual ~BufferedResourceLoaderTest() { - ignore_result(frame_.release()); + ~BufferedResourceLoaderTest() { + if (bridge_.get()) + EXPECT_CALL(*bridge_, OnDestroy()); + EXPECT_CALL(bridge_factory_, OnDestroy()); } void Initialize(const char* url, int first_position, int last_position) { @@ -95,11 +78,8 @@ class BufferedResourceLoaderTest : public testing::Test { first_position_ = first_position; last_position_ = last_position; - frame_.reset(new NiceMock<MockWebFrame>()); - - loader_ = new BufferedResourceLoader(gurl_, + loader_ = new BufferedResourceLoader(&bridge_factory_, gurl_, first_position_, last_position_); - loader_->SetURLLoaderForTest(url_loader_); } void SetLoaderBuffer(size_t forward_capacity, size_t backward_capacity) { @@ -109,23 +89,25 @@ class BufferedResourceLoaderTest : public testing::Test { void Start() { InSequence s; - EXPECT_CALL(*url_loader_, loadAsynchronously(_, loader_.get())); + EXPECT_CALL(bridge_factory_, + CreateBridge(gurl_, _, first_position_, last_position_)) + .WillOnce(Return(bridge_.get())); + EXPECT_CALL(*bridge_, Start(loader_.get())); loader_->Start( NewCallback(this, &BufferedResourceLoaderTest::StartCallback), - NewCallback(this, &BufferedResourceLoaderTest::NetworkCallback), - frame_.get()); + NewCallback(this, &BufferedResourceLoaderTest::NetworkCallback)); } void FullResponse(int64 instance_size) { EXPECT_CALL(*this, StartCallback(net::OK)); - - WebURLResponse response(gurl_); - response.setHTTPHeaderField(WebString::fromUTF8("Content-Length"), - WebString::fromUTF8(base::StringPrintf("%" - PRId64, instance_size))); - response.setExpectedContentLength(instance_size); - response.setHTTPStatusCode(kHttpOK); - loader_->didReceiveResponse(url_loader_, response); + ResourceResponseInfo info; + std::string header = base::StringPrintf("HTTP/1.1 200 OK\n" + "Content-Length: %" PRId64, + instance_size); + replace(header.begin(), header.end(), '\n', '\0'); + info.headers = new net::HttpResponseHeaders(header); + info.content_length = instance_size; + loader_->OnReceivedResponse(info, false); EXPECT_EQ(instance_size, loader_->content_length()); EXPECT_EQ(instance_size, loader_->instance_size()); EXPECT_FALSE(loader_->partial_response()); @@ -135,17 +117,17 @@ class BufferedResourceLoaderTest : public testing::Test { int64 instance_size) { EXPECT_CALL(*this, StartCallback(net::OK)); int64 content_length = last_position - first_position + 1; - - WebURLResponse response(gurl_); - response.setHTTPHeaderField(WebString::fromUTF8("Content-Range"), - WebString::fromUTF8(base::StringPrintf("bytes " + ResourceResponseInfo info; + std::string header = base::StringPrintf("HTTP/1.1 206 Partial Content\n" + "Content-Range: bytes " "%" PRId64 "-%" PRId64 "/%" PRId64, first_position, last_position, - instance_size))); - response.setExpectedContentLength(content_length); - response.setHTTPStatusCode(kHttpPartialContent); - loader_->didReceiveResponse(url_loader_, response); + instance_size); + replace(header.begin(), header.end(), '\n', '\0'); + info.headers = new net::HttpResponseHeaders(header); + info.content_length = content_length; + loader_->OnReceivedResponse(info, false); EXPECT_EQ(content_length, loader_->content_length()); EXPECT_EQ(instance_size, loader_->instance_size()); EXPECT_TRUE(loader_->partial_response()); @@ -153,17 +135,22 @@ class BufferedResourceLoaderTest : public testing::Test { void StopWhenLoad() { InSequence s; - EXPECT_CALL(*url_loader_, cancel()) + EXPECT_CALL(*bridge_, Cancel()) .WillOnce(RequestCanceled(loader_)); + EXPECT_CALL(*bridge_, OnDestroy()) + .WillOnce(Invoke(this, &BufferedResourceLoaderTest::ReleaseBridge)); loader_->Stop(); } + void ReleaseBridge() { + ignore_result(bridge_.release()); + } + // Helper method to write to |loader_| from |data_|. void WriteLoader(int position, int size) { EXPECT_CALL(*this, NetworkCallback()) .RetiresOnSaturation(); - loader_->didReceiveData(url_loader_, - reinterpret_cast<char*>(data_ + position), size); + loader_->OnReceivedData(reinterpret_cast<char*>(data_ + position), size); } // Helper method to read from |loader_|. @@ -180,7 +167,7 @@ class BufferedResourceLoaderTest : public testing::Test { // Helper method to disallow deferring in |loader_|. void DisallowLoaderDefer() { if (loader_->deferred_) { - EXPECT_CALL(*url_loader_, setDefersLoading(false)); + EXPECT_CALL(*bridge_, SetDefersLoading(false)); EXPECT_CALL(*this, NetworkCallback()); } loader_->SetAllowDefer(false); @@ -201,8 +188,8 @@ class BufferedResourceLoaderTest : public testing::Test { int64 last_position_; scoped_refptr<BufferedResourceLoader> loader_; - NiceMock<MockWebURLLoader>* url_loader_; - scoped_ptr<NiceMock<MockWebFrame> > frame_; + StrictMock<MockMediaResourceLoaderBridgeFactory> bridge_factory_; + scoped_ptr<StrictMock<MockResourceLoaderBridge> > bridge_; uint8 data_[kDataSize]; @@ -216,19 +203,35 @@ TEST_F(BufferedResourceLoaderTest, StartStop) { StopWhenLoad(); } +// Tests that HTTP header is missing in the response. +TEST_F(BufferedResourceLoaderTest, MissingHttpHeader) { + Initialize(kHttpUrl, -1, -1); + Start(); + + EXPECT_CALL(*this, StartCallback(net::ERR_INVALID_RESPONSE)); + EXPECT_CALL(*bridge_, Cancel()) + .WillOnce(RequestCanceled(loader_)); + EXPECT_CALL(*bridge_, OnDestroy()) + .WillOnce(Invoke(this, &BufferedResourceLoaderTest::ReleaseBridge)); + + ResourceResponseInfo info; + loader_->OnReceivedResponse(info, false); +} + // Tests that a bad HTTP response is recived, e.g. file not found. TEST_F(BufferedResourceLoaderTest, BadHttpResponse) { Initialize(kHttpUrl, -1, -1); Start(); EXPECT_CALL(*this, StartCallback(net::ERR_FAILED)); - EXPECT_CALL(*url_loader_, cancel()) + EXPECT_CALL(*bridge_, Cancel()) .WillOnce(RequestCanceled(loader_)); + EXPECT_CALL(*bridge_, OnDestroy()) + .WillOnce(Invoke(this, &BufferedResourceLoaderTest::ReleaseBridge)); - WebURLResponse response(gurl_); - response.setHTTPStatusCode(404); - response.setHTTPStatusText("Not Found\n"); - loader_->didReceiveResponse(url_loader_, response); + ResourceResponseInfo info; + info.headers = new net::HttpResponseHeaders("HTTP/1.1 404 Not Found\n"); + loader_->OnReceivedResponse(info, false); } // Tests that partial content is requested but not fulfilled. @@ -261,16 +264,19 @@ TEST_F(BufferedResourceLoaderTest, InvalidPartialResponse) { Start(); EXPECT_CALL(*this, StartCallback(net::ERR_INVALID_RESPONSE)); - EXPECT_CALL(*url_loader_, cancel()) + EXPECT_CALL(*bridge_, Cancel()) .WillOnce(RequestCanceled(loader_)); - - WebURLResponse response(gurl_); - response.setHTTPHeaderField(WebString::fromUTF8("Content-Range"), - WebString::fromUTF8(base::StringPrintf("bytes " - "%d-%d/%d", 1, 10, 1024))); - response.setExpectedContentLength(10); - response.setHTTPStatusCode(kHttpPartialContent); - loader_->didReceiveResponse(url_loader_, response); + EXPECT_CALL(*bridge_, OnDestroy()) + .WillOnce(Invoke(this, &BufferedResourceLoaderTest::ReleaseBridge)); + + ResourceResponseInfo info; + std::string header = base::StringPrintf("HTTP/1.1 206 Partial Content\n" + "Content-Range: bytes %d-%d/%d", + 1, 10, 1024); + replace(header.begin(), header.end(), '\n', '\0'); + info.headers = new net::HttpResponseHeaders(header); + info.content_length = 10; + loader_->OnReceivedResponse(info, false); } // Tests the logic of sliding window for data buffering and reading. @@ -308,7 +314,11 @@ TEST_F(BufferedResourceLoaderTest, BufferAndRead) { // Response has completed. EXPECT_CALL(*this, NetworkCallback()); - loader_->didFinishLoading(url_loader_, 0); + EXPECT_CALL(*bridge_, OnDestroy()) + .WillOnce(Invoke(this, &BufferedResourceLoaderTest::ReleaseBridge)); + URLRequestStatus status; + status.set_status(URLRequestStatus::SUCCESS); + loader_->OnCompletedRequest(status, "", base::Time()); // Try to read 10 from position 25 will just return with 5 bytes. EXPECT_CALL(*this, ReadCallback(5)); @@ -350,7 +360,11 @@ TEST_F(BufferedResourceLoaderTest, ReadOutsideBuffer) { EXPECT_CALL(*this, ReadCallback(5)); EXPECT_CALL(*this, NetworkCallback()); - loader_->didFinishLoading(url_loader_, 0); + EXPECT_CALL(*bridge_, OnDestroy()) + .WillOnce(Invoke(this, &BufferedResourceLoaderTest::ReleaseBridge)); + URLRequestStatus status; + status.set_status(URLRequestStatus::SUCCESS); + loader_->OnCompletedRequest(status, "", base::Time()); } TEST_F(BufferedResourceLoaderTest, RequestFailedWhenRead) { @@ -364,9 +378,11 @@ TEST_F(BufferedResourceLoaderTest, RequestFailedWhenRead) { ReadLoader(10, 10, buffer); EXPECT_CALL(*this, ReadCallback(net::ERR_FAILED)); EXPECT_CALL(*this, NetworkCallback()); - WebURLError error; - error.reason = net::ERR_FAILED; - loader_->didFail(url_loader_, error); + EXPECT_CALL(*bridge_, OnDestroy()) + .WillOnce(Invoke(this, &BufferedResourceLoaderTest::ReleaseBridge)); + URLRequestStatus status; + status.set_status(URLRequestStatus::FAILED); + loader_->OnCompletedRequest(status, "", base::Time()); } // Tests the logic of caching data to disk when media is paused. @@ -433,7 +449,7 @@ TEST_F(BufferedResourceLoaderTest, AllowDefer_DeferredNoDataReceived) { // Start in deferred state, then disallow defer, receive no data, and // allow defer and read. - EXPECT_CALL(*url_loader_, setDefersLoading(true)); + EXPECT_CALL(*bridge_, SetDefersLoading(true)); EXPECT_CALL(*this, NetworkCallback()); WriteLoader(10, 40); @@ -456,7 +472,7 @@ TEST_F(BufferedResourceLoaderTest, AllowDefer_DeferredReadSameWindow) { // Start in deferred state, disallow defer, receive data and shift buffer // window, allow defer, and read in a place that's still in the window. - EXPECT_CALL(*url_loader_, setDefersLoading(true)); + EXPECT_CALL(*bridge_, SetDefersLoading(true)); EXPECT_CALL(*this, NetworkCallback()); WriteLoader(10, 30); @@ -480,7 +496,7 @@ TEST_F(BufferedResourceLoaderTest, AllowDefer_DeferredReadPastWindow) { // Start in deferred state, disallow defer, receive data and shift buffer // window, allow defer, and read outside of the buffer window. - EXPECT_CALL(*url_loader_, setDefersLoading(true)); + EXPECT_CALL(*bridge_, SetDefersLoading(true)); EXPECT_CALL(*this, NetworkCallback()); WriteLoader(10, 40); @@ -493,16 +509,16 @@ TEST_F(BufferedResourceLoaderTest, AllowDefer_DeferredReadPastWindow) { ReadLoader(20, 5, buffer); StopWhenLoad(); } + // TODO(hclam): add unit test for defer loading. class MockBufferedResourceLoader : public BufferedResourceLoader { public: - MockBufferedResourceLoader() : BufferedResourceLoader(GURL(), 0, 0) { + MockBufferedResourceLoader() : BufferedResourceLoader(NULL, GURL(), 0, 0) { } - MOCK_METHOD3(Start, void(net::CompletionCallback* read_callback, - NetworkEventCallback* network_callback, - WebFrame* frame)); + MOCK_METHOD2(Start, void(net::CompletionCallback* read_callback, + NetworkEventCallback* network_callback)); MOCK_METHOD0(Stop, void()); MOCK_METHOD4(Read, void(int64 position, int read_size, uint8* buffer, net::CompletionCallback* callback)); @@ -525,8 +541,8 @@ class MockBufferedResourceLoader : public BufferedResourceLoader { class MockBufferedDataSource : public BufferedDataSource { public: MockBufferedDataSource( - MessageLoop* message_loop, WebFrame* frame) - : BufferedDataSource(message_loop, frame) { + MessageLoop* message_loop, MediaResourceLoaderBridgeFactory* factory) + : BufferedDataSource(message_loop, factory) { } virtual base::TimeDelta GetTimeoutMilliseconds() { @@ -545,6 +561,8 @@ class BufferedDataSourceTest : public testing::Test { public: BufferedDataSourceTest() { message_loop_ = MessageLoop::current(); + bridge_factory_.reset( + new StrictMock<MockMediaResourceLoaderBridgeFactory>()); // Prepare test data. for (size_t i = 0; i < sizeof(data_); ++i) { @@ -553,14 +571,20 @@ class BufferedDataSourceTest : public testing::Test { } virtual ~BufferedDataSourceTest() { - ignore_result(frame_.release()); + if (data_source_) { + // Release the bridge factory because we don't own it. + // Expects bridge factory to be destroyed along with data source. + EXPECT_CALL(*bridge_factory_, OnDestroy()) + .WillOnce(Invoke(this, + &BufferedDataSourceTest::ReleaseBridgeFactory)); + } } void ExpectCreateAndStartResourceLoader(int start_error) { EXPECT_CALL(*data_source_, CreateResourceLoader(_, _)) .WillOnce(Return(loader_.get())); - EXPECT_CALL(*loader_, Start(NotNull(), NotNull(), NotNull())) + EXPECT_CALL(*loader_, Start(NotNull(), NotNull())) .WillOnce( DoAll(Assign(&error_, start_error), Invoke(this, @@ -573,10 +597,15 @@ class BufferedDataSourceTest : public testing::Test { // Saves the url first. gurl_ = GURL(url); - frame_.reset(new NiceMock<MockWebFrame>()); - + media::MediaFormat url_format; + url_format.SetAsString(media::MediaFormat::kMimeType, + media::mime_type::kURL); + url_format.SetAsString(media::MediaFormat::kURL, url); data_source_ = new MockBufferedDataSource(MessageLoop::current(), - frame_.get()); + bridge_factory_.get()); + CHECK(data_source_); + + // There is no need to provide a message loop to data source. data_source_->set_host(&host_); scoped_refptr<NiceMock<MockBufferedResourceLoader> > first_loader( @@ -602,7 +631,7 @@ class BufferedDataSourceTest : public testing::Test { // Replace loader_ with a new instance. loader_ = new NiceMock<MockBufferedResourceLoader>(); - // Create and start. Make sure Start() is called on the new loader. + // Create and start Make sure Start() is called the new loader. ExpectCreateAndStartResourceLoader(net::OK); // Update initialization variable since we know the second loader will @@ -676,10 +705,13 @@ class BufferedDataSourceTest : public testing::Test { message_loop_->RunAllPending(); } + void ReleaseBridgeFactory() { + ignore_result(bridge_factory_.release()); + } + void InvokeStartCallback( net::CompletionCallback* callback, - BufferedResourceLoader::NetworkEventCallback* network_callback, - WebFrame* frame) { + BufferedResourceLoader::NetworkEventCallback* network_callback) { callback->RunWithParams(Tuple1<int>(error_)); delete callback; // TODO(hclam): Save this callback. @@ -758,7 +790,7 @@ class BufferedDataSourceTest : public testing::Test { .WillOnce(Return(new_loader)); // 3. Then the new loader will be started. - EXPECT_CALL(*new_loader, Start(NotNull(), NotNull(), NotNull())) + EXPECT_CALL(*new_loader, Start(NotNull(), NotNull())) .WillOnce(DoAll(Assign(&error_, net::OK), Invoke(this, &BufferedDataSourceTest::InvokeStartCallback))); @@ -824,7 +856,7 @@ class BufferedDataSourceTest : public testing::Test { // 3. Then the new loader will be started and respond to queries about // whether this is a partial response using the value of the previous // loader. - EXPECT_CALL(*new_loader, Start(NotNull(), NotNull(), NotNull())) + EXPECT_CALL(*new_loader, Start(NotNull(), NotNull())) .WillOnce(DoAll(Assign(&error_, net::OK), Invoke(this, &BufferedDataSourceTest::InvokeStartCallback))); @@ -857,9 +889,10 @@ class BufferedDataSourceTest : public testing::Test { MOCK_METHOD1(ReadCallback, void(size_t size)); + scoped_ptr<StrictMock<MockMediaResourceLoaderBridgeFactory> > + bridge_factory_; scoped_refptr<NiceMock<MockBufferedResourceLoader> > loader_; scoped_refptr<MockBufferedDataSource> data_source_; - scoped_ptr<NiceMock<MockWebFrame> > frame_; StrictMock<media::MockFilterHost> host_; GURL gurl_; diff --git a/webkit/glue/media/simple_data_source.cc b/webkit/glue/media/simple_data_source.cc index 97a9c39..291928e 100644 --- a/webkit/glue/media/simple_data_source.cc +++ b/webkit/glue/media/simple_data_source.cc @@ -7,10 +7,10 @@ #include "media/base/filter_host.h" #include "net/base/load_flags.h" #include "net/base/data_url.h" +#include "net/http/http_response_headers.h" #include "net/url_request/url_request_status.h" -#include "third_party/WebKit/WebKit/chromium/public/WebKit.h" -#include "third_party/WebKit/WebKit/chromium/public/WebKitClient.h" #include "webkit/glue/media/simple_data_source.h" +#include "webkit/glue/resource_loader_bridge.h" #include "webkit/glue/webkit_glue.h" namespace { @@ -30,13 +30,12 @@ namespace webkit_glue { SimpleDataSource::SimpleDataSource( MessageLoop* render_loop, - WebKit::WebFrame* frame) + webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory) : render_loop_(render_loop), - frame_(frame), + bridge_factory_(bridge_factory), size_(-1), single_origin_(true), - state_(UNINITIALIZED), - keep_test_loader_(false) { + state_(UNINITIALIZED) { DCHECK(render_loop); } @@ -109,81 +108,34 @@ bool SimpleDataSource::IsStreaming() { return false; } -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) { +bool SimpleDataSource::OnReceivedRedirect( + const GURL& new_url, + const webkit_glue::ResourceResponseInfo& info, + bool* has_new_first_party_for_cookies, + GURL* new_first_party_for_cookies) { DCHECK(MessageLoop::current() == render_loop_); - single_origin_ = url_.GetOrigin() == GURL(newRequest.url()).GetOrigin(); + single_origin_ = url_.GetOrigin() == new_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(); + // TODO(wtc): should we return a new first party for cookies URL? + *has_new_first_party_for_cookies = false; + return true; } -void SimpleDataSource::didReceiveData( - WebKit::WebURLLoader* loader, - const char* data, - int data_length) { +void SimpleDataSource::OnReceivedResponse( + const webkit_glue::ResourceResponseInfo& info, + bool content_filtered) { DCHECK(MessageLoop::current() == render_loop_); - data_.append(data, data_length); -} - -void SimpleDataSource::didReceiveCachedMetadata( - WebKit::WebURLLoader* loader, - const char* data, - int dataLength) { - NOTIMPLEMENTED(); + size_ = info.content_length; } -void SimpleDataSource::didFinishLoading( - WebKit::WebURLLoader* loader, - double finishTime) { +void SimpleDataSource::OnReceivedData(const char* data, int len) { DCHECK(MessageLoop::current() == render_loop_); - 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); + data_.append(data, len); } -void SimpleDataSource::didFail( - WebKit::WebURLLoader* loader, - const WebKit::WebURLError& error) { +void SimpleDataSource::OnCompletedRequest(const URLRequestStatus& status, + const std::string& security_info, + const base::Time& completion_time) { DCHECK(MessageLoop::current() == render_loop_); AutoLock auto_lock(lock_); // It's possible this gets called after Stop(), in which case |host_| is no @@ -191,8 +143,10 @@ void SimpleDataSource::didFail( if (state_ == STOPPED) return; - // Otherwise we should be initializing and have created a WebURLLoader. + // Otherwise we should be initializing and have created a bridge. DCHECK_EQ(state_, INITIALIZING); + DCHECK(bridge_.get()); + bridge_.reset(); // If we don't get a content length or the request has failed, report it // as a network error. @@ -200,7 +154,7 @@ void SimpleDataSource::didFail( size_ = data_.length(); DCHECK(static_cast<size_t>(size_) == data_.length()); - DoneInitialization_Locked(false); + DoneInitialization_Locked(status.is_success()); } bool SimpleDataSource::HasSingleOrigin() { @@ -210,7 +164,7 @@ bool SimpleDataSource::HasSingleOrigin() { void SimpleDataSource::Abort() { DCHECK(MessageLoop::current() == render_loop_); - frame_ = NULL; + NOTIMPLEMENTED(); } void SimpleDataSource::SetURL(const GURL& url) { @@ -229,8 +183,6 @@ void SimpleDataSource::StartTask() { if (state_ == STOPPED) return; - CHECK(frame_); - DCHECK_EQ(state_, INITIALIZING); if (IsDataProtocol(url_)) { @@ -242,19 +194,10 @@ void SimpleDataSource::StartTask() { size_ = data_.length(); DoneInitialization_Locked(success); } else { - // Prepare the request. - WebKit::WebURLRequest request(url_); - - frame_->setReferrerForRequest(request, WebKit::WebURL()); - // TODO(annacc): we should be using createAssociatedURLLoader() instead? - frame_->dispatchWillSendRequest(request); - - // This flag is for unittests as we don't want to reset |url_loader| - if (!keep_test_loader_) - url_loader_.reset(WebKit::webKitClient()->createURLLoader()); - - // Start the resource loading. - url_loader_->loadAsynchronously(request, this); + // Create our bridge and start loading the resource. + bridge_.reset(bridge_factory_->CreateBridge( + url_, net::LOAD_BYPASS_CACHE, -1, -1)); + bridge_->Start(this); } } @@ -264,9 +207,9 @@ void SimpleDataSource::CancelTask() { DCHECK_EQ(state_, STOPPED); // Cancel any pending requests. - if (url_loader_.get()) { - url_loader_->cancel(); - url_loader_.reset(); + if (bridge_.get()) { + bridge_->Cancel(); + bridge_.reset(); } } diff --git a/webkit/glue/media/simple_data_source.h b/webkit/glue/media/simple_data_source.h index f4c83e6..394a9e3 100644 --- a/webkit/glue/media/simple_data_source.h +++ b/webkit/glue/media/simple_data_source.h @@ -10,17 +10,10 @@ #ifndef WEBKIT_GLUE_MEDIA_SIMPLE_DATA_SOURCE_H_ #define WEBKIT_GLUE_MEDIA_SIMPLE_DATA_SOURCE_H_ -#include <algorithm> -#include <string> - #include "base/message_loop.h" #include "base/scoped_ptr.h" #include "media/base/filters.h" -#include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" -#include "third_party/WebKit/WebKit/chromium/public/WebURLLoader.h" -#include "third_party/WebKit/WebKit/chromium/public/WebURLLoaderClient.h" -#include "third_party/WebKit/WebKit/chromium/public/WebURLRequest.h" -#include "third_party/WebKit/WebKit/chromium/public/WebURLResponse.h" +#include "webkit/glue/media/media_resource_loader_bridge_factory.h" #include "webkit/glue/media/web_data_source.h" class MessageLoop; @@ -29,9 +22,11 @@ class WebMediaPlayerDelegateImpl; namespace webkit_glue { class SimpleDataSource : public WebDataSource, - public WebKit::WebURLLoaderClient { + public webkit_glue::ResourceLoaderBridge::Peer { public: - SimpleDataSource(MessageLoop* render_loop, WebKit::WebFrame* frame); + SimpleDataSource( + MessageLoop* render_loop, + webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory); virtual ~SimpleDataSource(); // media::Filter implementation. @@ -46,37 +41,21 @@ class SimpleDataSource : public WebDataSource, virtual bool GetSize(int64* size_out); virtual bool IsStreaming(); - // 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); - 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::ResourceLoaderBridge::Peer implementation. + virtual void OnUploadProgress(uint64 position, uint64 size) {} + virtual bool OnReceivedRedirect( + const GURL& new_url, + const webkit_glue::ResourceResponseInfo& info, + bool* has_new_first_party_for_cookies, + GURL* new_first_party_for_cookies); + virtual void OnReceivedResponse( + const webkit_glue::ResourceResponseInfo& info, + bool content_filtered); + virtual void OnDownloadedData(int len) {} + virtual void OnReceivedData(const char* data, int len); + virtual void OnCompletedRequest(const URLRequestStatus& status, + const std::string& security_info, + const base::Time& completion_time); // webkit_glue::WebDataSource implementation. virtual bool HasSingleOrigin(); @@ -98,11 +77,11 @@ class SimpleDataSource : public WebDataSource, // Primarily used for asserting the bridge is loading on the render thread. MessageLoop* render_loop_; - // A webframe for loading. - WebKit::WebFrame* frame_; + // Factory to create a bridge. + scoped_ptr<webkit_glue::MediaResourceLoaderBridgeFactory> bridge_factory_; - // Does the work of loading and sends data back to this client. - scoped_ptr<WebKit::WebURLLoader> url_loader_; + // Bridge used to load the media resource. + scoped_ptr<webkit_glue::ResourceLoaderBridge> bridge_; media::MediaFormat media_format_; GURL url_; @@ -125,9 +104,6 @@ class SimpleDataSource : public WebDataSource, // Filter callbacks. scoped_ptr<media::FilterCallback> initialize_callback_; - // Used to ensure mocks for unittests are used instead of reset in Start(). - bool keep_test_loader_; - DISALLOW_COPY_AND_ASSIGN(SimpleDataSource); }; diff --git a/webkit/glue/media/simple_data_source_unittest.cc b/webkit/glue/media/simple_data_source_unittest.cc index c214949..537798f 100644 --- a/webkit/glue/media/simple_data_source_unittest.cc +++ b/webkit/glue/media/simple_data_source_unittest.cc @@ -6,15 +6,9 @@ #include "media/base/filters.h" #include "media/base/mock_filter_host.h" #include "media/base/mock_filters.h" -#include "net/base/net_errors.h" -#include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" -#include "third_party/WebKit/WebKit/chromium/public/WebURLError.h" -#include "third_party/WebKit/WebKit/chromium/public/WebURLLoader.h" -#include "third_party/WebKit/WebKit/chromium/public/WebURLRequest.h" -#include "third_party/WebKit/WebKit/chromium/public/WebURLResponse.h" +#include "webkit/glue/media/mock_media_resource_loader_bridge_factory.h" #include "webkit/glue/media/simple_data_source.h" -#include "webkit/glue/mock_webframe.h" -#include "webkit/glue/mock_weburlloader_impl.h" +#include "webkit/glue/mock_resource_loader_bridge.h" using ::testing::_; using ::testing::DoAll; @@ -27,11 +21,6 @@ using ::testing::SetArgumentPointee; using ::testing::StrictMock; using ::testing::WithArgs; -using WebKit::WebURLError; -using WebKit::WebURLLoader; -using WebKit::WebURLRequest; -using WebKit::WebURLResponse; - namespace { const int kDataSize = 1024; @@ -50,56 +39,68 @@ namespace webkit_glue { class SimpleDataSourceTest : public testing::Test { public: SimpleDataSourceTest() { + bridge_factory_.reset( + new NiceMock<MockMediaResourceLoaderBridgeFactory>()); + bridge_.reset(new NiceMock<MockResourceLoaderBridge>()); + for (int i = 0; i < kDataSize; ++i) { data_[i] = i; } } virtual ~SimpleDataSourceTest() { - ignore_result(frame_.release()); + if (bridge_.get()) + EXPECT_CALL(*bridge_, OnDestroy()); + if (bridge_factory_.get()) + EXPECT_CALL(*bridge_factory_, OnDestroy()); } void InitializeDataSource(const char* url) { - gurl_ = GURL(url); - - frame_.reset(new NiceMock<MockWebFrame>()); - url_loader_ = new NiceMock<MockWebURLLoader>(); - data_source_ = new SimpleDataSource(MessageLoop::current(), - frame_.get()); + bridge_factory_.get()); + CHECK(data_source_); // There is no need to provide a message loop to data source. data_source_->set_host(&host_); - data_source_->SetURLLoaderForTest(url_loader_); + // First a bridge is created. InSequence s; + EXPECT_CALL(*bridge_factory_, CreateBridge(GURL(url), _, -1, -1)) + .WillOnce(Return(bridge_.get())); + EXPECT_CALL(*bridge_, Start(data_source_.get())) + .WillOnce(Return(true)); data_source_->Initialize(url, callback_.NewCallback()); + MessageLoop::current()->RunAllPending(); } void RequestSucceeded(bool is_loaded) { - WebURLResponse response(gurl_); - response.setExpectedContentLength(kDataSize); + ResourceResponseInfo info; + info.content_length = kDataSize; - data_source_->didReceiveResponse(NULL, response); + data_source_->OnReceivedResponse(info, false); 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); - } + for (int i = 0; i < kDataSize; ++i) + data_source_->OnReceivedData(data_ + i, 1); EXPECT_CALL(host_, SetLoaded(is_loaded)); InSequence s; + EXPECT_CALL(*bridge_, OnDestroy()) + .WillOnce(Invoke(this, &SimpleDataSourceTest::ReleaseBridge)); EXPECT_CALL(host_, SetTotalBytes(kDataSize)); EXPECT_CALL(host_, SetBufferedBytes(kDataSize)); EXPECT_CALL(callback_, OnFilterCallback()); EXPECT_CALL(callback_, OnCallbackDestroyed()); - data_source_->didFinishLoading(NULL, 0); + URLRequestStatus status; + status.set_status(URLRequestStatus::SUCCESS); + status.set_os_error(0); + data_source_->OnCompletedRequest(status, "", base::Time()); // Let the tasks to be executed. MessageLoop::current()->RunAllPending(); @@ -107,23 +108,28 @@ class SimpleDataSourceTest : public testing::Test { void RequestFailed() { InSequence s; + EXPECT_CALL(*bridge_, OnDestroy()) + .WillOnce(Invoke(this, &SimpleDataSourceTest::ReleaseBridge)); EXPECT_CALL(host_, SetError(media::PIPELINE_ERROR_NETWORK)); EXPECT_CALL(callback_, OnFilterCallback()); EXPECT_CALL(callback_, OnCallbackDestroyed()); - WebURLError error; - error.reason = net::ERR_FAILED; - data_source_->didFail(NULL, error); + URLRequestStatus status; + status.set_status(URLRequestStatus::FAILED); + status.set_os_error(100); + data_source_->OnCompletedRequest(status, "", base::Time()); // Let the tasks to be executed. MessageLoop::current()->RunAllPending(); } void DestroyDataSource() { + EXPECT_CALL(*bridge_factory_, OnDestroy()) + .WillOnce(Invoke(this, &SimpleDataSourceTest::ReleaseBridgeFactory)); + StrictMock<media::MockFilterCallback> callback; EXPECT_CALL(callback, OnFilterCallback()); EXPECT_CALL(callback, OnCallbackDestroyed()); - data_source_->Stop(callback.NewCallback()); MessageLoop::current()->RunAllPending(); @@ -142,17 +148,23 @@ class SimpleDataSourceTest : public testing::Test { } } + void ReleaseBridge() { + ignore_result(bridge_.release()); + } + + void ReleaseBridgeFactory() { + ignore_result(bridge_factory_.release()); + } + MOCK_METHOD1(ReadCallback, void(size_t size)); protected: - GURL gurl_; scoped_ptr<MessageLoop> message_loop_; - NiceMock<MockWebURLLoader>* url_loader_; + scoped_ptr<NiceMock<MockMediaResourceLoaderBridgeFactory> > bridge_factory_; + scoped_ptr<NiceMock<MockResourceLoaderBridge> > bridge_; scoped_refptr<SimpleDataSource> data_source_; StrictMock<media::MockFilterHost> host_; StrictMock<media::MockFilterCallback> callback_; - scoped_ptr<NiceMock<MockWebFrame> > frame_; - char data_[kDataSize]; DISALLOW_COPY_AND_ASSIGN(SimpleDataSourceTest); @@ -177,16 +189,13 @@ TEST_F(SimpleDataSourceTest, InitializeFile) { } TEST_F(SimpleDataSourceTest, InitializeData) { - frame_.reset(new NiceMock<MockWebFrame>()); - url_loader_ = new NiceMock<MockWebURLLoader>(); - data_source_ = new SimpleDataSource(MessageLoop::current(), - frame_.get()); + bridge_factory_.get()); EXPECT_TRUE(data_source_->IsUrlSupported(kDataUrl)); + CHECK(data_source_); // 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_, SetLoaded(true)); EXPECT_CALL(host_, SetTotalBytes(sizeof(kDataUrlDecoded))); @@ -209,7 +218,9 @@ TEST_F(SimpleDataSourceTest, RequestFailed) { TEST_F(SimpleDataSourceTest, StopWhenDownloading) { InitializeDataSource(kHttpUrl); - EXPECT_CALL(*url_loader_, cancel()); + EXPECT_CALL(*bridge_, Cancel()); + EXPECT_CALL(*bridge_, OnDestroy()) + .WillOnce(Invoke(this, &SimpleDataSourceTest::ReleaseBridge)); EXPECT_CALL(callback_, OnCallbackDestroyed()); DestroyDataSource(); } diff --git a/webkit/glue/mock_webframe.h b/webkit/glue/mock_webframe.h deleted file mode 100644 index 9d6c70b..0000000 --- a/webkit/glue/mock_webframe.h +++ /dev/null @@ -1,352 +0,0 @@ -// Copyright (c) 2010 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. - -#ifndef WEBKIT_GLUE_MOCK_WEBFRAME_H_ -#define WEBKIT_GLUE_MOCK_WEBFRAME_H_ - -#include "testing/gmock/include/gmock/gmock.h" -#include "third_party/WebKit/WebKit/chromium/public/WebDocument.h" -#include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" -#include "third_party/WebKit/WebKit/chromium/public/WebHistoryItem.h" -#include "third_party/WebKit/WebKit/chromium/public/WebInputElement.h" -#include "third_party/WebKit/WebKit/chromium/public/WebPerformance.h" -#include "third_party/WebKit/WebKit/chromium/public/WebRange.h" -#include "third_party/WebKit/WebKit/chromium/public/WebRect.h" -#include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h" -#include "third_party/WebKit/WebKit/chromium/public/WebSize.h" -#include "third_party/WebKit/WebKit/chromium/public/WebString.h" -#include "v8/include/v8.h" - -using WebKit::WebAnimationController; -using WebKit::WebCanvas; -using WebKit::WebConsoleMessage; -using WebKit::WebData; -using WebKit::WebDocument; -using WebKit::WebElement; -using WebKit::WebFindOptions; -using WebKit::WebFormElement; -using WebKit::WebFrame; -using WebKit::WebHistoryItem; -using WebKit::WebInputElement; -using WebKit::WebPasswordAutocompleteListener; -using WebKit::WebPerformance; -using WebKit::WebRange; -using WebKit::WebRect; -using WebKit::WebURLRequest; -using WebKit::WebSecurityOrigin; -using WebKit::WebScriptSource; -using WebKit::WebSize; -using WebKit::WebString; -using WebKit::WebURL; -using WebKit::WebURLLoader; -using WebKit::WebVector; -using WebKit::WebView; - -namespace webkit_glue { - -class MockWebFrame : public WebKit::WebFrame { - public: - MockWebFrame() { - } - - virtual ~MockWebFrame() { - } - - MOCK_METHOD2(setReferrerForRequest, void(WebURLRequest&, const WebURL&)); - MOCK_METHOD1(dispatchWillSendRequest, void(WebURLRequest&)); - - // Methods from WebFrame that we don't care to mock. - WEBKIT_API static int instanceCount() { return 0; } - WEBKIT_API static WebFrame* frameForEnteredContext() { return NULL; } - WEBKIT_API static WebFrame* frameForCurrentContext() { return NULL; } - WEBKIT_API static WebFrame* fromFrameOwnerElement(const WebElement&) { - return NULL; - } - - virtual WebString name() const { - return WebString(); - } - virtual void setName(const WebString&) {} - virtual long long identifier() const { - return 0; - } - virtual WebURL url() const { - return WebURL(); - } - virtual WebURL favIconURL() const { - return WebURL(); - } - virtual WebURL openSearchDescriptionURL() const { - return WebURL(); - } - virtual WebString encoding() const { - return WebString(); - } - virtual void setCanHaveScrollbars(bool) {} - virtual WebSize scrollOffset() const { - return WebSize(0,0); - } - virtual WebSize contentsSize() const { - return WebSize(); - } - virtual int contentsPreferredWidth() const { - return 0; - } - virtual int documentElementScrollHeight() const { - return 0; - } - virtual bool hasVisibleContent() const { - return false; - } - virtual WebView* view() const { - return NULL; - } - virtual WebFrame* opener() const { - return NULL; - } - virtual WebFrame* parent() const { - return NULL; - } - virtual WebFrame* top() const { - return NULL; - } - virtual WebFrame* firstChild() const { - return NULL; - } - virtual WebFrame* lastChild() const { - return NULL; - } - virtual WebFrame* nextSibling() const { - return NULL; - } - virtual WebFrame* previousSibling() const { - return NULL; - } - virtual WebFrame* traverseNext(bool wrap) const { - return NULL; - } - virtual WebFrame* traversePrevious(bool wrap) const { - return NULL; - } - virtual WebFrame* findChildByName(const WebString& name) const { - return NULL; - } - virtual WebFrame* findChildByExpression(const WebString& xpath) const { - return NULL; - } - virtual WebDocument document() const { - return WebDocument(); - } - virtual void forms(WebVector<WebFormElement>&) const {} - virtual WebAnimationController* animationController() { - return NULL; - } - virtual WebPerformance performance() const { - return WebPerformance(); - } - virtual WebSecurityOrigin securityOrigin() const { - return WebSecurityOrigin(); - } - virtual void grantUniversalAccess() {} - virtual NPObject* windowObject() const { - return NULL; - } - virtual void bindToWindowObject(const WebString& name, NPObject*) {} - virtual void executeScript(const WebScriptSource&) {} - virtual void executeScriptInIsolatedWorld( - int worldId, const WebScriptSource* sources, unsigned numSources, - int extensionGroup) {} - virtual void addMessageToConsole(const WebConsoleMessage&) {} - virtual void collectGarbage() {} -#if WEBKIT_USING_V8 - virtual v8::Handle<v8::Value> executeScriptAndReturnValue( - const WebScriptSource&) { - return v8::Handle<v8::Value>(); - } - virtual v8::Local<v8::Context> mainWorldScriptContext() const { - return v8::Local<v8::Context>(); - } -#endif - virtual bool insertStyleText(const WebString& styleText, - const WebString& elementId) { - return false; - } - virtual void reload(bool ignoreCache = false) {} - virtual void loadRequest(const WebURLRequest&) {} - virtual void loadHistoryItem(const WebHistoryItem&) {} - virtual void loadData(const WebData& data, - const WebString& mimeType, - const WebString& textEncoding, - const WebURL& baseURL, - const WebURL& unreachableURL = WebURL(), - bool replace = false) {} - virtual void loadHTMLString(const WebData& html, - const WebURL& baseURL, - const WebURL& unreachableURL = WebURL(), - bool replace = false) {} - virtual bool isLoading() const { - return false; - } - virtual void stopLoading() {} - virtual WebKit::WebDataSource* provisionalDataSource() const { - return NULL; - } - virtual WebKit::WebDataSource* dataSource() const { - return NULL; - } - virtual WebHistoryItem previousHistoryItem() const { - return WebHistoryItem(); - } - virtual WebHistoryItem currentHistoryItem() const { - return WebHistoryItem(); - } - virtual void enableViewSourceMode(bool) {} - virtual bool isViewSourceModeEnabled() const { - return false; - } - // The next two methods were mocked above. - // virtual void setReferrerForRequest(WebURLRequest&, const WebURL&) {} - // virtual void dispatchWillSendRequest(WebURLRequest&) {} - virtual WebURLLoader* createAssociatedURLLoader() { - return NULL; - } - virtual void commitDocumentData(const char* data, size_t length) {} - virtual unsigned unloadListenerCount() const { - return 0; - } - virtual bool isProcessingUserGesture() const { - return false; - } - virtual bool willSuppressOpenerInNewFrame() const { - return false; - } - virtual void replaceSelection(const WebString& text) {} - virtual void insertText(const WebString& text) {} - virtual void setMarkedText(const WebString& text, - unsigned location, - unsigned length) {} - virtual void unmarkText() {} - virtual bool hasMarkedText() const { - return false; - } - virtual WebRange markedRange() const { - return WebRange(); - } - virtual bool firstRectForCharacterRange(unsigned location, - unsigned length, - WebRect&) const { - return false; - } - virtual bool executeCommand(const WebString&) { - return false; - } - virtual bool executeCommand(const WebString&, const WebString& value) { - return false; - } - virtual bool isCommandEnabled(const WebString&) const { - return false; - } - virtual void enableContinuousSpellChecking(bool) {} - virtual bool isContinuousSpellCheckingEnabled() const { - return false; - } - virtual bool hasSelection() const { - return false; - } - virtual WebRange selectionRange() const { - return WebRange(); - } - virtual WebString selectionAsText() const { - return WebString(); - } - virtual WebString selectionAsMarkup() const { - return WebString(); - } - virtual bool selectWordAroundCaret() { - return false; - } - virtual int printBegin(const WebSize& pageSize, int printerDPI = 72, - bool* useBrowserOverlays = 0) { - return 0; - } - virtual float getPrintPageShrink(int page) { - return 0; - } - virtual float printPage(int pageToPrint, WebCanvas*) { - return 0; - } - virtual void printEnd() {} - virtual bool isPageBoxVisible(int pageIndex) { - return false; - } - virtual void pageSizeAndMarginsInPixels(int pageIndex, - WebSize& pageSize, - int& marginTop, - int& marginRight, - int& marginBottom, - int& marginLeft) {} - virtual bool find(int identifier, - const WebString& searchText, - const WebFindOptions& options, - bool wrapWithinFrame, - WebRect* selectionRect) { - return false; - } - virtual void stopFinding(bool clearSelection) {} - virtual void scopeStringMatches(int identifier, - const WebString& searchText, - const WebFindOptions& options, - bool reset) {} - virtual void cancelPendingScopingEffort() {} - virtual void increaseMatchCount(int count, int identifier) {} - virtual void resetMatchCount() {} - virtual bool registerPasswordListener( - WebInputElement, - WebPasswordAutocompleteListener*) { - return false; - } - virtual void notifiyPasswordListenerOfAutocomplete( - const WebInputElement&) {} - virtual WebString contentAsText(size_t maxChars) const { - return WebString(); - } - virtual WebString contentAsMarkup() const { - return WebString(); - } - virtual WebString renderTreeAsText() const { - return WebString(); - } - virtual WebString counterValueForElementById(const WebString& id) const { - return WebString(); - } - virtual WebString markerTextForListItem(const WebElement&) const { - return WebString(); - } - virtual int pageNumberForElementById(const WebString& id, - float pageWidthInPixels, - float pageHeightInPixels) const { - return 0; - } - virtual WebRect selectionBoundsRect() const { - return WebRect(); - } - virtual bool selectionStartHasSpellingMarkerFor(int from, int length) const { - return false; - } - virtual bool pauseSVGAnimation(const WebString& animationId, - double time, - const WebString& elementId) { - return false; - } - virtual WebString layerTreeAsText() const { - return WebString(); - } - - private: - DISALLOW_COPY_AND_ASSIGN(MockWebFrame); -}; - -} // namespace webkit_glue - -#endif // WEBKIT_GLUE_MOCK_WEBFRAME_H_ diff --git a/webkit/glue/mock_weburlloader_impl.h b/webkit/glue/mock_weburlloader_impl.h deleted file mode 100644 index da50b72..0000000 --- a/webkit/glue/mock_weburlloader_impl.h +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (c) 2010 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. - -#ifndef WEBKIT_GLUE_MOCK_WEBURLLOADER_IMPL_H_ -#define WEBKIT_GLUE_MOCK_WEBURLLOADER_IMPL_H_ - -#include "testing/gmock/include/gmock/gmock.h" -#include "webkit/glue/weburlloader_impl.h" - -namespace webkit_glue { - -class MockWebURLLoader : public WebKit::WebURLLoader { - public: - MockWebURLLoader() { - } - - virtual ~MockWebURLLoader() { - } - - MOCK_METHOD4(loadSynchronously, void(const WebKit::WebURLRequest& request, - WebKit::WebURLResponse& response, - WebKit::WebURLError& error, - WebKit::WebData& data)); - MOCK_METHOD2(loadAsynchronously, void(const WebKit::WebURLRequest& request, - WebKit::WebURLLoaderClient* client)); - MOCK_METHOD0(cancel, void()); - MOCK_METHOD1(setDefersLoading, void(bool value)); - - private: - DISALLOW_COPY_AND_ASSIGN(MockWebURLLoader); -}; - -} // namespace webkit_glue - -#endif // WEBKIT_GLUE_MOCK_WEBURLLOADER_IMPL_H_ diff --git a/webkit/glue/multipart_response_delegate.cc b/webkit/glue/multipart_response_delegate.cc index b8c7758..99a9e4c 100644 --- a/webkit/glue/multipart_response_delegate.cc +++ b/webkit/glue/multipart_response_delegate.cc @@ -316,8 +316,7 @@ bool MultipartResponseDelegate::ReadMultipartBoundary( bool MultipartResponseDelegate::ReadContentRanges( const WebURLResponse& response, int* content_range_lower_bound, - int* content_range_upper_bound, - int* content_range_instance_size) { + int* content_range_upper_bound) { std::string content_range = response.httpHeaderField("Content-Range").utf8(); if (content_range.empty()) { @@ -337,20 +336,12 @@ bool MultipartResponseDelegate::ReadContentRanges( // Skip over the initial space. byte_range_lower_bound_start_offset++; - // Find the lower bound. size_t byte_range_lower_bound_end_offset = content_range.find("-", byte_range_lower_bound_start_offset); if (byte_range_lower_bound_end_offset == std::string::npos) { return false; } - size_t byte_range_lower_bound_characters = - byte_range_lower_bound_end_offset - byte_range_lower_bound_start_offset; - std::string byte_range_lower_bound = - content_range.substr(byte_range_lower_bound_start_offset, - byte_range_lower_bound_characters); - - // Find the upper bound. size_t byte_range_upper_bound_start_offset = byte_range_lower_bound_end_offset + 1; @@ -360,31 +351,16 @@ bool MultipartResponseDelegate::ReadContentRanges( return false; } - size_t byte_range_upper_bound_characters = - byte_range_upper_bound_end_offset - byte_range_upper_bound_start_offset; - std::string byte_range_upper_bound = - content_range.substr(byte_range_upper_bound_start_offset, - byte_range_upper_bound_characters); - - // Find the instance size. - size_t byte_range_instance_size_start_offset = - byte_range_upper_bound_end_offset + 1; - - size_t byte_range_instance_size_end_offset = - content_range.length(); - - size_t byte_range_instance_size_characters = - byte_range_instance_size_end_offset - - byte_range_instance_size_start_offset; - std::string byte_range_instance_size = - content_range.substr(byte_range_instance_size_start_offset, - byte_range_instance_size_characters); - - if (!base::StringToInt(byte_range_lower_bound, content_range_lower_bound)) - return false; - if (!base::StringToInt(byte_range_upper_bound, content_range_upper_bound)) + if (!base::StringToInt( + content_range.begin() + byte_range_lower_bound_start_offset, + content_range.begin() + byte_range_lower_bound_end_offset, + content_range_lower_bound)) return false; - if (!base::StringToInt(byte_range_instance_size, content_range_instance_size)) + + if (!base::StringToInt( + content_range.begin() + byte_range_upper_bound_start_offset, + content_range.begin() + byte_range_upper_bound_end_offset, + content_range_upper_bound)) return false; return true; } diff --git a/webkit/glue/multipart_response_delegate.h b/webkit/glue/multipart_response_delegate.h index 0500983..aded54a 100644 --- a/webkit/glue/multipart_response_delegate.h +++ b/webkit/glue/multipart_response_delegate.h @@ -92,8 +92,7 @@ class MultipartResponseDelegate { // Returns true on success. static bool ReadContentRanges(const WebKit::WebURLResponse& response, int* content_range_lower_bound, - int* content_range_upper_bound, - int* content_range_instance_size); + int* content_range_upper_bound); private: friend class MultipartResponseDelegateTester; // For unittests. diff --git a/webkit/glue/multipart_response_delegate_unittest.cc b/webkit/glue/multipart_response_delegate_unittest.cc index 1837cb5..fab798c 100644 --- a/webkit/glue/multipart_response_delegate_unittest.cc +++ b/webkit/glue/multipart_response_delegate_unittest.cc @@ -550,12 +550,10 @@ TEST(MultipartResponseTest, MultipartContentRangesTest) { int content_range_lower_bound = 0; int content_range_upper_bound = 0; - int content_range_instance_size = 0; bool result = MultipartResponseDelegate::ReadContentRanges( response1, &content_range_lower_bound, - &content_range_upper_bound, - &content_range_instance_size); + &content_range_upper_bound); EXPECT_EQ(result, true); EXPECT_EQ(content_range_lower_bound, 1000); @@ -569,12 +567,10 @@ TEST(MultipartResponseTest, MultipartContentRangesTest) { content_range_lower_bound = 0; content_range_upper_bound = 0; - content_range_instance_size = 0; result = MultipartResponseDelegate::ReadContentRanges( response2, &content_range_lower_bound, - &content_range_upper_bound, - &content_range_instance_size); + &content_range_upper_bound); EXPECT_EQ(result, false); @@ -586,12 +582,10 @@ TEST(MultipartResponseTest, MultipartContentRangesTest) { content_range_lower_bound = 0; content_range_upper_bound = 0; - content_range_instance_size = 0; result = MultipartResponseDelegate::ReadContentRanges( response3, &content_range_lower_bound, - &content_range_upper_bound, - &content_range_instance_size); + &content_range_upper_bound); EXPECT_EQ(result, true); EXPECT_EQ(content_range_lower_bound, 1000); @@ -604,12 +598,10 @@ TEST(MultipartResponseTest, MultipartContentRangesTest) { content_range_lower_bound = 0; content_range_upper_bound = 0; - content_range_instance_size = 0; result = MultipartResponseDelegate::ReadContentRanges( response4, &content_range_lower_bound, - &content_range_upper_bound, - &content_range_instance_size); + &content_range_upper_bound); EXPECT_EQ(result, false); } diff --git a/webkit/glue/plugins/webplugin_impl.cc b/webkit/glue/plugins/webplugin_impl.cc index 3891563..cd91744 100644 --- a/webkit/glue/plugins/webplugin_impl.cc +++ b/webkit/glue/plugins/webplugin_impl.cc @@ -96,12 +96,10 @@ class MultiPartResponseClient : public WebURLLoaderClient { // response. virtual void didReceiveResponse( WebURLLoader*, const WebURLResponse& response) { - int instance_size; if (!MultipartResponseDelegate::ReadContentRanges( response, &byte_range_lower_bound_, - &byte_range_upper_bound_, - &instance_size)) { + &byte_range_upper_bound_)) { NOTREACHED(); return; } diff --git a/webkit/glue/webmediaplayer_impl.cc b/webkit/glue/webmediaplayer_impl.cc index 830a1942..f4dfcc8 100644 --- a/webkit/glue/webmediaplayer_impl.cc +++ b/webkit/glue/webmediaplayer_impl.cc @@ -244,7 +244,8 @@ WebMediaPlayerImpl::WebMediaPlayerImpl( } bool WebMediaPlayerImpl::Initialize( - WebKit::WebFrame* frame, + MediaResourceLoaderBridgeFactory* bridge_factory_simple, + MediaResourceLoaderBridgeFactory* bridge_factory_buffered, bool use_simple_data_source, scoped_refptr<WebVideoRenderer> web_video_renderer) { // Create the pipeline and its thread. @@ -274,11 +275,11 @@ bool WebMediaPlayerImpl::Initialize( // A simple data source that keeps all data in memory. scoped_refptr<SimpleDataSource> simple_data_source( - new SimpleDataSource(MessageLoop::current(), frame)); + new SimpleDataSource(MessageLoop::current(), bridge_factory_simple)); // A sophisticated data source that does memory caching. scoped_refptr<BufferedDataSource> buffered_data_source( - new BufferedDataSource(MessageLoop::current(), frame)); + new BufferedDataSource(MessageLoop::current(), bridge_factory_buffered)); proxy_->SetDataSource(buffered_data_source); if (use_simple_data_source) { diff --git a/webkit/glue/webmediaplayer_impl.h b/webkit/glue/webmediaplayer_impl.h index d1f73a0..a0224b1 100644 --- a/webkit/glue/webmediaplayer_impl.h +++ b/webkit/glue/webmediaplayer_impl.h @@ -69,10 +69,6 @@ class GURL; -namespace WebKit { -class WebFrame; -} - namespace webkit_glue { class MediaResourceLoaderBridgeFactory; @@ -180,7 +176,8 @@ class WebMediaPlayerImpl : public WebKit::WebMediaPlayer, // Finalizes initialization of the object. bool Initialize( - WebKit::WebFrame* frame, + MediaResourceLoaderBridgeFactory* bridge_factory_simple, + MediaResourceLoaderBridgeFactory* bridge_factory_buffered, bool use_simple_data_source, scoped_refptr<WebVideoRenderer> web_video_renderer); diff --git a/webkit/support/webkit_support.cc b/webkit/support/webkit_support.cc index 7183cdb..be3c88a 100644 --- a/webkit/support/webkit_support.cc +++ b/webkit/support/webkit_support.cc @@ -270,9 +270,27 @@ WebKit::WebMediaPlayer* CreateMediaPlayer(WebFrame* frame, scoped_ptr<media::FilterCollection> collection( new media::FilterCollection()); - // TODO(annacc): do we still need appcache_host? http://crbug.com/65135 - // appcache::WebApplicationCacheHostImpl* appcache_host = - // appcache::WebApplicationCacheHostImpl::FromFrame(frame); + appcache::WebApplicationCacheHostImpl* appcache_host = + appcache::WebApplicationCacheHostImpl::FromFrame(frame); + + // TODO(hclam): this is the same piece of code as in RenderView, maybe they + // should be grouped together. + webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory_simple = + new webkit_glue::MediaResourceLoaderBridgeFactory( + GURL(), // referrer + "null", // frame origin + "null", // main_frame_origin + base::GetCurrentProcId(), + appcache_host ? appcache_host->host_id() : appcache::kNoHostId, + 0); + webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory_buffered = + new webkit_glue::MediaResourceLoaderBridgeFactory( + GURL(), // referrer + "null", // frame origin + "null", // main_frame_origin + base::GetCurrentProcId(), + appcache_host ? appcache_host->host_id() : appcache::kNoHostId, + 0); scoped_refptr<webkit_glue::VideoRendererImpl> video_renderer( new webkit_glue::VideoRendererImpl(false)); @@ -280,7 +298,10 @@ WebKit::WebMediaPlayer* CreateMediaPlayer(WebFrame* frame, scoped_ptr<webkit_glue::WebMediaPlayerImpl> result( new webkit_glue::WebMediaPlayerImpl(client, collection.release())); - if (!result->Initialize(frame, false, video_renderer)) { + if (!result->Initialize(bridge_factory_simple, + bridge_factory_buffered, + false, + video_renderer)) { return NULL; } return result.release(); diff --git a/webkit/tools/test_shell/test_shell.gypi b/webkit/tools/test_shell/test_shell.gypi index 728ae77..935cbae 100644 --- a/webkit/tools/test_shell/test_shell.gypi +++ b/webkit/tools/test_shell/test_shell.gypi @@ -398,8 +398,6 @@ '../../glue/media/simple_data_source_unittest.cc', '../../glue/mimetype_unittest.cc', '../../glue/mock_resource_loader_bridge.h', - '../../glue/mock_webframe.h', - '../../glue/mock_weburlloader_impl.h', '../../glue/multipart_response_delegate_unittest.cc', '../../glue/plugins/plugin_group_unittest.cc', '../../glue/plugins/plugin_lib_unittest.cc', diff --git a/webkit/tools/test_shell/test_webview_delegate.cc b/webkit/tools/test_shell/test_webview_delegate.cc index cd95bad..50541cd 100644 --- a/webkit/tools/test_shell/test_webview_delegate.cc +++ b/webkit/tools/test_shell/test_webview_delegate.cc @@ -729,9 +729,27 @@ WebMediaPlayer* TestWebViewDelegate::createMediaPlayer( scoped_ptr<media::FilterCollection> collection( new media::FilterCollection()); - // TODO(annacc): do we still need appcache_host? http://crbug.com/65135 - // appcache::WebApplicationCacheHostImpl* appcache_host = - // appcache::WebApplicationCacheHostImpl::FromFrame(frame); + appcache::WebApplicationCacheHostImpl* appcache_host = + appcache::WebApplicationCacheHostImpl::FromFrame(frame); + + // TODO(hclam): this is the same piece of code as in RenderView, maybe they + // should be grouped together. + webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory_simple = + new webkit_glue::MediaResourceLoaderBridgeFactory( + GURL(frame->url()), // referrer + "null", // frame origin + "null", // main_frame_origin + base::GetCurrentProcId(), + appcache_host ? appcache_host->host_id() : appcache::kNoHostId, + 0); + webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory_buffered = + new webkit_glue::MediaResourceLoaderBridgeFactory( + GURL(frame->url()), // referrer + "null", // frame origin + "null", // main_frame_origin + base::GetCurrentProcId(), + appcache_host ? appcache_host->host_id() : appcache::kNoHostId, + 0); scoped_refptr<webkit_glue::VideoRendererImpl> video_renderer( new webkit_glue::VideoRendererImpl(false)); @@ -739,7 +757,10 @@ WebMediaPlayer* TestWebViewDelegate::createMediaPlayer( scoped_ptr<webkit_glue::WebMediaPlayerImpl> result( new webkit_glue::WebMediaPlayerImpl(client, collection.release())); - if (!result->Initialize(frame, false, video_renderer)) { + if (!result->Initialize(bridge_factory_simple, + bridge_factory_buffered, + false, + video_renderer)) { return NULL; } return result.release(); |