Commit 5f8b274c authored by hubbe's avatar hubbe Committed by Commit bot

Bugfix for cross-origin check

The code is mistaking a missing reader for an error, but readers are now destroyed and re-created on demand.
Adding a new variable to explicitly track failures fixes the problem.

BUG=639690

Review-Url: https://codereview.chromium.org/2271313002
Cr-Commit-Position: refs/heads/master@{#414218}
parent bac8641d
...@@ -113,6 +113,7 @@ MultibufferDataSource::MultibufferDataSource( ...@@ -113,6 +113,7 @@ MultibufferDataSource::MultibufferDataSource(
total_bytes_(kPositionNotSpecified), total_bytes_(kPositionNotSpecified),
streaming_(false), streaming_(false),
loading_(false), loading_(false),
failed_(false),
render_task_runner_(task_runner), render_task_runner_(task_runner),
url_index_(url_index), url_index_(url_index),
frame_(frame), frame_(frame),
...@@ -185,6 +186,7 @@ void MultibufferDataSource::OnRedirect( ...@@ -185,6 +186,7 @@ void MultibufferDataSource::OnRedirect(
const scoped_refptr<UrlData>& destination) { const scoped_refptr<UrlData>& destination) {
if (!destination) { if (!destination) {
// A failure occured. // A failure occured.
failed_ = true;
if (!init_cb_.is_null()) { if (!init_cb_.is_null()) {
render_task_runner_->PostTask( render_task_runner_->PostTask(
FROM_HERE, FROM_HERE,
...@@ -256,8 +258,7 @@ bool MultibufferDataSource::DidPassCORSAccessCheck() const { ...@@ -256,8 +258,7 @@ bool MultibufferDataSource::DidPassCORSAccessCheck() const {
// If init_cb is set, we initialization is not finished yet. // If init_cb is set, we initialization is not finished yet.
if (!init_cb_.is_null()) if (!init_cb_.is_null())
return false; return false;
// Loader will be false if there was a failure. if (failed_)
if (!reader_)
return false; return false;
return true; return true;
} }
......
...@@ -174,6 +174,9 @@ class MEDIA_BLINK_EXPORT MultibufferDataSource ...@@ -174,6 +174,9 @@ class MEDIA_BLINK_EXPORT MultibufferDataSource
// |downloading_cb_|. // |downloading_cb_|.
bool loading_; bool loading_;
// True if a failure has occured.
bool failed_;
// The task runner of the render thread. // The task runner of the render thread.
const scoped_refptr<base::SingleThreadTaskRunner> render_task_runner_; const scoped_refptr<base::SingleThreadTaskRunner> render_task_runner_;
......
...@@ -1448,4 +1448,34 @@ TEST_F(MultibufferDataSourceTest, FileSizeLessThanBlockSize) { ...@@ -1448,4 +1448,34 @@ TEST_F(MultibufferDataSourceTest, FileSizeLessThanBlockSize) {
Stop(); Stop();
} }
TEST_F(MultibufferDataSourceTest, DidPassCORSAccessTest) {
InitializeWithCORS(kHttpUrl, true, UrlData::CORS_ANONYMOUS);
set_preload(MultibufferDataSource::NONE);
WebURLResponse response1 =
response_generator_->GeneratePartial206(0, kDataSize - 1);
response1.setWasFetchedViaServiceWorker(true);
response1.setOriginalURLViaServiceWorker(GURL(kHttpDifferentOriginUrl));
WebURLResponse response2 =
response_generator_->GeneratePartial206(kDataSize, kDataSize * 2 - 1);
EXPECT_CALL(host_, SetTotalBytes(kFileSize));
EXPECT_CALL(host_, AddBufferedByteRange(0, kDataSize));
EXPECT_CALL(*this, ReadCallback(kDataSize));
EXPECT_FALSE(data_source_->DidPassCORSAccessCheck());
Respond(response1);
ReceiveData(kDataSize);
ReadAt(0);
EXPECT_TRUE(loading());
EXPECT_TRUE(data_source_->DidPassCORSAccessCheck());
FinishLoading();
// Verify that if reader_ is null, DidPassCORSAccessCheck still returns true.
data_source_->Stop();
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(data_source_->DidPassCORSAccessCheck());
}
} // namespace media } // namespace media
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment