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

Side by Side Diff: third_party/WebKit/Source/modules/webaudio/BaseAudioContext.cpp

Issue 2826263002: Make DOMArrayBuffer::Transfer neuter v8::ArrayBuffers (Closed)
Patch Set: Created 3 years, 8 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010, Google Inc. All rights reserved. 2 * Copyright (C) 2010, Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 DCHECK(IsMainThread()); 278 DCHECK(IsMainThread());
279 DCHECK(audio_data); 279 DCHECK(audio_data);
280 280
281 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); 281 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state);
282 ScriptPromise promise = resolver->Promise(); 282 ScriptPromise promise = resolver->Promise();
283 283
284 float rate = IsContextClosed() ? ClosedContextSampleRate() : sampleRate(); 284 float rate = IsContextClosed() ? ClosedContextSampleRate() : sampleRate();
285 285
286 DCHECK_GT(rate, 0); 286 DCHECK_GT(rate, 0);
287 287
288 if (audio_data->IsNeutered()) { 288 DOMException* error = nullptr;
289 v8::Isolate* isolate = script_state->GetIsolate();
290 if (audio_data->IsNeuterable(isolate)) {
291 // Detach the audio array buffer from the main thread and start
292 // async decoding of the data.
293 WTF::ArrayBufferContents buffer_contents;
294 if (audio_data->Transfer(isolate, buffer_contents)) {
295 DOMArrayBuffer* audio = DOMArrayBuffer::Create(buffer_contents);
296
297 decode_audio_resolvers_.insert(resolver);
298 audio_decoder_.DecodeAsync(audio, rate, success_callback, error_callback,
299 resolver, this);
300 } else {
301 error =
302 DOMException::Create(kDataCloneError, "Cannot transfer ArrayBuffer");
303 }
304 } else {
289 // If audioData is detached (neutered) we need to reject the 305 // If audioData is detached (neutered) we need to reject the
290 // promise with an error. 306 // promise with an error.
291 DOMException* error = DOMException::Create( 307 error = DOMException::Create(kDataCloneError,
292 kDataCloneError, "Cannot decode detached ArrayBuffer"); 308 "Cannot decode detached ArrayBuffer");
309 }
310
311 if (error) {
293 resolver->Reject(error); 312 resolver->Reject(error);
294 if (error_callback) { 313 if (error_callback) {
295 error_callback->handleEvent(error); 314 error_callback->handleEvent(error);
296 } 315 }
297 } else {
298 // Detach the audio array buffer from the main thread and start
299 // async decoding of the data.
300 WTF::ArrayBufferContents buffer_contents;
301 audio_data->Transfer(buffer_contents);
302 DOMArrayBuffer* audio = DOMArrayBuffer::Create(buffer_contents);
303
304 decode_audio_resolvers_.insert(resolver);
305 audio_decoder_.DecodeAsync(audio, rate, success_callback, error_callback,
306 resolver, this);
307 } 316 }
308 317
309 return promise; 318 return promise;
310 } 319 }
311 320
312 void BaseAudioContext::HandleDecodeAudioData( 321 void BaseAudioContext::HandleDecodeAudioData(
313 AudioBuffer* audio_buffer, 322 AudioBuffer* audio_buffer,
314 ScriptPromiseResolver* resolver, 323 ScriptPromiseResolver* resolver,
315 AudioBufferCallback* success_callback, 324 AudioBufferCallback* success_callback,
316 AudioBufferCallback* error_callback) { 325 AudioBufferCallback* error_callback) {
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after
919 } 928 }
920 929
921 SecurityOrigin* BaseAudioContext::GetSecurityOrigin() const { 930 SecurityOrigin* BaseAudioContext::GetSecurityOrigin() const {
922 if (GetExecutionContext()) 931 if (GetExecutionContext())
923 return GetExecutionContext()->GetSecurityOrigin(); 932 return GetExecutionContext()->GetSecurityOrigin();
924 933
925 return nullptr; 934 return nullptr;
926 } 935 }
927 936
928 } // namespace blink 937 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698