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

Side by Side Diff: webkit/media/webmediaplayer_impl.cc

Issue 10543007: Add CORS-awareness to HTML5 media elements. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "webkit/media/webmediaplayer_impl.h" 5 #include "webkit/media/webmediaplayer_impl.h"
6 6
7 #include <limits> 7 #include <limits>
8 #include <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 // Also our timers are not very accurate (especially for ogg), which becomes 74 // Also our timers are not very accurate (especially for ogg), which becomes
75 // evident at low speeds and on Vista. Since other speeds are risky and outside 75 // evident at low speeds and on Vista. Since other speeds are risky and outside
76 // the norms, we think 1/16x to 16x is a safe and useful range for now. 76 // the norms, we think 1/16x to 16x is a safe and useful range for now.
77 const float kMinRate = 0.0625f; 77 const float kMinRate = 0.0625f;
78 const float kMaxRate = 16.0f; 78 const float kMaxRate = 16.0f;
79 79
80 } // namespace 80 } // namespace
81 81
82 namespace webkit_media { 82 namespace webkit_media {
83 83
84 #define COMPILE_ASSERT_MATCHING_ENUM(name) \
85 COMPILE_ASSERT(static_cast<int>(WebKit::WebMediaPlayer::name) == \
86 static_cast<int>(BufferedResourceLoader::k ## name), \
87 mismatching_enums)
88 COMPILE_ASSERT_MATCHING_ENUM(Unspecified);
89 COMPILE_ASSERT_MATCHING_ENUM(Anonymous);
90 COMPILE_ASSERT_MATCHING_ENUM(UseCredentials);
91 #undef COMPILE_ASSERT_MATCHING_ENUM
92
84 WebMediaPlayerImpl::WebMediaPlayerImpl( 93 WebMediaPlayerImpl::WebMediaPlayerImpl(
85 WebKit::WebFrame* frame, 94 WebKit::WebFrame* frame,
86 WebKit::WebMediaPlayerClient* client, 95 WebKit::WebMediaPlayerClient* client,
87 base::WeakPtr<WebMediaPlayerDelegate> delegate, 96 base::WeakPtr<WebMediaPlayerDelegate> delegate,
88 media::FilterCollection* collection, 97 media::FilterCollection* collection,
89 WebKit::WebAudioSourceProvider* audio_source_provider, 98 WebKit::WebAudioSourceProvider* audio_source_provider,
90 media::MessageLoopFactory* message_loop_factory, 99 media::MessageLoopFactory* message_loop_factory,
91 MediaStreamClient* media_stream_client, 100 MediaStreamClient* media_stream_client,
92 media::MediaLog* media_log) 101 media::MediaLog* media_log)
93 : frame_(frame), 102 : frame_(frame),
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 if (url.SchemeIs("file")) return kFileURLScheme; 200 if (url.SchemeIs("file")) return kFileURLScheme;
192 if (url.SchemeIs("blob")) return kBlobURLScheme; 201 if (url.SchemeIs("blob")) return kBlobURLScheme;
193 if (url.SchemeIs("data")) return kDataURLScheme; 202 if (url.SchemeIs("data")) return kDataURLScheme;
194 if (url.SchemeIs("filesystem")) return kFileSystemScheme; 203 if (url.SchemeIs("filesystem")) return kFileSystemScheme;
195 return kUnknownURLScheme; 204 return kUnknownURLScheme;
196 } 205 }
197 206
198 } // anonymous namespace 207 } // anonymous namespace
199 208
200 void WebMediaPlayerImpl::load(const WebKit::WebURL& url) { 209 void WebMediaPlayerImpl::load(const WebKit::WebURL& url) {
210 load(url, Unspecified);
211 }
212
213 void WebMediaPlayerImpl::load(const WebKit::WebURL& url,
214 CrossOriginAttribute cross_origin_attribute) {
201 DCHECK_EQ(main_loop_, MessageLoop::current()); 215 DCHECK_EQ(main_loop_, MessageLoop::current());
202 216
203 GURL gurl(url); 217 GURL gurl(url);
204 UMA_HISTOGRAM_ENUMERATION("Media.URLScheme", URLScheme(gurl), kMaxURLScheme); 218 UMA_HISTOGRAM_ENUMERATION("Media.URLScheme", URLScheme(gurl), kMaxURLScheme);
205 219
206 // Handle any volume/preload changes that occured before load(). 220 // Handle any volume/preload changes that occured before load().
207 setVolume(GetClient()->volume()); 221 setVolume(GetClient()->volume());
208 setPreload(GetClient()->preload()); 222 setPreload(GetClient()->preload());
209 223
210 SetNetworkState(WebMediaPlayer::NetworkStateLoading); 224 SetNetworkState(WebMediaPlayer::NetworkStateLoading);
211 SetReadyState(WebMediaPlayer::ReadyStateHaveNothing); 225 SetReadyState(WebMediaPlayer::ReadyStateHaveNothing);
212 media_log_->AddEvent(media_log_->CreateLoadEvent(url.spec())); 226 media_log_->AddEvent(media_log_->CreateLoadEvent(url.spec()));
213 227
214 // Media streams pipelines can start immediately. 228 // Media streams pipelines can start immediately.
215 if (BuildMediaStreamCollection(url, media_stream_client_, 229 if (BuildMediaStreamCollection(url, media_stream_client_,
216 message_loop_factory_.get(), 230 message_loop_factory_.get(),
217 filter_collection_.get())) { 231 filter_collection_.get())) {
232 DCHECK_EQ(cross_origin_attribute, Unspecified);
scherkus (not reviewing) 2012/06/06 00:44:36 so adding a crossorigin attribute to a media strea
Ami GONE FROM CHROMIUM 2012/06/06 00:59:29 Done.
218 StartPipeline(); 233 StartPipeline();
219 return; 234 return;
220 } 235 }
221 236
222 // Media source pipelines can start immediately. 237 // Media source pipelines can start immediately.
223 scoped_refptr<media::FFmpegVideoDecoder> video_decoder; 238 scoped_refptr<media::FFmpegVideoDecoder> video_decoder;
224 if (BuildMediaSourceCollection(url, GetClient()->sourceURL(), proxy_, 239 if (BuildMediaSourceCollection(url, GetClient()->sourceURL(), proxy_,
225 message_loop_factory_.get(), 240 message_loop_factory_.get(),
226 filter_collection_.get(), 241 filter_collection_.get(),
227 &video_decoder)) { 242 &video_decoder)) {
243 DCHECK_EQ(cross_origin_attribute, Unspecified);
228 proxy_->set_video_decoder(video_decoder); 244 proxy_->set_video_decoder(video_decoder);
229 StartPipeline(); 245 StartPipeline();
230 return; 246 return;
231 } 247 }
232 248
233 // Otherwise it's a regular request which requires resolving the URL first. 249 // Otherwise it's a regular request which requires resolving the URL first.
234 proxy_->set_data_source( 250 proxy_->set_data_source(
235 new BufferedDataSource(main_loop_, frame_, media_log_)); 251 new BufferedDataSource(main_loop_, frame_, media_log_));
236 proxy_->data_source()->Initialize(url, base::Bind( 252 proxy_->data_source()->Initialize(
237 &WebMediaPlayerImpl::DataSourceInitialized, 253 url, static_cast<BufferedResourceLoader::CrossOriginAttribute>(
238 base::Unretained(this), gurl)); 254 cross_origin_attribute),
255 base::Bind(
256 &WebMediaPlayerImpl::DataSourceInitialized,
257 base::Unretained(this), gurl));
239 258
240 is_local_source_ = !gurl.SchemeIs("http") && !gurl.SchemeIs("https"); 259 is_local_source_ = !gurl.SchemeIs("http") && !gurl.SchemeIs("https");
241 260
242 BuildDefaultCollection(proxy_->data_source(), 261 BuildDefaultCollection(proxy_->data_source(),
243 message_loop_factory_.get(), 262 message_loop_factory_.get(),
244 filter_collection_.get(), 263 filter_collection_.get(),
245 &video_decoder); 264 &video_decoder);
246 proxy_->set_video_decoder(video_decoder); 265 proxy_->set_video_decoder(video_decoder);
247 } 266 }
248 267
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 return; 374 return;
356 } 375 }
357 376
358 #define COMPILE_ASSERT_MATCHING_ENUM(webkit_name, chromium_name) \ 377 #define COMPILE_ASSERT_MATCHING_ENUM(webkit_name, chromium_name) \
359 COMPILE_ASSERT(static_cast<int>(WebMediaPlayer::webkit_name) == \ 378 COMPILE_ASSERT(static_cast<int>(WebMediaPlayer::webkit_name) == \
360 static_cast<int>(webkit_media::chromium_name), \ 379 static_cast<int>(webkit_media::chromium_name), \
361 mismatching_enums) 380 mismatching_enums)
362 COMPILE_ASSERT_MATCHING_ENUM(PreloadNone, NONE); 381 COMPILE_ASSERT_MATCHING_ENUM(PreloadNone, NONE);
363 COMPILE_ASSERT_MATCHING_ENUM(PreloadMetaData, METADATA); 382 COMPILE_ASSERT_MATCHING_ENUM(PreloadMetaData, METADATA);
364 COMPILE_ASSERT_MATCHING_ENUM(PreloadAuto, AUTO); 383 COMPILE_ASSERT_MATCHING_ENUM(PreloadAuto, AUTO);
384 #undef COMPILE_ASSERT_MATCHING_ENUM
365 385
366 void WebMediaPlayerImpl::setPreload(WebMediaPlayer::Preload preload) { 386 void WebMediaPlayerImpl::setPreload(WebMediaPlayer::Preload preload) {
367 DCHECK_EQ(main_loop_, MessageLoop::current()); 387 DCHECK_EQ(main_loop_, MessageLoop::current());
368 388
369 if (proxy_ && proxy_->data_source()) { 389 if (proxy_ && proxy_->data_source()) {
370 // XXX: Why do I need to use webkit_media:: prefix? clang complains! 390 // XXX: Why do I need to use webkit_media:: prefix? clang complains!
371 proxy_->data_source()->SetPreload( 391 proxy_->data_source()->SetPreload(
372 static_cast<webkit_media::Preload>(preload)); 392 static_cast<webkit_media::Preload>(preload));
373 } 393 }
374 } 394 }
(...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after
1032 return audio_source_provider_; 1052 return audio_source_provider_;
1033 } 1053 }
1034 1054
1035 void WebMediaPlayerImpl::IncrementExternallyAllocatedMemory() { 1055 void WebMediaPlayerImpl::IncrementExternallyAllocatedMemory() {
1036 DCHECK_EQ(main_loop_, MessageLoop::current()); 1056 DCHECK_EQ(main_loop_, MessageLoop::current());
1037 incremented_externally_allocated_memory_ = true; 1057 incremented_externally_allocated_memory_ = true;
1038 v8::V8::AdjustAmountOfExternalAllocatedMemory(kPlayerExtraMemory); 1058 v8::V8::AdjustAmountOfExternalAllocatedMemory(kPlayerExtraMemory);
1039 } 1059 }
1040 1060
1041 } // namespace webkit_media 1061 } // namespace webkit_media
OLDNEW
« webkit/media/webmediaplayer_impl.h ('K') | « webkit/media/webmediaplayer_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698