Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(498)

Side by Side Diff: webkit/glue/media/buffered_data_source.cc

Issue 216022: Allow <audio> to work in extension (Closed)
Patch Set: omments Created 11 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/renderer/renderer_glue.cc ('k') | webkit/glue/webkit_glue.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this
2 // source code is governed by a BSD-style license that can be found in the 2 // source code is governed by a BSD-style license that can be found in the
3 // LICENSE file. 3 // LICENSE file.
4 4
5 #include "base/compiler_specific.h" 5 #include "base/compiler_specific.h"
6 #include "base/message_loop.h" 6 #include "base/message_loop.h"
7 #include "base/process_util.h" 7 #include "base/process_util.h"
8 #include "base/stl_util-inl.h" 8 #include "base/stl_util-inl.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "chrome/common/extensions/url_pattern.h" 10 #include "chrome/common/extensions/url_pattern.h"
11 #include "media/base/filter_host.h" 11 #include "media/base/filter_host.h"
12 #include "net/base/load_flags.h" 12 #include "net/base/load_flags.h"
13 #include "net/base/net_errors.h" 13 #include "net/base/net_errors.h"
14 #include "net/http/http_response_headers.h" 14 #include "net/http/http_response_headers.h"
15 #include "webkit/glue/media/buffered_data_source.h" 15 #include "webkit/glue/media/buffered_data_source.h"
16 #include "webkit/glue/webkit_glue.h"
16 17
17 namespace { 18 namespace {
18 19
19 const char kHttpScheme[] = "http"; 20 const char kHttpScheme[] = "http";
20 const char kHttpsScheme[] = "https"; 21 const char kHttpsScheme[] = "https";
21 const int64 kPositionNotSpecified = -1; 22 const int64 kPositionNotSpecified = -1;
22 const int kHttpOK = 200; 23 const int kHttpOK = 200;
23 const int kHttpPartialContent = 206; 24 const int kHttpPartialContent = 206;
24 25
25 // Define the number of bytes in a megabyte. 26 // Define the number of bytes in a megabyte.
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 143
143 void BufferedResourceLoader::Read(int64 position, 144 void BufferedResourceLoader::Read(int64 position,
144 int read_size, 145 int read_size,
145 uint8* buffer, 146 uint8* buffer,
146 net::CompletionCallback* read_callback) { 147 net::CompletionCallback* read_callback) {
147 DCHECK(!read_callback_.get()); 148 DCHECK(!read_callback_.get());
148 DCHECK(buffer_.get()); 149 DCHECK(buffer_.get());
149 DCHECK(read_callback); 150 DCHECK(read_callback);
150 DCHECK(buffer); 151 DCHECK(buffer);
151 152
152 // Saves the parameter of reading. 153 // Save the parameter of reading.
153 read_callback_.reset(read_callback); 154 read_callback_.reset(read_callback);
154 read_position_ = position; 155 read_position_ = position;
155 read_size_ = read_size; 156 read_size_ = read_size;
156 read_buffer_ = buffer; 157 read_buffer_ = buffer;
157 158
158 // If read position is beyond the instance size, we cannot read there. 159 // If read position is beyond the instance size, we cannot read there.
159 if (instance_size_ != kPositionNotSpecified && 160 if (instance_size_ != kPositionNotSpecified &&
160 instance_size_ <= read_position_) { 161 instance_size_ <= read_position_) {
161 DoneRead(0); 162 DoneRead(0);
162 return; 163 return;
(...skipping 28 matching lines...) Expand all
191 } 192 }
192 193
193 ///////////////////////////////////////////////////////////////////////////// 194 /////////////////////////////////////////////////////////////////////////////
194 // BufferedResourceLoader, 195 // BufferedResourceLoader,
195 // webkit_glue::ResourceLoaderBridge::Peer implementations 196 // webkit_glue::ResourceLoaderBridge::Peer implementations
196 bool BufferedResourceLoader::OnReceivedRedirect( 197 bool BufferedResourceLoader::OnReceivedRedirect(
197 const GURL& new_url, 198 const GURL& new_url,
198 const webkit_glue::ResourceLoaderBridge::ResponseInfo& info) { 199 const webkit_glue::ResourceLoaderBridge::ResponseInfo& info) {
199 DCHECK(bridge_.get()); 200 DCHECK(bridge_.get());
200 201
201 // Saves the new URL. 202 // Save the new URL.
202 url_ = new_url; 203 url_ = new_url;
203 204
204 // The load may have been stopped and |start_callback| is destroyed. 205 // The load may have been stopped and |start_callback| is destroyed.
205 // In this case we shouldn't do anything. 206 // In this case we shouldn't do anything.
206 if (!start_callback_.get()) 207 if (!start_callback_.get())
207 return true; 208 return true;
209
210 if (!IsProtocolSupportedForMedia(new_url)) {
211 DoneStart(net::ERR_ADDRESS_INVALID);
212 Stop();
213 return false;
214 }
208 return true; 215 return true;
209 } 216 }
210 217
211 void BufferedResourceLoader::OnReceivedResponse( 218 void BufferedResourceLoader::OnReceivedResponse(
212 const webkit_glue::ResourceLoaderBridge::ResponseInfo& info, 219 const webkit_glue::ResourceLoaderBridge::ResponseInfo& info,
213 bool content_filtered) { 220 bool content_filtered) {
214 DCHECK(bridge_.get()); 221 DCHECK(bridge_.get());
215 222
216 // The loader may have been stopped and |start_callback| is destroyed. 223 // The loader may have been stopped and |start_callback| is destroyed.
217 // In this case we shouldn't do anything. 224 // In this case we shouldn't do anything.
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 // method is to be overidded so as to provide a different timeout value 483 // method is to be overidded so as to provide a different timeout value
477 // for testing purpose. 484 // for testing purpose.
478 base::TimeDelta BufferedDataSource::GetTimeoutMilliseconds() { 485 base::TimeDelta BufferedDataSource::GetTimeoutMilliseconds() {
479 return base::TimeDelta::FromMilliseconds(kTimeoutMilliseconds); 486 return base::TimeDelta::FromMilliseconds(kTimeoutMilliseconds);
480 } 487 }
481 488
482 ///////////////////////////////////////////////////////////////////////////// 489 /////////////////////////////////////////////////////////////////////////////
483 // BufferedDataSource, media::MediaFilter implementation 490 // BufferedDataSource, media::MediaFilter implementation
484 void BufferedDataSource::Initialize(const std::string& url, 491 void BufferedDataSource::Initialize(const std::string& url,
485 media::FilterCallback* callback) { 492 media::FilterCallback* callback) {
493 // Saves the url.
494 url_ = GURL(url);
495
496 if (!IsProtocolSupportedForMedia(url_)) {
497 // This method is called on the thread where host() lives so it is safe
498 // to make this call.
499 host()->SetError(media::PIPELINE_ERROR_NETWORK);
500 callback->Run();
501 delete callback;
502 return;
503 }
504
486 DCHECK(callback); 505 DCHECK(callback);
487 initialize_callback_.reset(callback); 506 initialize_callback_.reset(callback);
488 507
489 // Saves the url.
490 url_ = GURL(url);
491
492 media_format_.SetAsString(media::MediaFormat::kMimeType, 508 media_format_.SetAsString(media::MediaFormat::kMimeType,
493 media::mime_type::kApplicationOctetStream); 509 media::mime_type::kApplicationOctetStream);
494 media_format_.SetAsString(media::MediaFormat::kURL, url); 510 media_format_.SetAsString(media::MediaFormat::kURL, url);
495 511
496 // Post a task to complete the initialization task. 512 // Post a task to complete the initialization task.
497 render_loop_->PostTask(FROM_HERE, 513 render_loop_->PostTask(FROM_HERE,
498 NewRunnableMethod(this, &BufferedDataSource::InitializeTask)); 514 NewRunnableMethod(this, &BufferedDataSource::InitializeTask));
499 } 515 }
500 516
501 void BufferedDataSource::Stop() { 517 void BufferedDataSource::Stop() {
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 render_loop_->PostTask(FROM_HERE, 850 render_loop_->PostTask(FROM_HERE,
835 NewRunnableMethod(this, &BufferedDataSource::SwapLoaderTask, 851 NewRunnableMethod(this, &BufferedDataSource::SwapLoaderTask,
836 CreateLoader(read_position_, -1))); 852 CreateLoader(read_position_, -1)));
837 } else { 853 } else {
838 loader_->Stop(); 854 loader_->Stop();
839 DoneRead(error); 855 DoneRead(error);
840 } 856 }
841 } 857 }
842 858
843 } // namespace webkit_glue 859 } // namespace webkit_glue
OLDNEW
« no previous file with comments | « chrome/renderer/renderer_glue.cc ('k') | webkit/glue/webkit_glue.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698