diff options
author | scherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-26 02:23:47 +0000 |
---|---|---|
committer | scherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-26 02:23:47 +0000 |
commit | cf31d6fbef998e90f09a0004c9e429784396b855 (patch) | |
tree | 590ff1da367af7f3100cb6dfd44096cd08cfdd33 /webkit/glue/media | |
parent | e0fcc515ac27f502b4e391fb7c1c865171bf7581 (diff) | |
download | chromium_src-cf31d6fbef998e90f09a0004c9e429784396b855.zip chromium_src-cf31d6fbef998e90f09a0004c9e429784396b855.tar.gz chromium_src-cf31d6fbef998e90f09a0004c9e429784396b855.tar.bz2 |
Add HasSingleOrigin() to WebDataSource.
BUG=25432, 55745
TEST=test_shell_tests and layout tests
Review URL: http://codereview.chromium.org/3984002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@63845 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue/media')
-rw-r--r-- | webkit/glue/media/buffered_data_source.cc | 12 | ||||
-rw-r--r-- | webkit/glue/media/buffered_data_source.h | 7 | ||||
-rw-r--r-- | webkit/glue/media/buffered_data_source_unittest.cc | 14 | ||||
-rw-r--r-- | webkit/glue/media/simple_data_source.cc | 21 | ||||
-rw-r--r-- | webkit/glue/media/simple_data_source.h | 8 | ||||
-rw-r--r-- | webkit/glue/media/web_data_source.h | 5 |
6 files changed, 60 insertions, 7 deletions
diff --git a/webkit/glue/media/buffered_data_source.cc b/webkit/glue/media/buffered_data_source.cc index 43d21f7..f97e7b5 100644 --- a/webkit/glue/media/buffered_data_source.cc +++ b/webkit/glue/media/buffered_data_source.cc @@ -529,6 +529,7 @@ BufferedDataSource::BufferedDataSource( : total_bytes_(kPositionNotSpecified), loaded_(false), streaming_(false), + single_origin_(true), bridge_factory_(bridge_factory), loader_(NULL), network_activity_(false), @@ -646,6 +647,11 @@ bool BufferedDataSource::IsStreaming() { return streaming_; } +bool BufferedDataSource::HasSingleOrigin() { + DCHECK(MessageLoop::current() == render_loop_); + return single_origin_; +} + void BufferedDataSource::Abort() { DCHECK(MessageLoop::current() == render_loop_); @@ -873,6 +879,9 @@ void BufferedDataSource::HttpInitialStartCallback(int error) { DCHECK(MessageLoop::current() == render_loop_); DCHECK(loader_.get()); + // Check if the request ended up at a different origin via redirect. + single_origin_ = url_.GetOrigin() == loader_->url().GetOrigin(); + int64 instance_size = loader_->instance_size(); bool partial_response = loader_->partial_response(); bool success = error == net::OK; @@ -937,6 +946,9 @@ void BufferedDataSource::NonHttpInitialStartCallback(int error) { DCHECK(MessageLoop::current() == render_loop_); DCHECK(loader_.get()); + // Check if the request ended up at a different origin via redirect. + single_origin_ = url_.GetOrigin() == loader_->url().GetOrigin(); + int64 instance_size = loader_->instance_size(); bool success = error == net::OK && instance_size != kPositionNotSpecified; diff --git a/webkit/glue/media/buffered_data_source.h b/webkit/glue/media/buffered_data_source.h index dfb78d5..2af9e84 100644 --- a/webkit/glue/media/buffered_data_source.h +++ b/webkit/glue/media/buffered_data_source.h @@ -106,6 +106,9 @@ class BufferedResourceLoader : // Returns true if network is currently active. virtual bool network_activity() { return !completed_ && !deferred_; } + // Returns resulting URL. + virtual const GURL& url() { return url_; } + ///////////////////////////////////////////////////////////////////////////// // webkit_glue::ResourceLoaderBridge::Peer implementations. virtual void OnUploadProgress(uint64 position, uint64 size) {} @@ -240,6 +243,7 @@ class BufferedDataSource : public WebDataSource { } // webkit_glue::WebDataSource implementation. + virtual bool HasSingleOrigin(); virtual void Abort(); protected: @@ -334,6 +338,9 @@ class BufferedDataSource : public WebDataSource { // i.e. range request is not supported. bool streaming_; + // 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_; diff --git a/webkit/glue/media/buffered_data_source_unittest.cc b/webkit/glue/media/buffered_data_source_unittest.cc index d41bbe2..929d8d9 100644 --- a/webkit/glue/media/buffered_data_source_unittest.cc +++ b/webkit/glue/media/buffered_data_source_unittest.cc @@ -27,6 +27,7 @@ using ::testing::Invoke; using ::testing::InvokeWithoutArgs; using ::testing::NotNull; using ::testing::Return; +using ::testing::ReturnRef; using ::testing::SetArgumentPointee; using ::testing::StrictMock; using ::testing::NiceMock; @@ -525,6 +526,7 @@ class MockBufferedResourceLoader : public BufferedResourceLoader { MOCK_METHOD0(instance_size, int64()); MOCK_METHOD0(partial_response, bool()); MOCK_METHOD0(network_activity, bool()); + MOCK_METHOD0(url, const GURL&()); MOCK_METHOD0(GetBufferedFirstBytePosition, int64()); MOCK_METHOD0(GetBufferedLastBytePosition, int64()); @@ -622,6 +624,8 @@ class BufferedDataSourceTest : public testing::Test { // to be created. if (partial_response && (error == net::ERR_INVALID_RESPONSE)) { // Verify that the initial loader is stopped. + EXPECT_CALL(*loader_, url()) + .WillRepeatedly(ReturnRef(gurl_)); EXPECT_CALL(*loader_, Stop()); // Replace loader_ with a new instance. @@ -642,10 +646,12 @@ class BufferedDataSourceTest : public testing::Test { .WillByDefault(DeleteArg<3>()); StrictMock<media::MockFilterCallback> callback; - EXPECT_CALL(*loader_, instance_size()) - .WillRepeatedly(Return(instance_size)); - EXPECT_CALL(*loader_, partial_response()) - .WillRepeatedly(Return(partial_response)); + ON_CALL(*loader_, instance_size()) + .WillByDefault(Return(instance_size)); + ON_CALL(*loader_, partial_response()) + .WillByDefault(Return(partial_response)); + ON_CALL(*loader_, url()) + .WillByDefault(ReturnRef(gurl_)); if (initialized_ok) { // Expected loaded or not. EXPECT_CALL(host_, SetLoaded(loaded)); diff --git a/webkit/glue/media/simple_data_source.cc b/webkit/glue/media/simple_data_source.cc index d5a4c3b..291928e 100644 --- a/webkit/glue/media/simple_data_source.cc +++ b/webkit/glue/media/simple_data_source.cc @@ -34,6 +34,7 @@ SimpleDataSource::SimpleDataSource( : render_loop_(render_loop), bridge_factory_(bridge_factory), size_(-1), + single_origin_(true), state_(UNINITIALIZED) { DCHECK(render_loop); } @@ -112,7 +113,9 @@ bool SimpleDataSource::OnReceivedRedirect( const webkit_glue::ResourceResponseInfo& info, bool* has_new_first_party_for_cookies, GURL* new_first_party_for_cookies) { - SetURL(new_url); + DCHECK(MessageLoop::current() == render_loop_); + single_origin_ = url_.GetOrigin() == new_url.GetOrigin(); + // TODO(wtc): should we return a new first party for cookies URL? *has_new_first_party_for_cookies = false; return true; @@ -121,16 +124,19 @@ bool SimpleDataSource::OnReceivedRedirect( void SimpleDataSource::OnReceivedResponse( const webkit_glue::ResourceResponseInfo& info, bool content_filtered) { + DCHECK(MessageLoop::current() == render_loop_); size_ = info.content_length; } void SimpleDataSource::OnReceivedData(const char* data, int len) { + DCHECK(MessageLoop::current() == render_loop_); data_.append(data, len); } 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 // longer valid. @@ -151,6 +157,16 @@ void SimpleDataSource::OnCompletedRequest(const URLRequestStatus& status, DoneInitialization_Locked(status.is_success()); } +bool SimpleDataSource::HasSingleOrigin() { + DCHECK(MessageLoop::current() == render_loop_); + return single_origin_; +} + +void SimpleDataSource::Abort() { + DCHECK(MessageLoop::current() == render_loop_); + NOTIMPLEMENTED(); +} + void SimpleDataSource::SetURL(const GURL& url) { url_ = url; media_format_.Clear(); @@ -160,8 +176,8 @@ void SimpleDataSource::SetURL(const GURL& url) { } void SimpleDataSource::StartTask() { - AutoLock auto_lock(lock_); DCHECK(MessageLoop::current() == render_loop_); + AutoLock auto_lock(lock_); // We may have stopped. if (state_ == STOPPED) @@ -186,6 +202,7 @@ void SimpleDataSource::StartTask() { } void SimpleDataSource::CancelTask() { + DCHECK(MessageLoop::current() == render_loop_); AutoLock auto_lock(lock_); DCHECK_EQ(state_, STOPPED); diff --git a/webkit/glue/media/simple_data_source.h b/webkit/glue/media/simple_data_source.h index f264b8c..ff1e247 100644 --- a/webkit/glue/media/simple_data_source.h +++ b/webkit/glue/media/simple_data_source.h @@ -14,13 +14,14 @@ #include "base/scoped_ptr.h" #include "media/base/filters.h" #include "webkit/glue/media/media_resource_loader_bridge_factory.h" +#include "webkit/glue/media/web_data_source.h" class MessageLoop; class WebMediaPlayerDelegateImpl; namespace webkit_glue { -class SimpleDataSource : public media::DataSource, +class SimpleDataSource : public WebDataSource, public webkit_glue::ResourceLoaderBridge::Peer { public: SimpleDataSource( @@ -56,6 +57,10 @@ class SimpleDataSource : public media::DataSource, const std::string& security_info, const base::Time& completion_time); + // webkit_glue::WebDataSource implementation. + virtual bool HasSingleOrigin(); + virtual void Abort(); + private: // Updates |url_| and |media_format_| with the given URL. void SetURL(const GURL& url); @@ -82,6 +87,7 @@ class SimpleDataSource : public media::DataSource, GURL url_; std::string data_; int64 size_; + bool single_origin_; // Simple state tracking variable. enum State { diff --git a/webkit/glue/media/web_data_source.h b/webkit/glue/media/web_data_source.h index 2bbfd1c..956ac9e 100644 --- a/webkit/glue/media/web_data_source.h +++ b/webkit/glue/media/web_data_source.h @@ -16,6 +16,11 @@ class WebDataSource : public media::DataSource { WebDataSource(); virtual ~WebDataSource(); + // Returns true if the media resource has a single origin, false otherwise. + // + // Method called on the render thread. + virtual bool HasSingleOrigin() = 0; + // This method is used to unblock any read calls that would cause the // media pipeline to stall. // |