Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2014 Google Inc. All rights reserved. | 2 * Copyright (C) 2014 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 |
| 11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
| 12 * | 12 * |
| 13 * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. ``AS IS'' AND ANY |
| 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE INC. OR |
| 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #include "config.h" | 26 #include "config.h" |
| 27 | 27 |
| 28 #include "modules/mediastream/MediaDevicesRequest.h" | 28 #include "modules/mediastream/MediaDevicesRequest.h" |
| 29 | 29 |
| 30 #include "bindings/core/v8/ExceptionState.h" | 30 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 31 #include "bindings/core/v8/ScriptState.h" | |
| 32 #include "core/dom/DOMException.h" | |
| 31 #include "core/dom/Document.h" | 33 #include "core/dom/Document.h" |
| 34 #include "core/dom/ExceptionCode.h" | |
| 32 #include "modules/mediastream/UserMediaController.h" | 35 #include "modules/mediastream/UserMediaController.h" |
| 33 | 36 |
| 34 namespace blink { | 37 namespace blink { |
| 35 | 38 |
| 36 MediaDevicesRequest* MediaDevicesRequest::create(ExecutionContext* context, User MediaController* controller, MediaDeviceInfoCallback* callback, ExceptionState& exceptionState) | 39 MediaDevicesRequest* MediaDevicesRequest::create(ScriptState* state, UserMediaCo ntroller* controller) |
| 37 { | 40 { |
| 38 MediaDevicesRequest* request = new MediaDevicesRequest(context, controller, callback); | 41 MediaDevicesRequest* request = new MediaDevicesRequest(state, controller); |
| 39 request->suspendIfNeeded(); | 42 request->suspendIfNeeded(); |
| 40 return request; | 43 return request; |
| 41 } | 44 } |
| 42 | 45 |
| 43 MediaDevicesRequest::MediaDevicesRequest(ExecutionContext* context, UserMediaCon troller* controller, MediaDeviceInfoCallback* callback) | 46 MediaDevicesRequest::MediaDevicesRequest(ScriptState* state, UserMediaController * controller) |
| 44 : ActiveDOMObject(context) | 47 : ActiveDOMObject(state->executionContext()) |
| 45 , m_controller(controller) | 48 , m_controller(controller) |
| 46 , m_callback(callback) | 49 , m_resolver(ScriptPromiseResolver::create(state)) |
| 47 { | 50 { |
| 48 } | 51 } |
| 49 | 52 |
| 50 MediaDevicesRequest::~MediaDevicesRequest() | 53 MediaDevicesRequest::~MediaDevicesRequest() |
| 51 { | 54 { |
| 52 } | 55 } |
| 53 | 56 |
| 54 Document* MediaDevicesRequest::ownerDocument() | 57 Document* MediaDevicesRequest::ownerDocument() |
| 55 { | 58 { |
| 56 if (ExecutionContext* context = executionContext()) { | 59 if (ExecutionContext* context = executionContext()) { |
| 57 return toDocument(context); | 60 return toDocument(context); |
| 58 } | 61 } |
| 59 | 62 |
| 60 return 0; | 63 return 0; |
| 61 } | 64 } |
| 62 | 65 |
| 63 void MediaDevicesRequest::start() | 66 ScriptPromise MediaDevicesRequest::start() |
| 64 { | 67 { |
| 65 if (m_controller) | 68 if (m_controller) { |
| 69 m_resolver->keepAliveWhilePending(); | |
| 66 m_controller->requestMediaDevices(this); | 70 m_controller->requestMediaDevices(this); |
| 71 return m_resolver->promise(); | |
| 72 } | |
| 73 | |
| 74 return ScriptPromise::rejectWithDOMException(m_resolver->scriptState(), DOME xception::create(NotSupportedError, "No media device controller available")); | |
|
Peter Beverloo
2015/06/18 14:28:50
I'd still like to know when this occurs (dito with
| |
| 67 } | 75 } |
| 68 | 76 |
| 69 void MediaDevicesRequest::succeed(const MediaDeviceInfoVector& mediaDevices) | 77 void MediaDevicesRequest::succeed(const MediaDeviceInfoVector& mediaDevices) |
| 70 { | 78 { |
| 71 if (!executionContext() || !m_callback) | 79 if (!executionContext() || !m_resolver) |
| 72 return; | 80 return; |
| 73 | 81 |
| 74 m_callback->handleEvent(mediaDevices); | 82 m_resolver->resolve(mediaDevices); |
| 75 } | 83 } |
| 76 | 84 |
| 77 void MediaDevicesRequest::stop() | 85 void MediaDevicesRequest::stop() |
| 78 { | 86 { |
| 79 m_callback.clear(); | |
| 80 m_controller.clear(); | 87 m_controller.clear(); |
| 88 m_resolver.clear(); | |
| 81 } | 89 } |
| 82 | 90 |
| 83 DEFINE_TRACE(MediaDevicesRequest) | 91 DEFINE_TRACE(MediaDevicesRequest) |
| 84 { | 92 { |
| 85 visitor->trace(m_controller); | 93 visitor->trace(m_controller); |
| 86 visitor->trace(m_callback); | 94 visitor->trace(m_resolver); |
| 87 ActiveDOMObject::trace(visitor); | 95 ActiveDOMObject::trace(visitor); |
| 88 } | 96 } |
| 89 | 97 |
| 90 } // namespace blink | 98 } // namespace blink |
| OLD | NEW |