| 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 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 #include "bindings/core/v8/ScriptState.h" | 29 #include "bindings/core/v8/ScriptState.h" |
| 30 #include "core/dom/DOMException.h" | 30 #include "core/dom/DOMException.h" |
| 31 #include "core/dom/Document.h" | 31 #include "core/dom/Document.h" |
| 32 #include "core/dom/ExceptionCode.h" | 32 #include "core/dom/ExceptionCode.h" |
| 33 #include "modules/mediastream/UserMediaController.h" | 33 #include "modules/mediastream/UserMediaController.h" |
| 34 | 34 |
| 35 namespace blink { | 35 namespace blink { |
| 36 | 36 |
| 37 MediaDevicesRequest* MediaDevicesRequest::create(ScriptState* state, UserMediaCo
ntroller* controller) | 37 MediaDevicesRequest* MediaDevicesRequest::create(ScriptState* state, UserMediaCo
ntroller* controller) |
| 38 { | 38 { |
| 39 MediaDevicesRequest* request = new MediaDevicesRequest(state, controller); | 39 return new MediaDevicesRequest(state, controller); |
| 40 request->suspendIfNeeded(); | |
| 41 return request; | |
| 42 } | 40 } |
| 43 | 41 |
| 44 MediaDevicesRequest::MediaDevicesRequest(ScriptState* state, UserMediaController
* controller) | 42 MediaDevicesRequest::MediaDevicesRequest(ScriptState* state, UserMediaController
* controller) |
| 45 : ActiveDOMObject(state->executionContext()) | 43 : ContextLifecycleObserver(state->executionContext()) |
| 46 , m_controller(controller) | 44 , m_controller(controller) |
| 47 , m_resolver(ScriptPromiseResolver::create(state)) | 45 , m_resolver(ScriptPromiseResolver::create(state)) |
| 48 { | 46 { |
| 49 } | 47 } |
| 50 | 48 |
| 51 MediaDevicesRequest::~MediaDevicesRequest() | |
| 52 { | |
| 53 } | |
| 54 | |
| 55 Document* MediaDevicesRequest::ownerDocument() | 49 Document* MediaDevicesRequest::ownerDocument() |
| 56 { | 50 { |
| 57 if (ExecutionContext* context = executionContext()) { | 51 if (ExecutionContext* context = executionContext()) { |
| 58 return toDocument(context); | 52 return toDocument(context); |
| 59 } | 53 } |
| 60 | 54 |
| 61 return 0; | 55 return 0; |
| 62 } | 56 } |
| 63 | 57 |
| 64 ScriptPromise MediaDevicesRequest::start() | 58 ScriptPromise MediaDevicesRequest::start() |
| 65 { | 59 { |
| 66 ASSERT(m_controller); | 60 ASSERT(m_controller); |
| 67 m_resolver->keepAliveWhilePending(); | 61 m_resolver->keepAliveWhilePending(); |
| 68 m_controller->requestMediaDevices(this); | 62 m_controller->requestMediaDevices(this); |
| 69 return m_resolver->promise(); | 63 return m_resolver->promise(); |
| 70 } | 64 } |
| 71 | 65 |
| 72 void MediaDevicesRequest::succeed(const MediaDeviceInfoVector& mediaDevices) | 66 void MediaDevicesRequest::succeed(const MediaDeviceInfoVector& mediaDevices) |
| 73 { | 67 { |
| 74 if (!executionContext() || !m_resolver) | 68 if (!executionContext() || !m_resolver) |
| 75 return; | 69 return; |
| 76 | 70 |
| 77 m_resolver->resolve(mediaDevices); | 71 m_resolver->resolve(mediaDevices); |
| 78 } | 72 } |
| 79 | 73 |
| 80 void MediaDevicesRequest::stop() | 74 void MediaDevicesRequest::contextDestroyed() |
| 81 { | 75 { |
| 82 m_controller.clear(); | 76 m_controller.clear(); |
| 83 m_resolver.clear(); | 77 m_resolver.clear(); |
| 84 } | 78 } |
| 85 | 79 |
| 86 DEFINE_TRACE(MediaDevicesRequest) | 80 DEFINE_TRACE(MediaDevicesRequest) |
| 87 { | 81 { |
| 88 visitor->trace(m_controller); | 82 visitor->trace(m_controller); |
| 89 visitor->trace(m_resolver); | 83 visitor->trace(m_resolver); |
| 90 ActiveDOMObject::trace(visitor); | 84 ContextLifecycleObserver::trace(visitor); |
| 91 } | 85 } |
| 92 | 86 |
| 93 } // namespace blink | 87 } // namespace blink |
| OLD | NEW |