Chromium Code Reviews| 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" |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 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; | 30 using FillLightMode = media::mojom::blink::FillLightMode; |
| 31 using MeteringMode = media::mojom::blink::MeteringMode; | |
| 31 | 32 |
| 32 namespace { | 33 namespace { |
| 33 | 34 |
| 34 const char kNoServiceError[] = "ImageCapture service unavailable."; | 35 const char kNoServiceError[] = "ImageCapture service unavailable."; |
| 35 | 36 |
| 36 bool trackIsInactive(const MediaStreamTrack& track) { | 37 bool trackIsInactive(const MediaStreamTrack& track) { |
| 37 // Spec instructs to return an exception if the Track's readyState() is not | 38 // Spec instructs to return an exception if the Track's readyState() is not |
| 38 // "live". Also reject if the track is disabled or muted. | 39 // "live". Also reject if the track is disabled or muted. |
| 39 return track.readyState() != "live" || !track.enabled() || track.muted(); | 40 return track.readyState() != "live" || !track.enabled() || track.muted(); |
| 40 } | 41 } |
| 41 | 42 |
| 42 media::mojom::blink::MeteringMode parseMeteringMode(const String& blinkMode) { | 43 MeteringMode parseMeteringMode(const String& blinkMode) { |
| 43 if (blinkMode == "manual") | 44 if (blinkMode == "manual") |
| 44 return media::mojom::blink::MeteringMode::MANUAL; | 45 return MeteringMode::MANUAL; |
| 45 if (blinkMode == "single-shot") | 46 if (blinkMode == "single-shot") |
| 46 return media::mojom::blink::MeteringMode::SINGLE_SHOT; | 47 return MeteringMode::SINGLE_SHOT; |
| 47 if (blinkMode == "continuous") | 48 if (blinkMode == "continuous") |
| 48 return media::mojom::blink::MeteringMode::CONTINUOUS; | 49 return MeteringMode::CONTINUOUS; |
| 49 return media::mojom::blink::MeteringMode::NONE; | 50 return MeteringMode::NONE; |
|
Reilly Grant (use Gerrit)
2017/03/31 20:13:09
if (blinkMode == "none")
return MeteringMode::NO
mcasas
2017/03/31 21:14:47
Right, done.
| |
| 50 } | 51 } |
| 51 | 52 |
| 52 FillLightMode parseFillLightMode(const String& blinkMode) { | 53 FillLightMode parseFillLightMode(const String& blinkMode) { |
| 53 if (blinkMode == "off") | 54 if (blinkMode == "off") |
| 54 return FillLightMode::OFF; | 55 return FillLightMode::OFF; |
| 55 if (blinkMode == "auto") | 56 if (blinkMode == "auto") |
| 56 return FillLightMode::AUTO; | 57 return FillLightMode::AUTO; |
| 57 if (blinkMode == "flash") | 58 if (blinkMode == "flash") |
| 58 return FillLightMode::FLASH; | 59 return FillLightMode::FLASH; |
| 59 return FillLightMode::NONE; | 60 NOTREACHED(); |
| 61 return FillLightMode::OFF; | |
| 60 } | 62 } |
| 61 | 63 |
| 62 WebString toString(media::mojom::blink::MeteringMode value) { | 64 WebString toString(MeteringMode value) { |
| 63 switch (value) { | 65 switch (value) { |
| 64 case media::mojom::blink::MeteringMode::NONE: | 66 case MeteringMode::NONE: |
| 65 return WebString::fromUTF8("none"); | 67 return WebString::fromUTF8("none"); |
| 66 case media::mojom::blink::MeteringMode::MANUAL: | 68 case MeteringMode::MANUAL: |
| 67 return WebString::fromUTF8("manual"); | 69 return WebString::fromUTF8("manual"); |
| 68 case media::mojom::blink::MeteringMode::SINGLE_SHOT: | 70 case MeteringMode::SINGLE_SHOT: |
| 69 return WebString::fromUTF8("single-shot"); | 71 return WebString::fromUTF8("single-shot"); |
| 70 case media::mojom::blink::MeteringMode::CONTINUOUS: | 72 case MeteringMode::CONTINUOUS: |
| 71 return WebString::fromUTF8("continuous"); | 73 return WebString::fromUTF8("continuous"); |
| 72 default: | 74 default: |
| 73 NOTREACHED() << "Unknown MeteringMode"; | 75 NOTREACHED() << "Unknown MeteringMode"; |
| 74 } | 76 } |
| 75 return WebString(); | 77 return WebString(); |
| 76 } | 78 } |
| 77 | 79 |
| 78 } // anonymous namespace | 80 } // anonymous namespace |
| 79 | 81 |
| 80 ImageCapture* ImageCapture::create(ExecutionContext* context, | 82 ImageCapture* ImageCapture::create(ExecutionContext* context, |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 338 m_currentConstraints.setSharpness(constraints.sharpness()); | 340 m_currentConstraints.setSharpness(constraints.sharpness()); |
| 339 settings->sharpness = constraints.sharpness().getAsDouble(); | 341 settings->sharpness = constraints.sharpness().getAsDouble(); |
| 340 } | 342 } |
| 341 | 343 |
| 342 settings->has_zoom = constraints.hasZoom() && constraints.zoom().isDouble(); | 344 settings->has_zoom = constraints.hasZoom() && constraints.zoom().isDouble(); |
| 343 if (settings->has_zoom) { | 345 if (settings->has_zoom) { |
| 344 m_currentConstraints.setZoom(constraints.zoom()); | 346 m_currentConstraints.setZoom(constraints.zoom()); |
| 345 settings->zoom = constraints.zoom().getAsDouble(); | 347 settings->zoom = constraints.zoom().getAsDouble(); |
| 346 } | 348 } |
| 347 | 349 |
| 348 // TODO(mcasas): add |torch| when the mojom interface is updated, | 350 // TODO(mcasas): support ConstrainBooleanParameters where applicable. |
| 349 // https://crbug.com/700607. | 351 settings->has_torch = |
| 352 constraints.hasTorch() && constraints.torch().isBoolean(); | |
| 353 if (settings->has_torch) { | |
| 354 m_currentConstraints.setTorch(constraints.torch()); | |
| 355 settings->torch = constraints.torch().getAsBoolean(); | |
| 356 } | |
| 350 | 357 |
| 351 m_service->SetOptions(m_streamTrack->component()->source()->id(), | 358 m_service->SetOptions(m_streamTrack->component()->source()->id(), |
| 352 std::move(settings), | 359 std::move(settings), |
| 353 convertToBaseCallback(WTF::bind( | 360 convertToBaseCallback(WTF::bind( |
| 354 &ImageCapture::onSetOptions, wrapPersistent(this), | 361 &ImageCapture::onSetOptions, wrapPersistent(this), |
| 355 wrapPersistent(resolver)))); | 362 wrapPersistent(resolver)))); |
| 356 } | 363 } |
| 357 | 364 |
| 358 const MediaTrackConstraintSet& ImageCapture::getMediaTrackConstraints() const { | 365 const MediaTrackConstraintSet& ImageCapture::getMediaTrackConstraints() const { |
| 359 return m_currentConstraints; | 366 return m_currentConstraints; |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 380 settings.setBrightness(m_capabilities.brightness()->current()); | 387 settings.setBrightness(m_capabilities.brightness()->current()); |
| 381 if (m_capabilities.hasContrast()) | 388 if (m_capabilities.hasContrast()) |
| 382 settings.setContrast(m_capabilities.contrast()->current()); | 389 settings.setContrast(m_capabilities.contrast()->current()); |
| 383 if (m_capabilities.hasSaturation()) | 390 if (m_capabilities.hasSaturation()) |
| 384 settings.setSaturation(m_capabilities.saturation()->current()); | 391 settings.setSaturation(m_capabilities.saturation()->current()); |
| 385 if (m_capabilities.hasSharpness()) | 392 if (m_capabilities.hasSharpness()) |
| 386 settings.setSharpness(m_capabilities.sharpness()->current()); | 393 settings.setSharpness(m_capabilities.sharpness()->current()); |
| 387 | 394 |
| 388 if (m_capabilities.hasZoom()) | 395 if (m_capabilities.hasZoom()) |
| 389 settings.setZoom(m_capabilities.zoom()->current()); | 396 settings.setZoom(m_capabilities.zoom()->current()); |
| 397 if (m_capabilities.hasTorch()) | |
| 398 settings.setTorch(m_capabilities.torch()); | |
| 390 | 399 |
| 391 // TODO(mcasas): add |torch| when the mojom interface is updated, | 400 // TODO(mcasas): add |torch| when the mojom interface is updated, |
| 392 // https://crbug.com/700607. | 401 // https://crbug.com/700607. |
| 393 } | 402 } |
| 394 | 403 |
| 395 ImageCapture::ImageCapture(ExecutionContext* context, MediaStreamTrack* track) | 404 ImageCapture::ImageCapture(ExecutionContext* context, MediaStreamTrack* track) |
| 396 : ContextLifecycleObserver(context), m_streamTrack(track) { | 405 : ContextLifecycleObserver(context), m_streamTrack(track) { |
| 397 DCHECK(m_streamTrack); | 406 DCHECK(m_streamTrack); |
| 398 DCHECK(!m_service.is_bound()); | 407 DCHECK(!m_service.is_bound()); |
| 399 | 408 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 416 media::mojom::blink::PhotoCapabilitiesPtr capabilities) { | 425 media::mojom::blink::PhotoCapabilitiesPtr capabilities) { |
| 417 if (!m_serviceRequests.contains(resolver)) | 426 if (!m_serviceRequests.contains(resolver)) |
| 418 return; | 427 return; |
| 419 if (capabilities.is_null()) { | 428 if (capabilities.is_null()) { |
| 420 resolver->reject(DOMException::create(UnknownError, "platform error")); | 429 resolver->reject(DOMException::create(UnknownError, "platform error")); |
| 421 } else { | 430 } else { |
| 422 // Update the local capabilities cache. | 431 // Update the local capabilities cache. |
| 423 onCapabilitiesUpdate(capabilities.Clone()); | 432 onCapabilitiesUpdate(capabilities.Clone()); |
| 424 | 433 |
| 425 PhotoCapabilities* caps = PhotoCapabilities::create(); | 434 PhotoCapabilities* caps = PhotoCapabilities::create(); |
| 435 | |
| 436 caps->setRedEyeReduction(capabilities->red_eye_reduction); | |
| 426 // TODO(mcasas): Remove the explicit MediaSettingsRange::create() when | 437 // TODO(mcasas): Remove the explicit MediaSettingsRange::create() when |
| 427 // mojo::StructTraits supports garbage-collected mappings, | 438 // mojo::StructTraits supports garbage-collected mappings, |
| 428 // https://crbug.com/700180. | 439 // https://crbug.com/700180. |
| 429 caps->setImageHeight( | 440 caps->setImageHeight( |
| 430 MediaSettingsRange::create(std::move(capabilities->height))); | 441 MediaSettingsRange::create(std::move(capabilities->height))); |
| 431 caps->setImageWidth( | 442 caps->setImageWidth( |
| 432 MediaSettingsRange::create(std::move(capabilities->width))); | 443 MediaSettingsRange::create(std::move(capabilities->width))); |
| 433 | 444 caps->setFillLightMode(capabilities->fill_light_mode); |
| 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. | |
| 443 caps->setRedEyeReduction(capabilities->red_eye_reduction); | |
| 444 | 445 |
| 445 resolver->resolve(caps); | 446 resolver->resolve(caps); |
| 446 } | 447 } |
| 447 m_serviceRequests.erase(resolver); | 448 m_serviceRequests.erase(resolver); |
| 448 } | 449 } |
| 449 | 450 |
| 450 void ImageCapture::onSetOptions(ScriptPromiseResolver* resolver, bool result) { | 451 void ImageCapture::onSetOptions(ScriptPromiseResolver* resolver, bool result) { |
| 451 if (!m_serviceRequests.contains(resolver)) | 452 if (!m_serviceRequests.contains(resolver)) |
| 452 return; | 453 return; |
| 453 | 454 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 526 if (capabilities->sharpness->max != capabilities->sharpness->min) { | 527 if (capabilities->sharpness->max != capabilities->sharpness->min) { |
| 527 m_capabilities.setSharpness( | 528 m_capabilities.setSharpness( |
| 528 MediaSettingsRange::create(std::move(capabilities->sharpness))); | 529 MediaSettingsRange::create(std::move(capabilities->sharpness))); |
| 529 } | 530 } |
| 530 | 531 |
| 531 if (capabilities->zoom->max != capabilities->zoom->min) { | 532 if (capabilities->zoom->max != capabilities->zoom->min) { |
| 532 m_capabilities.setZoom( | 533 m_capabilities.setZoom( |
| 533 MediaSettingsRange::create(std::move(capabilities->zoom))); | 534 MediaSettingsRange::create(std::move(capabilities->zoom))); |
| 534 } | 535 } |
| 535 | 536 |
| 537 m_capabilities.setTorch(capabilities->torch); | |
| 538 | |
| 536 // TODO(mcasas): do |torch| when the mojom interface is updated, | 539 // TODO(mcasas): do |torch| when the mojom interface is updated, |
| 537 // https://crbug.com/700607. | 540 // https://crbug.com/700607. |
| 538 } | 541 } |
| 539 | 542 |
| 540 void ImageCapture::onServiceConnectionError() { | 543 void ImageCapture::onServiceConnectionError() { |
| 541 m_service.reset(); | 544 m_service.reset(); |
| 542 for (ScriptPromiseResolver* resolver : m_serviceRequests) | 545 for (ScriptPromiseResolver* resolver : m_serviceRequests) |
| 543 resolver->reject(DOMException::create(NotFoundError, kNoServiceError)); | 546 resolver->reject(DOMException::create(NotFoundError, kNoServiceError)); |
| 544 m_serviceRequests.clear(); | 547 m_serviceRequests.clear(); |
| 545 } | 548 } |
| 546 | 549 |
| 547 DEFINE_TRACE(ImageCapture) { | 550 DEFINE_TRACE(ImageCapture) { |
| 548 visitor->trace(m_streamTrack); | 551 visitor->trace(m_streamTrack); |
| 549 visitor->trace(m_capabilities); | 552 visitor->trace(m_capabilities); |
| 550 visitor->trace(m_currentConstraints); | 553 visitor->trace(m_currentConstraints); |
| 551 visitor->trace(m_serviceRequests); | 554 visitor->trace(m_serviceRequests); |
| 552 EventTargetWithInlineData::trace(visitor); | 555 EventTargetWithInlineData::trace(visitor); |
| 553 ContextLifecycleObserver::trace(visitor); | 556 ContextLifecycleObserver::trace(visitor); |
| 554 } | 557 } |
| 555 | 558 |
| 556 } // namespace blink | 559 } // namespace blink |
| OLD | NEW |