| OLD | NEW |
| 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/frame/ImageBitmap.h" | 10 #include "core/frame/ImageBitmap.h" |
| 11 #include "core/frame/LocalFrame.h" | 11 #include "core/frame/LocalFrame.h" |
| 12 #include "core/html/HTMLImageElement.h" | 12 #include "core/html/HTMLImageElement.h" |
| 13 #include "core/html/HTMLVideoElement.h" | 13 #include "core/html/HTMLVideoElement.h" |
| 14 #include "core/html/ImageData.h" | 14 #include "core/html/canvas/CanvasImageSource.h" |
| 15 #include "core/loader/resource/ImageResourceContent.h" | |
| 16 #include "platform/graphics/Image.h" | 15 #include "platform/graphics/Image.h" |
| 17 #include "third_party/skia/include/core/SkImage.h" | 16 #include "third_party/skia/include/core/SkImage.h" |
| 18 #include "third_party/skia/include/core/SkImageInfo.h" | 17 #include "third_party/skia/include/core/SkImageInfo.h" |
| 19 #include "wtf/CheckedNumeric.h" | 18 #include "wtf/CheckedNumeric.h" |
| 20 | 19 |
| 21 namespace blink { | 20 namespace blink { |
| 22 | 21 |
| 23 namespace { | 22 namespace { |
| 24 | 23 |
| 25 mojo::ScopedSharedBufferHandle getSharedBufferOnData( | 24 mojo::ScopedSharedBufferHandle getSharedBufferOnData( |
| (...skipping 15 matching lines...) Expand all Loading... |
| 41 const mojo::ScopedSharedBufferMapping mappedBuffer = | 40 const mojo::ScopedSharedBufferMapping mappedBuffer = |
| 42 sharedBufferHandle->Map(size); | 41 sharedBufferHandle->Map(size); |
| 43 DCHECK(mappedBuffer.get()); | 42 DCHECK(mappedBuffer.get()); |
| 44 memcpy(mappedBuffer.get(), data, size); | 43 memcpy(mappedBuffer.get(), data, size); |
| 45 | 44 |
| 46 return sharedBufferHandle; | 45 return sharedBufferHandle; |
| 47 } | 46 } |
| 48 | 47 |
| 49 } // anonymous namespace | 48 } // anonymous namespace |
| 50 | 49 |
| 50 // TODO(xianglu): We don't need a service per frame. Remove this argument. |
| 51 ShapeDetector::ShapeDetector(LocalFrame& frame) { | 51 ShapeDetector::ShapeDetector(LocalFrame& frame) { |
| 52 DCHECK(frame.interfaceProvider()); | 52 DCHECK(frame.interfaceProvider()); |
| 53 } | 53 } |
| 54 | 54 |
| 55 ScriptPromise ShapeDetector::detect(ScriptState* scriptState, | 55 ScriptPromise ShapeDetector::detect(ScriptState* scriptState, |
| 56 const ImageBitmapSourceUnion& imageSource) { | 56 const ImageBitmapSourceUnion& imageSource) { |
| 57 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | 57 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
| 58 ScriptPromise promise = resolver->promise(); | 58 ScriptPromise promise = resolver->promise(); |
| 59 | 59 |
| 60 // ImageDatas cannot be tainted by definition. | 60 // ImageDatas cannot be tainted by definition. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 72 canvasImageSource = imageSource.getAsHTMLCanvasElement(); | 72 canvasImageSource = imageSource.getAsHTMLCanvasElement(); |
| 73 } else if (imageSource.isOffscreenCanvas()) { | 73 } else if (imageSource.isOffscreenCanvas()) { |
| 74 canvasImageSource = imageSource.getAsOffscreenCanvas(); | 74 canvasImageSource = imageSource.getAsOffscreenCanvas(); |
| 75 } else { | 75 } else { |
| 76 NOTREACHED() << "Unsupported CanvasImageSource"; | 76 NOTREACHED() << "Unsupported CanvasImageSource"; |
| 77 resolver->reject( | 77 resolver->reject( |
| 78 DOMException::create(NotSupportedError, "Unsupported source.")); | 78 DOMException::create(NotSupportedError, "Unsupported source.")); |
| 79 return promise; | 79 return promise; |
| 80 } | 80 } |
| 81 | 81 |
| 82 if (canvasImageSource->wouldTaintOrigin( | 82 // if (canvasImageSource->wouldTaintOrigin( |
| 83 scriptState->getExecutionContext()->getSecurityOrigin())) { | 83 // scriptState->getExecutionContext()->getSecurityOrigin())) { |
| 84 resolver->reject( | 84 // resolver->reject( |
| 85 DOMException::create(SecurityError, "Source would taint origin.")); | 85 // DOMException::create(SecurityError, "Source would taint origin.")); |
| 86 return promise; | 86 // return promise; |
| 87 } | 87 // } |
| 88 | 88 |
| 89 if (imageSource.isHTMLImageElement()) { | 89 if (imageSource.isHTMLImageElement()) { |
| 90 return detectShapesOnImageElement(resolver, | 90 return detectShapesOnImageElement(resolver, |
| 91 imageSource.getAsHTMLImageElement()); | 91 imageSource.getAsHTMLImageElement()); |
| 92 } | 92 } |
| 93 | 93 |
| 94 // TODO(mcasas): Check if |video| is actually playing a MediaStream by using | 94 // TODO(mcasas): Check if |video| is actually playing a MediaStream by using |
| 95 // HTMLMediaElement::isMediaStreamURL(video->currentSrc().getString()); if | 95 // HTMLMediaElement::isMediaStreamURL(video->currentSrc().getString()); if |
| 96 // there is a local WebCam associated, there might be sophisticated ways to | 96 // there is a local WebCam associated, there might be sophisticated ways to |
| 97 // detect faces on it. Until then, treat as a normal <video> element. | 97 // detect faces on it. Until then, treat as a normal <video> element. |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 InvalidStateError, | 226 InvalidStateError, |
| 227 "Failed to read pixels: Unable to decompress or unsupported format.")); | 227 "Failed to read pixels: Unable to decompress or unsupported format.")); |
| 228 return promise; | 228 return promise; |
| 229 } | 229 } |
| 230 | 230 |
| 231 return doDetect(resolver, std::move(sharedBufferHandle), img->naturalWidth(), | 231 return doDetect(resolver, std::move(sharedBufferHandle), img->naturalWidth(), |
| 232 img->naturalHeight()); | 232 img->naturalHeight()); |
| 233 } | 233 } |
| 234 | 234 |
| 235 } // namespace blink | 235 } // namespace blink |
| OLD | NEW |