Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/message_loop.h" | 5 #include "base/message_loop.h" |
| 6 #include "base/process_util.h" | 6 #include "base/process_util.h" |
| 7 #include "media/base/filter_host.h" | 7 #include "media/base/filter_host.h" |
| 8 #include "net/base/load_flags.h" | 8 #include "net/base/load_flags.h" |
|
scherkus (not reviewing)
2010/12/14 18:48:19
nit: alphabetize includes
annacc
2010/12/14 21:10:17
Done.
| |
| 9 #include "net/base/data_url.h" | 9 #include "net/base/data_url.h" |
| 10 #include "net/http/http_util.h" | |
| 10 #include "net/url_request/url_request_status.h" | 11 #include "net/url_request/url_request_status.h" |
| 11 #include "third_party/WebKit/WebKit/chromium/public/WebKit.h" | 12 #include "third_party/WebKit/WebKit/chromium/public/WebKit.h" |
| 12 #include "third_party/WebKit/WebKit/chromium/public/WebKitClient.h" | 13 #include "third_party/WebKit/WebKit/chromium/public/WebKitClient.h" |
| 13 #include "webkit/glue/media/simple_data_source.h" | 14 #include "webkit/glue/media/simple_data_source.h" |
| 14 #include "webkit/glue/webkit_glue.h" | 15 #include "webkit/glue/webkit_glue.h" |
| 15 | 16 |
| 16 namespace { | |
| 17 | |
| 18 const char kHttpScheme[] = "http"; | |
| 19 const char kHttpsScheme[] = "https"; | |
| 20 const char kDataScheme[] = "data"; | |
| 21 | |
| 22 // A helper method that accepts only HTTP, HTTPS and FILE protocol. | |
| 23 bool IsDataProtocol(const GURL& url) { | |
| 24 return url.SchemeIs(kDataScheme); | |
| 25 } | |
| 26 | |
| 27 } // namespace | |
| 28 | |
| 29 namespace webkit_glue { | 17 namespace webkit_glue { |
| 30 | 18 |
| 31 SimpleDataSource::SimpleDataSource( | 19 SimpleDataSource::SimpleDataSource( |
| 32 MessageLoop* render_loop, | 20 MessageLoop* render_loop, |
| 33 WebKit::WebFrame* frame) | 21 WebKit::WebFrame* frame) |
| 34 : render_loop_(render_loop), | 22 : render_loop_(render_loop), |
| 35 frame_(frame), | 23 frame_(frame), |
| 36 size_(-1), | 24 size_(-1), |
| 37 single_origin_(true), | 25 single_origin_(true), |
| 38 state_(UNINITIALIZED), | 26 state_(UNINITIALIZED), |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 226 AutoLock auto_lock(lock_); | 214 AutoLock auto_lock(lock_); |
| 227 | 215 |
| 228 // We may have stopped. | 216 // We may have stopped. |
| 229 if (state_ == STOPPED) | 217 if (state_ == STOPPED) |
| 230 return; | 218 return; |
| 231 | 219 |
| 232 CHECK(frame_); | 220 CHECK(frame_); |
| 233 | 221 |
| 234 DCHECK_EQ(state_, INITIALIZING); | 222 DCHECK_EQ(state_, INITIALIZING); |
| 235 | 223 |
| 236 if (IsDataProtocol(url_)) { | 224 if (net::HttpUtil::IsDataProtocol(url_)) { |
| 237 // If this using data protocol, we just need to decode it. | 225 // If this using data protocol, we just need to decode it. |
| 238 std::string mime_type, charset; | 226 std::string mime_type, charset; |
| 239 bool success = net::DataURL::Parse(url_, &mime_type, &charset, &data_); | 227 bool success = net::DataURL::Parse(url_, &mime_type, &charset, &data_); |
| 240 | 228 |
| 241 // Don't care about the mime-type just proceed if decoding was successful. | 229 // Don't care about the mime-type just proceed if decoding was successful. |
| 242 size_ = data_.length(); | 230 size_ = data_.length(); |
| 243 DoneInitialization_Locked(success); | 231 DoneInitialization_Locked(success); |
| 244 } else { | 232 } else { |
| 245 // Prepare the request. | 233 // Prepare the request. |
| 246 WebKit::WebURLRequest request(url_); | 234 WebKit::WebURLRequest request(url_); |
| 247 | 235 |
| 248 frame_->setReferrerForRequest(request, WebKit::WebURL()); | 236 frame_->setReferrerForRequest(request, WebKit::WebURL()); |
| 249 // TODO(annacc): we should be using createAssociatedURLLoader() instead? | |
| 250 frame_->dispatchWillSendRequest(request); | |
| 251 | 237 |
| 252 // This flag is for unittests as we don't want to reset |url_loader| | 238 // This flag is for unittests as we don't want to reset |url_loader| |
| 253 if (!keep_test_loader_) | 239 if (!keep_test_loader_) |
| 254 url_loader_.reset(WebKit::webKitClient()->createURLLoader()); | 240 url_loader_.reset(frame_->createAssociatedURLLoader()); |
| 255 | 241 |
| 256 // Start the resource loading. | 242 // Start the resource loading. |
| 257 url_loader_->loadAsynchronously(request, this); | 243 url_loader_->loadAsynchronously(request, this); |
| 258 } | 244 } |
| 259 } | 245 } |
| 260 | 246 |
| 261 void SimpleDataSource::CancelTask() { | 247 void SimpleDataSource::CancelTask() { |
| 262 DCHECK(MessageLoop::current() == render_loop_); | 248 DCHECK(MessageLoop::current() == render_loop_); |
| 263 AutoLock auto_lock(lock_); | 249 AutoLock auto_lock(lock_); |
| 264 DCHECK_EQ(state_, STOPPED); | 250 DCHECK_EQ(state_, STOPPED); |
| 265 | 251 |
| 266 // Cancel any pending requests. | 252 // Cancel any pending requests. |
| 267 if (url_loader_.get()) { | 253 if (url_loader_.get()) { |
| 268 url_loader_->cancel(); | 254 url_loader_->cancel(); |
| 269 url_loader_.reset(); | 255 url_loader_.reset(); |
| 270 } | 256 } |
| 271 } | 257 } |
| 272 | 258 |
| 273 void SimpleDataSource::DoneInitialization_Locked(bool success) { | 259 void SimpleDataSource::DoneInitialization_Locked(bool success) { |
| 274 lock_.AssertAcquired(); | 260 lock_.AssertAcquired(); |
| 275 if (success) { | 261 if (success) { |
| 276 state_ = INITIALIZED; | 262 state_ = INITIALIZED; |
| 277 host()->SetTotalBytes(size_); | 263 host()->SetTotalBytes(size_); |
| 278 host()->SetBufferedBytes(size_); | 264 host()->SetBufferedBytes(size_); |
| 279 // If scheme is file or data, say we are loaded. | 265 // If scheme is file or data, say we are loaded. |
| 280 host()->SetLoaded(url_.SchemeIsFile() || IsDataProtocol(url_)); | 266 host()->SetLoaded(url_.SchemeIsFile() || net::HttpUtil::IsDataProtocol(url_) ); |
|
scherkus (not reviewing)
2010/12/14 18:48:19
>80 chars
annacc
2010/12/14 21:10:17
Done.
| |
| 281 } else { | 267 } else { |
| 282 host()->SetError(media::PIPELINE_ERROR_NETWORK); | 268 host()->SetError(media::PIPELINE_ERROR_NETWORK); |
| 283 } | 269 } |
| 284 initialize_callback_->Run(); | 270 initialize_callback_->Run(); |
| 285 initialize_callback_.reset(); | 271 initialize_callback_.reset(); |
| 286 } | 272 } |
| 287 | 273 |
| 288 } // namespace webkit_glue | 274 } // namespace webkit_glue |
| OLD | NEW |