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

Side by Side Diff: Source/modules/mediastream/MediaDevices.cpp

Issue 1233173002: Have ScriptPromiseResolver on the Oilpan heap always. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: tidy unit tests Created 5 years, 5 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 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "config.h" 5 #include "config.h"
6 #include "modules/mediastream/MediaDevices.h" 6 #include "modules/mediastream/MediaDevices.h"
7 7
8 #include "bindings/core/v8/ScriptPromise.h" 8 #include "bindings/core/v8/ScriptPromise.h"
9 #include "bindings/core/v8/ScriptPromiseResolver.h" 9 #include "bindings/core/v8/ScriptPromiseResolver.h"
10 #include "bindings/core/v8/ScriptState.h" 10 #include "bindings/core/v8/ScriptState.h"
(...skipping 16 matching lines...) Expand all
27 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(NotSupportedError, "No media device controller available; is this a detac hed window?")); 27 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(NotSupportedError, "No media device controller available; is this a detac hed window?"));
28 28
29 MediaDevicesRequest* request = MediaDevicesRequest::create(scriptState, user Media); 29 MediaDevicesRequest* request = MediaDevicesRequest::create(scriptState, user Media);
30 return request->start(); 30 return request->start();
31 } 31 }
32 32
33 namespace { 33 namespace {
34 34
35 class PromiseSuccessCallback final : public NavigatorUserMediaSuccessCallback { 35 class PromiseSuccessCallback final : public NavigatorUserMediaSuccessCallback {
36 public: 36 public:
37 PromiseSuccessCallback(PassRefPtrWillBeRawPtr<ScriptPromiseResolver> resolve r) 37 PromiseSuccessCallback(ScriptPromiseResolver* resolver)
38 : m_resolver(resolver) 38 : m_resolver(resolver)
39 { 39 {
40 } 40 }
41 41
haraken 2015/07/17 01:40:36 I'm just curious, but is it valid that we reach th
sof 2015/07/17 09:43:26 But then handleEvent() would be called for the pai
42 ~PromiseSuccessCallback() 42 ~PromiseSuccessCallback()
43 { 43 {
44 } 44 }
45 45
46 void handleEvent(MediaStream* stream) 46 void handleEvent(MediaStream* stream)
47 { 47 {
48 m_resolver->resolve(stream); 48 m_resolver->resolve(stream);
49 } 49 }
50 50
51 DEFINE_INLINE_VIRTUAL_TRACE() 51 DEFINE_INLINE_VIRTUAL_TRACE()
52 { 52 {
53 visitor->trace(m_resolver); 53 visitor->trace(m_resolver);
54 NavigatorUserMediaSuccessCallback::trace(visitor); 54 NavigatorUserMediaSuccessCallback::trace(visitor);
55 } 55 }
56 56
57 private: 57 private:
58 RefPtrWillBeMember<ScriptPromiseResolver> m_resolver; 58 Member<ScriptPromiseResolver> m_resolver;
59 }; 59 };
60 60
61 class PromiseErrorCallback final : public NavigatorUserMediaErrorCallback { 61 class PromiseErrorCallback final : public NavigatorUserMediaErrorCallback {
62 public: 62 public:
63 PromiseErrorCallback(PassRefPtrWillBeRawPtr<ScriptPromiseResolver> resolver) 63 PromiseErrorCallback(ScriptPromiseResolver* resolver)
64 : m_resolver(resolver) 64 : m_resolver(resolver)
65 { 65 {
66 } 66 }
67 67
68 ~PromiseErrorCallback() 68 ~PromiseErrorCallback()
69 { 69 {
70 } 70 }
71 71
72 void handleEvent(NavigatorUserMediaError* error) 72 void handleEvent(NavigatorUserMediaError* error)
73 { 73 {
74 m_resolver->reject(error); 74 m_resolver->reject(error);
75 } 75 }
76 76
77 DEFINE_INLINE_VIRTUAL_TRACE() 77 DEFINE_INLINE_VIRTUAL_TRACE()
78 { 78 {
79 visitor->trace(m_resolver); 79 visitor->trace(m_resolver);
80 NavigatorUserMediaErrorCallback::trace(visitor); 80 NavigatorUserMediaErrorCallback::trace(visitor);
81 } 81 }
82 82
83 private: 83 private:
84 RefPtrWillBeMember<ScriptPromiseResolver> m_resolver; 84 Member<ScriptPromiseResolver> m_resolver;
85 }; 85 };
86 86
87 } // namespace 87 } // namespace
88 88
89 ScriptPromise MediaDevices::getUserMedia(ScriptState* scriptState, const Diction ary& options, ExceptionState& exceptionState) 89 ScriptPromise MediaDevices::getUserMedia(ScriptState* scriptState, const Diction ary& options, ExceptionState& exceptionState)
90 { 90 {
91 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState); 91 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
92 92
93 NavigatorUserMediaSuccessCallback* successCallback = new PromiseSuccessCallb ack(resolver); 93 NavigatorUserMediaSuccessCallback* successCallback = new PromiseSuccessCallb ack(resolver);
94 NavigatorUserMediaErrorCallback* errorCallback = new PromiseErrorCallback(re solver); 94 NavigatorUserMediaErrorCallback* errorCallback = new PromiseErrorCallback(re solver);
95 95
96 Document* document = toDocument(scriptState->executionContext()); 96 Document* document = toDocument(scriptState->executionContext());
97 UserMediaController* userMedia = UserMediaController::from(document->frame() ); 97 UserMediaController* userMedia = UserMediaController::from(document->frame() );
98 if (!userMedia) 98 if (!userMedia)
99 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(NotSupportedError, "No media device controller available; is this a detac hed window?")); 99 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(NotSupportedError, "No media device controller available; is this a detac hed window?"));
100 100
101 UserMediaRequest* request = UserMediaRequest::create(document, userMedia, op tions, successCallback, errorCallback, exceptionState); 101 UserMediaRequest* request = UserMediaRequest::create(document, userMedia, op tions, successCallback, errorCallback, exceptionState);
102 if (!request) { 102 if (!request) {
103 ASSERT(exceptionState.hadException()); 103 ASSERT(exceptionState.hadException());
104 return exceptionState.reject(scriptState); 104 return exceptionState.reject(scriptState);
105 } 105 }
106 106
107 request->start(); 107 request->start();
108 return resolver->promise(); 108 return resolver->promise();
109 } 109 }
110 110
111 } // namespace blink 111 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698