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/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" |
11 #include "core/fileapi/Blob.h" | 11 #include "core/fileapi/Blob.h" |
12 #include "core/frame/ImageBitmap.h" | 12 #include "core/frame/ImageBitmap.h" |
13 #include "modules/EventTargetModules.h" | 13 #include "modules/EventTargetModules.h" |
14 #include "modules/imagecapture/MediaSettingsRange.h" | 14 #include "modules/imagecapture/MediaSettingsRange.h" |
15 #include "modules/imagecapture/PhotoCapabilities.h" | 15 #include "modules/imagecapture/PhotoCapabilities.h" |
16 #include "modules/imagecapture/PhotoSettings.h" | 16 #include "modules/imagecapture/PhotoSettings.h" |
17 #include "modules/mediastream/MediaStreamTrack.h" | 17 #include "modules/mediastream/MediaStreamTrack.h" |
18 #include "modules/mediastream/MediaTrackCapabilities.h" | 18 #include "modules/mediastream/MediaTrackCapabilities.h" |
19 #include "modules/mediastream/MediaTrackSettings.h" | 19 #include "modules/mediastream/MediaTrackSettings.h" |
20 #include "platform/WaitableEvent.h" | 20 #include "platform/WaitableEvent.h" |
21 #include "platform/mojo/MojoHelper.h" | 21 #include "platform/mojo/MojoHelper.h" |
22 #include "public/platform/InterfaceProvider.h" | 22 #include "public/platform/InterfaceProvider.h" |
23 #include "public/platform/Platform.h" | 23 #include "public/platform/Platform.h" |
24 #include "public/platform/WebImageCaptureFrameGrabber.h" | 24 #include "public/platform/WebImageCaptureFrameGrabber.h" |
25 #include "public/platform/WebMediaStreamTrack.h" | 25 #include "public/platform/WebMediaStreamTrack.h" |
26 #include "wtf/PtrUtil.h" | 26 #include "wtf/PtrUtil.h" |
27 | 27 |
28 namespace blink { | 28 namespace blink { |
29 | 29 |
| 30 using FillLightMode = media::mojom::blink::FillLightMode; |
| 31 |
30 namespace { | 32 namespace { |
31 | 33 |
32 const char kNoServiceError[] = "ImageCapture service unavailable."; | 34 const char kNoServiceError[] = "ImageCapture service unavailable."; |
33 | 35 |
34 bool trackIsInactive(const MediaStreamTrack& track) { | 36 bool trackIsInactive(const MediaStreamTrack& track) { |
35 // Spec instructs to return an exception if the Track's readyState() is not | 37 // Spec instructs to return an exception if the Track's readyState() is not |
36 // "live". Also reject if the track is disabled or muted. | 38 // "live". Also reject if the track is disabled or muted. |
37 return track.readyState() != "live" || !track.enabled() || track.muted(); | 39 return track.readyState() != "live" || !track.enabled() || track.muted(); |
38 } | 40 } |
39 | 41 |
40 media::mojom::blink::MeteringMode parseMeteringMode(const String& blinkMode) { | 42 media::mojom::blink::MeteringMode parseMeteringMode(const String& blinkMode) { |
41 if (blinkMode == "manual") | 43 if (blinkMode == "manual") |
42 return media::mojom::blink::MeteringMode::MANUAL; | 44 return media::mojom::blink::MeteringMode::MANUAL; |
43 if (blinkMode == "single-shot") | 45 if (blinkMode == "single-shot") |
44 return media::mojom::blink::MeteringMode::SINGLE_SHOT; | 46 return media::mojom::blink::MeteringMode::SINGLE_SHOT; |
45 if (blinkMode == "continuous") | 47 if (blinkMode == "continuous") |
46 return media::mojom::blink::MeteringMode::CONTINUOUS; | 48 return media::mojom::blink::MeteringMode::CONTINUOUS; |
47 return media::mojom::blink::MeteringMode::NONE; | 49 return media::mojom::blink::MeteringMode::NONE; |
48 } | 50 } |
49 | 51 |
50 media::mojom::blink::FillLightMode parseFillLightMode(const String& blinkMode) { | 52 FillLightMode parseFillLightMode(const String& blinkMode) { |
51 if (blinkMode == "off") | 53 if (blinkMode == "off") |
52 return media::mojom::blink::FillLightMode::OFF; | 54 return FillLightMode::OFF; |
53 if (blinkMode == "auto") | 55 if (blinkMode == "auto") |
54 return media::mojom::blink::FillLightMode::AUTO; | 56 return FillLightMode::AUTO; |
55 if (blinkMode == "flash") | 57 if (blinkMode == "flash") |
56 return media::mojom::blink::FillLightMode::FLASH; | 58 return FillLightMode::FLASH; |
57 if (blinkMode == "torch") | 59 return FillLightMode::NONE; |
58 return media::mojom::blink::FillLightMode::TORCH; | |
59 return media::mojom::blink::FillLightMode::NONE; | |
60 } | 60 } |
61 | 61 |
62 WebString toString(media::mojom::blink::MeteringMode value) { | 62 WebString toString(media::mojom::blink::MeteringMode value) { |
63 switch (value) { | 63 switch (value) { |
64 case media::mojom::blink::MeteringMode::NONE: | 64 case media::mojom::blink::MeteringMode::NONE: |
65 return WebString::fromUTF8("none"); | 65 return WebString::fromUTF8("none"); |
66 case media::mojom::blink::MeteringMode::MANUAL: | 66 case media::mojom::blink::MeteringMode::MANUAL: |
67 return WebString::fromUTF8("manual"); | 67 return WebString::fromUTF8("manual"); |
68 case media::mojom::blink::MeteringMode::SINGLE_SHOT: | 68 case media::mojom::blink::MeteringMode::SINGLE_SHOT: |
69 return WebString::fromUTF8("single-shot"); | 69 return WebString::fromUTF8("single-shot"); |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 onCapabilitiesUpdate(capabilities.Clone()); | 423 onCapabilitiesUpdate(capabilities.Clone()); |
424 | 424 |
425 PhotoCapabilities* caps = PhotoCapabilities::create(); | 425 PhotoCapabilities* caps = PhotoCapabilities::create(); |
426 // TODO(mcasas): Remove the explicit MediaSettingsRange::create() when | 426 // TODO(mcasas): Remove the explicit MediaSettingsRange::create() when |
427 // mojo::StructTraits supports garbage-collected mappings, | 427 // mojo::StructTraits supports garbage-collected mappings, |
428 // https://crbug.com/700180. | 428 // https://crbug.com/700180. |
429 caps->setImageHeight( | 429 caps->setImageHeight( |
430 MediaSettingsRange::create(std::move(capabilities->height))); | 430 MediaSettingsRange::create(std::move(capabilities->height))); |
431 caps->setImageWidth( | 431 caps->setImageWidth( |
432 MediaSettingsRange::create(std::move(capabilities->width))); | 432 MediaSettingsRange::create(std::move(capabilities->width))); |
433 caps->setFillLightMode(capabilities->fill_light_mode); | 433 |
| 434 // TODO(mcasas): use a list of supported modes when mojo is updated. |
| 435 // https://crbug.com/700607. |
| 436 if (capabilities->fill_light_mode == FillLightMode::NONE) |
| 437 caps->setFillLightMode(Vector<FillLightMode>()); |
| 438 else |
| 439 caps->setFillLightMode({capabilities->fill_light_mode}); |
| 440 |
| 441 // TODO(mcasas): use a list of supported modes when mojo is updated. |
| 442 // https://crbug.com/700607. |
434 caps->setRedEyeReduction(capabilities->red_eye_reduction); | 443 caps->setRedEyeReduction(capabilities->red_eye_reduction); |
435 | 444 |
436 resolver->resolve(caps); | 445 resolver->resolve(caps); |
437 } | 446 } |
438 m_serviceRequests.erase(resolver); | 447 m_serviceRequests.erase(resolver); |
439 } | 448 } |
440 | 449 |
441 void ImageCapture::onSetOptions(ScriptPromiseResolver* resolver, bool result) { | 450 void ImageCapture::onSetOptions(ScriptPromiseResolver* resolver, bool result) { |
442 if (!m_serviceRequests.contains(resolver)) | 451 if (!m_serviceRequests.contains(resolver)) |
443 return; | 452 return; |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 DEFINE_TRACE(ImageCapture) { | 547 DEFINE_TRACE(ImageCapture) { |
539 visitor->trace(m_streamTrack); | 548 visitor->trace(m_streamTrack); |
540 visitor->trace(m_capabilities); | 549 visitor->trace(m_capabilities); |
541 visitor->trace(m_currentConstraints); | 550 visitor->trace(m_currentConstraints); |
542 visitor->trace(m_serviceRequests); | 551 visitor->trace(m_serviceRequests); |
543 EventTargetWithInlineData::trace(visitor); | 552 EventTargetWithInlineData::trace(visitor); |
544 ContextLifecycleObserver::trace(visitor); | 553 ContextLifecycleObserver::trace(visitor); |
545 } | 554 } |
546 | 555 |
547 } // namespace blink | 556 } // namespace blink |
OLD | NEW |