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

Side by Side Diff: third_party/WebKit/Source/modules/imagecapture/ImageCapture.cpp

Issue 1952463002: Media Stream Image Capture (4): wire takePhoto and implement in FakeVCDevice (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: tommi@ and mlamouri@ comments Created 4 years, 7 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
« no previous file with comments | « third_party/WebKit/LayoutTests/fast/imagecapture/ImageCapture-takePhoto.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "modules/imagecapture/ImageCapture.h" 5 #include "modules/imagecapture/ImageCapture.h"
6 6
7 #include "bindings/core/v8/CallbackPromiseAdapter.h" 7 #include "bindings/core/v8/CallbackPromiseAdapter.h"
8 #include "bindings/core/v8/ScriptPromiseResolver.h" 8 #include "bindings/core/v8/ScriptPromiseResolver.h"
9 #include "core/dom/DOMException.h" 9 #include "core/dom/DOMException.h"
10 #include "core/dom/ExceptionCode.h" 10 #include "core/dom/ExceptionCode.h"
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 Platform::current()->serviceRegistry()->connectToRemoteService(mojo::GetProx y(&m_service)); 135 Platform::current()->serviceRegistry()->connectToRemoteService(mojo::GetProx y(&m_service));
136 136
137 m_service.set_connection_error_handler(createBaseCallback(bind(&ImageCapture ::onServiceConnectionError, WeakPersistentThisPointer<ImageCapture>(this)))); 137 m_service.set_connection_error_handler(createBaseCallback(bind(&ImageCapture ::onServiceConnectionError, WeakPersistentThisPointer<ImageCapture>(this))));
138 } 138 }
139 139
140 void ImageCapture::onTakePhoto(ScriptPromiseResolver* resolver, const String& mi meType, mojo::WTFArray<uint8_t> data) 140 void ImageCapture::onTakePhoto(ScriptPromiseResolver* resolver, const String& mi meType, mojo::WTFArray<uint8_t> data)
141 { 141 {
142 if (!m_serviceRequests.contains(resolver)) 142 if (!m_serviceRequests.contains(resolver))
143 return; 143 return;
144 144
145 DCHECK(!data.is_null()); 145 if (data.is_null() || data.empty()) {
146 const auto& storage = data.storage(); 146 resolver->reject(DOMException::create(UnknownError, "platform error"));
147 resolver->resolve(Blob::create(storage.data(), storage.size(), mimeType)); 147 } else {
148 const auto& storage = data.storage();
149 resolver->resolve(Blob::create(storage.data(), storage.size(), mimeType) );
150 }
148 m_serviceRequests.remove(resolver); 151 m_serviceRequests.remove(resolver);
149 } 152 }
150 153
151 void ImageCapture::onServiceConnectionError() 154 void ImageCapture::onServiceConnectionError()
152 { 155 {
153 m_service.reset(); 156 m_service.reset();
154 for (ScriptPromiseResolver* resolver : m_serviceRequests) 157 for (ScriptPromiseResolver* resolver : m_serviceRequests)
155 resolver->reject(DOMException::create(NotFoundError, kNoServiceError)); 158 resolver->reject(DOMException::create(NotFoundError, kNoServiceError));
156 m_serviceRequests.clear(); 159 m_serviceRequests.clear();
157 } 160 }
158 161
159 DEFINE_TRACE(ImageCapture) 162 DEFINE_TRACE(ImageCapture)
160 { 163 {
161 visitor->trace(m_streamTrack); 164 visitor->trace(m_streamTrack);
162 visitor->trace(m_serviceRequests); 165 visitor->trace(m_serviceRequests);
163 EventTargetWithInlineData::trace(visitor); 166 EventTargetWithInlineData::trace(visitor);
164 ContextLifecycleObserver::trace(visitor); 167 ContextLifecycleObserver::trace(visitor);
165 } 168 }
166 169
167 } // namespace blink 170 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/fast/imagecapture/ImageCapture-takePhoto.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698