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

Side by Side Diff: third_party/WebKit/Source/modules/shapedetection/ShapeDetector.cpp

Issue 2522143002: ShapeDetection: split mojom into face and barcode interfaces (Closed)
Patch Set: Created 4 years, 1 month 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 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/shapedetection/ShapeDetector.h" 5 #include "modules/shapedetection/ShapeDetector.h"
6 6
7 #include "core/dom/DOMException.h" 7 #include "core/dom/DOMException.h"
8 #include "core/dom/DOMRect.h" 8 #include "core/dom/DOMRect.h"
9 #include "core/dom/Document.h" 9 #include "core/dom/Document.h"
10 #include "core/fetch/ImageResource.h" 10 #include "core/fetch/ImageResource.h"
(...skipping 26 matching lines...) Expand all
37 37
38 if (value.isHTMLVideoElement()) 38 if (value.isHTMLVideoElement())
39 return value.getAsHTMLVideoElement(); 39 return value.getAsHTMLVideoElement();
40 40
41 return nullptr; 41 return nullptr;
42 } 42 }
43 43
44 } // anonymous namespace 44 } // anonymous namespace
45 45
46 ShapeDetector::ShapeDetector(LocalFrame& frame) { 46 ShapeDetector::ShapeDetector(LocalFrame& frame) {
47 DCHECK(!m_service.is_bound()); 47 DCHECK(!m_faceService.is_bound());
48 DCHECK(frame.interfaceProvider()); 48 DCHECK(frame.interfaceProvider());
49 frame.interfaceProvider()->getInterface(mojo::GetProxy(&m_service)); 49 frame.interfaceProvider()->getInterface(mojo::GetProxy(&m_faceService));
50 } 50 }
51 51
52 ScriptPromise ShapeDetector::detectShapes( 52 ScriptPromise ShapeDetector::detectShapes(
53 ScriptState* scriptState, 53 ScriptState* scriptState,
54 DetectorType detectorType, 54 DetectorType detectorType,
55 const CanvasImageSourceUnion& imageSource) { 55 const CanvasImageSourceUnion& imageSource) {
56 CanvasImageSource* imageSourceInternal = toImageSourceInternal(imageSource); 56 CanvasImageSource* imageSourceInternal = toImageSourceInternal(imageSource);
57 57
58 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); 58 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
59 ScriptPromise promise = resolver->promise(); 59 ScriptPromise promise = resolver->promise();
60 60
61 if (!m_barcodeService.is_bound()) {
62 scriptState->domWindow()->frame()->interfaceProvider()->getInterface(
63 mojo::GetProxy(&m_barcodeService));
64 }
65
61 if (!imageSourceInternal) { 66 if (!imageSourceInternal) {
62 // TODO(mcasas): Implement more CanvasImageSources, https://crbug.com/659138 67 // TODO(mcasas): Implement more CanvasImageSources, https://crbug.com/659138
63 NOTIMPLEMENTED() << "Unsupported CanvasImageSource"; 68 NOTIMPLEMENTED() << "Unsupported CanvasImageSource";
64 resolver->reject( 69 resolver->reject(
65 DOMException::create(NotFoundError, "Unsupported source.")); 70 DOMException::create(NotFoundError, "Unsupported source."));
66 return promise; 71 return promise;
67 } 72 }
68 73
69 if (imageSourceInternal->wouldTaintOrigin( 74 if (imageSourceInternal->wouldTaintOrigin(
70 scriptState->getExecutionContext()->getSecurityOrigin())) { 75 scriptState->getExecutionContext()->getSecurityOrigin())) {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 sharedBufferHandle->Map(allocationSize); 153 sharedBufferHandle->Map(allocationSize);
149 154
150 const SkPixmap pixmap(skiaInfo, mappedBuffer.get(), skiaInfo.minRowBytes()); 155 const SkPixmap pixmap(skiaInfo, mappedBuffer.get(), skiaInfo.minRowBytes());
151 if (!image->readPixels(pixmap, 0, 0)) { 156 if (!image->readPixels(pixmap, 0, 0)) {
152 resolver->reject(DOMException::create( 157 resolver->reject(DOMException::create(
153 InvalidStateError, 158 InvalidStateError,
154 "Failed to read pixels: Unable to decompress or unsupported format.")); 159 "Failed to read pixels: Unable to decompress or unsupported format."));
155 return promise; 160 return promise;
156 } 161 }
157 162
158 if (!m_service) { 163 if (!m_faceService) {
159 resolver->reject(DOMException::create( 164 resolver->reject(DOMException::create(
160 NotSupportedError, "Shape detection service unavailable.")); 165 NotSupportedError, "Shape detection service unavailable."));
161 return promise; 166 return promise;
162 } 167 }
163 168
164 m_serviceRequests.add(resolver); 169 m_serviceRequests.add(resolver);
165 DCHECK(m_service.is_bound());
166 if (detectorType == DetectorType::Face) { 170 if (detectorType == DetectorType::Face) {
167 m_service->DetectFaces( 171 m_faceService->Detect(std::move(sharedBufferHandle), img->naturalWidth(),
168 std::move(sharedBufferHandle), img->naturalWidth(), 172 img->naturalHeight(), m_options.Clone(),
169 img->naturalHeight(), m_options.Clone(), 173 convertToBaseCallback(WTF::bind(
170 convertToBaseCallback(WTF::bind(&ShapeDetector::onDetectFaces, 174 &ShapeDetector::onDetectFaces,
171 wrapPersistent(this), 175 wrapPersistent(this), wrapPersistent(resolver))));
172 wrapPersistent(resolver))));
173 } else if (detectorType == DetectorType::Barcode) { 176 } else if (detectorType == DetectorType::Barcode) {
174 m_service->DetectBarcodes( 177 m_barcodeService->Detect(
175 std::move(sharedBufferHandle), img->naturalWidth(), 178 std::move(sharedBufferHandle), img->naturalWidth(),
176 img->naturalHeight(), 179 img->naturalHeight(),
177 convertToBaseCallback(WTF::bind(&ShapeDetector::onDetectBarcodes, 180 convertToBaseCallback(WTF::bind(&ShapeDetector::onDetectBarcodes,
178 wrapPersistent(this), 181 wrapPersistent(this),
179 wrapPersistent(resolver)))); 182 wrapPersistent(resolver))));
180 } else { 183 } else {
181 NOTREACHED() << "Unsupported detector type"; 184 NOTREACHED() << "Unsupported detector type";
182 } 185 }
183 186
184 return promise; 187 return promise;
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 ScriptPromise promise = resolver->promise(); 286 ScriptPromise promise = resolver->promise();
284 287
285 mojo::ScopedSharedBufferHandle sharedBufferHandle = 288 mojo::ScopedSharedBufferHandle sharedBufferHandle =
286 mojo::SharedBufferHandle::Create(size); 289 mojo::SharedBufferHandle::Create(size);
287 if (!sharedBufferHandle->is_valid()) { 290 if (!sharedBufferHandle->is_valid()) {
288 resolver->reject( 291 resolver->reject(
289 DOMException::create(InvalidStateError, "Internal allocation error")); 292 DOMException::create(InvalidStateError, "Internal allocation error"));
290 return promise; 293 return promise;
291 } 294 }
292 295
293 if (!m_service) { 296 if (!m_faceService) {
294 resolver->reject(DOMException::create( 297 resolver->reject(DOMException::create(
295 NotSupportedError, "Shape detection service unavailable.")); 298 NotSupportedError, "Shape detection service unavailable."));
296 return promise; 299 return promise;
297 } 300 }
298 301
299 const mojo::ScopedSharedBufferMapping mappedBuffer = 302 const mojo::ScopedSharedBufferMapping mappedBuffer =
300 sharedBufferHandle->Map(size); 303 sharedBufferHandle->Map(size);
301 DCHECK(mappedBuffer.get()); 304 DCHECK(mappedBuffer.get());
302 305
303 memcpy(mappedBuffer.get(), data, size); 306 memcpy(mappedBuffer.get(), data, size);
304 307
305 m_serviceRequests.add(resolver); 308 m_serviceRequests.add(resolver);
306 DCHECK(m_service.is_bound()); 309 DCHECK(m_faceService.is_bound());
xianglu 2016/11/23 02:53:37 nit: Remove this DCHECK too?
mcasas 2016/11/23 14:49:38 Yeah, this was paranoia, removed.
307 if (detectorType == DetectorType::Face) { 310 if (detectorType == DetectorType::Face) {
308 m_service->DetectFaces( 311 m_faceService->Detect(
309 std::move(sharedBufferHandle), width, height, m_options.Clone(), 312 std::move(sharedBufferHandle), width, height, m_options.Clone(),
310 convertToBaseCallback(WTF::bind(&ShapeDetector::onDetectFaces, 313 convertToBaseCallback(WTF::bind(&ShapeDetector::onDetectFaces,
311 wrapPersistent(this), 314 wrapPersistent(this),
312 wrapPersistent(resolver)))); 315 wrapPersistent(resolver))));
313 } else if (detectorType == DetectorType::Barcode) { 316 } else if (detectorType == DetectorType::Barcode) {
314 m_service->DetectBarcodes( 317 m_barcodeService->Detect(
315 std::move(sharedBufferHandle), width, height, 318 std::move(sharedBufferHandle), width, height,
316 convertToBaseCallback(WTF::bind(&ShapeDetector::onDetectBarcodes, 319 convertToBaseCallback(WTF::bind(&ShapeDetector::onDetectBarcodes,
317 wrapPersistent(this), 320 wrapPersistent(this),
318 wrapPersistent(resolver)))); 321 wrapPersistent(resolver))));
319 } else { 322 } else {
320 NOTREACHED() << "Unsupported detector type"; 323 NOTREACHED() << "Unsupported detector type";
321 } 324 }
322 sharedBufferHandle.reset(); 325 sharedBufferHandle.reset();
323 return promise; 326 return promise;
324 } 327 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 } 360 }
358 361
359 resolver->resolve(detectedBarcodes); 362 resolver->resolve(detectedBarcodes);
360 } 363 }
361 364
362 DEFINE_TRACE(ShapeDetector) { 365 DEFINE_TRACE(ShapeDetector) {
363 visitor->trace(m_serviceRequests); 366 visitor->trace(m_serviceRequests);
364 } 367 }
365 368
366 } // namespace blink 369 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698